Skip to content

Commit 724f3ff

Browse files
migrate lifetime too
1 parent 26cd548 commit 724f3ff

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

Diff for: compiler/rustc_hir_analysis/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ hir_analysis_invalid_union_field_sugg =
102102
hir_analysis_late_bound_const_in_apit = `impl Trait` can only mention const parameters from an fn or impl
103103
.label = const parameter declared here
104104
105+
hir_analysis_late_bound_lifetime_in_apit = `impl Trait` can only mention lifetimes from an fn or impl
106+
.label = lifetime declared here
107+
105108
hir_analysis_late_bound_type_in_apit = `impl Trait` can only mention type parameters from an fn or impl
106109
.label = type parameter declared here
107110

Diff for: compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1344,12 +1344,10 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
13441344
Scope::Binder {
13451345
where_bound_origin: Some(hir::PredicateOrigin::ImplTrait), ..
13461346
} => {
1347-
let mut err = self.tcx.sess.struct_span_err(
1348-
lifetime_ref.ident.span,
1349-
"`impl Trait` can only mention lifetimes bound at the fn or impl level",
1350-
);
1351-
err.span_note(self.tcx.def_span(region_def_id), "lifetime declared here");
1352-
err.emit();
1347+
self.tcx.sess.emit_err(errors::LateBoundInApit::Lifetime {
1348+
span: lifetime_ref.ident.span,
1349+
param_span: self.tcx.def_span(region_def_id),
1350+
});
13531351
return;
13541352
}
13551353
Scope::Root { .. } => break,

Diff for: compiler/rustc_hir_analysis/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -892,4 +892,11 @@ pub(crate) enum LateBoundInApit {
892892
#[label]
893893
param_span: Span,
894894
},
895+
#[diag(hir_analysis_late_bound_lifetime_in_apit)]
896+
Lifetime {
897+
#[primary_span]
898+
span: Span,
899+
#[label]
900+
param_span: Span,
901+
},
895902
}

Diff for: tests/ui/impl-trait/universal_wrong_hrtb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ trait Trait<'a> {
33
}
44

55
fn test_argument_position(x: impl for<'a> Trait<'a, Assoc = impl Copy + 'a>) {}
6-
//~^ ERROR `impl Trait` can only mention lifetimes bound at the fn or impl level
6+
//~^ ERROR `impl Trait` can only mention lifetimes from an fn or impl
77

88
fn main() {}

Diff for: tests/ui/impl-trait/universal_wrong_hrtb.stderr

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
error: `impl Trait` can only mention lifetimes bound at the fn or impl level
1+
error: `impl Trait` can only mention lifetimes from an fn or impl
22
--> $DIR/universal_wrong_hrtb.rs:5:73
33
|
44
LL | fn test_argument_position(x: impl for<'a> Trait<'a, Assoc = impl Copy + 'a>) {}
5-
| ^^
6-
|
7-
note: lifetime declared here
8-
--> $DIR/universal_wrong_hrtb.rs:5:39
9-
|
10-
LL | fn test_argument_position(x: impl for<'a> Trait<'a, Assoc = impl Copy + 'a>) {}
11-
| ^^
5+
| -- lifetime declared here ^^
126

137
error: aborting due to previous error
148

0 commit comments

Comments
 (0)