mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 00:47:16 +00:00
fix PathParameters usage
This commit is contained in:
parent
ab362031ed
commit
70c8fe5539
7 changed files with 48 additions and 53 deletions
|
@ -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;
|
||||
|
@ -282,8 +282,7 @@ 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() {
|
||||
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) |
|
||||
|
@ -303,7 +302,6 @@ impl<'v, 't> RefVisitor<'v, 't> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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),
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
@ -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.
|
||||
|
|
|
@ -56,10 +56,9 @@ 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 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,
|
||||
|
@ -67,6 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
|
|||
for impl_item_ref in refs {
|
||||
visitor.visit_impl_item(cx.tcx.hir.impl_item(impl_item_ref.id));
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue