-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #88090 - nbdd0121:inference, r=nikomatsakis
Perform type inference in range pattern Fix #88074
- Loading branch information
Showing
6 changed files
with
109 additions
and
28 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
28 changes: 28 additions & 0 deletions
28
src/test/ui/pattern/issue-88074-pat-range-type-inference-err.rs
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,28 @@ | ||
trait Zero { | ||
const ZERO: Self; | ||
} | ||
|
||
impl Zero for String { | ||
const ZERO: Self = String::new(); | ||
} | ||
|
||
fn foo() { | ||
match String::new() { | ||
Zero::ZERO ..= Zero::ZERO => {}, | ||
//~^ ERROR only `char` and numeric types are allowed in range patterns | ||
_ => {}, | ||
} | ||
} | ||
|
||
fn bar() { | ||
match Zero::ZERO { | ||
Zero::ZERO ..= Zero::ZERO => {}, | ||
//~^ ERROR type annotations needed [E0282] | ||
_ => {}, | ||
} | ||
} | ||
|
||
fn main() { | ||
foo(); | ||
bar(); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/pattern/issue-88074-pat-range-type-inference-err.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,21 @@ | ||
error[E0029]: only `char` and numeric types are allowed in range patterns | ||
--> $DIR/issue-88074-pat-range-type-inference-err.rs:11:9 | ||
| | ||
LL | Zero::ZERO ..= Zero::ZERO => {}, | ||
| ----------^^^^^---------- | ||
| | | | ||
| | this is of type `String` but it should be `char` or numeric | ||
| this is of type `String` but it should be `char` or numeric | ||
|
||
error[E0282]: type annotations needed | ||
--> $DIR/issue-88074-pat-range-type-inference-err.rs:19:9 | ||
| | ||
LL | Zero::ZERO ..= Zero::ZERO => {}, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type | ||
| | ||
= note: type must be known at this point | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0029, E0282. | ||
For more information about an error, try `rustc --explain E0029`. |
16 changes: 16 additions & 0 deletions
16
src/test/ui/pattern/issue-88074-pat-range-type-inference.rs
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 @@ | ||
// check-pass | ||
|
||
trait Zero { | ||
const ZERO: Self; | ||
} | ||
|
||
impl Zero for i32 { | ||
const ZERO: Self = 0; | ||
} | ||
|
||
fn main() { | ||
match 1 { | ||
Zero::ZERO ..= 1 => {}, | ||
_ => {}, | ||
} | ||
} |
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