Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error reporting for #![feature(...)] in the wrong place #81370

Closed
martindemello opened this issue Jan 25, 2021 · 2 comments · Fixed by #134858
Closed

Improve error reporting for #![feature(...)] in the wrong place #81370

martindemello opened this issue Jan 25, 2021 · 2 comments · Fixed by #134858
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@martindemello
Copy link
Contributor

I spent a while wondering why I was getting this error

error[E0658]: use of unstable library feature 'array_map'
  --> src/board.rs:67:17
   |
67 |         offsets.map(|(dx, dy)| {
   |                 ^^^
   |
   = note: see issue #75243 <https://github.com/rust-lang/rust/issues/75243> for more information
   = help: add `#![feature(array_map)]` to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.

even when I added !#[feature(array_map)] to the top of my file, and even when the same thing was working fine in main.rs. I finally found this stackoverflow post and this reddit thread that said if I were using cargo build I had to add the directive to lib.rs instead, after which everything worked.

I'm not sure where in the docs the best place for that would be (I had already read the section on attributes and crates in "rust by example" and not found the relevant hint), but it would be nice if it could be surfaced in the error message too.

@martindemello martindemello added the C-bug Category: This is a bug. label Jan 25, 2021
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Jan 25, 2021
@ehuss
Copy link
Contributor

ehuss commented Jan 25, 2021

I think there are two issues here. One is that the error message could provide more information. It does say the crate attributes which can only appear in the root of the crate. However, it would probably be clearer if it could tell you where that is.

The other issue is that the feature attribute position is not validated (it seems to be silently ignored anywhere but the root). That should be an error (or a future-incompatible warning).

estebank added a commit to estebank/rust that referenced this issue Dec 28, 2024
When encountering a call corresponding to an item marked as unstable behind a feature flag, provide a structured suggestion pointing at where in the crate the `#![feature(..)]` needs to be written.

```
error: `foobar` is not yet stable as a const fn
  --> $DIR/const-stability-attribute-implies-no-feature.rs:12:5
   |
LL |     foobar();
   |     ^^^^^^^^
   |
help: add `#![feature(const_foobar)]` to the crate attributes to enable
   |
LL + #![feature(const_foobar)]
   |
```

Fix rust-lang#81370.
@estebank
Copy link
Contributor

Split off the second part in the comment above to its own ticket.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jan 19, 2025
Provide structured suggestion for `#![feature(..)]` in more cases

Fix rust-lang#81370.
@bors bors closed this as completed in a47fee5 Jan 19, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 19, 2025
Rollup merge of rust-lang#134858 - estebank:issue-81370, r=Noratrieb

Provide structured suggestion for `#![feature(..)]` in more cases

Fix rust-lang#81370.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants