Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 431dd32

Browse files
committed
Unsized temporary is not an implementation error
1 parent 51e8b8f commit 431dd32

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

crates/hir-ty/src/consteval/tests.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,3 +2066,22 @@ fn type_error() {
20662066
|e| matches!(e, ConstEvalError::MirLowerError(MirLowerError::TypeMismatch(_))),
20672067
);
20682068
}
2069+
2070+
#[test]
2071+
fn unsized_local() {
2072+
check_fail(
2073+
r#"
2074+
//- minicore: coerce_unsized, index, slice
2075+
const fn x() -> SomeUnknownTypeThatDereferenceToSlice {
2076+
SomeUnknownTypeThatDereferenceToSlice
2077+
}
2078+
2079+
const GOAL: u16 = {
2080+
let y = x();
2081+
let z: &[u16] = &y;
2082+
z[1]
2083+
};
2084+
"#,
2085+
|e| matches!(e, ConstEvalError::MirLowerError(MirLowerError::UnsizedTemporary(_))),
2086+
);
2087+
}

crates/hir-ty/src/mir/lower.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub enum MirLowerError {
7575
RecordLiteralWithoutPath,
7676
UnresolvedMethod(String),
7777
UnresolvedField,
78+
UnsizedTemporary(Ty),
7879
MissingFunctionDefinition,
7980
TypeMismatch(TypeMismatch),
8081
/// This should be never happen. Type mismatch should catch everything.
@@ -108,6 +109,7 @@ impl MirLowerError {
108109
}
109110
}
110111
MirLowerError::LayoutError(_)
112+
| MirLowerError::UnsizedTemporary(_)
111113
| MirLowerError::IncompleteExpr
112114
| MirLowerError::UnaccessableLocal
113115
| MirLowerError::TraitFunctionDefinition(_, _)
@@ -199,7 +201,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
199201

200202
fn temp(&mut self, ty: Ty) -> Result<LocalId> {
201203
if matches!(ty.kind(Interner), TyKind::Slice(_) | TyKind::Dyn(_)) {
202-
implementation_error!("unsized temporaries");
204+
return Err(MirLowerError::UnsizedTemporary(ty));
203205
}
204206
Ok(self.result.locals.alloc(Local { ty }))
205207
}

0 commit comments

Comments
 (0)