@@ -17,7 +17,6 @@ use rustc_middle::{bug, span_bug};
1717use rustc_span:: def_id:: DefId ;
1818use rustc_span:: source_map:: Spanned ;
1919use rustc_span:: { DUMMY_SP , Span , Symbol , sym} ;
20- use rustc_trait_selection:: infer:: InferCtxtExt ;
2120use tracing:: { debug, instrument} ;
2221
2322use crate :: builder:: Builder ;
@@ -363,7 +362,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
363362 ) ;
364363 }
365364
366- /// Compare two values using `<T as std::compare::PartialEq >::eq `.
365+ /// Compare two values using `<T as std::compare::pattern::MatchLoweredCmp >::do_match `.
367366 /// If the values are already references, just call it directly, otherwise
368367 /// take a reference to the values first and then call it.
369368 fn non_scalar_compare (
@@ -451,36 +450,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
451450 ( _, expect) = coerce ( expect_ty, expect, * elem_ty) ;
452451 }
453452
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
455454 // reference: we can only compare two `&T`, and then compare_ty will be `T`.
456455 // 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 ,
458457 // which have their comparison defined in `core`.
459458 // (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!)
461460 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 ( ) => {
465462 deref_ty
466463 }
467464 _ => span_bug ! ( source_info. span, "invalid type for non-scalar compare: {}" , ty) ,
468465 } ;
469466
470- let mut cmp_trait_def_id =
467+ let cmp_trait_def_id =
471468 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-
482469 let method =
483470 trait_method ( self . tcx , cmp_trait_def_id, sym:: do_match, [ compare_ty, compare_ty] ) ;
471+
484472 let bool_ty = self . tcx . types . bool ;
485473 let eq_result = self . temp ( bool_ty, source_info. span ) ;
486474 let eq_block = self . cfg . start_new_block ( ) ;
0 commit comments