From 97b1a6146c630374ddab15f424eb8141dbb88960 Mon Sep 17 00:00:00 2001 From: Donough Liu Date: Mon, 29 Aug 2022 19:06:36 +0100 Subject: Use more `into_iter` rather than `drain(..)` --- compiler/rustc_errors/src/diagnostic.rs | 4 ++-- compiler/rustc_errors/src/translation.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 506198df4d8..935a9639231 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -981,12 +981,12 @@ impl Diagnostic { fn sub_with_highlights>( &mut self, level: Level, - mut message: Vec<(M, Style)>, + message: Vec<(M, Style)>, span: MultiSpan, render_span: Option, ) { let message = message - .drain(..) + .into_iter() .map(|m| (self.subdiagnostic_message_to_diagnostic_message(m.0), m.1)) .collect(); let sub = SubDiagnostic { level, message, span, render_span }; diff --git a/compiler/rustc_errors/src/translation.rs b/compiler/rustc_errors/src/translation.rs index 65338f56d9c..4f407badb3f 100644 --- a/compiler/rustc_errors/src/translation.rs +++ b/compiler/rustc_errors/src/translation.rs @@ -21,7 +21,7 @@ pub trait Translate { /// Typically performed once for each diagnostic at the start of `emit_diagnostic` and then /// passed around as a reference thereafter. fn to_fluent_args<'arg>(&self, args: &[DiagnosticArg<'arg>]) -> FluentArgs<'arg> { - FromIterator::from_iter(args.to_vec().drain(..)) + FromIterator::from_iter(args.iter().cloned()) } /// Convert `DiagnosticMessage`s to a string, performing translation if necessary. -- cgit 1.4.1-3-g733a5 From 0d65819d529f222e47164f6c8132d8134909f2a4 Mon Sep 17 00:00:00 2001 From: Nathan Stocks Date: Fri, 26 Aug 2022 14:39:59 -0600 Subject: respond to review feedback: mainly eliminate as many conversions as possible... - ... when creating diagnostics in rustc_metadata - use the error_code! macro - pass macro output to diag.code() - use fluent from within manual implementation of SessionDiagnostic - emit the untested errors in case they occur in the wild - stop panicking in the probably-not-dead code, add fixme to write test --- Cargo.lock | 1 + .../locales/en-US/metadata.ftl | 30 +++ compiler/rustc_errors/Cargo.toml | 5 +- compiler/rustc_errors/src/diagnostic.rs | 7 + compiler/rustc_metadata/src/creader.rs | 19 +- compiler/rustc_metadata/src/dependency_format.rs | 30 ++- compiler/rustc_metadata/src/errors.rs | 215 +++++++++++---------- compiler/rustc_metadata/src/fs.rs | 27 +-- compiler/rustc_metadata/src/locator.rs | 102 ++++------ compiler/rustc_metadata/src/native_libs.rs | 18 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 6 +- 11 files changed, 234 insertions(+), 226 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/Cargo.lock b/Cargo.lock index 002d73be7d1..0ce329ff070 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3514,6 +3514,7 @@ dependencies = [ "rustc_macros", "rustc_serialize", "rustc_span", + "rustc_target", "serde", "serde_json", "termcolor", diff --git a/compiler/rustc_error_messages/locales/en-US/metadata.ftl b/compiler/rustc_error_messages/locales/en-US/metadata.ftl index e3e58cf8bed..dee01bcad4b 100644 --- a/compiler/rustc_error_messages/locales/en-US/metadata.ftl +++ b/compiler/rustc_error_messages/locales/en-US/metadata.ftl @@ -225,3 +225,33 @@ metadata_cannot_find_crate = metadata_no_dylib_plugin = plugin `{$crate_name}` only found in rlib format, but must be available in dylib format + +metadata_target_not_installed = + the `{$locator_triple}` target may not be installed + +metadata_target_no_std_support = + the `{$locator_triple}` target may not support the standard library + +metadata_consider_downloading_target = + consider downloading the target with `rustup target add {$locator_triple}` + +metadata_std_required = + `std` is required by `{$current_crate}` because it does not declare `#![no_std]` + +metadata_consider_building_std = + consider building the standard library from source with `cargo build -Zbuild-std` + +metadata_compiler_missing_profiler = + the compiler may have been built without the profiler runtime + +metadata_install_missing_components = + maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview` + +metadata_cant_find_crate = + can't find crate + +metadata_crate_location_unknown_type = + extern location for {$crate_name} is of an unknown type: {$path} + +metadata_lib_filename_form = + file name should be lib*.rlib or {dll_prefix}*.{dll_suffix} diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index 36805aa874f..4d207fd17fb 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -15,13 +15,14 @@ rustc_macros = { path = "../rustc_macros" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_hir = { path = "../rustc_hir" } rustc_lint_defs = { path = "../rustc_lint_defs" } +rustc_target = { path = "../rustc_target" } unicode-width = "0.1.4" atty = "0.2" termcolor = "1.0" annotate-snippets = "0.9" termize = "0.1.1" -serde = { version = "1.0.125", features = ["derive"] } +serde = { version = "1.0.125", features = [ "derive" ] } serde_json = "1.0.59" [target.'cfg(windows)'.dependencies] -winapi = { version = "0.3", features = ["handleapi", "synchapi", "winbase"] } +winapi = { version = "0.3", features = [ "handleapi", "synchapi", "winbase" ] } diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index f75e2596f36..b569ef4fc2c 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -10,6 +10,7 @@ use rustc_lint_defs::{Applicability, LintExpectationId}; use rustc_span::edition::LATEST_STABLE_EDITION; use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol}; use rustc_span::{edition::Edition, Span, DUMMY_SP}; +use rustc_target::spec::PanicStrategy; use std::borrow::Cow; use std::fmt; use std::hash::{Hash, Hasher}; @@ -144,6 +145,12 @@ impl IntoDiagnosticArg for usize { } } +impl IntoDiagnosticArg for PanicStrategy { + fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + DiagnosticArgValue::Str(Cow::Owned(self.desc().to_string())) + } +} + impl<'source> Into> for DiagnosticArgValue<'source> { fn into(self) -> FluentValue<'source> { match self { diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index f9aa3733f6a..edffec8ab55 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -750,13 +750,10 @@ impl<'a> CrateLoader<'a> { // Sanity check the loaded crate to ensure it is indeed a panic runtime // and the panic strategy is indeed what we thought it was. if !data.is_panic_runtime() { - self.sess.emit_err(CrateNotPanicRuntime { crate_name: name.to_string() }); + self.sess.emit_err(CrateNotPanicRuntime { crate_name: name }); } if data.required_panic_strategy() != Some(desired_strategy) { - self.sess.emit_err(NoPanicStrategy { - crate_name: name.to_string(), - strategy: desired_strategy.desc().to_string(), - }); + self.sess.emit_err(NoPanicStrategy { crate_name: name, strategy: desired_strategy }); } self.cstore.injected_panic_runtime = Some(cnum); @@ -784,7 +781,7 @@ impl<'a> CrateLoader<'a> { // Sanity check the loaded crate to ensure it is indeed a profiler runtime if !data.is_profiler_runtime() { - self.sess.emit_err(NotProfilerRuntime { crate_name: name.to_string() }); + self.sess.emit_err(NotProfilerRuntime { crate_name: name }); } } @@ -828,8 +825,8 @@ impl<'a> CrateLoader<'a> { match global_allocator { Some(other_crate) => { self.sess.emit_err(ConflictingGlobalAlloc { - crate_name: data.name().to_string(), - other_crate_name: other_crate.to_string(), + crate_name: data.name(), + other_crate_name: other_crate, }); } None => global_allocator = Some(data.name()), @@ -874,9 +871,9 @@ impl<'a> CrateLoader<'a> { let data = self.cstore.get_crate_data(dep); if needs_dep(&data) { self.sess.emit_err(NoTransitiveNeedsDep { - crate_name: self.cstore.get_crate_data(krate).name().to_string(), - needs_crate_name: what.to_string(), - deps_crate_name: data.name().to_string(), + crate_name: self.cstore.get_crate_data(krate).name(), + needs_crate_name: what, + deps_crate_name: data.name(), }); } } diff --git a/compiler/rustc_metadata/src/dependency_format.rs b/compiler/rustc_metadata/src/dependency_format.rs index 5d1082acc0b..9ad0099ad25 100644 --- a/compiler/rustc_metadata/src/dependency_format.rs +++ b/compiler/rustc_metadata/src/dependency_format.rs @@ -140,7 +140,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList { if src.rlib.is_some() { continue; } - sess.emit_err(RlibRequired { crate_name: tcx.crate_name(cnum).to_string() }); + sess.emit_err(RlibRequired { crate_name: tcx.crate_name(cnum) }); } return Vec::new(); } @@ -224,10 +224,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList { Linkage::Static => "rlib", _ => "dylib", }; - sess.emit_err(LibRequired { - crate_name: tcx.crate_name(cnum).to_string(), - kind: kind.to_string(), - }); + sess.emit_err(LibRequired { crate_name: tcx.crate_name(cnum), kind: kind }); } } } @@ -251,8 +248,7 @@ fn add_library( // This error is probably a little obscure, but I imagine that it // can be refined over time. if link2 != link || link == RequireStatic { - tcx.sess - .emit_err(CrateDepMultiple { crate_name: tcx.crate_name(cnum).to_string() }); + tcx.sess.emit_err(CrateDepMultiple { crate_name: tcx.crate_name(cnum) }); } } None => { @@ -347,8 +343,8 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) { if tcx.is_panic_runtime(cnum) { if let Some((prev, _)) = panic_runtime { - let prev_name = tcx.crate_name(prev).to_string(); - let cur_name = tcx.crate_name(cnum).to_string(); + let prev_name = tcx.crate_name(prev); + let cur_name = tcx.crate_name(cnum); sess.emit_err(TwoPanicRuntimes { prev_name, cur_name }); } panic_runtime = Some(( @@ -370,8 +366,8 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) { // our same strategy. if found_strategy != desired_strategy { sess.emit_err(BadPanicStrategy { - runtime: tcx.crate_name(runtime_cnum).to_string(), - strategy: desired_strategy.desc().to_string(), + runtime: tcx.crate_name(runtime_cnum), + strategy: desired_strategy, }); } @@ -390,17 +386,17 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) { if let Some(found_strategy) = tcx.required_panic_strategy(cnum) && desired_strategy != found_strategy { sess.emit_err(RequiredPanicStrategy { - crate_name: tcx.crate_name(cnum).to_string(), - found_strategy: found_strategy.desc().to_string(), - desired_strategy: desired_strategy.desc().to_string() }); + crate_name: tcx.crate_name(cnum), + found_strategy, + desired_strategy}); } let found_drop_strategy = tcx.panic_in_drop_strategy(cnum); if tcx.sess.opts.unstable_opts.panic_in_drop != found_drop_strategy { sess.emit_err(IncompatiblePanicInDropStrategy { - crate_name: tcx.crate_name(cnum).to_string(), - found_strategy: found_drop_strategy.desc().to_string(), - desired_strategy: tcx.sess.opts.unstable_opts.panic_in_drop.desc().to_string(), + crate_name: tcx.crate_name(cnum), + found_strategy: found_drop_strategy, + desired_strategy: tcx.sess.opts.unstable_opts.panic_in_drop, }); } } diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index d3f35ca8d16..565c96917e2 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -1,59 +1,64 @@ -use std::path::PathBuf; +use std::{ + io::Error, + path::{Path, PathBuf}, +}; -use rustc_errors::{DiagnosticId, ErrorGuaranteed}; +use rustc_errors::{error_code, ErrorGuaranteed}; use rustc_macros::SessionDiagnostic; use rustc_session::{config, SessionDiagnostic}; use rustc_span::{sym, Span, Symbol}; -use rustc_target::spec::TargetTriple; +use rustc_target::spec::{PanicStrategy, TargetTriple}; + +use crate::locator::CrateFlavor; #[derive(SessionDiagnostic)] #[diag(metadata::rlib_required)] pub struct RlibRequired { - pub crate_name: String, + pub crate_name: Symbol, } #[derive(SessionDiagnostic)] #[diag(metadata::lib_required)] -pub struct LibRequired { - pub crate_name: String, - pub kind: String, +pub struct LibRequired<'a> { + pub crate_name: Symbol, + pub kind: &'a str, } #[derive(SessionDiagnostic)] #[diag(metadata::crate_dep_multiple)] #[help] pub struct CrateDepMultiple { - pub crate_name: String, + pub crate_name: Symbol, } #[derive(SessionDiagnostic)] #[diag(metadata::two_panic_runtimes)] pub struct TwoPanicRuntimes { - pub prev_name: String, - pub cur_name: String, + pub prev_name: Symbol, + pub cur_name: Symbol, } #[derive(SessionDiagnostic)] #[diag(metadata::bad_panic_strategy)] pub struct BadPanicStrategy { - pub runtime: String, - pub strategy: String, + pub runtime: Symbol, + pub strategy: PanicStrategy, } #[derive(SessionDiagnostic)] #[diag(metadata::required_panic_strategy)] pub struct RequiredPanicStrategy { - pub crate_name: String, - pub found_strategy: String, - pub desired_strategy: String, + pub crate_name: Symbol, + pub found_strategy: PanicStrategy, + pub desired_strategy: PanicStrategy, } #[derive(SessionDiagnostic)] #[diag(metadata::incompatible_panic_in_drop_strategy)] pub struct IncompatiblePanicInDropStrategy { - pub crate_name: String, - pub found_strategy: String, - pub desired_strategy: String, + pub crate_name: Symbol, + pub found_strategy: PanicStrategy, + pub desired_strategy: PanicStrategy, } #[derive(SessionDiagnostic)] @@ -129,11 +134,11 @@ pub struct FrameworkOnlyWindows { #[derive(SessionDiagnostic)] #[diag(metadata::unknown_link_kind, code = "E0458")] -pub struct UnknownLinkKind { +pub struct UnknownLinkKind<'a> { #[primary_span] #[label] pub span: Span, - pub kind: String, + pub kind: &'a str, } #[derive(SessionDiagnostic)] @@ -180,10 +185,10 @@ pub struct InvalidLinkModifier { #[derive(SessionDiagnostic)] #[diag(metadata::multiple_modifiers)] -pub struct MultipleModifiers { +pub struct MultipleModifiers<'a> { #[primary_span] pub span: Span, - pub modifier: String, + pub modifier: &'a str, } #[derive(SessionDiagnostic)] @@ -209,10 +214,10 @@ pub struct AsNeededCompatibility { #[derive(SessionDiagnostic)] #[diag(metadata::unknown_link_modifier)] -pub struct UnknownLinkModifier { +pub struct UnknownLinkModifier<'a> { #[primary_span] pub span: Span, - pub modifier: String, + pub modifier: &'a str, } #[derive(SessionDiagnostic)] @@ -250,20 +255,20 @@ pub struct LibFrameworkApple; #[derive(SessionDiagnostic)] #[diag(metadata::empty_renaming_target)] -pub struct EmptyRenamingTarget { - pub lib_name: String, +pub struct EmptyRenamingTarget<'a> { + pub lib_name: &'a str, } #[derive(SessionDiagnostic)] #[diag(metadata::renaming_no_link)] -pub struct RenamingNoLink { - pub lib_name: String, +pub struct RenamingNoLink<'a> { + pub lib_name: &'a str, } #[derive(SessionDiagnostic)] #[diag(metadata::multiple_renamings)] -pub struct MultipleRenamings { - pub lib_name: String, +pub struct MultipleRenamings<'a> { + pub lib_name: &'a str, } #[derive(SessionDiagnostic)] @@ -290,32 +295,32 @@ pub struct UnsupportedAbi { #[derive(SessionDiagnostic)] #[diag(metadata::fail_create_file_encoder)] pub struct FailCreateFileEncoder { - pub err: String, + pub err: Error, } #[derive(SessionDiagnostic)] #[diag(metadata::fail_seek_file)] pub struct FailSeekFile { - pub err: String, + pub err: Error, } #[derive(SessionDiagnostic)] #[diag(metadata::fail_write_file)] pub struct FailWriteFile { - pub err: String, + pub err: Error, } #[derive(SessionDiagnostic)] #[diag(metadata::crate_not_panic_runtime)] pub struct CrateNotPanicRuntime { - pub crate_name: String, + pub crate_name: Symbol, } #[derive(SessionDiagnostic)] #[diag(metadata::no_panic_strategy)] pub struct NoPanicStrategy { - pub crate_name: String, - pub strategy: String, + pub crate_name: Symbol, + pub strategy: PanicStrategy, } #[derive(SessionDiagnostic)] @@ -325,7 +330,7 @@ pub struct ProfilerBuiltinsNeedsCore; #[derive(SessionDiagnostic)] #[diag(metadata::not_profiler_runtime)] pub struct NotProfilerRuntime { - pub crate_name: String, + pub crate_name: Symbol, } #[derive(SessionDiagnostic)] @@ -341,8 +346,8 @@ pub struct NoMultipleGlobalAlloc { #[derive(SessionDiagnostic)] #[diag(metadata::conflicting_global_alloc)] pub struct ConflictingGlobalAlloc { - pub crate_name: String, - pub other_crate_name: String, + pub crate_name: Symbol, + pub other_crate_name: Symbol, } #[derive(SessionDiagnostic)] @@ -351,36 +356,36 @@ pub struct GlobalAllocRequired; #[derive(SessionDiagnostic)] #[diag(metadata::no_transitive_needs_dep)] -pub struct NoTransitiveNeedsDep { - pub crate_name: String, - pub needs_crate_name: String, - pub deps_crate_name: String, +pub struct NoTransitiveNeedsDep<'a> { + pub crate_name: Symbol, + pub needs_crate_name: &'a str, + pub deps_crate_name: Symbol, } #[derive(SessionDiagnostic)] #[diag(metadata::failed_write_error)] pub struct FailedWriteError { - pub filename: String, - pub err: String, + pub filename: PathBuf, + pub err: Error, } #[derive(SessionDiagnostic)] #[diag(metadata::failed_create_tempdir)] pub struct FailedCreateTempdir { - pub err: String, + pub err: Error, } #[derive(SessionDiagnostic)] #[diag(metadata::failed_create_file)] -pub struct FailedCreateFile { - pub filename: String, - pub err: String, +pub struct FailedCreateFile<'a> { + pub filename: &'a Path, + pub err: Error, } #[derive(SessionDiagnostic)] #[diag(metadata::failed_create_encoded_metadata)] pub struct FailedCreateEncodedMetadata { - pub err: String, + pub err: Error, } #[derive(SessionDiagnostic)] @@ -388,31 +393,31 @@ pub struct FailedCreateEncodedMetadata { pub struct NonAsciiName { #[primary_span] pub span: Span, - pub crate_name: String, + pub crate_name: Symbol, } #[derive(SessionDiagnostic)] #[diag(metadata::extern_location_not_exist)] -pub struct ExternLocationNotExist { +pub struct ExternLocationNotExist<'a> { #[primary_span] pub span: Span, - pub crate_name: String, - pub location: String, + pub crate_name: Symbol, + pub location: &'a Path, } #[derive(SessionDiagnostic)] #[diag(metadata::extern_location_not_file)] -pub struct ExternLocationNotFile { +pub struct ExternLocationNotFile<'a> { #[primary_span] pub span: Span, - pub crate_name: String, - pub location: String, + pub crate_name: Symbol, + pub location: &'a Path, } -pub struct MultipleCandidates { +pub(crate) struct MultipleCandidates { pub span: Span, - pub flavor: String, - pub crate_name: String, + pub flavor: CrateFlavor, + pub crate_name: Symbol, pub candidates: Vec, } @@ -424,7 +429,7 @@ impl SessionDiagnostic<'_> for MultipleCandidates { let mut diag = sess.struct_err(rustc_errors::fluent::metadata::multiple_candidates); diag.set_arg("crate_name", self.crate_name); diag.set_arg("flavor", self.flavor); - diag.code(DiagnosticId::Error("E0465".into())); + diag.code(error_code!(E0465)); diag.set_span(self.span); for (i, candidate) in self.candidates.iter().enumerate() { diag.span_note(self.span, &format!("candidate #{}: {}", i + 1, candidate.display())); @@ -439,7 +444,7 @@ impl SessionDiagnostic<'_> for MultipleCandidates { pub struct MultipleMatchingCrates { #[primary_span] pub span: Span, - pub crate_name: String, + pub crate_name: Symbol, pub candidates: String, } @@ -448,7 +453,7 @@ pub struct MultipleMatchingCrates { pub struct SymbolConflictsCurrent { #[primary_span] pub span: Span, - pub crate_name: String, + pub crate_name: Symbol, } #[derive(SessionDiagnostic)] @@ -456,7 +461,7 @@ pub struct SymbolConflictsCurrent { pub struct SymbolConflictsOthers { #[primary_span] pub span: Span, - pub crate_name: String, + pub crate_name: Symbol, } #[derive(SessionDiagnostic)] @@ -464,8 +469,8 @@ pub struct SymbolConflictsOthers { pub struct StableCrateIdCollision { #[primary_span] pub span: Span, - pub crate_name0: String, - pub crate_name1: String, + pub crate_name0: Symbol, + pub crate_name1: Symbol, } #[derive(SessionDiagnostic)] @@ -483,7 +488,7 @@ pub struct DlError { pub struct NewerCrateVersion { #[primary_span] pub span: Span, - pub crate_name: String, + pub crate_name: Symbol, pub add_info: String, pub found_crates: String, } @@ -491,11 +496,11 @@ pub struct NewerCrateVersion { #[derive(SessionDiagnostic)] #[diag(metadata::no_crate_with_triple, code = "E0461")] #[note(metadata::found_crate_versions)] -pub struct NoCrateWithTriple { +pub struct NoCrateWithTriple<'a> { #[primary_span] pub span: Span, - pub crate_name: String, - pub locator_triple: String, + pub crate_name: Symbol, + pub locator_triple: &'a str, pub add_info: String, pub found_crates: String, } @@ -507,7 +512,7 @@ pub struct NoCrateWithTriple { pub struct FoundStaticlib { #[primary_span] pub span: Span, - pub crate_name: String, + pub crate_name: Symbol, pub add_info: String, pub found_crates: String, } @@ -519,7 +524,7 @@ pub struct FoundStaticlib { pub struct IncompatibleRustc { #[primary_span] pub span: Span, - pub crate_name: String, + pub crate_name: Symbol, pub add_info: String, pub found_crates: String, pub rustc_version: String, @@ -527,7 +532,7 @@ pub struct IncompatibleRustc { pub struct InvalidMetadataFiles { pub span: Span, - pub crate_name: String, + pub crate_name: Symbol, pub add_info: String, pub crate_rejections: Vec, } @@ -540,7 +545,7 @@ impl SessionDiagnostic<'_> for InvalidMetadataFiles { let mut diag = sess.struct_err(rustc_errors::fluent::metadata::invalid_meta_files); diag.set_arg("crate_name", self.crate_name); diag.set_arg("add_info", self.add_info); - diag.code(DiagnosticId::Error("E0786".into())); + diag.code(error_code!(E0786)); diag.set_span(self.span); for crate_rejection in self.crate_rejections { diag.note(crate_rejection); @@ -551,8 +556,7 @@ impl SessionDiagnostic<'_> for InvalidMetadataFiles { pub struct CannotFindCrate { pub span: Span, - pub crate_name: String, - pub crate_name_symbol: Symbol, + pub crate_name: Symbol, pub add_info: String, pub missing_core: bool, pub current_crate: String, @@ -567,53 +571,41 @@ impl SessionDiagnostic<'_> for CannotFindCrate { sess: &'_ rustc_session::parse::ParseSess, ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { let mut diag = sess.struct_err(rustc_errors::fluent::metadata::cannot_find_crate); - diag.set_arg("crate_name", self.crate_name.clone()); + diag.set_arg("crate_name", self.crate_name); diag.set_arg("add_info", self.add_info); - diag.code(DiagnosticId::Error("E0463".into())); + diag.set_arg("locator_triple", self.locator_triple.triple()); + diag.code(error_code!(E0463)); diag.set_span(self.span); - // FIXME: Find a way to distill this logic down into the derived SessionDiagnostic form - if (self.crate_name_symbol == sym::std || self.crate_name_symbol == sym::core) + if (self.crate_name == sym::std || self.crate_name == sym::core) && self.locator_triple != TargetTriple::from_triple(config::host_triple()) { if self.missing_core { - diag.note(&format!("the `{}` target may not be installed", self.locator_triple)); + diag.note(rustc_errors::fluent::metadata::target_not_installed); } else { - diag.note(&format!( - "the `{}` target may not support the standard library", - self.locator_triple - )); + diag.note(rustc_errors::fluent::metadata::target_no_std_support); } // NOTE: this suggests using rustup, even though the user may not have it installed. // That's because they could choose to install it; or this may give them a hint which // target they need to install from their distro. if self.missing_core { - diag.help(&format!( - "consider downloading the target with `rustup target add {}`", - self.locator_triple - )); + diag.help(rustc_errors::fluent::metadata::consider_downloading_target); } // Suggest using #![no_std]. #[no_core] is unstable and not really supported anyway. // NOTE: this is a dummy span if `extern crate std` was injected by the compiler. // If it's not a dummy, that means someone added `extern crate std` explicitly and // `#![no_std]` won't help. if !self.missing_core && self.span.is_dummy() { - diag.note(&format!( - "`std` is required by `{}` because it does not declare `#![no_std]`", - self.current_crate - )); + diag.note(rustc_errors::fluent::metadata::std_required); } if self.is_nightly_build { - diag.help("consider building the standard library from source with `cargo build -Zbuild-std`"); + diag.help(rustc_errors::fluent::metadata::consider_building_std); } - } else if self.crate_name_symbol == self.profiler_runtime { - diag.note("the compiler may have been built without the profiler runtime"); - } else if self.crate_name.starts_with("rustc_") { - diag.help( - "maybe you need to install the missing components with: \ - `rustup component add rust-src rustc-dev llvm-tools-preview`", - ); + } else if self.crate_name == self.profiler_runtime { + diag.note(rustc_errors::fluent::metadata::compiler_missing_profiler); + } else if self.crate_name.as_str().starts_with("rustc_") { + diag.help(rustc_errors::fluent::metadata::install_missing_components); } - diag.span_label(self.span, "can't find crate"); + diag.span_label(self.span, rustc_errors::fluent::metadata::cant_find_crate); diag } } @@ -623,5 +615,22 @@ impl SessionDiagnostic<'_> for CannotFindCrate { pub struct NoDylibPlugin { #[primary_span] pub span: Span, - pub crate_name: String, + pub crate_name: Symbol, +} + +#[derive(SessionDiagnostic)] +#[diag(metadata::crate_location_unknown_type)] +pub struct CrateLocationUnknownType<'a> { + #[primary_span] + pub span: Span, + pub path: &'a Path, +} + +#[derive(SessionDiagnostic)] +#[diag(metadata::lib_filename_form)] +pub struct LibFilenameForm<'a> { + #[primary_span] + pub span: Span, + pub dll_prefix: &'a str, + pub dll_suffix: &'a str, } diff --git a/compiler/rustc_metadata/src/fs.rs b/compiler/rustc_metadata/src/fs.rs index 67c18766c59..f360a586476 100644 --- a/compiler/rustc_metadata/src/fs.rs +++ b/compiler/rustc_metadata/src/fs.rs @@ -26,11 +26,8 @@ pub fn emit_metadata(sess: &Session, metadata: &[u8], tmpdir: &MaybeTempDir) -> let out_filename = tmpdir.as_ref().join(METADATA_FILENAME); let result = fs::write(&out_filename, metadata); - if let Err(e) = result { - sess.emit_fatal(FailedWriteError { - filename: out_filename.display().to_string(), - err: e.to_string(), - }); + if let Err(err) = result { + sess.emit_fatal(FailedWriteError { filename: out_filename, err }); } out_filename @@ -71,7 +68,7 @@ pub fn encode_and_write_metadata( let metadata_tmpdir = TempFileBuilder::new() .prefix("rmeta") .tempdir_in(out_filename.parent().unwrap_or_else(|| Path::new(""))) - .unwrap_or_else(|err| tcx.sess.emit_fatal(FailedCreateTempdir { err: err.to_string() })); + .unwrap_or_else(|err| tcx.sess.emit_fatal(FailedCreateTempdir { err })); let metadata_tmpdir = MaybeTempDir::new(metadata_tmpdir, tcx.sess.opts.cg.save_temps); let metadata_filename = metadata_tmpdir.as_ref().join(METADATA_FILENAME); @@ -79,11 +76,8 @@ pub fn encode_and_write_metadata( // This simplifies the creation of the output `out_filename` when requested. match metadata_kind { MetadataKind::None => { - std::fs::File::create(&metadata_filename).unwrap_or_else(|e| { - tcx.sess.emit_fatal(FailedCreateFile { - filename: metadata_filename.display().to_string(), - err: e.to_string(), - }); + std::fs::File::create(&metadata_filename).unwrap_or_else(|err| { + tcx.sess.emit_fatal(FailedCreateFile { filename: &metadata_filename, err }); }); } MetadataKind::Uncompressed | MetadataKind::Compressed => { @@ -98,11 +92,8 @@ pub fn encode_and_write_metadata( // this file always exists. let need_metadata_file = tcx.sess.opts.output_types.contains_key(&OutputType::Metadata); let (metadata_filename, metadata_tmpdir) = if need_metadata_file { - if let Err(e) = non_durable_rename(&metadata_filename, &out_filename) { - tcx.sess.emit_fatal(FailedWriteError { - filename: out_filename.display().to_string(), - err: e.to_string(), - }); + if let Err(err) = non_durable_rename(&metadata_filename, &out_filename) { + tcx.sess.emit_fatal(FailedWriteError { filename: out_filename, err }); } if tcx.sess.opts.json_artifact_notifications { tcx.sess @@ -117,8 +108,8 @@ pub fn encode_and_write_metadata( // Load metadata back to memory: codegen may need to include it in object files. let metadata = - EncodedMetadata::from_path(metadata_filename, metadata_tmpdir).unwrap_or_else(|e| { - tcx.sess.emit_fatal(FailedCreateEncodedMetadata { err: e.to_string() }); + EncodedMetadata::from_path(metadata_filename, metadata_tmpdir).unwrap_or_else(|err| { + tcx.sess.emit_fatal(FailedCreateEncodedMetadata { err }); }); let need_metadata_module = metadata_kind == MetadataKind::Compressed; diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 83c8756078e..5edad819e7e 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -214,10 +214,11 @@ use crate::creader::Library; use crate::errors::{ - CannotFindCrate, DlError, ExternLocationNotExist, ExternLocationNotFile, FoundStaticlib, - IncompatibleRustc, InvalidMetadataFiles, MultipleCandidates, MultipleMatchingCrates, - NewerCrateVersion, NoCrateWithTriple, NoDylibPlugin, NonAsciiName, StableCrateIdCollision, - SymbolConflictsCurrent, SymbolConflictsOthers, + CannotFindCrate, CrateLocationUnknownType, DlError, ExternLocationNotExist, + ExternLocationNotFile, FoundStaticlib, IncompatibleRustc, InvalidMetadataFiles, + LibFilenameForm, MultipleCandidates, MultipleMatchingCrates, NewerCrateVersion, + NoCrateWithTriple, NoDylibPlugin, NonAsciiName, StableCrateIdCollision, SymbolConflictsCurrent, + SymbolConflictsOthers, }; use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER}; @@ -226,7 +227,7 @@ use rustc_data_structures::memmap::Mmap; use rustc_data_structures::owning_ref::OwningRef; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::MetadataRef; -use rustc_errors::FatalError; +use rustc_errors::{DiagnosticArgValue, FatalError, IntoDiagnosticArg}; use rustc_session::config::{self, CrateType}; use rustc_session::cstore::{CrateSource, MetadataLoader}; use rustc_session::filesearch::FileSearch; @@ -238,6 +239,7 @@ use rustc_span::Span; use rustc_target::spec::{Target, TargetTriple}; use snap::read::FrameDecoder; +use std::borrow::Cow; use std::fmt::Write as _; use std::io::{Read, Result as IoResult, Write}; use std::path::{Path, PathBuf}; @@ -294,6 +296,16 @@ impl fmt::Display for CrateFlavor { } } +impl IntoDiagnosticArg for CrateFlavor { + fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { + match self { + CrateFlavor::Rlib => DiagnosticArgValue::Str(Cow::Borrowed("rlib")), + CrateFlavor::Rmeta => DiagnosticArgValue::Str(Cow::Borrowed("rmeta")), + CrateFlavor::Dylib => DiagnosticArgValue::Str(Cow::Borrowed("dylib")), + } + } +} + impl<'a> CrateLocator<'a> { pub(crate) fn new( sess: &'a Session, @@ -946,29 +958,16 @@ impl CrateError { pub(crate) fn report(self, sess: &Session, span: Span, missing_core: bool) { match self { CrateError::NonAsciiName(crate_name) => { - sess.emit_err(NonAsciiName { span, crate_name: crate_name.to_string() }); + sess.emit_err(NonAsciiName { span, crate_name }); } CrateError::ExternLocationNotExist(crate_name, loc) => { - sess.emit_err(ExternLocationNotExist { - span, - crate_name: crate_name.to_string(), - location: loc.display().to_string(), - }); + sess.emit_err(ExternLocationNotExist { span, crate_name, location: &loc }); } CrateError::ExternLocationNotFile(crate_name, loc) => { - sess.emit_err(ExternLocationNotFile { - span, - crate_name: crate_name.to_string(), - location: loc.display().to_string(), - }); + sess.emit_err(ExternLocationNotFile { span, crate_name, location: &loc }); } CrateError::MultipleCandidates(crate_name, flavor, candidates) => { - sess.emit_err(MultipleCandidates { - span, - flavor: flavor.to_string(), - crate_name: crate_name.to_string(), - candidates, - }); + sess.emit_err(MultipleCandidates { span, flavor: flavor, crate_name, candidates }); } CrateError::MultipleMatchingCrates(crate_name, libraries) => { let mut libraries: Vec<_> = libraries.into_values().collect(); @@ -998,27 +997,23 @@ impl CrateError { s }) .collect::(); - sess.emit_err(MultipleMatchingCrates { - span, - crate_name: crate_name.to_string(), - candidates, - }); + sess.emit_err(MultipleMatchingCrates { span, crate_name, candidates }); } CrateError::SymbolConflictsCurrent(root_name) => { - sess.emit_err(SymbolConflictsCurrent { span, crate_name: root_name.to_string() }); + sess.emit_err(SymbolConflictsCurrent { span, crate_name: root_name }); } CrateError::SymbolConflictsOthers(root_name) => { - sess.emit_err(SymbolConflictsOthers { span, crate_name: root_name.to_string() }); + sess.emit_err(SymbolConflictsOthers { span, crate_name: root_name }); } CrateError::StableCrateIdCollision(crate_name0, crate_name1) => { sess.emit_err(StableCrateIdCollision { span, - crate_name0: crate_name0.to_string(), - crate_name1: crate_name1.to_string(), + crate_name0: crate_name0, + crate_name1: crate_name1, }); } CrateError::DlOpen(s) | CrateError::DlSym(s) => { - sess.emit_err(DlError { span, err: s.to_string() }); + sess.emit_err(DlError { span, err: s }); } CrateError::LocatorCombined(locator) => { let crate_name = locator.crate_name; @@ -1026,24 +1021,17 @@ impl CrateError { None => String::new(), Some(r) => format!(" which `{}` depends on", r.name), }; - // FIXME: Is there any way to get these notes and helps onto every diagnostic in this - // huge branch arm without changing them all to manual implementations? - let mut global_loc_notes = Vec::new(); - let mut global_loc_helps = Vec::new(); + // FIXME: There are no tests for CrateLocationUnknownType or LibFilenameForm if !locator.crate_rejections.via_filename.is_empty() { let mismatches = locator.crate_rejections.via_filename.iter(); for CrateMismatch { path, .. } in mismatches { - global_loc_notes.push(format!( - "extern location for {} is of an unknown type: {}", - crate_name, - path.display(), - )); - global_loc_helps.push(format!( - "file name should be lib*.rlib or {}*.{}", - locator.dll_prefix, locator.dll_suffix - )); + sess.emit_err(CrateLocationUnknownType { span, path: &path }); + sess.emit_err(LibFilenameForm { + span, + dll_prefix: &locator.dll_prefix, + dll_suffix: &locator.dll_suffix, + }); } - panic!("!!!!! REVERT THIS COMMIT !!!!!"); } let mut found_crates = String::new(); if !locator.crate_rejections.via_hash.is_empty() { @@ -1066,7 +1054,7 @@ impl CrateError { } sess.emit_err(NewerCrateVersion { span, - crate_name: crate_name.to_string(), + crate_name: crate_name, add_info, found_crates, }); @@ -1082,8 +1070,8 @@ impl CrateError { } sess.emit_err(NoCrateWithTriple { span, - crate_name: crate_name.to_string(), - locator_triple: locator.triple.to_string(), + crate_name: crate_name, + locator_triple: locator.triple.triple(), add_info, found_crates, }); @@ -1096,12 +1084,7 @@ impl CrateError { path.display() )); } - sess.emit_err(FoundStaticlib { - span, - crate_name: crate_name.to_string(), - add_info, - found_crates, - }); + sess.emit_err(FoundStaticlib { span, crate_name, add_info, found_crates }); } else if !locator.crate_rejections.via_version.is_empty() { let mismatches = locator.crate_rejections.via_version.iter(); for CrateMismatch { path, got } in mismatches { @@ -1114,7 +1097,7 @@ impl CrateError { } sess.emit_err(IncompatibleRustc { span, - crate_name: crate_name.to_string(), + crate_name, add_info, found_crates, rustc_version: rustc_version(), @@ -1126,15 +1109,14 @@ impl CrateError { } sess.emit_err(InvalidMetadataFiles { span, - crate_name: crate_name.to_string(), + crate_name, add_info, crate_rejections, }); } else { sess.emit_err(CannotFindCrate { span, - crate_name: crate_name.to_string(), - crate_name_symbol: crate_name, + crate_name, add_info, missing_core, current_crate: sess @@ -1149,7 +1131,7 @@ impl CrateError { } } CrateError::NonDylibPlugin(crate_name) => { - sess.emit_err(NoDylibPlugin { span, crate_name: crate_name.to_string() }); + sess.emit_err(NoDylibPlugin { span, crate_name }); } } } diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index dbaa2e9defa..19f64ef70c9 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -124,7 +124,7 @@ impl<'tcx> Collector<'tcx> { NativeLibKind::RawDylib } kind => { - sess.emit_err(UnknownLinkKind { span, kind: kind.to_string() }); + sess.emit_err(UnknownLinkKind { span, kind }); continue; } }; @@ -249,10 +249,7 @@ impl<'tcx> Collector<'tcx> { } let assign_modifier = |dst: &mut Option| { if dst.is_some() { - sess.emit_err(MultipleModifiers { - span, - modifier: modifier.to_string(), - }); + sess.emit_err(MultipleModifiers { span, modifier }); } else { *dst = Some(value); } @@ -287,10 +284,7 @@ impl<'tcx> Collector<'tcx> { } _ => { - sess.emit_err(UnknownLinkModifier { - span, - modifier: modifier.to_string(), - }); + sess.emit_err(UnknownLinkModifier { span, modifier }); } } } @@ -379,11 +373,11 @@ impl<'tcx> Collector<'tcx> { .filter_map(|lib| lib.name.as_ref()) .any(|n| n.as_str() == lib.name); if new_name.is_empty() { - self.tcx.sess.emit_err(EmptyRenamingTarget { lib_name: lib.name.clone() }); + self.tcx.sess.emit_err(EmptyRenamingTarget { lib_name: &lib.name }); } else if !any_duplicate { - self.tcx.sess.emit_err(RenamingNoLink { lib_name: lib.name.clone() }); + self.tcx.sess.emit_err(RenamingNoLink { lib_name: &lib.name }); } else if !renames.insert(&lib.name) { - self.tcx.sess.emit_err(MultipleRenamings { lib_name: lib.name.clone() }); + self.tcx.sess.emit_err(MultipleRenamings { lib_name: &lib.name }); } } } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 2b1f9f17a3c..8f55fb59f0b 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2270,7 +2270,7 @@ pub fn encode_metadata(tcx: TyCtxt<'_>, path: &Path) { fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) { let mut encoder = opaque::FileEncoder::new(path) - .unwrap_or_else(|err| tcx.sess.emit_fatal(FailCreateFileEncoder { err: err.to_string() })); + .unwrap_or_else(|err| tcx.sess.emit_fatal(FailCreateFileEncoder { err })); encoder.emit_raw_bytes(METADATA_HEADER); // Will be filled with the root position after encoding everything. @@ -2315,10 +2315,10 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) { // Encode the root position. let header = METADATA_HEADER.len(); file.seek(std::io::SeekFrom::Start(header as u64)) - .unwrap_or_else(|err| tcx.sess.emit_fatal(FailSeekFile { err: err.to_string() })); + .unwrap_or_else(|err| tcx.sess.emit_fatal(FailSeekFile { err })); let pos = root.position.get(); file.write_all(&[(pos >> 24) as u8, (pos >> 16) as u8, (pos >> 8) as u8, (pos >> 0) as u8]) - .unwrap_or_else(|err| tcx.sess.emit_fatal(FailWriteFile { err: err.to_string() })); + .unwrap_or_else(|err| tcx.sess.emit_fatal(FailWriteFile { err })); // Return to the position where we are before writing the root position. file.seek(std::io::SeekFrom::Start(pos_before_seek)).unwrap(); -- cgit 1.4.1-3-g733a5 From ee3c8350189de045ec71997874eaa6cebf99fbf3 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 31 Aug 2022 13:09:26 +0000 Subject: Always import all tracing macros for the entire crate instead of piecemeal by module --- compiler/rustc_ast/src/lib.rs | 3 +++ compiler/rustc_ast/src/util/literal.rs | 1 - compiler/rustc_ast_lowering/src/index.rs | 2 -- compiler/rustc_ast_lowering/src/path.rs | 1 - compiler/rustc_ast_passes/src/feature_gate.rs | 2 -- compiler/rustc_ast_passes/src/lib.rs | 3 +++ .../src/diagnostics/outlives_suggestion.rs | 1 - compiler/rustc_builtin_macros/src/lib.rs | 3 +++ compiler/rustc_builtin_macros/src/test.rs | 2 +- compiler/rustc_builtin_macros/src/test_harness.rs | 1 - compiler/rustc_codegen_llvm/src/asm.rs | 1 - compiler/rustc_codegen_llvm/src/back/archive.rs | 8 ++++---- compiler/rustc_codegen_llvm/src/back/lto.rs | 1 - compiler/rustc_codegen_llvm/src/back/write.rs | 1 - compiler/rustc_codegen_llvm/src/builder.rs | 1 - compiler/rustc_codegen_llvm/src/callee.rs | 1 - compiler/rustc_codegen_llvm/src/common.rs | 1 - compiler/rustc_codegen_llvm/src/consts.rs | 1 - compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs | 2 -- compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs | 1 - compiler/rustc_codegen_llvm/src/debuginfo/mod.rs | 1 - compiler/rustc_codegen_llvm/src/debuginfo/utils.rs | 2 +- compiler/rustc_codegen_llvm/src/declare.rs | 1 - compiler/rustc_codegen_llvm/src/llvm_util.rs | 1 - compiler/rustc_codegen_llvm/src/mono_item.rs | 1 - compiler/rustc_codegen_llvm/src/type_of.rs | 1 - compiler/rustc_error_messages/src/lib.rs | 4 +++- compiler/rustc_errors/src/diagnostic_builder.rs | 1 - compiler/rustc_errors/src/emitter.rs | 1 - compiler/rustc_expand/src/lib.rs | 3 +++ compiler/rustc_expand/src/mbe/macro_rules.rs | 1 - compiler/rustc_hir/src/definitions.rs | 1 - compiler/rustc_hir/src/lib.rs | 3 +++ compiler/rustc_interface/src/interface.rs | 2 +- compiler/rustc_interface/src/lib.rs | 3 +++ compiler/rustc_interface/src/passes.rs | 5 ++--- compiler/rustc_interface/src/queries.rs | 2 +- compiler/rustc_interface/src/util.rs | 2 +- compiler/rustc_lint/src/builtin.rs | 1 - compiler/rustc_lint/src/context.rs | 5 ++--- compiler/rustc_lint/src/early.rs | 1 - compiler/rustc_lint/src/internal.rs | 1 - compiler/rustc_lint/src/late.rs | 1 - compiler/rustc_lint/src/levels.rs | 1 - compiler/rustc_lint/src/lib.rs | 2 ++ compiler/rustc_lint/src/types.rs | 1 - compiler/rustc_metadata/src/creader.rs | 3 +-- compiler/rustc_metadata/src/dependency_format.rs | 6 +++--- compiler/rustc_metadata/src/lib.rs | 3 +++ compiler/rustc_metadata/src/locator.rs | 1 - compiler/rustc_metadata/src/rmeta/decoder.rs | 1 - compiler/rustc_metadata/src/rmeta/encoder.rs | 1 - compiler/rustc_metadata/src/rmeta/table.rs | 1 - compiler/rustc_mir_build/src/thir/cx/expr.rs | 2 +- compiler/rustc_parse/src/lexer/mod.rs | 2 -- .../rustc_parse/src/lexer/unescape_error_reporting.rs | 8 ++------ compiler/rustc_parse/src/parser/attr.rs | 2 -- compiler/rustc_parse/src/parser/diagnostics.rs | 1 - compiler/rustc_parse/src/parser/item.rs | 1 - compiler/rustc_parse/src/parser/mod.rs | 1 - compiler/rustc_parse/src/parser/path.rs | 1 - compiler/rustc_privacy/src/lib.rs | 5 ++++- compiler/rustc_resolve/src/access_levels.rs | 2 +- compiler/rustc_resolve/src/build_reduced_graph.rs | 1 - compiler/rustc_resolve/src/def_collector.rs | 1 - compiler/rustc_resolve/src/diagnostics.rs | 1 - compiler/rustc_resolve/src/imports.rs | 2 -- compiler/rustc_resolve/src/late.rs | 7 ++----- compiler/rustc_resolve/src/late/diagnostics.rs | 2 -- compiler/rustc_resolve/src/late/lifetimes.rs | 2 +- compiler/rustc_resolve/src/lib.rs | 1 - compiler/rustc_save_analysis/src/dump_visitor.rs | 2 -- compiler/rustc_save_analysis/src/lib.rs | 5 +++-- compiler/rustc_session/src/cgu_reuse_tracker.rs | 1 - compiler/rustc_session/src/config.rs | 2 +- compiler/rustc_session/src/filesearch.rs | 1 - compiler/rustc_session/src/lib.rs | 3 +++ compiler/rustc_span/src/hygiene.rs | 1 - compiler/rustc_span/src/lib.rs | 2 -- compiler/rustc_span/src/source_map.rs | 1 - compiler/rustc_symbol_mangling/src/legacy.rs | 2 -- compiler/rustc_symbol_mangling/src/lib.rs | 5 +++-- .../src/traits/error_reporting/mod.rs | 2 +- compiler/rustc_transmute/src/layout/tree.rs | 16 ++++++++-------- compiler/rustc_transmute/src/maybe_transmutable/mod.rs | 4 ++-- .../src/maybe_transmutable/query_context.rs | 2 +- compiler/rustc_ty_utils/src/instance.rs | 2 -- compiler/rustc_typeck/src/check/generator_interior.rs | 1 - 88 files changed, 76 insertions(+), 119 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 27061f300a2..e5435e3a3d4 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -26,6 +26,9 @@ #[macro_use] extern crate rustc_macros; +#[macro_use] +extern crate tracing; + pub mod util { pub mod classify; pub mod comments; diff --git a/compiler/rustc_ast/src/util/literal.rs b/compiler/rustc_ast/src/util/literal.rs index 69a78d165ef..6a1578498e6 100644 --- a/compiler/rustc_ast/src/util/literal.rs +++ b/compiler/rustc_ast/src/util/literal.rs @@ -9,7 +9,6 @@ use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; use std::ascii; -use tracing::debug; pub enum LitError { NotLiteral, diff --git a/compiler/rustc_ast_lowering/src/index.rs b/compiler/rustc_ast_lowering/src/index.rs index a0547497b19..219e1b81d1e 100644 --- a/compiler/rustc_ast_lowering/src/index.rs +++ b/compiler/rustc_ast_lowering/src/index.rs @@ -11,8 +11,6 @@ use rustc_session::Session; use rustc_span::source_map::SourceMap; use rustc_span::{Span, DUMMY_SP}; -use tracing::debug; - /// A visitor that walks over the HIR and collects `Node`s into a HIR map. pub(super) struct NodeCollector<'a, 'hir> { /// Source map diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 5874d08a94f..897c7215805 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -13,7 +13,6 @@ use rustc_span::symbol::{kw, Ident}; use rustc_span::{BytePos, Span, DUMMY_SP}; use smallvec::smallvec; -use tracing::debug; impl<'a, 'hir> LoweringContext<'a, 'hir> { #[instrument(level = "trace", skip(self))] diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 6f7e88eb86f..ca5b7a64155 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -11,8 +11,6 @@ use rustc_span::source_map::Spanned; use rustc_span::symbol::sym; use rustc_span::Span; -use tracing::debug; - macro_rules! gate_feature_fn { ($visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr, $help: expr) => {{ let (visitor, has_feature, span, name, explain, help) = diff --git a/compiler/rustc_ast_passes/src/lib.rs b/compiler/rustc_ast_passes/src/lib.rs index f282ff251bd..af25982e288 100644 --- a/compiler/rustc_ast_passes/src/lib.rs +++ b/compiler/rustc_ast_passes/src/lib.rs @@ -12,6 +12,9 @@ #![feature(let_else)] #![recursion_limit = "256"] +#[macro_use] +extern crate tracing; + pub mod ast_validation; mod errors; pub mod feature_gate; diff --git a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs index d359d7efb62..35c3df76899 100644 --- a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs +++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs @@ -6,7 +6,6 @@ use rustc_errors::Diagnostic; use rustc_middle::ty::RegionVid; use smallvec::SmallVec; use std::collections::BTreeMap; -use tracing::debug; use crate::MirBorrowckCtxt; diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 11565ba72d7..280fa704511 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -16,6 +16,9 @@ extern crate proc_macro; +#[macro_use] +extern crate tracing; + use crate::deriving::*; use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind}; diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 7eee8073366..7efb6cc61ee 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -335,7 +335,7 @@ pub fn expand_test_or_bench( // extern crate test let test_extern = cx.item(sp, test_id, ast::AttrVec::new(), ast::ItemKind::ExternCrate(None)); - tracing::debug!("synthetic test item:\n{}\n", pprust::item_to_string(&test_const)); + debug!("synthetic test item:\n{}\n", pprust::item_to_string(&test_const)); if is_stmt { vec![ diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 89b0d2cc9be..079c6ff37cf 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -15,7 +15,6 @@ use rustc_span::{Span, DUMMY_SP}; use rustc_target::spec::PanicStrategy; use smallvec::{smallvec, SmallVec}; use thin_vec::thin_vec; -use tracing::debug; use std::{iter, mem}; diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index 2a6612eb86f..5202ac697e9 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -19,7 +19,6 @@ use rustc_target::asm::*; use libc::{c_char, c_uint}; use smallvec::SmallVec; -use tracing::debug; impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { fn codegen_inline_asm( diff --git a/compiler/rustc_codegen_llvm/src/back/archive.rs b/compiler/rustc_codegen_llvm/src/back/archive.rs index 2e614e5dd88..38a366095b4 100644 --- a/compiler/rustc_codegen_llvm/src/back/archive.rs +++ b/compiler/rustc_codegen_llvm/src/back/archive.rs @@ -190,10 +190,10 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder { let output_path_z = rustc_fs_util::path_to_c_string(&output_path); - tracing::trace!("invoking LLVMRustWriteImportLibrary"); - tracing::trace!(" dll_name {:#?}", dll_name_z); - tracing::trace!(" output_path {}", output_path.display()); - tracing::trace!( + trace!("invoking LLVMRustWriteImportLibrary"); + trace!(" dll_name {:#?}", dll_name_z); + trace!(" output_path {}", output_path.display()); + trace!( " import names: {}", dll_imports .iter() diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index e4af6269abc..a89df00e248 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -18,7 +18,6 @@ use rustc_middle::dep_graph::WorkProduct; use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel}; use rustc_session::cgu_reuse_tracker::CguReuse; use rustc_session::config::{self, CrateType, Lto}; -use tracing::{debug, info}; use std::ffi::{CStr, CString}; use std::fs::File; diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 740a68d0772..a695df8409b 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -28,7 +28,6 @@ use rustc_session::Session; use rustc_span::symbol::sym; use rustc_span::InnerSpan; use rustc_target::spec::{CodeModel, RelocModel, SanitizerSet, SplitDebuginfo}; -use tracing::debug; use libc::{c_char, c_int, c_uint, c_void, size_t}; use std::ffi::CString; diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index e7e373bf45d..63b63c6a1fa 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -27,7 +27,6 @@ use std::ffi::CStr; use std::iter; use std::ops::Deref; use std::ptr; -use tracing::{debug, instrument}; // All Builders must have an llfn associated with them #[must_use] diff --git a/compiler/rustc_codegen_llvm/src/callee.rs b/compiler/rustc_codegen_llvm/src/callee.rs index d55f995b933..b83c1e8f08f 100644 --- a/compiler/rustc_codegen_llvm/src/callee.rs +++ b/compiler/rustc_codegen_llvm/src/callee.rs @@ -11,7 +11,6 @@ use crate::context::CodegenCx; use crate::llvm; use crate::value::Value; use rustc_codegen_ssa::traits::*; -use tracing::debug; use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt}; use rustc_middle::ty::{self, Instance, TypeVisitable}; diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index 63d3bb40a3f..13e437cfbf7 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -21,7 +21,6 @@ use rustc_target::spec::Target; use libc::{c_char, c_uint}; use std::fmt::Write; -use tracing::debug; /* * A note on nomenclature of linking: "extern", "foreign", and "upcall". diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index d3e33da2799..a559f7f3d57 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -23,7 +23,6 @@ use rustc_target::abi::{ AddressSpace, Align, HasDataLayout, Primitive, Scalar, Size, WrappingRange, }; use std::ops::Range; -use tracing::debug; pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<'_>) -> &'ll Value { let alloc = alloc.inner(); diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index 58f391692c4..0d1df6fb1ac 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -16,8 +16,6 @@ use rustc_middle::ty::TyCtxt; use std::ffi::CString; -use tracing::debug; - /// Generates and exports the Coverage Map. /// /// Rust Coverage Map generation supports LLVM Coverage Mapping Format versions diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs index 98ba38356a4..964a632b6ee 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs @@ -28,7 +28,6 @@ use std::cell::RefCell; use std::ffi::CString; use std::iter; -use tracing::debug; pub mod mapgen; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index cf591295b84..b23fe3fc9d5 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -39,7 +39,6 @@ use smallvec::SmallVec; use std::cell::OnceCell; use std::cell::RefCell; use std::iter; -use tracing::debug; mod create_scope_map; pub mod gdb; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs b/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs index 8f243673907..a40cfc8b23f 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs @@ -6,7 +6,7 @@ use super::CodegenUnitDebugContext; use rustc_hir::def_id::DefId; use rustc_middle::ty::layout::{HasParamEnv, LayoutOf}; use rustc_middle::ty::{self, DefIdTree, Ty}; -use tracing::trace; +use trace; use crate::common::CodegenCx; use crate::llvm; diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs index fa0ecd18fc8..0f663a26732 100644 --- a/compiler/rustc_codegen_llvm/src/declare.rs +++ b/compiler/rustc_codegen_llvm/src/declare.rs @@ -22,7 +22,6 @@ use rustc_codegen_ssa::traits::TypeMembershipMethods; use rustc_middle::ty::Ty; use rustc_symbol_mangling::typeid::typeid_for_fnabi; use smallvec::SmallVec; -use tracing::debug; /// Declare a function. /// diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index f5d676c44e3..1b049dfe979 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -15,7 +15,6 @@ use rustc_span::symbol::Symbol; use rustc_target::spec::{MergeFunctions, PanicStrategy}; use smallvec::{smallvec, SmallVec}; use std::ffi::{CStr, CString}; -use tracing::debug; use std::mem; use std::path::Path; diff --git a/compiler/rustc_codegen_llvm/src/mono_item.rs b/compiler/rustc_codegen_llvm/src/mono_item.rs index 6e94284852f..1eceb7f5c87 100644 --- a/compiler/rustc_codegen_llvm/src/mono_item.rs +++ b/compiler/rustc_codegen_llvm/src/mono_item.rs @@ -11,7 +11,6 @@ use rustc_middle::ty::layout::{FnAbiOf, LayoutOf}; use rustc_middle::ty::{self, Instance, TypeVisitable}; use rustc_session::config::CrateType; use rustc_target::spec::RelocModel; -use tracing::debug; impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'_, 'tcx> { fn predefine_static( diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index 9f0e6c80b19..dc1165835e7 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -11,7 +11,6 @@ use rustc_target::abi::{Abi, AddressSpace, Align, FieldsShape}; use rustc_target::abi::{Int, Pointer, F32, F64}; use rustc_target::abi::{PointeeInfo, Scalar, Size, TyAbiInterface, Variants}; use smallvec::{smallvec, SmallVec}; -use tracing::debug; use std::fmt::Write; diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 8f47be25db9..ed5e092814f 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -5,6 +5,9 @@ #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] +#[macro_use] +extern crate tracing; + use fluent_bundle::FluentResource; use fluent_syntax::parser::ParserError; use rustc_data_structures::sync::Lrc; @@ -16,7 +19,6 @@ use std::fmt; use std::fs; use std::io; use std::path::{Path, PathBuf}; -use tracing::{instrument, trace}; #[cfg(not(parallel_compiler))] use std::cell::LazyCell as Lazy; diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index 61d767a1cc6..7e29dc207ac 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -12,7 +12,6 @@ use std::fmt::{self, Debug}; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; use std::thread::panicking; -use tracing::debug; /// Used for emitting structured error messages and other diagnostic information. /// diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 6c1bfcb9919..e79ce11a6fc 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -34,7 +34,6 @@ use std::iter; use std::path::Path; use termcolor::{Ansi, BufferWriter, ColorChoice, ColorSpec, StandardStream}; use termcolor::{Buffer, Color, WriteColor}; -use tracing::*; /// Default column width, used in tests and when terminal dimensions cannot be determined. const DEFAULT_COLUMN_WIDTH: usize = 140; diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index 75dcbd69674..ac0e200b1b7 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -15,6 +15,9 @@ #[macro_use] extern crate rustc_macros; +#[macro_use] +extern crate tracing; + extern crate proc_macro as pm; mod placeholders; diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 86dbd33a221..7764ffd246e 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -32,7 +32,6 @@ use rustc_span::Span; use std::borrow::Cow; use std::collections::hash_map::Entry; use std::{mem, slice}; -use tracing::debug; pub(crate) struct ParserAnyMacro<'a> { parser: Parser<'a>, diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs index c2c551e78a4..d85ac960f9b 100644 --- a/compiler/rustc_hir/src/definitions.rs +++ b/compiler/rustc_hir/src/definitions.rs @@ -15,7 +15,6 @@ use rustc_span::symbol::{kw, sym, Symbol}; use std::fmt::{self, Write}; use std::hash::Hash; -use tracing::debug; /// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa. /// Internally the `DefPathTable` holds a tree of `DefKey`s, where each `DefKey` diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index 092029ef09e..1b33cb9c2da 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -17,6 +17,9 @@ #[macro_use] extern crate rustc_macros; +#[macro_use] +extern crate tracing; + #[macro_use] extern crate rustc_data_structures; diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 1c6243c275c..949bd02ad68 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -332,7 +332,7 @@ pub fn create_compiler_and_run(config: Config, f: impl FnOnce(&Compiler) -> R // JUSTIFICATION: before session exists, only config #[allow(rustc::bad_opt_access)] pub fn run_compiler(config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R { - tracing::trace!("run_compiler"); + trace!("run_compiler"); util::run_in_thread_pool_with_globals( config.opts.edition, config.opts.unstable_opts.threads, diff --git a/compiler/rustc_interface/src/lib.rs b/compiler/rustc_interface/src/lib.rs index 258e38c3bdb..1a8d619fafb 100644 --- a/compiler/rustc_interface/src/lib.rs +++ b/compiler/rustc_interface/src/lib.rs @@ -8,6 +8,9 @@ #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] +#[macro_use] +extern crate tracing; + mod callbacks; mod errors; pub mod interface; diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 66c6a229b89..f8b40949e2e 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -38,7 +38,6 @@ use rustc_span::symbol::{sym, Symbol}; use rustc_span::FileName; use rustc_trait_selection::traits; use rustc_typeck as typeck; -use tracing::{info, warn}; use std::any::Any; use std::cell::RefCell; @@ -165,7 +164,7 @@ pub fn create_resolver( krate: &ast::Crate, crate_name: &str, ) -> BoxedResolver { - tracing::trace!("create_resolver"); + trace!("create_resolver"); BoxedResolver::new(sess, move |sess, resolver_arenas| { Resolver::new(sess, krate, crate_name, metadata_loader, resolver_arenas) }) @@ -279,7 +278,7 @@ pub fn configure_and_expand( crate_name: &str, resolver: &mut Resolver<'_>, ) -> Result { - tracing::trace!("configure_and_expand"); + trace!("configure_and_expand"); pre_expansion_lint(sess, lint_store, resolver.registered_tools(), &krate, crate_name); rustc_builtin_macros::register_builtin_macros(resolver); diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 65fa8d7495a..6c725a01b53 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -166,7 +166,7 @@ impl<'tcx> Queries<'tcx> { pub fn expansion( &self, ) -> Result<&Query<(Lrc, Rc>, Lrc)>> { - tracing::trace!("expansion"); + trace!("expansion"); self.expansion.compute(|| { let crate_name = self.crate_name()?.peek().clone(); let (krate, lint_store) = self.register_plugins()?.take(); diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index e74978485a2..f7e70d355cf 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -1,3 +1,4 @@ +use info; use libloading::Library; use rustc_ast as ast; use rustc_codegen_ssa::traits::CodegenBackend; @@ -31,7 +32,6 @@ use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::OnceLock; use std::thread; -use tracing::info; /// Function pointer type that constructs a new CodegenBackend. pub type MakeBackendFn = fn() -> Box; diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 868555a72b0..4a744748b2b 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -59,7 +59,6 @@ use rustc_trait_selection::traits::{self, misc::can_type_implement_copy}; use crate::nonstandard_style::{method_context, MethodLateContext}; use std::fmt::Write; -use tracing::{debug, trace}; // hardwired lints from librustc_middle pub use rustc_session::lint::builtin::*; diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 002bba4759b..e3b6c015987 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -45,7 +45,6 @@ use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::{BytePos, Span}; use rustc_target::abi; -use tracing::debug; use std::cell::Cell; use std::iter; @@ -417,7 +416,7 @@ impl LintStore { None => { // 1. The tool is currently running, so this lint really doesn't exist. // FIXME: should this handle tools that never register a lint, like rustfmt? - tracing::debug!("lints={:?}", self.by_name.keys().collect::>()); + debug!("lints={:?}", self.by_name.keys().collect::>()); let tool_prefix = format!("{}::", tool_name); return if self.by_name.keys().any(|lint| lint.starts_with(&tool_prefix)) { self.no_lint_suggestion(&complete_name) @@ -510,7 +509,7 @@ impl LintStore { CheckLintNameResult::Tool(Err((Some(slice::from_ref(id)), complete_name))) } Some(other) => { - tracing::debug!("got renamed lint {:?}", other); + debug!("got renamed lint {:?}", other); CheckLintNameResult::NoLint(None) } } diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index cdb5b3c4284..27d173ebde8 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -26,7 +26,6 @@ use rustc_span::symbol::Ident; use rustc_span::Span; use std::slice; -use tracing::debug; macro_rules! run_early_pass { ($cx:expr, $f:ident, $($args:expr),*) => ({ $cx.pass.$f(&$cx.context, $($args),*); diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 6d451f3090a..16b7d2cbbae 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -12,7 +12,6 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::hygiene::{ExpnKind, MacroKind}; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; -use tracing::debug; declare_tool_lint! { pub rustc::DEFAULT_HASH_TYPES, diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index 5188ac633d3..8a336844dc2 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -29,7 +29,6 @@ use rustc_span::Span; use std::any::Any; use std::cell::Cell; use std::slice; -use tracing::debug; /// Extract the `LintStore` from the query context. /// This function exists because we've erased `LintStore` as `dyn Any` in the context. diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 89409b58f88..f1d8ef2e47d 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -21,7 +21,6 @@ use rustc_session::parse::{add_feature_diagnostics, feature_err}; use rustc_session::Session; use rustc_span::symbol::{sym, Symbol}; use rustc_span::{Span, DUMMY_SP}; -use tracing::debug; use crate::errors::{ MalformedAttribute, MalformedAttributeSub, OverruledAttribute, OverruledAttributeSub, diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index c3065e4a2d9..801249badcc 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -42,6 +42,8 @@ extern crate rustc_middle; #[macro_use] extern crate rustc_session; +#[macro_use] +extern crate tracing; mod array_into_iter; pub mod builtin; diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 484e541afc5..03166519981 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -19,7 +19,6 @@ use rustc_target::spec::abi::Abi as SpecAbi; use std::cmp; use std::iter; use std::ops::ControlFlow; -use tracing::debug; declare_lint! { /// The `unused_comparisons` lint detects comparisons made useless by diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 708d0b1fd8a..6a5716600b3 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -29,7 +29,6 @@ use proc_macro::bridge::client::ProcMacro; use std::ops::Fn; use std::path::Path; use std::{cmp, env}; -use tracing::{debug, info}; #[derive(Clone)] pub struct CStore { @@ -263,7 +262,7 @@ impl<'a> CrateLoader<'a> { fn existing_match(&self, name: Symbol, hash: Option, kind: PathKind) -> Option { for (cnum, data) in self.cstore.iter_crate_data() { if data.name() != name { - tracing::trace!("{} did not match {}", data.name(), name); + trace!("{} did not match {}", data.name(), name); continue; } diff --git a/compiler/rustc_metadata/src/dependency_format.rs b/compiler/rustc_metadata/src/dependency_format.rs index b765c34f8e3..1a25e987d3a 100644 --- a/compiler/rustc_metadata/src/dependency_format.rs +++ b/compiler/rustc_metadata/src/dependency_format.rs @@ -158,11 +158,11 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList { let name = tcx.crate_name(cnum); let src = tcx.used_crate_source(cnum); if src.dylib.is_some() { - tracing::info!("adding dylib: {}", name); + info!("adding dylib: {}", name); add_library(tcx, cnum, RequireDynamic, &mut formats); let deps = tcx.dylib_dependency_formats(cnum); for &(depnum, style) in deps.iter() { - tracing::info!("adding {:?}: {}", style, tcx.crate_name(depnum)); + info!("adding {:?}: {}", style, tcx.crate_name(depnum)); add_library(tcx, depnum, style, &mut formats); } } @@ -190,7 +190,7 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList { && tcx.dep_kind(cnum) == CrateDepKind::Explicit { assert!(src.rlib.is_some() || src.rmeta.is_some()); - tracing::info!("adding staticlib: {}", tcx.crate_name(cnum)); + info!("adding staticlib: {}", tcx.crate_name(cnum)); add_library(tcx, cnum, RequireStatic, &mut formats); ret[cnum.as_usize() - 1] = Linkage::Static; } diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index 6440f3e390c..337d3cca2ae 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -26,6 +26,9 @@ extern crate rustc_middle; #[macro_use] extern crate rustc_data_structures; +#[macro_use] +extern crate tracing; + pub use rmeta::{provide, provide_extern}; mod dependency_format; diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 2c1c84b0be2..5b7d0c8581a 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -236,7 +236,6 @@ use std::fmt::Write as _; use std::io::{Read, Result as IoResult, Write}; use std::path::{Path, PathBuf}; use std::{cmp, fmt, fs}; -use tracing::{debug, info}; #[derive(Clone)] pub(crate) struct CrateLocator<'a> { diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index d0e0aa91480..b28f54fac1a 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -42,7 +42,6 @@ use std::iter::TrustedLen; use std::mem; use std::num::NonZeroUsize; use std::path::Path; -use tracing::debug; pub(super) use cstore_impl::provide; pub use cstore_impl::provide_extern; diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 3482d9f0451..34d8edc30cd 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -44,7 +44,6 @@ use std::io::{Read, Seek, Write}; use std::iter; use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; -use tracing::{debug, trace}; pub(super) struct EncodeContext<'a, 'tcx> { opaque: opaque::FileEncoder, diff --git a/compiler/rustc_metadata/src/rmeta/table.rs b/compiler/rustc_metadata/src/rmeta/table.rs index 21841ae2532..8085675d75c 100644 --- a/compiler/rustc_metadata/src/rmeta/table.rs +++ b/compiler/rustc_metadata/src/rmeta/table.rs @@ -10,7 +10,6 @@ use rustc_span::hygiene::MacroKind; use std::convert::TryInto; use std::marker::PhantomData; use std::num::NonZeroUsize; -use tracing::debug; /// Helper trait, for encoding to, and decoding from, a fixed number of bytes. /// Used mainly for Lazy positions and lengths. diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 0c2b117453f..9ed1c064d2b 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -268,7 +268,7 @@ impl<'tcx> Cx<'tcx> { // the overall method call for better diagnostics. args[0] // is guaranteed to exist, since a method call always has a receiver. let old_adjustment_span = self.adjustment_span.replace((args[0].hir_id, expr_span)); - tracing::info!("Using method span: {:?}", expr.span); + info!("Using method span: {:?}", expr.span); let args = self.mirror_exprs(args); self.adjustment_span = old_adjustment_span; ExprKind::Call { diff --git a/compiler/rustc_parse/src/lexer/mod.rs b/compiler/rustc_parse/src/lexer/mod.rs index 848e142e59c..63819a2f98d 100644 --- a/compiler/rustc_parse/src/lexer/mod.rs +++ b/compiler/rustc_parse/src/lexer/mod.rs @@ -14,8 +14,6 @@ use rustc_session::parse::ParseSess; use rustc_span::symbol::{sym, Symbol}; use rustc_span::{edition::Edition, BytePos, Pos, Span}; -use tracing::debug; - mod tokentrees; mod unescape_error_reporting; mod unicode_chars; diff --git a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs index 273827864f1..77c4fadab45 100644 --- a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs +++ b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs @@ -20,13 +20,9 @@ pub(crate) fn emit_unescape_error( range: Range, error: EscapeError, ) { - tracing::debug!( + debug!( "emit_unescape_error: {:?}, {:?}, {:?}, {:?}, {:?}", - lit, - span_with_quotes, - mode, - range, - error + lit, span_with_quotes, mode, range, error ); let last_char = || { let c = lit[range.clone()].chars().rev().next().unwrap(); diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index 72ab96b5ca6..77a6bde1c16 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -7,8 +7,6 @@ use rustc_errors::{error_code, Diagnostic, PResult}; use rustc_span::{sym, BytePos, Span}; use std::convert::TryInto; -use tracing::debug; - // Public for rustfmt usage #[derive(Debug)] pub enum InnerAttrPolicy<'a> { diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index f0ea1dfe297..dd806e2130e 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -29,7 +29,6 @@ use std::ops::{Deref, DerefMut}; use std::mem::take; use crate::parser; -use tracing::{debug, trace}; const TURBOFISH_SUGGESTION_STR: &str = "use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments"; diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index b743162a7e4..5b75d1d5f22 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -22,7 +22,6 @@ use rustc_span::DUMMY_SP; use std::convert::TryFrom; use std::mem; -use tracing::debug; impl<'a> Parser<'a> { /// Parses a source module as a crate. This is the main entry point for the parser. diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 5e79308464f..5c8f374255c 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -37,7 +37,6 @@ use rustc_errors::{ use rustc_session::parse::ParseSess; use rustc_span::source_map::{Span, DUMMY_SP}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; -use tracing::debug; use std::ops::Range; use std::{cmp, mem, slice}; diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index fc7fb866f11..fdc1af27f82 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -13,7 +13,6 @@ use rustc_span::source_map::{BytePos, Span}; use rustc_span::symbol::{kw, sym, Ident}; use std::mem; -use tracing::debug; /// Specifies how to parse a path. #[derive(Copy, Clone, PartialEq)] diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 5d562f18a81..a9271761358 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -8,6 +8,9 @@ #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] +#[macro_use] +extern crate tracing; + mod errors; use rustc_ast::MacroDef; @@ -1784,7 +1787,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> { fn leaks_private_dep(&self, item_id: DefId) -> bool { let ret = self.required_visibility.is_public() && self.tcx.is_private_dep(item_id.krate); - tracing::debug!("leaks_private_dep(item_id={:?})={}", item_id, ret); + debug!("leaks_private_dep(item_id={:?})={}", item_id, ret); ret } } diff --git a/compiler/rustc_resolve/src/access_levels.rs b/compiler/rustc_resolve/src/access_levels.rs index 3fba923d9fd..882a92c0ebb 100644 --- a/compiler/rustc_resolve/src/access_levels.rs +++ b/compiler/rustc_resolve/src/access_levels.rs @@ -39,7 +39,7 @@ impl<'r, 'a> AccessLevelsVisitor<'r, 'a> { visit::walk_crate(&mut visitor, krate); } - tracing::info!("resolve::access_levels: {:#?}", r.access_levels); + info!("resolve::access_levels: {:#?}", r.access_levels); } fn reset(&mut self) { diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 8f3b6009bd6..cd0b2443da5 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -36,7 +36,6 @@ use rustc_span::Span; use std::cell::Cell; use std::ptr; -use tracing::debug; type Res = def::Res; diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 66641fb2cb2..5955d8df16e 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -8,7 +8,6 @@ use rustc_hir::definitions::*; use rustc_span::hygiene::LocalExpnId; use rustc_span::symbol::sym; use rustc_span::Span; -use tracing::debug; pub(crate) fn collect_definitions( resolver: &mut Resolver<'_>, diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 2d15b1b0a1b..4fd6fe4e36c 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -25,7 +25,6 @@ use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::source_map::SourceMap; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{BytePos, Span}; -use tracing::debug; use crate::imports::{Import, ImportKind, ImportResolver}; use crate::late::{PatternSource, Rib}; diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index c2491c6ebde..619ce046220 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -23,8 +23,6 @@ use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::symbol::{kw, Ident, Symbol}; use rustc_span::Span; -use tracing::*; - use std::cell::Cell; use std::{mem, ptr}; diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 4cdfc6e7a4d..dbe4d691f04 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -32,7 +32,6 @@ use smallvec::{smallvec, SmallVec}; use rustc_span::source_map::{respan, Spanned}; use std::collections::{hash_map::Entry, BTreeSet}; use std::mem::{replace, take}; -use tracing::debug; mod diagnostics; pub(crate) mod lifetimes; @@ -3268,11 +3267,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { source: PathSource<'ast>, finalize: Finalize, ) -> PartialRes { - tracing::debug!( + debug!( "smart_resolve_path_fragment(qself={:?}, path={:?}, finalize={:?})", - qself, - path, - finalize, + qself, path, finalize, ); let ns = source.namespace(); diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 9fc637ddbbf..99d13acbae1 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -33,8 +33,6 @@ use rustc_span::{BytePos, Span}; use std::iter; use std::ops::Deref; -use tracing::debug; - type Res = def::Res; /// A field or associated item from self type suggested in case of resolution failure. diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index 242dad17ec9..c16eab222f6 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -1212,7 +1212,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { scope: &wrap_scope, trait_definition_only: self.trait_definition_only, }; - let span = tracing::debug_span!("scope", scope = ?TruncatedScopeDebug(&this.scope)); + let span = debug_span!("scope", scope = ?TruncatedScopeDebug(&this.scope)); { let _enter = span.enter(); f(&mut this); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 5c33cb694a7..4e8f3a2cae8 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -58,7 +58,6 @@ use smallvec::{smallvec, SmallVec}; use std::cell::{Cell, RefCell}; use std::collections::BTreeSet; use std::{cmp, fmt, ptr}; -use tracing::debug; use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion}; use imports::{Import, ImportKind, ImportResolver, NameResolution}; diff --git a/compiler/rustc_save_analysis/src/dump_visitor.rs b/compiler/rustc_save_analysis/src/dump_visitor.rs index e2e0e1f5b30..ac6c3663b63 100644 --- a/compiler/rustc_save_analysis/src/dump_visitor.rs +++ b/compiler/rustc_save_analysis/src/dump_visitor.rs @@ -44,8 +44,6 @@ use rls_data::{ RefKind, Relation, RelationKind, SpanData, }; -use tracing::{debug, error}; - #[rustfmt::skip] // https://github.com/rust-lang/rustfmt/issues/5213 macro_rules! down_cast_data { ($id:ident, $kind:ident, $sp:expr) => { diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index 619e083d89a..16af5338510 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -7,6 +7,9 @@ #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] +#[macro_use] +extern crate tracing; + mod dump_visitor; mod dumper; #[macro_use] @@ -49,8 +52,6 @@ use rls_data::{ RefKind, Relation, RelationKind, SpanData, }; -use tracing::{debug, error, info}; - pub struct SaveContext<'tcx> { tcx: TyCtxt<'tcx>, maybe_typeck_results: Option<&'tcx ty::TypeckResults<'tcx>>, diff --git a/compiler/rustc_session/src/cgu_reuse_tracker.rs b/compiler/rustc_session/src/cgu_reuse_tracker.rs index 2a4a772f610..2336d99363f 100644 --- a/compiler/rustc_session/src/cgu_reuse_tracker.rs +++ b/compiler/rustc_session/src/cgu_reuse_tracker.rs @@ -10,7 +10,6 @@ use rustc_span::{Span, Symbol}; use std::borrow::Cow; use std::fmt::{self}; use std::sync::{Arc, Mutex}; -use tracing::debug; #[derive(Copy, Clone, Debug, PartialEq, PartialOrd)] pub enum CguReuse { diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 162fc9aa0a6..7c50fe2d823 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2530,7 +2530,7 @@ fn parse_pretty(unstable_opts: &UnstableOptions, efmt: ErrorOutputType) -> Optio ), ), }; - tracing::debug!("got unpretty option: {first:?}"); + debug!("got unpretty option: {first:?}"); Some(first) } diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs index c973e3140ce..e8edb38f503 100644 --- a/compiler/rustc_session/src/filesearch.rs +++ b/compiler/rustc_session/src/filesearch.rs @@ -7,7 +7,6 @@ use std::path::{Path, PathBuf}; use crate::search_paths::{PathKind, SearchPath}; use rustc_fs_util::fix_windows_verbatim_for_gcc; -use tracing::debug; #[derive(Copy, Clone)] pub enum FileMatch { diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index 429475c573c..02d5d33c8d5 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -14,6 +14,9 @@ extern crate rustc_macros; pub mod errors; +#[macro_use] +extern crate tracing; + pub mod cgu_reuse_tracker; pub mod utils; pub use lint::{declare_lint, declare_lint_pass, declare_tool_lint, impl_lint_pass}; diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index e169d3c7cfb..e8ddb4ed17a 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -41,7 +41,6 @@ use rustc_macros::HashStable_Generic; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use std::fmt; use std::hash::Hash; -use tracing::*; /// A `SyntaxContext` represents a chain of pairs `(ExpnId, Transparency)` named "marks". #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 860af7fe93a..34e2e92bdfc 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -76,8 +76,6 @@ use md5::Md5; use sha1::Sha1; use sha2::Sha256; -use tracing::debug; - #[cfg(test)] mod tests; diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index a32cabab4c4..8ffbbff7a7d 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -23,7 +23,6 @@ use std::{convert::TryFrom, unreachable}; use std::fs; use std::io; -use tracing::debug; #[cfg(test)] mod tests; diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index 9241fd82c74..46c5fe78ffb 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -6,8 +6,6 @@ use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeVisitable}; use rustc_middle::util::common::record_time; -use tracing::debug; - use std::fmt::{self, Write}; use std::mem::{self, discriminant}; diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index 0c6489acb34..62f44a48032 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -97,6 +97,9 @@ #[macro_use] extern crate rustc_middle; +#[macro_use] +extern crate tracing; + use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; @@ -107,8 +110,6 @@ use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, Instance, TyCtxt}; use rustc_session::config::SymbolManglingVersion; -use tracing::debug; - mod legacy; mod v0; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index e4af7022239..99046bd126f 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -2014,7 +2014,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> { let predicate = self.resolve_vars_if_possible(obligation.predicate); let span = obligation.cause.span; - debug!(?predicate, obligation.cause.code = tracing::field::debug(&obligation.cause.code())); + debug!(?predicate, obligation.cause.code = ?obligation.cause.code()); // Ambiguity errors are often caused as fallout from earlier errors. // We ignore them if this `infcx` is tainted in some cases below. diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs index 4ab6d3737c5..211c813b800 100644 --- a/compiler/rustc_transmute/src/layout/tree.rs +++ b/compiler/rustc_transmute/src/layout/tree.rs @@ -317,7 +317,7 @@ pub(crate) mod rustc { tcx, )?, AdtKind::Enum => { - tracing::trace!(?adt_def, "treeifying enum"); + trace!(?adt_def, "treeifying enum"); let mut tree = Tree::uninhabited(); for (idx, discr) in adt_def.discriminants(tcx) { @@ -381,7 +381,7 @@ pub(crate) mod rustc { let clamp = |align: Align| align.clamp(min_align, max_align).bytes().try_into().unwrap(); - let variant_span = tracing::trace_span!( + let variant_span = trace_span!( "treeifying variant", min_align = ?min_align, max_align = ?max_align, @@ -396,22 +396,22 @@ pub(crate) mod rustc { // The layout of the variant is prefixed by the discriminant, if any. if let Some(discr) = discr { - tracing::trace!(?discr, "treeifying discriminant"); + trace!(?discr, "treeifying discriminant"); let discr_layout = alloc::Layout::from_size_align( layout_summary.discriminant_size, clamp(layout_summary.discriminant_align), ) .unwrap(); - tracing::trace!(?discr_layout, "computed discriminant layout"); + trace!(?discr_layout, "computed discriminant layout"); variant_layout = variant_layout.extend(discr_layout).unwrap().0; tree = tree.then(Self::from_disr(discr, tcx, layout_summary.discriminant_size)); } // Next come fields. - let fields_span = tracing::trace_span!("treeifying fields").entered(); + let fields_span = trace_span!("treeifying fields").entered(); for field_def in variant_def.fields.iter() { let field_ty = field_def.ty(tcx, substs_ref); - let _span = tracing::trace_span!("treeifying field", field = ?field_ty).entered(); + let _span = trace_span!("treeifying field", field = ?field_ty).entered(); // begin with the field's visibility tree = tree.then(Self::def(Def::Field(field_def))); @@ -434,7 +434,7 @@ pub(crate) mod rustc { drop(fields_span); // finally: padding - let padding_span = tracing::trace_span!("adding trailing padding").entered(); + let padding_span = trace_span!("adding trailing padding").entered(); let padding_needed = layout_summary.total_size - variant_layout.size(); if padding_needed > 0 { tree = tree.then(Self::padding(padding_needed)); @@ -467,7 +467,7 @@ pub(crate) mod rustc { layout.align().abi.bytes().try_into().unwrap(), ) .unwrap(); - tracing::trace!(?ty, ?layout, "computed layout for type"); + trace!(?ty, ?layout, "computed layout for type"); Ok(layout) } } diff --git a/compiler/rustc_transmute/src/maybe_transmutable/mod.rs b/compiler/rustc_transmute/src/maybe_transmutable/mod.rs index 076d922d1b7..248ff1ec241 100644 --- a/compiler/rustc_transmute/src/maybe_transmutable/mod.rs +++ b/compiler/rustc_transmute/src/maybe_transmutable/mod.rs @@ -110,7 +110,7 @@ where // Remove all `Def` nodes from `src`, without checking their visibility. let src = src.prune(&|def| true); - tracing::trace!(?src, "pruned src"); + trace!(?src, "pruned src"); // Remove all `Def` nodes from `dst`, additionally... let dst = if assume_visibility { @@ -121,7 +121,7 @@ where dst.prune(&|def| context.is_accessible_from(def, scope)) }; - tracing::trace!(?dst, "pruned dst"); + trace!(?dst, "pruned dst"); // Convert `src` from a tree-based representation to an NFA-based representation. // If the conversion fails because `src` is uninhabited, conclude that the transmutation diff --git a/compiler/rustc_transmute/src/maybe_transmutable/query_context.rs b/compiler/rustc_transmute/src/maybe_transmutable/query_context.rs index 9c2cf4c9a92..adab343ac98 100644 --- a/compiler/rustc_transmute/src/maybe_transmutable/query_context.rs +++ b/compiler/rustc_transmute/src/maybe_transmutable/query_context.rs @@ -82,7 +82,7 @@ mod rustc { false }; - tracing::trace!(?ret, "ret"); + trace!(?ret, "ret"); ret } diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index bd1d568cd9a..661e413fc5b 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -15,8 +15,6 @@ use std::collections::btree_map::Entry; use std::collections::BTreeMap; use std::ops::ControlFlow; -use tracing::debug; - // FIXME(#86795): `BoundVarsCollector` here should **NOT** be used // outside of `resolve_associated_item`. It's just to address #64494, // #83765, and #85848 which are creating bound types/regions that lose diff --git a/compiler/rustc_typeck/src/check/generator_interior.rs b/compiler/rustc_typeck/src/check/generator_interior.rs index 85a0d4e4499..2a8c460bb11 100644 --- a/compiler/rustc_typeck/src/check/generator_interior.rs +++ b/compiler/rustc_typeck/src/check/generator_interior.rs @@ -17,7 +17,6 @@ use rustc_middle::middle::region::{self, Scope, ScopeData, YieldData}; use rustc_middle::ty::{self, RvalueScopes, Ty, TyCtxt, TypeVisitable}; use rustc_span::symbol::sym; use rustc_span::Span; -use tracing::debug; mod drop_ranges; -- cgit 1.4.1-3-g733a5 From 38935bbe6a91212e77d535dbad31d369e9a4a453 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 6 Sep 2022 07:08:12 +0000 Subject: Report number of delayed bugs properly with -Ztreat-err-as-bug --- compiler/rustc_errors/src/lib.rs | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 68abdd0bad1..37ff6dcff7d 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1250,14 +1250,14 @@ impl HandlerInner { fn treat_err_as_bug(&self) -> bool { self.flags.treat_err_as_bug.map_or(false, |c| { - self.err_count() - + self.lint_err_count - + self.delayed_span_bugs.len() - + self.delayed_good_path_bugs.len() - >= c.get() + self.err_count() + self.lint_err_count + self.delayed_bug_count() >= c.get() }) } + fn delayed_bug_count(&self) -> usize { + self.delayed_span_bugs.len() + self.delayed_good_path_bugs.len() + } + fn print_error_count(&mut self, registry: &Registry) { self.emit_stashed_diagnostics(); @@ -1412,12 +1412,7 @@ impl HandlerInner { // incrementing `err_count` by one, so we need to +1 the comparing. // FIXME: Would be nice to increment err_count in a more coherent way. if self.flags.treat_err_as_bug.map_or(false, |c| { - self.err_count() - + self.lint_err_count - + self.delayed_span_bugs.len() - + self.delayed_good_path_bugs.len() - + 1 - >= c.get() + self.err_count() + self.lint_err_count + self.delayed_bug_count() + 1 >= c.get() }) { // FIXME: don't abort here if report_delayed_bugs is off self.span_bug(sp, msg); @@ -1518,14 +1513,24 @@ impl HandlerInner { if self.treat_err_as_bug() { match ( self.err_count() + self.lint_err_count, + self.delayed_bug_count(), self.flags.treat_err_as_bug.map(|c| c.get()).unwrap_or(0), ) { - (1, 1) => panic!("aborting due to `-Z treat-err-as-bug=1`"), - (0 | 1, _) => {} - (count, as_bug) => panic!( - "aborting after {} errors due to `-Z treat-err-as-bug={}`", - count, as_bug, - ), + (1, 0, 1) => panic!("aborting due to `-Z treat-err-as-bug=1`"), + (0, 1, 1) => panic!("aborting due delayed bug with `-Z treat-err-as-bug=1`"), + (count, delayed_count, as_bug) => { + if delayed_count > 0 { + panic!( + "aborting after {} errors and {} delayed bugs due to `-Z treat-err-as-bug={}`", + count, delayed_count, as_bug, + ) + } else { + panic!( + "aborting after {} errors due to `-Z treat-err-as-bug={}`", + count, as_bug, + ) + } + } } } } -- cgit 1.4.1-3-g733a5 From d7a750b50436fbd228b176f6438566625e235990 Mon Sep 17 00:00:00 2001 From: Michael Benfield Date: Tue, 8 Mar 2022 19:07:01 +0000 Subject: Use niche-filling optimization even when multiple variants have data. Fixes #46213 --- compiler/rustc_ast/src/ast.rs | 3 +- compiler/rustc_const_eval/src/interpret/operand.rs | 10 +- compiler/rustc_const_eval/src/interpret/place.rs | 6 +- .../src/obligation_forest/mod.rs | 4 + compiler/rustc_errors/src/lib.rs | 4 +- compiler/rustc_hir/src/hir.rs | 15 +- compiler/rustc_middle/src/mir/syntax.rs | 3 +- compiler/rustc_middle/src/thir.rs | 12 +- compiler/rustc_middle/src/ty/layout.rs | 314 +++++++++++++-------- src/librustdoc/clean/types.rs | 3 +- src/test/ui/stats/hir-stats.rs | 1 + src/test/ui/stats/hir-stats.stderr | 44 +-- src/test/ui/structs-enums/type-sizes.rs | 79 ++++++ 13 files changed, 339 insertions(+), 159 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index f25fdc942b0..e38572f609b 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -3075,7 +3075,8 @@ mod size_asserts { static_assert_size!(Block, 48); static_assert_size!(Expr, 104); static_assert_size!(ExprKind, 72); - static_assert_size!(Fn, 192); + #[cfg(not(bootstrap))] + static_assert_size!(Fn, 184); static_assert_size!(ForeignItem, 96); static_assert_size!(ForeignItemKind, 24); static_assert_size!(GenericArg, 24); diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index efa33e18510..ba041810bd1 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -780,13 +780,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } // Some nodes are used a lot. Make sure they don't unintentionally get bigger. -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] +#[cfg(all(target_arch = "x86_64", target_pointer_width = "64", not(bootstrap)))] mod size_asserts { use super::*; use rustc_data_structures::static_assert_size; // These are in alphabetical order, which is easy to maintain. - static_assert_size!(Immediate, 56); - static_assert_size!(ImmTy<'_>, 72); - static_assert_size!(Operand, 64); - static_assert_size!(OpTy<'_>, 88); + static_assert_size!(Immediate, 48); + static_assert_size!(ImmTy<'_>, 64); + static_assert_size!(Operand, 56); + static_assert_size!(OpTy<'_>, 80); } diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 81b0b5a7459..b328892906d 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -890,6 +890,8 @@ mod size_asserts { static_assert_size!(MemPlaceMeta, 24); static_assert_size!(MemPlace, 40); static_assert_size!(MPlaceTy<'_>, 64); - static_assert_size!(Place, 48); - static_assert_size!(PlaceTy<'_>, 72); + #[cfg(not(bootstrap))] + static_assert_size!(Place, 40); + #[cfg(not(bootstrap))] + static_assert_size!(PlaceTy<'_>, 64); } diff --git a/compiler/rustc_data_structures/src/obligation_forest/mod.rs b/compiler/rustc_data_structures/src/obligation_forest/mod.rs index 07a96dd7dbb..e351b650a16 100644 --- a/compiler/rustc_data_structures/src/obligation_forest/mod.rs +++ b/compiler/rustc_data_structures/src/obligation_forest/mod.rs @@ -117,6 +117,10 @@ pub trait ObligationProcessor { } /// The result type used by `process_obligation`. +// `repr(C)` to inhibit the niche filling optimization. Otherwise, the `match` appearing +// in `process_obligations` is significantly slower, which can substantially affect +// benchmarks like `rustc-perf`'s inflate and keccak. +#[repr(C)] #[derive(Debug)] pub enum ProcessResult { Unchanged, diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 37ff6dcff7d..513225e1606 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -69,8 +69,8 @@ pub type PResult<'a, T> = Result>; // (See also the comment on `DiagnosticBuilder`'s `diagnostic` field.) #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] rustc_data_structures::static_assert_size!(PResult<'_, ()>, 16); -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(PResult<'_, bool>, 24); +#[cfg(all(target_arch = "x86_64", target_pointer_width = "64", not(bootstrap)))] +rustc_data_structures::static_assert_size!(PResult<'_, bool>, 16); #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Encodable, Decodable)] pub enum SuggestionStyle { diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 50e7c5d2d04..a668c0e95ce 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3473,12 +3473,15 @@ mod size_asserts { static_assert_size!(FnDecl<'_>, 40); static_assert_size!(ForeignItem<'_>, 72); static_assert_size!(ForeignItemKind<'_>, 40); - static_assert_size!(GenericArg<'_>, 40); + #[cfg(not(bootstrap))] + static_assert_size!(GenericArg<'_>, 32); static_assert_size!(GenericBound<'_>, 48); static_assert_size!(Generics<'_>, 56); static_assert_size!(Impl<'_>, 80); - static_assert_size!(ImplItem<'_>, 88); - static_assert_size!(ImplItemKind<'_>, 40); + #[cfg(not(bootstrap))] + static_assert_size!(ImplItem<'_>, 80); + #[cfg(not(bootstrap))] + static_assert_size!(ImplItemKind<'_>, 32); static_assert_size!(Item<'_>, 80); static_assert_size!(ItemKind<'_>, 48); static_assert_size!(Local<'_>, 64); @@ -3490,8 +3493,10 @@ mod size_asserts { static_assert_size!(QPath<'_>, 24); static_assert_size!(Stmt<'_>, 32); static_assert_size!(StmtKind<'_>, 16); - static_assert_size!(TraitItem<'_>, 96); - static_assert_size!(TraitItemKind<'_>, 56); + #[cfg(not(bootstrap))] + static_assert_size!(TraitItem<'static>, 88); + #[cfg(not(bootstrap))] + static_assert_size!(TraitItemKind<'_>, 48); static_assert_size!(Ty<'_>, 72); static_assert_size!(TyKind<'_>, 56); } diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index bf63b8efaf7..e149535bec7 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -1231,7 +1231,8 @@ pub enum BinOp { mod size_asserts { use super::*; // These are in alphabetical order, which is easy to maintain. - static_assert_size!(AggregateKind<'_>, 48); + #[cfg(not(bootstrap))] + static_assert_size!(AggregateKind<'_>, 40); static_assert_size!(Operand<'_>, 24); static_assert_size!(Place<'_>, 16); static_assert_size!(PlaceElem<'_>, 24); diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 7e543929b0f..c50f8b0eebe 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -825,8 +825,12 @@ mod size_asserts { static_assert_size!(Block, 56); static_assert_size!(Expr<'_>, 64); static_assert_size!(ExprKind<'_>, 40); - static_assert_size!(Pat<'_>, 72); - static_assert_size!(PatKind<'_>, 56); - static_assert_size!(Stmt<'_>, 56); - static_assert_size!(StmtKind<'_>, 48); + #[cfg(not(bootstrap))] + static_assert_size!(Pat<'_>, 64); + #[cfg(not(bootstrap))] + static_assert_size!(PatKind<'_>, 48); + #[cfg(not(bootstrap))] + static_assert_size!(Stmt<'_>, 48); + #[cfg(not(bootstrap))] + static_assert_size!(StmtKind<'_>, 40); } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 0a5463a021f..abb7ddd88b1 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -22,7 +22,7 @@ use rustc_target::abi::call::{ use rustc_target::abi::*; use rustc_target::spec::{abi::Abi as SpecAbi, HasTargetSpec, PanicStrategy, Target}; -use std::cmp; +use std::cmp::{self, Ordering}; use std::fmt; use std::iter; use std::num::NonZeroUsize; @@ -1046,131 +1046,191 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // that allow representation optimization.) assert!(def.is_enum()); - // The current code for niche-filling relies on variant indices - // instead of actual discriminants, so untagged enums with - // explicit discriminants (RFC #2363) would misbehave. - let no_explicit_discriminants = def - .variants() - .iter_enumerated() - .all(|(i, v)| v.discr == ty::VariantDiscr::Relative(i.as_u32())); - - let mut niche_filling_layout = None; - - // Niche-filling enum optimization. - if !def.repr().inhibit_enum_layout_opt() && no_explicit_discriminants { - let mut untagged_variant = None; - let mut niche_variants = VariantIdx::MAX..=VariantIdx::new(0); + // Until we've decided whether to use the tagged or + // niche filling LayoutS, we don't want to intern the + // variant layouts, so we can't store them in the + // overall LayoutS. Store the overall LayoutS + // and the variant LayoutSs here until then. + struct TmpLayout<'tcx> { + layout: LayoutS<'tcx>, + variants: IndexVec>, + } - // Find one non-ZST variant. - 'variants: for (v, fields) in variants.iter_enumerated() { - if absent(fields) { - continue 'variants; + let calculate_niche_filling_layout = + || -> Result>, LayoutError<'tcx>> { + // The current code for niche-filling relies on variant indices + // instead of actual discriminants, so enums with + // explicit discriminants (RFC #2363) would misbehave. + if def.repr().inhibit_enum_layout_opt() + || def + .variants() + .iter_enumerated() + .any(|(i, v)| v.discr != ty::VariantDiscr::Relative(i.as_u32())) + { + return Ok(None); } - for f in fields { - if !f.is_zst() { - if untagged_variant.is_none() { - untagged_variant = Some(v); - continue 'variants; - } else { - untagged_variant = None; - break 'variants; - } - } + + if variants.len() < 2 { + return Ok(None); } - niche_variants = *niche_variants.start().min(&v)..=v; - } - if niche_variants.start() > niche_variants.end() { - untagged_variant = None; - } + let mut align = dl.aggregate_align; + let mut variant_layouts = variants + .iter_enumerated() + .map(|(j, v)| { + let mut st = self.univariant_uninterned( + ty, + v, + &def.repr(), + StructKind::AlwaysSized, + )?; + st.variants = Variants::Single { index: j }; + + align = align.max(st.align); + + Ok(st) + }) + .collect::, _>>()?; + + let largest_variant_index = match variant_layouts + .iter_enumerated() + .max_by_key(|(_i, layout)| layout.size.bytes()) + .map(|(i, _layout)| i) + { + None => return Ok(None), + Some(i) => i, + }; - if let Some(i) = untagged_variant { - let count = (niche_variants.end().as_u32() - - niche_variants.start().as_u32() - + 1) as u128; + let all_indices = VariantIdx::new(0)..=VariantIdx::new(variants.len() - 1); + let needs_disc = |index: VariantIdx| { + index != largest_variant_index && !absent(&variants[index]) + }; + let niche_variants = all_indices.clone().find(|v| needs_disc(*v)).unwrap() + ..=all_indices.rev().find(|v| needs_disc(*v)).unwrap(); + + let count = niche_variants.size_hint().1.unwrap() as u128; // Find the field with the largest niche - let niche_candidate = variants[i] + let (field_index, niche, (niche_start, niche_scalar)) = match variants + [largest_variant_index] .iter() .enumerate() .filter_map(|(j, field)| Some((j, field.largest_niche?))) - .max_by_key(|(_, niche)| niche.available(dl)); - - if let Some((field_index, niche, (niche_start, niche_scalar))) = - niche_candidate.and_then(|(field_index, niche)| { - Some((field_index, niche, niche.reserve(self, count)?)) - }) + .max_by_key(|(_, niche)| niche.available(dl)) + .and_then(|(j, niche)| Some((j, niche, niche.reserve(self, count)?))) { - let mut align = dl.aggregate_align; - let st = variants - .iter_enumerated() - .map(|(j, v)| { - let mut st = self.univariant_uninterned( - ty, - v, - &def.repr(), - StructKind::AlwaysSized, - )?; - st.variants = Variants::Single { index: j }; + None => return Ok(None), + Some(x) => x, + }; - align = align.max(st.align); + let niche_offset = niche.offset + + variant_layouts[largest_variant_index].fields.offset(field_index); + let niche_size = niche.value.size(dl); + let size = variant_layouts[largest_variant_index].size.align_to(align.abi); - Ok(tcx.intern_layout(st)) - }) - .collect::, _>>()?; + let all_variants_fit = + variant_layouts.iter_enumerated_mut().all(|(i, layout)| { + if i == largest_variant_index { + return true; + } - let offset = st[i].fields().offset(field_index) + niche.offset; + layout.largest_niche = None; - // Align the total size to the largest alignment. - let size = st[i].size().align_to(align.abi); + if layout.size <= niche_offset { + // This variant will fit before the niche. + return true; + } - let abi = if st.iter().all(|v| v.abi().is_uninhabited()) { - Abi::Uninhabited - } else if align == st[i].align() && size == st[i].size() { - // When the total alignment and size match, we can use the - // same ABI as the scalar variant with the reserved niche. - match st[i].abi() { - Abi::Scalar(_) => Abi::Scalar(niche_scalar), - Abi::ScalarPair(first, second) => { - // Only the niche is guaranteed to be initialised, - // so use union layout for the other primitive. - if offset.bytes() == 0 { - Abi::ScalarPair(niche_scalar, second.to_union()) - } else { - Abi::ScalarPair(first.to_union(), niche_scalar) + // Determine if it'll fit after the niche. + let this_align = layout.align.abi; + let this_offset = (niche_offset + niche_size).align_to(this_align); + + if this_offset + layout.size > size { + return false; + } + + // It'll fit, but we need to make some adjustments. + match layout.fields { + FieldsShape::Arbitrary { ref mut offsets, .. } => { + for (j, offset) in offsets.iter_mut().enumerate() { + if !variants[i][j].is_zst() { + *offset += this_offset; + } } } - _ => Abi::Aggregate { sized: true }, + _ => { + panic!("Layout of fields should be Arbitrary for variants") + } } - } else { - Abi::Aggregate { sized: true } - }; - let largest_niche = Niche::from_scalar(dl, offset, niche_scalar); - - niche_filling_layout = Some(LayoutS { - variants: Variants::Multiple { - tag: niche_scalar, - tag_encoding: TagEncoding::Niche { - untagged_variant: i, - niche_variants, - niche_start, - }, - tag_field: 0, - variants: st, - }, - fields: FieldsShape::Arbitrary { - offsets: vec![offset], - memory_index: vec![0], - }, - abi, - largest_niche, - size, - align, + // It can't be a Scalar or ScalarPair because the offset isn't 0. + if !layout.abi.is_uninhabited() { + layout.abi = Abi::Aggregate { sized: true }; + } + layout.size += this_offset; + + true }); + + if !all_variants_fit { + return Ok(None); } - } - } + + let largest_niche = Niche::from_scalar(dl, niche_offset, niche_scalar); + + let others_zst = variant_layouts.iter_enumerated().all(|(i, layout)| { + i == largest_variant_index || layout.size == Size::ZERO + }); + let same_size = size == variant_layouts[largest_variant_index].size; + let same_align = align == variant_layouts[largest_variant_index].align; + + let abi = if variant_layouts.iter().all(|v| v.abi.is_uninhabited()) { + Abi::Uninhabited + } else if same_size && same_align && others_zst { + match variant_layouts[largest_variant_index].abi { + // When the total alignment and size match, we can use the + // same ABI as the scalar variant with the reserved niche. + Abi::Scalar(_) => Abi::Scalar(niche_scalar), + Abi::ScalarPair(first, second) => { + // Only the niche is guaranteed to be initialised, + // so use union layouts for the other primitive. + if niche_offset == Size::ZERO { + Abi::ScalarPair(niche_scalar, second.to_union()) + } else { + Abi::ScalarPair(first.to_union(), niche_scalar) + } + } + _ => Abi::Aggregate { sized: true }, + } + } else { + Abi::Aggregate { sized: true } + }; + + let layout = LayoutS { + variants: Variants::Multiple { + tag: niche_scalar, + tag_encoding: TagEncoding::Niche { + untagged_variant: largest_variant_index, + niche_variants, + niche_start, + }, + tag_field: 0, + variants: IndexVec::new(), + }, + fields: FieldsShape::Arbitrary { + offsets: vec![niche_offset], + memory_index: vec![0], + }, + abi, + largest_niche, + size, + align, + }; + + Ok(Some(TmpLayout { layout, variants: variant_layouts })) + }; + + let niche_filling_layout = calculate_niche_filling_layout()?; let (mut min, mut max) = (i128::MAX, i128::MIN); let discr_type = def.repr().discr_type(); @@ -1425,15 +1485,12 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let largest_niche = Niche::from_scalar(dl, Size::ZERO, tag); - let layout_variants = - layout_variants.into_iter().map(|v| tcx.intern_layout(v)).collect(); - let tagged_layout = LayoutS { variants: Variants::Multiple { tag, tag_encoding: TagEncoding::Direct, tag_field: 0, - variants: layout_variants, + variants: IndexVec::new(), }, fields: FieldsShape::Arbitrary { offsets: vec![Size::ZERO], @@ -1445,20 +1502,45 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { size, }; - let best_layout = match (tagged_layout, niche_filling_layout) { - (tagged_layout, Some(niche_filling_layout)) => { + let tagged_layout = TmpLayout { layout: tagged_layout, variants: layout_variants }; + + let mut best_layout = match (tagged_layout, niche_filling_layout) { + (tl, Some(nl)) => { // Pick the smaller layout; otherwise, // pick the layout with the larger niche; otherwise, // pick tagged as it has simpler codegen. - cmp::min_by_key(tagged_layout, niche_filling_layout, |layout| { - let niche_size = layout.largest_niche.map_or(0, |n| n.available(dl)); - (layout.size, cmp::Reverse(niche_size)) - }) + use Ordering::*; + let niche_size = |tmp_l: &TmpLayout<'_>| { + tmp_l.layout.largest_niche.map_or(0, |n| n.available(dl)) + }; + match ( + tl.layout.size.cmp(&nl.layout.size), + niche_size(&tl).cmp(&niche_size(&nl)), + ) { + (Greater, _) => nl, + (Equal, Less) => nl, + _ => tl, + } } - (tagged_layout, None) => tagged_layout, + (tl, None) => tl, + }; + + // Now we can intern the variant layouts and store them in the enum layout. + best_layout.layout.variants = match best_layout.layout.variants { + Variants::Multiple { tag, tag_encoding, tag_field, .. } => Variants::Multiple { + tag, + tag_encoding, + tag_field, + variants: best_layout + .variants + .into_iter() + .map(|layout| tcx.intern_layout(layout)) + .collect(), + }, + _ => bug!(), }; - tcx.intern_layout(best_layout) + tcx.intern_layout(best_layout.layout) } // Types with no meaningful known layout. diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index d6bb7c6c4fc..2077cf71b2e 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2532,7 +2532,8 @@ mod size_asserts { // These are in alphabetical order, which is easy to maintain. static_assert_size!(Crate, 72); // frequently moved by-value static_assert_size!(DocFragment, 32); - static_assert_size!(GenericArg, 64); + #[cfg(not(bootstrap))] + static_assert_size!(GenericArg, 56); static_assert_size!(GenericArgs, 32); static_assert_size!(GenericParamDef, 56); static_assert_size!(Item, 56); diff --git a/src/test/ui/stats/hir-stats.rs b/src/test/ui/stats/hir-stats.rs index a24b3ada57e..5102574d4be 100644 --- a/src/test/ui/stats/hir-stats.rs +++ b/src/test/ui/stats/hir-stats.rs @@ -1,6 +1,7 @@ // check-pass // compile-flags: -Zhir-stats // only-x86_64 +// ignore-stage1 // The aim here is to include at least one of every different type of top-level // AST/HIR node reported by `-Zhir-stats`. diff --git a/src/test/ui/stats/hir-stats.stderr b/src/test/ui/stats/hir-stats.stderr index 0a736f7be83..c8ceb6ff22d 100644 --- a/src/test/ui/stats/hir-stats.stderr +++ b/src/test/ui/stats/hir-stats.stderr @@ -21,39 +21,39 @@ ast-stats-1 - MacCall 32 ( 0.4%) 1 ast-stats-1 - Expr 96 ( 1.1%) 3 ast-stats-1 Param 160 ( 1.9%) 4 40 ast-stats-1 FnDecl 200 ( 2.4%) 5 40 -ast-stats-1 Variant 240 ( 2.8%) 2 120 +ast-stats-1 Variant 240 ( 2.9%) 2 120 ast-stats-1 Block 288 ( 3.4%) 6 48 ast-stats-1 GenericBound 352 ( 4.2%) 4 88 ast-stats-1 - Trait 352 ( 4.2%) 4 ast-stats-1 AssocItem 416 ( 4.9%) 4 104 ast-stats-1 - TyAlias 208 ( 2.5%) 2 ast-stats-1 - Fn 208 ( 2.5%) 2 -ast-stats-1 GenericParam 520 ( 6.1%) 5 104 -ast-stats-1 PathSegment 720 ( 8.5%) 30 24 -ast-stats-1 Expr 832 ( 9.8%) 8 104 +ast-stats-1 GenericParam 480 ( 5.7%) 5 96 +ast-stats-1 PathSegment 720 ( 8.6%) 30 24 +ast-stats-1 Expr 832 ( 9.9%) 8 104 ast-stats-1 - Path 104 ( 1.2%) 1 ast-stats-1 - Match 104 ( 1.2%) 1 ast-stats-1 - Struct 104 ( 1.2%) 1 ast-stats-1 - Lit 208 ( 2.5%) 2 ast-stats-1 - Block 312 ( 3.7%) 3 -ast-stats-1 Pat 840 ( 9.9%) 7 120 +ast-stats-1 Pat 840 (10.0%) 7 120 ast-stats-1 - Struct 120 ( 1.4%) 1 ast-stats-1 - Wild 120 ( 1.4%) 1 ast-stats-1 - Ident 600 ( 7.1%) 5 -ast-stats-1 Ty 1_344 (15.9%) 14 96 +ast-stats-1 Ty 1_344 (16.0%) 14 96 ast-stats-1 - Rptr 96 ( 1.1%) 1 ast-stats-1 - Ptr 96 ( 1.1%) 1 ast-stats-1 - ImplicitSelf 192 ( 2.3%) 2 ast-stats-1 - Path 960 (11.4%) 10 -ast-stats-1 Item 1_656 (19.6%) 9 184 +ast-stats-1 Item 1_656 (19.7%) 9 184 ast-stats-1 - Trait 184 ( 2.2%) 1 ast-stats-1 - Enum 184 ( 2.2%) 1 ast-stats-1 - ForeignMod 184 ( 2.2%) 1 ast-stats-1 - Impl 184 ( 2.2%) 1 ast-stats-1 - Fn 368 ( 4.4%) 2 -ast-stats-1 - Use 552 ( 6.5%) 3 +ast-stats-1 - Use 552 ( 6.6%) 3 ast-stats-1 ---------------------------------------------------------------- -ast-stats-1 Total 8_456 +ast-stats-1 Total 8_416 ast-stats-1 ast-stats-2 POST EXPANSION AST STATS ast-stats-2 Name Accumulated Size Count Item Size @@ -86,12 +86,12 @@ ast-stats-2 - Trait 352 ( 3.8%) 4 ast-stats-2 AssocItem 416 ( 4.5%) 4 104 ast-stats-2 - TyAlias 208 ( 2.3%) 2 ast-stats-2 - Fn 208 ( 2.3%) 2 -ast-stats-2 GenericParam 520 ( 5.7%) 5 104 -ast-stats-2 PathSegment 792 ( 8.6%) 33 24 -ast-stats-2 Pat 840 ( 9.1%) 7 120 +ast-stats-2 GenericParam 480 ( 5.2%) 5 96 +ast-stats-2 PathSegment 792 ( 8.7%) 33 24 +ast-stats-2 Pat 840 ( 9.2%) 7 120 ast-stats-2 - Struct 120 ( 1.3%) 1 ast-stats-2 - Wild 120 ( 1.3%) 1 -ast-stats-2 - Ident 600 ( 6.5%) 5 +ast-stats-2 - Ident 600 ( 6.6%) 5 ast-stats-2 Expr 936 (10.2%) 9 104 ast-stats-2 - Path 104 ( 1.1%) 1 ast-stats-2 - Match 104 ( 1.1%) 1 @@ -99,12 +99,12 @@ ast-stats-2 - Struct 104 ( 1.1%) 1 ast-stats-2 - InlineAsm 104 ( 1.1%) 1 ast-stats-2 - Lit 208 ( 2.3%) 2 ast-stats-2 - Block 312 ( 3.4%) 3 -ast-stats-2 Ty 1_344 (14.6%) 14 96 +ast-stats-2 Ty 1_344 (14.7%) 14 96 ast-stats-2 - Rptr 96 ( 1.0%) 1 ast-stats-2 - Ptr 96 ( 1.0%) 1 ast-stats-2 - ImplicitSelf 192 ( 2.1%) 2 ast-stats-2 - Path 960 (10.5%) 10 -ast-stats-2 Item 2_024 (22.0%) 11 184 +ast-stats-2 Item 2_024 (22.1%) 11 184 ast-stats-2 - Trait 184 ( 2.0%) 1 ast-stats-2 - Enum 184 ( 2.0%) 1 ast-stats-2 - ExternCrate 184 ( 2.0%) 1 @@ -113,7 +113,7 @@ ast-stats-2 - Impl 184 ( 2.0%) 1 ast-stats-2 - Fn 368 ( 4.0%) 2 ast-stats-2 - Use 736 ( 8.0%) 4 ast-stats-2 ---------------------------------------------------------------- -ast-stats-2 Total 9_184 +ast-stats-2 Total 9_144 ast-stats-2 hir-stats HIR STATS hir-stats Name Accumulated Size Count Item Size @@ -121,7 +121,7 @@ hir-stats ---------------------------------------------------------------- hir-stats ForeignItemRef 24 ( 0.2%) 1 24 hir-stats Mod 32 ( 0.3%) 1 32 hir-stats ExprField 40 ( 0.4%) 1 40 -hir-stats TraitItemRef 56 ( 0.5%) 2 28 +hir-stats TraitItemRef 56 ( 0.6%) 2 28 hir-stats Param 64 ( 0.6%) 2 32 hir-stats Local 64 ( 0.6%) 1 64 hir-stats InlineAsm 72 ( 0.7%) 1 72 @@ -135,11 +135,11 @@ hir-stats - Semi 32 ( 0.3%) 1 hir-stats - Expr 32 ( 0.3%) 1 hir-stats FnDecl 120 ( 1.2%) 3 40 hir-stats Attribute 128 ( 1.3%) 4 32 +hir-stats GenericArg 128 ( 1.3%) 4 32 +hir-stats - Type 32 ( 0.3%) 1 +hir-stats - Lifetime 96 ( 0.9%) 3 hir-stats GenericArgs 144 ( 1.4%) 3 48 hir-stats Variant 160 ( 1.6%) 2 80 -hir-stats GenericArg 160 ( 1.6%) 4 40 -hir-stats - Type 40 ( 0.4%) 1 -hir-stats - Lifetime 120 ( 1.2%) 3 hir-stats GenericBound 192 ( 1.9%) 4 48 hir-stats - Trait 192 ( 1.9%) 4 hir-stats WherePredicate 216 ( 2.1%) 3 72 @@ -151,7 +151,7 @@ hir-stats - Wild 88 ( 0.9%) 1 hir-stats - Struct 88 ( 0.9%) 1 hir-stats - Binding 264 ( 2.6%) 3 hir-stats Generics 560 ( 5.5%) 10 56 -hir-stats Expr 768 ( 7.5%) 12 64 +hir-stats Expr 768 ( 7.6%) 12 64 hir-stats - Path 64 ( 0.6%) 1 hir-stats - Struct 64 ( 0.6%) 1 hir-stats - Match 64 ( 0.6%) 1 @@ -173,5 +173,5 @@ hir-stats - Path 936 ( 9.2%) 13 hir-stats Path 1_536 (15.1%) 32 48 hir-stats PathSegment 2_240 (22.0%) 40 56 hir-stats ---------------------------------------------------------------- -hir-stats Total 10_200 +hir-stats Total 10_168 hir-stats diff --git a/src/test/ui/structs-enums/type-sizes.rs b/src/test/ui/structs-enums/type-sizes.rs index 73a11a5e743..7a23f13630a 100644 --- a/src/test/ui/structs-enums/type-sizes.rs +++ b/src/test/ui/structs-enums/type-sizes.rs @@ -120,6 +120,54 @@ pub enum AlwaysTaggedBecauseItHasNoNiche { B } +pub enum NicheFilledMultipleFields { + A(bool, u8), + B(u8), + C(u8), + D(bool), + E, + F, + G, +} + +struct BoolInTheMiddle(std::num::NonZeroU16, bool, u8); + +enum NicheWithData { + A, + B([u16; 5]), + Largest { a1: u32, a2: BoolInTheMiddle, a3: u32 }, + C, + D(u32, u32), +} + +// A type with almost 2^16 invalid values. +#[repr(u16)] +pub enum NicheU16 { + _0, +} + +pub enum EnumManyVariant { + Dataful(u8, X), + + // 0x100 niche variants. + _00, _01, _02, _03, _04, _05, _06, _07, _08, _09, _0A, _0B, _0C, _0D, _0E, _0F, + _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _1A, _1B, _1C, _1D, _1E, _1F, + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _2A, _2B, _2C, _2D, _2E, _2F, + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _3A, _3B, _3C, _3D, _3E, _3F, + _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _4A, _4B, _4C, _4D, _4E, _4F, + _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _5A, _5B, _5C, _5D, _5E, _5F, + _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _6A, _6B, _6C, _6D, _6E, _6F, + _70, _71, _72, _73, _74, _75, _76, _77, _78, _79, _7A, _7B, _7C, _7D, _7E, _7F, + _80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _8A, _8B, _8C, _8D, _8E, _8F, + _90, _91, _92, _93, _94, _95, _96, _97, _98, _99, _9A, _9B, _9C, _9D, _9E, _9F, + _A0, _A1, _A2, _A3, _A4, _A5, _A6, _A7, _A8, _A9, _AA, _AB, _AC, _AD, _AE, _AF, + _B0, _B1, _B2, _B3, _B4, _B5, _B6, _B7, _B8, _B9, _BA, _BB, _BC, _BD, _BE, _BF, + _C0, _C1, _C2, _C3, _C4, _C5, _C6, _C7, _C8, _C9, _CA, _CB, _CC, _CD, _CE, _CF, + _D0, _D1, _D2, _D3, _D4, _D5, _D6, _D7, _D8, _D9, _DA, _DB, _DC, _DD, _DE, _DF, + _E0, _E1, _E2, _E3, _E4, _E5, _E6, _E7, _E8, _E9, _EA, _EB, _EC, _ED, _EE, _EF, + _F0, _F1, _F2, _F3, _F4, _F5, _F6, _F7, _F8, _F9, _FA, _FB, _FC, _FD, _FE, _FF, +} + pub fn main() { assert_eq!(size_of::(), 1 as usize); assert_eq!(size_of::(), 4 as usize); @@ -170,4 +218,35 @@ pub fn main() { assert_eq!(size_of::(), 8); assert_eq!(size_of::>(), 8); assert_eq!(size_of::>>(), 8); + + assert_eq!(size_of::(), 2); + assert_eq!(size_of::>(), 2); + assert_eq!(size_of::>>(), 2); + + struct S1{ a: u16, b: std::num::NonZeroU16, c: u16, d: u8, e: u32, f: u64, g:[u8;2] } + assert_eq!(size_of::(), 24); + assert_eq!(size_of::>(), 24); + + assert_eq!(size_of::(), 12); + assert_eq!(size_of::>(), 12); + assert_eq!(size_of::>>(), 12); + assert_eq!( + size_of::>>>(), + size_of::<(&(), NicheWithData)>() + ); + + pub enum FillPadding { A(std::num::NonZeroU8, u32), B } + assert_eq!(size_of::(), 8); + assert_eq!(size_of::>(), 8); + assert_eq!(size_of::>>(), 8); + + assert_eq!(size_of::>(), 4); + assert_eq!(size_of::>>(), 4); + assert_eq!(size_of::>(), 4); + + assert_eq!(size_of::>(), 6); + assert_eq!(size_of::>(), 4); + assert_eq!(size_of::>>(), 4); + assert_eq!(size_of::>>(), 6); + assert_eq!(size_of::>>(), 6); } -- cgit 1.4.1-3-g733a5 From bdc865d8f7f50482ae67e942a98bd554e51dda30 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Thu, 8 Sep 2022 06:15:33 +0900 Subject: remove unnecessary `PartialOrd` and `Ord` --- compiler/rustc_borrowck/src/region_infer/mod.rs | 1 - compiler/rustc_errors/src/lib.rs | 2 +- compiler/rustc_hir/src/def.rs | 2 +- compiler/rustc_lexer/src/lib.rs | 2 +- compiler/rustc_middle/src/mir/syntax.rs | 2 +- compiler/rustc_middle/src/mir/terminator.rs | 2 +- compiler/rustc_resolve/src/lib.rs | 23 ++--------------------- 7 files changed, 7 insertions(+), 27 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 8dc9368a0b9..de70b17e44c 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -135,7 +135,6 @@ pub struct RegionInferenceContext<'tcx> { /// adds a new lower bound to the SCC it is analyzing: so you wind up /// with `'R: 'O` where `'R` is the pick-region and `'O` is the /// minimal viable option. -#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] pub(crate) struct AppliedMemberConstraint { /// The SCC that was affected. (The "member region".) /// diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 68abdd0bad1..b5f0e22f925 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -456,7 +456,7 @@ struct HandlerInner { } /// A key denoting where from a diagnostic was stashed. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] pub enum StashKey { ItemNoType, UnderscoreForArrayLengths, diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index d5ac07f1e63..b44ee02cfe3 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -457,7 +457,7 @@ impl PartialRes { /// Different kinds of symbols can coexist even if they share the same textual name. /// Therefore, they each have a separate universe (known as a "namespace"). -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum Namespace { /// The type namespace includes `struct`s, `enum`s, `union`s, `trait`s, and `mod`s /// (and, by extension, crates). diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs index 178366f7d80..a79c982649a 100644 --- a/compiler/rustc_lexer/src/lib.rs +++ b/compiler/rustc_lexer/src/lib.rs @@ -141,7 +141,7 @@ pub enum TokenKind { Unknown, } -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum DocStyle { Outer, Inner, diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index d7b9d59eced..b49fd6f6458 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -705,7 +705,7 @@ pub enum TerminatorKind<'tcx> { } /// Information about an assertion failure. -#[derive(Clone, TyEncodable, TyDecodable, Hash, HashStable, PartialEq, PartialOrd)] +#[derive(Clone, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)] pub enum AssertKind { BoundsCheck { len: O, index: O }, Overflow(BinOp, O, O), diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index 9ccf5aea63c..02a9958525b 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -14,7 +14,7 @@ use std::slice; pub use super::query::*; -#[derive(Debug, Clone, TyEncodable, TyDecodable, Hash, HashStable, PartialEq, PartialOrd)] +#[derive(Debug, Clone, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)] pub struct SwitchTargets { /// Possible values. The locations to branch to in each case /// are found in the corresponding indices from the `targets` vector. diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index a15a0c298a9..f8a3e5b8bb0 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -57,7 +57,7 @@ use rustc_span::{Span, DUMMY_SP}; use smallvec::{smallvec, SmallVec}; use std::cell::{Cell, RefCell}; use std::collections::BTreeSet; -use std::{cmp, fmt, ptr}; +use std::{fmt, ptr}; use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion}; use imports::{Import, ImportKind, ImportResolver, NameResolution}; @@ -163,7 +163,6 @@ enum ImplTraitContext { Universal(LocalDefId), } -#[derive(Eq)] struct BindingError { name: Symbol, origin: BTreeSet, @@ -171,24 +170,6 @@ struct BindingError { could_be_path: bool, } -impl PartialOrd for BindingError { - fn partial_cmp(&self, other: &BindingError) -> Option { - Some(self.cmp(other)) - } -} - -impl PartialEq for BindingError { - fn eq(&self, other: &BindingError) -> bool { - self.name == other.name - } -} - -impl Ord for BindingError { - fn cmp(&self, other: &BindingError) -> cmp::Ordering { - self.name.cmp(&other.name) - } -} - enum ResolutionError<'a> { /// Error E0401: can't use type or const parameters from outer function. GenericParamsFromOuterFunction(Res, HasGenericParams), @@ -845,7 +826,7 @@ impl<'a> NameBinding<'a> { } } -#[derive(Debug, Default, Clone)] +#[derive(Default, Clone)] pub struct ExternPreludeEntry<'a> { extern_crate_item: Option<&'a NameBinding<'a>>, pub introduced_by_item: bool, -- cgit 1.4.1-3-g733a5 From 0f06320c2491acc8cf9e61c976041785acb06aca Mon Sep 17 00:00:00 2001 From: Luis Cardoso <61982523+LuisCardosoOliveira@users.noreply.github.com> Date: Fri, 2 Sep 2022 19:29:52 +0200 Subject: translations(rustc_session): migrate TargetDataLayout::parse --- .../rustc_error_messages/locales/en-US/session.ftl | 14 +++++ compiler/rustc_errors/src/diagnostic.rs | 2 + compiler/rustc_middle/src/ty/context.rs | 3 +- compiler/rustc_session/src/errors.rs | 61 +++++++++++++++++++-- compiler/rustc_target/src/abi/mod.rs | 63 +++++++++++++--------- 5 files changed, 111 insertions(+), 32 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_error_messages/locales/en-US/session.ftl b/compiler/rustc_error_messages/locales/en-US/session.ftl index 998196403e7..c5d23f29250 100644 --- a/compiler/rustc_error_messages/locales/en-US/session.ftl +++ b/compiler/rustc_error_messages/locales/en-US/session.ftl @@ -40,3 +40,17 @@ session_sanitizer_cfi_enabled = `-Zsanitizer=cfi` requires `-Clto` session_unstable_virtual_function_elimination = `-Zvirtual-function-elimination` requires `-Clto` session_unsupported_dwarf_version = requested DWARF version {$dwarf_version} is greater than 5 + +session_target_invalid_address_space = invalid address space `{$addr_space}` for `{$cause}` in "data-layout": {$err} + +session_target_invalid_bits = invalid {$kind} `{$bit}` for `{$cause}` in "data-layout": {$err} + +session_target_missing_alignment = missing alignment for `{$cause}` in "data-layout" + +session_target_invalid_alignment = invalid alignment for `{$cause}` in "data-layout": {$err} + +session_target_inconsistent_architecture = inconsistent target specification: "data-layout" claims architecture is {$dl}-endian, while "target-endian" is `{$target}` + +session_target_inconsistent_pointer_width = inconsistent target specification: "data-layout" claims pointers are {$pointer_size}-bit, while "target-pointer-width" is `{$target}` + +session_target_invalid_bits_size = {$err} diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index a052aaee047..b88292b893c 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -14,6 +14,7 @@ use rustc_target::spec::PanicStrategy; use std::borrow::Cow; use std::fmt; use std::hash::{Hash, Hasher}; +use std::num::ParseIntError; use std::path::{Path, PathBuf}; /// Error type for `Diagnostic`'s `suggestions` field, indicating that @@ -91,6 +92,7 @@ into_diagnostic_arg_using_display!( Edition, Ident, MacroRulesNormalizedIdent, + ParseIntError, ); impl IntoDiagnosticArg for bool { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 262d59f8ff8..583f682f568 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -52,6 +52,7 @@ use rustc_query_system::ich::StableHashingContext; use rustc_serialize::opaque::{FileEncodeResult, FileEncoder}; use rustc_session::config::{CrateType, OutputFilenames}; use rustc_session::cstore::CrateStoreDyn; +use rustc_session::errors::TargetDataLayoutParseError; use rustc_session::lint::{Level, Lint}; use rustc_session::Limit; use rustc_session::Session; @@ -1251,7 +1252,7 @@ impl<'tcx> TyCtxt<'tcx> { output_filenames: OutputFilenames, ) -> GlobalCtxt<'tcx> { let data_layout = TargetDataLayout::parse(&s.target).unwrap_or_else(|err| { - s.fatal(&err); + s.emit_fatal(TargetDataLayoutParseError { err }); }); let interners = CtxtInterners::new(arena); let common_types = CommonTypes::new( diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index 7aa8d668241..226e0958927 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -1,10 +1,12 @@ use std::num::NonZeroU32; use crate::cgu_reuse_tracker::CguReuse; +use crate::parse::ParseSess; use crate::{self as rustc_session}; -use rustc_errors::MultiSpan; +use rustc_errors::{fluent, MultiSpan}; use rustc_macros::SessionDiagnostic; use rustc_span::{Span, Symbol}; +use rustc_target::abi::TargetDataLayoutErrors; #[derive(SessionDiagnostic)] #[diag(session::incorrect_cgu_reuse_type)] @@ -44,10 +46,59 @@ pub struct FeatureDiagnosticHelp { pub feature: Symbol, } -#[derive(SessionDiagnostic)] -#[diag(session::target_data_layout_parse_error)] -pub struct TargetDataLayoutParseError { - pub err: String, +pub struct TargetDataLayoutParseError<'a> { + pub err: TargetDataLayoutErrors<'a>, +} + +impl crate::SessionDiagnostic<'_, !> for TargetDataLayoutParseError<'_> { + fn into_diagnostic(self, sess: &ParseSess) -> rustc_errors::DiagnosticBuilder<'_, !> { + let mut diag; + match self.err { + TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => { + diag = sess.struct_fatal(fluent::session::target_invalid_address_space); + diag.set_arg("addr_space", addr_space); + diag.set_arg("cause", cause); + diag.set_arg("err", err); + diag + } + TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => { + diag = sess.struct_fatal(fluent::session::target_invalid_bits); + diag.set_arg("kind", kind); + diag.set_arg("bit", bit); + diag.set_arg("cause", cause); + diag.set_arg("err", err); + diag + } + TargetDataLayoutErrors::MissingAlignment { cause } => { + diag = sess.struct_fatal(fluent::session::target_missing_alignment); + diag.set_arg("cause", cause); + diag + } + TargetDataLayoutErrors::InvalidAlignment { cause, err } => { + diag = sess.struct_fatal(fluent::session::target_invalid_alignment); + diag.set_arg("cause", cause); + diag.set_arg("err", err); + diag + } + TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => { + diag = sess.struct_fatal(fluent::session::target_inconsistent_architecture); + diag.set_arg("dl", dl); + diag.set_arg("target", target); + diag + } + TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => { + diag = sess.struct_fatal(fluent::session::target_inconsistent_pointer_width); + diag.set_arg("pointer_size", pointer_size); + diag.set_arg("target", target); + diag + } + TargetDataLayoutErrors::InvalidBitsSize { err } => { + diag = sess.struct_fatal(fluent::session::target_invalid_bits_size); + diag.set_arg("err", err); + diag + } + } + } } #[derive(SessionDiagnostic)] diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index bcaf209f84b..ec334e5887a 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -7,7 +7,7 @@ use crate::spec::Target; use std::convert::{TryFrom, TryInto}; use std::fmt; use std::iter::Step; -use std::num::NonZeroUsize; +use std::num::{NonZeroUsize, ParseIntError}; use std::ops::{Add, AddAssign, Deref, Mul, RangeInclusive, Sub}; use std::str::FromStr; @@ -69,34 +69,46 @@ impl Default for TargetDataLayout { } } +pub enum TargetDataLayoutErrors<'a> { + InvalidAddressSpace { addr_space: &'a str, cause: &'a str, err: ParseIntError }, + InvalidBits { kind: &'a str, bit: &'a str, cause: &'a str, err: ParseIntError }, + MissingAlignment { cause: &'a str }, + InvalidAlignment { cause: &'a str, err: String }, + InconsistentTargetArchitecture { dl: &'a str, target: &'a str }, + InconsistentTargetPointerWidth { pointer_size: u64, target: u32 }, + InvalidBitsSize { err: String }, +} + impl TargetDataLayout { - pub fn parse(target: &Target) -> Result { + pub fn parse<'a>(target: &'a Target) -> Result> { // Parse an address space index from a string. - let parse_address_space = |s: &str, cause: &str| { + let parse_address_space = |s: &'a str, cause: &'a str| { s.parse::().map(AddressSpace).map_err(|err| { - format!("invalid address space `{}` for `{}` in \"data-layout\": {}", s, cause, err) + TargetDataLayoutErrors::InvalidAddressSpace { addr_space: s, cause, err } }) }; // Parse a bit count from a string. - let parse_bits = |s: &str, kind: &str, cause: &str| { - s.parse::().map_err(|err| { - format!("invalid {} `{}` for `{}` in \"data-layout\": {}", kind, s, cause, err) + let parse_bits = |s: &'a str, kind: &'a str, cause: &'a str| { + s.parse::().map_err(|err| TargetDataLayoutErrors::InvalidBits { + kind, + bit: s, + cause, + err, }) }; // Parse a size string. - let size = |s: &str, cause: &str| parse_bits(s, "size", cause).map(Size::from_bits); + let size = |s: &'a str, cause: &'a str| parse_bits(s, "size", cause).map(Size::from_bits); // Parse an alignment string. - let align = |s: &[&str], cause: &str| { + let align = |s: &[&'a str], cause: &'a str| { if s.is_empty() { - return Err(format!("missing alignment for `{}` in \"data-layout\"", cause)); + return Err(TargetDataLayoutErrors::MissingAlignment { cause }); } let align_from_bits = |bits| { - Align::from_bits(bits).map_err(|err| { - format!("invalid alignment for `{}` in \"data-layout\": {}", cause, err) - }) + Align::from_bits(bits) + .map_err(|err| TargetDataLayoutErrors::InvalidAlignment { cause, err }) }; let abi = parse_bits(s[0], "alignment", cause)?; let pref = s.get(1).map_or(Ok(abi), |pref| parse_bits(pref, "alignment", cause))?; @@ -158,25 +170,24 @@ impl TargetDataLayout { // Perform consistency checks against the Target information. if dl.endian != target.endian { - return Err(format!( - "inconsistent target specification: \"data-layout\" claims \ - architecture is {}-endian, while \"target-endian\" is `{}`", - dl.endian.as_str(), - target.endian.as_str(), - )); + return Err(TargetDataLayoutErrors::InconsistentTargetArchitecture { + dl: dl.endian.as_str(), + target: target.endian.as_str(), + }); } let target_pointer_width: u64 = target.pointer_width.into(); if dl.pointer_size.bits() != target_pointer_width { - return Err(format!( - "inconsistent target specification: \"data-layout\" claims \ - pointers are {}-bit, while \"target-pointer-width\" is `{}`", - dl.pointer_size.bits(), - target.pointer_width - )); + return Err(TargetDataLayoutErrors::InconsistentTargetPointerWidth { + pointer_size: dl.pointer_size.bits(), + target: target.pointer_width, + }); } - dl.c_enum_min_size = Integer::from_size(Size::from_bits(target.c_enum_min_bits))?; + dl.c_enum_min_size = match Integer::from_size(Size::from_bits(target.c_enum_min_bits)) { + Ok(bits) => bits, + Err(err) => return Err(TargetDataLayoutErrors::InvalidBitsSize { err }), + }; Ok(dl) } -- cgit 1.4.1-3-g733a5 From 0e497a714ebfefbee094b8475ea9aa4eeaa7b692 Mon Sep 17 00:00:00 2001 From: Luis Cardoso <61982523+LuisCardosoOliveira@users.noreply.github.com> Date: Thu, 8 Sep 2022 08:15:37 +0200 Subject: translations(rustc_session): migrates two diagnostics in session.rs --- .../rustc_error_messages/locales/en-US/session.ftl | 6 ++++-- compiler/rustc_errors/src/diagnostic.rs | 5 ++++- compiler/rustc_session/src/errors.rs | 14 ++++++++++++++ compiler/rustc_session/src/session.rs | 18 ++++++++---------- 4 files changed, 30 insertions(+), 13 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_error_messages/locales/en-US/session.ftl b/compiler/rustc_error_messages/locales/en-US/session.ftl index a9ed8b4835b..d2a2958f624 100644 --- a/compiler/rustc_error_messages/locales/en-US/session.ftl +++ b/compiler/rustc_error_messages/locales/en-US/session.ftl @@ -15,8 +15,6 @@ session_feature_diagnostic_for_issue = session_feature_diagnostic_help = add `#![feature({$feature})]` to the crate attributes to enable -session_target_data_layout_parse_error = {$err} - session_not_circumvent_feature = `-Zunleash-the-miri-inside-of-you` may not be used to circumvent feature gates, except when testing error paths in the CTFE engine session_profile_use_file_does_not_exist = file `{$path}` passed to `-C profile-use` does not exist. @@ -54,3 +52,7 @@ session_target_inconsistent_architecture = inconsistent target specification: "d session_target_inconsistent_pointer_width = inconsistent target specification: "data-layout" claims pointers are {$pointer_size}-bit, while "target-pointer-width" is `{$target}` session_target_invalid_bits_size = {$err} + +session_target_stack_protector_not_supported = `-Z stack-protector={$stack_protector}` is not supported for target {$target_triple} and will be ignored + +session_split_debuginfo_unstable_platform = `-Csplit-debuginfo={$debuginfo}` is unstable on this platform diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index b88292b893c..a774b52c8a5 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -10,7 +10,7 @@ use rustc_lint_defs::{Applicability, LintExpectationId}; use rustc_span::edition::LATEST_STABLE_EDITION; use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol}; use rustc_span::{edition::Edition, Span, DUMMY_SP}; -use rustc_target::spec::PanicStrategy; +use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple}; use std::borrow::Cow; use std::fmt; use std::hash::{Hash, Hasher}; @@ -93,6 +93,9 @@ into_diagnostic_arg_using_display!( Ident, MacroRulesNormalizedIdent, ParseIntError, + StackProtector, + &TargetTriple, + SplitDebuginfo ); impl IntoDiagnosticArg for bool { diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index a4e13e22ae2..3c93cfab183 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -6,6 +6,7 @@ use rustc_errors::{fluent, DiagnosticBuilder, Handler, MultiSpan}; use rustc_macros::SessionDiagnostic; use rustc_span::{Span, Symbol}; use rustc_target::abi::TargetDataLayoutErrors; +use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple}; #[derive(SessionDiagnostic)] #[diag(session::incorrect_cgu_reuse_type)] @@ -156,3 +157,16 @@ pub struct UnstableVirtualFunctionElimination; pub struct UnsupportedDwarfVersion { pub dwarf_version: u32, } + +#[derive(SessionDiagnostic)] +#[diag(session::target_stack_protector_not_supported)] +pub struct StackProtectorNotSupportedForTarget<'a> { + pub stack_protector: StackProtector, + pub target_triple: &'a TargetTriple, +} + +#[derive(SessionDiagnostic)] +#[diag(session::split_debuginfo_unstable_platform)] +pub struct SplitDebugInfoUnstablePlatform { + pub debuginfo: SplitDebuginfo, +} diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 6add576cdff..caf9d582ab0 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -5,8 +5,9 @@ use crate::config::{self, CrateType, InstrumentCoverage, OptLevel, OutputType, S use crate::errors::{ CannotEnableCrtStaticLinux, CannotMixAndMatchSanitizers, LinkerPluginToWindowsNotSupported, NotCircumventFeature, ProfileSampleUseFileDoesNotExist, ProfileUseFileDoesNotExist, - SanitizerCfiEnabled, SanitizerNotSupported, SanitizersNotSupported, TargetRequiresUnwindTables, - UnstableVirtualFunctionElimination, UnsupportedDwarfVersion, + SanitizerCfiEnabled, SanitizerNotSupported, SanitizersNotSupported, + SplitDebugInfoUnstablePlatform, StackProtectorNotSupportedForTarget, + TargetRequiresUnwindTables, UnstableVirtualFunctionElimination, UnsupportedDwarfVersion, }; use crate::parse::{add_feature_diagnostics, ParseSess}; use crate::search_paths::{PathKind, SearchPath}; @@ -1544,10 +1545,10 @@ fn validate_commandline_args_with_session_available(sess: &Session) { if sess.opts.unstable_opts.stack_protector != StackProtector::None { if !sess.target.options.supports_stack_protector { - sess.warn(&format!( - "`-Z stack-protector={}` is not supported for target {} and will be ignored", - sess.opts.unstable_opts.stack_protector, sess.opts.target_triple - )) + sess.emit_warning(StackProtectorNotSupportedForTarget { + stack_protector: sess.opts.unstable_opts.stack_protector, + target_triple: &sess.opts.target_triple, + }); } } @@ -1560,10 +1561,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) { if !sess.target.options.supported_split_debuginfo.contains(&sess.split_debuginfo()) && !sess.opts.unstable_opts.unstable_options { - sess.err(&format!( - "`-Csplit-debuginfo={}` is unstable on this platform", - sess.split_debuginfo() - )); + sess.emit_err(SplitDebugInfoUnstablePlatform { debuginfo: sess.split_debuginfo() }); } } -- cgit 1.4.1-3-g733a5 From 8d3c30c00491b8452300d5ebaeb7822c9271306f Mon Sep 17 00:00:00 2001 From: Niklas Jonsson Date: Sat, 16 Jul 2022 15:16:57 +0200 Subject: rustc_error, rustc_private, rustc_ast: Switch to stable hash containers --- compiler/rustc_ast/src/node_id.rs | 2 +- compiler/rustc_data_structures/src/fx.rs | 15 ++++++++++++++- compiler/rustc_errors/src/emitter.rs | 4 ++-- compiler/rustc_errors/src/lib.rs | 5 ++--- compiler/rustc_hir/src/hir_id.rs | 9 +++++++-- compiler/rustc_privacy/src/lib.rs | 1 - compiler/rustc_span/src/def_id.rs | 9 +++++++-- .../clippy/clippy_lints/src/matches/match_same_arms.rs | 7 +++---- 8 files changed, 36 insertions(+), 16 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_ast/src/node_id.rs b/compiler/rustc_ast/src/node_id.rs index 7f928cb5761..7b5acc3f485 100644 --- a/compiler/rustc_ast/src/node_id.rs +++ b/compiler/rustc_ast/src/node_id.rs @@ -13,7 +13,7 @@ rustc_index::newtype_index! { } } -rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeId); +rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeMapEntry, NodeId); /// The [`NodeId`] used to represent the root of the crate. pub const CRATE_NODE_ID: NodeId = NodeId::from_u32(0); diff --git a/compiler/rustc_data_structures/src/fx.rs b/compiler/rustc_data_structures/src/fx.rs index bbeb193dba3..0d0c51b6819 100644 --- a/compiler/rustc_data_structures/src/fx.rs +++ b/compiler/rustc_data_structures/src/fx.rs @@ -2,13 +2,26 @@ use std::hash::BuildHasherDefault; pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher}; +pub type StdEntry<'a, K, V> = std::collections::hash_map::Entry<'a, K, V>; + pub type FxIndexMap = indexmap::IndexMap>; pub type FxIndexSet = indexmap::IndexSet>; +pub type IndexEntry<'a, K, V> = indexmap::map::Entry<'a, K, V>; #[macro_export] macro_rules! define_id_collections { - ($map_name:ident, $set_name:ident, $key:ty) => { + ($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => { pub type $map_name = $crate::fx::FxHashMap<$key, T>; pub type $set_name = $crate::fx::FxHashSet<$key>; + pub type $entry_name<'a, T> = $crate::fx::StdEntry<'a, $key, T>; + }; +} + +#[macro_export] +macro_rules! define_stable_id_collections { + ($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => { + pub type $map_name = $crate::fx::FxIndexMap<$key, T>; + pub type $set_name = $crate::fx::FxIndexSet<$key>; + pub type $entry_name<'a, T> = $crate::fx::IndexEntry<'a, $key, T>; }; } diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index e79ce11a6fc..1d260f7cafc 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -22,7 +22,7 @@ use crate::{ use rustc_lint_defs::pluralize; -use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_data_structures::sync::Lrc; use rustc_error_messages::FluentArgs; use rustc_span::hygiene::{ExpnKind, MacroKind}; @@ -1487,7 +1487,7 @@ impl EmitterWriter { ); // Contains the vertical lines' positions for active multiline annotations - let mut multilines = FxHashMap::default(); + let mut multilines = FxIndexMap::default(); // Get the left-side margin to remove it let mut whitespace_margin = usize::MAX; diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 3e02d2ebb7e..fb7ae6f99cf 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -12,7 +12,6 @@ #![feature(result_option_inspect)] #![feature(rustc_attrs)] #![allow(incomplete_features)] -#![allow(rustc::potential_query_instability)] #[macro_use] extern crate rustc_macros; @@ -27,7 +26,7 @@ use Level::*; use emitter::{is_case_difference, Emitter, EmitterWriter}; use registry::Registry; -use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::stable_hasher::StableHasher; use rustc_data_structures::sync::{self, Lock, Lrc}; use rustc_data_structures::AtomicRef; @@ -413,7 +412,7 @@ struct HandlerInner { taught_diagnostics: FxHashSet, /// Used to suggest rustc --explain - emitted_diagnostic_codes: FxHashSet, + emitted_diagnostic_codes: FxIndexSet, /// This set contains a hash of every diagnostic that has been emitted by /// this handler. These hashes is used to avoid emitting the same error diff --git a/compiler/rustc_hir/src/hir_id.rs b/compiler/rustc_hir/src/hir_id.rs index e586d5cd5d9..84b0740c7b3 100644 --- a/compiler/rustc_hir/src/hir_id.rs +++ b/compiler/rustc_hir/src/hir_id.rs @@ -67,8 +67,13 @@ impl PartialOrd for HirId { } } -rustc_data_structures::define_id_collections!(HirIdMap, HirIdSet, HirId); -rustc_data_structures::define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId); +rustc_data_structures::define_stable_id_collections!(HirIdMap, HirIdSet, HirIdMapEntry, HirId); +rustc_data_structures::define_id_collections!( + ItemLocalMap, + ItemLocalSet, + ItemLocalMapEntry, + ItemLocalId +); rustc_index::newtype_index! { /// An `ItemLocalId` uniquely identifies something within a given "item-like"; diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index afd423dc5fa..b8e81bb5d20 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -5,7 +5,6 @@ #![feature(rustc_private)] #![feature(try_blocks)] #![recursion_limit = "256"] -#![allow(rustc::potential_query_instability)] #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index ceb6b6c68b0..37b8371a8fe 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -337,7 +337,7 @@ impl fmt::Debug for DefId { } } -rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId); +rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefIdMapEntry, DefId); /// A `LocalDefId` is equivalent to a `DefId` with `krate == LOCAL_CRATE`. Since /// we encode this information in the type, we can ensure at compile time that @@ -399,7 +399,12 @@ impl Decodable for LocalDefId { } } -rustc_data_structures::define_id_collections!(LocalDefIdMap, LocalDefIdSet, LocalDefId); +rustc_data_structures::define_id_collections!( + LocalDefIdMap, + LocalDefIdSet, + LocalDefIdMapEntry, + LocalDefId +); impl HashStable for DefId { #[inline] diff --git a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs b/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs index 93874b103b4..d37f44d4a17 100644 --- a/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs +++ b/src/tools/clippy/clippy_lints/src/matches/match_same_arms.rs @@ -8,11 +8,10 @@ use rustc_arena::DroplessArena; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; -use rustc_hir::{Arm, Expr, ExprKind, HirId, HirIdMap, HirIdSet, Pat, PatKind, RangeEnd}; +use rustc_hir::{Arm, Expr, ExprKind, HirId, HirIdMap, HirIdMapEntry, HirIdSet, Pat, PatKind, RangeEnd}; use rustc_lint::LateContext; use rustc_middle::ty; use rustc_span::Symbol; -use std::collections::hash_map::Entry; use super::MATCH_SAME_ARMS; @@ -71,9 +70,9 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) { if let Some(a_id) = path_to_local(a); if let Some(b_id) = path_to_local(b); let entry = match local_map.entry(a_id) { - Entry::Vacant(entry) => entry, + HirIdMapEntry::Vacant(entry) => entry, // check if using the same bindings as before - Entry::Occupied(entry) => return *entry.get() == b_id, + HirIdMapEntry::Occupied(entry) => return *entry.get() == b_id, }; // the names technically don't have to match; this makes the lint more conservative if cx.tcx.hir().name(a_id) == cx.tcx.hir().name(b_id); -- cgit 1.4.1-3-g733a5 From 370c816a71742373401fd3c75699c04f1ceaf81f Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 11 Sep 2022 19:19:07 +0000 Subject: A SubstitutionPart is not a deletion if it replaces nothing with nothing --- compiler/rustc_errors/src/emitter.rs | 2 +- compiler/rustc_errors/src/lib.rs | 19 ++++++------ .../ui/dyn-keyword/dyn-2018-edition-lint.stderr | 35 +++++++++------------- .../ui/dyn-keyword/dyn-2021-edition-error.stderr | 10 +++---- src/test/ui/dyn-keyword/dyn-angle-brackets.stderr | 5 ++-- ...th-implicit-hrtb-without-dyn.edition2021.stderr | 5 ++-- src/test/ui/issues/issue-86756.stderr | 5 ++-- .../allowed-group-warn-by-default-lint.stderr | 15 ++++------ src/test/ui/lint/force-warn/cap-lints-allow.stderr | 15 ++++------ ...t-group-allowed-cli-warn-by-default-lint.stderr | 15 ++++------ .../lint-group-allowed-lint-group.stderr | 15 ++++------ .../lint-group-allowed-warn-by-default-lint.stderr | 15 ++++------ src/test/ui/parser/increment-notfixed.stderr | 30 ++++++++----------- .../ui/parser/trait-object-trait-parens.stderr | 15 ++++------ .../rust-2021/reserved-prefixes-migration.stderr | 15 ++++------ src/test/ui/rust-2021/reserved-prefixes.stderr | 27 ++++++----------- src/test/ui/suggestions/issue-61963.stderr | 35 +++++++++------------- .../suggest-blanket-impl-local-trait.stderr | 35 +++++++++------------- ...-swapping-self-ty-and-trait-edition-2021.stderr | 5 ++-- .../suggest-swapping-self-ty-and-trait.stderr | 5 ++-- src/test/ui/traits/bound/not-on-bare-trait.stderr | 5 ++-- 21 files changed, 130 insertions(+), 198 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 1d260f7cafc..880006cf1fc 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1704,7 +1704,7 @@ impl EmitterWriter { { notice_capitalization |= only_capitalization; - let has_deletion = parts.iter().any(|p| p.is_deletion()); + let has_deletion = parts.iter().any(|p| p.is_deletion(sm)); let is_multiline = complete.lines().count() > 1; if let Some(span) = span.primary_span() { diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index fb7ae6f99cf..888128f3f74 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -150,21 +150,20 @@ pub struct SubstitutionHighlight { impl SubstitutionPart { pub fn is_addition(&self, sm: &SourceMap) -> bool { - !self.snippet.is_empty() - && sm - .span_to_snippet(self.span) - .map_or(self.span.is_empty(), |snippet| snippet.trim().is_empty()) + !self.snippet.is_empty() && !self.replaces_meaningful_content(sm) } - pub fn is_deletion(&self) -> bool { - self.snippet.trim().is_empty() + pub fn is_deletion(&self, sm: &SourceMap) -> bool { + self.snippet.trim().is_empty() && self.replaces_meaningful_content(sm) } pub fn is_replacement(&self, sm: &SourceMap) -> bool { - !self.snippet.is_empty() - && sm - .span_to_snippet(self.span) - .map_or(!self.span.is_empty(), |snippet| !snippet.trim().is_empty()) + !self.snippet.is_empty() && self.replaces_meaningful_content(sm) + } + + fn replaces_meaningful_content(&self, sm: &SourceMap) -> bool { + sm.span_to_snippet(self.span) + .map_or(!self.span.is_empty(), |snippet| !snippet.trim().is_empty()) } } diff --git a/src/test/ui/dyn-keyword/dyn-2018-edition-lint.stderr b/src/test/ui/dyn-keyword/dyn-2018-edition-lint.stderr index 34699bb2658..e7db68693c0 100644 --- a/src/test/ui/dyn-keyword/dyn-2018-edition-lint.stderr +++ b/src/test/ui/dyn-keyword/dyn-2018-edition-lint.stderr @@ -13,9 +13,8 @@ LL | #[deny(bare_trait_objects)] = note: for more information, see help: use `dyn` | -LL - fn function(x: &SomeTrait, y: Box) { -LL + fn function(x: &dyn SomeTrait, y: Box) { - | +LL | fn function(x: &dyn SomeTrait, y: Box) { + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/dyn-2018-edition-lint.rs:4:35 @@ -27,9 +26,8 @@ LL | fn function(x: &SomeTrait, y: Box) { = note: for more information, see help: use `dyn` | -LL - fn function(x: &SomeTrait, y: Box) { -LL + fn function(x: &SomeTrait, y: Box) { - | +LL | fn function(x: &SomeTrait, y: Box) { + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/dyn-2018-edition-lint.rs:17:14 @@ -41,9 +39,8 @@ LL | let _x: &SomeTrait = todo!(); = note: for more information, see help: use `dyn` | -LL - let _x: &SomeTrait = todo!(); -LL + let _x: &dyn SomeTrait = todo!(); - | +LL | let _x: &dyn SomeTrait = todo!(); + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/dyn-2018-edition-lint.rs:4:17 @@ -55,9 +52,8 @@ LL | fn function(x: &SomeTrait, y: Box) { = note: for more information, see help: use `dyn` | -LL - fn function(x: &SomeTrait, y: Box) { -LL + fn function(x: &dyn SomeTrait, y: Box) { - | +LL | fn function(x: &dyn SomeTrait, y: Box) { + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/dyn-2018-edition-lint.rs:4:17 @@ -69,9 +65,8 @@ LL | fn function(x: &SomeTrait, y: Box) { = note: for more information, see help: use `dyn` | -LL - fn function(x: &SomeTrait, y: Box) { -LL + fn function(x: &dyn SomeTrait, y: Box) { - | +LL | fn function(x: &dyn SomeTrait, y: Box) { + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/dyn-2018-edition-lint.rs:4:35 @@ -83,9 +78,8 @@ LL | fn function(x: &SomeTrait, y: Box) { = note: for more information, see help: use `dyn` | -LL - fn function(x: &SomeTrait, y: Box) { -LL + fn function(x: &SomeTrait, y: Box) { - | +LL | fn function(x: &SomeTrait, y: Box) { + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/dyn-2018-edition-lint.rs:4:35 @@ -97,9 +91,8 @@ LL | fn function(x: &SomeTrait, y: Box) { = note: for more information, see help: use `dyn` | -LL - fn function(x: &SomeTrait, y: Box) { -LL + fn function(x: &SomeTrait, y: Box) { - | +LL | fn function(x: &SomeTrait, y: Box) { + | +++ error: aborting due to 7 previous errors diff --git a/src/test/ui/dyn-keyword/dyn-2021-edition-error.stderr b/src/test/ui/dyn-keyword/dyn-2021-edition-error.stderr index 9e212c77dc7..08ee77116f0 100644 --- a/src/test/ui/dyn-keyword/dyn-2021-edition-error.stderr +++ b/src/test/ui/dyn-keyword/dyn-2021-edition-error.stderr @@ -6,9 +6,8 @@ LL | fn function(x: &SomeTrait, y: Box) { | help: add `dyn` keyword before this trait | -LL - fn function(x: &SomeTrait, y: Box) { -LL + fn function(x: &dyn SomeTrait, y: Box) { - | +LL | fn function(x: &dyn SomeTrait, y: Box) { + | +++ error[E0782]: trait objects must include the `dyn` keyword --> $DIR/dyn-2021-edition-error.rs:3:35 @@ -18,9 +17,8 @@ LL | fn function(x: &SomeTrait, y: Box) { | help: add `dyn` keyword before this trait | -LL - fn function(x: &SomeTrait, y: Box) { -LL + fn function(x: &SomeTrait, y: Box) { - | +LL | fn function(x: &SomeTrait, y: Box) { + | +++ error: aborting due to 2 previous errors diff --git a/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr b/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr index 9bc603fba54..261c2d5742f 100644 --- a/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr +++ b/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr @@ -13,9 +13,8 @@ LL | #![deny(bare_trait_objects)] = note: for more information, see help: use `dyn` | -LL - ::fmt(self, f) -LL + ::fmt(self, f) - | +LL | ::fmt(self, f) + | +++ error: aborting due to previous error diff --git a/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2021.stderr b/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2021.stderr index c01c33a8931..8f409227324 100644 --- a/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2021.stderr +++ b/src/test/ui/impl-trait/generic-with-implicit-hrtb-without-dyn.edition2021.stderr @@ -6,9 +6,8 @@ LL | fn ice() -> impl AsRef { | help: add `dyn` keyword before this trait | -LL - fn ice() -> impl AsRef { -LL + fn ice() -> impl AsRef { - | +LL | fn ice() -> impl AsRef { + | +++ error[E0277]: the trait bound `(): AsRef<(dyn for<'r> Fn(&'r ()) + 'static)>` is not satisfied --> $DIR/generic-with-implicit-hrtb-without-dyn.rs:6:13 diff --git a/src/test/ui/issues/issue-86756.stderr b/src/test/ui/issues/issue-86756.stderr index 399c940ca19..b26c1834d84 100644 --- a/src/test/ui/issues/issue-86756.stderr +++ b/src/test/ui/issues/issue-86756.stderr @@ -25,9 +25,8 @@ LL | eq:: = note: for more information, see help: use `dyn` | -LL - eq:: -LL + eq:: - | +LL | eq:: + | +++ error[E0107]: missing generics for trait `Foo` --> $DIR/issue-86756.rs:5:15 diff --git a/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr b/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr index 8d826bd1457..94d81c3aa71 100644 --- a/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr +++ b/src/test/ui/lint/force-warn/allowed-group-warn-by-default-lint.stderr @@ -9,9 +9,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: trait objects without an explicit `dyn` are deprecated --> $DIR/allowed-group-warn-by-default-lint.rs:10:25 @@ -23,9 +22,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: trait objects without an explicit `dyn` are deprecated --> $DIR/allowed-group-warn-by-default-lint.rs:10:25 @@ -37,9 +35,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: 3 warnings emitted diff --git a/src/test/ui/lint/force-warn/cap-lints-allow.stderr b/src/test/ui/lint/force-warn/cap-lints-allow.stderr index 978270872c4..7f0fd8530e2 100644 --- a/src/test/ui/lint/force-warn/cap-lints-allow.stderr +++ b/src/test/ui/lint/force-warn/cap-lints-allow.stderr @@ -9,9 +9,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: trait objects without an explicit `dyn` are deprecated --> $DIR/cap-lints-allow.rs:8:25 @@ -23,9 +22,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: trait objects without an explicit `dyn` are deprecated --> $DIR/cap-lints-allow.rs:8:25 @@ -37,9 +35,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: 3 warnings emitted diff --git a/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr b/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr index 6e67ebf2747..eb2bca7b84d 100644 --- a/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr +++ b/src/test/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr @@ -9,9 +9,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: trait objects without an explicit `dyn` are deprecated --> $DIR/lint-group-allowed-cli-warn-by-default-lint.rs:8:25 @@ -23,9 +22,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: trait objects without an explicit `dyn` are deprecated --> $DIR/lint-group-allowed-cli-warn-by-default-lint.rs:8:25 @@ -37,9 +35,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: 3 warnings emitted diff --git a/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr b/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr index c5dea84b8f3..ed01937a57b 100644 --- a/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr +++ b/src/test/ui/lint/force-warn/lint-group-allowed-lint-group.stderr @@ -9,9 +9,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: trait objects without an explicit `dyn` are deprecated --> $DIR/lint-group-allowed-lint-group.rs:10:25 @@ -23,9 +22,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: trait objects without an explicit `dyn` are deprecated --> $DIR/lint-group-allowed-lint-group.rs:10:25 @@ -37,9 +35,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: 3 warnings emitted diff --git a/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr b/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr index acd0c503d9c..8db7c12757b 100644 --- a/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr +++ b/src/test/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr @@ -9,9 +9,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: trait objects without an explicit `dyn` are deprecated --> $DIR/lint-group-allowed-warn-by-default-lint.rs:10:25 @@ -23,9 +22,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: trait objects without an explicit `dyn` are deprecated --> $DIR/lint-group-allowed-warn-by-default-lint.rs:10:25 @@ -37,9 +35,8 @@ LL | pub fn function(_x: Box) {} = note: for more information, see help: use `dyn` | -LL - pub fn function(_x: Box) {} -LL + pub fn function(_x: Box) {} - | +LL | pub fn function(_x: Box) {} + | +++ warning: 3 warnings emitted diff --git a/src/test/ui/parser/increment-notfixed.stderr b/src/test/ui/parser/increment-notfixed.stderr index 352d98cf82e..ae55ae06714 100644 --- a/src/test/ui/parser/increment-notfixed.stderr +++ b/src/test/ui/parser/increment-notfixed.stderr @@ -8,9 +8,8 @@ help: use `+= 1` instead | LL | { let tmp = i; i += 1; tmp }; | +++++++++++ ~~~~~~~~~~~~~~~ -LL - i++; -LL + i += 1; - | +LL | i += 1; + | ~~~~ error: Rust has no postfix increment operator --> $DIR/increment-notfixed.rs:17:12 @@ -24,9 +23,8 @@ help: use `+= 1` instead | LL | while { let tmp = i; i += 1; tmp } < 5 { | +++++++++++ ~~~~~~~~~~~~~~~ -LL - while i++ < 5 { -LL + while i += 1 < 5 { - | +LL | while i += 1 < 5 { + | ~~~~ error: Rust has no postfix increment operator --> $DIR/increment-notfixed.rs:25:8 @@ -38,9 +36,8 @@ help: use `+= 1` instead | LL | { let tmp_ = tmp; tmp += 1; tmp_ }; | ++++++++++++ ~~~~~~~~~~~~~~~~~~ -LL - tmp++; -LL + tmp += 1; - | +LL | tmp += 1; + | ~~~~ error: Rust has no postfix increment operator --> $DIR/increment-notfixed.rs:31:14 @@ -54,9 +51,8 @@ help: use `+= 1` instead | LL | while { let tmp_ = tmp; tmp += 1; tmp_ } < 5 { | ++++++++++++ ~~~~~~~~~~~~~~~~~~ -LL - while tmp++ < 5 { -LL + while tmp += 1 < 5 { - | +LL | while tmp += 1 < 5 { + | ~~~~ error: Rust has no postfix increment operator --> $DIR/increment-notfixed.rs:39:16 @@ -68,9 +64,8 @@ help: use `+= 1` instead | LL | { let tmp = foo.bar.qux; foo.bar.qux += 1; tmp }; | +++++++++++ ~~~~~~~~~~~~~~~~~~~~~~~~~ -LL - foo.bar.qux++; -LL + foo.bar.qux += 1; - | +LL | foo.bar.qux += 1; + | ~~~~ error: Rust has no postfix increment operator --> $DIR/increment-notfixed.rs:49:10 @@ -82,9 +77,8 @@ help: use `+= 1` instead | LL | { let tmp = s.tmp; s.tmp += 1; tmp }; | +++++++++++ ~~~~~~~~~~~~~~~~~~~ -LL - s.tmp++; -LL + s.tmp += 1; - | +LL | s.tmp += 1; + | ~~~~ error: Rust has no prefix increment operator --> $DIR/increment-notfixed.rs:56:5 diff --git a/src/test/ui/parser/trait-object-trait-parens.stderr b/src/test/ui/parser/trait-object-trait-parens.stderr index 7ee965bd2ba..823f75bfac8 100644 --- a/src/test/ui/parser/trait-object-trait-parens.stderr +++ b/src/test/ui/parser/trait-object-trait-parens.stderr @@ -27,9 +27,8 @@ LL | let _: Box<(Obj) + (?Sized) + (for<'a> Trait<'a>)>; = note: for more information, see help: use `dyn` | -LL - let _: Box<(Obj) + (?Sized) + (for<'a> Trait<'a>)>; -LL + let _: Box Trait<'a>)>; - | +LL | let _: Box Trait<'a>)>; + | +++ error[E0225]: only auto traits can be used as additional traits in a trait object --> $DIR/trait-object-trait-parens.rs:8:35 @@ -52,9 +51,8 @@ LL | let _: Box Trait<'a>) + (Obj)>; = note: for more information, see help: use `dyn` | -LL - let _: Box Trait<'a>) + (Obj)>; -LL + let _: Box Trait<'a>) + (Obj)>; - | +LL | let _: Box Trait<'a>) + (Obj)>; + | +++ error[E0225]: only auto traits can be used as additional traits in a trait object --> $DIR/trait-object-trait-parens.rs:13:47 @@ -77,9 +75,8 @@ LL | let _: Box Trait<'a> + (Obj) + (?Sized)>; = note: for more information, see help: use `dyn` | -LL - let _: Box Trait<'a> + (Obj) + (?Sized)>; -LL + let _: Box Trait<'a> + (Obj) + (?Sized)>; - | +LL | let _: Box Trait<'a> + (Obj) + (?Sized)>; + | +++ error[E0225]: only auto traits can be used as additional traits in a trait object --> $DIR/trait-object-trait-parens.rs:18:36 diff --git a/src/test/ui/rust-2021/reserved-prefixes-migration.stderr b/src/test/ui/rust-2021/reserved-prefixes-migration.stderr index 647a9f39312..94f9bb57cc8 100644 --- a/src/test/ui/rust-2021/reserved-prefixes-migration.stderr +++ b/src/test/ui/rust-2021/reserved-prefixes-migration.stderr @@ -13,8 +13,7 @@ LL | #![warn(rust_2021_prefixes_incompatible_syntax)] = note: for more information, see help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 | -LL - m2!(z"hey"); -LL + m2!(z "hey"); +LL | m2!(z "hey"); | warning: prefix `prefix` is unknown @@ -27,8 +26,7 @@ LL | m2!(prefix"hey"); = note: for more information, see help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 | -LL - m2!(prefix"hey"); -LL + m2!(prefix "hey"); +LL | m2!(prefix "hey"); | warning: prefix `hey` is unknown @@ -41,8 +39,7 @@ LL | m3!(hey#123); = note: for more information, see help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 | -LL - m3!(hey#123); -LL + m3!(hey #123); +LL | m3!(hey #123); | warning: prefix `hey` is unknown @@ -55,8 +52,7 @@ LL | m3!(hey#hey); = note: for more information, see help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 | -LL - m3!(hey#hey); -LL + m3!(hey #hey); +LL | m3!(hey #hey); | warning: prefix `kind` is unknown @@ -69,8 +65,7 @@ LL | #name = #kind#value = note: for more information, see help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 | -LL - #name = #kind#value -LL + #name = #kind #value +LL | #name = #kind #value | warning: 5 warnings emitted diff --git a/src/test/ui/rust-2021/reserved-prefixes.stderr b/src/test/ui/rust-2021/reserved-prefixes.stderr index df31aee66fe..fcda5fcac5b 100644 --- a/src/test/ui/rust-2021/reserved-prefixes.stderr +++ b/src/test/ui/rust-2021/reserved-prefixes.stderr @@ -7,8 +7,7 @@ LL | demo3!(foo#bar); = note: prefixed identifiers and literals are reserved since Rust 2021 help: consider inserting whitespace here | -LL - demo3!(foo#bar); -LL + demo3!(foo #bar); +LL | demo3!(foo #bar); | error: prefix `foo` is unknown @@ -20,8 +19,7 @@ LL | demo2!(foo"bar"); = note: prefixed identifiers and literals are reserved since Rust 2021 help: consider inserting whitespace here | -LL - demo2!(foo"bar"); -LL + demo2!(foo "bar"); +LL | demo2!(foo "bar"); | error: prefix `foo` is unknown @@ -33,8 +31,7 @@ LL | demo2!(foo'b'); = note: prefixed identifiers and literals are reserved since Rust 2021 help: consider inserting whitespace here | -LL - demo2!(foo'b'); -LL + demo2!(foo 'b'); +LL | demo2!(foo 'b'); | error: prefix `foo` is unknown @@ -46,8 +43,7 @@ LL | demo2!(foo'b); = note: prefixed identifiers and literals are reserved since Rust 2021 help: consider inserting whitespace here | -LL - demo2!(foo'b); -LL + demo2!(foo 'b); +LL | demo2!(foo 'b); | error: prefix `foo` is unknown @@ -59,8 +55,7 @@ LL | demo3!(foo# bar); = note: prefixed identifiers and literals are reserved since Rust 2021 help: consider inserting whitespace here | -LL - demo3!(foo# bar); -LL + demo3!(foo # bar); +LL | demo3!(foo # bar); | error: prefix `foo` is unknown @@ -72,8 +67,7 @@ LL | demo4!(foo#! bar); = note: prefixed identifiers and literals are reserved since Rust 2021 help: consider inserting whitespace here | -LL - demo4!(foo#! bar); -LL + demo4!(foo #! bar); +LL | demo4!(foo #! bar); | error: prefix `foo` is unknown @@ -85,8 +79,7 @@ LL | demo4!(foo## bar); = note: prefixed identifiers and literals are reserved since Rust 2021 help: consider inserting whitespace here | -LL - demo4!(foo## bar); -LL + demo4!(foo ## bar); +LL | demo4!(foo ## bar); | error: prefix `foo` is unknown @@ -98,8 +91,7 @@ LL | demo4!(foo#bar#); = note: prefixed identifiers and literals are reserved since Rust 2021 help: consider inserting whitespace here | -LL - demo4!(foo#bar#); -LL + demo4!(foo #bar#); +LL | demo4!(foo #bar#); | error: prefix `bar` is unknown @@ -111,8 +103,7 @@ LL | demo4!(foo#bar#); = note: prefixed identifiers and literals are reserved since Rust 2021 help: consider inserting whitespace here | -LL - demo4!(foo#bar#); -LL + demo4!(foo#bar #); +LL | demo4!(foo#bar #); | error: aborting due to 9 previous errors diff --git a/src/test/ui/suggestions/issue-61963.stderr b/src/test/ui/suggestions/issue-61963.stderr index c0d776e59ab..a788cab6e4e 100644 --- a/src/test/ui/suggestions/issue-61963.stderr +++ b/src/test/ui/suggestions/issue-61963.stderr @@ -13,9 +13,8 @@ LL | #![deny(bare_trait_objects)] = note: for more information, see help: use `dyn` | -LL - bar: Box, -LL + bar: Box, - | +LL | bar: Box, + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/issue-61963.rs:18:1 @@ -27,9 +26,8 @@ LL | pub struct Foo { = note: for more information, see help: use `dyn` | -LL - pub struct Foo { -LL + dyn pub struct Foo { - | +LL | dyn pub struct Foo { + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/issue-61963.rs:28:14 @@ -41,9 +39,8 @@ LL | bar: Box, = note: for more information, see help: use `dyn` | -LL - bar: Box, -LL + bar: Box, - | +LL | bar: Box, + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/issue-61963.rs:28:14 @@ -55,9 +52,8 @@ LL | bar: Box, = note: for more information, see help: use `dyn` | -LL - bar: Box, -LL + bar: Box, - | +LL | bar: Box, + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/issue-61963.rs:18:1 @@ -69,9 +65,8 @@ LL | pub struct Foo { = note: for more information, see help: use `dyn` | -LL - pub struct Foo { -LL + dyn pub struct Foo { - | +LL | dyn pub struct Foo { + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/issue-61963.rs:18:1 @@ -83,9 +78,8 @@ LL | pub struct Foo { = note: for more information, see help: use `dyn` | -LL - pub struct Foo { -LL + dyn pub struct Foo { - | +LL | dyn pub struct Foo { + | +++ error: trait objects without an explicit `dyn` are deprecated --> $DIR/issue-61963.rs:18:1 @@ -97,9 +91,8 @@ LL | pub struct Foo { = note: for more information, see help: use `dyn` | -LL - pub struct Foo { -LL + dyn pub struct Foo { - | +LL | dyn pub struct Foo { + | +++ error: aborting due to 7 previous errors diff --git a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr index d739a8272f1..398caa98b84 100644 --- a/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr +++ b/src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr @@ -6,9 +6,8 @@ LL | impl LocalTraitTwo for LocalTraitOne {} | help: add `dyn` keyword before this trait | -LL - impl LocalTraitTwo for LocalTraitOne {} -LL + impl LocalTraitTwo for dyn LocalTraitOne {} - | +LL | impl LocalTraitTwo for dyn LocalTraitOne {} + | +++ help: alternatively use a blanket implementation to implement `LocalTraitTwo` for all types that also implement `LocalTraitOne` | LL | impl LocalTraitTwo for T {} @@ -22,9 +21,8 @@ LL | impl fmt::Display for LocalTraitOne { | help: add `dyn` keyword before this trait | -LL - impl fmt::Display for LocalTraitOne { -LL + impl fmt::Display for dyn LocalTraitOne { - | +LL | impl fmt::Display for dyn LocalTraitOne { + | +++ error[E0782]: trait objects must include the `dyn` keyword --> $DIR/suggest-blanket-impl-local-trait.rs:26:23 @@ -34,9 +32,8 @@ LL | impl fmt::Display for LocalTraitTwo + Send { | help: add `dyn` keyword before this trait | -LL - impl fmt::Display for LocalTraitTwo + Send { -LL + impl fmt::Display for dyn LocalTraitTwo + Send { - | +LL | impl fmt::Display for dyn LocalTraitTwo + Send { + | +++ error[E0782]: trait objects must include the `dyn` keyword --> $DIR/suggest-blanket-impl-local-trait.rs:34:24 @@ -46,9 +43,8 @@ LL | impl LocalTraitOne for fmt::Display {} | help: add `dyn` keyword before this trait | -LL - impl LocalTraitOne for fmt::Display {} -LL + impl LocalTraitOne for dyn fmt::Display {} - | +LL | impl LocalTraitOne for dyn fmt::Display {} + | +++ help: alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display` | LL | impl LocalTraitOne for T {} @@ -62,9 +58,8 @@ LL | impl LocalTraitOne for fmt::Display + Send {} | help: add `dyn` keyword before this trait | -LL - impl LocalTraitOne for fmt::Display + Send {} -LL + impl LocalTraitOne for dyn fmt::Display + Send {} - | +LL | impl LocalTraitOne for dyn fmt::Display + Send {} + | +++ help: alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display + Send` | LL | impl LocalTraitOne for T {} @@ -78,9 +73,8 @@ LL | impl GenericTrait for LocalTraitOne {} | help: add `dyn` keyword before this trait | -LL - impl GenericTrait for LocalTraitOne {} -LL + impl GenericTrait for dyn LocalTraitOne {} - | +LL | impl GenericTrait for dyn LocalTraitOne {} + | +++ help: alternatively use a blanket implementation to implement `GenericTrait` for all types that also implement `LocalTraitOne` | LL | impl GenericTrait for T {} @@ -94,9 +88,8 @@ LL | impl GenericTraitTwo for GenericTrait {} | help: add `dyn` keyword before this trait | -LL - impl GenericTraitTwo for GenericTrait {} -LL + impl GenericTraitTwo for dyn GenericTrait {} - | +LL | impl GenericTraitTwo for dyn GenericTrait {} + | +++ help: alternatively use a blanket implementation to implement `GenericTraitTwo` for all types that also implement `GenericTrait` | LL | impl> GenericTraitTwo for U {} diff --git a/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr b/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr index fc880d6b86a..87e71643620 100644 --- a/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr +++ b/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr @@ -39,9 +39,8 @@ LL | impl<'a, T> Struct for Trait<'a, T> {} | help: add `dyn` keyword before this trait | -LL - impl<'a, T> Struct for Trait<'a, T> {} -LL + impl<'a, T> Struct for dyn Trait<'a, T> {} - | +LL | impl<'a, T> Struct for dyn Trait<'a, T> {} + | +++ error: aborting due to 4 previous errors diff --git a/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr b/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr index f5143762da8..f716e6c17e2 100644 --- a/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr +++ b/src/test/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr @@ -42,9 +42,8 @@ LL | impl<'a, T> Struct for Trait<'a, T> {} = note: for more information, see help: use `dyn` | -LL - impl<'a, T> Struct for Trait<'a, T> {} -LL + impl<'a, T> Struct for dyn Trait<'a, T> {} - | +LL | impl<'a, T> Struct for dyn Trait<'a, T> {} + | +++ error: aborting due to 3 previous errors; 1 warning emitted diff --git a/src/test/ui/traits/bound/not-on-bare-trait.stderr b/src/test/ui/traits/bound/not-on-bare-trait.stderr index 8a92dd11872..1c52629daa4 100644 --- a/src/test/ui/traits/bound/not-on-bare-trait.stderr +++ b/src/test/ui/traits/bound/not-on-bare-trait.stderr @@ -9,9 +9,8 @@ LL | fn foo(_x: Foo + Send) { = note: for more information, see help: use `dyn` | -LL - fn foo(_x: Foo + Send) { -LL + fn foo(_x: dyn Foo + Send) { - | +LL | fn foo(_x: dyn Foo + Send) { + | +++ error[E0277]: the size for values of type `(dyn Foo + Send + 'static)` cannot be known at compilation time --> $DIR/not-on-bare-trait.rs:7:8 -- cgit 1.4.1-3-g733a5 From c2cff68d8445fc2bcaff060a8b78993939f33878 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 11 Sep 2022 20:02:33 +0000 Subject: Don't trim substitution if it's only whitespace --- compiler/rustc_errors/src/emitter.rs | 28 +++++++++++++++------- .../rust-2021/reserved-prefixes-migration.stderr | 10 ++++---- src/test/ui/rust-2021/reserved-prefixes.stderr | 18 +++++++------- 3 files changed, 33 insertions(+), 23 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 880006cf1fc..016404c5f67 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -268,7 +268,10 @@ pub trait Emitter: Translate { SuggestionStyle::ShowAlways, ].contains(&sugg.style) { - let substitution = &sugg.substitutions[0].parts[0].snippet.trim(); + // Don't trim the substitution if it's only whitespace changes + let substitution = &sugg.substitutions[0].parts[0].snippet; + let substitution = + if substitution.trim().is_empty() { substitution } else { substitution.trim() }; let msg = if substitution.is_empty() || sugg.style.hide_inline() { // This substitution is only removal OR we explicitly don't want to show the // code inline (`hide_inline`). Therefore, we don't show the substitution. @@ -1880,16 +1883,23 @@ impl EmitterWriter { let span_start_pos = sm.lookup_char_pos(part.span.lo()).col_display; let span_end_pos = sm.lookup_char_pos(part.span.hi()).col_display; + // If this addition is _only_ whitespace, then don't trim it, + // or else we're just not rendering anything. + let is_whitespace_addition = part.snippet.trim().is_empty(); + // Do not underline the leading... - let start = part.snippet.len().saturating_sub(part.snippet.trim_start().len()); + let start = if is_whitespace_addition { + 0 + } else { + part.snippet.len().saturating_sub(part.snippet.trim_start().len()) + }; // ...or trailing spaces. Account for substitutions containing unicode // characters. - let sub_len: usize = part - .snippet - .trim() - .chars() - .map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) - .sum(); + let sub_len: usize = + if is_whitespace_addition { &part.snippet } else { part.snippet.trim() } + .chars() + .map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1)) + .sum(); let offset: isize = offsets .iter() @@ -2130,7 +2140,7 @@ impl EmitterWriter { } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] enum DisplaySuggestion { Underline, Diff, diff --git a/src/test/ui/rust-2021/reserved-prefixes-migration.stderr b/src/test/ui/rust-2021/reserved-prefixes-migration.stderr index 94f9bb57cc8..c6bc082cf18 100644 --- a/src/test/ui/rust-2021/reserved-prefixes-migration.stderr +++ b/src/test/ui/rust-2021/reserved-prefixes-migration.stderr @@ -14,7 +14,7 @@ LL | #![warn(rust_2021_prefixes_incompatible_syntax)] help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 | LL | m2!(z "hey"); - | + | + warning: prefix `prefix` is unknown --> $DIR/reserved-prefixes-migration.rs:19:9 @@ -27,7 +27,7 @@ LL | m2!(prefix"hey"); help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 | LL | m2!(prefix "hey"); - | + | + warning: prefix `hey` is unknown --> $DIR/reserved-prefixes-migration.rs:22:9 @@ -40,7 +40,7 @@ LL | m3!(hey#123); help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 | LL | m3!(hey #123); - | + | + warning: prefix `hey` is unknown --> $DIR/reserved-prefixes-migration.rs:25:9 @@ -53,7 +53,7 @@ LL | m3!(hey#hey); help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 | LL | m3!(hey #hey); - | + | + warning: prefix `kind` is unknown --> $DIR/reserved-prefixes-migration.rs:35:14 @@ -66,7 +66,7 @@ LL | #name = #kind#value help: insert whitespace here to avoid this being parsed as a prefix in Rust 2021 | LL | #name = #kind #value - | + | + warning: 5 warnings emitted diff --git a/src/test/ui/rust-2021/reserved-prefixes.stderr b/src/test/ui/rust-2021/reserved-prefixes.stderr index fcda5fcac5b..807d6d98bd3 100644 --- a/src/test/ui/rust-2021/reserved-prefixes.stderr +++ b/src/test/ui/rust-2021/reserved-prefixes.stderr @@ -8,7 +8,7 @@ LL | demo3!(foo#bar); help: consider inserting whitespace here | LL | demo3!(foo #bar); - | + | + error: prefix `foo` is unknown --> $DIR/reserved-prefixes.rs:17:12 @@ -20,7 +20,7 @@ LL | demo2!(foo"bar"); help: consider inserting whitespace here | LL | demo2!(foo "bar"); - | + | + error: prefix `foo` is unknown --> $DIR/reserved-prefixes.rs:18:12 @@ -32,7 +32,7 @@ LL | demo2!(foo'b'); help: consider inserting whitespace here | LL | demo2!(foo 'b'); - | + | + error: prefix `foo` is unknown --> $DIR/reserved-prefixes.rs:20:12 @@ -44,7 +44,7 @@ LL | demo2!(foo'b); help: consider inserting whitespace here | LL | demo2!(foo 'b); - | + | + error: prefix `foo` is unknown --> $DIR/reserved-prefixes.rs:21:12 @@ -56,7 +56,7 @@ LL | demo3!(foo# bar); help: consider inserting whitespace here | LL | demo3!(foo # bar); - | + | + error: prefix `foo` is unknown --> $DIR/reserved-prefixes.rs:22:12 @@ -68,7 +68,7 @@ LL | demo4!(foo#! bar); help: consider inserting whitespace here | LL | demo4!(foo #! bar); - | + | + error: prefix `foo` is unknown --> $DIR/reserved-prefixes.rs:23:12 @@ -80,7 +80,7 @@ LL | demo4!(foo## bar); help: consider inserting whitespace here | LL | demo4!(foo ## bar); - | + | + error: prefix `foo` is unknown --> $DIR/reserved-prefixes.rs:25:12 @@ -92,7 +92,7 @@ LL | demo4!(foo#bar#); help: consider inserting whitespace here | LL | demo4!(foo #bar#); - | + | + error: prefix `bar` is unknown --> $DIR/reserved-prefixes.rs:25:16 @@ -104,7 +104,7 @@ LL | demo4!(foo#bar#); help: consider inserting whitespace here | LL | demo4!(foo#bar #); - | + | + error: aborting due to 9 previous errors -- cgit 1.4.1-3-g733a5 From cd962e66cf2c3b48a4a54884c475e27e44ddf260 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 13 Sep 2022 00:44:02 +0000 Subject: Don't render inline suggestions of only spaces --- compiler/rustc_errors/src/emitter.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 016404c5f67..66fbb8f1213 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -268,10 +268,7 @@ pub trait Emitter: Translate { SuggestionStyle::ShowAlways, ].contains(&sugg.style) { - // Don't trim the substitution if it's only whitespace changes - let substitution = &sugg.substitutions[0].parts[0].snippet; - let substitution = - if substitution.trim().is_empty() { substitution } else { substitution.trim() }; + let substitution = &sugg.substitutions[0].parts[0].snippet.trim(); let msg = if substitution.is_empty() || sugg.style.hide_inline() { // This substitution is only removal OR we explicitly don't want to show the // code inline (`hide_inline`). Therefore, we don't show the substitution. -- cgit 1.4.1-3-g733a5 From eb19a8a6208d992d6d4e661be8fa80c1eeab01f6 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 22 Jul 2022 16:48:36 +0000 Subject: Compute `lint_levels` by definition --- compiler/rustc_errors/src/diagnostic.rs | 5 +- compiler/rustc_errors/src/lib.rs | 2 +- compiler/rustc_lint/src/context.rs | 2 +- compiler/rustc_lint/src/early.rs | 1 + compiler/rustc_lint/src/expect.rs | 4 +- compiler/rustc_lint/src/levels.rs | 588 +++++++++++---------- compiler/rustc_lint_defs/src/lib.rs | 31 +- compiler/rustc_middle/src/lint.rs | 111 +++- compiler/rustc_middle/src/query/mod.rs | 10 +- compiler/rustc_middle/src/ty/context.rs | 23 +- compiler/rustc_middle/src/ty/query.rs | 4 +- compiler/rustc_query_impl/src/keys.rs | 17 + .../force_warn_expected_lints_fulfilled.stderr | 16 +- 13 files changed, 482 insertions(+), 332 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index a774b52c8a5..6dfb6b11b16 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -338,9 +338,10 @@ impl Diagnostic { // The lint index inside the attribute is manually transferred here. let lint_index = expectation_id.get_lint_index(); expectation_id.set_lint_index(None); - let mut stable_id = *unstable_to_stable + let mut stable_id = unstable_to_stable .get(&expectation_id) - .expect("each unstable `LintExpectationId` must have a matching stable id"); + .expect("each unstable `LintExpectationId` must have a matching stable id") + .normalize(); stable_id.set_lint_index(lint_index); *expectation_id = stable_id; diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 888128f3f74..1b24f07e689 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1167,7 +1167,7 @@ impl HandlerInner { if let Some(expectation_id) = diagnostic.level.get_expectation_id() { self.suppressed_expected_diag = true; - self.fulfilled_expectations.insert(expectation_id); + self.fulfilled_expectations.insert(expectation_id.normalize()); } if matches!(diagnostic.level, Warning(_)) diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 7ca6ec5d962..34506c84cb8 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -560,7 +560,7 @@ pub struct LateContext<'tcx> { /// Context for lint checking of the AST, after expansion, before lowering to HIR. pub struct EarlyContext<'a> { - pub builder: LintLevelsBuilder<'a>, + pub builder: LintLevelsBuilder<'a, crate::levels::TopDown>, pub buffered: LintBuffer, } diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index 96ecd79a69c..45f54cfed2d 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -59,6 +59,7 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> { F: FnOnce(&mut Self), { let is_crate_node = id == ast::CRATE_NODE_ID; + debug!(?id); let push = self.context.builder.push(attrs, is_crate_node, None); self.check_id(id); diff --git a/compiler/rustc_lint/src/expect.rs b/compiler/rustc_lint/src/expect.rs index 699e8154318..b9a3d52ca9b 100644 --- a/compiler/rustc_lint/src/expect.rs +++ b/compiler/rustc_lint/src/expect.rs @@ -16,8 +16,10 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option) { return; } + let lint_expectations = tcx.lint_expectations(()); let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids(); - let lint_expectations = &tcx.lint_levels(()).lint_expectations; + + tracing::debug!(?lint_expectations, ?fulfilled_expectations); for (id, expectation) in lint_expectations { // This check will always be true, since `lint_expectations` only diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 1e16ac51e9e..1626a4a99df 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -8,7 +8,7 @@ use rustc_hir as hir; use rustc_hir::{intravisit, HirId}; use rustc_middle::hir::nested_filter; use rustc_middle::lint::{ - struct_lint_level, LevelAndSource, LintExpectation, LintLevelMap, LintLevelSets, + struct_lint_level, LevelAndSource, LintExpectation, LintLevelQueryMap, LintLevelSets, LintLevelSource, LintSet, LintStackIndex, COMMAND_LINE, }; use rustc_middle::ty::query::Providers; @@ -27,35 +27,199 @@ use crate::errors::{ UnknownToolInScopedLint, }; -fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap { +fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExpectation)> { let store = unerased_lint_store(tcx); - let levels = - LintLevelsBuilder::new(tcx.sess, false, &store, &tcx.resolutions(()).registered_tools); - let mut builder = LintLevelMapBuilder { levels, tcx }; - let krate = tcx.hir().krate(); - builder.levels.id_to_set.reserve(krate.owners.len() + 1); + let mut builder = LintLevelsBuilder { + sess: tcx.sess, + provider: QueryMapExpectationsWrapper { + map: LintLevelQueryMap { tcx, cur: hir::CRATE_HIR_ID, specs: FxHashMap::default() }, + expectations: Vec::new(), + unstable_to_stable_ids: FxHashMap::default(), + }, + warn_about_weird_lints: false, + store, + registered_tools: &tcx.resolutions(()).registered_tools, + }; + + builder.add_command_line(); + builder.add_id(hir::CRATE_HIR_ID); + tcx.hir().walk_toplevel_module(&mut builder); - let push = - builder.levels.push(tcx.hir().attrs(hir::CRATE_HIR_ID), true, Some(hir::CRATE_HIR_ID)); + tcx.sess.diagnostic().update_unstable_expectation_id(&builder.provider.unstable_to_stable_ids); - builder.levels.register_id(hir::CRATE_HIR_ID); - tcx.hir().walk_toplevel_module(&mut builder); - builder.levels.pop(push); + builder.provider.expectations +} + +fn lint_levels_on(tcx: TyCtxt<'_>, hir_id: HirId) -> FxHashMap { + let store = unerased_lint_store(tcx); + + let mut levels = LintLevelsBuilder { + sess: tcx.sess, + provider: LintLevelQueryMap { tcx, cur: hir_id, specs: FxHashMap::default() }, + warn_about_weird_lints: false, + store, + registered_tools: &tcx.resolutions(()).registered_tools, + }; + + let is_crate = hir::CRATE_HIR_ID == hir_id; + if is_crate { + levels.add_command_line(); + } + debug!(?hir_id); + levels.add(tcx.hir().attrs(hir_id), is_crate, Some(hir_id)); - builder.levels.update_unstable_expectation_ids(); - builder.levels.build_map() + levels.provider.specs } -pub struct LintLevelsBuilder<'s> { - sess: &'s Session, - lint_expectations: Vec<(LintExpectationId, LintExpectation)>, - /// Each expectation has a stable and an unstable identifier. This map - /// is used to map from unstable to stable [`LintExpectationId`]s. - expectation_id_map: FxHashMap, +pub struct TopDown { sets: LintLevelSets, - id_to_set: FxHashMap, cur: LintStackIndex, +} + +pub struct QueryMapExpectationsWrapper<'tcx> { + map: LintLevelQueryMap<'tcx>, + expectations: Vec<(LintExpectationId, LintExpectation)>, + unstable_to_stable_ids: FxHashMap, +} + +pub trait LintLevelsProvider { + fn current_specs(&self) -> &FxHashMap; + fn current_specs_mut(&mut self) -> &mut FxHashMap; + fn get_lint_level(&self, lint: &'static Lint, sess: &Session) -> LevelAndSource; + fn push_expectation(&mut self, _id: LintExpectationId, _expectation: LintExpectation) {} +} + +impl LintLevelsProvider for TopDown { + fn current_specs(&self) -> &FxHashMap { + &self.sets.list[self.cur].specs + } + + fn current_specs_mut(&mut self) -> &mut FxHashMap { + &mut self.sets.list[self.cur].specs + } + + fn get_lint_level(&self, lint: &'static Lint, sess: &Session) -> LevelAndSource { + self.sets.get_lint_level(lint, self.cur, Some(self.current_specs()), sess) + } +} + +impl LintLevelsProvider for LintLevelQueryMap<'_> { + fn current_specs(&self) -> &FxHashMap { + &self.specs + } + fn current_specs_mut(&mut self) -> &mut FxHashMap { + &mut self.specs + } + fn get_lint_level(&self, lint: &'static Lint, _: &Session) -> LevelAndSource { + self.lint_level(lint) + } +} + +impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> { + fn current_specs(&self) -> &FxHashMap { + &self.map.specs + } + fn current_specs_mut(&mut self) -> &mut FxHashMap { + self.map.specs.clear(); + &mut self.map.specs + } + fn get_lint_level(&self, lint: &'static Lint, _: &Session) -> LevelAndSource { + self.map.lint_level(lint) + } + fn push_expectation(&mut self, id: LintExpectationId, expectation: LintExpectation) { + let LintExpectationId::Stable { attr_id: Some(attr_id), hir_id, attr_index, .. } = id else { bug!("unstable expectation id should already be mapped") }; + let key = LintExpectationId::Unstable { attr_id, lint_index: None }; + + if !self.unstable_to_stable_ids.contains_key(&key) { + self.unstable_to_stable_ids.insert( + key, + LintExpectationId::Stable { hir_id, attr_index, lint_index: None, attr_id: None }, + ); + } + + self.expectations.push((id.normalize(), expectation)); + } +} + +impl<'tcx> LintLevelsBuilder<'_, QueryMapExpectationsWrapper<'tcx>> { + fn add_id(&mut self, hir_id: HirId) { + self.add( + self.provider.map.tcx.hir().attrs(hir_id), + hir_id == hir::CRATE_HIR_ID, + Some(hir_id), + ); + } +} + +impl<'tcx> intravisit::Visitor<'tcx> for LintLevelsBuilder<'_, QueryMapExpectationsWrapper<'tcx>> { + type NestedFilter = nested_filter::All; + + fn nested_visit_map(&mut self) -> Self::Map { + self.provider.map.tcx.hir() + } + + fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) { + self.add_id(param.hir_id); + intravisit::walk_param(self, param); + } + + fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) { + self.add_id(it.hir_id()); + intravisit::walk_item(self, it); + } + + fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) { + self.add_id(it.hir_id()); + intravisit::walk_foreign_item(self, it); + } + + fn visit_stmt(&mut self, e: &'tcx hir::Stmt<'tcx>) { + // We will call `add_id` when we walk + // the `StmtKind`. The outer statement itself doesn't + // define the lint levels. + intravisit::walk_stmt(self, e); + } + + fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) { + self.add_id(e.hir_id); + intravisit::walk_expr(self, e); + } + + fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) { + self.add_id(s.hir_id); + intravisit::walk_field_def(self, s); + } + + fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) { + self.add_id(v.id); + intravisit::walk_variant(self, v); + } + + fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) { + self.add_id(l.hir_id); + intravisit::walk_local(self, l); + } + + fn visit_arm(&mut self, a: &'tcx hir::Arm<'tcx>) { + self.add_id(a.hir_id); + intravisit::walk_arm(self, a); + } + + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { + self.add_id(trait_item.hir_id()); + intravisit::walk_trait_item(self, trait_item); + } + + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { + self.add_id(impl_item.hir_id()); + intravisit::walk_impl_item(self, impl_item); + } +} + +pub struct LintLevelsBuilder<'s, P> { + sess: &'s Session, + provider: P, warn_about_weird_lints: bool, store: &'s LintStore, registered_tools: &'s RegisteredTools, @@ -66,7 +230,7 @@ pub struct BuilderPush { pub changed: bool, } -impl<'s> LintLevelsBuilder<'s> { +impl<'s> LintLevelsBuilder<'s, TopDown> { pub fn new( sess: &'s Session, warn_about_weird_lints: bool, @@ -75,20 +239,66 @@ impl<'s> LintLevelsBuilder<'s> { ) -> Self { let mut builder = LintLevelsBuilder { sess, - lint_expectations: Default::default(), - expectation_id_map: Default::default(), - sets: LintLevelSets::new(), - cur: COMMAND_LINE, - id_to_set: Default::default(), + provider: TopDown { sets: LintLevelSets::new(), cur: COMMAND_LINE }, warn_about_weird_lints, store, registered_tools, }; - builder.process_command_line(sess, store); - assert_eq!(builder.sets.list.len(), 1); + builder.process_command_line(); + assert_eq!(builder.provider.sets.list.len(), 1); builder } + fn process_command_line(&mut self) { + self.provider.cur = self + .provider + .sets + .list + .push(LintSet { specs: FxHashMap::default(), parent: COMMAND_LINE }); + self.add_command_line(); + } + + /// Pushes a list of AST lint attributes onto this context. + /// + /// This function will return a `BuilderPush` object which should be passed + /// to `pop` when this scope for the attributes provided is exited. + /// + /// This function will perform a number of tasks: + /// + /// * It'll validate all lint-related attributes in `attrs` + /// * It'll mark all lint-related attributes as used + /// * Lint levels will be updated based on the attributes provided + /// * Lint attributes are validated, e.g., a `#[forbid]` can't be switched to + /// `#[allow]` + /// + /// Don't forget to call `pop`! + pub(crate) fn push( + &mut self, + attrs: &[ast::Attribute], + is_crate_node: bool, + source_hir_id: Option, + ) -> BuilderPush { + let prev = self.provider.cur; + self.provider.cur = + self.provider.sets.list.push(LintSet { specs: FxHashMap::default(), parent: prev }); + + self.add(attrs, is_crate_node, source_hir_id); + + if self.provider.current_specs().is_empty() { + self.provider.sets.list.pop(); + self.provider.cur = prev; + } + + BuilderPush { prev, changed: prev != self.provider.cur } + } + + /// Called after `push` when the scope of a set of attributes are exited. + pub fn pop(&mut self, push: BuilderPush) { + self.provider.cur = push.prev; + } +} + +impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { pub(crate) fn sess(&self) -> &Session { self.sess } @@ -98,24 +308,20 @@ impl<'s> LintLevelsBuilder<'s> { } fn current_specs(&self) -> &FxHashMap { - &self.sets.list[self.cur].specs + self.provider.current_specs() } fn current_specs_mut(&mut self) -> &mut FxHashMap { - &mut self.sets.list[self.cur].specs + self.provider.current_specs_mut() } - fn process_command_line(&mut self, sess: &Session, store: &LintStore) { - self.sets.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid); - - self.cur = - self.sets.list.push(LintSet { specs: FxHashMap::default(), parent: COMMAND_LINE }); - for &(ref lint_name, level) in &sess.opts.lint_opts { - store.check_lint_name_cmdline(sess, &lint_name, level, self.registered_tools); + fn add_command_line(&mut self) { + for &(ref lint_name, level) in &self.sess.opts.lint_opts { + self.store.check_lint_name_cmdline(self.sess, &lint_name, level, self.registered_tools); let orig_level = level; let lint_flag_val = Symbol::intern(lint_name); - let Ok(ids) = store.find_lints(&lint_name) else { + let Ok(ids) = self.store.find_lints(&lint_name) else { // errors handled in check_lint_name_cmdline above continue }; @@ -138,9 +344,11 @@ impl<'s> LintLevelsBuilder<'s> { /// Attempts to insert the `id` to `level_src` map entry. If unsuccessful /// (e.g. if a forbid was already inserted on the same scope), then emits a /// diagnostic with no change to `specs`. - fn insert_spec(&mut self, id: LintId, (level, src): LevelAndSource) { - let (old_level, old_src) = - self.sets.get_lint_level(id.lint, self.cur, Some(self.current_specs()), &self.sess); + fn insert_spec(&mut self, id: LintId, (mut level, src): LevelAndSource) { + let (old_level, old_src) = self.provider.get_lint_level(id.lint, &self.sess); + if let Level::Expect(id) = &mut level && let LintExpectationId::Stable { .. } = id { + *id = id.normalize(); + } // Setting to a non-forbid level is an error if the lint previously had // a forbid level. Note that this is not necessarily true even with a // `#[forbid(..)]` attribute present, as that is overridden by `--cap-lints`. @@ -158,7 +366,7 @@ impl<'s> LintLevelsBuilder<'s> { let id_name = id.lint.name_lower(); let fcw_warning = match old_src { LintLevelSource::Default => false, - LintLevelSource::Node(symbol, _, _) => self.store.is_lint_group(symbol), + LintLevelSource::Node { name, .. } => self.store.is_lint_group(name), LintLevelSource::CommandLine(symbol, _) => self.store.is_lint_group(symbol), }; debug!( @@ -178,8 +386,8 @@ impl<'s> LintLevelsBuilder<'s> { id.to_string() )); } - LintLevelSource::Node(_, forbid_source_span, reason) => { - diag.span_label(forbid_source_span, "`forbid` level set here"); + LintLevelSource::Node { span, reason, .. } => { + diag.span_label(span, "`forbid` level set here"); if let Some(rationale) = reason { diag.note(rationale.as_str()); } @@ -199,11 +407,8 @@ impl<'s> LintLevelsBuilder<'s> { LintLevelSource::Default => { OverruledAttributeSub::DefaultSource { id: id.to_string() } } - LintLevelSource::Node(_, forbid_source_span, reason) => { - OverruledAttributeSub::NodeSource { - span: forbid_source_span, - reason, - } + LintLevelSource::Node { span, reason, .. } => { + OverruledAttributeSub::NodeSource { span, reason } } LintLevelSource::CommandLine(_, _) => { OverruledAttributeSub::CommandLineSource @@ -256,29 +461,7 @@ impl<'s> LintLevelsBuilder<'s> { }; } - /// Pushes a list of AST lint attributes onto this context. - /// - /// This function will return a `BuilderPush` object which should be passed - /// to `pop` when this scope for the attributes provided is exited. - /// - /// This function will perform a number of tasks: - /// - /// * It'll validate all lint-related attributes in `attrs` - /// * It'll mark all lint-related attributes as used - /// * Lint levels will be updated based on the attributes provided - /// * Lint attributes are validated, e.g., a `#[forbid]` can't be switched to - /// `#[allow]` - /// - /// Don't forget to call `pop`! - pub(crate) fn push( - &mut self, - attrs: &[ast::Attribute], - is_crate_node: bool, - source_hir_id: Option, - ) -> BuilderPush { - let prev = self.cur; - self.cur = self.sets.list.push(LintSet { specs: FxHashMap::default(), parent: prev }); - + fn add(&mut self, attrs: &[ast::Attribute], is_crate_node: bool, source_hir_id: Option) { let sess = self.sess; for (attr_index, attr) in attrs.iter().enumerate() { if attr.has_name(sym::automatically_derived) { @@ -293,7 +476,17 @@ impl<'s> LintLevelsBuilder<'s> { None => continue, // This is the only lint level with a `LintExpectationId` that can be created from an attribute Some(Level::Expect(unstable_id)) if let Some(hir_id) = source_hir_id => { - let stable_id = self.create_stable_id(unstable_id, hir_id, attr_index); + let LintExpectationId::Unstable { attr_id, lint_index } = unstable_id + else { bug!("stable id Level::from_attr") }; + + let stable_id = LintExpectationId::Stable { + hir_id, + attr_index: attr_index.try_into().unwrap(), + lint_index, + // we pass the previous unstable attr_id such that we can trace the ast id when building a map + // to go from unstable to stable id. + attr_id: Some(attr_id), + }; Level::Expect(stable_id) } @@ -408,7 +601,7 @@ impl<'s> LintLevelsBuilder<'s> { [lint] => *lint == LintId::of(UNFULFILLED_LINT_EXPECTATIONS), _ => false, }; - self.lint_expectations.push(( + self.provider.push_expectation( expect_id, LintExpectation::new( reason, @@ -416,13 +609,20 @@ impl<'s> LintLevelsBuilder<'s> { is_unfulfilled_lint_expectations, tool_name, ), - )); + ); } - let src = LintLevelSource::Node( - meta_item.path.segments.last().expect("empty lint name").ident.name, - sp, + let src = LintLevelSource::Node { + name: meta_item + .path + .segments + .last() + .expect("empty lint name") + .ident + .name, + span: sp, reason, - ); + tool: tool_name, + }; for &id in *ids { if self.check_gated_lint(id, attr.span) { self.insert_spec(id, (level, src)); @@ -435,31 +635,27 @@ impl<'s> LintLevelsBuilder<'s> { Ok(ids) => { let complete_name = &format!("{}::{}", tool_ident.unwrap().name, name); - let src = LintLevelSource::Node( - Symbol::intern(complete_name), - sp, + let src = LintLevelSource::Node { + name: Symbol::intern(complete_name), + span: sp, reason, - ); + tool: tool_name, + }; for &id in ids { if self.check_gated_lint(id, attr.span) { self.insert_spec(id, (level, src)); } } if let Level::Expect(expect_id) = level { - self.lint_expectations.push(( + self.provider.push_expectation( expect_id, LintExpectation::new(reason, sp, false, tool_name), - )); + ); } } Err((Some(ids), ref new_lint_name)) => { let lint = builtin::RENAMED_AND_REMOVED_LINTS; - let (lvl, src) = self.sets.get_lint_level( - lint, - self.cur, - Some(self.current_specs()), - &sess, - ); + let (lvl, src) = self.provider.get_lint_level(lint, &sess); struct_lint_level( self.sess, lint, @@ -483,19 +679,20 @@ impl<'s> LintLevelsBuilder<'s> { }, ); - let src = LintLevelSource::Node( - Symbol::intern(&new_lint_name), - sp, + let src = LintLevelSource::Node { + name: Symbol::intern(&new_lint_name), + span: sp, reason, - ); + tool: tool_name, + }; for id in ids { self.insert_spec(*id, (level, src)); } if let Level::Expect(expect_id) = level { - self.lint_expectations.push(( + self.provider.push_expectation( expect_id, LintExpectation::new(reason, sp, false, tool_name), - )); + ); } } Err((None, _)) => { @@ -521,12 +718,7 @@ impl<'s> LintLevelsBuilder<'s> { CheckLintNameResult::Warning(msg, renamed) => { let lint = builtin::RENAMED_AND_REMOVED_LINTS; - let (renamed_lint_level, src) = self.sets.get_lint_level( - lint, - self.cur, - Some(self.current_specs()), - &sess, - ); + let (renamed_lint_level, src) = self.provider.get_lint_level(lint, &sess); struct_lint_level( self.sess, lint, @@ -549,12 +741,7 @@ impl<'s> LintLevelsBuilder<'s> { } CheckLintNameResult::NoLint(suggestion) => { let lint = builtin::UNKNOWN_LINTS; - let (level, src) = self.sets.get_lint_level( - lint, - self.cur, - Some(self.current_specs()), - self.sess, - ); + let (level, src) = self.provider.get_lint_level(lint, self.sess); struct_lint_level(self.sess, lint, level, src, Some(sp.into()), |lint| { let name = if let Some(tool_ident) = tool_ident { format!("{}::{}", tool_ident.name, name) @@ -583,17 +770,22 @@ impl<'s> LintLevelsBuilder<'s> { if let CheckLintNameResult::Ok(ids) = self.store.check_lint_name(&new_name, None, self.registered_tools) { - let src = LintLevelSource::Node(Symbol::intern(&new_name), sp, reason); + let src = LintLevelSource::Node { + name: Symbol::intern(&new_name), + span: sp, + reason, + tool: tool_name, + }; for &id in ids { if self.check_gated_lint(id, attr.span) { self.insert_spec(id, (level, src)); } } if let Level::Expect(expect_id) = level { - self.lint_expectations.push(( + self.provider.push_expectation( expect_id, LintExpectation::new(reason, sp, false, tool_name), - )); + ); } } else { panic!("renamed lint does not exist: {}", new_name); @@ -608,13 +800,12 @@ impl<'s> LintLevelsBuilder<'s> { continue; } - let LintLevelSource::Node(lint_attr_name, lint_attr_span, _) = *src else { + let LintLevelSource::Node { name: lint_attr_name, span: lint_attr_span, .. } = *src else { continue }; let lint = builtin::UNUSED_ATTRIBUTES; - let (lint_level, lint_src) = - self.sets.get_lint_level(lint, self.cur, Some(self.current_specs()), self.sess); + let (lint_level, lint_src) = self.provider.get_lint_level(lint, &self.sess); struct_lint_level( self.sess, lint, @@ -634,27 +825,6 @@ impl<'s> LintLevelsBuilder<'s> { break; } } - - if self.current_specs().is_empty() { - self.sets.list.pop(); - self.cur = prev; - } - - BuilderPush { prev, changed: prev != self.cur } - } - - fn create_stable_id( - &mut self, - unstable_id: LintExpectationId, - hir_id: HirId, - attr_index: usize, - ) -> LintExpectationId { - let stable_id = - LintExpectationId::Stable { hir_id, attr_index: attr_index as u16, lint_index: None }; - - self.expectation_id_map.insert(unstable_id, stable_id); - - stable_id } /// Checks if the lint is gated on a feature that is not enabled. @@ -678,14 +848,9 @@ impl<'s> LintLevelsBuilder<'s> { true } - /// Called after `push` when the scope of a set of attributes are exited. - pub fn pop(&mut self, push: BuilderPush) { - self.cur = push.prev; - } - /// Find the lint level for a lint. - pub fn lint_level(&self, lint: &'static Lint) -> (Level, LintLevelSource) { - self.sets.get_lint_level(lint, self.cur, None, self.sess) + pub fn lint_level(&self, lint: &'static Lint) -> LevelAndSource { + self.provider.get_lint_level(lint, self.sess) } /// Used to emit a lint-related diagnostic based on the current state of @@ -699,141 +864,8 @@ impl<'s> LintLevelsBuilder<'s> { let (level, src) = self.lint_level(lint); struct_lint_level(self.sess, lint, level, src, span, decorate) } - - /// Registers the ID provided with the current set of lints stored in - /// this context. - pub fn register_id(&mut self, id: HirId) { - self.id_to_set.insert(id, self.cur); - } - - fn update_unstable_expectation_ids(&self) { - self.sess.diagnostic().update_unstable_expectation_id(&self.expectation_id_map); - } - - pub fn build_map(self) -> LintLevelMap { - LintLevelMap { - sets: self.sets, - id_to_set: self.id_to_set, - lint_expectations: self.lint_expectations, - } - } -} - -struct LintLevelMapBuilder<'tcx> { - levels: LintLevelsBuilder<'tcx>, - tcx: TyCtxt<'tcx>, -} - -impl LintLevelMapBuilder<'_> { - fn with_lint_attrs(&mut self, id: hir::HirId, f: F) - where - F: FnOnce(&mut Self), - { - let is_crate_hir = id == hir::CRATE_HIR_ID; - let attrs = self.tcx.hir().attrs(id); - let push = self.levels.push(attrs, is_crate_hir, Some(id)); - - if push.changed { - self.levels.register_id(id); - } - f(self); - self.levels.pop(push); - } -} - -impl<'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'tcx> { - type NestedFilter = nested_filter::All; - - fn nested_visit_map(&mut self) -> Self::Map { - self.tcx.hir() - } - - fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) { - self.with_lint_attrs(param.hir_id, |builder| { - intravisit::walk_param(builder, param); - }); - } - - fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) { - self.with_lint_attrs(it.hir_id(), |builder| { - intravisit::walk_item(builder, it); - }); - } - - fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) { - self.with_lint_attrs(it.hir_id(), |builder| { - intravisit::walk_foreign_item(builder, it); - }) - } - - fn visit_stmt(&mut self, e: &'tcx hir::Stmt<'tcx>) { - // We will call `with_lint_attrs` when we walk - // the `StmtKind`. The outer statement itself doesn't - // define the lint levels. - intravisit::walk_stmt(self, e); - } - - fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) { - self.with_lint_attrs(e.hir_id, |builder| { - intravisit::walk_expr(builder, e); - }) - } - - fn visit_expr_field(&mut self, field: &'tcx hir::ExprField<'tcx>) { - self.with_lint_attrs(field.hir_id, |builder| { - intravisit::walk_expr_field(builder, field); - }) - } - - fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) { - self.with_lint_attrs(s.hir_id, |builder| { - intravisit::walk_field_def(builder, s); - }) - } - - fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) { - self.with_lint_attrs(v.id, |builder| { - intravisit::walk_variant(builder, v); - }) - } - - fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) { - self.with_lint_attrs(l.hir_id, |builder| { - intravisit::walk_local(builder, l); - }) - } - - fn visit_arm(&mut self, a: &'tcx hir::Arm<'tcx>) { - self.with_lint_attrs(a.hir_id, |builder| { - intravisit::walk_arm(builder, a); - }) - } - - fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { - self.with_lint_attrs(trait_item.hir_id(), |builder| { - intravisit::walk_trait_item(builder, trait_item); - }); - } - - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { - self.with_lint_attrs(impl_item.hir_id(), |builder| { - intravisit::walk_impl_item(builder, impl_item); - }); - } - - fn visit_pat_field(&mut self, field: &'tcx hir::PatField<'tcx>) { - self.with_lint_attrs(field.hir_id, |builder| { - intravisit::walk_pat_field(builder, field); - }) - } - - fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) { - self.with_lint_attrs(p.hir_id, |builder| { - intravisit::walk_generic_param(builder, p); - }); - } } pub fn provide(providers: &mut Providers) { - providers.lint_levels = lint_levels; + *providers = Providers { lint_levels_on, lint_expectations, ..*providers }; } diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 11b2d057a07..cbe7afc8e55 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -92,7 +92,7 @@ pub enum LintExpectationId { /// stable and can be cached. The additional index ensures that nodes with /// several expectations can correctly match diagnostics to the individual /// expectation. - Stable { hir_id: HirId, attr_index: u16, lint_index: Option }, + Stable { hir_id: HirId, attr_index: u16, lint_index: Option, attr_id: Option }, } impl LintExpectationId { @@ -116,13 +116,31 @@ impl LintExpectationId { *lint_index = new_lint_index } + + /// Prepares the id for hashing. Removes references to the ast. + /// Should only be called when the id is stable. + pub fn normalize(self) -> Self { + match self { + Self::Stable { hir_id, attr_index, lint_index, .. } => { + Self::Stable { hir_id, attr_index, lint_index, attr_id: None } + } + Self::Unstable { .. } => { + unreachable!("`normalize` called when `ExpectationId` is unstable") + } + } + } } impl HashStable for LintExpectationId { #[inline] fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { match self { - LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => { + LintExpectationId::Stable { + hir_id, + attr_index, + lint_index: Some(lint_index), + attr_id: _, + } => { hir_id.hash_stable(hcx, hasher); attr_index.hash_stable(hcx, hasher); lint_index.hash_stable(hcx, hasher); @@ -142,9 +160,12 @@ impl ToStableHashKey for LintExpectation #[inline] fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType { match self { - LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => { - (*hir_id, *attr_index, *lint_index) - } + LintExpectationId::Stable { + hir_id, + attr_index, + lint_index: Some(lint_index), + attr_id: _, + } => (*hir_id, *attr_index, *lint_index), _ => { unreachable!("HashStable should only be called for a filled `LintExpectationId`") } diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 2f45222de47..c659e677fa0 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -15,6 +15,8 @@ use rustc_span::hygiene::MacroKind; use rustc_span::source_map::{DesugaringKind, ExpnKind}; use rustc_span::{symbol, Span, Symbol, DUMMY_SP}; +use crate::ty::TyCtxt; + /// How a lint level was set. #[derive(Clone, Copy, PartialEq, Eq, HashStable, Debug)] pub enum LintLevelSource { @@ -23,7 +25,14 @@ pub enum LintLevelSource { Default, /// Lint level was set by an attribute. - Node(Symbol, Span, Option /* RFC 2383 reason */), + Node { + name: Symbol, + span: Span, + /// RFC 2383 reason + reason: Option, + /// The lint tool. (e.g. rustdoc, clippy) + tool: Option, + }, /// Lint level was set by a command-line flag. /// The provided `Level` is the level specified on the command line. @@ -35,7 +44,7 @@ impl LintLevelSource { pub fn name(&self) -> Symbol { match *self { LintLevelSource::Default => symbol::kw::Default, - LintLevelSource::Node(name, _, _) => name, + LintLevelSource::Node { name, .. } => name, LintLevelSource::CommandLine(name, _) => name, } } @@ -43,7 +52,7 @@ impl LintLevelSource { pub fn span(&self) -> Span { match *self { LintLevelSource::Default => DUMMY_SP, - LintLevelSource::Node(_, span, _) => span, + LintLevelSource::Node { span, .. } => span, LintLevelSource::CommandLine(_, _) => DUMMY_SP, } } @@ -55,7 +64,6 @@ pub type LevelAndSource = (Level, LintLevelSource); #[derive(Debug, HashStable)] pub struct LintLevelSets { pub list: IndexVec, - pub lint_cap: Level, } rustc_index::newtype_index! { @@ -76,18 +84,16 @@ pub struct LintSet { impl LintLevelSets { pub fn new() -> Self { - LintLevelSets { list: IndexVec::new(), lint_cap: Level::Forbid } + LintLevelSets { list: IndexVec::new() } } - pub fn get_lint_level( - &self, - lint: &'static Lint, - idx: LintStackIndex, - aux: Option<&FxHashMap>, + pub fn actual_level( + level: Option, + src: &mut LintLevelSource, sess: &Session, - ) -> LevelAndSource { - let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux); - + lint: &'static Lint, + get_lint_id_level: impl FnOnce(LintId) -> (Option, LintLevelSource), + ) -> Level { // If `level` is none then we actually assume the default level for this // lint. let mut level = level.unwrap_or_else(|| lint.default_level(sess.edition())); @@ -101,12 +107,11 @@ impl LintLevelSets { // and so if we turned that into an error, it'd defeat the purpose of the // future compatibility warning. if level == Level::Warn && LintId::of(lint) != LintId::of(FORBIDDEN_LINT_GROUPS) { - let (warnings_level, warnings_src) = - self.get_lint_id_level(LintId::of(builtin::WARNINGS), idx, aux); + let (warnings_level, warnings_src) = get_lint_id_level(LintId::of(builtin::WARNINGS)); if let Some(configured_warning_level) = warnings_level { if configured_warning_level != Level::Warn { level = configured_warning_level; - src = warnings_src; + *src = warnings_src; } } } @@ -116,7 +121,7 @@ impl LintLevelSets { level = if let LintLevelSource::CommandLine(_, Level::ForceWarn(_)) = src { level } else { - cmp::min(level, self.lint_cap) + cmp::min(level, sess.opts.lint_cap.unwrap_or(Level::Forbid)) }; if let Some(driver_level) = sess.driver_lint_caps.get(&LintId::of(lint)) { @@ -124,6 +129,22 @@ impl LintLevelSets { level = cmp::min(*driver_level, level); } + level + } + + pub fn get_lint_level( + &self, + lint: &'static Lint, + idx: LintStackIndex, + aux: Option<&FxHashMap>, + sess: &Session, + ) -> LevelAndSource { + let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux); + + let level = Self::actual_level(level, &mut src, sess, lint, |id| { + self.get_lint_id_level(id, idx, aux) + }); + (level, src) } @@ -193,6 +214,58 @@ impl<'a> HashStable> for LintLevelMap { hcx.while_hashing_spans(true, |hcx| sets.hash_stable(hcx, hasher)) } } +pub struct LintLevelQueryMap<'tcx> { + pub tcx: TyCtxt<'tcx>, + pub cur: HirId, + pub specs: FxHashMap, +} + +impl<'tcx> LintLevelQueryMap<'tcx> { + pub fn lint_id_level(&self, id: LintId) -> (Option, LintLevelSource) { + Self::get_lint_id_level(id, self.cur, self.tcx, &self.specs) + } + + pub fn lint_level(&self, lint: &'static Lint) -> LevelAndSource { + Self::get_lint_level(LintId::of(lint), self.cur, self.tcx, &self.specs) + } + + pub fn get_lint_id_level( + id: LintId, + cur: HirId, + tcx: TyCtxt<'tcx>, + specs: &FxHashMap, + ) -> (Option, LintLevelSource) { + if let Some(&(level, src)) = specs.get(&id) { + return (Some(level), src); + } + let mut cur = cur; + + loop { + let parent = tcx.hir().get_parent_node(cur); + if cur == parent { + return (None, LintLevelSource::Default); + } + let specs = tcx.lint_levels_on(parent); + if let Some(&(level, src)) = specs.get(&id) { + return (Some(level), src); + } + cur = parent + } + } + + pub fn get_lint_level( + id: LintId, + cur: HirId, + tcx: TyCtxt<'tcx>, + specs: &FxHashMap, + ) -> (Level, LintLevelSource) { + let (level, mut src) = Self::get_lint_id_level(id, cur, tcx, specs); + let level = LintLevelSets::actual_level(level, &mut src, tcx.sess, id.lint, |id| { + Self::get_lint_id_level(id, cur, tcx, specs) + }); + (level, src) + } +} /// This struct represents a lint expectation and holds all required information /// to emit the `unfulfilled_lint_expectations` lint if it is unfulfilled after @@ -261,11 +334,11 @@ pub fn explain_lint_level_source( )); } } - LintLevelSource::Node(lint_attr_name, src, reason) => { + LintLevelSource::Node { name: lint_attr_name, span, reason, .. } => { if let Some(rationale) = reason { err.note(rationale.as_str()); } - err.span_note_once(src, "the lint level is defined here"); + err.span_note_once(span, "the lint level is defined here"); if lint_attr_name.as_str() != name { let level_str = level.as_str(); err.note_once(&format!( diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 9cb19583121..09c336f9e4c 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -273,10 +273,14 @@ rustc_queries! { separate_provide_extern } - query lint_levels(_: ()) -> LintLevelMap { + query lint_levels_on(key: HirId) -> FxHashMap { arena_cache - eval_always - desc { "computing the lint levels for items in this crate" } + desc { |tcx| "looking up lint levels for `{}`", key } + } + + query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> { + arena_cache + desc { "computing `#[expect]`ed lints in this crate" } } query parent_module_from_def_id(key: LocalDefId) -> LocalDefId { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 94eddef944a..4cd9004fa18 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -53,7 +53,7 @@ use rustc_query_system::ich::StableHashingContext; use rustc_serialize::opaque::{FileEncodeResult, FileEncoder}; use rustc_session::config::{CrateType, OutputFilenames}; use rustc_session::cstore::CrateStoreDyn; -use rustc_session::lint::{Level, Lint}; +use rustc_session::lint::{Level, Lint, LintId}; use rustc_session::Limit; use rustc_session::Session; use rustc_span::def_id::{DefPathHash, StableCrateId}; @@ -2832,19 +2832,16 @@ impl<'tcx> TyCtxt<'tcx> { pub fn lint_level_at_node( self, lint: &'static Lint, - mut id: hir::HirId, + id: hir::HirId, ) -> (Level, LintLevelSource) { - let sets = self.lint_levels(()); - loop { - if let Some(pair) = sets.level_and_source(lint, id, self.sess) { - return pair; - } - let next = self.hir().get_parent_node(id); - if next == id { - bug!("lint traversal reached the root of the crate"); - } - id = next; - } + let level_and_src = crate::lint::LintLevelQueryMap::get_lint_level( + LintId::of(lint), + id, + self, + self.lint_levels_on(id), + ); + debug!(?id, ?level_and_src); + level_and_src } /// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`, diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index a300a8df23d..1a1b020905b 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -1,6 +1,6 @@ use crate::dep_graph; use crate::infer::canonical::{self, Canonical}; -use crate::lint::LintLevelMap; +use crate::lint::{LevelAndSource, LintExpectation}; use crate::metadata::ModChild; use crate::middle::codegen_fn_attrs::CodegenFnAttrs; use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; @@ -44,12 +44,14 @@ use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId}; +use rustc_hir::hir_id::HirId; use rustc_hir::lang_items::{LangItem, LanguageItems}; use rustc_hir::{Crate, ItemLocalId, TraitCandidate}; use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec}; use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion}; use rustc_session::cstore::{CrateDepKind, CrateSource}; use rustc_session::cstore::{ExternCrate, ForeignModule, LinkagePreference, NativeLib}; +use rustc_session::lint::{LintExpectationId, LintId}; use rustc_session::utils::NativeLibKind; use rustc_session::Limits; use rustc_span::symbol::Symbol; diff --git a/compiler/rustc_query_impl/src/keys.rs b/compiler/rustc_query_impl/src/keys.rs index 49175e97f41..ea2d10cd14b 100644 --- a/compiler/rustc_query_impl/src/keys.rs +++ b/compiler/rustc_query_impl/src/keys.rs @@ -1,6 +1,7 @@ //! Defines the set of legal keys that can be used in queries. use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; +use rustc_hir::hir_id::HirId; use rustc_middle::infer::canonical::Canonical; use rustc_middle::mir; use rustc_middle::traits; @@ -543,3 +544,19 @@ impl<'tcx> Key for (Ty<'tcx>, ty::ValTree<'tcx>) { DUMMY_SP } } + +impl Key for HirId { + #[inline(always)] + fn query_crate_is_local(&self) -> bool { + true + } + + fn default_span(&self, tcx: TyCtxt<'_>) -> Span { + self.owner.default_span(tcx) + } + + #[inline(always)] + fn key_as_def_id(&self) -> Option { + Some(self.owner.to_def_id()) + } +} diff --git a/src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr b/src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr index 06befcbb511..5942fa8aeb4 100644 --- a/src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr +++ b/src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr @@ -1,11 +1,3 @@ -warning: denote infinite loops with `loop { ... }` - --> $DIR/force_warn_expected_lints_fulfilled.rs:10:5 - | -LL | while true { - | ^^^^^^^^^^ help: use `loop` - | - = note: requested on the command line with `--force-warn while-true` - warning: unused variable: `x` --> $DIR/force_warn_expected_lints_fulfilled.rs:20:9 | @@ -36,5 +28,13 @@ LL | let mut what_does_the_fox_say = "*ding* *deng* *dung*"; | = note: requested on the command line with `--force-warn unused-mut` +warning: denote infinite loops with `loop { ... }` + --> $DIR/force_warn_expected_lints_fulfilled.rs:10:5 + | +LL | while true { + | ^^^^^^^^^^ help: use `loop` + | + = note: requested on the command line with `--force-warn while-true` + warning: 5 warnings emitted -- cgit 1.4.1-3-g733a5 From 173eb6f407438dff732b1636b5134ff220da3f5b Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 27 Feb 2022 07:07:36 +0100 Subject: Only enable the let_else feature on bootstrap On later stages, the feature is already stable. Result of running: rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#" --- compiler/rustc_ast/src/lib.rs | 2 +- compiler/rustc_ast_lowering/src/lib.rs | 2 +- compiler/rustc_ast_passes/src/lib.rs | 2 +- compiler/rustc_attr/src/lib.rs | 2 +- compiler/rustc_borrowck/src/lib.rs | 2 +- compiler/rustc_builtin_macros/src/lib.rs | 2 +- compiler/rustc_codegen_llvm/src/lib.rs | 2 +- compiler/rustc_codegen_ssa/src/lib.rs | 2 +- compiler/rustc_const_eval/src/lib.rs | 2 +- compiler/rustc_data_structures/src/lib.rs | 2 +- compiler/rustc_driver/src/lib.rs | 2 +- compiler/rustc_errors/src/lib.rs | 2 +- compiler/rustc_expand/src/lib.rs | 2 +- compiler/rustc_hir/src/lib.rs | 2 +- compiler/rustc_incremental/src/lib.rs | 2 +- compiler/rustc_index/src/lib.rs | 2 +- compiler/rustc_infer/src/lib.rs | 2 +- compiler/rustc_interface/src/lib.rs | 2 +- compiler/rustc_lint/src/lib.rs | 2 +- compiler/rustc_macros/src/lib.rs | 2 +- compiler/rustc_metadata/src/lib.rs | 2 +- compiler/rustc_middle/src/lib.rs | 2 +- compiler/rustc_mir_build/src/lib.rs | 2 +- compiler/rustc_mir_dataflow/src/lib.rs | 2 +- compiler/rustc_mir_transform/src/lib.rs | 2 +- compiler/rustc_monomorphize/src/lib.rs | 2 +- compiler/rustc_parse/src/lib.rs | 2 +- compiler/rustc_passes/src/lib.rs | 2 +- compiler/rustc_privacy/src/lib.rs | 2 +- compiler/rustc_query_system/src/lib.rs | 2 +- compiler/rustc_resolve/src/lib.rs | 2 +- compiler/rustc_save_analysis/src/lib.rs | 2 +- compiler/rustc_serialize/src/lib.rs | 2 +- compiler/rustc_session/src/lib.rs | 2 +- compiler/rustc_span/src/lib.rs | 2 +- compiler/rustc_target/src/lib.rs | 2 +- compiler/rustc_trait_selection/src/lib.rs | 2 +- compiler/rustc_traits/src/lib.rs | 2 +- compiler/rustc_ty_utils/src/lib.rs | 2 +- compiler/rustc_typeck/src/lib.rs | 2 +- library/alloc/src/lib.rs | 2 +- library/std/src/lib.rs | 2 +- src/librustdoc/lib.rs | 2 +- 43 files changed, 43 insertions(+), 43 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 4d3620ee8b0..bd7a85b07a0 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -15,7 +15,7 @@ #![feature(if_let_guard)] #![cfg_attr(bootstrap, feature(label_break_value))] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(negative_impls)] #![feature(slice_internals)] diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 409ee55268c..9ac09b5c8b3 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -32,7 +32,7 @@ #![feature(box_patterns)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(never_type)] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] diff --git a/compiler/rustc_ast_passes/src/lib.rs b/compiler/rustc_ast_passes/src/lib.rs index af25982e288..8aa9d57f046 100644 --- a/compiler/rustc_ast_passes/src/lib.rs +++ b/compiler/rustc_ast_passes/src/lib.rs @@ -9,7 +9,7 @@ #![feature(if_let_guard)] #![feature(iter_is_partitioned)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![recursion_limit = "256"] #[macro_use] diff --git a/compiler/rustc_attr/src/lib.rs b/compiler/rustc_attr/src/lib.rs index 053f848aacb..52e65a9c774 100644 --- a/compiler/rustc_attr/src/lib.rs +++ b/compiler/rustc_attr/src/lib.rs @@ -5,7 +5,7 @@ //! to this crate. #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index ec652f85217..86da87d0603 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -3,7 +3,7 @@ #![allow(rustc::potential_query_instability)] #![feature(box_patterns)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(never_type)] #![feature(rustc_attrs)] diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 280fa704511..8aeb3b82a9c 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -9,7 +9,7 @@ #![feature(if_let_guard)] #![feature(is_sorted)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(proc_macro_internals)] #![feature(proc_macro_quote)] #![recursion_limit = "256"] diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index 334425ae55b..42c65e04e3b 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -7,7 +7,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(hash_raw_entry)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(extern_types)] #![feature(once_cell)] #![feature(iter_intersperse)] diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 4ea75dba471..e736b2aba9c 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -1,7 +1,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(box_patterns)] #![feature(try_blocks)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![feature(associated_type_bounds)] #![feature(strict_provenance)] diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index 72ac6af685d..9f47d302a0c 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -10,7 +10,7 @@ Rust MIR: a lowered representation of Rust. #![feature(decl_macro)] #![feature(exact_size_is_empty)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(map_try_insert)] #![feature(min_specialization)] #![feature(slice_ptr_get)] diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index a7429ed008f..56f7823efe0 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -13,7 +13,7 @@ #![feature(cell_leak)] #![feature(control_flow_enum)] #![feature(extend_one)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(hash_raw_entry)] #![feature(hasher_prefixfree_extras)] #![feature(maybe_uninit_uninit_array)] diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index d6f51d7eee1..8fb9508194b 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -5,7 +5,7 @@ //! This API is completely unstable and subject to change. #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 1b24f07e689..c3e78209612 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -7,7 +7,7 @@ #![feature(if_let_guard)] #![feature(adt_const_params)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(never_type)] #![feature(result_option_inspect)] #![feature(rustc_attrs)] diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index ac0e200b1b7..ffc9abe64d2 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -3,7 +3,7 @@ #![feature(associated_type_defaults)] #![feature(if_let_guard)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(macro_metavar_expr)] #![feature(proc_macro_diagnostic)] #![feature(proc_macro_internals)] diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index 1b33cb9c2da..946da9265ba 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -5,7 +5,7 @@ #![feature(associated_type_defaults)] #![feature(closure_track_caller)] #![feature(const_btree_new)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![feature(min_specialization)] #![feature(never_type)] diff --git a/compiler/rustc_incremental/src/lib.rs b/compiler/rustc_incremental/src/lib.rs index 1e88e8091c3..2c9e21f769f 100644 --- a/compiler/rustc_incremental/src/lib.rs +++ b/compiler/rustc_incremental/src/lib.rs @@ -2,7 +2,7 @@ #![deny(missing_docs)] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] diff --git a/compiler/rustc_index/src/lib.rs b/compiler/rustc_index/src/lib.rs index aa34673de81..a00d7bd6801 100644 --- a/compiler/rustc_index/src/lib.rs +++ b/compiler/rustc_index/src/lib.rs @@ -3,7 +3,7 @@ #![feature(allow_internal_unstable)] #![feature(bench_black_box)] #![feature(extend_one)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(new_uninit)] #![feature(step_trait)] diff --git a/compiler/rustc_infer/src/lib.rs b/compiler/rustc_infer/src/lib.rs index 931ebca7d01..ef60d2c9188 100644 --- a/compiler/rustc_infer/src/lib.rs +++ b/compiler/rustc_infer/src/lib.rs @@ -19,7 +19,7 @@ #![feature(extend_one)] #![cfg_attr(bootstrap, feature(label_break_value))] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(never_type)] #![feature(try_blocks)] diff --git a/compiler/rustc_interface/src/lib.rs b/compiler/rustc_interface/src/lib.rs index 1a8d619fafb..41cd7b0e9b1 100644 --- a/compiler/rustc_interface/src/lib.rs +++ b/compiler/rustc_interface/src/lib.rs @@ -1,5 +1,5 @@ #![feature(box_patterns)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(internal_output_capture)] #![feature(thread_spawn_unchecked)] #![feature(once_cell)] diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 2a22a6e5be1..c760e435699 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -34,7 +34,7 @@ #![feature(iter_intersperse)] #![feature(iter_order_by)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(never_type)] #![recursion_limit = "256"] diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index 20ee5dfc727..2c027d754da 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -1,5 +1,5 @@ #![feature(allow_internal_unstable)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(never_type)] #![feature(proc_macro_diagnostic)] #![feature(proc_macro_span)] diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index ba6f1e4a3a5..6f5604b7e11 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -5,7 +5,7 @@ #![cfg_attr(bootstrap, feature(generic_associated_types))] #![feature(iter_from_generator)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![feature(proc_macro_internals)] #![feature(macro_metavar_expr)] diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index ea08879cb53..01b9277b983 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -40,7 +40,7 @@ #![feature(new_uninit)] #![feature(once_cell)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(trusted_len)] #![feature(type_alias_impl_trait)] diff --git a/compiler/rustc_mir_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs index 11cd2a9aa4d..0c0a2fe9c9e 100644 --- a/compiler/rustc_mir_build/src/lib.rs +++ b/compiler/rustc_mir_build/src/lib.rs @@ -6,7 +6,7 @@ #![feature(control_flow_enum)] #![feature(if_let_guard)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(once_cell)] #![recursion_limit = "256"] diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs index 62b712f7b8d..b45c32ee986 100644 --- a/compiler/rustc_mir_dataflow/src/lib.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -1,7 +1,7 @@ #![feature(associated_type_defaults)] #![feature(box_patterns)] #![feature(exact_size_is_empty)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(once_cell)] #![feature(stmt_expr_attributes)] diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 162f7d969b1..e6fc8559571 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -1,7 +1,7 @@ #![allow(rustc::potential_query_instability)] #![feature(box_patterns)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(map_try_insert)] #![feature(min_specialization)] #![feature(never_type)] diff --git a/compiler/rustc_monomorphize/src/lib.rs b/compiler/rustc_monomorphize/src/lib.rs index 3afff7bcabf..ba6ce9fd40f 100644 --- a/compiler/rustc_monomorphize/src/lib.rs +++ b/compiler/rustc_monomorphize/src/lib.rs @@ -1,6 +1,6 @@ #![feature(array_windows)] #![feature(control_flow_enum)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] #![deny(rustc::untranslatable_diagnostic)] diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 3c88e1ef377..a37327f4294 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -4,7 +4,7 @@ #![feature(box_patterns)] #![feature(if_let_guard)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(never_type)] #![feature(rustc_attrs)] #![recursion_limit = "256"] diff --git a/compiler/rustc_passes/src/lib.rs b/compiler/rustc_passes/src/lib.rs index 7b2f83958af..39ebb8db21c 100644 --- a/compiler/rustc_passes/src/lib.rs +++ b/compiler/rustc_passes/src/lib.rs @@ -8,7 +8,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(iter_intersperse)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(map_try_insert)] #![feature(min_specialization)] #![feature(try_blocks)] diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 92ef61fe64c..48ab31ab92d 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -1,7 +1,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(associated_type_defaults)] #![feature(control_flow_enum)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(rustc_private)] #![feature(try_blocks)] #![recursion_limit = "256"] diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index 8a88b5c3340..f92c3831f26 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -1,7 +1,7 @@ #![feature(assert_matches)] #![feature(core_intrinsics)] #![feature(hash_raw_entry)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(extern_types)] #![allow(rustc::potential_query_instability)] diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 749a78a7552..54a7f416ce6 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -12,7 +12,7 @@ #![feature(if_let_guard)] #![feature(iter_intersperse)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(never_type)] #![recursion_limit = "256"] #![allow(rustdoc::private_intra_doc_links)] diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index ebe44a56449..ce03c2a8ad0 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -1,6 +1,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(if_let_guard)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] #![feature(never_type)] diff --git a/compiler/rustc_serialize/src/lib.rs b/compiler/rustc_serialize/src/lib.rs index 91f4cfaf5ac..fa9c7bd54c3 100644 --- a/compiler/rustc_serialize/src/lib.rs +++ b/compiler/rustc_serialize/src/lib.rs @@ -14,7 +14,7 @@ Core encoding and decoding interfaces. #![feature(min_specialization)] #![feature(core_intrinsics)] #![feature(maybe_uninit_slice)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(new_uninit)] #![feature(allocator_api)] #![cfg_attr(test, feature(test))] diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index b9b243f6f08..f6bab775e76 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -1,6 +1,6 @@ #![feature(if_let_guard)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(never_type)] #![feature(once_cell)] diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 26b4ebeab1b..ada3bae6150 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -15,7 +15,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(array_windows)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(if_let_guard)] #![feature(negative_impls)] #![feature(min_specialization)] diff --git a/compiler/rustc_target/src/lib.rs b/compiler/rustc_target/src/lib.rs index 9c9e297849e..a7deab9d2ef 100644 --- a/compiler/rustc_target/src/lib.rs +++ b/compiler/rustc_target/src/lib.rs @@ -11,7 +11,7 @@ #![feature(assert_matches)] #![feature(associated_type_bounds)] #![feature(exhaustive_patterns)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(never_type)] #![feature(rustc_attrs)] diff --git a/compiler/rustc_trait_selection/src/lib.rs b/compiler/rustc_trait_selection/src/lib.rs index f039b1fca18..d35f74974fd 100644 --- a/compiler/rustc_trait_selection/src/lib.rs +++ b/compiler/rustc_trait_selection/src/lib.rs @@ -18,7 +18,7 @@ #![feature(hash_drain_filter)] #![cfg_attr(bootstrap, feature(label_break_value))] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(if_let_guard)] #![feature(never_type)] #![feature(type_alias_impl_trait)] diff --git a/compiler/rustc_traits/src/lib.rs b/compiler/rustc_traits/src/lib.rs index 318e76c79f1..2d39e973ed9 100644 --- a/compiler/rustc_traits/src/lib.rs +++ b/compiler/rustc_traits/src/lib.rs @@ -3,7 +3,7 @@ #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![recursion_limit = "256"] #[macro_use] diff --git a/compiler/rustc_ty_utils/src/lib.rs b/compiler/rustc_ty_utils/src/lib.rs index 6931b15b1ba..8524e57cb58 100644 --- a/compiler/rustc_ty_utils/src/lib.rs +++ b/compiler/rustc_ty_utils/src/lib.rs @@ -6,7 +6,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(control_flow_enum)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(never_type)] #![feature(box_patterns)] #![recursion_limit = "256"] diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index ac66819d283..b1ce972e1d6 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -66,7 +66,7 @@ This API is completely unstable and subject to change. #![feature(iter_intersperse)] #![cfg_attr(bootstrap, feature(label_break_value))] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(never_type)] #![feature(once_cell)] diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index e5cf9033c86..8619467c2d9 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -169,7 +169,7 @@ #![cfg_attr(not(test), feature(generator_trait))] #![feature(hashmap_internals)] #![feature(lang_items)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(negative_impls)] #![feature(never_type)] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index f13500de014..bc4f1b27c2a 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -255,7 +255,7 @@ #![cfg_attr(bootstrap, feature(label_break_value))] #![feature(lang_items)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(linkage)] #![feature(link_cfg)] #![feature(min_specialization)] diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index f6c648140b8..14d695582b0 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -9,7 +9,7 @@ #![feature(control_flow_enum)] #![feature(drain_filter)] #![feature(let_chains)] -#![feature(let_else)] +#![cfg_attr(bootstrap, feature(let_else))] #![feature(test)] #![feature(never_type)] #![feature(once_cell)] -- cgit 1.4.1-3-g733a5 From 527292a1a697c8831fc1ec01b1047ecebc10f809 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Fri, 16 Sep 2022 11:24:14 +0900 Subject: do not suggest a placeholder to const and static without a type --- compiler/rustc_errors/src/lib.rs | 4 ++++ compiler/rustc_typeck/src/collect.rs | 8 +++++--- ...ggest-placeholder-to-const-static-without-type.rs | 8 ++++++++ ...t-placeholder-to-const-static-without-type.stderr | 20 ++++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.rs create mode 100644 src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.stderr (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 68abdd0bad1..d89b3da049c 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -637,6 +637,10 @@ impl Handler { inner.steal((span, key)).map(|diag| DiagnosticBuilder::new_diagnostic(self, diag)) } + pub fn has_stashed_diagnostic(&self, span: Span, key: StashKey) -> bool { + self.inner.borrow().stashed_diagnostics.get(&(span, key)).is_some() + } + /// Emit all stashed diagnostics. pub fn emit_stashed_diagnostics(&self) -> Option { self.inner.borrow_mut().emit_stashed_diagnostics() diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 6236ad370df..8f5b4815cf8 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -25,7 +25,7 @@ use rustc_ast::{MetaItemKind, NestedMetaItem}; use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr}; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; -use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed}; +use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind}; use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE}; @@ -852,12 +852,14 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { tcx.ensure().type_of(trait_item_id.def_id); } - hir::TraitItemKind::Const(..) => { + hir::TraitItemKind::Const(hir_ty, _) => { tcx.ensure().type_of(trait_item_id.def_id); // Account for `const C: _;`. let mut visitor = HirPlaceholderCollector::default(); visitor.visit_trait_item(trait_item); - placeholder_type_error(tcx, None, visitor.0, false, None, "constant"); + if !tcx.sess.diagnostic().has_stashed_diagnostic(hir_ty.span, StashKey::ItemNoType) { + placeholder_type_error(tcx, None, visitor.0, false, None, "constant"); + } } hir::TraitItemKind::Type(_, Some(_)) => { diff --git a/src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.rs b/src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.rs new file mode 100644 index 00000000000..97e0b213f2e --- /dev/null +++ b/src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.rs @@ -0,0 +1,8 @@ +trait Foo { + const A; //~ ERROR missing type for `const` item + static B; + //~^ ERROR associated `static` items are not allowed + //~| ERROR missing type for `static` item +} + +fn main() {} diff --git a/src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.stderr b/src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.stderr new file mode 100644 index 00000000000..8982d628561 --- /dev/null +++ b/src/test/ui/typeck/do-not-suggest-placeholder-to-const-static-without-type.stderr @@ -0,0 +1,20 @@ +error: associated `static` items are not allowed + --> $DIR/do-not-suggest-placeholder-to-const-static-without-type.rs:3:5 + | +LL | static B; + | ^^^^^^^^^ + +error: missing type for `const` item + --> $DIR/do-not-suggest-placeholder-to-const-static-without-type.rs:2:12 + | +LL | const A; + | ^ help: provide a type for the item: `: ` + +error: missing type for `static` item + --> $DIR/do-not-suggest-placeholder-to-const-static-without-type.rs:3:13 + | +LL | static B; + | ^ help: provide a type for the item: `: ` + +error: aborting due to 3 previous errors + -- cgit 1.4.1-3-g733a5 From 5b8152807cae152d5c7cfb40615e5a817a6cf750 Mon Sep 17 00:00:00 2001 From: Jhonny Bill Mena Date: Wed, 7 Sep 2022 09:36:08 -0400 Subject: UPDATE - move SessionDiagnostic from rustc_session to rustc_errors --- compiler/rustc_attr/src/session_diagnostics.rs | 2 +- compiler/rustc_errors/src/diagnostic_builder.rs | 9 +++++++++ compiler/rustc_errors/src/lib.rs | 1 + compiler/rustc_expand/src/base.rs | 6 ++++-- .../rustc_infer/src/infer/error_reporting/need_type_info.rs | 2 +- compiler/rustc_lint/src/errors.rs | 4 ++-- compiler/rustc_macros/src/diagnostics/diagnostic.rs | 2 +- compiler/rustc_metadata/src/errors.rs | 4 ++-- compiler/rustc_monomorphize/src/errors.rs | 2 +- compiler/rustc_parse/src/parser/expr.rs | 2 +- compiler/rustc_query_system/src/query/job.rs | 6 ++++-- compiler/rustc_session/src/parse.rs | 3 +-- compiler/rustc_session/src/session.rs | 11 +---------- compiler/rustc_trait_selection/src/errors.rs | 4 ++-- compiler/rustc_typeck/src/errors.rs | 2 +- src/test/ui-fulldeps/internal-lints/diagnostics.rs | 3 +-- 16 files changed, 33 insertions(+), 30 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_attr/src/session_diagnostics.rs b/compiler/rustc_attr/src/session_diagnostics.rs index 085175d4bed..ed8400391c2 100644 --- a/compiler/rustc_attr/src/session_diagnostics.rs +++ b/compiler/rustc_attr/src/session_diagnostics.rs @@ -1,11 +1,11 @@ use std::num::IntErrorKind; use rustc_ast as ast; +use rustc_errors::SessionDiagnostic; use rustc_errors::{ error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, }; use rustc_macros::SessionDiagnostic; -use rustc_session::SessionDiagnostic; use rustc_span::{Span, Symbol}; use crate::UnsupportedLiteralReason; diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index 7e29dc207ac..71e21373d0d 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -13,6 +13,15 @@ use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; use std::thread::panicking; +/// Trait implemented by error types. This should not be implemented manually. Instead, use +/// `#[derive(SessionDiagnostic)]` -- see [rustc_macros::SessionDiagnostic]. +#[rustc_diagnostic_item = "SessionDiagnostic"] +pub trait SessionDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> { + /// Write out as a diagnostic out of `Handler`. + #[must_use] + fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, T>; +} + /// Used for emitting structured error messages and other diagnostic information. /// /// If there is some state in a downstream crate you would like to diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 6f969bfcc53..3549d3c4999 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -60,6 +60,7 @@ mod snippet; mod styled_buffer; pub mod translation; +pub use diagnostic_builder::SessionDiagnostic; pub use snippet::Style; pub type PResult<'a, T> = Result>; diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index e1da3ecdec7..11598ea0fff 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -10,11 +10,13 @@ use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind use rustc_attr::{self as attr, Deprecation, Stability}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::sync::{self, Lrc}; -use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult}; +use rustc_errors::{ + Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult, SessionDiagnostic, +}; use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT; use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics}; use rustc_parse::{self, parser, MACRO_ARGUMENTS}; -use rustc_session::{parse::ParseSess, Limit, Session, SessionDiagnostic}; +use rustc_session::{parse::ParseSess, Limit, Session}; use rustc_span::def_id::{CrateNum, DefId, LocalDefId}; use rustc_span::edition::Edition; use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId}; diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 89a448edc9b..dccd3f3a1cc 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -4,6 +4,7 @@ use crate::errors::{ }; use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::InferCtxt; +use rustc_errors::SessionDiagnostic; use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, IntoDiagnosticArg}; use rustc_hir as hir; use rustc_hir::def::Res; @@ -18,7 +19,6 @@ use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer}; use rustc_middle::ty::{self, DefIdTree, InferConst}; use rustc_middle::ty::{GenericArg, GenericArgKind, SubstsRef}; use rustc_middle::ty::{IsSuggestable, Ty, TyCtxt, TypeckResults}; -use rustc_session::SessionDiagnostic; use rustc_span::symbol::{kw, Ident}; use rustc_span::{BytePos, Span}; use std::borrow::Cow; diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs index 5c183d4091e..ac98948189b 100644 --- a/compiler/rustc_lint/src/errors.rs +++ b/compiler/rustc_lint/src/errors.rs @@ -1,6 +1,6 @@ -use rustc_errors::{fluent, AddSubdiagnostic, ErrorGuaranteed, Handler}; +use rustc_errors::{fluent, AddSubdiagnostic, ErrorGuaranteed, Handler, SessionDiagnostic}; use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; -use rustc_session::{lint::Level, SessionDiagnostic}; +use rustc_session::lint::Level; use rustc_span::{Span, Symbol}; #[derive(SessionDiagnostic)] diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs index cf1c5945529..891b6a118de 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs @@ -82,7 +82,7 @@ impl<'a> SessionDiagnosticDerive<'a> { structure.gen_impl(quote! { gen impl<'__session_diagnostic_sess, G> - rustc_session::SessionDiagnostic<'__session_diagnostic_sess, G> + rustc_errors::SessionDiagnostic<'__session_diagnostic_sess, G> for @Self where G: rustc_errors::EmissionGuarantee { diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 7d63fad3240..8cbcadb625a 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -3,9 +3,9 @@ use std::{ path::{Path, PathBuf}, }; -use rustc_errors::{error_code, ErrorGuaranteed}; +use rustc_errors::{error_code, ErrorGuaranteed, SessionDiagnostic}; use rustc_macros::SessionDiagnostic; -use rustc_session::{config, SessionDiagnostic}; +use rustc_session::config; use rustc_span::{sym, Span, Symbol}; use rustc_target::spec::{PanicStrategy, TargetTriple}; diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs index d5f05e790d3..883380dca08 100644 --- a/compiler/rustc_monomorphize/src/errors.rs +++ b/compiler/rustc_monomorphize/src/errors.rs @@ -1,8 +1,8 @@ use std::path::PathBuf; use rustc_errors::ErrorGuaranteed; +use rustc_errors::SessionDiagnostic; use rustc_macros::{LintDiagnostic, SessionDiagnostic}; -use rustc_session::SessionDiagnostic; use rustc_span::Span; #[derive(SessionDiagnostic)] diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index f4f75f71e72..bb93f1cc260 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -36,10 +36,10 @@ use rustc_ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits}; use rustc_ast::{ClosureBinder, StmtKind}; use rustc_ast_pretty::pprust; +use rustc_errors::SessionDiagnostic; use rustc_errors::{Applicability, Diagnostic, PResult}; use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP; use rustc_session::lint::BuiltinLintDiagnostics; -use rustc_session::SessionDiagnostic; use rustc_span::source_map::{self, Span, Spanned}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{BytePos, Pos}; diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 95305eabd0d..705305ff806 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -3,9 +3,11 @@ use crate::query::plumbing::CycleError; use crate::query::{QueryContext, QueryStackFrame}; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, Level}; +use rustc_errors::{ + Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, Level, SessionDiagnostic, +}; use rustc_hir::def::DefKind; -use rustc_session::{Session, SessionDiagnostic}; +use rustc_session::Session; use rustc_span::Span; use std::hash::Hash; diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 0389b2a06a3..564629a6703 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -6,14 +6,13 @@ use crate::errors::{FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGat use crate::lint::{ builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId, }; -use crate::SessionDiagnostic; use rustc_ast::node_id::NodeId; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_data_structures::sync::{Lock, Lrc}; use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler}; use rustc_errors::{ fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId, - DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, StashKey, + DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, SessionDiagnostic, StashKey, }; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_span::edition::Edition; diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index a001f87db00..6a5a89747df 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -28,7 +28,7 @@ use rustc_errors::json::JsonEmitter; use rustc_errors::registry::Registry; use rustc_errors::{ error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, - EmissionGuarantee, ErrorGuaranteed, FluentBundle, Handler, LazyFallbackBundle, MultiSpan, + ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan, SessionDiagnostic, }; use rustc_macros::HashStable_Generic; pub use rustc_span::def_id::StableCrateId; @@ -223,15 +223,6 @@ pub struct PerfStats { pub normalize_projection_ty: AtomicUsize, } -/// Trait implemented by error types. This should not be implemented manually. Instead, use -/// `#[derive(SessionDiagnostic)]` -- see [rustc_macros::SessionDiagnostic]. -#[rustc_diagnostic_item = "SessionDiagnostic"] -pub trait SessionDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> { - /// Write out as a diagnostic out of `Handler`. - #[must_use] - fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, T>; -} - impl Session { pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option) { self.miri_unleashed_features.lock().push((span, feature_gate)); diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index ab0afc54514..dc7078d9ada 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -1,7 +1,7 @@ -use rustc_errors::{fluent, ErrorGuaranteed, Handler}; +use rustc_errors::{fluent, ErrorGuaranteed, Handler, SessionDiagnostic}; use rustc_macros::SessionDiagnostic; use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated}; -use rustc_session::{Limit, SessionDiagnostic}; +use rustc_session::Limit; use rustc_span::{Span, Symbol}; #[derive(SessionDiagnostic)] diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index 0d2e6674585..ed4c4f688bf 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -1,8 +1,8 @@ //! Errors emitted by typeck. +use rustc_errors::SessionDiagnostic; use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler}; use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; use rustc_middle::ty::Ty; -use rustc_session::SessionDiagnostic; use rustc_span::{symbol::Ident, Span, Symbol}; #[derive(SessionDiagnostic)] diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.rs b/src/test/ui-fulldeps/internal-lints/diagnostics.rs index e9e809fa416..3b31a290449 100644 --- a/src/test/ui-fulldeps/internal-lints/diagnostics.rs +++ b/src/test/ui-fulldeps/internal-lints/diagnostics.rs @@ -12,10 +12,9 @@ extern crate rustc_session; extern crate rustc_span; use rustc_errors::{ - AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent + AddSubdiagnostic, SessionDiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent }; use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; -use rustc_session::SessionDiagnostic; use rustc_span::Span; #[derive(SessionDiagnostic)] -- cgit 1.4.1-3-g733a5 From 19b348fed44342d8addbbb5e8f67cda5dc8d9b95 Mon Sep 17 00:00:00 2001 From: Jhonny Bill Mena Date: Sun, 18 Sep 2022 11:45:41 -0400 Subject: UPDATE - rename DiagnosticHandler trait to IntoDiagnostic --- compiler/rustc_ast_lowering/src/errors.rs | 66 ++++----- compiler/rustc_ast_passes/src/errors.rs | 54 +++---- compiler/rustc_attr/src/session_diagnostics.rs | 68 ++++----- compiler/rustc_borrowck/src/session_diagnostics.rs | 16 +-- compiler/rustc_builtin_macros/src/cfg.rs | 6 +- compiler/rustc_const_eval/src/errors.rs | 44 +++--- compiler/rustc_driver/src/session_diagnostics.rs | 16 +-- .../rustc_error_messages/locales/en-US/lint.ftl | 2 +- compiler/rustc_errors/src/diagnostic.rs | 2 +- compiler/rustc_errors/src/diagnostic_builder.rs | 7 +- compiler/rustc_errors/src/lib.rs | 75 +++++++++- compiler/rustc_expand/src/base.rs | 6 +- compiler/rustc_expand/src/errors.rs | 14 +- .../src/infer/error_reporting/need_type_info.rs | 2 +- compiler/rustc_interface/src/errors.rs | 30 ++-- compiler/rustc_lint/src/errors.rs | 22 +-- compiler/rustc_lint/src/internal.rs | 4 +- .../rustc_macros/src/diagnostics/diagnostic.rs | 22 +-- .../src/diagnostics/diagnostic_builder.rs | 6 +- compiler/rustc_macros/src/diagnostics/mod.rs | 8 +- compiler/rustc_macros/src/lib.rs | 2 +- compiler/rustc_metadata/src/errors.rs | 158 ++++++++++----------- compiler/rustc_middle/src/error.rs | 8 +- compiler/rustc_mir_dataflow/src/errors.rs | 22 +-- compiler/rustc_monomorphize/src/errors.rs | 16 +-- compiler/rustc_parse/src/parser/diagnostics.rs | 84 +++++------ compiler/rustc_parse/src/parser/expr.rs | 2 +- compiler/rustc_passes/src/errors.rs | 104 +++++++------- compiler/rustc_plugin_impl/src/errors.rs | 6 +- compiler/rustc_privacy/src/errors.rs | 14 +- compiler/rustc_query_system/src/error.rs | 14 +- compiler/rustc_query_system/src/query/job.rs | 2 +- compiler/rustc_save_analysis/src/errors.rs | 4 +- compiler/rustc_session/src/errors.rs | 24 ++-- compiler/rustc_session/src/parse.rs | 16 +-- compiler/rustc_session/src/session.rs | 18 +-- compiler/rustc_span/src/symbol.rs | 2 +- compiler/rustc_symbol_mangling/src/errors.rs | 4 +- compiler/rustc_trait_selection/src/errors.rs | 18 +-- compiler/rustc_ty_utils/src/errors.rs | 6 +- compiler/rustc_typeck/src/check/expr.rs | 2 +- compiler/rustc_typeck/src/errors.rs | 58 ++++---- src/test/ui-fulldeps/internal-lints/diagnostics.rs | 15 +- .../ui-fulldeps/internal-lints/diagnostics.stderr | 4 +- .../session-diagnostic/diagnostic-derive.rs | 154 ++++++++++---------- .../session-diagnostic/diagnostic-derive.stderr | 16 +-- 46 files changed, 659 insertions(+), 584 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index c87d0ca9657..3f3024eb2b8 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -1,8 +1,8 @@ use rustc_errors::{fluent, AddSubdiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay}; -use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; use rustc_span::{symbol::Ident, Span, Symbol}; -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::generic_type_with_parentheses, code = "E0214")] pub struct GenericTypeWithParentheses { #[primary_span] @@ -28,7 +28,7 @@ impl AddSubdiagnostic for UseAngleBrackets { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[help] #[diag(ast_lowering::invalid_abi, code = "E0703")] pub struct InvalidAbi { @@ -39,7 +39,7 @@ pub struct InvalidAbi { pub valid_abis: String, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::assoc_ty_parentheses)] pub struct AssocTyParentheses { #[primary_span] @@ -71,7 +71,7 @@ impl AddSubdiagnostic for AssocTyParenthesesSub { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(ast_lowering::misplaced_impl_trait, code = "E0562")] pub struct MisplacedImplTrait<'a> { #[primary_span] @@ -79,14 +79,14 @@ pub struct MisplacedImplTrait<'a> { pub position: DiagnosticArgFromDisplay<'a>, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::rustc_box_attribute_error)] pub struct RustcBoxAttributeError { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::underscore_expr_lhs_assign)] pub struct UnderscoreExprLhsAssign { #[primary_span] @@ -94,7 +94,7 @@ pub struct UnderscoreExprLhsAssign { pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::base_expression_double_dot)] pub struct BaseExpressionDoubleDot { #[primary_span] @@ -102,7 +102,7 @@ pub struct BaseExpressionDoubleDot { pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::await_only_in_async_fn_and_blocks, code = "E0728")] pub struct AwaitOnlyInAsyncFnAndBlocks { #[primary_span] @@ -112,21 +112,21 @@ pub struct AwaitOnlyInAsyncFnAndBlocks { pub item_span: Option, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::generator_too_many_parameters, code = "E0628")] pub struct GeneratorTooManyParameters { #[primary_span] pub fn_decl_span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::closure_cannot_be_static, code = "E0697")] pub struct ClosureCannotBeStatic { #[primary_span] pub fn_decl_span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[help] #[diag(ast_lowering::async_non_move_closure_not_supported, code = "E0708")] pub struct AsyncNonMoveClosureNotSupported { @@ -134,7 +134,7 @@ pub struct AsyncNonMoveClosureNotSupported { pub fn_decl_span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::functional_record_update_destructuring_assignment)] pub struct FunctionalRecordUpdateDestructuringAssignemnt { #[primary_span] @@ -142,28 +142,28 @@ pub struct FunctionalRecordUpdateDestructuringAssignemnt { pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::async_generators_not_supported, code = "E0727")] pub struct AsyncGeneratorsNotSupported { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::inline_asm_unsupported_target, code = "E0472")] pub struct InlineAsmUnsupportedTarget { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::att_syntax_only_x86)] pub struct AttSyntaxOnlyX86 { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::abi_specified_multiple_times)] pub struct AbiSpecifiedMultipleTimes { #[primary_span] @@ -175,14 +175,14 @@ pub struct AbiSpecifiedMultipleTimes { pub equivalent: Option<()>, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::clobber_abi_not_supported)] pub struct ClobberAbiNotSupported { #[primary_span] pub abi_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[note] #[diag(ast_lowering::invalid_abi_clobber_abi)] pub struct InvalidAbiClobberAbi { @@ -191,7 +191,7 @@ pub struct InvalidAbiClobberAbi { pub supported_abis: String, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::invalid_register)] pub struct InvalidRegister<'a> { #[primary_span] @@ -200,7 +200,7 @@ pub struct InvalidRegister<'a> { pub error: &'a str, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::invalid_register_class)] pub struct InvalidRegisterClass<'a> { #[primary_span] @@ -209,7 +209,7 @@ pub struct InvalidRegisterClass<'a> { pub error: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(ast_lowering::invalid_asm_template_modifier_reg_class)] pub struct InvalidAsmTemplateModifierRegClass { #[primary_span] @@ -229,7 +229,7 @@ pub enum InvalidAsmTemplateModifierRegClassSub { DoesNotSupportModifier { class_name: Symbol }, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::invalid_asm_template_modifier_const)] pub struct InvalidAsmTemplateModifierConst { #[primary_span] @@ -239,7 +239,7 @@ pub struct InvalidAsmTemplateModifierConst { pub op_span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::invalid_asm_template_modifier_sym)] pub struct InvalidAsmTemplateModifierSym { #[primary_span] @@ -249,7 +249,7 @@ pub struct InvalidAsmTemplateModifierSym { pub op_span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::register_class_only_clobber)] pub struct RegisterClassOnlyClobber { #[primary_span] @@ -257,7 +257,7 @@ pub struct RegisterClassOnlyClobber { pub reg_class_name: Symbol, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::register_conflict)] pub struct RegisterConflict<'a> { #[primary_span] @@ -271,7 +271,7 @@ pub struct RegisterConflict<'a> { pub in_out: Option, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[help] #[diag(ast_lowering::sub_tuple_binding)] pub struct SubTupleBinding<'a> { @@ -288,7 +288,7 @@ pub struct SubTupleBinding<'a> { pub ctx: &'a str, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::extra_double_dot)] pub struct ExtraDoubleDot<'a> { #[primary_span] @@ -299,7 +299,7 @@ pub struct ExtraDoubleDot<'a> { pub ctx: &'a str, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[note] #[diag(ast_lowering::misplaced_double_dot)] pub struct MisplacedDoubleDot { @@ -307,28 +307,28 @@ pub struct MisplacedDoubleDot { pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::misplaced_relax_trait_bound)] pub struct MisplacedRelaxTraitBound { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::not_supported_for_lifetime_binder_async_closure)] pub struct NotSupportedForLifetimeBinderAsyncClosure { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::arbitrary_expression_in_pattern)] pub struct ArbitraryExpressionInPattern { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(DiagnosticHandler, Clone, Copy)] #[diag(ast_lowering::inclusive_range_with_no_end)] pub struct InclusiveRangeWithNoEnd { #[primary_span] diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index 4f3b09c5871..20e2209acbe 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -1,12 +1,12 @@ //! Errors emitted by ast_passes. -use rustc_errors::{fluent, AddSubdiagnostic, Applicability, Diagnostic}; -use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; +use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic}; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{Span, Symbol}; use crate::ast_validation::ForbiddenLetReason; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::forbidden_let)] #[note] pub struct ForbiddenLet { @@ -16,7 +16,7 @@ pub struct ForbiddenLet { pub(crate) reason: ForbiddenLetReason, } -impl AddSubdiagnostic for ForbiddenLetReason { +impl AddToDiagnostic for ForbiddenLetReason { fn add_to_diagnostic(self, diag: &mut Diagnostic) { match self { Self::GenericForbidden => {} @@ -30,7 +30,7 @@ impl AddSubdiagnostic for ForbiddenLetReason { } } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::forbidden_let_stable)] #[note] pub struct ForbiddenLetStable { @@ -38,21 +38,21 @@ pub struct ForbiddenLetStable { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::forbidden_assoc_constraint)] pub struct ForbiddenAssocConstraint { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::keyword_lifetime)] pub struct KeywordLifetime { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::invalid_label)] pub struct InvalidLabel { #[primary_span] @@ -60,7 +60,7 @@ pub struct InvalidLabel { pub name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::invalid_visibility, code = "E0449")] pub struct InvalidVisibility { #[primary_span] @@ -79,7 +79,7 @@ pub enum InvalidVisibilityNote { IndividualForeignItems, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::trait_fn_const, code = "E0379")] pub struct TraitFnConst { #[primary_span] @@ -87,21 +87,21 @@ pub struct TraitFnConst { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::forbidden_lifetime_bound)] pub struct ForbiddenLifetimeBound { #[primary_span] pub spans: Vec, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::forbidden_non_lifetime_param)] pub struct ForbiddenNonLifetimeParam { #[primary_span] pub spans: Vec, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::fn_param_too_many)] pub struct FnParamTooMany { #[primary_span] @@ -109,21 +109,21 @@ pub struct FnParamTooMany { pub max_num_args: usize, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::fn_param_c_var_args_only)] pub struct FnParamCVarArgsOnly { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::fn_param_c_var_args_not_last)] pub struct FnParamCVarArgsNotLast { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::fn_param_doc_comment)] pub struct FnParamDocComment { #[primary_span] @@ -131,14 +131,14 @@ pub struct FnParamDocComment { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::fn_param_forbidden_attr)] pub struct FnParamForbiddenAttr { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::fn_param_forbidden_self)] #[note] pub struct FnParamForbiddenSelf { @@ -147,7 +147,7 @@ pub struct FnParamForbiddenSelf { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::forbidden_default)] pub struct ForbiddenDefault { #[primary_span] @@ -156,7 +156,7 @@ pub struct ForbiddenDefault { pub def_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::assoc_const_without_body)] pub struct AssocConstWithoutBody { #[primary_span] @@ -165,7 +165,7 @@ pub struct AssocConstWithoutBody { pub replace_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::assoc_fn_without_body)] pub struct AssocFnWithoutBody { #[primary_span] @@ -174,7 +174,7 @@ pub struct AssocFnWithoutBody { pub replace_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::assoc_type_without_body)] pub struct AssocTypeWithoutBody { #[primary_span] @@ -183,7 +183,7 @@ pub struct AssocTypeWithoutBody { pub replace_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::const_without_body)] pub struct ConstWithoutBody { #[primary_span] @@ -192,7 +192,7 @@ pub struct ConstWithoutBody { pub replace_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::static_without_body)] pub struct StaticWithoutBody { #[primary_span] @@ -201,7 +201,7 @@ pub struct StaticWithoutBody { pub replace_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::ty_alias_without_body)] pub struct TyAliasWithoutBody { #[primary_span] @@ -210,7 +210,7 @@ pub struct TyAliasWithoutBody { pub replace_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(ast_passes::fn_without_body)] pub struct FnWithoutBody { #[primary_span] @@ -227,7 +227,7 @@ pub struct ExternBlockSuggestion { pub abi: Option, } -impl AddSubdiagnostic for ExternBlockSuggestion { +impl AddToDiagnostic for ExternBlockSuggestion { fn add_to_diagnostic(self, diag: &mut Diagnostic) { let start_suggestion = if let Some(abi) = self.abi { format!("extern \"{}\" {{", abi) diff --git a/compiler/rustc_attr/src/session_diagnostics.rs b/compiler/rustc_attr/src/session_diagnostics.rs index ed8400391c2..8362b51af40 100644 --- a/compiler/rustc_attr/src/session_diagnostics.rs +++ b/compiler/rustc_attr/src/session_diagnostics.rs @@ -1,23 +1,23 @@ use std::num::IntErrorKind; use rustc_ast as ast; -use rustc_errors::SessionDiagnostic; use rustc_errors::{ - error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, + error_code, fluent, Applicability, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, + Handler, }; -use rustc_macros::SessionDiagnostic; +use rustc_macros::DiagnosticHandler; use rustc_span::{Span, Symbol}; use crate::UnsupportedLiteralReason; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::expected_one_cfg_pattern, code = "E0536")] pub(crate) struct ExpectedOneCfgPattern { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::invalid_predicate, code = "E0537")] pub(crate) struct InvalidPredicate { #[primary_span] @@ -26,7 +26,7 @@ pub(crate) struct InvalidPredicate { pub predicate: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::multiple_item, code = "E0538")] pub(crate) struct MultipleItem { #[primary_span] @@ -35,7 +35,7 @@ pub(crate) struct MultipleItem { pub item: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::incorrect_meta_item, code = "E0539")] pub(crate) struct IncorrectMetaItem { #[primary_span] @@ -50,7 +50,7 @@ pub(crate) struct UnknownMetaItem<'a> { } // Manual implementation to be able to format `expected` items correctly. -impl<'a> SessionDiagnostic<'a> for UnknownMetaItem<'_> { +impl<'a> IntoDiagnostic<'a> for UnknownMetaItem<'_> { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { let expected = self.expected.iter().map(|name| format!("`{}`", name)).collect::>(); let mut diag = handler.struct_span_err_with_code( @@ -65,28 +65,28 @@ impl<'a> SessionDiagnostic<'a> for UnknownMetaItem<'_> { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::missing_since, code = "E0542")] pub(crate) struct MissingSince { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::missing_note, code = "E0543")] pub(crate) struct MissingNote { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::multiple_stability_levels, code = "E0544")] pub(crate) struct MultipleStabilityLevels { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::invalid_issue_string, code = "E0545")] pub(crate) struct InvalidIssueString { #[primary_span] @@ -144,21 +144,21 @@ impl InvalidIssueStringCause { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::missing_feature, code = "E0546")] pub(crate) struct MissingFeature { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::non_ident_feature, code = "E0546")] pub(crate) struct NonIdentFeature { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::missing_issue, code = "E0547")] pub(crate) struct MissingIssue { #[primary_span] @@ -167,7 +167,7 @@ pub(crate) struct MissingIssue { // FIXME: This diagnostic is identical to `IncorrectMetaItem`, barring the error code. Consider // changing this to `IncorrectMetaItem`. See #51489. -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::incorrect_meta_item, code = "E0551")] pub(crate) struct IncorrectMetaItem2 { #[primary_span] @@ -176,14 +176,14 @@ pub(crate) struct IncorrectMetaItem2 { // FIXME: Why is this the same error code as `InvalidReprHintNoParen` and `InvalidReprHintNoValue`? // It is more similar to `IncorrectReprFormatGeneric`. -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::incorrect_repr_format_packed_one_or_zero_arg, code = "E0552")] pub(crate) struct IncorrectReprFormatPackedOneOrZeroArg { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::invalid_repr_hint_no_paren, code = "E0552")] pub(crate) struct InvalidReprHintNoParen { #[primary_span] @@ -192,7 +192,7 @@ pub(crate) struct InvalidReprHintNoParen { pub name: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::invalid_repr_hint_no_value, code = "E0552")] pub(crate) struct InvalidReprHintNoValue { #[primary_span] @@ -209,7 +209,7 @@ pub(crate) struct UnsupportedLiteral { pub start_point_span: Span, } -impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral { +impl<'a> IntoDiagnostic<'a> for UnsupportedLiteral { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { let mut diag = handler.struct_span_err_with_code( self.span, @@ -237,7 +237,7 @@ impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::invalid_repr_align_need_arg, code = "E0589")] pub(crate) struct InvalidReprAlignNeedArg { #[primary_span] @@ -245,7 +245,7 @@ pub(crate) struct InvalidReprAlignNeedArg { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::invalid_repr_generic, code = "E0589")] pub(crate) struct InvalidReprGeneric<'a> { #[primary_span] @@ -255,14 +255,14 @@ pub(crate) struct InvalidReprGeneric<'a> { pub error_part: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::incorrect_repr_format_align_one_arg, code = "E0693")] pub(crate) struct IncorrectReprFormatAlignOneArg { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::incorrect_repr_format_generic, code = "E0693")] pub(crate) struct IncorrectReprFormatGeneric<'a> { #[primary_span] @@ -317,28 +317,28 @@ impl<'a> IncorrectReprFormatGenericCause<'a> { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::rustc_promotable_pairing, code = "E0717")] pub(crate) struct RustcPromotablePairing { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::rustc_allowed_unstable_pairing, code = "E0789")] pub(crate) struct RustcAllowedUnstablePairing { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::cfg_predicate_identifier)] pub(crate) struct CfgPredicateIdentifier { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::deprecated_item_suggestion)] pub(crate) struct DeprecatedItemSuggestion { #[primary_span] @@ -351,21 +351,21 @@ pub(crate) struct DeprecatedItemSuggestion { pub details: (), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::expected_single_version_literal)] pub(crate) struct ExpectedSingleVersionLiteral { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::expected_version_literal)] pub(crate) struct ExpectedVersionLiteral { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::expects_feature_list)] pub(crate) struct ExpectsFeatureList { #[primary_span] @@ -374,7 +374,7 @@ pub(crate) struct ExpectsFeatureList { pub name: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::expects_features)] pub(crate) struct ExpectsFeatures { #[primary_span] @@ -383,14 +383,14 @@ pub(crate) struct ExpectsFeatures { pub name: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::soft_no_args)] pub(crate) struct SoftNoArgs { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(attr::unknown_version_literal)] pub(crate) struct UnknownVersionLiteral { #[primary_span] diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index 5d750c6ca8c..1014a92cc39 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -1,11 +1,11 @@ use rustc_errors::{IntoDiagnosticArg, MultiSpan}; -use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{DiagnosticHandler, LintDiagnostic, SessionSubdiagnostic}; use rustc_middle::ty::Ty; use rustc_span::Span; use crate::diagnostics::RegionName; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(borrowck::move_unsized, code = "E0161")] pub(crate) struct MoveUnsized<'tcx> { pub ty: Ty<'tcx>, @@ -14,7 +14,7 @@ pub(crate) struct MoveUnsized<'tcx> { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(borrowck::higher_ranked_lifetime_error)] pub(crate) struct HigherRankedLifetimeError { #[subdiagnostic] @@ -31,14 +31,14 @@ pub(crate) enum HigherRankedErrorCause { CouldNotNormalize { value: String }, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(borrowck::higher_ranked_subtype_error)] pub(crate) struct HigherRankedSubtypeError { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(borrowck::generic_does_not_live_long_enough)] pub(crate) struct GenericDoesNotLiveLongEnough { pub kind: String, @@ -53,7 +53,7 @@ pub(crate) struct VarNeedNotMut { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(borrowck::const_not_used_in_type_alias)] pub(crate) struct ConstNotUsedTraitAlias { pub ct: String, @@ -61,7 +61,7 @@ pub(crate) struct ConstNotUsedTraitAlias { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(borrowck::var_cannot_escape_closure)] #[note] #[note(borrowck::cannot_escape)] @@ -110,7 +110,7 @@ pub(crate) enum FnMutReturnTypeErr { }, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(borrowck::lifetime_constraints_error)] pub(crate) struct LifetimeOutliveErr { #[primary_span] diff --git a/compiler/rustc_builtin_macros/src/cfg.rs b/compiler/rustc_builtin_macros/src/cfg.rs index 9046bf13059..55b54fede93 100644 --- a/compiler/rustc_builtin_macros/src/cfg.rs +++ b/compiler/rustc_builtin_macros/src/cfg.rs @@ -8,7 +8,7 @@ use rustc_ast::tokenstream::TokenStream; use rustc_attr as attr; use rustc_errors::PResult; use rustc_expand::base::{self, *}; -use rustc_macros::SessionDiagnostic; +use rustc_macros::DiagnosticHandler; use rustc_span::Span; pub fn expand_cfg( @@ -35,7 +35,7 @@ pub fn expand_cfg( } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(builtin_macros::requires_cfg_pattern)] struct RequiresCfgPattern { #[primary_span] @@ -43,7 +43,7 @@ struct RequiresCfgPattern { span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(builtin_macros::expected_one_cfg_pattern)] struct OneCfgPattern { #[primary_span] diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index c3547cb3abd..d0b94e91abf 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -1,8 +1,8 @@ use rustc_hir::ConstContext; -use rustc_macros::SessionDiagnostic; +use rustc_macros::DiagnosticHandler; use rustc_span::Span; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::unstable_in_stable)] pub(crate) struct UnstableInStable { pub gate: String, @@ -21,14 +21,14 @@ pub(crate) struct UnstableInStable { pub attr_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::thread_local_access, code = "E0625")] pub(crate) struct NonConstOpErr { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::static_access, code = "E0013")] #[help] pub(crate) struct StaticAccessErr { @@ -40,7 +40,7 @@ pub(crate) struct StaticAccessErr { pub teach: Option<()>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::raw_ptr_to_int)] #[note] #[note(const_eval::note2)] @@ -49,7 +49,7 @@ pub(crate) struct RawPtrToIntErr { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::raw_ptr_comparison)] #[note] pub(crate) struct RawPtrComparisonErr { @@ -57,14 +57,14 @@ pub(crate) struct RawPtrComparisonErr { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::panic_non_str)] pub(crate) struct PanicNonStrErr { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::mut_deref, code = "E0658")] pub(crate) struct MutDerefErr { #[primary_span] @@ -72,7 +72,7 @@ pub(crate) struct MutDerefErr { pub kind: ConstContext, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::transient_mut_borrow, code = "E0658")] pub(crate) struct TransientMutBorrowErr { #[primary_span] @@ -80,7 +80,7 @@ pub(crate) struct TransientMutBorrowErr { pub kind: ConstContext, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::transient_mut_borrow_raw, code = "E0658")] pub(crate) struct TransientMutBorrowErrRaw { #[primary_span] @@ -88,7 +88,7 @@ pub(crate) struct TransientMutBorrowErrRaw { pub kind: ConstContext, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::max_num_nodes_in_const)] pub(crate) struct MaxNumNodesInConstErr { #[primary_span] @@ -96,7 +96,7 @@ pub(crate) struct MaxNumNodesInConstErr { pub global_const_id: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::unallowed_fn_pointer_call)] pub(crate) struct UnallowedFnPointerCall { #[primary_span] @@ -104,7 +104,7 @@ pub(crate) struct UnallowedFnPointerCall { pub kind: ConstContext, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::unstable_const_fn)] pub(crate) struct UnstableConstFn { #[primary_span] @@ -112,7 +112,7 @@ pub(crate) struct UnstableConstFn { pub def_path: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::unallowed_mutable_refs, code = "E0764")] pub(crate) struct UnallowedMutableRefs { #[primary_span] @@ -122,7 +122,7 @@ pub(crate) struct UnallowedMutableRefs { pub teach: Option<()>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::unallowed_mutable_refs_raw, code = "E0764")] pub(crate) struct UnallowedMutableRefsRaw { #[primary_span] @@ -131,7 +131,7 @@ pub(crate) struct UnallowedMutableRefsRaw { #[note(const_eval::teach_note)] pub teach: Option<()>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::non_const_fmt_macro_call, code = "E0015")] pub(crate) struct NonConstFmtMacroCall { #[primary_span] @@ -139,7 +139,7 @@ pub(crate) struct NonConstFmtMacroCall { pub kind: ConstContext, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::non_const_fn_call, code = "E0015")] pub(crate) struct NonConstFnCall { #[primary_span] @@ -148,7 +148,7 @@ pub(crate) struct NonConstFnCall { pub kind: ConstContext, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::unallowed_op_in_const_context)] pub(crate) struct UnallowedOpInConstContext { #[primary_span] @@ -156,7 +156,7 @@ pub(crate) struct UnallowedOpInConstContext { pub msg: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::unallowed_heap_allocations, code = "E0010")] pub(crate) struct UnallowedHeapAllocations { #[primary_span] @@ -167,7 +167,7 @@ pub(crate) struct UnallowedHeapAllocations { pub teach: Option<()>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::unallowed_inline_asm, code = "E0015")] pub(crate) struct UnallowedInlineAsm { #[primary_span] @@ -175,7 +175,7 @@ pub(crate) struct UnallowedInlineAsm { pub kind: ConstContext, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::interior_mutable_data_refer, code = "E0492")] pub(crate) struct InteriorMutableDataRefer { #[primary_span] @@ -188,7 +188,7 @@ pub(crate) struct InteriorMutableDataRefer { pub teach: Option<()>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(const_eval::interior_mutability_borrow)] pub(crate) struct InteriorMutabilityBorrow { #[primary_span] diff --git a/compiler/rustc_driver/src/session_diagnostics.rs b/compiler/rustc_driver/src/session_diagnostics.rs index e9696792d05..704d3c7fd2a 100644 --- a/compiler/rustc_driver/src/session_diagnostics.rs +++ b/compiler/rustc_driver/src/session_diagnostics.rs @@ -1,38 +1,38 @@ -use rustc_macros::SessionDiagnostic; +use rustc_macros::DiagnosticHandler; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(driver::rlink_unable_to_read)] pub(crate) struct RlinkUnableToRead { pub err: std::io::Error, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(driver::rlink_wrong_file_type)] pub(crate) struct RLinkWrongFileType; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(driver::rlink_empty_version_number)] pub(crate) struct RLinkEmptyVersionNumber; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(driver::rlink_encoding_version_mismatch)] pub(crate) struct RLinkEncodingVersionMismatch { pub version_array: String, pub rlink_version: u32, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(driver::rlink_rustc_version_mismatch)] pub(crate) struct RLinkRustcVersionMismatch<'a> { pub rustc_version: String, pub current_version: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(driver::rlink_no_a_file)] pub(crate) struct RlinkNotAFile; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(driver::unpretty_dump_fail)] pub(crate) struct UnprettyDumpFail { pub path: String, diff --git a/compiler/rustc_error_messages/locales/en-US/lint.ftl b/compiler/rustc_error_messages/locales/en-US/lint.ftl index 7f9918e4f12..6cc0cb49e1f 100644 --- a/compiler/rustc_error_messages/locales/en-US/lint.ftl +++ b/compiler/rustc_error_messages/locales/en-US/lint.ftl @@ -51,7 +51,7 @@ lint_non_existant_doc_keyword = found non-existing keyword `{$keyword}` used in .help = only existing keywords are allowed in core/std lint_diag_out_of_impl = - diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls + diagnostics should only be created in `IntoDiagnostic`/`AddSubdiagnostic` impls lint_untranslatable_diag = diagnostics should be created using translatable messages diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 6dfb6b11b16..8a56068fcc7 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -35,7 +35,7 @@ pub enum DiagnosticArgValue<'source> { Number(usize), } -/// Converts a value of a type into a `DiagnosticArg` (typically a field of a `SessionDiagnostic` +/// Converts a value of a type into a `DiagnosticArg` (typically a field of an `IntoDiagnostic` /// struct). Implemented as a custom trait rather than `From` so that it is implemented on the type /// being converted rather than on `DiagnosticArgValue`, which enables types from other `rustc_*` /// crates to implement this. diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index 71e21373d0d..b646dd662cb 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -14,9 +14,10 @@ use std::ops::{Deref, DerefMut}; use std::thread::panicking; /// Trait implemented by error types. This should not be implemented manually. Instead, use -/// `#[derive(SessionDiagnostic)]` -- see [rustc_macros::SessionDiagnostic]. -#[rustc_diagnostic_item = "SessionDiagnostic"] -pub trait SessionDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> { +/// `#[derive(DiagnosticHandler)]` -- see [rustc_macros::DiagnosticHandler]. +#[cfg_attr(bootstrap, rustc_diagnostic_item = "SessionDiagnostic")] +#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "DiagnosticHandler")] +pub trait IntoDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> { /// Write out as a diagnostic out of `Handler`. #[must_use] fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, T>; diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 3549d3c4999..aed52bce9aa 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -60,7 +60,7 @@ mod snippet; mod styled_buffer; pub mod translation; -pub use diagnostic_builder::SessionDiagnostic; +pub use diagnostic_builder::IntoDiagnostic; pub use snippet::Style; pub type PResult<'a, T> = Result>; @@ -647,6 +647,8 @@ impl Handler { /// Construct a builder with the `msg` at the level appropriate for the specific `EmissionGuarantee`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_diagnostic( &self, msg: impl Into, @@ -660,6 +662,8 @@ impl Handler { /// * `can_emit_warnings` is `true` /// * `is_force_warn` was set in `DiagnosticId::Lint` #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_warn( &self, span: impl Into, @@ -676,6 +680,8 @@ impl Handler { /// Attempting to `.emit()` the builder will only emit if either: /// * `can_emit_warnings` is `true` /// * `is_force_warn` was set in `DiagnosticId::Lint` + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_warn_with_expectation( &self, span: impl Into, @@ -689,6 +695,8 @@ impl Handler { /// Construct a builder at the `Allow` level at the given `span` and with the `msg`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_allow( &self, span: impl Into, @@ -702,6 +710,8 @@ impl Handler { /// Construct a builder at the `Warning` level at the given `span` and with the `msg`. /// Also include a code. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_warn_with_code( &self, span: impl Into, @@ -719,6 +729,8 @@ impl Handler { /// * `can_emit_warnings` is `true` /// * `is_force_warn` was set in `DiagnosticId::Lint` #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_warn(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { DiagnosticBuilder::new(self, Level::Warning(None), msg) } @@ -729,6 +741,8 @@ impl Handler { /// Attempting to `.emit()` the builder will only emit if either: /// * `can_emit_warnings` is `true` /// * `is_force_warn` was set in `DiagnosticId::Lint` + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_warn_with_expectation( &self, msg: impl Into, @@ -739,12 +753,16 @@ impl Handler { /// Construct a builder at the `Allow` level with the `msg`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_allow(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { DiagnosticBuilder::new(self, Level::Allow, msg) } /// Construct a builder at the `Expect` level with the `msg`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_expect( &self, msg: impl Into, @@ -755,6 +773,8 @@ impl Handler { /// Construct a builder at the `Error` level at the given `span` and with the `msg`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_err( &self, span: impl Into, @@ -767,6 +787,8 @@ impl Handler { /// Construct a builder at the `Error` level at the given `span`, with the `msg`, and `code`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_err_with_code( &self, span: impl Into, @@ -781,6 +803,8 @@ impl Handler { /// Construct a builder at the `Error` level with the `msg`. // FIXME: This method should be removed (every error should have an associated error code). #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_err( &self, msg: impl Into, @@ -790,12 +814,16 @@ impl Handler { /// This should only be used by `rustc_middle::lint::struct_lint_level`. Do not use it for hard errors. #[doc(hidden)] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_err_lint(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { DiagnosticBuilder::new(self, Level::Error { lint: true }, msg) } /// Construct a builder at the `Error` level with the `msg` and the `code`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_err_with_code( &self, msg: impl Into, @@ -808,6 +836,8 @@ impl Handler { /// Construct a builder at the `Warn` level with the `msg` and the `code`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_warn_with_code( &self, msg: impl Into, @@ -820,6 +850,8 @@ impl Handler { /// Construct a builder at the `Fatal` level at the given `span` and with the `msg`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_fatal( &self, span: impl Into, @@ -832,6 +864,8 @@ impl Handler { /// Construct a builder at the `Fatal` level at the given `span`, with the `msg`, and `code`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_fatal_with_code( &self, span: impl Into, @@ -845,18 +879,24 @@ impl Handler { /// Construct a builder at the `Error` level with the `msg`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_fatal(&self, msg: impl Into) -> DiagnosticBuilder<'_, !> { DiagnosticBuilder::new_fatal(self, msg) } /// Construct a builder at the `Help` level with the `msg`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_help(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { DiagnosticBuilder::new(self, Level::Help, msg) } /// Construct a builder at the `Note` level with the `msg`. #[rustc_lint_diagnostics] + #[allow(rustc::diagnostic_outside_of_impl)] + #[allow(rustc::untranslatable_diagnostic)] pub fn struct_note_without_error( &self, msg: impl Into, @@ -1029,6 +1069,39 @@ impl Handler { self.inner.borrow_mut().emit_diagnostic(diagnostic) } + pub fn emit_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> ErrorGuaranteed { + self.create_err(err).emit() + } + + pub fn create_err<'a>( + &'a self, + err: impl IntoDiagnostic<'a>, + ) -> DiagnosticBuilder<'a, ErrorGuaranteed> { + err.into_diagnostic(self) + } + + pub fn create_warning<'a>( + &'a self, + warning: impl IntoDiagnostic<'a, ()>, + ) -> DiagnosticBuilder<'a, ()> { + warning.into_diagnostic(self) + } + + pub fn emit_warning<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) { + self.create_warning(warning).emit() + } + + pub fn create_fatal<'a>( + &'a self, + fatal: impl IntoDiagnostic<'a, !>, + ) -> DiagnosticBuilder<'a, !> { + fatal.into_diagnostic(self) + } + + pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, !>) -> ! { + self.create_fatal(fatal).emit() + } + fn emit_diag_at_span( &self, mut diag: Diagnostic, diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 11598ea0fff..ca429b6adc1 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -11,7 +11,7 @@ use rustc_attr::{self as attr, Deprecation, Stability}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::sync::{self, Lrc}; use rustc_errors::{ - Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult, SessionDiagnostic, + Applicability, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, MultiSpan, PResult, }; use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT; use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics}; @@ -1111,12 +1111,12 @@ impl<'a> ExtCtxt<'a> { pub fn create_err( &self, - err: impl SessionDiagnostic<'a>, + err: impl IntoDiagnostic<'a>, ) -> DiagnosticBuilder<'a, ErrorGuaranteed> { self.sess.create_err(err) } - pub fn emit_err(&self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed { + pub fn emit_err(&self, err: impl IntoDiagnostic<'a>) -> ErrorGuaranteed { self.sess.emit_err(err) } diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index 0feae0debd2..7cbdad3cd95 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -1,29 +1,29 @@ -use rustc_macros::SessionDiagnostic; +use rustc_macros::DiagnosticHandler; use rustc_span::symbol::MacroRulesNormalizedIdent; use rustc_span::Span; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(expand::expr_repeat_no_syntax_vars)] pub(crate) struct NoSyntaxVarsExprRepeat { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(expand::must_repeat_once)] pub(crate) struct MustRepeatOnce { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(expand::count_repetition_misplaced)] pub(crate) struct CountRepetitionMisplaced { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(expand::meta_var_expr_unrecognized_var)] pub(crate) struct MetaVarExprUnrecognizedVar { #[primary_span] @@ -31,7 +31,7 @@ pub(crate) struct MetaVarExprUnrecognizedVar { pub key: MacroRulesNormalizedIdent, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(expand::var_still_repeating)] pub(crate) struct VarStillRepeating { #[primary_span] @@ -39,7 +39,7 @@ pub(crate) struct VarStillRepeating { pub ident: MacroRulesNormalizedIdent, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(expand::meta_var_dif_seq_matchers)] pub(crate) struct MetaVarsDifSeqMatchers { #[primary_span] diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index dccd3f3a1cc..baa97d72a4b 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -4,7 +4,7 @@ use crate::errors::{ }; use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::InferCtxt; -use rustc_errors::SessionDiagnostic; +use rustc_errors::IntoDiagnostic; use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, IntoDiagnosticArg}; use rustc_hir as hir; use rustc_hir::def::Res; diff --git a/compiler/rustc_interface/src/errors.rs b/compiler/rustc_interface/src/errors.rs index 6a497aed4ab..dc975099fc7 100644 --- a/compiler/rustc_interface/src/errors.rs +++ b/compiler/rustc_interface/src/errors.rs @@ -1,10 +1,10 @@ -use rustc_macros::SessionDiagnostic; +use rustc_macros::DiagnosticHandler; use rustc_span::{Span, Symbol}; use std::io; use std::path::Path; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::ferris_identifier)] pub struct FerrisIdentifier { #[primary_span] @@ -13,7 +13,7 @@ pub struct FerrisIdentifier { pub first_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::emoji_identifier)] pub struct EmojiIdentifier { #[primary_span] @@ -21,67 +21,67 @@ pub struct EmojiIdentifier { pub ident: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::mixed_bin_crate)] pub struct MixedBinCrate; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::mixed_proc_macro_crate)] pub struct MixedProcMacroCrate; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::proc_macro_doc_without_arg)] pub struct ProcMacroDocWithoutArg; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::error_writing_dependencies)] pub struct ErrorWritingDependencies<'a> { pub path: &'a Path, pub error: io::Error, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::input_file_would_be_overwritten)] pub struct InputFileWouldBeOverWritten<'a> { pub path: &'a Path, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::generated_file_conflicts_with_directory)] pub struct GeneratedFileConflictsWithDirectory<'a> { pub input_path: &'a Path, pub dir_path: &'a Path, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::temps_dir_error)] pub struct TempsDirError; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::out_dir_error)] pub struct OutDirError; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::cant_emit_mir)] pub struct CantEmitMIR { pub error: io::Error, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::rustc_error_fatal)] pub struct RustcErrorFatal { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::rustc_error_unexpected_annotation)] pub struct RustcErrorUnexpectedAnnotation { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(interface::failed_writing_file)] pub struct FailedWritingFile<'a> { pub path: &'a Path, diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs index ac98948189b..261570acb7b 100644 --- a/compiler/rustc_lint/src/errors.rs +++ b/compiler/rustc_lint/src/errors.rs @@ -1,9 +1,9 @@ -use rustc_errors::{fluent, AddSubdiagnostic, ErrorGuaranteed, Handler, SessionDiagnostic}; -use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; +use rustc_errors::{fluent, AddSubdiagnostic, IntoDiagnostic, ErrorGuaranteed, Handler}; +use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; use rustc_session::lint::Level; use rustc_span::{Span, Symbol}; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(lint::overruled_attribute, code = "E0453")] pub struct OverruledAttribute { #[primary_span] @@ -42,7 +42,7 @@ impl AddSubdiagnostic for OverruledAttributeSub { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(lint::malformed_attribute, code = "E0452")] pub struct MalformedAttribute { #[primary_span] @@ -61,7 +61,7 @@ pub enum MalformedAttributeSub { ReasonMustComeLast(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(lint::unknown_tool_in_scoped_lint, code = "E0710")] pub struct UnknownToolInScopedLint { #[primary_span] @@ -72,7 +72,7 @@ pub struct UnknownToolInScopedLint { pub is_nightly_build: Option<()>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(lint::builtin_ellipsis_inclusive_range_patterns, code = "E0783")] pub struct BuiltinEllpisisInclusiveRangePatterns { #[primary_span] @@ -107,7 +107,7 @@ impl AddSubdiagnostic for RequestedLevel { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(lint::unsupported_group, code = "E0602")] pub struct UnsupportedGroup { pub lint_group: String, @@ -119,7 +119,7 @@ pub struct CheckNameUnknown { pub sub: RequestedLevel, } -impl SessionDiagnostic<'_> for CheckNameUnknown { +impl IntoDiagnostic<'_> for CheckNameUnknown { fn into_diagnostic( self, handler: &Handler, @@ -136,7 +136,7 @@ impl SessionDiagnostic<'_> for CheckNameUnknown { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(lint::check_name_unknown_tool, code = "E0602")] pub struct CheckNameUnknownTool { pub tool_name: Symbol, @@ -144,7 +144,7 @@ pub struct CheckNameUnknownTool { pub sub: RequestedLevel, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(lint::check_name_warning)] pub struct CheckNameWarning { pub msg: String, @@ -152,7 +152,7 @@ pub struct CheckNameWarning { pub sub: RequestedLevel, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(lint::check_name_deprecated)] pub struct CheckNameDeprecated { pub lint_name: String, diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index dd1fc5916db..dec75c9d380 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -372,7 +372,7 @@ declare_tool_lint! { declare_tool_lint! { pub rustc::DIAGNOSTIC_OUTSIDE_OF_IMPL, Allow, - "prevent creation of diagnostics outside of `SessionDiagnostic`/`AddSubdiagnostic` impls", + "prevent creation of diagnostics outside of `DiagnosticHandler`/`AddSubdiagnostic` impls", report_in_external_macro: true } @@ -404,7 +404,7 @@ impl LateLintPass<'_> for Diagnostics { let Impl { of_trait: Some(of_trait), .. } = impl_ && let Some(def_id) = of_trait.trait_def_id() && let Some(name) = cx.tcx.get_diagnostic_name(def_id) && - matches!(name, sym::SessionDiagnostic | sym::AddSubdiagnostic | sym::DecorateLint) + matches!(name, sym::DiagnosticHandler | sym::AddSubdiagnostic | sym::DecorateLint) { found_impl = true; break; diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs index 891b6a118de..c5b5edab816 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs @@ -11,27 +11,27 @@ use synstructure::Structure; /// The central struct for constructing the `into_diagnostic` method from an annotated struct. pub(crate) struct SessionDiagnosticDerive<'a> { structure: Structure<'a>, - sess: syn::Ident, + handler: syn::Ident, builder: DiagnosticDeriveBuilder, } impl<'a> SessionDiagnosticDerive<'a> { - pub(crate) fn new(diag: syn::Ident, sess: syn::Ident, structure: Structure<'a>) -> Self { + pub(crate) fn new(diag: syn::Ident, handler: syn::Ident, structure: Structure<'a>) -> Self { Self { builder: DiagnosticDeriveBuilder { diag, fields: build_field_mapping(&structure), - kind: DiagnosticDeriveKind::SessionDiagnostic, + kind: DiagnosticDeriveKind::DiagnosticHandler, code: None, slug: None, }, - sess, + handler, structure, } } pub(crate) fn into_tokens(self) -> TokenStream { - let SessionDiagnosticDerive { mut structure, sess, mut builder } = self; + let SessionDiagnosticDerive { mut structure, handler, mut builder } = self; let ast = structure.ast(); let implementation = { @@ -53,7 +53,7 @@ impl<'a> SessionDiagnosticDerive<'a> { } Some(slug) => { quote! { - let mut #diag = #sess.struct_diagnostic(rustc_errors::fluent::#slug); + let mut #diag = #handler.struct_diagnostic(rustc_errors::fluent::#slug); } } }; @@ -72,7 +72,7 @@ impl<'a> SessionDiagnosticDerive<'a> { } else { span_err( ast.span().unwrap(), - "`#[derive(SessionDiagnostic)]` can only be used on structs", + "`#[derive(DiagnosticHandler)]` can only be used on structs", ) .emit(); @@ -81,15 +81,15 @@ impl<'a> SessionDiagnosticDerive<'a> { }; structure.gen_impl(quote! { - gen impl<'__session_diagnostic_sess, G> - rustc_errors::SessionDiagnostic<'__session_diagnostic_sess, G> + gen impl<'__diagnostic_handler_sess, G> + rustc_errors::IntoDiagnostic<'__diagnostic_handler_sess, G> for @Self where G: rustc_errors::EmissionGuarantee { fn into_diagnostic( self, - #sess: &'__session_diagnostic_sess rustc_errors::Handler - ) -> rustc_errors::DiagnosticBuilder<'__session_diagnostic_sess, G> { + #handler: &'__diagnostic_handler_sess rustc_errors::Handler + ) -> rustc_errors::DiagnosticBuilder<'__diagnostic_handler_sess, G> { use rustc_errors::IntoDiagnosticArg; #implementation } diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index 2a4fe48a8ac..4af3fd23624 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -21,12 +21,12 @@ use synstructure::{BindingInfo, Structure}; /// What kind of diagnostic is being derived - a fatal/error/warning or a lint? #[derive(Copy, Clone, PartialEq, Eq)] pub(crate) enum DiagnosticDeriveKind { - SessionDiagnostic, + DiagnosticHandler, LintDiagnostic, } /// Tracks persistent information required for building up individual calls to diagnostic methods -/// for generated diagnostic derives - both `SessionDiagnostic` for fatal/errors/warnings and +/// for generated diagnostic derives - both `DiagnosticHandler` for fatal/errors/warnings and /// `LintDiagnostic` for lints. pub(crate) struct DiagnosticDeriveBuilder { /// The identifier to use for the generated `DiagnosticBuilder` instance. @@ -333,7 +333,7 @@ impl DiagnosticDeriveBuilder { } "primary_span" => { match self.kind { - DiagnosticDeriveKind::SessionDiagnostic => { + DiagnosticDeriveKind::DiagnosticHandler => { report_error_if_not_applied_to_span(attr, &info)?; Ok(quote! { diff --git a/compiler/rustc_macros/src/diagnostics/mod.rs b/compiler/rustc_macros/src/diagnostics/mod.rs index 2ff21e18ff8..162089c881e 100644 --- a/compiler/rustc_macros/src/diagnostics/mod.rs +++ b/compiler/rustc_macros/src/diagnostics/mod.rs @@ -12,7 +12,7 @@ use quote::format_ident; use subdiagnostic::SessionSubdiagnosticDerive; use synstructure::Structure; -/// Implements `#[derive(SessionDiagnostic)]`, which allows for errors to be specified as a struct, +/// Implements `#[derive(DiagnosticHandler)]`, which allows for errors to be specified as a struct, /// independent from the actual diagnostics emitting code. /// /// ```ignore (rust) @@ -22,7 +22,7 @@ use synstructure::Structure; /// # use rustc_span::{symbol::Ident, Span}; /// # extern crate rust_middle; /// # use rustc_middle::ty::Ty; -/// #[derive(SessionDiagnostic)] +/// #[derive(DiagnosticHandler)] /// #[diag(borrowck::move_out_of_borrow, code = "E0505")] /// pub struct MoveOutOfBorrowError<'tcx> { /// pub name: Ident, @@ -56,10 +56,10 @@ use synstructure::Structure; /// }); /// ``` /// -/// See rustc dev guide for more examples on using the `#[derive(SessionDiagnostic)]`: +/// See rustc dev guide for more examples on using the `#[derive(DiagnosticHandler)]`: /// pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream { - SessionDiagnosticDerive::new(format_ident!("diag"), format_ident!("sess"), s).into_tokens() + SessionDiagnosticDerive::new(format_ident!("diag"), format_ident!("handler"), s).into_tokens() } /// Implements `#[derive(LintDiagnostic)]`, which allows for lints to be specified as a struct, diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index 2c027d754da..13305782ff1 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -127,7 +127,7 @@ decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_fo decl_derive!([TypeVisitable, attributes(type_visitable)] => type_visitable::type_visitable_derive); decl_derive!([Lift, attributes(lift)] => lift::lift_derive); decl_derive!( - [SessionDiagnostic, attributes( + [DiagnosticHandler, attributes( // struct attributes diag, help, diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 8cbcadb625a..0a5973ca1aa 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -3,49 +3,49 @@ use std::{ path::{Path, PathBuf}, }; -use rustc_errors::{error_code, ErrorGuaranteed, SessionDiagnostic}; -use rustc_macros::SessionDiagnostic; +use rustc_errors::{error_code, IntoDiagnostic, ErrorGuaranteed}; +use rustc_macros::DiagnosticHandler; use rustc_session::config; use rustc_span::{sym, Span, Symbol}; use rustc_target::spec::{PanicStrategy, TargetTriple}; use crate::locator::CrateFlavor; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::rlib_required)] pub struct RlibRequired { pub crate_name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::lib_required)] pub struct LibRequired<'a> { pub crate_name: Symbol, pub kind: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::crate_dep_multiple)] #[help] pub struct CrateDepMultiple { pub crate_name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::two_panic_runtimes)] pub struct TwoPanicRuntimes { pub prev_name: Symbol, pub cur_name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::bad_panic_strategy)] pub struct BadPanicStrategy { pub runtime: Symbol, pub strategy: PanicStrategy, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::required_panic_strategy)] pub struct RequiredPanicStrategy { pub crate_name: Symbol, @@ -53,7 +53,7 @@ pub struct RequiredPanicStrategy { pub desired_strategy: PanicStrategy, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::incompatible_panic_in_drop_strategy)] pub struct IncompatiblePanicInDropStrategy { pub crate_name: Symbol, @@ -61,56 +61,56 @@ pub struct IncompatiblePanicInDropStrategy { pub desired_strategy: PanicStrategy, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::multiple_names_in_link)] pub struct MultipleNamesInLink { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::multiple_kinds_in_link)] pub struct MultipleKindsInLink { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::link_name_form)] pub struct LinkNameForm { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::link_kind_form)] pub struct LinkKindForm { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::link_modifiers_form)] pub struct LinkModifiersForm { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::link_cfg_form)] pub struct LinkCfgForm { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::wasm_import_form)] pub struct WasmImportForm { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::empty_link_name, code = "E0454")] pub struct EmptyLinkName { #[primary_span] @@ -118,21 +118,21 @@ pub struct EmptyLinkName { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::link_framework_apple, code = "E0455")] pub struct LinkFrameworkApple { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::framework_only_windows, code = "E0455")] pub struct FrameworkOnlyWindows { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::unknown_link_kind, code = "E0458")] pub struct UnknownLinkKind<'a> { #[primary_span] @@ -141,49 +141,49 @@ pub struct UnknownLinkKind<'a> { pub kind: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::multiple_link_modifiers)] pub struct MultipleLinkModifiers { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::multiple_cfgs)] pub struct MultipleCfgs { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::link_cfg_single_predicate)] pub struct LinkCfgSinglePredicate { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::multiple_wasm_import)] pub struct MultipleWasmImport { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::unexpected_link_arg)] pub struct UnexpectedLinkArg { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::invalid_link_modifier)] pub struct InvalidLinkModifier { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::multiple_modifiers)] pub struct MultipleModifiers<'a> { #[primary_span] @@ -191,28 +191,28 @@ pub struct MultipleModifiers<'a> { pub modifier: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::bundle_needs_static)] pub struct BundleNeedsStatic { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::whole_archive_needs_static)] pub struct WholeArchiveNeedsStatic { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::as_needed_compatibility)] pub struct AsNeededCompatibility { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::unknown_link_modifier)] pub struct UnknownLinkModifier<'a> { #[primary_span] @@ -220,14 +220,14 @@ pub struct UnknownLinkModifier<'a> { pub modifier: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::incompatible_wasm_link)] pub struct IncompatibleWasmLink { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::link_requires_name, code = "E0459")] pub struct LinkRequiresName { #[primary_span] @@ -235,105 +235,105 @@ pub struct LinkRequiresName { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::raw_dylib_no_nul)] pub struct RawDylibNoNul { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::link_ordinal_raw_dylib)] pub struct LinkOrdinalRawDylib { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::lib_framework_apple)] pub struct LibFrameworkApple; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::empty_renaming_target)] pub struct EmptyRenamingTarget<'a> { pub lib_name: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::renaming_no_link)] pub struct RenamingNoLink<'a> { pub lib_name: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::multiple_renamings)] pub struct MultipleRenamings<'a> { pub lib_name: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::no_link_mod_override)] pub struct NoLinkModOverride { #[primary_span] pub span: Option, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::unsupported_abi_i686)] pub struct UnsupportedAbiI686 { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::unsupported_abi)] pub struct UnsupportedAbi { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::fail_create_file_encoder)] pub struct FailCreateFileEncoder { pub err: Error, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::fail_seek_file)] pub struct FailSeekFile { pub err: Error, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::fail_write_file)] pub struct FailWriteFile { pub err: Error, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::crate_not_panic_runtime)] pub struct CrateNotPanicRuntime { pub crate_name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::no_panic_strategy)] pub struct NoPanicStrategy { pub crate_name: Symbol, pub strategy: PanicStrategy, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::profiler_builtins_needs_core)] pub struct ProfilerBuiltinsNeedsCore; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::not_profiler_runtime)] pub struct NotProfilerRuntime { pub crate_name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::no_multiple_global_alloc)] pub struct NoMultipleGlobalAlloc { #[primary_span] @@ -343,18 +343,18 @@ pub struct NoMultipleGlobalAlloc { pub span1: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::conflicting_global_alloc)] pub struct ConflictingGlobalAlloc { pub crate_name: Symbol, pub other_crate_name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::global_alloc_required)] pub struct GlobalAllocRequired; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::no_transitive_needs_dep)] pub struct NoTransitiveNeedsDep<'a> { pub crate_name: Symbol, @@ -362,7 +362,7 @@ pub struct NoTransitiveNeedsDep<'a> { pub deps_crate_name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::failed_write_error)] pub struct FailedWriteError { pub filename: PathBuf, @@ -381,20 +381,20 @@ pub struct FailedCreateTempdir { pub err: Error, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::failed_create_file)] pub struct FailedCreateFile<'a> { pub filename: &'a Path, pub err: Error, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::failed_create_encoded_metadata)] pub struct FailedCreateEncodedMetadata { pub err: Error, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::non_ascii_name)] pub struct NonAsciiName { #[primary_span] @@ -402,7 +402,7 @@ pub struct NonAsciiName { pub crate_name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::extern_location_not_exist)] pub struct ExternLocationNotExist<'a> { #[primary_span] @@ -411,7 +411,7 @@ pub struct ExternLocationNotExist<'a> { pub location: &'a Path, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::extern_location_not_file)] pub struct ExternLocationNotFile<'a> { #[primary_span] @@ -427,7 +427,7 @@ pub(crate) struct MultipleCandidates { pub candidates: Vec, } -impl SessionDiagnostic<'_> for MultipleCandidates { +impl IntoDiagnostic<'_> for MultipleCandidates { fn into_diagnostic( self, handler: &'_ rustc_errors::Handler, @@ -444,7 +444,7 @@ impl SessionDiagnostic<'_> for MultipleCandidates { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::multiple_matching_crates, code = "E0464")] #[note] pub struct MultipleMatchingCrates { @@ -454,7 +454,7 @@ pub struct MultipleMatchingCrates { pub candidates: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::symbol_conflicts_current, code = "E0519")] pub struct SymbolConflictsCurrent { #[primary_span] @@ -462,7 +462,7 @@ pub struct SymbolConflictsCurrent { pub crate_name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::symbol_conflicts_others, code = "E0523")] pub struct SymbolConflictsOthers { #[primary_span] @@ -470,7 +470,7 @@ pub struct SymbolConflictsOthers { pub crate_name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::stable_crate_id_collision)] pub struct StableCrateIdCollision { #[primary_span] @@ -479,7 +479,7 @@ pub struct StableCrateIdCollision { pub crate_name1: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::dl_error)] pub struct DlError { #[primary_span] @@ -487,7 +487,7 @@ pub struct DlError { pub err: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::newer_crate_version, code = "E0460")] #[note] #[note(metadata::found_crate_versions)] @@ -499,7 +499,7 @@ pub struct NewerCrateVersion { pub found_crates: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::no_crate_with_triple, code = "E0461")] #[note(metadata::found_crate_versions)] pub struct NoCrateWithTriple<'a> { @@ -511,7 +511,7 @@ pub struct NoCrateWithTriple<'a> { pub found_crates: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::found_staticlib, code = "E0462")] #[note(metadata::found_crate_versions)] #[help] @@ -523,7 +523,7 @@ pub struct FoundStaticlib { pub found_crates: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::incompatible_rustc, code = "E0514")] #[note(metadata::found_crate_versions)] #[help] @@ -543,7 +543,7 @@ pub struct InvalidMetadataFiles { pub crate_rejections: Vec, } -impl SessionDiagnostic<'_> for InvalidMetadataFiles { +impl IntoDiagnostic<'_> for InvalidMetadataFiles { fn into_diagnostic( self, handler: &'_ rustc_errors::Handler, @@ -571,7 +571,7 @@ pub struct CannotFindCrate { pub locator_triple: TargetTriple, } -impl SessionDiagnostic<'_> for CannotFindCrate { +impl IntoDiagnostic<'_> for CannotFindCrate { fn into_diagnostic( self, handler: &'_ rustc_errors::Handler, @@ -617,7 +617,7 @@ impl SessionDiagnostic<'_> for CannotFindCrate { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::no_dylib_plugin, code = "E0457")] pub struct NoDylibPlugin { #[primary_span] @@ -625,7 +625,7 @@ pub struct NoDylibPlugin { pub crate_name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::crate_location_unknown_type)] pub struct CrateLocationUnknownType<'a> { #[primary_span] @@ -633,7 +633,7 @@ pub struct CrateLocationUnknownType<'a> { pub path: &'a Path, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::lib_filename_form)] pub struct LibFilenameForm<'a> { #[primary_span] @@ -642,28 +642,28 @@ pub struct LibFilenameForm<'a> { pub dll_suffix: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::multiple_import_name_type)] pub struct MultipleImportNameType { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::import_name_type_form)] pub struct ImportNameTypeForm { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::import_name_type_x86)] pub struct ImportNameTypeX86 { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::unknown_import_name_type)] pub struct UnknownImportNameType<'a> { #[primary_span] @@ -671,7 +671,7 @@ pub struct UnknownImportNameType<'a> { pub import_name_type: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(metadata::import_name_type_raw)] pub struct ImportNameTypeRaw { #[primary_span] diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index 18b31a75bcc..effda9c0557 100644 --- a/compiler/rustc_middle/src/error.rs +++ b/compiler/rustc_middle/src/error.rs @@ -1,9 +1,9 @@ -use rustc_macros::SessionDiagnostic; +use rustc_macros::DiagnosticHandler; use rustc_span::Span; use crate::ty::Ty; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(middle::drop_check_overflow, code = "E0320")] #[note] pub struct DropCheckOverflow<'tcx> { @@ -13,7 +13,7 @@ pub struct DropCheckOverflow<'tcx> { pub overflow_ty: Ty<'tcx>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(middle::opaque_hidden_type_mismatch)] pub struct OpaqueHiddenTypeMismatch<'tcx> { pub self_ty: Ty<'tcx>, @@ -39,7 +39,7 @@ pub enum TypeMismatchReason { }, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(middle::limit_invalid)] pub struct LimitInvalid<'a> { #[primary_span] diff --git a/compiler/rustc_mir_dataflow/src/errors.rs b/compiler/rustc_mir_dataflow/src/errors.rs index cc14257876c..0d36abed2c0 100644 --- a/compiler/rustc_mir_dataflow/src/errors.rs +++ b/compiler/rustc_mir_dataflow/src/errors.rs @@ -1,21 +1,21 @@ -use rustc_macros::SessionDiagnostic; +use rustc_macros::DiagnosticHandler; use rustc_span::{Span, Symbol}; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(mir_dataflow::path_must_end_in_filename)] pub(crate) struct PathMustEndInFilename { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(mir_dataflow::unknown_formatter)] pub(crate) struct UnknownFormatter { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(mir_dataflow::duplicate_values_for)] pub(crate) struct DuplicateValuesFor { #[primary_span] @@ -23,7 +23,7 @@ pub(crate) struct DuplicateValuesFor { pub name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(mir_dataflow::requires_an_argument)] pub(crate) struct RequiresAnArgument { #[primary_span] @@ -31,39 +31,39 @@ pub(crate) struct RequiresAnArgument { pub name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(mir_dataflow::stop_after_dataflow_ended_compilation)] pub(crate) struct StopAfterDataFlowEndedCompilation; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(mir_dataflow::peek_must_be_place_or_ref_place)] pub(crate) struct PeekMustBePlaceOrRefPlace { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(mir_dataflow::peek_must_be_not_temporary)] pub(crate) struct PeekMustBeNotTemporary { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(mir_dataflow::peek_bit_not_set)] pub(crate) struct PeekBitNotSet { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(mir_dataflow::peek_argument_not_a_local)] pub(crate) struct PeekArgumentNotALocal { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(mir_dataflow::peek_argument_untracked)] pub(crate) struct PeekArgumentUntracked { #[primary_span] diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs index 883380dca08..150a702dc24 100644 --- a/compiler/rustc_monomorphize/src/errors.rs +++ b/compiler/rustc_monomorphize/src/errors.rs @@ -1,11 +1,11 @@ use std::path::PathBuf; +use rustc_errors::IntoDiagnostic; use rustc_errors::ErrorGuaranteed; -use rustc_errors::SessionDiagnostic; -use rustc_macros::{LintDiagnostic, SessionDiagnostic}; +use rustc_macros::{DiagnosticHandler, LintDiagnostic}; use rustc_span::Span; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(monomorphize::recursion_limit)] pub struct RecursionLimit { #[primary_span] @@ -19,7 +19,7 @@ pub struct RecursionLimit { pub path: PathBuf, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(monomorphize::type_length_limit)] #[help(monomorphize::consider_type_length_limit)] pub struct TypeLengthLimit { @@ -32,7 +32,7 @@ pub struct TypeLengthLimit { pub type_length: usize, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(monomorphize::requires_lang_item)] pub struct RequiresLangItem { pub lang_item: String, @@ -44,7 +44,7 @@ pub struct UnusedGenericParams { pub param_names: Vec, } -impl SessionDiagnostic<'_> for UnusedGenericParams { +impl IntoDiagnostic<'_> for UnusedGenericParams { fn into_diagnostic( self, handler: &'_ rustc_errors::Handler, @@ -72,11 +72,11 @@ pub struct LargeAssignmentsLint { pub limit: u64, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(monomorphize::unknown_partition_strategy)] pub struct UnknownPartitionStrategy; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(monomorphize::symbol_already_defined)] pub struct SymbolAlreadyDefined { #[primary_span] diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index a65f523a0f4..02148193cf0 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -20,7 +20,7 @@ use rustc_errors::{ fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult, }; use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed}; -use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::{Span, SpanSnippetError, DUMMY_SP}; @@ -242,7 +242,7 @@ impl MultiSugg { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::maybe_report_ambiguous_plus)] struct AmbiguousPlus { pub sum_ty: String, @@ -251,7 +251,7 @@ struct AmbiguousPlus { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::maybe_recover_from_bad_type_plus, code = "E0178")] struct BadTypePlus { pub ty: String, @@ -285,7 +285,7 @@ pub enum BadTypePlusSub { }, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::maybe_recover_from_bad_qpath_stage_2)] struct BadQPathStage2 { #[primary_span] @@ -294,7 +294,7 @@ struct BadQPathStage2 { ty: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::incorrect_semicolon)] struct IncorrectSemicolon<'a> { #[primary_span] @@ -305,7 +305,7 @@ struct IncorrectSemicolon<'a> { name: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::incorrect_use_of_await)] struct IncorrectUseOfAwait { #[primary_span] @@ -313,7 +313,7 @@ struct IncorrectUseOfAwait { span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::incorrect_use_of_await)] struct IncorrectAwait { #[primary_span] @@ -324,7 +324,7 @@ struct IncorrectAwait { question_mark: &'static str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::in_in_typo)] struct InInTypo { #[primary_span] @@ -333,7 +333,7 @@ struct InInTypo { sugg_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::invalid_variable_declaration)] pub struct InvalidVariableDeclaration { #[primary_span] @@ -362,7 +362,7 @@ pub enum InvalidVariableDeclarationSub { UseLetNotVar(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::invalid_comparison_operator)] pub(crate) struct InvalidComparisonOperator { #[primary_span] @@ -389,7 +389,7 @@ pub(crate) enum InvalidComparisonOperatorSub { Spaceship(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::invalid_logical_operator)] #[note] pub(crate) struct InvalidLogicalOperator { @@ -416,7 +416,7 @@ pub(crate) enum InvalidLogicalOperatorSub { Disjunction(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::tilde_is_not_unary_operator)] pub(crate) struct TildeAsUnaryOperator( #[primary_span] @@ -424,7 +424,7 @@ pub(crate) struct TildeAsUnaryOperator( pub Span, ); -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::unexpected_token_after_not)] pub(crate) struct NotAsNegationOperator { #[primary_span] @@ -458,7 +458,7 @@ pub enum NotAsNegationOperatorSub { SuggestNotLogical(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::malformed_loop_label)] pub(crate) struct MalformedLoopLabel { #[primary_span] @@ -467,7 +467,7 @@ pub(crate) struct MalformedLoopLabel { pub correct_label: Ident, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::lifetime_in_borrow_expression)] pub(crate) struct LifetimeInBorrowExpression { #[primary_span] @@ -477,15 +477,15 @@ pub(crate) struct LifetimeInBorrowExpression { pub lifetime_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::field_expression_with_generic)] pub(crate) struct FieldExpressionWithGeneric(#[primary_span] pub Span); -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::macro_invocation_with_qualified_path)] pub(crate) struct MacroInvocationWithQualifiedPath(#[primary_span] pub Span); -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::unexpected_token_after_label)] pub(crate) struct UnexpectedTokenAfterLabel( #[primary_span] @@ -493,7 +493,7 @@ pub(crate) struct UnexpectedTokenAfterLabel( pub Span, ); -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::require_colon_after_labeled_expression)] #[note] pub(crate) struct RequireColonAfterLabeledExpression { @@ -505,7 +505,7 @@ pub(crate) struct RequireColonAfterLabeledExpression { pub label_end: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::do_catch_syntax_removed)] #[note] pub(crate) struct DoCatchSyntaxRemoved { @@ -514,7 +514,7 @@ pub(crate) struct DoCatchSyntaxRemoved { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::float_literal_requires_integer_part)] pub(crate) struct FloatLiteralRequiresIntegerPart { #[primary_span] @@ -523,7 +523,7 @@ pub(crate) struct FloatLiteralRequiresIntegerPart { pub correct: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::invalid_int_literal_width)] #[help] pub(crate) struct InvalidIntLiteralWidth { @@ -532,7 +532,7 @@ pub(crate) struct InvalidIntLiteralWidth { pub width: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::invalid_num_literal_base_prefix)] #[note] pub(crate) struct InvalidNumLiteralBasePrefix { @@ -542,7 +542,7 @@ pub(crate) struct InvalidNumLiteralBasePrefix { pub fixed: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::invalid_num_literal_suffix)] #[help] pub(crate) struct InvalidNumLiteralSuffix { @@ -552,7 +552,7 @@ pub(crate) struct InvalidNumLiteralSuffix { pub suffix: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::invalid_float_literal_width)] #[help] pub(crate) struct InvalidFloatLiteralWidth { @@ -561,7 +561,7 @@ pub(crate) struct InvalidFloatLiteralWidth { pub width: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::invalid_float_literal_suffix)] #[help] pub(crate) struct InvalidFloatLiteralSuffix { @@ -571,14 +571,14 @@ pub(crate) struct InvalidFloatLiteralSuffix { pub suffix: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::int_literal_too_large)] pub(crate) struct IntLiteralTooLarge { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::missing_semicolon_before_array)] pub(crate) struct MissingSemicolonBeforeArray { #[primary_span] @@ -587,7 +587,7 @@ pub(crate) struct MissingSemicolonBeforeArray { pub semicolon: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::invalid_block_macro_segment)] pub(crate) struct InvalidBlockMacroSegment { #[primary_span] @@ -596,7 +596,7 @@ pub(crate) struct InvalidBlockMacroSegment { pub context: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::if_expression_missing_then_block)] pub(crate) struct IfExpressionMissingThenBlock { #[primary_span] @@ -613,7 +613,7 @@ pub(crate) enum IfExpressionMissingThenBlockSub { AddThenBlock(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::if_expression_missing_condition)] pub(crate) struct IfExpressionMissingCondition { #[primary_span] @@ -623,14 +623,14 @@ pub(crate) struct IfExpressionMissingCondition { pub block_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::expected_expression_found_let)] pub(crate) struct ExpectedExpressionFoundLet { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::expected_else_block)] pub(crate) struct ExpectedElseBlock { #[primary_span] @@ -642,7 +642,7 @@ pub(crate) struct ExpectedElseBlock { pub condition_start: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::outer_attribute_not_allowed_on_if_else)] pub(crate) struct OuterAttributeNotAllowedOnIfElse { #[primary_span] @@ -659,7 +659,7 @@ pub(crate) struct OuterAttributeNotAllowedOnIfElse { pub attributes: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::missing_in_in_for_loop)] pub(crate) struct MissingInInForLoop { #[primary_span] @@ -677,7 +677,7 @@ pub(crate) enum MissingInInForLoopSub { AddIn(#[primary_span] Span), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::missing_comma_after_match_arm)] pub(crate) struct MissingCommaAfterMatchArm { #[primary_span] @@ -685,7 +685,7 @@ pub(crate) struct MissingCommaAfterMatchArm { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::catch_after_try)] #[help] pub(crate) struct CatchAfterTry { @@ -693,7 +693,7 @@ pub(crate) struct CatchAfterTry { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::comma_after_base_struct)] #[note] pub(crate) struct CommaAfterBaseStruct { @@ -703,7 +703,7 @@ pub(crate) struct CommaAfterBaseStruct { pub comma: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::eq_field_init)] pub(crate) struct EqFieldInit { #[primary_span] @@ -712,7 +712,7 @@ pub(crate) struct EqFieldInit { pub eq: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::dotdotdot)] pub(crate) struct DotDotDot { #[primary_span] @@ -721,7 +721,7 @@ pub(crate) struct DotDotDot { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::left_arrow_operator)] pub(crate) struct LeftArrowOperator { #[primary_span] @@ -729,7 +729,7 @@ pub(crate) struct LeftArrowOperator { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::remove_let)] pub(crate) struct RemoveLet { #[primary_span] diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index bb93f1cc260..ae77961b7bc 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -36,7 +36,7 @@ use rustc_ast::{AnonConst, BinOp, BinOpKind, FnDecl, FnRetTy, MacCall, Param, Ty use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits}; use rustc_ast::{ClosureBinder, StmtKind}; use rustc_ast_pretty::pprust; -use rustc_errors::SessionDiagnostic; +use rustc_errors::IntoDiagnostic; use rustc_errors::{Applicability, Diagnostic, PResult}; use rustc_session::lint::builtin::BREAK_WITH_LABEL_AND_LOOP; use rustc_session::lint::BuiltinLintDiagnostics; diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 96cc8ae988c..ade5927be8e 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1,5 +1,5 @@ use rustc_errors::{Applicability, MultiSpan}; -use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{DiagnosticHandler, LintDiagnostic, SessionSubdiagnostic}; use rustc_span::{Span, Symbol}; #[derive(LintDiagnostic)] @@ -32,7 +32,7 @@ pub struct IgnoredInlineAttrFnProto; #[note] pub struct IgnoredInlineAttrConstants; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::inline_not_fn_or_closure, code = "E0518")] pub struct InlineNotFnOrClosure { #[primary_span] @@ -53,7 +53,7 @@ pub struct IgnoredNoCoveragePropagate; #[diag(passes::no_coverage_fn_defn)] pub struct IgnoredNoCoverageFnDefn; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::no_coverage_not_coverable, code = "E0788")] pub struct IgnoredNoCoverageNotCoverable { #[primary_span] @@ -62,7 +62,7 @@ pub struct IgnoredNoCoverageNotCoverable { pub defn_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::should_be_applied_to_fn)] pub struct AttrShouldBeAppliedToFn { #[primary_span] @@ -71,14 +71,14 @@ pub struct AttrShouldBeAppliedToFn { pub defn_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::naked_tracked_caller, code = "E0736")] pub struct NakedTrackedCaller { #[primary_span] pub attr_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::should_be_applied_to_fn, code = "E0739")] pub struct TrackedCallerWrongLocation { #[primary_span] @@ -87,7 +87,7 @@ pub struct TrackedCallerWrongLocation { pub defn_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::should_be_applied_to_struct_enum, code = "E0701")] pub struct NonExhaustiveWrongLocation { #[primary_span] @@ -96,7 +96,7 @@ pub struct NonExhaustiveWrongLocation { pub defn_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::should_be_applied_to_trait)] pub struct AttrShouldBeAppliedToTrait { #[primary_span] @@ -109,7 +109,7 @@ pub struct AttrShouldBeAppliedToTrait { #[diag(passes::target_feature_on_statement)] pub struct TargetFeatureOnStatement; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::should_be_applied_to_static)] pub struct AttrShouldBeAppliedToStatic { #[primary_span] @@ -118,7 +118,7 @@ pub struct AttrShouldBeAppliedToStatic { pub defn_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_expect_str)] pub struct DocExpectStr<'a> { #[primary_span] @@ -126,7 +126,7 @@ pub struct DocExpectStr<'a> { pub attr_name: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_alias_empty)] pub struct DocAliasEmpty<'a> { #[primary_span] @@ -134,7 +134,7 @@ pub struct DocAliasEmpty<'a> { pub attr_str: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_alias_bad_char)] pub struct DocAliasBadChar<'a> { #[primary_span] @@ -143,7 +143,7 @@ pub struct DocAliasBadChar<'a> { pub char_: char, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_alias_start_end)] pub struct DocAliasStartEnd<'a> { #[primary_span] @@ -151,7 +151,7 @@ pub struct DocAliasStartEnd<'a> { pub attr_str: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_alias_bad_location)] pub struct DocAliasBadLocation<'a> { #[primary_span] @@ -160,7 +160,7 @@ pub struct DocAliasBadLocation<'a> { pub location: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_alias_not_an_alias)] pub struct DocAliasNotAnAlias<'a> { #[primary_span] @@ -175,35 +175,35 @@ pub struct DocAliasDuplicated { pub first_defn: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_alias_not_string_literal)] pub struct DocAliasNotStringLiteral { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_alias_malformed)] pub struct DocAliasMalformed { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_keyword_empty_mod)] pub struct DocKeywordEmptyMod { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_keyword_not_mod)] pub struct DocKeywordNotMod { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_keyword_invalid_ident)] pub struct DocKeywordInvalidIdent { #[primary_span] @@ -211,21 +211,21 @@ pub struct DocKeywordInvalidIdent { pub doc_keyword: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_fake_variadic_not_valid)] pub struct DocFakeVariadicNotValid { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_keyword_only_impl)] pub struct DocKeywordOnlyImpl { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_inline_conflict)] #[help] pub struct DocKeywordConflict { @@ -243,7 +243,7 @@ pub struct DocInlineOnlyUse { pub item_span: Option, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::doc_attr_not_crate_level)] pub struct DocAttrNotCrateLevel<'a> { #[primary_span] @@ -295,7 +295,7 @@ pub struct DocTestUnknownInclude { #[diag(passes::doc_invalid)] pub struct DocInvalid; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::pass_by_value)] pub struct PassByValue { #[primary_span] @@ -304,7 +304,7 @@ pub struct PassByValue { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::allow_incoherent_impl)] pub struct AllowIncoherentImpl { #[primary_span] @@ -313,7 +313,7 @@ pub struct AllowIncoherentImpl { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::has_incoherent_inherent_impl)] pub struct HasIncoherentInherentImpl { #[primary_span] @@ -336,7 +336,7 @@ pub struct MustUseNoEffect { pub target: rustc_hir::Target, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::must_not_suspend)] pub struct MustNotSuspend { #[primary_span] @@ -372,7 +372,7 @@ pub struct LinkName<'a> { pub value: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::no_link)] pub struct NoLink { #[primary_span] @@ -381,7 +381,7 @@ pub struct NoLink { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::export_name)] pub struct ExportName { #[primary_span] @@ -390,7 +390,7 @@ pub struct ExportName { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::rustc_layout_scalar_valid_range_not_struct)] pub struct RustcLayoutScalarValidRangeNotStruct { #[primary_span] @@ -399,14 +399,14 @@ pub struct RustcLayoutScalarValidRangeNotStruct { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::rustc_layout_scalar_valid_range_arg)] pub struct RustcLayoutScalarValidRangeArg { #[primary_span] pub attr_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::rustc_legacy_const_generics_only)] pub struct RustcLegacyConstGenericsOnly { #[primary_span] @@ -415,7 +415,7 @@ pub struct RustcLegacyConstGenericsOnly { pub param_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::rustc_legacy_const_generics_index)] pub struct RustcLegacyConstGenericsIndex { #[primary_span] @@ -424,7 +424,7 @@ pub struct RustcLegacyConstGenericsIndex { pub generics_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::rustc_legacy_const_generics_index_exceed)] pub struct RustcLegacyConstGenericsIndexExceed { #[primary_span] @@ -433,14 +433,14 @@ pub struct RustcLegacyConstGenericsIndexExceed { pub arg_count: usize, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::rustc_legacy_const_generics_index_negative)] pub struct RustcLegacyConstGenericsIndexNegative { #[primary_span] pub invalid_args: Vec, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::rustc_dirty_clean)] pub struct RustcDirtyClean { #[primary_span] @@ -475,7 +475,7 @@ pub struct NoMangle { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::repr_ident, code = "E0565")] pub struct ReprIdent { #[primary_span] @@ -486,21 +486,21 @@ pub struct ReprIdent { #[diag(passes::repr_conflicting, code = "E0566")] pub struct ReprConflicting; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::used_static)] pub struct UsedStatic { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::used_compiler_linker)] pub struct UsedCompilerLinker { #[primary_span] pub spans: Vec, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::allow_internal_unstable)] pub struct AllowInternalUnstable { #[primary_span] @@ -509,14 +509,14 @@ pub struct AllowInternalUnstable { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::debug_visualizer_placement)] pub struct DebugVisualizerPlacement { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::debug_visualizer_invalid)] #[note(passes::note_1)] #[note(passes::note_2)] @@ -526,7 +526,7 @@ pub struct DebugVisualizerInvalid { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::rustc_allow_const_fn_unstable)] pub struct RustcAllowConstFnUnstable { #[primary_span] @@ -535,7 +535,7 @@ pub struct RustcAllowConstFnUnstable { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::rustc_std_internal_symbol)] pub struct RustcStdInternalSymbol { #[primary_span] @@ -544,21 +544,21 @@ pub struct RustcStdInternalSymbol { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::const_trait)] pub struct ConstTrait { #[primary_span] pub attr_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::link_ordinal)] pub struct LinkOrdinal { #[primary_span] pub attr_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::stability_promotable)] pub struct StabilityPromotable { #[primary_span] @@ -602,7 +602,7 @@ pub struct Unused { pub note: UnusedNote, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::non_exported_macro_invalid_attrs, code = "E0518")] pub struct NonExportedMacroInvalidAttrs { #[primary_span] @@ -621,7 +621,7 @@ pub struct UnusedDuplicate { pub warning: Option<()>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::unused_multiple)] pub struct UnusedMultiple { #[primary_span] @@ -632,7 +632,7 @@ pub struct UnusedMultiple { pub name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::rustc_lint_opt_ty)] pub struct RustcLintOptTy { #[primary_span] @@ -641,7 +641,7 @@ pub struct RustcLintOptTy { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(passes::rustc_lint_opt_deny_field_access)] pub struct RustcLintOptDenyFieldAccess { #[primary_span] diff --git a/compiler/rustc_plugin_impl/src/errors.rs b/compiler/rustc_plugin_impl/src/errors.rs index 2bdb6e4feca..0b2c09f9e1d 100644 --- a/compiler/rustc_plugin_impl/src/errors.rs +++ b/compiler/rustc_plugin_impl/src/errors.rs @@ -1,9 +1,9 @@ //! Errors emitted by plugin_impl -use rustc_macros::SessionDiagnostic; +use rustc_macros::DiagnosticHandler; use rustc_span::Span; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(plugin_impl::load_plugin_error)] pub struct LoadPluginError { #[primary_span] @@ -11,7 +11,7 @@ pub struct LoadPluginError { pub msg: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(plugin_impl::malformed_plugin_attribute, code = "E0498")] pub struct MalformedPluginAttribute { #[primary_span] diff --git a/compiler/rustc_privacy/src/errors.rs b/compiler/rustc_privacy/src/errors.rs index 705ad567aa7..56a2cb059b5 100644 --- a/compiler/rustc_privacy/src/errors.rs +++ b/compiler/rustc_privacy/src/errors.rs @@ -1,8 +1,8 @@ use rustc_errors::DiagnosticArgFromDisplay; -use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{DiagnosticHandler, LintDiagnostic, SessionSubdiagnostic}; use rustc_span::{Span, Symbol}; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(privacy::field_is_private, code = "E0451")] pub struct FieldIsPrivate { #[primary_span] @@ -29,7 +29,7 @@ pub enum FieldIsPrivateLabel { }, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(privacy::item_is_private)] pub struct ItemIsPrivate<'a> { #[primary_span] @@ -39,7 +39,7 @@ pub struct ItemIsPrivate<'a> { pub descr: DiagnosticArgFromDisplay<'a>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(privacy::unnamed_item_is_private)] pub struct UnnamedItemIsPrivate { #[primary_span] @@ -48,7 +48,7 @@ pub struct UnnamedItemIsPrivate { } // Duplicate of `InPublicInterface` but with a different error code, shares the same slug. -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(privacy::in_public_interface, code = "E0445")] pub struct InPublicInterfaceTraits<'a> { #[primary_span] @@ -62,7 +62,7 @@ pub struct InPublicInterfaceTraits<'a> { } // Duplicate of `InPublicInterfaceTraits` but with a different error code, shares the same slug. -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(privacy::in_public_interface, code = "E0446")] pub struct InPublicInterface<'a> { #[primary_span] @@ -75,7 +75,7 @@ pub struct InPublicInterface<'a> { pub vis_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(privacy::report_effective_visibility)] pub struct ReportEffectiveVisibility { #[primary_span] diff --git a/compiler/rustc_query_system/src/error.rs b/compiler/rustc_query_system/src/error.rs index bececca7585..97a74517f68 100644 --- a/compiler/rustc_query_system/src/error.rs +++ b/compiler/rustc_query_system/src/error.rs @@ -1,4 +1,4 @@ -use rustc_errors::AddSubdiagnostic; +use rustc_errors::AddToDiagnostic; use rustc_session::Limit; use rustc_span::{Span, Symbol}; @@ -7,7 +7,7 @@ pub struct CycleStack { pub desc: String, } -impl AddSubdiagnostic for CycleStack { +impl AddToDiagnostic for CycleStack { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { diag.span_note(self.span, &format!("...which requires {}...", self.desc)); } @@ -46,7 +46,7 @@ pub struct CycleUsage { pub usage: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(query_system::cycle, code = "E0391")] pub struct Cycle { #[primary_span] @@ -62,11 +62,11 @@ pub struct Cycle { pub cycle_usage: Option, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(query_system::reentrant)] pub struct Reentrant; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(query_system::increment_compilation)] #[help] #[note(query_system::increment_compilation_note1)] @@ -76,7 +76,7 @@ pub struct IncrementCompilation { pub dep_node: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[help] #[diag(query_system::query_overflow)] pub struct QueryOverflow { @@ -88,7 +88,7 @@ pub struct QueryOverflow { pub crate_name: Symbol, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[note(query_system::layout_of_depth)] pub struct LayoutOfDepth { pub desc: String, diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 705305ff806..6d26c8f47f3 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -4,7 +4,7 @@ use crate::query::{QueryContext, QueryStackFrame}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{ - Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, Level, SessionDiagnostic, + Diagnostic, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, Handler, Level, }; use rustc_hir::def::DefKind; use rustc_session::Session; diff --git a/compiler/rustc_save_analysis/src/errors.rs b/compiler/rustc_save_analysis/src/errors.rs index f0ce41d02a6..0983ec2f6f7 100644 --- a/compiler/rustc_save_analysis/src/errors.rs +++ b/compiler/rustc_save_analysis/src/errors.rs @@ -1,8 +1,8 @@ -use rustc_macros::SessionDiagnostic; +use rustc_macros::DiagnosticHandler; use std::path::Path; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(save_analysis::could_not_open)] pub(crate) struct CouldNotOpen<'a> { pub file_name: &'a Path, diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index c6596ff2498..4cf46109895 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -8,7 +8,7 @@ use rustc_span::{Span, Symbol}; use rustc_target::abi::TargetDataLayoutErrors; use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple}; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(session::incorrect_cgu_reuse_type)] pub struct IncorrectCguReuseType<'a> { #[primary_span] @@ -19,14 +19,14 @@ pub struct IncorrectCguReuseType<'a> { pub at_least: u8, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(session::cgu_not_recorded)] pub struct CguNotRecorded<'a> { pub cgu_user_name: &'a str, pub cgu_name: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(session::feature_gate_error, code = "E0658")] pub struct FeatureGateError<'a> { #[primary_span] @@ -46,19 +46,19 @@ pub struct FeatureDiagnosticHelp { pub feature: Symbol, } -impl SessionDiagnostic<'_, !> for TargetDataLayoutErrors<'_> { - fn into_diagnostic(self, sess: &Handler) -> DiagnosticBuilder<'_, !> { +impl DiagnosticHandler<'_, !> for TargetDataLayoutErrors<'_> { + fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> { let mut diag; match self { TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => { - diag = sess.struct_fatal(fluent::session::target_invalid_address_space); + diag = handler.struct_fatal(fluent::session::target_invalid_address_space); diag.set_arg("addr_space", addr_space); diag.set_arg("cause", cause); diag.set_arg("err", err); diag } TargetDataLayoutErrors::InvalidBits { kind, bit, cause, err } => { - diag = sess.struct_fatal(fluent::session::target_invalid_bits); + diag = handler.struct_fatal(fluent::session::target_invalid_bits); diag.set_arg("kind", kind); diag.set_arg("bit", bit); diag.set_arg("cause", cause); @@ -66,30 +66,30 @@ impl SessionDiagnostic<'_, !> for TargetDataLayoutErrors<'_> { diag } TargetDataLayoutErrors::MissingAlignment { cause } => { - diag = sess.struct_fatal(fluent::session::target_missing_alignment); + diag = handler.struct_fatal(fluent::session::target_missing_alignment); diag.set_arg("cause", cause); diag } TargetDataLayoutErrors::InvalidAlignment { cause, err } => { - diag = sess.struct_fatal(fluent::session::target_invalid_alignment); + diag = handler.struct_fatal(fluent::session::target_invalid_alignment); diag.set_arg("cause", cause); diag.set_arg("err", err); diag } TargetDataLayoutErrors::InconsistentTargetArchitecture { dl, target } => { - diag = sess.struct_fatal(fluent::session::target_inconsistent_architecture); + diag = handler.struct_fatal(fluent::session::target_inconsistent_architecture); diag.set_arg("dl", dl); diag.set_arg("target", target); diag } TargetDataLayoutErrors::InconsistentTargetPointerWidth { pointer_size, target } => { - diag = sess.struct_fatal(fluent::session::target_inconsistent_pointer_width); + diag = handler.struct_fatal(fluent::session::target_inconsistent_pointer_width); diag.set_arg("pointer_size", pointer_size); diag.set_arg("target", target); diag } TargetDataLayoutErrors::InvalidBitsSize { err } => { - diag = sess.struct_fatal(fluent::session::target_invalid_bits_size); + diag = handler.struct_fatal(fluent::session::target_invalid_bits_size); diag.set_arg("err", err); diag } diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 564629a6703..3189dcb08ad 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -11,8 +11,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_data_structures::sync::{Lock, Lrc}; use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler}; use rustc_errors::{ - fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId, - DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, SessionDiagnostic, StashKey, + fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, IntoDiagnostic, + DiagnosticId, DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, StashKey, }; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_span::edition::Edition; @@ -344,34 +344,34 @@ impl ParseSess { pub fn create_err<'a>( &'a self, - err: impl SessionDiagnostic<'a>, + err: impl IntoDiagnostic<'a>, ) -> DiagnosticBuilder<'a, ErrorGuaranteed> { err.into_diagnostic(&self.span_diagnostic) } - pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed { + pub fn emit_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> ErrorGuaranteed { self.create_err(err).emit() } pub fn create_warning<'a>( &'a self, - warning: impl SessionDiagnostic<'a, ()>, + warning: impl IntoDiagnostic<'a, ()>, ) -> DiagnosticBuilder<'a, ()> { warning.into_diagnostic(&self.span_diagnostic) } - pub fn emit_warning<'a>(&'a self, warning: impl SessionDiagnostic<'a, ()>) { + pub fn emit_warning<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) { self.create_warning(warning).emit() } pub fn create_fatal<'a>( &'a self, - fatal: impl SessionDiagnostic<'a, !>, + fatal: impl IntoDiagnostic<'a, !>, ) -> DiagnosticBuilder<'a, !> { fatal.into_diagnostic(&self.span_diagnostic) } - pub fn emit_fatal<'a>(&'a self, fatal: impl SessionDiagnostic<'a, !>) -> ! { + pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, !>) -> ! { self.create_fatal(fatal).emit() } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 6a5a89747df..e660b739928 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -27,8 +27,8 @@ use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType}; use rustc_errors::json::JsonEmitter; use rustc_errors::registry::Registry; use rustc_errors::{ - error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, - ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan, SessionDiagnostic, + error_code, fallback_fluent_bundle, DiagnosticBuilder, IntoDiagnostic, DiagnosticId, + DiagnosticMessage, ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan, }; use rustc_macros::HashStable_Generic; pub use rustc_span::def_id::StableCrateId; @@ -505,13 +505,13 @@ impl Session { } pub fn create_err<'a>( &'a self, - err: impl SessionDiagnostic<'a>, + err: impl IntoDiagnostic<'a>, ) -> DiagnosticBuilder<'a, ErrorGuaranteed> { self.parse_sess.create_err(err) } pub fn create_feature_err<'a>( &'a self, - err: impl SessionDiagnostic<'a>, + err: impl IntoDiagnostic<'a>, feature: Symbol, ) -> DiagnosticBuilder<'a, ErrorGuaranteed> { let mut err = self.parse_sess.create_err(err); @@ -521,25 +521,25 @@ impl Session { add_feature_diagnostics(&mut err, &self.parse_sess, feature); err } - pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed { + pub fn emit_err<'a>(&'a self, err: impl IntoDiagnostic<'a>) -> ErrorGuaranteed { self.parse_sess.emit_err(err) } pub fn create_warning<'a>( &'a self, - err: impl SessionDiagnostic<'a, ()>, + err: impl IntoDiagnostic<'a, ()>, ) -> DiagnosticBuilder<'a, ()> { self.parse_sess.create_warning(err) } - pub fn emit_warning<'a>(&'a self, warning: impl SessionDiagnostic<'a, ()>) { + pub fn emit_warning<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) { self.parse_sess.emit_warning(warning) } pub fn create_fatal<'a>( &'a self, - fatal: impl SessionDiagnostic<'a, !>, + fatal: impl IntoDiagnostic<'a, !>, ) -> DiagnosticBuilder<'a, !> { self.parse_sess.create_fatal(fatal) } - pub fn emit_fatal<'a>(&'a self, fatal: impl SessionDiagnostic<'a, !>) -> ! { + pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, !>) -> ! { self.parse_sess.emit_fatal(fatal) } #[inline] diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 562360130e9..98ff9694808 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -177,6 +177,7 @@ symbols! { DecorateLint, Default, Deref, + DiagnosticHandler, DiagnosticMessage, DirBuilder, Display, @@ -277,7 +278,6 @@ symbols! { RwLockWriteGuard, Send, SeqCst, - SessionDiagnostic, SliceIndex, Some, String, diff --git a/compiler/rustc_symbol_mangling/src/errors.rs b/compiler/rustc_symbol_mangling/src/errors.rs index 664d2543f1f..eb487a03c93 100644 --- a/compiler/rustc_symbol_mangling/src/errors.rs +++ b/compiler/rustc_symbol_mangling/src/errors.rs @@ -1,10 +1,10 @@ //! Errors emitted by symbol_mangling. use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg}; -use rustc_macros::SessionDiagnostic; +use rustc_macros::Diagnostic; use rustc_span::Span; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(symbol_mangling::test_output)] pub struct TestOutput { #[primary_span] diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index dc7078d9ada..f62bdb00ee0 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -1,10 +1,10 @@ -use rustc_errors::{fluent, ErrorGuaranteed, Handler, SessionDiagnostic}; -use rustc_macros::SessionDiagnostic; +use rustc_errors::{fluent, IntoDiagnostic, ErrorGuaranteed, Handler}; +use rustc_macros::DiagnosticHandler; use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated}; use rustc_session::Limit; use rustc_span::{Span, Symbol}; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(trait_selection::dump_vtable_entries)] pub struct DumpVTableEntries<'a> { #[primary_span] @@ -13,7 +13,7 @@ pub struct DumpVTableEntries<'a> { pub entries: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(trait_selection::unable_to_construct_constant_value)] pub struct UnableToConstructConstantValue<'a> { #[primary_span] @@ -21,7 +21,7 @@ pub struct UnableToConstructConstantValue<'a> { pub unevaluated: Unevaluated<'a>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[help] #[diag(trait_selection::auto_deref_reached_recursion_limit, code = "E0055")] pub struct AutoDerefReachedRecursionLimit<'a> { @@ -33,7 +33,7 @@ pub struct AutoDerefReachedRecursionLimit<'a> { pub crate_name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(trait_selection::empty_on_clause_in_rustc_on_unimplemented, code = "E0232")] pub struct EmptyOnClauseInOnUnimplemented { #[primary_span] @@ -41,7 +41,7 @@ pub struct EmptyOnClauseInOnUnimplemented { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(trait_selection::invalid_on_clause_in_rustc_on_unimplemented, code = "E0232")] pub struct InvalidOnClauseInOnUnimplemented { #[primary_span] @@ -49,7 +49,7 @@ pub struct InvalidOnClauseInOnUnimplemented { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(trait_selection::no_value_in_rustc_on_unimplemented, code = "E0232")] #[note] pub struct NoValueInOnUnimplemented { @@ -66,7 +66,7 @@ pub struct NegativePositiveConflict<'a> { pub positive_impl_span: Result, } -impl SessionDiagnostic<'_> for NegativePositiveConflict<'_> { +impl IntoDiagnostic<'_> for NegativePositiveConflict<'_> { fn into_diagnostic( self, handler: &Handler, diff --git a/compiler/rustc_ty_utils/src/errors.rs b/compiler/rustc_ty_utils/src/errors.rs index 3a8ef96c991..995e87bcd3b 100644 --- a/compiler/rustc_ty_utils/src/errors.rs +++ b/compiler/rustc_ty_utils/src/errors.rs @@ -1,16 +1,16 @@ //! Errors emitted by ty_utils -use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; use rustc_middle::ty::Ty; use rustc_span::Span; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(ty_utils::needs_drop_overflow)] pub struct NeedsDropOverflow<'tcx> { pub query_ty: Ty<'tcx>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(ty_utils::generic_constant_too_complex)] #[help] pub struct GenericConstantTooComplex { diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 93b00850069..11661b8ef6c 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -881,7 +881,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; } - // FIXME: Make this use SessionDiagnostic once error codes can be dynamically set. + // FIXME: Make this use DiagnosticHandler once error codes can be dynamically set. let mut err = self.tcx.sess.struct_span_err_with_code( op_span, "invalid left-hand side of assignment", diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index ed4c4f688bf..50d400e2921 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -1,11 +1,11 @@ //! Errors emitted by typeck. -use rustc_errors::SessionDiagnostic; +use rustc_errors::IntoDiagnostic; use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler}; -use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{DiagnosticHandler, LintDiagnostic, SessionSubdiagnostic}; use rustc_middle::ty::Ty; use rustc_span::{symbol::Ident, Span, Symbol}; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::field_multiply_specified_in_initializer, code = "E0062")] pub struct FieldMultiplySpecifiedInInitializer { #[primary_span] @@ -16,7 +16,7 @@ pub struct FieldMultiplySpecifiedInInitializer { pub ident: Ident, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::unrecognized_atomic_operation, code = "E0092")] pub struct UnrecognizedAtomicOperation<'a> { #[primary_span] @@ -25,7 +25,7 @@ pub struct UnrecognizedAtomicOperation<'a> { pub op: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::wrong_number_of_generic_arguments_to_intrinsic, code = "E0094")] pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> { #[primary_span] @@ -36,7 +36,7 @@ pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> { pub descr: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::unrecognized_intrinsic_function, code = "E0093")] pub struct UnrecognizedIntrinsicFunction { #[primary_span] @@ -45,7 +45,7 @@ pub struct UnrecognizedIntrinsicFunction { pub name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::lifetimes_or_bounds_mismatch_on_trait, code = "E0195")] pub struct LifetimesOrBoundsMismatchOnTrait { #[primary_span] @@ -57,7 +57,7 @@ pub struct LifetimesOrBoundsMismatchOnTrait { pub ident: Ident, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::drop_impl_on_wrong_item, code = "E0120")] pub struct DropImplOnWrongItem { #[primary_span] @@ -65,7 +65,7 @@ pub struct DropImplOnWrongItem { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::field_already_declared, code = "E0124")] pub struct FieldAlreadyDeclared { pub field_name: Ident, @@ -76,7 +76,7 @@ pub struct FieldAlreadyDeclared { pub prev_span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::copy_impl_on_type_with_dtor, code = "E0184")] pub struct CopyImplOnTypeWithDtor { #[primary_span] @@ -84,14 +84,14 @@ pub struct CopyImplOnTypeWithDtor { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::multiple_relaxed_default_bounds, code = "E0203")] pub struct MultipleRelaxedDefaultBounds { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::copy_impl_on_non_adt, code = "E0206")] pub struct CopyImplOnNonAdt { #[primary_span] @@ -99,7 +99,7 @@ pub struct CopyImplOnNonAdt { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::trait_object_declared_with_no_traits, code = "E0224")] pub struct TraitObjectDeclaredWithNoTraits { #[primary_span] @@ -108,14 +108,14 @@ pub struct TraitObjectDeclaredWithNoTraits { pub trait_alias_span: Option, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0227")] pub struct AmbiguousLifetimeBound { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::assoc_type_binding_not_allowed, code = "E0229")] pub struct AssocTypeBindingNotAllowed { #[primary_span] @@ -123,14 +123,14 @@ pub struct AssocTypeBindingNotAllowed { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::functional_record_update_on_non_struct, code = "E0436")] pub struct FunctionalRecordUpdateOnNonStruct { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::typeof_reserved_keyword_used, code = "E0516")] pub struct TypeofReservedKeywordUsed<'tcx> { pub ty: Ty<'tcx>, @@ -141,7 +141,7 @@ pub struct TypeofReservedKeywordUsed<'tcx> { pub opt_sugg: Option<(Span, Applicability)>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::return_stmt_outside_of_fn_body, code = "E0572")] pub struct ReturnStmtOutsideOfFnBody { #[primary_span] @@ -152,14 +152,14 @@ pub struct ReturnStmtOutsideOfFnBody { pub encl_fn_span: Option, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::yield_expr_outside_of_generator, code = "E0627")] pub struct YieldExprOutsideOfGenerator { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::struct_expr_non_exhaustive, code = "E0639")] pub struct StructExprNonExhaustive { #[primary_span] @@ -167,14 +167,14 @@ pub struct StructExprNonExhaustive { pub what: &'static str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::method_call_on_unknown_type, code = "E0699")] pub struct MethodCallOnUnknownType { #[primary_span] pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::value_of_associated_struct_already_specified, code = "E0719")] pub struct ValueOfAssociatedStructAlreadySpecified { #[primary_span] @@ -186,7 +186,7 @@ pub struct ValueOfAssociatedStructAlreadySpecified { pub def_path: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::address_of_temporary_taken, code = "E0745")] pub struct AddressOfTemporaryTaken { #[primary_span] @@ -232,7 +232,7 @@ pub enum ExpectedReturnTypeLabel<'tcx> { }, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::unconstrained_opaque_type)] #[note] pub struct UnconstrainedOpaqueType { @@ -249,8 +249,8 @@ pub struct MissingTypeParams { pub empty_generic_args: bool, } -// Manual implementation of `SessionDiagnostic` to be able to call `span_to_snippet`. -impl<'a> SessionDiagnostic<'a> for MissingTypeParams { +// Manual implementation of `DiagnosticHandler` to be able to call `span_to_snippet`. +impl<'a> IntoDiagnostic<'a> for MissingTypeParams { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { let mut err = handler.struct_span_err_with_code( self.span, @@ -306,7 +306,7 @@ impl<'a> SessionDiagnostic<'a> for MissingTypeParams { } } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::manual_implementation, code = "E0183")] #[help] pub struct ManualImplementation { @@ -316,7 +316,7 @@ pub struct ManualImplementation { pub trait_name: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::substs_on_overridden_impl)] pub struct SubstsOnOverriddenImpl { #[primary_span] @@ -339,7 +339,7 @@ pub struct ExternCrateNotIdiomatic { pub suggestion_code: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::expected_used_symbol)] pub struct ExpectedUsedSymbol { #[primary_span] diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.rs b/src/test/ui-fulldeps/internal-lints/diagnostics.rs index 3b31a290449..1ead987ec41 100644 --- a/src/test/ui-fulldeps/internal-lints/diagnostics.rs +++ b/src/test/ui-fulldeps/internal-lints/diagnostics.rs @@ -12,12 +12,13 @@ extern crate rustc_session; extern crate rustc_span; use rustc_errors::{ - AddSubdiagnostic, SessionDiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent + AddSubdiagnostic, IntoDiagnostic, Diagnostic, DiagnosticBuilder, + ErrorGuaranteed, Handler, fluent }; -use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; use rustc_span::Span; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(parser::expect_path)] struct DeriveSessionDiagnostic { #[primary_span] @@ -33,7 +34,7 @@ struct Note { pub struct UntranslatableInSessionDiagnostic; -impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic { +impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { handler.struct_err("untranslatable diagnostic") //~^ ERROR diagnostics should be created using translatable messages @@ -42,7 +43,7 @@ impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagn pub struct TranslatableInSessionDiagnostic; -impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic { +impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { handler.struct_err(fluent::parser::expect_path) } @@ -67,10 +68,10 @@ impl AddSubdiagnostic for TranslatableInAddSubdiagnostic { pub fn make_diagnostics<'a>(handler: &'a Handler) { let _diag = handler.struct_err(fluent::parser::expect_path); - //~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls + //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddSubdiagnostic` impls let _diag = handler.struct_err("untranslatable diagnostic"); - //~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls + //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddSubdiagnostic` impls //~^^ ERROR diagnostics should be created using translatable messages } diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.stderr b/src/test/ui-fulldeps/internal-lints/diagnostics.stderr index e5c5bc2e998..d5833cf3970 100644 --- a/src/test/ui-fulldeps/internal-lints/diagnostics.stderr +++ b/src/test/ui-fulldeps/internal-lints/diagnostics.stderr @@ -16,7 +16,7 @@ error: diagnostics should be created using translatable messages LL | diag.note("untranslatable diagnostic"); | ^^^^ -error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls +error: diagnostics should only be created in `IntoDiagnostic`/`AddSubdiagnostic` impls --> $DIR/diagnostics.rs:70:25 | LL | let _diag = handler.struct_err(fluent::parser::expect_path); @@ -28,7 +28,7 @@ note: the lint level is defined here LL | #![deny(rustc::diagnostic_outside_of_impl)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls +error: diagnostics should only be created in `IntoDiagnostic`/`AddSubdiagnostic` impls --> $DIR/diagnostics.rs:73:25 | LL | let _diag = handler.struct_err("untranslatable diagnostic"); diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index c1c109ac1ea..32ba5be8963 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -1,10 +1,10 @@ // check-fail -// Tests error conditions for specifying diagnostics using #[derive(SessionDiagnostic)] +// Tests error conditions for specifying diagnostics using #[derive(DiagnosticHandler)] // normalize-stderr-test "the following other types implement trait `IntoDiagnosticArg`:(?:.*\n){0,9}\s+and \d+ others" -> "normalized in stderr" // normalize-stderr-test "diagnostic_builder\.rs:[0-9]+:[0-9]+" -> "diagnostic_builder.rs:LL:CC" // The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly, -// changing the output of this test. Since SessionDiagnostic is strictly internal to the compiler +// changing the output of this test. Since DiagnosticHandler is strictly internal to the compiler // the test is just ignored on stable and beta: // ignore-beta // ignore-stable @@ -17,7 +17,7 @@ use rustc_span::symbol::Ident; use rustc_span::Span; extern crate rustc_macros; -use rustc_macros::{SessionDiagnostic, LintDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{DiagnosticHandler, LintDiagnostic, SessionSubdiagnostic}; extern crate rustc_middle; use rustc_middle::ty::Ty; @@ -27,70 +27,70 @@ use rustc_errors::{Applicability, MultiSpan}; extern crate rustc_session; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct Hello {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct HelloWarn {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] -//~^ ERROR `#[derive(SessionDiagnostic)]` can only be used on structs -enum SessionDiagnosticOnEnum { +//~^ ERROR `#[derive(DiagnosticHandler)]` can only be used on structs +enum DiagnosticHandlerOnEnum { Foo, Bar, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag = "E0123"] //~^ ERROR `#[diag = ...]` is not a valid attribute struct WrongStructAttrStyle {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")] //~^ ERROR `#[nonsense(...)]` is not a valid attribute //~^^ ERROR diagnostic slug not specified //~^^^ ERROR cannot find attribute `nonsense` in this scope struct InvalidStructAttr {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag("E0123")] //~^ ERROR `#[diag("...")]` is not a valid attribute //~^^ ERROR diagnostic slug not specified struct InvalidLitNestedAttr {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(nonsense, code = "E0123")] //~^ ERROR cannot find value `nonsense` in module `rustc_errors::fluent` struct InvalidNestedStructAttr {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(nonsense("foo"), code = "E0123", slug = "foo")] //~^ ERROR `#[diag(nonsense(...))]` is not a valid attribute //~^^ ERROR diagnostic slug not specified struct InvalidNestedStructAttr1 {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(nonsense = "...", code = "E0123", slug = "foo")] //~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute //~^^ ERROR diagnostic slug not specified struct InvalidNestedStructAttr2 {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(nonsense = 4, code = "E0123", slug = "foo")] //~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute //~^^ ERROR diagnostic slug not specified struct InvalidNestedStructAttr3 {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123", slug = "foo")] //~^ ERROR `#[diag(slug = ...)]` is not a valid attribute struct InvalidNestedStructAttr4 {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct WrongPlaceField { #[suggestion = "bar"] @@ -98,36 +98,36 @@ struct WrongPlaceField { sp: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0456")] //~^ ERROR specified multiple times //~^^ ERROR specified multiple times struct DiagSpecifiedTwice {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0456", code = "E0457")] //~^ ERROR specified multiple times struct CodeSpecifiedTwice {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, typeck::ambiguous_lifetime_bound, code = "E0456")] //~^ ERROR `#[diag(typeck::ambiguous_lifetime_bound)]` is not a valid attribute struct SlugSpecifiedTwice {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] struct KindNotProvided {} //~ ERROR diagnostic slug not specified -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(code = "E0456")] //~^ ERROR diagnostic slug not specified struct SlugNotProvided {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound)] struct CodeNotProvided {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct MessageWrongType { #[primary_span] @@ -135,7 +135,7 @@ struct MessageWrongType { foo: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct InvalidPathFieldAttr { #[nonsense] @@ -144,7 +144,7 @@ struct InvalidPathFieldAttr { foo: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithField { name: String, @@ -152,7 +152,7 @@ struct ErrorWithField { span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithMessageAppliedToField { #[label(typeck::label)] @@ -160,7 +160,7 @@ struct ErrorWithMessageAppliedToField { name: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithNonexistentField { #[suggestion(typeck::suggestion, code = "{name}")] @@ -168,7 +168,7 @@ struct ErrorWithNonexistentField { suggestion: (Span, Applicability), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] //~^ ERROR invalid format string: expected `'}'` #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorMissingClosingBrace { @@ -178,7 +178,7 @@ struct ErrorMissingClosingBrace { val: usize, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] //~^ ERROR invalid format string: unmatched `}` #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorMissingOpeningBrace { @@ -188,14 +188,14 @@ struct ErrorMissingOpeningBrace { val: usize, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelOnSpan { #[label(typeck::label)] sp: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelOnNonSpan { #[label(typeck::label)] @@ -203,7 +203,7 @@ struct LabelOnNonSpan { id: u32, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct Suggest { #[suggestion(typeck::suggestion, code = "This is the suggested code")] @@ -213,14 +213,14 @@ struct Suggest { suggestion: (Span, Applicability), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithoutCode { #[suggestion(typeck::suggestion)] suggestion: (Span, Applicability), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithBadKey { #[suggestion(nonsense = "bar")] @@ -228,7 +228,7 @@ struct SuggestWithBadKey { suggestion: (Span, Applicability), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithShorthandMsg { #[suggestion(msg = "bar")] @@ -236,21 +236,21 @@ struct SuggestWithShorthandMsg { suggestion: (Span, Applicability), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithoutMsg { #[suggestion(code = "bar")] suggestion: (Span, Applicability), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithTypesSwapped { #[suggestion(typeck::suggestion, code = "This is suggested code")] suggestion: (Applicability, Span), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithWrongTypeApplicabilityOnly { #[suggestion(typeck::suggestion, code = "This is suggested code")] @@ -258,14 +258,14 @@ struct SuggestWithWrongTypeApplicabilityOnly { suggestion: Applicability, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithSpanOnly { #[suggestion(typeck::suggestion, code = "This is suggested code")] suggestion: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithDuplicateSpanAndApplicability { #[suggestion(typeck::suggestion, code = "This is suggested code")] @@ -273,7 +273,7 @@ struct SuggestWithDuplicateSpanAndApplicability { suggestion: (Span, Span, Applicability), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithDuplicateApplicabilityAndSpan { #[suggestion(typeck::suggestion, code = "This is suggested code")] @@ -281,7 +281,7 @@ struct SuggestWithDuplicateApplicabilityAndSpan { suggestion: (Applicability, Applicability, Span), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct WrongKindOfAnnotation { #[label = "bar"] @@ -289,7 +289,7 @@ struct WrongKindOfAnnotation { z: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct OptionsInErrors { #[label(typeck::label)] @@ -298,7 +298,7 @@ struct OptionsInErrors { opt_sugg: Option<(Span, Applicability)>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0456")] struct MoveOutOfBorrowError<'tcx> { name: Ident, @@ -312,7 +312,7 @@ struct MoveOutOfBorrowError<'tcx> { opt_sugg: Option<(Span, Applicability)>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithLifetime<'a> { #[label(typeck::label)] @@ -320,7 +320,7 @@ struct ErrorWithLifetime<'a> { name: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithDefaultLabelAttr<'a> { #[label] @@ -328,7 +328,7 @@ struct ErrorWithDefaultLabelAttr<'a> { name: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] //~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ArgFieldWithoutSkip { @@ -337,7 +337,7 @@ struct ArgFieldWithoutSkip { other: Hello, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ArgFieldWithSkip { #[primary_span] @@ -348,91 +348,91 @@ struct ArgFieldWithSkip { other: Hello, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithSpannedNote { #[note] span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithSpannedNoteCustom { #[note(typeck::note)] span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[note] struct ErrorWithNote { val: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[note(typeck::note)] struct ErrorWithNoteCustom { val: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithSpannedHelp { #[help] span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithSpannedHelpCustom { #[help(typeck::help)] span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[help] struct ErrorWithHelp { val: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[help(typeck::help)] struct ErrorWithHelpCustom { val: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[help] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithHelpWrongOrder { val: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[help(typeck::help)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithHelpCustomWrongOrder { val: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[note] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithNoteWrongOrder { val: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[note(typeck::note)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithNoteCustomWrongOrder { val: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ApplicabilityInBoth { #[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")] @@ -440,7 +440,7 @@ struct ApplicabilityInBoth { suggestion: (Span, Applicability), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct InvalidApplicability { #[suggestion(typeck::suggestion, code = "...", applicability = "batman")] @@ -448,14 +448,14 @@ struct InvalidApplicability { suggestion: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ValidApplicability { #[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")] suggestion: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct NoApplicability { #[suggestion(typeck::suggestion, code = "...")] @@ -466,14 +466,14 @@ struct NoApplicability { #[note(parser::add_paren)] struct Note; -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound)] struct Subdiagnostic { #[subdiagnostic] note: Note, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct VecField { #[primary_span] @@ -481,7 +481,7 @@ struct VecField { spans: Vec, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct UnitField { #[primary_span] @@ -492,7 +492,7 @@ struct UnitField { bar: (), } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct OptUnitField { #[primary_span] @@ -503,7 +503,7 @@ struct OptUnitField { bar: Option<()>, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelWithTrailingPath { #[label(typeck::label, foo)] @@ -511,7 +511,7 @@ struct LabelWithTrailingPath { span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelWithTrailingNameValue { #[label(typeck::label, foo = "...")] @@ -519,7 +519,7 @@ struct LabelWithTrailingNameValue { span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelWithTrailingList { #[label(typeck::label, foo("..."))] @@ -540,35 +540,35 @@ struct PrimarySpanOnLint { span: Span, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithMultiSpan { #[primary_span] span: MultiSpan, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[warning] struct ErrorWithWarn { val: String, } -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[error(typeck::ambiguous_lifetime_bound, code = "E0123")] //~^ ERROR `#[error(...)]` is not a valid attribute //~| ERROR diagnostic slug not specified //~| ERROR cannot find attribute `error` in this scope struct ErrorAttribute {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")] //~^ ERROR `#[warn_(...)]` is not a valid attribute //~| ERROR diagnostic slug not specified //~| ERROR cannot find attribute `warn_` in this scope struct WarnAttribute {} -#[derive(SessionDiagnostic)] +#[derive(DiagnosticHandler)] #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] //~^ ERROR `#[lint(...)]` is not a valid attribute //~| ERROR diagnostic slug not specified diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index ab5c28fe473..d9198d4ef80 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -1,9 +1,9 @@ -error: `#[derive(SessionDiagnostic)]` can only be used on structs +error: `#[derive(DiagnosticHandler)]` can only be used on structs --> $DIR/diagnostic-derive.rs:39:1 | LL | / #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | | -LL | | enum SessionDiagnosticOnEnum { +LL | | enum DiagnosticHandlerOnEnum { LL | | Foo, LL | | Bar, LL | | } @@ -214,22 +214,22 @@ LL | #[suggestion(typeck::suggestion, code = "{name}")] error: invalid format string: expected `'}'` but string was terminated --> $DIR/diagnostic-derive.rs:171:16 | -LL | #[derive(SessionDiagnostic)] +LL | #[derive(DiagnosticHandler)] | - ^ expected `'}'` in format string | | | because of this opening brace | = note: if you intended to print `{`, you can escape it using `{{` - = note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `DiagnosticHandler` (in Nightly builds, run with -Z macro-backtrace for more info) error: invalid format string: unmatched `}` found --> $DIR/diagnostic-derive.rs:181:15 | -LL | #[derive(SessionDiagnostic)] +LL | #[derive(DiagnosticHandler)] | ^ unmatched `}` in format string | = note: if you intended to print `}`, you can escape it using `}}` - = note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `DiagnosticHandler` (in Nightly builds, run with -Z macro-backtrace for more info) error: the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` --> $DIR/diagnostic-derive.rs:201:5 @@ -448,7 +448,7 @@ LL | #[diag(nonsense, code = "E0123")] error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied --> $DIR/diagnostic-derive.rs:331:10 | -LL | #[derive(SessionDiagnostic)] +LL | #[derive(DiagnosticHandler)] | ^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` | = help: normalized in stderr @@ -457,7 +457,7 @@ note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg` | LL | arg: impl IntoDiagnosticArg, | ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg` - = note: this error originates in the derive macro `SessionDiagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `DiagnosticHandler` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 55 previous errors -- cgit 1.4.1-3-g733a5 From 191fac68266b73158ff048c83556ea91cbf977fd Mon Sep 17 00:00:00 2001 From: Jhonny Bill Mena Date: Sun, 18 Sep 2022 11:46:16 -0400 Subject: UPDATE - rename AddSubdiagnostic trait to AddToDiagnostic --- compiler/rustc_ast_lowering/src/errors.rs | 6 +++--- compiler/rustc_error_messages/locales/en-US/lint.ftl | 2 +- compiler/rustc_errors/src/diagnostic.rs | 4 ++-- compiler/rustc_errors/src/diagnostic_builder.rs | 2 +- compiler/rustc_errors/src/lib.rs | 2 +- compiler/rustc_infer/src/infer/error_reporting/note.rs | 2 +- compiler/rustc_lint/src/errors.rs | 6 +++--- compiler/rustc_lint/src/internal.rs | 2 +- compiler/rustc_macros/src/diagnostics/subdiagnostic.rs | 2 +- src/test/ui-fulldeps/internal-lints/diagnostics.rs | 14 +++++++------- src/test/ui-fulldeps/internal-lints/diagnostics.stderr | 4 ++-- 11 files changed, 23 insertions(+), 23 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 3f3024eb2b8..75f20b07277 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -1,4 +1,4 @@ -use rustc_errors::{fluent, AddSubdiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay}; +use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay}; use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; use rustc_span::{symbol::Ident, Span, Symbol}; @@ -18,7 +18,7 @@ pub struct UseAngleBrackets { pub close_param: Span, } -impl AddSubdiagnostic for UseAngleBrackets { +impl AddToDiagnostic for UseAngleBrackets { fn add_to_diagnostic(self, diag: &mut Diagnostic) { diag.multipart_suggestion( fluent::ast_lowering::use_angle_brackets, @@ -54,7 +54,7 @@ pub enum AssocTyParenthesesSub { NotEmpty { open_param: Span, close_param: Span }, } -impl AddSubdiagnostic for AssocTyParenthesesSub { +impl AddToDiagnostic for AssocTyParenthesesSub { fn add_to_diagnostic(self, diag: &mut Diagnostic) { match self { Self::Empty { parentheses_span } => diag.multipart_suggestion( diff --git a/compiler/rustc_error_messages/locales/en-US/lint.ftl b/compiler/rustc_error_messages/locales/en-US/lint.ftl index 6cc0cb49e1f..80b0b1a8904 100644 --- a/compiler/rustc_error_messages/locales/en-US/lint.ftl +++ b/compiler/rustc_error_messages/locales/en-US/lint.ftl @@ -51,7 +51,7 @@ lint_non_existant_doc_keyword = found non-existing keyword `{$keyword}` used in .help = only existing keywords are allowed in core/std lint_diag_out_of_impl = - diagnostics should only be created in `IntoDiagnostic`/`AddSubdiagnostic` impls + diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls lint_untranslatable_diag = diagnostics should be created using translatable messages diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 8a56068fcc7..d3a263ac56d 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -178,7 +178,7 @@ impl IntoDiagnosticArg for hir::ConstContext { /// Trait implemented by error types. This should not be implemented manually. Instead, use /// `#[derive(SessionSubdiagnostic)]` -- see [rustc_macros::SessionSubdiagnostic]. #[rustc_diagnostic_item = "AddSubdiagnostic"] -pub trait AddSubdiagnostic { +pub trait AddToDiagnostic { /// Add a subdiagnostic to an existing diagnostic. fn add_to_diagnostic(self, diag: &mut Diagnostic); } @@ -893,7 +893,7 @@ impl Diagnostic { /// Add a subdiagnostic from a type that implements `SessionSubdiagnostic` - see /// [rustc_macros::SessionSubdiagnostic]. - pub fn subdiagnostic(&mut self, subdiagnostic: impl AddSubdiagnostic) -> &mut Self { + pub fn subdiagnostic(&mut self, subdiagnostic: impl AddToDiagnostic) -> &mut Self { subdiagnostic.add_to_diagnostic(self); self } diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index b646dd662cb..209a50fd306 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -580,7 +580,7 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> { forward!(pub fn subdiagnostic( &mut self, - subdiagnostic: impl crate::AddSubdiagnostic + subdiagnostic: impl crate::AddToDiagnostic ) -> &mut Self); } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index aed52bce9aa..19cae2c9077 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -371,7 +371,7 @@ impl fmt::Display for ExplicitBug { impl error::Error for ExplicitBug {} pub use diagnostic::{ - AddSubdiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgFromDisplay, + AddToDiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgFromDisplay, DiagnosticArgValue, DiagnosticId, DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic, }; pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder}; diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index adaa47c0140..286cfb64a1e 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -2,7 +2,7 @@ use crate::errors::RegionOriginNote; use crate::infer::error_reporting::note_and_explain_region; use crate::infer::{self, InferCtxt, SubregionOrigin}; use rustc_errors::{ - fluent, struct_span_err, AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, + fluent, struct_span_err, AddToDiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, }; use rustc_middle::traits::ObligationCauseCode; use rustc_middle::ty::error::TypeError; diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs index 261570acb7b..e5670833898 100644 --- a/compiler/rustc_lint/src/errors.rs +++ b/compiler/rustc_lint/src/errors.rs @@ -1,4 +1,4 @@ -use rustc_errors::{fluent, AddSubdiagnostic, IntoDiagnostic, ErrorGuaranteed, Handler}; +use rustc_errors::{fluent, AddToDiagnostic, IntoDiagnostic, ErrorGuaranteed, Handler}; use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; use rustc_session::lint::Level; use rustc_span::{Span, Symbol}; @@ -22,7 +22,7 @@ pub enum OverruledAttributeSub { CommandLineSource, } -impl AddSubdiagnostic for OverruledAttributeSub { +impl AddToDiagnostic for OverruledAttributeSub { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { match self { OverruledAttributeSub::DefaultSource { id } => { @@ -87,7 +87,7 @@ pub struct RequestedLevel { pub lint_name: String, } -impl AddSubdiagnostic for RequestedLevel { +impl AddToDiagnostic for RequestedLevel { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { diag.note(fluent::lint::requested_level); diag.set_arg( diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index dec75c9d380..47da8ec5da1 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -372,7 +372,7 @@ declare_tool_lint! { declare_tool_lint! { pub rustc::DIAGNOSTIC_OUTSIDE_OF_IMPL, Allow, - "prevent creation of diagnostics outside of `DiagnosticHandler`/`AddSubdiagnostic` impls", + "prevent creation of diagnostics outside of `DiagnosticHandler`/`AddToDiagnostic` impls", report_in_external_macro: true } diff --git a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs index dce5d3cfb84..f1bb7feb062 100644 --- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs @@ -166,7 +166,7 @@ impl<'a> SessionSubdiagnosticDerive<'a> { }; let ret = structure.gen_impl(quote! { - gen impl rustc_errors::AddSubdiagnostic for @Self { + gen impl rustc_errors::AddToDiagnostic for @Self { fn add_to_diagnostic(self, #diag: &mut rustc_errors::Diagnostic) { use rustc_errors::{Applicability, IntoDiagnosticArg}; #implementation diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.rs b/src/test/ui-fulldeps/internal-lints/diagnostics.rs index 1ead987ec41..e95ab048db3 100644 --- a/src/test/ui-fulldeps/internal-lints/diagnostics.rs +++ b/src/test/ui-fulldeps/internal-lints/diagnostics.rs @@ -12,7 +12,7 @@ extern crate rustc_session; extern crate rustc_span; use rustc_errors::{ - AddSubdiagnostic, IntoDiagnostic, Diagnostic, DiagnosticBuilder, + AddToDiagnostic, IntoDiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent }; use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; @@ -49,18 +49,18 @@ impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic } } -pub struct UntranslatableInAddSubdiagnostic; +pub struct UntranslatableInAddToDiagnostic; -impl AddSubdiagnostic for UntranslatableInAddSubdiagnostic { +impl AddToDiagnostic for UntranslatableInAddToDiagnostic { fn add_to_diagnostic(self, diag: &mut Diagnostic) { diag.note("untranslatable diagnostic"); //~^ ERROR diagnostics should be created using translatable messages } } -pub struct TranslatableInAddSubdiagnostic; +pub struct TranslatableInAddToDiagnostic; -impl AddSubdiagnostic for TranslatableInAddSubdiagnostic { +impl AddToDiagnostic for TranslatableInAddToDiagnostic { fn add_to_diagnostic(self, diag: &mut Diagnostic) { diag.note(fluent::typeck::note); } @@ -68,10 +68,10 @@ impl AddSubdiagnostic for TranslatableInAddSubdiagnostic { pub fn make_diagnostics<'a>(handler: &'a Handler) { let _diag = handler.struct_err(fluent::parser::expect_path); - //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddSubdiagnostic` impls + //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls let _diag = handler.struct_err("untranslatable diagnostic"); - //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddSubdiagnostic` impls + //~^ ERROR diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls //~^^ ERROR diagnostics should be created using translatable messages } diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.stderr b/src/test/ui-fulldeps/internal-lints/diagnostics.stderr index d5833cf3970..9219d09e9b4 100644 --- a/src/test/ui-fulldeps/internal-lints/diagnostics.stderr +++ b/src/test/ui-fulldeps/internal-lints/diagnostics.stderr @@ -16,7 +16,7 @@ error: diagnostics should be created using translatable messages LL | diag.note("untranslatable diagnostic"); | ^^^^ -error: diagnostics should only be created in `IntoDiagnostic`/`AddSubdiagnostic` impls +error: diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls --> $DIR/diagnostics.rs:70:25 | LL | let _diag = handler.struct_err(fluent::parser::expect_path); @@ -28,7 +28,7 @@ note: the lint level is defined here LL | #![deny(rustc::diagnostic_outside_of_impl)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: diagnostics should only be created in `IntoDiagnostic`/`AddSubdiagnostic` impls +error: diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls --> $DIR/diagnostics.rs:73:25 | LL | let _diag = handler.struct_err("untranslatable diagnostic"); -- cgit 1.4.1-3-g733a5 From a3396b207093c01065b63b0c58f1e6654629166d Mon Sep 17 00:00:00 2001 From: Jhonny Bill Mena Date: Sun, 18 Sep 2022 11:46:56 -0400 Subject: UPDATE - rename DiagnosticHandler macro to Diagnostic --- compiler/rustc_ast_lowering/src/errors.rs | 66 ++++----- compiler/rustc_attr/src/session_diagnostics.rs | 60 ++++---- compiler/rustc_borrowck/src/session_diagnostics.rs | 16 +-- compiler/rustc_builtin_macros/src/cfg.rs | 6 +- compiler/rustc_const_eval/src/errors.rs | 44 +++--- compiler/rustc_driver/src/session_diagnostics.rs | 16 +-- compiler/rustc_errors/src/diagnostic_builder.rs | 4 +- compiler/rustc_expand/src/errors.rs | 14 +- compiler/rustc_interface/src/errors.rs | 30 ++-- compiler/rustc_lint/src/errors.rs | 18 +-- compiler/rustc_lint/src/internal.rs | 4 +- .../rustc_macros/src/diagnostics/diagnostic.rs | 4 +- .../src/diagnostics/diagnostic_builder.rs | 6 +- compiler/rustc_macros/src/diagnostics/mod.rs | 6 +- compiler/rustc_macros/src/lib.rs | 2 +- compiler/rustc_metadata/src/errors.rs | 154 ++++++++++----------- compiler/rustc_middle/src/error.rs | 8 +- compiler/rustc_mir_dataflow/src/errors.rs | 22 +-- compiler/rustc_monomorphize/src/errors.rs | 12 +- compiler/rustc_parse/src/parser/diagnostics.rs | 84 +++++------ compiler/rustc_passes/src/errors.rs | 104 +++++++------- compiler/rustc_plugin_impl/src/errors.rs | 6 +- compiler/rustc_privacy/src/errors.rs | 12 +- compiler/rustc_query_system/src/error.rs | 6 +- compiler/rustc_save_analysis/src/errors.rs | 4 +- compiler/rustc_session/src/errors.rs | 8 +- compiler/rustc_span/src/symbol.rs | 2 +- compiler/rustc_trait_selection/src/errors.rs | 14 +- compiler/rustc_ty_utils/src/errors.rs | 6 +- compiler/rustc_typeck/src/check/expr.rs | 2 +- compiler/rustc_typeck/src/errors.rs | 54 ++++---- src/test/ui-fulldeps/internal-lints/diagnostics.rs | 4 +- .../session-diagnostic/diagnostic-derive.rs | 154 ++++++++++----------- .../session-diagnostic/diagnostic-derive.stderr | 16 +-- 34 files changed, 484 insertions(+), 484 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 75f20b07277..6dbb2582a37 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -1,8 +1,8 @@ use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay}; -use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, SessionSubdiagnostic}; use rustc_span::{symbol::Ident, Span, Symbol}; -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::generic_type_with_parentheses, code = "E0214")] pub struct GenericTypeWithParentheses { #[primary_span] @@ -28,7 +28,7 @@ impl AddToDiagnostic for UseAngleBrackets { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[help] #[diag(ast_lowering::invalid_abi, code = "E0703")] pub struct InvalidAbi { @@ -39,7 +39,7 @@ pub struct InvalidAbi { pub valid_abis: String, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::assoc_ty_parentheses)] pub struct AssocTyParentheses { #[primary_span] @@ -71,7 +71,7 @@ impl AddToDiagnostic for AssocTyParenthesesSub { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(ast_lowering::misplaced_impl_trait, code = "E0562")] pub struct MisplacedImplTrait<'a> { #[primary_span] @@ -79,14 +79,14 @@ pub struct MisplacedImplTrait<'a> { pub position: DiagnosticArgFromDisplay<'a>, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::rustc_box_attribute_error)] pub struct RustcBoxAttributeError { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::underscore_expr_lhs_assign)] pub struct UnderscoreExprLhsAssign { #[primary_span] @@ -94,7 +94,7 @@ pub struct UnderscoreExprLhsAssign { pub span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::base_expression_double_dot)] pub struct BaseExpressionDoubleDot { #[primary_span] @@ -102,7 +102,7 @@ pub struct BaseExpressionDoubleDot { pub span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::await_only_in_async_fn_and_blocks, code = "E0728")] pub struct AwaitOnlyInAsyncFnAndBlocks { #[primary_span] @@ -112,21 +112,21 @@ pub struct AwaitOnlyInAsyncFnAndBlocks { pub item_span: Option, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::generator_too_many_parameters, code = "E0628")] pub struct GeneratorTooManyParameters { #[primary_span] pub fn_decl_span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::closure_cannot_be_static, code = "E0697")] pub struct ClosureCannotBeStatic { #[primary_span] pub fn_decl_span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[help] #[diag(ast_lowering::async_non_move_closure_not_supported, code = "E0708")] pub struct AsyncNonMoveClosureNotSupported { @@ -134,7 +134,7 @@ pub struct AsyncNonMoveClosureNotSupported { pub fn_decl_span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::functional_record_update_destructuring_assignment)] pub struct FunctionalRecordUpdateDestructuringAssignemnt { #[primary_span] @@ -142,28 +142,28 @@ pub struct FunctionalRecordUpdateDestructuringAssignemnt { pub span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::async_generators_not_supported, code = "E0727")] pub struct AsyncGeneratorsNotSupported { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::inline_asm_unsupported_target, code = "E0472")] pub struct InlineAsmUnsupportedTarget { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::att_syntax_only_x86)] pub struct AttSyntaxOnlyX86 { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::abi_specified_multiple_times)] pub struct AbiSpecifiedMultipleTimes { #[primary_span] @@ -175,14 +175,14 @@ pub struct AbiSpecifiedMultipleTimes { pub equivalent: Option<()>, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::clobber_abi_not_supported)] pub struct ClobberAbiNotSupported { #[primary_span] pub abi_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[note] #[diag(ast_lowering::invalid_abi_clobber_abi)] pub struct InvalidAbiClobberAbi { @@ -191,7 +191,7 @@ pub struct InvalidAbiClobberAbi { pub supported_abis: String, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::invalid_register)] pub struct InvalidRegister<'a> { #[primary_span] @@ -200,7 +200,7 @@ pub struct InvalidRegister<'a> { pub error: &'a str, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::invalid_register_class)] pub struct InvalidRegisterClass<'a> { #[primary_span] @@ -209,7 +209,7 @@ pub struct InvalidRegisterClass<'a> { pub error: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(ast_lowering::invalid_asm_template_modifier_reg_class)] pub struct InvalidAsmTemplateModifierRegClass { #[primary_span] @@ -229,7 +229,7 @@ pub enum InvalidAsmTemplateModifierRegClassSub { DoesNotSupportModifier { class_name: Symbol }, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::invalid_asm_template_modifier_const)] pub struct InvalidAsmTemplateModifierConst { #[primary_span] @@ -239,7 +239,7 @@ pub struct InvalidAsmTemplateModifierConst { pub op_span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::invalid_asm_template_modifier_sym)] pub struct InvalidAsmTemplateModifierSym { #[primary_span] @@ -249,7 +249,7 @@ pub struct InvalidAsmTemplateModifierSym { pub op_span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::register_class_only_clobber)] pub struct RegisterClassOnlyClobber { #[primary_span] @@ -257,7 +257,7 @@ pub struct RegisterClassOnlyClobber { pub reg_class_name: Symbol, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::register_conflict)] pub struct RegisterConflict<'a> { #[primary_span] @@ -271,7 +271,7 @@ pub struct RegisterConflict<'a> { pub in_out: Option, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[help] #[diag(ast_lowering::sub_tuple_binding)] pub struct SubTupleBinding<'a> { @@ -288,7 +288,7 @@ pub struct SubTupleBinding<'a> { pub ctx: &'a str, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::extra_double_dot)] pub struct ExtraDoubleDot<'a> { #[primary_span] @@ -299,7 +299,7 @@ pub struct ExtraDoubleDot<'a> { pub ctx: &'a str, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[note] #[diag(ast_lowering::misplaced_double_dot)] pub struct MisplacedDoubleDot { @@ -307,28 +307,28 @@ pub struct MisplacedDoubleDot { pub span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::misplaced_relax_trait_bound)] pub struct MisplacedRelaxTraitBound { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::not_supported_for_lifetime_binder_async_closure)] pub struct NotSupportedForLifetimeBinderAsyncClosure { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::arbitrary_expression_in_pattern)] pub struct ArbitraryExpressionInPattern { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::inclusive_range_with_no_end)] pub struct InclusiveRangeWithNoEnd { #[primary_span] diff --git a/compiler/rustc_attr/src/session_diagnostics.rs b/compiler/rustc_attr/src/session_diagnostics.rs index 8362b51af40..5e8f9b79850 100644 --- a/compiler/rustc_attr/src/session_diagnostics.rs +++ b/compiler/rustc_attr/src/session_diagnostics.rs @@ -5,19 +5,19 @@ use rustc_errors::{ error_code, fluent, Applicability, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, Handler, }; -use rustc_macros::DiagnosticHandler; +use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; use crate::UnsupportedLiteralReason; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::expected_one_cfg_pattern, code = "E0536")] pub(crate) struct ExpectedOneCfgPattern { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::invalid_predicate, code = "E0537")] pub(crate) struct InvalidPredicate { #[primary_span] @@ -26,7 +26,7 @@ pub(crate) struct InvalidPredicate { pub predicate: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::multiple_item, code = "E0538")] pub(crate) struct MultipleItem { #[primary_span] @@ -35,7 +35,7 @@ pub(crate) struct MultipleItem { pub item: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::incorrect_meta_item, code = "E0539")] pub(crate) struct IncorrectMetaItem { #[primary_span] @@ -65,28 +65,28 @@ impl<'a> IntoDiagnostic<'a> for UnknownMetaItem<'_> { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::missing_since, code = "E0542")] pub(crate) struct MissingSince { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::missing_note, code = "E0543")] pub(crate) struct MissingNote { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::multiple_stability_levels, code = "E0544")] pub(crate) struct MultipleStabilityLevels { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::invalid_issue_string, code = "E0545")] pub(crate) struct InvalidIssueString { #[primary_span] @@ -144,21 +144,21 @@ impl InvalidIssueStringCause { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::missing_feature, code = "E0546")] pub(crate) struct MissingFeature { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::non_ident_feature, code = "E0546")] pub(crate) struct NonIdentFeature { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::missing_issue, code = "E0547")] pub(crate) struct MissingIssue { #[primary_span] @@ -167,7 +167,7 @@ pub(crate) struct MissingIssue { // FIXME: This diagnostic is identical to `IncorrectMetaItem`, barring the error code. Consider // changing this to `IncorrectMetaItem`. See #51489. -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::incorrect_meta_item, code = "E0551")] pub(crate) struct IncorrectMetaItem2 { #[primary_span] @@ -176,14 +176,14 @@ pub(crate) struct IncorrectMetaItem2 { // FIXME: Why is this the same error code as `InvalidReprHintNoParen` and `InvalidReprHintNoValue`? // It is more similar to `IncorrectReprFormatGeneric`. -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::incorrect_repr_format_packed_one_or_zero_arg, code = "E0552")] pub(crate) struct IncorrectReprFormatPackedOneOrZeroArg { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::invalid_repr_hint_no_paren, code = "E0552")] pub(crate) struct InvalidReprHintNoParen { #[primary_span] @@ -192,7 +192,7 @@ pub(crate) struct InvalidReprHintNoParen { pub name: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::invalid_repr_hint_no_value, code = "E0552")] pub(crate) struct InvalidReprHintNoValue { #[primary_span] @@ -237,7 +237,7 @@ impl<'a> IntoDiagnostic<'a> for UnsupportedLiteral { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::invalid_repr_align_need_arg, code = "E0589")] pub(crate) struct InvalidReprAlignNeedArg { #[primary_span] @@ -245,7 +245,7 @@ pub(crate) struct InvalidReprAlignNeedArg { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::invalid_repr_generic, code = "E0589")] pub(crate) struct InvalidReprGeneric<'a> { #[primary_span] @@ -255,14 +255,14 @@ pub(crate) struct InvalidReprGeneric<'a> { pub error_part: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::incorrect_repr_format_align_one_arg, code = "E0693")] pub(crate) struct IncorrectReprFormatAlignOneArg { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::incorrect_repr_format_generic, code = "E0693")] pub(crate) struct IncorrectReprFormatGeneric<'a> { #[primary_span] @@ -317,28 +317,28 @@ impl<'a> IncorrectReprFormatGenericCause<'a> { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::rustc_promotable_pairing, code = "E0717")] pub(crate) struct RustcPromotablePairing { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::rustc_allowed_unstable_pairing, code = "E0789")] pub(crate) struct RustcAllowedUnstablePairing { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::cfg_predicate_identifier)] pub(crate) struct CfgPredicateIdentifier { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::deprecated_item_suggestion)] pub(crate) struct DeprecatedItemSuggestion { #[primary_span] @@ -351,21 +351,21 @@ pub(crate) struct DeprecatedItemSuggestion { pub details: (), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::expected_single_version_literal)] pub(crate) struct ExpectedSingleVersionLiteral { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::expected_version_literal)] pub(crate) struct ExpectedVersionLiteral { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::expects_feature_list)] pub(crate) struct ExpectsFeatureList { #[primary_span] @@ -374,7 +374,7 @@ pub(crate) struct ExpectsFeatureList { pub name: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::expects_features)] pub(crate) struct ExpectsFeatures { #[primary_span] @@ -383,14 +383,14 @@ pub(crate) struct ExpectsFeatures { pub name: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::soft_no_args)] pub(crate) struct SoftNoArgs { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(attr::unknown_version_literal)] pub(crate) struct UnknownVersionLiteral { #[primary_span] diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index 1014a92cc39..aa8f26eece5 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -1,11 +1,11 @@ use rustc_errors::{IntoDiagnosticArg, MultiSpan}; -use rustc_macros::{DiagnosticHandler, LintDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic}; use rustc_middle::ty::Ty; use rustc_span::Span; use crate::diagnostics::RegionName; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(borrowck::move_unsized, code = "E0161")] pub(crate) struct MoveUnsized<'tcx> { pub ty: Ty<'tcx>, @@ -14,7 +14,7 @@ pub(crate) struct MoveUnsized<'tcx> { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(borrowck::higher_ranked_lifetime_error)] pub(crate) struct HigherRankedLifetimeError { #[subdiagnostic] @@ -31,14 +31,14 @@ pub(crate) enum HigherRankedErrorCause { CouldNotNormalize { value: String }, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(borrowck::higher_ranked_subtype_error)] pub(crate) struct HigherRankedSubtypeError { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(borrowck::generic_does_not_live_long_enough)] pub(crate) struct GenericDoesNotLiveLongEnough { pub kind: String, @@ -53,7 +53,7 @@ pub(crate) struct VarNeedNotMut { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(borrowck::const_not_used_in_type_alias)] pub(crate) struct ConstNotUsedTraitAlias { pub ct: String, @@ -61,7 +61,7 @@ pub(crate) struct ConstNotUsedTraitAlias { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(borrowck::var_cannot_escape_closure)] #[note] #[note(borrowck::cannot_escape)] @@ -110,7 +110,7 @@ pub(crate) enum FnMutReturnTypeErr { }, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(borrowck::lifetime_constraints_error)] pub(crate) struct LifetimeOutliveErr { #[primary_span] diff --git a/compiler/rustc_builtin_macros/src/cfg.rs b/compiler/rustc_builtin_macros/src/cfg.rs index 55b54fede93..46b54eae384 100644 --- a/compiler/rustc_builtin_macros/src/cfg.rs +++ b/compiler/rustc_builtin_macros/src/cfg.rs @@ -8,7 +8,7 @@ use rustc_ast::tokenstream::TokenStream; use rustc_attr as attr; use rustc_errors::PResult; use rustc_expand::base::{self, *}; -use rustc_macros::DiagnosticHandler; +use rustc_macros::Diagnostic; use rustc_span::Span; pub fn expand_cfg( @@ -35,7 +35,7 @@ pub fn expand_cfg( } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(builtin_macros::requires_cfg_pattern)] struct RequiresCfgPattern { #[primary_span] @@ -43,7 +43,7 @@ struct RequiresCfgPattern { span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(builtin_macros::expected_one_cfg_pattern)] struct OneCfgPattern { #[primary_span] diff --git a/compiler/rustc_const_eval/src/errors.rs b/compiler/rustc_const_eval/src/errors.rs index d0b94e91abf..c6cb7a8b961 100644 --- a/compiler/rustc_const_eval/src/errors.rs +++ b/compiler/rustc_const_eval/src/errors.rs @@ -1,8 +1,8 @@ use rustc_hir::ConstContext; -use rustc_macros::DiagnosticHandler; +use rustc_macros::Diagnostic; use rustc_span::Span; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::unstable_in_stable)] pub(crate) struct UnstableInStable { pub gate: String, @@ -21,14 +21,14 @@ pub(crate) struct UnstableInStable { pub attr_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::thread_local_access, code = "E0625")] pub(crate) struct NonConstOpErr { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::static_access, code = "E0013")] #[help] pub(crate) struct StaticAccessErr { @@ -40,7 +40,7 @@ pub(crate) struct StaticAccessErr { pub teach: Option<()>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::raw_ptr_to_int)] #[note] #[note(const_eval::note2)] @@ -49,7 +49,7 @@ pub(crate) struct RawPtrToIntErr { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::raw_ptr_comparison)] #[note] pub(crate) struct RawPtrComparisonErr { @@ -57,14 +57,14 @@ pub(crate) struct RawPtrComparisonErr { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::panic_non_str)] pub(crate) struct PanicNonStrErr { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::mut_deref, code = "E0658")] pub(crate) struct MutDerefErr { #[primary_span] @@ -72,7 +72,7 @@ pub(crate) struct MutDerefErr { pub kind: ConstContext, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::transient_mut_borrow, code = "E0658")] pub(crate) struct TransientMutBorrowErr { #[primary_span] @@ -80,7 +80,7 @@ pub(crate) struct TransientMutBorrowErr { pub kind: ConstContext, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::transient_mut_borrow_raw, code = "E0658")] pub(crate) struct TransientMutBorrowErrRaw { #[primary_span] @@ -88,7 +88,7 @@ pub(crate) struct TransientMutBorrowErrRaw { pub kind: ConstContext, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::max_num_nodes_in_const)] pub(crate) struct MaxNumNodesInConstErr { #[primary_span] @@ -96,7 +96,7 @@ pub(crate) struct MaxNumNodesInConstErr { pub global_const_id: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::unallowed_fn_pointer_call)] pub(crate) struct UnallowedFnPointerCall { #[primary_span] @@ -104,7 +104,7 @@ pub(crate) struct UnallowedFnPointerCall { pub kind: ConstContext, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::unstable_const_fn)] pub(crate) struct UnstableConstFn { #[primary_span] @@ -112,7 +112,7 @@ pub(crate) struct UnstableConstFn { pub def_path: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::unallowed_mutable_refs, code = "E0764")] pub(crate) struct UnallowedMutableRefs { #[primary_span] @@ -122,7 +122,7 @@ pub(crate) struct UnallowedMutableRefs { pub teach: Option<()>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::unallowed_mutable_refs_raw, code = "E0764")] pub(crate) struct UnallowedMutableRefsRaw { #[primary_span] @@ -131,7 +131,7 @@ pub(crate) struct UnallowedMutableRefsRaw { #[note(const_eval::teach_note)] pub teach: Option<()>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::non_const_fmt_macro_call, code = "E0015")] pub(crate) struct NonConstFmtMacroCall { #[primary_span] @@ -139,7 +139,7 @@ pub(crate) struct NonConstFmtMacroCall { pub kind: ConstContext, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::non_const_fn_call, code = "E0015")] pub(crate) struct NonConstFnCall { #[primary_span] @@ -148,7 +148,7 @@ pub(crate) struct NonConstFnCall { pub kind: ConstContext, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::unallowed_op_in_const_context)] pub(crate) struct UnallowedOpInConstContext { #[primary_span] @@ -156,7 +156,7 @@ pub(crate) struct UnallowedOpInConstContext { pub msg: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::unallowed_heap_allocations, code = "E0010")] pub(crate) struct UnallowedHeapAllocations { #[primary_span] @@ -167,7 +167,7 @@ pub(crate) struct UnallowedHeapAllocations { pub teach: Option<()>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::unallowed_inline_asm, code = "E0015")] pub(crate) struct UnallowedInlineAsm { #[primary_span] @@ -175,7 +175,7 @@ pub(crate) struct UnallowedInlineAsm { pub kind: ConstContext, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::interior_mutable_data_refer, code = "E0492")] pub(crate) struct InteriorMutableDataRefer { #[primary_span] @@ -188,7 +188,7 @@ pub(crate) struct InteriorMutableDataRefer { pub teach: Option<()>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(const_eval::interior_mutability_borrow)] pub(crate) struct InteriorMutabilityBorrow { #[primary_span] diff --git a/compiler/rustc_driver/src/session_diagnostics.rs b/compiler/rustc_driver/src/session_diagnostics.rs index 704d3c7fd2a..289baf17773 100644 --- a/compiler/rustc_driver/src/session_diagnostics.rs +++ b/compiler/rustc_driver/src/session_diagnostics.rs @@ -1,38 +1,38 @@ -use rustc_macros::DiagnosticHandler; +use rustc_macros::Diagnostic; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(driver::rlink_unable_to_read)] pub(crate) struct RlinkUnableToRead { pub err: std::io::Error, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(driver::rlink_wrong_file_type)] pub(crate) struct RLinkWrongFileType; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(driver::rlink_empty_version_number)] pub(crate) struct RLinkEmptyVersionNumber; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(driver::rlink_encoding_version_mismatch)] pub(crate) struct RLinkEncodingVersionMismatch { pub version_array: String, pub rlink_version: u32, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(driver::rlink_rustc_version_mismatch)] pub(crate) struct RLinkRustcVersionMismatch<'a> { pub rustc_version: String, pub current_version: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(driver::rlink_no_a_file)] pub(crate) struct RlinkNotAFile; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(driver::unpretty_dump_fail)] pub(crate) struct UnprettyDumpFail { pub path: String, diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index 209a50fd306..f9b46053486 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -14,9 +14,9 @@ use std::ops::{Deref, DerefMut}; use std::thread::panicking; /// Trait implemented by error types. This should not be implemented manually. Instead, use -/// `#[derive(DiagnosticHandler)]` -- see [rustc_macros::DiagnosticHandler]. +/// `#[derive(Diagnostic)]` -- see [rustc_macros::Diagnostic]. #[cfg_attr(bootstrap, rustc_diagnostic_item = "SessionDiagnostic")] -#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "DiagnosticHandler")] +#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "Diagnostic")] pub trait IntoDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> { /// Write out as a diagnostic out of `Handler`. #[must_use] diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index 7cbdad3cd95..bd93f0717f5 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -1,29 +1,29 @@ -use rustc_macros::DiagnosticHandler; +use rustc_macros::Diagnostic; use rustc_span::symbol::MacroRulesNormalizedIdent; use rustc_span::Span; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(expand::expr_repeat_no_syntax_vars)] pub(crate) struct NoSyntaxVarsExprRepeat { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(expand::must_repeat_once)] pub(crate) struct MustRepeatOnce { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(expand::count_repetition_misplaced)] pub(crate) struct CountRepetitionMisplaced { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(expand::meta_var_expr_unrecognized_var)] pub(crate) struct MetaVarExprUnrecognizedVar { #[primary_span] @@ -31,7 +31,7 @@ pub(crate) struct MetaVarExprUnrecognizedVar { pub key: MacroRulesNormalizedIdent, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(expand::var_still_repeating)] pub(crate) struct VarStillRepeating { #[primary_span] @@ -39,7 +39,7 @@ pub(crate) struct VarStillRepeating { pub ident: MacroRulesNormalizedIdent, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(expand::meta_var_dif_seq_matchers)] pub(crate) struct MetaVarsDifSeqMatchers { #[primary_span] diff --git a/compiler/rustc_interface/src/errors.rs b/compiler/rustc_interface/src/errors.rs index dc975099fc7..097640f26c1 100644 --- a/compiler/rustc_interface/src/errors.rs +++ b/compiler/rustc_interface/src/errors.rs @@ -1,10 +1,10 @@ -use rustc_macros::DiagnosticHandler; +use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; use std::io; use std::path::Path; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::ferris_identifier)] pub struct FerrisIdentifier { #[primary_span] @@ -13,7 +13,7 @@ pub struct FerrisIdentifier { pub first_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::emoji_identifier)] pub struct EmojiIdentifier { #[primary_span] @@ -21,67 +21,67 @@ pub struct EmojiIdentifier { pub ident: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::mixed_bin_crate)] pub struct MixedBinCrate; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::mixed_proc_macro_crate)] pub struct MixedProcMacroCrate; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::proc_macro_doc_without_arg)] pub struct ProcMacroDocWithoutArg; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::error_writing_dependencies)] pub struct ErrorWritingDependencies<'a> { pub path: &'a Path, pub error: io::Error, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::input_file_would_be_overwritten)] pub struct InputFileWouldBeOverWritten<'a> { pub path: &'a Path, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::generated_file_conflicts_with_directory)] pub struct GeneratedFileConflictsWithDirectory<'a> { pub input_path: &'a Path, pub dir_path: &'a Path, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::temps_dir_error)] pub struct TempsDirError; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::out_dir_error)] pub struct OutDirError; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::cant_emit_mir)] pub struct CantEmitMIR { pub error: io::Error, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::rustc_error_fatal)] pub struct RustcErrorFatal { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::rustc_error_unexpected_annotation)] pub struct RustcErrorUnexpectedAnnotation { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(interface::failed_writing_file)] pub struct FailedWritingFile<'a> { pub path: &'a Path, diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs index e5670833898..0c66ce475c4 100644 --- a/compiler/rustc_lint/src/errors.rs +++ b/compiler/rustc_lint/src/errors.rs @@ -1,9 +1,9 @@ use rustc_errors::{fluent, AddToDiagnostic, IntoDiagnostic, ErrorGuaranteed, Handler}; -use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, SessionSubdiagnostic}; use rustc_session::lint::Level; use rustc_span::{Span, Symbol}; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(lint::overruled_attribute, code = "E0453")] pub struct OverruledAttribute { #[primary_span] @@ -42,7 +42,7 @@ impl AddToDiagnostic for OverruledAttributeSub { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(lint::malformed_attribute, code = "E0452")] pub struct MalformedAttribute { #[primary_span] @@ -61,7 +61,7 @@ pub enum MalformedAttributeSub { ReasonMustComeLast(#[primary_span] Span), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(lint::unknown_tool_in_scoped_lint, code = "E0710")] pub struct UnknownToolInScopedLint { #[primary_span] @@ -72,7 +72,7 @@ pub struct UnknownToolInScopedLint { pub is_nightly_build: Option<()>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(lint::builtin_ellipsis_inclusive_range_patterns, code = "E0783")] pub struct BuiltinEllpisisInclusiveRangePatterns { #[primary_span] @@ -107,7 +107,7 @@ impl AddToDiagnostic for RequestedLevel { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(lint::unsupported_group, code = "E0602")] pub struct UnsupportedGroup { pub lint_group: String, @@ -136,7 +136,7 @@ impl IntoDiagnostic<'_> for CheckNameUnknown { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(lint::check_name_unknown_tool, code = "E0602")] pub struct CheckNameUnknownTool { pub tool_name: Symbol, @@ -144,7 +144,7 @@ pub struct CheckNameUnknownTool { pub sub: RequestedLevel, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(lint::check_name_warning)] pub struct CheckNameWarning { pub msg: String, @@ -152,7 +152,7 @@ pub struct CheckNameWarning { pub sub: RequestedLevel, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(lint::check_name_deprecated)] pub struct CheckNameDeprecated { pub lint_name: String, diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 47da8ec5da1..36d8ade22ae 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -372,7 +372,7 @@ declare_tool_lint! { declare_tool_lint! { pub rustc::DIAGNOSTIC_OUTSIDE_OF_IMPL, Allow, - "prevent creation of diagnostics outside of `DiagnosticHandler`/`AddToDiagnostic` impls", + "prevent creation of diagnostics outside of `IntoDiagnostic`/`AddToDiagnostic` impls", report_in_external_macro: true } @@ -404,7 +404,7 @@ impl LateLintPass<'_> for Diagnostics { let Impl { of_trait: Some(of_trait), .. } = impl_ && let Some(def_id) = of_trait.trait_def_id() && let Some(name) = cx.tcx.get_diagnostic_name(def_id) && - matches!(name, sym::DiagnosticHandler | sym::AddSubdiagnostic | sym::DecorateLint) + matches!(name, sym::Diagnostic | sym::AddSubdiagnostic | sym::DecorateLint) { found_impl = true; break; diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs index c5b5edab816..c1aae04fcee 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs @@ -21,7 +21,7 @@ impl<'a> SessionDiagnosticDerive<'a> { builder: DiagnosticDeriveBuilder { diag, fields: build_field_mapping(&structure), - kind: DiagnosticDeriveKind::DiagnosticHandler, + kind: DiagnosticDeriveKind::Diagnostic, code: None, slug: None, }, @@ -72,7 +72,7 @@ impl<'a> SessionDiagnosticDerive<'a> { } else { span_err( ast.span().unwrap(), - "`#[derive(DiagnosticHandler)]` can only be used on structs", + "`#[derive(Diagnostic)]` can only be used on structs", ) .emit(); diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs index 4af3fd23624..32d6ba62a0d 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs @@ -21,12 +21,12 @@ use synstructure::{BindingInfo, Structure}; /// What kind of diagnostic is being derived - a fatal/error/warning or a lint? #[derive(Copy, Clone, PartialEq, Eq)] pub(crate) enum DiagnosticDeriveKind { - DiagnosticHandler, + Diagnostic, LintDiagnostic, } /// Tracks persistent information required for building up individual calls to diagnostic methods -/// for generated diagnostic derives - both `DiagnosticHandler` for fatal/errors/warnings and +/// for generated diagnostic derives - both `Diagnostic` for fatal/errors/warnings and /// `LintDiagnostic` for lints. pub(crate) struct DiagnosticDeriveBuilder { /// The identifier to use for the generated `DiagnosticBuilder` instance. @@ -333,7 +333,7 @@ impl DiagnosticDeriveBuilder { } "primary_span" => { match self.kind { - DiagnosticDeriveKind::DiagnosticHandler => { + DiagnosticDeriveKind::Diagnostic => { report_error_if_not_applied_to_span(attr, &info)?; Ok(quote! { diff --git a/compiler/rustc_macros/src/diagnostics/mod.rs b/compiler/rustc_macros/src/diagnostics/mod.rs index 162089c881e..1d5b32c2556 100644 --- a/compiler/rustc_macros/src/diagnostics/mod.rs +++ b/compiler/rustc_macros/src/diagnostics/mod.rs @@ -12,7 +12,7 @@ use quote::format_ident; use subdiagnostic::SessionSubdiagnosticDerive; use synstructure::Structure; -/// Implements `#[derive(DiagnosticHandler)]`, which allows for errors to be specified as a struct, +/// Implements `#[derive(Diagnostic)]`, which allows for errors to be specified as a struct, /// independent from the actual diagnostics emitting code. /// /// ```ignore (rust) @@ -22,7 +22,7 @@ use synstructure::Structure; /// # use rustc_span::{symbol::Ident, Span}; /// # extern crate rust_middle; /// # use rustc_middle::ty::Ty; -/// #[derive(DiagnosticHandler)] +/// #[derive(Diagnostic)] /// #[diag(borrowck::move_out_of_borrow, code = "E0505")] /// pub struct MoveOutOfBorrowError<'tcx> { /// pub name: Ident, @@ -56,7 +56,7 @@ use synstructure::Structure; /// }); /// ``` /// -/// See rustc dev guide for more examples on using the `#[derive(DiagnosticHandler)]`: +/// See rustc dev guide for more examples on using the `#[derive(Diagnostic)]`: /// pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream { SessionDiagnosticDerive::new(format_ident!("diag"), format_ident!("handler"), s).into_tokens() diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index 13305782ff1..9dd7ccad8bb 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -127,7 +127,7 @@ decl_derive!([TypeFoldable, attributes(type_foldable)] => type_foldable::type_fo decl_derive!([TypeVisitable, attributes(type_visitable)] => type_visitable::type_visitable_derive); decl_derive!([Lift, attributes(lift)] => lift::lift_derive); decl_derive!( - [DiagnosticHandler, attributes( + [Diagnostic, attributes( // struct attributes diag, help, diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 0a5973ca1aa..8ff4eb5fdbc 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -4,48 +4,48 @@ use std::{ }; use rustc_errors::{error_code, IntoDiagnostic, ErrorGuaranteed}; -use rustc_macros::DiagnosticHandler; +use rustc_macros::Diagnostic; use rustc_session::config; use rustc_span::{sym, Span, Symbol}; use rustc_target::spec::{PanicStrategy, TargetTriple}; use crate::locator::CrateFlavor; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::rlib_required)] pub struct RlibRequired { pub crate_name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::lib_required)] pub struct LibRequired<'a> { pub crate_name: Symbol, pub kind: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::crate_dep_multiple)] #[help] pub struct CrateDepMultiple { pub crate_name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::two_panic_runtimes)] pub struct TwoPanicRuntimes { pub prev_name: Symbol, pub cur_name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::bad_panic_strategy)] pub struct BadPanicStrategy { pub runtime: Symbol, pub strategy: PanicStrategy, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::required_panic_strategy)] pub struct RequiredPanicStrategy { pub crate_name: Symbol, @@ -53,7 +53,7 @@ pub struct RequiredPanicStrategy { pub desired_strategy: PanicStrategy, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::incompatible_panic_in_drop_strategy)] pub struct IncompatiblePanicInDropStrategy { pub crate_name: Symbol, @@ -61,56 +61,56 @@ pub struct IncompatiblePanicInDropStrategy { pub desired_strategy: PanicStrategy, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::multiple_names_in_link)] pub struct MultipleNamesInLink { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::multiple_kinds_in_link)] pub struct MultipleKindsInLink { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::link_name_form)] pub struct LinkNameForm { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::link_kind_form)] pub struct LinkKindForm { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::link_modifiers_form)] pub struct LinkModifiersForm { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::link_cfg_form)] pub struct LinkCfgForm { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::wasm_import_form)] pub struct WasmImportForm { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::empty_link_name, code = "E0454")] pub struct EmptyLinkName { #[primary_span] @@ -118,21 +118,21 @@ pub struct EmptyLinkName { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::link_framework_apple, code = "E0455")] pub struct LinkFrameworkApple { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::framework_only_windows, code = "E0455")] pub struct FrameworkOnlyWindows { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::unknown_link_kind, code = "E0458")] pub struct UnknownLinkKind<'a> { #[primary_span] @@ -141,49 +141,49 @@ pub struct UnknownLinkKind<'a> { pub kind: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::multiple_link_modifiers)] pub struct MultipleLinkModifiers { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::multiple_cfgs)] pub struct MultipleCfgs { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::link_cfg_single_predicate)] pub struct LinkCfgSinglePredicate { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::multiple_wasm_import)] pub struct MultipleWasmImport { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::unexpected_link_arg)] pub struct UnexpectedLinkArg { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::invalid_link_modifier)] pub struct InvalidLinkModifier { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::multiple_modifiers)] pub struct MultipleModifiers<'a> { #[primary_span] @@ -191,28 +191,28 @@ pub struct MultipleModifiers<'a> { pub modifier: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::bundle_needs_static)] pub struct BundleNeedsStatic { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::whole_archive_needs_static)] pub struct WholeArchiveNeedsStatic { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::as_needed_compatibility)] pub struct AsNeededCompatibility { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::unknown_link_modifier)] pub struct UnknownLinkModifier<'a> { #[primary_span] @@ -220,14 +220,14 @@ pub struct UnknownLinkModifier<'a> { pub modifier: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::incompatible_wasm_link)] pub struct IncompatibleWasmLink { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::link_requires_name, code = "E0459")] pub struct LinkRequiresName { #[primary_span] @@ -235,105 +235,105 @@ pub struct LinkRequiresName { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::raw_dylib_no_nul)] pub struct RawDylibNoNul { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::link_ordinal_raw_dylib)] pub struct LinkOrdinalRawDylib { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::lib_framework_apple)] pub struct LibFrameworkApple; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::empty_renaming_target)] pub struct EmptyRenamingTarget<'a> { pub lib_name: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::renaming_no_link)] pub struct RenamingNoLink<'a> { pub lib_name: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::multiple_renamings)] pub struct MultipleRenamings<'a> { pub lib_name: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::no_link_mod_override)] pub struct NoLinkModOverride { #[primary_span] pub span: Option, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::unsupported_abi_i686)] pub struct UnsupportedAbiI686 { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::unsupported_abi)] pub struct UnsupportedAbi { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::fail_create_file_encoder)] pub struct FailCreateFileEncoder { pub err: Error, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::fail_seek_file)] pub struct FailSeekFile { pub err: Error, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::fail_write_file)] pub struct FailWriteFile { pub err: Error, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::crate_not_panic_runtime)] pub struct CrateNotPanicRuntime { pub crate_name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::no_panic_strategy)] pub struct NoPanicStrategy { pub crate_name: Symbol, pub strategy: PanicStrategy, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::profiler_builtins_needs_core)] pub struct ProfilerBuiltinsNeedsCore; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::not_profiler_runtime)] pub struct NotProfilerRuntime { pub crate_name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::no_multiple_global_alloc)] pub struct NoMultipleGlobalAlloc { #[primary_span] @@ -343,18 +343,18 @@ pub struct NoMultipleGlobalAlloc { pub span1: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::conflicting_global_alloc)] pub struct ConflictingGlobalAlloc { pub crate_name: Symbol, pub other_crate_name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::global_alloc_required)] pub struct GlobalAllocRequired; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::no_transitive_needs_dep)] pub struct NoTransitiveNeedsDep<'a> { pub crate_name: Symbol, @@ -362,39 +362,39 @@ pub struct NoTransitiveNeedsDep<'a> { pub deps_crate_name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::failed_write_error)] pub struct FailedWriteError { pub filename: PathBuf, pub err: Error, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(metadata::missing_native_library)] pub struct MissingNativeLibrary<'a> { pub libname: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(metadata::failed_create_tempdir)] pub struct FailedCreateTempdir { pub err: Error, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::failed_create_file)] pub struct FailedCreateFile<'a> { pub filename: &'a Path, pub err: Error, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::failed_create_encoded_metadata)] pub struct FailedCreateEncodedMetadata { pub err: Error, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::non_ascii_name)] pub struct NonAsciiName { #[primary_span] @@ -402,7 +402,7 @@ pub struct NonAsciiName { pub crate_name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::extern_location_not_exist)] pub struct ExternLocationNotExist<'a> { #[primary_span] @@ -411,7 +411,7 @@ pub struct ExternLocationNotExist<'a> { pub location: &'a Path, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::extern_location_not_file)] pub struct ExternLocationNotFile<'a> { #[primary_span] @@ -444,7 +444,7 @@ impl IntoDiagnostic<'_> for MultipleCandidates { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::multiple_matching_crates, code = "E0464")] #[note] pub struct MultipleMatchingCrates { @@ -454,7 +454,7 @@ pub struct MultipleMatchingCrates { pub candidates: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::symbol_conflicts_current, code = "E0519")] pub struct SymbolConflictsCurrent { #[primary_span] @@ -462,7 +462,7 @@ pub struct SymbolConflictsCurrent { pub crate_name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::symbol_conflicts_others, code = "E0523")] pub struct SymbolConflictsOthers { #[primary_span] @@ -470,7 +470,7 @@ pub struct SymbolConflictsOthers { pub crate_name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::stable_crate_id_collision)] pub struct StableCrateIdCollision { #[primary_span] @@ -479,7 +479,7 @@ pub struct StableCrateIdCollision { pub crate_name1: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::dl_error)] pub struct DlError { #[primary_span] @@ -487,7 +487,7 @@ pub struct DlError { pub err: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::newer_crate_version, code = "E0460")] #[note] #[note(metadata::found_crate_versions)] @@ -499,7 +499,7 @@ pub struct NewerCrateVersion { pub found_crates: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::no_crate_with_triple, code = "E0461")] #[note(metadata::found_crate_versions)] pub struct NoCrateWithTriple<'a> { @@ -511,7 +511,7 @@ pub struct NoCrateWithTriple<'a> { pub found_crates: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::found_staticlib, code = "E0462")] #[note(metadata::found_crate_versions)] #[help] @@ -523,7 +523,7 @@ pub struct FoundStaticlib { pub found_crates: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::incompatible_rustc, code = "E0514")] #[note(metadata::found_crate_versions)] #[help] @@ -617,7 +617,7 @@ impl IntoDiagnostic<'_> for CannotFindCrate { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::no_dylib_plugin, code = "E0457")] pub struct NoDylibPlugin { #[primary_span] @@ -625,7 +625,7 @@ pub struct NoDylibPlugin { pub crate_name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::crate_location_unknown_type)] pub struct CrateLocationUnknownType<'a> { #[primary_span] @@ -633,7 +633,7 @@ pub struct CrateLocationUnknownType<'a> { pub path: &'a Path, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::lib_filename_form)] pub struct LibFilenameForm<'a> { #[primary_span] @@ -642,28 +642,28 @@ pub struct LibFilenameForm<'a> { pub dll_suffix: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::multiple_import_name_type)] pub struct MultipleImportNameType { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::import_name_type_form)] pub struct ImportNameTypeForm { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::import_name_type_x86)] pub struct ImportNameTypeX86 { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::unknown_import_name_type)] pub struct UnknownImportNameType<'a> { #[primary_span] @@ -671,7 +671,7 @@ pub struct UnknownImportNameType<'a> { pub import_name_type: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(metadata::import_name_type_raw)] pub struct ImportNameTypeRaw { #[primary_span] diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index effda9c0557..6d15feb888a 100644 --- a/compiler/rustc_middle/src/error.rs +++ b/compiler/rustc_middle/src/error.rs @@ -1,9 +1,9 @@ -use rustc_macros::DiagnosticHandler; +use rustc_macros::Diagnostic; use rustc_span::Span; use crate::ty::Ty; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(middle::drop_check_overflow, code = "E0320")] #[note] pub struct DropCheckOverflow<'tcx> { @@ -13,7 +13,7 @@ pub struct DropCheckOverflow<'tcx> { pub overflow_ty: Ty<'tcx>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(middle::opaque_hidden_type_mismatch)] pub struct OpaqueHiddenTypeMismatch<'tcx> { pub self_ty: Ty<'tcx>, @@ -39,7 +39,7 @@ pub enum TypeMismatchReason { }, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(middle::limit_invalid)] pub struct LimitInvalid<'a> { #[primary_span] diff --git a/compiler/rustc_mir_dataflow/src/errors.rs b/compiler/rustc_mir_dataflow/src/errors.rs index 0d36abed2c0..5b1a88cb284 100644 --- a/compiler/rustc_mir_dataflow/src/errors.rs +++ b/compiler/rustc_mir_dataflow/src/errors.rs @@ -1,21 +1,21 @@ -use rustc_macros::DiagnosticHandler; +use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(mir_dataflow::path_must_end_in_filename)] pub(crate) struct PathMustEndInFilename { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(mir_dataflow::unknown_formatter)] pub(crate) struct UnknownFormatter { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(mir_dataflow::duplicate_values_for)] pub(crate) struct DuplicateValuesFor { #[primary_span] @@ -23,7 +23,7 @@ pub(crate) struct DuplicateValuesFor { pub name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(mir_dataflow::requires_an_argument)] pub(crate) struct RequiresAnArgument { #[primary_span] @@ -31,39 +31,39 @@ pub(crate) struct RequiresAnArgument { pub name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(mir_dataflow::stop_after_dataflow_ended_compilation)] pub(crate) struct StopAfterDataFlowEndedCompilation; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(mir_dataflow::peek_must_be_place_or_ref_place)] pub(crate) struct PeekMustBePlaceOrRefPlace { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(mir_dataflow::peek_must_be_not_temporary)] pub(crate) struct PeekMustBeNotTemporary { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(mir_dataflow::peek_bit_not_set)] pub(crate) struct PeekBitNotSet { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(mir_dataflow::peek_argument_not_a_local)] pub(crate) struct PeekArgumentNotALocal { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(mir_dataflow::peek_argument_untracked)] pub(crate) struct PeekArgumentUntracked { #[primary_span] diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs index 150a702dc24..cdc2c74ac8f 100644 --- a/compiler/rustc_monomorphize/src/errors.rs +++ b/compiler/rustc_monomorphize/src/errors.rs @@ -2,10 +2,10 @@ use std::path::PathBuf; use rustc_errors::IntoDiagnostic; use rustc_errors::ErrorGuaranteed; -use rustc_macros::{DiagnosticHandler, LintDiagnostic}; +use rustc_macros::{Diagnostic, LintDiagnostic}; use rustc_span::Span; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(monomorphize::recursion_limit)] pub struct RecursionLimit { #[primary_span] @@ -19,7 +19,7 @@ pub struct RecursionLimit { pub path: PathBuf, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(monomorphize::type_length_limit)] #[help(monomorphize::consider_type_length_limit)] pub struct TypeLengthLimit { @@ -32,7 +32,7 @@ pub struct TypeLengthLimit { pub type_length: usize, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(monomorphize::requires_lang_item)] pub struct RequiresLangItem { pub lang_item: String, @@ -72,11 +72,11 @@ pub struct LargeAssignmentsLint { pub limit: u64, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(monomorphize::unknown_partition_strategy)] pub struct UnknownPartitionStrategy; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(monomorphize::symbol_already_defined)] pub struct SymbolAlreadyDefined { #[primary_span] diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 02148193cf0..9989ebb7cdf 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -20,7 +20,7 @@ use rustc_errors::{ fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult, }; use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed}; -use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, SessionSubdiagnostic}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::{Span, SpanSnippetError, DUMMY_SP}; @@ -242,7 +242,7 @@ impl MultiSugg { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::maybe_report_ambiguous_plus)] struct AmbiguousPlus { pub sum_ty: String, @@ -251,7 +251,7 @@ struct AmbiguousPlus { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::maybe_recover_from_bad_type_plus, code = "E0178")] struct BadTypePlus { pub ty: String, @@ -285,7 +285,7 @@ pub enum BadTypePlusSub { }, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::maybe_recover_from_bad_qpath_stage_2)] struct BadQPathStage2 { #[primary_span] @@ -294,7 +294,7 @@ struct BadQPathStage2 { ty: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::incorrect_semicolon)] struct IncorrectSemicolon<'a> { #[primary_span] @@ -305,7 +305,7 @@ struct IncorrectSemicolon<'a> { name: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::incorrect_use_of_await)] struct IncorrectUseOfAwait { #[primary_span] @@ -313,7 +313,7 @@ struct IncorrectUseOfAwait { span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::incorrect_use_of_await)] struct IncorrectAwait { #[primary_span] @@ -324,7 +324,7 @@ struct IncorrectAwait { question_mark: &'static str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::in_in_typo)] struct InInTypo { #[primary_span] @@ -333,7 +333,7 @@ struct InInTypo { sugg_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::invalid_variable_declaration)] pub struct InvalidVariableDeclaration { #[primary_span] @@ -362,7 +362,7 @@ pub enum InvalidVariableDeclarationSub { UseLetNotVar(#[primary_span] Span), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::invalid_comparison_operator)] pub(crate) struct InvalidComparisonOperator { #[primary_span] @@ -389,7 +389,7 @@ pub(crate) enum InvalidComparisonOperatorSub { Spaceship(#[primary_span] Span), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::invalid_logical_operator)] #[note] pub(crate) struct InvalidLogicalOperator { @@ -416,7 +416,7 @@ pub(crate) enum InvalidLogicalOperatorSub { Disjunction(#[primary_span] Span), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::tilde_is_not_unary_operator)] pub(crate) struct TildeAsUnaryOperator( #[primary_span] @@ -424,7 +424,7 @@ pub(crate) struct TildeAsUnaryOperator( pub Span, ); -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::unexpected_token_after_not)] pub(crate) struct NotAsNegationOperator { #[primary_span] @@ -458,7 +458,7 @@ pub enum NotAsNegationOperatorSub { SuggestNotLogical(#[primary_span] Span), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::malformed_loop_label)] pub(crate) struct MalformedLoopLabel { #[primary_span] @@ -467,7 +467,7 @@ pub(crate) struct MalformedLoopLabel { pub correct_label: Ident, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::lifetime_in_borrow_expression)] pub(crate) struct LifetimeInBorrowExpression { #[primary_span] @@ -477,15 +477,15 @@ pub(crate) struct LifetimeInBorrowExpression { pub lifetime_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::field_expression_with_generic)] pub(crate) struct FieldExpressionWithGeneric(#[primary_span] pub Span); -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::macro_invocation_with_qualified_path)] pub(crate) struct MacroInvocationWithQualifiedPath(#[primary_span] pub Span); -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::unexpected_token_after_label)] pub(crate) struct UnexpectedTokenAfterLabel( #[primary_span] @@ -493,7 +493,7 @@ pub(crate) struct UnexpectedTokenAfterLabel( pub Span, ); -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::require_colon_after_labeled_expression)] #[note] pub(crate) struct RequireColonAfterLabeledExpression { @@ -505,7 +505,7 @@ pub(crate) struct RequireColonAfterLabeledExpression { pub label_end: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::do_catch_syntax_removed)] #[note] pub(crate) struct DoCatchSyntaxRemoved { @@ -514,7 +514,7 @@ pub(crate) struct DoCatchSyntaxRemoved { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::float_literal_requires_integer_part)] pub(crate) struct FloatLiteralRequiresIntegerPart { #[primary_span] @@ -523,7 +523,7 @@ pub(crate) struct FloatLiteralRequiresIntegerPart { pub correct: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::invalid_int_literal_width)] #[help] pub(crate) struct InvalidIntLiteralWidth { @@ -532,7 +532,7 @@ pub(crate) struct InvalidIntLiteralWidth { pub width: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::invalid_num_literal_base_prefix)] #[note] pub(crate) struct InvalidNumLiteralBasePrefix { @@ -542,7 +542,7 @@ pub(crate) struct InvalidNumLiteralBasePrefix { pub fixed: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::invalid_num_literal_suffix)] #[help] pub(crate) struct InvalidNumLiteralSuffix { @@ -552,7 +552,7 @@ pub(crate) struct InvalidNumLiteralSuffix { pub suffix: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::invalid_float_literal_width)] #[help] pub(crate) struct InvalidFloatLiteralWidth { @@ -561,7 +561,7 @@ pub(crate) struct InvalidFloatLiteralWidth { pub width: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::invalid_float_literal_suffix)] #[help] pub(crate) struct InvalidFloatLiteralSuffix { @@ -571,14 +571,14 @@ pub(crate) struct InvalidFloatLiteralSuffix { pub suffix: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::int_literal_too_large)] pub(crate) struct IntLiteralTooLarge { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::missing_semicolon_before_array)] pub(crate) struct MissingSemicolonBeforeArray { #[primary_span] @@ -587,7 +587,7 @@ pub(crate) struct MissingSemicolonBeforeArray { pub semicolon: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::invalid_block_macro_segment)] pub(crate) struct InvalidBlockMacroSegment { #[primary_span] @@ -596,7 +596,7 @@ pub(crate) struct InvalidBlockMacroSegment { pub context: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::if_expression_missing_then_block)] pub(crate) struct IfExpressionMissingThenBlock { #[primary_span] @@ -613,7 +613,7 @@ pub(crate) enum IfExpressionMissingThenBlockSub { AddThenBlock(#[primary_span] Span), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::if_expression_missing_condition)] pub(crate) struct IfExpressionMissingCondition { #[primary_span] @@ -623,14 +623,14 @@ pub(crate) struct IfExpressionMissingCondition { pub block_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::expected_expression_found_let)] pub(crate) struct ExpectedExpressionFoundLet { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::expected_else_block)] pub(crate) struct ExpectedElseBlock { #[primary_span] @@ -642,7 +642,7 @@ pub(crate) struct ExpectedElseBlock { pub condition_start: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::outer_attribute_not_allowed_on_if_else)] pub(crate) struct OuterAttributeNotAllowedOnIfElse { #[primary_span] @@ -659,7 +659,7 @@ pub(crate) struct OuterAttributeNotAllowedOnIfElse { pub attributes: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::missing_in_in_for_loop)] pub(crate) struct MissingInInForLoop { #[primary_span] @@ -677,7 +677,7 @@ pub(crate) enum MissingInInForLoopSub { AddIn(#[primary_span] Span), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::missing_comma_after_match_arm)] pub(crate) struct MissingCommaAfterMatchArm { #[primary_span] @@ -685,7 +685,7 @@ pub(crate) struct MissingCommaAfterMatchArm { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::catch_after_try)] #[help] pub(crate) struct CatchAfterTry { @@ -693,7 +693,7 @@ pub(crate) struct CatchAfterTry { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::comma_after_base_struct)] #[note] pub(crate) struct CommaAfterBaseStruct { @@ -703,7 +703,7 @@ pub(crate) struct CommaAfterBaseStruct { pub comma: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::eq_field_init)] pub(crate) struct EqFieldInit { #[primary_span] @@ -712,7 +712,7 @@ pub(crate) struct EqFieldInit { pub eq: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::dotdotdot)] pub(crate) struct DotDotDot { #[primary_span] @@ -721,7 +721,7 @@ pub(crate) struct DotDotDot { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::left_arrow_operator)] pub(crate) struct LeftArrowOperator { #[primary_span] @@ -729,7 +729,7 @@ pub(crate) struct LeftArrowOperator { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::remove_let)] pub(crate) struct RemoveLet { #[primary_span] diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index ade5927be8e..bff2978bd13 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1,5 +1,5 @@ use rustc_errors::{Applicability, MultiSpan}; -use rustc_macros::{DiagnosticHandler, LintDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic}; use rustc_span::{Span, Symbol}; #[derive(LintDiagnostic)] @@ -32,7 +32,7 @@ pub struct IgnoredInlineAttrFnProto; #[note] pub struct IgnoredInlineAttrConstants; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::inline_not_fn_or_closure, code = "E0518")] pub struct InlineNotFnOrClosure { #[primary_span] @@ -53,7 +53,7 @@ pub struct IgnoredNoCoveragePropagate; #[diag(passes::no_coverage_fn_defn)] pub struct IgnoredNoCoverageFnDefn; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::no_coverage_not_coverable, code = "E0788")] pub struct IgnoredNoCoverageNotCoverable { #[primary_span] @@ -62,7 +62,7 @@ pub struct IgnoredNoCoverageNotCoverable { pub defn_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::should_be_applied_to_fn)] pub struct AttrShouldBeAppliedToFn { #[primary_span] @@ -71,14 +71,14 @@ pub struct AttrShouldBeAppliedToFn { pub defn_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::naked_tracked_caller, code = "E0736")] pub struct NakedTrackedCaller { #[primary_span] pub attr_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::should_be_applied_to_fn, code = "E0739")] pub struct TrackedCallerWrongLocation { #[primary_span] @@ -87,7 +87,7 @@ pub struct TrackedCallerWrongLocation { pub defn_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::should_be_applied_to_struct_enum, code = "E0701")] pub struct NonExhaustiveWrongLocation { #[primary_span] @@ -96,7 +96,7 @@ pub struct NonExhaustiveWrongLocation { pub defn_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::should_be_applied_to_trait)] pub struct AttrShouldBeAppliedToTrait { #[primary_span] @@ -109,7 +109,7 @@ pub struct AttrShouldBeAppliedToTrait { #[diag(passes::target_feature_on_statement)] pub struct TargetFeatureOnStatement; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::should_be_applied_to_static)] pub struct AttrShouldBeAppliedToStatic { #[primary_span] @@ -118,7 +118,7 @@ pub struct AttrShouldBeAppliedToStatic { pub defn_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_expect_str)] pub struct DocExpectStr<'a> { #[primary_span] @@ -126,7 +126,7 @@ pub struct DocExpectStr<'a> { pub attr_name: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_alias_empty)] pub struct DocAliasEmpty<'a> { #[primary_span] @@ -134,7 +134,7 @@ pub struct DocAliasEmpty<'a> { pub attr_str: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_alias_bad_char)] pub struct DocAliasBadChar<'a> { #[primary_span] @@ -143,7 +143,7 @@ pub struct DocAliasBadChar<'a> { pub char_: char, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_alias_start_end)] pub struct DocAliasStartEnd<'a> { #[primary_span] @@ -151,7 +151,7 @@ pub struct DocAliasStartEnd<'a> { pub attr_str: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_alias_bad_location)] pub struct DocAliasBadLocation<'a> { #[primary_span] @@ -160,7 +160,7 @@ pub struct DocAliasBadLocation<'a> { pub location: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_alias_not_an_alias)] pub struct DocAliasNotAnAlias<'a> { #[primary_span] @@ -175,35 +175,35 @@ pub struct DocAliasDuplicated { pub first_defn: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_alias_not_string_literal)] pub struct DocAliasNotStringLiteral { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_alias_malformed)] pub struct DocAliasMalformed { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_keyword_empty_mod)] pub struct DocKeywordEmptyMod { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_keyword_not_mod)] pub struct DocKeywordNotMod { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_keyword_invalid_ident)] pub struct DocKeywordInvalidIdent { #[primary_span] @@ -211,21 +211,21 @@ pub struct DocKeywordInvalidIdent { pub doc_keyword: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_fake_variadic_not_valid)] pub struct DocFakeVariadicNotValid { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_keyword_only_impl)] pub struct DocKeywordOnlyImpl { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_inline_conflict)] #[help] pub struct DocKeywordConflict { @@ -243,7 +243,7 @@ pub struct DocInlineOnlyUse { pub item_span: Option, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::doc_attr_not_crate_level)] pub struct DocAttrNotCrateLevel<'a> { #[primary_span] @@ -295,7 +295,7 @@ pub struct DocTestUnknownInclude { #[diag(passes::doc_invalid)] pub struct DocInvalid; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::pass_by_value)] pub struct PassByValue { #[primary_span] @@ -304,7 +304,7 @@ pub struct PassByValue { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::allow_incoherent_impl)] pub struct AllowIncoherentImpl { #[primary_span] @@ -313,7 +313,7 @@ pub struct AllowIncoherentImpl { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::has_incoherent_inherent_impl)] pub struct HasIncoherentInherentImpl { #[primary_span] @@ -336,7 +336,7 @@ pub struct MustUseNoEffect { pub target: rustc_hir::Target, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::must_not_suspend)] pub struct MustNotSuspend { #[primary_span] @@ -372,7 +372,7 @@ pub struct LinkName<'a> { pub value: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::no_link)] pub struct NoLink { #[primary_span] @@ -381,7 +381,7 @@ pub struct NoLink { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::export_name)] pub struct ExportName { #[primary_span] @@ -390,7 +390,7 @@ pub struct ExportName { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::rustc_layout_scalar_valid_range_not_struct)] pub struct RustcLayoutScalarValidRangeNotStruct { #[primary_span] @@ -399,14 +399,14 @@ pub struct RustcLayoutScalarValidRangeNotStruct { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::rustc_layout_scalar_valid_range_arg)] pub struct RustcLayoutScalarValidRangeArg { #[primary_span] pub attr_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::rustc_legacy_const_generics_only)] pub struct RustcLegacyConstGenericsOnly { #[primary_span] @@ -415,7 +415,7 @@ pub struct RustcLegacyConstGenericsOnly { pub param_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::rustc_legacy_const_generics_index)] pub struct RustcLegacyConstGenericsIndex { #[primary_span] @@ -424,7 +424,7 @@ pub struct RustcLegacyConstGenericsIndex { pub generics_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::rustc_legacy_const_generics_index_exceed)] pub struct RustcLegacyConstGenericsIndexExceed { #[primary_span] @@ -433,14 +433,14 @@ pub struct RustcLegacyConstGenericsIndexExceed { pub arg_count: usize, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::rustc_legacy_const_generics_index_negative)] pub struct RustcLegacyConstGenericsIndexNegative { #[primary_span] pub invalid_args: Vec, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::rustc_dirty_clean)] pub struct RustcDirtyClean { #[primary_span] @@ -475,7 +475,7 @@ pub struct NoMangle { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::repr_ident, code = "E0565")] pub struct ReprIdent { #[primary_span] @@ -486,21 +486,21 @@ pub struct ReprIdent { #[diag(passes::repr_conflicting, code = "E0566")] pub struct ReprConflicting; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::used_static)] pub struct UsedStatic { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::used_compiler_linker)] pub struct UsedCompilerLinker { #[primary_span] pub spans: Vec, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::allow_internal_unstable)] pub struct AllowInternalUnstable { #[primary_span] @@ -509,14 +509,14 @@ pub struct AllowInternalUnstable { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::debug_visualizer_placement)] pub struct DebugVisualizerPlacement { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::debug_visualizer_invalid)] #[note(passes::note_1)] #[note(passes::note_2)] @@ -526,7 +526,7 @@ pub struct DebugVisualizerInvalid { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::rustc_allow_const_fn_unstable)] pub struct RustcAllowConstFnUnstable { #[primary_span] @@ -535,7 +535,7 @@ pub struct RustcAllowConstFnUnstable { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::rustc_std_internal_symbol)] pub struct RustcStdInternalSymbol { #[primary_span] @@ -544,21 +544,21 @@ pub struct RustcStdInternalSymbol { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::const_trait)] pub struct ConstTrait { #[primary_span] pub attr_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::link_ordinal)] pub struct LinkOrdinal { #[primary_span] pub attr_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::stability_promotable)] pub struct StabilityPromotable { #[primary_span] @@ -602,7 +602,7 @@ pub struct Unused { pub note: UnusedNote, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::non_exported_macro_invalid_attrs, code = "E0518")] pub struct NonExportedMacroInvalidAttrs { #[primary_span] @@ -621,7 +621,7 @@ pub struct UnusedDuplicate { pub warning: Option<()>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::unused_multiple)] pub struct UnusedMultiple { #[primary_span] @@ -632,7 +632,7 @@ pub struct UnusedMultiple { pub name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::rustc_lint_opt_ty)] pub struct RustcLintOptTy { #[primary_span] @@ -641,7 +641,7 @@ pub struct RustcLintOptTy { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(passes::rustc_lint_opt_deny_field_access)] pub struct RustcLintOptDenyFieldAccess { #[primary_span] diff --git a/compiler/rustc_plugin_impl/src/errors.rs b/compiler/rustc_plugin_impl/src/errors.rs index 0b2c09f9e1d..07ce92a9b26 100644 --- a/compiler/rustc_plugin_impl/src/errors.rs +++ b/compiler/rustc_plugin_impl/src/errors.rs @@ -1,9 +1,9 @@ //! Errors emitted by plugin_impl -use rustc_macros::DiagnosticHandler; +use rustc_macros::Diagnostic; use rustc_span::Span; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(plugin_impl::load_plugin_error)] pub struct LoadPluginError { #[primary_span] @@ -11,7 +11,7 @@ pub struct LoadPluginError { pub msg: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(plugin_impl::malformed_plugin_attribute, code = "E0498")] pub struct MalformedPluginAttribute { #[primary_span] diff --git a/compiler/rustc_privacy/src/errors.rs b/compiler/rustc_privacy/src/errors.rs index 56a2cb059b5..71552119482 100644 --- a/compiler/rustc_privacy/src/errors.rs +++ b/compiler/rustc_privacy/src/errors.rs @@ -1,8 +1,8 @@ use rustc_errors::DiagnosticArgFromDisplay; -use rustc_macros::{DiagnosticHandler, LintDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic}; use rustc_span::{Span, Symbol}; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(privacy::field_is_private, code = "E0451")] pub struct FieldIsPrivate { #[primary_span] @@ -29,7 +29,7 @@ pub enum FieldIsPrivateLabel { }, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(privacy::item_is_private)] pub struct ItemIsPrivate<'a> { #[primary_span] @@ -39,7 +39,7 @@ pub struct ItemIsPrivate<'a> { pub descr: DiagnosticArgFromDisplay<'a>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(privacy::unnamed_item_is_private)] pub struct UnnamedItemIsPrivate { #[primary_span] @@ -48,7 +48,7 @@ pub struct UnnamedItemIsPrivate { } // Duplicate of `InPublicInterface` but with a different error code, shares the same slug. -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(privacy::in_public_interface, code = "E0445")] pub struct InPublicInterfaceTraits<'a> { #[primary_span] @@ -62,7 +62,7 @@ pub struct InPublicInterfaceTraits<'a> { } // Duplicate of `InPublicInterfaceTraits` but with a different error code, shares the same slug. -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(privacy::in_public_interface, code = "E0446")] pub struct InPublicInterface<'a> { #[primary_span] diff --git a/compiler/rustc_query_system/src/error.rs b/compiler/rustc_query_system/src/error.rs index 97a74517f68..4c770152f12 100644 --- a/compiler/rustc_query_system/src/error.rs +++ b/compiler/rustc_query_system/src/error.rs @@ -46,7 +46,7 @@ pub struct CycleUsage { pub usage: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(query_system::cycle, code = "E0391")] pub struct Cycle { #[primary_span] @@ -62,11 +62,11 @@ pub struct Cycle { pub cycle_usage: Option, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(query_system::reentrant)] pub struct Reentrant; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(query_system::increment_compilation)] #[help] #[note(query_system::increment_compilation_note1)] diff --git a/compiler/rustc_save_analysis/src/errors.rs b/compiler/rustc_save_analysis/src/errors.rs index 0983ec2f6f7..8a15ba63661 100644 --- a/compiler/rustc_save_analysis/src/errors.rs +++ b/compiler/rustc_save_analysis/src/errors.rs @@ -1,8 +1,8 @@ -use rustc_macros::DiagnosticHandler; +use rustc_macros::Diagnostic; use std::path::Path; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(save_analysis::could_not_open)] pub(crate) struct CouldNotOpen<'a> { pub file_name: &'a Path, diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index 4cf46109895..7ffe757463f 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -8,7 +8,7 @@ use rustc_span::{Span, Symbol}; use rustc_target::abi::TargetDataLayoutErrors; use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple}; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(session::incorrect_cgu_reuse_type)] pub struct IncorrectCguReuseType<'a> { #[primary_span] @@ -19,14 +19,14 @@ pub struct IncorrectCguReuseType<'a> { pub at_least: u8, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(session::cgu_not_recorded)] pub struct CguNotRecorded<'a> { pub cgu_user_name: &'a str, pub cgu_name: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(session::feature_gate_error, code = "E0658")] pub struct FeatureGateError<'a> { #[primary_span] @@ -46,7 +46,7 @@ pub struct FeatureDiagnosticHelp { pub feature: Symbol, } -impl DiagnosticHandler<'_, !> for TargetDataLayoutErrors<'_> { +impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> { fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> { let mut diag; match self { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 98ff9694808..ea69334616b 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -177,7 +177,7 @@ symbols! { DecorateLint, Default, Deref, - DiagnosticHandler, + Diagnostic, DiagnosticMessage, DirBuilder, Display, diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index f62bdb00ee0..b02ee593cbe 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -1,10 +1,10 @@ use rustc_errors::{fluent, IntoDiagnostic, ErrorGuaranteed, Handler}; -use rustc_macros::DiagnosticHandler; +use rustc_macros::Diagnostic; use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated}; use rustc_session::Limit; use rustc_span::{Span, Symbol}; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(trait_selection::dump_vtable_entries)] pub struct DumpVTableEntries<'a> { #[primary_span] @@ -13,7 +13,7 @@ pub struct DumpVTableEntries<'a> { pub entries: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(trait_selection::unable_to_construct_constant_value)] pub struct UnableToConstructConstantValue<'a> { #[primary_span] @@ -21,7 +21,7 @@ pub struct UnableToConstructConstantValue<'a> { pub unevaluated: Unevaluated<'a>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[help] #[diag(trait_selection::auto_deref_reached_recursion_limit, code = "E0055")] pub struct AutoDerefReachedRecursionLimit<'a> { @@ -33,7 +33,7 @@ pub struct AutoDerefReachedRecursionLimit<'a> { pub crate_name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(trait_selection::empty_on_clause_in_rustc_on_unimplemented, code = "E0232")] pub struct EmptyOnClauseInOnUnimplemented { #[primary_span] @@ -41,7 +41,7 @@ pub struct EmptyOnClauseInOnUnimplemented { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(trait_selection::invalid_on_clause_in_rustc_on_unimplemented, code = "E0232")] pub struct InvalidOnClauseInOnUnimplemented { #[primary_span] @@ -49,7 +49,7 @@ pub struct InvalidOnClauseInOnUnimplemented { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(trait_selection::no_value_in_rustc_on_unimplemented, code = "E0232")] #[note] pub struct NoValueInOnUnimplemented { diff --git a/compiler/rustc_ty_utils/src/errors.rs b/compiler/rustc_ty_utils/src/errors.rs index 995e87bcd3b..85165187310 100644 --- a/compiler/rustc_ty_utils/src/errors.rs +++ b/compiler/rustc_ty_utils/src/errors.rs @@ -1,16 +1,16 @@ //! Errors emitted by ty_utils -use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, SessionSubdiagnostic}; use rustc_middle::ty::Ty; use rustc_span::Span; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(ty_utils::needs_drop_overflow)] pub struct NeedsDropOverflow<'tcx> { pub query_ty: Ty<'tcx>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(ty_utils::generic_constant_too_complex)] #[help] pub struct GenericConstantTooComplex { diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 11661b8ef6c..23fadff3248 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -881,7 +881,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; } - // FIXME: Make this use DiagnosticHandler once error codes can be dynamically set. + // FIXME: Make this use Diagnostic once error codes can be dynamically set. let mut err = self.tcx.sess.struct_span_err_with_code( op_span, "invalid left-hand side of assignment", diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index 50d400e2921..6f00591d54e 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -1,11 +1,11 @@ //! Errors emitted by typeck. use rustc_errors::IntoDiagnostic; use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler}; -use rustc_macros::{DiagnosticHandler, LintDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic}; use rustc_middle::ty::Ty; use rustc_span::{symbol::Ident, Span, Symbol}; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::field_multiply_specified_in_initializer, code = "E0062")] pub struct FieldMultiplySpecifiedInInitializer { #[primary_span] @@ -16,7 +16,7 @@ pub struct FieldMultiplySpecifiedInInitializer { pub ident: Ident, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::unrecognized_atomic_operation, code = "E0092")] pub struct UnrecognizedAtomicOperation<'a> { #[primary_span] @@ -25,7 +25,7 @@ pub struct UnrecognizedAtomicOperation<'a> { pub op: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::wrong_number_of_generic_arguments_to_intrinsic, code = "E0094")] pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> { #[primary_span] @@ -36,7 +36,7 @@ pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> { pub descr: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::unrecognized_intrinsic_function, code = "E0093")] pub struct UnrecognizedIntrinsicFunction { #[primary_span] @@ -45,7 +45,7 @@ pub struct UnrecognizedIntrinsicFunction { pub name: Symbol, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::lifetimes_or_bounds_mismatch_on_trait, code = "E0195")] pub struct LifetimesOrBoundsMismatchOnTrait { #[primary_span] @@ -57,7 +57,7 @@ pub struct LifetimesOrBoundsMismatchOnTrait { pub ident: Ident, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::drop_impl_on_wrong_item, code = "E0120")] pub struct DropImplOnWrongItem { #[primary_span] @@ -65,7 +65,7 @@ pub struct DropImplOnWrongItem { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::field_already_declared, code = "E0124")] pub struct FieldAlreadyDeclared { pub field_name: Ident, @@ -76,7 +76,7 @@ pub struct FieldAlreadyDeclared { pub prev_span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::copy_impl_on_type_with_dtor, code = "E0184")] pub struct CopyImplOnTypeWithDtor { #[primary_span] @@ -84,14 +84,14 @@ pub struct CopyImplOnTypeWithDtor { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::multiple_relaxed_default_bounds, code = "E0203")] pub struct MultipleRelaxedDefaultBounds { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::copy_impl_on_non_adt, code = "E0206")] pub struct CopyImplOnNonAdt { #[primary_span] @@ -99,7 +99,7 @@ pub struct CopyImplOnNonAdt { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::trait_object_declared_with_no_traits, code = "E0224")] pub struct TraitObjectDeclaredWithNoTraits { #[primary_span] @@ -108,14 +108,14 @@ pub struct TraitObjectDeclaredWithNoTraits { pub trait_alias_span: Option, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0227")] pub struct AmbiguousLifetimeBound { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::assoc_type_binding_not_allowed, code = "E0229")] pub struct AssocTypeBindingNotAllowed { #[primary_span] @@ -123,14 +123,14 @@ pub struct AssocTypeBindingNotAllowed { pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::functional_record_update_on_non_struct, code = "E0436")] pub struct FunctionalRecordUpdateOnNonStruct { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::typeof_reserved_keyword_used, code = "E0516")] pub struct TypeofReservedKeywordUsed<'tcx> { pub ty: Ty<'tcx>, @@ -141,7 +141,7 @@ pub struct TypeofReservedKeywordUsed<'tcx> { pub opt_sugg: Option<(Span, Applicability)>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::return_stmt_outside_of_fn_body, code = "E0572")] pub struct ReturnStmtOutsideOfFnBody { #[primary_span] @@ -152,14 +152,14 @@ pub struct ReturnStmtOutsideOfFnBody { pub encl_fn_span: Option, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::yield_expr_outside_of_generator, code = "E0627")] pub struct YieldExprOutsideOfGenerator { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::struct_expr_non_exhaustive, code = "E0639")] pub struct StructExprNonExhaustive { #[primary_span] @@ -167,14 +167,14 @@ pub struct StructExprNonExhaustive { pub what: &'static str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::method_call_on_unknown_type, code = "E0699")] pub struct MethodCallOnUnknownType { #[primary_span] pub span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::value_of_associated_struct_already_specified, code = "E0719")] pub struct ValueOfAssociatedStructAlreadySpecified { #[primary_span] @@ -186,7 +186,7 @@ pub struct ValueOfAssociatedStructAlreadySpecified { pub def_path: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::address_of_temporary_taken, code = "E0745")] pub struct AddressOfTemporaryTaken { #[primary_span] @@ -232,7 +232,7 @@ pub enum ExpectedReturnTypeLabel<'tcx> { }, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::unconstrained_opaque_type)] #[note] pub struct UnconstrainedOpaqueType { @@ -249,7 +249,7 @@ pub struct MissingTypeParams { pub empty_generic_args: bool, } -// Manual implementation of `DiagnosticHandler` to be able to call `span_to_snippet`. +// Manual implementation of `IntoDiagnostic` to be able to call `span_to_snippet`. impl<'a> IntoDiagnostic<'a> for MissingTypeParams { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { let mut err = handler.struct_span_err_with_code( @@ -306,7 +306,7 @@ impl<'a> IntoDiagnostic<'a> for MissingTypeParams { } } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::manual_implementation, code = "E0183")] #[help] pub struct ManualImplementation { @@ -316,7 +316,7 @@ pub struct ManualImplementation { pub trait_name: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::substs_on_overridden_impl)] pub struct SubstsOnOverriddenImpl { #[primary_span] @@ -339,7 +339,7 @@ pub struct ExternCrateNotIdiomatic { pub suggestion_code: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::expected_used_symbol)] pub struct ExpectedUsedSymbol { #[primary_span] diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.rs b/src/test/ui-fulldeps/internal-lints/diagnostics.rs index e95ab048db3..93766de9a91 100644 --- a/src/test/ui-fulldeps/internal-lints/diagnostics.rs +++ b/src/test/ui-fulldeps/internal-lints/diagnostics.rs @@ -15,10 +15,10 @@ use rustc_errors::{ AddToDiagnostic, IntoDiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent }; -use rustc_macros::{DiagnosticHandler, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, SessionSubdiagnostic}; use rustc_span::Span; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(parser::expect_path)] struct DeriveSessionDiagnostic { #[primary_span] diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index 32ba5be8963..fd8128c31f8 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -1,10 +1,10 @@ // check-fail -// Tests error conditions for specifying diagnostics using #[derive(DiagnosticHandler)] +// Tests error conditions for specifying diagnostics using #[derive(Diagnostic)] // normalize-stderr-test "the following other types implement trait `IntoDiagnosticArg`:(?:.*\n){0,9}\s+and \d+ others" -> "normalized in stderr" // normalize-stderr-test "diagnostic_builder\.rs:[0-9]+:[0-9]+" -> "diagnostic_builder.rs:LL:CC" // The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly, -// changing the output of this test. Since DiagnosticHandler is strictly internal to the compiler +// changing the output of this test. Since Diagnostic is strictly internal to the compiler // the test is just ignored on stable and beta: // ignore-beta // ignore-stable @@ -17,7 +17,7 @@ use rustc_span::symbol::Ident; use rustc_span::Span; extern crate rustc_macros; -use rustc_macros::{DiagnosticHandler, LintDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic}; extern crate rustc_middle; use rustc_middle::ty::Ty; @@ -27,70 +27,70 @@ use rustc_errors::{Applicability, MultiSpan}; extern crate rustc_session; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct Hello {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct HelloWarn {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] -//~^ ERROR `#[derive(DiagnosticHandler)]` can only be used on structs -enum DiagnosticHandlerOnEnum { +//~^ ERROR `#[derive(Diagnostic)]` can only be used on structs +enum DiagnosticOnEnum { Foo, Bar, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag = "E0123"] //~^ ERROR `#[diag = ...]` is not a valid attribute struct WrongStructAttrStyle {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[nonsense(typeck::ambiguous_lifetime_bound, code = "E0123")] //~^ ERROR `#[nonsense(...)]` is not a valid attribute //~^^ ERROR diagnostic slug not specified //~^^^ ERROR cannot find attribute `nonsense` in this scope struct InvalidStructAttr {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag("E0123")] //~^ ERROR `#[diag("...")]` is not a valid attribute //~^^ ERROR diagnostic slug not specified struct InvalidLitNestedAttr {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(nonsense, code = "E0123")] //~^ ERROR cannot find value `nonsense` in module `rustc_errors::fluent` struct InvalidNestedStructAttr {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(nonsense("foo"), code = "E0123", slug = "foo")] //~^ ERROR `#[diag(nonsense(...))]` is not a valid attribute //~^^ ERROR diagnostic slug not specified struct InvalidNestedStructAttr1 {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(nonsense = "...", code = "E0123", slug = "foo")] //~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute //~^^ ERROR diagnostic slug not specified struct InvalidNestedStructAttr2 {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(nonsense = 4, code = "E0123", slug = "foo")] //~^ ERROR `#[diag(nonsense = ...)]` is not a valid attribute //~^^ ERROR diagnostic slug not specified struct InvalidNestedStructAttr3 {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123", slug = "foo")] //~^ ERROR `#[diag(slug = ...)]` is not a valid attribute struct InvalidNestedStructAttr4 {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct WrongPlaceField { #[suggestion = "bar"] @@ -98,36 +98,36 @@ struct WrongPlaceField { sp: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[diag(typeck::ambiguous_lifetime_bound, code = "E0456")] //~^ ERROR specified multiple times //~^^ ERROR specified multiple times struct DiagSpecifiedTwice {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0456", code = "E0457")] //~^ ERROR specified multiple times struct CodeSpecifiedTwice {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, typeck::ambiguous_lifetime_bound, code = "E0456")] //~^ ERROR `#[diag(typeck::ambiguous_lifetime_bound)]` is not a valid attribute struct SlugSpecifiedTwice {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] struct KindNotProvided {} //~ ERROR diagnostic slug not specified -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(code = "E0456")] //~^ ERROR diagnostic slug not specified struct SlugNotProvided {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound)] struct CodeNotProvided {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct MessageWrongType { #[primary_span] @@ -135,7 +135,7 @@ struct MessageWrongType { foo: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct InvalidPathFieldAttr { #[nonsense] @@ -144,7 +144,7 @@ struct InvalidPathFieldAttr { foo: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithField { name: String, @@ -152,7 +152,7 @@ struct ErrorWithField { span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithMessageAppliedToField { #[label(typeck::label)] @@ -160,7 +160,7 @@ struct ErrorWithMessageAppliedToField { name: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithNonexistentField { #[suggestion(typeck::suggestion, code = "{name}")] @@ -168,7 +168,7 @@ struct ErrorWithNonexistentField { suggestion: (Span, Applicability), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] //~^ ERROR invalid format string: expected `'}'` #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorMissingClosingBrace { @@ -178,7 +178,7 @@ struct ErrorMissingClosingBrace { val: usize, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] //~^ ERROR invalid format string: unmatched `}` #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorMissingOpeningBrace { @@ -188,14 +188,14 @@ struct ErrorMissingOpeningBrace { val: usize, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelOnSpan { #[label(typeck::label)] sp: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelOnNonSpan { #[label(typeck::label)] @@ -203,7 +203,7 @@ struct LabelOnNonSpan { id: u32, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct Suggest { #[suggestion(typeck::suggestion, code = "This is the suggested code")] @@ -213,14 +213,14 @@ struct Suggest { suggestion: (Span, Applicability), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithoutCode { #[suggestion(typeck::suggestion)] suggestion: (Span, Applicability), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithBadKey { #[suggestion(nonsense = "bar")] @@ -228,7 +228,7 @@ struct SuggestWithBadKey { suggestion: (Span, Applicability), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithShorthandMsg { #[suggestion(msg = "bar")] @@ -236,21 +236,21 @@ struct SuggestWithShorthandMsg { suggestion: (Span, Applicability), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithoutMsg { #[suggestion(code = "bar")] suggestion: (Span, Applicability), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithTypesSwapped { #[suggestion(typeck::suggestion, code = "This is suggested code")] suggestion: (Applicability, Span), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithWrongTypeApplicabilityOnly { #[suggestion(typeck::suggestion, code = "This is suggested code")] @@ -258,14 +258,14 @@ struct SuggestWithWrongTypeApplicabilityOnly { suggestion: Applicability, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithSpanOnly { #[suggestion(typeck::suggestion, code = "This is suggested code")] suggestion: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithDuplicateSpanAndApplicability { #[suggestion(typeck::suggestion, code = "This is suggested code")] @@ -273,7 +273,7 @@ struct SuggestWithDuplicateSpanAndApplicability { suggestion: (Span, Span, Applicability), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct SuggestWithDuplicateApplicabilityAndSpan { #[suggestion(typeck::suggestion, code = "This is suggested code")] @@ -281,7 +281,7 @@ struct SuggestWithDuplicateApplicabilityAndSpan { suggestion: (Applicability, Applicability, Span), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct WrongKindOfAnnotation { #[label = "bar"] @@ -289,7 +289,7 @@ struct WrongKindOfAnnotation { z: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct OptionsInErrors { #[label(typeck::label)] @@ -298,7 +298,7 @@ struct OptionsInErrors { opt_sugg: Option<(Span, Applicability)>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0456")] struct MoveOutOfBorrowError<'tcx> { name: Ident, @@ -312,7 +312,7 @@ struct MoveOutOfBorrowError<'tcx> { opt_sugg: Option<(Span, Applicability)>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithLifetime<'a> { #[label(typeck::label)] @@ -320,7 +320,7 @@ struct ErrorWithLifetime<'a> { name: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithDefaultLabelAttr<'a> { #[label] @@ -328,7 +328,7 @@ struct ErrorWithDefaultLabelAttr<'a> { name: &'a str, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] //~^ ERROR the trait bound `Hello: IntoDiagnosticArg` is not satisfied #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ArgFieldWithoutSkip { @@ -337,7 +337,7 @@ struct ArgFieldWithoutSkip { other: Hello, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ArgFieldWithSkip { #[primary_span] @@ -348,91 +348,91 @@ struct ArgFieldWithSkip { other: Hello, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithSpannedNote { #[note] span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithSpannedNoteCustom { #[note(typeck::note)] span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[note] struct ErrorWithNote { val: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[note(typeck::note)] struct ErrorWithNoteCustom { val: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithSpannedHelp { #[help] span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithSpannedHelpCustom { #[help(typeck::help)] span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[help] struct ErrorWithHelp { val: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[help(typeck::help)] struct ErrorWithHelpCustom { val: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[help] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithHelpWrongOrder { val: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[help(typeck::help)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithHelpCustomWrongOrder { val: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[note] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithNoteWrongOrder { val: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[note(typeck::note)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithNoteCustomWrongOrder { val: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ApplicabilityInBoth { #[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")] @@ -440,7 +440,7 @@ struct ApplicabilityInBoth { suggestion: (Span, Applicability), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct InvalidApplicability { #[suggestion(typeck::suggestion, code = "...", applicability = "batman")] @@ -448,14 +448,14 @@ struct InvalidApplicability { suggestion: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ValidApplicability { #[suggestion(typeck::suggestion, code = "...", applicability = "maybe-incorrect")] suggestion: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct NoApplicability { #[suggestion(typeck::suggestion, code = "...")] @@ -466,14 +466,14 @@ struct NoApplicability { #[note(parser::add_paren)] struct Note; -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound)] struct Subdiagnostic { #[subdiagnostic] note: Note, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct VecField { #[primary_span] @@ -481,7 +481,7 @@ struct VecField { spans: Vec, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct UnitField { #[primary_span] @@ -492,7 +492,7 @@ struct UnitField { bar: (), } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct OptUnitField { #[primary_span] @@ -503,7 +503,7 @@ struct OptUnitField { bar: Option<()>, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelWithTrailingPath { #[label(typeck::label, foo)] @@ -511,7 +511,7 @@ struct LabelWithTrailingPath { span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelWithTrailingNameValue { #[label(typeck::label, foo = "...")] @@ -519,7 +519,7 @@ struct LabelWithTrailingNameValue { span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct LabelWithTrailingList { #[label(typeck::label, foo("..."))] @@ -540,35 +540,35 @@ struct PrimarySpanOnLint { span: Span, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] struct ErrorWithMultiSpan { #[primary_span] span: MultiSpan, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] #[warning] struct ErrorWithWarn { val: String, } -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[error(typeck::ambiguous_lifetime_bound, code = "E0123")] //~^ ERROR `#[error(...)]` is not a valid attribute //~| ERROR diagnostic slug not specified //~| ERROR cannot find attribute `error` in this scope struct ErrorAttribute {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[warn_(typeck::ambiguous_lifetime_bound, code = "E0123")] //~^ ERROR `#[warn_(...)]` is not a valid attribute //~| ERROR diagnostic slug not specified //~| ERROR cannot find attribute `warn_` in this scope struct WarnAttribute {} -#[derive(DiagnosticHandler)] +#[derive(Diagnostic)] #[lint(typeck::ambiguous_lifetime_bound, code = "E0123")] //~^ ERROR `#[lint(...)]` is not a valid attribute //~| ERROR diagnostic slug not specified diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index d9198d4ef80..b07b35f2723 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -1,9 +1,9 @@ -error: `#[derive(DiagnosticHandler)]` can only be used on structs +error: `#[derive(Diagnostic)]` can only be used on structs --> $DIR/diagnostic-derive.rs:39:1 | LL | / #[diag(typeck::ambiguous_lifetime_bound, code = "E0123")] LL | | -LL | | enum DiagnosticHandlerOnEnum { +LL | | enum DiagnosticOnEnum { LL | | Foo, LL | | Bar, LL | | } @@ -214,22 +214,22 @@ LL | #[suggestion(typeck::suggestion, code = "{name}")] error: invalid format string: expected `'}'` but string was terminated --> $DIR/diagnostic-derive.rs:171:16 | -LL | #[derive(DiagnosticHandler)] +LL | #[derive(Diagnostic)] | - ^ expected `'}'` in format string | | | because of this opening brace | = note: if you intended to print `{`, you can escape it using `{{` - = note: this error originates in the derive macro `DiagnosticHandler` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) error: invalid format string: unmatched `}` found --> $DIR/diagnostic-derive.rs:181:15 | -LL | #[derive(DiagnosticHandler)] +LL | #[derive(Diagnostic)] | ^ unmatched `}` in format string | = note: if you intended to print `}`, you can escape it using `}}` - = note: this error originates in the derive macro `DiagnosticHandler` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) error: the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` --> $DIR/diagnostic-derive.rs:201:5 @@ -448,7 +448,7 @@ LL | #[diag(nonsense, code = "E0123")] error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied --> $DIR/diagnostic-derive.rs:331:10 | -LL | #[derive(DiagnosticHandler)] +LL | #[derive(Diagnostic)] | ^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` | = help: normalized in stderr @@ -457,7 +457,7 @@ note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg` | LL | arg: impl IntoDiagnosticArg, | ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg` - = note: this error originates in the derive macro `DiagnosticHandler` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 55 previous errors -- cgit 1.4.1-3-g733a5 From 5f91719f75a1012f4b59391fd89a20bb989b2801 Mon Sep 17 00:00:00 2001 From: Jhonny Bill Mena Date: Sun, 18 Sep 2022 11:47:31 -0400 Subject: UPDATE - rename SessionSubdiagnostic macro to Subdiagnostic Also renames: - sym::AddSubdiagnostic to sym:: Subdiagnostic - rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic" --- compiler/rustc_ast_lowering/src/errors.rs | 4 +- compiler/rustc_ast_passes/src/errors.rs | 2 +- compiler/rustc_attr/src/session_diagnostics.rs | 4 +- compiler/rustc_borrowck/src/session_diagnostics.rs | 12 +- compiler/rustc_error_messages/src/lib.rs | 4 +- compiler/rustc_errors/src/diagnostic.rs | 9 +- compiler/rustc_expand/src/mbe/macro_rules.rs | 2 +- compiler/rustc_lint/src/errors.rs | 4 +- compiler/rustc_lint/src/internal.rs | 2 +- compiler/rustc_macros/src/diagnostics/mod.rs | 10 +- .../rustc_macros/src/diagnostics/subdiagnostic.rs | 18 +-- compiler/rustc_macros/src/lib.rs | 2 +- compiler/rustc_middle/src/error.rs | 2 +- compiler/rustc_parse/src/parser/diagnostics.rs | 14 +-- compiler/rustc_passes/src/errors.rs | 4 +- compiler/rustc_privacy/src/errors.rs | 4 +- compiler/rustc_query_system/src/error.rs | 7 +- compiler/rustc_session/src/errors.rs | 4 +- compiler/rustc_span/src/symbol.rs | 2 +- compiler/rustc_ty_utils/src/errors.rs | 4 +- compiler/rustc_typeck/src/errors.rs | 6 +- src/test/ui-fulldeps/internal-lints/diagnostics.rs | 4 +- .../session-diagnostic/diagnostic-derive.rs | 4 +- .../session-diagnostic/subdiagnostic-derive.rs | 130 ++++++++++----------- 24 files changed, 130 insertions(+), 128 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 6dbb2582a37..052979d6d45 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -1,5 +1,5 @@ use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay}; -use rustc_macros::{Diagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{symbol::Ident, Span, Symbol}; #[derive(Diagnostic, Clone, Copy)] @@ -221,7 +221,7 @@ pub struct InvalidAsmTemplateModifierRegClass { pub sub: InvalidAsmTemplateModifierRegClassSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum InvalidAsmTemplateModifierRegClassSub { #[note(ast_lowering::support_modifiers)] SupportModifier { class_name: Symbol, modifiers: String }, diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index 20e2209acbe..035f0ce1cbc 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -71,7 +71,7 @@ pub struct InvalidVisibility { pub note: Option, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum InvalidVisibilityNote { #[note(ast_passes::individual_impl_items)] IndividualImplItems, diff --git a/compiler/rustc_attr/src/session_diagnostics.rs b/compiler/rustc_attr/src/session_diagnostics.rs index 5e8f9b79850..940a48ed915 100644 --- a/compiler/rustc_attr/src/session_diagnostics.rs +++ b/compiler/rustc_attr/src/session_diagnostics.rs @@ -98,7 +98,7 @@ pub(crate) struct InvalidIssueString { // The error kinds of `IntErrorKind` are duplicated here in order to allow the messages to be // translatable. -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum InvalidIssueStringCause { #[label(attr::must_not_be_zero)] MustNotBeZero { @@ -274,7 +274,7 @@ pub(crate) struct IncorrectReprFormatGeneric<'a> { pub cause: Option>, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum IncorrectReprFormatGenericCause<'a> { #[suggestion(attr::suggestion, code = "{name}({int})", applicability = "machine-applicable")] Int { diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index aa8f26eece5..9f19453a1a6 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -1,5 +1,5 @@ use rustc_errors::{IntoDiagnosticArg, MultiSpan}; -use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::ty::Ty; use rustc_span::Span; @@ -23,7 +23,7 @@ pub(crate) struct HigherRankedLifetimeError { pub span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum HigherRankedErrorCause { #[note(borrowck::could_not_prove)] CouldNotProve { predicate: String }, @@ -72,7 +72,7 @@ pub(crate) struct FnMutError { pub ty_err: FnMutReturnTypeErr, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum VarHereDenote { #[label(borrowck::var_here_captured)] Captured { @@ -91,7 +91,7 @@ pub(crate) enum VarHereDenote { }, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum FnMutReturnTypeErr { #[label(borrowck::returned_closure_escaped)] ReturnClosure { @@ -117,7 +117,7 @@ pub(crate) struct LifetimeOutliveErr { pub span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum LifetimeReturnCategoryErr<'a> { #[label(borrowck::returned_lifetime_wrong)] WrongReturn { @@ -149,7 +149,7 @@ impl IntoDiagnosticArg for RegionName { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum RequireStaticErr { #[note(borrowck::used_impl_require_static)] UsedImpl { diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index b6e0f3faa73..ff33ae7e8f2 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -268,14 +268,14 @@ type FluentId = Cow<'static, str>; /// Translatable messages for subdiagnostics are typically attributes attached to a larger Fluent /// message so messages of this type must be combined with a `DiagnosticMessage` (using /// `DiagnosticMessage::with_subdiagnostic_message`) before rendering. However, subdiagnostics from -/// the `SessionSubdiagnostic` derive refer to Fluent identifiers directly. +/// the `Subdiagnostic` derive refer to Fluent identifiers directly. #[rustc_diagnostic_item = "SubdiagnosticMessage"] pub enum SubdiagnosticMessage { /// Non-translatable diagnostic message. // FIXME(davidtwco): can a `Cow<'static, str>` be used here? Str(String), /// Identifier of a Fluent message. Instances of this variant are generated by the - /// `SessionSubdiagnostic` derive. + /// `Subdiagnostic` derive. FluentIdentifier(FluentId), /// Attribute of a Fluent message. Needs to be combined with a Fluent identifier to produce an /// actual translated message. Instances of this variant are generated by the `fluent_messages` diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index d3a263ac56d..c66889189ad 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -176,8 +176,9 @@ impl IntoDiagnosticArg for hir::ConstContext { } /// Trait implemented by error types. This should not be implemented manually. Instead, use -/// `#[derive(SessionSubdiagnostic)]` -- see [rustc_macros::SessionSubdiagnostic]. -#[rustc_diagnostic_item = "AddSubdiagnostic"] +/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic]. +#[cfg_attr(bootstrap, rustc_diagnostic_item = "AddSubdiagnostic")] +#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "Subdiagnostic")] pub trait AddToDiagnostic { /// Add a subdiagnostic to an existing diagnostic. fn add_to_diagnostic(self, diag: &mut Diagnostic); @@ -891,8 +892,8 @@ impl Diagnostic { self } - /// Add a subdiagnostic from a type that implements `SessionSubdiagnostic` - see - /// [rustc_macros::SessionSubdiagnostic]. + /// Add a subdiagnostic from a type that implements `Subdiagnostic` - see + /// [rustc_macros::Subdiagnostic]. pub fn subdiagnostic(&mut self, subdiagnostic: impl AddToDiagnostic) -> &mut Self { subdiagnostic.add_to_diagnostic(self); self diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 7764ffd246e..6d2c7aac6af 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -593,7 +593,7 @@ pub fn compile_declarative_macro( (mk_syn_ext(expander), rule_spans) } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] enum ExplainDocComment { #[label(expand::explain_doc_comment_inner)] Inner { diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs index 0c66ce475c4..3a89d90c88a 100644 --- a/compiler/rustc_lint/src/errors.rs +++ b/compiler/rustc_lint/src/errors.rs @@ -1,5 +1,5 @@ use rustc_errors::{fluent, AddToDiagnostic, IntoDiagnostic, ErrorGuaranteed, Handler}; -use rustc_macros::{Diagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_session::lint::Level; use rustc_span::{Span, Symbol}; @@ -51,7 +51,7 @@ pub struct MalformedAttribute { pub sub: MalformedAttributeSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum MalformedAttributeSub { #[label(lint::bad_attribute_argument)] BadAttributeArgument(#[primary_span] Span), diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 36d8ade22ae..942475d31fe 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -404,7 +404,7 @@ impl LateLintPass<'_> for Diagnostics { let Impl { of_trait: Some(of_trait), .. } = impl_ && let Some(def_id) = of_trait.trait_def_id() && let Some(name) = cx.tcx.get_diagnostic_name(def_id) && - matches!(name, sym::Diagnostic | sym::AddSubdiagnostic | sym::DecorateLint) + matches!(name, sym::Diagnostic | sym::Subdiagnostic | sym::DecorateLint) { found_impl = true; break; diff --git a/compiler/rustc_macros/src/diagnostics/mod.rs b/compiler/rustc_macros/src/diagnostics/mod.rs index 1d5b32c2556..8eaa8b87c0f 100644 --- a/compiler/rustc_macros/src/diagnostics/mod.rs +++ b/compiler/rustc_macros/src/diagnostics/mod.rs @@ -9,7 +9,7 @@ use diagnostic::{LintDiagnosticDerive, SessionDiagnosticDerive}; pub(crate) use fluent::fluent_messages; use proc_macro2::TokenStream; use quote::format_ident; -use subdiagnostic::SessionSubdiagnosticDerive; +use subdiagnostic::SubdiagnosticDerive; use synstructure::Structure; /// Implements `#[derive(Diagnostic)]`, which allows for errors to be specified as a struct, @@ -108,12 +108,12 @@ pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream { LintDiagnosticDerive::new(format_ident!("diag"), s).into_tokens() } -/// Implements `#[derive(SessionSubdiagnostic)]`, which allows for labels, notes, helps and +/// Implements `#[derive(Subdiagnostic)]`, which allows for labels, notes, helps and /// suggestions to be specified as a structs or enums, independent from the actual diagnostics /// emitting code or diagnostic derives. /// /// ```ignore (rust) -/// #[derive(SessionSubdiagnostic)] +/// #[derive(Subdiagnostic)] /// pub enum ExpectedIdentifierLabel<'tcx> { /// #[label(parser::expected_identifier)] /// WithoutFound { @@ -128,7 +128,7 @@ pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream { /// } /// } /// -/// #[derive(SessionSubdiagnostic)] +/// #[derive(Subdiagnostic)] /// #[suggestion_verbose(parser::raw_identifier)] /// pub struct RawIdentifierSuggestion<'tcx> { /// #[primary_span] @@ -155,5 +155,5 @@ pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream { /// diag.subdiagnostic(RawIdentifierSuggestion { span, applicability, ident }); /// ``` pub fn session_subdiagnostic_derive(s: Structure<'_>) -> TokenStream { - SessionSubdiagnosticDerive::new(s).into_tokens() + SubdiagnosticDerive::new(s).into_tokens() } diff --git a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs index f1bb7feb062..bdeca3420bc 100644 --- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs @@ -98,19 +98,19 @@ impl quote::IdentFragment for SubdiagnosticKind { } /// The central struct for constructing the `add_to_diagnostic` method from an annotated struct. -pub(crate) struct SessionSubdiagnosticDerive<'a> { +pub(crate) struct SubdiagnosticDerive<'a> { structure: Structure<'a>, diag: syn::Ident, } -impl<'a> SessionSubdiagnosticDerive<'a> { +impl<'a> SubdiagnosticDerive<'a> { pub(crate) fn new(structure: Structure<'a>) -> Self { let diag = format_ident!("diag"); Self { structure, diag } } pub(crate) fn into_tokens(self) -> TokenStream { - let SessionSubdiagnosticDerive { mut structure, diag } = self; + let SubdiagnosticDerive { mut structure, diag } = self; let implementation = { let ast = structure.ast(); let span = ast.span().unwrap(); @@ -119,7 +119,7 @@ impl<'a> SessionSubdiagnosticDerive<'a> { syn::Data::Union(..) => { span_err( span, - "`#[derive(SessionSubdiagnostic)]` can only be used on structs and enums", + "`#[derive(Subdiagnostic)]` can only be used on structs and enums", ); } } @@ -146,7 +146,7 @@ impl<'a> SessionSubdiagnosticDerive<'a> { } } - let mut builder = SessionSubdiagnosticDeriveBuilder { + let mut builder = SubdiagnosticDeriveBuilder { diag: &diag, variant, span, @@ -178,10 +178,10 @@ impl<'a> SessionSubdiagnosticDerive<'a> { } /// Tracks persistent information required for building up the call to add to the diagnostic -/// for the final generated method. This is a separate struct to `SessionSubdiagnosticDerive` +/// for the final generated method. This is a separate struct to `SubdiagnosticDerive` /// only to be able to destructure and split `self.builder` and the `self.structure` up to avoid a /// double mut borrow later on. -struct SessionSubdiagnosticDeriveBuilder<'a> { +struct SubdiagnosticDeriveBuilder<'a> { /// The identifier to use for the generated `DiagnosticBuilder` instance. diag: &'a syn::Ident, @@ -205,7 +205,7 @@ struct SessionSubdiagnosticDeriveBuilder<'a> { has_suggestion_parts: bool, } -impl<'a> HasFieldMap for SessionSubdiagnosticDeriveBuilder<'a> { +impl<'a> HasFieldMap for SubdiagnosticDeriveBuilder<'a> { fn get_field_binding(&self, field: &String) -> Option<&TokenStream> { self.fields.get(field) } @@ -241,7 +241,7 @@ impl<'a> FromIterator<&'a SubdiagnosticKind> for KindsStatistics { } } -impl<'a> SessionSubdiagnosticDeriveBuilder<'a> { +impl<'a> SubdiagnosticDeriveBuilder<'a> { fn identify_kind(&mut self) -> Result, DiagnosticDeriveError> { let mut kind_slugs = vec![]; diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index 9dd7ccad8bb..8fd23ee5ced 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -161,7 +161,7 @@ decl_derive!( suggestion_verbose)] => diagnostics::lint_diagnostic_derive ); decl_derive!( - [SessionSubdiagnostic, attributes( + [Subdiagnostic, attributes( // struct/variant attributes label, help, diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index 6d15feb888a..a4ceb494569 100644 --- a/compiler/rustc_middle/src/error.rs +++ b/compiler/rustc_middle/src/error.rs @@ -25,7 +25,7 @@ pub struct OpaqueHiddenTypeMismatch<'tcx> { pub sub: TypeMismatchReason, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum TypeMismatchReason { #[label(middle::conflict_types)] ConflictType { diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 9989ebb7cdf..78bc29fc375 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -20,7 +20,7 @@ use rustc_errors::{ fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult, }; use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed}; -use rustc_macros::{Diagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::{Span, SpanSnippetError, DUMMY_SP}; @@ -261,7 +261,7 @@ struct BadTypePlus { pub sub: BadTypePlusSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum BadTypePlusSub { #[suggestion( parser::add_paren, @@ -342,7 +342,7 @@ pub struct InvalidVariableDeclaration { pub sub: InvalidVariableDeclarationSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum InvalidVariableDeclarationSub { #[suggestion( parser::switch_mut_let_order, @@ -372,7 +372,7 @@ pub(crate) struct InvalidComparisonOperator { pub sub: InvalidComparisonOperatorSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum InvalidComparisonOperatorSub { #[suggestion_short( parser::use_instead, @@ -400,7 +400,7 @@ pub(crate) struct InvalidLogicalOperator { pub sub: InvalidLogicalOperatorSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum InvalidLogicalOperatorSub { #[suggestion_short( parser::use_amp_amp_for_conjunction, @@ -605,7 +605,7 @@ pub(crate) struct IfExpressionMissingThenBlock { pub sub: IfExpressionMissingThenBlockSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum IfExpressionMissingThenBlockSub { #[help(parser::condition_possibly_unfinished)] UnfinishedCondition(#[primary_span] Span), @@ -668,7 +668,7 @@ pub(crate) struct MissingInInForLoop { pub sub: MissingInInForLoopSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub(crate) enum MissingInInForLoopSub { // Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect #[suggestion_short(parser::use_in_not_of, applicability = "maybe-incorrect", code = "in")] diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index bff2978bd13..52aea9bba43 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1,5 +1,5 @@ use rustc_errors::{Applicability, MultiSpan}; -use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_span::{Span, Symbol}; #[derive(LintDiagnostic)] @@ -583,7 +583,7 @@ pub struct MacroExport; #[diag(passes::plugin_registrar)] pub struct PluginRegistrar; -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum UnusedNote { #[note(passes::unused_empty_lints_note)] EmptyList { name: Symbol }, diff --git a/compiler/rustc_privacy/src/errors.rs b/compiler/rustc_privacy/src/errors.rs index 71552119482..f3a617c2f0f 100644 --- a/compiler/rustc_privacy/src/errors.rs +++ b/compiler/rustc_privacy/src/errors.rs @@ -1,5 +1,5 @@ use rustc_errors::DiagnosticArgFromDisplay; -use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_span::{Span, Symbol}; #[derive(Diagnostic)] @@ -14,7 +14,7 @@ pub struct FieldIsPrivate { pub label: FieldIsPrivateLabel, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum FieldIsPrivateLabel { #[label(privacy::field_is_private_is_update_syntax_label)] IsUpdateSyntax { diff --git a/compiler/rustc_query_system/src/error.rs b/compiler/rustc_query_system/src/error.rs index 4c770152f12..ceec75fce28 100644 --- a/compiler/rustc_query_system/src/error.rs +++ b/compiler/rustc_query_system/src/error.rs @@ -1,6 +1,7 @@ use rustc_errors::AddToDiagnostic; use rustc_session::Limit; use rustc_span::{Span, Symbol}; +use rustc_macros::{Diagnostic, Subdiagnostic}; pub struct CycleStack { pub span: Span, @@ -20,7 +21,7 @@ pub enum HandleCycleError { DelayBug, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum StackCount { #[note(query_system::cycle_stack_single)] Single, @@ -28,7 +29,7 @@ pub enum StackCount { Multiple, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum Alias { #[note(query_system::cycle_recursive_ty_alias)] #[help(query_system::cycle_recursive_ty_alias_help1)] @@ -38,7 +39,7 @@ pub enum Alias { Trait, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[note(query_system::cycle_usage)] pub struct CycleUsage { #[primary_span] diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index 7ffe757463f..997a45272bc 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -34,13 +34,13 @@ pub struct FeatureGateError<'a> { pub explain: &'a str, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[note(session::feature_diagnostic_for_issue)] pub struct FeatureDiagnosticForIssue { pub n: NonZeroU32, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[help(session::feature_diagnostic_help)] pub struct FeatureDiagnosticHelp { pub feature: Symbol, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index ea69334616b..1baad6a9fd7 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -125,7 +125,6 @@ symbols! { Symbols { AcqRel, Acquire, - AddSubdiagnostic, Alignment, Any, Arc, @@ -283,6 +282,7 @@ symbols! { String, StructuralEq, StructuralPartialEq, + Subdiagnostic, SubdiagnosticMessage, Sync, T, diff --git a/compiler/rustc_ty_utils/src/errors.rs b/compiler/rustc_ty_utils/src/errors.rs index 85165187310..753c474a34b 100644 --- a/compiler/rustc_ty_utils/src/errors.rs +++ b/compiler/rustc_ty_utils/src/errors.rs @@ -1,6 +1,6 @@ //! Errors emitted by ty_utils -use rustc_macros::{Diagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_middle::ty::Ty; use rustc_span::Span; @@ -22,7 +22,7 @@ pub struct GenericConstantTooComplex { pub sub: GenericConstantTooComplexSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum GenericConstantTooComplexSub { #[label(ty_utils::borrow_not_supported)] BorrowNotSupported(#[primary_span] Span), diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index 6f00591d54e..44df47e2fa0 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -1,7 +1,7 @@ //! Errors emitted by typeck. use rustc_errors::IntoDiagnostic; use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler}; -use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::ty::Ty; use rustc_span::{symbol::Ident, Span, Symbol}; @@ -194,7 +194,7 @@ pub struct AddressOfTemporaryTaken { pub span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum AddReturnTypeSuggestion { #[suggestion( typeck::add_return_type_add, @@ -217,7 +217,7 @@ pub enum AddReturnTypeSuggestion { }, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum ExpectedReturnTypeLabel<'tcx> { #[label(typeck::expected_default_return_type)] Unit { diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.rs b/src/test/ui-fulldeps/internal-lints/diagnostics.rs index 93766de9a91..4c2c28dc336 100644 --- a/src/test/ui-fulldeps/internal-lints/diagnostics.rs +++ b/src/test/ui-fulldeps/internal-lints/diagnostics.rs @@ -15,7 +15,7 @@ use rustc_errors::{ AddToDiagnostic, IntoDiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, fluent }; -use rustc_macros::{Diagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; #[derive(Diagnostic)] @@ -25,7 +25,7 @@ struct DeriveSessionDiagnostic { span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[note(parser::add_paren)] struct Note { #[primary_span] diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index fd8128c31f8..80ea9082881 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -17,7 +17,7 @@ use rustc_span::symbol::Ident; use rustc_span::Span; extern crate rustc_macros; -use rustc_macros::{Diagnostic, LintDiagnostic, SessionSubdiagnostic}; +use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; extern crate rustc_middle; use rustc_middle::ty::Ty; @@ -462,7 +462,7 @@ struct NoApplicability { suggestion: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[note(parser::add_paren)] struct Note; diff --git a/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs b/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs index 812ca0c72bd..9fbe7b1f4c8 100644 --- a/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs +++ b/src/test/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs @@ -1,8 +1,8 @@ // check-fail -// Tests error conditions for specifying subdiagnostics using #[derive(SessionSubdiagnostic)] +// Tests error conditions for specifying subdiagnostics using #[derive(Subdiagnostic)] // The proc_macro2 crate handles spans differently when on beta/stable release rather than nightly, -// changing the output of this test. Since SessionSubdiagnostic is strictly internal to the compiler +// changing the output of this test. Since Subdiagnostic is strictly internal to the compiler // the test is just ignored on stable and beta: // ignore-beta // ignore-stable @@ -17,9 +17,9 @@ extern crate rustc_macros; use rustc_errors::Applicability; use rustc_span::Span; -use rustc_macros::SessionSubdiagnostic; +use rustc_macros::Subdiagnostic; -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren)] struct A { #[primary_span] @@ -27,7 +27,7 @@ struct A { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] enum B { #[label(parser::add_paren)] A { @@ -43,14 +43,14 @@ enum B { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren)] //~^ ERROR label without `#[primary_span]` field struct C { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label] //~^ ERROR `#[label]` is not a valid attribute struct D { @@ -59,7 +59,7 @@ struct D { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[foo] //~^ ERROR `#[foo]` is not a valid attribute //~^^ ERROR cannot find attribute `foo` in this scope @@ -69,7 +69,7 @@ struct E { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label = "..."] //~^ ERROR `#[label = ...]` is not a valid attribute struct F { @@ -78,7 +78,7 @@ struct F { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(bug = "...")] //~^ ERROR `#[label(bug = ...)]` is not a valid attribute struct G { @@ -87,7 +87,7 @@ struct G { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label("...")] //~^ ERROR `#[label("...")]` is not a valid attribute struct H { @@ -96,7 +96,7 @@ struct H { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(slug = 4)] //~^ ERROR `#[label(slug = ...)]` is not a valid attribute struct J { @@ -105,7 +105,7 @@ struct J { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(slug("..."))] //~^ ERROR `#[label(slug(...))]` is not a valid attribute struct K { @@ -114,7 +114,7 @@ struct K { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(slug)] //~^ ERROR cannot find value `slug` in module `rustc_errors::fluent` //~^^ NOTE not found in `rustc_errors::fluent` @@ -124,7 +124,7 @@ struct L { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label()] //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute struct M { @@ -133,7 +133,7 @@ struct M { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren, code = "...")] //~^ ERROR `code` is not a valid nested attribute of a `label` attribute struct N { @@ -142,7 +142,7 @@ struct N { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren, applicability = "machine-applicable")] //~^ ERROR `applicability` is not a valid nested attribute of a `label` attribute struct O { @@ -151,7 +151,7 @@ struct O { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[foo] //~^ ERROR cannot find attribute `foo` in this scope //~^^ ERROR unsupported type attribute for subdiagnostic enum @@ -164,7 +164,7 @@ enum P { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] enum Q { #[bar] //~^ ERROR `#[bar]` is not a valid attribute @@ -176,7 +176,7 @@ enum Q { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] enum R { #[bar = "..."] //~^ ERROR `#[bar = ...]` is not a valid attribute @@ -188,7 +188,7 @@ enum R { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] enum S { #[bar = 4] //~^ ERROR `#[bar = ...]` is not a valid attribute @@ -200,7 +200,7 @@ enum S { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] enum T { #[bar("...")] //~^ ERROR `#[bar(...)]` is not a valid attribute @@ -212,7 +212,7 @@ enum T { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] enum U { #[label(code = "...")] //~^ ERROR diagnostic slug must be first argument of a `#[label(...)]` attribute @@ -223,7 +223,7 @@ enum U { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] enum V { #[label(parser::add_paren)] A { @@ -239,7 +239,7 @@ enum V { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren)] //~^ ERROR label without `#[primary_span]` field struct W { @@ -248,7 +248,7 @@ struct W { span: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren)] struct X { #[primary_span] @@ -258,7 +258,7 @@ struct X { applicability: Applicability, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren)] struct Y { #[primary_span] @@ -269,7 +269,7 @@ struct Y { bar: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren)] struct Z { #[primary_span] @@ -280,7 +280,7 @@ struct Z { bar: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren)] struct AA { #[primary_span] @@ -291,7 +291,7 @@ struct AA { bar: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren)] struct AB { #[primary_span] @@ -300,14 +300,14 @@ struct AB { z: Z } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] union AC { //~^ ERROR unexpected unsupported untagged union span: u32, b: u64 } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren)] #[label(parser::add_paren)] struct AD { @@ -315,7 +315,7 @@ struct AD { span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren, parser::add_paren)] //~^ ERROR `#[label(parser::add_paren)]` is not a valid attribute struct AE { @@ -323,7 +323,7 @@ struct AE { span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(parser::add_paren)] struct AF { #[primary_span] @@ -334,14 +334,14 @@ struct AF { span_b: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] struct AG { //~^ ERROR subdiagnostic kind not specified #[primary_span] span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[suggestion(parser::add_paren, code = "...")] struct AH { #[primary_span] @@ -351,7 +351,7 @@ struct AH { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] enum AI { #[suggestion(parser::add_paren, code = "...")] A { @@ -371,7 +371,7 @@ enum AI { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[suggestion(parser::add_paren, code = "...", code = "...")] //~^ ERROR specified multiple times //~^^ NOTE previously specified here @@ -382,7 +382,7 @@ struct AJ { applicability: Applicability, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[suggestion(parser::add_paren, code = "...")] struct AK { #[primary_span] @@ -395,7 +395,7 @@ struct AK { applicability_b: Applicability, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[suggestion(parser::add_paren, code = "...")] struct AL { #[primary_span] @@ -405,14 +405,14 @@ struct AL { applicability: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[suggestion(parser::add_paren, code = "...")] struct AM { #[primary_span] span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[suggestion(parser::add_paren)] //~^ ERROR suggestion without `code = "..."` struct AN { @@ -422,7 +422,7 @@ struct AN { applicability: Applicability, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[suggestion(parser::add_paren, code ="...", applicability = "foo")] //~^ ERROR invalid applicability struct AO { @@ -430,31 +430,31 @@ struct AO { span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[help(parser::add_paren)] struct AP { var: String } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[note(parser::add_paren)] struct AQ; -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[suggestion(parser::add_paren, code = "...")] //~^ ERROR suggestion without `#[primary_span]` field struct AR { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[suggestion(parser::add_paren, code ="...", applicability = "machine-applicable")] struct AS { #[primary_span] span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label] //~^ ERROR unsupported type attribute for subdiagnostic enum enum AT { @@ -466,7 +466,7 @@ enum AT { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")] struct AU { #[primary_span] @@ -474,7 +474,7 @@ struct AU { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")] //~^ ERROR `var` doesn't refer to a field on this type struct AV { @@ -482,7 +482,7 @@ struct AV { span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] enum AW { #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")] A { @@ -492,7 +492,7 @@ enum AW { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] enum AX { #[suggestion(parser::add_paren, code ="{var}", applicability = "machine-applicable")] //~^ ERROR `var` doesn't refer to a field on this type @@ -502,18 +502,18 @@ enum AX { } } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[warning(parser::add_paren)] struct AY {} -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[warning(parser::add_paren)] struct AZ { #[primary_span] span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[suggestion(parser::add_paren, code = "...")] //~^ ERROR suggestion without `#[primary_span]` field struct BA { @@ -528,7 +528,7 @@ struct BA { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[multipart_suggestion(parser::add_paren, code = "...", applicability = "machine-applicable")] //~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields //~| ERROR `code` is not a valid nested attribute of a `multipart_suggestion` attribute @@ -536,7 +536,7 @@ struct BBa { var: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] struct BBb { #[suggestion_part] @@ -544,7 +544,7 @@ struct BBb { span1: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] struct BBc { #[suggestion_part()] @@ -552,7 +552,7 @@ struct BBc { span1: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[multipart_suggestion(parser::add_paren)] //~^ ERROR multipart suggestion without any `#[suggestion_part(...)]` fields struct BC { @@ -561,7 +561,7 @@ struct BC { span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[multipart_suggestion(parser::add_paren)] struct BD { #[suggestion_part] @@ -581,7 +581,7 @@ struct BD { s2: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] struct BE { #[suggestion_part(code = "...", code = ",,,")] @@ -590,7 +590,7 @@ struct BE { span: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] struct BF { #[suggestion_part(code = "(")] @@ -599,7 +599,7 @@ struct BF { second: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[multipart_suggestion(parser::add_paren)] struct BG { #[applicability] @@ -610,7 +610,7 @@ struct BG { second: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] //~^ NOTE previously specified here struct BH { @@ -623,7 +623,7 @@ struct BH { second: Span, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[multipart_suggestion(parser::add_paren, applicability = "machine-applicable")] struct BI { #[suggestion_part(code = "")] -- cgit 1.4.1-3-g733a5 From e52e2344dc574922ce4f8ddfd508f8bfdec3f404 Mon Sep 17 00:00:00 2001 From: Jhonny Bill Mena Date: Thu, 15 Sep 2022 00:01:44 -0400 Subject: FIX - adopt new Diagnostic naming in newly migrated modules FIX - ambiguous Diagnostic link in docs UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic [Gardening] FIX - formatting via `x fmt` FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way DELETE - unneeded allow attributes in Handler method FIX - broken test FIX - Rebase conflict UPDATE - rename residual _SessionDiagnostic and fix LintDiag link --- compiler/rustc_ast_lowering/src/errors.rs | 2 +- compiler/rustc_attr/src/session_diagnostics.rs | 3 +- compiler/rustc_errors/src/diagnostic.rs | 2 +- compiler/rustc_errors/src/diagnostic_builder.rs | 2 +- compiler/rustc_errors/src/lib.rs | 44 +---------------- compiler/rustc_expand/src/base.rs | 2 +- compiler/rustc_infer/src/errors/mod.rs | 36 +++++++------- .../rustc_infer/src/errors/note_and_explain.rs | 4 +- .../nice_region_error/different_lifetimes.rs | 2 +- compiler/rustc_lint/src/errors.rs | 2 +- compiler/rustc_lint/src/internal.rs | 2 +- .../rustc_macros/src/diagnostics/diagnostic.rs | 6 +-- compiler/rustc_macros/src/diagnostics/mod.rs | 6 +-- compiler/rustc_metadata/src/errors.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 3 +- compiler/rustc_monomorphize/src/errors.rs | 2 +- compiler/rustc_parse/src/parser/diagnostics.rs | 4 +- compiler/rustc_passes/src/errors.rs | 2 +- compiler/rustc_query_system/src/error.rs | 2 +- compiler/rustc_query_system/src/query/job.rs | 2 +- compiler/rustc_session/src/config.rs | 3 +- compiler/rustc_session/src/errors.rs | 56 +++++++++++----------- compiler/rustc_session/src/parse.rs | 4 +- compiler/rustc_session/src/session.rs | 4 +- compiler/rustc_span/src/symbol.rs | 4 +- compiler/rustc_trait_selection/src/errors.rs | 2 +- src/test/ui-fulldeps/internal-lints/diagnostics.rs | 10 ++-- .../session-diagnostic/diagnostic-derive.stderr | 2 +- 28 files changed, 88 insertions(+), 127 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 052979d6d45..1ad5fa21d85 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -335,7 +335,7 @@ pub struct InclusiveRangeWithNoEnd { pub span: Span, } -#[derive(SessionDiagnostic, Clone, Copy)] +#[derive(Diagnostic, Clone, Copy)] #[diag(ast_lowering::trait_fn_async, code = "E0706")] #[note] #[note(ast_lowering::note2)] diff --git a/compiler/rustc_attr/src/session_diagnostics.rs b/compiler/rustc_attr/src/session_diagnostics.rs index 940a48ed915..d3e9a16a9a8 100644 --- a/compiler/rustc_attr/src/session_diagnostics.rs +++ b/compiler/rustc_attr/src/session_diagnostics.rs @@ -2,8 +2,7 @@ use std::num::IntErrorKind; use rustc_ast as ast; use rustc_errors::{ - error_code, fluent, Applicability, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, - Handler, + error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, }; use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index c66889189ad..a52e95e92d5 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -178,7 +178,7 @@ impl IntoDiagnosticArg for hir::ConstContext { /// Trait implemented by error types. This should not be implemented manually. Instead, use /// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic]. #[cfg_attr(bootstrap, rustc_diagnostic_item = "AddSubdiagnostic")] -#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "Subdiagnostic")] +#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "AddToDiagnostic")] pub trait AddToDiagnostic { /// Add a subdiagnostic to an existing diagnostic. fn add_to_diagnostic(self, diag: &mut Diagnostic); diff --git a/compiler/rustc_errors/src/diagnostic_builder.rs b/compiler/rustc_errors/src/diagnostic_builder.rs index f9b46053486..b4ba65ca96d 100644 --- a/compiler/rustc_errors/src/diagnostic_builder.rs +++ b/compiler/rustc_errors/src/diagnostic_builder.rs @@ -16,7 +16,7 @@ use std::thread::panicking; /// Trait implemented by error types. This should not be implemented manually. Instead, use /// `#[derive(Diagnostic)]` -- see [rustc_macros::Diagnostic]. #[cfg_attr(bootstrap, rustc_diagnostic_item = "SessionDiagnostic")] -#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "Diagnostic")] +#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "IntoDiagnostic")] pub trait IntoDiagnostic<'a, T: EmissionGuarantee = ErrorGuaranteed> { /// Write out as a diagnostic out of `Handler`. #[must_use] diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 19cae2c9077..68971cebc35 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -437,11 +437,11 @@ struct HandlerInner { /// have been converted. check_unstable_expect_diagnostics: bool, - /// Expected [`Diagnostic`]s store a [`LintExpectationId`] as part of + /// Expected [`Diagnostic`][diagnostic::Diagnostic]s store a [`LintExpectationId`] as part of /// the lint level. [`LintExpectationId`]s created early during the compilation /// (before `HirId`s have been defined) are not stable and can therefore not be /// stored on disk. This buffer stores these diagnostics until the ID has been - /// replaced by a stable [`LintExpectationId`]. The [`Diagnostic`]s are the + /// replaced by a stable [`LintExpectationId`]. The [`Diagnostic`][diagnostic::Diagnostic]s are the /// submitted for storage and added to the list of fulfilled expectations. unstable_expect_diagnostics: Vec, @@ -647,8 +647,6 @@ impl Handler { /// Construct a builder with the `msg` at the level appropriate for the specific `EmissionGuarantee`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_diagnostic( &self, msg: impl Into, @@ -662,8 +660,6 @@ impl Handler { /// * `can_emit_warnings` is `true` /// * `is_force_warn` was set in `DiagnosticId::Lint` #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_warn( &self, span: impl Into, @@ -680,8 +676,6 @@ impl Handler { /// Attempting to `.emit()` the builder will only emit if either: /// * `can_emit_warnings` is `true` /// * `is_force_warn` was set in `DiagnosticId::Lint` - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_warn_with_expectation( &self, span: impl Into, @@ -695,8 +689,6 @@ impl Handler { /// Construct a builder at the `Allow` level at the given `span` and with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_allow( &self, span: impl Into, @@ -710,8 +702,6 @@ impl Handler { /// Construct a builder at the `Warning` level at the given `span` and with the `msg`. /// Also include a code. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_warn_with_code( &self, span: impl Into, @@ -729,8 +719,6 @@ impl Handler { /// * `can_emit_warnings` is `true` /// * `is_force_warn` was set in `DiagnosticId::Lint` #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_warn(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { DiagnosticBuilder::new(self, Level::Warning(None), msg) } @@ -741,8 +729,6 @@ impl Handler { /// Attempting to `.emit()` the builder will only emit if either: /// * `can_emit_warnings` is `true` /// * `is_force_warn` was set in `DiagnosticId::Lint` - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_warn_with_expectation( &self, msg: impl Into, @@ -753,16 +739,12 @@ impl Handler { /// Construct a builder at the `Allow` level with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_allow(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { DiagnosticBuilder::new(self, Level::Allow, msg) } /// Construct a builder at the `Expect` level with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_expect( &self, msg: impl Into, @@ -773,8 +755,6 @@ impl Handler { /// Construct a builder at the `Error` level at the given `span` and with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_err( &self, span: impl Into, @@ -787,8 +767,6 @@ impl Handler { /// Construct a builder at the `Error` level at the given `span`, with the `msg`, and `code`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_err_with_code( &self, span: impl Into, @@ -803,8 +781,6 @@ impl Handler { /// Construct a builder at the `Error` level with the `msg`. // FIXME: This method should be removed (every error should have an associated error code). #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_err( &self, msg: impl Into, @@ -814,16 +790,12 @@ impl Handler { /// This should only be used by `rustc_middle::lint::struct_lint_level`. Do not use it for hard errors. #[doc(hidden)] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_err_lint(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { DiagnosticBuilder::new(self, Level::Error { lint: true }, msg) } /// Construct a builder at the `Error` level with the `msg` and the `code`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_err_with_code( &self, msg: impl Into, @@ -836,8 +808,6 @@ impl Handler { /// Construct a builder at the `Warn` level with the `msg` and the `code`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_warn_with_code( &self, msg: impl Into, @@ -850,8 +820,6 @@ impl Handler { /// Construct a builder at the `Fatal` level at the given `span` and with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_fatal( &self, span: impl Into, @@ -864,8 +832,6 @@ impl Handler { /// Construct a builder at the `Fatal` level at the given `span`, with the `msg`, and `code`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_span_fatal_with_code( &self, span: impl Into, @@ -879,24 +845,18 @@ impl Handler { /// Construct a builder at the `Error` level with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_fatal(&self, msg: impl Into) -> DiagnosticBuilder<'_, !> { DiagnosticBuilder::new_fatal(self, msg) } /// Construct a builder at the `Help` level with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_help(&self, msg: impl Into) -> DiagnosticBuilder<'_, ()> { DiagnosticBuilder::new(self, Level::Help, msg) } /// Construct a builder at the `Note` level with the `msg`. #[rustc_lint_diagnostics] - #[allow(rustc::diagnostic_outside_of_impl)] - #[allow(rustc::untranslatable_diagnostic)] pub fn struct_note_without_error( &self, msg: impl Into, diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index ca429b6adc1..cd8a525e062 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -11,7 +11,7 @@ use rustc_attr::{self as attr, Deprecation, Stability}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::sync::{self, Lrc}; use rustc_errors::{ - Applicability, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, MultiSpan, PResult, + Applicability, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, MultiSpan, PResult, }; use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT; use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiagnostics}; diff --git a/compiler/rustc_infer/src/errors/mod.rs b/compiler/rustc_infer/src/errors/mod.rs index d232a186462..85b877652c6 100644 --- a/compiler/rustc_infer/src/errors/mod.rs +++ b/compiler/rustc_infer/src/errors/mod.rs @@ -1,10 +1,10 @@ use hir::GenericParamKind; use rustc_errors::{ - fluent, AddSubdiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString, MultiSpan, + fluent, AddToDiagnostic, Applicability, DiagnosticMessage, DiagnosticStyledString, MultiSpan, }; use rustc_hir as hir; use rustc_hir::{FnRetTy, Ty}; -use rustc_macros::SessionDiagnostic; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_middle::ty::{Region, TyCtxt}; use rustc_span::symbol::kw; use rustc_span::{symbol::Ident, BytePos, Span}; @@ -16,7 +16,7 @@ use crate::infer::error_reporting::{ pub mod note_and_explain; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::opaque_hidden_type)] pub struct OpaqueHiddenTypeDiag { #[primary_span] @@ -28,7 +28,7 @@ pub struct OpaqueHiddenTypeDiag { pub hidden_type: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::type_annotations_needed, code = "E0282")] pub struct AnnotationRequired<'a> { #[primary_span] @@ -46,7 +46,7 @@ pub struct AnnotationRequired<'a> { } // Copy of `AnnotationRequired` for E0283 -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::type_annotations_needed, code = "E0283")] pub struct AmbigousImpl<'a> { #[primary_span] @@ -64,7 +64,7 @@ pub struct AmbigousImpl<'a> { } // Copy of `AnnotationRequired` for E0284 -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::type_annotations_needed, code = "E0284")] pub struct AmbigousReturn<'a> { #[primary_span] @@ -81,7 +81,7 @@ pub struct AmbigousReturn<'a> { pub multi_suggestions: Vec>, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::need_type_info_in_generator, code = "E0698")] pub struct NeedTypeInfoInGenerator<'a> { #[primary_span] @@ -92,7 +92,7 @@ pub struct NeedTypeInfoInGenerator<'a> { } // Used when a better one isn't available -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] #[label(infer::label_bad)] pub struct InferenceBadError<'a> { #[primary_span] @@ -106,7 +106,7 @@ pub struct InferenceBadError<'a> { pub name: String, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum SourceKindSubdiag<'a> { #[suggestion_verbose( infer::source_kind_subdiag_let, @@ -147,7 +147,7 @@ pub enum SourceKindSubdiag<'a> { }, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum SourceKindMultiSuggestion<'a> { #[multipart_suggestion_verbose( infer::source_kind_fully_qualified, @@ -228,7 +228,7 @@ pub enum RegionOriginNote<'a> { }, } -impl AddSubdiagnostic for RegionOriginNote<'_> { +impl AddToDiagnostic for RegionOriginNote<'_> { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { let mut label_or_note = |span, msg: DiagnosticMessage| { let sub_count = diag.children.iter().filter(|d| d.span.is_dummy()).count(); @@ -289,7 +289,7 @@ pub enum LifetimeMismatchLabels { }, } -impl AddSubdiagnostic for LifetimeMismatchLabels { +impl AddToDiagnostic for LifetimeMismatchLabels { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { match self { LifetimeMismatchLabels::InRet { param_span, ret_span, span, label_var1 } => { @@ -339,7 +339,7 @@ pub struct AddLifetimeParamsSuggestion<'a> { pub add_note: bool, } -impl AddSubdiagnostic for AddLifetimeParamsSuggestion<'_> { +impl AddToDiagnostic for AddLifetimeParamsSuggestion<'_> { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { let mut mk_suggestion = || { let ( @@ -422,7 +422,7 @@ impl AddSubdiagnostic for AddLifetimeParamsSuggestion<'_> { } } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::lifetime_mismatch, code = "E0623")] pub struct LifetimeMismatch<'a> { #[primary_span] @@ -438,7 +438,7 @@ pub struct IntroducesStaticBecauseUnmetLifetimeReq { pub binding_span: Span, } -impl AddSubdiagnostic for IntroducesStaticBecauseUnmetLifetimeReq { +impl AddToDiagnostic for IntroducesStaticBecauseUnmetLifetimeReq { fn add_to_diagnostic(mut self, diag: &mut rustc_errors::Diagnostic) { self.unmet_requirements .push_span_label(self.binding_span, fluent::infer::msl_introduces_static); @@ -450,7 +450,7 @@ pub struct ImplNote { pub impl_span: Option, } -impl AddSubdiagnostic for ImplNote { +impl AddToDiagnostic for ImplNote { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { match self.impl_span { Some(span) => diag.span_note(span, fluent::infer::msl_impl_note), @@ -465,7 +465,7 @@ pub enum TraitSubdiag { } // FIXME(#100717) used in `Vec` so requires eager translation/list support -impl AddSubdiagnostic for TraitSubdiag { +impl AddToDiagnostic for TraitSubdiag { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { match self { TraitSubdiag::Note { span } => { @@ -483,7 +483,7 @@ impl AddSubdiagnostic for TraitSubdiag { } } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(infer::mismatched_static_lifetime)] pub struct MismatchedStaticLifetime<'a> { #[primary_span] diff --git a/compiler/rustc_infer/src/errors/note_and_explain.rs b/compiler/rustc_infer/src/errors/note_and_explain.rs index 7e051835b4b..7f54918f736 100644 --- a/compiler/rustc_infer/src/errors/note_and_explain.rs +++ b/compiler/rustc_infer/src/errors/note_and_explain.rs @@ -1,5 +1,5 @@ use crate::infer::error_reporting::nice_region_error::find_anon_type; -use rustc_errors::{self, fluent, AddSubdiagnostic, IntoDiagnosticArg}; +use rustc_errors::{self, fluent, AddToDiagnostic, IntoDiagnosticArg}; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::{symbol::kw, Span}; @@ -158,7 +158,7 @@ impl RegionExplanation<'_> { } } -impl AddSubdiagnostic for RegionExplanation<'_> { +impl AddToDiagnostic for RegionExplanation<'_> { fn add_to_diagnostic(self, diag: &mut rustc_errors::Diagnostic) { if let Some(span) = self.desc.span { diag.span_note(span, fluent::infer::region_explanation); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs index 3a4320a9a8f..da0271a345e 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -11,7 +11,7 @@ use crate::infer::lexical_region_resolve::RegionResolutionError; use crate::infer::SubregionOrigin; use crate::infer::TyCtxt; -use rustc_errors::AddSubdiagnostic; +use rustc_errors::AddToDiagnostic; use rustc_errors::{Diagnostic, ErrorGuaranteed}; use rustc_hir::Ty; use rustc_middle::ty::Region; diff --git a/compiler/rustc_lint/src/errors.rs b/compiler/rustc_lint/src/errors.rs index 3a89d90c88a..880f3fbd00e 100644 --- a/compiler/rustc_lint/src/errors.rs +++ b/compiler/rustc_lint/src/errors.rs @@ -1,4 +1,4 @@ -use rustc_errors::{fluent, AddToDiagnostic, IntoDiagnostic, ErrorGuaranteed, Handler}; +use rustc_errors::{fluent, AddToDiagnostic, ErrorGuaranteed, Handler, IntoDiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_session::lint::Level; use rustc_span::{Span, Symbol}; diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 942475d31fe..d8a03024d13 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -404,7 +404,7 @@ impl LateLintPass<'_> for Diagnostics { let Impl { of_trait: Some(of_trait), .. } = impl_ && let Some(def_id) = of_trait.trait_def_id() && let Some(name) = cx.tcx.get_diagnostic_name(def_id) && - matches!(name, sym::Diagnostic | sym::Subdiagnostic | sym::DecorateLint) + matches!(name, sym::IntoDiagnostic | sym::AddToDiagnostic | sym::DecorateLint) { found_impl = true; break; diff --git a/compiler/rustc_macros/src/diagnostics/diagnostic.rs b/compiler/rustc_macros/src/diagnostics/diagnostic.rs index c1aae04fcee..3b8d9594eb9 100644 --- a/compiler/rustc_macros/src/diagnostics/diagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/diagnostic.rs @@ -9,13 +9,13 @@ use syn::spanned::Spanned; use synstructure::Structure; /// The central struct for constructing the `into_diagnostic` method from an annotated struct. -pub(crate) struct SessionDiagnosticDerive<'a> { +pub(crate) struct DiagnosticDerive<'a> { structure: Structure<'a>, handler: syn::Ident, builder: DiagnosticDeriveBuilder, } -impl<'a> SessionDiagnosticDerive<'a> { +impl<'a> DiagnosticDerive<'a> { pub(crate) fn new(diag: syn::Ident, handler: syn::Ident, structure: Structure<'a>) -> Self { Self { builder: DiagnosticDeriveBuilder { @@ -31,7 +31,7 @@ impl<'a> SessionDiagnosticDerive<'a> { } pub(crate) fn into_tokens(self) -> TokenStream { - let SessionDiagnosticDerive { mut structure, handler, mut builder } = self; + let DiagnosticDerive { mut structure, handler, mut builder } = self; let ast = structure.ast(); let implementation = { diff --git a/compiler/rustc_macros/src/diagnostics/mod.rs b/compiler/rustc_macros/src/diagnostics/mod.rs index 8eaa8b87c0f..4166816b5e3 100644 --- a/compiler/rustc_macros/src/diagnostics/mod.rs +++ b/compiler/rustc_macros/src/diagnostics/mod.rs @@ -5,7 +5,7 @@ mod fluent; mod subdiagnostic; mod utils; -use diagnostic::{LintDiagnosticDerive, SessionDiagnosticDerive}; +use diagnostic::{DiagnosticDerive, LintDiagnosticDerive}; pub(crate) use fluent::fluent_messages; use proc_macro2::TokenStream; use quote::format_ident; @@ -59,7 +59,7 @@ use synstructure::Structure; /// See rustc dev guide for more examples on using the `#[derive(Diagnostic)]`: /// pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream { - SessionDiagnosticDerive::new(format_ident!("diag"), format_ident!("handler"), s).into_tokens() + DiagnosticDerive::new(format_ident!("diag"), format_ident!("handler"), s).into_tokens() } /// Implements `#[derive(LintDiagnostic)]`, which allows for lints to be specified as a struct, @@ -103,7 +103,7 @@ pub fn session_diagnostic_derive(s: Structure<'_>) -> TokenStream { /// ``` /// /// See rustc dev guide for more examples on using the `#[derive(LintDiagnostic)]`: -/// +/// pub fn lint_diagnostic_derive(s: Structure<'_>) -> TokenStream { LintDiagnosticDerive::new(format_ident!("diag"), s).into_tokens() } diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 8ff4eb5fdbc..1cd550644bf 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -3,7 +3,7 @@ use std::{ path::{Path, PathBuf}, }; -use rustc_errors::{error_code, IntoDiagnostic, ErrorGuaranteed}; +use rustc_errors::{error_code, ErrorGuaranteed, IntoDiagnostic}; use rustc_macros::Diagnostic; use rustc_session::config; use rustc_span::{sym, Span, Symbol}; diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 10c5933574f..2b5b4017a5a 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -53,6 +53,7 @@ use rustc_query_system::ich::StableHashingContext; use rustc_serialize::opaque::{FileEncodeResult, FileEncoder}; use rustc_session::config::{CrateType, OutputFilenames}; use rustc_session::cstore::CrateStoreDyn; +use rustc_session::errors::TargetDataLayoutErrorsWrapper; use rustc_session::lint::Lint; use rustc_session::Limit; use rustc_session::Session; @@ -1245,7 +1246,7 @@ impl<'tcx> TyCtxt<'tcx> { output_filenames: OutputFilenames, ) -> GlobalCtxt<'tcx> { let data_layout = TargetDataLayout::parse(&s.target).unwrap_or_else(|err| { - s.emit_fatal(err); + s.emit_fatal(TargetDataLayoutErrorsWrapper(err)); }); let interners = CtxtInterners::new(arena); let common_types = CommonTypes::new( diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs index cdc2c74ac8f..cf6e18c013b 100644 --- a/compiler/rustc_monomorphize/src/errors.rs +++ b/compiler/rustc_monomorphize/src/errors.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; -use rustc_errors::IntoDiagnostic; use rustc_errors::ErrorGuaranteed; +use rustc_errors::IntoDiagnostic; use rustc_macros::{Diagnostic, LintDiagnostic}; use rustc_span::Span; diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 78bc29fc375..dcea11eadcb 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -434,7 +434,7 @@ pub(crate) struct NotAsNegationOperator { pub sub: NotAsNegationOperatorSub, } -#[derive(SessionSubdiagnostic)] +#[derive(Subdiagnostic)] pub enum NotAsNegationOperatorSub { #[suggestion_short( parser::unexpected_token_after_not_default, @@ -737,7 +737,7 @@ pub(crate) struct RemoveLet { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(parser::use_eq_instead)] pub(crate) struct UseEqInstead { #[primary_span] diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 52aea9bba43..be67c9e3b82 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -650,7 +650,7 @@ pub struct RustcLintOptDenyFieldAccess { pub span: Span, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(passes::collapse_debuginfo)] pub struct CollapseDebuginfo { #[primary_span] diff --git a/compiler/rustc_query_system/src/error.rs b/compiler/rustc_query_system/src/error.rs index ceec75fce28..8602a4cf5ae 100644 --- a/compiler/rustc_query_system/src/error.rs +++ b/compiler/rustc_query_system/src/error.rs @@ -1,7 +1,7 @@ use rustc_errors::AddToDiagnostic; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_session::Limit; use rustc_span::{Span, Symbol}; -use rustc_macros::{Diagnostic, Subdiagnostic}; pub struct CycleStack { pub span: Span, diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 6d26c8f47f3..64aba4703ca 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -4,7 +4,7 @@ use crate::query::{QueryContext, QueryStackFrame}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{ - Diagnostic, DiagnosticBuilder, IntoDiagnostic, ErrorGuaranteed, Handler, Level, + Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, Level, }; use rustc_hir::def::DefKind; use rustc_session::Session; diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 8bb3878fbbb..57c9a3f4822 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -3,6 +3,7 @@ pub use crate::options::*; +use crate::errors::TargetDataLayoutErrorsWrapper; use crate::search_paths::SearchPath; use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind}; use crate::{early_error, early_warn, Session}; @@ -898,7 +899,7 @@ fn default_configuration(sess: &Session) -> CrateConfig { let max_atomic_width = sess.target.max_atomic_width(); let atomic_cas = sess.target.atomic_cas; let layout = TargetDataLayout::parse(&sess.target).unwrap_or_else(|err| { - sess.emit_fatal(err); + sess.emit_fatal(TargetDataLayoutErrorsWrapper(err)); }); let mut ret = CrateConfig::default(); diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index 997a45272bc..e01dafe2102 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -1,9 +1,10 @@ use std::num::NonZeroU32; use crate::cgu_reuse_tracker::CguReuse; -use crate::{self as rustc_session, SessionDiagnostic}; -use rustc_errors::{fluent, DiagnosticBuilder, ErrorGuaranteed, Handler, MultiSpan}; -use rustc_macros::SessionDiagnostic; +use rustc_errors::{ + fluent, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic, MultiSpan, +}; +use rustc_macros::Diagnostic; use rustc_span::{Span, Symbol}; use rustc_target::abi::TargetDataLayoutErrors; use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple}; @@ -46,10 +47,12 @@ pub struct FeatureDiagnosticHelp { pub feature: Symbol, } -impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> { +pub struct TargetDataLayoutErrorsWrapper<'a>(pub TargetDataLayoutErrors<'a>); + +impl IntoDiagnostic<'_, !> for TargetDataLayoutErrorsWrapper<'_> { fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> { let mut diag; - match self { + match self.0 { TargetDataLayoutErrors::InvalidAddressSpace { addr_space, err, cause } => { diag = handler.struct_fatal(fluent::session::target_invalid_address_space); diag.set_arg("addr_space", addr_space); @@ -97,87 +100,87 @@ impl IntoDiagnostic<'_, !> for TargetDataLayoutErrors<'_> { } } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::not_circumvent_feature)] pub struct NotCircumventFeature; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::linker_plugin_lto_windows_not_supported)] pub struct LinkerPluginToWindowsNotSupported; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::profile_use_file_does_not_exist)] pub struct ProfileUseFileDoesNotExist<'a> { pub path: &'a std::path::Path, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::profile_sample_use_file_does_not_exist)] pub struct ProfileSampleUseFileDoesNotExist<'a> { pub path: &'a std::path::Path, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::target_requires_unwind_tables)] pub struct TargetRequiresUnwindTables; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::sanitizer_not_supported)] pub struct SanitizerNotSupported { pub us: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::sanitizers_not_supported)] pub struct SanitizersNotSupported { pub us: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::cannot_mix_and_match_sanitizers)] pub struct CannotMixAndMatchSanitizers { pub first: String, pub second: String, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::cannot_enable_crt_static_linux)] pub struct CannotEnableCrtStaticLinux; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::sanitizer_cfi_enabled)] pub struct SanitizerCfiEnabled; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::unstable_virtual_function_elimination)] pub struct UnstableVirtualFunctionElimination; -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::unsupported_dwarf_version)] pub struct UnsupportedDwarfVersion { pub dwarf_version: u32, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::target_stack_protector_not_supported)] pub struct StackProtectorNotSupportedForTarget<'a> { pub stack_protector: StackProtector, pub target_triple: &'a TargetTriple, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::split_debuginfo_unstable_platform)] pub struct SplitDebugInfoUnstablePlatform { pub debuginfo: SplitDebuginfo, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::file_is_not_writeable)] pub struct FileIsNotWriteable<'a> { pub file: &'a std::path::Path, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::crate_name_does_not_match)] pub struct CrateNameDoesNotMatch<'a> { #[primary_span] @@ -186,13 +189,13 @@ pub struct CrateNameDoesNotMatch<'a> { pub name: Symbol, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::crate_name_invalid)] pub struct CrateNameInvalid<'a> { pub s: &'a str, } -#[derive(SessionDiagnostic)] +#[derive(Diagnostic)] #[diag(session::crate_name_empty)] pub struct CrateNameEmpty { #[primary_span] @@ -205,11 +208,8 @@ pub struct InvalidCharacterInCrateName<'a> { pub crate_name: &'a str, } -impl crate::SessionDiagnostic<'_> for InvalidCharacterInCrateName<'_> { - fn into_diagnostic( - self, - sess: &Handler, - ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> { +impl IntoDiagnostic<'_> for InvalidCharacterInCrateName<'_> { + fn into_diagnostic(self, sess: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> { let mut diag = sess.struct_err(fluent::session::invalid_character_in_create_name); if let Some(sp) = self.span { diag.set_span(sp); diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index 3189dcb08ad..b9202af2a67 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -11,8 +11,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_data_structures::sync::{Lock, Lrc}; use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler}; use rustc_errors::{ - fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, IntoDiagnostic, - DiagnosticId, DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, MultiSpan, StashKey, + fallback_fluent_bundle, Applicability, Diagnostic, DiagnosticBuilder, DiagnosticId, + DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, MultiSpan, StashKey, }; use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures}; use rustc_span::edition::Edition; diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index e660b739928..0142e981766 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -27,8 +27,8 @@ use rustc_errors::emitter::{Emitter, EmitterWriter, HumanReadableErrorType}; use rustc_errors::json::JsonEmitter; use rustc_errors::registry::Registry; use rustc_errors::{ - error_code, fallback_fluent_bundle, DiagnosticBuilder, IntoDiagnostic, DiagnosticId, - DiagnosticMessage, ErrorGuaranteed, FluentBundle, LazyFallbackBundle, MultiSpan, + error_code, fallback_fluent_bundle, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, + ErrorGuaranteed, FluentBundle, IntoDiagnostic, LazyFallbackBundle, MultiSpan, }; use rustc_macros::HashStable_Generic; pub use rustc_span::def_id::StableCrateId; diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 1baad6a9fd7..7785d29c15f 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -125,6 +125,7 @@ symbols! { Symbols { AcqRel, Acquire, + AddToDiagnostic, Alignment, Any, Arc, @@ -176,7 +177,6 @@ symbols! { DecorateLint, Default, Deref, - Diagnostic, DiagnosticMessage, DirBuilder, Display, @@ -210,6 +210,7 @@ symbols! { Implied, Input, Into, + IntoDiagnostic, IntoFuture, IntoIterator, IoRead, @@ -282,7 +283,6 @@ symbols! { String, StructuralEq, StructuralPartialEq, - Subdiagnostic, SubdiagnosticMessage, Sync, T, diff --git a/compiler/rustc_trait_selection/src/errors.rs b/compiler/rustc_trait_selection/src/errors.rs index b02ee593cbe..5e1b80eae39 100644 --- a/compiler/rustc_trait_selection/src/errors.rs +++ b/compiler/rustc_trait_selection/src/errors.rs @@ -1,4 +1,4 @@ -use rustc_errors::{fluent, IntoDiagnostic, ErrorGuaranteed, Handler}; +use rustc_errors::{fluent, ErrorGuaranteed, Handler, IntoDiagnostic}; use rustc_macros::Diagnostic; use rustc_middle::ty::{PolyTraitRef, Ty, Unevaluated}; use rustc_session::Limit; diff --git a/src/test/ui-fulldeps/internal-lints/diagnostics.rs b/src/test/ui-fulldeps/internal-lints/diagnostics.rs index 4c2c28dc336..18e39108eca 100644 --- a/src/test/ui-fulldeps/internal-lints/diagnostics.rs +++ b/src/test/ui-fulldeps/internal-lints/diagnostics.rs @@ -20,7 +20,7 @@ use rustc_span::Span; #[derive(Diagnostic)] #[diag(parser::expect_path)] -struct DeriveSessionDiagnostic { +struct DeriveDiagnostic { #[primary_span] span: Span, } @@ -32,18 +32,18 @@ struct Note { span: Span, } -pub struct UntranslatableInSessionDiagnostic; +pub struct UntranslatableInIntoDiagnostic; -impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic { +impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for UntranslatableInIntoDiagnostic { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { handler.struct_err("untranslatable diagnostic") //~^ ERROR diagnostics should be created using translatable messages } } -pub struct TranslatableInSessionDiagnostic; +pub struct TranslatableInIntoDiagnostic; -impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic { +impl<'a> IntoDiagnostic<'a, ErrorGuaranteed> for TranslatableInIntoDiagnostic { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { handler.struct_err(fluent::parser::expect_path) } diff --git a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index b07b35f2723..c3972beb512 100644 --- a/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -449,7 +449,7 @@ error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied --> $DIR/diagnostic-derive.rs:331:10 | LL | #[derive(Diagnostic)] - | ^^^^^^^^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` + | ^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` | = help: normalized in stderr note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg` -- cgit 1.4.1-3-g733a5 From fc43df0333d5862a219f16d294ae38b14b9191d3 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 20 Sep 2022 20:04:35 +0200 Subject: Revert "Auto merge of #101620 - cjgillot:compute_lint_levels_by_def, r=oli-obk" This reverts commit 2cb9a65684dba47c52de8fa938febf97a73e70a9, reversing changes made to 750bd1a7ff3e010611b97ee75d30b7cbf5f3a03c. --- compiler/rustc_errors/src/diagnostic.rs | 5 +- compiler/rustc_errors/src/lib.rs | 2 +- compiler/rustc_lint/src/context.rs | 2 +- compiler/rustc_lint/src/early.rs | 1 - compiler/rustc_lint/src/expect.rs | 4 +- compiler/rustc_lint/src/levels.rs | 680 +++++++++------------ compiler/rustc_lint/src/lib.rs | 1 - compiler/rustc_lint_defs/src/lib.rs | 31 +- compiler/rustc_middle/src/dep_graph/dep_node.rs | 38 +- compiler/rustc_middle/src/lint.rs | 222 ++++--- compiler/rustc_middle/src/query/mod.rs | 10 +- compiler/rustc_middle/src/ty/context.rs | 42 +- compiler/rustc_middle/src/ty/query.rs | 4 +- compiler/rustc_query_impl/src/keys.rs | 17 - compiler/rustc_query_system/src/dep_graph/mod.rs | 6 +- ...re-gate-non_exhaustive_omitted_patterns_lint.rs | 5 - ...ate-non_exhaustive_omitted_patterns_lint.stderr | 72 +-- .../force_warn_expected_lints_fulfilled.stderr | 16 +- 18 files changed, 488 insertions(+), 670 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index a52e95e92d5..1c440a0a07e 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -339,10 +339,9 @@ impl Diagnostic { // The lint index inside the attribute is manually transferred here. let lint_index = expectation_id.get_lint_index(); expectation_id.set_lint_index(None); - let mut stable_id = unstable_to_stable + let mut stable_id = *unstable_to_stable .get(&expectation_id) - .expect("each unstable `LintExpectationId` must have a matching stable id") - .normalize(); + .expect("each unstable `LintExpectationId` must have a matching stable id"); stable_id.set_lint_index(lint_index); *expectation_id = stable_id; diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 68971cebc35..b44cf352233 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -1205,7 +1205,7 @@ impl HandlerInner { if let Some(expectation_id) = diagnostic.level.get_expectation_id() { self.suppressed_expected_diag = true; - self.fulfilled_expectations.insert(expectation_id.normalize()); + self.fulfilled_expectations.insert(expectation_id); } if matches!(diagnostic.level, Warning(_)) diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 34506c84cb8..7ca6ec5d962 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -560,7 +560,7 @@ pub struct LateContext<'tcx> { /// Context for lint checking of the AST, after expansion, before lowering to HIR. pub struct EarlyContext<'a> { - pub builder: LintLevelsBuilder<'a, crate::levels::TopDown>, + pub builder: LintLevelsBuilder<'a>, pub buffered: LintBuffer, } diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index 45f54cfed2d..96ecd79a69c 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -59,7 +59,6 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> { F: FnOnce(&mut Self), { let is_crate_node = id == ast::CRATE_NODE_ID; - debug!(?id); let push = self.context.builder.push(attrs, is_crate_node, None); self.check_id(id); diff --git a/compiler/rustc_lint/src/expect.rs b/compiler/rustc_lint/src/expect.rs index b9a3d52ca9b..699e8154318 100644 --- a/compiler/rustc_lint/src/expect.rs +++ b/compiler/rustc_lint/src/expect.rs @@ -16,10 +16,8 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option) { return; } - let lint_expectations = tcx.lint_expectations(()); let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids(); - - tracing::debug!(?lint_expectations, ?fulfilled_expectations); + let lint_expectations = &tcx.lint_levels(()).lint_expectations; for (id, expectation) in lint_expectations { // This check will always be true, since `lint_expectations` only diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index a9ba2ad1d10..1e16ac51e9e 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -6,11 +6,10 @@ use rustc_data_structures::fx::FxHashMap; use rustc_errors::{Applicability, Diagnostic, LintDiagnosticBuilder, MultiSpan}; use rustc_hir as hir; use rustc_hir::{intravisit, HirId}; -use rustc_index::vec::IndexVec; use rustc_middle::hir::nested_filter; use rustc_middle::lint::{ - reveal_actual_level, struct_lint_level, LevelAndSource, LintExpectation, LintLevelSource, - ShallowLintLevelMap, + struct_lint_level, LevelAndSource, LintExpectation, LintLevelMap, LintLevelSets, + LintLevelSource, LintSet, LintStackIndex, COMMAND_LINE, }; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{RegisteredTools, TyCtxt}; @@ -28,292 +27,47 @@ use crate::errors::{ UnknownToolInScopedLint, }; -/// Collection of lint levels for the whole crate. -/// This is used by AST-based lints, which do not -/// wait until we have built HIR to be emitted. -#[derive(Debug)] -struct LintLevelSets { - /// Linked list of specifications. - list: IndexVec, -} - -rustc_index::newtype_index! { - struct LintStackIndex { - ENCODABLE = custom, // we don't need encoding - const COMMAND_LINE = 0, - } -} - -/// Specifications found at this position in the stack. This map only represents the lints -/// found for one set of attributes (like `shallow_lint_levels_on` does). -/// -/// We store the level specifications as a linked list. -/// Each `LintSet` represents a set of attributes on the same AST node. -/// The `parent` forms a linked list that matches the AST tree. -/// This way, walking the linked list is equivalent to walking the AST bottom-up -/// to find the specifications for a given lint. -#[derive(Debug)] -struct LintSet { - // -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which - // flag. - specs: FxHashMap, - parent: LintStackIndex, -} - -impl LintLevelSets { - fn new() -> Self { - LintLevelSets { list: IndexVec::new() } - } - - fn get_lint_level( - &self, - lint: &'static Lint, - idx: LintStackIndex, - aux: Option<&FxHashMap>, - sess: &Session, - ) -> LevelAndSource { - let lint = LintId::of(lint); - let (level, mut src) = self.raw_lint_id_level(lint, idx, aux); - let level = reveal_actual_level(level, &mut src, sess, lint, |id| { - self.raw_lint_id_level(id, idx, aux) - }); - (level, src) - } - - fn raw_lint_id_level( - &self, - id: LintId, - mut idx: LintStackIndex, - aux: Option<&FxHashMap>, - ) -> (Option, LintLevelSource) { - if let Some(specs) = aux { - if let Some(&(level, src)) = specs.get(&id) { - return (Some(level), src); - } - } - loop { - let LintSet { ref specs, parent } = self.list[idx]; - if let Some(&(level, src)) = specs.get(&id) { - return (Some(level), src); - } - if idx == COMMAND_LINE { - return (None, LintLevelSource::Default); - } - idx = parent; - } - } -} - -fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExpectation)> { +fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap { let store = unerased_lint_store(tcx); + let levels = + LintLevelsBuilder::new(tcx.sess, false, &store, &tcx.resolutions(()).registered_tools); + let mut builder = LintLevelMapBuilder { levels, tcx }; + let krate = tcx.hir().krate(); - let mut builder = LintLevelsBuilder { - sess: tcx.sess, - provider: QueryMapExpectationsWrapper { - tcx, - cur: hir::CRATE_HIR_ID, - specs: ShallowLintLevelMap::default(), - expectations: Vec::new(), - unstable_to_stable_ids: FxHashMap::default(), - }, - warn_about_weird_lints: false, - store, - registered_tools: &tcx.resolutions(()).registered_tools, - }; - - builder.add_command_line(); - builder.add_id(hir::CRATE_HIR_ID); - tcx.hir().walk_toplevel_module(&mut builder); - - tcx.sess.diagnostic().update_unstable_expectation_id(&builder.provider.unstable_to_stable_ids); + builder.levels.id_to_set.reserve(krate.owners.len() + 1); - builder.provider.expectations -} + let push = + builder.levels.push(tcx.hir().attrs(hir::CRATE_HIR_ID), true, Some(hir::CRATE_HIR_ID)); -fn shallow_lint_levels_on(tcx: TyCtxt<'_>, hir_id: HirId) -> ShallowLintLevelMap { - let store = unerased_lint_store(tcx); - - let mut levels = LintLevelsBuilder { - sess: tcx.sess, - provider: LintLevelQueryMap { tcx, cur: hir_id, specs: ShallowLintLevelMap::default() }, - warn_about_weird_lints: false, - store, - registered_tools: &tcx.resolutions(()).registered_tools, - }; - - let is_crate = hir::CRATE_HIR_ID == hir_id; - if is_crate { - levels.add_command_line(); - } - debug!(?hir_id); - levels.add(tcx.hir().attrs(hir_id), is_crate, Some(hir_id)); + builder.levels.register_id(hir::CRATE_HIR_ID); + tcx.hir().walk_toplevel_module(&mut builder); + builder.levels.pop(push); - levels.provider.specs + builder.levels.update_unstable_expectation_ids(); + builder.levels.build_map() } -pub struct TopDown { +pub struct LintLevelsBuilder<'s> { + sess: &'s Session, + lint_expectations: Vec<(LintExpectationId, LintExpectation)>, + /// Each expectation has a stable and an unstable identifier. This map + /// is used to map from unstable to stable [`LintExpectationId`]s. + expectation_id_map: FxHashMap, sets: LintLevelSets, + id_to_set: FxHashMap, cur: LintStackIndex, -} - -pub trait LintLevelsProvider { - fn current_specs(&self) -> &FxHashMap; - fn current_specs_mut(&mut self) -> &mut FxHashMap; - fn get_lint_level(&self, lint: &'static Lint, sess: &Session) -> LevelAndSource; - fn push_expectation(&mut self, _id: LintExpectationId, _expectation: LintExpectation) {} -} - -impl LintLevelsProvider for TopDown { - fn current_specs(&self) -> &FxHashMap { - &self.sets.list[self.cur].specs - } - - fn current_specs_mut(&mut self) -> &mut FxHashMap { - &mut self.sets.list[self.cur].specs - } - - fn get_lint_level(&self, lint: &'static Lint, sess: &Session) -> LevelAndSource { - self.sets.get_lint_level(lint, self.cur, Some(self.current_specs()), sess) - } -} - -struct LintLevelQueryMap<'tcx> { - tcx: TyCtxt<'tcx>, - cur: HirId, - specs: ShallowLintLevelMap, -} - -impl LintLevelsProvider for LintLevelQueryMap<'_> { - fn current_specs(&self) -> &FxHashMap { - &self.specs.specs - } - fn current_specs_mut(&mut self) -> &mut FxHashMap { - &mut self.specs.specs - } - fn get_lint_level(&self, lint: &'static Lint, _: &Session) -> LevelAndSource { - self.specs.lint_level_id_at_node(self.tcx, LintId::of(lint), self.cur) - } -} - -struct QueryMapExpectationsWrapper<'tcx> { - tcx: TyCtxt<'tcx>, - cur: HirId, - specs: ShallowLintLevelMap, - expectations: Vec<(LintExpectationId, LintExpectation)>, - unstable_to_stable_ids: FxHashMap, -} - -impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> { - fn current_specs(&self) -> &FxHashMap { - &self.specs.specs - } - fn current_specs_mut(&mut self) -> &mut FxHashMap { - self.specs.specs.clear(); - &mut self.specs.specs - } - fn get_lint_level(&self, lint: &'static Lint, _: &Session) -> LevelAndSource { - self.specs.lint_level_id_at_node(self.tcx, LintId::of(lint), self.cur) - } - fn push_expectation(&mut self, id: LintExpectationId, expectation: LintExpectation) { - let LintExpectationId::Stable { attr_id: Some(attr_id), hir_id, attr_index, .. } = id else { bug!("unstable expectation id should already be mapped") }; - let key = LintExpectationId::Unstable { attr_id, lint_index: None }; - - if !self.unstable_to_stable_ids.contains_key(&key) { - self.unstable_to_stable_ids.insert( - key, - LintExpectationId::Stable { hir_id, attr_index, lint_index: None, attr_id: None }, - ); - } - - self.expectations.push((id.normalize(), expectation)); - } -} - -impl<'tcx> LintLevelsBuilder<'_, QueryMapExpectationsWrapper<'tcx>> { - fn add_id(&mut self, hir_id: HirId) { - self.add(self.provider.tcx.hir().attrs(hir_id), hir_id == hir::CRATE_HIR_ID, Some(hir_id)); - } -} - -impl<'tcx> intravisit::Visitor<'tcx> for LintLevelsBuilder<'_, QueryMapExpectationsWrapper<'tcx>> { - type NestedFilter = nested_filter::All; - - fn nested_visit_map(&mut self) -> Self::Map { - self.provider.tcx.hir() - } - - fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) { - self.add_id(param.hir_id); - intravisit::walk_param(self, param); - } - - fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) { - self.add_id(it.hir_id()); - intravisit::walk_item(self, it); - } - - fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) { - self.add_id(it.hir_id()); - intravisit::walk_foreign_item(self, it); - } - - fn visit_stmt(&mut self, e: &'tcx hir::Stmt<'tcx>) { - // We will call `add_id` when we walk - // the `StmtKind`. The outer statement itself doesn't - // define the lint levels. - intravisit::walk_stmt(self, e); - } - - fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) { - self.add_id(e.hir_id); - intravisit::walk_expr(self, e); - } - - fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) { - self.add_id(s.hir_id); - intravisit::walk_field_def(self, s); - } - - fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) { - self.add_id(v.id); - intravisit::walk_variant(self, v); - } - - fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) { - self.add_id(l.hir_id); - intravisit::walk_local(self, l); - } - - fn visit_arm(&mut self, a: &'tcx hir::Arm<'tcx>) { - self.add_id(a.hir_id); - intravisit::walk_arm(self, a); - } - - fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { - self.add_id(trait_item.hir_id()); - intravisit::walk_trait_item(self, trait_item); - } - - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { - self.add_id(impl_item.hir_id()); - intravisit::walk_impl_item(self, impl_item); - } -} - -pub struct LintLevelsBuilder<'s, P> { - sess: &'s Session, - provider: P, warn_about_weird_lints: bool, store: &'s LintStore, registered_tools: &'s RegisteredTools, } -pub(crate) struct BuilderPush { +pub struct BuilderPush { prev: LintStackIndex, + pub changed: bool, } -impl<'s> LintLevelsBuilder<'s, TopDown> { - pub(crate) fn new( +impl<'s> LintLevelsBuilder<'s> { + pub fn new( sess: &'s Session, warn_about_weird_lints: bool, store: &'s LintStore, @@ -321,66 +75,20 @@ impl<'s> LintLevelsBuilder<'s, TopDown> { ) -> Self { let mut builder = LintLevelsBuilder { sess, - provider: TopDown { sets: LintLevelSets::new(), cur: COMMAND_LINE }, + lint_expectations: Default::default(), + expectation_id_map: Default::default(), + sets: LintLevelSets::new(), + cur: COMMAND_LINE, + id_to_set: Default::default(), warn_about_weird_lints, store, registered_tools, }; - builder.process_command_line(); - assert_eq!(builder.provider.sets.list.len(), 1); + builder.process_command_line(sess, store); + assert_eq!(builder.sets.list.len(), 1); builder } - fn process_command_line(&mut self) { - self.provider.cur = self - .provider - .sets - .list - .push(LintSet { specs: FxHashMap::default(), parent: COMMAND_LINE }); - self.add_command_line(); - } - - /// Pushes a list of AST lint attributes onto this context. - /// - /// This function will return a `BuilderPush` object which should be passed - /// to `pop` when this scope for the attributes provided is exited. - /// - /// This function will perform a number of tasks: - /// - /// * It'll validate all lint-related attributes in `attrs` - /// * It'll mark all lint-related attributes as used - /// * Lint levels will be updated based on the attributes provided - /// * Lint attributes are validated, e.g., a `#[forbid]` can't be switched to - /// `#[allow]` - /// - /// Don't forget to call `pop`! - pub(crate) fn push( - &mut self, - attrs: &[ast::Attribute], - is_crate_node: bool, - source_hir_id: Option, - ) -> BuilderPush { - let prev = self.provider.cur; - self.provider.cur = - self.provider.sets.list.push(LintSet { specs: FxHashMap::default(), parent: prev }); - - self.add(attrs, is_crate_node, source_hir_id); - - if self.provider.current_specs().is_empty() { - self.provider.sets.list.pop(); - self.provider.cur = prev; - } - - BuilderPush { prev } - } - - /// Called after `push` when the scope of a set of attributes are exited. - pub(crate) fn pop(&mut self, push: BuilderPush) { - self.provider.cur = push.prev; - } -} - -impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { pub(crate) fn sess(&self) -> &Session { self.sess } @@ -390,20 +98,24 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { } fn current_specs(&self) -> &FxHashMap { - self.provider.current_specs() + &self.sets.list[self.cur].specs } fn current_specs_mut(&mut self) -> &mut FxHashMap { - self.provider.current_specs_mut() + &mut self.sets.list[self.cur].specs } - fn add_command_line(&mut self) { - for &(ref lint_name, level) in &self.sess.opts.lint_opts { - self.store.check_lint_name_cmdline(self.sess, &lint_name, level, self.registered_tools); + fn process_command_line(&mut self, sess: &Session, store: &LintStore) { + self.sets.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid); + + self.cur = + self.sets.list.push(LintSet { specs: FxHashMap::default(), parent: COMMAND_LINE }); + for &(ref lint_name, level) in &sess.opts.lint_opts { + store.check_lint_name_cmdline(sess, &lint_name, level, self.registered_tools); let orig_level = level; let lint_flag_val = Symbol::intern(lint_name); - let Ok(ids) = self.store.find_lints(&lint_name) else { + let Ok(ids) = store.find_lints(&lint_name) else { // errors handled in check_lint_name_cmdline above continue }; @@ -426,11 +138,9 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { /// Attempts to insert the `id` to `level_src` map entry. If unsuccessful /// (e.g. if a forbid was already inserted on the same scope), then emits a /// diagnostic with no change to `specs`. - fn insert_spec(&mut self, id: LintId, (mut level, src): LevelAndSource) { - let (old_level, old_src) = self.provider.get_lint_level(id.lint, &self.sess); - if let Level::Expect(id) = &mut level && let LintExpectationId::Stable { .. } = id { - *id = id.normalize(); - } + fn insert_spec(&mut self, id: LintId, (level, src): LevelAndSource) { + let (old_level, old_src) = + self.sets.get_lint_level(id.lint, self.cur, Some(self.current_specs()), &self.sess); // Setting to a non-forbid level is an error if the lint previously had // a forbid level. Note that this is not necessarily true even with a // `#[forbid(..)]` attribute present, as that is overridden by `--cap-lints`. @@ -448,7 +158,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { let id_name = id.lint.name_lower(); let fcw_warning = match old_src { LintLevelSource::Default => false, - LintLevelSource::Node { name, .. } => self.store.is_lint_group(name), + LintLevelSource::Node(symbol, _, _) => self.store.is_lint_group(symbol), LintLevelSource::CommandLine(symbol, _) => self.store.is_lint_group(symbol), }; debug!( @@ -468,8 +178,8 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { id.to_string() )); } - LintLevelSource::Node { span, reason, .. } => { - diag.span_label(span, "`forbid` level set here"); + LintLevelSource::Node(_, forbid_source_span, reason) => { + diag.span_label(forbid_source_span, "`forbid` level set here"); if let Some(rationale) = reason { diag.note(rationale.as_str()); } @@ -489,8 +199,11 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { LintLevelSource::Default => { OverruledAttributeSub::DefaultSource { id: id.to_string() } } - LintLevelSource::Node { span, reason, .. } => { - OverruledAttributeSub::NodeSource { span, reason } + LintLevelSource::Node(_, forbid_source_span, reason) => { + OverruledAttributeSub::NodeSource { + span: forbid_source_span, + reason, + } } LintLevelSource::CommandLine(_, _) => { OverruledAttributeSub::CommandLineSource @@ -543,7 +256,29 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { }; } - fn add(&mut self, attrs: &[ast::Attribute], is_crate_node: bool, source_hir_id: Option) { + /// Pushes a list of AST lint attributes onto this context. + /// + /// This function will return a `BuilderPush` object which should be passed + /// to `pop` when this scope for the attributes provided is exited. + /// + /// This function will perform a number of tasks: + /// + /// * It'll validate all lint-related attributes in `attrs` + /// * It'll mark all lint-related attributes as used + /// * Lint levels will be updated based on the attributes provided + /// * Lint attributes are validated, e.g., a `#[forbid]` can't be switched to + /// `#[allow]` + /// + /// Don't forget to call `pop`! + pub(crate) fn push( + &mut self, + attrs: &[ast::Attribute], + is_crate_node: bool, + source_hir_id: Option, + ) -> BuilderPush { + let prev = self.cur; + self.cur = self.sets.list.push(LintSet { specs: FxHashMap::default(), parent: prev }); + let sess = self.sess; for (attr_index, attr) in attrs.iter().enumerate() { if attr.has_name(sym::automatically_derived) { @@ -558,17 +293,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { None => continue, // This is the only lint level with a `LintExpectationId` that can be created from an attribute Some(Level::Expect(unstable_id)) if let Some(hir_id) = source_hir_id => { - let LintExpectationId::Unstable { attr_id, lint_index } = unstable_id - else { bug!("stable id Level::from_attr") }; - - let stable_id = LintExpectationId::Stable { - hir_id, - attr_index: attr_index.try_into().unwrap(), - lint_index, - // we pass the previous unstable attr_id such that we can trace the ast id when building a map - // to go from unstable to stable id. - attr_id: Some(attr_id), - }; + let stable_id = self.create_stable_id(unstable_id, hir_id, attr_index); Level::Expect(stable_id) } @@ -683,7 +408,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { [lint] => *lint == LintId::of(UNFULFILLED_LINT_EXPECTATIONS), _ => false, }; - self.provider.push_expectation( + self.lint_expectations.push(( expect_id, LintExpectation::new( reason, @@ -691,19 +416,13 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { is_unfulfilled_lint_expectations, tool_name, ), - ); + )); } - let src = LintLevelSource::Node { - name: meta_item - .path - .segments - .last() - .expect("empty lint name") - .ident - .name, - span: sp, + let src = LintLevelSource::Node( + meta_item.path.segments.last().expect("empty lint name").ident.name, + sp, reason, - }; + ); for &id in *ids { if self.check_gated_lint(id, attr.span) { self.insert_spec(id, (level, src)); @@ -716,26 +435,31 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { Ok(ids) => { let complete_name = &format!("{}::{}", tool_ident.unwrap().name, name); - let src = LintLevelSource::Node { - name: Symbol::intern(complete_name), - span: sp, + let src = LintLevelSource::Node( + Symbol::intern(complete_name), + sp, reason, - }; + ); for &id in ids { if self.check_gated_lint(id, attr.span) { self.insert_spec(id, (level, src)); } } if let Level::Expect(expect_id) = level { - self.provider.push_expectation( + self.lint_expectations.push(( expect_id, LintExpectation::new(reason, sp, false, tool_name), - ); + )); } } Err((Some(ids), ref new_lint_name)) => { let lint = builtin::RENAMED_AND_REMOVED_LINTS; - let (lvl, src) = self.provider.get_lint_level(lint, &sess); + let (lvl, src) = self.sets.get_lint_level( + lint, + self.cur, + Some(self.current_specs()), + &sess, + ); struct_lint_level( self.sess, lint, @@ -759,19 +483,19 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { }, ); - let src = LintLevelSource::Node { - name: Symbol::intern(&new_lint_name), - span: sp, + let src = LintLevelSource::Node( + Symbol::intern(&new_lint_name), + sp, reason, - }; + ); for id in ids { self.insert_spec(*id, (level, src)); } if let Level::Expect(expect_id) = level { - self.provider.push_expectation( + self.lint_expectations.push(( expect_id, LintExpectation::new(reason, sp, false, tool_name), - ); + )); } } Err((None, _)) => { @@ -797,7 +521,12 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { CheckLintNameResult::Warning(msg, renamed) => { let lint = builtin::RENAMED_AND_REMOVED_LINTS; - let (renamed_lint_level, src) = self.provider.get_lint_level(lint, &sess); + let (renamed_lint_level, src) = self.sets.get_lint_level( + lint, + self.cur, + Some(self.current_specs()), + &sess, + ); struct_lint_level( self.sess, lint, @@ -820,7 +549,12 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { } CheckLintNameResult::NoLint(suggestion) => { let lint = builtin::UNKNOWN_LINTS; - let (level, src) = self.provider.get_lint_level(lint, self.sess); + let (level, src) = self.sets.get_lint_level( + lint, + self.cur, + Some(self.current_specs()), + self.sess, + ); struct_lint_level(self.sess, lint, level, src, Some(sp.into()), |lint| { let name = if let Some(tool_ident) = tool_ident { format!("{}::{}", tool_ident.name, name) @@ -849,21 +583,17 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { if let CheckLintNameResult::Ok(ids) = self.store.check_lint_name(&new_name, None, self.registered_tools) { - let src = LintLevelSource::Node { - name: Symbol::intern(&new_name), - span: sp, - reason, - }; + let src = LintLevelSource::Node(Symbol::intern(&new_name), sp, reason); for &id in ids { if self.check_gated_lint(id, attr.span) { self.insert_spec(id, (level, src)); } } if let Level::Expect(expect_id) = level { - self.provider.push_expectation( + self.lint_expectations.push(( expect_id, LintExpectation::new(reason, sp, false, tool_name), - ); + )); } } else { panic!("renamed lint does not exist: {}", new_name); @@ -878,12 +608,13 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { continue; } - let LintLevelSource::Node { name: lint_attr_name, span: lint_attr_span, .. } = *src else { + let LintLevelSource::Node(lint_attr_name, lint_attr_span, _) = *src else { continue }; let lint = builtin::UNUSED_ATTRIBUTES; - let (lint_level, lint_src) = self.provider.get_lint_level(lint, &self.sess); + let (lint_level, lint_src) = + self.sets.get_lint_level(lint, self.cur, Some(self.current_specs()), self.sess); struct_lint_level( self.sess, lint, @@ -903,13 +634,32 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { break; } } + + if self.current_specs().is_empty() { + self.sets.list.pop(); + self.cur = prev; + } + + BuilderPush { prev, changed: prev != self.cur } + } + + fn create_stable_id( + &mut self, + unstable_id: LintExpectationId, + hir_id: HirId, + attr_index: usize, + ) -> LintExpectationId { + let stable_id = + LintExpectationId::Stable { hir_id, attr_index: attr_index as u16, lint_index: None }; + + self.expectation_id_map.insert(unstable_id, stable_id); + + stable_id } /// Checks if the lint is gated on a feature that is not enabled. /// /// Returns `true` if the lint's feature is enabled. - // FIXME only emit this once for each attribute, instead of repeating it 4 times for - // pre-expansion lints, post-expansion lints, `shallow_lint_levels_on` and `lint_expectations`. fn check_gated_lint(&self, lint_id: LintId, span: Span) -> bool { if let Some(feature) = lint_id.lint.feature_gate { if !self.sess.features_untracked().enabled(feature) { @@ -928,14 +678,19 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { true } + /// Called after `push` when the scope of a set of attributes are exited. + pub fn pop(&mut self, push: BuilderPush) { + self.cur = push.prev; + } + /// Find the lint level for a lint. - pub fn lint_level(&self, lint: &'static Lint) -> LevelAndSource { - self.provider.get_lint_level(lint, self.sess) + pub fn lint_level(&self, lint: &'static Lint) -> (Level, LintLevelSource) { + self.sets.get_lint_level(lint, self.cur, None, self.sess) } /// Used to emit a lint-related diagnostic based on the current state of /// this lint context. - pub(crate) fn struct_lint( + pub fn struct_lint( &self, lint: &'static Lint, span: Option, @@ -944,8 +699,141 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { let (level, src) = self.lint_level(lint); struct_lint_level(self.sess, lint, level, src, span, decorate) } + + /// Registers the ID provided with the current set of lints stored in + /// this context. + pub fn register_id(&mut self, id: HirId) { + self.id_to_set.insert(id, self.cur); + } + + fn update_unstable_expectation_ids(&self) { + self.sess.diagnostic().update_unstable_expectation_id(&self.expectation_id_map); + } + + pub fn build_map(self) -> LintLevelMap { + LintLevelMap { + sets: self.sets, + id_to_set: self.id_to_set, + lint_expectations: self.lint_expectations, + } + } +} + +struct LintLevelMapBuilder<'tcx> { + levels: LintLevelsBuilder<'tcx>, + tcx: TyCtxt<'tcx>, +} + +impl LintLevelMapBuilder<'_> { + fn with_lint_attrs(&mut self, id: hir::HirId, f: F) + where + F: FnOnce(&mut Self), + { + let is_crate_hir = id == hir::CRATE_HIR_ID; + let attrs = self.tcx.hir().attrs(id); + let push = self.levels.push(attrs, is_crate_hir, Some(id)); + + if push.changed { + self.levels.register_id(id); + } + f(self); + self.levels.pop(push); + } +} + +impl<'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'tcx> { + type NestedFilter = nested_filter::All; + + fn nested_visit_map(&mut self) -> Self::Map { + self.tcx.hir() + } + + fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) { + self.with_lint_attrs(param.hir_id, |builder| { + intravisit::walk_param(builder, param); + }); + } + + fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) { + self.with_lint_attrs(it.hir_id(), |builder| { + intravisit::walk_item(builder, it); + }); + } + + fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) { + self.with_lint_attrs(it.hir_id(), |builder| { + intravisit::walk_foreign_item(builder, it); + }) + } + + fn visit_stmt(&mut self, e: &'tcx hir::Stmt<'tcx>) { + // We will call `with_lint_attrs` when we walk + // the `StmtKind`. The outer statement itself doesn't + // define the lint levels. + intravisit::walk_stmt(self, e); + } + + fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) { + self.with_lint_attrs(e.hir_id, |builder| { + intravisit::walk_expr(builder, e); + }) + } + + fn visit_expr_field(&mut self, field: &'tcx hir::ExprField<'tcx>) { + self.with_lint_attrs(field.hir_id, |builder| { + intravisit::walk_expr_field(builder, field); + }) + } + + fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) { + self.with_lint_attrs(s.hir_id, |builder| { + intravisit::walk_field_def(builder, s); + }) + } + + fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) { + self.with_lint_attrs(v.id, |builder| { + intravisit::walk_variant(builder, v); + }) + } + + fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) { + self.with_lint_attrs(l.hir_id, |builder| { + intravisit::walk_local(builder, l); + }) + } + + fn visit_arm(&mut self, a: &'tcx hir::Arm<'tcx>) { + self.with_lint_attrs(a.hir_id, |builder| { + intravisit::walk_arm(builder, a); + }) + } + + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { + self.with_lint_attrs(trait_item.hir_id(), |builder| { + intravisit::walk_trait_item(builder, trait_item); + }); + } + + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { + self.with_lint_attrs(impl_item.hir_id(), |builder| { + intravisit::walk_impl_item(builder, impl_item); + }); + } + + fn visit_pat_field(&mut self, field: &'tcx hir::PatField<'tcx>) { + self.with_lint_attrs(field.hir_id, |builder| { + intravisit::walk_pat_field(builder, field); + }) + } + + fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) { + self.with_lint_attrs(p.hir_id, |builder| { + intravisit::walk_generic_param(builder, p); + }); + } } -pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { shallow_lint_levels_on, lint_expectations, ..*providers }; +pub fn provide(providers: &mut Providers) { + providers.lint_levels = lint_levels; } diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index c760e435699..752a751f6bc 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -35,7 +35,6 @@ #![feature(iter_order_by)] #![feature(let_chains)] #![cfg_attr(bootstrap, feature(let_else))] -#![feature(min_specialization)] #![feature(never_type)] #![recursion_limit = "256"] diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index cbe7afc8e55..11b2d057a07 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -92,7 +92,7 @@ pub enum LintExpectationId { /// stable and can be cached. The additional index ensures that nodes with /// several expectations can correctly match diagnostics to the individual /// expectation. - Stable { hir_id: HirId, attr_index: u16, lint_index: Option, attr_id: Option }, + Stable { hir_id: HirId, attr_index: u16, lint_index: Option }, } impl LintExpectationId { @@ -116,31 +116,13 @@ impl LintExpectationId { *lint_index = new_lint_index } - - /// Prepares the id for hashing. Removes references to the ast. - /// Should only be called when the id is stable. - pub fn normalize(self) -> Self { - match self { - Self::Stable { hir_id, attr_index, lint_index, .. } => { - Self::Stable { hir_id, attr_index, lint_index, attr_id: None } - } - Self::Unstable { .. } => { - unreachable!("`normalize` called when `ExpectationId` is unstable") - } - } - } } impl HashStable for LintExpectationId { #[inline] fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { match self { - LintExpectationId::Stable { - hir_id, - attr_index, - lint_index: Some(lint_index), - attr_id: _, - } => { + LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => { hir_id.hash_stable(hcx, hasher); attr_index.hash_stable(hcx, hasher); lint_index.hash_stable(hcx, hasher); @@ -160,12 +142,9 @@ impl ToStableHashKey for LintExpectation #[inline] fn to_stable_hash_key(&self, _: &HCX) -> Self::KeyType { match self { - LintExpectationId::Stable { - hir_id, - attr_index, - lint_index: Some(lint_index), - attr_id: _, - } => (*hir_id, *attr_index, *lint_index), + LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => { + (*hir_id, *attr_index, *lint_index) + } _ => { unreachable!("HashStable should only be called for a filled `LintExpectationId`") } diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index eded3b3eedc..1fa0c6babab 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -62,7 +62,7 @@ use crate::ty::TyCtxt; use rustc_data_structures::fingerprint::Fingerprint; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId}; use rustc_hir::definitions::DefPathHash; -use rustc_hir::{HirId, ItemLocalId}; +use rustc_hir::HirId; use rustc_query_system::dep_graph::FingerprintStyle; use rustc_span::symbol::Symbol; use std::hash::Hash; @@ -280,7 +280,7 @@ impl DepNodeExt for DepNode { let kind = dep_kind_from_label_string(label)?; match kind.fingerprint_style(tcx) { - FingerprintStyle::Opaque | FingerprintStyle::HirId => Err(()), + FingerprintStyle::Opaque => Err(()), FingerprintStyle::Unit => Ok(DepNode::new_no_params(tcx, kind)), FingerprintStyle::DefPathHash => { Ok(DepNode::from_def_path_hash(tcx, def_path_hash, kind)) @@ -408,7 +408,7 @@ impl<'tcx> DepNodeParams> for (DefId, DefId) { impl<'tcx> DepNodeParams> for HirId { #[inline(always)] fn fingerprint_style() -> FingerprintStyle { - FingerprintStyle::HirId + FingerprintStyle::Opaque } // We actually would not need to specialize the implementation of this @@ -417,36 +417,10 @@ impl<'tcx> DepNodeParams> for HirId { #[inline(always)] fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint { let HirId { owner, local_id } = *self; - let def_path_hash = tcx.def_path_hash(owner.to_def_id()); - Fingerprint::new( - // `owner` is local, so is completely defined by the local hash - def_path_hash.local_hash(), - local_id.as_u32().into(), - ) - } - #[inline(always)] - fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String { - let HirId { owner, local_id } = *self; - format!("{}.{}", tcx.def_path_str(owner.to_def_id()), local_id.as_u32()) - } + let def_path_hash = tcx.def_path_hash(owner.to_def_id()); + let local_id = Fingerprint::from_smaller_hash(local_id.as_u32().into()); - #[inline(always)] - fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option { - if dep_node.kind.fingerprint_style(tcx) == FingerprintStyle::HirId { - let (local_hash, local_id) = Fingerprint::from(dep_node.hash).as_value(); - let def_path_hash = DefPathHash::new(tcx.sess.local_stable_crate_id(), local_hash); - let owner = tcx - .def_path_hash_to_def_id(def_path_hash, &mut || { - panic!("Failed to extract HirId: {:?} {}", dep_node.kind, dep_node.hash) - }) - .expect_local(); - let local_id = local_id - .try_into() - .unwrap_or_else(|_| panic!("local id should be u32, found {:?}", local_id)); - Some(HirId { owner, local_id: ItemLocalId::from_u32(local_id) }) - } else { - None - } + def_path_hash.0.combine(local_id) } } diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index 4cb5ef79177..2f45222de47 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -1,19 +1,20 @@ use std::cmp; use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_errors::{Diagnostic, DiagnosticId, LintDiagnosticBuilder, MultiSpan}; use rustc_hir::HirId; +use rustc_index::vec::IndexVec; +use rustc_query_system::ich::StableHashingContext; use rustc_session::lint::{ builtin::{self, FORBIDDEN_LINT_GROUPS}, - FutureIncompatibilityReason, Level, Lint, LintId, + FutureIncompatibilityReason, Level, Lint, LintExpectationId, LintId, }; use rustc_session::Session; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::{DesugaringKind, ExpnKind}; use rustc_span::{symbol, Span, Symbol, DUMMY_SP}; -use crate::ty::TyCtxt; - /// How a lint level was set. #[derive(Clone, Copy, PartialEq, Eq, HashStable, Debug)] pub enum LintLevelSource { @@ -22,12 +23,7 @@ pub enum LintLevelSource { Default, /// Lint level was set by an attribute. - Node { - name: Symbol, - span: Span, - /// RFC 2383 reason - reason: Option, - }, + Node(Symbol, Span, Option /* RFC 2383 reason */), /// Lint level was set by a command-line flag. /// The provided `Level` is the level specified on the command line. @@ -39,7 +35,7 @@ impl LintLevelSource { pub fn name(&self) -> Symbol { match *self { LintLevelSource::Default => symbol::kw::Default, - LintLevelSource::Node { name, .. } => name, + LintLevelSource::Node(name, _, _) => name, LintLevelSource::CommandLine(name, _) => name, } } @@ -47,7 +43,7 @@ impl LintLevelSource { pub fn span(&self) -> Span { match *self { LintLevelSource::Default => DUMMY_SP, - LintLevelSource::Node { span, .. } => span, + LintLevelSource::Node(_, span, _) => span, LintLevelSource::CommandLine(_, _) => DUMMY_SP, } } @@ -56,115 +52,145 @@ impl LintLevelSource { /// A tuple of a lint level and its source. pub type LevelAndSource = (Level, LintLevelSource); -/// Return type for the `shallow_lint_levels_on` query. -/// -/// This map represents the set of allowed lints and allowance levels given -/// by the attributes for *a single HirId*. -#[derive(Default, Debug, HashStable)] -pub struct ShallowLintLevelMap { +#[derive(Debug, HashStable)] +pub struct LintLevelSets { + pub list: IndexVec, + pub lint_cap: Level, +} + +rustc_index::newtype_index! { + #[derive(HashStable)] + pub struct LintStackIndex { + const COMMAND_LINE = 0, + } +} + +#[derive(Debug, HashStable)] +pub struct LintSet { + // -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which + // flag. pub specs: FxHashMap, + + pub parent: LintStackIndex, } -/// From an initial level and source, verify the effect of special annotations: -/// `warnings` lint level and lint caps. -/// -/// The return of this function is suitable for diagnostics. -pub fn reveal_actual_level( - level: Option, - src: &mut LintLevelSource, - sess: &Session, - lint: LintId, - probe_for_lint_level: impl FnOnce(LintId) -> (Option, LintLevelSource), -) -> Level { - // If `level` is none then we actually assume the default level for this lint. - let mut level = level.unwrap_or_else(|| lint.lint.default_level(sess.edition())); - - // If we're about to issue a warning, check at the last minute for any - // directives against the warnings "lint". If, for example, there's an - // `allow(warnings)` in scope then we want to respect that instead. - // - // We exempt `FORBIDDEN_LINT_GROUPS` from this because it specifically - // triggers in cases (like #80988) where you have `forbid(warnings)`, - // and so if we turned that into an error, it'd defeat the purpose of the - // future compatibility warning. - if level == Level::Warn && lint != LintId::of(FORBIDDEN_LINT_GROUPS) { - let (warnings_level, warnings_src) = probe_for_lint_level(LintId::of(builtin::WARNINGS)); - if let Some(configured_warning_level) = warnings_level { - if configured_warning_level != Level::Warn { - level = configured_warning_level; - *src = warnings_src; +impl LintLevelSets { + pub fn new() -> Self { + LintLevelSets { list: IndexVec::new(), lint_cap: Level::Forbid } + } + + pub fn get_lint_level( + &self, + lint: &'static Lint, + idx: LintStackIndex, + aux: Option<&FxHashMap>, + sess: &Session, + ) -> LevelAndSource { + let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux); + + // If `level` is none then we actually assume the default level for this + // lint. + let mut level = level.unwrap_or_else(|| lint.default_level(sess.edition())); + + // If we're about to issue a warning, check at the last minute for any + // directives against the warnings "lint". If, for example, there's an + // `allow(warnings)` in scope then we want to respect that instead. + // + // We exempt `FORBIDDEN_LINT_GROUPS` from this because it specifically + // triggers in cases (like #80988) where you have `forbid(warnings)`, + // and so if we turned that into an error, it'd defeat the purpose of the + // future compatibility warning. + if level == Level::Warn && LintId::of(lint) != LintId::of(FORBIDDEN_LINT_GROUPS) { + let (warnings_level, warnings_src) = + self.get_lint_id_level(LintId::of(builtin::WARNINGS), idx, aux); + if let Some(configured_warning_level) = warnings_level { + if configured_warning_level != Level::Warn { + level = configured_warning_level; + src = warnings_src; + } } } - } - // Ensure that we never exceed the `--cap-lints` argument unless the source is a --force-warn - level = if let LintLevelSource::CommandLine(_, Level::ForceWarn(_)) = src { - level - } else { - cmp::min(level, sess.opts.lint_cap.unwrap_or(Level::Forbid)) - }; + // Ensure that we never exceed the `--cap-lints` argument + // unless the source is a --force-warn + level = if let LintLevelSource::CommandLine(_, Level::ForceWarn(_)) = src { + level + } else { + cmp::min(level, self.lint_cap) + }; + + if let Some(driver_level) = sess.driver_lint_caps.get(&LintId::of(lint)) { + // Ensure that we never exceed driver level. + level = cmp::min(*driver_level, level); + } - if let Some(driver_level) = sess.driver_lint_caps.get(&lint) { - // Ensure that we never exceed driver level. - level = cmp::min(*driver_level, level); + (level, src) } - level -} - -impl ShallowLintLevelMap { - /// Perform a deep probe in the HIR tree looking for the actual level for the lint. - /// This lint level is not usable for diagnostics, it needs to be corrected by - /// `reveal_actual_level` beforehand. - fn probe_for_lint_level( + pub fn get_lint_id_level( &self, - tcx: TyCtxt<'_>, id: LintId, - start: HirId, + mut idx: LintStackIndex, + aux: Option<&FxHashMap>, ) -> (Option, LintLevelSource) { - if let Some(&(level, src)) = self.specs.get(&id) { - return (Some(level), src); + if let Some(specs) = aux { + if let Some(&(level, src)) = specs.get(&id) { + return (Some(level), src); + } } - - for (parent, _) in tcx.hir().parent_iter(start) { - let specs = tcx.shallow_lint_levels_on(parent); - if let Some(&(level, src)) = specs.specs.get(&id) { + loop { + let LintSet { ref specs, parent } = self.list[idx]; + if let Some(&(level, src)) = specs.get(&id) { return (Some(level), src); } + if idx == COMMAND_LINE { + return (None, LintLevelSource::Default); + } + idx = parent; } - (None, LintLevelSource::Default) } +} + +#[derive(Debug)] +pub struct LintLevelMap { + /// This is a collection of lint expectations as described in RFC 2383, that + /// can be fulfilled during this compilation session. This means that at least + /// one expected lint is currently registered in the lint store. + /// + /// The [`LintExpectationId`] is stored as a part of the [`Expect`](Level::Expect) + /// lint level. + pub lint_expectations: Vec<(LintExpectationId, LintExpectation)>, + pub sets: LintLevelSets, + pub id_to_set: FxHashMap, +} - /// Fetch and return the user-visible lint level for the given lint at the given HirId. - pub fn lint_level_id_at_node( +impl LintLevelMap { + /// If the `id` was previously registered with `register_id` when building + /// this `LintLevelMap` this returns the corresponding lint level and source + /// of the lint level for the lint provided. + /// + /// If the `id` was not previously registered, returns `None`. If `None` is + /// returned then the parent of `id` should be acquired and this function + /// should be called again. + pub fn level_and_source( &self, - tcx: TyCtxt<'_>, - lint: LintId, + lint: &'static Lint, id: HirId, - ) -> (Level, LintLevelSource) { - let (level, mut src) = self.probe_for_lint_level(tcx, lint, id); - let level = reveal_actual_level(level, &mut src, tcx.sess, lint, |lint| { - self.probe_for_lint_level(tcx, lint, id) - }); - debug!(?id, ?level, ?src); - (level, src) + session: &Session, + ) -> Option { + self.id_to_set.get(&id).map(|idx| self.sets.get_lint_level(lint, *idx, None, session)) } } -impl TyCtxt<'_> { - /// Fetch and return the user-visible lint level for the given lint at the given HirId. - pub fn lint_level_at_node(self, lint: &'static Lint, id: HirId) -> (Level, LintLevelSource) { - self.shallow_lint_levels_on(id).lint_level_id_at_node(self, LintId::of(lint), id) - } +impl<'a> HashStable> for LintLevelMap { + #[inline] + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + let LintLevelMap { ref sets, ref id_to_set, ref lint_expectations } = *self; - /// Walks upwards from `id` to find a node which might change lint levels with attributes. - /// It stops at `bound` and just returns it if reached. - pub fn maybe_lint_level_root_bounded(self, mut id: HirId, bound: HirId) -> HirId { - let hir = self.hir(); - while id != bound && self.shallow_lint_levels_on(id).specs.is_empty() { - id = hir.get_parent_node(id) - } - id + id_to_set.hash_stable(hcx, hasher); + lint_expectations.hash_stable(hcx, hasher); + + hcx.while_hashing_spans(true, |hcx| sets.hash_stable(hcx, hasher)) } } @@ -235,11 +261,11 @@ pub fn explain_lint_level_source( )); } } - LintLevelSource::Node { name: lint_attr_name, span, reason, .. } => { + LintLevelSource::Node(lint_attr_name, src, reason) => { if let Some(rationale) = reason { err.note(rationale.as_str()); } - err.span_note_once(span, "the lint level is defined here"); + err.span_note_once(src, "the lint level is defined here"); if lint_attr_name.as_str() != name { let level_str = level.as_str(); err.note_once(&format!( diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 1afea4864b8..7ea8c9ed3d3 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -274,14 +274,10 @@ rustc_queries! { separate_provide_extern } - query shallow_lint_levels_on(key: HirId) -> rustc_middle::lint::ShallowLintLevelMap { + query lint_levels(_: ()) -> LintLevelMap { arena_cache - desc { |tcx| "looking up lint levels for `{}`", key } - } - - query lint_expectations(_: ()) -> Vec<(LintExpectationId, LintExpectation)> { - arena_cache - desc { "computing `#[expect]`ed lints in this crate" } + eval_always + desc { "computing the lint levels for items in this crate" } } query parent_module_from_def_id(key: LocalDefId) -> LocalDefId { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 2b5b4017a5a..8c44f4a98df 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -4,7 +4,7 @@ use crate::arena::Arena; use crate::dep_graph::{DepGraph, DepKind, DepKindStruct}; use crate::hir::place::Place as HirPlace; use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos}; -use crate::lint::struct_lint_level; +use crate::lint::{struct_lint_level, LintLevelSource}; use crate::middle::codegen_fn_attrs::CodegenFnAttrs; use crate::middle::resolve_lifetime; use crate::middle::stability; @@ -54,7 +54,7 @@ use rustc_serialize::opaque::{FileEncodeResult, FileEncoder}; use rustc_session::config::{CrateType, OutputFilenames}; use rustc_session::cstore::CrateStoreDyn; use rustc_session::errors::TargetDataLayoutErrorsWrapper; -use rustc_session::lint::Lint; +use rustc_session::lint::{Level, Lint}; use rustc_session::Limit; use rustc_session::Session; use rustc_span::def_id::{DefPathHash, StableCrateId}; @@ -2813,6 +2813,44 @@ impl<'tcx> TyCtxt<'tcx> { iter.intern_with(|xs| self.intern_bound_variable_kinds(xs)) } + /// Walks upwards from `id` to find a node which might change lint levels with attributes. + /// It stops at `bound` and just returns it if reached. + pub fn maybe_lint_level_root_bounded(self, mut id: HirId, bound: HirId) -> HirId { + let hir = self.hir(); + loop { + if id == bound { + return bound; + } + + if hir.attrs(id).iter().any(|attr| Level::from_attr(attr).is_some()) { + return id; + } + let next = hir.get_parent_node(id); + if next == id { + bug!("lint traversal reached the root of the crate"); + } + id = next; + } + } + + pub fn lint_level_at_node( + self, + lint: &'static Lint, + mut id: hir::HirId, + ) -> (Level, LintLevelSource) { + let sets = self.lint_levels(()); + loop { + if let Some(pair) = sets.level_and_source(lint, id, self.sess) { + return pair; + } + let next = self.hir().get_parent_node(id); + if next == id { + bug!("lint traversal reached the root of the crate"); + } + id = next; + } + } + /// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`, /// typically generated by `#[derive(LintDiagnostic)]`). pub fn emit_spanned_lint( diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index be208a9fc70..00da260b1dc 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -1,6 +1,6 @@ use crate::dep_graph; use crate::infer::canonical::{self, Canonical}; -use crate::lint::LintExpectation; +use crate::lint::LintLevelMap; use crate::metadata::ModChild; use crate::middle::codegen_fn_attrs::CodegenFnAttrs; use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; @@ -44,14 +44,12 @@ use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId}; -use rustc_hir::hir_id::HirId; use rustc_hir::lang_items::{LangItem, LanguageItems}; use rustc_hir::{Crate, ItemLocalId, TraitCandidate}; use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec}; use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion}; use rustc_session::cstore::{CrateDepKind, CrateSource}; use rustc_session::cstore::{ExternCrate, ForeignModule, LinkagePreference, NativeLib}; -use rustc_session::lint::LintExpectationId; use rustc_session::utils::NativeLibKind; use rustc_session::Limits; use rustc_span::symbol::Symbol; diff --git a/compiler/rustc_query_impl/src/keys.rs b/compiler/rustc_query_impl/src/keys.rs index 31de83ee141..49175e97f41 100644 --- a/compiler/rustc_query_impl/src/keys.rs +++ b/compiler/rustc_query_impl/src/keys.rs @@ -1,7 +1,6 @@ //! Defines the set of legal keys that can be used in queries. use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; -use rustc_hir::hir_id::HirId; use rustc_middle::infer::canonical::Canonical; use rustc_middle::mir; use rustc_middle::traits; @@ -544,19 +543,3 @@ impl<'tcx> Key for (Ty<'tcx>, ty::ValTree<'tcx>) { DUMMY_SP } } - -impl Key for HirId { - #[inline(always)] - fn query_crate_is_local(&self) -> bool { - true - } - - fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - tcx.hir().span(*self) - } - - #[inline(always)] - fn key_as_def_id(&self) -> Option { - None - } -} diff --git a/compiler/rustc_query_system/src/dep_graph/mod.rs b/compiler/rustc_query_system/src/dep_graph/mod.rs index 6f3bd776216..342d95ca490 100644 --- a/compiler/rustc_query_system/src/dep_graph/mod.rs +++ b/compiler/rustc_query_system/src/dep_graph/mod.rs @@ -67,8 +67,6 @@ impl HasDepContext for T { pub enum FingerprintStyle { /// The fingerprint is actually a DefPathHash. DefPathHash, - /// The fingerprint is actually a HirId. - HirId, /// Query key was `()` or equivalent, so fingerprint is just zero. Unit, /// Some opaque hash. @@ -79,9 +77,7 @@ impl FingerprintStyle { #[inline] pub fn reconstructible(self) -> bool { match self { - FingerprintStyle::DefPathHash | FingerprintStyle::Unit | FingerprintStyle::HirId => { - true - } + FingerprintStyle::DefPathHash | FingerprintStyle::Unit => true, FingerprintStyle::Opaque => false, } } diff --git a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.rs b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.rs index 23457b8e062..9b646060adf 100644 --- a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.rs +++ b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.rs @@ -3,11 +3,9 @@ #![deny(non_exhaustive_omitted_patterns)] //~^ WARNING unknown lint: `non_exhaustive_omitted_patterns` //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` -//~| WARNING unknown lint: `non_exhaustive_omitted_patterns` #![allow(non_exhaustive_omitted_patterns)] //~^ WARNING unknown lint: `non_exhaustive_omitted_patterns` //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` -//~| WARNING unknown lint: `non_exhaustive_omitted_patterns` fn main() { enum Foo { @@ -19,8 +17,6 @@ fn main() { //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` - //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` - //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` match Foo::A { Foo::A => {} Foo::B => {} @@ -35,5 +31,4 @@ fn main() { } //~^^^ WARNING unknown lint: `non_exhaustive_omitted_patterns` //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` - //~| WARNING unknown lint: `non_exhaustive_omitted_patterns` } diff --git a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr index 29023858e4f..3de08e215da 100644 --- a/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr +++ b/src/test/ui/feature-gates/feature-gate-non_exhaustive_omitted_patterns_lint.stderr @@ -10,7 +10,7 @@ LL | #![deny(non_exhaustive_omitted_patterns)] = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:7:1 + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:6:1 | LL | #![allow(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | #![allow(non_exhaustive_omitted_patterns)] = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:17:5 + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:15:5 | LL | #[allow(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +30,7 @@ LL | #[allow(non_exhaustive_omitted_patterns)] = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:17:5 + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:15:5 | LL | #[allow(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,7 +40,7 @@ LL | #[allow(non_exhaustive_omitted_patterns)] = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:33:9 + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:29:9 | LL | #[warn(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -60,7 +60,7 @@ LL | #![deny(non_exhaustive_omitted_patterns)] = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:7:1 + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:6:1 | LL | #![allow(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -70,7 +70,7 @@ LL | #![allow(non_exhaustive_omitted_patterns)] = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:17:5 + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:15:5 | LL | #[allow(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | #[allow(non_exhaustive_omitted_patterns)] = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:17:5 + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:15:5 | LL | #[allow(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -90,7 +90,7 @@ LL | #[allow(non_exhaustive_omitted_patterns)] = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:33:9 + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:29:9 | LL | #[warn(non_exhaustive_omitted_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -100,13 +100,13 @@ LL | #[warn(non_exhaustive_omitted_patterns)] = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable error[E0004]: non-exhaustive patterns: `Foo::C` not covered - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:24:11 + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:20:11 | LL | match Foo::A { | ^^^^^^ pattern `Foo::C` not covered | note: `Foo` defined here - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:14:15 + --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:12:15 | LL | enum Foo { | --- @@ -119,56 +119,6 @@ LL ~ Foo::B => {} LL + Foo::C => todo!() | -warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:3:1 - | -LL | #![deny(non_exhaustive_omitted_patterns)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the `non_exhaustive_omitted_patterns` lint is unstable - = note: see issue #89554 for more information - = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable - -warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:7:1 - | -LL | #![allow(non_exhaustive_omitted_patterns)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the `non_exhaustive_omitted_patterns` lint is unstable - = note: see issue #89554 for more information - = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable - -warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:17:5 - | -LL | #[allow(non_exhaustive_omitted_patterns)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the `non_exhaustive_omitted_patterns` lint is unstable - = note: see issue #89554 for more information - = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable - -warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:17:5 - | -LL | #[allow(non_exhaustive_omitted_patterns)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the `non_exhaustive_omitted_patterns` lint is unstable - = note: see issue #89554 for more information - = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable - -warning: unknown lint: `non_exhaustive_omitted_patterns` - --> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:33:9 - | -LL | #[warn(non_exhaustive_omitted_patterns)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the `non_exhaustive_omitted_patterns` lint is unstable - = note: see issue #89554 for more information - = help: add `#![feature(non_exhaustive_omitted_patterns_lint)]` to the crate attributes to enable - -error: aborting due to previous error; 15 warnings emitted +error: aborting due to previous error; 10 warnings emitted For more information about this error, try `rustc --explain E0004`. diff --git a/src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr b/src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr index 5942fa8aeb4..06befcbb511 100644 --- a/src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr +++ b/src/test/ui/lint/rfc-2383-lint-reason/force_warn_expected_lints_fulfilled.stderr @@ -1,3 +1,11 @@ +warning: denote infinite loops with `loop { ... }` + --> $DIR/force_warn_expected_lints_fulfilled.rs:10:5 + | +LL | while true { + | ^^^^^^^^^^ help: use `loop` + | + = note: requested on the command line with `--force-warn while-true` + warning: unused variable: `x` --> $DIR/force_warn_expected_lints_fulfilled.rs:20:9 | @@ -28,13 +36,5 @@ LL | let mut what_does_the_fox_say = "*ding* *deng* *dung*"; | = note: requested on the command line with `--force-warn unused-mut` -warning: denote infinite loops with `loop { ... }` - --> $DIR/force_warn_expected_lints_fulfilled.rs:10:5 - | -LL | while true { - | ^^^^^^^^^^ help: use `loop` - | - = note: requested on the command line with `--force-warn while-true` - warning: 5 warnings emitted -- cgit 1.4.1-3-g733a5 From 3975d55d9888392cd738708b914442de9ac2bff5 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Tue, 20 Sep 2022 15:41:42 +0200 Subject: remove cfg(bootstrap) --- compiler/rustc_ast/src/ast.rs | 1 - compiler/rustc_ast/src/lib.rs | 2 - compiler/rustc_ast_lowering/src/lib.rs | 1 - compiler/rustc_ast_passes/src/lib.rs | 1 - compiler/rustc_attr/src/lib.rs | 1 - compiler/rustc_borrowck/src/lib.rs | 1 - compiler/rustc_builtin_macros/src/lib.rs | 1 - compiler/rustc_codegen_llvm/src/lib.rs | 1 - compiler/rustc_codegen_ssa/src/lib.rs | 1 - compiler/rustc_const_eval/src/interpret/operand.rs | 2 +- compiler/rustc_const_eval/src/interpret/place.rs | 2 - compiler/rustc_const_eval/src/lib.rs | 1 - compiler/rustc_data_structures/src/lib.rs | 1 - compiler/rustc_driver/src/lib.rs | 1 - compiler/rustc_errors/src/lib.rs | 3 +- compiler/rustc_expand/src/lib.rs | 1 - compiler/rustc_hir/src/hir.rs | 5 - compiler/rustc_hir/src/lib.rs | 1 - compiler/rustc_incremental/src/lib.rs | 1 - compiler/rustc_index/src/lib.rs | 1 - compiler/rustc_infer/src/lib.rs | 2 - compiler/rustc_interface/src/lib.rs | 1 - compiler/rustc_lint/src/lib.rs | 2 +- compiler/rustc_macros/src/lib.rs | 1 - compiler/rustc_metadata/src/lib.rs | 2 - compiler/rustc_middle/src/lib.rs | 2 - compiler/rustc_middle/src/mir/syntax.rs | 1 - compiler/rustc_middle/src/thir.rs | 4 - compiler/rustc_mir_build/src/lib.rs | 1 - compiler/rustc_mir_dataflow/src/lib.rs | 1 - compiler/rustc_mir_transform/src/lib.rs | 1 - compiler/rustc_monomorphize/src/lib.rs | 1 - compiler/rustc_parse/src/lib.rs | 1 - compiler/rustc_passes/src/lib.rs | 1 - compiler/rustc_privacy/src/lib.rs | 1 - compiler/rustc_query_system/src/lib.rs | 1 - compiler/rustc_resolve/src/lib.rs | 1 - compiler/rustc_save_analysis/src/lib.rs | 1 - compiler/rustc_serialize/src/lib.rs | 1 - compiler/rustc_session/src/lib.rs | 1 - compiler/rustc_span/src/lib.rs | 1 - compiler/rustc_target/src/lib.rs | 1 - compiler/rustc_trait_selection/src/lib.rs | 2 - compiler/rustc_traits/src/lib.rs | 1 - compiler/rustc_ty_utils/src/lib.rs | 1 - compiler/rustc_typeck/src/lib.rs | 2 - library/alloc/src/boxed.rs | 14 - library/alloc/src/boxed/thin.rs | 2 - library/alloc/src/collections/btree/map/entry.rs | 1 - library/alloc/src/collections/mod.rs | 1 - library/alloc/src/ffi/c_str.rs | 3 - library/alloc/src/lib.rs | 7 +- library/alloc/src/string.rs | 3 - library/alloc/src/sync.rs | 1 - library/core/src/alloc/layout.rs | 2 - library/core/src/alloc/mod.rs | 2 - library/core/src/array/mod.rs | 2 - library/core/src/char/decode.rs | 2 - library/core/src/char/mod.rs | 2 - library/core/src/convert/mod.rs | 2 - library/core/src/intrinsics.rs | 65 -- library/core/src/lib.rs | 1 - library/core/src/marker.rs | 2 +- library/core/src/mem/transmutability.rs | 4 +- library/core/src/num/error.rs | 3 - library/core/src/num/mod.rs | 2 - library/core/src/ops/generator.rs | 1 - library/core/src/ops/try_trait.rs | 84 +- library/core/src/ptr/const_ptr.rs | 1 - library/core/src/ptr/mut_ptr.rs | 1 - library/core/src/str/error.rs | 3 - library/core/src/str/mod.rs | 1 - library/std/src/collections/hash/map.rs | 2 - library/std/src/error.rs | 1023 -------------------- library/std/src/io/error.rs | 1 - library/std/src/lib.rs | 8 +- library/std/src/rt.rs | 5 +- src/librustdoc/clean/types.rs | 1 - src/librustdoc/lib.rs | 2 - src/test/mir-opt/issue-101867.rs | 1 - src/test/ui/let-else/const-fn.rs | 1 - src/tools/clippy/clippy_dev/src/lib.rs | 1 - src/tools/clippy/clippy_lints/src/lib.rs | 1 - src/tools/clippy/clippy_utils/src/lib.rs | 1 - 84 files changed, 15 insertions(+), 1308 deletions(-) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 6c514c75a50..0efde1e7b21 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -3046,7 +3046,6 @@ mod size_asserts { static_assert_size!(Block, 48); static_assert_size!(Expr, 104); static_assert_size!(ExprKind, 72); - #[cfg(not(bootstrap))] static_assert_size!(Fn, 184); static_assert_size!(ForeignItem, 96); static_assert_size!(ForeignItemKind, 24); diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index bd7a85b07a0..eeb7e56e2b1 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -13,9 +13,7 @@ #![feature(const_default_impls)] #![feature(const_trait_impl)] #![feature(if_let_guard)] -#![cfg_attr(bootstrap, feature(label_break_value))] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(negative_impls)] #![feature(slice_internals)] diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 186c10065f3..275ceed30d7 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -32,7 +32,6 @@ #![feature(box_patterns)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(never_type)] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] diff --git a/compiler/rustc_ast_passes/src/lib.rs b/compiler/rustc_ast_passes/src/lib.rs index 8aa9d57f046..f58fffc9172 100644 --- a/compiler/rustc_ast_passes/src/lib.rs +++ b/compiler/rustc_ast_passes/src/lib.rs @@ -9,7 +9,6 @@ #![feature(if_let_guard)] #![feature(iter_is_partitioned)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![recursion_limit = "256"] #[macro_use] diff --git a/compiler/rustc_attr/src/lib.rs b/compiler/rustc_attr/src/lib.rs index 52e65a9c774..4580ffcc6d8 100644 --- a/compiler/rustc_attr/src/lib.rs +++ b/compiler/rustc_attr/src/lib.rs @@ -5,7 +5,6 @@ //! to this crate. #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 6b90f2daeea..a83840e1099 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -3,7 +3,6 @@ #![allow(rustc::potential_query_instability)] #![feature(box_patterns)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(never_type)] #![feature(rustc_attrs)] diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 8aeb3b82a9c..0de27d3d407 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -9,7 +9,6 @@ #![feature(if_let_guard)] #![feature(is_sorted)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(proc_macro_internals)] #![feature(proc_macro_quote)] #![recursion_limit = "256"] diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index 42c65e04e3b..15bfa843046 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -7,7 +7,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(hash_raw_entry)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(extern_types)] #![feature(once_cell)] #![feature(iter_intersperse)] diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index e736b2aba9c..3ef9a634e18 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -1,7 +1,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(box_patterns)] #![feature(try_blocks)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![feature(associated_type_bounds)] #![feature(strict_provenance)] diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index dc5305aabcf..510adde6296 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -784,7 +784,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } // Some nodes are used a lot. Make sure they don't unintentionally get bigger. -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64", not(bootstrap)))] +#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] mod size_asserts { use super::*; use rustc_data_structures::static_assert_size; diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index bc1aa43b73a..7a01b85381a 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -890,8 +890,6 @@ mod size_asserts { static_assert_size!(MemPlaceMeta, 24); static_assert_size!(MemPlace, 40); static_assert_size!(MPlaceTy<'_>, 64); - #[cfg(not(bootstrap))] static_assert_size!(Place, 40); - #[cfg(not(bootstrap))] static_assert_size!(PlaceTy<'_>, 64); } diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index 9f47d302a0c..7c4c7db1035 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -10,7 +10,6 @@ Rust MIR: a lowered representation of Rust. #![feature(decl_macro)] #![feature(exact_size_is_empty)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(map_try_insert)] #![feature(min_specialization)] #![feature(slice_ptr_get)] diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 56f7823efe0..467ac401d08 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -13,7 +13,6 @@ #![feature(cell_leak)] #![feature(control_flow_enum)] #![feature(extend_one)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(hash_raw_entry)] #![feature(hasher_prefixfree_extras)] #![feature(maybe_uninit_uninit_array)] diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index c768935eb62..fcd49f5d015 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -5,7 +5,6 @@ //! This API is completely unstable and subject to change. #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index b44cf352233..4d262ae0f5e 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -7,7 +7,6 @@ #![feature(if_let_guard)] #![feature(adt_const_params)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(never_type)] #![feature(result_option_inspect)] #![feature(rustc_attrs)] @@ -69,7 +68,7 @@ pub type PResult<'a, T> = Result>; // (See also the comment on `DiagnosticBuilder`'s `diagnostic` field.) #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] rustc_data_structures::static_assert_size!(PResult<'_, ()>, 16); -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64", not(bootstrap)))] +#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] rustc_data_structures::static_assert_size!(PResult<'_, bool>, 16); #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Encodable, Decodable)] diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index ffc9abe64d2..b34de94fb7d 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -3,7 +3,6 @@ #![feature(associated_type_defaults)] #![feature(if_let_guard)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(macro_metavar_expr)] #![feature(proc_macro_diagnostic)] #![feature(proc_macro_internals)] diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 018b7cc5d9d..c1948052e3c 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3520,14 +3520,11 @@ mod size_asserts { static_assert_size!(FnDecl<'_>, 40); static_assert_size!(ForeignItem<'_>, 72); static_assert_size!(ForeignItemKind<'_>, 40); - #[cfg(not(bootstrap))] static_assert_size!(GenericArg<'_>, 24); static_assert_size!(GenericBound<'_>, 48); static_assert_size!(Generics<'_>, 56); static_assert_size!(Impl<'_>, 80); - #[cfg(not(bootstrap))] static_assert_size!(ImplItem<'_>, 80); - #[cfg(not(bootstrap))] static_assert_size!(ImplItemKind<'_>, 32); static_assert_size!(Item<'_>, 80); static_assert_size!(ItemKind<'_>, 48); @@ -3540,9 +3537,7 @@ mod size_asserts { static_assert_size!(QPath<'_>, 24); static_assert_size!(Stmt<'_>, 32); static_assert_size!(StmtKind<'_>, 16); - #[cfg(not(bootstrap))] static_assert_size!(TraitItem<'_>, 88); - #[cfg(not(bootstrap))] static_assert_size!(TraitItemKind<'_>, 48); static_assert_size!(Ty<'_>, 48); static_assert_size!(TyKind<'_>, 32); diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index 556ff1cc48e..1c4aa420c9b 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -5,7 +5,6 @@ #![feature(associated_type_defaults)] #![feature(closure_track_caller)] #![feature(const_btree_len)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![feature(min_specialization)] #![feature(never_type)] diff --git a/compiler/rustc_incremental/src/lib.rs b/compiler/rustc_incremental/src/lib.rs index 2c9e21f769f..83dd9a67e61 100644 --- a/compiler/rustc_incremental/src/lib.rs +++ b/compiler/rustc_incremental/src/lib.rs @@ -2,7 +2,6 @@ #![deny(missing_docs)] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] -#![cfg_attr(bootstrap, feature(let_else))] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] diff --git a/compiler/rustc_index/src/lib.rs b/compiler/rustc_index/src/lib.rs index a00d7bd6801..9753fb35530 100644 --- a/compiler/rustc_index/src/lib.rs +++ b/compiler/rustc_index/src/lib.rs @@ -3,7 +3,6 @@ #![feature(allow_internal_unstable)] #![feature(bench_black_box)] #![feature(extend_one)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(new_uninit)] #![feature(step_trait)] diff --git a/compiler/rustc_infer/src/lib.rs b/compiler/rustc_infer/src/lib.rs index 909a597e221..b91c098ab03 100644 --- a/compiler/rustc_infer/src/lib.rs +++ b/compiler/rustc_infer/src/lib.rs @@ -17,9 +17,7 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(extend_one)] -#![cfg_attr(bootstrap, feature(label_break_value))] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(if_let_guard)] #![feature(min_specialization)] #![feature(never_type)] diff --git a/compiler/rustc_interface/src/lib.rs b/compiler/rustc_interface/src/lib.rs index 41cd7b0e9b1..a41a749ee68 100644 --- a/compiler/rustc_interface/src/lib.rs +++ b/compiler/rustc_interface/src/lib.rs @@ -1,5 +1,4 @@ #![feature(box_patterns)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(internal_output_capture)] #![feature(thread_spawn_unchecked)] #![feature(once_cell)] diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 752a751f6bc..4408f68dd63 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -34,7 +34,7 @@ #![feature(iter_intersperse)] #![feature(iter_order_by)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] +#![feature(min_specialization)] #![feature(never_type)] #![recursion_limit = "256"] diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index 8fd23ee5ced..36bda3e0f6b 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -1,5 +1,4 @@ #![feature(allow_internal_unstable)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(never_type)] #![feature(proc_macro_diagnostic)] #![feature(proc_macro_span)] diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index 6f5604b7e11..98cf6fef54a 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -2,10 +2,8 @@ #![feature(decl_macro)] #![feature(drain_filter)] #![feature(generators)] -#![cfg_attr(bootstrap, feature(generic_associated_types))] #![feature(iter_from_generator)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![feature(proc_macro_internals)] #![feature(macro_metavar_expr)] diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 01b9277b983..a180706e1cf 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -31,7 +31,6 @@ #![feature(discriminant_kind)] #![feature(exhaustive_patterns)] #![feature(get_mut_unchecked)] -#![cfg_attr(bootstrap, feature(generic_associated_types))] #![feature(if_let_guard)] #![feature(map_first_last)] #![feature(negative_impls)] @@ -40,7 +39,6 @@ #![feature(new_uninit)] #![feature(once_cell)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(trusted_len)] #![feature(type_alias_impl_trait)] diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 568d63fb062..ee8377d1987 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -1242,7 +1242,6 @@ pub enum BinOp { mod size_asserts { use super::*; // These are in alphabetical order, which is easy to maintain. - #[cfg(not(bootstrap))] static_assert_size!(AggregateKind<'_>, 40); static_assert_size!(Operand<'_>, 24); static_assert_size!(Place<'_>, 16); diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 86b4150505f..84374a25ed8 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -852,12 +852,8 @@ mod size_asserts { static_assert_size!(Block, 56); static_assert_size!(Expr<'_>, 64); static_assert_size!(ExprKind<'_>, 40); - #[cfg(not(bootstrap))] static_assert_size!(Pat<'_>, 72); - #[cfg(not(bootstrap))] static_assert_size!(PatKind<'_>, 56); - #[cfg(not(bootstrap))] static_assert_size!(Stmt<'_>, 48); - #[cfg(not(bootstrap))] static_assert_size!(StmtKind<'_>, 40); } diff --git a/compiler/rustc_mir_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs index 0c0a2fe9c9e..8236b1528c0 100644 --- a/compiler/rustc_mir_build/src/lib.rs +++ b/compiler/rustc_mir_build/src/lib.rs @@ -6,7 +6,6 @@ #![feature(control_flow_enum)] #![feature(if_let_guard)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(once_cell)] #![recursion_limit = "256"] diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs index b45c32ee986..b471d04fd60 100644 --- a/compiler/rustc_mir_dataflow/src/lib.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -1,7 +1,6 @@ #![feature(associated_type_defaults)] #![feature(box_patterns)] #![feature(exact_size_is_empty)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(once_cell)] #![feature(stmt_expr_attributes)] diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index e6fc8559571..2230c3399f0 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -1,7 +1,6 @@ #![allow(rustc::potential_query_instability)] #![feature(box_patterns)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(map_try_insert)] #![feature(min_specialization)] #![feature(never_type)] diff --git a/compiler/rustc_monomorphize/src/lib.rs b/compiler/rustc_monomorphize/src/lib.rs index ba6ce9fd40f..42781bd25f0 100644 --- a/compiler/rustc_monomorphize/src/lib.rs +++ b/compiler/rustc_monomorphize/src/lib.rs @@ -1,6 +1,5 @@ #![feature(array_windows)] #![feature(control_flow_enum)] -#![cfg_attr(bootstrap, feature(let_else))] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] #![deny(rustc::untranslatable_diagnostic)] diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index a37327f4294..06245380927 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -4,7 +4,6 @@ #![feature(box_patterns)] #![feature(if_let_guard)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(never_type)] #![feature(rustc_attrs)] #![recursion_limit = "256"] diff --git a/compiler/rustc_passes/src/lib.rs b/compiler/rustc_passes/src/lib.rs index 39ebb8db21c..6e621b7eb5e 100644 --- a/compiler/rustc_passes/src/lib.rs +++ b/compiler/rustc_passes/src/lib.rs @@ -8,7 +8,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(iter_intersperse)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(map_try_insert)] #![feature(min_specialization)] #![feature(try_blocks)] diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 72867447250..41d5f54b366 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -1,7 +1,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(associated_type_defaults)] #![feature(control_flow_enum)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(rustc_private)] #![feature(try_blocks)] #![recursion_limit = "256"] diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index 5987651322a..8f6da73d1f2 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -1,7 +1,6 @@ #![feature(assert_matches)] #![feature(core_intrinsics)] #![feature(hash_raw_entry)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(extern_types)] #![allow(rustc::potential_query_instability)] diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 54a7f416ce6..583030b0e50 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -12,7 +12,6 @@ #![feature(if_let_guard)] #![feature(iter_intersperse)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(never_type)] #![recursion_limit = "256"] #![allow(rustdoc::private_intra_doc_links)] diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index 1a3511a1dc8..ad7aca3cb94 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -1,6 +1,5 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(if_let_guard)] -#![cfg_attr(bootstrap, feature(let_else))] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] #![feature(never_type)] diff --git a/compiler/rustc_serialize/src/lib.rs b/compiler/rustc_serialize/src/lib.rs index fa9c7bd54c3..1f8d2336c4e 100644 --- a/compiler/rustc_serialize/src/lib.rs +++ b/compiler/rustc_serialize/src/lib.rs @@ -14,7 +14,6 @@ Core encoding and decoding interfaces. #![feature(min_specialization)] #![feature(core_intrinsics)] #![feature(maybe_uninit_slice)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(new_uninit)] #![feature(allocator_api)] #![cfg_attr(test, feature(test))] diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index f6bab775e76..39e871f532c 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -1,6 +1,5 @@ #![feature(if_let_guard)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(never_type)] #![feature(once_cell)] diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 366fd9d2cd1..f8df4169715 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -15,7 +15,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(array_windows)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(if_let_guard)] #![feature(negative_impls)] #![feature(min_specialization)] diff --git a/compiler/rustc_target/src/lib.rs b/compiler/rustc_target/src/lib.rs index a7deab9d2ef..aaba0d7f093 100644 --- a/compiler/rustc_target/src/lib.rs +++ b/compiler/rustc_target/src/lib.rs @@ -11,7 +11,6 @@ #![feature(assert_matches)] #![feature(associated_type_bounds)] #![feature(exhaustive_patterns)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(never_type)] #![feature(rustc_attrs)] diff --git a/compiler/rustc_trait_selection/src/lib.rs b/compiler/rustc_trait_selection/src/lib.rs index d35f74974fd..5d52aa07523 100644 --- a/compiler/rustc_trait_selection/src/lib.rs +++ b/compiler/rustc_trait_selection/src/lib.rs @@ -16,9 +16,7 @@ #![feature(control_flow_enum)] #![feature(drain_filter)] #![feature(hash_drain_filter)] -#![cfg_attr(bootstrap, feature(label_break_value))] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(if_let_guard)] #![feature(never_type)] #![feature(type_alias_impl_trait)] diff --git a/compiler/rustc_traits/src/lib.rs b/compiler/rustc_traits/src/lib.rs index 2d39e973ed9..0da28737f69 100644 --- a/compiler/rustc_traits/src/lib.rs +++ b/compiler/rustc_traits/src/lib.rs @@ -3,7 +3,6 @@ #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] -#![cfg_attr(bootstrap, feature(let_else))] #![recursion_limit = "256"] #[macro_use] diff --git a/compiler/rustc_ty_utils/src/lib.rs b/compiler/rustc_ty_utils/src/lib.rs index 8524e57cb58..10c18789f74 100644 --- a/compiler/rustc_ty_utils/src/lib.rs +++ b/compiler/rustc_ty_utils/src/lib.rs @@ -6,7 +6,6 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(control_flow_enum)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(never_type)] #![feature(box_patterns)] #![recursion_limit = "256"] diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index b1ce972e1d6..1859473166a 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -64,9 +64,7 @@ This API is completely unstable and subject to change. #![feature(if_let_guard)] #![feature(is_sorted)] #![feature(iter_intersperse)] -#![cfg_attr(bootstrap, feature(label_break_value))] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(never_type)] #![feature(once_cell)] diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 0aff1323f97..f651cb02176 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -151,7 +151,6 @@ use core::async_iter::AsyncIterator; use core::borrow; use core::cmp::Ordering; use core::convert::{From, TryFrom}; -#[cfg(not(bootstrap))] use core::error::Error; use core::fmt; use core::future::Future; @@ -176,7 +175,6 @@ use crate::borrow::Cow; use crate::raw_vec::RawVec; #[cfg(not(no_global_oom_handling))] use crate::str::from_boxed_utf8_unchecked; -#[cfg(not(bootstrap))] #[cfg(not(no_global_oom_handling))] use crate::string::String; #[cfg(not(no_global_oom_handling))] @@ -2090,7 +2088,6 @@ impl AsyncIterator for Box { } } -#[cfg(not(bootstrap))] impl dyn Error { #[inline] #[stable(feature = "error_downcast", since = "1.3.0")] @@ -2108,7 +2105,6 @@ impl dyn Error { } } -#[cfg(not(bootstrap))] impl dyn Error + Send { #[inline] #[stable(feature = "error_downcast", since = "1.3.0")] @@ -2123,7 +2119,6 @@ impl dyn Error + Send { } } -#[cfg(not(bootstrap))] impl dyn Error + Send + Sync { #[inline] #[stable(feature = "error_downcast", since = "1.3.0")] @@ -2138,7 +2133,6 @@ impl dyn Error + Send + Sync { } } -#[cfg(not(bootstrap))] #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl<'a, E: Error + 'a> From for Box { @@ -2172,7 +2166,6 @@ impl<'a, E: Error + 'a> From for Box { } } -#[cfg(not(bootstrap))] #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl<'a, E: Error + Send + Sync + 'a> From for Box { @@ -2212,7 +2205,6 @@ impl<'a, E: Error + Send + Sync + 'a> From for Box for Box { @@ -2257,7 +2249,6 @@ impl From for Box { } } -#[cfg(not(bootstrap))] #[cfg(not(no_global_oom_handling))] #[stable(feature = "string_box_error", since = "1.6.0")] impl From for Box { @@ -2280,7 +2271,6 @@ impl From for Box { } } -#[cfg(not(bootstrap))] #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl<'a> From<&str> for Box { @@ -2305,7 +2295,6 @@ impl<'a> From<&str> for Box { } } -#[cfg(not(bootstrap))] #[cfg(not(no_global_oom_handling))] #[stable(feature = "string_box_error", since = "1.6.0")] impl From<&str> for Box { @@ -2328,7 +2317,6 @@ impl From<&str> for Box { } } -#[cfg(not(bootstrap))] #[cfg(not(no_global_oom_handling))] #[stable(feature = "cow_box_error", since = "1.22.0")] impl<'a, 'b> From> for Box { @@ -2351,7 +2339,6 @@ impl<'a, 'b> From> for Box { } } -#[cfg(not(bootstrap))] #[cfg(not(no_global_oom_handling))] #[stable(feature = "cow_box_error", since = "1.22.0")] impl<'a> From> for Box { @@ -2373,7 +2360,6 @@ impl<'a> From> for Box { } } -#[cfg(not(bootstrap))] #[stable(feature = "box_error", since = "1.8.0")] impl core::error::Error for Box { #[allow(deprecated, deprecated_in_future)] diff --git a/library/alloc/src/boxed/thin.rs b/library/alloc/src/boxed/thin.rs index 0a20c74b00f..c477c44906c 100644 --- a/library/alloc/src/boxed/thin.rs +++ b/library/alloc/src/boxed/thin.rs @@ -2,7 +2,6 @@ // https://github.com/matthieu-m/rfc2580/blob/b58d1d3cba0d4b5e859d3617ea2d0943aaa31329/examples/thin.rs // by matthieu-m use crate::alloc::{self, Layout, LayoutError}; -#[cfg(not(bootstrap))] use core::error::Error; use core::fmt::{self, Debug, Display, Formatter}; use core::marker::PhantomData; @@ -274,7 +273,6 @@ impl WithHeader { } } -#[cfg(not(bootstrap))] #[unstable(feature = "thin_box", issue = "92791")] impl Error for ThinBox { fn source(&self) -> Option<&(dyn Error + 'static)> { diff --git a/library/alloc/src/collections/btree/map/entry.rs b/library/alloc/src/collections/btree/map/entry.rs index cd7cdc19207..370b58864af 100644 --- a/library/alloc/src/collections/btree/map/entry.rs +++ b/library/alloc/src/collections/btree/map/entry.rs @@ -133,7 +133,6 @@ impl<'a, K: Debug + Ord, V: Debug, A: Allocator + Clone> fmt::Display } } -#[cfg(not(bootstrap))] #[unstable(feature = "map_try_insert", issue = "82766")] impl<'a, K: core::fmt::Debug + Ord, V: core::fmt::Debug> core::error::Error for crate::collections::btree_map::OccupiedError<'a, K, V> diff --git a/library/alloc/src/collections/mod.rs b/library/alloc/src/collections/mod.rs index 21d0def0866..161a375736c 100644 --- a/library/alloc/src/collections/mod.rs +++ b/library/alloc/src/collections/mod.rs @@ -153,6 +153,5 @@ trait SpecExtend { fn spec_extend(&mut self, iter: I); } -#[cfg(not(bootstrap))] #[stable(feature = "try_reserve", since = "1.57.0")] impl core::error::Error for TryReserveError {} diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index aede6d54c6c..11bd4c4dc1b 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -1122,7 +1122,6 @@ impl CStr { } } -#[cfg(not(bootstrap))] #[stable(feature = "rust1", since = "1.0.0")] impl core::error::Error for NulError { #[allow(deprecated)] @@ -1131,11 +1130,9 @@ impl core::error::Error for NulError { } } -#[cfg(not(bootstrap))] #[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")] impl core::error::Error for FromVecWithNulError {} -#[cfg(not(bootstrap))] #[stable(feature = "cstring_into", since = "1.7.0")] impl core::error::Error for IntoStringError { #[allow(deprecated)] diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index de58f22daae..7fde8f670a2 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -114,8 +114,8 @@ #![feature(const_waker)] #![feature(cstr_from_bytes_until_nul)] #![feature(dispatch_from_dyn)] -#![cfg_attr(not(bootstrap), feature(error_generic_member_access))] -#![cfg_attr(not(bootstrap), feature(error_in_core))] +#![feature(error_generic_member_access)] +#![feature(error_in_core)] #![feature(exact_size_is_empty)] #![feature(extend_one)] #![feature(fmt_internals)] @@ -132,7 +132,7 @@ #![feature(nonnull_slice_from_raw_parts)] #![feature(pattern)] #![feature(pointer_byte_offsets)] -#![cfg_attr(not(bootstrap), feature(provide_any))] +#![feature(provide_any)] #![feature(ptr_internals)] #![feature(ptr_metadata)] #![feature(ptr_sub_ptr)] @@ -173,7 +173,6 @@ #![cfg_attr(not(test), feature(generator_trait))] #![feature(hashmap_internals)] #![feature(lang_items)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(min_specialization)] #![feature(negative_impls)] #![feature(never_type)] diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index f2448396ce8..983376a282b 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -44,7 +44,6 @@ #[cfg(not(no_global_oom_handling))] use core::char::{decode_utf16, REPLACEMENT_CHARACTER}; -#[cfg(not(bootstrap))] use core::error::Error; use core::fmt; use core::hash; @@ -1941,7 +1940,6 @@ impl fmt::Display for FromUtf16Error { } } -#[cfg(not(bootstrap))] #[stable(feature = "rust1", since = "1.0.0")] impl Error for FromUtf8Error { #[allow(deprecated)] @@ -1950,7 +1948,6 @@ impl Error for FromUtf8Error { } } -#[cfg(not(bootstrap))] #[stable(feature = "rust1", since = "1.0.0")] impl Error for FromUtf16Error { #[allow(deprecated)] diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 4377edeee87..a5322953d49 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -2764,7 +2764,6 @@ fn data_offset_align(align: usize) -> usize { layout.size() + layout.padding_needed_for(align) } -#[cfg(not(bootstrap))] #[stable(feature = "arc_error", since = "1.52.0")] impl core::error::Error for Arc { #[allow(deprecated, deprecated_in_future)] diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index f03502429ab..5bb44b40859 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -5,7 +5,6 @@ // Your performance intuition is useless. Run perf. use crate::cmp; -#[cfg(not(bootstrap))] use crate::error::Error; use crate::fmt; use crate::mem::{self, ValidAlign}; @@ -463,7 +462,6 @@ pub type LayoutErr = LayoutError; #[derive(Clone, PartialEq, Eq, Debug)] pub struct LayoutError; -#[cfg(not(bootstrap))] #[stable(feature = "alloc_layout", since = "1.28.0")] impl Error for LayoutError {} diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 61553157478..a4bf6a853a6 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -21,7 +21,6 @@ pub use self::layout::LayoutErr; #[stable(feature = "alloc_layout_error", since = "1.50.0")] pub use self::layout::LayoutError; -#[cfg(not(bootstrap))] use crate::error::Error; use crate::fmt; use crate::ptr::{self, NonNull}; @@ -34,7 +33,6 @@ use crate::ptr::{self, NonNull}; #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub struct AllocError; -#[cfg(not(bootstrap))] #[unstable( feature = "allocator_api", reason = "the precise API and guarantees it provides may be tweaked.", diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 36e89a95fd2..b82bbf2267a 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -7,7 +7,6 @@ use crate::borrow::{Borrow, BorrowMut}; use crate::cmp::Ordering; use crate::convert::{Infallible, TryFrom}; -#[cfg(not(bootstrap))] use crate::error::Error; use crate::fmt; use crate::hash::{self, Hash}; @@ -121,7 +120,6 @@ impl fmt::Display for TryFromSliceError { } } -#[cfg(not(bootstrap))] #[stable(feature = "try_from", since = "1.34.0")] impl Error for TryFromSliceError { #[allow(deprecated)] diff --git a/library/core/src/char/decode.rs b/library/core/src/char/decode.rs index dc8ea66cc6d..11f1c30f6d5 100644 --- a/library/core/src/char/decode.rs +++ b/library/core/src/char/decode.rs @@ -1,6 +1,5 @@ //! UTF-8 and UTF-16 decoding iterators -#[cfg(not(bootstrap))] use crate::error::Error; use crate::fmt; @@ -124,7 +123,6 @@ impl fmt::Display for DecodeUtf16Error { } } -#[cfg(not(bootstrap))] #[stable(feature = "decode_utf16", since = "1.9.0")] impl Error for DecodeUtf16Error { #[allow(deprecated)] diff --git a/library/core/src/char/mod.rs b/library/core/src/char/mod.rs index 72d63ac4b4b..b34a7121631 100644 --- a/library/core/src/char/mod.rs +++ b/library/core/src/char/mod.rs @@ -38,7 +38,6 @@ pub use self::methods::encode_utf16_raw; #[unstable(feature = "char_internals", reason = "exposed only for libstd", issue = "none")] pub use self::methods::encode_utf8_raw; -#[cfg(not(bootstrap))] use crate::error::Error; use crate::fmt::{self, Write}; use crate::iter::FusedIterator; @@ -587,6 +586,5 @@ impl fmt::Display for TryFromCharError { } } -#[cfg(not(bootstrap))] #[stable(feature = "u8_from_char", since = "1.59.0")] impl Error for TryFromCharError {} diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index 0480704a6d6..c42adda8da5 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -34,7 +34,6 @@ #![stable(feature = "rust1", since = "1.0.0")] -#[cfg(not(bootstrap))] use crate::error::Error; use crate::fmt; use crate::hash::{Hash, Hasher}; @@ -724,7 +723,6 @@ impl fmt::Display for Infallible { } } -#[cfg(not(bootstrap))] #[stable(feature = "str_parse_error2", since = "1.8.0")] impl Error for Infallible { fn description(&self) -> &str { diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 11c75e2c912..12b43da5a42 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -54,8 +54,6 @@ )] #![allow(missing_docs)] -#[cfg(bootstrap)] -use crate::marker::Destruct; use crate::marker::DiscriminantKind; use crate::mem; @@ -1297,7 +1295,6 @@ extern "rust-intrinsic" { /// any safety invariants. /// /// Consider using [`pointer::mask`] instead. - #[cfg(not(bootstrap))] pub fn ptr_mask(ptr: *const T, mask: usize) -> *const T; /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with @@ -2022,17 +2019,8 @@ extern "rust-intrinsic" { /// Therefore, implementations must not require the user to uphold /// any safety invariants. #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")] - #[cfg(not(bootstrap))] pub fn ptr_guaranteed_cmp(ptr: *const T, other: *const T) -> u8; - #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")] - #[cfg(bootstrap)] - pub fn ptr_guaranteed_eq(ptr: *const T, other: *const T) -> bool; - - #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")] - #[cfg(bootstrap)] - pub fn ptr_guaranteed_ne(ptr: *const T, other: *const T) -> bool; - /// Allocates a block of memory at compile time. /// At runtime, just returns a null pointer. /// @@ -2143,7 +2131,6 @@ extern "rust-intrinsic" { /// `unreachable_unchecked` is actually being reached. The bug is in *crate A*, /// which violates the principle that a `const fn` must behave the same at /// compile-time and at run-time. The unsafe code in crate B is fine. - #[cfg(not(bootstrap))] #[rustc_const_unstable(feature = "const_eval_select", issue = "none")] pub fn const_eval_select(arg: ARG, called_in_const: F, called_at_rt: G) -> RET where @@ -2216,16 +2203,6 @@ pub(crate) fn is_nonoverlapping(src: *const T, dst: *const T, count: usize) - diff >= size } -#[cfg(bootstrap)] -pub const fn ptr_guaranteed_cmp(a: *const (), b: *const ()) -> u8 { - match (ptr_guaranteed_eq(a, b), ptr_guaranteed_ne(a, b)) { - (false, false) => 2, - (true, false) => 1, - (false, true) => 0, - (true, true) => unreachable!(), - } -} - /// Copies `count * size_of::()` bytes from `src` to `dst`. The source /// and destination must *not* overlap. /// @@ -2484,45 +2461,3 @@ pub const unsafe fn write_bytes(dst: *mut T, val: u8, count: usize) { write_bytes(dst, val, count) } } - -#[cfg(bootstrap)] -#[unstable( - feature = "const_eval_select", - issue = "none", - reason = "const_eval_select will never be stable" -)] -#[rustc_const_unstable(feature = "const_eval_select", issue = "none")] -#[lang = "const_eval_select"] -#[rustc_do_not_const_check] -#[inline] -pub const unsafe fn const_eval_select( - arg: ARG, - _called_in_const: F, - called_at_rt: G, -) -> RET -where - F: ~const FnOnce, - G: FnOnce + ~const Destruct, -{ - called_at_rt.call_once(arg) -} - -#[cfg(bootstrap)] -#[unstable( - feature = "const_eval_select", - issue = "none", - reason = "const_eval_select will never be stable" -)] -#[rustc_const_unstable(feature = "const_eval_select", issue = "none")] -#[lang = "const_eval_select_ct"] -pub const unsafe fn const_eval_select_ct( - arg: ARG, - called_in_const: F, - _called_at_rt: G, -) -> RET -where - F: ~const FnOnce, - G: FnOnce + ~const Destruct, -{ - called_in_const.call_once(arg) -} diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index a48290ea08e..5690b5256e8 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -310,7 +310,6 @@ pub mod clone; pub mod cmp; pub mod convert; pub mod default; -#[cfg(not(bootstrap))] pub mod error; pub mod marker; pub mod ops; diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 40a7b696193..5cb5e4458cc 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -806,7 +806,7 @@ pub trait Destruct {} /// The implementation of this trait is built-in and cannot be implemented /// for any user type. #[unstable(feature = "tuple_trait", issue = "none")] -#[cfg_attr(not(bootstrap), lang = "tuple_trait")] +#[lang = "tuple_trait"] #[rustc_on_unimplemented(message = "`{Self}` is not a tuple")] pub trait Tuple {} diff --git a/library/core/src/mem/transmutability.rs b/library/core/src/mem/transmutability.rs index 87a37863105..3b98efff293 100644 --- a/library/core/src/mem/transmutability.rs +++ b/library/core/src/mem/transmutability.rs @@ -4,7 +4,7 @@ /// any value of type `Self` are safely transmutable into a value of type `Dst`, in a given `Context`, /// notwithstanding whatever safety checks you have asked the compiler to [`Assume`] are satisfied. #[unstable(feature = "transmutability", issue = "99571")] -#[cfg_attr(not(bootstrap), lang = "transmute_trait")] +#[lang = "transmute_trait"] #[rustc_on_unimplemented( message = "`{Src}` cannot be safely transmuted into `{Self}` in the defining scope of `{Context}`.", label = "`{Src}` cannot be safely transmuted into `{Self}` in the defining scope of `{Context}`." @@ -17,7 +17,7 @@ where /// What transmutation safety conditions shall the compiler assume that *you* are checking? #[unstable(feature = "transmutability", issue = "99571")] -#[cfg_attr(not(bootstrap), lang = "transmute_opts")] +#[lang = "transmute_opts"] #[derive(PartialEq, Eq, Clone, Copy, Debug)] pub struct Assume { /// When `true`, the compiler assumes that *you* are ensuring (either dynamically or statically) that diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index 1f6b40e5df5..768dd87816d 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -1,7 +1,6 @@ //! Error types for conversion to integral types. use crate::convert::Infallible; -#[cfg(not(bootstrap))] use crate::error::Error; use crate::fmt; @@ -147,7 +146,6 @@ impl fmt::Display for ParseIntError { } } -#[cfg(not(bootstrap))] #[stable(feature = "rust1", since = "1.0.0")] impl Error for ParseIntError { #[allow(deprecated)] @@ -156,7 +154,6 @@ impl Error for ParseIntError { } } -#[cfg(not(bootstrap))] #[stable(feature = "try_from", since = "1.34.0")] impl Error for TryFromIntError { #[allow(deprecated)] diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index dd4409198e3..c0be235c120 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -3,7 +3,6 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::ascii; -#[cfg(not(bootstrap))] use crate::error::Error; use crate::intrinsics; use crate::mem; @@ -59,7 +58,6 @@ pub use wrapping::Wrapping; #[cfg(not(no_fp_fmt_parse))] pub use dec2flt::ParseFloatError; -#[cfg(not(bootstrap))] #[cfg(not(no_fp_fmt_parse))] #[stable(feature = "rust1", since = "1.0.0")] impl Error for ParseFloatError { diff --git a/library/core/src/ops/generator.rs b/library/core/src/ops/generator.rs index 3ebd6f8cdbd..fee4beb1e84 100644 --- a/library/core/src/ops/generator.rs +++ b/library/core/src/ops/generator.rs @@ -83,7 +83,6 @@ pub trait Generator { /// `return` statement or implicitly as the last expression of a generator /// literal. For example futures would use this as `Result` as it /// represents a completed future. - #[cfg_attr(bootstrap, lang = "generator_return")] type Return; /// Resumes the execution of this generator. diff --git a/library/core/src/ops/try_trait.rs b/library/core/src/ops/try_trait.rs index 4d0d4e12adb..33df9e6c5cd 100644 --- a/library/core/src/ops/try_trait.rs +++ b/library/core/src/ops/try_trait.rs @@ -223,7 +223,7 @@ pub trait Try: ~const FromResidual { /// Every `Try` type needs to be recreatable from its own associated /// `Residual` type, but can also have additional `FromResidual` implementations /// to support interconversion with other `Try` types. -#[cfg_attr(not(bootstrap), rustc_on_unimplemented( +#[rustc_on_unimplemented( on( all( from_desugaring = "QuestionMark", @@ -302,87 +302,7 @@ pub trait Try: ~const FromResidual { label = "cannot use the `?` operator in {ItemContext} that returns `{Self}`", parent_label = "this function should return `Result` or `Option` to accept `?`" ), -))] -#[cfg_attr(bootstrap, rustc_on_unimplemented( - on( - all( - from_desugaring = "QuestionMark", - _Self = "std::result::Result", - R = "std::option::Option" - ), - message = "the `?` operator can only be used on `Result`s, not `Option`s, \ - in {ItemContext} that returns `Result`", - label = "use `.ok_or(...)?` to provide an error compatible with `{Self}`", - enclosing_scope = "this function returns a `Result`" - ), - on( - all( - from_desugaring = "QuestionMark", - _Self = "std::result::Result", - ), - // There's a special error message in the trait selection code for - // `From` in `?`, so this is not shown for result-in-result errors, - // and thus it can be phrased more strongly than `ControlFlow`'s. - message = "the `?` operator can only be used on `Result`s \ - in {ItemContext} that returns `Result`", - label = "this `?` produces `{R}`, which is incompatible with `{Self}`", - enclosing_scope = "this function returns a `Result`" - ), - on( - all( - from_desugaring = "QuestionMark", - _Self = "std::option::Option", - R = "std::result::Result", - ), - message = "the `?` operator can only be used on `Option`s, not `Result`s, \ - in {ItemContext} that returns `Option`", - label = "use `.ok()?` if you want to discard the `{R}` error information", - enclosing_scope = "this function returns an `Option`" - ), - on( - all( - from_desugaring = "QuestionMark", - _Self = "std::option::Option", - ), - // `Option`-in-`Option` always works, as there's only one possible - // residual, so this can also be phrased strongly. - message = "the `?` operator can only be used on `Option`s \ - in {ItemContext} that returns `Option`", - label = "this `?` produces `{R}`, which is incompatible with `{Self}`", - enclosing_scope = "this function returns an `Option`" - ), - on( - all( - from_desugaring = "QuestionMark", - _Self = "std::ops::ControlFlow", - R = "std::ops::ControlFlow", - ), - message = "the `?` operator in {ItemContext} that returns `ControlFlow` \ - can only be used on other `ControlFlow`s (with the same Break type)", - label = "this `?` produces `{R}`, which is incompatible with `{Self}`", - enclosing_scope = "this function returns a `ControlFlow`", - note = "unlike `Result`, there's no `From`-conversion performed for `ControlFlow`" - ), - on( - all( - from_desugaring = "QuestionMark", - _Self = "std::ops::ControlFlow", - // `R` is not a `ControlFlow`, as that case was matched previously - ), - message = "the `?` operator can only be used on `ControlFlow`s \ - in {ItemContext} that returns `ControlFlow`", - label = "this `?` produces `{R}`, which is incompatible with `{Self}`", - enclosing_scope = "this function returns a `ControlFlow`", - ), - on( - all(from_desugaring = "QuestionMark"), - message = "the `?` operator can only be used in {ItemContext} \ - that returns `Result` or `Option` \ - (or another type that implements `{FromResidual}`)", - label = "cannot use the `?` operator in {ItemContext} that returns `{Self}`", - enclosing_scope = "this function should return `Result` or `Option` to accept `?`" - ), -))] +)] #[rustc_diagnostic_item = "FromResidual"] #[unstable(feature = "try_trait_v2", issue = "84277")] #[const_trait] diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 43e883b8bf7..d898108be58 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -568,7 +568,6 @@ impl *const T { /// /// For non-`Sized` pointees this operation changes only the data pointer, /// leaving the metadata untouched. - #[cfg(not(bootstrap))] #[unstable(feature = "ptr_mask", issue = "98290")] #[must_use = "returns a new pointer rather than modifying its argument"] #[inline(always)] diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index e277b818175..543ab826c4e 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -584,7 +584,6 @@ impl *mut T { /// /// For non-`Sized` pointees this operation changes only the data pointer, /// leaving the metadata untouched. - #[cfg(not(bootstrap))] #[unstable(feature = "ptr_mask", issue = "98290")] #[must_use = "returns a new pointer rather than modifying its argument"] #[inline(always)] diff --git a/library/core/src/str/error.rs b/library/core/src/str/error.rs index 343889b6999..a11b5add42e 100644 --- a/library/core/src/str/error.rs +++ b/library/core/src/str/error.rs @@ -1,6 +1,5 @@ //! Defines utf8 error type. -#[cfg(not(bootstrap))] use crate::error::Error; use crate::fmt; @@ -124,7 +123,6 @@ impl fmt::Display for Utf8Error { } } -#[cfg(not(bootstrap))] #[stable(feature = "rust1", since = "1.0.0")] impl Error for Utf8Error { #[allow(deprecated)] @@ -148,7 +146,6 @@ impl fmt::Display for ParseBoolError { } } -#[cfg(not(bootstrap))] #[stable(feature = "rust1", since = "1.0.0")] impl Error for ParseBoolError { #[allow(deprecated)] diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index f673aa2a44b..fbc0fc397a5 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -2642,5 +2642,4 @@ impl_fn_for_zst! { } #[stable(feature = "rust1", since = "1.0.0")] -#[cfg(not(bootstrap))] impl !crate::error::Error for &str {} diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index 9845d1faf9a..d2db4bb7a46 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -9,7 +9,6 @@ use crate::borrow::Borrow; use crate::cell::Cell; use crate::collections::TryReserveError; use crate::collections::TryReserveErrorKind; -#[cfg(not(bootstrap))] use crate::error::Error; use crate::fmt::{self, Debug}; #[allow(deprecated)] @@ -2160,7 +2159,6 @@ impl<'a, K: Debug, V: Debug> fmt::Display for OccupiedError<'a, K, V> { } } -#[cfg(not(bootstrap))] #[unstable(feature = "map_try_insert", issue = "82766")] impl<'a, K: fmt::Debug, V: fmt::Debug> Error for OccupiedError<'a, K, V> { #[allow(deprecated)] diff --git a/library/std/src/error.rs b/library/std/src/error.rs index e4505959536..05f8fd8de32 100644 --- a/library/std/src/error.rs +++ b/library/std/src/error.rs @@ -4,242 +4,12 @@ #[cfg(test)] mod tests; -#[cfg(bootstrap)] -use core::array; -#[cfg(bootstrap)] -use core::convert::Infallible; - -#[cfg(bootstrap)] -use crate::alloc::{AllocError, LayoutError}; -#[cfg(bootstrap)] -use crate::any::Demand; -#[cfg(bootstrap)] -use crate::any::{Provider, TypeId}; use crate::backtrace::Backtrace; -#[cfg(bootstrap)] -use crate::borrow::Cow; -#[cfg(bootstrap)] -use crate::cell; -#[cfg(bootstrap)] -use crate::char; -#[cfg(bootstrap)] -use crate::fmt::Debug; -#[cfg(bootstrap)] -use crate::fmt::Display; use crate::fmt::{self, Write}; -#[cfg(bootstrap)] -use crate::io; -#[cfg(bootstrap)] -use crate::mem::transmute; -#[cfg(bootstrap)] -use crate::num; -#[cfg(bootstrap)] -use crate::str; -#[cfg(bootstrap)] -use crate::string; -#[cfg(bootstrap)] -use crate::sync::Arc; -#[cfg(bootstrap)] -use crate::time; -#[cfg(not(bootstrap))] #[stable(feature = "rust1", since = "1.0.0")] pub use core::error::Error; -/// `Error` is a trait representing the basic expectations for error values, -/// i.e., values of type `E` in [`Result`]. -/// -/// Errors must describe themselves through the [`Display`] and [`Debug`] -/// traits. Error messages are typically concise lowercase sentences without -/// trailing punctuation: -/// -/// ``` -/// let err = "NaN".parse::().unwrap_err(); -/// assert_eq!(err.to_string(), "invalid digit found in string"); -/// ``` -/// -/// Errors may provide cause information. [`Error::source()`] is generally -/// used when errors cross "abstraction boundaries". If one module must report -/// an error that is caused by an error from a lower-level module, it can allow -/// accessing that error via [`Error::source()`]. This makes it possible for the -/// high-level module to provide its own errors while also revealing some of the -/// implementation for debugging. -#[stable(feature = "rust1", since = "1.0.0")] -#[cfg_attr(not(test), rustc_diagnostic_item = "Error")] -#[cfg(bootstrap)] -pub trait Error: Debug + Display { - /// The lower-level source of this error, if any. - /// - /// # Examples - /// - /// ``` - /// use std::error::Error; - /// use std::fmt; - /// - /// #[derive(Debug)] - /// struct SuperError { - /// source: SuperErrorSideKick, - /// } - /// - /// impl fmt::Display for SuperError { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "SuperError is here!") - /// } - /// } - /// - /// impl Error for SuperError { - /// fn source(&self) -> Option<&(dyn Error + 'static)> { - /// Some(&self.source) - /// } - /// } - /// - /// #[derive(Debug)] - /// struct SuperErrorSideKick; - /// - /// impl fmt::Display for SuperErrorSideKick { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "SuperErrorSideKick is here!") - /// } - /// } - /// - /// impl Error for SuperErrorSideKick {} - /// - /// fn get_super_error() -> Result<(), SuperError> { - /// Err(SuperError { source: SuperErrorSideKick }) - /// } - /// - /// fn main() { - /// match get_super_error() { - /// Err(e) => { - /// println!("Error: {e}"); - /// println!("Caused by: {}", e.source().unwrap()); - /// } - /// _ => println!("No error"), - /// } - /// } - /// ``` - #[stable(feature = "error_source", since = "1.30.0")] - fn source(&self) -> Option<&(dyn Error + 'static)> { - None - } - - /// Gets the `TypeId` of `self`. - #[doc(hidden)] - #[unstable( - feature = "error_type_id", - reason = "this is memory-unsafe to override in user code", - issue = "60784" - )] - fn type_id(&self, _: private::Internal) -> TypeId - where - Self: 'static, - { - TypeId::of::() - } - - /// ``` - /// if let Err(e) = "xc".parse::() { - /// // Print `e` itself, no need for description(). - /// eprintln!("Error: {e}"); - /// } - /// ``` - #[stable(feature = "rust1", since = "1.0.0")] - #[deprecated(since = "1.42.0", note = "use the Display impl or to_string()")] - fn description(&self) -> &str { - "description() is deprecated; use Display" - } - - #[stable(feature = "rust1", since = "1.0.0")] - #[deprecated( - since = "1.33.0", - note = "replaced by Error::source, which can support downcasting" - )] - #[allow(missing_docs)] - fn cause(&self) -> Option<&dyn Error> { - self.source() - } - - /// Provides type based access to context intended for error reports. - /// - /// Used in conjunction with [`Demand::provide_value`] and [`Demand::provide_ref`] to extract - /// references to member variables from `dyn Error` trait objects. - /// - /// # Example - /// - /// ```rust - /// #![feature(provide_any)] - /// #![feature(error_generic_member_access)] - /// use core::fmt; - /// use core::any::Demand; - /// - /// #[derive(Debug)] - /// struct MyBacktrace { - /// // ... - /// } - /// - /// impl MyBacktrace { - /// fn new() -> MyBacktrace { - /// // ... - /// # MyBacktrace {} - /// } - /// } - /// - /// #[derive(Debug)] - /// struct SourceError { - /// // ... - /// } - /// - /// impl fmt::Display for SourceError { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "Example Source Error") - /// } - /// } - /// - /// impl std::error::Error for SourceError {} - /// - /// #[derive(Debug)] - /// struct Error { - /// source: SourceError, - /// backtrace: MyBacktrace, - /// } - /// - /// impl fmt::Display for Error { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "Example Error") - /// } - /// } - /// - /// impl std::error::Error for Error { - /// fn provide<'a>(&'a self, demand: &mut Demand<'a>) { - /// demand - /// .provide_ref::(&self.backtrace) - /// .provide_ref::(&self.source); - /// } - /// } - /// - /// fn main() { - /// let backtrace = MyBacktrace::new(); - /// let source = SourceError {}; - /// let error = Error { source, backtrace }; - /// let dyn_error = &error as &dyn std::error::Error; - /// let backtrace_ref = dyn_error.request_ref::().unwrap(); - /// - /// assert!(core::ptr::eq(&error.backtrace, backtrace_ref)); - /// } - /// ``` - #[unstable(feature = "error_generic_member_access", issue = "99301")] - #[allow(unused_variables)] - fn provide<'a>(&'a self, demand: &mut Demand<'a>) {} -} - -#[cfg(bootstrap)] -#[unstable(feature = "error_generic_member_access", issue = "99301")] -impl<'b> Provider for dyn Error + 'b { - fn provide<'a>(&'a self, demand: &mut Demand<'a>) { - self.provide(demand) - } -} - mod private { // This is a hack to prevent `type_id` from being overridden by `Error` // implementations, since that can enable unsound downcasting. @@ -248,799 +18,6 @@ mod private { pub struct Internal; } -#[cfg(bootstrap)] -#[stable(feature = "rust1", since = "1.0.0")] -impl<'a, E: Error + 'a> From for Box { - /// Converts a type of [`Error`] into a box of dyn [`Error`]. - /// - /// # Examples - /// - /// ``` - /// use std::error::Error; - /// use std::fmt; - /// use std::mem; - /// - /// #[derive(Debug)] - /// struct AnError; - /// - /// impl fmt::Display for AnError { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "An error") - /// } - /// } - /// - /// impl Error for AnError {} - /// - /// let an_error = AnError; - /// assert!(0 == mem::size_of_val(&an_error)); - /// let a_boxed_error = Box::::from(an_error); - /// assert!(mem::size_of::>() == mem::size_of_val(&a_boxed_error)) - /// ``` - fn from(err: E) -> Box { - Box::new(err) - } -} - -#[cfg(bootstrap)] -#[stable(feature = "rust1", since = "1.0.0")] -impl<'a, E: Error + Send + Sync + 'a> From for Box { - /// Converts a type of [`Error`] + [`Send`] + [`Sync`] into a box of - /// dyn [`Error`] + [`Send`] + [`Sync`]. - /// - /// # Examples - /// - /// ``` - /// use std::error::Error; - /// use std::fmt; - /// use std::mem; - /// - /// #[derive(Debug)] - /// struct AnError; - /// - /// impl fmt::Display for AnError { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "An error") - /// } - /// } - /// - /// impl Error for AnError {} - /// - /// unsafe impl Send for AnError {} - /// - /// unsafe impl Sync for AnError {} - /// - /// let an_error = AnError; - /// assert!(0 == mem::size_of_val(&an_error)); - /// let a_boxed_error = Box::::from(an_error); - /// assert!( - /// mem::size_of::>() == mem::size_of_val(&a_boxed_error)) - /// ``` - fn from(err: E) -> Box { - Box::new(err) - } -} - -#[cfg(bootstrap)] -#[stable(feature = "rust1", since = "1.0.0")] -impl From for Box { - /// Converts a [`String`] into a box of dyn [`Error`] + [`Send`] + [`Sync`]. - /// - /// # Examples - /// - /// ``` - /// use std::error::Error; - /// use std::mem; - /// - /// let a_string_error = "a string error".to_string(); - /// let a_boxed_error = Box::::from(a_string_error); - /// assert!( - /// mem::size_of::>() == mem::size_of_val(&a_boxed_error)) - /// ``` - #[inline] - fn from(err: String) -> Box { - struct StringError(String); - - impl Error for StringError { - #[allow(deprecated)] - fn description(&self) -> &str { - &self.0 - } - } - - impl Display for StringError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - Display::fmt(&self.0, f) - } - } - - // Purposefully skip printing "StringError(..)" - impl Debug for StringError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - Debug::fmt(&self.0, f) - } - } - - Box::new(StringError(err)) - } -} - -#[cfg(bootstrap)] -#[stable(feature = "string_box_error", since = "1.6.0")] -impl From for Box { - /// Converts a [`String`] into a box of dyn [`Error`]. - /// - /// # Examples - /// - /// ``` - /// use std::error::Error; - /// use std::mem; - /// - /// let a_string_error = "a string error".to_string(); - /// let a_boxed_error = Box::::from(a_string_error); - /// assert!(mem::size_of::>() == mem::size_of_val(&a_boxed_error)) - /// ``` - fn from(str_err: String) -> Box { - let err1: Box = From::from(str_err); - let err2: Box = err1; - err2 - } -} - -#[cfg(bootstrap)] -#[stable(feature = "rust1", since = "1.0.0")] -impl<'a> From<&str> for Box { - /// Converts a [`str`] into a box of dyn [`Error`] + [`Send`] + [`Sync`]. - /// - /// [`str`]: prim@str - /// - /// # Examples - /// - /// ``` - /// use std::error::Error; - /// use std::mem; - /// - /// let a_str_error = "a str error"; - /// let a_boxed_error = Box::::from(a_str_error); - /// assert!( - /// mem::size_of::>() == mem::size_of_val(&a_boxed_error)) - /// ``` - #[inline] - fn from(err: &str) -> Box { - From::from(String::from(err)) - } -} - -#[cfg(bootstrap)] -#[stable(feature = "string_box_error", since = "1.6.0")] -impl From<&str> for Box { - /// Converts a [`str`] into a box of dyn [`Error`]. - /// - /// [`str`]: prim@str - /// - /// # Examples - /// - /// ``` - /// use std::error::Error; - /// use std::mem; - /// - /// let a_str_error = "a str error"; - /// let a_boxed_error = Box::::from(a_str_error); - /// assert!(mem::size_of::>() == mem::size_of_val(&a_boxed_error)) - /// ``` - fn from(err: &str) -> Box { - From::from(String::from(err)) - } -} - -#[cfg(bootstrap)] -#[stable(feature = "cow_box_error", since = "1.22.0")] -impl<'a, 'b> From> for Box { - /// Converts a [`Cow`] into a box of dyn [`Error`] + [`Send`] + [`Sync`]. - /// - /// # Examples - /// - /// ``` - /// use std::error::Error; - /// use std::mem; - /// use std::borrow::Cow; - /// - /// let a_cow_str_error = Cow::from("a str error"); - /// let a_boxed_error = Box::::from(a_cow_str_error); - /// assert!( - /// mem::size_of::>() == mem::size_of_val(&a_boxed_error)) - /// ``` - fn from(err: Cow<'b, str>) -> Box { - From::from(String::from(err)) - } -} - -#[cfg(bootstrap)] -#[stable(feature = "cow_box_error", since = "1.22.0")] -impl<'a> From> for Box { - /// Converts a [`Cow`] into a box of dyn [`Error`]. - /// - /// # Examples - /// - /// ``` - /// use std::error::Error; - /// use std::mem; - /// use std::borrow::Cow; - /// - /// let a_cow_str_error = Cow::from("a str error"); - /// let a_boxed_error = Box::::from(a_cow_str_error); - /// assert!(mem::size_of::>() == mem::size_of_val(&a_boxed_error)) - /// ``` - fn from(err: Cow<'a, str>) -> Box { - From::from(String::from(err)) - } -} - -#[cfg(bootstrap)] -#[unstable(feature = "never_type", issue = "35121")] -impl Error for ! {} - -#[cfg(bootstrap)] -#[unstable( - feature = "allocator_api", - reason = "the precise API and guarantees it provides may be tweaked.", - issue = "32838" -)] -impl Error for AllocError {} - -#[cfg(bootstrap)] -#[stable(feature = "alloc_layout", since = "1.28.0")] -impl Error for LayoutError {} - -#[cfg(bootstrap)] -#[stable(feature = "rust1", since = "1.0.0")] -impl Error for str::ParseBoolError { - #[allow(deprecated)] - fn description(&self) -> &str { - "failed to parse bool" - } -} - -#[cfg(bootstrap)] -#[stable(feature = "rust1", since = "1.0.0")] -impl Error for str::Utf8Error { - #[allow(deprecated)] - fn description(&self) -> &str { - "invalid utf-8: corrupt contents" - } -} - -#[cfg(bootstrap)] -#[stable(feature = "rust1", since = "1.0.0")] -impl Error for num::ParseIntError { - #[allow(deprecated)] - fn description(&self) -> &str { - self.__description() - } -} - -#[cfg(bootstrap)] -#[stable(feature = "try_from", since = "1.34.0")] -impl Error for num::TryFromIntError { - #[allow(deprecated)] - fn description(&self) -> &str { - self.__description() - } -} - -#[cfg(bootstrap)] -#[stable(feature = "try_from", since = "1.34.0")] -impl Error for array::TryFromSliceError { - #[allow(deprecated)] - fn description(&self) -> &str { - self.__description() - } -} - -#[cfg(bootstrap)] -#[stable(feature = "rust1", since = "1.0.0")] -impl Error for num::ParseFloatError { - #[allow(deprecated)] - fn description(&self) -> &str { - self.__description() - } -} - -#[cfg(bootstrap)] -#[stable(feature = "rust1", since = "1.0.0")] -impl Error for string::FromUtf8Error { - #[allow(deprecated)] - fn description(&self) -> &str { - "invalid utf-8" - } -} - -#[cfg(bootstrap)] -#[stable(feature = "rust1", since = "1.0.0")] -impl Error for string::FromUtf16Error { - #[allow(deprecated)] - fn description(&self) -> &str { - "invalid utf-16" - } -} - -#[cfg(bootstrap)] -#[stable(feature = "str_parse_error2", since = "1.8.0")] -impl Error for Infallible { - fn description(&self) -> &str { - match *self {} - } -} - -#[cfg(bootstrap)] -#[stable(feature = "decode_utf16", since = "1.9.0")] -impl Error for char::DecodeUtf16Error { - #[allow(deprecated)] - fn description(&self) -> &str { - "unpaired surrogate found" - } -} - -#[cfg(bootstrap)] -#[stable(feature = "u8_from_char", since = "1.59.0")] -impl Error for char::TryFromCharError {} - -#[cfg(bootstrap)] -#[unstable(feature = "map_try_insert", issue = "82766")] -impl<'a, K: Debug + Ord, V: Debug> Error - for crate::collections::btree_map::OccupiedError<'a, K, V> -{ - #[allow(deprecated)] - fn description(&self) -> &str { - "key already exists" - } -} - -#[cfg(bootstrap)] -#[unstable(feature = "map_try_insert", issue = "82766")] -impl<'a, K: Debug, V: Debug> Error for crate::collections::hash_map::OccupiedError<'a, K, V> { - #[allow(deprecated)] - fn description(&self) -> &str { - "key already exists" - } -} - -#[cfg(bootstrap)] -#[stable(feature = "box_error", since = "1.8.0")] -impl Error for Box { - #[allow(deprecated, deprecated_in_future)] - fn description(&self) -> &str { - Error::description(&**self) - } - - #[allow(deprecated)] - fn cause(&self) -> Option<&dyn Error> { - Error::cause(&**self) - } - - fn source(&self) -> Option<&(dyn Error + 'static)> { - Error::source(&**self) - } -} - -#[cfg(bootstrap)] -#[unstable(feature = "thin_box", issue = "92791")] -impl crate::error::Error for crate::boxed::ThinBox { - fn source(&self) -> Option<&(dyn crate::error::Error + 'static)> { - use core::ops::Deref; - self.deref().source() - } -} - -#[cfg(bootstrap)] -#[stable(feature = "error_by_ref", since = "1.51.0")] -impl<'a, T: Error + ?Sized> Error for &'a T { - #[allow(deprecated, deprecated_in_future)] - fn description(&self) -> &str { - Error::description(&**self) - } - - #[allow(deprecated)] - fn cause(&self) -> Option<&dyn Error> { - Error::cause(&**self) - } - - fn source(&self) -> Option<&(dyn Error + 'static)> { - Error::source(&**self) - } - - fn provide<'b>(&'b self, demand: &mut Demand<'b>) { - Error::provide(&**self, demand); - } -} - -#[cfg(bootstrap)] -#[stable(feature = "arc_error", since = "1.52.0")] -impl Error for Arc { - #[allow(deprecated, deprecated_in_future)] - fn description(&self) -> &str { - Error::description(&**self) - } - - #[allow(deprecated)] - fn cause(&self) -> Option<&dyn Error> { - Error::cause(&**self) - } - - fn source(&self) -> Option<&(dyn Error + 'static)> { - Error::source(&**self) - } - - fn provide<'a>(&'a self, demand: &mut Demand<'a>) { - Error::provide(&**self, demand); - } -} - -#[cfg(bootstrap)] -#[stable(feature = "fmt_error", since = "1.11.0")] -impl Error for fmt::Error { - #[allow(deprecated)] - fn description(&self) -> &str { - "an error occurred when formatting an argument" - } -} - -#[cfg(bootstrap)] -#[stable(feature = "try_borrow", since = "1.13.0")] -impl Error for cell::BorrowError { - #[allow(deprecated)] - fn description(&self) -> &str { - "already mutably borrowed" - } -} - -#[cfg(bootstrap)] -#[stable(feature = "try_borrow", since = "1.13.0")] -impl Error for cell::BorrowMutError { - #[allow(deprecated)] - fn description(&self) -> &str { - "already borrowed" - } -} - -#[cfg(bootstrap)] -#[stable(feature = "try_from", since = "1.34.0")] -impl Error for char::CharTryFromError { - #[allow(deprecated)] - fn description(&self) -> &str { - "converted integer out of range for `char`" - } -} - -#[cfg(bootstrap)] -#[stable(feature = "char_from_str", since = "1.20.0")] -impl Error for char::ParseCharError { - #[allow(deprecated)] - fn description(&self) -> &str { - self.__description() - } -} - -#[cfg(bootstrap)] -#[stable(feature = "try_reserve", since = "1.57.0")] -impl Error for alloc::collections::TryReserveError {} - -#[cfg(bootstrap)] -#[unstable(feature = "duration_checked_float", issue = "83400")] -impl Error for time::FromFloatSecsError {} - -#[cfg(bootstrap)] -#[stable(feature = "rust1", since = "1.0.0")] -impl Error for alloc::ffi::NulError { - #[allow(deprecated)] - fn description(&self) -> &str { - "nul byte found in data" - } -} - -#[cfg(bootstrap)] -#[stable(feature = "rust1", since = "1.0.0")] -impl From for io::Error { - /// Converts a [`alloc::ffi::NulError`] into a [`io::Error`]. - fn from(_: alloc::ffi::NulError) -> io::Error { - io::const_io_error!(io::ErrorKind::InvalidInput, "data provided contains a nul byte") - } -} - -#[cfg(bootstrap)] -#[stable(feature = "frombyteswithnulerror_impls", since = "1.17.0")] -impl Error for core::ffi::FromBytesWithNulError { - #[allow(deprecated)] - fn description(&self) -> &str { - self.__description() - } -} - -#[cfg(bootstrap)] -#[unstable(feature = "cstr_from_bytes_until_nul", issue = "95027")] -impl Error for core::ffi::FromBytesUntilNulError {} - -#[cfg(bootstrap)] -#[stable(feature = "cstring_from_vec_with_nul", since = "1.58.0")] -impl Error for alloc::ffi::FromVecWithNulError {} - -#[cfg(bootstrap)] -#[stable(feature = "cstring_into", since = "1.7.0")] -impl Error for alloc::ffi::IntoStringError { - #[allow(deprecated)] - fn description(&self) -> &str { - "C string contained non-utf8 bytes" - } - - fn source(&self) -> Option<&(dyn Error + 'static)> { - Some(self.__source()) - } -} - -#[cfg(bootstrap)] -impl<'a> dyn Error + 'a { - /// Request a reference of type `T` as context about this error. - #[unstable(feature = "error_generic_member_access", issue = "99301")] - pub fn request_ref(&'a self) -> Option<&'a T> { - core::any::request_ref(self) - } - - /// Request a value of type `T` as context about this error. - #[unstable(feature = "error_generic_member_access", issue = "99301")] - pub fn request_value(&'a self) -> Option { - core::any::request_value(self) - } -} - -// Copied from `any.rs`. -#[cfg(bootstrap)] -impl dyn Error + 'static { - /// Returns `true` if the inner type is the same as `T`. - #[stable(feature = "error_downcast", since = "1.3.0")] - #[inline] - pub fn is(&self) -> bool { - // Get `TypeId` of the type this function is instantiated with. - let t = TypeId::of::(); - - // Get `TypeId` of the type in the trait object (`self`). - let concrete = self.type_id(private::Internal); - - // Compare both `TypeId`s on equality. - t == concrete - } - - /// Returns some reference to the inner value if it is of type `T`, or - /// `None` if it isn't. - #[stable(feature = "error_downcast", since = "1.3.0")] - #[inline] - pub fn downcast_ref(&self) -> Option<&T> { - if self.is::() { - unsafe { Some(&*(self as *const dyn Error as *const T)) } - } else { - None - } - } - - /// Returns some mutable reference to the inner value if it is of type `T`, or - /// `None` if it isn't. - #[stable(feature = "error_downcast", since = "1.3.0")] - #[inline] - pub fn downcast_mut(&mut self) -> Option<&mut T> { - if self.is::() { - unsafe { Some(&mut *(self as *mut dyn Error as *mut T)) } - } else { - None - } - } -} - -#[cfg(bootstrap)] -impl dyn Error + 'static + Send { - /// Forwards to the method defined on the type `dyn Error`. - #[stable(feature = "error_downcast", since = "1.3.0")] - #[inline] - pub fn is(&self) -> bool { - ::is::(self) - } - - /// Forwards to the method defined on the type `dyn Error`. - #[stable(feature = "error_downcast", since = "1.3.0")] - #[inline] - pub fn downcast_ref(&self) -> Option<&T> { - ::downcast_ref::(self) - } - - /// Forwards to the method defined on the type `dyn Error`. - #[stable(feature = "error_downcast", since = "1.3.0")] - #[inline] - pub fn downcast_mut(&mut self) -> Option<&mut T> { - ::downcast_mut::(self) - } - - /// Request a reference of type `T` as context about this error. - #[unstable(feature = "error_generic_member_access", issue = "99301")] - pub fn request_ref(&self) -> Option<&T> { - ::request_ref(self) - } - - /// Request a value of type `T` as context about this error. - #[unstable(feature = "error_generic_member_access", issue = "99301")] - pub fn request_value(&self) -> Option { - ::request_value(self) - } -} - -#[cfg(bootstrap)] -impl dyn Error + 'static + Send + Sync { - /// Forwards to the method defined on the type `dyn Error`. - #[stable(feature = "error_downcast", since = "1.3.0")] - #[inline] - pub fn is(&self) -> bool { - ::is::(self) - } - - /// Forwards to the method defined on the type `dyn Error`. - #[stable(feature = "error_downcast", since = "1.3.0")] - #[inline] - pub fn downcast_ref(&self) -> Option<&T> { - ::downcast_ref::(self) - } - - /// Forwards to the method defined on the type `dyn Error`. - #[stable(feature = "error_downcast", since = "1.3.0")] - #[inline] - pub fn downcast_mut(&mut self) -> Option<&mut T> { - ::downcast_mut::(self) - } - - /// Request a reference of type `T` as context about this error. - #[unstable(feature = "error_generic_member_access", issue = "99301")] - pub fn request_ref(&self) -> Option<&T> { - ::request_ref(self) - } - - /// Request a value of type `T` as context about this error. - #[unstable(feature = "error_generic_member_access", issue = "99301")] - pub fn request_value(&self) -> Option { - ::request_value(self) - } -} - -#[cfg(bootstrap)] -impl dyn Error { - #[inline] - #[stable(feature = "error_downcast", since = "1.3.0")] - /// Attempts to downcast the box to a concrete type. - pub fn downcast(self: Box) -> Result, Box> { - if self.is::() { - unsafe { - let raw: *mut dyn Error = Box::into_raw(self); - Ok(Box::from_raw(raw as *mut T)) - } - } else { - Err(self) - } - } - - /// Returns an iterator starting with the current error and continuing with - /// recursively calling [`Error::source`]. - /// - /// If you want to omit the current error and only use its sources, - /// use `skip(1)`. - /// - /// # Examples - /// - /// ``` - /// #![feature(error_iter)] - /// use std::error::Error; - /// use std::fmt; - /// - /// #[derive(Debug)] - /// struct A; - /// - /// #[derive(Debug)] - /// struct B(Option>); - /// - /// impl fmt::Display for A { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "A") - /// } - /// } - /// - /// impl fmt::Display for B { - /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "B") - /// } - /// } - /// - /// impl Error for A {} - /// - /// impl Error for B { - /// fn source(&self) -> Option<&(dyn Error + 'static)> { - /// self.0.as_ref().map(|e| e.as_ref()) - /// } - /// } - /// - /// let b = B(Some(Box::new(A))); - /// - /// // let err : Box = b.into(); // or - /// let err = &b as &(dyn Error); - /// - /// let mut iter = err.sources(); - /// - /// assert_eq!("B".to_string(), iter.next().unwrap().to_string()); - /// assert_eq!("A".to_string(), iter.next().unwrap().to_string()); - /// assert!(iter.next().is_none()); - /// assert!(iter.next().is_none()); - /// ``` - #[unstable(feature = "error_iter", issue = "58520")] - #[inline] - pub fn sources(&self) -> Sources<'_> { - // You may think this method would be better in the Error trait, and you'd be right. - // Unfortunately that doesn't work, not because of the object safety rules but because we - // save a reference to self in Sources below as a trait object. If this method was - // declared in Error, then self would have the type &T where T is some concrete type which - // implements Error. We would need to coerce self to have type &dyn Error, but that requires - // that Self has a known size (i.e., Self: Sized). We can't put that bound on Error - // since that would forbid Error trait objects, and we can't put that bound on the method - // because that means the method can't be called on trait objects (we'd also need the - // 'static bound, but that isn't allowed because methods with bounds on Self other than - // Sized are not object-safe). Requiring an Unsize bound is not backwards compatible. - - Sources { current: Some(self) } - } -} - -/// An iterator over an [`Error`] and its sources. -/// -/// If you want to omit the initial error and only process -/// its sources, use `skip(1)`. -#[unstable(feature = "error_iter", issue = "58520")] -#[derive(Clone, Debug)] -#[cfg(bootstrap)] -pub struct Sources<'a> { - current: Option<&'a (dyn Error + 'static)>, -} - -#[cfg(bootstrap)] -#[unstable(feature = "error_iter", issue = "58520")] -impl<'a> Iterator for Sources<'a> { - type Item = &'a (dyn Error + 'static); - - fn next(&mut self) -> Option { - let current = self.current; - self.current = self.current.and_then(Error::source); - current - } -} - -#[cfg(bootstrap)] -impl dyn Error + Send { - #[inline] - #[stable(feature = "error_downcast", since = "1.3.0")] - /// Attempts to downcast the box to a concrete type. - pub fn downcast(self: Box) -> Result, Box> { - let err: Box = self; - ::downcast(err).map_err(|s| unsafe { - // Reapply the `Send` marker. - transmute::, Box>(s) - }) - } -} - -#[cfg(bootstrap)] -impl dyn Error + Send + Sync { - #[inline] - #[stable(feature = "error_downcast", since = "1.3.0")] - /// Attempts to downcast the box to a concrete type. - pub fn downcast(self: Box) -> Result, Box> { - let err: Box = self; - ::downcast(err).map_err(|s| unsafe { - // Reapply the `Send + Sync` marker. - transmute::, Box>(s) - }) - } -} - /// An error reporter that prints an error and its sources. /// /// Report also exposes configuration options for formatting the error sources, either entirely on a diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 29b09fcc527..feb3fb989a7 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -76,7 +76,6 @@ impl fmt::Debug for Error { } } -#[cfg(not(bootstrap))] #[stable(feature = "rust1", since = "1.0.0")] impl From for Error { /// Converts a [`alloc::ffi::NulError`] into a [`Error`]. diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 3131dd47269..c2b7a4d8648 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -252,10 +252,8 @@ #![feature(dropck_eyepatch)] #![feature(exhaustive_patterns)] #![feature(intra_doc_pointers)] -#![cfg_attr(bootstrap, feature(label_break_value))] #![feature(lang_items)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(linkage)] #![feature(link_cfg)] #![feature(min_specialization)] @@ -282,9 +280,9 @@ #![feature(cstr_internals)] #![feature(duration_checked_float)] #![feature(duration_constants)] -#![cfg_attr(not(bootstrap), feature(error_generic_member_access))] -#![cfg_attr(not(bootstrap), feature(error_in_core))] -#![cfg_attr(not(bootstrap), feature(error_iter))] +#![feature(error_generic_member_access)] +#![feature(error_in_core)] +#![feature(error_iter)] #![feature(exact_size_is_empty)] #![feature(exclusive_wrapper)] #![feature(extend_one)] diff --git a/library/std/src/rt.rs b/library/std/src/rt.rs index 98f6cc7aa3e..b8bcdbece0a 100644 --- a/library/std/src/rt.rs +++ b/library/std/src/rt.rs @@ -160,15 +160,12 @@ fn lang_start( main: fn() -> T, argc: isize, argv: *const *const u8, - #[cfg(not(bootstrap))] sigpipe: u8, + sigpipe: u8, ) -> isize { let Ok(v) = lang_start_internal( &move || crate::sys_common::backtrace::__rust_begin_short_backtrace(main).report().to_i32(), argc, argv, - #[cfg(bootstrap)] - 2, // Temporary inlining of sigpipe::DEFAULT until bootstrap stops being special - #[cfg(not(bootstrap))] sigpipe, ); v diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index f973fd0889e..f06d2cf108d 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2535,7 +2535,6 @@ mod size_asserts { // These are in alphabetical order, which is easy to maintain. static_assert_size!(Crate, 72); // frequently moved by-value static_assert_size!(DocFragment, 32); - #[cfg(not(bootstrap))] static_assert_size!(GenericArg, 56); static_assert_size!(GenericArgs, 32); static_assert_size!(GenericParamDef, 56); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 23ad0c30f21..23e3de45fa5 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -9,14 +9,12 @@ #![feature(control_flow_enum)] #![feature(drain_filter)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(test)] #![feature(never_type)] #![feature(once_cell)] #![feature(type_ascription)] #![feature(iter_intersperse)] #![feature(type_alias_impl_trait)] -#![cfg_attr(bootstrap, feature(generic_associated_types))] #![recursion_limit = "256"] #![warn(rustc::internal)] #![allow(clippy::collapsible_if, clippy::collapsible_else_if)] diff --git a/src/test/mir-opt/issue-101867.rs b/src/test/mir-opt/issue-101867.rs index 931396e2171..fcbe5a2b90a 100644 --- a/src/test/mir-opt/issue-101867.rs +++ b/src/test/mir-opt/issue-101867.rs @@ -1,4 +1,3 @@ -#![cfg_attr(bootstrap, feature(let_else))] // EMIT_MIR issue_101867.main.mir_map.0.mir fn main() { diff --git a/src/test/ui/let-else/const-fn.rs b/src/test/ui/let-else/const-fn.rs index 336b0b4b72a..a3921b8033f 100644 --- a/src/test/ui/let-else/const-fn.rs +++ b/src/test/ui/let-else/const-fn.rs @@ -1,7 +1,6 @@ // run-pass // issue #101932 -#![cfg_attr(bootstrap, feature(let_else))] const fn foo(a: Option) -> i32 { let Some(a) = a else { diff --git a/src/tools/clippy/clippy_dev/src/lib.rs b/src/tools/clippy/clippy_dev/src/lib.rs index 54c7456a2a3..80bb83af43b 100644 --- a/src/tools/clippy/clippy_dev/src/lib.rs +++ b/src/tools/clippy/clippy_dev/src/lib.rs @@ -1,5 +1,4 @@ #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![feature(rustc_private)] #![cfg_attr(feature = "deny-warnings", deny(warnings))] diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs index 298566cb5b6..00bf6445c12 100644 --- a/src/tools/clippy/clippy_lints/src/lib.rs +++ b/src/tools/clippy/clippy_lints/src/lib.rs @@ -5,7 +5,6 @@ #![feature(drain_filter)] #![feature(iter_intersperse)] #![feature(let_chains)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(lint_reasons)] #![feature(never_type)] #![feature(once_cell)] diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 9343cf457b3..b1abd3b04c9 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -3,7 +3,6 @@ #![feature(control_flow_enum)] #![feature(let_chains)] #![feature(lint_reasons)] -#![cfg_attr(bootstrap, feature(let_else))] #![feature(once_cell)] #![feature(rustc_private)] #![recursion_limit = "512"] -- cgit 1.4.1-3-g733a5