Skip to content

Commit 08dd58f

Browse files
committed
chore: sync up with current nightly
1 parent 2a4e641 commit 08dd58f

File tree

14 files changed

+976
-516
lines changed

14 files changed

+976
-516
lines changed

src/core/item/mod.rs

+31-15
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,36 @@ pub mod state;
33

44
pub use self::state::ItemState;
55

6-
use std::{slice, iter};
76
use std::rc::Rc;
7+
use std::{iter, slice};
88

9-
use rustc_ast::{ptr, ast};
9+
use rustc_ast::{ast, ptr};
1010

1111
use crate::module::path::ModulePath;
1212

1313
/// The structure Item is a iterable collection of abstract elements.
1414
1515
#[derive(Debug, Clone)]
16-
pub struct Item <'a> {
16+
pub struct Item<'a> {
1717
/// Iterator.
1818
it: iter::Peekable<slice::Iter<'a, (ptr::P<ast::Item>, Rc<ModulePath>)>>,
1919
}
2020

21-
impl <'a>From<iter::Peekable<slice::Iter<'a, (ptr::P<ast::Item>, Rc<ModulePath>)>>> for Item<'a> {
22-
21+
impl<'a> From<iter::Peekable<slice::Iter<'a, (ptr::P<ast::Item>, Rc<ModulePath>)>>> for Item<'a> {
2322
/// The constructor method `from` returns a typed and iterable collection of abstract element.
2423
fn from(iter: iter::Peekable<slice::Iter<'a, (ptr::P<ast::Item>, Rc<ModulePath>)>>) -> Item {
25-
Item {
26-
it: iter,
27-
}
24+
Item { it: iter }
2825
}
2926
}
3027

31-
impl <'a>Iterator for Item<'a> {
28+
impl<'a> Iterator for Item<'a> {
3229
type Item = ItemState<'a>;
3330

3431
/// The method `next` will returns the first abstract elements defined like a structure,
3532
/// enumeration or trait.
3633
fn next(&mut self) -> Option<ItemState<'a>> {
3734
self.it.next().and_then(|item| {
38-
let mut list: Vec<&'a (ptr::P<ast::Item>, Rc<ModulePath>)> = vec!(item);
35+
let mut list: Vec<&'a (ptr::P<ast::Item>, Rc<ModulePath>)> = vec![item];
3936

4037
// Loop over all Items to find any Impl with a name that matches our name.
4138
// This way we can handle cases like:
@@ -45,17 +42,36 @@ impl <'a>Iterator for Item<'a> {
4542
// impl Bar {...}
4643
// impl Foo {...}
4744
let item_name = &item.0.ident.name;
48-
list.extend(self.it.clone().filter(|&&(ref subitem, _): &&'a (ptr::P<ast::Item>, Rc<ModulePath>)| {
49-
if let &ast::ItemKind::Impl(box ast::ImplKind{self_ty: ref ty, ..}) = &subitem.kind {
50-
if let &ast::Ty {kind: ast::TyKind::Path(_, ast::Path{segments: ref seg, ..} ), .. } = &**ty {
45+
list.extend(
46+
self.it
47+
.clone()
48+
.filter(
49+
|&&(ref subitem, _): &&'a (ptr::P<ast::Item>, Rc<ModulePath>)| {
50+
if let &ast::ItemKind::Impl(box ast::Impl {
51+
self_ty: ref ty, ..
52+
}) = &subitem.kind
53+
{
54+
if let &ast::Ty {
55+
kind:
56+
ast::TyKind::Path(
57+
_,
58+
ast::Path {
59+
segments: ref seg, ..
60+
},
61+
),
62+
..
63+
} = &**ty
64+
{
5165
if !seg.is_empty() && &seg[0].ident.name == item_name {
5266
return true;
5367
}
5468
}
5569
}
5670
false
57-
})
58-
.collect::<Vec<&'a (ptr::P<ast::Item>, Rc<ModulePath>)>>());
71+
},
72+
)
73+
.collect::<Vec<&'a (ptr::P<ast::Item>, Rc<ModulePath>)>>(),
74+
);
5975
Some(ItemState::from(list))
6076
})
6177
}

src/core/item/relation.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::ItemState;
22

3-
use ::dot::{Fill, ArrowShape, Side};
3+
use dot::{ArrowShape, Fill, Side};
44

55
/// The enumeration `Relation` is the relationship specification from [UML 2.5](http://www.omg.org/spec/UML/2.5) without generalization.
66
#[derive(Debug, Copy, Clone)]
@@ -14,7 +14,6 @@ pub enum Relation {
1414
}
1515

1616
impl Relation {
17-
1817
/// The method `as_style` returns a stylized arrow (See *Table B.2 UML Edges* from [UML 2.5](http://www.omg.org/spec/UML/2.5).
1918
pub fn as_style(&self) -> ArrowShape {
2019
match self {
@@ -28,7 +27,7 @@ impl Relation {
2827
}
2928
}
3029

31-
impl <'a>From<(&'a ItemState<'a>, &'a ItemState<'a>)> for Relation {
30+
impl<'a> From<(&'a ItemState<'a>, &'a ItemState<'a>)> for Relation {
3231
fn from((left, right): (&'a ItemState<'a>, &'a ItemState<'a>)) -> Relation {
3332
if left.is_composition(right) {
3433
Relation::Composition
+83-37
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::fmt;
22
use std::rc::Rc;
33

4-
use rustc_ast_pretty::pprust::ty_to_string;
54
use rustc_ast::ast;
5+
use rustc_ast_pretty::pprust::ty_to_string;
66
use rustc_span::symbol;
77

88
use crate::module::path::ModulePath;
@@ -15,77 +15,123 @@ use crate::Config;
1515
pub struct Enum<'a> {
1616
pub path: Rc<ModulePath>,
1717
pub span: rustc_span::Span,
18-
18+
1919
/// Visibility
2020
pub vis: &'a ast::VisibilityKind,
2121
pub name: symbol::Symbol,
2222
pub params: Vec<symbol::Symbol>,
2323
pub variants: Vec<(symbol::Symbol, Vec<String>)>,
2424
}
2525

26-
impl <'a>PartialEq for Enum<'a> {
26+
impl<'a> PartialEq for Enum<'a> {
2727
fn eq(&self, b: &Self) -> bool {
28-
2928
let a = self;
3029

3130
use ast::VisibilityKind::*;
3231

3332
let bvis = match (a.vis, b.vis) {
3433
(Public, Public) => true,
3534
(Crate(_), Crate(_)) => true,
36-
(Restricted{..}, Restricted{..}) => true,
35+
(Restricted { .. }, Restricted { .. }) => true,
3736
(Inherited, Inherited) => true,
3837
_ => false,
3938
};
4039

41-
a.path == b.path &&
42-
a.name == b.name &&
43-
a.span == b.span &&
44-
a.params == b.params &&
45-
a.variants == b.variants &&
46-
bvis
40+
a.path == b.path
41+
&& a.name == b.name
42+
&& a.span == b.span
43+
&& a.params == b.params
44+
&& a.variants == b.variants
45+
&& bvis
4746
}
4847
}
4948

50-
impl <'a>Eq for Enum<'a> {}
49+
impl<'a> Eq for Enum<'a> {}
5150

52-
53-
impl <'a>From<((&'a ast::Item, &'a Vec<ast::GenericParam>, &'a Vec<ast::Variant>), Rc<ModulePath>)> for Enum<'a> {
54-
fn from(((item, params, variants), path): ((&'a ast::Item, &'a Vec<ast::GenericParam>, &'a Vec<ast::Variant>), Rc<ModulePath>)) -> Enum<'a> {
51+
impl<'a>
52+
From<(
53+
(
54+
&'a ast::Item,
55+
&'a Vec<ast::GenericParam>,
56+
&'a Vec<ast::Variant>,
57+
),
58+
Rc<ModulePath>,
59+
)> for Enum<'a>
60+
{
61+
fn from(
62+
((item, params, variants), path): (
63+
(
64+
&'a ast::Item,
65+
&'a Vec<ast::GenericParam>,
66+
&'a Vec<ast::Variant>,
67+
),
68+
Rc<ModulePath>,
69+
),
70+
) -> Enum<'a> {
5571
Enum {
5672
path: path,
5773
vis: &item.vis.kind,
5874
name: item.ident.name,
5975
span: item.span,
60-
params: params.iter()
61-
.map(|&ast::GenericParam {attrs: _, ident: symbol::Ident {name, ..}, ..}| name)
62-
.collect::<Vec<symbol::Symbol>>(),
63-
variants: variants.iter()
64-
.map(|&ast::Variant {ident: symbol::Ident {name, ..}, attrs: _, ref data, ..}| {
65-
if let &ast::VariantData::Tuple(ref struct_field, _) = data {
66-
(name,
67-
struct_field.iter()
68-
.filter_map(|&ast::FieldDef { span: _, ident: _, vis: _, id: _, ref ty, .. }| Some(ty_to_string(&ty)))
69-
.collect::<Vec<String>>())
70-
} else {
71-
(name, Vec::new())
72-
}
73-
})
74-
.collect::<Vec<(symbol::Symbol, Vec<String>)>>(),
76+
params: params
77+
.iter()
78+
.map(
79+
|&ast::GenericParam {
80+
attrs: _,
81+
ident: symbol::Ident { name, .. },
82+
..
83+
}| name,
84+
)
85+
.collect::<Vec<symbol::Symbol>>(),
86+
variants: variants
87+
.iter()
88+
.map(
89+
|&ast::Variant {
90+
ident: symbol::Ident { name, .. },
91+
attrs: _,
92+
ref data,
93+
..
94+
}| {
95+
if let &ast::VariantData::Tuple(ref struct_field, _) = data {
96+
(
97+
name,
98+
struct_field
99+
.iter()
100+
.filter_map(
101+
|&ast::FieldDef {
102+
span: _,
103+
ident: _,
104+
vis: _,
105+
id: _,
106+
ref ty,
107+
..
108+
}| {
109+
Some(ty_to_string(&ty))
110+
},
111+
)
112+
.collect::<Vec<String>>(),
113+
)
114+
} else {
115+
(name, Vec::new())
116+
}
117+
},
118+
)
119+
.collect::<Vec<(symbol::Symbol, Vec<String>)>>(),
75120
}
76121
}
77122
}
78123

79-
impl <'a>fmt::Display for Enum<'a> {
124+
impl<'a> fmt::Display for Enum<'a> {
80125
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
81-
82126
let include_variants = !self.variants.is_empty() && Config::global().include_fields;
83127

84128
if !include_variants {
85-
write!(f,
86-
"<tr><td bgcolor=\"{bgcolor}\"><b>{name}</b></td></tr>",
87-
bgcolor = Config::global().enum_header_bgcolor,
88-
name = self.name)
129+
write!(
130+
f,
131+
"<tr><td bgcolor=\"{bgcolor}\"><b>{name}</b></td></tr>",
132+
bgcolor = Config::global().enum_header_bgcolor,
133+
name = self.name
134+
)
89135
} else {
90136
write!(f, "<tr><td bgcolor=\"{header_bgcolor}\"><b>{name}</b></td></tr><tr><td align=\"left\" bgcolor=\"{fields_bgcolor}\">{variants}<br align=\"left\"/></td></tr>",
91137
header_bgcolor = Config::global().enum_header_bgcolor,
@@ -105,4 +151,4 @@ impl <'a>fmt::Display for Enum<'a> {
105151
)
106152
}
107153
}
108-
}
154+
}

0 commit comments

Comments
 (0)