Skip to content

Commit bc2c6c4

Browse files
committed
remove the bug invoke during compare string const
1 parent 935a091 commit bc2c6c4

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

compiler/rustc_mir_build/src/build/matches/test.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
236236

237237
TestKind::Eq { value, ty } => {
238238
let tcx = self.tcx;
239-
if let ty::Adt(def, _) = ty.kind() && Some(def.did()) == tcx.lang_items().string() {
240-
if !tcx.features().string_deref_patterns {
241-
bug!("matching on `String` went through without enabling string_deref_patterns");
242-
}
239+
if let ty::Adt(def, _) = ty.kind()
240+
&& Some(def.did()) == tcx.lang_items().string()
241+
&& tcx.features().string_deref_patterns
242+
{
243243
let re_erased = tcx.lifetimes.re_erased;
244244
let ref_string = self.temp(Ty::new_imm_ref(tcx,re_erased, ty), test.span);
245245
let ref_str_ty = Ty::new_imm_ref(tcx,re_erased, tcx.types.str_);

tests/ui/pattern/issue-115599.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// check-pass
2+
3+
const CONST_STRING: String = String::new();
4+
5+
fn main() {
6+
let empty_str = String::from("");
7+
if let CONST_STRING = empty_str {}
8+
//~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
9+
//~| WARN this was previously accepted
10+
}

tests/ui/pattern/issue-115599.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: to use a constant of type `Vec<u8>` in a pattern, `Vec<u8>` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/issue-115599.rs:7:12
3+
|
4+
LL | if let CONST_STRING = empty_str {}
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)