From a5245ef284f70e048e9a4f6bbe1678067d0a3bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Tue, 27 Feb 2024 01:13:14 +0000 Subject: [PATCH 01/12] Hint user to update nightly on ICEs produced from outdated nightly --- compiler/rustc_driver_impl/Cargo.toml | 2 +- compiler/rustc_driver_impl/messages.ftl | 8 ++++ compiler/rustc_driver_impl/src/lib.rs | 42 +++++++++++++++++-- .../src/session_diagnostics.rs | 21 ++++++++++ 4 files changed, 68 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml index 242aa06fe3e3c..fcc0afd3488b0 100644 --- a/compiler/rustc_driver_impl/Cargo.toml +++ b/compiler/rustc_driver_impl/Cargo.toml @@ -50,7 +50,7 @@ rustc_trait_selection = { path = "../rustc_trait_selection" } rustc_ty_utils = { path = "../rustc_ty_utils" } serde_json = "1.0.59" shlex = "1.0" -time = { version = "0.3", default-features = false, features = ["alloc", "formatting"] } +time = { version = "0.3", default-features = false, features = ["alloc", "formatting", "parsing", "macros"] } tracing = { version = "0.1.35" } # tidy-alphabetical-end diff --git a/compiler/rustc_driver_impl/messages.ftl b/compiler/rustc_driver_impl/messages.ftl index 39462112dc287..4b0efeba4c6d7 100644 --- a/compiler/rustc_driver_impl/messages.ftl +++ b/compiler/rustc_driver_impl/messages.ftl @@ -1,6 +1,14 @@ driver_impl_ice = the compiler unexpectedly panicked. this is a bug. driver_impl_ice_bug_report = we would appreciate a bug report: {$bug_report_url} driver_impl_ice_bug_report_internal_feature = using internal features is not supported and expected to cause internal compiler errors when used incorrectly +driver_impl_ice_bug_report_internal_feature_outdated = + using internal features is not supported and expected to cause internal compiler errors when used incorrectly + .outdated = it seems this '{$version}' is outdated, a newer nightly should have been released in the mean time + .update = please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists +driver_impl_ice_bug_report_outdated = + it seems this '{$version}' is outdated, a newer nightly should have been released in the mean time + .update = please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists + .url = we would appreciate a bug report: {$bug_report_url} driver_impl_ice_exclude_cargo_defaults = some of the compiler flags provided by cargo are hidden driver_impl_ice_flags = compiler flags: {$flags} diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 692c059beb0c4..fcf18b6749796 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -57,7 +57,7 @@ use std::str; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, OnceLock}; use std::time::{Instant, SystemTime}; -use time::OffsetDateTime; +use time::{Date, OffsetDateTime, Time}; #[allow(unused_macros)] macro do_not_use_print($($t:tt)*) { @@ -1370,6 +1370,9 @@ pub fn install_ice_hook( using_internal_features } +const DATE_FORMAT: &[time::format_description::FormatItem<'static>] = + &time::macros::format_description!("[year]-[month]-[day]"); + /// Prints the ICE message, including query stack, but without backtrace. /// /// The message will point the user at `bug_report_url` to report the ICE. @@ -1398,10 +1401,41 @@ fn report_ice( dcx.emit_err(session_diagnostics::Ice); } - if using_internal_features.load(std::sync::atomic::Ordering::Relaxed) { - dcx.emit_note(session_diagnostics::IceBugReportInternalFeature); + use time::ext::NumericalDuration; + + // Try to hint user to update nightly if applicable when reporting an ICE. + // Attempt to calculate when current version was released, and add 12 hours + // as buffer. If the current version's release timestamp is older than + // the system's current time + 24 hours + 12 hours buffer if we're on + // nightly. + if let Some("nightly") = option_env!("CFG_RELEASE_CHANNEL") + && let Some(version) = option_env!("CFG_VERSION") + && let Some(ver_date_str) = option_env!("CFG_VER_DATE") + && let Ok(ver_date) = Date::parse(&ver_date_str, DATE_FORMAT) + && let ver_datetime = OffsetDateTime::new_utc(ver_date, Time::MIDNIGHT) + && let system_datetime = OffsetDateTime::from(SystemTime::now()) + && system_datetime.checked_sub(36.hours()).is_some_and(|d| d > ver_datetime) + { + if using_internal_features.load(std::sync::atomic::Ordering::Relaxed) { + dcx.emit_note(session_diagnostics::IceBugReportInternalFeatureOutdated { + version, + note_update: (), + note_outdated: (), + }); + } else { + dcx.emit_note(session_diagnostics::IceBugReportOutdated { + version, + bug_report_url, + note_update: (), + note_url: (), + }); + } } else { - dcx.emit_note(session_diagnostics::IceBugReport { bug_report_url }); + if using_internal_features.load(std::sync::atomic::Ordering::Relaxed) { + dcx.emit_note(session_diagnostics::IceBugReportInternalFeature); + } else { + dcx.emit_note(session_diagnostics::IceBugReport { bug_report_url }); + } } let version = util::version_str!().unwrap_or("unknown_version"); diff --git a/compiler/rustc_driver_impl/src/session_diagnostics.rs b/compiler/rustc_driver_impl/src/session_diagnostics.rs index 2b31fdd77cca3..0c3909e68ca8f 100644 --- a/compiler/rustc_driver_impl/src/session_diagnostics.rs +++ b/compiler/rustc_driver_impl/src/session_diagnostics.rs @@ -46,6 +46,27 @@ pub(crate) struct IceBugReport<'a> { #[diag(driver_impl_ice_bug_report_internal_feature)] pub(crate) struct IceBugReportInternalFeature; +#[derive(Diagnostic)] +#[diag(driver_impl_ice_bug_report_outdated)] +pub(crate) struct IceBugReportOutdated<'a> { + pub version: &'a str, + pub bug_report_url: &'a str, + #[note(driver_impl_update)] + pub note_update: (), + #[note(driver_impl_url)] + pub note_url: (), +} + +#[derive(Diagnostic)] +#[diag(driver_impl_ice_bug_report_internal_feature_outdated)] +pub(crate) struct IceBugReportInternalFeatureOutdated<'a> { + pub version: &'a str, + #[note(driver_impl_outdated)] + pub note_outdated: (), + #[note(driver_impl_update)] + pub note_update: (), +} + #[derive(Diagnostic)] #[diag(driver_impl_ice_version)] pub(crate) struct IceVersion<'a> { From a0ca9b16338be84a520dd842d351de0679d5e2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Tue, 27 Feb 2024 12:40:02 +0000 Subject: [PATCH 02/12] Don't suggest update nightly if using internal features --- compiler/rustc_driver_impl/messages.ftl | 4 ---- compiler/rustc_driver_impl/src/lib.rs | 21 +++++++------------ .../src/session_diagnostics.rs | 10 --------- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_driver_impl/messages.ftl b/compiler/rustc_driver_impl/messages.ftl index 4b0efeba4c6d7..5dd0295897b92 100644 --- a/compiler/rustc_driver_impl/messages.ftl +++ b/compiler/rustc_driver_impl/messages.ftl @@ -1,10 +1,6 @@ driver_impl_ice = the compiler unexpectedly panicked. this is a bug. driver_impl_ice_bug_report = we would appreciate a bug report: {$bug_report_url} driver_impl_ice_bug_report_internal_feature = using internal features is not supported and expected to cause internal compiler errors when used incorrectly -driver_impl_ice_bug_report_internal_feature_outdated = - using internal features is not supported and expected to cause internal compiler errors when used incorrectly - .outdated = it seems this '{$version}' is outdated, a newer nightly should have been released in the mean time - .update = please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists driver_impl_ice_bug_report_outdated = it seems this '{$version}' is outdated, a newer nightly should have been released in the mean time .update = please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index fcf18b6749796..95747ee6cd50c 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -1415,21 +1415,14 @@ fn report_ice( && let ver_datetime = OffsetDateTime::new_utc(ver_date, Time::MIDNIGHT) && let system_datetime = OffsetDateTime::from(SystemTime::now()) && system_datetime.checked_sub(36.hours()).is_some_and(|d| d > ver_datetime) + && !using_internal_features.load(std::sync::atomic::Ordering::Relaxed) { - if using_internal_features.load(std::sync::atomic::Ordering::Relaxed) { - dcx.emit_note(session_diagnostics::IceBugReportInternalFeatureOutdated { - version, - note_update: (), - note_outdated: (), - }); - } else { - dcx.emit_note(session_diagnostics::IceBugReportOutdated { - version, - bug_report_url, - note_update: (), - note_url: (), - }); - } + dcx.emit_note(session_diagnostics::IceBugReportOutdated { + version, + bug_report_url, + note_update: (), + note_url: (), + }); } else { if using_internal_features.load(std::sync::atomic::Ordering::Relaxed) { dcx.emit_note(session_diagnostics::IceBugReportInternalFeature); diff --git a/compiler/rustc_driver_impl/src/session_diagnostics.rs b/compiler/rustc_driver_impl/src/session_diagnostics.rs index 0c3909e68ca8f..62d0da62d2a79 100644 --- a/compiler/rustc_driver_impl/src/session_diagnostics.rs +++ b/compiler/rustc_driver_impl/src/session_diagnostics.rs @@ -57,16 +57,6 @@ pub(crate) struct IceBugReportOutdated<'a> { pub note_url: (), } -#[derive(Diagnostic)] -#[diag(driver_impl_ice_bug_report_internal_feature_outdated)] -pub(crate) struct IceBugReportInternalFeatureOutdated<'a> { - pub version: &'a str, - #[note(driver_impl_outdated)] - pub note_outdated: (), - #[note(driver_impl_update)] - pub note_update: (), -} - #[derive(Diagnostic)] #[diag(driver_impl_ice_version)] pub(crate) struct IceVersion<'a> { From 9c963fc5bcc5915db1b3f01c60d08add08504968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Tue, 27 Feb 2024 12:53:41 +0000 Subject: [PATCH 03/12] Adjust wording --- compiler/rustc_driver_impl/messages.ftl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_driver_impl/messages.ftl b/compiler/rustc_driver_impl/messages.ftl index 5dd0295897b92..1b69a6e2fbecc 100644 --- a/compiler/rustc_driver_impl/messages.ftl +++ b/compiler/rustc_driver_impl/messages.ftl @@ -2,9 +2,9 @@ driver_impl_ice = the compiler unexpectedly panicked. this is a bug. driver_impl_ice_bug_report = we would appreciate a bug report: {$bug_report_url} driver_impl_ice_bug_report_internal_feature = using internal features is not supported and expected to cause internal compiler errors when used incorrectly driver_impl_ice_bug_report_outdated = - it seems this '{$version}' is outdated, a newer nightly should have been released in the mean time + it seems that this compiler `{$version}` is outdated, a newer nightly should have been released in the mean time .update = please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists - .url = we would appreciate a bug report: {$bug_report_url} + .url = if the problem still persists, we would appreciate a bug report: {$bug_report_url} driver_impl_ice_exclude_cargo_defaults = some of the compiler flags provided by cargo are hidden driver_impl_ice_flags = compiler flags: {$flags} From 89954e55e1e8e42d28a506db1aceb7a3eb84a689 Mon Sep 17 00:00:00 2001 From: bohan Date: Fri, 1 Mar 2024 19:39:07 +0800 Subject: [PATCH 04/12] only compare ambiguity item that have hard error --- compiler/rustc_resolve/src/imports.rs | 10 +++--- .../imports/unresolved-seg-after-ambiguous.rs | 24 ++++++++++++++ .../unresolved-seg-after-ambiguous.stderr | 32 +++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 tests/ui/imports/unresolved-seg-after-ambiguous.rs create mode 100644 tests/ui/imports/unresolved-seg-after-ambiguous.stderr diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 9bfca0f179880..bd0b2a4856238 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -8,8 +8,8 @@ use crate::errors::{ ItemsInTraitsAreNotImportable, }; use crate::Determinacy::{self, *}; -use crate::Namespace::*; use crate::{module_to_string, names_to_string, ImportSuggestion}; +use crate::{AmbiguityError, Namespace::*}; use crate::{AmbiguityKind, BindingKey, ResolutionError, Resolver, Segment}; use crate::{Finalize, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet}; use crate::{NameBinding, NameBindingData, NameBindingKind, PathResult, Used}; @@ -538,7 +538,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { .chain(indeterminate_imports.iter().map(|i| (true, i))) { let unresolved_import_error = self.finalize_import(*import); - // If this import is unresolved then create a dummy import // resolution for it so that later resolve stages won't complain. self.import_dummy_binding(*import, is_indeterminate); @@ -856,7 +855,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { ImportKind::Single { target_bindings, .. } => target_bindings[TypeNS].get(), _ => None, }; - let prev_ambiguity_errors_len = self.ambiguity_errors.len(); + let ambiguity_errors_len = + |errors: &Vec>| errors.iter().filter(|error| !error.warning).count(); + let prev_ambiguity_errors_len = ambiguity_errors_len(&self.ambiguity_errors); let finalize = Finalize::with_root_span(import.root_id, import.span, import.root_span); // We'll provide more context to the privacy errors later, up to `len`. @@ -870,7 +871,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { ignore_binding, ); - let no_ambiguity = self.ambiguity_errors.len() == prev_ambiguity_errors_len; + let no_ambiguity = + ambiguity_errors_len(&self.ambiguity_errors) == prev_ambiguity_errors_len; import.vis.set(orig_vis); let module = match path_res { PathResult::Module(module) => { diff --git a/tests/ui/imports/unresolved-seg-after-ambiguous.rs b/tests/ui/imports/unresolved-seg-after-ambiguous.rs new file mode 100644 index 0000000000000..dcabc528a85ed --- /dev/null +++ b/tests/ui/imports/unresolved-seg-after-ambiguous.rs @@ -0,0 +1,24 @@ +mod a { + mod b { + mod c { + pub struct E; + } + + mod d { + #[derive(Debug)] + pub struct E; + } + + pub use self::d::*; + pub use self::c::*; + } + + pub use self::b::*; +} + +use self::a::E::in_exist; +//~^ ERROR: unresolved import `self::a::E` +//~| WARNING: `E` is ambiguous +//~| WARNING: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +fn main() {} diff --git a/tests/ui/imports/unresolved-seg-after-ambiguous.stderr b/tests/ui/imports/unresolved-seg-after-ambiguous.stderr new file mode 100644 index 0000000000000..9e0efd4a75f84 --- /dev/null +++ b/tests/ui/imports/unresolved-seg-after-ambiguous.stderr @@ -0,0 +1,32 @@ +error[E0432]: unresolved import `self::a::E` + --> $DIR/unresolved-seg-after-ambiguous.rs:19:14 + | +LL | use self::a::E::in_exist; + | ^ `E` is a struct, not a module + +warning: `E` is ambiguous + --> $DIR/unresolved-seg-after-ambiguous.rs:19:14 + | +LL | use self::a::E::in_exist; + | ^ ambiguous name + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #114095 + = note: ambiguous because of multiple glob imports of a name in the same module +note: `E` could refer to the struct imported here + --> $DIR/unresolved-seg-after-ambiguous.rs:13:17 + | +LL | pub use self::c::*; + | ^^^^^^^^^^ + = help: consider adding an explicit import of `E` to disambiguate +note: `E` could also refer to the struct imported here + --> $DIR/unresolved-seg-after-ambiguous.rs:12:17 + | +LL | pub use self::d::*; + | ^^^^^^^^^^ + = help: consider adding an explicit import of `E` to disambiguate + = note: `#[warn(ambiguous_glob_imports)]` on by default + +error: aborting due to 1 previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0432`. From 6e9f59f967f6d749f0a20f0c9042dd93b39e4651 Mon Sep 17 00:00:00 2001 From: surechen Date: Mon, 4 Mar 2024 12:28:59 +0800 Subject: [PATCH 05/12] add test for #78894 --- .../use-redundant/use-redundant-issue-78894.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/ui/lint/use-redundant/use-redundant-issue-78894.rs diff --git a/tests/ui/lint/use-redundant/use-redundant-issue-78894.rs b/tests/ui/lint/use-redundant/use-redundant-issue-78894.rs new file mode 100644 index 0000000000000..1a81c16f954d8 --- /dev/null +++ b/tests/ui/lint/use-redundant/use-redundant-issue-78894.rs @@ -0,0 +1,14 @@ +//@ check-pass +//@ edition:2018 +#![warn(unused_imports)] + +fn main () +{ + bar!(); + + macro_rules! bar { + () => (); + } + + use bar; +} From 4e03c51f7d693258cdffc9d6b66e7930cbe8509f Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 4 Mar 2024 11:34:10 +0000 Subject: [PATCH 06/12] hir_analysis: enums return `None` in `find_field` Unnamed union fields with enums are checked for, but if `find_field` causes an ICE then the compiler won't get to that point. Signed-off-by: David Wood --- compiler/rustc_hir_analysis/src/collect.rs | 7 ++- .../unnamed-enum-field-issue-121757.rs | 25 +++++++++++ .../unnamed-enum-field-issue-121757.stderr | 45 +++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/ui/union/unnamed-fields/unnamed-enum-field-issue-121757.rs create mode 100644 tests/ui/union/unnamed-fields/unnamed-enum-field-issue-121757.stderr diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index b6e2695590c13..2cc37651ef521 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -791,7 +791,12 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) { } fn find_field(tcx: TyCtxt<'_>, (def_id, ident): (DefId, Ident)) -> Option { - tcx.adt_def(def_id).non_enum_variant().fields.iter_enumerated().find_map(|(idx, field)| { + let adt = tcx.adt_def(def_id); + if adt.is_enum() { + return None; + } + + adt.non_enum_variant().fields.iter_enumerated().find_map(|(idx, field)| { if field.is_unnamed() { let field_ty = tcx.type_of(field.did).instantiate_identity(); let adt_def = field_ty.ty_adt_def().expect("expect Adt for unnamed field"); diff --git a/tests/ui/union/unnamed-fields/unnamed-enum-field-issue-121757.rs b/tests/ui/union/unnamed-fields/unnamed-enum-field-issue-121757.rs new file mode 100644 index 0000000000000..5d15ec4cffdb9 --- /dev/null +++ b/tests/ui/union/unnamed-fields/unnamed-enum-field-issue-121757.rs @@ -0,0 +1,25 @@ +type NodeId = u32; +struct Type<'a>(std::marker::PhantomData::<&'a ()>); + +type Ast<'ast> = &'ast AstStructure<'ast>; + +struct AstStructure<'ast> { +//~^ ERROR struct with unnamed fields must have `#[repr(C)]` representation + id: NodeId, + _: AstKind<'ast> +//~^ ERROR unnamed fields are not yet fully implemented [E0658] +//~^^ ERROR unnamed fields can only have struct or union types +} + +enum AstKind<'ast> { + ExprInt, + ExprLambda(Ast<'ast>), +} + +fn compute_types<'tcx,'ast>(ast: Ast<'ast>) -> Type<'tcx> +{ + match ast.kind {} +//~^ ERROR no field `kind` on type `&'ast AstStructure<'ast>` [E0609] +} + +fn main() {} diff --git a/tests/ui/union/unnamed-fields/unnamed-enum-field-issue-121757.stderr b/tests/ui/union/unnamed-fields/unnamed-enum-field-issue-121757.stderr new file mode 100644 index 0000000000000..4ea910202de98 --- /dev/null +++ b/tests/ui/union/unnamed-fields/unnamed-enum-field-issue-121757.stderr @@ -0,0 +1,45 @@ +error[E0658]: unnamed fields are not yet fully implemented + --> $DIR/unnamed-enum-field-issue-121757.rs:9:5 + | +LL | _: AstKind<'ast> + | ^ + | + = note: see issue #49804 for more information + = help: add `#![feature(unnamed_fields)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: struct with unnamed fields must have `#[repr(C)]` representation + --> $DIR/unnamed-enum-field-issue-121757.rs:6:1 + | +LL | struct AstStructure<'ast> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ struct `AstStructure` defined here + | +note: unnamed field defined here + --> $DIR/unnamed-enum-field-issue-121757.rs:9:5 + | +LL | _: AstKind<'ast> + | ^^^^^^^^^^^^^^^^ +help: add `#[repr(C)]` to this struct + | +LL + #[repr(C)] +LL | struct AstStructure<'ast> { + | + +error: unnamed fields can only have struct or union types + --> $DIR/unnamed-enum-field-issue-121757.rs:9:5 + | +LL | _: AstKind<'ast> + | ^^^^^^^^^^^^^^^^ + +error[E0609]: no field `kind` on type `&'ast AstStructure<'ast>` + --> $DIR/unnamed-enum-field-issue-121757.rs:21:15 + | +LL | match ast.kind {} + | ^^^^ unknown field + | + = note: available fields are: `id`, `_` + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0609, E0658. +For more information about an error, try `rustc --explain E0609`. From 640e99ccc982586352b1ad94c350af3cbeff3c2e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 4 Mar 2024 14:30:46 +0100 Subject: [PATCH 07/12] Fix duplicated path in the "not found dylib" error --- compiler/rustc_metadata/src/creader.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index f65fe1a29c7cc..564c35f881d60 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -1132,7 +1132,13 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result { // Only try to recover from this specific error. if !matches!(err, libloading::Error::LoadLibraryExW { .. }) { - return Err(err.to_string()); + let err = format_dlopen_err(&err); + // We include the path of the dylib in the error ourselves, so + // if it's in the error, we strip it. + if let Some(err) = err.strip_prefix(&format!(": {}", path.display())) { + return Err(err.to_string()); + } + return Err(err); } last_error = Some(err); From 5e6e140b0cf44079cd0f42ba8bfcbf874859dd68 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 4 Mar 2024 14:31:23 +0100 Subject: [PATCH 08/12] Add regression ui test for duplicated path in dylib error --- tests/ui/codegen/duplicated-path-in-error.rs | 7 +++++++ tests/ui/codegen/duplicated-path-in-error.stderr | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 tests/ui/codegen/duplicated-path-in-error.rs create mode 100644 tests/ui/codegen/duplicated-path-in-error.stderr diff --git a/tests/ui/codegen/duplicated-path-in-error.rs b/tests/ui/codegen/duplicated-path-in-error.rs new file mode 100644 index 0000000000000..cff20dd9bd639 --- /dev/null +++ b/tests/ui/codegen/duplicated-path-in-error.rs @@ -0,0 +1,7 @@ +//@ only-linux +//@ compile-flags: -Zcodegen-backend=/non-existing-one.so + +// This test ensures that the error of the "not found dylib" doesn't duplicate +// the path of the dylib. + +fn main() {} diff --git a/tests/ui/codegen/duplicated-path-in-error.stderr b/tests/ui/codegen/duplicated-path-in-error.stderr new file mode 100644 index 0000000000000..d0d34e2f93468 --- /dev/null +++ b/tests/ui/codegen/duplicated-path-in-error.stderr @@ -0,0 +1,2 @@ +error: couldn't load codegen backend /non-existing-one.so: cannot open shared object file: No such file or directory + From 523ab25418f5bf624bdb7752ec9d9ecba9b8aa4e Mon Sep 17 00:00:00 2001 From: surechen Date: Mon, 4 Mar 2024 14:25:51 +0800 Subject: [PATCH 09/12] add test for #71450 --- .../use-redundant-issue-71450.rs | 45 +++++++++++++++++++ .../use-redundant-issue-71450.stderr | 17 +++++++ .../use-redundant-issue-78894.rs | 34 ++++++++++++++ .../use-redundant-issue-78894.stderr | 14 ++++++ 4 files changed, 110 insertions(+) create mode 100644 tests/ui/lint/use-redundant/use-redundant-issue-71450.rs create mode 100644 tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr create mode 100644 tests/ui/lint/use-redundant/use-redundant-issue-78894.stderr diff --git a/tests/ui/lint/use-redundant/use-redundant-issue-71450.rs b/tests/ui/lint/use-redundant/use-redundant-issue-71450.rs new file mode 100644 index 0000000000000..d0fb3454d3f2b --- /dev/null +++ b/tests/ui/lint/use-redundant/use-redundant-issue-71450.rs @@ -0,0 +1,45 @@ +//@ check-pass + +#![warn(unused_imports)] + +mod foo { + use std::fmt; + + pub struct String; + + impl String { + pub fn new() -> String { + String{} + } + } + + impl fmt::Display for String { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "String") + } + } +} + +fn main() { + + { + use std::string::String; //~ WARNING the item `String` is imported redundantly + // 'String' from 'std::string::String'. + let s = String::new(); + println!("{}", s); + } + + { + // 'String' from 'std::string::String'. + let s = String::new(); + println!("{}", s); + } + + { + use foo::*; + // 'String' from 'foo::String'. + let s = String::new(); + println!("{}", s); + } + +} diff --git a/tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr b/tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr new file mode 100644 index 0000000000000..b8832a3178371 --- /dev/null +++ b/tests/ui/lint/use-redundant/use-redundant-issue-71450.stderr @@ -0,0 +1,17 @@ +warning: the item `String` is imported redundantly + --> $DIR/use-redundant-issue-71450.rs:26:13 + | +LL | use std::string::String; + | ^^^^^^^^^^^^^^^^^^^ + --> $SRC_DIR/std/src/prelude/mod.rs:LL:COL + | + = note: the item `String` is already defined here + | +note: the lint level is defined here + --> $DIR/use-redundant-issue-71450.rs:3:9 + | +LL | #![warn(unused_imports)] + | ^^^^^^^^^^^^^^ + +warning: 1 warning emitted + diff --git a/tests/ui/lint/use-redundant/use-redundant-issue-78894.rs b/tests/ui/lint/use-redundant/use-redundant-issue-78894.rs index 1a81c16f954d8..09c87bc37a630 100644 --- a/tests/ui/lint/use-redundant/use-redundant-issue-78894.rs +++ b/tests/ui/lint/use-redundant/use-redundant-issue-78894.rs @@ -1,7 +1,16 @@ //@ check-pass //@ edition:2018 + #![warn(unused_imports)] +mod foo { + macro_rules! foo1 { + () => (); + } + + pub(crate) use foo1; +} + fn main () { bar!(); @@ -11,4 +20,29 @@ fn main () } use bar; + + mod m { + bar1!(); + + macro_rules! bar1 { + () => (); + } + + use bar1; + } + + { + foo::foo1!(); + } + + { + use foo::foo1; + foo1!(); + } + + { + use foo::foo1; //~ WARNING unused import: `foo::foo1` + foo::foo1!(); + } + } diff --git a/tests/ui/lint/use-redundant/use-redundant-issue-78894.stderr b/tests/ui/lint/use-redundant/use-redundant-issue-78894.stderr new file mode 100644 index 0000000000000..78dfe364223d4 --- /dev/null +++ b/tests/ui/lint/use-redundant/use-redundant-issue-78894.stderr @@ -0,0 +1,14 @@ +warning: unused import: `foo::foo1` + --> $DIR/use-redundant-issue-78894.rs:44:13 + | +LL | use foo::foo1; + | ^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/use-redundant-issue-78894.rs:4:9 + | +LL | #![warn(unused_imports)] + | ^^^^^^^^^^^^^^ + +warning: 1 warning emitted + From 9d9b26bca942dc4cf9cda0b8612bff715aebf7da Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 16 Feb 2024 21:32:53 +0100 Subject: [PATCH 10/12] Limit the number of names and values in check-cfg diagnostics --- .../rustc_lint/src/context/diagnostics.rs | 71 +++++++++++++------ compiler/rustc_session/src/options.rs | 2 + tests/ui/check-cfg/mix.rs | 2 + tests/ui/check-cfg/mix.stderr | 11 ++- tests/ui/check-cfg/well-known-values.rs | 1 + tests/ui/check-cfg/well-known-values.stderr | 54 +++++++------- 6 files changed, 93 insertions(+), 48 deletions(-) diff --git a/compiler/rustc_lint/src/context/diagnostics.rs b/compiler/rustc_lint/src/context/diagnostics.rs index a0aa252bcdf2f..a58a37bf3ac08 100644 --- a/compiler/rustc_lint/src/context/diagnostics.rs +++ b/compiler/rustc_lint/src/context/diagnostics.rs @@ -12,6 +12,43 @@ use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::symbol::{sym, Symbol}; use rustc_span::BytePos; +const MAX_CHECK_CFG_NAMES_OR_VALUES: usize = 35; + +fn check_cfg_expected_note( + sess: &Session, + possibilities: &[Symbol], + type_: &str, + name: Option, + suffix: &str, +) -> String { + use std::fmt::Write; + + let n_possibilities = if sess.opts.unstable_opts.check_cfg_all_expected { + possibilities.len() + } else { + std::cmp::min(possibilities.len(), MAX_CHECK_CFG_NAMES_OR_VALUES) + }; + + let mut possibilities = possibilities.iter().map(Symbol::as_str).collect::>(); + possibilities.sort(); + + let and_more = possibilities.len().saturating_sub(n_possibilities); + let possibilities = possibilities[..n_possibilities].join("`, `"); + + let mut note = String::with_capacity(50 + possibilities.len()); + + write!(&mut note, "expected {type_}").unwrap(); + if let Some(name) = name { + write!(&mut note, " for `{name}`").unwrap(); + } + write!(&mut note, " are: {suffix}`{possibilities}`").unwrap(); + if and_more > 0 { + write!(&mut note, " and {and_more} more").unwrap(); + } + + note +} + pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Diag<'_, ()>) { match diagnostic { BuiltinLintDiag::UnicodeTextFlow(span, content) => { @@ -286,16 +323,13 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di } } if !possibilities.is_empty() { - let mut possibilities = - possibilities.iter().map(Symbol::as_str).collect::>(); - possibilities.sort(); - let possibilities = possibilities.join("`, `"); - - // The list of expected names can be long (even by default) and - // so the diagnostic produced can take a lot of space. To avoid - // cloging the user output we only want to print that diagnostic - // once. - diag.help_once(format!("expected names are: `{possibilities}`")); + diag.help_once(check_cfg_expected_note( + sess, + &possibilities, + "names", + None, + "", + )); } } @@ -338,16 +372,13 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di // Show the full list if all possible values for a given name, but don't do it // for names as the possibilities could be very long if !possibilities.is_empty() { - { - let mut possibilities = - possibilities.iter().map(Symbol::as_str).collect::>(); - possibilities.sort(); - - let possibilities = possibilities.join("`, `"); - let none = if have_none_possibility { "(none), " } else { "" }; - - diag.note(format!("expected values for `{name}` are: {none}`{possibilities}`")); - } + diag.note(check_cfg_expected_note( + sess, + &possibilities, + "values", + Some(name), + if have_none_possibility { "(none), " } else { "" }, + )); if let Some((value, value_span)) = value { // Suggest the most probable if we found one diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 42c9d5e10eba1..55e1556cdf8d6 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1565,6 +1565,8 @@ options! { "set options for branch target identification and pointer authentication on AArch64"), cf_protection: CFProtection = (CFProtection::None, parse_cfprotection, [TRACKED], "instrument control-flow architecture protection"), + check_cfg_all_expected: bool = (false, parse_bool, [UNTRACKED], + "show all expected values in check-cfg diagnostics (default: no)"), codegen_backend: Option = (None, parse_opt_string, [TRACKED], "the backend to use"), collapse_macro_debuginfo: CollapseMacroDebuginfo = (CollapseMacroDebuginfo::Unspecified, diff --git a/tests/ui/check-cfg/mix.rs b/tests/ui/check-cfg/mix.rs index ba30bc1e69b50..69156ab67635e 100644 --- a/tests/ui/check-cfg/mix.rs +++ b/tests/ui/check-cfg/mix.rs @@ -74,6 +74,8 @@ fn test_cfg_macro() { //~^ WARNING unexpected `cfg` condition value //~| WARNING unexpected `cfg` condition value //~| WARNING unexpected `cfg` condition value + cfg!(target_feature = "zebra"); + //~^ WARNING unexpected `cfg` condition value } fn main() {} diff --git a/tests/ui/check-cfg/mix.stderr b/tests/ui/check-cfg/mix.stderr index 77643f227d9d0..93333e5ef2a5b 100644 --- a/tests/ui/check-cfg/mix.stderr +++ b/tests/ui/check-cfg/mix.stderr @@ -245,5 +245,14 @@ LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra")); = help: to expect this configuration use `--check-cfg=cfg(feature, values("zebra"))` = note: see for more information about checking conditional configuration -warning: 26 warnings emitted +warning: unexpected `cfg` condition value: `zebra` + --> $DIR/mix.rs:77:10 + | +LL | cfg!(target_feature = "zebra"); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: expected values for `target_feature` are: `10e60`, `2e3`, `3e3r1`, `3e3r2`, `3e3r3`, `3e7`, `7e10`, `a`, `aclass`, `adx`, `aes`, `altivec`, `alu32`, `atomics`, `avx`, `avx2`, `avx512bf16`, `avx512bitalg`, `avx512bw`, `avx512cd`, `avx512dq`, `avx512er`, `avx512f`, `avx512fp16`, `avx512ifma`, `avx512pf`, `avx512vbmi`, `avx512vbmi2`, `avx512vl`, `avx512vnni`, `avx512vp2intersect`, `avx512vpopcntdq`, `bf16`, `bmi1`, `bmi2` and 186 more + = note: see for more information about checking conditional configuration + +warning: 27 warnings emitted diff --git a/tests/ui/check-cfg/well-known-values.rs b/tests/ui/check-cfg/well-known-values.rs index 859a36c604c6f..fa062a3fe2eae 100644 --- a/tests/ui/check-cfg/well-known-values.rs +++ b/tests/ui/check-cfg/well-known-values.rs @@ -6,6 +6,7 @@ // //@ check-pass //@ compile-flags: --check-cfg=cfg() -Z unstable-options +//@ compile-flags: -Zcheck-cfg-all-expected #![feature(cfg_overflow_checks)] #![feature(cfg_relocation_model)] diff --git a/tests/ui/check-cfg/well-known-values.stderr b/tests/ui/check-cfg/well-known-values.stderr index 01fc3f83f162b..86df829fe726c 100644 --- a/tests/ui/check-cfg/well-known-values.stderr +++ b/tests/ui/check-cfg/well-known-values.stderr @@ -1,5 +1,5 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:25:5 + --> $DIR/well-known-values.rs:26:5 | LL | clippy = "_UNEXPECTED_VALUE", | ^^^^^^---------------------- @@ -11,7 +11,7 @@ LL | clippy = "_UNEXPECTED_VALUE", = note: `#[warn(unexpected_cfgs)]` on by default warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:27:5 + --> $DIR/well-known-values.rs:28:5 | LL | debug_assertions = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^---------------------- @@ -22,7 +22,7 @@ LL | debug_assertions = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:29:5 + --> $DIR/well-known-values.rs:30:5 | LL | doc = "_UNEXPECTED_VALUE", | ^^^---------------------- @@ -33,7 +33,7 @@ LL | doc = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:31:5 + --> $DIR/well-known-values.rs:32:5 | LL | doctest = "_UNEXPECTED_VALUE", | ^^^^^^^---------------------- @@ -44,7 +44,7 @@ LL | doctest = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:33:5 + --> $DIR/well-known-values.rs:34:5 | LL | miri = "_UNEXPECTED_VALUE", | ^^^^---------------------- @@ -55,7 +55,7 @@ LL | miri = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:35:5 + --> $DIR/well-known-values.rs:36:5 | LL | overflow_checks = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^---------------------- @@ -66,7 +66,7 @@ LL | overflow_checks = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:37:5 + --> $DIR/well-known-values.rs:38:5 | LL | panic = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -75,7 +75,7 @@ LL | panic = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:39:5 + --> $DIR/well-known-values.rs:40:5 | LL | proc_macro = "_UNEXPECTED_VALUE", | ^^^^^^^^^^---------------------- @@ -86,7 +86,7 @@ LL | proc_macro = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:41:5 + --> $DIR/well-known-values.rs:42:5 | LL | relocation_model = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -95,7 +95,7 @@ LL | relocation_model = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:43:5 + --> $DIR/well-known-values.rs:44:5 | LL | sanitize = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -104,7 +104,7 @@ LL | sanitize = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:45:5 + --> $DIR/well-known-values.rs:46:5 | LL | target_abi = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -113,7 +113,7 @@ LL | target_abi = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:47:5 + --> $DIR/well-known-values.rs:48:5 | LL | target_arch = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +122,7 @@ LL | target_arch = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:49:5 + --> $DIR/well-known-values.rs:50:5 | LL | target_endian = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -131,7 +131,7 @@ LL | target_endian = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:51:5 + --> $DIR/well-known-values.rs:52:5 | LL | target_env = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -140,7 +140,7 @@ LL | target_env = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:53:5 + --> $DIR/well-known-values.rs:54:5 | LL | target_family = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -149,7 +149,7 @@ LL | target_family = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:55:5 + --> $DIR/well-known-values.rs:56:5 | LL | target_feature = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -158,7 +158,7 @@ LL | target_feature = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:57:5 + --> $DIR/well-known-values.rs:58:5 | LL | target_has_atomic = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -167,7 +167,7 @@ LL | target_has_atomic = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:59:5 + --> $DIR/well-known-values.rs:60:5 | LL | target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -176,7 +176,7 @@ LL | target_has_atomic_equal_alignment = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:61:5 + --> $DIR/well-known-values.rs:62:5 | LL | target_has_atomic_load_store = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -185,7 +185,7 @@ LL | target_has_atomic_load_store = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:63:5 + --> $DIR/well-known-values.rs:64:5 | LL | target_os = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -194,7 +194,7 @@ LL | target_os = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:65:5 + --> $DIR/well-known-values.rs:66:5 | LL | target_pointer_width = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -203,7 +203,7 @@ LL | target_pointer_width = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:67:5 + --> $DIR/well-known-values.rs:68:5 | LL | target_thread_local = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^---------------------- @@ -214,7 +214,7 @@ LL | target_thread_local = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:69:5 + --> $DIR/well-known-values.rs:70:5 | LL | target_vendor = "_UNEXPECTED_VALUE", | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -223,7 +223,7 @@ LL | target_vendor = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:71:5 + --> $DIR/well-known-values.rs:72:5 | LL | test = "_UNEXPECTED_VALUE", | ^^^^---------------------- @@ -234,7 +234,7 @@ LL | test = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:73:5 + --> $DIR/well-known-values.rs:74:5 | LL | unix = "_UNEXPECTED_VALUE", | ^^^^---------------------- @@ -245,7 +245,7 @@ LL | unix = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE` - --> $DIR/well-known-values.rs:75:5 + --> $DIR/well-known-values.rs:76:5 | LL | windows = "_UNEXPECTED_VALUE", | ^^^^^^^---------------------- @@ -256,7 +256,7 @@ LL | windows = "_UNEXPECTED_VALUE", = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `linuz` - --> $DIR/well-known-values.rs:81:7 + --> $DIR/well-known-values.rs:82:7 | LL | #[cfg(target_os = "linuz")] // testing that we suggest `linux` | ^^^^^^^^^^^^------- From 2ee0409f323574af15c5d75dbfc42b1721720de8 Mon Sep 17 00:00:00 2001 From: David Wood Date: Mon, 19 Feb 2024 15:07:08 +0000 Subject: [PATCH 11/12] errors: share `SilentEmitter` between rustc and rustfmt Signed-off-by: David Wood --- compiler/rustc_errors/src/emitter.rs | 32 ++----- compiler/rustc_errors/src/lib.rs | 95 +++++++++++++++----- compiler/rustc_interface/src/interface.rs | 14 +-- compiler/rustc_session/src/parse.rs | 18 ++-- src/tools/rustfmt/src/parse/session.rs | 73 ++++++--------- src/tools/rustfmt/tests/rustfmt/main.rs | 2 +- src/tools/rustfmt/tests/target/issue_6082.rs | 5 ++ 7 files changed, 131 insertions(+), 108 deletions(-) create mode 100644 src/tools/rustfmt/tests/target/issue_6082.rs diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 293d8f01e673a..57b8df52f4b79 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -10,7 +10,6 @@ use rustc_span::source_map::SourceMap; use rustc_span::{FileLines, FileName, SourceFile, Span}; -use crate::error::TranslateError; use crate::snippet::{ Annotation, AnnotationColumn, AnnotationType, Line, MultilineAnnotation, Style, StyledString, }; @@ -539,18 +538,9 @@ impl Emitter for HumanEmitter { /// Fatal diagnostics are forwarded to `fatal_dcx` to avoid silent /// failures of rustc, as witnessed e.g. in issue #89358. pub struct SilentEmitter { + pub fallback_bundle: LazyFallbackBundle, pub fatal_dcx: DiagCtxt, - pub fatal_note: String, -} - -pub fn silent_translate<'a>(message: &'a DiagMessage) -> Result, TranslateError<'_>> { - match message { - DiagMessage::Str(msg) | DiagMessage::Translated(msg) => Ok(Cow::Borrowed(msg)), - DiagMessage::FluentIdentifier(identifier, _) => { - // Any value works here. - Ok(identifier.clone()) - } - } + pub fatal_note: Option, } impl Translate for SilentEmitter { @@ -559,17 +549,9 @@ impl Translate for SilentEmitter { } fn fallback_fluent_bundle(&self) -> &FluentBundle { - panic!("silent emitter attempted to translate message") - } - - // Override `translate_message` for the silent emitter because eager translation of - // subdiagnostics result in a call to this. - fn translate_message<'a>( - &'a self, - message: &'a DiagMessage, - _: &'a FluentArgs<'_>, - ) -> Result, TranslateError<'_>> { - silent_translate(message) + // Ideally this field wouldn't be necessary and the fallback bundle in `fatal_dcx` would be + // used but the lock prevents this. + &self.fallback_bundle } } @@ -580,7 +562,9 @@ impl Emitter for SilentEmitter { fn emit_diagnostic(&mut self, mut diag: DiagInner) { if diag.level == Level::Fatal { - diag.sub(Level::Note, self.fatal_note.clone(), MultiSpan::new()); + if let Some(fatal_note) = &self.fatal_note { + diag.sub(Level::Note, fatal_note.clone(), MultiSpan::new()); + } self.fatal_dcx.emit_diagnostic(diag); } } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 0a6d66f52dad0..0caa8fa9e8abe 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -63,7 +63,7 @@ use emitter::{is_case_difference, DynEmitter, Emitter}; use registry::Registry; use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::stable_hasher::{Hash128, StableHasher}; -use rustc_data_structures::sync::Lock; +use rustc_data_structures::sync::{Lock, Lrc}; use rustc_data_structures::AtomicRef; use rustc_lint_defs::LintExpectationId; use rustc_span::source_map::SourceMap; @@ -606,29 +606,54 @@ impl DiagCtxt { } pub fn new(emitter: Box) -> Self { - Self { - inner: Lock::new(DiagCtxtInner { - flags: DiagCtxtFlags { can_emit_warnings: true, ..Default::default() }, - err_guars: Vec::new(), - lint_err_guars: Vec::new(), - delayed_bugs: Vec::new(), - deduplicated_err_count: 0, - deduplicated_warn_count: 0, - emitter, - must_produce_diag: false, - has_printed: false, - suppressed_expected_diag: false, - taught_diagnostics: Default::default(), - emitted_diagnostic_codes: Default::default(), - emitted_diagnostics: Default::default(), - stashed_diagnostics: Default::default(), - future_breakage_diagnostics: Vec::new(), - check_unstable_expect_diagnostics: false, - unstable_expect_diagnostics: Vec::new(), - fulfilled_expectations: Default::default(), - ice_file: None, - }), + Self { inner: Lock::new(DiagCtxtInner::new(emitter)) } + } + + pub fn make_silent(&mut self, fallback_bundle: LazyFallbackBundle, fatal_note: Option) { + self.wrap_emitter(|old_dcx| { + Box::new(emitter::SilentEmitter { + fallback_bundle, + fatal_dcx: DiagCtxt { inner: Lock::new(old_dcx) }, + fatal_note, + }) + }); + } + + fn wrap_emitter(&mut self, f: F) + where + F: FnOnce(DiagCtxtInner) -> Box, + { + // A empty type that implements `Emitter` so that a `DiagCtxtInner` can be constructed + // to temporarily swap in place of the real one, which will be used in constructing + // its replacement. + struct FalseEmitter; + + impl Emitter for FalseEmitter { + fn emit_diagnostic(&mut self, _: DiagInner) { + unimplemented!("false emitter must only used during `wrap_emitter`") + } + + fn source_map(&self) -> Option<&Lrc> { + unimplemented!("false emitter must only used during `wrap_emitter`") + } } + + impl translation::Translate for FalseEmitter { + fn fluent_bundle(&self) -> Option<&Lrc> { + unimplemented!("false emitter must only used during `wrap_emitter`") + } + + fn fallback_fluent_bundle(&self) -> &FluentBundle { + unimplemented!("false emitter must only used during `wrap_emitter`") + } + } + + let mut inner = self.inner.borrow_mut(); + let mut prev_dcx = DiagCtxtInner::new(Box::new(FalseEmitter)); + std::mem::swap(&mut *inner, &mut prev_dcx); + let new_emitter = f(prev_dcx); + let mut new_dcx = DiagCtxtInner::new(new_emitter); + std::mem::swap(&mut *inner, &mut new_dcx); } /// Translate `message` eagerly with `args` to `SubdiagMessage::Eager`. @@ -1345,6 +1370,30 @@ impl DiagCtxt { // `DiagCtxt::foo()` just borrows `inner` and forwards a call to // `DiagCtxtInner::foo`. impl DiagCtxtInner { + fn new(emitter: Box) -> Self { + Self { + flags: DiagCtxtFlags { can_emit_warnings: true, ..Default::default() }, + err_guars: Vec::new(), + lint_err_guars: Vec::new(), + delayed_bugs: Vec::new(), + deduplicated_err_count: 0, + deduplicated_warn_count: 0, + emitter, + must_produce_diag: false, + has_printed: false, + suppressed_expected_diag: false, + taught_diagnostics: Default::default(), + emitted_diagnostic_codes: Default::default(), + emitted_diagnostics: Default::default(), + stashed_diagnostics: Default::default(), + future_breakage_diagnostics: Vec::new(), + check_unstable_expect_diagnostics: false, + unstable_expect_diagnostics: Vec::new(), + fulfilled_expectations: Default::default(), + ice_file: None, + } + } + /// Emit all stashed diagnostics. fn emit_stashed_diagnostics(&mut self) -> Option { let mut guar = None; diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 3a2bbed19beff..b2ec8e5342924 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -45,9 +45,10 @@ pub struct Compiler { pub(crate) fn parse_cfg(dcx: &DiagCtxt, cfgs: Vec) -> Cfg { cfgs.into_iter() .map(|s| { - let psess = ParseSess::with_silent_emitter(format!( - "this error occurred on the command line: `--cfg={s}`" - )); + let psess = ParseSess::with_silent_emitter( + vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE], + format!("this error occurred on the command line: `--cfg={s}`"), + ); let filename = FileName::cfg_spec_source_code(&s); macro_rules! error { @@ -107,9 +108,10 @@ pub(crate) fn parse_check_cfg(dcx: &DiagCtxt, specs: Vec) -> CheckCfg { let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg::default() }; for s in specs { - let psess = ParseSess::with_silent_emitter(format!( - "this error occurred on the command line: `--check-cfg={s}`" - )); + let psess = ParseSess::with_silent_emitter( + vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE], + format!("this error occurred on the command line: `--check-cfg={s}`"), + ); let filename = FileName::cfg_spec_source_code(&s); macro_rules! error { diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 25b5422f3225f..506bd5d5dbd81 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -265,14 +265,20 @@ impl ParseSess { } } - pub fn with_silent_emitter(fatal_note: String) -> Self { - let fallback_bundle = fallback_fluent_bundle(Vec::new(), false); + pub fn with_silent_emitter(locale_resources: Vec<&'static str>, fatal_note: String) -> Self { + let fallback_bundle = fallback_fluent_bundle(locale_resources, false); let sm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - let emitter = - Box::new(HumanEmitter::new(stderr_destination(ColorConfig::Auto), fallback_bundle)); + let emitter = Box::new(HumanEmitter::new( + stderr_destination(ColorConfig::Auto), + fallback_bundle.clone(), + )); let fatal_dcx = DiagCtxt::new(emitter); - let dcx = - DiagCtxt::new(Box::new(SilentEmitter { fatal_dcx, fatal_note })).disable_warnings(); + let dcx = DiagCtxt::new(Box::new(SilentEmitter { + fallback_bundle, + fatal_dcx, + fatal_note: Some(fatal_note), + })) + .disable_warnings(); ParseSess::with_dcx(dcx, sm) } diff --git a/src/tools/rustfmt/src/parse/session.rs b/src/tools/rustfmt/src/parse/session.rs index 11af986051351..60a89a5753641 100644 --- a/src/tools/rustfmt/src/parse/session.rs +++ b/src/tools/rustfmt/src/parse/session.rs @@ -1,9 +1,8 @@ -use std::borrow::Cow; use std::path::Path; use std::sync::atomic::{AtomicBool, Ordering}; use rustc_data_structures::sync::{IntoDynSyncSend, Lrc}; -use rustc_errors::emitter::{stderr_destination, DynEmitter, Emitter, HumanEmitter}; +use rustc_errors::emitter::{stderr_destination, DynEmitter, Emitter, HumanEmitter, SilentEmitter}; use rustc_errors::translation::Translate; use rustc_errors::{ColorConfig, Diag, DiagCtxt, DiagInner, Level as DiagnosticLevel}; use rustc_session::parse::ParseSess as RawParseSess; @@ -28,41 +27,6 @@ pub(crate) struct ParseSess { can_reset_errors: Lrc, } -/// Emitter which discards every error. -struct SilentEmitter; - -impl Translate for SilentEmitter { - fn fluent_bundle(&self) -> Option<&Lrc> { - None - } - - fn fallback_fluent_bundle(&self) -> &rustc_errors::FluentBundle { - panic!("silent emitter attempted to translate a diagnostic"); - } - - // Override `translate_message` for the silent emitter because eager translation of - // subdiagnostics result in a call to this. - fn translate_message<'a>( - &'a self, - message: &'a rustc_errors::DiagMessage, - _: &'a rustc_errors::translation::FluentArgs<'_>, - ) -> Result, rustc_errors::error::TranslateError<'_>> { - rustc_errors::emitter::silent_translate(message) - } -} - -impl Emitter for SilentEmitter { - fn source_map(&self) -> Option<&Lrc> { - None - } - - fn emit_diagnostic(&mut self, _diag: DiagInner) {} -} - -fn silent_emitter() -> Box { - Box::new(SilentEmitter {}) -} - /// Emit errors against every files expect ones specified in the `ignore_path_set`. struct SilentOnIgnoredFilesEmitter { ignore_path_set: IntoDynSyncSend>, @@ -143,17 +107,23 @@ fn default_dcx( ColorConfig::Never }; - let emitter = if hide_parse_errors { - silent_emitter() + let fallback_bundle = rustc_errors::fallback_fluent_bundle( + rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), + false, + ); + let emitter = Box::new( + HumanEmitter::new(stderr_destination(emit_color), fallback_bundle.clone()) + .sm(Some(source_map.clone())), + ); + + let emitter: Box = if hide_parse_errors { + Box::new(SilentEmitter { + fallback_bundle, + fatal_dcx: DiagCtxt::new(emitter), + fatal_note: None, + }) } else { - let fallback_bundle = rustc_errors::fallback_fluent_bundle( - rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), - false, - ); - Box::new( - HumanEmitter::new(stderr_destination(emit_color), fallback_bundle) - .sm(Some(source_map.clone())), - ) + emitter }; DiagCtxt::new(Box::new(SilentOnIgnoredFilesEmitter { has_non_ignorable_parser_errors: false, @@ -232,7 +202,14 @@ impl ParseSess { } pub(crate) fn set_silent_emitter(&mut self) { - self.raw_psess.dcx = DiagCtxt::new(silent_emitter()); + // Ideally this invocation wouldn't be necessary and the fallback bundle in + // `self.parse_sess.dcx` could be used, but the lock in `DiagCtxt` prevents this. + // See `::fallback_fluent_bundle`. + let fallback_bundle = rustc_errors::fallback_fluent_bundle( + rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), + false, + ); + self.raw_psess.dcx.make_silent(fallback_bundle, None); } pub(crate) fn span_to_filename(&self, span: Span) -> FileName { diff --git a/src/tools/rustfmt/tests/rustfmt/main.rs b/src/tools/rustfmt/tests/rustfmt/main.rs index 7dcf7c8416eec..e66fad1e7fa7b 100644 --- a/src/tools/rustfmt/tests/rustfmt/main.rs +++ b/src/tools/rustfmt/tests/rustfmt/main.rs @@ -176,7 +176,7 @@ fn rustfmt_emits_error_on_line_overflow_true() { #[test] #[allow(non_snake_case)] fn dont_emit_ICE() { - let files = ["tests/target/issue_5728.rs", "tests/target/issue_5729.rs"]; + let files = ["tests/target/issue_5728.rs", "tests/target/issue_5729.rs", "tests/target/issue_6082.rs"]; for file in files { let args = [file]; diff --git a/src/tools/rustfmt/tests/target/issue_6082.rs b/src/tools/rustfmt/tests/target/issue_6082.rs new file mode 100644 index 0000000000000..58e512c710e98 --- /dev/null +++ b/src/tools/rustfmt/tests/target/issue_6082.rs @@ -0,0 +1,5 @@ +macro_rules! test { + ($T:ident, $b:lifetime) => { + Box<$T<$b>> + }; +} From da357346e802b6898e1c151420ce3c481896b3ef Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 4 Mar 2024 19:23:30 +0000 Subject: [PATCH 12/12] Merge `impl_trait_in_assoc_types_defined_by` query back into `opaque_types_defined_by` Instead, when we're collecting opaques for associated items, we choose the right collection mode depending on whether we're collecting for an associated item of a trait impl or not. --- .../src/collect/type_of/opaque.rs | 28 ++++++------------- compiler/rustc_middle/src/query/mod.rs | 9 ------ compiler/rustc_ty_utils/src/opaque_types.rs | 21 +++++--------- .../hidden_behind_struct_field2.rs | 2 +- .../hidden_behind_struct_field2.stderr | 13 ++++++--- .../hidden_behind_struct_field3.rs | 2 +- .../hidden_behind_struct_field3.stderr | 13 ++++++--- 7 files changed, 35 insertions(+), 53 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs index f0e998b7a0032..dcb01a117b047 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs @@ -46,9 +46,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type( for &assoc_id in tcx.associated_item_def_ids(impl_def_id) { let assoc = tcx.associated_item(assoc_id); match assoc.kind { - ty::AssocKind::Const | ty::AssocKind::Fn => { - locator.check(assoc_id.expect_local(), ImplTraitSource::AssocTy) - } + ty::AssocKind::Const | ty::AssocKind::Fn => locator.check(assoc_id.expect_local()), // Associated types don't have bodies, so they can't constrain hidden types ty::AssocKind::Type => {} } @@ -182,15 +180,9 @@ struct TaitConstraintLocator<'tcx> { typeck_types: Vec>, } -#[derive(Debug)] -enum ImplTraitSource { - AssocTy, - TyAlias, -} - impl TaitConstraintLocator<'_> { #[instrument(skip(self), level = "debug")] - fn check(&mut self, item_def_id: LocalDefId, source: ImplTraitSource) { + fn check(&mut self, item_def_id: LocalDefId) { // Don't try to check items that cannot possibly constrain the type. if !self.tcx.has_typeck_results(item_def_id) { debug!("no constraint: no typeck results"); @@ -242,12 +234,8 @@ impl TaitConstraintLocator<'_> { continue; } constrained = true; - let opaque_types_defined_by = match source { - ImplTraitSource::AssocTy => { - self.tcx.impl_trait_in_assoc_types_defined_by(item_def_id) - } - ImplTraitSource::TyAlias => self.tcx.opaque_types_defined_by(item_def_id), - }; + let opaque_types_defined_by = self.tcx.opaque_types_defined_by(item_def_id); + if !opaque_types_defined_by.contains(&self.def_id) { self.tcx.dcx().emit_err(TaitForwardCompat { span: hidden_type.span, @@ -308,7 +296,7 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> { } fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) { if let hir::ExprKind::Closure(closure) = ex.kind { - self.check(closure.def_id, ImplTraitSource::TyAlias); + self.check(closure.def_id); } intravisit::walk_expr(self, ex); } @@ -316,7 +304,7 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> { trace!(?it.owner_id); // The opaque type itself or its children are not within its reveal scope. if it.owner_id.def_id != self.def_id { - self.check(it.owner_id.def_id, ImplTraitSource::TyAlias); + self.check(it.owner_id.def_id); intravisit::walk_item(self, it); } } @@ -324,13 +312,13 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> { trace!(?it.owner_id); // The opaque type itself or its children are not within its reveal scope. if it.owner_id.def_id != self.def_id { - self.check(it.owner_id.def_id, ImplTraitSource::TyAlias); + self.check(it.owner_id.def_id); intravisit::walk_impl_item(self, it); } } fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) { trace!(?it.owner_id); - self.check(it.owner_id.def_id, ImplTraitSource::TyAlias); + self.check(it.owner_id.def_id); intravisit::walk_trait_item(self, it); } fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) { diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 8357c21a3c2be..b0431ae05d395 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -344,15 +344,6 @@ rustc_queries! { } } - query impl_trait_in_assoc_types_defined_by( - key: LocalDefId - ) -> &'tcx ty::List { - desc { - |tcx| "computing the opaque types defined by `{}`", - tcx.def_path_str(key.to_def_id()) - } - } - /// Returns the list of bounds that can be used for /// `SelectionCandidate::ProjectionCandidate(_)` and /// `ProjectionTyCandidate::TraitDef`. diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 282595169737d..0ac14b338ac12 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -34,7 +34,11 @@ enum CollectionMode { } impl<'tcx> OpaqueTypeCollector<'tcx> { - fn new(tcx: TyCtxt<'tcx>, item: LocalDefId, mode: CollectionMode) -> Self { + fn new(tcx: TyCtxt<'tcx>, item: LocalDefId) -> Self { + let mode = match tcx.def_kind(tcx.local_parent(item)) { + DefKind::Impl { of_trait: true } => CollectionMode::ImplTraitInAssocTypes, + _ => CollectionMode::TypeAliasImplTraitTransition, + }; Self { tcx, opaques: Vec::new(), item, seen: Default::default(), span: None, mode } } @@ -287,23 +291,13 @@ impl<'tcx> TypeVisitor> for OpaqueTypeCollector<'tcx> { } } -fn impl_trait_in_assoc_types_defined_by<'tcx>( - tcx: TyCtxt<'tcx>, - item: LocalDefId, -) -> &'tcx ty::List { - let mut collector = OpaqueTypeCollector::new(tcx, item, CollectionMode::ImplTraitInAssocTypes); - super::sig_types::walk_types(tcx, item, &mut collector); - tcx.mk_local_def_ids(&collector.opaques) -} - fn opaque_types_defined_by<'tcx>( tcx: TyCtxt<'tcx>, item: LocalDefId, ) -> &'tcx ty::List { let kind = tcx.def_kind(item); trace!(?kind); - let mut collector = - OpaqueTypeCollector::new(tcx, item, CollectionMode::TypeAliasImplTraitTransition); + let mut collector = OpaqueTypeCollector::new(tcx, item); super::sig_types::walk_types(tcx, item, &mut collector); match kind { DefKind::AssocFn @@ -346,6 +340,5 @@ fn opaque_types_defined_by<'tcx>( } pub(super) fn provide(providers: &mut Providers) { - *providers = - Providers { opaque_types_defined_by, impl_trait_in_assoc_types_defined_by, ..*providers }; + *providers = Providers { opaque_types_defined_by, ..*providers }; } diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.rs b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.rs index 4c881dd133086..3117060cef0d2 100644 --- a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.rs +++ b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.rs @@ -15,7 +15,7 @@ impl Trait for Bar { type Assoc = impl std::fmt::Debug; fn foo() -> Foo { Foo { field: () } - //~^ ERROR: item constrains opaque type that is not in its signature + //~^ ERROR: mismatched types } } diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.stderr b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.stderr index 5c53dfa3a7500..4910e794e8d6e 100644 --- a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.stderr +++ b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.stderr @@ -1,11 +1,15 @@ -error: item constrains opaque type that is not in its signature +error[E0308]: mismatched types --> $DIR/hidden_behind_struct_field2.rs:17:22 | +LL | type Assoc = impl std::fmt::Debug; + | -------------------- the expected opaque type +LL | fn foo() -> Foo { LL | Foo { field: () } - | ^^ + | ^^ expected opaque type, found `()` | - = note: this item must mention the opaque type in its signature in order to be able to register hidden types -note: this item must mention the opaque type in its signature in order to be able to register hidden types + = note: expected opaque type `::Assoc` + found unit type `()` +note: this item must have the opaque type in its signature in order to be able to register hidden types --> $DIR/hidden_behind_struct_field2.rs:16:8 | LL | fn foo() -> Foo { @@ -13,3 +17,4 @@ LL | fn foo() -> Foo { error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.rs b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.rs index 1278563a92c46..c1f135994121e 100644 --- a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.rs +++ b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.rs @@ -17,7 +17,7 @@ impl Trait for Bar { type Assoc = impl Iterator; fn foo() -> Self::Assoc { vec![Foo { field: () }].into_iter() - //~^ ERROR item constrains opaque type that is not in its signature + //~^ ERROR mismatched types } } diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.stderr b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.stderr index 0570e0303c633..f10ccc0029973 100644 --- a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.stderr +++ b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.stderr @@ -1,11 +1,15 @@ -error: item constrains opaque type that is not in its signature +error[E0308]: mismatched types --> $DIR/hidden_behind_struct_field3.rs:19:27 | +LL | type Assoc2 = impl std::fmt::Debug; + | -------------------- the expected opaque type +... LL | vec![Foo { field: () }].into_iter() - | ^^ + | ^^ expected opaque type, found `()` | - = note: this item must mention the opaque type in its signature in order to be able to register hidden types -note: this item must mention the opaque type in its signature in order to be able to register hidden types + = note: expected opaque type `::Assoc2` + found unit type `()` +note: this item must have the opaque type in its signature in order to be able to register hidden types --> $DIR/hidden_behind_struct_field3.rs:18:8 | LL | fn foo() -> Self::Assoc { @@ -13,3 +17,4 @@ LL | fn foo() -> Self::Assoc { error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0308`.