Currently, rustc uses a heuristic to determine if a range expression is not a literal based on whether the expression looks like a function call or struct initialization. This fails for range literals whose lower/upper bounds are the results of function calls. A possibly-better heuristic is to check if the expression contains `..`, required in range literals. Of course, this is also not perfect; for example, if the range expression is a struct which includes some text with `..` this will fail, but in general I believe it is a better heuristic. A better alternative altogether is to add the `QPath::LangItem` enum variant suggested in #60607. I would be happy to do this as a precursor to this patch if someone is able to provide general suggestions on how usages of `QPath` need to be changed later in the compiler with the `LangItem` variant. Closes #73553
28 lines
926 B
Plaintext
28 lines
926 B
Plaintext
error[E0308]: mismatched types
|
|
--> $DIR/issue-73553-misinterp-range-literal.rs:12:10
|
|
|
|
|
LL | demo(tell(1)..tell(10));
|
|
| ^^^^^^^^^^^^^^^^^
|
|
| |
|
|
| expected reference, found struct `std::ops::Range`
|
|
| help: consider borrowing here: `&(tell(1)..tell(10))`
|
|
|
|
|
= note: expected reference `&std::ops::Range<usize>`
|
|
found struct `std::ops::Range<usize>`
|
|
|
|
error[E0308]: mismatched types
|
|
--> $DIR/issue-73553-misinterp-range-literal.rs:14:10
|
|
|
|
|
LL | demo(1..10);
|
|
| ^^^^^
|
|
| |
|
|
| expected reference, found struct `std::ops::Range`
|
|
| help: consider borrowing here: `&(1..10)`
|
|
|
|
|
= note: expected reference `&std::ops::Range<usize>`
|
|
found struct `std::ops::Range<{integer}>`
|
|
|
|
error: aborting due to 2 previous errors
|
|
|
|
For more information about this error, try `rustc --explain E0308`.
|