Skip to content

Commit cd48ce1

Browse files
committed
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
2 parents 4bb5d35 + 8cab350 commit cd48ce1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/librustc_typeck/check/mod.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
914914
fcx.resolve_generator_interiors(def_id);
915915

916916
for (ty, span, code) in fcx.deferred_sized_obligations.borrow_mut().drain(..) {
917+
let ty = fcx.normalize_ty(span, ty);
917918
fcx.require_type_is_sized(ty, span, code);
918919
}
919920
fcx.select_all_obligations_or_error();
@@ -3969,15 +3970,27 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
39693970
//
39703971
// to work in stable even if the Sized bound on `drop` is relaxed.
39713972
for i in 0..fn_sig.inputs().skip_binder().len() {
3972-
let input = tcx.erase_late_bound_regions(&fn_sig.input(i));
3973+
// We just want to check sizedness, so instead of introducing
3974+
// placeholder lifetimes with probing, we just replace higher lifetimes
3975+
// with fresh vars.
3976+
let input = self.replace_bound_vars_with_fresh_vars(
3977+
expr.span,
3978+
infer::LateBoundRegionConversionTime::FnCall,
3979+
&fn_sig.input(i)).0;
39733980
self.require_type_is_sized_deferred(input, expr.span,
39743981
traits::SizedArgumentType);
39753982
}
39763983
}
39773984
// Here we want to prevent struct constructors from returning unsized types.
39783985
// There were two cases this happened: fn pointer coercion in stable
39793986
// and usual function call in presense of unsized_locals.
3980-
let output = tcx.erase_late_bound_regions(&fn_sig.output());
3987+
// Also, as we just want to check sizedness, instead of introducing
3988+
// placeholder lifetimes with probing, we just replace higher lifetimes
3989+
// with fresh vars.
3990+
let output = self.replace_bound_vars_with_fresh_vars(
3991+
expr.span,
3992+
infer::LateBoundRegionConversionTime::FnCall,
3993+
&fn_sig.output()).0;
39813994
self.require_type_is_sized_deferred(output, expr.span, traits::SizedReturnType);
39823995
}
39833996

src/test/run-pass/issue-56237.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use std::ops::Deref;
2+
3+
fn foo<P>(_value: <P as Deref>::Target)
4+
where
5+
P: Deref,
6+
<P as Deref>::Target: Sized,
7+
{}
8+
9+
fn main() {
10+
foo::<Box<u32>>(2);
11+
}

0 commit comments

Comments
 (0)