use matches::matches;
-use rustc::declare_lint_pass;
-use rustc::hir::def::{DefKind, Res};
-use rustc::hir::intravisit::*;
-use rustc::hir::*;
-use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
+use rustc::hir::map::Map;
+use rustc::lint::in_external_macro;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
-use rustc_session::declare_tool_lint;
-use syntax::source_map::Span;
-use syntax::symbol::kw;
-
-use crate::reexport::*;
+use rustc_hir::def::{DefKind, Res};
+use rustc_hir::intravisit::{
+ walk_fn_decl, walk_generic_param, walk_generics, walk_param_bound, walk_ty, NestedVisitorMap, Visitor,
+};
+use rustc_hir::FnRetTy::Return;
+use rustc_hir::{
+ BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, ImplItemKind, Item,
+ ItemKind, Lifetime, LifetimeName, ParamName, QPath, TraitBoundModifier, TraitItem, TraitItemKind, TraitMethod, Ty,
+ TyKind, WhereClause, WherePredicate,
+};
+use rustc_lint::{LateContext, LateLintPass, LintContext};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::source_map::Span;
+use rustc_span::symbol::kw;
+
+use crate::reexport::Name;
use crate::utils::{last_path_segment, span_lint, trait_ref_of_method};
declare_clippy_lint! {
}
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem<'_>) {
- if let TraitItemKind::Method(ref sig, ref body) = item.kind {
+ if let TraitItemKind::Fn(ref sig, ref body) = item.kind {
let body = match *body {
TraitMethod::Required(_) => None,
TraitMethod::Provided(id) => Some(id),
fn check_fn_inner<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
- decl: &'tcx FnDecl,
+ decl: &'tcx FnDecl<'_>,
body: Option<BodyId>,
- generics: &'tcx Generics,
+ generics: &'tcx Generics<'_>,
span: Span,
report_extra_lifetimes: bool,
) {
_ => false,
});
for typ in types {
- for bound in &typ.bounds {
+ for bound in typ.bounds {
let mut visitor = RefVisitor::new(cx);
walk_param_bound(&mut visitor, bound);
if visitor.lts.iter().any(|lt| matches!(lt, RefLt::Named(_))) {
fn could_use_elision<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
- func: &'tcx FnDecl,
+ func: &'tcx FnDecl<'_>,
body: Option<BodyId>,
- named_generics: &'tcx [GenericParam],
+ named_generics: &'tcx [GenericParam<'_>],
bounds_lts: Vec<&'tcx Lifetime>,
) -> bool {
// There are two scenarios where elision works:
let mut output_visitor = RefVisitor::new(cx);
// extract lifetimes in input argument types
- for arg in &func.inputs {
+ for arg in func.inputs {
input_visitor.visit_ty(arg);
}
// extract lifetimes in output type
}
}
-fn allowed_lts_from(named_generics: &[GenericParam]) -> FxHashSet<RefLt> {
+fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxHashSet<RefLt> {
let mut allowed_lts = FxHashSet::default();
for par in named_generics.iter() {
if let GenericParamKind::Lifetime { .. } = par.kind {
}
}
- fn collect_anonymous_lifetimes(&mut self, qpath: &QPath, ty: &Ty) {
+ fn collect_anonymous_lifetimes(&mut self, qpath: &QPath<'_>, ty: &Ty<'_>) {
if let Some(ref last_path_segment) = last_path_segment(qpath).args {
if !last_path_segment.parenthesized
&& !last_path_segment.args.iter().any(|arg| match arg {
}
impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
+ type Map = Map<'tcx>;
+
// for lifetimes as parameters of generics
fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) {
self.record(&Some(*lifetime));
}
- fn visit_ty(&mut self, ty: &'tcx Ty) {
+ fn visit_ty(&mut self, ty: &'tcx Ty<'_>) {
match ty.kind {
TyKind::Rptr(ref lt, _) if lt.is_elided() => {
self.record(&None);
TyKind::Def(item, _) => {
let map = self.cx.tcx.hir();
if let ItemKind::OpaqueTy(ref exist_ty) = map.expect_item(item.id).kind {
- for bound in &exist_ty.bounds {
+ for bound in exist_ty.bounds {
if let GenericBound::Outlives(_) = *bound {
self.record(&None);
}
}
walk_ty(self, ty);
},
- TyKind::TraitObject(ref bounds, ref lt) => {
+ TyKind::TraitObject(bounds, ref lt) => {
if !lt.is_elided() {
self.abort = true;
}
}
walk_ty(self, ty);
}
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
NestedVisitorMap::None
}
}
/// Are any lifetimes mentioned in the `where` clause? If so, we don't try to
/// reason about elision.
-fn has_where_lifetimes<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, where_clause: &'tcx WhereClause) -> bool {
- for predicate in &where_clause.predicates {
+fn has_where_lifetimes<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, where_clause: &'tcx WhereClause<'_>) -> bool {
+ for predicate in where_clause.predicates {
match *predicate {
WherePredicate::RegionPredicate(..) => return true,
WherePredicate::BoundPredicate(ref pred) => {
}
impl<'tcx> Visitor<'tcx> for LifetimeChecker {
+ type Map = Map<'tcx>;
+
// for lifetimes as parameters of generics
fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) {
self.map.remove(&lifetime.name.ident().name);
}
- fn visit_generic_param(&mut self, param: &'tcx GenericParam) {
+ fn visit_generic_param(&mut self, param: &'tcx GenericParam<'_>) {
// don't actually visit `<'a>` or `<'a: 'b>`
// we've already visited the `'a` declarations and
// don't want to spuriously remove them
walk_generic_param(self, param)
}
}
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
NestedVisitorMap::None
}
}
-fn report_extra_lifetimes<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, func: &'tcx FnDecl, generics: &'tcx Generics) {
+fn report_extra_lifetimes<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, func: &'tcx FnDecl<'_>, generics: &'tcx Generics<'_>) {
let hs = generics
.params
.iter()
}
impl<'tcx> Visitor<'tcx> for BodyLifetimeChecker {
+ type Map = Map<'tcx>;
+
// for lifetimes as parameters of generics
fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) {
if lifetime.name.ident().name != kw::Invalid && lifetime.name.ident().name != kw::StaticLifetime {
}
}
- fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
NestedVisitorMap::None
}
}