diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs index d2728f79a27..b134ccdf4c5 100644 --- a/components/script/dom/canvasrenderingcontext2d.rs +++ b/components/script/dom/canvasrenderingcontext2d.rs @@ -127,7 +127,6 @@ impl LayoutCanvasRenderingContextHelpers for LayoutDom<'_, CanvasRenderingContex impl CanvasContext for CanvasRenderingContext2D { type ID = CanvasId; - #[cfg_attr(crown, allow(crown::unrooted_must_root))] // Crown is wrong here #35570 fn context_id(&self) -> Self::ID { self.canvas_state.get_canvas_id() } diff --git a/components/script/dom/testbindingmaplikewithinterface.rs b/components/script/dom/testbindingmaplikewithinterface.rs index 3fddb41bb34..e60d251aeaf 100644 --- a/components/script/dom/testbindingmaplikewithinterface.rs +++ b/components/script/dom/testbindingmaplikewithinterface.rs @@ -89,9 +89,6 @@ impl TestBindingMaplikeWithInterfaceMethods } } -// this error is wrong because if we inline Self::Key and Self::Value all errors are gone -// TODO: FIX THIS -#[cfg_attr(crown, allow(crown::unrooted_must_root))] impl Maplike for TestBindingMaplikeWithInterface { type Key = DOMString; type Value = DomRoot; diff --git a/components/script/dom/testbindingmaplikewithprimitive.rs b/components/script/dom/testbindingmaplikewithprimitive.rs index e90c984d028..1a89bebb00b 100644 --- a/components/script/dom/testbindingmaplikewithprimitive.rs +++ b/components/script/dom/testbindingmaplikewithprimitive.rs @@ -87,9 +87,6 @@ impl TestBindingMaplikeWithPrimitiveMethods } } -// this error is wrong because if we inline Self::Key and Self::Value all errors are gone -// TODO: FIX THIS -#[cfg_attr(crown, allow(crown::unrooted_must_root))] impl Maplike for TestBindingMaplikeWithPrimitive { type Key = DOMString; type Value = i32; diff --git a/components/script/dom/testbindingsetlikewithinterface.rs b/components/script/dom/testbindingsetlikewithinterface.rs index 22c6c308c03..b41888e4dd6 100644 --- a/components/script/dom/testbindingsetlikewithinterface.rs +++ b/components/script/dom/testbindingsetlikewithinterface.rs @@ -61,9 +61,6 @@ impl TestBindingSetlikeWithInterfaceMethods } } -// this error is wrong because if we inline Self::Key and Self::Value all errors are gone -// TODO: FIX THIS -#[cfg_attr(crown, allow(crown::unrooted_must_root))] impl Setlike for TestBindingSetlikeWithInterface { type Key = DomRoot; diff --git a/components/script/dom/testbindingsetlikewithprimitive.rs b/components/script/dom/testbindingsetlikewithprimitive.rs index 4d556085a13..031c55e50f4 100644 --- a/components/script/dom/testbindingsetlikewithprimitive.rs +++ b/components/script/dom/testbindingsetlikewithprimitive.rs @@ -61,9 +61,6 @@ impl TestBindingSetlikeWithPrimitiveMethods } } -// this error is wrong because if we inline Self::Key and Self::Value all errors are gone -// TODO: FIX THIS -#[cfg_attr(crown, allow(crown::unrooted_must_root))] impl Setlike for TestBindingSetlikeWithPrimitive { type Key = DOMString; diff --git a/components/script/dom/webgl2renderingcontext.rs b/components/script/dom/webgl2renderingcontext.rs index 58e6149a271..11f37525d64 100644 --- a/components/script/dom/webgl2renderingcontext.rs +++ b/components/script/dom/webgl2renderingcontext.rs @@ -903,7 +903,6 @@ impl WebGL2RenderingContext { impl CanvasContext for WebGL2RenderingContext { type ID = WebGLContextId; - #[cfg_attr(crown, allow(crown::unrooted_must_root))] // Crown is wrong here #35570 fn context_id(&self) -> Self::ID { self.base.context_id() } diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index 54478a810cd..9944e7bf47f 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -1864,7 +1864,6 @@ impl WebGLRenderingContext { impl CanvasContext for WebGLRenderingContext { type ID = WebGLContextId; - #[cfg_attr(crown, allow(crown::unrooted_must_root))] // Crown is wrong here #35570 fn context_id(&self) -> Self::ID { self.webgl_sender.context_id() } diff --git a/components/script/dom/webgpu/gpucanvascontext.rs b/components/script/dom/webgpu/gpucanvascontext.rs index 1f5de8ea194..00bdcbec64c 100644 --- a/components/script/dom/webgpu/gpucanvascontext.rs +++ b/components/script/dom/webgpu/gpucanvascontext.rs @@ -253,7 +253,6 @@ impl GPUCanvasContext { impl CanvasContext for GPUCanvasContext { type ID = WebGPUContextId; - #[cfg_attr(crown, allow(crown::unrooted_must_root))] // Crown is wrong here #35570 fn context_id(&self) -> WebGPUContextId { self.context_id } diff --git a/components/script/dom/webgpu/gpusupportedfeatures.rs b/components/script/dom/webgpu/gpusupportedfeatures.rs index d065cfa39c0..f3941e90c7a 100644 --- a/components/script/dom/webgpu/gpusupportedfeatures.rs +++ b/components/script/dom/webgpu/gpusupportedfeatures.rs @@ -139,8 +139,6 @@ pub(crate) fn gpu_to_wgt_feature(feature: GPUFeatureName) -> Option { } } -// this error is wrong because if we inline Self::Key and Self::Value all errors are gone -#[cfg_attr(crown, allow(crown::unrooted_must_root))] impl Setlike for GPUSupportedFeatures { type Key = DOMString; diff --git a/components/script/dom/webgpu/wgsllanguagefeatures.rs b/components/script/dom/webgpu/wgsllanguagefeatures.rs index 131f07bc677..dcaafdb6375 100644 --- a/components/script/dom/webgpu/wgsllanguagefeatures.rs +++ b/components/script/dom/webgpu/wgsllanguagefeatures.rs @@ -54,8 +54,6 @@ impl WGSLLanguageFeaturesMethods for WGSLLanguageFeatures } } -// this error is wrong because if we inline Self::Key and Self::Value all errors are gone -#[cfg_attr(crown, allow(crown::unrooted_must_root))] impl Setlike for WGSLLanguageFeatures { type Key = DOMString; diff --git a/support/crown/src/unrooted_must_root.rs b/support/crown/src/unrooted_must_root.rs index 3c1c2f87d9a..b954ad66043 100644 --- a/support/crown/src/unrooted_must_root.rs +++ b/support/crown/src/unrooted_must_root.rs @@ -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, diff --git a/support/crown/tests/run-pass/alias-projection-ignored.rs b/support/crown/tests/run-pass/alias-projection-ignored.rs new file mode 100644 index 00000000000..f2c034e6a0c --- /dev/null +++ b/support/crown/tests/run-pass/alias-projection-ignored.rs @@ -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) } +}