Skip to content

Commit 471dcbd

Browse files
committed
Auto merge of rust-lang#119274 - RalfJung:raw-ptr-pattern-ice, r=compiler-errors
fix ICE when using raw ptr in a pattern Fixes rust-lang#119270
2 parents bf8716f + 41020d1 commit 471dcbd

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

Diff for: compiler/rustc_const_eval/src/const_eval/valtrees.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ fn valtree_into_mplace<'tcx>(
341341
ty::FnDef(_, _) => {
342342
// Zero-sized type, nothing to do.
343343
}
344-
ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char => {
344+
ty::Bool | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Char | ty::RawPtr(..) => {
345345
let scalar_int = valtree.unwrap_leaf();
346346
debug!("writing trivial valtree {:?} to place {:?}", scalar_int, place);
347347
ecx.write_immediate(Immediate::Scalar(scalar_int.into()), place).unwrap();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-pass
2+
// Eventually this will be rejected (when the future-compat lints are turned into hard errors), and
3+
// then this test can be removed. But meanwhile we should ensure that this works and does not ICE.
4+
struct NoDerive(i32);
5+
6+
#[derive(PartialEq)]
7+
struct WrapEmbedded(*const NoDerive);
8+
9+
const WRAP_UNSAFE_EMBEDDED: &&WrapEmbedded = &&WrapEmbedded(std::ptr::null());
10+
11+
fn main() {
12+
let b = match WRAP_UNSAFE_EMBEDDED {
13+
WRAP_UNSAFE_EMBEDDED => true,
14+
//~^ WARN: must be annotated with `#[derive(PartialEq, Eq)]`
15+
//~| previously accepted
16+
_ => false,
17+
};
18+
assert!(b);
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: to use a constant of type `WrapEmbedded` in a pattern, `WrapEmbedded` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/null-raw-ptr-issue-119270.rs:13:9
3+
|
4+
LL | WRAP_UNSAFE_EMBEDDED => true,
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
9+
= note: the traits must be derived, manual `impl`s are not sufficient
10+
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
11+
= note: `#[warn(indirect_structural_match)]` on by default
12+
13+
warning: 1 warning emitted
14+

0 commit comments

Comments
 (0)