rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.92k stars 12.53k forks source link

ICE: Should not have unglued last token with cfg attr #87577

Open samlich opened 3 years ago

samlich commented 3 years ago

Code

#[derive(Debug)]      
struct S<#[cfg(feature = "alloc")] N: A<T>> {}

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (2faabf579 2021-07-27)
binary: rustc
commit-hash: 2faabf579323f5252329264cc53ba9ff803429a3
commit-date: 2021-07-27
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1

First fails in rustc 1.53.0-nightly (a86612456 2021-04-11).

Compiles successfully in rustc 1.53.0-nightly (a836d9b64 2021-04-10).

Perhaps related to #82608 which was merged on that date and appears when searching "unglued."

Error output

thread 'rustc' panicked at 'Should not have unglued last token with cfg attr', compiler/rustc_parse/src/parser/attr_wrapper.rs:371:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.56.0-nightly (2faabf579 2021-07-27) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental -C link-arg=-fuse-ld=lld --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `unglued`
Backtrace

``` thread 'rustc' panicked at 'Should not have unglued last token with cfg attr', compiler/rustc_parse/src/parser/attr_wrapper.rs:371:13 stack backtrace: 0: std::panicking::begin_panic 1: rustc_parse::parser::generics::::parse_generic_params 2: rustc_parse::parser::generics::::parse_generics 3: rustc_parse::parser::item::::parse_item_kind 4: rustc_parse::parser::item::::parse_item_common 5: rustc_parse::parser::item::::parse_item 6: rustc_builtin_macros::cfg_eval::cfg_eval 7: ::expand 8: rustc_expand::expand::MacroExpander::fully_expand_fragment 9: rustc_expand::expand::MacroExpander::expand_crate 10: rustc_session::utils::::time 11: rustc_interface::passes::configure_and_expand 12: rustc_interface::queries::Queries::expansion 13: rustc_interface::queries::::enter 14: rustc_span::with_source_map 15: rustc_interface::interface::create_compiler_and_run 16: scoped_tls::ScopedKey::set note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ```

Aaron1011 commented 3 years ago

As a temporary workaround, you can add a comma between the two > characters:

#[derive(Debug)]      
struct S<#[cfg(feature = "alloc")] N: A<T>,> {}
Enselic commented 1 year ago

Triage: This ICE still reproduces with latest nightly:

$ echo '#[derive(Debug)] struct S<#[cfg(feature = "alloc")] N: A<T>> {}' | rustc +nightly --crate-type lib -
thread 'rustc' panicked at compiler/rustc_parse/src/parser/attr_wrapper.rs:365:13:
Should not have unglued last token with cfg attr
...
$ rustc +nightly -vV
rustc 1.74.0-nightly (1e746d774 2023-09-07)
binary: rustc
commit-hash: 1e746d7741d44551e9378daf13b8797322aa0b74
commit-date: 2023-09-07
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0
lolbinarycat commented 1 week ago

triage: yep, still broken