@@ -132,17 +132,10 @@ pub enum InternKind {
132
132
Promoted ,
133
133
}
134
134
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 ,
146
139
}
147
140
148
141
/// Intern `ret` and everything it references.
@@ -212,7 +205,7 @@ pub fn intern_const_alloc_recursive<
212
205
// Whether we encountered a bad mutable pointer.
213
206
// We want to first report "dangling" and then "mutable", so we need to delay reporting these
214
207
// errors.
215
- let mut result = InternResult :: default ( ) ;
208
+ let mut result = Ok ( ( ) ) ;
216
209
217
210
// Keep interning as long as there are things to intern.
218
211
// We show errors if there are dangling pointers, or mutable pointers in immutable contexts
@@ -262,7 +255,10 @@ pub fn intern_const_alloc_recursive<
262
255
// on the promotion analysis not screwing up to ensure that it is sound to intern
263
256
// promoteds as immutable.
264
257
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
+ }
266
262
}
267
263
if ecx. tcx . try_get_global_alloc ( alloc_id) . is_some ( ) {
268
264
// Already interned.
@@ -284,11 +280,11 @@ pub fn intern_const_alloc_recursive<
284
280
Ok ( nested) => todo. extend ( nested) ,
285
281
Err ( ( ) ) => {
286
282
ecx. tcx . dcx ( ) . delayed_bug ( "found dangling pointer during const interning" ) ;
287
- result. found_dangling_pointer = true
283
+ result = Err ( InternResult :: FoundDanglingPointer ) ;
288
284
}
289
285
}
290
286
}
291
- if result. has_errors ( ) { Err ( result ) } else { Ok ( ( ) ) }
287
+ result
292
288
}
293
289
294
290
/// Intern `ret`. This function assumes that `ret` references no other allocation.
0 commit comments