Skip to content

Commit 9bd9587

Browse files
committed
change check logic
1 parent 5446e27 commit 9bd9587

File tree

1 file changed

+20
-33
lines changed

1 file changed

+20
-33
lines changed

compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs

+20-33
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
579579
}
580580
}
581581

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);
583584

584585
match error_code {
585586
TypeAnnotationNeeded::E0282 => self.dcx().create_err(AnnotationRequired {
@@ -625,47 +626,33 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
625626
fn detect_old_time_crate_version(
626627
&self,
627628
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.
629631
infer_subdiags: &mut Vec<SourceKindSubdiag<'_>>,
630632
) -> Option<()> {
631633
if self.infcx.tcx.crate_name(LOCAL_CRATE) != sym::time {
632634
// Only relevant when building the `time` crate.
633635
return None;
634636
}
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+
}
636649
let FileName::Real(file) = self.infcx.tcx.sess.source_map().span_to_filename(span) else {
637650
return None;
638651
};
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(());
669656
}
670657
None
671658
}

0 commit comments

Comments
 (0)