Skip to content

Commit b72fa8c

Browse files
authored
Auto merge of #35567 - creativcoder:e0261, r=jonathandturner
Update E0261 and E0262 to new error format Fixes #35516 and #35517 . Part of #35233 r? @jonathandturner
2 parents f0bab98 + 02fa14f commit b72fa8c

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/librustc/middle/resolve_lifetime.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
697697
}
698698

699699
fn unresolved_lifetime_ref(&self, lifetime_ref: &hir::Lifetime) {
700-
span_err!(self.sess, lifetime_ref.span, E0261,
701-
"use of undeclared lifetime name `{}`",
702-
lifetime_ref.name);
700+
struct_span_err!(self.sess, lifetime_ref.span, E0261,
701+
"use of undeclared lifetime name `{}`", lifetime_ref.name)
702+
.span_label(lifetime_ref.span, &format!("undeclared lifetime"))
703+
.emit();
703704
}
704705

705706
fn check_lifetime_defs(&mut self, old_scope: Scope, lifetimes: &[hir::LifetimeDef]) {
@@ -708,8 +709,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
708709

709710
for lifetime in lifetimes {
710711
if lifetime.lifetime.name == keywords::StaticLifetime.name() {
711-
span_err!(self.sess, lifetime.lifetime.span, E0262,
712-
"invalid lifetime parameter name: `{}`", lifetime.lifetime.name);
712+
let lifetime = lifetime.lifetime;
713+
let mut err = struct_span_err!(self.sess, lifetime.span, E0262,
714+
"invalid lifetime parameter name: `{}`", lifetime.name);
715+
err.span_label(lifetime.span,
716+
&format!("{} is a reserved lifetime name", lifetime.name));
717+
err.emit();
713718
}
714719
}
715720

src/test/compile-fail/E0261.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
// except according to those terms.
1010

1111
fn foo(x: &'a str) { } //~ ERROR E0261
12+
//~| undeclared lifetime
1213

1314
struct Foo {
1415
x: &'a str, //~ ERROR E0261
16+
//~| undeclared lifetime
1517
}
1618

1719
fn main() {}

src/test/compile-fail/E0262.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
// except according to those terms.
1010

1111
fn foo<'static>(x: &'static str) { } //~ ERROR E0262
12+
//~| 'static is a reserved lifetime name
1213

1314
fn main() {}

0 commit comments

Comments
 (0)