From 61c02cb3b1b0bcbf8de3262093cb26a5a16aff0b Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Wed, 20 Nov 2024 20:29:01 +0800 Subject: [PATCH] Disarm `time` bomb (diagnostics) Revert "Rollup merge of #129343 - estebank:time-version, r=jieyouxu" This reverts commit 26f75a65d70773e4520634b9f6599ddf08c499e6, reversing changes made to 2572e0e8c9d5d671eccb1d5791e55c929c4720f4. Imports are modified to fix merge conflicts and remove unused ones. --- compiler/rustc_span/src/symbol.rs | 1 - compiler/rustc_trait_selection/messages.ftl | 2 - .../error_reporting/infer/need_type_info.rs | 46 +------------------ compiler/rustc_trait_selection/src/errors.rs | 2 - ...d-time-version-format_description-parse.rs | 13 ------ ...me-version-format_description-parse.stderr | 14 ------ 6 files changed, 2 insertions(+), 76 deletions(-) delete mode 100644 tests/ui/inference/detect-old-time-version-format_description-parse.rs delete mode 100644 tests/ui/inference/detect-old-time-version-format_description-parse.stderr diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 522bccb1acb05..43ba13d4d79b0 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2041,7 +2041,6 @@ symbols! { three_way_compare, thumb2, thumb_mode: "thumb-mode", - time, tmm_reg, to_owned_method, to_string, diff --git a/compiler/rustc_trait_selection/messages.ftl b/compiler/rustc_trait_selection/messages.ftl index 4db9d9915b139..a50d56091964e 100644 --- a/compiler/rustc_trait_selection/messages.ftl +++ b/compiler/rustc_trait_selection/messages.ftl @@ -439,8 +439,6 @@ trait_selection_type_annotations_needed = {$source_kind -> } .label = type must be known at this point -trait_selection_type_annotations_needed_error_time = this is an inference error on crate `time` caused by an API change in Rust 1.80.0; update `time` to version `>=0.3.35` by calling `cargo update` - trait_selection_types_declared_different = these two types are declared with different lifetimes... trait_selection_unable_to_construct_constant_value = unable to construct a constant value for the unevaluated constant {$unevaluated} diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs index a6d8eb6add7d0..5fea142027cbd 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs @@ -6,7 +6,7 @@ use rustc_errors::codes::*; use rustc_errors::{Diag, IntoDiagArg}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Namespace, Res}; -use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId}; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource}; use rustc_middle::bug; @@ -17,7 +17,7 @@ use rustc_middle::ty::{ self, GenericArg, GenericArgKind, GenericArgsRef, InferConst, IsSuggestable, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeckResults, }; -use rustc_span::{BytePos, DUMMY_SP, FileName, Ident, Span, sym}; +use rustc_span::{BytePos, DUMMY_SP, Ident, Span, sym}; use rustc_type_ir::visit::TypeVisitableExt; use tracing::{debug, instrument, warn}; @@ -440,7 +440,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { bad_label, was_written: false, path: Default::default(), - time_version: false, }), TypeAnnotationNeeded::E0283 => self.dcx().create_err(AmbiguousImpl { span, @@ -632,10 +631,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } } } - - let time_version = - self.detect_old_time_crate_version(failure_span, &kind, &mut infer_subdiags); - match error_code { TypeAnnotationNeeded::E0282 => self.dcx().create_err(AnnotationRequired { span, @@ -647,7 +642,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { bad_label: None, was_written: path.is_some(), path: path.unwrap_or_default(), - time_version, }), TypeAnnotationNeeded::E0283 => self.dcx().create_err(AmbiguousImpl { span, @@ -673,42 +667,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { }), } } - - /// Detect the inference regression on crate `time` <= 0.3.35 and emit a more targeted error. - /// - // FIXME: we should figure out a more generic version of doing this, ideally in cargo itself. - fn detect_old_time_crate_version( - &self, - span: Option, - kind: &InferSourceKind<'_>, - // We will clear the non-actionable suggestion from the error to reduce noise. - infer_subdiags: &mut Vec>, - ) -> bool { - // FIXME(#129461): We are time-boxing this code in the compiler. It'll start failing - // compilation once we promote 1.89 to beta, which will happen in 9 months from now. - #[cfg(not(version("1.89")))] - const fn version_check() {} - #[cfg(version("1.89"))] - const fn version_check() { - panic!("remove this check as presumably the ecosystem has moved from needing it"); - } - const { version_check() }; - // Only relevant when building the `time` crate. - if self.infcx.tcx.crate_name(LOCAL_CRATE) == sym::time - && let Some(span) = span - && let InferSourceKind::LetBinding { pattern_name, .. } = kind - && let Some(name) = pattern_name - && name.as_str() == "items" - && let FileName::Real(file) = self.infcx.tcx.sess.source_map().span_to_filename(span) - { - let path = file.local_path_if_available().to_string_lossy(); - if path.contains("format_description") && path.contains("parse") { - infer_subdiags.clear(); - return true; - } - } - false - } } #[derive(Debug)] diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index fe859eb53cd78..8ed51494cf5ea 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -195,8 +195,6 @@ pub struct AnnotationRequired<'a> { #[note(trait_selection_full_type_written)] pub was_written: bool, pub path: PathBuf, - #[note(trait_selection_type_annotations_needed_error_time)] - pub time_version: bool, } // Copy of `AnnotationRequired` for E0283 diff --git a/tests/ui/inference/detect-old-time-version-format_description-parse.rs b/tests/ui/inference/detect-old-time-version-format_description-parse.rs deleted file mode 100644 index 386b2a3bf3c8a..0000000000000 --- a/tests/ui/inference/detect-old-time-version-format_description-parse.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![crate_name = "time"] -#![crate_type = "lib"] - -// This code compiled without error in Rust 1.79, but started failing in 1.80 -// after the addition of several `impl FromIterator<_> for Box`. - -pub fn parse() -> Option> { - let iter = std::iter::once(Some(())).map(|o| o.map(Into::into)); - let items = iter.collect::>>()?; //~ ERROR E0282 - //~^ NOTE this is an inference error on crate `time` caused by an API change in Rust 1.80.0; update `time` to version `>=0.3.35` - Some(items.into()) - //~^ NOTE type must be known at this point -} diff --git a/tests/ui/inference/detect-old-time-version-format_description-parse.stderr b/tests/ui/inference/detect-old-time-version-format_description-parse.stderr deleted file mode 100644 index a70ce9dd2681c..0000000000000 --- a/tests/ui/inference/detect-old-time-version-format_description-parse.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0282]: type annotations needed for `Box<_>` - --> $DIR/detect-old-time-version-format_description-parse.rs:9:9 - | -LL | let items = iter.collect::>>()?; - | ^^^^^ -LL | -LL | Some(items.into()) - | ---- type must be known at this point - | - = note: this is an inference error on crate `time` caused by an API change in Rust 1.80.0; update `time` to version `>=0.3.35` by calling `cargo update` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0282`.