Rollup merge of #88090 - nbdd0121:inference, r=nikomatsakis
Perform type inference in range pattern Fix #88074
This commit is contained in:
commit
4f6afee4e5
6 changed files with 109 additions and 28 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -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
src/test/ui/pattern/issue-88074-pat-range-type-inference.rs
Normal file
16
src/test/ui/pattern/issue-88074-pat-range-type-inference.rs
Normal file
|
|
@ -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 => {},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,6 @@ enum_number!(Change {
|
|||
Neg = -1,
|
||||
Arith = 1 + 1, //~ ERROR arbitrary expressions aren't allowed in patterns
|
||||
//~| ERROR arbitrary expressions aren't allowed in patterns
|
||||
//~| ERROR only `char` and numeric types are allowed in range patterns
|
||||
});
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -10,15 +10,5 @@ error: arbitrary expressions aren't allowed in patterns
|
|||
LL | Arith = 1 + 1,
|
||||
| ^^^^^
|
||||
|
||||
error[E0029]: only `char` and numeric types are allowed in range patterns
|
||||
--> $DIR/patkind-litrange-no-expr.rs:20:13
|
||||
|
|
||||
LL | $( $value ..= 42 => Some($name::$variant), )* // PatKind::Range
|
||||
| -- this is of type `{integer}`
|
||||
...
|
||||
LL | Arith = 1 + 1,
|
||||
| ^^^^^ this is of type `_` but it should be `char` or numeric
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0029`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue