Repository: rust
Issue: ICE: Should not have unglued last token with cfg attr
Labels: I-ICE,T-compiler,C-bug,glacier,S-bug-has-test

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.

http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/

-->

### Code

```Rust
#[derive(Debug)]      
struct S<#[cfg(feature = "alloc")] N: A<T>> {}
```


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`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`
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
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::<impl rustc_parse::parser::Parser>::parse_generic_params
   2: rustc_parse::parser::generics::<impl rustc_parse::parser::Parser>::parse_generics
   3: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_item_kind
   4: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_item_common
   5: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_item
   6: rustc_builtin_macros::cfg_eval::cfg_eval
   7: <rustc_builtin_macros::derive::Expander as rustc_expand::base::MultiItemModifier>::expand
   8: rustc_expand::expand::MacroExpander::fully_expand_fragment
   9: rustc_expand::expand::MacroExpander::expand_crate
  10: rustc_session::utils::<impl rustc_session::session::Session>::time
  11: rustc_interface::passes::configure_and_expand
  12: rustc_interface::queries::Queries::expansion
  13: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  14: rustc_span::with_source_map
  15: rustc_interface::interface::create_compiler_and_run
  16: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```

</p>
</details>