diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index 8133f9f68234b..6f7ce916c7ac7 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -66,6 +66,13 @@ struct BoundVarContext<'a, 'tcx> { rbv: &'a mut ResolveBoundVars, disambiguator: &'a mut DisambiguatorState, scope: ScopeRef<'a>, + opaque_capture_errors: RefCell>, +} + +struct OpaqueHigherRankedLifetimeCaptureErrors { + bad_place: &'static str, + capture_spans: Vec, + decl_spans: Vec, } #[derive(Debug)] @@ -253,6 +260,7 @@ fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBou rbv: &mut rbv, scope: &Scope::Root { opt_parent_item: None }, disambiguator: &mut DisambiguatorState::new(), + opaque_capture_errors: RefCell::new(None), }; match tcx.hir_owner_node(local_def_id) { hir::OwnerNode::Item(item) => visitor.visit_item(item), @@ -597,6 +605,8 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { }) }); + self.emit_opaque_capture_errors(); + let captures = captures.into_inner().into_iter().collect(); debug!(?captures); self.rbv.opaque_captured_lifetimes.insert(opaque.def_id, captures); @@ -1089,12 +1099,20 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { F: for<'b> FnOnce(&mut BoundVarContext<'b, 'tcx>), { let BoundVarContext { tcx, rbv, disambiguator, .. } = self; - let mut this = BoundVarContext { tcx: *tcx, rbv, disambiguator, scope: &wrap_scope }; + let nested_errors = RefCell::new(self.opaque_capture_errors.borrow_mut().take()); + let mut this = BoundVarContext { + tcx: *tcx, + rbv, + disambiguator, + scope: &wrap_scope, + opaque_capture_errors: nested_errors, + }; let span = debug_span!("scope", scope = ?this.scope.debug_truncated()); { let _enter = span.enter(); f(&mut this); } + *self.opaque_capture_errors.borrow_mut() = this.opaque_capture_errors.into_inner(); } fn record_late_bound_vars(&mut self, hir_id: HirId, binder: Vec) { @@ -1424,21 +1442,52 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { }; let decl_span = self.tcx.def_span(lifetime_def_id); - let (span, label) = if capture_span != decl_span { - (capture_span, None) - } else { - let opaque_span = self.tcx.def_span(opaque_def_id); - (opaque_span, Some(opaque_span)) - }; + let opaque_span = self.tcx.def_span(opaque_def_id); + + let mut errors = self.opaque_capture_errors.borrow_mut(); + let error_info = errors.get_or_insert_with(|| OpaqueHigherRankedLifetimeCaptureErrors { + bad_place, + capture_spans: Vec::new(), + decl_spans: Vec::new(), + }); + + if error_info.capture_spans.is_empty() { + error_info.capture_spans.push(opaque_span); + } + + if capture_span != decl_span && capture_span != opaque_span { + error_info.capture_spans.push(capture_span); + } + + if !error_info.decl_spans.contains(&decl_span) { + error_info.decl_spans.push(decl_span); + } + + // Errors should be emitted by `emit_opaque_capture_errors`. + Err(self.tcx.dcx().span_delayed_bug(capture_span, "opaque capture error not emitted")) + } + + fn emit_opaque_capture_errors(&self) -> Option { + let errors = self.opaque_capture_errors.borrow_mut().take()?; + if errors.capture_spans.is_empty() { + return None; + } + + let mut span = rustc_errors::MultiSpan::from_span(errors.capture_spans[0]); + for &capture_span in &errors.capture_spans[1..] { + span.push_span_label(capture_span, ""); + } + let decl_span = rustc_errors::MultiSpan::from_spans(errors.decl_spans); // Ensure that the parent of the def is an item, not HRTB let guar = self.tcx.dcx().emit_err(errors::OpaqueCapturesHigherRankedLifetime { span, - label, + label: Some(errors.capture_spans[0]), decl_span, - bad_place, + bad_place: errors.bad_place, }); - Err(guar) + + Some(guar) } #[instrument(level = "trace", skip(self, opaque_capture_scopes), ret)] diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 49c5106422881..c0cb6f7327993 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -1562,11 +1562,11 @@ pub(crate) struct UnconstrainedGenericParameter { #[diag(hir_analysis_opaque_captures_higher_ranked_lifetime, code = E0657)] pub(crate) struct OpaqueCapturesHigherRankedLifetime { #[primary_span] - pub span: Span, + pub span: MultiSpan, #[label] pub label: Option, #[note] - pub decl_span: Span, + pub decl_span: MultiSpan, pub bad_place: &'static str, } diff --git a/tests/ui/error-codes/E0657.stderr b/tests/ui/error-codes/E0657.stderr index c9dfc9eb9069d..1d69af5d9654a 100644 --- a/tests/ui/error-codes/E0657.stderr +++ b/tests/ui/error-codes/E0657.stderr @@ -1,8 +1,8 @@ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from `dyn` type - --> $DIR/E0657.rs:10:35 + --> $DIR/E0657.rs:10:27 | LL | -> Box Id>> - | ^^ + | ^^^^^^^^--^ `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/E0657.rs:10:20 @@ -11,10 +11,10 @@ LL | -> Box Id>> | ^^ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from `dyn` type - --> $DIR/E0657.rs:19:39 + --> $DIR/E0657.rs:19:31 | LL | -> Box Id>> - | ^^ + | ^^^^^^^^--^ `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/E0657.rs:19:24 diff --git a/tests/ui/impl-trait/higher-ranked-lifetime-capture-deduplication.edition2015.stderr b/tests/ui/impl-trait/higher-ranked-lifetime-capture-deduplication.edition2015.stderr new file mode 100644 index 0000000000000..8954a802ab952 --- /dev/null +++ b/tests/ui/impl-trait/higher-ranked-lifetime-capture-deduplication.edition2015.stderr @@ -0,0 +1,17 @@ +error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` + --> $DIR/higher-ranked-lifetime-capture-deduplication.rs:19:44 + | +LL | fn f() -> impl for<'a, 'b> Trait<'a, Out = impl Sized + 'a + 'b> { + | ^^^^^^^^^^^^^--^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope + | +note: lifetime declared here + --> $DIR/higher-ranked-lifetime-capture-deduplication.rs:19:20 + | +LL | fn f() -> impl for<'a, 'b> Trait<'a, Out = impl Sized + 'a + 'b> { + | ^^ ^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0657`. diff --git a/tests/ui/impl-trait/higher-ranked-lifetime-capture-deduplication.edition2024.stderr b/tests/ui/impl-trait/higher-ranked-lifetime-capture-deduplication.edition2024.stderr new file mode 100644 index 0000000000000..8954a802ab952 --- /dev/null +++ b/tests/ui/impl-trait/higher-ranked-lifetime-capture-deduplication.edition2024.stderr @@ -0,0 +1,17 @@ +error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` + --> $DIR/higher-ranked-lifetime-capture-deduplication.rs:19:44 + | +LL | fn f() -> impl for<'a, 'b> Trait<'a, Out = impl Sized + 'a + 'b> { + | ^^^^^^^^^^^^^--^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope + | +note: lifetime declared here + --> $DIR/higher-ranked-lifetime-capture-deduplication.rs:19:20 + | +LL | fn f() -> impl for<'a, 'b> Trait<'a, Out = impl Sized + 'a + 'b> { + | ^^ ^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0657`. diff --git a/tests/ui/impl-trait/higher-ranked-lifetime-capture-deduplication.rs b/tests/ui/impl-trait/higher-ranked-lifetime-capture-deduplication.rs new file mode 100644 index 0000000000000..d8da93e5560d7 --- /dev/null +++ b/tests/ui/impl-trait/higher-ranked-lifetime-capture-deduplication.rs @@ -0,0 +1,26 @@ +//@revisions: edition2015 edition2024 +//@[edition2015] edition:2015 +//@[edition2024] edition:2024 + +trait Trait<'a> { + type Out; + fn call(&'a self) -> Self::Out; +} + +struct X(()); + +impl<'a> Trait<'a> for X { + type Out = (); + fn call(&'a self) -> Self::Out { + () + } +} + +fn f() -> impl for<'a, 'b> Trait<'a, Out = impl Sized + 'a + 'b> { + //~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` + X(()) +} + +fn main() { + let _ = f(); +} diff --git a/tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr b/tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr index 40cb6b647d1e9..36f52e8103a33 100644 --- a/tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr +++ b/tests/ui/impl-trait/impl-fn-hrtb-bounds.stderr @@ -12,10 +12,12 @@ LL + fn d() -> impl Fn() -> (impl Debug + 'static) { | error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/impl-fn-hrtb-bounds.rs:4:41 + --> $DIR/impl-fn-hrtb-bounds.rs:4:28 | LL | fn a() -> impl Fn(&u8) -> (impl Debug + '_) { - | ^^ + | ^^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/impl-fn-hrtb-bounds.rs:4:19 @@ -24,10 +26,12 @@ LL | fn a() -> impl Fn(&u8) -> (impl Debug + '_) { | ^ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/impl-fn-hrtb-bounds.rs:9:52 + --> $DIR/impl-fn-hrtb-bounds.rs:9:39 | LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) { - | ^^ + | ^^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/impl-fn-hrtb-bounds.rs:9:20 @@ -36,10 +40,12 @@ LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) { | ^^ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/impl-fn-hrtb-bounds.rs:14:52 + --> $DIR/impl-fn-hrtb-bounds.rs:14:39 | LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) { - | ^^ + | ^^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/impl-fn-hrtb-bounds.rs:14:20 diff --git a/tests/ui/impl-trait/impl-fn-parsing-ambiguities.stderr b/tests/ui/impl-trait/impl-fn-parsing-ambiguities.stderr index 94b6ffdd91230..5ba9567e14e37 100644 --- a/tests/ui/impl-trait/impl-fn-parsing-ambiguities.stderr +++ b/tests/ui/impl-trait/impl-fn-parsing-ambiguities.stderr @@ -21,10 +21,12 @@ LL | fn b() -> impl Fn() -> (impl Debug + Send) { | + + error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/impl-fn-parsing-ambiguities.rs:4:40 + --> $DIR/impl-fn-parsing-ambiguities.rs:4:27 | LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ { - | ^^ + | ^^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/impl-fn-parsing-ambiguities.rs:4:19 diff --git a/tests/ui/impl-trait/issues/issue-54895.edition2015.stderr b/tests/ui/impl-trait/issues/issue-54895.edition2015.stderr index 27a3c6c8b7ce0..8348a1d5e87b1 100644 --- a/tests/ui/impl-trait/issues/issue-54895.edition2015.stderr +++ b/tests/ui/impl-trait/issues/issue-54895.edition2015.stderr @@ -1,8 +1,10 @@ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/issue-54895.rs:18:53 + --> $DIR/issue-54895.rs:18:40 | LL | fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> { - | ^^ + | ^^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/issue-54895.rs:18:20 diff --git a/tests/ui/impl-trait/issues/issue-54895.edition2024.stderr b/tests/ui/impl-trait/issues/issue-54895.edition2024.stderr index 54aa29e62d880..8348a1d5e87b1 100644 --- a/tests/ui/impl-trait/issues/issue-54895.edition2024.stderr +++ b/tests/ui/impl-trait/issues/issue-54895.edition2024.stderr @@ -2,7 +2,9 @@ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `imp --> $DIR/issue-54895.rs:18:40 | LL | fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> { - | ^^^^^^^^^^^^^^^ `impl Trait` implicitly captures all lifetimes in scope + | ^^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/issue-54895.rs:18:20 @@ -10,18 +12,6 @@ note: lifetime declared here LL | fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> { | ^^ -error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/issue-54895.rs:18:53 - | -LL | fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> { - | ^^ - | -note: lifetime declared here - --> $DIR/issue-54895.rs:18:20 - | -LL | fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> { - | ^^ - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0657`. diff --git a/tests/ui/impl-trait/issues/issue-54895.rs b/tests/ui/impl-trait/issues/issue-54895.rs index bc1841209e170..ccdb0ce20f9a0 100644 --- a/tests/ui/impl-trait/issues/issue-54895.rs +++ b/tests/ui/impl-trait/issues/issue-54895.rs @@ -17,7 +17,6 @@ impl<'a> Trait<'a> for X { fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> { //~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - //[edition2024]~^^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` X(()) } diff --git a/tests/ui/impl-trait/issues/issue-67830.stderr b/tests/ui/impl-trait/issues/issue-67830.stderr index a7633c7f20b65..7254955ed0bde 100644 --- a/tests/ui/impl-trait/issues/issue-67830.stderr +++ b/tests/ui/impl-trait/issues/issue-67830.stderr @@ -1,8 +1,10 @@ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/issue-67830.rs:20:64 + --> $DIR/issue-67830.rs:20:48 | LL | fn test() -> impl for<'a> MyFn<&'a A, Output = impl Iterator + 'a> { - | ^^ + | ^^^^^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/issue-67830.rs:20:23 diff --git a/tests/ui/impl-trait/issues/issue-88236-2.stderr b/tests/ui/impl-trait/issues/issue-88236-2.stderr index 4ded9ed386fa6..3943c41218454 100644 --- a/tests/ui/impl-trait/issues/issue-88236-2.stderr +++ b/tests/ui/impl-trait/issues/issue-88236-2.stderr @@ -1,8 +1,10 @@ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/issue-88236-2.rs:15:61 + --> $DIR/issue-88236-2.rs:15:49 | LL | fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {} - | ^^ + | ^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/issue-88236-2.rs:15:28 @@ -11,10 +13,12 @@ LL | fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {} | ^^ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/issue-88236-2.rs:18:80 + --> $DIR/issue-88236-2.rs:18:68 | LL | fn make_weird_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> { - | ^^ + | ^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/issue-88236-2.rs:18:47 @@ -23,10 +27,12 @@ LL | fn make_weird_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Sen | ^^ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/issue-88236-2.rs:23:78 + --> $DIR/issue-88236-2.rs:23:66 | LL | fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> { - | ^^ + | ^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/issue-88236-2.rs:23:45 diff --git a/tests/ui/impl-trait/issues/issue-88236.stderr b/tests/ui/impl-trait/issues/issue-88236.stderr index 5dee5f88c89f2..6303379288b7f 100644 --- a/tests/ui/impl-trait/issues/issue-88236.stderr +++ b/tests/ui/impl-trait/issues/issue-88236.stderr @@ -1,8 +1,10 @@ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/issue-88236.rs:15:61 + --> $DIR/issue-88236.rs:15:49 | LL | fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {} - | ^^ + | ^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/issue-88236.rs:15:28 diff --git a/tests/ui/impl-trait/nested-rpit-hrtb.stderr b/tests/ui/impl-trait/nested-rpit-hrtb.stderr index 93cd7bd788f45..130723035b1ac 100644 --- a/tests/ui/impl-trait/nested-rpit-hrtb.stderr +++ b/tests/ui/impl-trait/nested-rpit-hrtb.stderr @@ -30,10 +30,12 @@ LL | fn two_htrb_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl for<'b | ++++ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/nested-rpit-hrtb.rs:25:69 + --> $DIR/nested-rpit-hrtb.rs:25:56 | LL | fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {} - | ^^ + | ^^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/nested-rpit-hrtb.rs:25:36 @@ -42,10 +44,10 @@ LL | fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {} | ^^ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/nested-rpit-hrtb.rs:29:68 + --> $DIR/nested-rpit-hrtb.rs:29:59 | LL | fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {} - | ^^ + | ^^^^^^^^^--^ `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/nested-rpit-hrtb.rs:29:39 @@ -54,10 +56,12 @@ LL | fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {} | ^^ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/nested-rpit-hrtb.rs:32:74 + --> $DIR/nested-rpit-hrtb.rs:32:61 | LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {} - | ^^ + | ^^^^^^^^^^^^^-- + | | + | `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/nested-rpit-hrtb.rs:32:41 @@ -66,10 +70,10 @@ LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a | ^^ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/nested-rpit-hrtb.rs:35:73 + --> $DIR/nested-rpit-hrtb.rs:35:64 | LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {} - | ^^ + | ^^^^^^^^^--^ `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/nested-rpit-hrtb.rs:35:44 diff --git a/tests/ui/type-alias-impl-trait/bound-lifetime-through-dyn-trait.stderr b/tests/ui/type-alias-impl-trait/bound-lifetime-through-dyn-trait.stderr index 7219fda4772a2..6f0c6bb22060a 100644 --- a/tests/ui/type-alias-impl-trait/bound-lifetime-through-dyn-trait.stderr +++ b/tests/ui/type-alias-impl-trait/bound-lifetime-through-dyn-trait.stderr @@ -1,8 +1,8 @@ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from `dyn` type - --> $DIR/bound-lifetime-through-dyn-trait.rs:6:71 + --> $DIR/bound-lifetime-through-dyn-trait.rs:6:57 | LL | fn dyn_hoops() -> dyn for<'a> Iterator> { - | ^^ + | ^^^^^^^^^^^^^^--^ `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/bound-lifetime-through-dyn-trait.rs:6:37 diff --git a/tests/ui/type-alias-impl-trait/escaping-bound-var.rs b/tests/ui/type-alias-impl-trait/escaping-bound-var.rs index 31bdd0815ec34..4b17448080ed7 100644 --- a/tests/ui/type-alias-impl-trait/escaping-bound-var.rs +++ b/tests/ui/type-alias-impl-trait/escaping-bound-var.rs @@ -8,7 +8,6 @@ trait Test<'a> {} pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>; //~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` -//~| ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` impl Trait<'_> for () { type Assoc = (); diff --git a/tests/ui/type-alias-impl-trait/escaping-bound-var.stderr b/tests/ui/type-alias-impl-trait/escaping-bound-var.stderr index c9f0618639afb..cdbcfa6f3dc95 100644 --- a/tests/ui/type-alias-impl-trait/escaping-bound-var.stderr +++ b/tests/ui/type-alias-impl-trait/escaping-bound-var.stderr @@ -2,7 +2,7 @@ error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `imp --> $DIR/escaping-bound-var.rs:9:47 | LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>; - | ^^^^^^^^^^^^^ `impl Trait` implicitly captures all lifetimes in scope + | ^^^^^^^^^^--^ `impl Trait` implicitly captures all lifetimes in scope | note: lifetime declared here --> $DIR/escaping-bound-var.rs:9:25 @@ -10,18 +10,6 @@ note: lifetime declared here LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>; | ^^ -error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait` - --> $DIR/escaping-bound-var.rs:9:57 - | -LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>; - | ^^ - | -note: lifetime declared here - --> $DIR/escaping-bound-var.rs:9:25 - | -LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>; - | ^^ - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0657`.