When I run a certain compiler flag the Rust compiler can't find my main

  #![cfg(feature = "const_mut_refs")] //currently breaking my main function
  
  
  
  
  fn main() {
      println!("Hello, world!");
  }

Currently whenever I have this compiler flag on my nightly compiler my main function can't be found. It gives me the error:

"main function not found in crate insert_name_here consider adding a main function to src/main.rs"

I don't know who to inform about said error, but I know it's a nightly feature so I thought I should inform the community in some way. I tried to make the smallest reproducable version so others could tell me their experiences or if there was a way they could fix it.

I'd define this as a compiler error but not in the traditional sense, because the compiler is the one making the mistake.

You got the syntax wrong, it's

#![feature(const_mut_refs)]

for activating unstable language features on nightly; whereas the cfg syntax you used is for adding feature flags to your crate for conditional compilation.

See also:

Conditional compilation - The Rust Reference

Unstable features - The rustdoc book

5 Likes

Also, why have you got to be cross-posting this? Unmarked, and within <10min, isn't that a bit impatient? It just means that people collectively need to do duplicate work to answer the same question multiple times in multiple places.

3 Likes

My bad thought it'd be faster, but I will be more considerate in the future, It was honestly very spontaneous, I had an idea and I wanted to implement it and I encountered an error but I already found a solution. My apologies for the late reply.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.