@@ -132,17 +132,10 @@ pub enum InternKind {
132132 Promoted ,
133133}
134134
135- #[ derive( Default , Debug ) ]
136- pub struct InternResult {
137- pub found_bad_mutable_pointer : bool ,
138- pub found_dangling_pointer : bool ,
139- }
140-
141- impl InternResult {
142- fn has_errors ( & self ) -> bool {
143- let Self { found_bad_mutable_pointer, found_dangling_pointer } = * self ;
144- found_bad_mutable_pointer || found_dangling_pointer
145- }
135+ #[ derive( Debug ) ]
136+ pub enum InternResult {
137+ FoundBadMutablePointer ,
138+ FoundDanglingPointer ,
146139}
147140
148141/// Intern `ret` and everything it references.
@@ -212,7 +205,7 @@ pub fn intern_const_alloc_recursive<
212205 // Whether we encountered a bad mutable pointer.
213206 // We want to first report "dangling" and then "mutable", so we need to delay reporting these
214207 // errors.
215- let mut result = InternResult :: default ( ) ;
208+ let mut result = Ok ( ( ) ) ;
216209
217210 // Keep interning as long as there are things to intern.
218211 // We show errors if there are dangling pointers, or mutable pointers in immutable contexts
@@ -262,7 +255,10 @@ pub fn intern_const_alloc_recursive<
262255 // on the promotion analysis not screwing up to ensure that it is sound to intern
263256 // promoteds as immutable.
264257 trace ! ( "found bad mutable pointer" ) ;
265- result. found_bad_mutable_pointer = true ;
258+ // Prefer dangling pointer errors over mutable pointer errors
259+ if result. is_ok ( ) {
260+ result = Err ( InternResult :: FoundBadMutablePointer ) ;
261+ }
266262 }
267263 if ecx. tcx . try_get_global_alloc ( alloc_id) . is_some ( ) {
268264 // Already interned.
@@ -284,11 +280,11 @@ pub fn intern_const_alloc_recursive<
284280 Ok ( nested) => todo. extend ( nested) ,
285281 Err ( ( ) ) => {
286282 ecx. tcx . dcx ( ) . delayed_bug ( "found dangling pointer during const interning" ) ;
287- result. found_dangling_pointer = true
283+ result = Err ( InternResult :: FoundDanglingPointer ) ;
288284 }
289285 }
290286 }
291- if result. has_errors ( ) { Err ( result ) } else { Ok ( ( ) ) }
287+ result
292288}
293289
294290/// Intern `ret`. This function assumes that `ret` references no other allocation.
0 commit comments