Skip to content

Commit e62471d

Browse files
authored
Rollup merge of rust-lang#143280 - xizheyin:143152-1, r=compiler-errors
Remove duplicate error about raw underscore lifetime Fixes rust-lang#143152 r? `@fee1-dead`
2 parents c837add + 848d4a5 commit e62471d

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

compiler/rustc_resolve/src/late.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2899,9 +2899,21 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28992899
}
29002900

29012901
if param.ident.name == kw::UnderscoreLifetime {
2902+
// To avoid emitting two similar errors,
2903+
// we need to check if the span is a raw underscore lifetime, see issue #143152
2904+
let is_raw_underscore_lifetime = self
2905+
.r
2906+
.tcx
2907+
.sess
2908+
.psess
2909+
.raw_identifier_spans
2910+
.iter()
2911+
.any(|span| span == param.span());
2912+
29022913
self.r
29032914
.dcx()
2904-
.emit_err(errors::UnderscoreLifetimeIsReserved { span: param.ident.span });
2915+
.create_err(errors::UnderscoreLifetimeIsReserved { span: param.ident.span })
2916+
.emit_unless(is_raw_underscore_lifetime);
29052917
// Record lifetime res, so lowering knows there is something fishy.
29062918
self.record_lifetime_param(param.id, LifetimeRes::Error);
29072919
continue;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This test is to ensure that the raw underscore lifetime won't emit two duplicate errors.
2+
// See issue #143152
3+
4+
//@ edition: 2021
5+
6+
fn f<'r#_>(){}
7+
//~^ ERROR `_` cannot be a raw lifetime
8+
9+
fn main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: `_` cannot be a raw lifetime
2+
--> $DIR/raw-underscore-lifetime.rs:6:6
3+
|
4+
LL | fn f<'r#_>(){}
5+
| ^^^^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)