Skip to content

Commit

Permalink
remove the bug invoke during compare string const
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Oct 7, 2023
1 parent 935a091 commit bc2c6c4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_mir_build/src/build/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

TestKind::Eq { value, ty } => {
let tcx = self.tcx;
if let ty::Adt(def, _) = ty.kind() && Some(def.did()) == tcx.lang_items().string() {
if !tcx.features().string_deref_patterns {
bug!("matching on `String` went through without enabling string_deref_patterns");
}
if let ty::Adt(def, _) = ty.kind()
&& Some(def.did()) == tcx.lang_items().string()
&& tcx.features().string_deref_patterns
{
let re_erased = tcx.lifetimes.re_erased;
let ref_string = self.temp(Ty::new_imm_ref(tcx,re_erased, ty), test.span);
let ref_str_ty = Ty::new_imm_ref(tcx,re_erased, tcx.types.str_);
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/pattern/issue-115599.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// check-pass

const CONST_STRING: String = String::new();

fn main() {
let empty_str = String::from("");
if let CONST_STRING = empty_str {}
//~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
//~| WARN this was previously accepted
}
14 changes: 14 additions & 0 deletions tests/ui/pattern/issue-115599.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
warning: to use a constant of type `Vec<u8>` in a pattern, `Vec<u8>` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/issue-115599.rs:7:12
|
LL | if let CONST_STRING = empty_str {}
| ^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
= note: `#[warn(indirect_structural_match)]` on by default

warning: 1 warning emitted

0 comments on commit bc2c6c4

Please sign in to comment.