-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #116284 - RalfJung:no-nan-match, r=<try>
make matching on NaN a hard error These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.
- Loading branch information
Showing
9 changed files
with
172 additions
and
85 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
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
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
32 changes: 32 additions & 0 deletions
32
tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/issue-6804-nan-match.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,32 @@ | ||
// Matching against NaN should result in an error | ||
#![feature(exclusive_range_pattern)] | ||
#![allow(unused)] | ||
#![allow(illegal_floating_point_literal_pattern)] | ||
|
||
const NAN: f64 = f64::NAN; | ||
|
||
fn main() { | ||
let x = NAN; | ||
match x { | ||
NAN => {}, //~ ERROR cannot use NaN in patterns | ||
_ => {}, | ||
}; | ||
|
||
match [x, 1.0] { | ||
[NAN, _] => {}, //~ ERROR cannot use NaN in patterns | ||
_ => {}, | ||
}; | ||
|
||
// Also cover range patterns | ||
match x { | ||
NAN..=1.0 => {}, //~ ERROR cannot use NaN in patterns | ||
//~^ ERROR lower range bound must be less than or equal to upper | ||
-1.0..=NAN => {}, //~ ERROR cannot use NaN in patterns | ||
//~^ ERROR lower range bound must be less than or equal to upper | ||
NAN.. => {}, //~ ERROR cannot use NaN in patterns | ||
//~^ ERROR lower range bound must be less than or equal to upper | ||
..NAN => {}, //~ ERROR cannot use NaN in patterns | ||
//~^ ERROR lower range bound must be less than upper | ||
_ => {}, | ||
}; | ||
} |
64 changes: 64 additions & 0 deletions
64
tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/issue-6804-nan-match.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,64 @@ | ||
error: cannot use NaN in patterns | ||
--> $DIR/issue-6804-nan-match.rs:11:9 | ||
| | ||
LL | NAN => {}, | ||
| ^^^ | ||
|
||
error: cannot use NaN in patterns | ||
--> $DIR/issue-6804-nan-match.rs:16:10 | ||
| | ||
LL | [NAN, _] => {}, | ||
| ^^^ | ||
|
||
error: cannot use NaN in patterns | ||
--> $DIR/issue-6804-nan-match.rs:22:9 | ||
| | ||
LL | NAN..=1.0 => {}, | ||
| ^^^ | ||
|
||
error[E0030]: lower range bound must be less than or equal to upper | ||
--> $DIR/issue-6804-nan-match.rs:22:9 | ||
| | ||
LL | NAN..=1.0 => {}, | ||
| ^^^ lower bound larger than upper bound | ||
|
||
error: cannot use NaN in patterns | ||
--> $DIR/issue-6804-nan-match.rs:24:16 | ||
| | ||
LL | -1.0..=NAN => {}, | ||
| ^^^ | ||
|
||
error[E0030]: lower range bound must be less than or equal to upper | ||
--> $DIR/issue-6804-nan-match.rs:24:9 | ||
| | ||
LL | -1.0..=NAN => {}, | ||
| ^^^^ lower bound larger than upper bound | ||
|
||
error: cannot use NaN in patterns | ||
--> $DIR/issue-6804-nan-match.rs:26:9 | ||
| | ||
LL | NAN.. => {}, | ||
| ^^^ | ||
|
||
error[E0030]: lower range bound must be less than or equal to upper | ||
--> $DIR/issue-6804-nan-match.rs:26:9 | ||
| | ||
LL | NAN.. => {}, | ||
| ^^^ lower bound larger than upper bound | ||
|
||
error: cannot use NaN in patterns | ||
--> $DIR/issue-6804-nan-match.rs:28:11 | ||
| | ||
LL | ..NAN => {}, | ||
| ^^^ | ||
|
||
error[E0579]: lower range bound must be less than upper | ||
--> $DIR/issue-6804-nan-match.rs:28:9 | ||
| | ||
LL | ..NAN => {}, | ||
| ^^^^^ | ||
|
||
error: aborting due to 10 previous errors | ||
|
||
Some errors have detailed explanations: E0030, E0579. | ||
For more information about an error, try `rustc --explain E0030`. |
21 changes: 0 additions & 21 deletions
21
tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/issue-6804.rs
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/issue-6804.stderr
This file was deleted.
Oops, something went wrong.