From fabb6b6645ec9f804b17707fb1e69ff09c15cbed Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 25 Sep 2017 19:04:55 -0700 Subject: [PATCH] Rustup to rustc 1.22.0-nightly (6c476ce46 2017-09-25) --- clippy_lints/src/lifetimes.rs | 50 +++++++++++----------- clippy_lints/src/map_clone.rs | 3 +- clippy_lints/src/methods.rs | 17 +++++--- clippy_lints/src/needless_pass_by_value.rs | 3 +- clippy_lints/src/ptr.rs | 2 +- clippy_lints/src/transmute.rs | 5 ++- clippy_lints/src/types.rs | 22 ++++++---- clippy_lints/src/use_self.rs | 2 +- clippy_lints/src/utils/hir_utils.rs | 9 +++- 9 files changed, 69 insertions(+), 44 deletions(-) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index 5cbb854be923..16d636c68ab6 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -104,19 +104,20 @@ 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 params = &trait_ref .trait_ref .path .segments .last() .expect("a path must have at least one segment") - .parameters - .lifetimes; - for bound in bounds { - if bound.name.name() != "'static" && !bound.is_elided() { - return; + .parameters; + if let Some(ref params) = *params { + for bound in ¶ms.lifetimes { + if bound.name.name() != "'static" && !bound.is_elided() { + return; + } + bounds_lts.push(bound); } - bounds_lts.push(bound); } } } @@ -287,23 +288,24 @@ 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 !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); - } - }, - _ => (), + if let Some(ref last_path_segment) = last_path_segment(qpath).parameters { + 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); + } + }, + _ => (), + } } } } diff --git a/clippy_lints/src/map_clone.rs b/clippy_lints/src/map_clone.rs index 733022f1703f..e35e1ab477c0 100644 --- a/clippy_lints/src/map_clone.rs +++ b/clippy_lints/src/map_clone.rs @@ -100,7 +100,8 @@ fn expr_eq_name(expr: &Expr, id: ast::Name) -> bool { let arg_segment = [ PathSegment { name: id, - parameters: PathParameters::none(), + parameters: None, + infer_types: true, }, ]; !path.is_global() && path.segments[..] == arg_segment diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index b36e1851d0de..6d3a3f39d1a2 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -1617,11 +1617,18 @@ fn is_as_ref_or_mut_trait(ty: &hir::Ty, self_ty: &hir::Ty, generics: &hir::Gener match_path(path, name) && path.segments .last() - .map_or(false, |s| 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)) + .map_or(false, |s| { + if let Some(ref params) = s.parameters { + if params.parenthesized { + false + } else { + params.types.len() == 1 && + (is_self_ty(¶ms.types[0]) + || is_ty(&*params.types[0], self_ty)) + } + } else { + false + } }) } else { false diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 4a7a042924a2..35cbd6ff3dbf 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -144,7 +144,8 @@ 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]), + .and_then(|ref ps| ps.parameters.as_ref()) + .map(|params| ¶ms.types[0]), ], { let slice_ty = format!("&[{}]", snippet(cx, elem_ty.span, "_")); db.span_suggestion(input.span, diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 69ba0d8bccf4..03c94cbf3fbd 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -159,7 +159,7 @@ fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option< let mut ty_snippet = None; if_let_chain!([ let TyPath(QPath::Resolved(_, ref path)) = walk_ptrs_hir_ty(arg).node, - let Some(&PathSegment{ref parameters, ..}) = path.segments.last(), + let Some(&PathSegment{parameters: Some(ref parameters), ..}) = path.segments.last(), parameters.types.len() == 1, ], { ty_snippet = snippet_opt(cx, parameters.types[0].span); diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index 18b80c76810c..76110ecb152b 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -194,8 +194,9 @@ 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!{[ - !seg.parameters.parenthesized, - let Some(to_ty) = seg.parameters.types.get(1), + let Some(ref params) = seg.parameters, + !params.parenthesized, + let Some(to_ty) = params.types.get(1), let TyRptr(_, ref to_ty) = to_ty.node, ], { return snippet(cx, to_ty.ty.span, &to_rty.to_string()).to_string(); diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 90f1e87796d3..50683d1fb402 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -154,8 +154,9 @@ 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! {[ - !last.parameters.parenthesized, - let Some(vec) = last.parameters.types.get(0), + let Some(ref params) = last.parameters, + !params.parenthesized, + let Some(vec) = params.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), @@ -183,21 +184,25 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool) { check_ty(cx, ty, is_local); for ty in p.segments .iter() - .flat_map(|seg| seg.parameters.types.iter()) + .filter_map(|ref seg| seg.parameters.as_ref()) + .flat_map(|ref params| params.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.iter()) + .filter_map(|ref seg| seg.parameters.as_ref()) + .flat_map(|ref params| params.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.iter() { - check_ty(cx, ty, is_local); + if let Some(ref params) = seg.parameters { + for ty in params.types.iter() { + check_ty(cx, ty, is_local); + } } }, } @@ -212,8 +217,9 @@ 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, - !bx.parameters.parenthesized, - let [ref inner] = *bx.parameters.types + let Some(ref params) = bx.parameters, + !params.parenthesized, + let [ref inner] = *params.types ], { if is_any_trait(inner) { // Ignore `Box` types, see #1884 for details. diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index bb5f6075d0da..d4166f6a2bda 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -59,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf { let Ty_::TyPath(QPath::Resolved(_, ref item_path)) = item_type.node, ], { let parameters = &item_path.segments.last().expect(SEGMENTS_MSG).parameters; - if !parameters.parenthesized && parameters.lifetimes.len() == 0 { + if parameters.is_none() { let visitor = &mut UseSelfVisitor { item_path: item_path, cx: cx, diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 2d3d5874d821..f7867dfd0bd4 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -214,7 +214,14 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> { fn eq_path_segment(&self, left: &PathSegment, right: &PathSegment) -> bool { // The == of idents doesn't work with different contexts, // we have to be explicit about hygiene - left.name.as_str() == right.name.as_str() && self.eq_path_parameters(&left.parameters, &right.parameters) + if left.name.as_str() != right.name.as_str() { + return false; + } + match (&left.parameters, &right.parameters) { + (&None, &None) => true, + (&Some(ref l), &Some(ref r)) => self.eq_path_parameters(l, r), + _ => false + } } fn eq_ty(&self, left: &Ty, right: &Ty) -> bool {