mirror of
https://github.com/servo/servo.git
synced 2025-09-29 16:19:14 +01:00
Support future uses of traits with associated types in rooting analysis (#34359)
* crown: Support Rc<T::Promise> and callback objects parameterized over a trait.. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * crown: Verify that attributes match between trait associated types and impls. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * crown: Check type aliases as part of associated type checks. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * crown: Add periods to all diagnostic messages. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Tidy. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix compile-fail test expectations. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
60dc3b26fb
commit
a014da590a
12 changed files with 296 additions and 33 deletions
30
support/crown/tests/compile-fail/missing_allow_in_rc.rs
Normal file
30
support/crown/tests/compile-fail/missing_allow_in_rc.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* 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)]
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
trait TypeHolderTrait {
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
type F;
|
||||
//~^ ERROR: Mismatched use of #[crown::unrooted_must_root_lint::allow_unrooted_interior_in_rc] between associated type declaration and impl definition. [crown::unrooted_must_root]
|
||||
}
|
||||
|
||||
struct TypeHolder;
|
||||
impl TypeHolderTrait for TypeHolder {
|
||||
type F = Foo;
|
||||
}
|
||||
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
#[crown::unrooted_must_root_lint::allow_unrooted_in_rc]
|
||||
struct Foo;
|
||||
|
||||
fn foo<T: TypeHolderTrait>() -> Rc<T::F> {
|
||||
//~^ ERROR: Type must be rooted. [crown::unrooted_must_root]
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,17 @@
|
|||
/* 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)]
|
||||
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
struct MustBeRooted;
|
||||
|
||||
struct CanBeUnrooted {
|
||||
val: MustBeRooted,
|
||||
//~^ ERROR: Type must be rooted, use #[crown::unrooted_must_root_lint::must_root] on the struct definition to propagate. [crown::unrooted_must_root]
|
||||
}
|
||||
|
||||
|
||||
fn main() {}
|
|
@ -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)]
|
||||
|
||||
trait TypeHolderTrait {
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
type F: Default;
|
||||
}
|
||||
|
||||
struct TypeHolder;
|
||||
impl TypeHolderTrait for TypeHolder {
|
||||
type F = Foo;
|
||||
}
|
||||
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
#[derive(Default)]
|
||||
struct Foo;
|
||||
|
||||
struct MustBeRooted<T: TypeHolderTrait>(T::F);
|
||||
//~^ ERROR: Type must be rooted, use #[crown::unrooted_must_root_lint::must_root] on the struct definition to propagate. [crown::unrooted_must_root]
|
||||
|
||||
fn main() {}
|
|
@ -18,4 +18,4 @@ impl Trait for TypeHolder {
|
|||
type F = Foo;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
fn main() {}
|
||||
|
|
|
@ -11,6 +11,7 @@ struct Bar<TH: TypeHolderTrait>(TH::F);
|
|||
trait TypeHolderTrait {
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
type F;
|
||||
//~^ Mismatched use of #[crown::unrooted_must_root_lint::must_root] between associated type declaration and impl definition. [crown::unrooted_must_root]
|
||||
}
|
||||
|
||||
struct TypeHolder;
|
||||
|
|
28
support/crown/tests/run-pass/allow_interior_trait.rs
Normal file
28
support/crown/tests/run-pass/allow_interior_trait.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* 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)]
|
||||
|
||||
trait TypeHolderTrait {
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
type F;
|
||||
}
|
||||
|
||||
struct TypeHolder;
|
||||
impl TypeHolderTrait for TypeHolder {
|
||||
type F = Foo;
|
||||
}
|
||||
|
||||
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
struct Foo;
|
||||
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
struct MustBeRooted<T: TypeHolderTrait>(T::F);
|
||||
|
||||
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
|
||||
struct CanBeUnrooted<T: TypeHolderTrait>(MustBeRooted<T>);
|
||||
|
||||
fn main() {}
|
29
support/crown/tests/run-pass/allow_trait_in_rc.rs
Normal file
29
support/crown/tests/run-pass/allow_trait_in_rc.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* 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)]
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
trait TypeHolderTrait {
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
#[crown::unrooted_must_root_lint::allow_unrooted_in_rc]
|
||||
type F;
|
||||
}
|
||||
|
||||
struct TypeHolder;
|
||||
impl TypeHolderTrait for TypeHolder {
|
||||
type F = Foo;
|
||||
}
|
||||
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
#[crown::unrooted_must_root_lint::allow_unrooted_in_rc]
|
||||
struct Foo;
|
||||
|
||||
fn foo<T: TypeHolderTrait>() -> Rc<T::F> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn main() {}
|
16
support/crown/tests/run-pass/allowed_interior.rs
Normal file
16
support/crown/tests/run-pass/allowed_interior.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* 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)]
|
||||
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
struct MustBeRooted;
|
||||
|
||||
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
|
||||
struct CanBeUnrooted {
|
||||
val: MustBeRooted,
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue