forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#73639 - ayazhafiz:i/73553, r=davidtwco
Change heuristic for determining range literal 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 rust-lang#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 rust-lang#73553
- Loading branch information
Showing
3 changed files
with
44 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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)); | ||
//~^ ERROR mismatched types | ||
demo(1..10); | ||
//~^ ERROR mismatched types | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/ui/range/issue-73553-misinterp-range-literal.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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`. |