Skip to content

Dont walk into unsafe binders when emiting error for non-structural type match #141429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ fn extend_type_not_partial_eq<'tcx>(
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
match ty.kind() {
ty::Dynamic(..) => return ControlFlow::Break(()),
// Unsafe binders never implement `PartialEq`, so avoid walking into them
// which would require instantiating its binder with placeholders too.
ty::UnsafeBinder(..) => return ControlFlow::Break(()),
ty::FnPtr(..) => return ControlFlow::Continue(()),
ty::Adt(def, _args) => {
let ty_def_id = def.did();
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/unsafe-binders/non-strucutral-type-diag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// regression test for <https://github.com/rust-lang/rust/issues/141422>.

#![feature(unsafe_binders)]
#![allow(incomplete_features)]

#[derive(Copy, Clone)]
struct Adt<'a>(&'a ());

const C: Option<(unsafe<'a> Adt<'a>, Box<dyn Send>)> = None;

fn main() {
match None {
C => {}
//~^ ERROR constant of non-structural type
_ => {}
}
}
13 changes: 13 additions & 0 deletions tests/ui/unsafe-binders/non-strucutral-type-diag.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error: constant of non-structural type `Option<(unsafe<'a> Adt<'a>, Box<dyn Send>)>` in a pattern
--> $DIR/non-strucutral-type-diag.rs:13:9
|
LL | const C: Option<(unsafe<'a> Adt<'a>, Box<dyn Send>)> = 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

error: aborting due to 1 previous error

Loading