Skip to content

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

Closed
@matthiaskrgr

Description

@matthiaskrgr

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyD-confusingDiagnostics: Confusing error or lint that should be reworked.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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