Auto merge of #139000 - compiler-errors:rigid-missing-item, r=lcnr
Rigidly project missing item due to guaranteed impossible sized predicate This is a somewhat involved change, but it amounts to treating missing impl items due to guaranteed impossible where clauses (dyn/str/slice sized, cc #135480) as *rigid projections* rather than projecting to an error term, since that was preventing either reporting a proper error (in an empty param env) *or* successfully type checking the code (in the presence of trivially false where clauses). Fixes https://github.com/rust-lang/rust/issues/138970 r? `@lcnr` `@oli-obk`
This commit is contained in:
commit
9d28fe3976
19 changed files with 524 additions and 91 deletions
|
@ -134,7 +134,7 @@ where
|
|||
// Add GAT where clauses from the trait's definition
|
||||
// FIXME: We don't need these, since these are the type's own WF obligations.
|
||||
ecx.add_goals(
|
||||
GoalSource::Misc,
|
||||
GoalSource::AliasWellFormed,
|
||||
cx.own_predicates_of(goal.predicate.def_id())
|
||||
.iter_instantiated(cx, goal.predicate.alias.args)
|
||||
.map(|pred| goal.with(cx, pred)),
|
||||
|
@ -199,7 +199,7 @@ where
|
|||
// Add GAT where clauses from the trait's definition.
|
||||
// FIXME: We don't need these, since these are the type's own WF obligations.
|
||||
ecx.add_goals(
|
||||
GoalSource::Misc,
|
||||
GoalSource::AliasWellFormed,
|
||||
cx.own_predicates_of(goal.predicate.def_id())
|
||||
.iter_instantiated(cx, goal.predicate.alias.args)
|
||||
.map(|pred| goal.with(cx, pred)),
|
||||
|
@ -232,7 +232,33 @@ where
|
|||
};
|
||||
|
||||
if !cx.has_item_definition(target_item_def_id) {
|
||||
return error_response(ecx, cx.delay_bug("missing item"));
|
||||
// If the impl is missing an item, it's either because the user forgot to
|
||||
// provide it, or the user is not *obligated* to provide it (because it
|
||||
// has a trivially false `Sized` predicate). If it's the latter, we cannot
|
||||
// delay a bug because we can have trivially false where clauses, so we
|
||||
// treat it as rigid.
|
||||
if cx.impl_self_is_guaranteed_unsized(impl_def_id) {
|
||||
match ecx.typing_mode() {
|
||||
ty::TypingMode::Coherence => {
|
||||
return ecx.evaluate_added_goals_and_make_canonical_response(
|
||||
Certainty::AMBIGUOUS,
|
||||
);
|
||||
}
|
||||
ty::TypingMode::Analysis { .. }
|
||||
| ty::TypingMode::Borrowck { .. }
|
||||
| ty::TypingMode::PostBorrowckAnalysis { .. }
|
||||
| ty::TypingMode::PostAnalysis => {
|
||||
ecx.structurally_instantiate_normalizes_to_term(
|
||||
goal,
|
||||
goal.predicate.alias,
|
||||
);
|
||||
return ecx
|
||||
.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return error_response(ecx, cx.delay_bug("missing item"));
|
||||
}
|
||||
}
|
||||
|
||||
let target_container_def_id = cx.parent(target_item_def_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue