From b02f2982e72ceca83965ac0bd19ffed196110758 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 25 Sep 2021 11:49:14 +0000 Subject: [PATCH] Remove regionck member constraint handling and leave it to mir borrowck --- .../src/infer/lexical_region_resolve/mod.rs | 163 +----------------- .../multiple-lifetimes/ret-impl-trait-one.rs | 1 - .../ret-impl-trait-one.stderr | 17 +- .../ui/impl-trait/hidden-lifetimes.nll.stderr | 29 ---- .../ui/impl-trait/hidden-lifetimes.stderr | 2 +- .../ordinary-bounds-unrelated.nll.stderr | 16 -- .../ordinary-bounds-unrelated.stderr | 11 +- .../ordinary-bounds-unsuited.nll.stderr | 16 -- .../ordinary-bounds-unsuited.stderr | 11 +- ...t_outlive_least_region_or_bound.nll.stderr | 8 +- .../must_outlive_least_region_or_bound.rs | 2 - .../must_outlive_least_region_or_bound.stderr | 67 +++---- .../static-return-lifetime-infered.nll.stderr | 55 ------ .../static-return-lifetime-infered.rs | 4 - .../static-return-lifetime-infered.stderr | 102 ++++------- ...s_pin_lifetime_impl_trait-async.nll.stderr | 16 -- ...elf_types_pin_lifetime_impl_trait-async.rs | 1 - ...types_pin_lifetime_impl_trait-async.stderr | 15 +- ...f_types_pin_lifetime_impl_trait.nll.stderr | 16 -- ..._self_types_pin_lifetime_impl_trait.stderr | 11 +- 20 files changed, 79 insertions(+), 484 deletions(-) delete mode 100644 src/test/ui/impl-trait/hidden-lifetimes.nll.stderr delete mode 100644 src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr delete mode 100644 src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr delete mode 100644 src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr delete mode 100644 src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr delete mode 100644 src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index bae6103cad53..d7e1b4545b8c 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -2,7 +2,6 @@ use crate::infer::region_constraints::Constraint; use crate::infer::region_constraints::GenericKind; -use crate::infer::region_constraints::MemberConstraint; use crate::infer::region_constraints::RegionConstraintData; use crate::infer::region_constraints::VarInfos; use crate::infer::region_constraints::VerifyBound; @@ -150,12 +149,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { let graph = self.construct_graph(); self.expand_givens(&graph); - loop { - self.expansion(&mut var_data); - if !self.enforce_member_constraints(&graph, &mut var_data) { - break; - } - } + self.expansion(&mut var_data); self.collect_errors(&mut var_data, errors); self.collect_var_errors(&var_data, &graph, errors); var_data @@ -233,133 +227,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { } } - /// Enforce all member constraints and return true if anything - /// changed. See `enforce_member_constraint` for more details. - fn enforce_member_constraints( - &self, - graph: &RegionGraph<'tcx>, - var_values: &mut LexicalRegionResolutions<'tcx>, - ) -> bool { - // Note: we don't use the `any` combinator because we don't - // want to stop at the first constraint that makes a change. - let mut any_changed = false; - for member_constraint in &self.data.member_constraints { - any_changed |= self.enforce_member_constraint(graph, member_constraint, var_values); - } - any_changed - } - - /// Enforce a constraint like - /// - /// ``` - /// 'r member of ['c...] - /// ``` - /// - /// We look for all choice regions from the list `'c...` that: - /// - /// (a) are greater than the current value of `'r` (which is a lower bound) - /// - /// and - /// - /// (b) are compatible with the upper bounds of `'r` that we can - /// find by traversing the graph. - /// - /// From that list, we look for a *minimal* option `'c_min`. If we - /// find one, then we can enforce that `'r: 'c_min`. - #[instrument(level = "debug", skip(self, graph, member_constraint, var_values))] - fn enforce_member_constraint( - &self, - graph: &RegionGraph<'tcx>, - member_constraint: &MemberConstraint<'tcx>, - var_values: &mut LexicalRegionResolutions<'tcx>, - ) -> bool { - debug!("member_constraint={:#?}", member_constraint); - - // The constraint is some inference variable (`vid`) which - // must be equal to one of the options. - let member_vid = match member_constraint.member_region { - ty::ReVar(vid) => *vid, - _ => return false, - }; - - // The current value of `vid` is a lower bound LB -- i.e., we - // know that `LB <= vid` must be true. - let member_lower_bound: ty::Region<'tcx> = match var_values.value(member_vid) { - VarValue::ErrorValue => return false, - VarValue::Value(r) => r, - }; - - // Find all the "upper bounds" -- that is, each region `b` such that - // `r0 <= b` must hold. - let (member_upper_bounds, ..) = - self.collect_bounding_regions(graph, member_vid, OUTGOING, None); - - // Get an iterator over the *available choice* -- that is, - // each choice region `c` where `lb <= c` and `c <= ub` for all the - // upper bounds `ub`. - debug!("upper_bounds={:#?}", member_upper_bounds); - let mut options = member_constraint - .choice_regions - .iter() - // If any of the regions are inference vars, resolve them, as far - // as possible. - .filter_map(|option| match option { - ty::ReVar(vid) => match var_values.value(*vid) { - VarValue::ErrorValue => None, - VarValue::Value(r) => Some(r), - }, - r => Some(r), - }) - .filter(|option| { - self.sub_concrete_regions(member_lower_bound, option) - && member_upper_bounds - .iter() - .all(|upper_bound| self.sub_concrete_regions(option, upper_bound.region)) - }); - - // If there is more than one option, we only make a choice if - // there is a single *least* choice -- i.e., some available - // region that is `<=` all the others. - let mut least_choice: ty::Region<'tcx> = match options.next() { - Some(&r) => r, - None => return false, - }; - debug!(?least_choice); - for &option in options { - debug!(?option); - if !self.sub_concrete_regions(least_choice, option) { - if self.sub_concrete_regions(option, least_choice) { - debug!("new least choice"); - least_choice = option; - } else { - debug!("no least choice"); - return false; - } - } - } - - // (#72087) Different `ty::Regions` can be known to be equal, for - // example, we know that `'a` and `'static` are equal in a function - // with a parameter of type `&'static &'a ()`. - // - // When we have two equal regions like this `expansion` will use - // `lub_concrete_regions` to pick a canonical representative. The same - // choice is needed here so that we don't end up in a cycle of - // `expansion` changing the region one way and the code here changing - // it back. - let lub = self.lub_concrete_regions(least_choice, member_lower_bound); - debug!( - "enforce_member_constraint: final least choice = {:?}\nlub = {:?}", - least_choice, lub - ); - if lub != member_lower_bound { - *var_values.value_mut(member_vid) = VarValue::Value(least_choice); - true - } else { - false - } - } - fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) { let mut constraints = IndexVec::from_elem_n(Vec::new(), var_values.values.len()); let mut changes = Vec::new(); @@ -632,34 +499,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { } } - // Check that all member constraints are satisfied. - for member_constraint in &self.data.member_constraints { - let member_region = var_data.normalize(self.tcx(), member_constraint.member_region); - let choice_regions = member_constraint - .choice_regions - .iter() - .map(|&choice_region| var_data.normalize(self.tcx(), choice_region)); - let fr = &self.region_rels.free_regions; - let sub = |a, b| { - fr.is_free_or_static(a) - && fr.is_free_or_static(b) - && fr.sub_free_regions(self.tcx(), a, b) - }; - if !choice_regions.clone().any(|choice_region| { - // This is really checking if the regions are equal. After member constraint - // resolution, one region must be equal, or a lifetime has been leaked into - // the hidden type, but does not appear in the corresponding impl trait. - sub(member_region, choice_region) && sub(choice_region, member_region) - }) { - let span = self.tcx().def_span(member_constraint.opaque_type_def_id); - errors.push(RegionResolutionError::MemberConstraintFailure { - span, - hidden_ty: member_constraint.hidden_ty, - member_region, - }); - } - } - for verify in &self.data.verifys { debug!("collect_errors: verify={:?}", verify); let sub = var_data.normalize(self.tcx(), verify.region); diff --git a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs index e2d00d8c9c4f..4f32489014d5 100644 --- a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs +++ b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.rs @@ -15,7 +15,6 @@ async fn async_ret_impl_trait3<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + // Only `'a` permitted in return type, not `'b`. async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> { //~^ ERROR captures lifetime that does not appear in bounds - //~| ERROR captures lifetime that does not appear in bounds (a, b) } diff --git a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr index 8d2a8e8f1d86..bcd96367e2fa 100644 --- a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr +++ b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr @@ -14,27 +14,14 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> { | -- ^^^^^^^^^^^^^^ | | - | hidden type `(&u8, &u8)` captures the lifetime `'b` as defined here + | hidden type `(&'a u8, &'b u8)` captures the lifetime `'b` as defined here | help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound | LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b { | ++++ -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/ret-impl-trait-one.rs:16:65 - | -LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> { - | -- ^^^^^^^^^^^^^^ - | | - | hidden type `(&u8, &u8)` captures the lifetime `'b` as defined here - | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound - | -LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b { - | ++++ - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0623, E0700. For more information about an error, try `rustc --explain E0623`. diff --git a/src/test/ui/impl-trait/hidden-lifetimes.nll.stderr b/src/test/ui/impl-trait/hidden-lifetimes.nll.stderr deleted file mode 100644 index 60d3409a8acc..000000000000 --- a/src/test/ui/impl-trait/hidden-lifetimes.nll.stderr +++ /dev/null @@ -1,29 +0,0 @@ -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/hidden-lifetimes.rs:28:54 - | -LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { - | -- ^^^^^^^^^^^^^^ - | | - | hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here - | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound - | -LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + 'b { - | ++++ - -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/hidden-lifetimes.rs:45:70 - | -LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a { - | -- ^^^^^^^^^^^^^^ - | | - | hidden type `Rc>` captures the lifetime `'b` as defined here - | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound - | -LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc>) -> impl Swap + 'a + 'b { - | ++++ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/impl-trait/hidden-lifetimes.stderr b/src/test/ui/impl-trait/hidden-lifetimes.stderr index bba920387002..60d3409a8acc 100644 --- a/src/test/ui/impl-trait/hidden-lifetimes.stderr +++ b/src/test/ui/impl-trait/hidden-lifetimes.stderr @@ -4,7 +4,7 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a { | -- ^^^^^^^^^^^^^^ | | - | hidden type `&mut &'b T` captures the lifetime `'b` as defined here + | hidden type `&'a mut &'b T` captures the lifetime `'b` as defined here | help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound | diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr deleted file mode 100644 index bfe656c7e2b4..000000000000 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.nll.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/ordinary-bounds-unrelated.rs:16:74 - | -LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> - | -- ^^^^^^^^^^^^^^^^^^ - | | - | hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here - | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound - | -LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> + 'b - | ++++ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr index a6bc8fec2838..bfe656c7e2b4 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unrelated.stderr @@ -2,13 +2,14 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea --> $DIR/ordinary-bounds-unrelated.rs:16:74 | LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> - | ^^^^^^^^^^^^^^^^^^ + | -- ^^^^^^^^^^^^^^^^^^ + | | + | hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here | -note: hidden type `Ordinary<'_>` captures lifetime smaller than the function body - --> $DIR/ordinary-bounds-unrelated.rs:16:74 +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound | -LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> - | ^^^^^^^^^^^^^^^^^^ +LL | fn upper_bounds<'a, 'b, 'c, 'd, 'e>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'d, 'e> + 'b + | ++++ error: aborting due to previous error diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr deleted file mode 100644 index 75c2dd8e9d39..000000000000 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.nll.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/ordinary-bounds-unsuited.rs:18:62 - | -LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> - | -- ^^^^^^^^^^^^^^^^^^ - | | - | hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here - | -help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound - | -LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> + 'b - | ++++ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr index a219e7474154..75c2dd8e9d39 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-unsuited.stderr @@ -2,13 +2,14 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea --> $DIR/ordinary-bounds-unsuited.rs:18:62 | LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> - | ^^^^^^^^^^^^^^^^^^ + | -- ^^^^^^^^^^^^^^^^^^ + | | + | hidden type `Ordinary<'b>` captures the lifetime `'b` as defined here | -note: hidden type `Ordinary<'_>` captures lifetime smaller than the function body - --> $DIR/ordinary-bounds-unsuited.rs:18:62 +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound | -LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> - | ^^^^^^^^^^^^^^^^^^ +LL | fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> + 'b + | ++++ error: aborting due to previous error diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr index 479874695a7f..eaf341248a18 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr @@ -59,7 +59,7 @@ LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } | let's call the lifetime of this reference `'1` error: lifetime may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:30:69 + --> $DIR/must_outlive_least_region_or_bound.rs:29:69 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } | -- lifetime `'a` defined here ^ returning this value requires that `'a` must outlive `'static` @@ -67,12 +67,12 @@ LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } = help: consider replacing `'a` with `'static` error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/must_outlive_least_region_or_bound.rs:34:61 + --> $DIR/must_outlive_least_region_or_bound.rs:33:61 | LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { | -- ^^^^^^^^^^^^^^^^ | | - | hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:37:5: 37:31]` captures the lifetime `'b` as defined here + | hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:35:5: 35:31]` captures the lifetime `'b` as defined here | help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound | @@ -80,7 +80,7 @@ LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32 | ++++ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:40:51 + --> $DIR/must_outlive_least_region_or_bound.rs:38:51 | LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { | ^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs index d30e01918409..69d2843ff3f0 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.rs @@ -22,7 +22,6 @@ fn elided4(x: &i32) -> Box { Box::new(x) } //~ ERROR E0759 fn explicit4<'a>(x: &'a i32) -> Box { Box::new(x) } //~ ERROR E0759 fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } //~ ERROR E0759 -//~^ ERROR: captures lifetime that does not appear in bounds trait LifetimeTrait<'a> {} impl<'a> LifetimeTrait<'a> for &'a i32 {} @@ -33,7 +32,6 @@ fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } //~ ERRO // only 'a was expected. fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { //~^ ERROR: captures lifetime that does not appear in bounds - //~| ERROR: captures lifetime that does not appear in bounds move |_| println!("{}", y) } diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr index b472132a12b5..d65dea7adc90 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr @@ -2,25 +2,27 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea --> $DIR/must_outlive_least_region_or_bound.rs:3:23 | LL | fn elided(x: &i32) -> impl Copy { x } - | ^^^^^^^^^ + | ---- ^^^^^^^^^ + | | + | hidden type `&i32` captures the anonymous lifetime defined here | -note: hidden type `&i32` captures lifetime smaller than the function body - --> $DIR/must_outlive_least_region_or_bound.rs:3:23 +help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound | -LL | fn elided(x: &i32) -> impl Copy { x } - | ^^^^^^^^^ +LL | fn elided(x: &i32) -> impl Copy + '_ { x } + | ++++ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> $DIR/must_outlive_least_region_or_bound.rs:6:32 | LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } - | ^^^^^^^^^ + | -- ^^^^^^^^^ + | | + | hidden type `&'a i32` captures the lifetime `'a` as defined here | -note: hidden type `&i32` captures lifetime smaller than the function body - --> $DIR/must_outlive_least_region_or_bound.rs:6:32 +help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound | -LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } - | ^^^^^^^^^ +LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } + | ++++ error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement --> $DIR/must_outlive_least_region_or_bound.rs:9:46 @@ -74,18 +76,6 @@ LL | fn foo<'a>(x: &i32) -> impl Copy + 'a { x } | | | help: add explicit lifetime `'a` to the type of `x`: `&'a i32` -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/must_outlive_least_region_or_bound.rs:24:41 - | -LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } - | ^^^^^^^^^^ - | -note: hidden type `&i32` captures lifetime smaller than the function body - --> $DIR/must_outlive_least_region_or_bound.rs:24:41 - | -LL | fn elided5(x: &i32) -> (Box, impl Debug) { (Box::new(x), x) } - | ^^^^^^^^^^ - error[E0759]: `x` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement --> $DIR/must_outlive_least_region_or_bound.rs:24:65 | @@ -102,13 +92,13 @@ LL | fn elided5(x: &i32) -> (Box, impl Debug + '_) { (Box::new(x), x) | ++++ error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/must_outlive_least_region_or_bound.rs:30:69 + --> $DIR/must_outlive_least_region_or_bound.rs:29:69 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } | ------- this data with lifetime `'a`... ^ ...is captured here... | note: ...and is required to live as long as `'static` here - --> $DIR/must_outlive_least_region_or_bound.rs:30:34 + --> $DIR/must_outlive_least_region_or_bound.rs:29:34 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,31 +112,20 @@ LL | fn with_bound<'a>(x: &'static i32) -> impl LifetimeTrait<'a> + 'static { x | ~~~~~~~~~~~~ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/must_outlive_least_region_or_bound.rs:34:61 + --> $DIR/must_outlive_least_region_or_bound.rs:33:61 | LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { - | ^^^^^^^^^^^^^^^^ + | -- ^^^^^^^^^^^^^^^^ + | | + | hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:35:5: 35:31]` captures the lifetime `'b` as defined here | -note: hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:37:5: 37:31]` captures lifetime smaller than the function body - --> $DIR/must_outlive_least_region_or_bound.rs:34:61 +help: to declare that the `impl Trait` captures 'b, you can add an explicit `'b` lifetime bound | -LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { - | ^^^^^^^^^^^^^^^^ - -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/must_outlive_least_region_or_bound.rs:34:61 - | -LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { - | ^^^^^^^^^^^^^^^^ - | -note: hidden type `[closure@$DIR/must_outlive_least_region_or_bound.rs:37:5: 37:31]` captures lifetime smaller than the function body - --> $DIR/must_outlive_least_region_or_bound.rs:34:61 - | -LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) { - | ^^^^^^^^^^^^^^^^ +LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b { + | ++++ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/must_outlive_least_region_or_bound.rs:40:51 + --> $DIR/must_outlive_least_region_or_bound.rs:38:51 | LL | fn ty_param_wont_outlive_static(x: T) -> impl Debug + 'static { | -- ^^^^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds @@ -211,7 +190,7 @@ help: alternatively, add an explicit `'static` bound to this reference LL | fn explicit4<'a>(x: &'static i32) -> Box { Box::new(x) } | ~~~~~~~~~~~~ -error: aborting due to 15 previous errors +error: aborting due to 13 previous errors Some errors have detailed explanations: E0310, E0621, E0700, E0759. For more information about an error, try `rustc --explain E0310`. diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr deleted file mode 100644 index 3d435bd1c3ff..000000000000 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr +++ /dev/null @@ -1,55 +0,0 @@ -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/static-return-lifetime-infered.rs:6:35 - | -LL | fn iter_values_anon(&self) -> impl Iterator { - | ----- ^^^^^^^^^^^^^^^^^^^^^^^ - | | - | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures the anonymous lifetime defined here - | -help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound - | -LL | fn iter_values_anon(&self) -> impl Iterator + '_ { - | ++++ - -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/static-return-lifetime-infered.rs:6:35 - | -LL | fn iter_values_anon(&self) -> impl Iterator { - | ----- ^^^^^^^^^^^^^^^^^^^^^^^ - | | - | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures the anonymous lifetime defined here - | -help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound - | -LL | fn iter_values_anon(&self) -> impl Iterator + '_ { - | ++++ - -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/static-return-lifetime-infered.rs:13:37 - | -LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | -- ^^^^^^^^^^^^^^^^^^^^^^^ - | | - | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures the lifetime `'a` as defined here - | -help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound - | -LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { - | ++++ - -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/static-return-lifetime-infered.rs:13:37 - | -LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | -- ^^^^^^^^^^^^^^^^^^^^^^^ - | | - | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures the lifetime `'a` as defined here - | -help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound - | -LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { - | ++++ - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.rs b/src/test/ui/impl-trait/static-return-lifetime-infered.rs index e204cb0f7a7f..d792c6eafb32 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.rs +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.rs @@ -6,15 +6,11 @@ impl A { fn iter_values_anon(&self) -> impl Iterator { //~^ ERROR: captures lifetime that does not appear in bounds //~| ERROR: captures lifetime that does not appear in bounds - //~| ERROR: captures lifetime that does not appear in bounds - //~| ERROR: captures lifetime that does not appear in bounds self.x.iter().map(|a| a.0) } fn iter_values<'a>(&'a self) -> impl Iterator { //~^ ERROR: captures lifetime that does not appear in bounds //~| ERROR: captures lifetime that does not appear in bounds - //~| ERROR: captures lifetime that does not appear in bounds - //~| ERROR: captures lifetime that does not appear in bounds self.x.iter().map(|a| a.0) } } diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr index 33502bcf7d05..0d68f8c825f7 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr @@ -2,98 +2,54 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea --> $DIR/static-return-lifetime-infered.rs:6:35 | LL | fn iter_values_anon(&self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ----- ^^^^^^^^^^^^^^^^^^^^^^^ + | | + | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:9:27: 9:34]>` captures the anonymous lifetime defined here | -note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures lifetime smaller than the function body - --> $DIR/static-return-lifetime-infered.rs:6:35 +help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound | -LL | fn iter_values_anon(&self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn iter_values_anon(&self) -> impl Iterator + '_ { + | ++++ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> $DIR/static-return-lifetime-infered.rs:6:35 | LL | fn iter_values_anon(&self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ----- ^^^^^^^^^^^^^^^^^^^^^^^ + | | + | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:9:27: 9:34]>` captures the anonymous lifetime defined here | -note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures lifetime smaller than the function body - --> $DIR/static-return-lifetime-infered.rs:6:35 +help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound | -LL | fn iter_values_anon(&self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn iter_values_anon(&self) -> impl Iterator + '_ { + | ++++ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/static-return-lifetime-infered.rs:6:35 + --> $DIR/static-return-lifetime-infered.rs:11:37 | -LL | fn iter_values_anon(&self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn iter_values<'a>(&'a self) -> impl Iterator { + | -- ^^^^^^^^^^^^^^^^^^^^^^^ + | | + | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:14:27: 14:34]>` captures the lifetime `'a` as defined here | -note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures lifetime smaller than the function body - --> $DIR/static-return-lifetime-infered.rs:6:35 +help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound | -LL | fn iter_values_anon(&self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { + | ++++ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/static-return-lifetime-infered.rs:6:35 + --> $DIR/static-return-lifetime-infered.rs:11:37 | -LL | fn iter_values_anon(&self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn iter_values<'a>(&'a self) -> impl Iterator { + | -- ^^^^^^^^^^^^^^^^^^^^^^^ + | | + | hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:14:27: 14:34]>` captures the lifetime `'a` as defined here | -note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:11:27: 11:34]>` captures lifetime smaller than the function body - --> $DIR/static-return-lifetime-infered.rs:6:35 +help: to declare that the `impl Trait` captures 'a, you can add an explicit `'a` lifetime bound | -LL | fn iter_values_anon(&self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { + | ++++ -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/static-return-lifetime-infered.rs:13:37 - | -LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures lifetime smaller than the function body - --> $DIR/static-return-lifetime-infered.rs:13:37 - | -LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/static-return-lifetime-infered.rs:13:37 - | -LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures lifetime smaller than the function body - --> $DIR/static-return-lifetime-infered.rs:13:37 - | -LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/static-return-lifetime-infered.rs:13:37 - | -LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures lifetime smaller than the function body - --> $DIR/static-return-lifetime-infered.rs:13:37 - | -LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/static-return-lifetime-infered.rs:13:37 - | -LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -note: hidden type `Map, [closure@$DIR/static-return-lifetime-infered.rs:18:27: 18:34]>` captures lifetime smaller than the function body - --> $DIR/static-return-lifetime-infered.rs:13:37 - | -LL | fn iter_values<'a>(&'a self) -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 8 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr deleted file mode 100644 index 953d7cd6a076..000000000000 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:37 - | -LL | async fn f(self: Pin<&Self>) -> impl Clone { self } - | - ^^^^^^^^^^ - | | - | hidden type `Pin<&Foo>` captures the lifetime `'_` as defined here - | -help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound - | -LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } - | ++++ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs index e3483e4e62ab..a1e7f4aa875e 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.rs @@ -7,7 +7,6 @@ struct Foo; impl Foo { async fn f(self: Pin<&Self>) -> impl Clone { self } //~^ ERROR: captures lifetime that does not appear in bounds - //~| ERROR: captures lifetime that does not appear in bounds } fn main() { diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr index aac585ca414c..953d7cd6a076 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr @@ -11,19 +11,6 @@ help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ++++ -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait-async.rs:8:37 - | -LL | async fn f(self: Pin<&Self>) -> impl Clone { self } - | - ^^^^^^^^^^ - | | - | hidden type `Pin<&Foo>` captures the lifetime `'_` as defined here - | -help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound - | -LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } - | ++++ - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr deleted file mode 100644 index faa1233ffde6..000000000000 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:31 - | -LL | fn f(self: Pin<&Self>) -> impl Clone { self } - | ----- ^^^^^^^^^^ - | | - | hidden type `Pin<&Foo>` captures the anonymous lifetime defined here - | -help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound - | -LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self } - | ++++ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr index 7b645f51fe08..faa1233ffde6 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr @@ -2,13 +2,14 @@ error[E0700]: hidden type for `impl Trait` captures lifetime that does not appea --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:31 | LL | fn f(self: Pin<&Self>) -> impl Clone { self } - | ^^^^^^^^^^ + | ----- ^^^^^^^^^^ + | | + | hidden type `Pin<&Foo>` captures the anonymous lifetime defined here | -note: hidden type `Pin<&Foo>` captures lifetime smaller than the function body - --> $DIR/arbitrary_self_types_pin_lifetime_impl_trait.rs:6:31 +help: to declare that the `impl Trait` captures '_, you can add an explicit `'_` lifetime bound | -LL | fn f(self: Pin<&Self>) -> impl Clone { self } - | ^^^^^^^^^^ +LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self } + | ++++ error: aborting due to previous error