Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/rustc_parse/src/parser/attr_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Comment on lines +365 to +367
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrochenkov this change is so that we no longer ICE on the face of

struct S<#[cfg(feature = "alloc")] N: A<T>>;
                                         ^^ these currently get split and cause the assertion to fail unconditionally

I believe that this change is reasonable. Is there any reason we shouldn't land this PR as is? Put another way, are there any non-local knock down effects from this change that come to mind?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gentle ping @petrochenkov for this comment. thanks.


let range: Range<u32> = (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);
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/unpretty/unglued-token.rs
Original file line number Diff line number Diff line change
@@ -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<T>>;

fn main() {
let s = S;
}
17 changes: 17 additions & 0 deletions tests/ui/unpretty/unglued-token.stdout
Original file line number Diff line number Diff line change
@@ -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; }