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
|
|
|
//! This module is used to store stuff from Rust's AST in a more convenient
|
|
|
|
//! manner (and with prettier names) before cleaning.
|
2014-11-06 00:05:53 -08:00
|
|
|
pub use self::StructType::*;
|
2013-08-15 16:28:54 -04:00
|
|
|
|
|
|
|
use syntax::ast;
|
2015-09-20 16:47:24 +03:00
|
|
|
use syntax::ast::{Name, NodeId};
|
2015-09-14 21:58:20 +12:00
|
|
|
use syntax::attr;
|
2014-05-18 16:56:13 +03:00
|
|
|
use syntax::ptr::P;
|
2018-06-30 20:34:18 -07:00
|
|
|
use syntax::codemap::Spanned;
|
2016-06-21 18:08:13 -04:00
|
|
|
use syntax_pos::{self, Span};
|
|
|
|
|
2016-03-29 08:50:44 +03:00
|
|
|
use rustc::hir;
|
2016-08-31 14:00:29 +03:00
|
|
|
use rustc::hir::def_id::CrateNum;
|
2014-05-16 10:15:33 -07:00
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Module {
|
2015-09-20 04:50:30 +03:00
|
|
|
pub name: Option<Name>,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2014-04-27 05:08:36 +09:00
|
|
|
pub where_outer: Span,
|
|
|
|
pub where_inner: Span,
|
2014-12-26 10:55:16 +02:00
|
|
|
pub extern_crates: Vec<ExternCrate>,
|
|
|
|
pub imports: Vec<Import>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub structs: Vec<Struct>,
|
2016-08-10 21:00:17 +03:00
|
|
|
pub unions: Vec<Union>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub enums: Vec<Enum>,
|
|
|
|
pub fns: Vec<Function>,
|
|
|
|
pub mods: Vec<Module>,
|
|
|
|
pub id: NodeId,
|
|
|
|
pub typedefs: Vec<Typedef>,
|
2018-07-03 19:38:14 +02:00
|
|
|
pub existentials: Vec<Existential>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub statics: Vec<Static>,
|
2014-10-06 17:41:15 -07:00
|
|
|
pub constants: Vec<Constant>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub traits: Vec<Trait>,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub vis: hir::Visibility,
|
2014-06-26 11:37:39 -07:00
|
|
|
pub stab: Option<attr::Stability>,
|
2015-12-12 23:01:27 +03:00
|
|
|
pub depr: Option<attr::Deprecation>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub impls: Vec<Impl>,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub foreigns: Vec<hir::ForeignMod>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub macros: Vec<Macro>,
|
|
|
|
pub is_crate: bool,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Module {
|
2015-09-20 04:50:30 +03:00
|
|
|
pub fn new(name: Option<Name>) -> Module {
|
2013-08-15 16:28:54 -04:00
|
|
|
Module {
|
|
|
|
name : name,
|
2016-08-31 14:00:29 +03:00
|
|
|
id: ast::CRATE_NODE_ID,
|
2018-07-01 11:05:10 -07:00
|
|
|
vis: Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Inherited },
|
2014-06-26 11:37:39 -07:00
|
|
|
stab: None,
|
2015-12-12 23:01:27 +03:00
|
|
|
depr: None,
|
2016-06-21 18:08:13 -04:00
|
|
|
where_outer: syntax_pos::DUMMY_SP,
|
|
|
|
where_inner: syntax_pos::DUMMY_SP,
|
2015-12-17 20:41:28 +03:00
|
|
|
attrs : hir::HirVec::new(),
|
2014-12-26 10:55:16 +02:00
|
|
|
extern_crates: Vec::new(),
|
|
|
|
imports : Vec::new(),
|
2014-03-05 15:28:08 -08:00
|
|
|
structs : Vec::new(),
|
2016-08-10 21:00:17 +03:00
|
|
|
unions : Vec::new(),
|
2014-03-05 15:28:08 -08:00
|
|
|
enums : Vec::new(),
|
|
|
|
fns : Vec::new(),
|
|
|
|
mods : Vec::new(),
|
|
|
|
typedefs : Vec::new(),
|
2018-07-03 19:38:14 +02:00
|
|
|
existentials: Vec::new(),
|
2014-03-05 15:28:08 -08:00
|
|
|
statics : Vec::new(),
|
2014-10-06 17:41:15 -07:00
|
|
|
constants : Vec::new(),
|
2014-03-05 15:28:08 -08:00
|
|
|
traits : Vec::new(),
|
|
|
|
impls : Vec::new(),
|
|
|
|
foreigns : Vec::new(),
|
|
|
|
macros : Vec::new(),
|
2014-02-28 22:33:45 +01:00
|
|
|
is_crate : false,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Debug, Clone, RustcEncodable, RustcDecodable, Copy)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub enum StructType {
|
2016-08-26 19:23:42 +03:00
|
|
|
/// A braced struct
|
2013-08-15 16:28:54 -04:00
|
|
|
Plain,
|
|
|
|
/// A tuple struct
|
|
|
|
Tuple,
|
|
|
|
/// A unit struct
|
2016-08-26 19:23:42 +03:00
|
|
|
Unit,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Struct {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub vis: hir::Visibility,
|
2014-06-26 11:37:39 -07:00
|
|
|
pub stab: Option<attr::Stability>,
|
2016-08-10 21:00:17 +03:00
|
|
|
pub depr: Option<attr::Deprecation>,
|
|
|
|
pub id: NodeId,
|
|
|
|
pub struct_type: StructType,
|
|
|
|
pub name: Name,
|
|
|
|
pub generics: hir::Generics,
|
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
|
|
|
pub fields: hir::HirVec<hir::StructField>,
|
|
|
|
pub whence: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Union {
|
|
|
|
pub vis: hir::Visibility,
|
|
|
|
pub stab: Option<attr::Stability>,
|
2015-12-12 23:01:27 +03:00
|
|
|
pub depr: Option<attr::Deprecation>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub id: NodeId,
|
|
|
|
pub struct_type: StructType,
|
2015-09-20 04:50:30 +03:00
|
|
|
pub name: Name,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub generics: hir::Generics,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
|
|
|
pub fields: hir::HirVec<hir::StructField>,
|
2014-08-11 09:32:26 -07:00
|
|
|
pub whence: Span,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Enum {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub vis: hir::Visibility,
|
2014-06-26 11:37:39 -07:00
|
|
|
pub stab: Option<attr::Stability>,
|
2015-12-12 23:01:27 +03:00
|
|
|
pub depr: Option<attr::Deprecation>,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub variants: hir::HirVec<Variant>,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub generics: hir::Generics,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub id: NodeId,
|
2014-08-11 09:32:26 -07:00
|
|
|
pub whence: Span,
|
2015-09-20 04:50:30 +03:00
|
|
|
pub name: Name,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Variant {
|
2015-09-20 16:47:24 +03:00
|
|
|
pub name: Name,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2015-10-25 18:33:51 +03:00
|
|
|
pub def: hir::VariantData,
|
2014-06-26 11:37:39 -07:00
|
|
|
pub stab: Option<attr::Stability>,
|
2015-12-12 23:01:27 +03:00
|
|
|
pub depr: Option<attr::Deprecation>,
|
2014-08-11 09:32:26 -07:00
|
|
|
pub whence: Span,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Function {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub decl: hir::FnDecl,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub id: NodeId,
|
2015-09-20 04:50:30 +03:00
|
|
|
pub name: Name,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub vis: hir::Visibility,
|
2014-06-26 11:37:39 -07:00
|
|
|
pub stab: Option<attr::Stability>,
|
2015-12-12 23:01:27 +03:00
|
|
|
pub depr: Option<attr::Deprecation>,
|
2018-05-16 22:55:18 -07:00
|
|
|
pub header: hir::FnHeader,
|
2014-08-11 09:32:26 -07:00
|
|
|
pub whence: Span,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub generics: hir::Generics,
|
2016-12-20 22:46:11 +02:00
|
|
|
pub body: hir::BodyId,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Typedef {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub ty: P<hir::Ty>,
|
|
|
|
pub gen: hir::Generics,
|
2015-09-20 04:50:30 +03:00
|
|
|
pub name: Name,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub id: ast::NodeId,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2014-08-11 09:32:26 -07:00
|
|
|
pub whence: Span,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub vis: hir::Visibility,
|
2014-06-26 11:37:39 -07:00
|
|
|
pub stab: Option<attr::Stability>,
|
2015-12-12 23:01:27 +03:00
|
|
|
pub depr: Option<attr::Deprecation>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2018-07-03 19:38:14 +02:00
|
|
|
pub struct Existential {
|
|
|
|
pub exist_ty: hir::ExistTy,
|
|
|
|
pub name: Name,
|
|
|
|
pub id: ast::NodeId,
|
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
|
|
|
pub whence: Span,
|
|
|
|
pub vis: hir::Visibility,
|
|
|
|
pub stab: Option<attr::Stability>,
|
|
|
|
pub depr: Option<attr::Deprecation>,
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Static {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub type_: P<hir::Ty>,
|
|
|
|
pub mutability: hir::Mutability,
|
2016-12-21 12:32:59 +02:00
|
|
|
pub expr: hir::BodyId,
|
2015-09-20 04:50:30 +03:00
|
|
|
pub name: Name,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub vis: hir::Visibility,
|
2014-06-26 11:37:39 -07:00
|
|
|
pub stab: Option<attr::Stability>,
|
2015-12-12 23:01:27 +03:00
|
|
|
pub depr: Option<attr::Deprecation>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub id: ast::NodeId,
|
2014-08-11 09:32:26 -07:00
|
|
|
pub whence: Span,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-10-06 17:41:15 -07:00
|
|
|
pub struct Constant {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub type_: P<hir::Ty>,
|
2016-12-21 12:32:59 +02:00
|
|
|
pub expr: hir::BodyId,
|
2015-09-20 04:50:30 +03:00
|
|
|
pub name: Name,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub vis: hir::Visibility,
|
2014-10-06 17:41:15 -07:00
|
|
|
pub stab: Option<attr::Stability>,
|
2015-12-12 23:01:27 +03:00
|
|
|
pub depr: Option<attr::Deprecation>,
|
2014-10-06 17:41:15 -07:00
|
|
|
pub id: ast::NodeId,
|
|
|
|
pub whence: Span,
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Trait {
|
2018-01-23 01:04:24 +00:00
|
|
|
pub is_auto: hir::IsAuto,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub unsafety: hir::Unsafety,
|
2015-09-20 04:50:30 +03:00
|
|
|
pub name: Name,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub items: hir::HirVec<hir::TraitItem>,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub generics: hir::Generics,
|
2018-06-14 12:08:58 +01:00
|
|
|
pub bounds: hir::HirVec<hir::GenericBound>,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub id: ast::NodeId,
|
2014-08-11 09:32:26 -07:00
|
|
|
pub whence: Span,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub vis: hir::Visibility,
|
2014-06-26 11:37:39 -07:00
|
|
|
pub stab: Option<attr::Stability>,
|
2015-12-12 23:01:27 +03:00
|
|
|
pub depr: Option<attr::Deprecation>,
|
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
|
|
|
#[derive(Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Impl {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub unsafety: hir::Unsafety,
|
|
|
|
pub polarity: hir::ImplPolarity,
|
2016-11-18 17:14:42 +01:00
|
|
|
pub defaultness: hir::Defaultness,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub generics: hir::Generics,
|
|
|
|
pub trait_: Option<hir::TraitRef>,
|
|
|
|
pub for_: P<hir::Ty>,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub items: hir::HirVec<hir::ImplItem>,
|
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2014-08-11 09:32:26 -07:00
|
|
|
pub whence: Span,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub vis: hir::Visibility,
|
2014-06-26 11:37:39 -07:00
|
|
|
pub stab: Option<attr::Stability>,
|
2015-12-12 23:01:27 +03:00
|
|
|
pub depr: Option<attr::Deprecation>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub id: ast::NodeId,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2016-12-19 14:24:33 -05:00
|
|
|
// For Macro we store the DefId instead of the NodeId, since we also create
|
|
|
|
// these imported macro_rules (which only have a DUMMY_NODE_ID).
|
2014-02-16 21:40:26 -08:00
|
|
|
pub struct Macro {
|
2015-09-20 14:51:40 +03:00
|
|
|
pub name: Name,
|
2016-12-19 14:24:33 -05:00
|
|
|
pub def_id: hir::def_id::DefId,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2014-08-11 09:32:26 -07:00
|
|
|
pub whence: Span,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub matchers: hir::HirVec<Span>,
|
2014-06-26 11:37:39 -07:00
|
|
|
pub stab: Option<attr::Stability>,
|
2015-12-12 23:01:27 +03:00
|
|
|
pub depr: Option<attr::Deprecation>,
|
2015-09-20 14:51:40 +03:00
|
|
|
pub imported_from: Option<Name>,
|
2014-02-16 21:40:26 -08:00
|
|
|
}
|
|
|
|
|
2014-12-26 10:55:16 +02:00
|
|
|
pub struct ExternCrate {
|
2015-09-20 04:50:30 +03:00
|
|
|
pub name: Name,
|
2016-08-31 14:00:29 +03:00
|
|
|
pub cnum: CrateNum,
|
2014-12-26 10:55:16 +02:00
|
|
|
pub path: Option<String>,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub vis: hir::Visibility,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2014-12-26 10:55:16 +02:00
|
|
|
pub whence: Span,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Import {
|
2016-11-24 06:11:31 +02:00
|
|
|
pub name: Name,
|
2014-12-26 10:55:16 +02:00
|
|
|
pub id: NodeId,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub vis: hir::Visibility,
|
2015-12-17 20:41:28 +03:00
|
|
|
pub attrs: hir::HirVec<ast::Attribute>,
|
2016-11-24 06:11:31 +02:00
|
|
|
pub path: hir::Path,
|
|
|
|
pub glob: bool,
|
2014-12-26 10:55:16 +02:00
|
|
|
pub whence: Span,
|
|
|
|
}
|
|
|
|
|
2016-08-26 19:23:42 +03:00
|
|
|
pub fn struct_type_from_def(vdata: &hir::VariantData) -> StructType {
|
|
|
|
match *vdata {
|
|
|
|
hir::VariantData::Struct(..) => Plain,
|
|
|
|
hir::VariantData::Tuple(..) => Tuple,
|
|
|
|
hir::VariantData::Unit(..) => Unit,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|