about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2025-07-10 17:34:39 +0000
committerEsteban Küber <esteban@kuber.com.ar>2025-07-10 17:34:39 +0000
commitd6924441cd2b49678fcaf7cdee4e4a0263b7bdbf (patch)
treeb966a39bb0b04f2db1ef84fdc378c9d9345c3784
parent0674eca2f0c4ac45b7cf1a66fd4df44dfc603e7e (diff)
downloadrust-d6924441cd2b49678fcaf7cdee4e4a0263b7bdbf.tar.gz
rust-d6924441cd2b49678fcaf7cdee4e4a0263b7bdbf.zip
Update test
-rw-r--r--tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.fixed14
-rw-r--r--tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.rs12
-rw-r--r--tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.stderr58
3 files changed, 70 insertions, 14 deletions
diff --git a/tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.fixed b/tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.fixed
index 95fd920dec2..00b92b42bb5 100644
--- a/tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.fixed
+++ b/tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.fixed
@@ -4,14 +4,24 @@ struct S;
 trait Trait {
     fn foo() {}
 }
-impl Trait for &S {}
 impl Trait for &mut S {}
+trait Trait2 {
+    fn bar() {}
+}
+impl Trait2 for &S {}
+impl Trait2 for &mut S {}
 fn main() {
     let _ = <&str>::from("value");
     //~^ ERROR the trait bound `str: From<_>` is not satisfied
     //~| ERROR the size for values of type `str` cannot be known at compilation time
     let _ = <&mut S>::foo();
     //~^ ERROR the trait bound `S: Trait` is not satisfied
-    let _ = <&S>::foo();
+    let _ = <&mut S>::foo();
+    //~^ ERROR the trait bound `S: Trait` is not satisfied
+    let _ = <&mut S>::foo();
     //~^ ERROR the trait bound `S: Trait` is not satisfied
+    let _ = <&mut S>::bar();
+    //~^ ERROR the trait bound `S: Trait2` is not satisfied
+    let _ = <&S>::bar();
+    //~^ ERROR the trait bound `S: Trait2` is not satisfied
 }
diff --git a/tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.rs b/tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.rs
index f79d2465062..3059ccdffb4 100644
--- a/tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.rs
+++ b/tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.rs
@@ -4,8 +4,12 @@ struct S;
 trait Trait {
     fn foo() {}
 }
-impl Trait for &S {}
 impl Trait for &mut S {}
+trait Trait2 {
+    fn bar() {}
+}
+impl Trait2 for &S {}
+impl Trait2 for &mut S {}
 fn main() {
     let _ = &str::from("value");
     //~^ ERROR the trait bound `str: From<_>` is not satisfied
@@ -14,4 +18,10 @@ fn main() {
     //~^ ERROR the trait bound `S: Trait` is not satisfied
     let _ = &S::foo();
     //~^ ERROR the trait bound `S: Trait` is not satisfied
+    let _ = S::foo();
+    //~^ ERROR the trait bound `S: Trait` is not satisfied
+    let _ = &mut S::bar();
+    //~^ ERROR the trait bound `S: Trait2` is not satisfied
+    let _ = &S::bar();
+    //~^ ERROR the trait bound `S: Trait2` is not satisfied
 }
diff --git a/tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.stderr b/tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.stderr
index ac96ec76da7..c2e2fe941a6 100644
--- a/tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.stderr
+++ b/tests/ui/suggestions/dont-suggest-borrowing-existing-borrow.stderr
@@ -1,5 +1,5 @@
 error[E0277]: the trait bound `str: From<_>` is not satisfied
-  --> $DIR/dont-suggest-borrowing-existing-borrow.rs:10:14
+  --> $DIR/dont-suggest-borrowing-existing-borrow.rs:14:14
    |
 LL |     let _ = &str::from("value");
    |              ^^^ the trait `From<_>` is not implemented for `str`
@@ -17,35 +17,71 @@ LL |     let _ = <&str>::from("value");
    |             +    +
 
 error[E0277]: the trait bound `S: Trait` is not satisfied
-  --> $DIR/dont-suggest-borrowing-existing-borrow.rs:13:18
+  --> $DIR/dont-suggest-borrowing-existing-borrow.rs:17:18
    |
 LL |     let _ = &mut S::foo();
    |                  ^ the trait `Trait` is not implemented for `S`
    |
-   = help: the following other types implement trait `Trait`:
-             &S
-             &mut S
+   = help: the trait `Trait` is implemented for `&mut S`
 help: you likely meant to call the associated function `foo` for type `&mut S`, but the code as written calls associated function `foo` on type `S`
    |
 LL |     let _ = <&mut S>::foo();
    |             +      +
 
 error[E0277]: the trait bound `S: Trait` is not satisfied
-  --> $DIR/dont-suggest-borrowing-existing-borrow.rs:15:14
+  --> $DIR/dont-suggest-borrowing-existing-borrow.rs:19:14
    |
 LL |     let _ = &S::foo();
    |              ^ the trait `Trait` is not implemented for `S`
    |
-   = help: the following other types implement trait `Trait`:
+   = help: the trait `Trait` is implemented for `&mut S`
+help: you likely meant to call the associated function `foo` for type `&S`, but the code as written calls associated function `foo` on type `S`
+   |
+LL -     let _ = &S::foo();
+LL +     let _ = <&mut S>::foo();
+   |
+
+error[E0277]: the trait bound `S: Trait` is not satisfied
+  --> $DIR/dont-suggest-borrowing-existing-borrow.rs:21:13
+   |
+LL |     let _ = S::foo();
+   |             ^ the trait `Trait` is not implemented for `S`
+   |
+help: consider mutably borrowing here
+   |
+LL |     let _ = <&mut S>::foo();
+   |             +++++  +
+
+error[E0277]: the trait bound `S: Trait2` is not satisfied
+  --> $DIR/dont-suggest-borrowing-existing-borrow.rs:23:18
+   |
+LL |     let _ = &mut S::bar();
+   |                  ^ the trait `Trait2` is not implemented for `S`
+   |
+   = help: the following other types implement trait `Trait2`:
              &S
              &mut S
-help: you likely meant to call the associated function `foo` for type `&S`, but the code as written calls associated function `foo` on type `S`
+help: you likely meant to call the associated function `bar` for type `&mut S`, but the code as written calls associated function `bar` on type `S`
+   |
+LL |     let _ = <&mut S>::bar();
+   |             +      +
+
+error[E0277]: the trait bound `S: Trait2` is not satisfied
+  --> $DIR/dont-suggest-borrowing-existing-borrow.rs:25:14
+   |
+LL |     let _ = &S::bar();
+   |              ^ the trait `Trait2` is not implemented for `S`
+   |
+   = help: the following other types implement trait `Trait2`:
+             &S
+             &mut S
+help: you likely meant to call the associated function `bar` for type `&S`, but the code as written calls associated function `bar` on type `S`
    |
-LL |     let _ = <&S>::foo();
+LL |     let _ = <&S>::bar();
    |             +  +
 
 error[E0277]: the size for values of type `str` cannot be known at compilation time
-  --> $DIR/dont-suggest-borrowing-existing-borrow.rs:10:14
+  --> $DIR/dont-suggest-borrowing-existing-borrow.rs:14:14
    |
 LL |     let _ = &str::from("value");
    |              ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
@@ -53,6 +89,6 @@ LL |     let _ = &str::from("value");
    = help: the trait `Sized` is not implemented for `str`
    = note: the return type of a function must have a statically known size
 
-error: aborting due to 4 previous errors
+error: aborting due to 7 previous errors
 
 For more information about this error, try `rustc --explain E0277`.