diff options
| author | bors <bors@rust-lang.org> | 2018-12-06 17:31:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-12-06 17:31:15 +0000 |
| commit | cd48ce1e9a9c0965f01ede2ea1a554eca2c74336 (patch) | |
| tree | 8acb9c494c96f9349ac5f44f7f6bf0a16433b2eb /src | |
| parent | 4bb5d35659b6d8579007f49db09aa1d35782b834 (diff) | |
| parent | 8cab350c85b9738e4dbc99c67e71bd4a5b6f62a7 (diff) | |
| download | rust-cd48ce1e9a9c0965f01ede2ea1a554eca2c74336.tar.gz rust-cd48ce1e9a9c0965f01ede2ea1a554eca2c74336.zip | |
Auto merge of #56282 - qnighy:additional-sizedness-fix, r=nikomatsakis
Fix #56237: normalize type before deferred sizedness checking. This seems to fix #56237, which was introduced by #56045. I don't thoroughly understand how this works, but the problem seemed to be a lack of normalization. r? @cramertj
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 17 | ||||
| -rw-r--r-- | src/test/run-pass/issue-56237.rs | 11 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e30a79b25de..a107cec9ef4 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -914,6 +914,7 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fcx.resolve_generator_interiors(def_id); for (ty, span, code) in fcx.deferred_sized_obligations.borrow_mut().drain(..) { + let ty = fcx.normalize_ty(span, ty); fcx.require_type_is_sized(ty, span, code); } fcx.select_all_obligations_or_error(); @@ -3969,7 +3970,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // // to work in stable even if the Sized bound on `drop` is relaxed. for i in 0..fn_sig.inputs().skip_binder().len() { - let input = tcx.erase_late_bound_regions(&fn_sig.input(i)); + // We just want to check sizedness, so instead of introducing + // placeholder lifetimes with probing, we just replace higher lifetimes + // with fresh vars. + let input = self.replace_bound_vars_with_fresh_vars( + expr.span, + infer::LateBoundRegionConversionTime::FnCall, + &fn_sig.input(i)).0; self.require_type_is_sized_deferred(input, expr.span, traits::SizedArgumentType); } @@ -3977,7 +3984,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Here we want to prevent struct constructors from returning unsized types. // There were two cases this happened: fn pointer coercion in stable // and usual function call in presense of unsized_locals. - let output = tcx.erase_late_bound_regions(&fn_sig.output()); + // Also, as we just want to check sizedness, instead of introducing + // placeholder lifetimes with probing, we just replace higher lifetimes + // with fresh vars. + let output = self.replace_bound_vars_with_fresh_vars( + expr.span, + infer::LateBoundRegionConversionTime::FnCall, + &fn_sig.output()).0; self.require_type_is_sized_deferred(output, expr.span, traits::SizedReturnType); } diff --git a/src/test/run-pass/issue-56237.rs b/src/test/run-pass/issue-56237.rs new file mode 100644 index 00000000000..87e10e83612 --- /dev/null +++ b/src/test/run-pass/issue-56237.rs @@ -0,0 +1,11 @@ +use std::ops::Deref; + +fn foo<P>(_value: <P as Deref>::Target) +where + P: Deref, + <P as Deref>::Target: Sized, +{} + +fn main() { + foo::<Box<u32>>(2); +} |
