Skip to content

Commit 9267119

Browse files
committed
Auto merge of #63873 - Centril:rollup-jgglypd, r=Centril
Rollup of 6 pull requests Successful merges: - #62744 (Refactor `TinyList::contains` and `len` to iterate instead of recurse) - #63813 (Do not suggest `.try_into()` on `i32::from(x)`) - #63833 (Suggest calling closure with resolved return type when appropriate) - #63839 (Ensure miri can do bit ops on pointer values) - #63854 (Modifies how Arg, Arm, Field, FieldPattern and Variant are visited) - #63859 (Don't unwrap the result of `span_to_snippet`) Failed merges: r? @ghost
2 parents eeba189 + 4d3d06a commit 9267119

29 files changed

+436
-307
lines changed

src/librustc/hir/map/def_collector.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,19 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
154154
});
155155
}
156156

157-
fn visit_variant(&mut self, v: &'a Variant, g: &'a Generics, item_id: NodeId) {
157+
fn visit_variant(&mut self, v: &'a Variant) {
158158
let def = self.create_def(v.id,
159159
DefPathData::TypeNs(v.ident.as_interned_str()),
160160
v.span);
161161
self.with_parent(def, |this| {
162162
if let Some(ctor_hir_id) = v.data.ctor_id() {
163163
this.create_def(ctor_hir_id, DefPathData::Ctor, v.span);
164164
}
165-
visit::walk_variant(this, v, g, item_id)
165+
visit::walk_variant(this, v)
166166
});
167167
}
168168

169-
fn visit_variant_data(&mut self, data: &'a VariantData, _: Ident,
170-
_: &'a Generics, _: NodeId, _: Span) {
169+
fn visit_variant_data(&mut self, data: &'a VariantData) {
171170
for (index, field) in data.fields().iter().enumerate() {
172171
let name = field.ident.map(|ident| ident.name)
173172
.unwrap_or_else(|| sym::integer(index));

src/librustc/lint/context.rs

+15-20
Original file line numberDiff line numberDiff line change
@@ -1040,13 +1040,13 @@ for LateContextAndPass<'a, 'tcx, T> {
10401040

10411041
fn visit_variant_data(&mut self,
10421042
s: &'tcx hir::VariantData,
1043-
name: ast::Name,
1044-
g: &'tcx hir::Generics,
1045-
item_id: hir::HirId,
1043+
_: ast::Name,
1044+
_: &'tcx hir::Generics,
1045+
_: hir::HirId,
10461046
_: Span) {
1047-
lint_callback!(self, check_struct_def, s, name, g, item_id);
1047+
lint_callback!(self, check_struct_def, s);
10481048
hir_visit::walk_struct_def(self, s);
1049-
lint_callback!(self, check_struct_def_post, s, name, g, item_id);
1049+
lint_callback!(self, check_struct_def_post, s);
10501050
}
10511051

10521052
fn visit_struct_field(&mut self, s: &'tcx hir::StructField) {
@@ -1061,9 +1061,9 @@ for LateContextAndPass<'a, 'tcx, T> {
10611061
g: &'tcx hir::Generics,
10621062
item_id: hir::HirId) {
10631063
self.with_lint_attrs(v.id, &v.attrs, |cx| {
1064-
lint_callback!(cx, check_variant, v, g);
1064+
lint_callback!(cx, check_variant, v);
10651065
hir_visit::walk_variant(cx, v, g, item_id);
1066-
lint_callback!(cx, check_variant_post, v, g);
1066+
lint_callback!(cx, check_variant_post, v);
10671067
})
10681068
}
10691069

@@ -1214,18 +1214,13 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
12141214
run_early_pass!(self, check_fn_post, fk, decl, span, id);
12151215
}
12161216

1217-
fn visit_variant_data(&mut self,
1218-
s: &'a ast::VariantData,
1219-
ident: ast::Ident,
1220-
g: &'a ast::Generics,
1221-
item_id: ast::NodeId,
1222-
_: Span) {
1223-
run_early_pass!(self, check_struct_def, s, ident, g, item_id);
1217+
fn visit_variant_data(&mut self, s: &'a ast::VariantData) {
1218+
run_early_pass!(self, check_struct_def, s);
12241219
if let Some(ctor_hir_id) = s.ctor_id() {
12251220
self.check_id(ctor_hir_id);
12261221
}
12271222
ast_visit::walk_struct_def(self, s);
1228-
run_early_pass!(self, check_struct_def_post, s, ident, g, item_id);
1223+
run_early_pass!(self, check_struct_def_post, s);
12291224
}
12301225

12311226
fn visit_struct_field(&mut self, s: &'a ast::StructField) {
@@ -1235,11 +1230,11 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
12351230
})
12361231
}
12371232

1238-
fn visit_variant(&mut self, v: &'a ast::Variant, g: &'a ast::Generics, item_id: ast::NodeId) {
1239-
self.with_lint_attrs(item_id, &v.attrs, |cx| {
1240-
run_early_pass!(cx, check_variant, v, g);
1241-
ast_visit::walk_variant(cx, v, g, item_id);
1242-
run_early_pass!(cx, check_variant_post, v, g);
1233+
fn visit_variant(&mut self, v: &'a ast::Variant) {
1234+
self.with_lint_attrs(v.id, &v.attrs, |cx| {
1235+
run_early_pass!(cx, check_variant, v);
1236+
ast_visit::walk_variant(cx, v);
1237+
run_early_pass!(cx, check_variant_post, v);
12431238
})
12441239
}
12451240

src/librustc/lint/mod.rs

+8-28
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,11 @@ macro_rules! late_lint_methods {
248248
fn check_trait_item_post(a: &$hir hir::TraitItem);
249249
fn check_impl_item(a: &$hir hir::ImplItem);
250250
fn check_impl_item_post(a: &$hir hir::ImplItem);
251-
fn check_struct_def(
252-
a: &$hir hir::VariantData,
253-
b: ast::Name,
254-
c: &$hir hir::Generics,
255-
d: hir::HirId
256-
);
257-
fn check_struct_def_post(
258-
a: &$hir hir::VariantData,
259-
b: ast::Name,
260-
c: &$hir hir::Generics,
261-
d: hir::HirId
262-
);
251+
fn check_struct_def(a: &$hir hir::VariantData);
252+
fn check_struct_def_post(a: &$hir hir::VariantData);
263253
fn check_struct_field(a: &$hir hir::StructField);
264-
fn check_variant(a: &$hir hir::Variant, b: &$hir hir::Generics);
265-
fn check_variant_post(a: &$hir hir::Variant, b: &$hir hir::Generics);
254+
fn check_variant(a: &$hir hir::Variant);
255+
fn check_variant_post(a: &$hir hir::Variant);
266256
fn check_lifetime(a: &$hir hir::Lifetime);
267257
fn check_path(a: &$hir hir::Path, b: hir::HirId);
268258
fn check_attribute(a: &$hir ast::Attribute);
@@ -395,21 +385,11 @@ macro_rules! early_lint_methods {
395385
fn check_trait_item_post(a: &ast::TraitItem);
396386
fn check_impl_item(a: &ast::ImplItem);
397387
fn check_impl_item_post(a: &ast::ImplItem);
398-
fn check_struct_def(
399-
a: &ast::VariantData,
400-
b: ast::Ident,
401-
c: &ast::Generics,
402-
d: ast::NodeId
403-
);
404-
fn check_struct_def_post(
405-
a: &ast::VariantData,
406-
b: ast::Ident,
407-
c: &ast::Generics,
408-
d: ast::NodeId
409-
);
388+
fn check_struct_def(a: &ast::VariantData);
389+
fn check_struct_def_post(a: &ast::VariantData);
410390
fn check_struct_field(a: &ast::StructField);
411-
fn check_variant(a: &ast::Variant, b: &ast::Generics);
412-
fn check_variant_post(a: &ast::Variant, b: &ast::Generics);
391+
fn check_variant(a: &ast::Variant);
392+
fn check_variant_post(a: &ast::Variant);
413393
fn check_lifetime(a: &ast::Lifetime);
414394
fn check_path(a: &ast::Path, b: ast::NodeId);
415395
fn check_attribute(a: &ast::Attribute);

src/librustc/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'tcx> ClosureSubsts<'tcx> {
385385
let ty = self.closure_sig_ty(def_id, tcx);
386386
match ty.sty {
387387
ty::FnPtr(sig) => sig,
388-
_ => bug!("closure_sig_ty is not a fn-ptr: {:?}", ty),
388+
_ => bug!("closure_sig_ty is not a fn-ptr: {:?}", ty.sty),
389389
}
390390
}
391391
}

src/librustc_data_structures/tiny_list.rs

+16-40
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub struct TinyList<T: PartialEq> {
2020
}
2121

2222
impl<T: PartialEq> TinyList<T> {
23-
2423
#[inline]
2524
pub fn new() -> TinyList<T> {
2625
TinyList {
@@ -60,20 +59,24 @@ impl<T: PartialEq> TinyList<T> {
6059

6160
#[inline]
6261
pub fn contains(&self, data: &T) -> bool {
63-
if let Some(ref head) = self.head {
64-
head.contains(data)
65-
} else {
66-
false
62+
let mut elem = self.head.as_ref();
63+
while let Some(ref e) = elem {
64+
if &e.data == data {
65+
return true;
66+
}
67+
elem = e.next.as_ref().map(|e| &**e);
6768
}
69+
false
6870
}
6971

7072
#[inline]
7173
pub fn len(&self) -> usize {
72-
if let Some(ref head) = self.head {
73-
head.len()
74-
} else {
75-
0
74+
let (mut elem, mut count) = (self.head.as_ref(), 0);
75+
while let Some(ref e) = elem {
76+
count += 1;
77+
elem = e.next.as_ref().map(|e| &**e);
7678
}
79+
count
7780
}
7881
}
7982

@@ -84,40 +87,13 @@ struct Element<T: PartialEq> {
8487
}
8588

8689
impl<T: PartialEq> Element<T> {
87-
8890
fn remove_next(&mut self, data: &T) -> bool {
89-
let new_next = if let Some(ref mut next) = self.next {
90-
if next.data != *data {
91-
return next.remove_next(data)
92-
} else {
93-
next.next.take()
94-
}
95-
} else {
96-
return false
91+
let new_next = match self.next {
92+
Some(ref mut next) if next.data == *data => next.next.take(),
93+
Some(ref mut next) => return next.remove_next(data),
94+
None => return false,
9795
};
98-
9996
self.next = new_next;
100-
10197
true
10298
}
103-
104-
fn len(&self) -> usize {
105-
if let Some(ref next) = self.next {
106-
1 + next.len()
107-
} else {
108-
1
109-
}
110-
}
111-
112-
fn contains(&self, data: &T) -> bool {
113-
if self.data == *data {
114-
return true
115-
}
116-
117-
if let Some(ref next) = self.next {
118-
next.contains(data)
119-
} else {
120-
false
121-
}
122-
}
12399
}

src/librustc_data_structures/tiny_list/tests.rs

+29-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22

33
extern crate test;
4-
use test::Bencher;
4+
use test::{Bencher, black_box};
55

66
#[test]
77
fn test_contains_and_insert() {
@@ -98,36 +98,59 @@ fn test_remove_single() {
9898
#[bench]
9999
fn bench_insert_empty(b: &mut Bencher) {
100100
b.iter(|| {
101-
let mut list = TinyList::new();
101+
let mut list = black_box(TinyList::new());
102102
list.insert(1);
103+
list
103104
})
104105
}
105106

106107
#[bench]
107108
fn bench_insert_one(b: &mut Bencher) {
108109
b.iter(|| {
109-
let mut list = TinyList::new_single(0);
110+
let mut list = black_box(TinyList::new_single(0));
110111
list.insert(1);
112+
list
111113
})
112114
}
113115

116+
#[bench]
117+
fn bench_contains_empty(b: &mut Bencher) {
118+
b.iter(|| {
119+
black_box(TinyList::new()).contains(&1)
120+
});
121+
}
122+
123+
#[bench]
124+
fn bench_contains_unknown(b: &mut Bencher) {
125+
b.iter(|| {
126+
black_box(TinyList::new_single(0)).contains(&1)
127+
});
128+
}
129+
130+
#[bench]
131+
fn bench_contains_one(b: &mut Bencher) {
132+
b.iter(|| {
133+
black_box(TinyList::new_single(1)).contains(&1)
134+
});
135+
}
136+
114137
#[bench]
115138
fn bench_remove_empty(b: &mut Bencher) {
116139
b.iter(|| {
117-
TinyList::new().remove(&1)
140+
black_box(TinyList::new()).remove(&1)
118141
});
119142
}
120143

121144
#[bench]
122145
fn bench_remove_unknown(b: &mut Bencher) {
123146
b.iter(|| {
124-
TinyList::new_single(0).remove(&1)
147+
black_box(TinyList::new_single(0)).remove(&1)
125148
});
126149
}
127150

128151
#[bench]
129152
fn bench_remove_one(b: &mut Bencher) {
130153
b.iter(|| {
131-
TinyList::new_single(1).remove(&1)
154+
black_box(TinyList::new_single(1)).remove(&1)
132155
});
133156
}

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
482482
}
483483
}
484484

485-
fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant, _: &hir::Generics) {
485+
fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant) {
486486
self.check_missing_docs_attrs(cx,
487487
Some(v.id),
488488
&v.attrs,

src/librustc_lint/nonstandard_style.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl EarlyLintPass for NonCamelCaseTypes {
146146
}
147147
}
148148

149-
fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant, _: &ast::Generics) {
149+
fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant) {
150150
self.check_case(cx, "variant", &v.ident);
151151
}
152152

@@ -350,9 +350,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
350350
&mut self,
351351
cx: &LateContext<'_, '_>,
352352
s: &hir::VariantData,
353-
_: ast::Name,
354-
_: &hir::Generics,
355-
_: hir::HirId,
356353
) {
357354
for sf in s.fields() {
358355
self.check_snake_case(cx, "structure field", &sf.ident);

0 commit comments

Comments
 (0)