Skip to content

Commit 2919ecd

Browse files
committed
A few cleanups for hir
1 parent fdcd4a4 commit 2919ecd

11 files changed

+93
-155
lines changed

src/librustc/hir/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
125125
.iter()
126126
.filter(|attr| attr.name() == "repr")
127127
.filter_map(|attr| attr.meta_item_list())
128-
.flat_map(|hints| hints)
128+
.flatten()
129129
.collect();
130130

131131
let mut int_reprs = 0;
@@ -185,7 +185,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
185185
continue
186186
}
187187
}
188-
"i8" | "u8" | "i16" | "u16" |
188+
"i8" | "u8" | "i16" | "u16" |
189189
"i32" | "u32" | "i64" | "u64" |
190190
"isize" | "usize" => {
191191
int_reprs += 1;

src/librustc/hir/intravisit.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ use super::itemlikevisit::DeepVisitor;
5050

5151
use std::cmp;
5252
use std::u32;
53-
use std::result::Result::Err;
5453

5554
#[derive(Copy, Clone)]
5655
pub enum FnKind<'a> {
@@ -1067,31 +1066,26 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10671066
ExprKind::Break(ref destination, ref opt_expr) => {
10681067
if let Some(ref label) = destination.label {
10691068
visitor.visit_label(label);
1070-
match destination.target_id {
1071-
Ok(node_id) => visitor.visit_def_mention(Def::Label(node_id)),
1072-
Err(_) => {},
1073-
};
1069+
if let Ok(node_id) = destination.target_id {
1070+
visitor.visit_def_mention(Def::Label(node_id))
1071+
}
10741072
}
10751073
walk_list!(visitor, visit_expr, opt_expr);
10761074
}
10771075
ExprKind::Continue(ref destination) => {
10781076
if let Some(ref label) = destination.label {
10791077
visitor.visit_label(label);
1080-
match destination.target_id {
1081-
Ok(node_id) => visitor.visit_def_mention(Def::Label(node_id)),
1082-
Err(_) => {},
1083-
};
1078+
if let Ok(node_id) = destination.target_id {
1079+
visitor.visit_def_mention(Def::Label(node_id))
1080+
}
10841081
}
10851082
}
10861083
ExprKind::Ret(ref optional_expression) => {
10871084
walk_list!(visitor, visit_expr, optional_expression);
10881085
}
10891086
ExprKind::InlineAsm(_, ref outputs, ref inputs) => {
1090-
for output in outputs {
1091-
visitor.visit_expr(output)
1092-
}
1093-
for input in inputs {
1094-
visitor.visit_expr(input)
1087+
for expr in outputs.iter().chain(inputs.iter()) {
1088+
visitor.visit_expr(expr)
10951089
}
10961090
}
10971091
ExprKind::Yield(ref subexpression) => {
@@ -1156,7 +1150,6 @@ impl IdRange {
11561150
self.min = cmp::min(self.min, id);
11571151
self.max = cmp::max(self.max, NodeId::from_u32(id.as_u32() + 1));
11581152
}
1159-
11601153
}
11611154

11621155

src/librustc/hir/lowering.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ impl<'a> LoweringContext<'a> {
596596
})
597597
}
598598

599-
fn expect_full_def_from_use(&mut self, id: NodeId) -> impl Iterator<Item=Def> {
599+
fn expect_full_def_from_use(&mut self, id: NodeId) -> impl Iterator<Item = Def> {
600600
self.resolver.get_import(id).present_items().map(|pr| {
601601
if pr.unresolved_segments() != 0 {
602602
bug!("path not fully resolved: {:?}", pr);
@@ -989,7 +989,7 @@ impl<'a> LoweringContext<'a> {
989989
None => {
990990
self.loop_scopes
991991
.last()
992-
.map(|innermost_loop_id| *innermost_loop_id)
992+
.cloned()
993993
.map(|id| Ok(self.lower_node_id(id).node_id))
994994
.unwrap_or(Err(hir::LoopIdError::OutsideLoopScope))
995995
.into()

src/librustc/hir/map/blocks.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -161,27 +161,27 @@ impl<'a> FnLikeNode<'a> {
161161
}
162162

163163
pub fn body(self) -> ast::BodyId {
164-
self.handle(|i: ItemFnParts<'a>| i.body,
165-
|_, _, _: &'a ast::MethodSig, _, body: ast::BodyId, _, _| body,
164+
self.handle(|i: ItemFnParts<'a>| i.body,
165+
|_, _, _: &'a ast::MethodSig, _, body: ast::BodyId, _, _| body,
166166
|c: ClosureParts<'a>| c.body)
167167
}
168168

169169
pub fn decl(self) -> &'a FnDecl {
170-
self.handle(|i: ItemFnParts<'a>| &*i.decl,
171-
|_, _, sig: &'a ast::MethodSig, _, _, _, _| &sig.decl,
170+
self.handle(|i: ItemFnParts<'a>| &*i.decl,
171+
|_, _, sig: &'a ast::MethodSig, _, _, _, _| &sig.decl,
172172
|c: ClosureParts<'a>| c.decl)
173173
}
174174

175175
pub fn span(self) -> Span {
176-
self.handle(|i: ItemFnParts| i.span,
176+
self.handle(|i: ItemFnParts| i.span,
177177
|_, _, _: &'a ast::MethodSig, _, _, span, _| span,
178-
|c: ClosureParts| c.span)
178+
|c: ClosureParts| c.span)
179179
}
180180

181181
pub fn id(self) -> NodeId {
182-
self.handle(|i: ItemFnParts| i.id,
182+
self.handle(|i: ItemFnParts| i.id,
183183
|id, _, _: &'a ast::MethodSig, _, _, _, _| id,
184-
|c: ClosureParts| c.id)
184+
|c: ClosureParts| c.id)
185185
}
186186

187187
pub fn constness(self) -> ast::Constness {
@@ -260,9 +260,7 @@ impl<'a> FnLikeNode<'a> {
260260
ast::ImplItemKind::Method(ref sig, body) => {
261261
method(ii.id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
262262
}
263-
_ => {
264-
bug!("impl method FnLikeNode that is not fn-like")
265-
}
263+
_ => bug!("impl method FnLikeNode that is not fn-like")
266264
}
267265
},
268266
map::Node::Expr(e) => match e.node {

src/librustc/hir/map/collector.rs

+10-18
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
6767
// them explicitly here.
6868
ref attrs,
6969
span,
70-
7170
// These fields are handled separately:
7271
exported_macros: _,
7372
items: _,
@@ -128,30 +127,27 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
128127
cstore: &dyn CrateStore,
129128
source_map: &SourceMap,
130129
commandline_args_hash: u64)
131-
-> (Vec<Option<Entry<'hir>>>, Svh) {
132-
self.hir_body_nodes
133-
.sort_unstable_by(|&(ref d1, _), &(ref d2, _)| d1.cmp(d2));
130+
-> (Vec<Option<Entry<'hir>>>, Svh)
131+
{
132+
self.hir_body_nodes.sort_unstable_by_key(|bn| bn.0);
134133

135134
let node_hashes = self
136135
.hir_body_nodes
137136
.iter()
138-
.fold(Fingerprint::ZERO, |fingerprint , &(def_path_hash, dep_node_index)| {
137+
.fold(Fingerprint::ZERO, |fingerprint, &(def_path_hash, dep_node_index)| {
139138
fingerprint.combine(
140139
def_path_hash.0.combine(self.dep_graph.fingerprint_of(dep_node_index))
141140
)
142141
});
143142

144143
let mut upstream_crates: Vec<_> = cstore.crates_untracked().iter().map(|&cnum| {
145144
let name = cstore.crate_name_untracked(cnum).as_str();
146-
let disambiguator = cstore.crate_disambiguator_untracked(cnum)
147-
.to_fingerprint();
145+
let disambiguator = cstore.crate_disambiguator_untracked(cnum).to_fingerprint();
148146
let hash = cstore.crate_hash_untracked(cnum);
149147
(name, disambiguator, hash)
150148
}).collect();
151149

152-
upstream_crates.sort_unstable_by(|&(name1, dis1, _), &(name2, dis2, _)| {
153-
(name1, dis1).cmp(&(name2, dis2))
154-
});
150+
upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name, dis));
155151

156152
// We hash the final, remapped names of all local source files so we
157153
// don't have to include the path prefix remapping commandline args.
@@ -229,7 +225,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
229225
}
230226

231227
self.insert_entry(id, entry);
232-
233228
}
234229

235230
fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_id: NodeId, f: F) {
@@ -311,14 +306,11 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
311306
self.with_dep_node_owner(i.hir_id.owner, i, |this| {
312307
this.insert(i.id, Node::Item(i));
313308
this.with_parent(i.id, |this| {
314-
match i.node {
315-
ItemKind::Struct(ref struct_def, _) => {
316-
// If this is a tuple-like struct, register the constructor.
317-
if !struct_def.is_struct() {
318-
this.insert(struct_def.id(), Node::StructCtor(struct_def));
319-
}
309+
if let ItemKind::Struct(ref struct_def, _) = i.node {
310+
// If this is a tuple-like struct, register the constructor.
311+
if !struct_def.is_struct() {
312+
this.insert(struct_def.id(), Node::StructCtor(struct_def));
320313
}
321-
_ => {}
322314
}
323315
intravisit::walk_item(this, i);
324316
});

src/librustc/hir/map/def_collector.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,10 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
331331

332332
fn visit_token(&mut self, t: Token) {
333333
if let Token::Interpolated(nt) = t {
334-
match nt.0 {
335-
token::NtExpr(ref expr) => {
336-
if let ExprKind::Mac(..) = expr.node {
337-
self.visit_macro_invoc(expr.id);
338-
}
334+
if let token::NtExpr(ref expr) = nt.0 {
335+
if let ExprKind::Mac(..) = expr.node {
336+
self.visit_macro_invoc(expr.id);
339337
}
340-
_ => {}
341338
}
342339
}
343340
}

src/librustc/hir/map/definitions.rs

-6
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,8 @@ pub enum DefPathData {
317317
// they are treated specially by the `def_path` function.
318318
/// The crate root (marker)
319319
CrateRoot,
320-
321320
// Catch-all for random DefId things like DUMMY_NODE_ID
322321
Misc,
323-
324322
// Different kinds of items and item-like things:
325323
/// An impl
326324
Impl,
@@ -342,7 +340,6 @@ pub enum DefPathData {
342340
MacroDef(InternedString),
343341
/// A closure expression
344342
ClosureExpr,
345-
346343
// Subportions of items
347344
/// A type parameter (generic parameter)
348345
TypeParam(InternedString),
@@ -358,7 +355,6 @@ pub enum DefPathData {
358355
AnonConst,
359356
/// An `impl Trait` type node
360357
ImplTrait,
361-
362358
/// GlobalMetaData identifies a piece of crate metadata that is global to
363359
/// a whole crate (as opposed to just one item). GlobalMetaData components
364360
/// are only supposed to show up right below the crate root.
@@ -656,10 +652,8 @@ impl DefPathData {
656652
GlobalMetaData(name) => {
657653
return name
658654
}
659-
660655
// note that this does not show up in user printouts
661656
CrateRoot => "{{root}}",
662-
663657
Impl => "{{impl}}",
664658
Misc => "{{?}}",
665659
ClosureExpr => "{{closure}}",

src/librustc/hir/map/hir_id_validator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
100100

101101
if max != self.hir_ids_seen.len() - 1 {
102102
// Collect the missing ItemLocalIds
103-
let missing: Vec<_> = (0 .. max + 1)
104-
.filter(|&i| !self.hir_ids_seen.contains_key(&ItemLocalId(i as u32)))
103+
let missing: Vec<_> = (0 .. max as u32 + 1)
104+
.filter(|&i| !self.hir_ids_seen.contains_key(&ItemLocalId(i)))
105105
.collect();
106106

107107
// Try to map those to something more useful

0 commit comments

Comments
 (0)