]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/methods/option_map_unwrap_or.rs
rustup https://github.com/rust-lang/rust/pull/68944
[rust.git] / clippy_lints / src / methods / option_map_unwrap_or.rs
index f4aaf959be189207d6be66fd98fd0d1afa6e0ccb..c40ab7beba442e4bbf13dff49fbfb0b8d8e9719d 100644 (file)
@@ -1,21 +1,22 @@
 use crate::utils::{differing_macro_contexts, paths, snippet_with_applicability, span_lint_and_then};
 use crate::utils::{is_copy, match_type};
-use rustc::hir::intravisit::{walk_path, NestedVisitorMap, Visitor};
-use rustc::hir::{self, *};
-use rustc::lint::LateContext;
+use rustc::hir::map::Map;
 use rustc_data_structures::fx::FxHashSet;
 use rustc_errors::Applicability;
-use syntax::source_map::Span;
-use syntax_pos::symbol::Symbol;
+use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor};
+use rustc_hir::{self, HirId, Path};
+use rustc_lint::LateContext;
+use rustc_span::source_map::Span;
+use rustc_span::symbol::Symbol;
 
 use super::OPTION_MAP_UNWRAP_OR;
 
 /// lint use of `map().unwrap_or()` for `Option`s
 pub(super) fn lint<'a, 'tcx>(
     cx: &LateContext<'a, 'tcx>,
-    expr: &hir::Expr<'_>,
-    map_args: &'tcx [hir::Expr<'_>],
-    unwrap_args: &'tcx [hir::Expr<'_>],
+    expr: &rustc_hir::Expr<'_>,
+    map_args: &'tcx [rustc_hir::Expr<'_>],
+    unwrap_args: &'tcx [rustc_hir::Expr<'_>],
     map_span: Span,
 ) {
     // lint if the caller of `map()` is an `Option`
@@ -60,7 +61,7 @@ pub(super) fn lint<'a, 'tcx>(
             "map_or(a, f)"
         };
         let msg = &format!(
-            "called `map(f).unwrap_or({})` on an Option value. \
+            "called `map(f).unwrap_or({})` on an `Option` value. \
              This can be done more directly by calling `{}` instead",
             arg, suggest
         );
@@ -91,13 +92,15 @@ struct UnwrapVisitor<'a, 'tcx> {
 }
 
 impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> {
+    type Map = Map<'tcx>;
+
     fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
         self.identifiers.insert(ident(path));
         walk_path(self, path);
     }
 
-    fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir())
+    fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
+        NestedVisitorMap::All(self.cx.tcx.hir())
     }
 }
 
@@ -108,6 +111,8 @@ struct MapExprVisitor<'a, 'tcx> {
 }
 
 impl<'a, 'tcx> Visitor<'tcx> for MapExprVisitor<'a, 'tcx> {
+    type Map = Map<'tcx>;
+
     fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
         if self.identifiers.contains(&ident(path)) {
             self.found_identifier = true;
@@ -116,8 +121,8 @@ fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
         walk_path(self, path);
     }
 
-    fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir())
+    fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
+        NestedVisitorMap::All(self.cx.tcx.hir())
     }
 }