diff --git a/src/librustc/ty/outlives.rs b/src/librustc/ty/outlives.rs index 5b21ed5abd77b..053bf2f24e058 100644 --- a/src/librustc/ty/outlives.rs +++ b/src/librustc/ty/outlives.rs @@ -65,6 +65,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { for upvar_ty in substs.upvar_tys(def_id, *self) { self.compute_components(upvar_ty, out); } + self.compute_components(substs.closure_sig_ty(def_id, *self), out); } ty::Generator(def_id, ref substs, _) => { @@ -73,6 +74,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.compute_components(upvar_ty, out); } + self.compute_components(substs.return_ty(def_id, *self), out); + self.compute_components(substs.yield_ty(def_id, *self), out); // We ignore regions in the generator interior as we don't // want these to affect region inference } diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 0e3d05d29a3da..67b6a789d59ea 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -135,7 +135,7 @@ impl<'a, 'tcx: 'a, T: Decodable> Lazy { } } -impl<'a, 'tcx: 'a, T: Decodable> LazySeq { +impl<'a, 'tcx: 'a, T: Decodable + 'a> LazySeq { pub fn decode>( self, meta: M, diff --git a/src/test/incremental/hashes/closure_expressions.rs b/src/test/incremental/hashes/closure_expressions.rs index 5bfd540eca63e..5165f9821fd88 100644 --- a/src/test/incremental/hashes/closure_expressions.rs +++ b/src/test/incremental/hashes/closure_expressions.rs @@ -49,14 +49,14 @@ pub fn add_parameter() { // Change parameter pattern ---------------------------------------------------- #[cfg(cfail1)] pub fn change_parameter_pattern() { - let _ = |x: &u32| x; + let _ = |x: (u32,)| x; } #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", except="HirBody, mir_built, typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_parameter_pattern() { - let _ = |&x: &u32| x; + let _ = |(x,): (u32,)| x; } diff --git a/src/test/run-pass/regions/regions-relate-bound-regions-on-closures-to-inference-variables.rs b/src/test/run-pass/regions/regions-relate-bound-regions-on-closures-to-inference-variables.rs index f26ef85ef7234..1c3deed58b44e 100644 --- a/src/test/run-pass/regions/regions-relate-bound-regions-on-closures-to-inference-variables.rs +++ b/src/test/run-pass/regions/regions-relate-bound-regions-on-closures-to-inference-variables.rs @@ -44,7 +44,7 @@ impl<'a,'tcx> Foo<'a,'tcx> { fn elaborate_bounds( &mut self, - mut mk_cand: Box FnMut(&mut Foo<'b, 'tcx>) -> isize>) + mut mk_cand: Box FnMut(&mut Foo<'b, 'tcx>) -> isize + 'tcx>) -> isize { mk_cand(self) diff --git a/src/test/ui/impl-trait/issue-55608-captures-empty-region.rs b/src/test/ui/impl-trait/issue-55608-captures-empty-region.rs index 7ebc348996f5e..50646edd61a85 100644 --- a/src/test/ui/impl-trait/issue-55608-captures-empty-region.rs +++ b/src/test/ui/impl-trait/issue-55608-captures-empty-region.rs @@ -1,9 +1,9 @@ // This used to ICE because it creates an `impl Trait` that captures a // hidden empty region. -#![feature(conservative_impl_trait)] +// compile-pass -fn server() -> impl FilterBase2 { //~ ERROR [E0700] +fn server() -> impl FilterBase2 { segment2(|| { loop { } }).map2(|| "") } diff --git a/src/test/ui/impl-trait/issue-55608-captures-empty-region.stderr b/src/test/ui/impl-trait/issue-55608-captures-empty-region.stderr deleted file mode 100644 index 6311a7f00674f..0000000000000 --- a/src/test/ui/impl-trait/issue-55608-captures-empty-region.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/issue-55608-captures-empty-region.rs:6:16 - | -LL | fn server() -> impl FilterBase2 { - | ^^^^^^^^^^^^^^^^ - | - = note: hidden type `Map2<[closure@$DIR/issue-55608-captures-empty-region.rs:7:36: 7:41]>` captures an empty lifetime - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0700`. diff --git a/src/test/ui/issues/issue-40510-1.rs b/src/test/ui/issues/issue-40510-1.rs index dd8a6bc5ab2bd..af106e84b6455 100644 --- a/src/test/ui/issues/issue-40510-1.rs +++ b/src/test/ui/issues/issue-40510-1.rs @@ -1,11 +1,10 @@ -// compile-pass #![allow(unused)] fn f() { let mut x: Box<()> = Box::new(()); || { - &mut x + &mut x //~ ERROR cannot infer }; } diff --git a/src/test/ui/issues/issue-40510-1.stderr b/src/test/ui/issues/issue-40510-1.stderr index 44234cbc8816e..2a701e58dc625 100644 --- a/src/test/ui/issues/issue-40510-1.stderr +++ b/src/test/ui/issues/issue-40510-1.stderr @@ -1,13 +1,33 @@ -warning: captured variable cannot escape `FnMut` closure body - --> $DIR/issue-40510-1.rs:8:9 +error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements + --> $DIR/issue-40510-1.rs:7:9 + | +LL | &mut x + | ^^^^^^ + | +note: first, the lifetime cannot outlive the lifetime '_ as defined on the body at 6:5... + --> $DIR/issue-40510-1.rs:6:5 | LL | || { - | - inferred to be a `FnMut` closure + | ^^ +note: ...so that closure can access `x` + --> $DIR/issue-40510-1.rs:7:9 + | LL | &mut x - | ^^^^^^ returns a reference to a captured variable which escapes the closure body + | ^^^^^^ +note: but, the lifetime must be valid for the expression at 6:5... + --> $DIR/issue-40510-1.rs:6:5 + | +LL | / || { +LL | | &mut x +LL | | }; + | |_____^ +note: ...so type `[closure@$DIR/issue-40510-1.rs:6:5: 8:6 x:&mut std::boxed::Box<()>]` of expression is valid during the expression + --> $DIR/issue-40510-1.rs:6:5 | - = note: `FnMut` closures only have access to their captured variables while they are executing... - = note: ...therefore, they cannot allow references to captured variables to escape - = warning: this error has been downgraded to a warning for backwards compatibility with previous releases - = warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future +LL | / || { +LL | | &mut x +LL | | }; + | |_____^ + +error: aborting due to previous error diff --git a/src/test/ui/issues/issue-40510-3.rs b/src/test/ui/issues/issue-40510-3.rs index bc95c461d1e1e..7f634c31ea305 100644 --- a/src/test/ui/issues/issue-40510-3.rs +++ b/src/test/ui/issues/issue-40510-3.rs @@ -1,11 +1,10 @@ -// compile-pass #![allow(unused)] fn f() { let mut x: Vec<()> = Vec::new(); || { - || { + || { //~ ERROR captured variable cannot escape `FnMut` closure body x.push(()) } }; diff --git a/src/test/ui/issues/issue-40510-3.stderr b/src/test/ui/issues/issue-40510-3.stderr index 1297e1418981f..4bc7d0f5deac5 100644 --- a/src/test/ui/issues/issue-40510-3.stderr +++ b/src/test/ui/issues/issue-40510-3.stderr @@ -1,5 +1,5 @@ -warning: captured variable cannot escape `FnMut` closure body - --> $DIR/issue-40510-3.rs:8:9 +error: captured variable cannot escape `FnMut` closure body + --> $DIR/issue-40510-3.rs:7:9 | LL | || { | - inferred to be a `FnMut` closure @@ -10,6 +10,6 @@ LL | | } | = note: `FnMut` closures only have access to their captured variables while they are executing... = note: ...therefore, they cannot allow references to captured variables to escape - = warning: this error has been downgraded to a warning for backwards compatibility with previous releases - = warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future + +error: aborting due to previous error diff --git a/src/test/ui/issues/issue-49556.rs b/src/test/ui/issues/issue-49556.rs index b8fcc645a59d3..46d9e749aae23 100644 --- a/src/test/ui/issues/issue-49556.rs +++ b/src/test/ui/issues/issue-49556.rs @@ -2,10 +2,10 @@ fn iter<'a>(data: &'a [usize]) -> impl Iterator + 'a { data.iter() .map( - |x| x // fn(&'a usize) -> &'(ReScope) usize + |x| x // fn(&'a usize) -> &'a usize ) .map( - |x| *x // fn(&'(ReScope) usize) -> usize + |x| *x // fn(&'a usize) -> usize ) } diff --git a/src/test/ui/issues/issue-49824.rs b/src/test/ui/issues/issue-49824.rs index b0d01b3d98d51..a417b7ab91abc 100644 --- a/src/test/ui/issues/issue-49824.rs +++ b/src/test/ui/issues/issue-49824.rs @@ -1,16 +1,10 @@ -#![feature(rustc_attrs)] - // This test checks that a warning occurs with migrate mode. -#[rustc_error] fn main() { - //~^ ERROR compilation successful let mut x = 0; || { || { - //~^ WARNING captured variable cannot escape `FnMut` closure body - //~| WARNING this error has been downgraded to a warning - //~| WARNING this warning will become a hard error in the future + //~^ ERROR captured variable cannot escape `FnMut` closure body let _y = &mut x; } }; diff --git a/src/test/ui/issues/issue-49824.stderr b/src/test/ui/issues/issue-49824.stderr index c66ee69cb2bdb..9072125842797 100644 --- a/src/test/ui/issues/issue-49824.stderr +++ b/src/test/ui/issues/issue-49824.stderr @@ -1,32 +1,16 @@ -warning: captured variable cannot escape `FnMut` closure body - --> $DIR/issue-49824.rs:10:9 +error: captured variable cannot escape `FnMut` closure body + --> $DIR/issue-49824.rs:6:9 | LL | || { | - inferred to be a `FnMut` closure LL | / || { LL | | -LL | | -LL | | LL | | let _y = &mut x; LL | | } | |_________^ returns a closure that contains a reference to a captured variable, which then escapes the closure body | = note: `FnMut` closures only have access to their captured variables while they are executing... = note: ...therefore, they cannot allow references to captured variables to escape - = warning: this error has been downgraded to a warning for backwards compatibility with previous releases - = warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future - -error: compilation successful - --> $DIR/issue-49824.rs:6:1 - | -LL | / fn main() { -LL | | -LL | | let mut x = 0; -LL | | || { -... | -LL | | }; -LL | | } - | |_^ error: aborting due to previous error diff --git a/src/test/ui/regions/regions-escape-via-trait-or-not.stderr b/src/test/ui/regions/regions-escape-via-trait-or-not.stderr index c8a02683d1000..bfc5a05420d6b 100644 --- a/src/test/ui/regions/regions-escape-via-trait-or-not.stderr +++ b/src/test/ui/regions/regions-escape-via-trait-or-not.stderr @@ -12,16 +12,16 @@ LL | with(|o| o) = note: ...so that the expression is assignable: expected &isize found &isize -note: but, the lifetime must be valid for the expression at 18:5... +note: but, the lifetime must be valid for the call at 18:5... --> $DIR/regions-escape-via-trait-or-not.rs:18:5 | LL | with(|o| o) - | ^^^^ -note: ...so type `fn([closure@$DIR/regions-escape-via-trait-or-not.rs:18:10: 18:15]) -> isize {with::<&isize, [closure@$DIR/regions-escape-via-trait-or-not.rs:18:10: 18:15]>}` of expression is valid during the expression - --> $DIR/regions-escape-via-trait-or-not.rs:18:5 + | ^^^^^^^^^^^ +note: ...so that argument is valid for the call + --> $DIR/regions-escape-via-trait-or-not.rs:18:10 | LL | with(|o| o) - | ^^^^ + | ^^^^^ error: aborting due to previous error diff --git a/src/test/ui/regions/regions-return-ref-to-upvar-issue-17403.rs b/src/test/ui/regions/regions-return-ref-to-upvar-issue-17403.rs index afe87f47eadbe..0b1d97c4b4f53 100644 --- a/src/test/ui/regions/regions-return-ref-to-upvar-issue-17403.rs +++ b/src/test/ui/regions/regions-return-ref-to-upvar-issue-17403.rs @@ -4,7 +4,7 @@ fn main() { // Unboxed closure case { let mut x = 0; - let mut f = || &mut x; //~ ERROR cannot infer + let mut f = || &mut x; //~ ERROR borrowed data cannot be stored outside of its closure let x = f(); let y = f(); } diff --git a/src/test/ui/regions/regions-return-ref-to-upvar-issue-17403.stderr b/src/test/ui/regions/regions-return-ref-to-upvar-issue-17403.stderr index 291b8367f7b75..57b7c869e9009 100644 --- a/src/test/ui/regions/regions-return-ref-to-upvar-issue-17403.stderr +++ b/src/test/ui/regions/regions-return-ref-to-upvar-issue-17403.stderr @@ -1,29 +1,11 @@ -error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements +error: borrowed data cannot be stored outside of its closure --> $DIR/regions-return-ref-to-upvar-issue-17403.rs:7:24 | LL | let mut f = || &mut x; - | ^^^^^^ - | -note: first, the lifetime cannot outlive the lifetime '_ as defined on the body at 7:21... - --> $DIR/regions-return-ref-to-upvar-issue-17403.rs:7:21 - | -LL | let mut f = || &mut x; - | ^^^^^^^^^ -note: ...so that closure can access `x` - --> $DIR/regions-return-ref-to-upvar-issue-17403.rs:7:24 - | -LL | let mut f = || &mut x; - | ^^^^^^ -note: but, the lifetime must be valid for the call at 9:17... - --> $DIR/regions-return-ref-to-upvar-issue-17403.rs:9:17 - | -LL | let y = f(); - | ^^^ -note: ...so type `&mut i32` of expression is valid during the expression - --> $DIR/regions-return-ref-to-upvar-issue-17403.rs:9:17 - | -LL | let y = f(); - | ^^^ + | ----- -- ^^^^^^ cannot be stored outside of its closure + | | | + | | ...because it cannot outlive this closure + | borrowed data cannot be stored into here... error: aborting due to previous error