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`
"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
);
}
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())
}
}
}
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;
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())
}
}