Closed
Description
Hi there!
With this code (here's a playground)
type Range = std::ops::Range<usize>;
fn demo(r: &Range) {
println!("{:?}", r);
}
fn tell(x: usize) -> usize {
x
}
fn main() {
demo(tell(1)..tell(10)); // here, it is reported wrongly!
demo(1..10); // here, it is reported correctly!
}
The compiler reports this error message with a hint
error[E0308]: mismatched types
--> src/main.rs:13:10
|
13 | demo(tell(1)..tell(10)); // here, it is reported wrongly!
| ^^^^^^^^^^^^^^^^^
| |
| 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>`
but the hint is incorrect due to missing parantheses in this case. The correct answer would be
| help: consider borrowing here: `&(tell(1)..tell(10))`
It works correctly when the second line in main is executed, where the range is provided directly.
Meta
rustc --version --verbose
:
1.44.1
This issue has been assigned to @ayazhafiz via this comment.