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

Add X to crate attributes to enable message is not very clear #55941

Closed
Firstyear opened this issue Nov 14, 2018 · 1 comment · Fixed by #122158
Closed

Add X to crate attributes to enable message is not very clear #55941

Firstyear opened this issue Nov 14, 2018 · 1 comment · Fixed by #122158
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Firstyear
Copy link
Contributor

Firstyear commented Nov 14, 2018

error[E0658]: use of unstable library feature 'try_from' (see issue #33417)
   --> src/schema.rs:441:9
    |
441 |     use std::convert::TryFrom;
    |         ^^^^^^^^^^^^^^^^^^^^^
    |
    = help: add #![feature(try_from)] to the crate attributes to enable

The message above is what I get attempting to use try_from. The issue is that it's not clear where crate attributes are, or whey they go. The rust book makes little mention of them. Adding this to "lib.rs", causes new errors such as:

error: an inner attribute is not permitted in this context
  --> src/lib.rs:15:3
   |
15 | #![feature(try_from)]
   |   ^
   |
   = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.

As a result, it's really not clear how to resolve this error.

The descriptive error rustc --explain E0658 also doesn't demonstrate what to do correctly.

The error message should explain which file to add the #[feature] line too. Additionally, the E0658 should explain not just what file, but what to do in a multi-file case (ie lib.rs contains mod foo, and foo.rs wants to use the feature).

This would help to make this easier to resolve and access these features.

EDIT: It would be also useful to handle the mod tests situation as well where you want to test a feature like TryFrom in mod tests, because that likely needs different/other handling?

@jonas-schievink jonas-schievink added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 27, 2019
@crlf0710 crlf0710 added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 11, 2020
@estebank
Copy link
Contributor

estebank commented Mar 7, 2024

Triage: no change. It should be relatively straightforward to find the right span place (it's effectively tcx.def_span(crate_root).shrink_to_lo()).

estebank added a commit to estebank/rust that referenced this issue Mar 7, 2024
```
error: `S2<'_>` is forbidden as the type of a const generic parameter
  --> $DIR/lifetime-in-const-param.rs:5:23
   |
LL | struct S<'a, const N: S2>(&'a ());
   |                       ^^
   |
   = note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
   |
LL + #![feature(adt_const_params)]
   |
```

Fix rust-lang#55941.
estebank added a commit to estebank/rust that referenced this issue Mar 7, 2024
```
error: `S2<'_>` is forbidden as the type of a const generic parameter
  --> $DIR/lifetime-in-const-param.rs:5:23
   |
LL | struct S<'a, const N: S2>(&'a ());
   |                       ^^
   |
   = note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
   |
LL + #![feature(adt_const_params)]
   |
```

Fix rust-lang#55941.
estebank added a commit to estebank/rust that referenced this issue Mar 14, 2024
```
error: `S2<'_>` is forbidden as the type of a const generic parameter
  --> $DIR/lifetime-in-const-param.rs:5:23
   |
LL | struct S<'a, const N: S2>(&'a ());
   |                       ^^
   |
   = note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
   |
LL + #![feature(adt_const_params)]
   |
```

Fix rust-lang#55941.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 18, 2024
Provide structured suggestion for `#![feature(foo)]`

```
error: `S2<'_>` is forbidden as the type of a const generic parameter
  --> $DIR/lifetime-in-const-param.rs:5:23
   |
LL | struct S<'a, const N: S2>(&'a ());
   |                       ^^
   |
   = note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
   |
LL + #![feature(adt_const_params)]
   |
```

Fix rust-lang#55941.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 18, 2024
Provide structured suggestion for `#![feature(foo)]`

```
error: `S2<'_>` is forbidden as the type of a const generic parameter
  --> $DIR/lifetime-in-const-param.rs:5:23
   |
LL | struct S<'a, const N: S2>(&'a ());
   |                       ^^
   |
   = note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
   |
LL + #![feature(adt_const_params)]
   |
```

Fix rust-lang#55941.
@bors bors closed this as completed in 6c31f6c Mar 18, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 18, 2024
Rollup merge of rust-lang#122158 - estebank:feature-sugg, r=WaffleLapkin

Provide structured suggestion for `#![feature(foo)]`

```
error: `S2<'_>` is forbidden as the type of a const generic parameter
  --> $DIR/lifetime-in-const-param.rs:5:23
   |
LL | struct S<'a, const N: S2>(&'a ());
   |                       ^^
   |
   = note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
   |
LL + #![feature(adt_const_params)]
   |
```

Fix rust-lang#55941.
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. 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.

4 participants