diff options
| author | Takayuki Maeda <takoyaki0316@gmail.com> | 2021-09-27 00:59:57 +0900 |
|---|---|---|
| committer | Takayuki Maeda <takoyaki0316@gmail.com> | 2021-09-27 00:59:57 +0900 |
| commit | 3bab36357cf21766b50946b64345f771ede0e2be (patch) | |
| tree | b0f659ca496b8f7aa82f4b6035432959c57a7604 | |
| parent | 3e41397ef22f15f5bf17c148384756a0f7dbd662 (diff) | |
| download | rust-3bab36357cf21766b50946b64345f771ede0e2be.tar.gz rust-3bab36357cf21766b50946b64345f771ede0e2be.zip | |
test suggesting immutable or mutable trait implementations
4 files changed, 82 insertions, 36 deletions
diff --git a/src/test/ui/suggestions/suggest-both-imm-and-mut-trait-implementation.rs b/src/test/ui/suggestions/suggest-both-imm-and-mut-trait-implementation.rs deleted file mode 100644 index 0a4f0b489fc..00000000000 --- a/src/test/ui/suggestions/suggest-both-imm-and-mut-trait-implementation.rs +++ /dev/null @@ -1,13 +0,0 @@ -trait Trait {} - -struct S; - -impl Trait for &S {} -impl Trait for &mut S {} - -fn foo<X: Trait>(_: X) {} - -fn main() { - let s = S; - foo(s); //~ ERROR the trait bound `S: Trait` is not satisfied -} diff --git a/src/test/ui/suggestions/suggest-both-imm-and-mut-trait-implementation.stderr b/src/test/ui/suggestions/suggest-both-imm-and-mut-trait-implementation.stderr deleted file mode 100644 index d31c1e6ccee..00000000000 --- a/src/test/ui/suggestions/suggest-both-imm-and-mut-trait-implementation.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0277]: the trait bound `S: Trait` is not satisfied - --> $DIR/suggest-both-imm-and-mut-trait-implementation.rs:12:9 - | -LL | foo(s); - | --- ^ expected an implementor of trait `Trait` - | | - | required by a bound introduced by this call - | -note: required by a bound in `foo` - --> $DIR/suggest-both-imm-and-mut-trait-implementation.rs:8:11 - | -LL | fn foo<X: Trait>(_: X) {} - | ^^^^^ required by this bound in `foo` -help: consider borrowing here - | -LL | foo(&s); - | + -LL | foo(&mut s); - | ++++ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/suggestions/suggest-imm-mut-trait-implementations.rs b/src/test/ui/suggestions/suggest-imm-mut-trait-implementations.rs new file mode 100644 index 00000000000..a62669d5b2d --- /dev/null +++ b/src/test/ui/suggestions/suggest-imm-mut-trait-implementations.rs @@ -0,0 +1,23 @@ +trait Trait {} + +struct A; +struct B; +struct C; + +impl Trait for &A {} +impl Trait for &mut A {} + +impl Trait for &B {} + +impl Trait for &mut C {} + +fn foo<X: Trait>(_: X) {} + +fn main() { + let a = A; + let b = B; + let c = C; + foo(a); //~ ERROR the trait bound `A: Trait` is not satisfied + foo(b); //~ ERROR the trait bound `B: Trait` is not satisfied + foo(c); //~ ERROR the trait bound `C: Trait` is not satisfied +} diff --git a/src/test/ui/suggestions/suggest-imm-mut-trait-implementations.stderr b/src/test/ui/suggestions/suggest-imm-mut-trait-implementations.stderr new file mode 100644 index 00000000000..6583cabe184 --- /dev/null +++ b/src/test/ui/suggestions/suggest-imm-mut-trait-implementations.stderr @@ -0,0 +1,59 @@ +error[E0277]: the trait bound `A: Trait` is not satisfied + --> $DIR/suggest-imm-mut-trait-implementations.rs:20:9 + | +LL | foo(a); + | --- ^ expected an implementor of trait `Trait` + | | + | required by a bound introduced by this call + | +note: required by a bound in `foo` + --> $DIR/suggest-imm-mut-trait-implementations.rs:14:11 + | +LL | fn foo<X: Trait>(_: X) {} + | ^^^^^ required by this bound in `foo` +help: consider borrowing here + | +LL | foo(&a); + | + +LL | foo(&mut a); + | ++++ + +error[E0277]: the trait bound `B: Trait` is not satisfied + --> $DIR/suggest-imm-mut-trait-implementations.rs:21:9 + | +LL | foo(b); + | --- ^ expected an implementor of trait `Trait` + | | + | required by a bound introduced by this call + | +note: required by a bound in `foo` + --> $DIR/suggest-imm-mut-trait-implementations.rs:14:11 + | +LL | fn foo<X: Trait>(_: X) {} + | ^^^^^ required by this bound in `foo` +help: consider borrowing here + | +LL | foo(&b); + | + + +error[E0277]: the trait bound `C: Trait` is not satisfied + --> $DIR/suggest-imm-mut-trait-implementations.rs:22:9 + | +LL | foo(c); + | --- ^ expected an implementor of trait `Trait` + | | + | required by a bound introduced by this call + | +note: required by a bound in `foo` + --> $DIR/suggest-imm-mut-trait-implementations.rs:14:11 + | +LL | fn foo<X: Trait>(_: X) {} + | ^^^^^ required by this bound in `foo` +help: consider mutably borrowing here + | +LL | foo(&mut c); + | ++++ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. |
