diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2022-03-16 20:49:54 +1100 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-05-30 08:52:24 +0000 |
| commit | 257f06587c7cb271517ca9a02c4ed3fd4581f71e (patch) | |
| tree | 6874a3d3b7940e79c007321146df413274c6a3b2 /src | |
| parent | f558990814bb43cfb67db321b299dfdf275663e3 (diff) | |
| download | rust-257f06587c7cb271517ca9a02c4ed3fd4581f71e.tar.gz rust-257f06587c7cb271517ca9a02c4ed3fd4581f71e.zip | |
Remove `#[default..]` and add `#[const_trait]`
Diffstat (limited to 'src')
17 files changed, 34 insertions, 142 deletions
diff --git a/src/test/rustdoc/rfc-2632-const-trait-impl.rs b/src/test/rustdoc/rfc-2632-const-trait-impl.rs index f9173feeeec..ec70a69ff10 100644 --- a/src/test/rustdoc/rfc-2632-const-trait-impl.rs +++ b/src/test/rustdoc/rfc-2632-const-trait-impl.rs @@ -16,12 +16,12 @@ pub struct S<T>(T); // @has - '//pre[@class="rust trait"]/code/a[@class="trait"]' 'Clone' // @!has - '//pre[@class="rust trait"]/code/span[@class="where"]' '~const' // @has - '//pre[@class="rust trait"]/code/span[@class="where"]' ': Clone' +#[const_trait] pub trait Tr<T> { // @!has - '//div[@id="method.a"]/h4[@class="code-header"]' '~const' // @has - '//div[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Clone' // @!has - '//div[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const' // @has - '//div[@id="method.a"]/h4[@class="code-header"]/span[@class="where fmt-newline"]' ': Clone' - #[default_method_body_is_const] fn a<A: ~const Clone + ~const Destruct>() where Option<A>: ~const Clone + ~const Destruct, diff --git a/src/test/ui/rfc-2632-const-trait-impl/attr-misuse.rs b/src/test/ui/rfc-2632-const-trait-impl/attr-misuse.rs index be73ec09ceb..01ac74feff7 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/attr-misuse.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/attr-misuse.rs @@ -1,13 +1,10 @@ #![feature(const_trait_impl)] -#[default_method_body_is_const] //~ ERROR attribute should be applied +#[const_trait] trait A { - #[default_method_body_is_const] //~ ERROR attribute should be applied - fn no_body(self); - - #[default_method_body_is_const] - fn correct_use(&self) {} + #[const_trait] //~ ERROR attribute should be applied + fn foo(self); } -#[default_method_body_is_const] //~ ERROR attribute should be applied +#[const_trait] //~ ERROR attribute should be applied fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/attr-misuse.stderr b/src/test/ui/rfc-2632-const-trait-impl/attr-misuse.stderr index fcb7e15b205..b18f33218c2 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/attr-misuse.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/attr-misuse.stderr @@ -1,32 +1,14 @@ -error: attribute should be applied to a trait method with body - --> $DIR/attr-misuse.rs:3:1 +error: attribute should be applied to a trait + --> $DIR/attr-misuse.rs:9:1 | -LL | #[default_method_body_is_const] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | / trait A { -LL | | #[default_method_body_is_const] -LL | | fn no_body(self); -LL | | -LL | | #[default_method_body_is_const] -LL | | fn correct_use(&self) {} -LL | | } - | |_- not a trait method or missing a body +LL | #[const_trait] + | ^^^^^^^^^^^^^^ -error: attribute should be applied to a trait method with body - --> $DIR/attr-misuse.rs:12:1 - | -LL | #[default_method_body_is_const] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | fn main() {} - | ------------ not a trait method or missing a body - -error: attribute should be applied to a trait method with body +error: attribute should be applied to a trait --> $DIR/attr-misuse.rs:5:5 | -LL | #[default_method_body_is_const] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | fn no_body(self); - | ----------------- not a trait method or missing a body +LL | #[const_trait] + | ^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors diff --git a/src/test/ui/rfc-2632-const-trait-impl/auxiliary/cross-crate.rs b/src/test/ui/rfc-2632-const-trait-impl/auxiliary/cross-crate.rs index 34934d1e01d..e73082c1127 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/auxiliary/cross-crate.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/auxiliary/cross-crate.rs @@ -1,7 +1,7 @@ #![feature(const_trait_impl)] +#[const_trait] pub trait MyTrait { - #[default_method_body_is_const] fn defaulted_func(&self) {} fn func(self); } diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.rs b/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.rs index dd509931766..f66d63da693 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.rs @@ -2,7 +2,7 @@ pub struct Int(i32); -impl const std::ops::Add for i32 { //~ ERROR type annotations needed +impl const std::ops::Add for i32 { //~^ ERROR only traits defined in the current crate can be implemented for primitive types type Output = Self; @@ -11,7 +11,7 @@ impl const std::ops::Add for i32 { //~ ERROR type annotations needed } } -impl std::ops::Add for Int { //~ ERROR type annotations needed +impl std::ops::Add for Int { type Output = Self; fn add(self, rhs: Self) -> Self { @@ -19,7 +19,7 @@ impl std::ops::Add for Int { //~ ERROR type annotations needed } } -impl const std::ops::Add for Int { //~ ERROR type annotations needed +impl const std::ops::Add for Int { //~^ ERROR conflicting implementations of trait type Output = Self; diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.stderr index 9fd82196e79..f515ec198ad 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-and-non-const-impl.stderr @@ -19,50 +19,7 @@ LL | impl std::ops::Add for Int { LL | impl const std::ops::Add for Int { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Int` -error[E0283]: type annotations needed - --> $DIR/const-and-non-const-impl.rs:5:12 - | -LL | impl const std::ops::Add for i32 { - | ^^^^^^^^^^^^^ cannot infer type for type `i32` - | -note: multiple `impl`s satisfying `i32: Add` found - --> $DIR/const-and-non-const-impl.rs:5:1 - | -LL | impl const std::ops::Add for i32 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: and another `impl` found in the `core` crate: `impl Add for i32;` - -error[E0283]: type annotations needed - --> $DIR/const-and-non-const-impl.rs:14:6 - | -LL | impl std::ops::Add for Int { - | ^^^^^^^^^^^^^ cannot infer type for struct `Int` - | -note: multiple `impl`s satisfying `Int: Add` found - --> $DIR/const-and-non-const-impl.rs:14:1 - | -LL | impl std::ops::Add for Int { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | impl const std::ops::Add for Int { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0283]: type annotations needed - --> $DIR/const-and-non-const-impl.rs:22:12 - | -LL | impl const std::ops::Add for Int { - | ^^^^^^^^^^^^^ cannot infer type for struct `Int` - | -note: multiple `impl`s satisfying `Int: Add` found - --> $DIR/const-and-non-const-impl.rs:14:1 - | -LL | impl std::ops::Add for Int { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | impl const std::ops::Add for Int { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 5 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0117, E0119, E0283. +Some errors have detailed explanations: E0117, E0119. For more information about an error, try `rustc --explain E0117`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.rs b/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.rs index 3c82fe1ad6c..0b981d1621e 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.rs @@ -1,9 +1,9 @@ #![feature(const_trait_impl)] +#[const_trait] trait ConstDefaultFn: Sized { fn b(self); - #[default_method_body_is_const] fn a(self) { self.b(); } diff --git a/src/test/ui/rfc-2632-const-trait-impl/cross-crate-default-method-body-is-const.rs b/src/test/ui/rfc-2632-const-trait-impl/cross-crate-default-method-body-is-const.rs index c0f90c116e4..bde8bf20f46 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/cross-crate-default-method-body-is-const.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/cross-crate-default-method-body-is-const.rs @@ -1,4 +1,4 @@ -// This tests that `default_method_body_is_const` methods can +// This tests that `const_trait` default methods can // be called from a const context when used across crates. // // check-pass diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs index 17c88e44296..d27291231fb 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs @@ -5,8 +5,8 @@ impl Tr for () {} const fn foo<T>() where T: ~const Tr {} +#[const_trait] pub trait Foo { - #[default_method_body_is_const] fn foo() { foo::<()>(); //~^ ERROR the trait bound `(): ~const Tr` is not satisfied diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.rs b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.rs index be2f3f6d623..d798516ff70 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.rs @@ -1,10 +1,9 @@ #![feature(const_trait_impl)] +#[const_trait] pub trait Tr { - #[default_method_body_is_const] fn a(&self) {} - #[default_method_body_is_const] fn b(&self) { ().a() //~^ ERROR the trait bound diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr index cf357971951..8bb7f014103 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr @@ -1,17 +1,17 @@ error[E0277]: the trait bound `(): ~const Tr` is not satisfied - --> $DIR/default-method-body-is-const-same-trait-ck.rs:9:12 + --> $DIR/default-method-body-is-const-same-trait-ck.rs:8:12 | LL | ().a() | ^^^ the trait `~const Tr` is not implemented for `()` | note: the trait `Tr` is implemented for `()`, but that implementation is not `const` - --> $DIR/default-method-body-is-const-same-trait-ck.rs:9:12 + --> $DIR/default-method-body-is-const-same-trait-ck.rs:8:12 | LL | ().a() | ^^^ error[E0015]: cannot call non-const fn `<() as Tr>::a` in constant functions - --> $DIR/default-method-body-is-const-same-trait-ck.rs:9:12 + --> $DIR/default-method-body-is-const-same-trait-ck.rs:8:12 | LL | ().a() | ^^^ diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-with-staged-api.rs b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-with-staged-api.rs index 7f6d86d3375..1b45cd9aab9 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-with-staged-api.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-with-staged-api.rs @@ -9,8 +9,8 @@ #![feature(const_trait_impl)] #![stable(since = "1", feature = "foo")] +#[const_trait] trait Tr { - #[default_method_body_is_const] fn a() {} } diff --git a/src/test/ui/rfc-2632-const-trait-impl/impl-with-default-fn-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/impl-with-default-fn-fail.rs index eba8b665ceb..6df9696f2cb 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/impl-with-default-fn-fail.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/impl-with-default-fn-fail.rs @@ -1,32 +1,17 @@ #![feature(const_trait_impl)] +#[const_trait] trait Tr { fn req(&self); - fn prov(&self) { - println!("lul"); - self.req(); - } - - #[default_method_body_is_const] fn default() {} } struct S; -impl const Tr for S { - fn req(&self) {} -} //~^^ ERROR const trait implementations may not use non-const default functions - impl const Tr for u16 { - fn prov(&self) {} fn default() {} -} //~^^^ ERROR not all trait items implemented +} //~^^ ERROR not all trait items implemented -impl const Tr for u32 { - fn req(&self) {} - fn default() {} -} //~^^^ ERROR const trait implementations may not use non-const default functions - fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/impl-with-default-fn-fail.stderr b/src/test/ui/rfc-2632-const-trait-impl/impl-with-default-fn-fail.stderr index 4ec6f929ffc..6c6ca9f5db8 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/impl-with-default-fn-fail.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/impl-with-default-fn-fail.stderr @@ -1,26 +1,5 @@ -error: const trait implementations may not use non-const default functions - --> $DIR/impl-with-default-fn-fail.rs:17:1 - | -LL | / impl const Tr for S { -LL | | fn req(&self) {} -LL | | } - | |_^ - | - = note: `prov` not implemented - -error: const trait implementations may not use non-const default functions - --> $DIR/impl-with-default-fn-fail.rs:27:1 - | -LL | / impl const Tr for u32 { -LL | | fn req(&self) {} -LL | | fn default() {} -LL | | } - | |_^ - | - = note: `prov` not implemented - error[E0046]: not all trait items implemented, missing: `req` - --> $DIR/impl-with-default-fn-fail.rs:21:1 + --> $DIR/impl-with-default-fn-fail.rs:12:1 | LL | fn req(&self); | -------------- `req` from trait @@ -28,6 +7,6 @@ LL | fn req(&self); LL | impl const Tr for u16 { | ^^^^^^^^^^^^^^^^^^^^^ missing `req` in implementation -error: aborting due to 3 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0046`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/impl-with-default-fn-pass.rs b/src/test/ui/rfc-2632-const-trait-impl/impl-with-default-fn-pass.rs index 2e4664714a7..ae81421e9e1 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/impl-with-default-fn-pass.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/impl-with-default-fn-pass.rs @@ -2,28 +2,21 @@ #![feature(const_trait_impl)] +#[const_trait] trait Tr { fn req(&self); - fn prov(&self) { - println!("lul"); - self.req(); - } - - #[default_method_body_is_const] fn default() {} } impl const Tr for u8 { fn req(&self) {} - fn prov(&self) {} } macro_rules! impl_tr { ($ty: ty) => { impl const Tr for $ty { fn req(&self) {} - fn prov(&self) {} } } } diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-default-body-stability.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-default-body-stability.rs index f4a5d0133ce..334fc4cb847 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/trait-default-body-stability.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-default-body-stability.rs @@ -37,8 +37,8 @@ impl const FromResidual for T { } #[stable(feature = "foo", since = "1.0")] +#[const_trait] pub trait Tr { - #[default_method_body_is_const] #[stable(feature = "foo", since = "1.0")] fn bar() -> T { T? diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs index e47c5c7bd66..b7cf9a13b79 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs @@ -6,8 +6,8 @@ trait Bar { fn bar() -> u8; } +#[const_trait] trait Foo { - #[default_method_body_is_const] fn foo() -> u8 where Self: ~const Bar { <Self as Bar>::bar() * 6 } |
