mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-20 03:32:52 +00:00
Auto merge of #4972 - JohnTitor:rustup, r=llogiq
Rustup to rust-lang/rust#66942 changelog: none
This commit is contained in:
commit
5b255883f5
@ -60,7 +60,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
_: intravisit::FnKind<'tcx>,
|
||||
_: &'tcx FnDecl,
|
||||
_: &'tcx FnDecl<'_>,
|
||||
body: &'tcx Body<'_>,
|
||||
_: Span,
|
||||
_: HirId,
|
||||
|
@ -287,7 +287,7 @@ fn get_types_from_cast<'a>(expr: &'a Expr<'_>, func: &'a str, types: &'a [&str])
|
||||
}
|
||||
|
||||
/// Gets the type which implements the called function
|
||||
fn get_implementing_type<'a>(path: &QPath, candidates: &'a [&str], function: &str) -> Option<&'a str> {
|
||||
fn get_implementing_type<'a>(path: &QPath<'_>, candidates: &'a [&str], function: &str) -> Option<&'a str> {
|
||||
if_chain! {
|
||||
if let QPath::TypeRelative(ref ty, ref path) = &path;
|
||||
if path.ident.name.as_str() == function;
|
||||
@ -304,7 +304,7 @@ fn get_implementing_type<'a>(path: &QPath, candidates: &'a [&str], function: &st
|
||||
}
|
||||
|
||||
/// Gets the type as a string, if it is a supported integer
|
||||
fn int_ty_to_sym(path: &QPath) -> Option<&str> {
|
||||
fn int_ty_to_sym<'tcx>(path: &QPath<'_>) -> Option<&'tcx str> {
|
||||
if_chain! {
|
||||
if let QPath::Resolved(_, ref path) = *path;
|
||||
if let [ty] = &*path.segments;
|
||||
|
@ -47,7 +47,7 @@ impl CognitiveComplexity {
|
||||
&mut self,
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
kind: FnKind<'tcx>,
|
||||
decl: &'tcx FnDecl,
|
||||
decl: &'tcx FnDecl<'_>,
|
||||
body: &'tcx Body<'_>,
|
||||
body_span: Span,
|
||||
) {
|
||||
@ -116,7 +116,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity {
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
kind: FnKind<'tcx>,
|
||||
decl: &'tcx FnDecl,
|
||||
decl: &'tcx FnDecl<'_>,
|
||||
body: &'tcx Body<'_>,
|
||||
span: Span,
|
||||
hir_id: HirId,
|
||||
|
@ -320,7 +320,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
||||
}
|
||||
|
||||
/// Lookup a possibly constant expression from a `ExprKind::Path`.
|
||||
fn fetch_path(&mut self, qpath: &QPath, id: HirId) -> Option<Constant> {
|
||||
fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId) -> Option<Constant> {
|
||||
let res = self.tables.qpath_res(qpath, id);
|
||||
match res {
|
||||
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
|
||||
|
@ -84,7 +84,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
|
||||
fn check_hash_peq<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
span: Span,
|
||||
trait_ref: &TraitRef,
|
||||
trait_ref: &TraitRef<'_>,
|
||||
ty: Ty<'tcx>,
|
||||
hash_is_automatically_derived: bool,
|
||||
) {
|
||||
@ -130,7 +130,7 @@ fn check_hash_peq<'a, 'tcx>(
|
||||
}
|
||||
|
||||
/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint.
|
||||
fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item<'_>, trait_ref: &TraitRef, ty: Ty<'tcx>) {
|
||||
fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item<'_>, trait_ref: &TraitRef<'_>, ty: Ty<'tcx>) {
|
||||
if match_path(&trait_ref.path, &paths::CLONE_TRAIT) {
|
||||
if !is_copy(cx, ty) {
|
||||
return;
|
||||
|
@ -190,7 +190,7 @@ fn lint_for_missing_headers<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
hir_id: hir::HirId,
|
||||
span: impl Into<MultiSpan> + Copy,
|
||||
sig: &hir::FnSig,
|
||||
sig: &hir::FnSig<'_>,
|
||||
headers: DocHeaders,
|
||||
) {
|
||||
if !cx.access_levels.is_exported(hir_id) {
|
||||
|
@ -39,21 +39,21 @@ const DROP_BOUNDS_SUMMARY: &str = "Bounds of the form `T: Drop` are useless. \
|
||||
declare_lint_pass!(DropBounds => [DROP_BOUNDS]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropBounds {
|
||||
fn check_generic_param(&mut self, cx: &rustc::lint::LateContext<'a, 'tcx>, p: &'tcx GenericParam) {
|
||||
for bound in &p.bounds {
|
||||
fn check_generic_param(&mut self, cx: &rustc::lint::LateContext<'a, 'tcx>, p: &'tcx GenericParam<'_>) {
|
||||
for bound in p.bounds.iter() {
|
||||
lint_bound(cx, bound);
|
||||
}
|
||||
}
|
||||
fn check_where_predicate(&mut self, cx: &rustc::lint::LateContext<'a, 'tcx>, p: &'tcx WherePredicate) {
|
||||
fn check_where_predicate(&mut self, cx: &rustc::lint::LateContext<'a, 'tcx>, p: &'tcx WherePredicate<'_>) {
|
||||
if let WherePredicate::BoundPredicate(WhereBoundPredicate { bounds, .. }) = p {
|
||||
for bound in bounds {
|
||||
for bound in *bounds {
|
||||
lint_bound(cx, bound);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lint_bound<'a, 'tcx>(cx: &rustc::lint::LateContext<'a, 'tcx>, bound: &'tcx GenericBound) {
|
||||
fn lint_bound<'a, 'tcx>(cx: &rustc::lint::LateContext<'a, 'tcx>, bound: &'tcx GenericBound<'_>) {
|
||||
if_chain! {
|
||||
if let GenericBound::Trait(t, _) = bound;
|
||||
if let Some(def_id) = t.trait_ref.path.res.opt_def_id();
|
||||
|
@ -55,7 +55,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
_: visit::FnKind<'tcx>,
|
||||
_: &'tcx FnDecl,
|
||||
_: &'tcx FnDecl<'_>,
|
||||
body: &'tcx Body<'_>,
|
||||
_: Span,
|
||||
hir_id: HirId,
|
||||
|
@ -46,7 +46,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom {
|
||||
}
|
||||
}
|
||||
|
||||
fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef]) {
|
||||
fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef<'_>]) {
|
||||
use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc::hir::*;
|
||||
|
||||
|
@ -187,7 +187,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
kind: intravisit::FnKind<'tcx>,
|
||||
decl: &'tcx hir::FnDecl,
|
||||
decl: &'tcx hir::FnDecl<'_>,
|
||||
body: &'tcx hir::Body<'_>,
|
||||
span: Span,
|
||||
hir_id: hir::HirId,
|
||||
@ -306,7 +306,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Functions {
|
||||
fn check_arg_number(self, cx: &LateContext<'_, '_>, decl: &hir::FnDecl, fn_span: Span) {
|
||||
fn check_arg_number(self, cx: &LateContext<'_, '_>, decl: &hir::FnDecl<'_>, fn_span: Span) {
|
||||
let args = decl.inputs.len() as u64;
|
||||
if args > self.threshold {
|
||||
span_lint(
|
||||
@ -375,7 +375,7 @@ impl<'a, 'tcx> Functions {
|
||||
fn check_raw_ptr(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
unsafety: hir::Unsafety,
|
||||
decl: &'tcx hir::FnDecl,
|
||||
decl: &'tcx hir::FnDecl<'_>,
|
||||
body: &'tcx hir::Body<'_>,
|
||||
hir_id: hir::HirId,
|
||||
) {
|
||||
@ -402,7 +402,7 @@ impl<'a, 'tcx> Functions {
|
||||
|
||||
fn check_needless_must_use(
|
||||
cx: &LateContext<'_, '_>,
|
||||
decl: &hir::FnDecl,
|
||||
decl: &hir::FnDecl<'_>,
|
||||
item_id: hir::HirId,
|
||||
item_span: Span,
|
||||
fn_header_span: Span,
|
||||
@ -439,7 +439,7 @@ fn check_needless_must_use(
|
||||
|
||||
fn check_must_use_candidate<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
decl: &'tcx hir::FnDecl,
|
||||
decl: &'tcx hir::FnDecl<'_>,
|
||||
body: &'tcx hir::Body<'_>,
|
||||
item_span: Span,
|
||||
item_id: hir::HirId,
|
||||
@ -467,7 +467,7 @@ fn check_must_use_candidate<'a, 'tcx>(
|
||||
});
|
||||
}
|
||||
|
||||
fn returns_unit(decl: &hir::FnDecl) -> bool {
|
||||
fn returns_unit(decl: &hir::FnDecl<'_>) -> bool {
|
||||
match decl.output {
|
||||
hir::FunctionRetTy::DefaultReturn(_) => true,
|
||||
hir::FunctionRetTy::Return(ref ty) => match ty.kind {
|
||||
@ -518,7 +518,7 @@ fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span,
|
||||
}
|
||||
}
|
||||
|
||||
fn raw_ptr_arg(arg: &hir::Param<'_>, ty: &hir::Ty) -> Option<hir::HirId> {
|
||||
fn raw_ptr_arg(arg: &hir::Param<'_>, ty: &hir::Ty<'_>) -> Option<hir::HirId> {
|
||||
if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.kind, &ty.kind) {
|
||||
Some(id)
|
||||
} else {
|
||||
|
@ -129,7 +129,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitReturn {
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
_: FnKind<'tcx>,
|
||||
_: &'tcx FnDecl,
|
||||
_: &'tcx FnDecl<'_>,
|
||||
body: &'tcx Body<'_>,
|
||||
span: Span,
|
||||
_: HirId,
|
||||
|
@ -166,8 +166,8 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item<'_>, trait_i
|
||||
}
|
||||
}
|
||||
|
||||
fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item<'_>, impl_items: &[ImplItemRef]) {
|
||||
fn is_named_self(cx: &LateContext<'_, '_>, item: &ImplItemRef, name: &str) -> bool {
|
||||
fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item<'_>, impl_items: &[ImplItemRef<'_>]) {
|
||||
fn is_named_self(cx: &LateContext<'_, '_>, item: &ImplItemRef<'_>, name: &str) -> bool {
|
||||
item.ident.name.as_str() == name
|
||||
&& if let AssocItemKind::Method { has_self } = item.kind {
|
||||
has_self && {
|
||||
|
@ -112,9 +112,9 @@ enum RefLt {
|
||||
|
||||
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,
|
||||
) {
|
||||
@ -128,7 +128,7 @@ fn check_fn_inner<'a, 'tcx>(
|
||||
_ => 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(_))) {
|
||||
@ -173,9 +173,9 @@ fn check_fn_inner<'a, 'tcx>(
|
||||
|
||||
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:
|
||||
@ -192,7 +192,7 @@ fn could_use_elision<'a, 'tcx>(
|
||||
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
|
||||
@ -258,7 +258,7 @@ fn could_use_elision<'a, 'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -328,7 +328,7 @@ impl<'v, 't> RefVisitor<'v, 't> {
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -363,7 +363,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
||||
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);
|
||||
@ -374,7 +374,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
||||
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);
|
||||
}
|
||||
@ -384,7 +384,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
||||
}
|
||||
walk_ty(self, ty);
|
||||
},
|
||||
TyKind::TraitObject(ref bounds, ref lt) => {
|
||||
TyKind::TraitObject(bounds, ref lt) => {
|
||||
if !lt.is_elided() {
|
||||
self.abort = true;
|
||||
}
|
||||
@ -404,8 +404,8 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
||||
|
||||
/// 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) => {
|
||||
@ -457,7 +457,7 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker {
|
||||
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
|
||||
@ -472,7 +472,7 @@ impl<'tcx> Visitor<'tcx> for LifetimeChecker {
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -3109,8 +3109,8 @@ enum OutType {
|
||||
}
|
||||
|
||||
impl OutType {
|
||||
fn matches(self, cx: &LateContext<'_, '_>, ty: &hir::FunctionRetTy) -> bool {
|
||||
let is_unit = |ty: &hir::Ty| SpanlessEq::new(cx).eq_ty_kind(&ty.kind, &hir::TyKind::Tup(vec![].into()));
|
||||
fn matches(self, cx: &LateContext<'_, '_>, ty: &hir::FunctionRetTy<'_>) -> bool {
|
||||
let is_unit = |ty: &hir::Ty<'_>| SpanlessEq::new(cx).eq_ty_kind(&ty.kind, &hir::TyKind::Tup(&[]));
|
||||
match (self, ty) {
|
||||
(Self::Unit, &hir::DefaultReturn(_)) => true,
|
||||
(Self::Unit, &hir::Return(ref ty)) if is_unit(ty) => true,
|
||||
@ -3122,7 +3122,7 @@ impl OutType {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_bool(ty: &hir::Ty) -> bool {
|
||||
fn is_bool(ty: &hir::Ty<'_>) -> bool {
|
||||
if let hir::TyKind::Path(ref p) = ty.kind {
|
||||
match_qpath(p, &["bool"])
|
||||
} else {
|
||||
|
@ -83,7 +83,7 @@ struct UnwrapVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> {
|
||||
fn visit_path(&mut self, path: &'tcx Path, _id: HirId) {
|
||||
fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
|
||||
self.identifiers.insert(ident(path));
|
||||
walk_path(self, path);
|
||||
}
|
||||
@ -100,7 +100,7 @@ struct MapExprVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for MapExprVisitor<'a, 'tcx> {
|
||||
fn visit_path(&mut self, path: &'tcx Path, _id: HirId) {
|
||||
fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
|
||||
if self.identifiers.contains(&ident(path)) {
|
||||
self.found_identifier = true;
|
||||
return;
|
||||
@ -113,7 +113,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MapExprVisitor<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn ident(path: &Path) -> Symbol {
|
||||
fn ident(path: &Path<'_>) -> Symbol {
|
||||
path.segments
|
||||
.last()
|
||||
.expect("segments should be composed of at least 1 element")
|
||||
|
@ -237,7 +237,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
k: FnKind<'tcx>,
|
||||
decl: &'tcx FnDecl,
|
||||
decl: &'tcx FnDecl<'_>,
|
||||
body: &'tcx Body<'_>,
|
||||
_: Span,
|
||||
_: HirId,
|
||||
@ -626,7 +626,7 @@ fn non_macro_local(cx: &LateContext<'_, '_>, res: def::Res) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_cast(cx: &LateContext<'_, '_>, span: Span, e: &Expr<'_>, ty: &Ty) {
|
||||
fn check_cast(cx: &LateContext<'_, '_>, span: Span, e: &Expr<'_>, ty: &Ty<'_>) {
|
||||
if_chain! {
|
||||
if let TyKind::Ptr(ref mut_ty) = ty.kind;
|
||||
if let ExprKind::Lit(ref lit) = e.kind;
|
||||
|
@ -2,7 +2,7 @@ use crate::utils::{has_drop, is_entrypoint_fn, span_lint, trait_ref_of_method};
|
||||
use rustc::declare_lint_pass;
|
||||
use rustc::hir;
|
||||
use rustc::hir::intravisit::FnKind;
|
||||
use rustc::hir::{Body, Constness, FnDecl, HirId, HirVec};
|
||||
use rustc::hir::{Body, Constness, FnDecl, HirId};
|
||||
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn;
|
||||
use rustc_session::declare_tool_lint;
|
||||
@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
|
||||
&mut self,
|
||||
cx: &LateContext<'_, '_>,
|
||||
kind: FnKind<'_>,
|
||||
_: &FnDecl,
|
||||
_: &FnDecl<'_>,
|
||||
_: &Body<'_>,
|
||||
span: Span,
|
||||
hir_id: HirId,
|
||||
@ -98,7 +98,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
|
||||
FnKind::Method(_, sig, ..) => {
|
||||
if trait_ref_of_method(cx, hir_id).is_some()
|
||||
|| already_const(sig.header)
|
||||
|| method_accepts_dropable(cx, &sig.decl.inputs)
|
||||
|| method_accepts_dropable(cx, sig.decl.inputs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -120,7 +120,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
|
||||
|
||||
/// Returns true if any of the method parameters is a type that implements `Drop`. The method
|
||||
/// can't be made const then, because `drop` can't be const-evaluated.
|
||||
fn method_accepts_dropable(cx: &LateContext<'_, '_>, param_tys: &HirVec<hir::Ty>) -> bool {
|
||||
fn method_accepts_dropable(cx: &LateContext<'_, '_>, param_tys: &[hir::Ty<'_>]) -> bool {
|
||||
// If any of the params are dropable, return true
|
||||
param_tys.iter().any(|hir_ty| {
|
||||
let ty_ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
||||
|
@ -81,7 +81,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableKeyType {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_sig<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item_hir_id: hir::HirId, decl: &hir::FnDecl) {
|
||||
fn check_sig<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item_hir_id: hir::HirId, decl: &hir::FnDecl<'_>) {
|
||||
let fn_def_id = cx.tcx.hir().local_def_id(item_hir_id);
|
||||
let fn_sig = cx.tcx.fn_sig(fn_def_id);
|
||||
for (hir_ty, ty) in decl.inputs.iter().zip(fn_sig.inputs().skip_binder().iter()) {
|
||||
|
@ -32,7 +32,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutMut {
|
||||
intravisit::walk_block(&mut MutVisitor { cx }, block);
|
||||
}
|
||||
|
||||
fn check_ty(&mut self, cx: &LateContext<'a, 'tcx>, ty: &'tcx hir::Ty) {
|
||||
fn check_ty(&mut self, cx: &LateContext<'a, 'tcx>, ty: &'tcx hir::Ty<'_>) {
|
||||
use rustc::hir::intravisit::Visitor;
|
||||
|
||||
MutVisitor { cx }.visit_ty(ty);
|
||||
@ -77,7 +77,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
|
||||
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
|
||||
if let hir::TyKind::Rptr(
|
||||
_,
|
||||
hir::MutTy {
|
||||
|
@ -71,7 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
kind: FnKind<'tcx>,
|
||||
decl: &'tcx FnDecl,
|
||||
decl: &'tcx FnDecl<'_>,
|
||||
body: &'tcx Body<'_>,
|
||||
span: Span,
|
||||
hir_id: HirId,
|
||||
|
@ -145,7 +145,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr {
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id: Option<BodyId>) {
|
||||
fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id: Option<BodyId>) {
|
||||
let fn_def_id = cx.tcx.hir().local_def_id(fn_id);
|
||||
let sig = cx.tcx.fn_sig(fn_def_id);
|
||||
let fn_ty = sig.skip_binder();
|
||||
@ -285,7 +285,7 @@ fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: HirId, opt_body_id:
|
||||
}
|
||||
}
|
||||
|
||||
fn get_rptr_lm(ty: &Ty) -> Option<(&Lifetime, Mutability, Span)> {
|
||||
fn get_rptr_lm<'tcx>(ty: &'tcx Ty<'tcx>) -> Option<(&'tcx Lifetime, Mutability, Span)> {
|
||||
if let TyKind::Rptr(ref lt, ref m) = ty.kind {
|
||||
Some((lt, m.mutbl, ty.span))
|
||||
} else {
|
||||
|
@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
_: FnKind<'tcx>,
|
||||
_: &'tcx FnDecl,
|
||||
_: &'tcx FnDecl<'_>,
|
||||
body: &'tcx Body<'_>,
|
||||
_: Span,
|
||||
_: HirId,
|
||||
|
@ -172,8 +172,8 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_
|
||||
|
||||
fn find_good_method_for_match<'a>(
|
||||
arms: &[Arm<'_>],
|
||||
path_left: &QPath,
|
||||
path_right: &QPath,
|
||||
path_left: &QPath<'_>,
|
||||
path_right: &QPath<'_>,
|
||||
expected_left: &[&str],
|
||||
expected_right: &[&str],
|
||||
should_be_left: &'a str,
|
||||
|
@ -88,7 +88,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Shadow {
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
_: FnKind<'tcx>,
|
||||
decl: &'tcx FnDecl,
|
||||
decl: &'tcx FnDecl<'_>,
|
||||
body: &'tcx Body<'_>,
|
||||
_: Span,
|
||||
_: HirId,
|
||||
@ -100,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Shadow {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl, body: &'tcx Body<'_>) {
|
||||
fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>) {
|
||||
let mut bindings = Vec::new();
|
||||
for arg in iter_input_pats(decl, body) {
|
||||
if let PatKind::Binding(.., ident, _) = arg.pat.kind {
|
||||
@ -345,7 +345,7 @@ fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, bindin
|
||||
}
|
||||
}
|
||||
|
||||
fn check_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty, bindings: &mut Vec<(Name, Span)>) {
|
||||
fn check_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty<'_>, bindings: &mut Vec<(Name, Span)>) {
|
||||
match ty.kind {
|
||||
TyKind::Slice(ref sty) => check_ty(cx, sty, bindings),
|
||||
TyKind::Array(ref fty, ref anon_const) => {
|
||||
@ -355,7 +355,7 @@ fn check_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty, bindings: &mut V
|
||||
TyKind::Ptr(MutTy { ty: ref mty, .. }) | TyKind::Rptr(_, MutTy { ty: ref mty, .. }) => {
|
||||
check_ty(cx, mty, bindings)
|
||||
},
|
||||
TyKind::Tup(ref tup) => {
|
||||
TyKind::Tup(tup) => {
|
||||
for t in tup {
|
||||
check_ty(cx, t, bindings)
|
||||
}
|
||||
@ -377,6 +377,6 @@ fn is_self_shadow(name: Name, expr: &Expr<'_>) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn path_eq_name(name: Name, path: &Path) -> bool {
|
||||
fn path_eq_name(name: Name, path: &Path<'_>) -> bool {
|
||||
!path.is_global() && path.segments.len() == 1 && path.segments[0].ident.as_str() == name.as_str()
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ declare_clippy_lint! {
|
||||
impl_lint_pass!(TraitBounds => [TYPE_REPETITION_IN_BOUNDS]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds {
|
||||
fn check_generics(&mut self, cx: &LateContext<'a, 'tcx>, gen: &'tcx Generics) {
|
||||
fn check_generics(&mut self, cx: &LateContext<'a, 'tcx>, gen: &'tcx Generics<'_>) {
|
||||
if in_macro(gen.span) {
|
||||
return;
|
||||
}
|
||||
@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TraitBounds {
|
||||
hasher.finish()
|
||||
};
|
||||
let mut map = FxHashMap::default();
|
||||
for bound in &gen.where_clause.predicates {
|
||||
for bound in gen.where_clause.predicates {
|
||||
if let WherePredicate::BoundPredicate(ref p) = bound {
|
||||
let h = hash(&p.bounded_ty);
|
||||
if let Some(ref v) = map.insert(h, p.bounds.iter().collect::<Vec<_>>()) {
|
||||
|
@ -618,7 +618,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||
/// the type's `ToString` implementation. In weird cases it could lead to types
|
||||
/// with invalid `'_`
|
||||
/// lifetime, but it should be rare.
|
||||
fn get_type_snippet(cx: &LateContext<'_, '_>, path: &QPath, to_ref_ty: Ty<'_>) -> String {
|
||||
fn get_type_snippet(cx: &LateContext<'_, '_>, path: &QPath<'_>, to_ref_ty: Ty<'_>) -> String {
|
||||
let seg = last_path_segment(path);
|
||||
if_chain! {
|
||||
if let Some(ref params) = seg.args;
|
||||
|
@ -75,7 +75,7 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
|
||||
Self { limit }
|
||||
}
|
||||
|
||||
fn check_poly_fn(&mut self, cx: &LateContext<'_, 'tcx>, hir_id: HirId, decl: &FnDecl, span: Option<Span>) {
|
||||
fn check_poly_fn(&mut self, cx: &LateContext<'_, 'tcx>, hir_id: HirId, decl: &FnDecl<'_>, span: Option<Span>) {
|
||||
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
|
||||
|
||||
let fn_sig = cx.tcx.fn_sig(fn_def_id);
|
||||
@ -142,7 +142,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
kind: FnKind<'tcx>,
|
||||
decl: &'tcx FnDecl,
|
||||
decl: &'tcx FnDecl<'_>,
|
||||
_body: &'tcx Body<'_>,
|
||||
span: Span,
|
||||
hir_id: HirId,
|
||||
|
@ -170,7 +170,15 @@ declare_clippy_lint! {
|
||||
declare_lint_pass!(Types => [BOX_VEC, VEC_BOX, OPTION_OPTION, LINKEDLIST, BORROWED_BOX]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Types {
|
||||
fn check_fn(&mut self, cx: &LateContext<'_, '_>, _: FnKind<'_>, decl: &FnDecl, _: &Body<'_>, _: Span, id: HirId) {
|
||||
fn check_fn(
|
||||
&mut self,
|
||||
cx: &LateContext<'_, '_>,
|
||||
_: FnKind<'_>,
|
||||
decl: &FnDecl<'_>,
|
||||
_: &Body<'_>,
|
||||
_: Span,
|
||||
id: HirId,
|
||||
) {
|
||||
// Skip trait implementations; see issue #605.
|
||||
if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(id)) {
|
||||
if let ItemKind::Impl(_, _, _, _, Some(..), _, _) = item.kind {
|
||||
@ -200,8 +208,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Types {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_fn_decl(cx: &LateContext<'_, '_>, decl: &FnDecl) {
|
||||
for input in &decl.inputs {
|
||||
fn check_fn_decl(cx: &LateContext<'_, '_>, decl: &FnDecl<'_>) {
|
||||
for input in decl.inputs {
|
||||
check_ty(cx, input, false);
|
||||
}
|
||||
|
||||
@ -211,7 +219,7 @@ fn check_fn_decl(cx: &LateContext<'_, '_>, decl: &FnDecl) {
|
||||
}
|
||||
|
||||
/// Checks if `qpath` has last segment with type parameter matching `path`
|
||||
fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath, path: &[&str]) -> bool {
|
||||
fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath<'_>, path: &[&str]) -> bool {
|
||||
let last = last_path_segment(qpath);
|
||||
if_chain! {
|
||||
if let Some(ref params) = last.args;
|
||||
@ -236,7 +244,7 @@ fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath, path: &[&str])
|
||||
/// The parameter `is_local` distinguishes the context of the type; types from
|
||||
/// local bindings should only be checked for the `BORROWED_BOX` lint.
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
|
||||
fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty<'_>, is_local: bool) {
|
||||
if hir_ty.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
@ -359,7 +367,7 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
|
||||
TyKind::Slice(ref ty) | TyKind::Array(ref ty, _) | TyKind::Ptr(MutTy { ref ty, .. }) => {
|
||||
check_ty(cx, ty, is_local)
|
||||
},
|
||||
TyKind::Tup(ref tys) => {
|
||||
TyKind::Tup(tys) => {
|
||||
for ty in tys {
|
||||
check_ty(cx, ty, is_local);
|
||||
}
|
||||
@ -368,7 +376,7 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_ty_rptr(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool, lt: &Lifetime, mut_ty: &MutTy) {
|
||||
fn check_ty_rptr(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty<'_>, is_local: bool, lt: &Lifetime, mut_ty: &MutTy<'_>) {
|
||||
match mut_ty.ty.kind {
|
||||
TyKind::Path(ref qpath) => {
|
||||
let hir_id = mut_ty.ty.hir_id;
|
||||
@ -425,10 +433,10 @@ fn check_ty_rptr(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool, lt:
|
||||
}
|
||||
|
||||
// Returns true if given type is `Any` trait.
|
||||
fn is_any_trait(t: &hir::Ty) -> bool {
|
||||
fn is_any_trait(t: &hir::Ty<'_>) -> bool {
|
||||
if_chain! {
|
||||
if let TyKind::TraitObject(ref traits, _) = t.kind;
|
||||
if traits.len() >= 1;
|
||||
if !traits.is_empty();
|
||||
// Only Send/Sync can be used as additional traits, so it is enough to
|
||||
// check only the first trait.
|
||||
if match_path(&traits[0].trait_ref.path, &paths::ANY_TRAIT);
|
||||
@ -1394,7 +1402,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexity {
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
_: FnKind<'tcx>,
|
||||
decl: &'tcx FnDecl,
|
||||
decl: &'tcx FnDecl<'_>,
|
||||
_: &'tcx Body<'_>,
|
||||
_: Span,
|
||||
_: HirId,
|
||||
@ -1440,8 +1448,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexity {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeComplexity {
|
||||
fn check_fndecl(&self, cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl) {
|
||||
for arg in &decl.inputs {
|
||||
fn check_fndecl(&self, cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl<'_>) {
|
||||
for arg in decl.inputs {
|
||||
self.check_type(cx, arg);
|
||||
}
|
||||
if let Return(ref ty) = decl.output {
|
||||
@ -1449,7 +1457,7 @@ impl<'a, 'tcx> TypeComplexity {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_type(&self, cx: &LateContext<'_, '_>, ty: &hir::Ty) {
|
||||
fn check_type(&self, cx: &LateContext<'_, '_>, ty: &hir::Ty<'_>) {
|
||||
if ty.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
@ -1479,7 +1487,7 @@ struct TypeComplexityVisitor {
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
|
||||
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
|
||||
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
|
||||
let (add_score, sub_nest) = match ty.kind {
|
||||
// _, &x and *x have only small overhead; don't mess with nesting level
|
||||
TyKind::Infer | TyKind::Ptr(..) | TyKind::Rptr(..) => (1, 0),
|
||||
@ -2131,7 +2139,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher {
|
||||
ItemKind::Fn(ref sig, ref generics, body_id) => {
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
|
||||
for ty in &sig.decl.inputs {
|
||||
for ty in sig.decl.inputs {
|
||||
let mut vis = ImplicitHasherTypeVisitor::new(cx);
|
||||
vis.visit_ty(ty);
|
||||
|
||||
@ -2179,7 +2187,7 @@ enum ImplicitHasherType<'tcx> {
|
||||
|
||||
impl<'tcx> ImplicitHasherType<'tcx> {
|
||||
/// Checks that `ty` is a target type without a `BuildHasher`.
|
||||
fn new<'a>(cx: &LateContext<'a, 'tcx>, hir_ty: &hir::Ty) -> Option<Self> {
|
||||
fn new<'a>(cx: &LateContext<'a, 'tcx>, hir_ty: &hir::Ty<'_>) -> Option<Self> {
|
||||
if let TyKind::Path(QPath::Resolved(None, ref path)) = hir_ty.kind {
|
||||
let params: Vec<_> = path
|
||||
.segments
|
||||
@ -2258,7 +2266,7 @@ impl<'a, 'tcx> ImplicitHasherTypeVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for ImplicitHasherTypeVisitor<'a, 'tcx> {
|
||||
fn visit_ty(&mut self, t: &'tcx hir::Ty) {
|
||||
fn visit_ty(&mut self, t: &'tcx hir::Ty<'_>) {
|
||||
if let Some(target) = ImplicitHasherType::new(self.cx, t) {
|
||||
self.found.push(target);
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ struct UnusedSelfVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for UnusedSelfVisitor<'a, 'tcx> {
|
||||
fn visit_path(&mut self, path: &'tcx Path, _id: HirId) {
|
||||
fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
|
||||
if self.uses_self {
|
||||
// This function already uses `self`
|
||||
return;
|
||||
|
@ -70,7 +70,7 @@ struct UnwrappableVariablesVisitor<'a, 'tcx> {
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
struct UnwrapInfo<'tcx> {
|
||||
/// The variable that is checked
|
||||
ident: &'tcx Path,
|
||||
ident: &'tcx Path<'tcx>,
|
||||
/// The check, like `x.is_ok()`
|
||||
check: &'tcx Expr<'tcx>,
|
||||
/// Whether `is_some()` or `is_ok()` was called (as opposed to `is_err()` or `is_none()`).
|
||||
@ -191,7 +191,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Unwrap {
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
kind: FnKind<'tcx>,
|
||||
decl: &'tcx FnDecl,
|
||||
decl: &'tcx FnDecl<'_>,
|
||||
body: &'tcx Body<'_>,
|
||||
span: Span,
|
||||
fn_id: HirId,
|
||||
|
@ -52,7 +52,7 @@ declare_lint_pass!(UseSelf => [USE_SELF]);
|
||||
|
||||
const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element";
|
||||
|
||||
fn span_use_self_lint(cx: &LateContext<'_, '_>, path: &Path, last_segment: Option<&PathSegment>) {
|
||||
fn span_use_self_lint(cx: &LateContext<'_, '_>, path: &Path<'_>, last_segment: Option<&PathSegment<'_>>) {
|
||||
let last_segment = last_segment.unwrap_or_else(|| path.segments.last().expect(SEGMENTS_MSG));
|
||||
|
||||
// Path segments only include actual path, no methods or fields.
|
||||
@ -84,7 +84,7 @@ struct TraitImplTyVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for TraitImplTyVisitor<'a, 'tcx> {
|
||||
fn visit_ty(&mut self, t: &'tcx hir::Ty) {
|
||||
fn visit_ty(&mut self, t: &'tcx hir::Ty<'_>) {
|
||||
let trait_ty = self.trait_type_walker.next();
|
||||
let impl_ty = self.impl_type_walker.next();
|
||||
|
||||
@ -116,7 +116,7 @@ fn check_trait_method_impl_decl<'a, 'tcx>(
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
item_type: Ty<'tcx>,
|
||||
impl_item: &ImplItem<'_>,
|
||||
impl_decl: &'tcx FnDecl,
|
||||
impl_decl: &'tcx FnDecl<'_>,
|
||||
impl_trait_ref: &ty::TraitRef<'_>,
|
||||
) {
|
||||
let trait_method = cx
|
||||
@ -218,12 +218,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
|
||||
}
|
||||
|
||||
struct UseSelfVisitor<'a, 'tcx> {
|
||||
item_path: &'a Path,
|
||||
item_path: &'a Path<'a>,
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
|
||||
fn visit_path(&mut self, path: &'tcx Path, _id: HirId) {
|
||||
fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
|
||||
if !path.segments.iter().any(|p| p.ident.span.is_dummy()) {
|
||||
if path.segments.len() >= 2 {
|
||||
let last_but_one = &path.segments[path.segments.len() - 2];
|
||||
|
@ -172,7 +172,7 @@ impl PrintVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
fn print_qpath(&mut self, path: &QPath) {
|
||||
fn print_qpath(&mut self, path: &QPath<'_>) {
|
||||
print!(" if match_qpath({}, &[", self.current);
|
||||
print_path(path, &mut true);
|
||||
println!("]);");
|
||||
@ -725,10 +725,10 @@ fn loop_desugaring_name(des: hir::LoopSource) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
fn print_path(path: &QPath, first: &mut bool) {
|
||||
fn print_path(path: &QPath<'_>, first: &mut bool) {
|
||||
match *path {
|
||||
QPath::Resolved(_, ref path) => {
|
||||
for segment in &path.segments {
|
||||
for segment in path.segments {
|
||||
if *first {
|
||||
*first = false;
|
||||
} else {
|
||||
|
@ -167,7 +167,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn eq_generic_arg(&mut self, left: &GenericArg, right: &GenericArg) -> bool {
|
||||
fn eq_generic_arg(&mut self, left: &GenericArg<'_>, right: &GenericArg<'_>) -> bool {
|
||||
match (left, right) {
|
||||
(GenericArg::Lifetime(l_lt), GenericArg::Lifetime(r_lt)) => Self::eq_lifetime(l_lt, r_lt),
|
||||
(GenericArg::Type(l_ty), GenericArg::Type(r_ty)) => self.eq_ty(l_ty, r_ty),
|
||||
@ -209,7 +209,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
|
||||
}
|
||||
|
||||
#[allow(clippy::similar_names)]
|
||||
fn eq_qpath(&mut self, left: &QPath, right: &QPath) -> bool {
|
||||
fn eq_qpath(&mut self, left: &QPath<'_>, right: &QPath<'_>) -> bool {
|
||||
match (left, right) {
|
||||
(&QPath::Resolved(ref lty, ref lpath), &QPath::Resolved(ref rty, ref rpath)) => {
|
||||
both(lty, rty, |l, r| self.eq_ty(l, r)) && self.eq_path(lpath, rpath)
|
||||
@ -221,12 +221,12 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn eq_path(&mut self, left: &Path, right: &Path) -> bool {
|
||||
fn eq_path(&mut self, left: &Path<'_>, right: &Path<'_>) -> bool {
|
||||
left.is_global() == right.is_global()
|
||||
&& over(&left.segments, &right.segments, |l, r| self.eq_path_segment(l, r))
|
||||
}
|
||||
|
||||
fn eq_path_parameters(&mut self, left: &GenericArgs, right: &GenericArgs) -> bool {
|
||||
fn eq_path_parameters(&mut self, left: &GenericArgs<'_>, right: &GenericArgs<'_>) -> bool {
|
||||
if !(left.parenthesized || right.parenthesized) {
|
||||
over(&left.args, &right.args, |l, r| self.eq_generic_arg(l, r)) // FIXME(flip1995): may not work
|
||||
&& over(&left.bindings, &right.bindings, |l, r| self.eq_type_binding(l, r))
|
||||
@ -240,11 +240,11 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eq_path_segments(&mut self, left: &[PathSegment], right: &[PathSegment]) -> bool {
|
||||
pub fn eq_path_segments(&mut self, left: &[PathSegment<'_>], right: &[PathSegment<'_>]) -> bool {
|
||||
left.len() == right.len() && left.iter().zip(right).all(|(l, r)| self.eq_path_segment(l, r))
|
||||
}
|
||||
|
||||
pub fn eq_path_segment(&mut self, left: &PathSegment, right: &PathSegment) -> bool {
|
||||
pub fn eq_path_segment(&mut self, left: &PathSegment<'_>, right: &PathSegment<'_>) -> bool {
|
||||
// The == of idents doesn't work with different contexts,
|
||||
// we have to be explicit about hygiene
|
||||
if left.ident.as_str() != right.ident.as_str() {
|
||||
@ -257,12 +257,12 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eq_ty(&mut self, left: &Ty, right: &Ty) -> bool {
|
||||
pub fn eq_ty(&mut self, left: &Ty<'_>, right: &Ty<'_>) -> bool {
|
||||
self.eq_ty_kind(&left.kind, &right.kind)
|
||||
}
|
||||
|
||||
#[allow(clippy::similar_names)]
|
||||
pub fn eq_ty_kind(&mut self, left: &TyKind, right: &TyKind) -> bool {
|
||||
pub fn eq_ty_kind(&mut self, left: &TyKind<'_>, right: &TyKind<'_>) -> bool {
|
||||
match (left, right) {
|
||||
(&TyKind::Slice(ref l_vec), &TyKind::Slice(ref r_vec)) => self.eq_ty(l_vec, r_vec),
|
||||
(&TyKind::Array(ref lt, ref ll_id), &TyKind::Array(ref rt, ref rl_id)) => {
|
||||
@ -293,7 +293,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn eq_type_binding(&mut self, left: &TypeBinding, right: &TypeBinding) -> bool {
|
||||
fn eq_type_binding(&mut self, left: &TypeBinding<'_>, right: &TypeBinding<'_>) -> bool {
|
||||
left.ident.name == right.ident.name && self.eq_ty(&left.ty(), &right.ty())
|
||||
}
|
||||
}
|
||||
@ -544,7 +544,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||
n.as_str().hash(&mut self.s);
|
||||
}
|
||||
|
||||
pub fn hash_qpath(&mut self, p: &QPath) {
|
||||
pub fn hash_qpath(&mut self, p: &QPath<'_>) {
|
||||
match *p {
|
||||
QPath::Resolved(_, ref path) => {
|
||||
self.hash_path(path);
|
||||
@ -556,9 +556,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||
// self.cx.tables.qpath_res(p, id).hash(&mut self.s);
|
||||
}
|
||||
|
||||
pub fn hash_path(&mut self, p: &Path) {
|
||||
pub fn hash_path(&mut self, p: &Path<'_>) {
|
||||
p.is_global().hash(&mut self.s);
|
||||
for p in &p.segments {
|
||||
for p in p.segments {
|
||||
self.hash_name(p.ident.name);
|
||||
}
|
||||
}
|
||||
@ -603,11 +603,11 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hash_ty(&mut self, ty: &Ty) {
|
||||
pub fn hash_ty(&mut self, ty: &Ty<'_>) {
|
||||
self.hash_tykind(&ty.kind);
|
||||
}
|
||||
|
||||
pub fn hash_tykind(&mut self, ty: &TyKind) {
|
||||
pub fn hash_tykind(&mut self, ty: &TyKind<'_>) {
|
||||
std::mem::discriminant(ty).hash(&mut self.s);
|
||||
match ty {
|
||||
TyKind::Slice(ty) => {
|
||||
@ -629,7 +629,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||
TyKind::BareFn(bfn) => {
|
||||
bfn.unsafety.hash(&mut self.s);
|
||||
bfn.abi.hash(&mut self.s);
|
||||
for arg in &bfn.decl.inputs {
|
||||
for arg in bfn.decl.inputs {
|
||||
self.hash_ty(&arg);
|
||||
}
|
||||
match bfn.decl.output {
|
||||
@ -643,7 +643,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||
bfn.decl.c_variadic.hash(&mut self.s);
|
||||
},
|
||||
TyKind::Tup(ty_list) => {
|
||||
for ty in ty_list {
|
||||
for ty in *ty_list {
|
||||
self.hash_ty(ty);
|
||||
}
|
||||
},
|
||||
@ -652,7 +652,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||
if let Some(ref ty) = maybe_ty {
|
||||
self.hash_ty(ty);
|
||||
}
|
||||
for segment in &path.segments {
|
||||
for segment in path.segments {
|
||||
segment.ident.name.hash(&mut self.s);
|
||||
}
|
||||
},
|
||||
@ -662,7 +662,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||
},
|
||||
},
|
||||
TyKind::Def(_, arg_list) => {
|
||||
for arg in arg_list {
|
||||
for arg in *arg_list {
|
||||
match arg {
|
||||
GenericArg::Lifetime(ref l) => self.hash_lifetime(l),
|
||||
GenericArg::Type(ref ty) => self.hash_ty(&ty),
|
||||
|
@ -214,7 +214,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty) -> bool {
|
||||
fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty<'_>) -> bool {
|
||||
if let TyKind::Rptr(
|
||||
_,
|
||||
MutTy {
|
||||
@ -243,7 +243,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> {
|
||||
walk_expr(self, expr);
|
||||
}
|
||||
|
||||
fn visit_path(&mut self, path: &'tcx Path, _: HirId) {
|
||||
fn visit_path(&mut self, path: &'tcx Path<'_>, _: HirId) {
|
||||
if path.segments.len() == 1 {
|
||||
self.output.insert(path.segments[0].ident.name);
|
||||
}
|
||||
|
@ -162,14 +162,14 @@ pub fn match_var(expr: &Expr<'_>, var: Name) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn last_path_segment(path: &QPath) -> &PathSegment {
|
||||
pub fn last_path_segment<'tcx>(path: &QPath<'tcx>) -> &'tcx PathSegment<'tcx> {
|
||||
match *path {
|
||||
QPath::Resolved(_, ref path) => path.segments.last().expect("A path must have at least one segment"),
|
||||
QPath::TypeRelative(_, ref seg) => seg,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn single_segment_path(path: &QPath) -> Option<&PathSegment> {
|
||||
pub fn single_segment_path<'tcx>(path: &QPath<'tcx>) -> Option<&'tcx PathSegment<'tcx>> {
|
||||
match *path {
|
||||
QPath::Resolved(_, ref path) if path.segments.len() == 1 => Some(&path.segments[0]),
|
||||
QPath::Resolved(..) => None,
|
||||
@ -186,7 +186,7 @@ pub fn single_segment_path(path: &QPath) -> Option<&PathSegment> {
|
||||
/// ```rust,ignore
|
||||
/// match_qpath(path, &["std", "rt", "begin_unwind"])
|
||||
/// ```
|
||||
pub fn match_qpath(path: &QPath, segments: &[&str]) -> bool {
|
||||
pub fn match_qpath(path: &QPath<'_>, segments: &[&str]) -> bool {
|
||||
match *path {
|
||||
QPath::Resolved(_, ref path) => match_path(path, segments),
|
||||
QPath::TypeRelative(ref ty, ref segment) => match ty.kind {
|
||||
@ -216,7 +216,7 @@ pub fn match_qpath(path: &QPath, segments: &[&str]) -> bool {
|
||||
/// // This is a `rustc::lint::Lint`.
|
||||
/// }
|
||||
/// ```
|
||||
pub fn match_path(path: &Path, segments: &[&str]) -> bool {
|
||||
pub fn match_path(path: &Path<'_>, segments: &[&str]) -> bool {
|
||||
path.segments
|
||||
.iter()
|
||||
.rev()
|
||||
@ -275,7 +275,7 @@ pub fn path_to_res(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<def::Res>
|
||||
}
|
||||
}
|
||||
|
||||
pub fn qpath_res(cx: &LateContext<'_, '_>, qpath: &hir::QPath, id: hir::HirId) -> Res {
|
||||
pub fn qpath_res(cx: &LateContext<'_, '_>, qpath: &hir::QPath<'_>, id: hir::HirId) -> Res {
|
||||
match qpath {
|
||||
hir::QPath::Resolved(_, path) => path.res,
|
||||
hir::QPath::TypeRelative(..) => {
|
||||
@ -340,7 +340,7 @@ pub fn implements_trait<'a, 'tcx>(
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'_, 'tcx>, hir_id: HirId) -> Option<&'tcx TraitRef> {
|
||||
pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'_, 'tcx>, hir_id: HirId) -> Option<&'tcx TraitRef<'tcx>> {
|
||||
// Get the implemented trait for the current function
|
||||
let parent_impl = cx.tcx.hir().get_parent_item(hir_id);
|
||||
if_chain! {
|
||||
@ -661,7 +661,7 @@ pub fn get_enclosing_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, hir_id: HirId)
|
||||
}
|
||||
|
||||
/// Returns the base type for HIR references and pointers.
|
||||
pub fn walk_ptrs_hir_ty(ty: &hir::Ty) -> &hir::Ty {
|
||||
pub fn walk_ptrs_hir_ty<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> {
|
||||
match ty.kind {
|
||||
TyKind::Ptr(ref mut_ty) | TyKind::Rptr(_, ref mut_ty) => walk_ptrs_hir_ty(&mut_ty.ty),
|
||||
_ => ty,
|
||||
@ -826,7 +826,7 @@ pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_, '_>, expr: &Exp
|
||||
|
||||
/// Returns `true` if a pattern is refutable.
|
||||
pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat<'_>) -> bool {
|
||||
fn is_enum_variant(cx: &LateContext<'_, '_>, qpath: &QPath, id: HirId) -> bool {
|
||||
fn is_enum_variant(cx: &LateContext<'_, '_>, qpath: &QPath<'_>, id: HirId) -> bool {
|
||||
matches!(
|
||||
cx.tables.qpath_res(qpath, id),
|
||||
def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(def::CtorOf::Variant, _), _)
|
||||
@ -892,7 +892,7 @@ pub fn is_self(slf: &Param<'_>) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_self_ty(slf: &hir::Ty) -> bool {
|
||||
pub fn is_self_ty(slf: &hir::Ty<'_>) -> bool {
|
||||
if_chain! {
|
||||
if let TyKind::Path(ref qp) = slf.kind;
|
||||
if let QPath::Resolved(None, ref path) = *qp;
|
||||
@ -904,7 +904,7 @@ pub fn is_self_ty(slf: &hir::Ty) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body<'_>) -> impl Iterator<Item = &'tcx Param<'tcx>> {
|
||||
pub fn iter_input_pats<'tcx>(decl: &FnDecl<'_>, body: &'tcx Body<'_>) -> impl Iterator<Item = &'tcx Param<'tcx>> {
|
||||
(0..decl.inputs.len()).map(move |i| &body.params[i])
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ pub fn mutated_variables<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &'a LateContext<'a,
|
||||
}
|
||||
|
||||
pub fn is_potentially_mutated<'a, 'tcx>(
|
||||
variable: &'tcx Path,
|
||||
variable: &'tcx Path<'_>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
) -> bool {
|
||||
|
@ -1,5 +1,7 @@
|
||||
#![feature(proc_macro_quote, proc_macro_hygiene)]
|
||||
#![deny(rust_2018_idioms)]
|
||||
// FIXME: Remove this attribute once the weird failure is gone.
|
||||
#![allow(unused_extern_crates)]
|
||||
extern crate proc_macro;
|
||||
|
||||
use proc_macro::{quote, TokenStream};
|
||||
|
Loading…
Reference in New Issue
Block a user