@@ -579,7 +579,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
579
579
}
580
580
}
581
581
582
- let time_version = self . detect_old_time_crate_version ( failure_span, & mut infer_subdiags) ;
582
+ let time_version =
583
+ self . detect_old_time_crate_version ( failure_span, & kind, & mut infer_subdiags) ;
583
584
584
585
match error_code {
585
586
TypeAnnotationNeeded :: E0282 => self . dcx ( ) . create_err ( AnnotationRequired {
@@ -625,47 +626,33 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
625
626
fn detect_old_time_crate_version (
626
627
& self ,
627
628
span : Option < Span > ,
628
- /// We will clear the non-actionable suggestion from the error to reduce noise.
629
+ kind : & InferSourceKind < ' _ > ,
630
+ // We will clear the non-actionable suggestion from the error to reduce noise.
629
631
infer_subdiags : & mut Vec < SourceKindSubdiag < ' _ > > ,
630
632
) -> Option < ( ) > {
631
633
if self . infcx . tcx . crate_name ( LOCAL_CRATE ) != sym:: time {
632
634
// Only relevant when building the `time` crate.
633
635
return None ;
634
636
}
635
- let Some ( span) = span else { return None } ;
637
+ let Some ( span) = span else {
638
+ return None ;
639
+ } ;
640
+ let InferSourceKind :: LetBinding { pattern_name, .. } = kind else {
641
+ return None ;
642
+ } ;
643
+ let Some ( name) = pattern_name else {
644
+ return None ;
645
+ } ;
646
+ if name. as_str ( ) != "items" {
647
+ return None ;
648
+ }
636
649
let FileName :: Real ( file) = self . infcx . tcx . sess . source_map ( ) . span_to_filename ( span) else {
637
650
return None ;
638
651
} ;
639
- let path = file. local_path_if_available ( ) ;
640
- let mut components = path. components ( ) ;
641
- // We will take the filename of the error and see if it is of the form
642
- // `.../registry/src/index.crates.io-.../time-0...`, in order to detect the specific case
643
- // we care about.
644
- while let Some ( component) = components. next ( ) {
645
- let std:: path:: Component :: Normal ( component) = component else {
646
- continue ;
647
- } ;
648
- if component == "registry"
649
- && let Some ( next) = components. next ( )
650
- && let std:: path:: Component :: Normal ( next) = next
651
- && next == "src"
652
- && let Some ( next) = components. next ( )
653
- && let std:: path:: Component :: Normal ( next) = next
654
- && next. to_string_lossy ( ) . starts_with ( "index." )
655
- && let Some ( next) = components. next ( )
656
- && let std:: path:: Component :: Normal ( next) = next
657
- && let next = next. to_string_lossy ( )
658
- && next. starts_with ( "time-0." )
659
- && let Some ( version) = next. split ( '-' ) . skip ( 1 ) . next ( )
660
- && let mut segments = version. split ( '.' )
661
- && let Some ( major) = segments. next ( )
662
- && major == "0"
663
- && let Some ( minor) = segments. next ( )
664
- && minor == "3"
665
- {
666
- infer_subdiags. clear ( ) ;
667
- return Some ( ( ) ) ;
668
- }
652
+ let path = file. local_path_if_available ( ) . to_string_lossy ( ) ;
653
+ if path. contains ( "format_description" ) && path. contains ( "parse" ) {
654
+ infer_subdiags. clear ( ) ;
655
+ return Some ( ( ) ) ;
669
656
}
670
657
None
671
658
}
0 commit comments