Code
use std::borrow::Borrow;
fn foo(_v: impl IntoIterator<Item = impl Borrow<str>>) {}
fn main() {
foo(&[String::from("a")]);
}
Current output
Compiling test-borrow v0.1.0 (/tmp/test-borrow)
error[E0277]: the trait bound `&String: Borrow<str>` is not satisfied
--> src/main.rs:6:5
|
6 | foo(&[String::from("a")]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Borrow<str>` is not implemented for `&String`
|
note: required by a bound in `foo`
--> src/main.rs:3:42
|
3 | fn foo(_v: impl IntoIterator<Item = impl Borrow<str>>) {}
| ^^^^^^^^^^^ required by this bound in `foo`
help: consider borrowing here
|
6 | &foo(&[String::from("a")]);
| +
For more information about this error, try `rustc --explain E0277`.
error: could not compile `test-borrow` (bin "test-borrow") due to 1 previous error
Desired output
Compiling test-borrow v0.1.0 (/tmp/test-borrow)
error[E0277]: the trait bound `&String: Borrow<str>` is not satisfied
--> src/main.rs:6:5
|
6 | foo(&[String::from("a")]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Borrow<str>` is not implemented for `&String`
|
note: required by a bound in `foo`
--> src/main.rs:3:42
|
3 | fn foo(_v: impl IntoIterator<Item = impl Borrow<str>>) {}
| ^^^^^^^^^^^ required by this bound in `foo`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `test-borrow` (bin "test-borrow") due to 1 previous error
Rationale and extra context
If you apply the suggestion, it keeps suggestion adding more &'s:
help: consider borrowing here
|
6 | &&foo(&[String::from("a")]);
| +
help: consider borrowing here
|
6 | &&&foo(&[String::from("a")]);
| +
help: consider borrowing here
|
6 | &&&&foo(&[String::from("a")]);
| +
Other cases
Rust Version
$ rustc --version --verbose
rustc 1.94.1 (e408947bf 2026-03-25)
binary: rustc
commit-hash: e408947bfd200af42db322daf0fadfe7e26d3bd1
commit-date: 2026-03-25
host: x86_64-unknown-linux-gnu
release: 1.94.1
LLVM version: 21.1.8
$ rustc +nightly --version --verbose
rustc 1.96.0-nightly (f5eca4fcf 2026-04-09)
binary: rustc
commit-hash: f5eca4fcfa908d1e038afd19c6e746f075859130
commit-date: 2026-04-09
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.2
Anything else?
No response
Code
Current output
Desired output
Rationale and extra context
If you apply the suggestion, it keeps suggestion adding more
&'s:Other cases
Rust Version
Anything else?
No response