diff options
| author | Jeremy Fitzhardinge <jeremy@goop.org> | 2022-04-14 23:07:57 -0700 |
|---|---|---|
| committer | Jeremy Fitzhardinge <jsgf@fb.com> | 2022-04-15 11:19:06 -0700 |
| commit | 1be1157d7551d3664b6f55d5eea85fb08b86761b (patch) | |
| tree | c922665f4c5820a0bb1f53da9cb8296788812913 /compiler/rustc_errors/src | |
| parent | e7575f9670f3c837def3d186ae09366c75c7632e (diff) | |
| download | rust-1be1157d7551d3664b6f55d5eea85fb08b86761b.tar.gz rust-1be1157d7551d3664b6f55d5eea85fb08b86761b.zip | |
Remove `--extern-location` and all associated code
`--extern-location` was an experiment to investigate the best way to generate useful diagnostics for unused dependency warnings by enabling a build system to identify the corresponding build config. While I did successfully use this, I've since been convinced the alternative `--json unused-externs` mechanism is the way to go, and there's no point in having two mechanisms with basically the same functionality. This effectively reverts https://github.com/rust-lang/rust/pull/72603
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/json.rs | 67 | ||||
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 39 |
3 files changed, 3 insertions, 128 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index ecb3cdd627c..2ae599a134b 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -1,12 +1,11 @@ use crate::snippet::Style; use crate::{ CodeSuggestion, DiagnosticMessage, Level, MultiSpan, Substitution, SubstitutionPart, - SuggestionStyle, ToolMetadata, + SuggestionStyle, }; use rustc_data_structures::stable_map::FxHashMap; use rustc_error_messages::FluentValue; use rustc_lint_defs::{Applicability, LintExpectationId}; -use rustc_serialize::json::Json; use rustc_span::edition::LATEST_STABLE_EDITION; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; @@ -554,7 +553,6 @@ impl Diagnostic { msg: msg.into(), style, applicability, - tool_metadata: Default::default(), }); self } @@ -582,7 +580,6 @@ impl Diagnostic { msg: msg.into(), style: SuggestionStyle::CompletelyHidden, applicability, - tool_metadata: Default::default(), }); self } @@ -637,7 +634,6 @@ impl Diagnostic { msg: msg.into(), style, applicability, - tool_metadata: Default::default(), }); self } @@ -680,7 +676,6 @@ impl Diagnostic { msg: msg.into(), style: SuggestionStyle::ShowCode, applicability, - tool_metadata: Default::default(), }); self } @@ -705,7 +700,6 @@ impl Diagnostic { msg: msg.into(), style: SuggestionStyle::ShowCode, applicability, - tool_metadata: Default::default(), }); self } @@ -774,23 +768,6 @@ impl Diagnostic { self } - /// Adds a suggestion intended only for a tool. The intent is that the metadata encodes - /// the suggestion in a tool-specific way, as it may not even directly involve Rust code. - pub fn tool_only_suggestion_with_metadata( - &mut self, - msg: impl Into<DiagnosticMessage>, - applicability: Applicability, - tool_metadata: Json, - ) { - self.push_suggestion(CodeSuggestion { - substitutions: vec![], - msg: msg.into(), - style: SuggestionStyle::CompletelyHidden, - applicability, - tool_metadata: ToolMetadata::new(tool_metadata), - }) - } - pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self { self.span = sp.into(); if let Some(span) = self.span.primary_span() { diff --git a/compiler/rustc_errors/src/json.rs b/compiler/rustc_errors/src/json.rs index 0139007da42..d680e7fab70 100644 --- a/compiler/rustc_errors/src/json.rs +++ b/compiler/rustc_errors/src/json.rs @@ -14,7 +14,6 @@ use rustc_span::source_map::{FilePathMapping, SourceMap}; use crate::emitter::{Emitter, HumanReadableErrorType}; use crate::registry::Registry; use crate::DiagnosticId; -use crate::ToolMetadata; use crate::{ CodeSuggestion, FluentBundle, LazyFallbackBundle, MultiSpan, SpanLabel, SubDiagnostic, }; @@ -30,7 +29,6 @@ use std::sync::{Arc, Mutex}; use std::vec; use rustc_serialize::json::{as_json, as_pretty_json}; -use rustc_serialize::{Encodable, Encoder}; #[cfg(test)] mod tests; @@ -205,8 +203,7 @@ impl Emitter for JsonEmitter { // The following data types are provided just for serialisation. -// NOTE: this has a manual implementation of Encodable which needs to be updated in -// parallel. +#[derive(Encodable)] struct Diagnostic { /// The primary error message. message: String, @@ -218,65 +215,6 @@ struct Diagnostic { children: Vec<Diagnostic>, /// The message as rustc would render it. rendered: Option<String>, - /// Extra tool metadata - tool_metadata: ToolMetadata, -} - -macro_rules! encode_fields { - ( - $enc:expr, // encoder - $idx:expr, // starting field index - $struct:expr, // struct we're serializing - $struct_name:ident, // struct name - [ $($name:ident),+$(,)? ], // fields to encode - [ $($ignore:ident),+$(,)? ] // fields we're skipping - ) => { - { - // Pattern match to make sure all fields are accounted for - let $struct_name { $($name,)+ $($ignore: _,)+ } = $struct; - let mut idx = $idx; - $( - $enc.emit_struct_field( - stringify!($name), - idx == 0, - |enc| $name.encode(enc), - )?; - idx += 1; - )+ - idx - } - }; -} - -// Special-case encoder to skip tool_metadata if not set -impl<E: Encoder> Encodable<E> for Diagnostic { - fn encode(&self, s: &mut E) -> Result<(), E::Error> { - s.emit_struct(false, |s| { - let mut idx = 0; - - idx = encode_fields!( - s, - idx, - self, - Self, - [message, code, level, spans, children, rendered], - [tool_metadata] - ); - if self.tool_metadata.is_set() { - idx = encode_fields!( - s, - idx, - self, - Self, - [tool_metadata], - [message, code, level, spans, children, rendered] - ); - } - - let _ = idx; - Ok(()) - }) - } } #[derive(Encodable)] @@ -380,7 +318,6 @@ impl Diagnostic { spans: DiagnosticSpan::from_suggestion(sugg, &args, je), children: vec![], rendered: None, - tool_metadata: sugg.tool_metadata.clone(), } }); @@ -428,7 +365,6 @@ impl Diagnostic { .chain(sugg) .collect(), rendered: Some(output), - tool_metadata: ToolMetadata::default(), } } @@ -449,7 +385,6 @@ impl Diagnostic { .unwrap_or_else(|| DiagnosticSpan::from_multispan(&diag.span, args, je)), children: vec![], rendered: None, - tool_metadata: ToolMetadata::default(), } } } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index cfad1fc01ab..9168705bcff 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -36,13 +36,11 @@ pub use rustc_error_messages::{ LazyFallbackBundle, MultiSpan, SpanLabel, DEFAULT_LOCALE_RESOURCES, }; pub use rustc_lint_defs::{pluralize, Applicability}; -use rustc_serialize::json::Json; -use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_span::source_map::SourceMap; use rustc_span::{Loc, Span}; use std::borrow::Cow; -use std::hash::{Hash, Hasher}; +use std::hash::Hash; use std::num::NonZeroUsize; use std::panic; use std::path::Path; @@ -93,39 +91,6 @@ impl SuggestionStyle { } } -#[derive(Clone, Debug, PartialEq, Default)] -pub struct ToolMetadata(pub Option<Json>); - -impl ToolMetadata { - fn new(json: Json) -> Self { - ToolMetadata(Some(json)) - } - - fn is_set(&self) -> bool { - self.0.is_some() - } -} - -impl Hash for ToolMetadata { - fn hash<H: Hasher>(&self, _state: &mut H) {} -} - -// Doesn't really need to round-trip -impl<D: Decoder> Decodable<D> for ToolMetadata { - fn decode(_d: &mut D) -> Self { - ToolMetadata(None) - } -} - -impl<S: Encoder> Encodable<S> for ToolMetadata { - fn encode(&self, e: &mut S) -> Result<(), S::Error> { - match &self.0 { - None => e.emit_unit(), - Some(json) => json.encode(e), - } - } -} - #[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct CodeSuggestion { /// Each substitute can have multiple variants due to multiple @@ -159,8 +124,6 @@ pub struct CodeSuggestion { /// which are useful for users but not useful for /// tools like rustfix pub applicability: Applicability, - /// Tool-specific metadata - pub tool_metadata: ToolMetadata, } #[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] |
