Skip to content

Error message ascii art pointer / arrow points to wrong argument #85681

Description

@mkmik

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=8b21d823468da1cb8ba7442d8b4e0e85

fn foo(x: u32, a: impl Into<String>, y: u32, b: impl Into<String>) {
    println!("fox: a={}, b={}", a.into(), b.into());
}

fn main() {
    let bar: String = "bar".to_string();
    let baz: &str = "baz";

    for (a, b) in &[(&bar, baz)] {
        let a: &String = a;
        foo(42, a, 43, b);
    }
}

The current output is:

/Users/mkm/.cargo/bin/cargo play --cargo-option=--color=always /var/folders/zp/pk0v2q4x39z43k91vst1_jsc0000gn/T/scratch.rs
   Compiling p3ofvf9avhdc8sbzh9blgjf7wwnoz v0.1.0 (/var/folders/zp/pk0v2q4x39z43k91vst1_jsc0000gn/T/cargo-play.3oFVf9AvHdC8sbzH9BLGJf7wwnoz)
error[E0277]: the trait bound `String: From<&&str>` is not satisfied
  --> src/main.rs:11:17
   |
1  | fn foo(x: u32, a: impl Into<String>, y: u32, b: impl Into<String>) {
   |                                                      ------------ required by this bound in `foo`
...
11 |         foo(42, a, 43, b);
   |                 ^ the trait `From<&&str>` is not implemented for `String`
   |
   = help: the following implementations were found:
             <String as From<&String>>
             <String as From<&mut str>>
             <String as From<&str>>
             <String as From<Box<str>>>
           and 2 others
   = note: required because of the requirements on the impl of `Into<String>` for `&&str`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `p3ofvf9avhdc8sbzh9blgjf7wwnoz`

To learn more, run the command again with --verbose.

Ideally the output should look like:

/Users/mkm/.cargo/bin/cargo play --cargo-option=--color=always /var/folders/zp/pk0v2q4x39z43k91vst1_jsc0000gn/T/scratch.rs
   Compiling p3ofvf9avhdc8sbzh9blgjf7wwnoz v0.1.0 (/var/folders/zp/pk0v2q4x39z43k91vst1_jsc0000gn/T/cargo-play.3oFVf9AvHdC8sbzH9BLGJf7wwnoz)
error[E0277]: the trait bound `String: From<&&str>` is not satisfied
  --> src/main.rs:11:17
   |
1  | fn foo(x: u32, a: impl Into<String>, y: u32, b: impl Into<String>) {
   |                                                      ------------ required by this bound in `foo`
...
11 |         foo(42, a, 43, b);
   |                        ^ the trait `From<&&str>` is not implemented for `String`
   |
   = help: the following implementations were found:
             <String as From<&String>>
             <String as From<&mut str>>
             <String as From<&str>>
             <String as From<Box<str>>>
           and 2 others
   = note: required because of the requirements on the impl of `Into<String>` for `&&str`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `p3ofvf9avhdc8sbzh9blgjf7wwnoz`

To learn more, run the command again with --verbose.

I tried on stable (1.52.1) , beta and nightly (on rust playground and locally).

It seems to confuse only when there are multiple arguments of the same type (e.g. the impl Into<String> here.
I didn't try with other types.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions