Skip to content

Suggest adding & for "mismatched types: expected reference &&[&str], found reference &[&str]" #78613

Description

@camelid

This code can be easily fixed by adding an & in the call to contains.

fn main() {
    let haystack = [&["A1", "A2"][..], &["B1", "B2"], &["C1", "C2"]];
    let needle: &[&str] = &["D1", "D2"];
    println!("{}", haystack.contains(needle));
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/main.rs:4:38
  |
4 |     println!("{}", haystack.contains(needle));
  |                                      ^^^^^^ expected `&[&str]`, found slice `[&str]`
  |
  = note: expected reference `&&[&str]`
             found reference `&[&str]`

error: aborting due to previous error

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

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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