Support ?Trait bounds in supertraits and dyn Trait under a feature gate

This commit is contained in:
Bryanskiy 2024-02-23 16:39:57 +03:00
parent 28e684b470
commit 2a73553513
34 changed files with 305 additions and 85 deletions

View file

@ -429,7 +429,7 @@ fn ty_has_local_parent(
path_has_local_parent(ty_path, cx, impl_parent, impl_parent_parent)
}
TyKind::TraitObject([principle_poly_trait_ref, ..], _, _) => path_has_local_parent(
principle_poly_trait_ref.trait_ref.path,
principle_poly_trait_ref.0.trait_ref.path,
cx,
impl_parent,
impl_parent_parent,
@ -527,7 +527,7 @@ fn self_ty_kind_for_diagnostic(ty: &rustc_hir::Ty<'_>, tcx: TyCtxt<'_>) -> (Span
.to_string(),
),
TyKind::TraitObject([principle_poly_trait_ref, ..], _, _) => {
let path = &principle_poly_trait_ref.trait_ref.path;
let path = &principle_poly_trait_ref.0.trait_ref.path;
(
path_span_without_args(path),
path.res

View file

@ -113,9 +113,11 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &'tcx hir::Ty<'tcx>) {
let hir::TyKind::TraitObject(bounds, _lifetime, _syntax) = &ty.kind else { return };
for bound in &bounds[..] {
for (bound, modifier) in &bounds[..] {
let def_id = bound.trait_ref.trait_def_id();
if cx.tcx.lang_items().drop_trait() == def_id {
if cx.tcx.lang_items().drop_trait() == def_id
&& *modifier != hir::TraitBoundModifier::Maybe
{
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
cx.emit_span_lint(DYN_DROP, bound.span, DropGlue { tcx: cx.tcx, def_id });
}