Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ impl<'a> Parser<'a> {
self.break_last_token = 0;
if next.0.span.is_dummy() {
// Tweak the location for better diagnostics, but keep syntactic context intact.
let fallback_span = self.token.span;
let fallback_span = self.token.span.shrink_to_hi();
next.0.span = fallback_span.with_ctxt(next.0.span.ctxt());
}
debug_assert!(!matches!(
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/parser/lifetime-in-pattern-closure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Test case for issue #134061
// Check that the compiler properly suggests removing unexpected lifetime in closure pattern

const x: () = |&'a| ();
//~^ ERROR unexpected lifetime `'a` in pattern
//~| HELP remove the lifetime
//~| ERROR expected parameter name, found `|`

fn main() {}
20 changes: 20 additions & 0 deletions tests/ui/parser/lifetime-in-pattern-closure.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: unexpected lifetime `'a` in pattern
--> $DIR/lifetime-in-pattern-closure.rs:4:17
|
LL | const x: () = |&'a| ();
| ^^
|
help: remove the lifetime
|
LL - const x: () = |&'a| ();
LL + const x: () = |&| ();
Comment on lines +9 to +10
Copy link
Member

@Kivooeo Kivooeo Aug 13, 2025

Choose a reason for hiding this comment

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

I don't feel like that's a good idea to show incorrect suggestion like this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about whether there might be other good alternatives, but I keep reaching that this code suggestion is definitely unnecessary. I also confirmed that the updated stderr files show poor error indication quality. So, I'll closing this PR. Thanks for the review 👍

|

error: expected parameter name, found `|`
--> $DIR/lifetime-in-pattern-closure.rs:4:19
|
LL | const x: () = |&'a| ();
| ^ expected parameter name

error: aborting due to 2 previous errors

7 changes: 7 additions & 0 deletions tests/ui/parser/lifetime-in-pattern-eof.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test case for issue #134061 - exact reproduction case
// Tests the specific case where EOF is encountered after lifetime in pattern

const x: () = |&'a
//~^ ERROR unexpected lifetime `'a` in pattern
//~| HELP remove the lifetime
//~| ERROR expected parameter name, found `<eof>`
20 changes: 20 additions & 0 deletions tests/ui/parser/lifetime-in-pattern-eof.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: unexpected lifetime `'a` in pattern
--> $DIR/lifetime-in-pattern-eof.rs:4:17
|
LL | const x: () = |&'a
| ^^
|
help: remove the lifetime
|
LL - const x: () = |&'a
LL + const x: () = |&
Comment on lines +9 to +10
Copy link
Member

Choose a reason for hiding this comment

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

It does not make sense at all for me, but I may missing something?

|

error: expected parameter name, found `<eof>`
--> $DIR/lifetime-in-pattern-eof.rs:4:19
|
LL | const x: () = |&'a
| ^ expected parameter name

error: aborting due to 2 previous errors

Loading