-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #86857 - fee1-dead:add-attr, r=oli-obk
Add #[default_method_body_is_const] `@rustbot` label F-const_trait_impl
- Loading branch information
Showing
19 changed files
with
265 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#![feature(const_trait_impl)] | ||
#![allow(incomplete_features)] | ||
|
||
#[default_method_body_is_const] //~ ERROR attribute should be applied | ||
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) {} | ||
} | ||
|
||
#[default_method_body_is_const] //~ ERROR attribute should be applied | ||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
error: attribute should be applied to a trait method with body | ||
--> $DIR/attr-misuse.rs:4: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 | ||
|
||
error: attribute should be applied to a trait method with body | ||
--> $DIR/attr-misuse.rs:13: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 | ||
--> $DIR/attr-misuse.rs:6:5 | ||
| | ||
LL | #[default_method_body_is_const] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | fn no_body(self); | ||
| ----------------- not a trait method or missing a body | ||
|
||
error: aborting due to 3 previous errors | ||
|
31 changes: 31 additions & 0 deletions
31
src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#![feature(const_trait_impl)] | ||
#![feature(const_fn_trait_bound)] // FIXME is this needed? | ||
#![allow(incomplete_features)] | ||
|
||
trait ConstDefaultFn: Sized { | ||
fn b(self); | ||
|
||
#[default_method_body_is_const] | ||
fn a(self) { | ||
self.b(); | ||
} | ||
} | ||
|
||
struct NonConstImpl; | ||
struct ConstImpl; | ||
|
||
impl ConstDefaultFn for NonConstImpl { | ||
fn b(self) {} | ||
} | ||
|
||
impl const ConstDefaultFn for ConstImpl { | ||
fn b(self) {} | ||
} | ||
|
||
const fn test() { | ||
NonConstImpl.a(); | ||
//~^ ERROR calls in constant functions are limited to constant functions, tuple structs and tuple variants | ||
ConstImpl.a(); | ||
} | ||
|
||
fn main() {} |
9 changes: 9 additions & 0 deletions
9
src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants | ||
--> $DIR/const-default-method-bodies.rs:26:5 | ||
| | ||
LL | NonConstImpl.a(); | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0015`. |
Oops, something went wrong.