diff options
| author | bors <bors@rust-lang.org> | 2018-12-04 20:56:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-12-04 20:56:11 +0000 |
| commit | b3af09205b9af6026453946feadfd78b61b7a9fc (patch) | |
| tree | 738aa1f6faba7cba1f31a244071919578ac38f24 | |
| parent | 906deae0790bd18681b937fe9a141a3c26cf1855 (diff) | |
| parent | b2e6da7a7f8e3a82a48b0e3d6cb7912d2e31e758 (diff) | |
| download | rust-b3af09205b9af6026453946feadfd78b61b7a9fc.tar.gz rust-b3af09205b9af6026453946feadfd78b61b7a9fc.zip | |
Auto merge of #56486 - matthewjasper:propagate-all-closure-bounds, r=pnkfelix
Propagate all closure requirements to the caller Closes #56477 This should be backported to 1.32 if it doesn't make the cut. r? @pnkfelix cc @nikomatsakis
4 files changed, 46 insertions, 4 deletions
diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index 6a1dc50c67a..fbde699264b 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -1208,7 +1208,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { blame_span: blame_span_category.1, category: blame_span_category.0, }); - return; + continue; } } diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index b5addbd18d2..e5fe74f2305 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -355,13 +355,13 @@ fn check_item_type<'a, 'tcx>( ) { debug!("check_item_type: {:?}", item_id); - for_id(tcx, item_id, ty_span).with_fcx(|fcx, _this| { - let ty = fcx.tcx.type_of(fcx.tcx.hir.local_def_id(item_id)); + for_id(tcx, item_id, ty_span).with_fcx(|fcx, gcx| { + let ty = gcx.type_of(gcx.hir.local_def_id(item_id)); let item_ty = fcx.normalize_associated_types_in(ty_span, &ty); let mut forbid_unsized = true; if allow_foreign_ty { - if let TyKind::Foreign(_) = tcx.struct_tail(item_ty).sty { + if let TyKind::Foreign(_) = fcx.tcx.struct_tail(item_ty).sty { forbid_unsized = false; } } diff --git a/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.rs b/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.rs new file mode 100644 index 00000000000..dbc659b4aee --- /dev/null +++ b/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.rs @@ -0,0 +1,25 @@ +// Test that we propagate *all* requirements to the caller, not just the first +// one. + +#![feature(nll)] + +fn once<S, T, U, F: FnOnce(S, T) -> U>(f: F, s: S, t: T) -> U { + f(s, t) +} + +pub fn dangle() -> &'static [i32] { + let other_local_arr = [0, 2, 4]; + let local_arr = other_local_arr; + let mut out: &mut &'static [i32] = &mut (&[1] as _); + once(|mut z: &[i32], mut out_val: &mut &[i32]| { + // We unfortunately point to the first use in the closure in the error + // message + z = &local_arr; //~ ERROR + *out_val = &local_arr; + }, &[] as &[_], &mut *out); + *out +} + +fn main() { + println!("{:?}", dangle()); +} diff --git a/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.stderr b/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.stderr new file mode 100644 index 00000000000..2ad4577869a --- /dev/null +++ b/src/test/ui/nll/closure-requirements/propagate-multiple-requirements.stderr @@ -0,0 +1,17 @@ +error[E0597]: `local_arr` does not live long enough + --> $DIR/propagate-multiple-requirements.rs:17:14 + | +LL | let mut out: &mut &'static [i32] = &mut (&[1] as _); + | ------------------- type annotation requires that `local_arr` is borrowed for `'static` +LL | once(|mut z: &[i32], mut out_val: &mut &[i32]| { + | ----------------------------------------- value captured here +... +LL | z = &local_arr; //~ ERROR + | ^^^^^^^^^ borrowed value does not live long enough +... +LL | } + | - `local_arr` dropped here while still borrowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. |
