about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-01-22 16:54:59 +0100
committerGitHub <noreply@github.com>2024-01-22 16:54:59 +0100
commit6e4933f94f9b06a7a5ab4ad3e39a0229e9f17023 (patch)
treef91a5f64bd773cbac5a9b7c34c43ee4d25eea93b /compiler
parenta12e2ff7b2e5b3adbaa010c507039ebcb41405c3 (diff)
parentb58a8a98cdee84a9636c08877f623b97033c7dda (diff)
downloadrust-6e4933f94f9b06a7a5ab4ad3e39a0229e9f17023.tar.gz
rust-6e4933f94f9b06a7a5ab4ad3e39a0229e9f17023.zip
Rollup merge of #120164 - trevyn:is_downgradable, r=compiler-errors
`maybe_lint_impl_trait`: separate `is_downgradable` from `is_object_safe`

https://github.com/rust-lang/rust/pull/119752 leveraged and overloaded `is_object_safe` to prevent an ICE, but accurate object safety information is needed for precise suggestions. This separates out `is_downgradable`, used for the ICE prevention, and `is_object_safe`, which returns to its original meaning.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/lint.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/lint.rs b/compiler/rustc_hir_analysis/src/astconv/lint.rs
index b5f42e98127..27dc088d5dd 100644
--- a/compiler/rustc_hir_analysis/src/astconv/lint.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/lint.rs
@@ -94,15 +94,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
             return false;
         };
         let impl_sugg = vec![(self_ty.span.shrink_to_lo(), "impl ".to_string())];
+        let mut is_downgradable = true;
         let is_object_safe = match self_ty.kind {
             hir::TyKind::TraitObject(objects, ..) => {
                 objects.iter().all(|o| match o.trait_ref.path.res {
-                    Res::Def(DefKind::Trait, id) if Some(id) == owner => {
-                        // When we're dealing with a recursive trait, we don't want to downgrade
-                        // the error, so we consider them to be object safe always. (#119652)
-                        true
+                    Res::Def(DefKind::Trait, id) => {
+                        if Some(id) == owner {
+                            // For recursive traits, don't downgrade the error. (#119652)
+                            is_downgradable = false;
+                        }
+                        tcx.check_is_object_safe(id)
                     }
-                    Res::Def(DefKind::Trait, id) => tcx.check_is_object_safe(id),
                     _ => false,
                 })
             }
@@ -130,7 +132,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
                     ],
                     Applicability::MachineApplicable,
                 );
-            } else if diag.is_error() {
+            } else if diag.is_error() && is_downgradable {
                 // We'll emit the object safety error already, with a structured suggestion.
                 diag.downgrade_to_delayed_bug();
             }
@@ -156,7 +158,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
             }
             if !is_object_safe {
                 diag.note(format!("`{trait_name}` it is not object safe, so it can't be `dyn`"));
-                if diag.is_error() {
+                if diag.is_error() && is_downgradable {
                     // We'll emit the object safety error already, with a structured suggestion.
                     diag.downgrade_to_delayed_bug();
                 }