Skip to content

Commit fe2d923

Browse files
committed
Reference patterns should use PartialEq for figuring out the matching logic
1 parent 6bbf752 commit fe2d923

File tree

2 files changed

+2
-29
lines changed

2 files changed

+2
-29
lines changed

src/librustc_mir/build/matches/test.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
312312
})
313313
};
314314

315-
// Use PartialEq::eq for &str and &[u8] slices, instead of BinOp::Eq.
315+
// Use PartialEq::eq for references, instead of BinOp::Eq.
316316
let fail = self.cfg.start_new_block();
317317
let str_or_bytestr = ty
318318
.builtin_deref(true, ty::NoPreference)
319-
.and_then(|tam| match tam.ty.sty {
320-
ty::TyStr => Some(tam.ty),
321-
ty::TySlice(inner) if inner == self.hir.tcx().types.u8 => Some(tam.ty),
322-
_ => None,
323-
});
319+
.map(|tam| tam.ty);
324320
if let Some(ty) = str_or_bytestr {
325321
let eq_def_id = self.hir.tcx().lang_items().eq_trait().unwrap();
326322
let (mty, method) = self.hir.trait_method(eq_def_id, "eq", ty, &[ty]);
Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +0,0 @@
1-
warning: constant evaluation error
2-
--> $DIR/const-expr-addr-operator.rs:17:5
3-
|
4-
17 | / assert_eq!(0, match &22 {
5-
18 | | X => 0,
6-
19 | | _ => 1,
7-
20 | | });
8-
| |_______^ machine error: "Pointer arithmetic or comparison" needs an rfc before being allowed inside constants
9-
|
10-
= note: #[warn(const_err)] on by default
11-
note: inside call to main
12-
--> $DIR/const-expr-addr-operator.rs:14:1
13-
|
14-
14 | / pub fn main() {
15-
15 | | // Constant of generic type (int)
16-
16 | | const X: &'static u32 = &22;
17-
17 | | assert_eq!(0, match &22 {
18-
... |
19-
20 | | });
20-
21 | | }
21-
| |_^
22-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
23-

0 commit comments

Comments
 (0)