This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree 2 files changed +22
-1
lines changed 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -2066,3 +2066,22 @@ fn type_error() {
2066
2066
|e| matches ! ( e, ConstEvalError :: MirLowerError ( MirLowerError :: TypeMismatch ( _) ) ) ,
2067
2067
) ;
2068
2068
}
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
+ }
Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ pub enum MirLowerError {
75
75
RecordLiteralWithoutPath ,
76
76
UnresolvedMethod ( String ) ,
77
77
UnresolvedField ,
78
+ UnsizedTemporary ( Ty ) ,
78
79
MissingFunctionDefinition ,
79
80
TypeMismatch ( TypeMismatch ) ,
80
81
/// This should be never happen. Type mismatch should catch everything.
@@ -108,6 +109,7 @@ impl MirLowerError {
108
109
}
109
110
}
110
111
MirLowerError :: LayoutError ( _)
112
+ | MirLowerError :: UnsizedTemporary ( _)
111
113
| MirLowerError :: IncompleteExpr
112
114
| MirLowerError :: UnaccessableLocal
113
115
| MirLowerError :: TraitFunctionDefinition ( _, _)
@@ -199,7 +201,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
199
201
200
202
fn temp ( & mut self , ty : Ty ) -> Result < LocalId > {
201
203
if matches ! ( ty. kind( Interner ) , TyKind :: Slice ( _) | TyKind :: Dyn ( _) ) {
202
- implementation_error ! ( "unsized temporaries" ) ;
204
+ return Err ( MirLowerError :: UnsizedTemporary ( ty ) ) ;
203
205
}
204
206
Ok ( self . result . locals . alloc ( Local { ty } ) )
205
207
}
You can’t perform that action at this time.
0 commit comments