From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../ui/traits/suggest-deferences/issue-39029.fixed | 18 ++++++++ .../ui/traits/suggest-deferences/issue-39029.rs | 18 ++++++++ .../traits/suggest-deferences/issue-39029.stderr | 20 ++++++++ .../ui/traits/suggest-deferences/issue-62530.fixed | 15 ++++++ .../ui/traits/suggest-deferences/issue-62530.rs | 15 ++++++ .../traits/suggest-deferences/issue-62530.stderr | 19 ++++++++ .../ui/traits/suggest-deferences/multiple-0.fixed | 36 +++++++++++++++ .../ui/traits/suggest-deferences/multiple-0.rs | 36 +++++++++++++++ .../ui/traits/suggest-deferences/multiple-0.stderr | 19 ++++++++ .../ui/traits/suggest-deferences/multiple-1.rs | 54 ++++++++++++++++++++++ .../ui/traits/suggest-deferences/multiple-1.stderr | 18 ++++++++ .../suggest-deferences/root-obligation.fixed | 13 ++++++ .../traits/suggest-deferences/root-obligation.rs | 13 ++++++ .../suggest-deferences/root-obligation.stderr | 24 ++++++++++ 14 files changed, 318 insertions(+) create mode 100644 src/test/ui/traits/suggest-deferences/issue-39029.fixed create mode 100644 src/test/ui/traits/suggest-deferences/issue-39029.rs create mode 100644 src/test/ui/traits/suggest-deferences/issue-39029.stderr create mode 100644 src/test/ui/traits/suggest-deferences/issue-62530.fixed create mode 100644 src/test/ui/traits/suggest-deferences/issue-62530.rs create mode 100644 src/test/ui/traits/suggest-deferences/issue-62530.stderr create mode 100644 src/test/ui/traits/suggest-deferences/multiple-0.fixed create mode 100644 src/test/ui/traits/suggest-deferences/multiple-0.rs create mode 100644 src/test/ui/traits/suggest-deferences/multiple-0.stderr create mode 100644 src/test/ui/traits/suggest-deferences/multiple-1.rs create mode 100644 src/test/ui/traits/suggest-deferences/multiple-1.stderr create mode 100644 src/test/ui/traits/suggest-deferences/root-obligation.fixed create mode 100644 src/test/ui/traits/suggest-deferences/root-obligation.rs create mode 100644 src/test/ui/traits/suggest-deferences/root-obligation.stderr (limited to 'src/test/ui/traits/suggest-deferences') diff --git a/src/test/ui/traits/suggest-deferences/issue-39029.fixed b/src/test/ui/traits/suggest-deferences/issue-39029.fixed new file mode 100644 index 000000000..a1abf668b --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/issue-39029.fixed @@ -0,0 +1,18 @@ +// run-rustfix +use std::net::TcpListener; + +struct NoToSocketAddrs(String); + +impl std::ops::Deref for NoToSocketAddrs { + type Target = String; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +fn main() { + let _works = TcpListener::bind("some string"); + let bad = NoToSocketAddrs("bad".to_owned()); + let _errors = TcpListener::bind(&*bad); + //~^ ERROR the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied +} diff --git a/src/test/ui/traits/suggest-deferences/issue-39029.rs b/src/test/ui/traits/suggest-deferences/issue-39029.rs new file mode 100644 index 000000000..90d097105 --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/issue-39029.rs @@ -0,0 +1,18 @@ +// run-rustfix +use std::net::TcpListener; + +struct NoToSocketAddrs(String); + +impl std::ops::Deref for NoToSocketAddrs { + type Target = String; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +fn main() { + let _works = TcpListener::bind("some string"); + let bad = NoToSocketAddrs("bad".to_owned()); + let _errors = TcpListener::bind(&bad); + //~^ ERROR the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied +} diff --git a/src/test/ui/traits/suggest-deferences/issue-39029.stderr b/src/test/ui/traits/suggest-deferences/issue-39029.stderr new file mode 100644 index 000000000..5c324cd38 --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/issue-39029.stderr @@ -0,0 +1,20 @@ +error[E0277]: the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied + --> $DIR/issue-39029.rs:16:37 + | +LL | let _errors = TcpListener::bind(&bad); + | ----------------- ^^^^ + | | | + | | the trait `ToSocketAddrs` is not implemented for `NoToSocketAddrs` + | | help: consider dereferencing here: `&*bad` + | required by a bound introduced by this call + | + = note: required because of the requirements on the impl of `ToSocketAddrs` for `&NoToSocketAddrs` +note: required by a bound in `TcpListener::bind` + --> $SRC_DIR/std/src/net/tcp.rs:LL:COL + | +LL | pub fn bind(addr: A) -> io::Result { + | ^^^^^^^^^^^^^ required by this bound in `TcpListener::bind` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/traits/suggest-deferences/issue-62530.fixed b/src/test/ui/traits/suggest-deferences/issue-62530.fixed new file mode 100644 index 000000000..406caaa00 --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/issue-62530.fixed @@ -0,0 +1,15 @@ +// run-rustfix +fn takes_str(_x: &str) {} + +fn takes_type_parameter(_x: T) where T: SomeTrait {} + +trait SomeTrait {} +impl SomeTrait for &'_ str {} +impl SomeTrait for char {} + +fn main() { + let string = String::new(); + takes_str(&string); // Ok + takes_type_parameter(&*string); // Error + //~^ ERROR the trait bound `&String: SomeTrait` is not satisfied +} diff --git a/src/test/ui/traits/suggest-deferences/issue-62530.rs b/src/test/ui/traits/suggest-deferences/issue-62530.rs new file mode 100644 index 000000000..53846be73 --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/issue-62530.rs @@ -0,0 +1,15 @@ +// run-rustfix +fn takes_str(_x: &str) {} + +fn takes_type_parameter(_x: T) where T: SomeTrait {} + +trait SomeTrait {} +impl SomeTrait for &'_ str {} +impl SomeTrait for char {} + +fn main() { + let string = String::new(); + takes_str(&string); // Ok + takes_type_parameter(&string); // Error + //~^ ERROR the trait bound `&String: SomeTrait` is not satisfied +} diff --git a/src/test/ui/traits/suggest-deferences/issue-62530.stderr b/src/test/ui/traits/suggest-deferences/issue-62530.stderr new file mode 100644 index 000000000..d129328da --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/issue-62530.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `&String: SomeTrait` is not satisfied + --> $DIR/issue-62530.rs:13:26 + | +LL | takes_type_parameter(&string); // Error + | -------------------- ^^^^^^^ + | | | + | | the trait `SomeTrait` is not implemented for `&String` + | | help: consider dereferencing here: `&*string` + | required by a bound introduced by this call + | +note: required by a bound in `takes_type_parameter` + --> $DIR/issue-62530.rs:4:44 + | +LL | fn takes_type_parameter(_x: T) where T: SomeTrait {} + | ^^^^^^^^^ required by this bound in `takes_type_parameter` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/traits/suggest-deferences/multiple-0.fixed b/src/test/ui/traits/suggest-deferences/multiple-0.fixed new file mode 100644 index 000000000..b7160b75c --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/multiple-0.fixed @@ -0,0 +1,36 @@ +// run-rustfix +use std::ops::Deref; + +trait Happy {} +struct LDM; +impl Happy for &LDM {} + +struct Foo(LDM); +struct Bar(Foo); +struct Baz(Bar); +impl Deref for Foo { + type Target = LDM; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl Deref for Bar { + type Target = Foo; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl Deref for Baz { + type Target = Bar; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +fn foo(_: T) where T: Happy {} + +fn main() { + let baz = Baz(Bar(Foo(LDM))); + foo(&***baz); + //~^ ERROR the trait bound `&Baz: Happy` is not satisfied +} diff --git a/src/test/ui/traits/suggest-deferences/multiple-0.rs b/src/test/ui/traits/suggest-deferences/multiple-0.rs new file mode 100644 index 000000000..9ac55177f --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/multiple-0.rs @@ -0,0 +1,36 @@ +// run-rustfix +use std::ops::Deref; + +trait Happy {} +struct LDM; +impl Happy for &LDM {} + +struct Foo(LDM); +struct Bar(Foo); +struct Baz(Bar); +impl Deref for Foo { + type Target = LDM; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl Deref for Bar { + type Target = Foo; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl Deref for Baz { + type Target = Bar; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +fn foo(_: T) where T: Happy {} + +fn main() { + let baz = Baz(Bar(Foo(LDM))); + foo(&baz); + //~^ ERROR the trait bound `&Baz: Happy` is not satisfied +} diff --git a/src/test/ui/traits/suggest-deferences/multiple-0.stderr b/src/test/ui/traits/suggest-deferences/multiple-0.stderr new file mode 100644 index 000000000..efb3c7d12 --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/multiple-0.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `&Baz: Happy` is not satisfied + --> $DIR/multiple-0.rs:34:9 + | +LL | foo(&baz); + | --- ^^^^ + | | | + | | the trait `Happy` is not implemented for `&Baz` + | | help: consider dereferencing here: `&***baz` + | required by a bound introduced by this call + | +note: required by a bound in `foo` + --> $DIR/multiple-0.rs:30:26 + | +LL | fn foo(_: T) where T: Happy {} + | ^^^^^ required by this bound in `foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/traits/suggest-deferences/multiple-1.rs b/src/test/ui/traits/suggest-deferences/multiple-1.rs new file mode 100644 index 000000000..91c6c7924 --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/multiple-1.rs @@ -0,0 +1,54 @@ +use std::ops::{Deref, DerefMut}; + +trait Happy {} +struct LDM; +impl Happy for &mut LDM {} + +struct Foo(LDM); +struct Bar(Foo); +struct Baz(Bar); +impl Deref for Foo { + type Target = LDM; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl Deref for Bar { + type Target = Foo; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl Deref for Baz { + type Target = Bar; + fn deref(&self) -> &Self::Target { + &self.0 + } +} +impl DerefMut for Foo { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} +impl DerefMut for Bar { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} +impl DerefMut for Baz { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + + +fn foo(_: T) where T: Happy {} + +fn main() { + // Currently the compiler doesn't try to suggest dereferences for situations + // where DerefMut involves. So this test is meant to ensure compiler doesn't + // generate incorrect help message. + let mut baz = Baz(Bar(Foo(LDM))); + foo(&mut baz); + //~^ ERROR the trait bound `&mut Baz: Happy` is not satisfied +} diff --git a/src/test/ui/traits/suggest-deferences/multiple-1.stderr b/src/test/ui/traits/suggest-deferences/multiple-1.stderr new file mode 100644 index 000000000..6e12321c2 --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/multiple-1.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `&mut Baz: Happy` is not satisfied + --> $DIR/multiple-1.rs:52:9 + | +LL | foo(&mut baz); + | --- ^^^^^^^^ the trait `Happy` is not implemented for `&mut Baz` + | | + | required by a bound introduced by this call + | + = help: the trait `Happy` is implemented for `&mut LDM` +note: required by a bound in `foo` + --> $DIR/multiple-1.rs:45:26 + | +LL | fn foo(_: T) where T: Happy {} + | ^^^^^ required by this bound in `foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/traits/suggest-deferences/root-obligation.fixed b/src/test/ui/traits/suggest-deferences/root-obligation.fixed new file mode 100644 index 000000000..7a8433f90 --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/root-obligation.fixed @@ -0,0 +1,13 @@ +// run-rustfix + +fn get_vowel_count(string: &str) -> usize { + string + .chars() + .filter(|c| "aeiou".contains(*c)) + //~^ ERROR expected a `Fn<(char,)>` closure, found `char` + .count() +} + +fn main() { + let _ = get_vowel_count("asdf"); +} diff --git a/src/test/ui/traits/suggest-deferences/root-obligation.rs b/src/test/ui/traits/suggest-deferences/root-obligation.rs new file mode 100644 index 000000000..51bac2107 --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/root-obligation.rs @@ -0,0 +1,13 @@ +// run-rustfix + +fn get_vowel_count(string: &str) -> usize { + string + .chars() + .filter(|c| "aeiou".contains(c)) + //~^ ERROR expected a `Fn<(char,)>` closure, found `char` + .count() +} + +fn main() { + let _ = get_vowel_count("asdf"); +} diff --git a/src/test/ui/traits/suggest-deferences/root-obligation.stderr b/src/test/ui/traits/suggest-deferences/root-obligation.stderr new file mode 100644 index 000000000..16e03e79c --- /dev/null +++ b/src/test/ui/traits/suggest-deferences/root-obligation.stderr @@ -0,0 +1,24 @@ +error[E0277]: expected a `Fn<(char,)>` closure, found `char` + --> $DIR/root-obligation.rs:6:38 + | +LL | .filter(|c| "aeiou".contains(c)) + | -------- ^ expected an `Fn<(char,)>` closure, found `char` + | | + | required by a bound introduced by this call + | + = help: the trait `Fn<(char,)>` is not implemented for `char` + = note: required because of the requirements on the impl of `FnOnce<(char,)>` for `&char` + = note: required because of the requirements on the impl of `Pattern<'_>` for `&char` +note: required by a bound in `core::str::::contains` + --> $SRC_DIR/core/src/str/mod.rs:LL:COL + | +LL | pub fn contains<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool { + | ^^^^^^^^^^^ required by this bound in `core::str::::contains` +help: consider dereferencing here + | +LL | .filter(|c| "aeiou".contains(*c)) + | + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. -- cgit v1.2.3