From 3bb4d1a58c7198672db05c58108a6c675c2007eb Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 16 Dec 2015 21:44:33 +0300 Subject: [PATCH 1/2] Deprecate name `OwnedSlice` and don't use it --- clean/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean/mod.rs b/clean/mod.rs index 52eeb78..e217e7a 100644 --- a/clean/mod.rs +++ b/clean/mod.rs @@ -112,7 +112,7 @@ impl Clean for ty::Binder where T: Clean { } } -impl, U> Clean> for syntax::owned_slice::OwnedSlice { +impl, U> Clean> for P<[T]> { fn clean(&self, cx: &DocContext) -> Vec { self.iter().map(|x| x.clean(cx)).collect() } From 8957d67a96322adb9a78549ac14fe6cf1affd9e6 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 17 Dec 2015 20:41:28 +0300 Subject: [PATCH 2/2] Abstract away differences between Vec and ptr::P in HIR --- clean/mod.rs | 9 +++++++-- doctree.rs | 42 +++++++++++++++++++++--------------------- visit_ast.rs | 8 ++++---- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/clean/mod.rs b/clean/mod.rs index e217e7a..675eef6 100644 --- a/clean/mod.rs +++ b/clean/mod.rs @@ -1584,8 +1584,13 @@ impl Clean for hir::Ty { resolve_type(cx, p.clean(cx), self.id) } TyPath(Some(ref qself), ref p) => { - let mut trait_path = p.clone(); - trait_path.segments.pop(); + let mut segments: Vec<_> = p.segments.clone().into(); + segments.pop(); + let trait_path = hir::Path { + span: p.span, + global: p.global, + segments: segments.into(), + }; Type::QPath { name: p.segments.last().unwrap().identifier.name.clean(cx), self_type: box qself.ty.clean(cx), diff --git a/doctree.rs b/doctree.rs index d1030a6..fc0422b 100644 --- a/doctree.rs +++ b/doctree.rs @@ -24,7 +24,7 @@ use rustc_front::hir; pub struct Module { pub name: Option, - pub attrs: Vec, + pub attrs: hir::HirVec, pub where_outer: Span, pub where_inner: Span, pub extern_crates: Vec, @@ -58,7 +58,7 @@ impl Module { depr: None, where_outer: syntax::codemap::DUMMY_SP, where_inner: syntax::codemap::DUMMY_SP, - attrs : Vec::new(), + attrs : hir::HirVec::new(), extern_crates: Vec::new(), imports : Vec::new(), structs : Vec::new(), @@ -103,8 +103,8 @@ pub struct Struct { pub struct_type: StructType, pub name: Name, pub generics: hir::Generics, - pub attrs: Vec, - pub fields: Vec, + pub attrs: hir::HirVec, + pub fields: hir::HirVec, pub whence: Span, } @@ -112,9 +112,9 @@ pub struct Enum { pub vis: hir::Visibility, pub stab: Option, pub depr: Option, - pub variants: Vec, + pub variants: hir::HirVec, pub generics: hir::Generics, - pub attrs: Vec, + pub attrs: hir::HirVec, pub id: NodeId, pub whence: Span, pub name: Name, @@ -122,7 +122,7 @@ pub struct Enum { pub struct Variant { pub name: Name, - pub attrs: Vec, + pub attrs: hir::HirVec, pub def: hir::VariantData, pub stab: Option, pub depr: Option, @@ -131,7 +131,7 @@ pub struct Variant { pub struct Function { pub decl: hir::FnDecl, - pub attrs: Vec, + pub attrs: hir::HirVec, pub id: NodeId, pub name: Name, pub vis: hir::Visibility, @@ -149,7 +149,7 @@ pub struct Typedef { pub gen: hir::Generics, pub name: Name, pub id: ast::NodeId, - pub attrs: Vec, + pub attrs: hir::HirVec, pub whence: Span, pub vis: hir::Visibility, pub stab: Option, @@ -162,7 +162,7 @@ pub struct Static { pub mutability: hir::Mutability, pub expr: P, pub name: Name, - pub attrs: Vec, + pub attrs: hir::HirVec, pub vis: hir::Visibility, pub stab: Option, pub depr: Option, @@ -174,7 +174,7 @@ pub struct Constant { pub type_: P, pub expr: P, pub name: Name, - pub attrs: Vec, + pub attrs: hir::HirVec, pub vis: hir::Visibility, pub stab: Option, pub depr: Option, @@ -185,10 +185,10 @@ pub struct Constant { pub struct Trait { pub unsafety: hir::Unsafety, pub name: Name, - pub items: Vec, + pub items: hir::HirVec, pub generics: hir::Generics, - pub bounds: Vec, - pub attrs: Vec, + pub bounds: hir::HirVec, + pub attrs: hir::HirVec, pub id: ast::NodeId, pub whence: Span, pub vis: hir::Visibility, @@ -202,8 +202,8 @@ pub struct Impl { pub generics: hir::Generics, pub trait_: Option, pub for_: P, - pub items: Vec, - pub attrs: Vec, + pub items: hir::HirVec, + pub attrs: hir::HirVec, pub whence: Span, pub vis: hir::Visibility, pub stab: Option, @@ -215,16 +215,16 @@ pub struct DefaultImpl { pub unsafety: hir::Unsafety, pub trait_: hir::TraitRef, pub id: ast::NodeId, - pub attrs: Vec, + pub attrs: hir::HirVec, pub whence: Span, } pub struct Macro { pub name: Name, pub id: ast::NodeId, - pub attrs: Vec, + pub attrs: hir::HirVec, pub whence: Span, - pub matchers: Vec, + pub matchers: hir::HirVec, pub stab: Option, pub depr: Option, pub imported_from: Option, @@ -234,14 +234,14 @@ pub struct ExternCrate { pub name: Name, pub path: Option, pub vis: hir::Visibility, - pub attrs: Vec, + pub attrs: hir::HirVec, pub whence: Span, } pub struct Import { pub id: NodeId, pub vis: hir::Visibility, - pub attrs: Vec, + pub attrs: hir::HirVec, pub node: hir::ViewPath_, pub whence: Span, } diff --git a/visit_ast.rs b/visit_ast.rs index d95a455..ba389bc 100644 --- a/visit_ast.rs +++ b/visit_ast.rs @@ -38,7 +38,7 @@ use doctree::*; pub struct RustdocVisitor<'a, 'tcx: 'a> { pub module: Module, - pub attrs: Vec, + pub attrs: hir::HirVec, pub cx: &'a core::DocContext<'a, 'tcx>, pub analysis: Option<&'a core::CrateAnalysis>, view_item_stack: HashSet, @@ -53,7 +53,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { stack.insert(ast::CRATE_NODE_ID); RustdocVisitor { module: Module::new(None), - attrs: Vec::new(), + attrs: hir::HirVec::new(), cx: cx, analysis: analysis, view_item_stack: stack, @@ -157,7 +157,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } } - pub fn visit_mod_contents(&mut self, span: Span, attrs: Vec , + pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec, vis: hir::Visibility, id: ast::NodeId, m: &hir::Mod, name: Option) -> Module { @@ -192,7 +192,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { let mine = paths.into_iter().filter(|path| { !self.resolve_id(path.node.id(), None, false, om, please_inline) - }).collect::>(); + }).collect::>(); if mine.is_empty() { None