Skip to content

Commit

Permalink
test suggesting immutable or mutable trait implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
TaKO8Ki committed Sep 26, 2021
1 parent 3e41397 commit 3bab363
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 36 deletions.

This file was deleted.

This file was deleted.

23 changes: 23 additions & 0 deletions 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
}
@@ -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`.

0 comments on commit 3bab363

Please sign in to comment.