@@ -122,17 +122,10 @@ pub enum InternKind {
122
122
Promoted ,
123
123
}
124
124
125
- #[ derive( Default , Debug ) ]
126
- pub struct InternResult {
127
- pub found_bad_mutable_pointer : bool ,
128
- pub found_dangling_pointer : bool ,
129
- }
130
-
131
- impl InternResult {
132
- fn has_errors ( & self ) -> bool {
133
- let Self { found_bad_mutable_pointer, found_dangling_pointer } = * self ;
134
- found_bad_mutable_pointer || found_dangling_pointer
135
- }
125
+ #[ derive( Debug ) ]
126
+ pub enum InternResult {
127
+ FoundBadMutablePointer ,
128
+ FoundDanglingPointer ,
136
129
}
137
130
138
131
/// Intern `ret` and everything it references.
@@ -202,7 +195,7 @@ pub fn intern_const_alloc_recursive<
202
195
// Whether we encountered a bad mutable pointer.
203
196
// We want to first report "dangling" and then "mutable", so we need to delay reporting these
204
197
// errors.
205
- let mut result = InternResult :: default ( ) ;
198
+ let mut result = Ok ( ( ) ) ;
206
199
207
200
// Keep interning as long as there are things to intern.
208
201
// We show errors if there are dangling pointers, or mutable pointers in immutable contexts
@@ -252,7 +245,10 @@ pub fn intern_const_alloc_recursive<
252
245
// on the promotion analysis not screwing up to ensure that it is sound to intern
253
246
// promoteds as immutable.
254
247
trace ! ( "found bad mutable pointer" ) ;
255
- result. found_bad_mutable_pointer = true ;
248
+ // Prefer dangling pointer errors over mutable pointer errors
249
+ if result. is_ok ( ) {
250
+ result = Err ( InternResult :: FoundBadMutablePointer ) ;
251
+ }
256
252
}
257
253
if ecx. tcx . try_get_global_alloc ( alloc_id) . is_some ( ) {
258
254
// Already interned.
@@ -274,11 +270,11 @@ pub fn intern_const_alloc_recursive<
274
270
Ok ( nested) => todo. extend ( nested) ,
275
271
Err ( ( ) ) => {
276
272
ecx. tcx . dcx ( ) . delayed_bug ( "found dangling pointer during const interning" ) ;
277
- result. found_dangling_pointer = true
273
+ result = Err ( InternResult :: FoundDanglingPointer ) ;
278
274
}
279
275
}
280
276
}
281
- if result. has_errors ( ) { Err ( result ) } else { Ok ( ( ) ) }
277
+ result
282
278
}
283
279
284
280
/// Intern `ret`. This function assumes that `ret` references no other allocation.
0 commit comments