From 53300bda7709cc8bcc2d2d17bfad2e498f04d401 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 4 Dec 2018 06:22:54 +0200 Subject: [PATCH 01/15] syntax: rename MetaItem's ident field to path. --- src/librustc/ich/impls_syntax.rs | 2 +- src/librustc/lint/levels.rs | 6 +++--- src/librustc/session/config.rs | 2 +- src/librustc_driver/lib.rs | 2 +- src/librustc_mir/dataflow/mod.rs | 2 +- src/libsyntax/ast.rs | 2 +- src/libsyntax/attr/builtin.rs | 4 ++-- src/libsyntax/attr/mod.rs | 32 ++++++++++++++++---------------- src/libsyntax/ext/expand.rs | 2 +- src/libsyntax/fold.rs | 2 +- src/libsyntax/parse/attr.rs | 6 +++--- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax/print/pprust.rs | 6 +++--- src/libsyntax/test.rs | 2 +- 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index 4be467c01aac1..379ed1380bd58 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -380,7 +380,7 @@ impl_stable_hash_for!(enum ::syntax::ast::NestedMetaItemKind { }); impl_stable_hash_for!(struct ::syntax::ast::MetaItem { - ident, + path, node, span }); diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs index cfb9f04c4c6d1..15d5bed9c5a35 100644 --- a/src/librustc/lint/levels.rs +++ b/src/librustc/lint/levels.rs @@ -233,7 +233,7 @@ impl<'a> LintLevelsBuilder<'a> { ast::MetaItemKind::Word => {} // actual lint names handled later ast::MetaItemKind::NameValue(ref name_value) => { let gate_reasons = !self.sess.features_untracked().lint_reasons; - if item.ident == "reason" { + if item.path == "reason" { // found reason, reslice meta list to exclude it metas = &metas[0..metas.len()-1]; // FIXME (#55112): issue unused-attributes lint if we thereby @@ -274,7 +274,7 @@ impl<'a> LintLevelsBuilder<'a> { let mut err = bad_attr(li.span); if let Some(item) = li.meta_item() { if let ast::MetaItemKind::NameValue(_) = item.node { - if item.ident == "reason" { + if item.path == "reason" { err.help("reason in lint attribute must come last"); } } @@ -290,7 +290,7 @@ impl<'a> LintLevelsBuilder<'a> { lint_tool.span, E0710, "an unknown tool name found in scoped lint: `{}`", - word.ident + word.path ); continue; } diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 480d4a8e48f0e..7d8d0165fa799 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1766,7 +1766,7 @@ pub fn parse_cfgspecs(cfgspecs: Vec) -> ast::CrateConfig { match &mut parser.parse_meta_item() { Ok(meta_item) if parser.token == token::Eof => { - if meta_item.ident.segments.len() != 1 { + if meta_item.path.segments.len() != 1 { error!("argument key must be an identifier"); } match &meta_item.node { diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index b063176d3cafa..465f1df80edc1 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1071,7 +1071,7 @@ impl RustcDefaultCalls { let mut cfgs = sess.parse_sess.config.iter().filter_map(|&(name, ref value)| { let gated_cfg = GatedCfg::gate(&ast::MetaItem { - ident: ast::Path::from_ident(ast::Ident::with_empty_ctxt(name)), + path: ast::Path::from_ident(ast::Ident::with_empty_ctxt(name)), node: ast::MetaItemKind::Word, span: DUMMY_SP, }); diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs index c19145636e6da..0d21189e242f2 100644 --- a/src/librustc_mir/dataflow/mod.rs +++ b/src/librustc_mir/dataflow/mod.rs @@ -151,7 +151,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitD } else { sess.span_err( item.span, - &format!("{} attribute requires a path", item.ident)); + &format!("{} attribute requires a path", item.path)); return None; } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 227017a9073fe..174db705397a9 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -430,7 +430,7 @@ pub enum NestedMetaItemKind { /// E.g. `#[test]`, `#[derive(..)]`, `#[rustfmt::skip]` or `#[feature = "foo"]` #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct MetaItem { - pub ident: Path, + pub path: Path, pub node: MetaItemKind, pub span: Span, } diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 1bbc1accc07d6..2d43024b47842 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -499,8 +499,8 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat gated_cfg.check_and_emit(sess, feats); } let error = |span, msg| { sess.span_diagnostic.span_err(span, msg); true }; - if cfg.ident.segments.len() != 1 { - return error(cfg.ident.span, "`cfg` predicate key must be an identifier"); + if cfg.path.segments.len() != 1 { + return error(cfg.path.span, "`cfg` predicate key must be an identifier"); } match &cfg.node { MetaItemKind::List(..) => { diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 6487665947729..8e1828c7d0fd1 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -216,7 +216,7 @@ impl Attribute { impl MetaItem { pub fn name(&self) -> Name { - name_from_path(&self.ident) + name_from_path(&self.path) } // #[attribute(name = "value")] @@ -269,8 +269,8 @@ impl MetaItem { } pub fn is_scoped(&self) -> Option { - if self.ident.segments.len() > 1 { - Some(self.ident.segments[0].ident) + if self.path.segments.len() > 1 { + Some(self.path.segments[0].ident) } else { None } @@ -282,7 +282,7 @@ impl Attribute { pub fn meta(&self) -> Option { let mut tokens = self.tokens.trees().peekable(); Some(MetaItem { - ident: self.path.clone(), + path: self.path.clone(), node: if let Some(node) = MetaItemKind::from_tokens(&mut tokens) { if tokens.peek().is_some() { return None; @@ -328,7 +328,7 @@ impl Attribute { pub fn parse_meta<'a>(&self, sess: &'a ParseSess) -> PResult<'a, MetaItem> { Ok(MetaItem { - ident: self.path.clone(), + path: self.path.clone(), node: self.parse(sess, |parser| parser.parse_meta_item_kind())?, span: self.span, }) @@ -366,15 +366,15 @@ pub fn mk_name_value_item_str(ident: Ident, value: Spanned) -> MetaItem } pub fn mk_name_value_item(span: Span, ident: Ident, value: ast::Lit) -> MetaItem { - MetaItem { ident: Path::from_ident(ident), span, node: MetaItemKind::NameValue(value) } + MetaItem { path: Path::from_ident(ident), span, node: MetaItemKind::NameValue(value) } } pub fn mk_list_item(span: Span, ident: Ident, items: Vec) -> MetaItem { - MetaItem { ident: Path::from_ident(ident), span, node: MetaItemKind::List(items) } + MetaItem { path: Path::from_ident(ident), span, node: MetaItemKind::List(items) } } pub fn mk_word_item(ident: Ident) -> MetaItem { - MetaItem { ident: Path::from_ident(ident), span: ident.span, node: MetaItemKind::Word } + MetaItem { path: Path::from_ident(ident), span: ident.span, node: MetaItemKind::Word } } pub fn mk_nested_word_item(ident: Ident) -> NestedMetaItem { @@ -402,7 +402,7 @@ pub fn mk_spanned_attr_inner(sp: Span, id: AttrId, item: MetaItem) -> Attribute Attribute { id, style: ast::AttrStyle::Inner, - path: item.ident, + path: item.path, tokens: item.node.tokens(item.span), is_sugared_doc: false, span: sp, @@ -419,7 +419,7 @@ pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: MetaItem) -> Attribute Attribute { id, style: ast::AttrStyle::Outer, - path: item.ident, + path: item.path, tokens: item.node.tokens(item.span), is_sugared_doc: false, span: sp, @@ -470,7 +470,7 @@ impl MetaItem { fn tokens(&self) -> TokenStream { let mut idents = vec![]; let mut last_pos = BytePos(0 as u32); - for (i, segment) in self.ident.segments.iter().enumerate() { + for (i, segment) in self.path.segments.iter().enumerate() { let is_first = i == 0; if !is_first { let mod_sep_span = Span::new(last_pos, @@ -490,7 +490,7 @@ impl MetaItem { where I: Iterator, { // FIXME: Share code with `parse_path`. - let ident = match tokens.next() { + let path = match tokens.next() { Some(TokenTree::Token(span, Token::Ident(ident, _))) => { if let Some(TokenTree::Token(_, Token::ModSep)) = tokens.peek() { let mut segments = vec![PathSegment::from_ident(ident.with_span_pos(span))]; @@ -526,11 +526,11 @@ impl MetaItem { let node = MetaItemKind::from_tokens(tokens)?; let hi = match node { MetaItemKind::NameValue(ref lit) => lit.span.hi(), - MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(ident.span.hi()), - _ => ident.span.hi(), + MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(path.span.hi()), + _ => path.span.hi(), }; - let span = ident.span.with_hi(hi); - Some(MetaItem { ident, node, span }) + let span = path.span.with_hi(hi); + Some(MetaItem { path, node, span }) } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 68a96293891a0..146f5285f3fe6 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -934,7 +934,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { invoc.expansion_data.mark.set_expn_info(expn_info); let span = span.with_ctxt(self.cx.backtrace()); let dummy = ast::MetaItem { // FIXME(jseyfried) avoid this - ident: Path::from_ident(keywords::Invalid.ident()), + path: Path::from_ident(keywords::Invalid.ident()), span: DUMMY_SP, node: ast::MetaItemKind::Word, }; diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 0e6e2f90693cf..6b49ea3393e8e 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -581,7 +581,7 @@ pub fn noop_fold_meta_list_item(li: NestedMetaItem, fld: &mut T) pub fn noop_fold_meta_item(mi: MetaItem, fld: &mut T) -> MetaItem { MetaItem { - ident: mi.ident, + path: fld.fold_path(mi.path), node: match mi.node { MetaItemKind::Word => MetaItemKind::Word, MetaItemKind::List(mis) => { diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index a240604bfe0ad..fc76906d46542 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -157,7 +157,7 @@ impl<'a> Parser<'a> { }; Ok(if let Some(meta) = meta { self.bump(); - (meta.ident, meta.node.tokens(meta.span)) + (meta.path, meta.node.tokens(meta.span)) } else { let path = self.parse_path(PathStyle::Mod)?; let tokens = if self.check(&token::OpenDelim(DelimToken::Paren)) || @@ -248,10 +248,10 @@ impl<'a> Parser<'a> { } let lo = self.span; - let ident = self.parse_path(PathStyle::Mod)?; + let path = self.parse_path(PathStyle::Mod)?; let node = self.parse_meta_item_kind()?; let span = lo.to(self.prev_span); - Ok(ast::MetaItem { ident, node, span }) + Ok(ast::MetaItem { path, node, span }) } crate fn parse_meta_item_kind(&mut self) -> PResult<'a, ast::MetaItemKind> { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 33715f206dedf..9d0fcd9eaff29 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2095,7 +2095,7 @@ impl<'a> Parser<'a> { let meta_ident = match self.token { token::Interpolated(ref nt) => match nt.0 { token::NtMeta(ref meta) => match meta.node { - ast::MetaItemKind::Word => Some(meta.ident.clone()), + ast::MetaItemKind::Word => Some(meta.path.clone()), _ => None, }, _ => None, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 14ad4b5c6f815..13e0d7c8b3873 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -779,15 +779,15 @@ pub trait PrintState<'a> { fn print_meta_item(&mut self, item: &ast::MetaItem) -> io::Result<()> { self.ibox(INDENT_UNIT)?; match item.node { - ast::MetaItemKind::Word => self.print_attribute_path(&item.ident)?, + ast::MetaItemKind::Word => self.print_attribute_path(&item.path)?, ast::MetaItemKind::NameValue(ref value) => { - self.print_attribute_path(&item.ident)?; + self.print_attribute_path(&item.path)?; self.writer().space()?; self.word_space("=")?; self.print_literal(value)?; } ast::MetaItemKind::List(ref items) => { - self.print_attribute_path(&item.ident)?; + self.print_attribute_path(&item.path)?; self.popen()?; self.commasep(Consistent, &items[..], diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 8ff4b0d025c8d..3a68278344b36 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -443,7 +443,7 @@ fn get_test_runner(sd: &errors::Handler, krate: &ast::Crate) -> Option Date: Tue, 4 Dec 2018 08:48:17 +0200 Subject: [PATCH 02/15] syntax: don't pass an (unused) MetaItem to builtin derives. --- src/libsyntax/ext/base.rs | 4 ++-- src/libsyntax/ext/expand.rs | 10 ++-------- src/libsyntax_ext/deriving/bounds.rs | 5 +---- src/libsyntax_ext/deriving/clone.rs | 5 ++--- src/libsyntax_ext/deriving/cmp/eq.rs | 5 ++--- src/libsyntax_ext/deriving/cmp/ord.rs | 5 ++--- src/libsyntax_ext/deriving/cmp/partial_eq.rs | 5 ++--- src/libsyntax_ext/deriving/cmp/partial_ord.rs | 5 ++--- src/libsyntax_ext/deriving/debug.rs | 5 ++--- src/libsyntax_ext/deriving/decodable.rs | 11 ++++------- src/libsyntax_ext/deriving/default.rs | 5 ++--- src/libsyntax_ext/deriving/encodable.rs | 11 ++++------- src/libsyntax_ext/deriving/generic/mod.rs | 6 ++---- src/libsyntax_ext/deriving/hash.rs | 5 ++--- .../auxiliary/custom_derive_partial_eq.rs | 2 +- 15 files changed, 32 insertions(+), 57 deletions(-) diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index bb927b62a181e..9afa9e1f7f719 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -10,7 +10,7 @@ pub use self::SyntaxExtension::*; -use ast::{self, Attribute, Name, PatKind, MetaItem}; +use ast::{self, Attribute, Name, PatKind}; use attr::HasAttrs; use source_map::{self, SourceMap, Spanned, respan}; use syntax_pos::{Span, MultiSpan, DUMMY_SP}; @@ -571,7 +571,7 @@ impl MacResult for DummyResult { } pub type BuiltinDeriveFn = - for<'cx> fn(&'cx mut ExtCtxt, Span, &MetaItem, &Annotatable, &mut dyn FnMut(Annotatable)); + for<'cx> fn(&'cx mut ExtCtxt, Span, &Annotatable, &mut dyn FnMut(Annotatable)); /// Represents different kinds of macro invocations that can be resolved. #[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 146f5285f3fe6..ac43cd9436325 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -912,12 +912,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let pretty_name = Symbol::intern(&format!("derive({})", path)); let span = path.span; - let attr = ast::Attribute { - path, span, - tokens: TokenStream::empty(), - // irrelevant: - id: ast::AttrId(0), style: ast::AttrStyle::Outer, is_sugared_doc: false, - }; let mut expn_info = ExpnInfo { call_site: span, @@ -946,11 +940,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> { invoc.expansion_data.mark.set_expn_info(expn_info); let span = span.with_ctxt(self.cx.backtrace()); let mut items = Vec::new(); - func(self.cx, span, &attr.meta()?, &item, &mut |a| items.push(a)); + func(self.cx, span, &item, &mut |a| items.push(a)); Some(invoc.fragment_kind.expect_from_annotatables(items)) } _ => { - let msg = &format!("macro `{}` may not be used for derive attributes", attr.path); + let msg = &format!("macro `{}` may not be used for derive attributes", path); self.cx.span_err(span, msg); self.cx.trace_macros_diag(); invoc.fragment_kind.dummy(span) diff --git a/src/libsyntax_ext/deriving/bounds.rs b/src/libsyntax_ext/deriving/bounds.rs index 41e980b334616..25a9a3cebd463 100644 --- a/src/libsyntax_ext/deriving/bounds.rs +++ b/src/libsyntax_ext/deriving/bounds.rs @@ -11,13 +11,11 @@ use deriving::path_std; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::MetaItem; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax_pos::Span; pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt, span: Span, - _: &MetaItem, _: &Annotatable, _: &mut dyn FnMut(Annotatable)) { cx.span_err(span, "this unsafe trait should be implemented explicitly"); @@ -25,7 +23,6 @@ pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt, pub fn expand_deriving_copy(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { let trait_def = TraitDef { @@ -40,5 +37,5 @@ pub fn expand_deriving_copy(cx: &mut ExtCtxt, associated_types: Vec::new(), }; - trait_def.expand(cx, mitem, item, push); + trait_def.expand(cx, item, push); } diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index ec935b3e72f23..4666369382d63 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -12,7 +12,7 @@ use deriving::path_std; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{self, Expr, Generics, ItemKind, MetaItem, VariantData}; +use syntax::ast::{self, Expr, Generics, ItemKind, VariantData}; use syntax::ast::GenericArg; use syntax::attr; use syntax::ext::base::{Annotatable, ExtCtxt}; @@ -23,7 +23,6 @@ use syntax_pos::Span; pub fn expand_deriving_clone(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { // check if we can use a short form @@ -111,7 +110,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt, associated_types: Vec::new(), }; - trait_def.expand_ext(cx, mitem, item, push, is_shallow) + trait_def.expand_ext(cx, item, push, is_shallow) } fn cs_clone_shallow(name: &str, diff --git a/src/libsyntax_ext/deriving/cmp/eq.rs b/src/libsyntax_ext/deriving/cmp/eq.rs index f202bc4e524d2..e42e699714aaa 100644 --- a/src/libsyntax_ext/deriving/cmp/eq.rs +++ b/src/libsyntax_ext/deriving/cmp/eq.rs @@ -12,7 +12,7 @@ use deriving::path_std; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{self, Expr, MetaItem, GenericArg}; +use syntax::ast::{self, Expr, GenericArg}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -21,7 +21,6 @@ use syntax_pos::Span; pub fn expand_deriving_eq(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { let inline = cx.meta_word(span, Symbol::intern("inline")); @@ -51,7 +50,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt, }], associated_types: Vec::new(), }; - trait_def.expand_ext(cx, mitem, item, push, true) + trait_def.expand_ext(cx, item, push, true) } fn cs_total_eq_assert(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P { diff --git a/src/libsyntax_ext/deriving/cmp/ord.rs b/src/libsyntax_ext/deriving/cmp/ord.rs index 117bedf453e6c..abcae27c5b324 100644 --- a/src/libsyntax_ext/deriving/cmp/ord.rs +++ b/src/libsyntax_ext/deriving/cmp/ord.rs @@ -12,7 +12,7 @@ use deriving::path_std; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{self, Expr, MetaItem}; +use syntax::ast::{self, Expr}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -21,7 +21,6 @@ use syntax_pos::Span; pub fn expand_deriving_ord(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { let inline = cx.meta_word(span, Symbol::intern("inline")); @@ -50,7 +49,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt, associated_types: Vec::new(), }; - trait_def.expand(cx, mitem, item, push) + trait_def.expand(cx, item, push) } diff --git a/src/libsyntax_ext/deriving/cmp/partial_eq.rs b/src/libsyntax_ext/deriving/cmp/partial_eq.rs index 24a3a7542fb66..1a773aced6628 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_eq.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_eq.rs @@ -12,7 +12,7 @@ use deriving::{path_local, path_std}; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{BinOpKind, Expr, MetaItem}; +use syntax::ast::{BinOpKind, Expr}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -21,7 +21,6 @@ use syntax_pos::Span; pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { // structures are equal if all fields are equal, and non equal, if @@ -109,5 +108,5 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt, methods, associated_types: Vec::new(), }; - trait_def.expand(cx, mitem, item, push) + trait_def.expand(cx, item, push) } diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs index 32a58de3529fd..7aa7351b650a2 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -14,7 +14,7 @@ use deriving::{path_local, pathvec_std, path_std}; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{self, BinOpKind, Expr, MetaItem}; +use syntax::ast::{self, BinOpKind, Expr}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -23,7 +23,6 @@ use syntax_pos::Span; pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { macro_rules! md { @@ -93,7 +92,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt, methods, associated_types: Vec::new(), }; - trait_def.expand(cx, mitem, item, push) + trait_def.expand(cx, item, push) } #[derive(Copy, Clone)] diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs index df9c351ef1c95..3b2425111c3fd 100644 --- a/src/libsyntax_ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -15,7 +15,7 @@ use deriving::generic::ty::*; use rustc_data_structures::thin_vec::ThinVec; use syntax::ast::{self, Ident}; -use syntax::ast::{Expr, MetaItem}; +use syntax::ast::Expr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -23,7 +23,6 @@ use syntax_pos::{DUMMY_SP, Span}; pub fn expand_deriving_debug(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { // &mut ::std::fmt::Formatter @@ -53,7 +52,7 @@ pub fn expand_deriving_debug(cx: &mut ExtCtxt, }], associated_types: Vec::new(), }; - trait_def.expand(cx, mitem, item, push) + trait_def.expand(cx, item, push) } /// We use the debug builders to do the heavy lifting here diff --git a/src/libsyntax_ext/deriving/decodable.rs b/src/libsyntax_ext/deriving/decodable.rs index c2b9294499907..ecb7862279b27 100644 --- a/src/libsyntax_ext/deriving/decodable.rs +++ b/src/libsyntax_ext/deriving/decodable.rs @@ -16,7 +16,7 @@ use deriving::generic::ty::*; use deriving::warn_if_deprecated; use syntax::ast; -use syntax::ast::{Expr, MetaItem, Mutability}; +use syntax::ast::{Expr, Mutability}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -25,24 +25,21 @@ use syntax_pos::Span; pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { - expand_deriving_decodable_imp(cx, span, mitem, item, push, "rustc_serialize") + expand_deriving_decodable_imp(cx, span, item, push, "rustc_serialize") } pub fn expand_deriving_decodable(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { warn_if_deprecated(cx, span, "Decodable"); - expand_deriving_decodable_imp(cx, span, mitem, item, push, "serialize") + expand_deriving_decodable_imp(cx, span, item, push, "serialize") } fn expand_deriving_decodable_imp(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable), krate: &'static str) { @@ -86,7 +83,7 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt, associated_types: Vec::new(), }; - trait_def.expand(cx, mitem, item, push) + trait_def.expand(cx, item, push) } fn decodable_substructure(cx: &mut ExtCtxt, diff --git a/src/libsyntax_ext/deriving/default.rs b/src/libsyntax_ext/deriving/default.rs index adbc5828b8fb8..4150e5afe27c3 100644 --- a/src/libsyntax_ext/deriving/default.rs +++ b/src/libsyntax_ext/deriving/default.rs @@ -12,7 +12,7 @@ use deriving::path_std; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{Expr, MetaItem}; +use syntax::ast::Expr; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -21,7 +21,6 @@ use syntax_pos::Span; pub fn expand_deriving_default(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { let inline = cx.meta_word(span, Symbol::intern("inline")); @@ -49,7 +48,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt, }], associated_types: Vec::new(), }; - trait_def.expand(cx, mitem, item, push) + trait_def.expand(cx, item, push) } fn default_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P { diff --git a/src/libsyntax_ext/deriving/encodable.rs b/src/libsyntax_ext/deriving/encodable.rs index 5438c8b52af05..58f08306e03fa 100644 --- a/src/libsyntax_ext/deriving/encodable.rs +++ b/src/libsyntax_ext/deriving/encodable.rs @@ -97,7 +97,7 @@ use deriving::generic::*; use deriving::generic::ty::*; use deriving::warn_if_deprecated; -use syntax::ast::{Expr, ExprKind, MetaItem, Mutability}; +use syntax::ast::{Expr, ExprKind, Mutability}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -106,24 +106,21 @@ use syntax_pos::Span; pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { - expand_deriving_encodable_imp(cx, span, mitem, item, push, "rustc_serialize") + expand_deriving_encodable_imp(cx, span, item, push, "rustc_serialize") } pub fn expand_deriving_encodable(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { warn_if_deprecated(cx, span, "Encodable"); - expand_deriving_encodable_imp(cx, span, mitem, item, push, "serialize") + expand_deriving_encodable_imp(cx, span, item, push, "serialize") } fn expand_deriving_encodable_imp(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable), krate: &'static str) { @@ -169,7 +166,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt, associated_types: Vec::new(), }; - trait_def.expand(cx, mitem, item, push) + trait_def.expand(cx, item, push) } fn encodable_substructure(cx: &mut ExtCtxt, diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index a5b12ce4c4d83..1d9e14b340dd1 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -397,15 +397,13 @@ fn find_type_parameters(ty: &ast::Ty, impl<'a> TraitDef<'a> { pub fn expand(self, cx: &mut ExtCtxt, - mitem: &ast::MetaItem, item: &'a Annotatable, push: &mut dyn FnMut(Annotatable)) { - self.expand_ext(cx, mitem, item, push, false); + self.expand_ext(cx, item, push, false); } pub fn expand_ext(self, cx: &mut ExtCtxt, - mitem: &ast::MetaItem, item: &'a Annotatable, push: &mut dyn FnMut(Annotatable), from_scratch: bool) { @@ -461,7 +459,7 @@ impl<'a> TraitDef<'a> { generics, from_scratch, use_temporaries) } else { - cx.span_err(mitem.span, + cx.span_err(self.span, "this trait cannot be derived for unions"); return; } diff --git a/src/libsyntax_ext/deriving/hash.rs b/src/libsyntax_ext/deriving/hash.rs index 950e8c84f1765..ac2469871f344 100644 --- a/src/libsyntax_ext/deriving/hash.rs +++ b/src/libsyntax_ext/deriving/hash.rs @@ -12,7 +12,7 @@ use deriving::{self, pathvec_std, path_std}; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{Expr, MetaItem, Mutability}; +use syntax::ast::{Expr, Mutability}; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::build::AstBuilder; use syntax::ptr::P; @@ -20,7 +20,6 @@ use syntax_pos::Span; pub fn expand_deriving_hash(cx: &mut ExtCtxt, span: Span, - mitem: &MetaItem, item: &Annotatable, push: &mut dyn FnMut(Annotatable)) { @@ -57,7 +56,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt, associated_types: Vec::new(), }; - hash_trait_def.expand(cx, mitem, item, push); + hash_trait_def.expand(cx, item, push); } fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P { diff --git a/src/test/run-pass-fulldeps/auxiliary/custom_derive_partial_eq.rs b/src/test/run-pass-fulldeps/auxiliary/custom_derive_partial_eq.rs index 985f31296fb87..86ec96b6b629d 100644 --- a/src/test/run-pass-fulldeps/auxiliary/custom_derive_partial_eq.rs +++ b/src/test/run-pass-fulldeps/auxiliary/custom_derive_partial_eq.rs @@ -34,7 +34,7 @@ pub fn plugin_registrar(reg: &mut Registry) { MultiDecorator(Box::new(expand_deriving_partial_eq))); } -fn expand_deriving_partial_eq(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, item: &Annotatable, +fn expand_deriving_partial_eq(cx: &mut ExtCtxt, span: Span, item: &Annotatable, push: &mut FnMut(Annotatable)) { // structures are equal if all fields are equal, and non equal, if // any fields are not equal or if the enum variants are different From 3b5f8188f167c554528c59dd47921384c0babe5b Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 4 Dec 2018 07:34:07 +0200 Subject: [PATCH 03/15] syntax: use MetaPath (a simpler version of Path) for Attribute and MetaItem. --- src/librustc/ich/impls_syntax.rs | 6 +- src/librustc_driver/lib.rs | 2 +- src/librustc_resolve/build_reduced_graph.rs | 2 +- src/librustc_resolve/macros.rs | 9 ++- src/libsyntax/ast.rs | 64 ++++++++++++++++++- src/libsyntax/attr/mod.rs | 44 +++++++------ src/libsyntax/ext/expand.rs | 4 +- src/libsyntax/ext/quote.rs | 4 +- src/libsyntax/fold.rs | 4 +- src/libsyntax/parse/attr.rs | 10 ++- src/libsyntax/parse/parser.rs | 28 ++++++-- src/libsyntax/parse/token.rs | 6 +- src/libsyntax/print/pprust.rs | 26 ++++---- src/libsyntax/std_inject.rs | 4 +- src/libsyntax/test.rs | 2 +- src/libsyntax_ext/proc_macro_decls.rs | 4 +- .../mir-opt/inline-closure-borrows-arg.rs | 2 +- src/test/mir-opt/inline-closure.rs | 2 +- src/test/mir-opt/retag.rs | 2 +- src/test/ui/issues/issue-43424.stderr | 4 +- src/test/ui/span/import-ty-params.stderr | 8 +-- src/test/ui/span/macro-ty-params.rs | 3 +- src/test/ui/span/macro-ty-params.stderr | 10 +-- src/test/ui/span/visibility-ty-params.stderr | 8 +-- 24 files changed, 170 insertions(+), 88 deletions(-) diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index 379ed1380bd58..db69c5c4c8fc8 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -221,13 +221,13 @@ impl<'a> HashStable> for [ast::Attribute] { } } -impl<'a> HashStable> for ast::Path { +impl<'a> HashStable> for ast::MetaPath { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { self.segments.len().hash_stable(hcx, hasher); - for segment in &self.segments { - segment.ident.name.hash_stable(hcx, hasher); + for ident in &self.segments { + ident.name.hash_stable(hcx, hasher); } } } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 465f1df80edc1..4527c78b31ee7 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1071,7 +1071,7 @@ impl RustcDefaultCalls { let mut cfgs = sess.parse_sess.config.iter().filter_map(|&(name, ref value)| { let gated_cfg = GatedCfg::gate(&ast::MetaItem { - path: ast::Path::from_ident(ast::Ident::with_empty_ctxt(name)), + path: ast::MetaPath::from_ident(ast::Ident::with_empty_ctxt(name)), node: ast::MetaItemKind::Word, span: DUMMY_SP, }); diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 0fa41cb484fc9..7dd5ba2b63a13 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -1021,7 +1021,7 @@ impl<'a, 'b, 'cl> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b, 'cl> { derives: Vec::new(), }; parent_scope.module.builtin_attrs.borrow_mut().push(( - attr.path.segments[0].ident, parent_scope + attr.path.segments[0], parent_scope )); } visit::walk_attribute(self, attr); diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 5db3efee9f6a1..862f402f23ba8 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -299,7 +299,7 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> { }).into(); } return Some(ast::Attribute { - path: ast::Path::from_ident(Ident::new(legacy_name, span)), + path: ast::MetaPath::from_ident(Ident::new(legacy_name, span)), tokens: TokenStream::empty(), id: attr::mk_attr_id(), style: ast::AttrStyle::Outer, @@ -315,11 +315,14 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> { fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: Mark, force: bool) -> Result>, Determinacy> { + let path; let (path, kind, derives_in_scope, after_derive) = match invoc.kind { InvocationKind::Attr { attr: None, .. } => return Ok(None), - InvocationKind::Attr { attr: Some(ref attr), ref traits, after_derive, .. } => - (&attr.path, MacroKind::Attr, traits.clone(), after_derive), + InvocationKind::Attr { attr: Some(ref attr), ref traits, after_derive, .. } => { + path = attr.path.to_regular_path(); + (&path, MacroKind::Attr, traits.clone(), after_derive) + } InvocationKind::Bang { ref mac, .. } => (&mac.node.path, MacroKind::Bang, Vec::new(), false), InvocationKind::Derive { ref path, .. } => diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 174db705397a9..7052e49050652 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -63,6 +63,66 @@ impl fmt::Debug for Lifetime { } } +/// Simpler version of `Path` for `Attribute` and `MetaItem`. +#[derive(Clone, RustcEncodable, RustcDecodable)] +pub struct MetaPath { + pub span: Span, + pub segments: Vec, +} + +impl<'a> PartialEq<&'a str> for MetaPath { + fn eq(&self, string: &&'a str) -> bool { + self.segments.len() == 1 && self.segments[0].name == *string + } +} + +impl fmt::Debug for MetaPath { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "path({})", pprust::meta_path_to_string(self)) + } +} + +impl fmt::Display for MetaPath { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", pprust::meta_path_to_string(self)) + } +} + +impl MetaPath { + // convert a span and an identifier to the corresponding + // 1-segment path + pub fn from_ident(ident: Ident) -> MetaPath { + MetaPath { + span: ident.span, + segments: vec![ident], + } + } + + /// Try to convert a `Path` into a `MetaPath`, returning `None` + /// if any of the path's segments had any generic arguments. + pub fn from_regular_path(path: &Path) -> Option { + Some(MetaPath { + span: path.span, + segments: path.segments.iter().map(|segment| { + if segment.args.is_none() { + Some(segment.ident) + } else { + None + } + }).collect::>()?, + }) + } + + pub fn to_regular_path(&self) -> Path { + Path { + span: self.span, + segments: self.segments.iter().map(|&ident| { + PathSegment::from_ident(ident) + }).collect(), + } + } +} + /// A "Path" is essentially Rust's notion of a name. /// /// It's represented as a sequence of identifiers, @@ -430,7 +490,7 @@ pub enum NestedMetaItemKind { /// E.g. `#[test]`, `#[derive(..)]`, `#[rustfmt::skip]` or `#[feature = "foo"]` #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct MetaItem { - pub path: Path, + pub path: MetaPath, pub node: MetaItemKind, pub span: Span, } @@ -1988,7 +2048,7 @@ impl Idx for AttrId { pub struct Attribute { pub id: AttrId, pub style: AttrStyle, - pub path: Path, + pub path: MetaPath, pub tokens: TokenStream, pub is_sugared_doc: bool, pub span: Span, diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 8e1828c7d0fd1..513158f920584 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -22,7 +22,7 @@ pub use self::ReprAttr::*; pub use self::StabilityLevel::*; use ast; -use ast::{AttrId, Attribute, AttrStyle, Name, Ident, Path, PathSegment}; +use ast::{AttrId, Attribute, AttrStyle, Name, Ident, MetaPath}; use ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind}; use ast::{Lit, LitKind, Expr, ExprKind, Item, Local, Stmt, StmtKind, GenericParam}; use source_map::{BytePos, Spanned, respan, dummy_spanned}; @@ -166,8 +166,8 @@ impl NestedMetaItem { } } -fn name_from_path(path: &Path) -> Name { - path.segments.last().expect("empty path in attribute").ident.name +fn name_from_path(path: &MetaPath) -> Name { + path.segments.last().expect("empty path in attribute").name } impl Attribute { @@ -270,7 +270,7 @@ impl MetaItem { pub fn is_scoped(&self) -> Option { if self.path.segments.len() > 1 { - Some(self.path.segments[0].ident) + Some(self.path.segments[0]) } else { None } @@ -366,15 +366,15 @@ pub fn mk_name_value_item_str(ident: Ident, value: Spanned) -> MetaItem } pub fn mk_name_value_item(span: Span, ident: Ident, value: ast::Lit) -> MetaItem { - MetaItem { path: Path::from_ident(ident), span, node: MetaItemKind::NameValue(value) } + MetaItem { path: MetaPath::from_ident(ident), span, node: MetaItemKind::NameValue(value) } } pub fn mk_list_item(span: Span, ident: Ident, items: Vec) -> MetaItem { - MetaItem { path: Path::from_ident(ident), span, node: MetaItemKind::List(items) } + MetaItem { path: MetaPath::from_ident(ident), span, node: MetaItemKind::List(items) } } pub fn mk_word_item(ident: Ident) -> MetaItem { - MetaItem { path: Path::from_ident(ident), span: ident.span, node: MetaItemKind::Word } + MetaItem { path: MetaPath::from_ident(ident), span: ident.span, node: MetaItemKind::Word } } pub fn mk_nested_word_item(ident: Ident) -> NestedMetaItem { @@ -432,7 +432,7 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: Symbol, span: Span) -> Attribute { Attribute { id, style, - path: Path::from_ident(Ident::from_str("doc").with_span_pos(span)), + path: MetaPath::from_ident(Ident::from_str("doc").with_span_pos(span)), tokens: MetaItemKind::NameValue(lit).tokens(span), is_sugared_doc: true, span, @@ -470,17 +470,17 @@ impl MetaItem { fn tokens(&self) -> TokenStream { let mut idents = vec![]; let mut last_pos = BytePos(0 as u32); - for (i, segment) in self.path.segments.iter().enumerate() { + for (i, &ident) in self.path.segments.iter().enumerate() { let is_first = i == 0; if !is_first { let mod_sep_span = Span::new(last_pos, - segment.ident.span.lo(), - segment.ident.span.ctxt()); + ident.span.lo(), + ident.span.ctxt()); idents.push(TokenTree::Token(mod_sep_span, Token::ModSep).into()); } - idents.push(TokenTree::Token(segment.ident.span, - Token::from_ast_ident(segment.ident)).into()); - last_pos = segment.ident.span.hi(); + idents.push(TokenTree::Token(ident.span, + Token::from_ast_ident(ident)).into()); + last_pos = ident.span.hi(); } idents.push(self.node.tokens(self.span)); TokenStream::concat(idents) @@ -493,12 +493,12 @@ impl MetaItem { let path = match tokens.next() { Some(TokenTree::Token(span, Token::Ident(ident, _))) => { if let Some(TokenTree::Token(_, Token::ModSep)) = tokens.peek() { - let mut segments = vec![PathSegment::from_ident(ident.with_span_pos(span))]; + let mut segments = vec![ident.with_span_pos(span)]; tokens.next(); loop { if let Some(TokenTree::Token(span, Token::Ident(ident, _))) = tokens.next() { - segments.push(PathSegment::from_ident(ident.with_span_pos(span))); + segments.push(ident.with_span_pos(span)); } else { return None; } @@ -508,16 +508,18 @@ impl MetaItem { break; } } - let span = span.with_hi(segments.last().unwrap().ident.span.hi()); - Path { span, segments } + let span = span.with_hi(segments.last().unwrap().span.hi()); + MetaPath { span, segments } } else { - Path::from_ident(ident.with_span_pos(span)) + MetaPath::from_ident(ident.with_span_pos(span)) } } Some(TokenTree::Token(_, Token::Interpolated(ref nt))) => match nt.0 { - token::Nonterminal::NtIdent(ident, _) => Path::from_ident(ident), + token::Nonterminal::NtIdent(ident, _) => MetaPath::from_ident(ident), token::Nonterminal::NtMeta(ref meta) => return Some(meta.clone()), - token::Nonterminal::NtPath(ref path) => path.clone(), + token::Nonterminal::NtPath(ref path) => { + ast::MetaPath::from_regular_path(path)? + } _ => return None, }, _ => return None, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index ac43cd9436325..9992b3b5b9b84 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -601,7 +601,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { let input = self.extract_proc_macro_attr_input(attr.tokens, attr.span); let tok_result = mac.expand(self.cx, attr.span, input, item_tok); let res = self.parse_ast_fragment(tok_result, invoc.fragment_kind, - &attr.path, attr.span); + &attr.path.to_regular_path(), attr.span); self.gate_proc_macro_expansion(attr.span, &res); res } @@ -928,7 +928,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { invoc.expansion_data.mark.set_expn_info(expn_info); let span = span.with_ctxt(self.cx.backtrace()); let dummy = ast::MetaItem { // FIXME(jseyfried) avoid this - path: Path::from_ident(keywords::Invalid.ident()), + path: ast::MetaPath::from_ident(keywords::Invalid.ident()), span: DUMMY_SP, node: ast::MetaItemKind::Word, }; diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index c6e0adbb5a43e..c1d92a95ddcae 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -235,12 +235,12 @@ pub mod rt { r.push(TokenTree::Token(self.span, token::Not)); } let mut inner = Vec::new(); - for (i, segment) in self.path.segments.iter().enumerate() { + for (i, &ident) in self.path.segments.iter().enumerate() { if i > 0 { inner.push(TokenTree::Token(self.span, token::Colon).into()); } inner.push(TokenTree::Token( - self.span, token::Token::from_ast_ident(segment.ident) + self.span, token::Token::from_ast_ident(ident) ).into()); } inner.push(self.tokens.clone()); diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 6b49ea3393e8e..8a4b96d6dac29 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -541,7 +541,7 @@ pub fn noop_fold_attribute(attr: Attribute, fld: &mut T) -> Option(li: NestedMetaItem, fld: &mut T) pub fn noop_fold_meta_item(mi: MetaItem, fld: &mut T) -> MetaItem { MetaItem { - path: fld.fold_path(mi.path), + path: mi.path.clone(), node: match mi.node { MetaItemKind::Word => MetaItemKind::Word, MetaItemKind::List(mis) => { diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index fc76906d46542..6489b7598b3f4 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -147,7 +147,7 @@ impl<'a> Parser<'a> { /// PATH /// PATH `=` TOKEN_TREE /// The delimiters or `=` are still put into the resulting token stream. - crate fn parse_meta_item_unrestricted(&mut self) -> PResult<'a, (ast::Path, TokenStream)> { + crate fn parse_meta_item_unrestricted(&mut self) -> PResult<'a, (ast::MetaPath, TokenStream)> { let meta = match self.token { token::Interpolated(ref nt) => match nt.0 { Nonterminal::NtMeta(ref meta) => Some(meta.clone()), @@ -174,7 +174,7 @@ impl<'a> Parser<'a> { } else { TokenStream::empty() }; - (path, tokens) + (ast::MetaPath::from_regular_path(&path).unwrap(), tokens) }) } @@ -251,7 +251,11 @@ impl<'a> Parser<'a> { let path = self.parse_path(PathStyle::Mod)?; let node = self.parse_meta_item_kind()?; let span = lo.to(self.prev_span); - Ok(ast::MetaItem { path, node, span }) + Ok(ast::MetaItem { + path: ast::MetaPath::from_regular_path(&path).unwrap(), + node, + span, + }) } crate fn parse_meta_item_kind(&mut self) -> PResult<'a, ast::MetaItemKind> { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 9d0fcd9eaff29..4678279ea3975 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2071,10 +2071,22 @@ impl<'a> Parser<'a> { crate fn parse_path_common(&mut self, style: PathStyle, enable_warning: bool) -> PResult<'a, ast::Path> { maybe_whole!(self, NtPath, |path| { - if style == PathStyle::Mod && - path.segments.iter().any(|segment| segment.args.is_some()) { - self.diagnostic().span_err(path.span, "unexpected generic arguments in path"); + let mut path = path; + + // Check for disallowed generic arguments, and remove them. + // This guarantees a generic-less path for `PathStyle::Mod`, + // implying `MetaPath::from_regular_path` always succeeds. + if style == PathStyle::Mod { + for segment in &mut path.segments{ + if let Some(args) = segment.args.take() { + self.diagnostic().span_err( + args.span(), + "unexpected generic arguments in path", + ); + } + } } + path }); @@ -2092,17 +2104,17 @@ impl<'a> Parser<'a> { /// Like `parse_path`, but also supports parsing `Word` meta items into paths for back-compat. /// This is used when parsing derive macro paths in `#[derive]` attributes. pub fn parse_path_allowing_meta(&mut self, style: PathStyle) -> PResult<'a, ast::Path> { - let meta_ident = match self.token { + let meta_path = match self.token { token::Interpolated(ref nt) => match nt.0 { token::NtMeta(ref meta) => match meta.node { - ast::MetaItemKind::Word => Some(meta.path.clone()), + ast::MetaItemKind::Word => Some(meta.path.to_regular_path()), _ => None, }, _ => None, }, _ => None, }; - if let Some(path) = meta_ident { + if let Some(path) = meta_path { self.bump(); return Ok(path); } @@ -6479,7 +6491,9 @@ impl<'a> Parser<'a> { let attr = Attribute { id: attr::mk_attr_id(), style: ast::AttrStyle::Outer, - path: ast::Path::from_ident(Ident::from_str("warn_directory_ownership")), + path: ast::MetaPath::from_ident( + Ident::from_str("warn_directory_ownership"), + ), tokens: TokenStream::empty(), is_sugared_doc: false, span: syntax_pos::DUMMY_SP, diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 46fc6454d1c3b..1f23111a16bb1 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -799,8 +799,8 @@ fn prepend_attrs(sess: &ParseSess, let mut brackets = tokenstream::TokenStreamBuilder::new(); // For simple paths, push the identifier directly - if attr.path.segments.len() == 1 && attr.path.segments[0].args.is_none() { - let ident = attr.path.segments[0].ident; + if attr.path.segments.len() == 1 { + let ident = attr.path.segments[0]; let token = Ident(ident, ident.as_str().starts_with("r#")); brackets.push(tokenstream::TokenTree::Token(ident.span, token)); @@ -809,7 +809,7 @@ fn prepend_attrs(sess: &ParseSess, } else { let stream = parse_stream_from_source_str( FileName::MacroExpansion, - pprust::path_to_string(&attr.path), + pprust::meta_path_to_string(&attr.path), sess, Some(span), ); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 13e0d7c8b3873..50f8e371c5ee3 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -361,6 +361,10 @@ pub fn fn_block_to_string(p: &ast::FnDecl) -> String { to_string(|s| s.print_fn_block_args(p)) } +pub fn meta_path_to_string(p: &ast::MetaPath) -> String { + to_string(|s| s.print_meta_path(p)) +} + pub fn path_to_string(p: &ast::Path) -> String { to_string(|s| s.print_path(p, false, 0)) } @@ -720,17 +724,17 @@ pub trait PrintState<'a> { Ok(()) } - fn print_attribute_path(&mut self, path: &ast::Path) -> io::Result<()> { - for (i, segment) in path.segments.iter().enumerate() { + fn print_meta_path(&mut self, path: &ast::MetaPath) -> io::Result<()> { + for (i, ident) in path.segments.iter().enumerate() { if i > 0 { self.writer().word("::")? } - if segment.ident.name != keywords::CrateRoot.name() && - segment.ident.name != keywords::DollarCrate.name() + if ident.name != keywords::CrateRoot.name() && + ident.name != keywords::DollarCrate.name() { - self.writer().word(segment.ident.as_str().get())?; - } else if segment.ident.name == keywords::DollarCrate.name() { - self.print_dollar_crate(segment.ident.span.ctxt())?; + self.writer().word(ident.as_str().get())?; + } else if ident.name == keywords::DollarCrate.name() { + self.print_dollar_crate(ident.span.ctxt())?; } } Ok(()) @@ -757,7 +761,7 @@ pub trait PrintState<'a> { if let Some(mi) = attr.meta() { self.print_meta_item(&mi)? } else { - self.print_attribute_path(&attr.path)?; + self.print_meta_path(&attr.path)?; self.writer().space()?; self.print_tts(attr.tokens.clone())?; } @@ -779,15 +783,15 @@ pub trait PrintState<'a> { fn print_meta_item(&mut self, item: &ast::MetaItem) -> io::Result<()> { self.ibox(INDENT_UNIT)?; match item.node { - ast::MetaItemKind::Word => self.print_attribute_path(&item.path)?, + ast::MetaItemKind::Word => self.print_meta_path(&item.path)?, ast::MetaItemKind::NameValue(ref value) => { - self.print_attribute_path(&item.path)?; + self.print_meta_path(&item.path)?; self.writer().space()?; self.word_space("=")?; self.print_literal(value)?; } ast::MetaItemKind::List(ref items) => { - self.print_attribute_path(&item.path)?; + self.print_meta_path(&item.path)?; self.popen()?; self.commasep(Consistent, &items[..], diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 1210f331b285b..cc70e1eea47ad 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -103,7 +103,9 @@ pub fn maybe_inject_crates_ref( krate.module.items.insert(0, P(ast::Item { attrs: vec![ast::Attribute { style: ast::AttrStyle::Outer, - path: ast::Path::from_ident(ast::Ident::new(Symbol::intern("prelude_import"), span)), + path: ast::MetaPath::from_ident( + ast::Ident::new(Symbol::intern("prelude_import"), span), + ), tokens: TokenStream::empty(), id: attr::mk_attr_id(), is_sugared_doc: false, diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 3a68278344b36..3084ee6ecf758 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -443,7 +443,7 @@ fn get_test_runner(sd: &errors::Handler, krate: &ast::Crate) -> Option Visitor<'a> for CollectProcMacros<'a> { for attr in &item.attrs { if is_proc_macro_attr(&attr) { if let Some(prev_attr) = found_attr { - let msg = if attr.path.segments[0].ident.name == - prev_attr.path.segments[0].ident.name { + let msg = if attr.path.segments[0].name == + prev_attr.path.segments[0].name { format!("Only one `#[{}]` attribute is allowed on any given function", attr.path) } else { diff --git a/src/test/mir-opt/inline-closure-borrows-arg.rs b/src/test/mir-opt/inline-closure-borrows-arg.rs index ba1712f4ca398..a3289706af93c 100644 --- a/src/test/mir-opt/inline-closure-borrows-arg.rs +++ b/src/test/mir-opt/inline-closure-borrows-arg.rs @@ -30,7 +30,7 @@ fn foo(_t: T, q: &i32) -> i32 { // ... // bb0: { // ... -// _3 = [closure@NodeId(53)]; +// _3 = [closure@NodeId(51)]; // ... // _4 = &_3; // ... diff --git a/src/test/mir-opt/inline-closure.rs b/src/test/mir-opt/inline-closure.rs index 9cb0a4dc2bfac..868fb2787faf9 100644 --- a/src/test/mir-opt/inline-closure.rs +++ b/src/test/mir-opt/inline-closure.rs @@ -26,7 +26,7 @@ fn foo(_t: T, q: i32) -> i32 { // ... // bb0: { // ... -// _3 = [closure@NodeId(39)]; +// _3 = [closure@NodeId(37)]; // ... // _4 = &_3; // ... diff --git a/src/test/mir-opt/retag.rs b/src/test/mir-opt/retag.rs index 7da55c0868cd2..a9aa9d3e9bd16 100644 --- a/src/test/mir-opt/retag.rs +++ b/src/test/mir-opt/retag.rs @@ -108,7 +108,7 @@ fn main() { // } // END rustc.main.EraseRegions.after.mir // START rustc.main-{{closure}}.EraseRegions.after.mir -// fn main::{{closure}}(_1: &[closure@NodeId(124)], _2: &i32) -> &i32 { +// fn main::{{closure}}(_1: &[closure@NodeId(121)], _2: &i32) -> &i32 { // ... // bb0: { // Retag([fn entry] _1); diff --git a/src/test/ui/issues/issue-43424.stderr b/src/test/ui/issues/issue-43424.stderr index 3a9a316470399..b65ab587131e2 100644 --- a/src/test/ui/issues/issue-43424.stderr +++ b/src/test/ui/issues/issue-43424.stderr @@ -1,8 +1,8 @@ error: unexpected generic arguments in path - --> $DIR/issue-43424.rs:20:4 + --> $DIR/issue-43424.rs:20:10 | LL | m!(inline); //~ ERROR: unexpected generic arguments in path - | ^^^^^^^^^^ + | ^^^^ error: aborting due to previous error diff --git a/src/test/ui/span/import-ty-params.stderr b/src/test/ui/span/import-ty-params.stderr index 7e2c2d382fd69..f3ed1bcfcdd2b 100644 --- a/src/test/ui/span/import-ty-params.stderr +++ b/src/test/ui/span/import-ty-params.stderr @@ -1,14 +1,14 @@ error: unexpected generic arguments in path - --> $DIR/import-ty-params.rs:24:15 + --> $DIR/import-ty-params.rs:24:25 | LL | import! { a::b::c::S } //~ ERROR unexpected generic arguments in path - | ^^^^^^^^^^^^^^ + | ^^^^ error: unexpected generic arguments in path - --> $DIR/import-ty-params.rs:27:15 + --> $DIR/import-ty-params.rs:27:25 | LL | import! { a::b::c::S<> } //~ ERROR unexpected generic arguments in path - | ^^^^^^^^^^^^ + | ^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/span/macro-ty-params.rs b/src/test/ui/span/macro-ty-params.rs index 5d93b1266a4ae..fc2b780245abe 100644 --- a/src/test/ui/span/macro-ty-params.rs +++ b/src/test/ui/span/macro-ty-params.rs @@ -17,6 +17,5 @@ macro_rules! m { fn main() { foo::!(); //~ ERROR generic arguments in macro path foo::<>!(); //~ ERROR generic arguments in macro path - m!(MyTrait<>); //~ ERROR generic arguments in macro path - //~^ ERROR unexpected generic arguments in path + m!(MyTrait<>); //~ ERROR unexpected generic arguments in path } diff --git a/src/test/ui/span/macro-ty-params.stderr b/src/test/ui/span/macro-ty-params.stderr index 8a40556a6cd0e..fba55efe832ff 100644 --- a/src/test/ui/span/macro-ty-params.stderr +++ b/src/test/ui/span/macro-ty-params.stderr @@ -1,13 +1,7 @@ error: unexpected generic arguments in path - --> $DIR/macro-ty-params.rs:20:8 - | -LL | m!(MyTrait<>); //~ ERROR generic arguments in macro path - | ^^^^^^^^^ - -error: generic arguments in macro path --> $DIR/macro-ty-params.rs:20:15 | -LL | m!(MyTrait<>); //~ ERROR generic arguments in macro path +LL | m!(MyTrait<>); //~ ERROR unexpected generic arguments in path | ^^ error: generic arguments in macro path @@ -22,5 +16,5 @@ error: generic arguments in macro path LL | foo::<>!(); //~ ERROR generic arguments in macro path | ^^^^ -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors diff --git a/src/test/ui/span/visibility-ty-params.stderr b/src/test/ui/span/visibility-ty-params.stderr index 7719bd48c85bb..4b3f9e21c1c44 100644 --- a/src/test/ui/span/visibility-ty-params.stderr +++ b/src/test/ui/span/visibility-ty-params.stderr @@ -1,14 +1,14 @@ error: unexpected generic arguments in path - --> $DIR/visibility-ty-params.rs:16:5 + --> $DIR/visibility-ty-params.rs:16:6 | LL | m!{ S } //~ ERROR unexpected generic arguments in path - | ^^^^^ + | ^^^^ error: unexpected generic arguments in path - --> $DIR/visibility-ty-params.rs:19:9 + --> $DIR/visibility-ty-params.rs:19:10 | LL | m!{ m<> } //~ ERROR unexpected generic arguments in path - | ^^^ + | ^^ error: aborting due to 2 previous errors From 3a83d240dffe100cc2a78ef05ca0967d6b77e3a2 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 2 Dec 2018 22:47:41 +0200 Subject: [PATCH 04/15] Start using serde_derive in a couple places in the compiler. --- Cargo.lock | 5 +++++ src/librustc_cratesio_shim/Cargo.toml | 1 + src/librustc_cratesio_shim/src/lib.rs | 1 + src/librustc_errors/Cargo.toml | 2 ++ src/librustc_errors/lib.rs | 8 +++++++- src/libsyntax_pos/Cargo.toml | 2 ++ src/libsyntax_pos/lib.rs | 8 +++++++- src/tools/tidy/src/deps.rs | 6 ++++++ 8 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 72f3077d2be40..1231a60be8662 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2223,6 +2223,7 @@ version = "0.0.0" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2288,6 +2289,8 @@ dependencies = [ "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_cratesio_shim 0.0.0", "rustc_data_structures 0.0.0", + "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", "syntax_pos 0.0.0", "termcolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2901,6 +2904,8 @@ dependencies = [ "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_data_structures 0.0.0", "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/src/librustc_cratesio_shim/Cargo.toml b/src/librustc_cratesio_shim/Cargo.toml index b8e494e4040ec..a0886cd314baf 100644 --- a/src/librustc_cratesio_shim/Cargo.toml +++ b/src/librustc_cratesio_shim/Cargo.toml @@ -22,4 +22,5 @@ crate-type = ["dylib"] [dependencies] bitflags = "1.0" log = "0.4" +serde = "1.0" unicode-width = "0.1.4" diff --git a/src/librustc_cratesio_shim/src/lib.rs b/src/librustc_cratesio_shim/src/lib.rs index 56e480208e1c3..16caf0e129eaf 100644 --- a/src/librustc_cratesio_shim/src/lib.rs +++ b/src/librustc_cratesio_shim/src/lib.rs @@ -16,4 +16,5 @@ extern crate bitflags; extern crate log; extern crate proc_macro; +extern crate serde; extern crate unicode_width; diff --git a/src/librustc_errors/Cargo.toml b/src/librustc_errors/Cargo.toml index b24f8ddf4d9f7..c8725709de555 100644 --- a/src/librustc_errors/Cargo.toml +++ b/src/librustc_errors/Cargo.toml @@ -14,6 +14,8 @@ serialize = { path = "../libserialize" } syntax_pos = { path = "../libsyntax_pos" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_cratesio_shim = { path = "../librustc_cratesio_shim" } +serde = "1.0" +serde_derive = "1.0" unicode-width = "0.1.4" atty = "0.2" termcolor = "1.0" diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 0fb77a7a3ab52..15b522036045f 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -26,6 +26,9 @@ extern crate libc; #[macro_use] extern crate log; extern crate rustc_data_structures; +#[macro_use] +extern crate serde_derive; +extern crate serde; extern crate serialize as rustc_serialize; extern crate syntax_pos; extern crate unicode_width; @@ -66,7 +69,10 @@ use syntax_pos::{BytePos, Span, NO_EXPANSION}; -#[derive(Copy, Clone, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Hash, + RustcDecodable, RustcEncodable, + Serialize, Deserialize, +)] pub enum Applicability { MachineApplicable, HasPlaceholders, diff --git a/src/libsyntax_pos/Cargo.toml b/src/libsyntax_pos/Cargo.toml index 08ee2e0f37626..f61749a2b5d45 100644 --- a/src/libsyntax_pos/Cargo.toml +++ b/src/libsyntax_pos/Cargo.toml @@ -13,5 +13,7 @@ serialize = { path = "../libserialize" } rustc_data_structures = { path = "../librustc_data_structures" } arena = { path = "../libarena" } scoped-tls = { version = "0.1.1", features = ["nightly"] } +serde = "1.0" +serde_derive = "1.0" unicode-width = "0.1.4" cfg-if = "0.1.2" diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 34fb71e4ddf68..7d688b1f9912a 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -43,6 +43,9 @@ extern crate rustc_data_structures; #[macro_use] extern crate scoped_tls; +#[macro_use] +extern crate serde_derive; +extern crate serde; use serialize::{Encodable, Decodable, Encoder, Decoder}; @@ -84,7 +87,10 @@ impl Globals { scoped_thread_local!(pub static GLOBALS: Globals); /// Differentiates between real files and common virtual files -#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, RustcDecodable, RustcEncodable)] +#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, + RustcDecodable, RustcEncodable, + Serialize, Deserialize, +)] pub enum FileName { Real(PathBuf), /// A macro. This includes the full name of the macro, so that there are no clashes. diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index a40ae8894d5e7..b467a284d9e9d 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -107,7 +107,9 @@ const WHITELIST: &[Crate] = &[ Crate("parking_lot_core"), Crate("pkg-config"), Crate("polonius-engine"), + Crate("proc-macro2"), Crate("quick-error"), + Crate("quote"), Crate("rand"), Crate("rand_core"), Crate("redox_syscall"), @@ -121,8 +123,11 @@ const WHITELIST: &[Crate] = &[ Crate("rustc-rayon-core"), Crate("scoped-tls"), Crate("scopeguard"), + Crate("serde"), + Crate("serde_derive"), Crate("smallvec"), Crate("stable_deref_trait"), + Crate("syn"), Crate("tempfile"), Crate("termcolor"), Crate("terminon"), @@ -130,6 +135,7 @@ const WHITELIST: &[Crate] = &[ Crate("thread_local"), Crate("ucd-util"), Crate("unicode-width"), + Crate("unicode-xid"), Crate("unreachable"), Crate("utf8-ranges"), Crate("version_check"), From 70aeb7997009aa93f39f06baf47c779042ff1d47 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 2 Dec 2018 23:38:54 +0200 Subject: [PATCH 05/15] bootstrap: include host deps, not just target ones, in `run_cargo`. --- src/bootstrap/compile.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index b6bb11d07ef04..4f290f6664ea8 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -1064,15 +1064,9 @@ pub fn run_cargo(builder: &Builder, let filename = Path::new(&*filename); - // If this was an output file in the "host dir" we don't actually - // worry about it, it's not relevant for us. - if filename.starts_with(&host_root_dir) { - continue; - } - // If this was output in the `deps` dir then this is a precise file // name (hash included) so we start tracking it. - if filename.starts_with(&target_deps_dir) { + if filename.starts_with(&host_root_dir) || filename.starts_with(&target_deps_dir) { deps.push(filename.to_path_buf()); continue; } From 51a6a2ff793aa267193c06b45f2f5685ebe27433 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 3 Dec 2018 08:17:21 +0200 Subject: [PATCH 06/15] bootstrap: respect `RUSTC_FORCE_UNSTABLE` for build script/proc macro crates, too. --- src/bootstrap/bin/rustc.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index d18a48e5d2270..e0e124fb4831f 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -268,13 +268,6 @@ fn main() { } } - // Force all crates compiled by this compiler to (a) be unstable and (b) - // allow the `rustc_private` feature to link to other unstable crates - // also in the sysroot. - if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() { - cmd.arg("-Z").arg("force-unstable-if-unmarked"); - } - if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") { cmd.arg("--remap-path-prefix").arg(&map); } @@ -294,6 +287,13 @@ fn main() { } } + // Force all crates compiled by this compiler to (a) be unstable and (b) + // allow the `rustc_private` feature to link to other unstable crates + // also in the sysroot. + if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() { + cmd.arg("-Z").arg("force-unstable-if-unmarked"); + } + if env::var_os("RUSTC_PARALLEL_QUERIES").is_some() { cmd.arg("--cfg").arg("parallel_queries"); } From 389ad1d95a26d76967b5a9b3744da6c1fccfb2de Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 2 Dec 2018 17:17:44 +0200 Subject: [PATCH 07/15] rustc_target: remove unused #[derive(RustcEncodable, RustcDecodable)]. --- src/librustc_target/abi/mod.rs | 2 +- src/librustc_target/spec/mod.rs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index 50ce0ad6915da..3c8216265cc7c 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -424,7 +424,7 @@ impl Align { } /// A pair of aligments, ABI-mandated and preferred. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct AbiAndPrefAlign { pub abi: Align, pub pref: Align, diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 3285ccfd6c12d..fe977e33a0a5d 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -76,8 +76,7 @@ mod fuchsia_base; mod redox_base; mod riscv_base; -#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash, - RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] pub enum LinkerFlavor { Em, Gcc, @@ -86,8 +85,7 @@ pub enum LinkerFlavor { Lld(LldFlavor), } -#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash, - RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Hash)] pub enum LldFlavor { Wasm, Ld64, @@ -182,7 +180,7 @@ impl ToJson for PanicStrategy { } } -#[derive(Clone, Copy, Debug, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, Debug, PartialEq, Hash)] pub enum RelroLevel { Full, Partial, From 4750cdb34cbd455bff4a5756820546e6c76d8818 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 4 Dec 2018 16:32:42 +0200 Subject: [PATCH 08/15] rustdoc: remove unused #[derive(RustcEncodable, RustcDecodable)]. --- src/librustdoc/clean/mod.rs | 105 +++++++++++++++---------------- src/librustdoc/html/format.rs | 3 - src/librustdoc/html/item_type.rs | 1 - src/librustdoc/html/render.rs | 3 - 4 files changed, 51 insertions(+), 61 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index fd8f70b19e7ec..cd6ea0f3ba7d5 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -230,7 +230,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> Clean for visit_ast::RustdocVisitor<'a, 'tc } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct ExternalCrate { pub name: String, pub src: FileName, @@ -357,7 +357,7 @@ impl Clean for CrateNum { /// Anything with a source location and set of attributes and, optionally, a /// name. That is, anything that can be documented. This doesn't correspond /// directly to the AST's concept of an item; it's a strict superset. -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone)] pub struct Item { /// Stringified span pub source: Span, @@ -506,7 +506,7 @@ impl Item { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub enum ItemEnum { ExternCrateItem(String, Option), ImportItem(Import), @@ -570,7 +570,7 @@ impl ItemEnum { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Module { pub items: Vec, pub is_crate: bool, @@ -706,7 +706,7 @@ impl> NestedAttributesExt for I { /// Included files are kept separate from inline doc comments so that proper line-number /// information can be given when a doctest fails. Sugared doc comments and "raw" doc comments are /// kept separate because of issue #42760. -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub enum DocFragment { // FIXME #44229 (misdreavus): sugared and raw doc comments can be brought back together once // hoedown is completely removed from rustdoc. @@ -758,7 +758,7 @@ impl<'a> FromIterator<&'a DocFragment> for String { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Default)] +#[derive(Clone, Debug, Default)] pub struct Attributes { pub doc_strings: Vec, pub other_attrs: Vec, @@ -1021,7 +1021,7 @@ impl Clean for [ast::Attribute] { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub enum GenericBound { TraitBound(PolyTrait, hir::TraitBoundModifier), Outlives(Lifetime), @@ -1197,7 +1197,7 @@ impl<'tcx> Clean>> for Substs<'tcx> { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct Lifetime(String); impl Lifetime { @@ -1281,7 +1281,7 @@ impl Clean> for ty::RegionKind { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub enum WherePredicate { BoundPredicate { ty: Type, bounds: Vec }, RegionPredicate { lifetime: Lifetime, bounds: Vec }, @@ -1394,7 +1394,7 @@ impl<'tcx> Clean for ty::ProjectionTy<'tcx> { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub enum GenericParamDefKind { Lifetime, Type { @@ -1405,7 +1405,7 @@ pub enum GenericParamDefKind { }, } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct GenericParamDef { pub name: String, @@ -1489,7 +1489,7 @@ impl Clean for hir::GenericParam { } // maybe use a Generic enum and use Vec? -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Default, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Default, Hash)] pub struct Generics { pub params: Vec, pub where_predicates: Vec, @@ -1637,7 +1637,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Method { pub generics: Generics, pub decl: FnDecl, @@ -1657,14 +1657,14 @@ impl<'a> Clean for (&'a hir::MethodSig, &'a hir::Generics, hir::BodyId) } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct TyMethod { pub header: hir::FnHeader, pub decl: FnDecl, pub generics: Generics, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Function { pub decl: FnDecl, pub generics: Generics, @@ -1694,7 +1694,7 @@ impl Clean for doctree::Function { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct FnDecl { pub inputs: Arguments, pub output: FunctionRetTy, @@ -1708,7 +1708,7 @@ impl FnDecl { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct Arguments { pub values: Vec, } @@ -1784,13 +1784,13 @@ impl<'a, 'tcx> Clean for (DefId, ty::PolyFnSig<'tcx>) { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct Argument { pub type_: Type, pub name: String, } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)] +#[derive(Clone, PartialEq, Debug)] pub enum SelfTy { SelfValue, SelfBorrowed(Option, Mutability), @@ -1814,7 +1814,7 @@ impl Argument { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub enum FunctionRetTy { Return(Type), DefaultReturn, @@ -1838,7 +1838,7 @@ impl GetDefId for FunctionRetTy { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Trait { pub auto: bool, pub unsafety: hir::Unsafety, @@ -2118,7 +2118,7 @@ impl<'tcx> Clean for ty::AssociatedItem { } /// A trait reference, which may have higher ranked lifetimes. -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct PolyTrait { pub trait_: Type, pub generic_params: Vec, @@ -2127,7 +2127,7 @@ pub struct PolyTrait { /// A representation of a Type suitable for hyperlinking purposes. Ideally one can get the original /// type out of the AST/TyCtxt given one of these, if more information is needed. Most importantly /// it does not preserve mutability or boxes. -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub enum Type { /// structs/enums/traits (most that'd be an hir::TyKind::Path) ResolvedPath { @@ -2149,7 +2149,6 @@ pub enum Type { Slice(Box), Array(Box, String), Never, - Unique(Box), RawPointer(Mutability, Box), BorrowedRef { lifetime: Option, @@ -2171,7 +2170,7 @@ pub enum Type { ImplTrait(Vec), } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Copy, Debug)] +#[derive(Clone, PartialEq, Eq, Hash, Copy, Debug)] pub enum PrimitiveType { Isize, I8, I16, I32, I64, I128, Usize, U8, U16, U32, U64, U128, @@ -2189,7 +2188,7 @@ pub enum PrimitiveType { Never, } -#[derive(Clone, RustcEncodable, RustcDecodable, Copy, Debug)] +#[derive(Clone, Copy, Debug)] pub enum TypeKind { Enum, Function, @@ -2199,7 +2198,6 @@ pub enum TypeKind { Struct, Union, Trait, - Variant, Typedef, Foreign, Macro, @@ -2783,7 +2781,7 @@ impl<'tcx> Clean for ty::FieldDef { } } -#[derive(Clone, PartialEq, Eq, RustcDecodable, RustcEncodable, Debug)] +#[derive(Clone, PartialEq, Eq, Debug)] pub enum Visibility { Public, Inherited, @@ -2812,7 +2810,7 @@ impl Clean> for ty::Visibility { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Struct { pub struct_type: doctree::StructType, pub generics: Generics, @@ -2820,7 +2818,7 @@ pub struct Struct { pub fields_stripped: bool, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Union { pub struct_type: doctree::StructType, pub generics: Generics, @@ -2871,7 +2869,7 @@ impl Clean for doctree::Union { /// This is a more limited form of the standard Struct, different in that /// it lacks the things most items have (name, id, parameterization). Found /// only as a variant in an enum. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct VariantStruct { pub struct_type: doctree::StructType, pub fields: Vec, @@ -2888,7 +2886,7 @@ impl Clean for ::rustc::hir::VariantData { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Enum { pub variants: IndexVec, pub generics: Generics, @@ -2914,7 +2912,7 @@ impl Clean for doctree::Enum { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Variant { pub kind: VariantKind, } @@ -2977,7 +2975,7 @@ impl<'tcx> Clean for ty::VariantDef { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub enum VariantKind { CLike, Tuple(Vec), @@ -2996,7 +2994,7 @@ impl Clean for hir::VariantData { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Span { pub filename: FileName, pub loline: usize, @@ -3035,7 +3033,7 @@ impl Clean for syntax_pos::Span { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct Path { pub global: bool, pub def: Def, @@ -3058,7 +3056,7 @@ impl Clean for hir::Path { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub enum GenericArgs { AngleBracketed { lifetimes: Vec, @@ -3104,7 +3102,7 @@ impl Clean for hir::GenericArgs { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct PathSegment { pub name: String, pub args: GenericArgs, @@ -3129,7 +3127,6 @@ fn strip_type(ty: Type) -> Type { } Type::Slice(inner_ty) => Type::Slice(Box::new(strip_type(*inner_ty))), Type::Array(inner_ty, s) => Type::Array(Box::new(strip_type(*inner_ty)), s), - Type::Unique(inner_ty) => Type::Unique(Box::new(strip_type(*inner_ty))), Type::RawPointer(m, inner_ty) => Type::RawPointer(m, Box::new(strip_type(*inner_ty))), Type::BorrowedRef { lifetime, mutability, type_ } => { Type::BorrowedRef { lifetime, mutability, type_: Box::new(strip_type(*type_)) } @@ -3193,7 +3190,7 @@ impl Clean for InternedString { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Typedef { pub type_: Type, pub generics: Generics, @@ -3217,7 +3214,7 @@ impl Clean for doctree::Typedef { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Existential { pub bounds: Vec, pub generics: Generics, @@ -3241,7 +3238,7 @@ impl Clean for doctree::Existential { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct BareFunctionDecl { pub unsafety: hir::Unsafety, pub generic_params: Vec, @@ -3263,7 +3260,7 @@ impl Clean for hir::BareFnTy { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Static { pub type_: Type, pub mutability: Mutability, @@ -3293,7 +3290,7 @@ impl Clean for doctree::Static { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Constant { pub type_: Type, pub expr: String, @@ -3317,7 +3314,7 @@ impl Clean for doctree::Constant { } } -#[derive(Debug, Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Copy, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Copy, Hash)] pub enum Mutability { Mutable, Immutable, @@ -3332,7 +3329,7 @@ impl Clean for hir::Mutability { } } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Copy, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Copy, Debug, Hash)] pub enum ImplPolarity { Positive, Negative, @@ -3347,7 +3344,7 @@ impl Clean for hir::ImplPolarity { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Impl { pub unsafety: hir::Unsafety, pub generics: Generics, @@ -3557,7 +3554,7 @@ impl Clean> for doctree::Import { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub enum Import { // use source as str; Simple(String, ImportSource), @@ -3565,7 +3562,7 @@ pub enum Import { Glob(ImportSource) } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct ImportSource { pub path: Path, pub did: Option, @@ -3785,7 +3782,7 @@ fn resolve_use_source(cx: &DocContext, path: Path) -> ImportSource { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Macro { pub source: String, pub imported_from: Option, @@ -3814,7 +3811,7 @@ impl Clean for doctree::Macro { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct ProcMacro { pub kind: MacroKind, pub helpers: Vec, @@ -3838,7 +3835,7 @@ impl Clean for doctree::ProcMacro { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Stability { pub level: stability::StabilityLevel, pub feature: String, @@ -3849,7 +3846,7 @@ pub struct Stability { pub issue: Option } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Deprecation { pub since: String, pub note: String, @@ -3900,7 +3897,7 @@ impl Clean for attr::Deprecation { } /// An equality constraint on an associated type, e.g. `A=Bar` in `Foo` -#[derive(Clone, PartialEq, Eq, RustcDecodable, RustcEncodable, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct TypeBinding { pub name: String, pub ty: Type diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 445fc2e833a3f..0d9b8483944f7 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -728,9 +728,6 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: } } } - clean::Unique(..) => { - panic!("should have been cleaned") - } } } diff --git a/src/librustdoc/html/item_type.rs b/src/librustdoc/html/item_type.rs index acb8f6a66dfcb..43059d0c041b7 100644 --- a/src/librustdoc/html/item_type.rs +++ b/src/librustdoc/html/item_type.rs @@ -118,7 +118,6 @@ impl From for ItemType { clean::TypeKind::Module => ItemType::Module, clean::TypeKind::Static => ItemType::Static, clean::TypeKind::Const => ItemType::Constant, - clean::TypeKind::Variant => ItemType::Variant, clean::TypeKind::Typedef => ItemType::Typedef, clean::TypeKind::Foreign => ItemType::ForeignType, clean::TypeKind::Macro => ItemType::Macro, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index b46efb20d8f6b..c43a516c53437 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -4824,9 +4824,6 @@ fn collect_paths_for_type(first_ty: clean::Type) -> Vec { clean::Type::Array(ty, _) => { work.push_back(*ty); }, - clean::Type::Unique(ty) => { - work.push_back(*ty); - }, clean::Type::RawPointer(_, ty) => { work.push_back(*ty); }, From 54cf40fc9d1f26e794298b030428514e5d0c4c6a Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 2 Dec 2018 19:58:33 +0200 Subject: [PATCH 09/15] rustc_target: move from rustc_serialize::json to serde_json. --- Cargo.lock | 2 + src/librustc_driver/Cargo.toml | 1 + src/librustc_driver/lib.rs | 9 +- src/librustc_target/Cargo.toml | 1 + src/librustc_target/lib.rs | 1 + src/librustc_target/spec/mod.rs | 145 +++++++++++++++++++++----------- src/tools/tidy/src/deps.rs | 3 + 7 files changed, 109 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1231a60be8662..cc4dcff916337 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2274,6 +2274,7 @@ dependencies = [ "rustc_traits 0.0.0", "rustc_typeck 0.0.0", "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", @@ -2479,6 +2480,7 @@ dependencies = [ "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_cratesio_shim 0.0.0", "rustc_data_structures 0.0.0", + "serde_json 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", ] diff --git a/src/librustc_driver/Cargo.toml b/src/librustc_driver/Cargo.toml index 1e32f5ef6f0b6..8f8c53676f598 100644 --- a/src/librustc_driver/Cargo.toml +++ b/src/librustc_driver/Cargo.toml @@ -33,6 +33,7 @@ rustc_save_analysis = { path = "../librustc_save_analysis" } rustc_traits = { path = "../librustc_traits" } rustc_codegen_utils = { path = "../librustc_codegen_utils" } rustc_typeck = { path = "../librustc_typeck" } +serde_json = "1.0" serialize = { path = "../libserialize" } syntax = { path = "../libsyntax" } smallvec = { version = "0.6.5", features = ["union"] } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 4527c78b31ee7..c1dc9901eb3f9 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -56,6 +56,7 @@ extern crate rustc_traits; extern crate rustc_codegen_utils; extern crate rustc_typeck; extern crate scoped_tls; +extern crate serde_json; extern crate serialize; extern crate smallvec; #[macro_use] @@ -94,8 +95,6 @@ use rustc_metadata::dynamic_lib::DynamicLibrary; use rustc::util::common::{time, ErrorReported}; use rustc_codegen_utils::codegen_backend::CodegenBackend; -use serialize::json::ToJson; - use std::any::Any; use std::borrow::Cow; use std::cmp::max; @@ -1043,7 +1042,11 @@ impl RustcDefaultCalls { println!("{}", targets.join("\n")); }, Sysroot => println!("{}", sess.sysroot().display()), - TargetSpec => println!("{}", sess.target.target.to_json().pretty()), + TargetSpec => { + use rustc_target::spec::ToJson; + let json = sess.target.target.to_json(); + println!("{}", serde_json::to_string_pretty(&json).unwrap()); + } FileNames | CrateName => { let input = input.unwrap_or_else(|| early_error(ErrorOutputType::default(), "no input file provided")); diff --git a/src/librustc_target/Cargo.toml b/src/librustc_target/Cargo.toml index dfdd7f0ae58e5..becf6fd456cde 100644 --- a/src/librustc_target/Cargo.toml +++ b/src/librustc_target/Cargo.toml @@ -13,4 +13,5 @@ bitflags = "1.0" log = "0.4" rustc_cratesio_shim = { path = "../librustc_cratesio_shim" } rustc_data_structures = { path = "../librustc_data_structures" } +serde_json = "1.0" serialize = { path = "../libserialize" } diff --git a/src/librustc_target/lib.rs b/src/librustc_target/lib.rs index 813b39de06413..1d45e877e536b 100644 --- a/src/librustc_target/lib.rs +++ b/src/librustc_target/lib.rs @@ -31,6 +31,7 @@ extern crate bitflags; extern crate serialize; #[macro_use] extern crate log; +extern crate serde_json; extern crate serialize as rustc_serialize; // used by deriving diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index fe977e33a0a5d..8380a4ae02a16 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -44,7 +44,6 @@ //! the target's settings, though `target-feature` and `link-args` will *add* //! to the list specified by the target, rather than replace. -use serialize::json::{Json, ToJson}; use std::collections::BTreeMap; use std::default::Default; use std::{fmt, io}; @@ -105,8 +104,56 @@ impl LldFlavor { } } -impl ToJson for LldFlavor { - fn to_json(&self) -> Json { +// HACK(eddyb) Temporary workaround until we can use `serde_derive`. +pub trait ToJson { + fn to_json(&self) -> ::serde_json::Value; +} + +impl ToJson for [T] { + fn to_json(&self) -> ::serde_json::Value { + self.iter().map(ToJson::to_json).collect() + } +} + +impl ToJson for Vec { + fn to_json(&self) -> ::serde_json::Value { + self[..].to_json() + } +} + +impl ToJson for Option { + fn to_json(&self) -> ::serde_json::Value { + self.as_ref().map_or(::serde_json::Value::Null, ToJson::to_json) + } +} + +macro_rules! impl_to_json { + ($x:ident: &$ty:ty => $e:expr) => { + impl ToJson for $ty { + fn to_json(&self) -> ::serde_json::Value { + let $x = self; + Into::into($e) + } + } + }; + ($ty:ty) => { + impl_to_json!(x: &$ty => x); + } +} + +impl_to_json!(x: &bool => *x); +impl_to_json!(x: &u64 => *x); +impl_to_json!(str); +impl_to_json!(s: &String => &s[..]); + +impl_to_json!(LldFlavor); +impl_to_json!(LinkerFlavor); +impl_to_json!(PanicStrategy); +impl_to_json!(RelroLevel); +impl_to_json!(Target); + +impl Into<::serde_json::Value> for &'_ LldFlavor { + fn into(self) -> ::serde_json::Value { match *self { LldFlavor::Ld64 => "darwin", LldFlavor::Ld => "gnu", @@ -116,8 +163,8 @@ impl ToJson for LldFlavor { } } -impl ToJson for LinkerFlavor { - fn to_json(&self) -> Json { +impl Into<::serde_json::Value> for &'_ LinkerFlavor { + fn into(self) -> ::serde_json::Value { self.desc().to_json() } } @@ -171,9 +218,9 @@ impl PanicStrategy { } } -impl ToJson for PanicStrategy { - fn to_json(&self) -> Json { - match *self { +impl Into<::serde_json::Value> for &'_ PanicStrategy { + fn into(self) -> ::serde_json::Value { + match self { PanicStrategy::Abort => "abort".to_json(), PanicStrategy::Unwind => "unwind".to_json(), } @@ -213,9 +260,9 @@ impl FromStr for RelroLevel { } } -impl ToJson for RelroLevel { - fn to_json(&self) -> Json { - match *self { +impl Into<::serde_json::Value> for &'_ RelroLevel { + fn into(self) -> ::serde_json::Value { + match self { RelroLevel::Full => "full".to_json(), RelroLevel::Partial => "partial".to_json(), RelroLevel::Off => "off".to_json(), @@ -262,7 +309,6 @@ macro_rules! supported_targets { #[cfg(test)] mod test_json_encode_decode { - use serialize::json::ToJson; use super::Target; $(use super::$module;)* @@ -819,7 +865,7 @@ impl Target { } /// Load a target descriptor from a JSON object. - pub fn from_json(obj: Json) -> TargetResult { + pub fn from_json(obj: ::serde_json::Value) -> TargetResult { // While ugly, this code must remain this way to retain // compatibility with existing JSON fields and the internal // expected naming of the Target and TargetOptions structs. @@ -828,14 +874,14 @@ impl Target { // the JSON parser is not updated to match the structs. let get_req_field = |name: &str| { - obj.find(name) - .map(|s| s.as_string()) + obj.get(name) + .map(|s| s.as_str()) .and_then(|os| os.map(|s| s.to_string())) .ok_or_else(|| format!("Field {} in target specification is required", name)) }; let get_opt_field = |name: &str, default: &str| { - obj.find(name).and_then(|s| s.as_string()) + obj.get(name).and_then(|s| s.as_str()) .map(|s| s.to_string()) .unwrap_or_else(|| default.to_string()) }; @@ -860,24 +906,24 @@ impl Target { macro_rules! key { ($key_name:ident) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]).map(|o| o.as_string() + obj.get(&name[..]).map(|o| o.as_str() .map(|s| base.options.$key_name = s.to_string())); } ); ($key_name:ident, bool) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]) - .map(|o| o.as_boolean() + obj.get(&name[..]) + .map(|o| o.as_bool() .map(|s| base.options.$key_name = s)); } ); ($key_name:ident, Option) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]) + obj.get(&name[..]) .map(|o| o.as_u64() .map(|s| base.options.$key_name = Some(s))); } ); ($key_name:ident, PanicStrategy) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| { + obj.get(&name[..]).and_then(|o| o.as_str().and_then(|s| { match s { "unwind" => base.options.$key_name = PanicStrategy::Unwind, "abort" => base.options.$key_name = PanicStrategy::Abort, @@ -890,7 +936,7 @@ impl Target { } ); ($key_name:ident, RelroLevel) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| { + obj.get(&name[..]).and_then(|o| o.as_str().and_then(|s| { match s.parse::() { Ok(level) => base.options.$key_name = level, _ => return Some(Err(format!("'{}' is not a valid value for \ @@ -902,31 +948,31 @@ impl Target { } ); ($key_name:ident, list) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]).map(|o| o.as_array() + obj.get(&name[..]).map(|o| o.as_array() .map(|v| base.options.$key_name = v.iter() - .map(|a| a.as_string().unwrap().to_string()).collect() + .map(|a| a.as_str().unwrap().to_string()).collect() ) ); } ); ($key_name:ident, opt_list) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]).map(|o| o.as_array() + obj.get(&name[..]).map(|o| o.as_array() .map(|v| base.options.$key_name = Some(v.iter() - .map(|a| a.as_string().unwrap().to_string()).collect()) + .map(|a| a.as_str().unwrap().to_string()).collect()) ) ); } ); ($key_name:ident, optional) => ( { let name = (stringify!($key_name)).replace("_", "-"); - if let Some(o) = obj.find(&name[..]) { + if let Some(o) = obj.get(&name[..]) { base.options.$key_name = o - .as_string() + .as_str() .map(|s| s.to_string() ); } } ); ($key_name:ident, LldFlavor) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]).and_then(|o| o.as_string().and_then(|s| { + obj.get(&name[..]).and_then(|o| o.as_str().and_then(|s| { if let Some(flavor) = LldFlavor::from_str(&s) { base.options.$key_name = flavor; } else { @@ -940,7 +986,7 @@ impl Target { } ); ($key_name:ident, LinkerFlavor) => ( { let name = (stringify!($key_name)).replace("_", "-"); - obj.find(&name[..]).and_then(|o| o.as_string().map(|s| { + obj.get(&name[..]).and_then(|o| o.as_str().map(|s| { LinkerFlavor::from_str(&s).ok_or_else(|| { Err(format!("'{}' is not a valid value for linker-flavor. \ Use 'em', 'gcc', 'ld' or 'msvc.", s)) @@ -949,7 +995,7 @@ impl Target { } ); ($key_name:ident, link_args) => ( { let name = (stringify!($key_name)).replace("_", "-"); - if let Some(val) = obj.find(&name[..]) { + if let Some(val) = obj.get(&name[..]) { let obj = val.as_object().ok_or_else(|| format!("{}: expected a \ JSON object with fields per linker-flavor.", name))?; let mut args = LinkArgs::new(); @@ -963,9 +1009,9 @@ impl Target { format!("{}.{}: expected a JSON array", name, k) )?.iter().enumerate() .map(|(i,s)| { - let s = s.as_string().ok_or_else(|| + let s = s.as_str().ok_or_else(|| format!("{}.{}[{}]: expected a JSON string", name, k, i))?; - Ok(s.to_owned()) + Ok(s.to_string()) }) .collect::, String>>()?; @@ -976,9 +1022,9 @@ impl Target { } ); ($key_name:ident, env) => ( { let name = (stringify!($key_name)).replace("_", "-"); - if let Some(a) = obj.find(&name[..]).and_then(|o| o.as_array()) { + if let Some(a) = obj.get(&name[..]).and_then(|o| o.as_array()) { for o in a { - if let Some(s) = o.as_string() { + if let Some(s) = o.as_str() { let p = s.split('=').collect::>(); if p.len() == 2 { let k = p[0].to_string(); @@ -1065,8 +1111,8 @@ impl Target { key!(simd_types_indirect, bool); key!(override_export_symbols, opt_list); - if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) { - for name in array.iter().filter_map(|abi| abi.as_string()) { + if let Some(array) = obj.get("abi-blacklist").and_then(::serde_json::Value::as_array) { + for name in array.iter().filter_map(|abi| abi.as_str()) { match lookup_abi(name) { Some(abi) => { if abi.generic() { @@ -1094,11 +1140,10 @@ impl Target { pub fn search(target_triple: &TargetTriple) -> Result { use std::env; use std::fs; - use serialize::json; fn load_file(path: &Path) -> Result { let contents = fs::read(path).map_err(|e| e.to_string())?; - let obj = json::from_reader(&mut &contents[..]) + let obj = ::serde_json::from_reader(&mut &contents[..]) .map_err(|e| e.to_string())?; Target::from_json(obj) } @@ -1139,9 +1184,9 @@ impl Target { } } -impl ToJson for Target { - fn to_json(&self) -> Json { - let mut d = BTreeMap::new(); +impl Into<::serde_json::Value> for &'_ Target { + fn into(self) -> ::serde_json::Value { + let mut d = ::serde_json::Map::new(); let default: TargetOptions = Default::default(); macro_rules! target_val { @@ -1173,9 +1218,9 @@ impl ToJson for Target { if default.$attr != self.options.$attr { let obj = self.options.$attr .iter() - .map(|(k, v)| (k.desc().to_owned(), v.clone())) - .collect::>(); - d.insert(name, obj.to_json()); + .map(|(k, v)| (k.desc().to_string(), v[..].to_json())) + .collect::<::serde_json::Map<_, _>>(); + d.insert(name, obj.into()); } } ); (env - $attr:ident) => ( { @@ -1184,8 +1229,8 @@ impl ToJson for Target { let obj = self.options.$attr .iter() .map(|&(ref k, ref v)| k.clone() + "=" + &v) - .collect::>(); - d.insert(name, obj.to_json()); + .collect(); + d.insert(name, obj); } } ); @@ -1279,10 +1324,10 @@ impl ToJson for Target { if default.abi_blacklist != self.options.abi_blacklist { d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter() .map(|&name| Abi::name(name).to_json()) - .collect::>().to_json()); + .collect()); } - Json::Object(d) + ::serde_json::Value::Object(d) } } @@ -1333,7 +1378,7 @@ impl TargetTriple { let hash = hasher.finish(); format!("{}-{}", triple, hash) } else { - triple.to_owned() + triple.to_string() } } } diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index b467a284d9e9d..f181d47cc3f48 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -88,6 +88,7 @@ const WHITELIST: &[Crate] = &[ Crate("fuchsia-zircon-sys"), Crate("getopts"), Crate("humantime"), + Crate("itoa"), Crate("jobserver"), Crate("kernel32-sys"), Crate("lazy_static"), @@ -121,10 +122,12 @@ const WHITELIST: &[Crate] = &[ Crate("rustc-hash"), Crate("rustc-rayon"), Crate("rustc-rayon-core"), + Crate("ryu"), Crate("scoped-tls"), Crate("scopeguard"), Crate("serde"), Crate("serde_derive"), + Crate("serde_json"), Crate("smallvec"), Crate("stable_deref_trait"), Crate("syn"), From 0def0dcaab5c794c1f6b2eacbf5bd275418e29be Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 3 Dec 2018 00:07:30 +0200 Subject: [PATCH 10/15] rustc_codegen_ssa: move from rustc_serialize::json to serde_json. --- Cargo.lock | 3 ++- src/librustc_codegen_ssa/Cargo.toml | 3 ++- src/librustc_codegen_ssa/back/linker.rs | 29 ++++++++++--------------- src/librustc_codegen_ssa/lib.rs | 4 +++- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc4dcff916337..40bddfbf4dbfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2196,7 +2196,8 @@ dependencies = [ "rustc_incremental 0.0.0", "rustc_mir 0.0.0", "rustc_target 0.0.0", - "serialize 0.0.0", + "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", "syntax 0.0.0", "syntax_pos 0.0.0", ] diff --git a/src/librustc_codegen_ssa/Cargo.toml b/src/librustc_codegen_ssa/Cargo.toml index 7b1c7cfb56f4c..ce8f9964ebbfe 100644 --- a/src/librustc_codegen_ssa/Cargo.toml +++ b/src/librustc_codegen_ssa/Cargo.toml @@ -18,8 +18,9 @@ memmap = "0.6" log = "0.4.5" libc = "0.2.43" jobserver = "0.1.11" +serde = "1.0" +serde_json = "1.0" -serialize = { path = "../libserialize" } syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } rustc = { path = "../librustc" } diff --git a/src/librustc_codegen_ssa/back/linker.rs b/src/librustc_codegen_ssa/back/linker.rs index f3cc344254fea..c9bf0bd69739d 100644 --- a/src/librustc_codegen_ssa/back/linker.rs +++ b/src/librustc_codegen_ssa/back/linker.rs @@ -13,6 +13,7 @@ use super::command::Command; use super::archive; use rustc_data_structures::fx::FxHashMap; +use serde::ser::Serializer as _; use std::ffi::{OsStr, OsString}; use std::fs::{self, File}; use std::io::prelude::*; @@ -26,7 +27,6 @@ use rustc::session::config::{self, CrateType, OptLevel, DebugInfo, CrossLangLto}; use rustc::ty::TyCtxt; use rustc_target::spec::{LinkerFlavor, LldFlavor}; -use serialize::{json, Encoder}; /// For all the linkers we support, and information they might /// need out of the shared crate context before we get rid of it. @@ -842,22 +842,17 @@ impl<'a> Linker for EmLinker<'a> { self.cmd.arg("-s"); let mut arg = OsString::from("EXPORTED_FUNCTIONS="); - let mut encoded = String::new(); - - { - let mut encoder = json::Encoder::new(&mut encoded); - let res = encoder.emit_seq(symbols.len(), |encoder| { - for (i, sym) in symbols.iter().enumerate() { - encoder.emit_seq_elt(i, |encoder| { - encoder.emit_str(&("_".to_owned() + sym)) - })?; - } - Ok(()) - }); - if let Err(e) = res { - self.sess.fatal(&format!("failed to encode exported symbols: {}", e)); - } - } + let mut encoded: Vec = vec![]; + + ::serde_json::Serializer::new(&mut encoded).collect_seq( + symbols.iter().map(|sym| "_".to_string() + sym), + ).unwrap_or_else(|e| { + self.sess.fatal(&format!("failed to encode exported symbols: {}", e)); + }); + + let encoded = String::from_utf8(encoded).unwrap_or_else(|e| { + self.sess.fatal(&format!("failed to encode exported symbols: {}", e)); + }); debug!("{}", encoded); arg.push(encoded); diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index 24ede4db6e3df..ec0dd68e74f59 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -19,6 +19,7 @@ #![feature(rustc_diagnostic_macros)] #![feature(in_band_lifetimes)] #![feature(slice_sort_by_cached_key)] +#![feature(underscore_imports)] #![feature(nll)] #![allow(unused_attributes)] #![allow(dead_code)] @@ -41,7 +42,6 @@ extern crate rustc_codegen_utils; extern crate rustc_data_structures; extern crate rustc_allocator; extern crate rustc_fs_util; -extern crate serialize; extern crate rustc_errors; extern crate rustc_demangle; extern crate cc; @@ -49,6 +49,8 @@ extern crate libc; extern crate jobserver; extern crate memmap; extern crate num_cpus; +extern crate serde; +extern crate serde_json; use std::path::PathBuf; use rustc::dep_graph::WorkProduct; From a9b9ddb729e3b12de67dc7018b4f411de0115b4b Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sun, 2 Dec 2018 22:47:41 +0200 Subject: [PATCH 11/15] syntax: move from rustc_serialize::json to serde_json for diagnostics. --- Cargo.lock | 3 +++ src/libsyntax/Cargo.toml | 3 +++ src/libsyntax/diagnostics/metadata.rs | 12 +++++------- src/libsyntax/json.rs | 22 ++++++++++------------ src/libsyntax/lib.rs | 4 ++++ 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40bddfbf4dbfc..67fbd5a722fe5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2880,6 +2880,9 @@ dependencies = [ "rustc_errors 0.0.0", "rustc_target 0.0.0", "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "syntax_pos 0.0.0", diff --git a/src/libsyntax/Cargo.toml b/src/libsyntax/Cargo.toml index 519cc7aa92c55..c831439faf007 100644 --- a/src/libsyntax/Cargo.toml +++ b/src/libsyntax/Cargo.toml @@ -17,4 +17,7 @@ syntax_pos = { path = "../libsyntax_pos" } rustc_errors = { path = "../librustc_errors" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_target = { path = "../librustc_target" } +serde = "1.0" +serde_derive = "1.0" +serde_json = "1.0" smallvec = { version = "0.6.5", features = ["union"] } diff --git a/src/libsyntax/diagnostics/metadata.rs b/src/libsyntax/diagnostics/metadata.rs index 1438299d375b6..85a65a9cc3de8 100644 --- a/src/libsyntax/diagnostics/metadata.rs +++ b/src/libsyntax/diagnostics/metadata.rs @@ -16,17 +16,15 @@ use std::collections::BTreeMap; use std::env; use std::fs::{remove_file, create_dir_all, File}; -use std::io::Write; use std::path::PathBuf; use std::error::Error; -use rustc_serialize::json::as_json; use syntax_pos::{Span, FileName}; use ext::base::ExtCtxt; use diagnostics::plugin::{ErrorMap, ErrorInfo}; -/// JSON encodable/decodable version of `ErrorInfo`. -#[derive(PartialEq, RustcDecodable, RustcEncodable)] +/// JSON serializable/deserializable version of `ErrorInfo`. +#[derive(PartialEq, Serialize, Deserialize)] pub struct ErrorMetadata { pub description: Option, pub use_site: Option @@ -35,8 +33,8 @@ pub struct ErrorMetadata { /// Mapping from error codes to metadata that can be (de)serialized. pub type ErrorMetadataMap = BTreeMap; -/// JSON encodable error location type with filename and line number. -#[derive(PartialEq, RustcDecodable, RustcEncodable)] +/// JSON serializable error location type with filename and line number. +#[derive(PartialEq, Serialize, Deserialize)] pub struct ErrorLocation { pub filename: FileName, pub line: usize @@ -94,7 +92,7 @@ pub fn output_metadata(ecx: &ExtCtxt, prefix: &str, name: &str, err_map: &ErrorM }).collect::(); // Write the data to the file, deleting it if the write fails. - let result = write!(&mut metadata_file, "{}", as_json(&json_map)); + let result = ::serde_json::to_writer(&mut metadata_file, &json_map); if result.is_err() { remove_file(&metadata_path)?; } diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs index a32682967c740..6a831bd4f6e09 100644 --- a/src/libsyntax/json.rs +++ b/src/libsyntax/json.rs @@ -31,8 +31,6 @@ use std::io::{self, Write}; use std::vec; use std::sync::{Arc, Mutex}; -use rustc_serialize::json::{as_json, as_pretty_json}; - pub struct JsonEmitter { dst: Box, registry: Option, @@ -82,19 +80,19 @@ impl Emitter for JsonEmitter { fn emit(&mut self, db: &DiagnosticBuilder) { let data = Diagnostic::from_diagnostic_builder(db, self); let result = if self.pretty { - writeln!(&mut self.dst, "{}", as_pretty_json(&data)) + ::serde_json::to_writer_pretty(&mut self.dst, &data) } else { - writeln!(&mut self.dst, "{}", as_json(&data)) + ::serde_json::to_writer(&mut self.dst, &data) }; - if let Err(e) = result { - panic!("failed to print diagnostics: {:?}", e); - } + result.unwrap_or_else(|e| panic!("failed to print diagnostics: {:?}", e)); + self.dst.write(b"\n") + .unwrap_or_else(|e| panic!("failed to print diagnostics: {:?}", e)); } } // The following data types are provided just for serialisation. -#[derive(RustcEncodable)] +#[derive(Serialize)] struct Diagnostic { /// The primary error message. message: String, @@ -108,7 +106,7 @@ struct Diagnostic { rendered: Option, } -#[derive(RustcEncodable)] +#[derive(Serialize)] #[allow(unused_attributes)] struct DiagnosticSpan { file_name: String, @@ -136,7 +134,7 @@ struct DiagnosticSpan { expansion: Option>, } -#[derive(RustcEncodable)] +#[derive(Serialize)] struct DiagnosticSpanLine { text: String, @@ -146,7 +144,7 @@ struct DiagnosticSpanLine { highlight_end: usize, } -#[derive(RustcEncodable)] +#[derive(Serialize)] struct DiagnosticSpanMacroExpansion { /// span where macro was applied to generate this code; note that /// this may itself derive from a macro (if @@ -160,7 +158,7 @@ struct DiagnosticSpanMacroExpansion { def_site_span: Option, } -#[derive(RustcEncodable)] +#[derive(Serialize)] struct DiagnosticCode { /// The code itself. code: String, diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index ca9c5ad7b600e..702a1d874852e 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -41,6 +41,10 @@ extern crate syntax_pos; extern crate rustc_target; #[macro_use] extern crate scoped_tls; #[macro_use] +extern crate serde_derive; +extern crate serde; +extern crate serde_json; +#[macro_use] extern crate smallvec; extern crate serialize as rustc_serialize; // used by deriving From ed681dcbbddb120a78b7b31849a95109320d283b Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Mon, 3 Dec 2018 11:02:29 +0200 Subject: [PATCH 12/15] syntax: move from rustc_serialize::json to serde_json for AST. --- Cargo.lock | 4 + src/librustc/hir/mod.rs | 180 ++++++++-------- src/librustc_data_structures/Cargo.toml | 2 + src/librustc_data_structures/lib.rs | 3 + src/librustc_data_structures/thin_vec.rs | 6 +- src/librustc_driver/driver.rs | 13 +- src/librustc_target/Cargo.toml | 2 + src/librustc_target/abi/mod.rs | 6 +- src/librustc_target/lib.rs | 3 + src/librustc_target/spec/abi.rs | 5 +- src/libsyntax/Cargo.toml | 2 +- src/libsyntax/ast.rs | 260 ++++++++++++++--------- src/libsyntax/attr/builtin.rs | 7 +- src/libsyntax/ext/tt/quoted.rs | 8 +- src/libsyntax/parse/token.rs | 41 +++- src/libsyntax/ptr.rs | 25 +++ src/libsyntax/source_map.rs | 5 +- src/libsyntax/tokenstream.rs | 40 +++- src/libsyntax_pos/hygiene.rs | 15 ++ src/libsyntax_pos/lib.rs | 20 +- src/libsyntax_pos/symbol.rs | 36 ++++ 21 files changed, 458 insertions(+), 225 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67fbd5a722fe5..6b6c82f9fc2d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2241,6 +2241,8 @@ dependencies = [ "rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-rayon-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_cratesio_shim 0.0.0", + "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2481,6 +2483,8 @@ dependencies = [ "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_cratesio_shim 0.0.0", "rustc_data_structures 0.0.0", + "serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", ] diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 1674320165e65..135223d20e4f1 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -150,7 +150,7 @@ pub const DUMMY_HIR_ID: HirId = HirId { pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX; -#[derive(Clone, RustcEncodable, RustcDecodable, Copy)] +#[derive(Clone, Copy)] pub struct Label { pub ident: Ident, } @@ -161,7 +161,7 @@ impl fmt::Debug for Label { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Copy)] +#[derive(Clone, Copy)] pub struct Lifetime { pub id: NodeId, pub span: Span, @@ -175,7 +175,7 @@ pub struct Lifetime { pub name: LifetimeName, } -#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)] pub enum ParamName { /// Some user-given name like `T` or `'x`. Plain(Ident), @@ -217,7 +217,7 @@ impl ParamName { } } -#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)] pub enum LifetimeName { /// User-given names or fresh (synthetic) names. Param(ParamName), @@ -300,7 +300,7 @@ impl Lifetime { /// A "Path" is essentially Rust's notion of a name; for instance: /// `std::cmp::PartialEq`. It's represented as a sequence of identifiers, /// along with a bunch of supporting information. -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone)] pub struct Path { pub span: Span, /// The definition that the path resolved to. @@ -329,7 +329,7 @@ impl fmt::Display for Path { /// A segment of a path: an identifier, an optional lifetime, and a set of /// types. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct PathSegment { /// The identifier portion of this path segment. pub ident: Ident, @@ -401,7 +401,7 @@ impl PathSegment { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub enum GenericArg { Lifetime(Lifetime), Type(Ty), @@ -423,7 +423,7 @@ impl GenericArg { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct GenericArgs { /// The generic arguments for this path segment. pub args: HirVec, @@ -485,7 +485,7 @@ impl GenericArgs { /// A modifier on a bound, currently this is only used for `?Sized`, where the /// modifier is `Maybe`. Negative bounds should also be handled here. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] pub enum TraitBoundModifier { None, Maybe, @@ -495,7 +495,7 @@ pub enum TraitBoundModifier { /// `typeck::collect::compute_bounds` matches these against /// the "special" built-in traits (see `middle::lang_items`) and /// detects `Copy`, `Send` and `Sync`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub enum GenericBound { Trait(PolyTraitRef, TraitBoundModifier), Outlives(Lifetime), @@ -512,7 +512,7 @@ impl GenericBound { pub type GenericBounds = HirVec; -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum LifetimeParamKind { // Indicates that the lifetime definition was explicitly declared, like: // `fn foo<'a>(x: &'a u8) -> &'a u8 { x }` @@ -531,7 +531,7 @@ pub enum LifetimeParamKind { Error, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub enum GenericParamKind { /// A lifetime definition, eg `'a: 'b + 'c + 'd`. Lifetime { @@ -543,7 +543,7 @@ pub enum GenericParamKind { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct GenericParam { pub id: NodeId, pub name: ParamName, @@ -563,7 +563,7 @@ pub struct GenericParamCount { /// Represents lifetimes and type parameters attached to a declaration /// of a function, enum, trait, etc. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Generics { pub params: HirVec, pub where_clause: WhereClause, @@ -616,7 +616,7 @@ pub enum SyntheticTyParamKind { } /// A `where` clause in a definition -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct WhereClause { pub id: NodeId, pub predicates: HirVec, @@ -635,7 +635,7 @@ impl WhereClause { } /// A single predicate in a `where` clause -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub enum WherePredicate { /// A type binding, eg `for<'c> Foo: Send+Clone+'c` BoundPredicate(WhereBoundPredicate), @@ -656,7 +656,7 @@ impl WherePredicate { } /// A type bound, eg `for<'c> Foo: Send+Clone+'c` -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct WhereBoundPredicate { pub span: Span, /// Any generics from a `for` binding @@ -668,7 +668,7 @@ pub struct WhereBoundPredicate { } /// A lifetime predicate, e.g. `'a: 'b+'c` -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct WhereRegionPredicate { pub span: Span, pub lifetime: Lifetime, @@ -676,7 +676,7 @@ pub struct WhereRegionPredicate { } /// An equality predicate (unsupported), e.g. `T=int` -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct WhereEqPredicate { pub id: NodeId, pub span: Span, @@ -690,7 +690,7 @@ pub struct WhereEqPredicate { /// For more details, see the [rustc guide]. /// /// [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Crate { pub module: Mod, pub attrs: HirVec, @@ -788,7 +788,7 @@ impl Crate { /// A macro definition, in this crate or imported from another. /// /// Not parsed directly, but created on macro import or `macro_rules!` expansion. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct MacroDef { pub name: Name, pub vis: Visibility, @@ -799,7 +799,7 @@ pub struct MacroDef { pub legacy: bool, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Block { /// Statements in a block pub stmts: HirVec, @@ -822,7 +822,7 @@ pub struct Block { pub recovered: bool, } -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone)] pub struct Pat { pub id: NodeId, pub hir_id: HirId, @@ -885,7 +885,7 @@ impl Pat { /// Patterns like the fields of Foo `{ x, ref y, ref mut z }` /// are treated the same as` x: x, y: ref y, z: ref mut z`, /// except is_shorthand is true -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct FieldPat { pub id: NodeId, /// The identifier for the field @@ -898,7 +898,7 @@ pub struct FieldPat { /// Explicit binding annotations given in the HIR for a binding. Note /// that this is not the final binding *mode* that we infer after type /// inference. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Debug, Copy)] pub enum BindingAnnotation { /// No binding annotation given: this means that the final binding mode /// will depend on whether we have skipped through a `&` reference @@ -919,13 +919,13 @@ pub enum BindingAnnotation { RefMut, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Debug)] pub enum RangeEnd { Included, Excluded, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub enum PatKind { /// Represents a wildcard pattern (`_`) Wild, @@ -981,7 +981,7 @@ impl Mutability { } } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash)] +#[derive(Clone, PartialEq, Debug, Copy, Hash)] pub enum BinOpKind { /// The `+` operator (addition) Add, @@ -1115,7 +1115,7 @@ impl Into for BinOpKind { pub type BinOp = Spanned; -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash)] +#[derive(Clone, PartialEq, Debug, Copy, Hash)] pub enum UnOp { /// The `*` operator for dereferencing UnDeref, @@ -1157,7 +1157,7 @@ impl fmt::Debug for StmtKind { } } -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone)] pub enum StmtKind { /// Could be an item or a local (let) binding: Decl(P, NodeId), @@ -1188,7 +1188,7 @@ impl StmtKind { } /// Local represents a `let` statement, e.g., `let : = ;` -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Local { pub pat: P, pub ty: Option>, @@ -1203,7 +1203,7 @@ pub struct Local { pub type Decl = Spanned; -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub enum DeclKind { /// A local (let) binding: Local(P), @@ -1228,7 +1228,7 @@ impl DeclKind { } /// represents one arm of a 'match' -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Arm { pub attrs: HirVec, pub pats: HirVec>, @@ -1236,12 +1236,12 @@ pub struct Arm { pub body: P, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub enum Guard { If(P), } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Field { pub id: NodeId, pub ident: Ident, @@ -1250,7 +1250,7 @@ pub struct Field { pub is_shorthand: bool, } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Debug, Copy)] pub enum BlockCheckMode { DefaultBlock, UnsafeBlock(UnsafeSource), @@ -1258,13 +1258,13 @@ pub enum BlockCheckMode { PopUnsafeBlock(UnsafeSource), } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Debug, Copy)] pub enum UnsafeSource { CompilerGenerated, UserProvided, } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub struct BodyId { pub node_id: NodeId, } @@ -1290,7 +1290,7 @@ pub struct BodyId { /// /// All bodies have an **owner**, which can be accessed via the HIR /// map using `body_owner_def_id()`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub struct Body { pub arguments: HirVec, pub value: Expr, @@ -1322,7 +1322,7 @@ pub enum BodyOwnerKind { /// These are usually found nested inside types (e.g. array lengths) /// or expressions (e.g. repeat counts), and also used to define /// explicit discriminant values for enum variants. -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, PartialEq, Eq, Debug)] pub struct AnonConst { pub id: NodeId, pub hir_id: HirId, @@ -1330,7 +1330,7 @@ pub struct AnonConst { } /// An expression -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone)] pub struct Expr { pub id: NodeId, pub span: Span, @@ -1434,7 +1434,7 @@ impl fmt::Debug for Expr { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub enum ExprKind { /// A `box x` expression. Box(P), @@ -1536,7 +1536,7 @@ pub enum ExprKind { } /// Optionally `Self`-qualified value/type path or associated extension. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Debug)] pub enum QPath { /// Path to a definition, optionally "fully-qualified" with a `Self` /// type, if the path points to an associated item in a trait. @@ -1556,7 +1556,7 @@ pub enum QPath { } /// Hints at the original code for a let statement -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, Debug, Copy)] pub enum LocalSource { /// A `match _ { .. }` Normal, @@ -1565,7 +1565,7 @@ pub enum LocalSource { } /// Hints at the original code for a `match _ { .. }` -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, Eq, Hash, Debug, Copy)] pub enum MatchSource { /// A `match _ { .. }` Normal, @@ -1583,7 +1583,7 @@ pub enum MatchSource { } /// The loop type that yielded an ExprKind::Loop -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, Debug, Copy)] pub enum LoopSource { /// A `loop { .. }` loop Loop, @@ -1593,7 +1593,7 @@ pub enum LoopSource { ForLoop, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, Debug, Copy)] pub enum LoopIdError { OutsideLoopScope, UnlabeledCfInWhileCondition, @@ -1611,7 +1611,7 @@ impl fmt::Display for LoopIdError { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, Debug, Copy)] pub struct Destination { // This is `Some(_)` iff there is an explicit user-specified `label pub label: Option