@@ -122,17 +122,10 @@ pub enum InternKind {
122122 Promoted ,
123123}
124124
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 ,
136129}
137130
138131/// Intern `ret` and everything it references.
@@ -202,7 +195,7 @@ pub fn intern_const_alloc_recursive<
202195 // Whether we encountered a bad mutable pointer.
203196 // We want to first report "dangling" and then "mutable", so we need to delay reporting these
204197 // errors.
205- let mut result = InternResult :: default ( ) ;
198+ let mut result = Ok ( ( ) ) ;
206199
207200 // Keep interning as long as there are things to intern.
208201 // We show errors if there are dangling pointers, or mutable pointers in immutable contexts
@@ -252,7 +245,10 @@ pub fn intern_const_alloc_recursive<
252245 // on the promotion analysis not screwing up to ensure that it is sound to intern
253246 // promoteds as immutable.
254247 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+ }
256252 }
257253 if ecx. tcx . try_get_global_alloc ( alloc_id) . is_some ( ) {
258254 // Already interned.
@@ -274,11 +270,11 @@ pub fn intern_const_alloc_recursive<
274270 Ok ( nested) => todo. extend ( nested) ,
275271 Err ( ( ) ) => {
276272 ecx. tcx . dcx ( ) . delayed_bug ( "found dangling pointer during const interning" ) ;
277- result. found_dangling_pointer = true
273+ result = Err ( InternResult :: FoundDanglingPointer ) ;
278274 }
279275 }
280276 }
281- if result. has_errors ( ) { Err ( result ) } else { Ok ( ( ) ) }
277+ result
282278}
283279
284280/// Intern `ret`. This function assumes that `ret` references no other allocation.
0 commit comments