diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index 5d6c574baa612..063b6d73f4bbf 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -362,7 +362,10 @@ impl<'a> Parser<'a> { let start_pos = if has_outer_attrs { attrs.start_pos } else { start_pos }; let new_tokens = vec![(FlatToken::AttrTarget(attr_data), Spacing::Alone)]; - assert!(!self.break_last_token, "Should not have unglued last token with cfg attr"); + if !(self.token.kind == TokenKind::Gt && self.unmatched_angle_bracket_count > 0) { + assert!(!self.break_last_token, "Should not have unglued last token with cfg attr"); + } + let range: Range = (start_pos.try_into().unwrap())..(end_pos.try_into().unwrap()); self.capture_state.replace_ranges.push((range, new_tokens)); self.capture_state.replace_ranges.extend(inner_attr_replace_ranges); diff --git a/tests/ui/unpretty/unglued-token.rs b/tests/ui/unpretty/unglued-token.rs new file mode 100644 index 0000000000000..cb6257b4e843c --- /dev/null +++ b/tests/ui/unpretty/unglued-token.rs @@ -0,0 +1,11 @@ +// check-pass +// compile-flags: -Zunpretty=hir + +// https://github.com/rust-lang/rust/issues/87577 + +#[derive(Debug)] +struct S<#[cfg(feature = "alloc")] N: A>; + +fn main() { + let s = S; +} diff --git a/tests/ui/unpretty/unglued-token.stdout b/tests/ui/unpretty/unglued-token.stdout new file mode 100644 index 0000000000000..ccbbd8cc5c2b3 --- /dev/null +++ b/tests/ui/unpretty/unglued-token.stdout @@ -0,0 +1,17 @@ +#[prelude_import] +use ::std::prelude::rust_2015::*; +#[macro_use] +extern crate std; +// check-pass +// compile-flags: -Zunpretty=hir + +// https://github.com/rust-lang/rust/issues/87577 + +struct S; +#[automatically_derived] +impl ::core::fmt::Debug for S { + fn fmt<'_, '_, '_>(self: &'_ Self, f: &'_ mut ::core::fmt::Formatter<>) + -> ::core::fmt::Result { ::core::fmt::Formatter::write_str(f, "S") } +} + +fn main() { let s = S; }