@@ -17,7 +17,6 @@ use rustc_middle::{bug, span_bug};
17
17
use rustc_span:: def_id:: DefId ;
18
18
use rustc_span:: source_map:: Spanned ;
19
19
use rustc_span:: { DUMMY_SP , Span , Symbol , sym} ;
20
- use rustc_trait_selection:: infer:: InferCtxtExt ;
21
20
use tracing:: { debug, instrument} ;
22
21
23
22
use crate :: builder:: Builder ;
@@ -363,7 +362,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
363
362
) ;
364
363
}
365
364
366
- /// Compare two values using `<T as std::compare::PartialEq >::eq `.
365
+ /// Compare two values using `<T as std::compare::pattern::MatchLoweredCmp >::do_match `.
367
366
/// If the values are already references, just call it directly, otherwise
368
367
/// take a reference to the values first and then call it.
369
368
fn non_scalar_compare (
@@ -451,36 +450,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
451
450
( _, expect) = coerce ( expect_ty, expect, * elem_ty) ;
452
451
}
453
452
454
- // Figure out the type we are searching for traits against. This involves an extra wrapping
453
+ // Figure out the type we are searching for trait impls against. This involves an extra wrapping
455
454
// reference: we can only compare two `&T`, and then compare_ty will be `T`.
456
455
// Make sure that we do *not* call any user-defined code here.
457
- // The only types that can end up here are string and byte literals ,
456
+ // The only types that can end up here are str and ScalarInt slices ,
458
457
// which have their comparison defined in `core`.
459
458
// (Interestingly this means that exhaustiveness analysis relies, for soundness,
460
- // on the `PartialEq ` impls for `str` and `[u8 ]` to b correct!)
459
+ // on the `MatchLoweredCmp ` impls for `str` and `[T ]` to be correct!)
461
460
let compare_ty = match * ty. kind ( ) {
462
- ty:: Ref ( _, deref_ty, _)
463
- if deref_ty == self . tcx . types . str_ || deref_ty != self . tcx . types . u8 =>
464
- {
461
+ ty:: Ref ( _, deref_ty, _) if deref_ty == self . tcx . types . str_ || deref_ty. is_slice ( ) => {
465
462
deref_ty
466
463
}
467
464
_ => span_bug ! ( source_info. span, "invalid type for non-scalar compare: {}" , ty) ,
468
465
} ;
469
466
470
- let mut cmp_trait_def_id =
467
+ let cmp_trait_def_id =
471
468
self . tcx . require_lang_item ( LangItem :: MatchLoweredCmp , Some ( source_info. span ) ) ;
472
-
473
- let has_pattern_eq = self
474
- . infcx
475
- . type_implements_trait ( cmp_trait_def_id, [ compare_ty] , self . param_env )
476
- . must_apply_modulo_regions ( ) ;
477
- if !has_pattern_eq {
478
- cmp_trait_def_id =
479
- self . tcx . require_lang_item ( LangItem :: PartialEq , Some ( source_info. span ) ) ;
480
- }
481
-
482
469
let method =
483
470
trait_method ( self . tcx , cmp_trait_def_id, sym:: do_match, [ compare_ty, compare_ty] ) ;
471
+
484
472
let bool_ty = self . tcx . types . bool ;
485
473
let eq_result = self . temp ( bool_ty, source_info. span ) ;
486
474
let eq_block = self . cfg . start_new_block ( ) ;
0 commit comments