diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-04-02 14:22:22 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-04-17 09:50:44 +0000 |
| commit | 126dcc618d065e97887113926f63986bd0a9e681 (patch) | |
| tree | 40c3bbbcee86aea7f5ebd7e0a2bb3494ec338754 /compiler/rustc_const_eval/src/interpret/intern.rs | |
| parent | 77fe9f0a7243d875c419d9e72ae3253db4f6e17a (diff) | |
| download | rust-126dcc618d065e97887113926f63986bd0a9e681.tar.gz rust-126dcc618d065e97887113926f63986bd0a9e681.zip | |
Use less fragile error handling
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/intern.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/intern.rs | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index 3828351db0a..d4168273f29 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -132,17 +132,10 @@ pub enum InternKind { Promoted, } -#[derive(Default, Debug)] -pub struct InternResult { - pub found_bad_mutable_pointer: bool, - pub found_dangling_pointer: bool, -} - -impl InternResult { - fn has_errors(&self) -> bool { - let Self { found_bad_mutable_pointer, found_dangling_pointer } = *self; - found_bad_mutable_pointer || found_dangling_pointer - } +#[derive(Debug)] +pub enum InternResult { + FoundBadMutablePointer, + FoundDanglingPointer, } /// Intern `ret` and everything it references. @@ -212,7 +205,7 @@ pub fn intern_const_alloc_recursive< // Whether we encountered a bad mutable pointer. // We want to first report "dangling" and then "mutable", so we need to delay reporting these // errors. - let mut result = InternResult::default(); + let mut result = Ok(()); // Keep interning as long as there are things to intern. // We show errors if there are dangling pointers, or mutable pointers in immutable contexts @@ -262,7 +255,10 @@ pub fn intern_const_alloc_recursive< // on the promotion analysis not screwing up to ensure that it is sound to intern // promoteds as immutable. trace!("found bad mutable pointer"); - result.found_bad_mutable_pointer = true; + // Prefer dangling pointer errors over mutable pointer errors + if result.is_ok() { + result = Err(InternResult::FoundBadMutablePointer); + } } if ecx.tcx.try_get_global_alloc(alloc_id).is_some() { // Already interned. @@ -284,11 +280,11 @@ pub fn intern_const_alloc_recursive< Ok(nested) => todo.extend(nested), Err(()) => { ecx.tcx.dcx().delayed_bug("found dangling pointer during const interning"); - result.found_dangling_pointer = true + result = Err(InternResult::FoundDanglingPointer); } } } - if result.has_errors() { Err(result) } else { Ok(()) } + result } /// Intern `ret`. This function assumes that `ret` references no other allocation. |
