Skip to content

Incorrect help suggestion when attempting "arc" as Arc<str> #135412

Closed
@totbuae

Description

@totbuae

Code

fn main() {
    use std::sync::Arc;

    let _a = "arc" as Arc<str>;
}

Current output

error[E0605]: non-primitive cast: `&'static str` as `Arc<str>`
 --> main.rs:4:14
  |
4 |     let _a = "arc" as Arc<str>;
  |              ^^^^^^^^^^^^^^^^^ help: consider using the `From` trait instead: `Arc<str>::from("arc")`
  |
  = note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0605`.

Desired output

error[E0605]: non-primitive cast: `&'static str` as `Arc<str>`
 --> main.rs:4:14
  |
4 |     let _a = "arc" as Arc<str>;
  |              ^^^^^^^^^^^^^^^^^ help: consider using the `From` trait instead: `Arc::<str>::from("arc")`
  |
  = note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0605`.

Rationale and extra context

The compiler suggests:
help: consider using the From trait instead: Arc<str>::from("arc")

when it should be:
help: consider using the From trait instead: Arc::<str>::from("arc")

There's a :: missing to complete the turbofish.

Other cases

Rust Version

rustc 1.84.0 (9fc6b4312 2025-01-07)
binary: rustc
commit-hash: 9fc6b43126469e3858e2fe86cafb4f0fd5068869
commit-date: 2025-01-07
host: x86_64-unknown-linux-gnu
release: 1.84.0
LLVM version: 19.1.5

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.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