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.
Account for
for<'a>
types when checking for non-structural type in …
…constant as pattern When we encounter a constant in a pattern, we check if it is non-structural. If so, we check if the type implements `PartialEq`, but for types with escaping bound vars the check would be incorrect as is, so we break early. This is ok because these types would be filtered anyways. Fix rust-lang#134764.
- Loading branch information
Showing
3 changed files
with
40 additions
and
3 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
15 changes: 15 additions & 0 deletions
15
tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.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,15 @@ | ||
#![feature(structural_match)] | ||
impl<T: ?Sized> std::marker::StructuralPartialEq for O<T> { } | ||
|
||
enum O<T: ?Sized> { | ||
Some(*const T), | ||
None, | ||
} | ||
|
||
const C: O<dyn for<'a> Fn(Box<dyn Fn(&'a u8)>)> = O::None; | ||
|
||
fn main() { | ||
match O::None { | ||
C => (), //~ ERROR constant of non-structural type | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.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,15 @@ | ||
error: constant of non-structural type `O<dyn for<'a> Fn(Box<dyn Fn(&'a u8)>)>` in a pattern | ||
--> $DIR/non_structural_with_escaping_bounds.rs:13:9 | ||
| | ||
LL | const C: O<dyn for<'a> Fn(Box<dyn Fn(&'a u8)>)> = O::None; | ||
| ----------------------------------------------- constant defined here | ||
... | ||
LL | C => (), | ||
| ^ constant of non-structural type | ||
| | ||
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details | ||
= note: `std::alloc::Global` must be annotated with `#[derive(PartialEq)]` to be usable in patterns | ||
= note: `std::alloc::Global` must be annotated with `#[derive(PartialEq)]` to be usable in patterns | ||
|
||
error: aborting due to 1 previous error | ||
|