diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2020-06-11 15:49:57 +0100 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2020-08-14 17:34:30 +0100 |
| commit | cbcef3effcf64bd0d89ea2dc8973e18d7fcf94c3 (patch) | |
| tree | cf11d5e77bdfe87b0a19d5f93ff251b256770325 /src/librustc_errors | |
| parent | 55b9adfafa11b2ced5c0477c949fd875b19b3877 (diff) | |
| download | rust-cbcef3effcf64bd0d89ea2dc8973e18d7fcf94c3.tar.gz rust-cbcef3effcf64bd0d89ea2dc8973e18d7fcf94c3.zip | |
Rework `rustc_serialize`
- Move the type parameter from `encode` and `decode` methods to the trait. - Remove `UseSpecialized(En|De)codable` traits. - Remove blanket impls for references. - Add `RefDecodable` trait to allow deserializing to arena-allocated references safely. - Remove ability to (de)serialize HIR. - Create proc-macros `(Ty)?(En|De)codable` to help implement these new traits.
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/librustc_errors/diagnostic.rs | 6 | ||||
| -rw-r--r-- | src/librustc_errors/json.rs | 12 | ||||
| -rw-r--r-- | src/librustc_errors/json/tests.rs | 4 | ||||
| -rw-r--r-- | src/librustc_errors/lib.rs | 17 | ||||
| -rw-r--r-- | src/librustc_errors/snippet.rs | 2 |
6 files changed, 23 insertions, 19 deletions
diff --git a/src/librustc_errors/Cargo.toml b/src/librustc_errors/Cargo.toml index d0f04c3fe76..c17d61dae9f 100644 --- a/src/librustc_errors/Cargo.toml +++ b/src/librustc_errors/Cargo.toml @@ -13,6 +13,7 @@ doctest = false log = { package = "tracing", version = "0.1" } rustc_serialize = { path = "../librustc_serialize" } rustc_span = { path = "../librustc_span" } +rustc_macros = { path = "../librustc_macros" } rustc_data_structures = { path = "../librustc_data_structures" } unicode-width = "0.1.4" atty = "0.2" diff --git a/src/librustc_errors/diagnostic.rs b/src/librustc_errors/diagnostic.rs index acaa26c6ad2..cd4b5d56f36 100644 --- a/src/librustc_errors/diagnostic.rs +++ b/src/librustc_errors/diagnostic.rs @@ -9,7 +9,7 @@ use rustc_span::{MultiSpan, Span, DUMMY_SP}; use std::fmt; #[must_use] -#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct Diagnostic { pub level: Level, pub message: Vec<(String, Style)>, @@ -24,14 +24,14 @@ pub struct Diagnostic { pub sort_span: Span, } -#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, Encodable, Decodable)] pub enum DiagnosticId { Error(String), Lint(String), } /// For example a note attached to an error. -#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct SubDiagnostic { pub level: Level, pub message: Vec<(String, Style)>, diff --git a/src/librustc_errors/json.rs b/src/librustc_errors/json.rs index 24186198fd2..750d36d3d89 100644 --- a/src/librustc_errors/json.rs +++ b/src/librustc_errors/json.rs @@ -145,7 +145,7 @@ impl Emitter for JsonEmitter { // The following data types are provided just for serialisation. -#[derive(RustcEncodable)] +#[derive(Encodable)] struct Diagnostic { /// The primary error message. message: String, @@ -159,7 +159,7 @@ struct Diagnostic { rendered: Option<String>, } -#[derive(RustcEncodable)] +#[derive(Encodable)] struct DiagnosticSpan { file_name: String, byte_start: u32, @@ -186,7 +186,7 @@ struct DiagnosticSpan { expansion: Option<Box<DiagnosticSpanMacroExpansion>>, } -#[derive(RustcEncodable)] +#[derive(Encodable)] struct DiagnosticSpanLine { text: String, @@ -196,7 +196,7 @@ struct DiagnosticSpanLine { highlight_end: usize, } -#[derive(RustcEncodable)] +#[derive(Encodable)] struct DiagnosticSpanMacroExpansion { /// span where macro was applied to generate this code; note that /// this may itself derive from a macro (if @@ -210,7 +210,7 @@ struct DiagnosticSpanMacroExpansion { def_site_span: DiagnosticSpan, } -#[derive(RustcEncodable)] +#[derive(Encodable)] struct DiagnosticCode { /// The code itself. code: String, @@ -218,7 +218,7 @@ struct DiagnosticCode { explanation: Option<&'static str>, } -#[derive(RustcEncodable)] +#[derive(Encodable)] struct ArtifactNotification<'a> { /// The path of the artifact. artifact: &'a Path, diff --git a/src/librustc_errors/json/tests.rs b/src/librustc_errors/json/tests.rs index dcfcdbc63f2..e69e868c8ed 100644 --- a/src/librustc_errors/json/tests.rs +++ b/src/librustc_errors/json/tests.rs @@ -10,12 +10,12 @@ use rustc_span::{BytePos, Span}; use std::str; -#[derive(RustcDecodable, Debug, PartialEq, Eq)] +#[derive(Decodable, Debug, PartialEq, Eq)] struct TestData { spans: Vec<SpanTestData>, } -#[derive(RustcDecodable, Debug, PartialEq, Eq)] +#[derive(Decodable, Debug, PartialEq, Eq)] struct SpanTestData { pub byte_start: u32, pub byte_end: u32, diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 73d71063b23..98e9972530e 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -6,6 +6,9 @@ #![feature(crate_visibility_modifier)] #![feature(nll)] +#[macro_use] +extern crate rustc_macros; + pub use emitter::ColorConfig; use log::debug; @@ -50,7 +53,7 @@ rustc_data_structures::static_assert_size!(PResult<'_, bool>, 16); /// All suggestions are marked with an `Applicability`. Tools use the applicability of a suggestion /// to determine whether it should be automatically applied or if the user should be consulted /// before applying the suggestion. -#[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub enum Applicability { /// The suggestion is definitely what the user intended. This suggestion should be /// automatically applied. @@ -69,7 +72,7 @@ pub enum Applicability { Unspecified, } -#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, RustcEncodable, RustcDecodable)] +#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Encodable, Decodable)] pub enum SuggestionStyle { /// Hide the suggested code when displaying this suggestion inline. HideCodeInline, @@ -94,7 +97,7 @@ impl SuggestionStyle { } } -#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct CodeSuggestion { /// Each substitute can have multiple variants due to multiple /// applicable suggestions @@ -129,13 +132,13 @@ pub struct CodeSuggestion { pub applicability: Applicability, } -#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] /// See the docs on `CodeSuggestion::substitutions` pub struct Substitution { pub parts: Vec<SubstitutionPart>, } -#[derive(Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct SubstitutionPart { pub span: Span, pub snippet: String, @@ -943,7 +946,7 @@ impl HandlerInner { } } -#[derive(Copy, PartialEq, Clone, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, PartialEq, Clone, Hash, Debug, Encodable, Decodable)] pub enum Level { Bug, Fatal, @@ -1012,7 +1015,7 @@ macro_rules! pluralize { // Useful type to use with `Result<>` indicate that an error has already // been reported to the user, so no need to continue checking. -#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable, Hash, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Encodable, Decodable, Hash, PartialEq, Eq)] pub struct ErrorReported; rustc_data_structures::impl_stable_hash_via_hash!(ErrorReported); diff --git a/src/librustc_errors/snippet.rs b/src/librustc_errors/snippet.rs index 0660590a725..160bf577799 100644 --- a/src/librustc_errors/snippet.rs +++ b/src/librustc_errors/snippet.rs @@ -173,7 +173,7 @@ pub struct StyledString { pub style: Style, } -#[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub enum Style { MainHeaderMsg, HeaderMsg, |
