diff options
| author | David Tolnay <dtolnay@gmail.com> | 2023-01-19 01:24:45 -0800 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2023-02-03 08:33:40 -0800 |
| commit | 4501d3abe17a3dc10f0dffcb38be04b58a33bafb (patch) | |
| tree | 94a053116f1036348d12e5f91e8e32e26f1c48b9 /tests/ui | |
| parent | 9e1c600f74f966ec583f0ac39d0c2a103a2560a7 (diff) | |
| download | rust-4501d3abe17a3dc10f0dffcb38be04b58a33bafb.tar.gz rust-4501d3abe17a3dc10f0dffcb38be04b58a33bafb.zip | |
Autotrait bounds on dyn-safe trait methods
Diffstat (limited to 'tests/ui')
| -rw-r--r-- | tests/ui/where-clauses/self-in-where-clause-allowed.rs | 23 | ||||
| -rw-r--r-- | tests/ui/where-clauses/self-in-where-clause-allowed.stderr | 15 |
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/ui/where-clauses/self-in-where-clause-allowed.rs b/tests/ui/where-clauses/self-in-where-clause-allowed.rs new file mode 100644 index 00000000000..6cf5ed2e46a --- /dev/null +++ b/tests/ui/where-clauses/self-in-where-clause-allowed.rs @@ -0,0 +1,23 @@ +// check-fail + +#![feature(auto_traits)] +#![deny(where_clauses_object_safety)] + +auto trait AutoTrait {} + +trait Trait { + fn static_lifetime_bound(&self) where Self: 'static {} + + fn arg_lifetime_bound<'a>(&self, _arg: &'a ()) where Self: 'a {} + + fn autotrait_bound(&self) where Self: AutoTrait {} +} + +impl Trait for () {} + +fn main() { + let trait_object = &() as &dyn Trait; + trait_object.static_lifetime_bound(); + trait_object.arg_lifetime_bound(&()); + trait_object.autotrait_bound(); //~ ERROR: the trait bound `dyn Trait: AutoTrait` is not satisfied +} diff --git a/tests/ui/where-clauses/self-in-where-clause-allowed.stderr b/tests/ui/where-clauses/self-in-where-clause-allowed.stderr new file mode 100644 index 00000000000..ea51f5084f8 --- /dev/null +++ b/tests/ui/where-clauses/self-in-where-clause-allowed.stderr @@ -0,0 +1,15 @@ +error[E0277]: the trait bound `dyn Trait: AutoTrait` is not satisfied + --> $DIR/self-in-where-clause-allowed.rs:22:18 + | +LL | trait_object.autotrait_bound(); + | ^^^^^^^^^^^^^^^ the trait `AutoTrait` is not implemented for `dyn Trait` + | +note: required by a bound in `Trait::autotrait_bound` + --> $DIR/self-in-where-clause-allowed.rs:13:43 + | +LL | fn autotrait_bound(&self) where Self: AutoTrait {} + | ^^^^^^^^^ required by this bound in `Trait::autotrait_bound` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. |
