Skip to content

parse error in #[feature(...)] discards all mentioned features. #80227

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

Open
lcnr opened this issue Dec 20, 2020 · 3 comments
Open

parse error in #[feature(...)] discards all mentioned features. #80227

lcnr opened this issue Dec 20, 2020 · 3 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-parser Area: The lexing & parsing of Rust source code to an AST C-bug Category: This is a bug.

Comments

@lcnr
Copy link
Contributor

lcnr commented Dec 20, 2020

#![feature(const_generics, use std::mem)]

pub struct Bar<const N: usize>;

and

#![feature(const_generics, 'other_feature)]

pub struct Bar<const N: usize>;

Both emit both a parse error and

error[E0658]: const generics are unstable
 --> src/lib.rs:3:22
  |
3 | pub struct Bar<const N: usize>;
  |                      ^
  |
  = note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
  = help: add `#![feature(min_const_generics)]` to the crate attributes to enable

Ideally we should still accept the features parsed before that error, so it would be nice to only emit the parse error here.

Split out from #80077, thanks @leonardo-m for opening that issue.

@varkor
Copy link
Member

varkor commented Dec 20, 2020

Presumably this is the behaviour for attributes in general: if a single item is malformed, the entire attribute won't be parsed. I wonder whether resolving this in general might lead to unexpected behaviour for other attributes.

@camelid camelid added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-parser Area: The lexing & parsing of Rust source code to an AST labels Dec 20, 2020
@Veykril
Copy link
Member

Veykril commented Jun 11, 2025

This seems to be fixed, both of those snippets emit parser errors now

@lcnr
Copy link
Contributor Author

lcnr commented Jun 11, 2025

This is only as const_generics is stable 😁🤔

#![feature(inherent_associated_types, 'not_valid)]

struct Foo;
impl Foo {
    type Assoc = u32;
}

still results in

error: expected unsuffixed literal, found `'not_valid`
 --> src/lib.rs:1:39
  |
1 | #![feature(inherent_associated_types, 'not_valid)]
  |                                       ^^^^^^^^^^

error[E0658]: inherent associated types are unstable
 --> src/lib.rs:5:5
  |
5 |     type Assoc = u32;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information
  = help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable
  = note: this compiler was built on 2025-06-10; consider upgrading it if it is out of date

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-parser Area: The lexing & parsing of Rust source code to an AST C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants