Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

confusing output when using String::from::utf8 instead of String::from_utf8 #109195

Closed
matthiaskrgr opened this issue Mar 15, 2023 · 2 comments · Fixed by #120632
Closed

confusing output when using String::from::utf8 instead of String::from_utf8 #109195

matthiaskrgr opened this issue Mar 15, 2023 · 2 comments · Fixed by #120632
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution D-confusing Diagnostics: Confusing error or lint that should be reworked. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Mar 15, 2023

Code

`
    pub(crate) fn to_disk(&self) {
        let original_path = self.file.clone();
        let original_path_display = original_path.display();
        let original_code = std::fs::read_to_string(&original_path).unwrap_or("<error>".into());

        let executable = self.executable.clone();
        let executable_bin = self.executable.path();

        let output: String = if let Ok(output) = std::process::Command::new(&executable_bin)
            .arg("--version")
            .arg("--verbose")
            .output()
        {
            String::from::utf8(output.stdout).unwrap()
        } else if let Ok(output_verbose) = std::process::Command::new(&executable_bin)
            .arg("--version")
            .output()
        {
            String::from::utf8(output_verbose.stdout).unwrap()
        } else {
            "<failed to get version>".to_string()
        };

        let test = format!(
            "
        File: {original_path_display}
        `
        {original_code}
        ````
        
        
        "
        );
    }


### Current output

```Shell
error[E0223]: ambiguous associated type
   --> src/ice.rs:125:13
    |
125 |             String::from::utf8(output.stdout).unwrap()
    |             ^^^^^^^^^^^^
    |
help: if there were a trait named `Example` with associated type `from` implemented for `std::string::String`, you could use the fully-qualified path
    |
125 |             <std::string::String as Example>::from::utf8(output.stdout).unwrap()
    |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0223]: ambiguous associated type
   --> src/ice.rs:130:13
    |
130 |             String::from::utf8(output_verbose.stdout).unwrap()
    |             ^^^^^^^^^^^^
    |
help: if there were a trait named `Example` with associated type `from` implemented for `std::string::String`, you could use the fully-qualified path
    |
130 |             <std::string::String as Example>::from::utf8(output_verbose.stdout).unwrap()
    |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Desired output

Item `String::from::utf8` not found, did you mean similar similar function `String::from_utf8` which also happens to return the desired target type?

Rationale and extra context

This had me VERY confused as I was certain I would try to get a String here, where does Example come from?? And associated types wut??

The problem is I used String::from::utf8 which should have been String::from_utf8 :D

Maybe rustc could improve its suggestion somehow in that case?

Other cases

No response

Anything else?

No response

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 15, 2023
@WaffleLapkin
Copy link
Member

WaffleLapkin commented Mar 30, 2023

For reference, here is a MRE:

fn main() {
    String::from::utf8;
}
error[E0223]: ambiguous associated type
 --> src/main.rs:2:5
  |
2 |     String::from::utf8;
  |     ^^^^^^^^^^^^
  |
help: if there were a trait named `Example` with associated type `from` implemented for `String`, you could use the fully-qualified path
  |
2 |     <String as Example>::from::utf8;
  |     ~~~~~~~~~~~~~~~~~~~~~~~~~

@WaffleLapkin WaffleLapkin added A-resolve Area: Name resolution D-confusing Diagnostics: Confusing error or lint that should be reworked. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue labels Mar 30, 2023
@trevyn
Copy link
Contributor

trevyn commented Feb 2, 2024

@rustbot claim

@bors bors closed this as completed in eae477d Feb 6, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 6, 2024
Rollup merge of rust-lang#120632 - trevyn:issue-109195, r=oli-obk

For E0223, suggest associated functions that are similar to the path

e.g. for `String::from::utf8`, suggest `String::from_utf8`

Closes rust-lang#109195
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution D-confusing Diagnostics: Confusing error or lint that should be reworked. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants