crown: Do not check trait item projections. (#36095)

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-03-22 15:55:27 -04:00 committed by GitHub
parent 80434d4644
commit 471f3f49bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 32 additions and 22 deletions

View file

@ -192,7 +192,9 @@ fn is_unrooted_ty<'tcx>(
ty::RawPtr(..) => false, // don't recurse down *ptrs
ty::FnDef(..) | ty::FnPtr(..) => false,
ty::Alias(
ty::AliasTyKind::Projection | ty::AliasTyKind::Inherent | ty::AliasTyKind::Weak,
kind @ ty::AliasTyKind::Projection |
kind @ ty::AliasTyKind::Inherent |
kind @ ty::AliasTyKind::Weak,
ty,
) => {
if has_attr(ty.def_id, sym.must_root) {
@ -201,7 +203,10 @@ fn is_unrooted_ty<'tcx>(
} else if has_attr(ty.def_id, sym.allow_unrooted_interior) {
false
} else {
true
// If this is a projection (i.e. Self::FOO), recursing will
// make us consider Self, which is overly conservative for
// this analysys.
*kind != ty::AliasTyKind::Projection
}
},
_ => true,

View file

@ -0,0 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//@rustc-env:RUSTC_BOOTSTRAP=1
#![allow(dead_code)]
fn main() {}
struct CanvasId(u64);
trait CanvasContext {
type ID;
fn context_id(&self) -> Self::ID;
}
#[crown::unrooted_must_root_lint::must_root]
struct Context;
impl CanvasContext for Context {
type ID = CanvasId;
fn context_id(&self) -> Self::ID { CanvasId(0) }
}