Skip to content

Commit 46606a3

Browse files
Dont walk into unsafe binders when emiting error for non-structural type match
1 parent 52bf0cf commit 46606a3

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,9 @@ fn extend_type_not_partial_eq<'tcx>(
382382
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
383383
match ty.kind() {
384384
ty::Dynamic(..) => return ControlFlow::Break(()),
385+
// Unsafe binders never implement `PartialEq`, so avoid walking into them
386+
// which would require instantiating its binder with placeholders too.
387+
ty::UnsafeBinder(..) => return ControlFlow::Break(()),
385388
ty::FnPtr(..) => return ControlFlow::Continue(()),
386389
ty::Adt(def, _args) => {
387390
let ty_def_id = def.did();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// regression test for <https://github.com/rust-lang/rust/issues/141422>.
2+
3+
#![feature(unsafe_binders)]
4+
#![allow(incomplete_features)]
5+
6+
#[derive(Copy, Clone)]
7+
struct Adt<'a>(&'a ());
8+
9+
const C: Option<(unsafe<'a> Adt<'a>, Box<dyn Send>)> = None;
10+
11+
fn main() {
12+
match None {
13+
C => {}
14+
//~^ ERROR constant of non-structural type
15+
_ => {}
16+
}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: constant of non-structural type `Option<(unsafe<'a> Adt<'a>, Box<dyn Send>)>` in a pattern
2+
--> $DIR/non-strucutral-type-diag.rs:13:9
3+
|
4+
LL | const C: Option<(unsafe<'a> Adt<'a>, Box<dyn Send>)> = None;
5+
| ---------------------------------------------------- constant defined here
6+
...
7+
LL | C => {}
8+
| ^ constant of non-structural type
9+
|
10+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details
11+
12+
error: aborting due to 1 previous error
13+

0 commit comments

Comments
 (0)