Auto merge of #10097 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` I'm on the train and my internet is too bad to download the necessary toolchain, so I have to use CI to find sync fallout. changelog: none <!-- changelog_checked -->
This commit is contained in:
commit
4bdfb0741d
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "clippy"
|
||||
version = "0.1.67"
|
||||
version = "0.1.68"
|
||||
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
|
||||
repository = "https://github.com/rust-lang/rust-clippy"
|
||||
readme = "README.md"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "clippy_lints"
|
||||
version = "0.1.67"
|
||||
version = "0.1.68"
|
||||
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
|
||||
repository = "https://github.com/rust-lang/rust-clippy"
|
||||
readme = "README.md"
|
||||
|
@ -1244,7 +1244,7 @@ fn is_mixed_projection_predicate<'tcx>(
|
||||
let mut projection_ty = projection_predicate.projection_ty;
|
||||
loop {
|
||||
match projection_ty.self_ty().kind() {
|
||||
ty::Projection(inner_projection_ty) => {
|
||||
ty::Alias(ty::Projection, inner_projection_ty) => {
|
||||
projection_ty = *inner_projection_ty;
|
||||
}
|
||||
ty::Param(param_ty) => {
|
||||
@ -1330,7 +1330,7 @@ fn replace_types<'tcx>(
|
||||
&& let Some(term_ty) = projection_predicate.term.ty()
|
||||
&& let ty::Param(term_param_ty) = term_ty.kind()
|
||||
{
|
||||
let item_def_id = projection_predicate.projection_ty.item_def_id;
|
||||
let item_def_id = projection_predicate.projection_ty.def_id;
|
||||
let assoc_item = cx.tcx.associated_item(item_def_id);
|
||||
let projection = cx.tcx
|
||||
.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(new_ty, []));
|
||||
@ -1390,10 +1390,15 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc
|
||||
continue;
|
||||
},
|
||||
ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty),
|
||||
ty::Projection(_) if ty.has_non_region_param() => TyPosition::new_deref_stable_for_result(precedence, ty),
|
||||
ty::Infer(_) | ty::Error(_) | ty::Bound(..) | ty::Opaque(..) | ty::Placeholder(_) | ty::Dynamic(..) => {
|
||||
Position::ReborrowStable(precedence).into()
|
||||
ty::Alias(ty::Projection, _) if ty.has_non_region_param() => {
|
||||
TyPosition::new_deref_stable_for_result(precedence, ty)
|
||||
},
|
||||
ty::Infer(_)
|
||||
| ty::Error(_)
|
||||
| ty::Bound(..)
|
||||
| ty::Alias(ty::Opaque, ..)
|
||||
| ty::Placeholder(_)
|
||||
| ty::Dynamic(..) => Position::ReborrowStable(precedence).into(),
|
||||
ty::Adt(..) if ty.has_placeholders() || ty.has_opaque_types() => {
|
||||
Position::ReborrowStable(precedence).into()
|
||||
},
|
||||
@ -1417,7 +1422,7 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc
|
||||
| ty::Closure(..)
|
||||
| ty::Never
|
||||
| ty::Tuple(_)
|
||||
| ty::Projection(_) => {
|
||||
| ty::Alias(ty::Projection, _) => {
|
||||
Position::DerefStable(precedence, ty.is_sized(cx.tcx, cx.param_env.without_caller_bounds())).into()
|
||||
},
|
||||
};
|
||||
|
@ -15,7 +15,7 @@ use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::traits::Reveal;
|
||||
use rustc_middle::ty::{
|
||||
self, Binder, BoundConstness, Clause, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate,
|
||||
TraitRef, Ty, TyCtxt,
|
||||
Ty, TyCtxt,
|
||||
};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::source_map::Span;
|
||||
@ -513,10 +513,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
|
||||
tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain(
|
||||
params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| {
|
||||
tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate {
|
||||
trait_ref: TraitRef::new(
|
||||
eq_trait_id,
|
||||
tcx.mk_substs(std::iter::once(tcx.mk_param_from_def(param))),
|
||||
),
|
||||
trait_ref: tcx.mk_trait_ref(eq_trait_id, [tcx.mk_param_from_def(param)]),
|
||||
constness: BoundConstness::NotConst,
|
||||
polarity: ImplPolarity::Positive,
|
||||
}))))
|
||||
|
@ -106,7 +106,9 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedTypes {
|
||||
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||
if let ItemKind::Use(path, UseKind::Single) = &item.kind {
|
||||
self.check_res_emit(cx, &path.res, item.span);
|
||||
for res in &path.res {
|
||||
self.check_res_emit(cx, res, item.span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
|
||||
&& let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args
|
||||
&& let Some(middle_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id)
|
||||
&& cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id)
|
||||
&& !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Opaque(..))
|
||||
&& !matches!(middle_trait_ref.substs.type_at(1).kind(), ty::Alias(ty::Opaque, _))
|
||||
{
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
@ -127,7 +127,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SelfFinder<'a, 'tcx> {
|
||||
self.cx.tcx.hir()
|
||||
}
|
||||
|
||||
fn visit_path(&mut self, path: &'tcx Path<'tcx>, _id: HirId) {
|
||||
fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) {
|
||||
for segment in path.segments {
|
||||
match segment.ident.name {
|
||||
kw::SelfLower => self.lower.push(segment.ident.span),
|
||||
|
@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{Body, FnDecl, HirId};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{Clause, EarlyBinder, Opaque, PredicateKind};
|
||||
use rustc_middle::ty::{self, AliasTy, Clause, EarlyBinder, PredicateKind};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
|
||||
@ -62,11 +62,11 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
|
||||
return;
|
||||
}
|
||||
let ret_ty = return_ty(cx, hir_id);
|
||||
if let Opaque(id, subst) = *ret_ty.kind() {
|
||||
let preds = cx.tcx.explicit_item_bounds(id);
|
||||
if let ty::Alias(ty::Opaque, AliasTy { def_id, substs, .. }) = *ret_ty.kind() {
|
||||
let preds = cx.tcx.explicit_item_bounds(def_id);
|
||||
let mut is_future = false;
|
||||
for &(p, _span) in preds {
|
||||
let p = EarlyBinder(p).subst(cx.tcx, subst);
|
||||
let p = EarlyBinder(p).subst(cx.tcx, substs);
|
||||
if let Some(trait_pred) = p.to_opt_poly_trait_pred() {
|
||||
if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() {
|
||||
is_future = true;
|
||||
|
@ -33,7 +33,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidUtf8InUnchecked {
|
||||
if let Some([arg]) = match_function_call(cx, expr, &paths::STR_FROM_UTF8_UNCHECKED) {
|
||||
match &arg.kind {
|
||||
ExprKind::Lit(Spanned { node: lit, .. }) => {
|
||||
if let LitKind::ByteStr(bytes) = &lit
|
||||
if let LitKind::ByteStr(bytes, _) = &lit
|
||||
&& std::str::from_utf8(bytes).is_err()
|
||||
{
|
||||
lint(cx, expr.span);
|
||||
|
@ -60,7 +60,7 @@ impl LateLintPass<'_> for LargeIncludeFile {
|
||||
then {
|
||||
let len = match &lit.node {
|
||||
// include_bytes
|
||||
LitKind::ByteStr(bstr) => bstr.len(),
|
||||
LitKind::ByteStr(bstr, _) => bstr.len(),
|
||||
// include_str
|
||||
LitKind::Str(sym, _) => sym.as_str().len(),
|
||||
_ => return,
|
||||
|
@ -501,7 +501,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||
.filter_by_name_unhygienic(is_empty)
|
||||
.any(|item| is_is_empty(cx, item))
|
||||
}),
|
||||
ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id),
|
||||
ty::Alias(ty::Projection, ref proj) => has_is_empty_impl(cx, proj.def_id),
|
||||
ty::Adt(id, _) => has_is_empty_impl(cx, id.did()),
|
||||
ty::Array(..) | ty::Slice(..) | ty::Str => true,
|
||||
_ => false,
|
||||
|
@ -95,7 +95,10 @@ impl<'tcx> LateLintPass<'tcx> for MacroUseImports {
|
||||
let hir_id = item.hir_id();
|
||||
let attrs = cx.tcx.hir().attrs(hir_id);
|
||||
if let Some(mac_attr) = attrs.iter().find(|attr| attr.has_name(sym::macro_use));
|
||||
if let Res::Def(DefKind::Mod, id) = path.res;
|
||||
if let Some(id) = path.res.iter().find_map(|res| match res {
|
||||
Res::Def(DefKind::Mod, id) => Some(id),
|
||||
_ => None,
|
||||
});
|
||||
if !id.is_local();
|
||||
then {
|
||||
for kid in cx.tcx.module_children(id).iter() {
|
||||
|
@ -70,7 +70,8 @@ impl<'tcx> LateLintPass<'tcx> for ManualRetain {
|
||||
&& seg.args.is_none()
|
||||
&& let hir::ExprKind::MethodCall(_, target_expr, [], _) = &collect_expr.kind
|
||||
&& let Some(collect_def_id) = cx.typeck_results().type_dependent_def_id(collect_expr.hir_id)
|
||||
&& match_def_path(cx, collect_def_id, &paths::CORE_ITER_COLLECT) {
|
||||
&& cx.tcx.is_diagnostic_item(sym::iterator_collect_fn, collect_def_id)
|
||||
{
|
||||
check_into_iter(cx, parent_expr, left_expr, target_expr, &self.msrv);
|
||||
check_iter(cx, parent_expr, left_expr, target_expr, &self.msrv);
|
||||
check_to_owned(cx, parent_expr, left_expr, target_expr, &self.msrv);
|
||||
|
@ -282,7 +282,7 @@ impl<'a> NormalizedPat<'a> {
|
||||
// TODO: Handle negative integers. They're currently treated as a wild match.
|
||||
ExprKind::Lit(lit) => match lit.node {
|
||||
LitKind::Str(sym, _) => Self::LitStr(sym),
|
||||
LitKind::ByteStr(ref bytes) => Self::LitBytes(bytes),
|
||||
LitKind::ByteStr(ref bytes, _) => Self::LitBytes(bytes),
|
||||
LitKind::Byte(val) => Self::LitInt(val.into()),
|
||||
LitKind::Char(val) => Self::LitInt(val.into()),
|
||||
LitKind::Int(val, _) => Self::LitInt(val),
|
||||
|
@ -151,7 +151,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty:
|
||||
&& let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, item, [collect_ty])
|
||||
&& let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions(
|
||||
cx.param_env,
|
||||
cx.tcx.mk_projection(into_iter_item_proj.item_def_id, into_iter_item_proj.substs)
|
||||
cx.tcx.mk_projection(into_iter_item_proj.def_id, into_iter_item_proj.substs)
|
||||
)
|
||||
{
|
||||
iter_item_ty == into_iter_item_ty
|
||||
|
@ -97,7 +97,7 @@ struct UnwrapVisitor<'a, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> {
|
||||
type NestedFilter = nested_filter::All;
|
||||
|
||||
fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
|
||||
fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) {
|
||||
self.identifiers.insert(ident(path));
|
||||
walk_path(self, path);
|
||||
}
|
||||
@ -116,7 +116,7 @@ struct MapExprVisitor<'a, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for MapExprVisitor<'a, 'tcx> {
|
||||
type NestedFilter = nested_filter::All;
|
||||
|
||||
fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) {
|
||||
fn visit_path(&mut self, path: &Path<'tcx>, _id: HirId) {
|
||||
if self.identifiers.contains(&ident(path)) {
|
||||
self.found_identifier = true;
|
||||
return;
|
||||
|
@ -66,35 +66,38 @@ impl LateLintPass<'_> for ImportRename {
|
||||
}
|
||||
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
|
||||
if_chain! {
|
||||
if let ItemKind::Use(path, UseKind::Single) = &item.kind;
|
||||
if let Res::Def(_, id) = path.res;
|
||||
if let Some(name) = self.renames.get(&id);
|
||||
// Remove semicolon since it is not present for nested imports
|
||||
let span_without_semi = cx.sess().source_map().span_until_char(item.span, ';');
|
||||
if let Some(snip) = snippet_opt(cx, span_without_semi);
|
||||
if let Some(import) = match snip.split_once(" as ") {
|
||||
None => Some(snip.as_str()),
|
||||
Some((import, rename)) => {
|
||||
if rename.trim() == name.as_str() {
|
||||
None
|
||||
} else {
|
||||
Some(import.trim())
|
||||
if let ItemKind::Use(path, UseKind::Single) = &item.kind {
|
||||
for &res in &path.res {
|
||||
if_chain! {
|
||||
if let Res::Def(_, id) = res;
|
||||
if let Some(name) = self.renames.get(&id);
|
||||
// Remove semicolon since it is not present for nested imports
|
||||
let span_without_semi = cx.sess().source_map().span_until_char(item.span, ';');
|
||||
if let Some(snip) = snippet_opt(cx, span_without_semi);
|
||||
if let Some(import) = match snip.split_once(" as ") {
|
||||
None => Some(snip.as_str()),
|
||||
Some((import, rename)) => {
|
||||
if rename.trim() == name.as_str() {
|
||||
None
|
||||
} else {
|
||||
Some(import.trim())
|
||||
}
|
||||
},
|
||||
};
|
||||
then {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
MISSING_ENFORCED_IMPORT_RENAMES,
|
||||
span_without_semi,
|
||||
"this import should be renamed",
|
||||
"try",
|
||||
format!(
|
||||
"{import} as {name}",
|
||||
),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
then {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
MISSING_ENFORCED_IMPORT_RENAMES,
|
||||
span_without_semi,
|
||||
"this import should be renamed",
|
||||
"try",
|
||||
format!(
|
||||
"{import} as {name}",
|
||||
),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,11 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
|
||||
|
||||
fn is_not_macro_export<'tcx>(item: &'tcx Item<'tcx>) -> bool {
|
||||
if let ItemKind::Use(path, _) = item.kind {
|
||||
if let Res::Def(DefKind::Macro(MacroKind::Bang), _) = path.res {
|
||||
if path
|
||||
.res
|
||||
.iter()
|
||||
.all(|res| matches!(res, Res::Def(DefKind::Macro(MacroKind::Bang), _)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} else if let ItemKind::Macro(..) = item.kind {
|
||||
|
@ -149,7 +149,7 @@ impl SingleComponentPathImports {
|
||||
|
||||
// keep track of `use some_module;` usages
|
||||
if segments.len() == 1 {
|
||||
if let UseTreeKind::Simple(None, _, _) = use_tree.kind {
|
||||
if let UseTreeKind::Simple(None) = use_tree.kind {
|
||||
let name = segments[0].ident.name;
|
||||
if !macros.contains(&name) {
|
||||
single_use_usages.push(SingleUse {
|
||||
@ -169,7 +169,7 @@ impl SingleComponentPathImports {
|
||||
for tree in trees {
|
||||
let segments = &tree.0.prefix.segments;
|
||||
if segments.len() == 1 {
|
||||
if let UseTreeKind::Simple(None, _, _) = tree.0.kind {
|
||||
if let UseTreeKind::Simple(None) = tree.0.kind {
|
||||
let name = segments[0].ident.name;
|
||||
if !macros.contains(&name) {
|
||||
single_use_usages.push(SingleUse {
|
||||
|
@ -57,7 +57,7 @@ impl EarlyLintPass for UnnecessarySelfImports {
|
||||
format!(
|
||||
"{}{};",
|
||||
last_segment.ident,
|
||||
if let UseTreeKind::Simple(Some(alias), ..) = self_tree.kind { format!(" as {alias}") } else { String::new() },
|
||||
if let UseTreeKind::Simple(Some(alias)) = self_tree.kind { format!(" as {alias}") } else { String::new() },
|
||||
),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -39,7 +39,7 @@ impl EarlyLintPass for UnsafeNameRemoval {
|
||||
|
||||
fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) {
|
||||
match use_tree.kind {
|
||||
UseTreeKind::Simple(Some(new_name), ..) => {
|
||||
UseTreeKind::Simple(Some(new_name)) => {
|
||||
let old_name = use_tree
|
||||
.prefix
|
||||
.segments
|
||||
@ -48,7 +48,7 @@ fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) {
|
||||
.ident;
|
||||
unsafe_to_safe_check(old_name, new_name, cx, span);
|
||||
},
|
||||
UseTreeKind::Simple(None, ..) | UseTreeKind::Glob => {},
|
||||
UseTreeKind::Simple(None) | UseTreeKind::Glob => {},
|
||||
UseTreeKind::Nested(ref nested_use_tree) => {
|
||||
for (use_tree, _) in nested_use_tree {
|
||||
check_use_tree(use_tree, cx, span);
|
||||
|
@ -299,7 +299,7 @@ impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
|
||||
};
|
||||
kind!("Float(_, {float_ty})");
|
||||
},
|
||||
LitKind::ByteStr(ref vec) => {
|
||||
LitKind::ByteStr(ref vec, _) => {
|
||||
bind!(self, vec);
|
||||
kind!("ByteStr(ref {vec})");
|
||||
chain!(self, "let [{:?}] = **{vec}", vec.value);
|
||||
|
@ -7,7 +7,7 @@ use rustc_hir::def::DefKind;
|
||||
use rustc_hir::Item;
|
||||
use rustc_hir_analysis::hir_ty_to_ty;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{self, fast_reject::SimplifiedTypeGen, FloatTy};
|
||||
use rustc_middle::ty::{self, fast_reject::SimplifiedType, FloatTy};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::symbol::Symbol;
|
||||
|
||||
@ -73,10 +73,10 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
|
||||
let lang_items = cx.tcx.lang_items();
|
||||
// This list isn't complete, but good enough for our current list of paths.
|
||||
let incoherent_impls = [
|
||||
SimplifiedTypeGen::FloatSimplifiedType(FloatTy::F32),
|
||||
SimplifiedTypeGen::FloatSimplifiedType(FloatTy::F64),
|
||||
SimplifiedTypeGen::SliceSimplifiedType,
|
||||
SimplifiedTypeGen::StrSimplifiedType,
|
||||
SimplifiedType::FloatSimplifiedType(FloatTy::F32),
|
||||
SimplifiedType::FloatSimplifiedType(FloatTy::F64),
|
||||
SimplifiedType::SliceSimplifiedType,
|
||||
SimplifiedType::StrSimplifiedType,
|
||||
]
|
||||
.iter()
|
||||
.flat_map(|&ty| cx.tcx.incoherent_impls(ty).iter().copied());
|
||||
|
@ -330,7 +330,7 @@ struct LintCollector<'a, 'tcx> {
|
||||
impl<'a, 'tcx> Visitor<'tcx> for LintCollector<'a, 'tcx> {
|
||||
type NestedFilter = nested_filter::All;
|
||||
|
||||
fn visit_path(&mut self, path: &'tcx Path<'_>, _: HirId) {
|
||||
fn visit_path(&mut self, path: &Path<'_>, _: HirId) {
|
||||
if path.segments.len() == 1 {
|
||||
self.output.insert(path.segments[0].ident.name);
|
||||
}
|
||||
|
@ -1019,7 +1019,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for ApplicabilityResolver<'a, 'hir> {
|
||||
self.cx.tcx.hir()
|
||||
}
|
||||
|
||||
fn visit_path(&mut self, path: &'hir hir::Path<'hir>, _id: hir::HirId) {
|
||||
fn visit_path(&mut self, path: &hir::Path<'hir>, _id: hir::HirId) {
|
||||
for (index, enum_value) in paths::APPLICABILITY_VALUES.iter().enumerate() {
|
||||
if match_path(path, enum_value) {
|
||||
self.add_new_index(index);
|
||||
|
@ -176,7 +176,8 @@ impl LateLintPass<'_> for WildcardImports {
|
||||
format!("{import_source_snippet}::{imports_string}")
|
||||
};
|
||||
|
||||
let (lint, message) = if let Res::Def(DefKind::Enum, _) = use_path.res {
|
||||
// Glob imports always have a single resolution.
|
||||
let (lint, message) = if let Res::Def(DefKind::Enum, _) = use_path.res[0] {
|
||||
(ENUM_GLOB_USE, "usage of wildcard import for enum variants")
|
||||
} else {
|
||||
(WILDCARD_IMPORTS, "usage of wildcard import")
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "clippy_utils"
|
||||
version = "0.1.67"
|
||||
version = "0.1.68"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
|
@ -566,7 +566,7 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool {
|
||||
use UseTreeKind::*;
|
||||
match (l, r) {
|
||||
(Glob, Glob) => true,
|
||||
(Simple(l, _, _), Simple(r, _, _)) => both(l, r, |l, r| eq_id(*l, *r)),
|
||||
(Simple(l), Simple(r)) => both(l, r, |l, r| eq_id(*l, *r)),
|
||||
(Nested(l), Nested(r)) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)),
|
||||
_ => false,
|
||||
}
|
||||
|
@ -69,7 +69,9 @@ fn lit_search_pat(lit: &LitKind) -> (Pat, Pat) {
|
||||
LitKind::Str(_, StrStyle::Cooked) => (Pat::Str("\""), Pat::Str("\"")),
|
||||
LitKind::Str(_, StrStyle::Raw(0)) => (Pat::Str("r"), Pat::Str("\"")),
|
||||
LitKind::Str(_, StrStyle::Raw(_)) => (Pat::Str("r#"), Pat::Str("#")),
|
||||
LitKind::ByteStr(_) => (Pat::Str("b\""), Pat::Str("\"")),
|
||||
LitKind::ByteStr(_, StrStyle::Cooked) => (Pat::Str("b\""), Pat::Str("\"")),
|
||||
LitKind::ByteStr(_, StrStyle::Raw(0)) => (Pat::Str("br\""), Pat::Str("\"")),
|
||||
LitKind::ByteStr(_, StrStyle::Raw(_)) => (Pat::Str("br#\""), Pat::Str("#")),
|
||||
LitKind::Byte(_) => (Pat::Str("b'"), Pat::Str("'")),
|
||||
LitKind::Char(_) => (Pat::Str("'"), Pat::Str("'")),
|
||||
LitKind::Int(_, LitIntType::Signed(IntTy::Isize)) => (Pat::Num, Pat::Str("isize")),
|
||||
|
@ -210,7 +210,7 @@ pub fn lit_to_mir_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
|
||||
match *lit {
|
||||
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
|
||||
LitKind::Byte(b) => Constant::Int(u128::from(b)),
|
||||
LitKind::ByteStr(ref s) => Constant::Binary(Lrc::clone(s)),
|
||||
LitKind::ByteStr(ref s, _) => Constant::Binary(Lrc::clone(s)),
|
||||
LitKind::Char(c) => Constant::Char(c),
|
||||
LitKind::Int(n, _) => Constant::Int(n),
|
||||
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {
|
||||
|
@ -97,7 +97,7 @@ use rustc_middle::hir::place::PlaceBase;
|
||||
use rustc_middle::ty as rustc_ty;
|
||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
|
||||
use rustc_middle::ty::binding::BindingMode;
|
||||
use rustc_middle::ty::fast_reject::SimplifiedTypeGen::{
|
||||
use rustc_middle::ty::fast_reject::SimplifiedType::{
|
||||
ArraySimplifiedType, BoolSimplifiedType, CharSimplifiedType, FloatSimplifiedType, IntSimplifiedType,
|
||||
PtrSimplifiedType, SliceSimplifiedType, StrSimplifiedType, UintSimplifiedType,
|
||||
};
|
||||
|
@ -20,7 +20,6 @@ pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "
|
||||
pub const BTREEMAP_INSERT: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "insert"];
|
||||
pub const BTREESET_ITER: [&str; 6] = ["alloc", "collections", "btree", "set", "BTreeSet", "iter"];
|
||||
pub const CLONE_TRAIT_METHOD: [&str; 4] = ["core", "clone", "Clone", "clone"];
|
||||
pub const CORE_ITER_COLLECT: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "collect"];
|
||||
pub const CORE_ITER_CLONED: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "cloned"];
|
||||
pub const CORE_ITER_COPIED: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "copied"];
|
||||
pub const CORE_ITER_FILTER: [&str; 6] = ["core", "iter", "traits", "iterator", "Iterator", "filter"];
|
||||
|
@ -82,7 +82,7 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult {
|
||||
ty::Ref(_, _, hir::Mutability::Mut) => {
|
||||
return Err((span, "mutable references in const fn are unstable".into()));
|
||||
},
|
||||
ty::Opaque(..) => return Err((span, "`impl Trait` in const fn is unstable".into())),
|
||||
ty::Alias(ty::Opaque, ..) => return Err((span, "`impl Trait` in const fn is unstable".into())),
|
||||
ty::FnPtr(..) => {
|
||||
return Err((span, "function pointers in const fn are unstable".into()));
|
||||
},
|
||||
@ -301,11 +301,7 @@ fn check_terminator<'tcx>(
|
||||
check_operand(tcx, value, span, body)
|
||||
},
|
||||
|
||||
TerminatorKind::SwitchInt {
|
||||
discr,
|
||||
switch_ty: _,
|
||||
targets: _,
|
||||
} => check_operand(tcx, discr, span, body),
|
||||
TerminatorKind::SwitchInt { discr, targets: _ } => check_operand(tcx, discr, span, body),
|
||||
|
||||
TerminatorKind::Abort => Err((span, "abort is not stable in const fn".into())),
|
||||
TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => {
|
||||
|
@ -16,8 +16,8 @@ use rustc_infer::infer::{
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::mir::interpret::{ConstValue, Scalar};
|
||||
use rustc_middle::ty::{
|
||||
self, AdtDef, AssocKind, Binder, BoundRegion, DefIdTree, FnSig, IntTy, List, ParamEnv, Predicate, PredicateKind,
|
||||
ProjectionTy, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy,
|
||||
self, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, DefIdTree, FnSig, IntTy, List, ParamEnv, Predicate,
|
||||
PredicateKind, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy,
|
||||
VariantDef, VariantDiscr,
|
||||
};
|
||||
use rustc_middle::ty::{GenericArg, GenericArgKind};
|
||||
@ -85,7 +85,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
|
||||
return true;
|
||||
}
|
||||
|
||||
if let ty::Opaque(def_id, _) = *inner_ty.kind() {
|
||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *inner_ty.kind() {
|
||||
if !seen.insert(def_id) {
|
||||
return false;
|
||||
}
|
||||
@ -266,7 +266,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||
is_must_use_ty(cx, *ty)
|
||||
},
|
||||
ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)),
|
||||
ty::Opaque(def_id, _) => {
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
|
||||
for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) {
|
||||
if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() {
|
||||
if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) {
|
||||
@ -647,7 +647,9 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
|
||||
Some(ExprFnSig::Closure(decl, subs.as_closure().sig()))
|
||||
},
|
||||
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))),
|
||||
ty::Opaque(id, _) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(id), cx.tcx.opt_parent(id)),
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
|
||||
sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id))
|
||||
},
|
||||
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)),
|
||||
ty::Dynamic(bounds, _, _) => {
|
||||
let lang_items = cx.tcx.lang_items();
|
||||
@ -666,7 +668,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
|
||||
_ => None,
|
||||
}
|
||||
},
|
||||
ty::Projection(proj) => match cx.tcx.try_normalize_erasing_regions(cx.param_env, ty) {
|
||||
ty::Alias(ty::Projection, proj) => match cx.tcx.try_normalize_erasing_regions(cx.param_env, ty) {
|
||||
Ok(normalized_ty) if normalized_ty != ty => ty_sig(cx, normalized_ty),
|
||||
_ => sig_for_projection(cx, proj).or_else(|| sig_from_bounds(cx, ty, cx.param_env.caller_bounds(), None)),
|
||||
},
|
||||
@ -701,8 +703,7 @@ fn sig_from_bounds<'tcx>(
|
||||
inputs = Some(i);
|
||||
},
|
||||
PredicateKind::Clause(ty::Clause::Projection(p))
|
||||
if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output()
|
||||
&& p.projection_ty.self_ty() == ty =>
|
||||
if Some(p.projection_ty.def_id) == lang_items.fn_once_output() && p.projection_ty.self_ty() == ty =>
|
||||
{
|
||||
if output.is_some() {
|
||||
// Multiple different fn trait impls. Is this even allowed?
|
||||
@ -717,14 +718,14 @@ fn sig_from_bounds<'tcx>(
|
||||
inputs.map(|ty| ExprFnSig::Trait(ty, output, predicates_id))
|
||||
}
|
||||
|
||||
fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> Option<ExprFnSig<'tcx>> {
|
||||
fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option<ExprFnSig<'tcx>> {
|
||||
let mut inputs = None;
|
||||
let mut output = None;
|
||||
let lang_items = cx.tcx.lang_items();
|
||||
|
||||
for (pred, _) in cx
|
||||
.tcx
|
||||
.bound_explicit_item_bounds(ty.item_def_id)
|
||||
.bound_explicit_item_bounds(ty.def_id)
|
||||
.subst_iter_copied(cx.tcx, ty.substs)
|
||||
{
|
||||
match pred.kind().skip_binder() {
|
||||
@ -742,7 +743,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O
|
||||
inputs = Some(i);
|
||||
},
|
||||
PredicateKind::Clause(ty::Clause::Projection(p))
|
||||
if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() =>
|
||||
if Some(p.projection_ty.def_id) == lang_items.fn_once_output() =>
|
||||
{
|
||||
if output.is_some() {
|
||||
// Multiple different fn trait impls. Is this even allowed?
|
||||
@ -996,13 +997,13 @@ pub fn make_projection<'tcx>(
|
||||
container_id: DefId,
|
||||
assoc_ty: Symbol,
|
||||
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
||||
) -> Option<ProjectionTy<'tcx>> {
|
||||
) -> Option<AliasTy<'tcx>> {
|
||||
fn helper<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
container_id: DefId,
|
||||
assoc_ty: Symbol,
|
||||
substs: SubstsRef<'tcx>,
|
||||
) -> Option<ProjectionTy<'tcx>> {
|
||||
) -> Option<AliasTy<'tcx>> {
|
||||
let Some(assoc_item) = tcx
|
||||
.associated_items(container_id)
|
||||
.find_by_name_and_kind(tcx, Ident::with_dummy_span(assoc_ty), AssocKind::Type, container_id)
|
||||
@ -1055,10 +1056,7 @@ pub fn make_projection<'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
Some(ProjectionTy {
|
||||
substs,
|
||||
item_def_id: assoc_item.def_id,
|
||||
})
|
||||
Some(tcx.mk_alias_ty(assoc_item.def_id, substs))
|
||||
}
|
||||
helper(
|
||||
tcx,
|
||||
@ -1081,7 +1079,7 @@ pub fn make_normalized_projection<'tcx>(
|
||||
assoc_ty: Symbol,
|
||||
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
|
||||
) -> Option<Ty<'tcx>> {
|
||||
fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: ProjectionTy<'tcx>) -> Option<Ty<'tcx>> {
|
||||
fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option<Ty<'tcx>> {
|
||||
#[cfg(debug_assertions)]
|
||||
if let Some((i, subst)) = ty
|
||||
.substs
|
||||
@ -1097,7 +1095,7 @@ pub fn make_normalized_projection<'tcx>(
|
||||
);
|
||||
return None;
|
||||
}
|
||||
match tcx.try_normalize_erasing_regions(param_env, tcx.mk_projection(ty.item_def_id, ty.substs)) {
|
||||
match tcx.try_normalize_erasing_regions(param_env, tcx.mk_projection(ty.def_id, ty.substs)) {
|
||||
Ok(ty) => Some(ty),
|
||||
Err(e) => {
|
||||
debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}");
|
||||
|
@ -128,7 +128,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for BindingUsageFinder<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, _: hir::HirId) {
|
||||
fn visit_path(&mut self, path: &hir::Path<'tcx>, _: hir::HirId) {
|
||||
if let hir::def::Res::Local(id) = path.res {
|
||||
if self.binding_ids.contains(&id) {
|
||||
self.usage_found = true;
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "declare_clippy_lint"
|
||||
version = "0.1.67"
|
||||
version = "0.1.68"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
[toolchain]
|
||||
channel = "nightly-2022-12-01"
|
||||
channel = "nightly-2022-12-17"
|
||||
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
|
||||
|
@ -7,14 +7,6 @@ LL | const DEREF_TRAIT: [&str; 4] = ["core", "ops", "deref", "Deref"];
|
||||
= help: convert all references to use `sym::Deref`
|
||||
= note: `-D clippy::unnecessary-def-path` implied by `-D warnings`
|
||||
|
||||
error: hardcoded path to a diagnostic item
|
||||
--> $DIR/unnecessary_def_path_hardcoded_path.rs:12:43
|
||||
|
|
||||
LL | const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref", "deref"];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: convert all references to use `sym::deref_method`
|
||||
|
||||
error: hardcoded path to a language item
|
||||
--> $DIR/unnecessary_def_path_hardcoded_path.rs:11:40
|
||||
|
|
||||
@ -23,5 +15,13 @@ LL | const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"]
|
||||
|
|
||||
= help: convert all references to use `LangItem::DerefMut`
|
||||
|
||||
error: hardcoded path to a diagnostic item
|
||||
--> $DIR/unnecessary_def_path_hardcoded_path.rs:12:43
|
||||
|
|
||||
LL | const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref", "deref"];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: convert all references to use `sym::deref_method`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
|
||||
--> $DIR/macro_use_imports.rs:23:5
|
||||
--> $DIR/macro_use_imports.rs:25:5
|
||||
|
|
||||
LL | #[macro_use]
|
||||
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};`
|
||||
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;`
|
||||
|
|
||||
= note: `-D clippy::macro-use-imports` implied by `-D warnings`
|
||||
|
||||
@ -13,10 +13,10 @@ LL | #[macro_use]
|
||||
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;`
|
||||
|
||||
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
|
||||
--> $DIR/macro_use_imports.rs:25:5
|
||||
--> $DIR/macro_use_imports.rs:23:5
|
||||
|
|
||||
LL | #[macro_use]
|
||||
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;`
|
||||
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};`
|
||||
|
||||
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
|
||||
--> $DIR/macro_use_imports.rs:19:5
|
||||
|
Loading…
x
Reference in New Issue
Block a user