2013-09-12 21:10:51 -04:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
//! Rust AST Visitor. Extracts useful information and massages it into a form
|
|
|
|
//! usable for clean
|
|
|
|
|
2015-04-07 11:08:21 -07:00
|
|
|
use std::mem;
|
2014-09-23 15:13:56 -07:00
|
|
|
|
2013-12-22 11:23:04 -08:00
|
|
|
use syntax::ast;
|
2015-09-14 21:58:20 +12:00
|
|
|
use syntax::attr;
|
2018-06-30 20:34:18 -07:00
|
|
|
use syntax::codemap::Spanned;
|
|
|
|
use syntax_pos::{self, Span};
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2016-03-29 08:50:44 +03:00
|
|
|
use rustc::hir::map as hir_map;
|
2016-04-15 16:34:48 +02:00
|
|
|
use rustc::hir::def::Def;
|
2017-03-24 03:50:32 -07:00
|
|
|
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
2018-06-17 14:54:28 -05:00
|
|
|
use rustc::middle::cstore::CrateStore;
|
2016-04-15 16:34:48 +02:00
|
|
|
use rustc::middle::privacy::AccessLevel;
|
Generate documentation for auto-trait impls
A new section is added to both both struct and trait doc pages.
On struct/enum pages, a new 'Auto Trait Implementations' section displays any
synthetic implementations for auto traits. Currently, this is only done
for Send and Sync.
On trait pages, a new 'Auto Implementors' section displays all types
which automatically implement the trait. Effectively, this is a list of
all public types in the standard library.
Synthesized impls for a particular auto trait ('synthetic impls') take
into account generic bounds. For example, a type 'struct Foo<T>(T)' will
have 'impl<T> Send for Foo<T> where T: Send' generated for it.
Manual implementations of auto traits are also taken into account. If we have
the following types:
'struct Foo<T>(T)'
'struct Wrapper<T>(Foo<T>)'
'unsafe impl<T> Send for Wrapper<T>' // pretend that Wrapper<T> makes
this sound somehow
Then Wrapper will have the following impl generated:
'impl<T> Send for Wrapper<T>'
reflecting the fact that 'T: Send' need not hold for 'Wrapper<T>: Send'
to hold
Lifetimes, HRTBS, and projections (e.g. '<T as Iterator>::Item') are
taken into account by synthetic impls
However, if a type can *never* implement a particular auto trait
(e.g. 'struct MyStruct<T>(*const T)'), then a negative impl will be
generated (in this case, 'impl<T> !Send for MyStruct<T>')
All of this means that a user should be able to copy-paste a synthetic
impl into their code, without any observable changes in behavior
(assuming the rest of the program remains unchanged).
2017-11-22 16:16:55 -05:00
|
|
|
use rustc::util::nodemap::{FxHashSet, FxHashMap};
|
2014-06-26 11:37:39 -07:00
|
|
|
|
2016-03-29 08:50:44 +03:00
|
|
|
use rustc::hir;
|
2015-07-31 00:04:06 -07:00
|
|
|
|
2014-01-07 18:46:16 -08:00
|
|
|
use core;
|
Generate documentation for auto-trait impls
A new section is added to both both struct and trait doc pages.
On struct/enum pages, a new 'Auto Trait Implementations' section displays any
synthetic implementations for auto traits. Currently, this is only done
for Send and Sync.
On trait pages, a new 'Auto Implementors' section displays all types
which automatically implement the trait. Effectively, this is a list of
all public types in the standard library.
Synthesized impls for a particular auto trait ('synthetic impls') take
into account generic bounds. For example, a type 'struct Foo<T>(T)' will
have 'impl<T> Send for Foo<T> where T: Send' generated for it.
Manual implementations of auto traits are also taken into account. If we have
the following types:
'struct Foo<T>(T)'
'struct Wrapper<T>(Foo<T>)'
'unsafe impl<T> Send for Wrapper<T>' // pretend that Wrapper<T> makes
this sound somehow
Then Wrapper will have the following impl generated:
'impl<T> Send for Wrapper<T>'
reflecting the fact that 'T: Send' need not hold for 'Wrapper<T>: Send'
to hold
Lifetimes, HRTBS, and projections (e.g. '<T as Iterator>::Item') are
taken into account by synthetic impls
However, if a type can *never* implement a particular auto trait
(e.g. 'struct MyStruct<T>(*const T)'), then a negative impl will be
generated (in this case, 'impl<T> !Send for MyStruct<T>')
All of this means that a user should be able to copy-paste a synthetic
impl into their code, without any observable changes in behavior
(assuming the rest of the program remains unchanged).
2017-11-22 16:16:55 -05:00
|
|
|
use clean::{self, AttributesExt, NestedAttributesExt, def_id_to_path};
|
2013-08-15 16:28:54 -04:00
|
|
|
use doctree::*;
|
|
|
|
|
2014-07-17 09:45:31 -07:00
|
|
|
// looks to me like the first two of these are actually
|
|
|
|
// output parameters, maybe only mutated once; perhaps
|
|
|
|
// better simply to have the visit method return a tuple
|
|
|
|
// containing them?
|
|
|
|
|
|
|
|
// also, is there some reason that this doesn't use the 'visit'
|
|
|
|
// framework from syntax?
|
|
|
|
|
2017-12-28 10:52:40 -06:00
|
|
|
pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
|
Generate documentation for auto-trait impls
A new section is added to both both struct and trait doc pages.
On struct/enum pages, a new 'Auto Trait Implementations' section displays any
synthetic implementations for auto traits. Currently, this is only done
for Send and Sync.
On trait pages, a new 'Auto Implementors' section displays all types
which automatically implement the trait. Effectively, this is a list of
all public types in the standard library.
Synthesized impls for a particular auto trait ('synthetic impls') take
into account generic bounds. For example, a type 'struct Foo<T>(T)' will
have 'impl<T> Send for Foo<T> where T: Send' generated for it.
Manual implementations of auto traits are also taken into account. If we have
the following types:
'struct Foo<T>(T)'
'struct Wrapper<T>(Foo<T>)'
'unsafe impl<T> Send for Wrapper<T>' // pretend that Wrapper<T> makes
this sound somehow
Then Wrapper will have the following impl generated:
'impl<T> Send for Wrapper<T>'
reflecting the fact that 'T: Send' need not hold for 'Wrapper<T>: Send'
to hold
Lifetimes, HRTBS, and projections (e.g. '<T as Iterator>::Item') are
taken into account by synthetic impls
However, if a type can *never* implement a particular auto trait
(e.g. 'struct MyStruct<T>(*const T)'), then a negative impl will be
generated (in this case, 'impl<T> !Send for MyStruct<T>')
All of this means that a user should be able to copy-paste a synthetic
impl into their code, without any observable changes in behavior
(assuming the rest of the program remains unchanged).
2017-11-22 16:16:55 -05:00
|
|
|
pub cstore: &'a CrateStore,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub module: Module,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2017-12-28 10:52:40 -06:00
|
|
|
pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>,
|
2016-11-08 14:02:55 +11:00
|
|
|
view_item_stack: FxHashSet<ast::NodeId>,
|
2016-11-14 18:24:47 +00:00
|
|
|
inlining: bool,
|
|
|
|
/// Is the current module and all of its parents public?
|
|
|
|
inside_public_path: bool,
|
2018-02-15 17:21:26 -05:00
|
|
|
exact_paths: Option<FxHashMap<DefId, Vec<String>>>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2017-12-28 10:52:40 -06:00
|
|
|
impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
|
2017-12-25 14:34:56 +05:30
|
|
|
pub fn new(cstore: &'a CrateStore,
|
2017-12-28 10:52:40 -06:00
|
|
|
cx: &'a core::DocContext<'a, 'tcx, 'rcx>) -> RustdocVisitor<'a, 'tcx, 'rcx> {
|
2018-01-12 16:41:25 -05:00
|
|
|
// If the root is re-exported, terminate all recursion.
|
2016-11-08 14:02:55 +11:00
|
|
|
let mut stack = FxHashSet();
|
2014-09-23 15:19:30 -07:00
|
|
|
stack.insert(ast::CRATE_NODE_ID);
|
2013-08-15 16:28:54 -04:00
|
|
|
RustdocVisitor {
|
|
|
|
module: Module::new(None),
|
2015-12-17 20:41:28 +03:00
|
|
|
attrs: hir::HirVec::new(),
|
2017-08-06 22:54:09 -07:00
|
|
|
cx,
|
2014-09-23 15:19:30 -07:00
|
|
|
view_item_stack: stack,
|
2016-11-14 18:24:47 +00:00
|
|
|
inlining: false,
|
|
|
|
inside_public_path: true,
|
Generate documentation for auto-trait impls
A new section is added to both both struct and trait doc pages.
On struct/enum pages, a new 'Auto Trait Implementations' section displays any
synthetic implementations for auto traits. Currently, this is only done
for Send and Sync.
On trait pages, a new 'Auto Implementors' section displays all types
which automatically implement the trait. Effectively, this is a list of
all public types in the standard library.
Synthesized impls for a particular auto trait ('synthetic impls') take
into account generic bounds. For example, a type 'struct Foo<T>(T)' will
have 'impl<T> Send for Foo<T> where T: Send' generated for it.
Manual implementations of auto traits are also taken into account. If we have
the following types:
'struct Foo<T>(T)'
'struct Wrapper<T>(Foo<T>)'
'unsafe impl<T> Send for Wrapper<T>' // pretend that Wrapper<T> makes
this sound somehow
Then Wrapper will have the following impl generated:
'impl<T> Send for Wrapper<T>'
reflecting the fact that 'T: Send' need not hold for 'Wrapper<T>: Send'
to hold
Lifetimes, HRTBS, and projections (e.g. '<T as Iterator>::Item') are
taken into account by synthetic impls
However, if a type can *never* implement a particular auto trait
(e.g. 'struct MyStruct<T>(*const T)'), then a negative impl will be
generated (in this case, 'impl<T> !Send for MyStruct<T>')
All of this means that a user should be able to copy-paste a synthetic
impl into their code, without any observable changes in behavior
(assuming the rest of the program remains unchanged).
2017-11-22 16:16:55 -05:00
|
|
|
exact_paths: Some(FxHashMap()),
|
2017-09-07 13:21:46 -07:00
|
|
|
cstore,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Generate documentation for auto-trait impls
A new section is added to both both struct and trait doc pages.
On struct/enum pages, a new 'Auto Trait Implementations' section displays any
synthetic implementations for auto traits. Currently, this is only done
for Send and Sync.
On trait pages, a new 'Auto Implementors' section displays all types
which automatically implement the trait. Effectively, this is a list of
all public types in the standard library.
Synthesized impls for a particular auto trait ('synthetic impls') take
into account generic bounds. For example, a type 'struct Foo<T>(T)' will
have 'impl<T> Send for Foo<T> where T: Send' generated for it.
Manual implementations of auto traits are also taken into account. If we have
the following types:
'struct Foo<T>(T)'
'struct Wrapper<T>(Foo<T>)'
'unsafe impl<T> Send for Wrapper<T>' // pretend that Wrapper<T> makes
this sound somehow
Then Wrapper will have the following impl generated:
'impl<T> Send for Wrapper<T>'
reflecting the fact that 'T: Send' need not hold for 'Wrapper<T>: Send'
to hold
Lifetimes, HRTBS, and projections (e.g. '<T as Iterator>::Item') are
taken into account by synthetic impls
However, if a type can *never* implement a particular auto trait
(e.g. 'struct MyStruct<T>(*const T)'), then a negative impl will be
generated (in this case, 'impl<T> !Send for MyStruct<T>')
All of this means that a user should be able to copy-paste a synthetic
impl into their code, without any observable changes in behavior
(assuming the rest of the program remains unchanged).
2017-11-22 16:16:55 -05:00
|
|
|
fn store_path(&mut self, did: DefId) {
|
|
|
|
// We can't use the entry api, as that keeps the mutable borrow of self active
|
|
|
|
// when we try to use cx
|
|
|
|
let exact_paths = self.exact_paths.as_mut().unwrap();
|
|
|
|
if exact_paths.get(&did).is_none() {
|
|
|
|
let path = def_id_to_path(self.cx, did, self.cx.crate_name.clone());
|
|
|
|
exact_paths.insert(did, path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 11:37:39 -07:00
|
|
|
fn stability(&self, id: ast::NodeId) -> Option<attr::Stability> {
|
2017-01-26 02:41:06 +02:00
|
|
|
self.cx.tcx.hir.opt_local_def_id(id)
|
2016-11-20 03:42:54 +02:00
|
|
|
.and_then(|def_id| self.cx.tcx.lookup_stability(def_id)).cloned()
|
2014-06-26 11:37:39 -07:00
|
|
|
}
|
|
|
|
|
2015-12-12 23:01:27 +03:00
|
|
|
fn deprecation(&self, id: ast::NodeId) -> Option<attr::Deprecation> {
|
2017-01-26 02:41:06 +02:00
|
|
|
self.cx.tcx.hir.opt_local_def_id(id)
|
2016-11-20 03:42:54 +02:00
|
|
|
.and_then(|def_id| self.cx.tcx.lookup_deprecation(def_id))
|
2015-12-12 23:01:27 +03:00
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
pub fn visit(&mut self, krate: &hir::Crate) {
|
2014-05-18 16:56:13 +03:00
|
|
|
self.attrs = krate.attrs.clone();
|
2014-01-07 18:46:16 -08:00
|
|
|
|
2014-02-28 17:46:09 -08:00
|
|
|
self.module = self.visit_mod_contents(krate.span,
|
2014-05-18 16:56:13 +03:00
|
|
|
krate.attrs.clone(),
|
2018-06-30 20:34:18 -07:00
|
|
|
Spanned { span: syntax_pos::DUMMY_SP,
|
2018-07-01 11:05:10 -07:00
|
|
|
node: hir::VisibilityKind::Public },
|
2014-02-28 17:46:09 -08:00
|
|
|
ast::CRATE_NODE_ID,
|
|
|
|
&krate.module,
|
|
|
|
None);
|
2014-07-17 09:45:31 -07:00
|
|
|
// attach the crate's exported macros to the top-level module:
|
2016-10-29 07:31:07 +00:00
|
|
|
let macro_exports: Vec<_> =
|
2016-12-19 14:24:33 -05:00
|
|
|
krate.exported_macros.iter().map(|def| self.visit_local_macro(def)).collect();
|
2016-10-29 07:31:07 +00:00
|
|
|
self.module.macros.extend(macro_exports);
|
2014-02-28 22:33:45 +01:00
|
|
|
self.module.is_crate = true;
|
Generate documentation for auto-trait impls
A new section is added to both both struct and trait doc pages.
On struct/enum pages, a new 'Auto Trait Implementations' section displays any
synthetic implementations for auto traits. Currently, this is only done
for Send and Sync.
On trait pages, a new 'Auto Implementors' section displays all types
which automatically implement the trait. Effectively, this is a list of
all public types in the standard library.
Synthesized impls for a particular auto trait ('synthetic impls') take
into account generic bounds. For example, a type 'struct Foo<T>(T)' will
have 'impl<T> Send for Foo<T> where T: Send' generated for it.
Manual implementations of auto traits are also taken into account. If we have
the following types:
'struct Foo<T>(T)'
'struct Wrapper<T>(Foo<T>)'
'unsafe impl<T> Send for Wrapper<T>' // pretend that Wrapper<T> makes
this sound somehow
Then Wrapper will have the following impl generated:
'impl<T> Send for Wrapper<T>'
reflecting the fact that 'T: Send' need not hold for 'Wrapper<T>: Send'
to hold
Lifetimes, HRTBS, and projections (e.g. '<T as Iterator>::Item') are
taken into account by synthetic impls
However, if a type can *never* implement a particular auto trait
(e.g. 'struct MyStruct<T>(*const T)'), then a negative impl will be
generated (in this case, 'impl<T> !Send for MyStruct<T>')
All of this means that a user should be able to copy-paste a synthetic
impl into their code, without any observable changes in behavior
(assuming the rest of the program remains unchanged).
2017-11-22 16:16:55 -05:00
|
|
|
|
|
|
|
self.cx.renderinfo.borrow_mut().exact_paths = self.exact_paths.take().unwrap();
|
2014-01-07 18:46:16 -08:00
|
|
|
}
|
|
|
|
|
2015-10-08 03:20:57 +03:00
|
|
|
pub fn visit_variant_data(&mut self, item: &hir::Item,
|
|
|
|
name: ast::Name, sd: &hir::VariantData,
|
2015-07-31 00:04:06 -07:00
|
|
|
generics: &hir::Generics) -> Struct {
|
2014-01-07 18:46:16 -08:00
|
|
|
debug!("Visiting struct");
|
2014-05-16 10:15:33 -07:00
|
|
|
let struct_type = struct_type_from_def(&*sd);
|
2014-01-07 18:46:16 -08:00
|
|
|
Struct {
|
|
|
|
id: item.id,
|
2017-08-06 22:54:09 -07:00
|
|
|
struct_type,
|
|
|
|
name,
|
2016-03-25 06:08:11 +00:00
|
|
|
vis: item.vis.clone(),
|
2014-06-26 11:37:39 -07:00
|
|
|
stab: self.stability(item.id),
|
2015-12-12 23:01:27 +03:00
|
|
|
depr: self.deprecation(item.id),
|
2014-05-18 16:56:13 +03:00
|
|
|
attrs: item.attrs.clone(),
|
2014-01-07 18:46:16 -08:00
|
|
|
generics: generics.clone(),
|
2015-10-25 18:33:51 +03:00
|
|
|
fields: sd.fields().iter().cloned().collect(),
|
2014-08-11 09:32:26 -07:00
|
|
|
whence: item.span
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
2014-01-07 18:46:16 -08:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2016-08-10 21:00:17 +03:00
|
|
|
pub fn visit_union_data(&mut self, item: &hir::Item,
|
|
|
|
name: ast::Name, sd: &hir::VariantData,
|
|
|
|
generics: &hir::Generics) -> Union {
|
|
|
|
debug!("Visiting union");
|
|
|
|
let struct_type = struct_type_from_def(&*sd);
|
|
|
|
Union {
|
|
|
|
id: item.id,
|
2017-08-06 22:54:09 -07:00
|
|
|
struct_type,
|
|
|
|
name,
|
2016-08-10 21:00:17 +03:00
|
|
|
vis: item.vis.clone(),
|
|
|
|
stab: self.stability(item.id),
|
|
|
|
depr: self.deprecation(item.id),
|
|
|
|
attrs: item.attrs.clone(),
|
|
|
|
generics: generics.clone(),
|
|
|
|
fields: sd.fields().iter().cloned().collect(),
|
|
|
|
whence: item.span
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
pub fn visit_enum_def(&mut self, it: &hir::Item,
|
2015-09-20 04:50:30 +03:00
|
|
|
name: ast::Name, def: &hir::EnumDef,
|
2015-07-31 00:04:06 -07:00
|
|
|
params: &hir::Generics) -> Enum {
|
2014-01-07 18:46:16 -08:00
|
|
|
debug!("Visiting enum");
|
|
|
|
Enum {
|
2017-08-06 22:54:09 -07:00
|
|
|
name,
|
2014-05-18 16:56:13 +03:00
|
|
|
variants: def.variants.iter().map(|v| Variant {
|
|
|
|
name: v.node.name,
|
|
|
|
attrs: v.node.attrs.clone(),
|
2015-10-10 03:28:40 +03:00
|
|
|
stab: self.stability(v.node.data.id()),
|
2015-12-12 23:01:27 +03:00
|
|
|
depr: self.deprecation(v.node.data.id()),
|
2015-10-08 03:20:57 +03:00
|
|
|
def: v.node.data.clone(),
|
2014-05-18 16:56:13 +03:00
|
|
|
whence: v.span,
|
|
|
|
}).collect(),
|
2016-03-25 06:08:11 +00:00
|
|
|
vis: it.vis.clone(),
|
2014-06-26 11:37:39 -07:00
|
|
|
stab: self.stability(it.id),
|
2015-12-12 23:01:27 +03:00
|
|
|
depr: self.deprecation(it.id),
|
2014-01-07 18:46:16 -08:00
|
|
|
generics: params.clone(),
|
2014-05-18 16:56:13 +03:00
|
|
|
attrs: it.attrs.clone(),
|
2014-01-07 18:46:16 -08:00
|
|
|
id: it.id,
|
2014-08-11 09:32:26 -07:00
|
|
|
whence: it.span,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
2014-01-07 18:46:16 -08:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
pub fn visit_fn(&mut self, item: &hir::Item,
|
2015-09-20 04:50:30 +03:00
|
|
|
name: ast::Name, fd: &hir::FnDecl,
|
2018-05-16 22:55:18 -07:00
|
|
|
header: hir::FnHeader,
|
2016-12-20 22:46:11 +02:00
|
|
|
gen: &hir::Generics,
|
|
|
|
body: hir::BodyId) -> Function {
|
2014-01-07 18:46:16 -08:00
|
|
|
debug!("Visiting fn");
|
|
|
|
Function {
|
|
|
|
id: item.id,
|
2016-03-25 06:08:11 +00:00
|
|
|
vis: item.vis.clone(),
|
2014-06-26 11:37:39 -07:00
|
|
|
stab: self.stability(item.id),
|
2015-12-12 23:01:27 +03:00
|
|
|
depr: self.deprecation(item.id),
|
2014-05-18 16:56:13 +03:00
|
|
|
attrs: item.attrs.clone(),
|
2014-01-07 18:46:16 -08:00
|
|
|
decl: fd.clone(),
|
2017-08-06 22:54:09 -07:00
|
|
|
name,
|
2014-08-11 09:32:26 -07:00
|
|
|
whence: item.span,
|
2014-01-07 18:46:16 -08:00
|
|
|
generics: gen.clone(),
|
2018-05-16 22:55:18 -07:00
|
|
|
header,
|
2017-08-06 22:54:09 -07:00
|
|
|
body,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
2014-01-07 18:46:16 -08:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2015-12-17 20:41:28 +03:00
|
|
|
pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec<ast::Attribute>,
|
2015-07-31 00:04:06 -07:00
|
|
|
vis: hir::Visibility, id: ast::NodeId,
|
|
|
|
m: &hir::Mod,
|
2015-09-20 04:50:30 +03:00
|
|
|
name: Option<ast::Name>) -> Module {
|
2014-01-07 18:46:16 -08:00
|
|
|
let mut om = Module::new(name);
|
2014-04-27 05:08:36 +09:00
|
|
|
om.where_outer = span;
|
|
|
|
om.where_inner = m.inner;
|
2014-01-07 18:46:16 -08:00
|
|
|
om.attrs = attrs;
|
2016-03-25 06:08:11 +00:00
|
|
|
om.vis = vis.clone();
|
2014-06-26 11:37:39 -07:00
|
|
|
om.stab = self.stability(id);
|
2015-12-12 23:01:27 +03:00
|
|
|
om.depr = self.deprecation(id);
|
2014-01-07 18:46:16 -08:00
|
|
|
om.id = id;
|
2016-11-14 18:24:47 +00:00
|
|
|
// Keep track of if there were any private modules in the path.
|
|
|
|
let orig_inside_public_path = self.inside_public_path;
|
2018-06-30 20:34:18 -07:00
|
|
|
self.inside_public_path &= vis.node.is_pub();
|
2015-11-17 17:51:44 -05:00
|
|
|
for i in &m.item_ids {
|
2017-01-26 02:41:06 +02:00
|
|
|
let item = self.cx.tcx.hir.expect_item(i.id);
|
2015-11-17 17:51:44 -05:00
|
|
|
self.visit_item(item, None, &mut om);
|
2014-01-07 18:46:16 -08:00
|
|
|
}
|
2016-11-14 18:24:47 +00:00
|
|
|
self.inside_public_path = orig_inside_public_path;
|
2014-01-07 18:46:16 -08:00
|
|
|
om
|
|
|
|
}
|
|
|
|
|
2016-03-10 03:29:46 +01:00
|
|
|
/// Tries to resolve the target of a `pub use` statement and inlines the
|
|
|
|
/// target if it is defined locally and would not be documented otherwise,
|
|
|
|
/// or when it is specifically requested with `please_inline`.
|
|
|
|
/// (the latter is the case when the import is marked `doc(inline)`)
|
|
|
|
///
|
|
|
|
/// Cross-crate inlining occurs later on during crate cleaning
|
|
|
|
/// and follows different rules.
|
|
|
|
///
|
|
|
|
/// Returns true if the target has been inlined.
|
2016-11-25 13:21:19 +02:00
|
|
|
fn maybe_inline_local(&mut self,
|
|
|
|
id: ast::NodeId,
|
|
|
|
def: Def,
|
|
|
|
renamed: Option<ast::Name>,
|
|
|
|
glob: bool,
|
|
|
|
om: &mut Module,
|
|
|
|
please_inline: bool) -> bool {
|
2016-03-10 03:29:46 +01:00
|
|
|
|
|
|
|
fn inherits_doc_hidden(cx: &core::DocContext, mut node: ast::NodeId) -> bool {
|
2017-01-26 02:41:06 +02:00
|
|
|
while let Some(id) = cx.tcx.hir.get_enclosing_scope(node) {
|
2016-03-10 03:29:46 +01:00
|
|
|
node = id;
|
2017-01-26 02:41:06 +02:00
|
|
|
if cx.tcx.hir.attrs(node).lists("doc").has_word("hidden") {
|
2016-03-10 03:29:46 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if node == ast::CRATE_NODE_ID {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2017-03-24 03:50:32 -07:00
|
|
|
debug!("maybe_inline_local def: {:?}", def);
|
|
|
|
|
2016-11-20 03:42:54 +02:00
|
|
|
let tcx = self.cx.tcx;
|
2016-11-25 13:21:19 +02:00
|
|
|
if def == Def::Err {
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-15 16:34:48 +02:00
|
|
|
let def_did = def.def_id();
|
2016-03-10 03:29:46 +01:00
|
|
|
|
2017-01-26 02:41:06 +02:00
|
|
|
let use_attrs = tcx.hir.attrs(id);
|
2016-06-07 01:20:12 +01:00
|
|
|
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
|
2016-11-24 01:40:52 +02:00
|
|
|
let is_no_inline = use_attrs.lists("doc").has_word("no_inline") ||
|
|
|
|
use_attrs.lists("doc").has_word("hidden");
|
2016-04-15 16:34:48 +02:00
|
|
|
|
|
|
|
// For cross-crate impl inlining we need to know whether items are
|
|
|
|
// reachable in documentation - a previously nonreachable item can be
|
|
|
|
// made reachable by cross-crate inlining which we're checking here.
|
|
|
|
// (this is done here because we need to know this upfront)
|
2016-06-03 23:15:00 +03:00
|
|
|
if !def_did.is_local() && !is_no_inline {
|
2016-11-20 03:42:54 +02:00
|
|
|
let attrs = clean::inline::load_attrs(self.cx, def_did);
|
2016-11-24 01:40:52 +02:00
|
|
|
let self_is_hidden = attrs.lists("doc").has_word("hidden");
|
2016-06-03 23:15:00 +03:00
|
|
|
match def {
|
2016-04-15 16:34:48 +02:00
|
|
|
Def::Trait(did) |
|
|
|
|
Def::Struct(did) |
|
2016-08-10 21:00:17 +03:00
|
|
|
Def::Union(did) |
|
2016-04-15 16:34:48 +02:00
|
|
|
Def::Enum(did) |
|
2017-11-21 00:22:19 +08:00
|
|
|
Def::TyForeign(did) |
|
2016-04-15 16:34:48 +02:00
|
|
|
Def::TyAlias(did) if !self_is_hidden => {
|
|
|
|
self.cx.access_levels.borrow_mut().map.insert(did, AccessLevel::Public);
|
|
|
|
},
|
|
|
|
Def::Mod(did) => if !self_is_hidden {
|
|
|
|
::visit_lib::LibEmbargoVisitor::new(self.cx).visit_mod(did);
|
|
|
|
},
|
|
|
|
_ => {},
|
|
|
|
}
|
2017-03-24 03:50:32 -07:00
|
|
|
|
2016-04-15 16:34:48 +02:00
|
|
|
return false
|
|
|
|
}
|
2016-03-22 20:26:33 +01:00
|
|
|
|
2017-01-26 02:41:06 +02:00
|
|
|
let def_node_id = match tcx.hir.as_local_node_id(def_did) {
|
2016-04-15 16:34:48 +02:00
|
|
|
Some(n) => n, None => return false
|
|
|
|
};
|
|
|
|
|
|
|
|
let is_private = !self.cx.access_levels.borrow().is_public(def_did);
|
2016-03-10 03:29:46 +01:00
|
|
|
let is_hidden = inherits_doc_hidden(self.cx, def_node_id);
|
|
|
|
|
|
|
|
// Only inline if requested or if the item would otherwise be stripped
|
2016-03-22 20:26:33 +01:00
|
|
|
if (!please_inline && !is_private && !is_hidden) || is_no_inline {
|
2014-05-02 17:16:30 -07:00
|
|
|
return false
|
|
|
|
}
|
2016-03-10 03:29:46 +01:00
|
|
|
|
2015-09-04 13:52:28 -04:00
|
|
|
if !self.view_item_stack.insert(def_node_id) { return false }
|
2014-01-07 18:46:16 -08:00
|
|
|
|
2017-01-26 02:41:06 +02:00
|
|
|
let ret = match tcx.hir.get(def_node_id) {
|
2018-07-11 23:36:06 +08:00
|
|
|
hir_map::NodeItem(&hir::Item { node: hir::ItemKind::Mod(ref m), .. }) if glob => {
|
2016-11-14 18:24:47 +00:00
|
|
|
let prev = mem::replace(&mut self.inlining, true);
|
2017-06-12 19:00:09 +01:00
|
|
|
for i in &m.item_ids {
|
|
|
|
let i = self.cx.tcx.hir.expect_item(i.id);
|
|
|
|
self.visit_item(i, None, om);
|
2013-09-26 11:57:25 -07:00
|
|
|
}
|
2016-11-14 18:24:47 +00:00
|
|
|
self.inlining = prev;
|
2017-06-12 19:00:09 +01:00
|
|
|
true
|
|
|
|
}
|
|
|
|
hir_map::NodeItem(it) if !glob => {
|
|
|
|
let prev = mem::replace(&mut self.inlining, true);
|
|
|
|
self.visit_item(it, renamed, om);
|
|
|
|
self.inlining = prev;
|
2014-01-07 18:46:16 -08:00
|
|
|
true
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
2017-11-21 00:22:19 +08:00
|
|
|
hir_map::NodeForeignItem(it) if !glob => {
|
|
|
|
// generate a fresh `extern {}` block if we want to inline a foreign item.
|
|
|
|
om.foreigns.push(hir::ForeignMod {
|
|
|
|
abi: tcx.hir.get_foreign_abi(it.id),
|
|
|
|
items: vec![hir::ForeignItem {
|
|
|
|
name: renamed.unwrap_or(it.name),
|
|
|
|
.. it.clone()
|
|
|
|
}].into(),
|
|
|
|
});
|
|
|
|
true
|
|
|
|
}
|
2014-01-07 18:46:16 -08:00
|
|
|
_ => false,
|
2014-09-23 15:13:56 -07:00
|
|
|
};
|
2015-09-04 13:52:28 -04:00
|
|
|
self.view_item_stack.remove(&def_node_id);
|
2016-10-01 16:47:43 -04:00
|
|
|
ret
|
2014-01-07 18:46:16 -08:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
pub fn visit_item(&mut self, item: &hir::Item,
|
2015-09-20 14:51:40 +03:00
|
|
|
renamed: Option<ast::Name>, om: &mut Module) {
|
2014-12-20 00:09:35 -08:00
|
|
|
debug!("Visiting item {:?}", item);
|
2015-09-20 14:51:40 +03:00
|
|
|
let name = renamed.unwrap_or(item.name);
|
Generate documentation for auto-trait impls
A new section is added to both both struct and trait doc pages.
On struct/enum pages, a new 'Auto Trait Implementations' section displays any
synthetic implementations for auto traits. Currently, this is only done
for Send and Sync.
On trait pages, a new 'Auto Implementors' section displays all types
which automatically implement the trait. Effectively, this is a list of
all public types in the standard library.
Synthesized impls for a particular auto trait ('synthetic impls') take
into account generic bounds. For example, a type 'struct Foo<T>(T)' will
have 'impl<T> Send for Foo<T> where T: Send' generated for it.
Manual implementations of auto traits are also taken into account. If we have
the following types:
'struct Foo<T>(T)'
'struct Wrapper<T>(Foo<T>)'
'unsafe impl<T> Send for Wrapper<T>' // pretend that Wrapper<T> makes
this sound somehow
Then Wrapper will have the following impl generated:
'impl<T> Send for Wrapper<T>'
reflecting the fact that 'T: Send' need not hold for 'Wrapper<T>: Send'
to hold
Lifetimes, HRTBS, and projections (e.g. '<T as Iterator>::Item') are
taken into account by synthetic impls
However, if a type can *never* implement a particular auto trait
(e.g. 'struct MyStruct<T>(*const T)'), then a negative impl will be
generated (in this case, 'impl<T> !Send for MyStruct<T>')
All of this means that a user should be able to copy-paste a synthetic
impl into their code, without any observable changes in behavior
(assuming the rest of the program remains unchanged).
2017-11-22 16:16:55 -05:00
|
|
|
|
2018-06-30 20:34:18 -07:00
|
|
|
if item.vis.node.is_pub() {
|
Generate documentation for auto-trait impls
A new section is added to both both struct and trait doc pages.
On struct/enum pages, a new 'Auto Trait Implementations' section displays any
synthetic implementations for auto traits. Currently, this is only done
for Send and Sync.
On trait pages, a new 'Auto Implementors' section displays all types
which automatically implement the trait. Effectively, this is a list of
all public types in the standard library.
Synthesized impls for a particular auto trait ('synthetic impls') take
into account generic bounds. For example, a type 'struct Foo<T>(T)' will
have 'impl<T> Send for Foo<T> where T: Send' generated for it.
Manual implementations of auto traits are also taken into account. If we have
the following types:
'struct Foo<T>(T)'
'struct Wrapper<T>(Foo<T>)'
'unsafe impl<T> Send for Wrapper<T>' // pretend that Wrapper<T> makes
this sound somehow
Then Wrapper will have the following impl generated:
'impl<T> Send for Wrapper<T>'
reflecting the fact that 'T: Send' need not hold for 'Wrapper<T>: Send'
to hold
Lifetimes, HRTBS, and projections (e.g. '<T as Iterator>::Item') are
taken into account by synthetic impls
However, if a type can *never* implement a particular auto trait
(e.g. 'struct MyStruct<T>(*const T)'), then a negative impl will be
generated (in this case, 'impl<T> !Send for MyStruct<T>')
All of this means that a user should be able to copy-paste a synthetic
impl into their code, without any observable changes in behavior
(assuming the rest of the program remains unchanged).
2017-11-22 16:16:55 -05:00
|
|
|
let def_id = self.cx.tcx.hir.local_def_id(item.id);
|
|
|
|
self.store_path(def_id);
|
|
|
|
}
|
|
|
|
|
2014-01-07 18:46:16 -08:00
|
|
|
match item.node {
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::ForeignMod(ref fm) => {
|
2016-11-14 18:24:47 +00:00
|
|
|
// If inlining we only want to include public functions.
|
|
|
|
om.foreigns.push(if self.inlining {
|
|
|
|
hir::ForeignMod {
|
|
|
|
abi: fm.abi,
|
2018-06-30 20:34:18 -07:00
|
|
|
items: fm.items.iter().filter(|i| i.vis.node.is_pub()).cloned().collect(),
|
2016-11-14 18:24:47 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fm.clone()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// If we're inlining, skip private items.
|
2018-06-30 20:34:18 -07:00
|
|
|
_ if self.inlining && !item.vis.node.is_pub() => {}
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::GlobalAsm(..) => {}
|
|
|
|
hir::ItemKind::ExternCrate(orig_name) => {
|
2017-09-08 13:51:57 -07:00
|
|
|
let def_id = self.cx.tcx.hir.local_def_id(item.id);
|
2014-12-26 10:55:16 +02:00
|
|
|
om.extern_crates.push(ExternCrate {
|
2017-09-08 13:51:57 -07:00
|
|
|
cnum: self.cx.tcx.extern_mod_stmt_cnum(def_id)
|
2016-08-31 14:00:29 +03:00
|
|
|
.unwrap_or(LOCAL_CRATE),
|
2017-08-06 22:54:09 -07:00
|
|
|
name,
|
2018-03-09 18:51:48 +03:00
|
|
|
path: orig_name.map(|x|x.to_string()),
|
2016-03-25 06:08:11 +00:00
|
|
|
vis: item.vis.clone(),
|
2014-12-26 10:55:16 +02:00
|
|
|
attrs: item.attrs.clone(),
|
|
|
|
whence: item.span,
|
|
|
|
})
|
|
|
|
}
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::Use(_, hir::UseKind::ListStem) => {}
|
|
|
|
hir::ItemKind::Use(ref path, kind) => {
|
2016-11-24 06:11:31 +02:00
|
|
|
let is_glob = kind == hir::UseKind::Glob;
|
|
|
|
|
2018-07-10 00:16:18 +01:00
|
|
|
// struct and variant constructors always show up alongside their definitions, we've
|
|
|
|
// already processed them so just discard these.
|
|
|
|
match path.def {
|
|
|
|
Def::StructCtor(..) | Def::VariantCtor(..) => return,
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
2016-11-14 18:24:47 +00:00
|
|
|
// If there was a private module in the current path then don't bother inlining
|
|
|
|
// anything as it will probably be stripped anyway.
|
2018-06-30 20:34:18 -07:00
|
|
|
if item.vis.node.is_pub() && self.inside_public_path {
|
2014-12-26 10:55:16 +02:00
|
|
|
let please_inline = item.attrs.iter().any(|item| {
|
|
|
|
match item.meta_item_list() {
|
2017-03-03 09:23:59 +00:00
|
|
|
Some(ref list) if item.check_name("doc") => {
|
2016-08-19 18:58:14 -07:00
|
|
|
list.iter().any(|i| i.check_name("inline"))
|
2014-12-26 10:55:16 +02:00
|
|
|
}
|
2016-03-09 02:05:39 +01:00
|
|
|
_ => false,
|
2014-12-26 10:55:16 +02:00
|
|
|
}
|
|
|
|
});
|
2016-11-24 06:11:31 +02:00
|
|
|
let name = if is_glob { None } else { Some(name) };
|
2016-11-25 13:21:19 +02:00
|
|
|
if self.maybe_inline_local(item.id,
|
|
|
|
path.def,
|
|
|
|
name,
|
|
|
|
is_glob,
|
|
|
|
om,
|
|
|
|
please_inline) {
|
2016-11-24 06:11:31 +02:00
|
|
|
return;
|
2014-12-26 10:55:16 +02:00
|
|
|
}
|
2016-11-24 06:11:31 +02:00
|
|
|
}
|
|
|
|
|
2014-12-26 10:55:16 +02:00
|
|
|
om.imports.push(Import {
|
2017-08-06 22:54:09 -07:00
|
|
|
name,
|
2014-12-26 10:55:16 +02:00
|
|
|
id: item.id,
|
2016-03-25 06:08:11 +00:00
|
|
|
vis: item.vis.clone(),
|
2014-12-26 10:55:16 +02:00
|
|
|
attrs: item.attrs.clone(),
|
2016-11-24 06:11:31 +02:00
|
|
|
path: (**path).clone(),
|
|
|
|
glob: is_glob,
|
2014-12-26 10:55:16 +02:00
|
|
|
whence: item.span,
|
|
|
|
});
|
|
|
|
}
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::Mod(ref m) => {
|
2014-02-28 17:46:09 -08:00
|
|
|
om.mods.push(self.visit_mod_contents(item.span,
|
2014-05-18 16:56:13 +03:00
|
|
|
item.attrs.clone(),
|
2016-03-25 06:08:11 +00:00
|
|
|
item.vis.clone(),
|
2014-02-28 17:46:09 -08:00
|
|
|
item.id,
|
|
|
|
m,
|
2014-05-18 16:56:13 +03:00
|
|
|
Some(name)));
|
2014-01-07 18:46:16 -08:00
|
|
|
},
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::Enum(ref ed, ref gen) =>
|
2014-05-18 16:56:13 +03:00
|
|
|
om.enums.push(self.visit_enum_def(item, name, ed, gen)),
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::Struct(ref sd, ref gen) =>
|
2015-10-25 18:33:51 +03:00
|
|
|
om.structs.push(self.visit_variant_data(item, name, sd, gen)),
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::Union(ref sd, ref gen) =>
|
2016-08-10 21:00:17 +03:00
|
|
|
om.unions.push(self.visit_union_data(item, name, sd, gen)),
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::Fn(ref fd, header, ref gen, body) =>
|
2018-05-16 22:55:18 -07:00
|
|
|
om.fns.push(self.visit_fn(item, name, &**fd, header, gen, body)),
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::Ty(ref ty, ref gen) => {
|
2014-01-07 18:46:16 -08:00
|
|
|
let t = Typedef {
|
2014-05-18 16:56:13 +03:00
|
|
|
ty: ty.clone(),
|
2014-01-07 18:46:16 -08:00
|
|
|
gen: gen.clone(),
|
2017-08-06 22:54:09 -07:00
|
|
|
name,
|
2014-01-07 18:46:16 -08:00
|
|
|
id: item.id,
|
2014-05-18 16:56:13 +03:00
|
|
|
attrs: item.attrs.clone(),
|
2014-08-11 09:32:26 -07:00
|
|
|
whence: item.span,
|
2016-03-25 06:08:11 +00:00
|
|
|
vis: item.vis.clone(),
|
2014-06-26 11:37:39 -07:00
|
|
|
stab: self.stability(item.id),
|
2015-12-12 23:01:27 +03:00
|
|
|
depr: self.deprecation(item.id),
|
2014-01-07 18:46:16 -08:00
|
|
|
};
|
|
|
|
om.typedefs.push(t);
|
|
|
|
},
|
2018-07-03 19:38:14 +02:00
|
|
|
hir::ItemKind::Existential(ref exist_ty) => {
|
|
|
|
let t = Existential {
|
|
|
|
exist_ty: exist_ty.clone(),
|
|
|
|
name,
|
|
|
|
id: item.id,
|
|
|
|
attrs: item.attrs.clone(),
|
|
|
|
whence: item.span,
|
|
|
|
vis: item.vis.clone(),
|
|
|
|
stab: self.stability(item.id),
|
|
|
|
depr: self.deprecation(item.id),
|
|
|
|
};
|
|
|
|
om.existentials.push(t);
|
|
|
|
},
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::Static(ref ty, ref mut_, ref exp) => {
|
2014-01-07 18:46:16 -08:00
|
|
|
let s = Static {
|
2014-05-18 16:56:13 +03:00
|
|
|
type_: ty.clone(),
|
2014-01-07 18:46:16 -08:00
|
|
|
mutability: mut_.clone(),
|
|
|
|
expr: exp.clone(),
|
|
|
|
id: item.id,
|
2017-08-06 22:54:09 -07:00
|
|
|
name,
|
2014-05-18 16:56:13 +03:00
|
|
|
attrs: item.attrs.clone(),
|
2014-08-11 09:32:26 -07:00
|
|
|
whence: item.span,
|
2016-03-25 06:08:11 +00:00
|
|
|
vis: item.vis.clone(),
|
2014-06-26 11:37:39 -07:00
|
|
|
stab: self.stability(item.id),
|
2015-12-12 23:01:27 +03:00
|
|
|
depr: self.deprecation(item.id),
|
2014-01-07 18:46:16 -08:00
|
|
|
};
|
|
|
|
om.statics.push(s);
|
|
|
|
},
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::Const(ref ty, ref exp) => {
|
2014-10-06 17:41:15 -07:00
|
|
|
let s = Constant {
|
|
|
|
type_: ty.clone(),
|
|
|
|
expr: exp.clone(),
|
|
|
|
id: item.id,
|
2017-08-06 22:54:09 -07:00
|
|
|
name,
|
2014-10-06 17:41:15 -07:00
|
|
|
attrs: item.attrs.clone(),
|
|
|
|
whence: item.span,
|
2016-03-25 06:08:11 +00:00
|
|
|
vis: item.vis.clone(),
|
2014-10-06 17:41:15 -07:00
|
|
|
stab: self.stability(item.id),
|
2015-12-12 23:01:27 +03:00
|
|
|
depr: self.deprecation(item.id),
|
2014-10-06 17:41:15 -07:00
|
|
|
};
|
|
|
|
om.constants.push(s);
|
|
|
|
},
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::Trait(is_auto, unsafety, ref gen, ref b, ref item_ids) => {
|
2016-12-04 04:21:06 +02:00
|
|
|
let items = item_ids.iter()
|
2017-01-26 02:41:06 +02:00
|
|
|
.map(|ti| self.cx.tcx.hir.trait_item(ti.id).clone())
|
2016-12-04 04:21:06 +02:00
|
|
|
.collect();
|
2014-01-07 18:46:16 -08:00
|
|
|
let t = Trait {
|
2018-01-23 01:04:24 +00:00
|
|
|
is_auto,
|
2017-08-06 22:54:09 -07:00
|
|
|
unsafety,
|
|
|
|
name,
|
|
|
|
items,
|
2014-01-07 18:46:16 -08:00
|
|
|
generics: gen.clone(),
|
2015-02-13 07:33:44 +00:00
|
|
|
bounds: b.iter().cloned().collect(),
|
2014-01-07 18:46:16 -08:00
|
|
|
id: item.id,
|
2014-05-18 16:56:13 +03:00
|
|
|
attrs: item.attrs.clone(),
|
2014-08-11 09:32:26 -07:00
|
|
|
whence: item.span,
|
2016-03-25 06:08:11 +00:00
|
|
|
vis: item.vis.clone(),
|
2014-06-26 11:37:39 -07:00
|
|
|
stab: self.stability(item.id),
|
2015-12-12 23:01:27 +03:00
|
|
|
depr: self.deprecation(item.id),
|
2014-01-07 18:46:16 -08:00
|
|
|
};
|
|
|
|
om.traits.push(t);
|
|
|
|
},
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::TraitAlias(..) => {
|
2017-12-04 00:07:15 -05:00
|
|
|
unimplemented!("trait objects are not yet implemented")
|
|
|
|
},
|
2016-11-14 18:24:47 +00:00
|
|
|
|
2018-07-11 23:36:06 +08:00
|
|
|
hir::ItemKind::Impl(unsafety,
|
2016-11-21 11:59:52 +01:00
|
|
|
polarity,
|
|
|
|
defaultness,
|
|
|
|
ref gen,
|
|
|
|
ref tr,
|
|
|
|
ref ty,
|
|
|
|
ref item_ids) => {
|
2016-11-14 18:24:47 +00:00
|
|
|
// Don't duplicate impls when inlining, we'll pick them up
|
|
|
|
// regardless of where they're located.
|
|
|
|
if !self.inlining {
|
2016-11-04 18:20:15 -04:00
|
|
|
let items = item_ids.iter()
|
2017-01-26 02:41:06 +02:00
|
|
|
.map(|ii| self.cx.tcx.hir.impl_item(ii.id).clone())
|
2016-11-04 18:20:15 -04:00
|
|
|
.collect();
|
2016-11-14 18:24:47 +00:00
|
|
|
let i = Impl {
|
2017-08-06 22:54:09 -07:00
|
|
|
unsafety,
|
|
|
|
polarity,
|
|
|
|
defaultness,
|
2016-11-14 18:24:47 +00:00
|
|
|
generics: gen.clone(),
|
|
|
|
trait_: tr.clone(),
|
|
|
|
for_: ty.clone(),
|
2017-08-06 22:54:09 -07:00
|
|
|
items,
|
2016-11-14 18:24:47 +00:00
|
|
|
attrs: item.attrs.clone(),
|
|
|
|
id: item.id,
|
|
|
|
whence: item.span,
|
|
|
|
vis: item.vis.clone(),
|
|
|
|
stab: self.stability(item.id),
|
|
|
|
depr: self.deprecation(item.id),
|
|
|
|
};
|
2015-04-07 11:08:21 -07:00
|
|
|
om.impls.push(i);
|
|
|
|
}
|
2014-01-07 18:46:16 -08:00
|
|
|
},
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
2014-07-17 09:45:31 -07:00
|
|
|
|
|
|
|
// convert each exported_macro into a doc item
|
2016-12-19 14:24:33 -05:00
|
|
|
fn visit_local_macro(&self, def: &hir::MacroDef) -> Macro {
|
2018-05-23 16:22:18 -05:00
|
|
|
debug!("visit_local_macro: {}", def.name);
|
2017-02-21 05:05:59 +00:00
|
|
|
let tts = def.body.trees().collect::<Vec<_>>();
|
2015-11-26 19:14:36 +01:00
|
|
|
// Extract the spans of all matchers. They represent the "interface" of the macro.
|
2017-02-21 05:05:59 +00:00
|
|
|
let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect();
|
2015-11-26 19:14:36 +01:00
|
|
|
|
2014-07-17 09:45:31 -07:00
|
|
|
Macro {
|
2017-01-26 02:41:06 +02:00
|
|
|
def_id: self.cx.tcx.hir.local_def_id(def.id),
|
2014-12-30 19:10:46 -08:00
|
|
|
attrs: def.attrs.clone(),
|
2015-09-20 14:51:40 +03:00
|
|
|
name: def.name,
|
2014-12-30 19:10:46 -08:00
|
|
|
whence: def.span,
|
2017-08-06 22:54:09 -07:00
|
|
|
matchers,
|
2014-12-30 19:10:46 -08:00
|
|
|
stab: self.stability(def.id),
|
2015-12-12 23:01:27 +03:00
|
|
|
depr: self.deprecation(def.id),
|
2016-11-29 23:36:27 +00:00
|
|
|
imported_from: None,
|
2014-07-17 09:45:31 -07:00
|
|
|
}
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|