Rollup merge of #136205 - compiler-errors:len-3, r=BoxyUwU
Properly check that array length is valid type during built-in unsizing in index This results in duplicated errors, but this class of errors is not new; in general, we aren't really equipped to detect cases where a WF error due to a field type would be shadowed by the parent struct of that field also not being WF. This also adds a note for these types of mismatches to make it clear that this is due to an array type. Fixes #134352 r? boxyuwu
This commit is contained in:
commit
e8289d801c
13 changed files with 63 additions and 9 deletions
|
@ -2769,6 +2769,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
ObligationCauseCode::SliceOrArrayElem => {
|
||||
err.note("slice and array elements must have `Sized` type");
|
||||
}
|
||||
ObligationCauseCode::ArrayLen(array_ty) => {
|
||||
err.note(format!("the length of array `{array_ty}` must be type `usize`"));
|
||||
}
|
||||
ObligationCauseCode::TupleElem => {
|
||||
err.note("only the last element of a tuple may have a dynamically sized type");
|
||||
}
|
||||
|
|
|
@ -689,7 +689,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
|
|||
self.require_sized(subty, ObligationCauseCode::SliceOrArrayElem);
|
||||
// Note that the len being WF is implicitly checked while visiting.
|
||||
// Here we just check that it's of type usize.
|
||||
let cause = self.cause(ObligationCauseCode::Misc);
|
||||
let cause = self.cause(ObligationCauseCode::ArrayLen(t));
|
||||
self.out.push(traits::Obligation::with_depth(
|
||||
tcx,
|
||||
cause,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue