Skip to content

Commit

Permalink
migrate lifetime too
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 26, 2023
1 parent 26cd548 commit 724f3ff
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ hir_analysis_invalid_union_field_sugg =
hir_analysis_late_bound_const_in_apit = `impl Trait` can only mention const parameters from an fn or impl
.label = const parameter declared here
hir_analysis_late_bound_lifetime_in_apit = `impl Trait` can only mention lifetimes from an fn or impl
.label = lifetime declared here
hir_analysis_late_bound_type_in_apit = `impl Trait` can only mention type parameters from an fn or impl
.label = type parameter declared here
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,12 +1344,10 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
Scope::Binder {
where_bound_origin: Some(hir::PredicateOrigin::ImplTrait), ..
} => {
let mut err = self.tcx.sess.struct_span_err(
lifetime_ref.ident.span,
"`impl Trait` can only mention lifetimes bound at the fn or impl level",
);
err.span_note(self.tcx.def_span(region_def_id), "lifetime declared here");
err.emit();
self.tcx.sess.emit_err(errors::LateBoundInApit::Lifetime {
span: lifetime_ref.ident.span,
param_span: self.tcx.def_span(region_def_id),
});
return;
}
Scope::Root { .. } => break,
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,4 +892,11 @@ pub(crate) enum LateBoundInApit {
#[label]
param_span: Span,
},
#[diag(hir_analysis_late_bound_lifetime_in_apit)]
Lifetime {
#[primary_span]
span: Span,
#[label]
param_span: Span,
},
}
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/universal_wrong_hrtb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ trait Trait<'a> {
}

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

fn main() {}
10 changes: 2 additions & 8 deletions tests/ui/impl-trait/universal_wrong_hrtb.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
error: `impl Trait` can only mention lifetimes bound at the fn or impl level
error: `impl Trait` can only mention lifetimes from an fn or impl
--> $DIR/universal_wrong_hrtb.rs:5:73
|
LL | fn test_argument_position(x: impl for<'a> Trait<'a, Assoc = impl Copy + 'a>) {}
| ^^
|
note: lifetime declared here
--> $DIR/universal_wrong_hrtb.rs:5:39
|
LL | fn test_argument_position(x: impl for<'a> Trait<'a, Assoc = impl Copy + 'a>) {}
| ^^
| -- lifetime declared here ^^

error: aborting due to previous error

0 comments on commit 724f3ff

Please sign in to comment.