-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-inferenceArea: Type inferenceArea: Type inferenceT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Description: compiler can't infer &str type when String is inserted first in a collection with tuples.
Steps to reproduce: create a new array and fill it with tuples, where one of the elements is a string literal and one is a variable of type &String
. Depending one the order, it might or might not compile because type can't be inferred.
let s = &String::from("foo");
let arr1 = [(1, s), (2, "bar")]; // This line contains a compilation error
let arr2 = [(2, "bar"), (1, s)]; // Does compile; inferred type is [(i32, &str); 2]
Error message:
error[E0308]: mismatched types
|
| let arr1 = [(1, s), (2, "bar")];
| ^^^^^ expected `&String`, found `&str`
|
= note: expected reference `&String`
found reference `&'static str`
Rust compiler version: rustc 1.80.1 (3f5fd8dd4 2024-08-06)
Metadata
Metadata
Assignees
Labels
A-inferenceArea: Type inferenceArea: Type inferenceT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.