Skip to content

Commit edd5a3e

Browse files
committed
Remove duplicate error about raw underscore lifetime
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
1 parent ee4395b commit edd5a3e

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

‎compiler/rustc_resolve/src/late.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2902,7 +2902,16 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
29022902
}
29032903
}
29042904

2905-
if param.ident.name == kw::UnderscoreLifetime {
2905+
// To avoid emitting two duplicate errors, we need to check if the span is a raw underscore lifetime, see issue #143152
2906+
let is_raw_underscore = self
2907+
.r
2908+
.tcx
2909+
.sess
2910+
.psess
2911+
.raw_identifier_spans
2912+
.iter()
2913+
.any(|span| span == param.span());
2914+
if param.ident.name == kw::UnderscoreLifetime && !is_raw_underscore {
29062915
self.r
29072916
.dcx()
29082917
.emit_err(errors::UnderscoreLifetimeIsReserved { span: param.ident.span });

‎tests/ui/underscore-lifetime/raw-underscore-lifetime.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55

66
fn f<'r#_>(){}
77
//~^ ERROR `_` cannot be a raw lifetime
8-
//~| ERROR `'_` cannot be used here [E0637]
98

109
fn main() {}

‎tests/ui/underscore-lifetime/raw-underscore-lifetime.stderr

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,5 @@ error: `_` cannot be a raw lifetime
44
LL | fn f<'r#_>(){}
55
| ^^^^
66

7-
error[E0637]: `'_` cannot be used here
8-
--> $DIR/raw-underscore-lifetime.rs:6:6
9-
|
10-
LL | fn f<'r#_>(){}
11-
| ^^^^ `'_` is a reserved lifetime name
12-
13-
error: aborting due to 2 previous errors
7+
error: aborting due to 1 previous error
148

15-
For more information about this error, try `rustc --explain E0637`.

0 commit comments

Comments
 (0)