Unsized temporary is not an implementation error
This commit is contained in:
parent
51e8b8ff14
commit
431dd32f8a
@ -2066,3 +2066,22 @@ fn type_error() {
|
|||||||
|e| matches!(e, ConstEvalError::MirLowerError(MirLowerError::TypeMismatch(_))),
|
|e| matches!(e, ConstEvalError::MirLowerError(MirLowerError::TypeMismatch(_))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unsized_local() {
|
||||||
|
check_fail(
|
||||||
|
r#"
|
||||||
|
//- minicore: coerce_unsized, index, slice
|
||||||
|
const fn x() -> SomeUnknownTypeThatDereferenceToSlice {
|
||||||
|
SomeUnknownTypeThatDereferenceToSlice
|
||||||
|
}
|
||||||
|
|
||||||
|
const GOAL: u16 = {
|
||||||
|
let y = x();
|
||||||
|
let z: &[u16] = &y;
|
||||||
|
z[1]
|
||||||
|
};
|
||||||
|
"#,
|
||||||
|
|e| matches!(e, ConstEvalError::MirLowerError(MirLowerError::UnsizedTemporary(_))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -75,6 +75,7 @@ pub enum MirLowerError {
|
|||||||
RecordLiteralWithoutPath,
|
RecordLiteralWithoutPath,
|
||||||
UnresolvedMethod(String),
|
UnresolvedMethod(String),
|
||||||
UnresolvedField,
|
UnresolvedField,
|
||||||
|
UnsizedTemporary(Ty),
|
||||||
MissingFunctionDefinition,
|
MissingFunctionDefinition,
|
||||||
TypeMismatch(TypeMismatch),
|
TypeMismatch(TypeMismatch),
|
||||||
/// This should be never happen. Type mismatch should catch everything.
|
/// This should be never happen. Type mismatch should catch everything.
|
||||||
@ -108,6 +109,7 @@ pub fn pretty_print(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
MirLowerError::LayoutError(_)
|
MirLowerError::LayoutError(_)
|
||||||
|
| MirLowerError::UnsizedTemporary(_)
|
||||||
| MirLowerError::IncompleteExpr
|
| MirLowerError::IncompleteExpr
|
||||||
| MirLowerError::UnaccessableLocal
|
| MirLowerError::UnaccessableLocal
|
||||||
| MirLowerError::TraitFunctionDefinition(_, _)
|
| MirLowerError::TraitFunctionDefinition(_, _)
|
||||||
@ -199,7 +201,7 @@ fn new(
|
|||||||
|
|
||||||
fn temp(&mut self, ty: Ty) -> Result<LocalId> {
|
fn temp(&mut self, ty: Ty) -> Result<LocalId> {
|
||||||
if matches!(ty.kind(Interner), TyKind::Slice(_) | TyKind::Dyn(_)) {
|
if matches!(ty.kind(Interner), TyKind::Slice(_) | TyKind::Dyn(_)) {
|
||||||
implementation_error!("unsized temporaries");
|
return Err(MirLowerError::UnsizedTemporary(ty));
|
||||||
}
|
}
|
||||||
Ok(self.result.locals.alloc(Local { ty }))
|
Ok(self.result.locals.alloc(Local { ty }))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user