-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-technical-debtArea: Internal cleanup workArea: Internal cleanup workC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
Description
At its core we use fudging for the following pattern
fn foo<T>(x: T) -> Box<T> { Box::new(x) }
fn main() {
let _: Box<dyn Fn(&str) -> usize> = foo(|s| s.len());
}We end up with the expectation that foos argument is dyn Fn(&str) -> usize even though that type is not Sized. This is why fudge_inference_if_ok exists and why it's used for function calls when checkig their arguments.
We try to deal with this by weakening the expectation in case it's not sized
rust/compiler/rustc_hir_typeck/src/expectation.rs
Lines 77 to 89 in 7b9905e
| pub(super) fn rvalue_hint(fcx: &FnCtxt<'a, 'tcx>, ty: Ty<'tcx>) -> Expectation<'tcx> { | |
| let span = match ty.kind() { | |
| ty::Adt(adt_def, _) => fcx.tcx.def_span(adt_def.did()), | |
| _ => fcx.tcx.def_span(fcx.body_id), | |
| }; | |
| let cause = ObligationCause::misc(span, fcx.body_id); | |
| // FIXME: This is not right, even in the old solver... | |
| match fcx.tcx.struct_tail_raw(ty, &cause, |ty| ty, || {}).kind() { | |
| ty::Slice(_) | ty::Str | ty::Dynamic(..) => ExpectRvalueLikeUnsized(ty), | |
| _ => ExpectHasType(ty), | |
| } | |
| } |
This is widely insufficient for multiple reasons
mati865
Metadata
Metadata
Assignees
Labels
A-technical-debtArea: Internal cleanup workArea: Internal cleanup workC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.