X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=clippy_lints%2Fsrc%2Futils%2Fptr.rs;h=be7bd0d21f69cb4b8ab12ad90b4a4a6497e42016;hb=2c282252a93effa847517a4ced1b24036372dd46;hp=a28e1c7fe9d86ee63e37eb0dfcbeca20fbdc62d9;hpb=f166b7d2f4fb184e757c52973054ec07a7b8be60;p=rust.git diff --git a/clippy_lints/src/utils/ptr.rs b/clippy_lints/src/utils/ptr.rs index a28e1c7fe9d..be7bd0d21f6 100644 --- a/clippy_lints/src/utils/ptr.rs +++ b/clippy_lints/src/utils/ptr.rs @@ -1,29 +1,31 @@ -use std::borrow::Cow; -use crate::rustc::hir::*; -use crate::rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use crate::rustc::lint::LateContext; -use crate::syntax::ast::Name; -use crate::syntax::source_map::Span; use crate::utils::{get_pat_name, match_var, snippet}; +use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; +use rustc::hir::*; +use rustc::lint::LateContext; +use std::borrow::Cow; +use syntax::ast::Name; +use syntax::source_map::Span; pub fn get_spans( cx: &LateContext<'_, '_>, opt_body_id: Option, idx: usize, - replacements: &'static [(&'static str, &'static str)], + replacements: &[(&'static str, &'static str)], ) -> Option)>> { - if let Some(body) = opt_body_id.map(|id| cx.tcx.hir.body(id)) { - get_binding_name(&body.arguments[idx]) - .map_or_else(|| Some(vec![]), |name| extract_clone_suggestions(cx, name, replacements, body)) + if let Some(body) = opt_body_id.map(|id| cx.tcx.hir().body(id)) { + get_binding_name(&body.params[idx]).map_or_else( + || Some(vec![]), + |name| extract_clone_suggestions(cx, name, replacements, body), + ) } else { Some(vec![]) } } -fn extract_clone_suggestions<'a, 'tcx: 'a>( +fn extract_clone_suggestions<'a, 'tcx>( cx: &LateContext<'a, 'tcx>, name: Name, - replace: &'static [(&'static str, &'static str)], + replace: &[(&'static str, &'static str)], body: &'tcx Body, ) -> Option)>> { let mut visitor = PtrCloneVisitor { @@ -41,27 +43,27 @@ fn extract_clone_suggestions<'a, 'tcx: 'a>( } } -struct PtrCloneVisitor<'a, 'tcx: 'a> { +struct PtrCloneVisitor<'a, 'tcx> { cx: &'a LateContext<'a, 'tcx>, name: Name, - replace: &'static [(&'static str, &'static str)], + replace: &'a [(&'static str, &'static str)], spans: Vec<(Span, Cow<'static, str>)>, abort: bool, } -impl<'a, 'tcx: 'a> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> { +impl<'a, 'tcx> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx Expr) { if self.abort { return; } if let ExprKind::MethodCall(ref seg, _, ref args) = expr.node { if args.len() == 1 && match_var(&args[0], self.name) { - if seg.ident.name == "capacity" { + if seg.ident.name.as_str() == "capacity" { self.abort = true; return; } for &(fn_name, suffix) in self.replace { - if seg.ident.name == fn_name { + if seg.ident.name.as_str() == fn_name { self.spans .push((expr.span, snippet(self.cx, args[0].span, "_") + suffix)); return; @@ -78,6 +80,6 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { } } -fn get_binding_name(arg: &Arg) -> Option { +fn get_binding_name(arg: &Param) -> Option { get_pat_name(&arg.pat) }