mirror of
https://github.com/servo/servo.git
synced 2025-08-24 22:58:21 +01:00
Support associated types in must_root lint (#34163)
* Support associated types in must_root lint Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * fix Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * fixups Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * fixup Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Fix crown violations Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * fix eng Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * make new test use RUSTC_BOOTSTRAP=1 Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
2d3b46670f
commit
6c2b840e37
7 changed files with 144 additions and 21 deletions
|
@ -0,0 +1,21 @@
|
|||
/* 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
|
||||
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
struct Foo;
|
||||
|
||||
trait Trait {
|
||||
type F;
|
||||
//~^ ERROR: Type trait declaration must be marked with #[crown::unrooted_must_root_lint::must_root] to allow binding must_root types in associated types
|
||||
}
|
||||
|
||||
struct TypeHolder;
|
||||
|
||||
impl Trait for TypeHolder {
|
||||
// type F in trait must be also marked as must_root if we want to do this
|
||||
type F = Foo;
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,22 @@
|
|||
/* 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
|
||||
|
||||
struct Foo(i32);
|
||||
|
||||
struct Bar<TH: TypeHolderTrait>(TH::F);
|
||||
//~^ ERROR: Type must be rooted, use #[crown::unrooted_must_root_lint::must_root] on the struct definition to propagate
|
||||
|
||||
trait TypeHolderTrait {
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
type F;
|
||||
}
|
||||
|
||||
struct TypeHolder;
|
||||
|
||||
impl TypeHolderTrait for TypeHolder {
|
||||
type F = Foo;
|
||||
}
|
||||
|
||||
fn main() {}
|
26
support/crown/tests/run-pass/type_holder_must_root.rs
Normal file
26
support/crown/tests/run-pass/type_holder_must_root.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* 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
|
||||
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
struct Foo(i32);
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
struct Bar<TH: TypeHolderTrait>(TH::F, TH::B);
|
||||
|
||||
struct Baz(i32);
|
||||
|
||||
trait TypeHolderTrait {
|
||||
#[crown::unrooted_must_root_lint::must_root]
|
||||
type F;
|
||||
type B;
|
||||
}
|
||||
|
||||
struct TypeHolder;
|
||||
|
||||
impl TypeHolderTrait for TypeHolder {
|
||||
type F = Foo;
|
||||
type B = Baz;
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue