diff options
| author | trevyn <230691+trevyn@users.noreply.github.com> | 2024-01-20 20:12:54 +0400 |
|---|---|---|
| committer | trevyn <230691+trevyn@users.noreply.github.com> | 2024-01-21 20:04:39 +0400 |
| commit | b58a8a98cdee84a9636c08877f623b97033c7dda (patch) | |
| tree | d6a6f955947f352a63f7f58e82aa6c8b0e017e6f /compiler/rustc_hir_analysis/src/astconv/lint.rs | |
| parent | 6745c6000aa037c14bf4359c5cb56d4c657bfe3c (diff) | |
| download | rust-b58a8a98cdee84a9636c08877f623b97033c7dda.tar.gz rust-b58a8a98cdee84a9636c08877f623b97033c7dda.zip | |
`maybe_lint_impl_trait`: separate `is_downgradable` from `is_object_safe`
Diffstat (limited to 'compiler/rustc_hir_analysis/src/astconv/lint.rs')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/astconv/lint.rs | 16 |
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(); } |
