Skip to content

No turbofish suggestion for complex expressions #81816

Description

@tesuji

The turbofish suggestions are displayed for single expressions, but not for complex expressions. https://rust.godbolt.org/z/cbn58f

I tried this code:

use std::sync::Arc;
use std::sync::RwLock;

fn main() {
    let uuid = Arc::new(RwLock::new(std::collections::HashMap<i32, i64>::new()));
}

I expected to see this happen: Turbofish ::<> suggestion for HashMap type.
Instead, this happened: Invalid suggestion to use private field to initialize HashMap.

error[E0423]: expected value, found struct `std::collections::HashMap`
   --> <source>:5:37
    |
5   |       let uuid = Arc::new(RwLock::new(std::collections::HashMap<i32, i64>::new()));
    |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `std::collections::HashMap { base: val }`

error[E0423]: expected value, found builtin type `i32`
 --> <source>:5:63
  |
5 |     let uuid = Arc::new(RwLock::new(std::collections::HashMap<i32, i64>::new()));
  |                                                               ^^^ not a value

Meta

rustc --version --verbose: rustc 1.51.0-nightly (e708cbd 2021-02-03)

@rustbot label A-diagnostics D-confusing D-incorrect T-compiler D-invalid-suggestion

*This issue was detected by an user on Reddit: https://www.reddit.com/r/rust/comments/ld6q8u/bastion_of_the_turbofish_a_brief_tale_lamenting/gm5j0yz/.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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