Skip to content

Try to fix #1988 #1989

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 2 commits into from
Aug 25, 2017
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Change Log
All notable changes to this project will be documented in this file.

* New lint: [`naive_bytecount`]

## 0.0.154
* Update to *rustc 1.21.0-nightly (2c0558f63 2017-08-24)*
* Fix [`use_self`] triggering inside derives
* Add support for linting an entire workspace with `cargo clippy --all`
* New lint: [`naive_bytecount`]

## 0.0.153
* Update to *rustc 1.21.0-nightly (8c303ed87 2017-08-20)*
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.0.153"
version = "0.0.154"
authors = [
"Manish Goregaokar <[email protected]>",
"Andre Bogus <[email protected]>",
Expand Down Expand Up @@ -31,7 +31,7 @@ path = "src/main.rs"

[dependencies]
# begin automatic update
clippy_lints = { version = "0.0.153", path = "clippy_lints" }
clippy_lints = { version = "0.0.154", path = "clippy_lints" }
# end automatic update
cargo_metadata = "0.2"

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "clippy_lints"
# begin automatic update
version = "0.0.153"
version = "0.0.154"
# end automatic update
authors = [
"Manish Goregaokar <[email protected]>",
Expand Down
40 changes: 19 additions & 21 deletions clippy_lints/src/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ fn check_fn_inner<'a, 'tcx>(
for typ in &generics.ty_params {
for bound in &typ.bounds {
if let TraitTyParamBound(ref trait_ref, _) = *bound {
let bounds = trait_ref
let bounds = &trait_ref
.trait_ref
.path
.segments
.last()
.expect("a path must have at least one segment")
.parameters
.lifetimes();
.lifetimes;
for bound in bounds {
if bound.name != "'static" && !bound.is_elided() {
return;
Expand Down Expand Up @@ -282,25 +282,23 @@ impl<'v, 't> RefVisitor<'v, 't> {

fn collect_anonymous_lifetimes(&mut self, qpath: &QPath, ty: &Ty) {
let last_path_segment = &last_path_segment(qpath).parameters;
if let AngleBracketedParameters(ref params) = *last_path_segment {
if params.lifetimes.is_empty() {
let hir_id = self.cx.tcx.hir.node_to_hir_id(ty.id);
match self.cx.tables.qpath_def(qpath, hir_id) {
Def::TyAlias(def_id) |
Def::Struct(def_id) => {
let generics = self.cx.tcx.generics_of(def_id);
for _ in generics.regions.as_slice() {
self.record(&None);
}
},
Def::Trait(def_id) => {
let trait_def = self.cx.tcx.trait_def(def_id);
for _ in &self.cx.tcx.generics_of(trait_def.def_id).regions {
self.record(&None);
}
},
_ => (),
}
if !last_path_segment.parenthesized && last_path_segment.lifetimes.is_empty() {
let hir_id = self.cx.tcx.hir.node_to_hir_id(ty.id);
match self.cx.tables.qpath_def(qpath, hir_id) {
Def::TyAlias(def_id) |
Def::Struct(def_id) => {
let generics = self.cx.tcx.generics_of(def_id);
for _ in generics.regions.as_slice() {
self.record(&None);
}
},
Def::Trait(def_id) => {
let trait_def = self.cx.tcx.trait_def(def_id);
for _ in &self.cx.tcx.generics_of(trait_def.def_id).regions {
self.record(&None);
}
},
_ => (),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,11 +1464,11 @@ fn is_as_ref_or_mut_trait(ty: &hir::Ty, self_ty: &hir::Ty, generics: &hir::Gener
let path = &ptr.trait_ref.path;
match_path_old(path, name) &&
path.segments.last().map_or(false, |s| {
if let hir::PathParameters::AngleBracketedParameters(ref data) = s.parameters {
data.types.len() == 1 &&
(is_self_ty(&data.types[0]) || is_ty(&*data.types[0], self_ty))
} else {
if s.parameters.parenthesized {
false
} else {
s.parameters.types.len() == 1 &&
(is_self_ty(&s.parameters.types[0]) || is_ty(&*s.parameters.types[0], self_ty))
}
})
} else {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/needless_pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
let TyPath(QPath::Resolved(_, ref path)) = input.node,
let Some(elem_ty) = path.segments.iter()
.find(|seg| seg.name == "Vec")
.map(|ps| ps.parameters.types()[0]),
.map(|ps| &ps.parameters.types[0]),
], {
let slice_ty = format!("&[{}]", snippet(cx, elem_ty.span, "_"));
db.span_suggestion(input.span,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/transmute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
fn get_type_snippet(cx: &LateContext, path: &QPath, to_rty: Ty) -> String {
let seg = last_path_segment(path);
if_let_chain!{[
let PathParameters::AngleBracketedParameters(ref ang) = seg.parameters,
let Some(to_ty) = ang.types.get(1),
!seg.parameters.parenthesized,
let Some(to_ty) = seg.parameters.types.get(1),
let TyRptr(_, ref to_ty) = to_ty.node,
], {
return snippet(cx, to_ty.ty.span, &to_rty.to_string()).to_string();
Expand Down
14 changes: 7 additions & 7 deletions clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool) {
if Some(def_id) == cx.tcx.lang_items.owned_box() {
let last = last_path_segment(qpath);
if_let_chain! {[
let PathParameters::AngleBracketedParameters(ref ag) = last.parameters,
let Some(vec) = ag.types.get(0),
!last.parameters.parenthesized,
let Some(vec) = last.parameters.types.get(0),
let TyPath(ref qpath) = vec.node,
let Some(did) = opt_def_id(cx.tables.qpath_def(qpath, cx.tcx.hir.node_to_hir_id(vec.id))),
match_def_path(cx.tcx, did, &paths::VEC),
Expand All @@ -182,18 +182,18 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool) {
match *qpath {
QPath::Resolved(Some(ref ty), ref p) => {
check_ty(cx, ty, is_local);
for ty in p.segments.iter().flat_map(|seg| seg.parameters.types()) {
for ty in p.segments.iter().flat_map(|seg| seg.parameters.types.iter()) {
check_ty(cx, ty, is_local);
}
},
QPath::Resolved(None, ref p) => {
for ty in p.segments.iter().flat_map(|seg| seg.parameters.types()) {
for ty in p.segments.iter().flat_map(|seg| seg.parameters.types.iter()) {
check_ty(cx, ty, is_local);
}
},
QPath::TypeRelative(ref ty, ref seg) => {
check_ty(cx, ty, is_local);
for ty in seg.parameters.types() {
for ty in seg.parameters.types.iter() {
check_ty(cx, ty, is_local);
}
},
Expand All @@ -209,8 +209,8 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool) {
Some(def_id) == cx.tcx.lang_items.owned_box(),
let QPath::Resolved(None, ref path) = *qpath,
let [ref bx] = *path.segments,
let PathParameters::AngleBracketedParameters(ref ab_data) = bx.parameters,
let [ref inner] = *ab_data.types
!bx.parameters.parenthesized,
let [ref inner] = *bx.parameters.types
], {
if is_any_trait(inner) {
// Ignore `Box<Any>` types, see #1884 for details.
Expand Down
18 changes: 9 additions & 9 deletions clippy_lints/src/use_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
if_let_chain!([
let ItemImpl(.., ref item_type, ref refs) = item.node,
let Ty_::TyPath(QPath::Resolved(_, ref item_path)) = item_type.node,
let PathParameters::AngleBracketedParameters(ref param_data)
= item_path.segments.last().expect(SEGMENTS_MSG).parameters,
param_data.lifetimes.len() == 0,
], {
let visitor = &mut UseSelfVisitor {
item_path: item_path,
cx: cx,
};
for impl_item_ref in refs {
visitor.visit_impl_item(cx.tcx.hir.impl_item(impl_item_ref.id));
let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).parameters;
if !parameters.parenthesized && parameters.lifetimes.len() == 0 {
let visitor = &mut UseSelfVisitor {
item_path: item_path,
cx: cx,
};
for impl_item_ref in refs {
visitor.visit_impl_item(cx.tcx.hir.impl_item(impl_item_ref.id));
}
}
})
}
Expand Down
15 changes: 6 additions & 9 deletions clippy_lints/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,15 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
}

fn eq_path_parameters(&self, left: &PathParameters, right: &PathParameters) -> bool {
match (left, right) {
(&AngleBracketedParameters(ref left), &AngleBracketedParameters(ref right)) => {
if !(left.parenthesized || right.parenthesized) {
over(&left.lifetimes, &right.lifetimes, |l, r| self.eq_lifetime(l, r)) &&
over(&left.types, &right.types, |l, r| self.eq_ty(l, r)) &&
over(&left.bindings, &right.bindings, |l, r| self.eq_type_binding(l, r))
},
(&ParenthesizedParameters(ref left), &ParenthesizedParameters(ref right)) => {
over(&left.inputs, &right.inputs, |l, r| self.eq_ty(l, r)) &&
both(&left.output, &right.output, |l, r| self.eq_ty(l, r))
},
(&AngleBracketedParameters(_), &ParenthesizedParameters(_)) |
(&ParenthesizedParameters(_), &AngleBracketedParameters(_)) => false,
} else if left.parenthesized && right.parenthesized {
over(left.inputs(), right.inputs(), |l, r| self.eq_ty(l, r)) &&
both(&Some(&left.bindings[0].ty), &Some(&right.bindings[0].ty), |l, r| self.eq_ty(l, r))
} else {
false
}
}

Expand Down