@@ -147,13 +147,13 @@ for
147147 // Handle trait object vtables
148148 if let Ok ( meta) = value. to_meta ( ) {
149149 if let ty:: Dynamic ( ..) = self . ecx . tcx . struct_tail ( referenced_ty) . sty {
150- if let Ok ( vtable) = meta. unwrap ( ) . to_ptr ( ) {
151- // explitly choose `Immutable` here, since vtables are immutable, even
152- // if the reference of the fat pointer is mutable
153- self . intern_shallow ( vtable, Mutability :: Immutable ) ?;
154- }
150+ if let Ok ( vtable) = meta. unwrap ( ) . to_ptr ( ) {
151+ // explitly choose `Immutable` here, since vtables are immutable, even
152+ // if the reference of the fat pointer is mutable
153+ self . intern_shallow ( vtable, Mutability :: Immutable ) ?;
155154 }
156155 }
156+ }
157157 let mplace = self . ecx . ref_to_mplace ( value) ?;
158158 // Check if we have encountered this pointer+layout combination before.
159159 // Only recurse for allocation-backed pointers.
174174 ( InternMode :: Static , hir:: Mutability :: MutMutable ) => { } ,
175175 // we statically prevent `&mut T` via `const_qualif` and double check this here
176176 ( InternMode :: ConstBase , hir:: Mutability :: MutMutable ) |
177- ( InternMode :: Const , hir:: Mutability :: MutMutable ) =>
178- bug ! ( "const qualif failed to prevent mutable references" ) ,
177+ ( InternMode :: Const , hir:: Mutability :: MutMutable ) => {
178+ match referenced_ty. sty {
179+ ty:: Array ( _, n) if n. unwrap_usize ( self . ecx . tcx . tcx ) == 0 => { }
180+ ty:: Slice ( _)
181+ if value. to_meta ( ) . unwrap ( ) . unwrap ( ) . to_usize ( self . ecx ) ? == 0 => { }
182+ _ => bug ! ( "const qualif failed to prevent mutable references" ) ,
183+ }
184+ } ,
179185 }
180186 // Compute the mutability with which we'll start visiting the allocation. This is
181187 // what gets changed when we encounter an `UnsafeCell`
0 commit comments