Skip to content

Rollup of 6 pull requests #63873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,19 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
});
}

fn visit_variant(&mut self, v: &'a Variant, g: &'a Generics, item_id: NodeId) {
fn visit_variant(&mut self, v: &'a Variant) {
let def = self.create_def(v.id,
DefPathData::TypeNs(v.ident.as_interned_str()),
v.span);
self.with_parent(def, |this| {
if let Some(ctor_hir_id) = v.data.ctor_id() {
this.create_def(ctor_hir_id, DefPathData::Ctor, v.span);
}
visit::walk_variant(this, v, g, item_id)
visit::walk_variant(this, v)
});
}

fn visit_variant_data(&mut self, data: &'a VariantData, _: Ident,
_: &'a Generics, _: NodeId, _: Span) {
fn visit_variant_data(&mut self, data: &'a VariantData) {
for (index, field) in data.fields().iter().enumerate() {
let name = field.ident.map(|ident| ident.name)
.unwrap_or_else(|| sym::integer(index));
Expand Down
35 changes: 15 additions & 20 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,13 +1040,13 @@ for LateContextAndPass<'a, 'tcx, T> {

fn visit_variant_data(&mut self,
s: &'tcx hir::VariantData,
name: ast::Name,
g: &'tcx hir::Generics,
item_id: hir::HirId,
_: ast::Name,
_: &'tcx hir::Generics,
_: hir::HirId,
_: Span) {
lint_callback!(self, check_struct_def, s, name, g, item_id);
lint_callback!(self, check_struct_def, s);
hir_visit::walk_struct_def(self, s);
lint_callback!(self, check_struct_def_post, s, name, g, item_id);
lint_callback!(self, check_struct_def_post, s);
}

fn visit_struct_field(&mut self, s: &'tcx hir::StructField) {
Expand All @@ -1061,9 +1061,9 @@ for LateContextAndPass<'a, 'tcx, T> {
g: &'tcx hir::Generics,
item_id: hir::HirId) {
self.with_lint_attrs(v.id, &v.attrs, |cx| {
lint_callback!(cx, check_variant, v, g);
lint_callback!(cx, check_variant, v);
hir_visit::walk_variant(cx, v, g, item_id);
lint_callback!(cx, check_variant_post, v, g);
lint_callback!(cx, check_variant_post, v);
})
}

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

fn visit_variant_data(&mut self,
s: &'a ast::VariantData,
ident: ast::Ident,
g: &'a ast::Generics,
item_id: ast::NodeId,
_: Span) {
run_early_pass!(self, check_struct_def, s, ident, g, item_id);
fn visit_variant_data(&mut self, s: &'a ast::VariantData) {
run_early_pass!(self, check_struct_def, s);
if let Some(ctor_hir_id) = s.ctor_id() {
self.check_id(ctor_hir_id);
}
ast_visit::walk_struct_def(self, s);
run_early_pass!(self, check_struct_def_post, s, ident, g, item_id);
run_early_pass!(self, check_struct_def_post, s);
}

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

fn visit_variant(&mut self, v: &'a ast::Variant, g: &'a ast::Generics, item_id: ast::NodeId) {
self.with_lint_attrs(item_id, &v.attrs, |cx| {
run_early_pass!(cx, check_variant, v, g);
ast_visit::walk_variant(cx, v, g, item_id);
run_early_pass!(cx, check_variant_post, v, g);
fn visit_variant(&mut self, v: &'a ast::Variant) {
self.with_lint_attrs(v.id, &v.attrs, |cx| {
run_early_pass!(cx, check_variant, v);
ast_visit::walk_variant(cx, v);
run_early_pass!(cx, check_variant_post, v);
})
}

Expand Down
36 changes: 8 additions & 28 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,11 @@ macro_rules! late_lint_methods {
fn check_trait_item_post(a: &$hir hir::TraitItem);
fn check_impl_item(a: &$hir hir::ImplItem);
fn check_impl_item_post(a: &$hir hir::ImplItem);
fn check_struct_def(
a: &$hir hir::VariantData,
b: ast::Name,
c: &$hir hir::Generics,
d: hir::HirId
);
fn check_struct_def_post(
a: &$hir hir::VariantData,
b: ast::Name,
c: &$hir hir::Generics,
d: hir::HirId
);
fn check_struct_def(a: &$hir hir::VariantData);
fn check_struct_def_post(a: &$hir hir::VariantData);
fn check_struct_field(a: &$hir hir::StructField);
fn check_variant(a: &$hir hir::Variant, b: &$hir hir::Generics);
fn check_variant_post(a: &$hir hir::Variant, b: &$hir hir::Generics);
fn check_variant(a: &$hir hir::Variant);
fn check_variant_post(a: &$hir hir::Variant);
fn check_lifetime(a: &$hir hir::Lifetime);
fn check_path(a: &$hir hir::Path, b: hir::HirId);
fn check_attribute(a: &$hir ast::Attribute);
Expand Down Expand Up @@ -395,21 +385,11 @@ macro_rules! early_lint_methods {
fn check_trait_item_post(a: &ast::TraitItem);
fn check_impl_item(a: &ast::ImplItem);
fn check_impl_item_post(a: &ast::ImplItem);
fn check_struct_def(
a: &ast::VariantData,
b: ast::Ident,
c: &ast::Generics,
d: ast::NodeId
);
fn check_struct_def_post(
a: &ast::VariantData,
b: ast::Ident,
c: &ast::Generics,
d: ast::NodeId
);
fn check_struct_def(a: &ast::VariantData);
fn check_struct_def_post(a: &ast::VariantData);
fn check_struct_field(a: &ast::StructField);
fn check_variant(a: &ast::Variant, b: &ast::Generics);
fn check_variant_post(a: &ast::Variant, b: &ast::Generics);
fn check_variant(a: &ast::Variant);
fn check_variant_post(a: &ast::Variant);
fn check_lifetime(a: &ast::Lifetime);
fn check_path(a: &ast::Path, b: ast::NodeId);
fn check_attribute(a: &ast::Attribute);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl<'tcx> ClosureSubsts<'tcx> {
let ty = self.closure_sig_ty(def_id, tcx);
match ty.sty {
ty::FnPtr(sig) => sig,
_ => bug!("closure_sig_ty is not a fn-ptr: {:?}", ty),
_ => bug!("closure_sig_ty is not a fn-ptr: {:?}", ty.sty),
}
}
}
Expand Down
56 changes: 16 additions & 40 deletions src/librustc_data_structures/tiny_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub struct TinyList<T: PartialEq> {
}

impl<T: PartialEq> TinyList<T> {

#[inline]
pub fn new() -> TinyList<T> {
TinyList {
Expand Down Expand Up @@ -60,20 +59,24 @@ impl<T: PartialEq> TinyList<T> {

#[inline]
pub fn contains(&self, data: &T) -> bool {
if let Some(ref head) = self.head {
head.contains(data)
} else {
false
let mut elem = self.head.as_ref();
while let Some(ref e) = elem {
if &e.data == data {
return true;
}
elem = e.next.as_ref().map(|e| &**e);
}
false
}

#[inline]
pub fn len(&self) -> usize {
if let Some(ref head) = self.head {
head.len()
} else {
0
let (mut elem, mut count) = (self.head.as_ref(), 0);
while let Some(ref e) = elem {
count += 1;
elem = e.next.as_ref().map(|e| &**e);
}
count
}
}

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

impl<T: PartialEq> Element<T> {

fn remove_next(&mut self, data: &T) -> bool {
let new_next = if let Some(ref mut next) = self.next {
if next.data != *data {
return next.remove_next(data)
} else {
next.next.take()
}
} else {
return false
let new_next = match self.next {
Some(ref mut next) if next.data == *data => next.next.take(),
Some(ref mut next) => return next.remove_next(data),
None => return false,
};

self.next = new_next;

true
}

fn len(&self) -> usize {
if let Some(ref next) = self.next {
1 + next.len()
} else {
1
}
}

fn contains(&self, data: &T) -> bool {
if self.data == *data {
return true
}

if let Some(ref next) = self.next {
next.contains(data)
} else {
false
}
}
}
35 changes: 29 additions & 6 deletions src/librustc_data_structures/tiny_list/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;

extern crate test;
use test::Bencher;
use test::{Bencher, black_box};

#[test]
fn test_contains_and_insert() {
Expand Down Expand Up @@ -98,36 +98,59 @@ fn test_remove_single() {
#[bench]
fn bench_insert_empty(b: &mut Bencher) {
b.iter(|| {
let mut list = TinyList::new();
let mut list = black_box(TinyList::new());
list.insert(1);
list
})
}

#[bench]
fn bench_insert_one(b: &mut Bencher) {
b.iter(|| {
let mut list = TinyList::new_single(0);
let mut list = black_box(TinyList::new_single(0));
list.insert(1);
list
})
}

#[bench]
fn bench_contains_empty(b: &mut Bencher) {
b.iter(|| {
black_box(TinyList::new()).contains(&1)
});
}

#[bench]
fn bench_contains_unknown(b: &mut Bencher) {
b.iter(|| {
black_box(TinyList::new_single(0)).contains(&1)
});
}

#[bench]
fn bench_contains_one(b: &mut Bencher) {
b.iter(|| {
black_box(TinyList::new_single(1)).contains(&1)
});
}

#[bench]
fn bench_remove_empty(b: &mut Bencher) {
b.iter(|| {
TinyList::new().remove(&1)
black_box(TinyList::new()).remove(&1)
});
}

#[bench]
fn bench_remove_unknown(b: &mut Bencher) {
b.iter(|| {
TinyList::new_single(0).remove(&1)
black_box(TinyList::new_single(0)).remove(&1)
});
}

#[bench]
fn bench_remove_one(b: &mut Bencher) {
b.iter(|| {
TinyList::new_single(1).remove(&1)
black_box(TinyList::new_single(1)).remove(&1)
});
}
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
}
}

fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant, _: &hir::Generics) {
fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant) {
self.check_missing_docs_attrs(cx,
Some(v.id),
&v.attrs,
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_lint/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl EarlyLintPass for NonCamelCaseTypes {
}
}

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

Expand Down Expand Up @@ -350,9 +350,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
&mut self,
cx: &LateContext<'_, '_>,
s: &hir::VariantData,
_: ast::Name,
_: &hir::Generics,
_: hir::HirId,
) {
for sf in s.fields() {
self.check_snake_case(cx, "structure field", &sf.ident);
Expand Down
Loading