mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-09-21 07:01:54 +00:00
Auto merge of #12813 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: None
This commit is contained in:
commit
680256f3ce
56 changed files with 305 additions and 386 deletions
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_help;
|
||||||
use rustc_hir::{HirId, Item, ItemKind};
|
use rustc_hir::{HirId, Item, ItemKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::layout::LayoutOf;
|
use rustc_middle::ty::layout::LayoutOf;
|
||||||
use rustc_middle::ty::{self, FieldDef, GenericArg, List};
|
use rustc_middle::ty::{self, FieldDef};
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ fn is_union_with_two_non_zst_fields<'tcx>(cx: &LateContext<'tcx>, item: &Item<'t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: &'tcx List<GenericArg<'tcx>>) -> bool {
|
fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: ty::GenericArgsRef<'tcx>) -> bool {
|
||||||
let ty = field.ty(cx.tcx, args);
|
let ty = field.ty(cx.tcx, args);
|
||||||
if let Ok(layout) = cx.layout_of(ty) {
|
if let Ok(layout) = cx.layout_of(ty) {
|
||||||
layout.is_zst()
|
layout.is_zst()
|
||||||
|
|
|
@ -382,7 +382,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
|
||||||
cx,
|
cx,
|
||||||
impl_ty,
|
impl_ty,
|
||||||
trait_id,
|
trait_id,
|
||||||
&args[..cx.tcx.generics_of(trait_id).params.len() - 1],
|
&args[..cx.tcx.generics_of(trait_id).own_params.len() - 1],
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
false
|
false
|
||||||
|
|
|
@ -480,7 +480,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) ->
|
||||||
// Vec<(param_def, needs_eq)>
|
// Vec<(param_def, needs_eq)>
|
||||||
let mut params = tcx
|
let mut params = tcx
|
||||||
.generics_of(did)
|
.generics_of(did)
|
||||||
.params
|
.own_params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| (p, matches!(p.kind, GenericParamDefKind::Type { .. })))
|
.map(|p| (p, matches!(p.kind, GenericParamDefKind::Type { .. })))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use clippy_utils::diagnostics::span_lint_hir;
|
use clippy_utils::diagnostics::span_lint_hir;
|
||||||
use rustc_hir::{intravisit, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind};
|
use rustc_hir::{intravisit, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind};
|
||||||
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
|
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::mir::FakeReadCause;
|
use rustc_middle::mir::FakeReadCause;
|
||||||
use rustc_middle::ty::layout::LayoutOf;
|
use rustc_middle::ty::layout::LayoutOf;
|
||||||
|
@ -105,8 +104,9 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
|
||||||
too_large_for_stack: self.too_large_for_stack,
|
too_large_for_stack: self.too_large_for_stack,
|
||||||
};
|
};
|
||||||
|
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
ExprUseVisitor::for_clippy(cx, fn_def_id, &mut v)
|
||||||
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
|
.consume_body(body)
|
||||||
|
.into_ok();
|
||||||
|
|
||||||
for node in v.set {
|
for node in v.set {
|
||||||
span_lint_hir(
|
span_lint_hir(
|
||||||
|
|
|
@ -4,6 +4,7 @@ use rustc_hir::intravisit::FnKind;
|
||||||
use rustc_hir::{Body, FnDecl};
|
use rustc_hir::{Body, FnDecl};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
|
use rustc_middle::ty::print::PrintTraitRefExt;
|
||||||
use rustc_middle::ty::{self, AliasTy, ClauseKind, PredicateKind};
|
use rustc_middle::ty::{self, AliasTy, ClauseKind, PredicateKind};
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::LocalDefId;
|
||||||
|
|
|
@ -148,7 +148,7 @@ fn try_resolve_type<'tcx>(
|
||||||
match args.get(index - 1) {
|
match args.get(index - 1) {
|
||||||
Some(GenericArg::Type(ty)) => Some(lower_ty(tcx, ty)),
|
Some(GenericArg::Type(ty)) => Some(lower_ty(tcx, ty)),
|
||||||
Some(_) => None,
|
Some(_) => None,
|
||||||
None => Some(tcx.type_of(generics.params[index].def_id).skip_binder()),
|
None => Some(tcx.type_of(generics.own_params[index].def_id).skip_binder()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,7 +225,7 @@ impl {self_ty_without_ref} {{
|
||||||
&& let ImplItemKind::Fn(sig, _) = item.kind
|
&& let ImplItemKind::Fn(sig, _) = item.kind
|
||||||
&& let FnRetTy::Return(ret) = sig.decl.output
|
&& let FnRetTy::Return(ret) = sig.decl.output
|
||||||
&& is_nameable_in_impl_trait(ret)
|
&& is_nameable_in_impl_trait(ret)
|
||||||
&& cx.tcx.generics_of(item_did).params.is_empty()
|
&& cx.tcx.generics_of(item_did).own_params.is_empty()
|
||||||
&& sig.decl.implicit_self == expected_implicit_self
|
&& sig.decl.implicit_self == expected_implicit_self
|
||||||
&& sig.decl.inputs.len() == 1
|
&& sig.decl.inputs.len() == 1
|
||||||
&& let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id())
|
&& let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id())
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(rustc_private)]
|
#![feature(rustc_private)]
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
|
#![feature(unwrap_infallible)]
|
||||||
#![recursion_limit = "512"]
|
#![recursion_limit = "512"]
|
||||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||||
#![allow(
|
#![allow(
|
||||||
|
|
|
@ -4,7 +4,6 @@ use clippy_utils::{get_enclosing_block, higher, path_to_local};
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::{BindingMode, Expr, ExprKind, HirId, Node, PatKind};
|
use rustc_hir::{BindingMode, Expr, ExprKind, HirId, Node, PatKind};
|
||||||
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
|
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::mir::FakeReadCause;
|
use rustc_middle::mir::FakeReadCause;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
|
@ -61,15 +60,9 @@ fn check_for_mutation(
|
||||||
span_low: None,
|
span_low: None,
|
||||||
span_high: None,
|
span_high: None,
|
||||||
};
|
};
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
ExprUseVisitor::for_clippy(cx, body.hir_id.owner.def_id, &mut delegate)
|
||||||
ExprUseVisitor::new(
|
.walk_expr(body)
|
||||||
&mut delegate,
|
.into_ok();
|
||||||
&infcx,
|
|
||||||
body.hir_id.owner.def_id,
|
|
||||||
cx.param_env,
|
|
||||||
cx.typeck_results(),
|
|
||||||
)
|
|
||||||
.walk_expr(body);
|
|
||||||
|
|
||||||
delegate.mutation_span()
|
delegate.mutation_span()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
use crate::rustc_lint::LintContext;
|
|
||||||
use clippy_utils::diagnostics::span_lint_and_then;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::macros::{is_panic, root_macro_call};
|
use clippy_utils::macros::{is_panic, root_macro_call};
|
||||||
use clippy_utils::{is_else_clause, is_parent_stmt, peel_blocks_with_stmt, span_extract_comment, sugg};
|
use clippy_utils::{is_else_clause, is_parent_stmt, peel_blocks_with_stmt, span_extract_comment, sugg};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{Expr, ExprKind, UnOp};
|
use rustc_hir::{Expr, ExprKind, UnOp};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rustc_errors::{Applicability, Diag};
|
||||||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||||
use rustc_hir::{Arm, Expr, ExprKind, MatchSource};
|
use rustc_hir::{Arm, Expr, ExprKind, MatchSource};
|
||||||
use rustc_lint::{LateContext, LintContext};
|
use rustc_lint::{LateContext, LintContext};
|
||||||
use rustc_middle::ty::{GenericArgKind, Ty, TypeAndMut};
|
use rustc_middle::ty::{GenericArgKind, Ty};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
use super::SIGNIFICANT_DROP_IN_SCRUTINEE;
|
use super::SIGNIFICANT_DROP_IN_SCRUTINEE;
|
||||||
|
@ -249,9 +249,9 @@ impl<'a, 'tcx> SigDropHelper<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
let ty = self.cx.typeck_results().expr_ty(expr);
|
let ty = self.cx.typeck_results().expr_ty(expr);
|
||||||
if ty.is_ref() {
|
if ty.is_ref() {
|
||||||
// We checked that the type was ref, so builtin_deref will return Some TypeAndMut,
|
// We checked that the type was ref, so builtin_deref will return Some,
|
||||||
// but let's avoid any chance of an ICE
|
// but let's avoid any chance of an ICE.
|
||||||
if let Some(TypeAndMut { ty, .. }) = ty.builtin_deref(true) {
|
if let Some(ty) = ty.builtin_deref(true) {
|
||||||
if ty.is_trivially_pure_clone_copy() {
|
if ty.is_trivially_pure_clone_copy() {
|
||||||
self.replace_current_sig_drop(expr.span, false, LintSuggestion::MoveAndDerefToCopy);
|
self.replace_current_sig_drop(expr.span, false, LintSuggestion::MoveAndDerefToCopy);
|
||||||
} else if allow_move_and_clone {
|
} else if allow_move_and_clone {
|
||||||
|
|
|
@ -12,7 +12,6 @@ use rustc_span::sym;
|
||||||
|
|
||||||
use super::ITER_OVEREAGER_CLONED;
|
use super::ITER_OVEREAGER_CLONED;
|
||||||
use crate::redundant_clone::REDUNDANT_CLONE;
|
use crate::redundant_clone::REDUNDANT_CLONE;
|
||||||
use crate::rustc_trait_selection::infer::TyCtxtInferExt;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub(super) enum Op<'a> {
|
pub(super) enum Op<'a> {
|
||||||
|
@ -69,16 +68,10 @@ pub(super) fn check<'tcx>(
|
||||||
let mut delegate = MoveDelegate {
|
let mut delegate = MoveDelegate {
|
||||||
used_move: HirIdSet::default(),
|
used_move: HirIdSet::default(),
|
||||||
};
|
};
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
|
||||||
|
|
||||||
ExprUseVisitor::new(
|
ExprUseVisitor::for_clippy(cx, closure.def_id, &mut delegate)
|
||||||
&mut delegate,
|
.consume_body(body)
|
||||||
&infcx,
|
.into_ok();
|
||||||
closure.body.hir_id.owner.def_id,
|
|
||||||
cx.param_env,
|
|
||||||
cx.typeck_results(),
|
|
||||||
)
|
|
||||||
.consume_body(body);
|
|
||||||
|
|
||||||
let mut to_be_discarded = false;
|
let mut to_be_discarded = false;
|
||||||
|
|
||||||
|
|
|
@ -417,7 +417,7 @@ fn get_input_traits_and_projections<'tcx>(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ClauseKind::Projection(projection_predicate) => {
|
ClauseKind::Projection(projection_predicate) => {
|
||||||
if projection_predicate.projection_ty.self_ty() == input {
|
if projection_predicate.projection_term.self_ty() == input {
|
||||||
projection_predicates.push(projection_predicate);
|
projection_predicates.push(projection_predicate);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeParamMismatch {
|
||||||
};
|
};
|
||||||
|
|
||||||
// get the names of the generic parameters in the type
|
// get the names of the generic parameters in the type
|
||||||
let type_params = &cx.tcx.generics_of(defid).params;
|
let type_params = &cx.tcx.generics_of(defid).own_params;
|
||||||
let type_param_names: Vec<_> = type_params
|
let type_param_names: Vec<_> = type_params
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|p| match p.kind {
|
.filter_map(|p| match p.kind {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use rustc_index::bit_set::BitSet;
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, ClauseKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, List, ParamTy, ProjectionPredicate, Ty,
|
self, ClauseKind, EarlyBinder, FnSig, GenericArg, GenericArgKind, ParamTy, ProjectionPredicate, Ty,
|
||||||
};
|
};
|
||||||
use rustc_session::impl_lint_pass;
|
use rustc_session::impl_lint_pass;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
|
@ -157,7 +157,7 @@ fn path_has_args(p: &QPath<'_>) -> bool {
|
||||||
fn needless_borrow_count<'tcx>(
|
fn needless_borrow_count<'tcx>(
|
||||||
cx: &LateContext<'tcx>,
|
cx: &LateContext<'tcx>,
|
||||||
fn_id: DefId,
|
fn_id: DefId,
|
||||||
callee_args: &'tcx List<GenericArg<'tcx>>,
|
callee_args: ty::GenericArgsRef<'tcx>,
|
||||||
arg_index: usize,
|
arg_index: usize,
|
||||||
param_ty: ParamTy,
|
param_ty: ParamTy,
|
||||||
mut expr: &Expr<'tcx>,
|
mut expr: &Expr<'tcx>,
|
||||||
|
@ -316,11 +316,11 @@ fn is_mixed_projection_predicate<'tcx>(
|
||||||
&& (term_param_ty.index as usize) < generics.parent_count
|
&& (term_param_ty.index as usize) < generics.parent_count
|
||||||
{
|
{
|
||||||
// The inner-most self type is a type parameter from the current function.
|
// The inner-most self type is a type parameter from the current function.
|
||||||
let mut projection_ty = projection_predicate.projection_ty;
|
let mut projection_term = projection_predicate.projection_term;
|
||||||
loop {
|
loop {
|
||||||
match projection_ty.self_ty().kind() {
|
match *projection_term.self_ty().kind() {
|
||||||
ty::Alias(ty::Projection, inner_projection_ty) => {
|
ty::Alias(ty::Projection, inner_projection_ty) => {
|
||||||
projection_ty = *inner_projection_ty;
|
projection_term = inner_projection_ty.into();
|
||||||
},
|
},
|
||||||
ty::Param(param_ty) => {
|
ty::Param(param_ty) => {
|
||||||
return (param_ty.index as usize) >= generics.parent_count;
|
return (param_ty.index as usize) >= generics.parent_count;
|
||||||
|
@ -369,14 +369,15 @@ fn replace_types<'tcx>(
|
||||||
// The `replaced.insert(...)` check provides some protection against infinite loops.
|
// The `replaced.insert(...)` check provides some protection against infinite loops.
|
||||||
if replaced.insert(param_ty.index) {
|
if replaced.insert(param_ty.index) {
|
||||||
for projection_predicate in projection_predicates {
|
for projection_predicate in projection_predicates {
|
||||||
if projection_predicate.projection_ty.self_ty() == param_ty.to_ty(cx.tcx)
|
if projection_predicate.projection_term.self_ty() == param_ty.to_ty(cx.tcx)
|
||||||
&& let Some(term_ty) = projection_predicate.term.ty()
|
&& let Some(term_ty) = projection_predicate.term.ty()
|
||||||
&& let ty::Param(term_param_ty) = term_ty.kind()
|
&& let ty::Param(term_param_ty) = term_ty.kind()
|
||||||
{
|
{
|
||||||
let projection = cx.tcx.mk_ty_from_kind(ty::Alias(
|
let projection = projection_predicate
|
||||||
ty::Projection,
|
.projection_term
|
||||||
projection_predicate.projection_ty.with_self_ty(cx.tcx, new_ty),
|
.with_self_ty(cx.tcx, new_ty)
|
||||||
));
|
.expect_ty(cx.tcx)
|
||||||
|
.to_ty(cx.tcx);
|
||||||
|
|
||||||
if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection)
|
if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection)
|
||||||
&& args[term_param_ty.index as usize] != GenericArg::from(projected_ty)
|
&& args[term_param_ty.index as usize] != GenericArg::from(projected_ty)
|
||||||
|
|
|
@ -11,7 +11,6 @@ use rustc_hir::{
|
||||||
PatKind,
|
PatKind,
|
||||||
};
|
};
|
||||||
use rustc_hir_typeck::expr_use_visitor as euv;
|
use rustc_hir_typeck::expr_use_visitor as euv;
|
||||||
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::mir::FakeReadCause;
|
use rustc_middle::mir::FakeReadCause;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt, UpvarId, UpvarPath};
|
use rustc_middle::ty::{self, Ty, TyCtxt, UpvarId, UpvarPath};
|
||||||
|
@ -102,7 +101,6 @@ fn should_skip<'tcx>(
|
||||||
fn check_closures<'tcx>(
|
fn check_closures<'tcx>(
|
||||||
ctx: &mut MutablyUsedVariablesCtxt<'tcx>,
|
ctx: &mut MutablyUsedVariablesCtxt<'tcx>,
|
||||||
cx: &LateContext<'tcx>,
|
cx: &LateContext<'tcx>,
|
||||||
infcx: &InferCtxt<'tcx>,
|
|
||||||
checked_closures: &mut FxHashSet<LocalDefId>,
|
checked_closures: &mut FxHashSet<LocalDefId>,
|
||||||
closures: FxHashSet<LocalDefId>,
|
closures: FxHashSet<LocalDefId>,
|
||||||
) {
|
) {
|
||||||
|
@ -119,7 +117,9 @@ fn check_closures<'tcx>(
|
||||||
.associated_body()
|
.associated_body()
|
||||||
.map(|(_, body_id)| hir.body(body_id))
|
.map(|(_, body_id)| hir.body(body_id))
|
||||||
{
|
{
|
||||||
euv::ExprUseVisitor::new(ctx, infcx, closure, cx.param_env, cx.typeck_results()).consume_body(body);
|
euv::ExprUseVisitor::for_clippy(cx, closure, &mut *ctx)
|
||||||
|
.consume_body(body)
|
||||||
|
.into_ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,8 +196,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
|
||||||
async_closures: FxHashSet::default(),
|
async_closures: FxHashSet::default(),
|
||||||
tcx: cx.tcx,
|
tcx: cx.tcx,
|
||||||
};
|
};
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx)
|
||||||
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
|
.consume_body(body)
|
||||||
|
.into_ok();
|
||||||
|
|
||||||
let mut checked_closures = FxHashSet::default();
|
let mut checked_closures = FxHashSet::default();
|
||||||
|
|
||||||
|
@ -210,13 +211,13 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
|
||||||
}
|
}
|
||||||
ControlFlow::<()>::Continue(())
|
ControlFlow::<()>::Continue(())
|
||||||
});
|
});
|
||||||
check_closures(&mut ctx, cx, &infcx, &mut checked_closures, closures);
|
check_closures(&mut ctx, cx, &mut checked_closures, closures);
|
||||||
|
|
||||||
if is_async {
|
if is_async {
|
||||||
while !ctx.async_closures.is_empty() {
|
while !ctx.async_closures.is_empty() {
|
||||||
let async_closures = ctx.async_closures.clone();
|
let async_closures = ctx.async_closures.clone();
|
||||||
ctx.async_closures.clear();
|
ctx.async_closures.clear();
|
||||||
check_closures(&mut ctx, cx, &infcx, &mut checked_closures, async_closures);
|
check_closures(&mut ctx, cx, &mut checked_closures, async_closures);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.generate_mutably_used_ids_from_aliases()
|
ctx.generate_mutably_used_ids_from_aliases()
|
||||||
|
|
|
@ -13,7 +13,6 @@ use rustc_hir::{
|
||||||
TyKind,
|
TyKind,
|
||||||
};
|
};
|
||||||
use rustc_hir_typeck::expr_use_visitor as euv;
|
use rustc_hir_typeck::expr_use_visitor as euv;
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::mir::FakeReadCause;
|
use rustc_middle::mir::FakeReadCause;
|
||||||
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
||||||
|
@ -134,8 +133,9 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
|
||||||
// function body.
|
// function body.
|
||||||
let MovedVariablesCtxt { moved_vars } = {
|
let MovedVariablesCtxt { moved_vars } = {
|
||||||
let mut ctx = MovedVariablesCtxt::default();
|
let mut ctx = MovedVariablesCtxt::default();
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx)
|
||||||
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
|
.consume_body(body)
|
||||||
|
.into_ok();
|
||||||
ctx
|
ctx
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, Pl
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::mir::FakeReadCause;
|
use rustc_middle::mir::FakeReadCause;
|
||||||
use rustc_middle::ty::BorrowKind;
|
use rustc_middle::ty::BorrowKind;
|
||||||
use rustc_trait_selection::infer::TyCtxtInferExt;
|
|
||||||
|
|
||||||
use super::ASSIGN_OP_PATTERN;
|
use super::ASSIGN_OP_PATTERN;
|
||||||
|
|
||||||
|
@ -119,15 +118,8 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut s = S(HirIdSet::default());
|
let mut s = S(HirIdSet::default());
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
let v = ExprUseVisitor::for_clippy(cx, e.hir_id.owner.def_id, &mut s);
|
||||||
let mut v = ExprUseVisitor::new(
|
v.consume_expr(e).into_ok();
|
||||||
&mut s,
|
|
||||||
&infcx,
|
|
||||||
cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
|
|
||||||
cx.param_env,
|
|
||||||
cx.typeck_results(),
|
|
||||||
);
|
|
||||||
v.consume_expr(e);
|
|
||||||
s.0
|
s.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,14 +143,7 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut s = S(HirIdSet::default());
|
let mut s = S(HirIdSet::default());
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
let v = ExprUseVisitor::for_clippy(cx, e.hir_id.owner.def_id, &mut s);
|
||||||
let mut v = ExprUseVisitor::new(
|
v.consume_expr(e).into_ok();
|
||||||
&mut s,
|
|
||||||
&infcx,
|
|
||||||
cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
|
|
||||||
cx.param_env,
|
|
||||||
cx.typeck_results(),
|
|
||||||
);
|
|
||||||
v.consume_expr(e);
|
|
||||||
s.0
|
s.0
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ fn check_op(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left: bool)
|
||||||
let without_deref = symmetric_partial_eq(cx, arg_ty, other_ty).unwrap_or_default();
|
let without_deref = symmetric_partial_eq(cx, arg_ty, other_ty).unwrap_or_default();
|
||||||
let with_deref = arg_ty
|
let with_deref = arg_ty
|
||||||
.builtin_deref(true)
|
.builtin_deref(true)
|
||||||
.and_then(|tam| symmetric_partial_eq(cx, tam.ty, other_ty))
|
.and_then(|ty| symmetric_partial_eq(cx, ty, other_ty))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
if !with_deref.is_implemented() && !without_deref.is_implemented() {
|
if !with_deref.is_implemented() && !without_deref.is_implemented() {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::rustc_lint::LintContext;
|
|
||||||
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir};
|
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir};
|
||||||
use clippy_utils::get_parent_expr;
|
use clippy_utils::get_parent_expr;
|
||||||
use clippy_utils::sugg::Sugg;
|
use clippy_utils::sugg::Sugg;
|
||||||
|
@ -9,7 +8,7 @@ use rustc_hir::intravisit::{Visitor as HirVisitor, Visitor};
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
intravisit as hir_visit, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, ExprKind, Node,
|
intravisit as hir_visit, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, ExprKind, Node,
|
||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use crate::rustc_lint::LintContext;
|
|
||||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||||
use clippy_utils::source::snippet_with_context;
|
use clippy_utils::source::snippet_with_context;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{Block, ExprKind};
|
use rustc_hir::{Block, ExprKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
use rustc_span::{ExpnKind, MacroKind, Span};
|
use rustc_span::{ExpnKind, MacroKind, Span};
|
||||||
|
|
||||||
|
|
|
@ -201,8 +201,8 @@ impl SingleComponentPathImports {
|
||||||
|
|
||||||
if segments.is_empty() {
|
if segments.is_empty() {
|
||||||
// keep track of `use {some_module, some_other_module};` usages
|
// keep track of `use {some_module, some_other_module};` usages
|
||||||
if let UseTreeKind::Nested(trees) = &use_tree.kind {
|
if let UseTreeKind::Nested { items, .. } = &use_tree.kind {
|
||||||
for tree in trees {
|
for tree in items {
|
||||||
let segments = &tree.0.prefix.segments;
|
let segments = &tree.0.prefix.segments;
|
||||||
if segments.len() == 1 {
|
if segments.len() == 1 {
|
||||||
if let UseTreeKind::Simple(None) = tree.0.kind {
|
if let UseTreeKind::Simple(None) = tree.0.kind {
|
||||||
|
@ -229,8 +229,8 @@ impl SingleComponentPathImports {
|
||||||
}
|
}
|
||||||
|
|
||||||
// nested case such as `use self::{module1::Struct1, module2::Struct2}`
|
// nested case such as `use self::{module1::Struct1, module2::Struct2}`
|
||||||
if let UseTreeKind::Nested(trees) = &use_tree.kind {
|
if let UseTreeKind::Nested { items, .. } = &use_tree.kind {
|
||||||
for tree in trees {
|
for tree in items {
|
||||||
let segments = &tree.0.prefix.segments;
|
let segments = &tree.0.prefix.segments;
|
||||||
if !segments.is_empty() {
|
if !segments.is_empty() {
|
||||||
imports_reused_with_self.push(segments[0].ident.name);
|
imports_reused_with_self.push(segments[0].ident.name);
|
||||||
|
|
|
@ -87,7 +87,7 @@ pub(super) fn check<'tcx>(
|
||||||
&& is_normalizable(cx, cx.param_env, from_ty)
|
&& is_normalizable(cx, cx.param_env, from_ty)
|
||||||
&& is_normalizable(cx, cx.param_env, to_ty)
|
&& is_normalizable(cx, cx.param_env, to_ty)
|
||||||
// we only want to lint if the target type has a niche that is larger than the one of the source type
|
// we only want to lint if the target type has a niche that is larger than the one of the source type
|
||||||
// e.g. `u8` to `NonZeroU8` should lint, but `NonZeroU8` to `u8` should not
|
// e.g. `u8` to `NonZero<u8>` should lint, but `NonZero<u8>` to `u8` should not
|
||||||
&& let Ok(from_layout) = cx.tcx.layout_of(cx.param_env.and(from_ty))
|
&& let Ok(from_layout) = cx.tcx.layout_of(cx.param_env.and(from_ty))
|
||||||
&& let Ok(to_layout) = cx.tcx.layout_of(cx.param_env.and(to_ty))
|
&& let Ok(to_layout) = cx.tcx.layout_of(cx.param_env.and(to_ty))
|
||||||
&& match (from_layout.largest_niche, to_layout.largest_niche) {
|
&& match (from_layout.largest_niche, to_layout.largest_niche) {
|
||||||
|
|
|
@ -257,7 +257,7 @@ declare_clippy_lint! {
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// ### What it does
|
/// ### What it does
|
||||||
/// Checks for transmutes from integers to `NonZero*` types, and suggests their `new_unchecked`
|
/// Checks for transmutes from `T` to `NonZero<T>`, and suggests the `new_unchecked`
|
||||||
/// method instead.
|
/// method instead.
|
||||||
///
|
///
|
||||||
/// ### Why is this bad?
|
/// ### Why is this bad?
|
||||||
|
@ -266,13 +266,13 @@ declare_clippy_lint! {
|
||||||
///
|
///
|
||||||
/// ### Example
|
/// ### Example
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use core::num::NonZeroU32;
|
/// # use core::num::NonZero;
|
||||||
/// let _non_zero: NonZeroU32 = unsafe { std::mem::transmute(123) };
|
/// let _: NonZero<u32> = unsafe { std::mem::transmute(123) };
|
||||||
/// ```
|
/// ```
|
||||||
/// Use instead:
|
/// Use instead:
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use core::num::NonZeroU32;
|
/// # use core::num::NonZero;
|
||||||
/// let _non_zero = unsafe { NonZeroU32::new_unchecked(123) };
|
/// let _: NonZero<u32> = unsafe { NonZero::new_unchecked(123) };
|
||||||
/// ```
|
/// ```
|
||||||
#[clippy::version = "1.69.0"]
|
#[clippy::version = "1.69.0"]
|
||||||
pub TRANSMUTE_INT_TO_NON_ZERO,
|
pub TRANSMUTE_INT_TO_NON_ZERO,
|
||||||
|
|
|
@ -26,45 +26,22 @@ pub(super) fn check<'tcx>(
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME: This can be simplified once `NonZero<T>` is stable.
|
let int_ty = substs.type_at(0);
|
||||||
let coercible_types = [
|
if from_ty != int_ty {
|
||||||
("NonZeroU8", tcx.types.u8),
|
|
||||||
("NonZeroU16", tcx.types.u16),
|
|
||||||
("NonZeroU32", tcx.types.u32),
|
|
||||||
("NonZeroU64", tcx.types.u64),
|
|
||||||
("NonZeroU128", tcx.types.u128),
|
|
||||||
("NonZeroUsize", tcx.types.usize),
|
|
||||||
("NonZeroI8", tcx.types.i8),
|
|
||||||
("NonZeroI16", tcx.types.i16),
|
|
||||||
("NonZeroI32", tcx.types.i32),
|
|
||||||
("NonZeroI64", tcx.types.i64),
|
|
||||||
("NonZeroI128", tcx.types.i128),
|
|
||||||
("NonZeroIsize", tcx.types.isize),
|
|
||||||
];
|
|
||||||
|
|
||||||
let int_type = substs.type_at(0);
|
|
||||||
|
|
||||||
let Some(nonzero_alias) = coercible_types.iter().find_map(|(nonzero_alias, t)| {
|
|
||||||
if *t == int_type && *t == from_ty {
|
|
||||||
Some(nonzero_alias)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}) else {
|
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
span_lint_and_then(
|
span_lint_and_then(
|
||||||
cx,
|
cx,
|
||||||
TRANSMUTE_INT_TO_NON_ZERO,
|
TRANSMUTE_INT_TO_NON_ZERO,
|
||||||
e.span,
|
e.span,
|
||||||
format!("transmute from a `{from_ty}` to a `{nonzero_alias}`"),
|
format!("transmute from a `{from_ty}` to a `{}<{int_ty}>`", sym::NonZero),
|
||||||
|diag| {
|
|diag| {
|
||||||
let arg = sugg::Sugg::hir(cx, arg, "..");
|
let arg = sugg::Sugg::hir(cx, arg, "..");
|
||||||
diag.span_suggestion(
|
diag.span_suggestion(
|
||||||
e.span,
|
e.span,
|
||||||
"consider using",
|
"consider using",
|
||||||
format!("{nonzero_alias}::{}({arg})", sym::new_unchecked),
|
format!("{}::{}({arg})", sym::NonZero, sym::new_unchecked),
|
||||||
Applicability::Unspecified,
|
Applicability::Unspecified,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -66,7 +66,7 @@ fn get_projection_pred<'tcx>(
|
||||||
let projection_pred = cx
|
let projection_pred = cx
|
||||||
.tcx
|
.tcx
|
||||||
.instantiate_bound_regions_with_erased(proj_pred.kind().rebind(pred));
|
.instantiate_bound_regions_with_erased(proj_pred.kind().rebind(pred));
|
||||||
if projection_pred.projection_ty.args == trait_pred.trait_ref.args {
|
if projection_pred.projection_term.args == trait_pred.trait_ref.args {
|
||||||
return Some(projection_pred);
|
return Some(projection_pred);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,8 @@ declare_lint_pass!(UnnecessarySelfImports => [UNNECESSARY_SELF_IMPORTS]);
|
||||||
impl EarlyLintPass for UnnecessarySelfImports {
|
impl EarlyLintPass for UnnecessarySelfImports {
|
||||||
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
|
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
|
||||||
if let ItemKind::Use(use_tree) = &item.kind
|
if let ItemKind::Use(use_tree) = &item.kind
|
||||||
&& let UseTreeKind::Nested(nodes) = &use_tree.kind
|
&& let UseTreeKind::Nested { items, .. } = &use_tree.kind
|
||||||
&& let [(self_tree, _)] = &**nodes
|
&& let [(self_tree, _)] = &**items
|
||||||
&& let [self_seg] = &*self_tree.prefix.segments
|
&& let [self_seg] = &*self_tree.prefix.segments
|
||||||
&& self_seg.ident.name == kw::SelfLower
|
&& self_seg.ident.name == kw::SelfLower
|
||||||
&& let Some(last_segment) = use_tree.prefix.segments.last()
|
&& let Some(last_segment) = use_tree.prefix.segments.last()
|
||||||
|
|
|
@ -49,8 +49,8 @@ fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) {
|
||||||
unsafe_to_safe_check(old_name, new_name, cx, span);
|
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) => {
|
UseTreeKind::Nested { ref items, .. } => {
|
||||||
for (use_tree, _) in nested_use_tree {
|
for (use_tree, _) in items {
|
||||||
check_use_tree(use_tree, cx, span);
|
check_use_tree(use_tree, cx, span);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,6 @@ use rustc_errors::Applicability;
|
||||||
use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, Visitor};
|
use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, Visitor};
|
||||||
use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, Node, PathSegment, UnOp};
|
use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, Node, PathSegment, UnOp};
|
||||||
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceWithHirId};
|
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceWithHirId};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
|
@ -252,16 +251,9 @@ impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> {
|
||||||
local_id: unwrap_info.local_id,
|
local_id: unwrap_info.local_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let infcx = self.cx.tcx.infer_ctxt().build();
|
let vis = ExprUseVisitor::for_clippy(self.cx, cond.hir_id.owner.def_id, &mut delegate);
|
||||||
let mut vis = ExprUseVisitor::new(
|
vis.walk_expr(cond).into_ok();
|
||||||
&mut delegate,
|
vis.walk_expr(branch).into_ok();
|
||||||
&infcx,
|
|
||||||
cond.hir_id.owner.def_id,
|
|
||||||
self.cx.param_env,
|
|
||||||
self.cx.typeck_results(),
|
|
||||||
);
|
|
||||||
vis.walk_expr(cond);
|
|
||||||
vis.walk_expr(branch);
|
|
||||||
|
|
||||||
if delegate.is_mutated {
|
if delegate.is_mutated {
|
||||||
// if the variable is mutated, we don't know whether it can be unwrapped.
|
// if the variable is mutated, we don't know whether it can be unwrapped.
|
||||||
|
|
|
@ -648,7 +648,7 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool {
|
||||||
match (l, r) {
|
match (l, r) {
|
||||||
(Glob, Glob) => true,
|
(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)),
|
(Nested { items: l, .. }, Nested { items: r, .. }) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,7 @@ impl HirEqInterExpr<'_, '_, '_> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eq_array_length(&mut self, left: ArrayLen, right: ArrayLen) -> bool {
|
pub fn eq_array_length(&mut self, left: ArrayLen<'_>, right: ArrayLen<'_>) -> bool {
|
||||||
match (left, right) {
|
match (left, right) {
|
||||||
(ArrayLen::Infer(..), ArrayLen::Infer(..)) => true,
|
(ArrayLen::Infer(..), ArrayLen::Infer(..)) => true,
|
||||||
(ArrayLen::Body(l_ct), ArrayLen::Body(r_ct)) => self.eq_body(l_ct.body, r_ct.body),
|
(ArrayLen::Body(l_ct), ArrayLen::Body(r_ct)) => self.eq_body(l_ct.body, r_ct.body),
|
||||||
|
@ -1116,7 +1116,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash_array_length(&mut self, length: ArrayLen) {
|
pub fn hash_array_length(&mut self, length: ArrayLen<'_>) {
|
||||||
match length {
|
match length {
|
||||||
ArrayLen::Infer(..) => {},
|
ArrayLen::Infer(..) => {},
|
||||||
ArrayLen::Body(anon_const) => self.hash_body(anon_const.body),
|
ArrayLen::Body(anon_const) => self.hash_body(anon_const.body),
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(rustc_private)]
|
#![feature(rustc_private)]
|
||||||
#![feature(assert_matches)]
|
#![feature(assert_matches)]
|
||||||
|
#![feature(unwrap_infallible)]
|
||||||
#![recursion_limit = "512"]
|
#![recursion_limit = "512"]
|
||||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||||
#![allow(
|
#![allow(
|
||||||
|
|
|
@ -134,9 +134,7 @@ fn check_rvalue<'tcx>(
|
||||||
_,
|
_,
|
||||||
) => Err((span, "function pointer casts are not allowed in const fn".into())),
|
) => Err((span, "function pointer casts are not allowed in const fn".into())),
|
||||||
Rvalue::Cast(CastKind::PointerCoercion(PointerCoercion::Unsize), op, cast_ty) => {
|
Rvalue::Cast(CastKind::PointerCoercion(PointerCoercion::Unsize), op, cast_ty) => {
|
||||||
let pointee_ty = if let Some(deref_ty) = cast_ty.builtin_deref(true) {
|
let Some(pointee_ty) = cast_ty.builtin_deref(true) else {
|
||||||
deref_ty.ty
|
|
||||||
} else {
|
|
||||||
// We cannot allow this for now.
|
// We cannot allow this for now.
|
||||||
return Err((span, "unsizing casts are only allowed for references right now".into()));
|
return Err((span, "unsizing casts are only allowed for references right now".into()));
|
||||||
};
|
};
|
||||||
|
@ -414,7 +412,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx>
|
||||||
tcx,
|
tcx,
|
||||||
ObligationCause::dummy_with_span(body.span),
|
ObligationCause::dummy_with_span(body.span),
|
||||||
ConstCx::new(tcx, body).param_env,
|
ConstCx::new(tcx, body).param_env,
|
||||||
TraitRef::from_lang_item(tcx, LangItem::Destruct, body.span, [ty]),
|
TraitRef::new(tcx, tcx.require_lang_item(LangItem::Destruct, Some(body.span)), [ty]),
|
||||||
);
|
);
|
||||||
|
|
||||||
let infcx = tcx.infer_ctxt().build();
|
let infcx = tcx.infer_ctxt().build();
|
||||||
|
|
|
@ -11,7 +11,6 @@ use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::{Closure, ExprKind, HirId, MutTy, TyKind};
|
use rustc_hir::{Closure, ExprKind, HirId, MutTy, TyKind};
|
||||||
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
|
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
|
||||||
use rustc_lint::{EarlyContext, LateContext, LintContext};
|
use rustc_lint::{EarlyContext, LateContext, LintContext};
|
||||||
use rustc_middle::hir::place::ProjectionKind;
|
use rustc_middle::hir::place::ProjectionKind;
|
||||||
use rustc_middle::mir::{FakeReadCause, Mutability};
|
use rustc_middle::mir::{FakeReadCause, Mutability};
|
||||||
|
@ -830,8 +829,9 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti
|
||||||
applicability: Applicability::MachineApplicable,
|
applicability: Applicability::MachineApplicable,
|
||||||
};
|
};
|
||||||
|
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
ExprUseVisitor::for_clippy(cx, def_id, &mut visitor)
|
||||||
ExprUseVisitor::new(&mut visitor, &infcx, def_id, cx.param_env, cx.typeck_results()).consume_body(closure_body);
|
.consume_body(closure_body)
|
||||||
|
.into_ok();
|
||||||
|
|
||||||
if !visitor.suggestion_start.is_empty() {
|
if !visitor.suggestion_start.is_empty() {
|
||||||
return Some(DerefClosure {
|
return Some(DerefClosure {
|
||||||
|
|
|
@ -10,7 +10,6 @@ use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::{Expr, FnDecl, LangItem, TyKind, Unsafety};
|
use rustc_hir::{Expr, FnDecl, LangItem, TyKind, Unsafety};
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
use rustc_infer::infer::TyCtxtInferExt;
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::mir::interpret::Scalar;
|
use rustc_middle::mir::interpret::Scalar;
|
||||||
|
@ -19,8 +18,8 @@ use rustc_middle::traits::EvaluationResult;
|
||||||
use rustc_middle::ty::layout::ValidityRequirement;
|
use rustc_middle::ty::layout::ValidityRequirement;
|
||||||
use rustc_middle::ty::{
|
use rustc_middle::ty::{
|
||||||
self, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, FnSig, GenericArg, GenericArgKind, GenericArgsRef,
|
self, AdtDef, AliasTy, AssocKind, Binder, BoundRegion, FnSig, GenericArg, GenericArgKind, GenericArgsRef,
|
||||||
GenericParamDefKind, IntTy, List, ParamEnv, Region, RegionKind, ToPredicate, TraitRef, Ty, TyCtxt,
|
GenericParamDefKind, IntTy, ParamEnv, Region, RegionKind, ToPredicate, TraitRef, Ty, TyCtxt, TypeSuperVisitable,
|
||||||
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, UintTy, VariantDef, VariantDiscr,
|
TypeVisitable, TypeVisitableExt, TypeVisitor, UintTy, VariantDef, VariantDiscr,
|
||||||
};
|
};
|
||||||
use rustc_span::symbol::Ident;
|
use rustc_span::symbol::Ident;
|
||||||
use rustc_span::{sym, Span, Symbol, DUMMY_SP};
|
use rustc_span::{sym, Span, Symbol, DUMMY_SP};
|
||||||
|
@ -274,15 +273,7 @@ pub fn implements_trait_with_env_from_iter<'tcx>(
|
||||||
let infcx = tcx.infer_ctxt().build();
|
let infcx = tcx.infer_ctxt().build();
|
||||||
let args = args
|
let args = args
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|arg| {
|
.map(|arg| arg.into().unwrap_or_else(|| infcx.next_ty_var(DUMMY_SP).into()))
|
||||||
arg.into().unwrap_or_else(|| {
|
|
||||||
let orig = TypeVariableOrigin {
|
|
||||||
span: DUMMY_SP,
|
|
||||||
param_def_id: None,
|
|
||||||
};
|
|
||||||
infcx.next_ty_var(orig).into()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
// If an effect arg was not specified, we need to specify it.
|
// If an effect arg was not specified, we need to specify it.
|
||||||
|
@ -800,7 +791,8 @@ fn sig_from_bounds<'tcx>(
|
||||||
inputs = Some(i);
|
inputs = Some(i);
|
||||||
},
|
},
|
||||||
ty::ClauseKind::Projection(p)
|
ty::ClauseKind::Projection(p)
|
||||||
if Some(p.projection_ty.def_id) == lang_items.fn_once_output() && p.projection_ty.self_ty() == ty =>
|
if Some(p.projection_term.def_id) == lang_items.fn_once_output()
|
||||||
|
&& p.projection_term.self_ty() == ty =>
|
||||||
{
|
{
|
||||||
if output.is_some() {
|
if output.is_some() {
|
||||||
// Multiple different fn trait impls. Is this even allowed?
|
// Multiple different fn trait impls. Is this even allowed?
|
||||||
|
@ -839,7 +831,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option
|
||||||
}
|
}
|
||||||
inputs = Some(i);
|
inputs = Some(i);
|
||||||
},
|
},
|
||||||
ty::ClauseKind::Projection(p) if Some(p.projection_ty.def_id) == lang_items.fn_once_output() => {
|
ty::ClauseKind::Projection(p) if Some(p.projection_term.def_id) == lang_items.fn_once_output() => {
|
||||||
if output.is_some() {
|
if output.is_some() {
|
||||||
// Multiple different fn trait impls. Is this even allowed?
|
// Multiple different fn trait impls. Is this even allowed?
|
||||||
return None;
|
return None;
|
||||||
|
@ -961,7 +953,7 @@ pub struct AdtVariantInfo {
|
||||||
|
|
||||||
impl AdtVariantInfo {
|
impl AdtVariantInfo {
|
||||||
/// Returns ADT variants ordered by size
|
/// Returns ADT variants ordered by size
|
||||||
pub fn new<'tcx>(cx: &LateContext<'tcx>, adt: AdtDef<'tcx>, subst: &'tcx List<GenericArg<'tcx>>) -> Vec<Self> {
|
pub fn new<'tcx>(cx: &LateContext<'tcx>, adt: AdtDef<'tcx>, subst: GenericArgsRef<'tcx>) -> Vec<Self> {
|
||||||
let mut variants_size = adt
|
let mut variants_size = adt
|
||||||
.variants()
|
.variants()
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1070,11 +1062,11 @@ pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 {
|
||||||
fn assert_generic_args_match<'tcx>(tcx: TyCtxt<'tcx>, did: DefId, args: &[GenericArg<'tcx>]) {
|
fn assert_generic_args_match<'tcx>(tcx: TyCtxt<'tcx>, did: DefId, args: &[GenericArg<'tcx>]) {
|
||||||
let g = tcx.generics_of(did);
|
let g = tcx.generics_of(did);
|
||||||
let parent = g.parent.map(|did| tcx.generics_of(did));
|
let parent = g.parent.map(|did| tcx.generics_of(did));
|
||||||
let count = g.parent_count + g.params.len();
|
let count = g.parent_count + g.own_params.len();
|
||||||
let params = parent
|
let params = parent
|
||||||
.map_or([].as_slice(), |p| p.params.as_slice())
|
.map_or([].as_slice(), |p| p.own_params.as_slice())
|
||||||
.iter()
|
.iter()
|
||||||
.chain(&g.params)
|
.chain(&g.own_params)
|
||||||
.map(|x| &x.kind);
|
.map(|x| &x.kind);
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
|
|
|
@ -176,7 +176,7 @@ fn qpath_certainty(cx: &LateContext<'_>, qpath: &QPath<'_>, resolves_to_type: bo
|
||||||
.get(*lang_item)
|
.get(*lang_item)
|
||||||
.map_or(Certainty::Uncertain, |def_id| {
|
.map_or(Certainty::Uncertain, |def_id| {
|
||||||
let generics = cx.tcx.generics_of(def_id);
|
let generics = cx.tcx.generics_of(def_id);
|
||||||
if generics.parent_count == 0 && generics.params.is_empty() {
|
if generics.parent_count == 0 && generics.own_params.is_empty() {
|
||||||
Certainty::Certain(if resolves_to_type { Some(def_id) } else { None })
|
Certainty::Certain(if resolves_to_type { Some(def_id) } else { None })
|
||||||
} else {
|
} else {
|
||||||
Certainty::Uncertain
|
Certainty::Uncertain
|
||||||
|
@ -206,7 +206,7 @@ fn path_segment_certainty(
|
||||||
// Checking `res_generics_def_id(..)` before calling `generics_of` avoids an ICE.
|
// Checking `res_generics_def_id(..)` before calling `generics_of` avoids an ICE.
|
||||||
if cx.tcx.res_generics_def_id(path_segment.res).is_some() {
|
if cx.tcx.res_generics_def_id(path_segment.res).is_some() {
|
||||||
let generics = cx.tcx.generics_of(def_id);
|
let generics = cx.tcx.generics_of(def_id);
|
||||||
let count = generics.params.len() - usize::from(generics.host_effect_index.is_some());
|
let count = generics.own_params.len() - usize::from(generics.host_effect_index.is_some());
|
||||||
let lhs = if (parent_certainty.is_certain() || generics.parent_count == 0) && count == 0 {
|
let lhs = if (parent_certainty.is_certain() || generics.parent_count == 0) && count == 0 {
|
||||||
Certainty::Certain(None)
|
Certainty::Certain(None)
|
||||||
} else {
|
} else {
|
||||||
|
@ -299,7 +299,7 @@ fn type_is_inferable_from_arguments(cx: &LateContext<'_>, expr: &Expr<'_>) -> bo
|
||||||
let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder();
|
let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder();
|
||||||
|
|
||||||
// Check that all type parameters appear in the functions input types.
|
// Check that all type parameters appear in the functions input types.
|
||||||
(0..(generics.parent_count + generics.params.len()) as u32).all(|index| {
|
(0..(generics.parent_count + generics.own_params.len()) as u32).all(|index| {
|
||||||
Some(index as usize) == generics.host_effect_index
|
Some(index as usize) == generics.host_effect_index
|
||||||
|| fn_sig
|
|| fn_sig
|
||||||
.inputs()
|
.inputs()
|
||||||
|
|
|
@ -5,7 +5,6 @@ use hir::def::Res;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::{self as hir, Expr, ExprKind, HirId, HirIdSet};
|
use rustc_hir::{self as hir, Expr, ExprKind, HirId, HirIdSet};
|
||||||
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, Place, PlaceBase, PlaceWithHirId};
|
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, Place, PlaceBase, PlaceWithHirId};
|
||||||
use rustc_infer::infer::TyCtxtInferExt;
|
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
use rustc_middle::mir::FakeReadCause;
|
use rustc_middle::mir::FakeReadCause;
|
||||||
|
@ -17,15 +16,9 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) ->
|
||||||
used_mutably: HirIdSet::default(),
|
used_mutably: HirIdSet::default(),
|
||||||
skip: false,
|
skip: false,
|
||||||
};
|
};
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
ExprUseVisitor::for_clippy(cx, expr.hir_id.owner.def_id, &mut delegate)
|
||||||
ExprUseVisitor::new(
|
.walk_expr(expr)
|
||||||
&mut delegate,
|
.into_ok();
|
||||||
&infcx,
|
|
||||||
expr.hir_id.owner.def_id,
|
|
||||||
cx.param_env,
|
|
||||||
cx.typeck_results(),
|
|
||||||
)
|
|
||||||
.walk_expr(expr);
|
|
||||||
|
|
||||||
if delegate.skip {
|
if delegate.skip {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZero;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Parser)]
|
#[derive(Clone, Debug, Parser)]
|
||||||
|
@ -61,7 +61,7 @@ impl LintcheckConfig {
|
||||||
config.max_jobs = if config.fix || config.recursive {
|
config.max_jobs = if config.fix || config.recursive {
|
||||||
1
|
1
|
||||||
} else {
|
} else {
|
||||||
std::thread::available_parallelism().map_or(1, NonZeroUsize::get)
|
std::thread::available_parallelism().map_or(1, NonZero::get)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "nightly-2024-05-02"
|
channel = "nightly-2024-05-16"
|
||||||
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
|
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//@edition:2018
|
//@edition:2018
|
||||||
//@aux-build:proc_macros.rs
|
//@aux-build:proc_macros.rs
|
||||||
|
|
||||||
#![feature(exclusive_range_pattern)]
|
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
#![warn(clippy::almost_complete_range)]
|
#![warn(clippy::almost_complete_range)]
|
||||||
#![allow(ellipsis_inclusive_range_patterns)]
|
#![allow(ellipsis_inclusive_range_patterns)]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//@edition:2018
|
//@edition:2018
|
||||||
//@aux-build:proc_macros.rs
|
//@aux-build:proc_macros.rs
|
||||||
|
|
||||||
#![feature(exclusive_range_pattern)]
|
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
#![warn(clippy::almost_complete_range)]
|
#![warn(clippy::almost_complete_range)]
|
||||||
#![allow(ellipsis_inclusive_range_patterns)]
|
#![allow(ellipsis_inclusive_range_patterns)]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:18:17
|
--> tests/ui/almost_complete_range.rs:17:17
|
||||||
|
|
|
|
||||||
LL | let _ = ('a') ..'z';
|
LL | let _ = ('a') ..'z';
|
||||||
| ^^^^^^--^^^
|
| ^^^^^^--^^^
|
||||||
|
@ -10,7 +10,7 @@ LL | let _ = ('a') ..'z';
|
||||||
= help: to override `-D warnings` add `#[allow(clippy::almost_complete_range)]`
|
= help: to override `-D warnings` add `#[allow(clippy::almost_complete_range)]`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:19:17
|
--> tests/ui/almost_complete_range.rs:18:17
|
||||||
|
|
|
|
||||||
LL | let _ = 'A' .. ('Z');
|
LL | let _ = 'A' .. ('Z');
|
||||||
| ^^^^--^^^^^^
|
| ^^^^--^^^^^^
|
||||||
|
@ -18,7 +18,7 @@ LL | let _ = 'A' .. ('Z');
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:20:17
|
--> tests/ui/almost_complete_range.rs:19:17
|
||||||
|
|
|
|
||||||
LL | let _ = ((('0'))) .. ('9');
|
LL | let _ = ((('0'))) .. ('9');
|
||||||
| ^^^^^^^^^^--^^^^^^
|
| ^^^^^^^^^^--^^^^^^
|
||||||
|
@ -26,7 +26,7 @@ LL | let _ = ((('0'))) .. ('9');
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:27:13
|
--> tests/ui/almost_complete_range.rs:26:13
|
||||||
|
|
|
|
||||||
LL | let _ = (b'a')..(b'z');
|
LL | let _ = (b'a')..(b'z');
|
||||||
| ^^^^^^--^^^^^^
|
| ^^^^^^--^^^^^^
|
||||||
|
@ -34,7 +34,7 @@ LL | let _ = (b'a')..(b'z');
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:28:13
|
--> tests/ui/almost_complete_range.rs:27:13
|
||||||
|
|
|
|
||||||
LL | let _ = b'A'..b'Z';
|
LL | let _ = b'A'..b'Z';
|
||||||
| ^^^^--^^^^
|
| ^^^^--^^^^
|
||||||
|
@ -42,7 +42,7 @@ LL | let _ = b'A'..b'Z';
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:29:13
|
--> tests/ui/almost_complete_range.rs:28:13
|
||||||
|
|
|
|
||||||
LL | let _ = b'0'..b'9';
|
LL | let _ = b'0'..b'9';
|
||||||
| ^^^^--^^^^
|
| ^^^^--^^^^
|
||||||
|
@ -50,7 +50,7 @@ LL | let _ = b'0'..b'9';
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:35:13
|
--> tests/ui/almost_complete_range.rs:34:13
|
||||||
|
|
|
|
||||||
LL | let _ = inline!('a')..'z';
|
LL | let _ = inline!('a')..'z';
|
||||||
| ^^^^^^^^^^^^--^^^
|
| ^^^^^^^^^^^^--^^^
|
||||||
|
@ -58,7 +58,7 @@ LL | let _ = inline!('a')..'z';
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:36:13
|
--> tests/ui/almost_complete_range.rs:35:13
|
||||||
|
|
|
|
||||||
LL | let _ = inline!('A')..'Z';
|
LL | let _ = inline!('A')..'Z';
|
||||||
| ^^^^^^^^^^^^--^^^
|
| ^^^^^^^^^^^^--^^^
|
||||||
|
@ -66,7 +66,7 @@ LL | let _ = inline!('A')..'Z';
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:37:13
|
--> tests/ui/almost_complete_range.rs:36:13
|
||||||
|
|
|
|
||||||
LL | let _ = inline!('0')..'9';
|
LL | let _ = inline!('0')..'9';
|
||||||
| ^^^^^^^^^^^^--^^^
|
| ^^^^^^^^^^^^--^^^
|
||||||
|
@ -74,7 +74,7 @@ LL | let _ = inline!('0')..'9';
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:40:9
|
--> tests/ui/almost_complete_range.rs:39:9
|
||||||
|
|
|
|
||||||
LL | b'a'..b'z' if true => 1,
|
LL | b'a'..b'z' if true => 1,
|
||||||
| ^^^^--^^^^
|
| ^^^^--^^^^
|
||||||
|
@ -82,7 +82,7 @@ LL | b'a'..b'z' if true => 1,
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:41:9
|
--> tests/ui/almost_complete_range.rs:40:9
|
||||||
|
|
|
|
||||||
LL | b'A'..b'Z' if true => 2,
|
LL | b'A'..b'Z' if true => 2,
|
||||||
| ^^^^--^^^^
|
| ^^^^--^^^^
|
||||||
|
@ -90,7 +90,7 @@ LL | b'A'..b'Z' if true => 2,
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:42:9
|
--> tests/ui/almost_complete_range.rs:41:9
|
||||||
|
|
|
|
||||||
LL | b'0'..b'9' if true => 3,
|
LL | b'0'..b'9' if true => 3,
|
||||||
| ^^^^--^^^^
|
| ^^^^--^^^^
|
||||||
|
@ -98,7 +98,7 @@ LL | b'0'..b'9' if true => 3,
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:50:9
|
--> tests/ui/almost_complete_range.rs:49:9
|
||||||
|
|
|
|
||||||
LL | 'a'..'z' if true => 1,
|
LL | 'a'..'z' if true => 1,
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -106,7 +106,7 @@ LL | 'a'..'z' if true => 1,
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:51:9
|
--> tests/ui/almost_complete_range.rs:50:9
|
||||||
|
|
|
|
||||||
LL | 'A'..'Z' if true => 2,
|
LL | 'A'..'Z' if true => 2,
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -114,7 +114,7 @@ LL | 'A'..'Z' if true => 2,
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:52:9
|
--> tests/ui/almost_complete_range.rs:51:9
|
||||||
|
|
|
|
||||||
LL | '0'..'9' if true => 3,
|
LL | '0'..'9' if true => 3,
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -122,7 +122,7 @@ LL | '0'..'9' if true => 3,
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:65:17
|
--> tests/ui/almost_complete_range.rs:64:17
|
||||||
|
|
|
|
||||||
LL | let _ = 'a'..'z';
|
LL | let _ = 'a'..'z';
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -132,7 +132,7 @@ LL | let _ = 'a'..'z';
|
||||||
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:66:17
|
--> tests/ui/almost_complete_range.rs:65:17
|
||||||
|
|
|
|
||||||
LL | let _ = 'A'..'Z';
|
LL | let _ = 'A'..'Z';
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -142,7 +142,7 @@ LL | let _ = 'A'..'Z';
|
||||||
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:67:17
|
--> tests/ui/almost_complete_range.rs:66:17
|
||||||
|
|
|
|
||||||
LL | let _ = '0'..'9';
|
LL | let _ = '0'..'9';
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -152,7 +152,7 @@ LL | let _ = '0'..'9';
|
||||||
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:74:9
|
--> tests/ui/almost_complete_range.rs:73:9
|
||||||
|
|
|
|
||||||
LL | 'a'..'z' => 1,
|
LL | 'a'..'z' => 1,
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -160,7 +160,7 @@ LL | 'a'..'z' => 1,
|
||||||
| help: use an inclusive range: `...`
|
| help: use an inclusive range: `...`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:75:9
|
--> tests/ui/almost_complete_range.rs:74:9
|
||||||
|
|
|
|
||||||
LL | 'A'..'Z' => 2,
|
LL | 'A'..'Z' => 2,
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -168,7 +168,7 @@ LL | 'A'..'Z' => 2,
|
||||||
| help: use an inclusive range: `...`
|
| help: use an inclusive range: `...`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:76:9
|
--> tests/ui/almost_complete_range.rs:75:9
|
||||||
|
|
|
|
||||||
LL | '0'..'9' => 3,
|
LL | '0'..'9' => 3,
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -176,7 +176,7 @@ LL | '0'..'9' => 3,
|
||||||
| help: use an inclusive range: `...`
|
| help: use an inclusive range: `...`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:83:13
|
--> tests/ui/almost_complete_range.rs:82:13
|
||||||
|
|
|
|
||||||
LL | let _ = 'a'..'z';
|
LL | let _ = 'a'..'z';
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -184,7 +184,7 @@ LL | let _ = 'a'..'z';
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:84:13
|
--> tests/ui/almost_complete_range.rs:83:13
|
||||||
|
|
|
|
||||||
LL | let _ = 'A'..'Z';
|
LL | let _ = 'A'..'Z';
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -192,7 +192,7 @@ LL | let _ = 'A'..'Z';
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:85:13
|
--> tests/ui/almost_complete_range.rs:84:13
|
||||||
|
|
|
|
||||||
LL | let _ = '0'..'9';
|
LL | let _ = '0'..'9';
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -200,7 +200,7 @@ LL | let _ = '0'..'9';
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:87:9
|
--> tests/ui/almost_complete_range.rs:86:9
|
||||||
|
|
|
|
||||||
LL | 'a'..'z' => 1,
|
LL | 'a'..'z' => 1,
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -208,7 +208,7 @@ LL | 'a'..'z' => 1,
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:88:9
|
--> tests/ui/almost_complete_range.rs:87:9
|
||||||
|
|
|
|
||||||
LL | 'A'..'Z' => 1,
|
LL | 'A'..'Z' => 1,
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
@ -216,7 +216,7 @@ LL | 'A'..'Z' => 1,
|
||||||
| help: use an inclusive range: `..=`
|
| help: use an inclusive range: `..=`
|
||||||
|
|
||||||
error: almost complete ascii range
|
error: almost complete ascii range
|
||||||
--> tests/ui/almost_complete_range.rs:89:9
|
--> tests/ui/almost_complete_range.rs:88:9
|
||||||
|
|
|
|
||||||
LL | '0'..'9' => 3,
|
LL | '0'..'9' => 3,
|
||||||
| ^^^--^^^
|
| ^^^--^^^
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
extern crate proc_macro_derive;
|
extern crate proc_macro_derive;
|
||||||
|
|
||||||
use core::num::{NonZeroUsize, Saturating, Wrapping};
|
use core::num::{NonZero, Saturating, Wrapping};
|
||||||
|
|
||||||
const ONE: i32 = 1;
|
const ONE: i32 = 1;
|
||||||
const ZERO: i32 = 0;
|
const ZERO: i32 = 0;
|
||||||
|
@ -494,15 +494,15 @@ pub fn issue_11262() {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn issue_11392() {
|
pub fn issue_11392() {
|
||||||
fn example_div(unsigned: usize, nonzero_unsigned: NonZeroUsize) -> usize {
|
fn example_div(unsigned: usize, nonzero_unsigned: NonZero<usize>) -> usize {
|
||||||
unsigned / nonzero_unsigned
|
unsigned / nonzero_unsigned
|
||||||
}
|
}
|
||||||
|
|
||||||
fn example_rem(unsigned: usize, nonzero_unsigned: NonZeroUsize) -> usize {
|
fn example_rem(unsigned: usize, nonzero_unsigned: NonZero<usize>) -> usize {
|
||||||
unsigned % nonzero_unsigned
|
unsigned % nonzero_unsigned
|
||||||
}
|
}
|
||||||
|
|
||||||
let (unsigned, nonzero_unsigned) = (0, NonZeroUsize::new(1).unwrap());
|
let (unsigned, nonzero_unsigned) = (0, NonZero::new(1).unwrap());
|
||||||
example_div(unsigned, nonzero_unsigned);
|
example_div(unsigned, nonzero_unsigned);
|
||||||
example_rem(unsigned, nonzero_unsigned);
|
example_rem(unsigned, nonzero_unsigned);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#![warn(clippy::eager_transmute)]
|
#![warn(clippy::eager_transmute)]
|
||||||
#![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)]
|
#![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)]
|
||||||
|
|
||||||
use std::num::NonZeroU8;
|
use std::num::NonZero;
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
enum Opcode {
|
enum Opcode {
|
||||||
|
@ -85,21 +85,21 @@ macro_rules! impls {
|
||||||
}
|
}
|
||||||
impls!(NonMaxU8, NonZeroNonMaxU8);
|
impls!(NonMaxU8, NonZeroNonMaxU8);
|
||||||
|
|
||||||
fn niche_tests(v1: u8, v2: NonZeroU8, v3: NonZeroNonMaxU8) {
|
fn niche_tests(v1: u8, v2: NonZero<u8>, v3: NonZeroNonMaxU8) {
|
||||||
// u8 -> NonZeroU8, do lint
|
// u8 -> NonZero<u8>, do lint
|
||||||
let _: Option<NonZeroU8> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) });
|
let _: Option<NonZero<u8>> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) });
|
||||||
|
|
||||||
// NonZeroU8 -> u8, don't lint, target type has no niche and therefore a higher validity range
|
// NonZero<u8> -> u8, don't lint, target type has no niche and therefore a higher validity range
|
||||||
let _: Option<u8> = (v2 > NonZeroU8::new(1).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
|
let _: Option<u8> = (v2 > NonZero::new(1u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
|
||||||
|
|
||||||
// NonZeroU8 -> NonMaxU8, do lint, different niche
|
// NonZero<u8> -> NonMaxU8, do lint, different niche
|
||||||
let _: Option<NonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
|
let _: Option<NonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
|
||||||
|
|
||||||
// NonZeroNonMaxU8 -> NonMaxU8, don't lint, target type has more validity
|
// NonZeroNonMaxU8 -> NonMaxU8, don't lint, target type has more validity
|
||||||
let _: Option<NonMaxU8> = (v3 < 255).then_some(unsafe { std::mem::transmute(v2) });
|
let _: Option<NonMaxU8> = (v3 < 255).then_some(unsafe { std::mem::transmute(v2) });
|
||||||
|
|
||||||
// NonZeroU8 -> NonZeroNonMaxU8, do lint, target type has less validity
|
// NonZero<u8> -> NonZeroNonMaxU8, do lint, target type has less validity
|
||||||
let _: Option<NonZeroNonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
|
let _: Option<NonZeroNonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#![warn(clippy::eager_transmute)]
|
#![warn(clippy::eager_transmute)]
|
||||||
#![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)]
|
#![allow(clippy::transmute_int_to_non_zero, clippy::missing_transmute_annotations)]
|
||||||
|
|
||||||
use std::num::NonZeroU8;
|
use std::num::NonZero;
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
enum Opcode {
|
enum Opcode {
|
||||||
|
@ -85,21 +85,21 @@ macro_rules! impls {
|
||||||
}
|
}
|
||||||
impls!(NonMaxU8, NonZeroNonMaxU8);
|
impls!(NonMaxU8, NonZeroNonMaxU8);
|
||||||
|
|
||||||
fn niche_tests(v1: u8, v2: NonZeroU8, v3: NonZeroNonMaxU8) {
|
fn niche_tests(v1: u8, v2: NonZero<u8>, v3: NonZeroNonMaxU8) {
|
||||||
// u8 -> NonZeroU8, do lint
|
// u8 -> NonZero<u8>, do lint
|
||||||
let _: Option<NonZeroU8> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) });
|
let _: Option<NonZero<u8>> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) });
|
||||||
|
|
||||||
// NonZeroU8 -> u8, don't lint, target type has no niche and therefore a higher validity range
|
// NonZero<u8> -> u8, don't lint, target type has no niche and therefore a higher validity range
|
||||||
let _: Option<u8> = (v2 > NonZeroU8::new(1).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
|
let _: Option<u8> = (v2 > NonZero::new(1u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
|
||||||
|
|
||||||
// NonZeroU8 -> NonMaxU8, do lint, different niche
|
// NonZero<u8> -> NonMaxU8, do lint, different niche
|
||||||
let _: Option<NonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
|
let _: Option<NonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
|
||||||
|
|
||||||
// NonZeroNonMaxU8 -> NonMaxU8, don't lint, target type has more validity
|
// NonZeroNonMaxU8 -> NonMaxU8, don't lint, target type has more validity
|
||||||
let _: Option<NonMaxU8> = (v3 < 255).then_some(unsafe { std::mem::transmute(v2) });
|
let _: Option<NonMaxU8> = (v3 < 255).then_some(unsafe { std::mem::transmute(v2) });
|
||||||
|
|
||||||
// NonZeroU8 -> NonZeroNonMaxU8, do lint, target type has less validity
|
// NonZero<u8> -> NonZeroNonMaxU8, do lint, target type has less validity
|
||||||
let _: Option<NonZeroNonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
|
let _: Option<NonZeroNonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -155,36 +155,36 @@ LL | (op < 4).then(|| std::mem::transmute::<_, Opcode>(op));
|
||||||
| ~~~~ ++
|
| ~~~~ ++
|
||||||
|
|
||||||
error: this transmute is always evaluated eagerly, even if the condition is false
|
error: this transmute is always evaluated eagerly, even if the condition is false
|
||||||
--> tests/ui/eager_transmute.rs:90:60
|
--> tests/ui/eager_transmute.rs:90:62
|
||||||
|
|
|
|
||||||
LL | let _: Option<NonZeroU8> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) });
|
LL | let _: Option<NonZero<u8>> = (v1 > 0).then_some(unsafe { std::mem::transmute(v1) });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: consider using `bool::then` to only transmute if the condition holds
|
help: consider using `bool::then` to only transmute if the condition holds
|
||||||
|
|
|
|
||||||
LL | let _: Option<NonZeroU8> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) });
|
LL | let _: Option<NonZero<u8>> = (v1 > 0).then(|| unsafe { std::mem::transmute(v1) });
|
||||||
| ~~~~ ++
|
| ~~~~ ++
|
||||||
|
|
||||||
error: this transmute is always evaluated eagerly, even if the condition is false
|
error: this transmute is always evaluated eagerly, even if the condition is false
|
||||||
--> tests/ui/eager_transmute.rs:96:86
|
--> tests/ui/eager_transmute.rs:96:86
|
||||||
|
|
|
|
||||||
LL | let _: Option<NonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
|
LL | let _: Option<NonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: consider using `bool::then` to only transmute if the condition holds
|
help: consider using `bool::then` to only transmute if the condition holds
|
||||||
|
|
|
|
||||||
LL | let _: Option<NonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
|
LL | let _: Option<NonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
|
||||||
| ~~~~ ++
|
| ~~~~ ++
|
||||||
|
|
||||||
error: this transmute is always evaluated eagerly, even if the condition is false
|
error: this transmute is always evaluated eagerly, even if the condition is false
|
||||||
--> tests/ui/eager_transmute.rs:102:93
|
--> tests/ui/eager_transmute.rs:102:93
|
||||||
|
|
|
|
||||||
LL | let _: Option<NonZeroNonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
|
LL | let _: Option<NonZeroNonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then_some(unsafe { std::mem::transmute(v2) });
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: consider using `bool::then` to only transmute if the condition holds
|
help: consider using `bool::then` to only transmute if the condition holds
|
||||||
|
|
|
|
||||||
LL | let _: Option<NonZeroNonMaxU8> = (v2 < NonZeroU8::new(255).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
|
LL | let _: Option<NonZeroNonMaxU8> = (v2 < NonZero::new(255u8).unwrap()).then(|| unsafe { std::mem::transmute(v2) });
|
||||||
| ~~~~ ++
|
| ~~~~ ++
|
||||||
|
|
||||||
error: aborting due to 17 previous errors
|
error: aborting due to 17 previous errors
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
#![allow(non_contiguous_range_endpoints)]
|
#![allow(non_contiguous_range_endpoints)]
|
||||||
#![warn(clippy::manual_range_patterns)]
|
#![warn(clippy::manual_range_patterns)]
|
||||||
#![feature(exclusive_range_pattern)]
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let f = 6;
|
let f = 6;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
#![allow(non_contiguous_range_endpoints)]
|
#![allow(non_contiguous_range_endpoints)]
|
||||||
#![warn(clippy::manual_range_patterns)]
|
#![warn(clippy::manual_range_patterns)]
|
||||||
#![feature(exclusive_range_pattern)]
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let f = 6;
|
let f = 6;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:9:25
|
--> tests/ui/manual_range_patterns.rs:8:25
|
||||||
|
|
|
|
||||||
LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10);
|
LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10`
|
||||||
|
@ -8,109 +8,109 @@ LL | let _ = matches!(f, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10);
|
||||||
= help: to override `-D warnings` add `#[allow(clippy::manual_range_patterns)]`
|
= help: to override `-D warnings` add `#[allow(clippy::manual_range_patterns)]`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:10:25
|
--> tests/ui/manual_range_patterns.rs:9:25
|
||||||
|
|
|
|
||||||
LL | let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 7 | 8 | 10);
|
LL | let _ = matches!(f, 4 | 2 | 3 | 1 | 5 | 6 | 9 | 7 | 8 | 10);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:17:25
|
--> tests/ui/manual_range_patterns.rs:16:25
|
||||||
|
|
|
|
||||||
LL | let _ = matches!(f, 1 | (2..=4));
|
LL | let _ = matches!(f, 1 | (2..=4));
|
||||||
| ^^^^^^^^^^^ help: try: `1..=4`
|
| ^^^^^^^^^^^ help: try: `1..=4`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:18:25
|
--> tests/ui/manual_range_patterns.rs:17:25
|
||||||
|
|
|
|
||||||
LL | let _ = matches!(f, 1 | (2..4));
|
LL | let _ = matches!(f, 1 | (2..4));
|
||||||
| ^^^^^^^^^^ help: try: `1..4`
|
| ^^^^^^^^^^ help: try: `1..4`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:19:25
|
--> tests/ui/manual_range_patterns.rs:18:25
|
||||||
|
|
|
|
||||||
LL | let _ = matches!(f, (1..=10) | (2..=13) | (14..=48324728) | 48324729);
|
LL | let _ = matches!(f, (1..=10) | (2..=13) | (14..=48324728) | 48324729);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=48324729`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=48324729`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:20:25
|
--> tests/ui/manual_range_patterns.rs:19:25
|
||||||
|
|
|
|
||||||
LL | let _ = matches!(f, 0 | (1..=10) | 48324730 | (2..=13) | (14..=48324728) | 48324729);
|
LL | let _ = matches!(f, 0 | (1..=10) | 48324730 | (2..=13) | (14..=48324728) | 48324729);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0..=48324730`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0..=48324730`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:21:25
|
--> tests/ui/manual_range_patterns.rs:20:25
|
||||||
|
|
|
|
||||||
LL | let _ = matches!(f, 0..=1 | 0..=2 | 0..=3);
|
LL | let _ = matches!(f, 0..=1 | 0..=2 | 0..=3);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `0..=3`
|
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `0..=3`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:24:9
|
--> tests/ui/manual_range_patterns.rs:23:9
|
||||||
|
|
|
|
||||||
LL | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 => true,
|
LL | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 => true,
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:27:25
|
--> tests/ui/manual_range_patterns.rs:26:25
|
||||||
|
|
|
|
||||||
LL | let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1 | 2);
|
LL | let _ = matches!(f, -1 | -5 | 3 | -2 | -4 | -3 | 0 | 1 | 2);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-5..=3`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-5..=3`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:29:25
|
--> tests/ui/manual_range_patterns.rs:28:25
|
||||||
|
|
|
|
||||||
LL | let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001);
|
LL | let _ = matches!(f, -1_000_000..=1_000_000 | -1_000_001 | 1_000_001);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1_000_001..=1_000_001`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-1_000_001..=1_000_001`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:32:17
|
--> tests/ui/manual_range_patterns.rs:31:17
|
||||||
|
|
|
|
||||||
LL | matches!(f, 0x00 | 0x01 | 0x02 | 0x03);
|
LL | matches!(f, 0x00 | 0x01 | 0x02 | 0x03);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x03`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x03`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:33:17
|
--> tests/ui/manual_range_patterns.rs:32:17
|
||||||
|
|
|
|
||||||
LL | matches!(f, 0x00..=0x05 | 0x06 | 0x07);
|
LL | matches!(f, 0x00..=0x05 | 0x06 | 0x07);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x07`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `0x00..=0x07`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:34:17
|
--> tests/ui/manual_range_patterns.rs:33:17
|
||||||
|
|
|
|
||||||
LL | matches!(f, -0x09 | -0x08 | -0x07..=0x00);
|
LL | matches!(f, -0x09 | -0x08 | -0x07..=0x00);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-0x09..=0x00`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `-0x09..=0x00`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:36:17
|
--> tests/ui/manual_range_patterns.rs:35:17
|
||||||
|
|
|
|
||||||
LL | matches!(f, 0..5 | 5);
|
LL | matches!(f, 0..5 | 5);
|
||||||
| ^^^^^^^^ help: try: `0..=5`
|
| ^^^^^^^^ help: try: `0..=5`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:37:17
|
--> tests/ui/manual_range_patterns.rs:36:17
|
||||||
|
|
|
|
||||||
LL | matches!(f, 0 | 1..5);
|
LL | matches!(f, 0 | 1..5);
|
||||||
| ^^^^^^^^ help: try: `0..5`
|
| ^^^^^^^^ help: try: `0..5`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:39:17
|
--> tests/ui/manual_range_patterns.rs:38:17
|
||||||
|
|
|
|
||||||
LL | matches!(f, 0..=5 | 6..10);
|
LL | matches!(f, 0..=5 | 6..10);
|
||||||
| ^^^^^^^^^^^^^ help: try: `0..10`
|
| ^^^^^^^^^^^^^ help: try: `0..10`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:40:17
|
--> tests/ui/manual_range_patterns.rs:39:17
|
||||||
|
|
|
|
||||||
LL | matches!(f, 0..5 | 5..=10);
|
LL | matches!(f, 0..5 | 5..=10);
|
||||||
| ^^^^^^^^^^^^^ help: try: `0..=10`
|
| ^^^^^^^^^^^^^ help: try: `0..=10`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:41:17
|
--> tests/ui/manual_range_patterns.rs:40:17
|
||||||
|
|
|
|
||||||
LL | matches!(f, 5..=10 | 0..5);
|
LL | matches!(f, 5..=10 | 0..5);
|
||||||
| ^^^^^^^^^^^^^ help: try: `0..=10`
|
| ^^^^^^^^^^^^^ help: try: `0..=10`
|
||||||
|
|
||||||
error: this OR pattern can be rewritten using a range
|
error: this OR pattern can be rewritten using a range
|
||||||
--> tests/ui/manual_range_patterns.rs:45:26
|
--> tests/ui/manual_range_patterns.rs:44:26
|
||||||
|
|
|
|
||||||
LL | matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10)
|
LL | matches!($e, 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10)
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `1..=10`
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#![feature(exclusive_range_pattern)]
|
|
||||||
#![warn(clippy::match_overlapping_arm)]
|
#![warn(clippy::match_overlapping_arm)]
|
||||||
#![allow(clippy::redundant_pattern_matching)]
|
#![allow(clippy::redundant_pattern_matching)]
|
||||||
#![allow(clippy::if_same_then_else, clippy::equatable_if_let, clippy::needless_if)]
|
#![allow(clippy::if_same_then_else, clippy::equatable_if_let, clippy::needless_if)]
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
error: some ranges overlap
|
error: some ranges overlap
|
||||||
--> tests/ui/match_overlapping_arm.rs:12:9
|
--> tests/ui/match_overlapping_arm.rs:11:9
|
||||||
|
|
|
|
||||||
LL | 0..=10 => println!("0..=10"),
|
LL | 0..=10 => println!("0..=10"),
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
note: overlaps with this
|
note: overlaps with this
|
||||||
--> tests/ui/match_overlapping_arm.rs:14:9
|
--> tests/ui/match_overlapping_arm.rs:13:9
|
||||||
|
|
|
|
||||||
LL | 0..=11 => println!("0..=11"),
|
LL | 0..=11 => println!("0..=11"),
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
@ -13,85 +13,85 @@ LL | 0..=11 => println!("0..=11"),
|
||||||
= help: to override `-D warnings` add `#[allow(clippy::match_overlapping_arm)]`
|
= help: to override `-D warnings` add `#[allow(clippy::match_overlapping_arm)]`
|
||||||
|
|
||||||
error: some ranges overlap
|
error: some ranges overlap
|
||||||
--> tests/ui/match_overlapping_arm.rs:19:9
|
--> tests/ui/match_overlapping_arm.rs:18:9
|
||||||
|
|
|
|
||||||
LL | 0..=5 => println!("0..=5"),
|
LL | 0..=5 => println!("0..=5"),
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
|
|
||||||
note: overlaps with this
|
note: overlaps with this
|
||||||
--> tests/ui/match_overlapping_arm.rs:22:9
|
--> tests/ui/match_overlapping_arm.rs:21:9
|
||||||
|
|
|
|
||||||
LL | FOO..=11 => println!("FOO..=11"),
|
LL | FOO..=11 => println!("FOO..=11"),
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
|
||||||
error: some ranges overlap
|
error: some ranges overlap
|
||||||
--> tests/ui/match_overlapping_arm.rs:57:9
|
--> tests/ui/match_overlapping_arm.rs:56:9
|
||||||
|
|
|
|
||||||
LL | 0..11 => println!("0..11"),
|
LL | 0..11 => println!("0..11"),
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
|
|
||||||
note: overlaps with this
|
note: overlaps with this
|
||||||
--> tests/ui/match_overlapping_arm.rs:59:9
|
--> tests/ui/match_overlapping_arm.rs:58:9
|
||||||
|
|
|
|
||||||
LL | 0..=11 => println!("0..=11"),
|
LL | 0..=11 => println!("0..=11"),
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: some ranges overlap
|
error: some ranges overlap
|
||||||
--> tests/ui/match_overlapping_arm.rs:83:9
|
--> tests/ui/match_overlapping_arm.rs:82:9
|
||||||
|
|
|
|
||||||
LL | 0..=10 => println!("0..=10"),
|
LL | 0..=10 => println!("0..=10"),
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
|
||||||
note: overlaps with this
|
note: overlaps with this
|
||||||
--> tests/ui/match_overlapping_arm.rs:82:9
|
--> tests/ui/match_overlapping_arm.rs:81:9
|
||||||
|
|
|
|
||||||
LL | 5..14 => println!("5..14"),
|
LL | 5..14 => println!("5..14"),
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
||||||
error: some ranges overlap
|
error: some ranges overlap
|
||||||
--> tests/ui/match_overlapping_arm.rs:89:9
|
--> tests/ui/match_overlapping_arm.rs:88:9
|
||||||
|
|
|
|
||||||
LL | 0..7 => println!("0..7"),
|
LL | 0..7 => println!("0..7"),
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
|
|
||||||
note: overlaps with this
|
note: overlaps with this
|
||||||
--> tests/ui/match_overlapping_arm.rs:91:9
|
--> tests/ui/match_overlapping_arm.rs:90:9
|
||||||
|
|
|
|
||||||
LL | 0..=10 => println!("0..=10"),
|
LL | 0..=10 => println!("0..=10"),
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: some ranges overlap
|
error: some ranges overlap
|
||||||
--> tests/ui/match_overlapping_arm.rs:102:9
|
--> tests/ui/match_overlapping_arm.rs:101:9
|
||||||
|
|
|
|
||||||
LL | ..=23 => println!("..=23"),
|
LL | ..=23 => println!("..=23"),
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
|
|
||||||
note: overlaps with this
|
note: overlaps with this
|
||||||
--> tests/ui/match_overlapping_arm.rs:104:9
|
--> tests/ui/match_overlapping_arm.rs:103:9
|
||||||
|
|
|
|
||||||
LL | ..26 => println!("..26"),
|
LL | ..26 => println!("..26"),
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error: some ranges overlap
|
error: some ranges overlap
|
||||||
--> tests/ui/match_overlapping_arm.rs:112:9
|
--> tests/ui/match_overlapping_arm.rs:111:9
|
||||||
|
|
|
|
||||||
LL | 21..=30 => (),
|
LL | 21..=30 => (),
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
|
|
||||||
note: overlaps with this
|
note: overlaps with this
|
||||||
--> tests/ui/match_overlapping_arm.rs:114:9
|
--> tests/ui/match_overlapping_arm.rs:113:9
|
||||||
|
|
|
|
||||||
LL | 21..=40 => (),
|
LL | 21..=40 => (),
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
||||||
error: some ranges overlap
|
error: some ranges overlap
|
||||||
--> tests/ui/match_overlapping_arm.rs:127:9
|
--> tests/ui/match_overlapping_arm.rs:126:9
|
||||||
|
|
|
|
||||||
LL | 0..=0x0000_0000_0000_00ff => (),
|
LL | 0..=0x0000_0000_0000_00ff => (),
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
note: overlaps with this
|
note: overlaps with this
|
||||||
--> tests/ui/match_overlapping_arm.rs:129:9
|
--> tests/ui/match_overlapping_arm.rs:128:9
|
||||||
|
|
|
|
||||||
LL | 0..=0x0000_0000_0000_ffff => (),
|
LL | 0..=0x0000_0000_0000_ffff => (),
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#![feature(exclusive_range_pattern)]
|
|
||||||
#![allow(clippy::match_same_arms, dead_code)]
|
#![allow(clippy::match_same_arms, dead_code)]
|
||||||
#![warn(clippy::match_wild_err_arm)]
|
#![warn(clippy::match_wild_err_arm)]
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: `Err(_)` matches all errors
|
error: `Err(_)` matches all errors
|
||||||
--> tests/ui/match_wild_err_arm.rs:24:9
|
--> tests/ui/match_wild_err_arm.rs:23:9
|
||||||
|
|
|
|
||||||
LL | Err(_) => panic!("err"),
|
LL | Err(_) => panic!("err"),
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
@ -9,7 +9,7 @@ LL | Err(_) => panic!("err"),
|
||||||
= help: to override `-D warnings` add `#[allow(clippy::match_wild_err_arm)]`
|
= help: to override `-D warnings` add `#[allow(clippy::match_wild_err_arm)]`
|
||||||
|
|
||||||
error: `Err(_)` matches all errors
|
error: `Err(_)` matches all errors
|
||||||
--> tests/ui/match_wild_err_arm.rs:32:9
|
--> tests/ui/match_wild_err_arm.rs:31:9
|
||||||
|
|
|
|
||||||
LL | Err(_) => panic!(),
|
LL | Err(_) => panic!(),
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
@ -17,7 +17,7 @@ LL | Err(_) => panic!(),
|
||||||
= note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
|
= note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
|
||||||
|
|
||||||
error: `Err(_)` matches all errors
|
error: `Err(_)` matches all errors
|
||||||
--> tests/ui/match_wild_err_arm.rs:40:9
|
--> tests/ui/match_wild_err_arm.rs:39:9
|
||||||
|
|
|
|
||||||
LL | Err(_) => {
|
LL | Err(_) => {
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
@ -25,7 +25,7 @@ LL | Err(_) => {
|
||||||
= note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
|
= note: match each error separately or use the error output, or use `.expect(msg)` if the error case is unreachable
|
||||||
|
|
||||||
error: `Err(_e)` matches all errors
|
error: `Err(_e)` matches all errors
|
||||||
--> tests/ui/match_wild_err_arm.rs:50:9
|
--> tests/ui/match_wild_err_arm.rs:49:9
|
||||||
|
|
|
|
||||||
LL | Err(_e) => panic!(),
|
LL | Err(_e) => panic!(),
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#![warn(clippy::transmute_int_to_non_zero)]
|
#![warn(clippy::transmute_int_to_non_zero)]
|
||||||
#![allow(clippy::missing_transmute_annotations)]
|
#![allow(clippy::missing_transmute_annotations)]
|
||||||
|
|
||||||
use core::num::*;
|
use core::num::NonZero;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let int_u8: u8 = 1;
|
let int_u8: u8 = 1;
|
||||||
|
@ -16,38 +16,38 @@ fn main() {
|
||||||
let int_i64: i64 = 1;
|
let int_i64: i64 = 1;
|
||||||
let int_i128: i128 = 1;
|
let int_i128: i128 = 1;
|
||||||
|
|
||||||
let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) };
|
let _: NonZero<u8> = unsafe { NonZero::new_unchecked(int_u8) };
|
||||||
//~^ ERROR: transmute from a `u8` to a `NonZeroU8`
|
//~^ ERROR: transmute from a `u8` to a `NonZero<u8>`
|
||||||
//~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings`
|
//~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings`
|
||||||
let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) };
|
let _: NonZero<u16> = unsafe { NonZero::new_unchecked(int_u16) };
|
||||||
//~^ ERROR: transmute from a `u16` to a `NonZeroU16`
|
//~^ ERROR: transmute from a `u16` to a `NonZero<u16>`
|
||||||
let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) };
|
let _: NonZero<u32> = unsafe { NonZero::new_unchecked(int_u32) };
|
||||||
//~^ ERROR: transmute from a `u32` to a `NonZeroU32`
|
//~^ ERROR: transmute from a `u32` to a `NonZero<u32>`
|
||||||
let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) };
|
let _: NonZero<u64> = unsafe { NonZero::new_unchecked(int_u64) };
|
||||||
//~^ ERROR: transmute from a `u64` to a `NonZeroU64`
|
//~^ ERROR: transmute from a `u64` to a `NonZero<u64>`
|
||||||
let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) };
|
let _: NonZero<u128> = unsafe { NonZero::new_unchecked(int_u128) };
|
||||||
//~^ ERROR: transmute from a `u128` to a `NonZeroU128`
|
//~^ ERROR: transmute from a `u128` to a `NonZero<u128>`
|
||||||
|
|
||||||
let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) };
|
let _: NonZero<i8> = unsafe { NonZero::new_unchecked(int_i8) };
|
||||||
//~^ ERROR: transmute from a `i8` to a `NonZeroI8`
|
//~^ ERROR: transmute from a `i8` to a `NonZero<i8>`
|
||||||
let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) };
|
let _: NonZero<i16> = unsafe { NonZero::new_unchecked(int_i16) };
|
||||||
//~^ ERROR: transmute from a `i16` to a `NonZeroI16`
|
//~^ ERROR: transmute from a `i16` to a `NonZero<i16>`
|
||||||
let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) };
|
let _: NonZero<i32> = unsafe { NonZero::new_unchecked(int_i32) };
|
||||||
//~^ ERROR: transmute from a `i32` to a `NonZeroI32`
|
//~^ ERROR: transmute from a `i32` to a `NonZero<i32>`
|
||||||
let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) };
|
let _: NonZero<i64> = unsafe { NonZero::new_unchecked(int_i64) };
|
||||||
//~^ ERROR: transmute from a `i64` to a `NonZeroI64`
|
//~^ ERROR: transmute from a `i64` to a `NonZero<i64>`
|
||||||
let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) };
|
let _: NonZero<i128> = unsafe { NonZero::new_unchecked(int_i128) };
|
||||||
//~^ ERROR: transmute from a `i128` to a `NonZeroI128`
|
//~^ ERROR: transmute from a `i128` to a `NonZero<i128>`
|
||||||
|
|
||||||
let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) };
|
let _: NonZero<u8> = unsafe { NonZero::new_unchecked(int_u8) };
|
||||||
let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) };
|
let _: NonZero<u16> = unsafe { NonZero::new_unchecked(int_u16) };
|
||||||
let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) };
|
let _: NonZero<u32> = unsafe { NonZero::new_unchecked(int_u32) };
|
||||||
let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) };
|
let _: NonZero<u64> = unsafe { NonZero::new_unchecked(int_u64) };
|
||||||
let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) };
|
let _: NonZero<u128> = unsafe { NonZero::new_unchecked(int_u128) };
|
||||||
|
|
||||||
let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) };
|
let _: NonZero<i8> = unsafe { NonZero::new_unchecked(int_i8) };
|
||||||
let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) };
|
let _: NonZero<i16> = unsafe { NonZero::new_unchecked(int_i16) };
|
||||||
let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) };
|
let _: NonZero<i32> = unsafe { NonZero::new_unchecked(int_i32) };
|
||||||
let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) };
|
let _: NonZero<i64> = unsafe { NonZero::new_unchecked(int_i64) };
|
||||||
let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) };
|
let _: NonZero<i128> = unsafe { NonZero::new_unchecked(int_i128) };
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#![warn(clippy::transmute_int_to_non_zero)]
|
#![warn(clippy::transmute_int_to_non_zero)]
|
||||||
#![allow(clippy::missing_transmute_annotations)]
|
#![allow(clippy::missing_transmute_annotations)]
|
||||||
|
|
||||||
use core::num::*;
|
use core::num::NonZero;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let int_u8: u8 = 1;
|
let int_u8: u8 = 1;
|
||||||
|
@ -16,38 +16,38 @@ fn main() {
|
||||||
let int_i64: i64 = 1;
|
let int_i64: i64 = 1;
|
||||||
let int_i128: i128 = 1;
|
let int_i128: i128 = 1;
|
||||||
|
|
||||||
let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) };
|
let _: NonZero<u8> = unsafe { std::mem::transmute(int_u8) };
|
||||||
//~^ ERROR: transmute from a `u8` to a `NonZeroU8`
|
//~^ ERROR: transmute from a `u8` to a `NonZero<u8>`
|
||||||
//~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings`
|
//~| NOTE: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings`
|
||||||
let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) };
|
let _: NonZero<u16> = unsafe { std::mem::transmute(int_u16) };
|
||||||
//~^ ERROR: transmute from a `u16` to a `NonZeroU16`
|
//~^ ERROR: transmute from a `u16` to a `NonZero<u16>`
|
||||||
let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) };
|
let _: NonZero<u32> = unsafe { std::mem::transmute(int_u32) };
|
||||||
//~^ ERROR: transmute from a `u32` to a `NonZeroU32`
|
//~^ ERROR: transmute from a `u32` to a `NonZero<u32>`
|
||||||
let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) };
|
let _: NonZero<u64> = unsafe { std::mem::transmute(int_u64) };
|
||||||
//~^ ERROR: transmute from a `u64` to a `NonZeroU64`
|
//~^ ERROR: transmute from a `u64` to a `NonZero<u64>`
|
||||||
let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) };
|
let _: NonZero<u128> = unsafe { std::mem::transmute(int_u128) };
|
||||||
//~^ ERROR: transmute from a `u128` to a `NonZeroU128`
|
//~^ ERROR: transmute from a `u128` to a `NonZero<u128>`
|
||||||
|
|
||||||
let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) };
|
let _: NonZero<i8> = unsafe { std::mem::transmute(int_i8) };
|
||||||
//~^ ERROR: transmute from a `i8` to a `NonZeroI8`
|
//~^ ERROR: transmute from a `i8` to a `NonZero<i8>`
|
||||||
let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) };
|
let _: NonZero<i16> = unsafe { std::mem::transmute(int_i16) };
|
||||||
//~^ ERROR: transmute from a `i16` to a `NonZeroI16`
|
//~^ ERROR: transmute from a `i16` to a `NonZero<i16>`
|
||||||
let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) };
|
let _: NonZero<i32> = unsafe { std::mem::transmute(int_i32) };
|
||||||
//~^ ERROR: transmute from a `i32` to a `NonZeroI32`
|
//~^ ERROR: transmute from a `i32` to a `NonZero<i32>`
|
||||||
let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) };
|
let _: NonZero<i64> = unsafe { std::mem::transmute(int_i64) };
|
||||||
//~^ ERROR: transmute from a `i64` to a `NonZeroI64`
|
//~^ ERROR: transmute from a `i64` to a `NonZero<i64>`
|
||||||
let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) };
|
let _: NonZero<i128> = unsafe { std::mem::transmute(int_i128) };
|
||||||
//~^ ERROR: transmute from a `i128` to a `NonZeroI128`
|
//~^ ERROR: transmute from a `i128` to a `NonZero<i128>`
|
||||||
|
|
||||||
let _: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(int_u8) };
|
let _: NonZero<u8> = unsafe { NonZero::new_unchecked(int_u8) };
|
||||||
let _: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(int_u16) };
|
let _: NonZero<u16> = unsafe { NonZero::new_unchecked(int_u16) };
|
||||||
let _: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(int_u32) };
|
let _: NonZero<u32> = unsafe { NonZero::new_unchecked(int_u32) };
|
||||||
let _: NonZeroU64 = unsafe { NonZeroU64::new_unchecked(int_u64) };
|
let _: NonZero<u64> = unsafe { NonZero::new_unchecked(int_u64) };
|
||||||
let _: NonZeroU128 = unsafe { NonZeroU128::new_unchecked(int_u128) };
|
let _: NonZero<u128> = unsafe { NonZero::new_unchecked(int_u128) };
|
||||||
|
|
||||||
let _: NonZeroI8 = unsafe { NonZeroI8::new_unchecked(int_i8) };
|
let _: NonZero<i8> = unsafe { NonZero::new_unchecked(int_i8) };
|
||||||
let _: NonZeroI16 = unsafe { NonZeroI16::new_unchecked(int_i16) };
|
let _: NonZero<i16> = unsafe { NonZero::new_unchecked(int_i16) };
|
||||||
let _: NonZeroI32 = unsafe { NonZeroI32::new_unchecked(int_i32) };
|
let _: NonZero<i32> = unsafe { NonZero::new_unchecked(int_i32) };
|
||||||
let _: NonZeroI64 = unsafe { NonZeroI64::new_unchecked(int_i64) };
|
let _: NonZero<i64> = unsafe { NonZero::new_unchecked(int_i64) };
|
||||||
let _: NonZeroI128 = unsafe { NonZeroI128::new_unchecked(int_i128) };
|
let _: NonZero<i128> = unsafe { NonZero::new_unchecked(int_i128) };
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,65 +1,65 @@
|
||||||
error: transmute from a `u8` to a `NonZeroU8`
|
error: transmute from a `u8` to a `NonZero<u8>`
|
||||||
--> tests/ui/transmute_int_to_non_zero.rs:19:33
|
--> tests/ui/transmute_int_to_non_zero.rs:19:35
|
||||||
|
|
|
|
||||||
LL | let _: NonZeroU8 = unsafe { std::mem::transmute(int_u8) };
|
LL | let _: NonZero<u8> = unsafe { std::mem::transmute(int_u8) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU8::new_unchecked(int_u8)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u8)`
|
||||||
|
|
|
|
||||||
= note: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings`
|
= note: `-D clippy::transmute-int-to-non-zero` implied by `-D warnings`
|
||||||
= help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_non_zero)]`
|
= help: to override `-D warnings` add `#[allow(clippy::transmute_int_to_non_zero)]`
|
||||||
|
|
||||||
error: transmute from a `u16` to a `NonZeroU16`
|
error: transmute from a `u16` to a `NonZero<u16>`
|
||||||
--> tests/ui/transmute_int_to_non_zero.rs:22:34
|
--> tests/ui/transmute_int_to_non_zero.rs:22:36
|
||||||
|
|
|
|
||||||
LL | let _: NonZeroU16 = unsafe { std::mem::transmute(int_u16) };
|
LL | let _: NonZero<u16> = unsafe { std::mem::transmute(int_u16) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU16::new_unchecked(int_u16)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u16)`
|
||||||
|
|
||||||
error: transmute from a `u32` to a `NonZeroU32`
|
error: transmute from a `u32` to a `NonZero<u32>`
|
||||||
--> tests/ui/transmute_int_to_non_zero.rs:24:34
|
--> tests/ui/transmute_int_to_non_zero.rs:24:36
|
||||||
|
|
|
|
||||||
LL | let _: NonZeroU32 = unsafe { std::mem::transmute(int_u32) };
|
LL | let _: NonZero<u32> = unsafe { std::mem::transmute(int_u32) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU32::new_unchecked(int_u32)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u32)`
|
||||||
|
|
||||||
error: transmute from a `u64` to a `NonZeroU64`
|
error: transmute from a `u64` to a `NonZero<u64>`
|
||||||
--> tests/ui/transmute_int_to_non_zero.rs:26:34
|
--> tests/ui/transmute_int_to_non_zero.rs:26:36
|
||||||
|
|
|
|
||||||
LL | let _: NonZeroU64 = unsafe { std::mem::transmute(int_u64) };
|
LL | let _: NonZero<u64> = unsafe { std::mem::transmute(int_u64) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU64::new_unchecked(int_u64)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u64)`
|
||||||
|
|
||||||
error: transmute from a `u128` to a `NonZeroU128`
|
error: transmute from a `u128` to a `NonZero<u128>`
|
||||||
--> tests/ui/transmute_int_to_non_zero.rs:28:35
|
--> tests/ui/transmute_int_to_non_zero.rs:28:37
|
||||||
|
|
|
|
||||||
LL | let _: NonZeroU128 = unsafe { std::mem::transmute(int_u128) };
|
LL | let _: NonZero<u128> = unsafe { std::mem::transmute(int_u128) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroU128::new_unchecked(int_u128)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_u128)`
|
||||||
|
|
||||||
error: transmute from a `i8` to a `NonZeroI8`
|
error: transmute from a `i8` to a `NonZero<i8>`
|
||||||
--> tests/ui/transmute_int_to_non_zero.rs:31:33
|
--> tests/ui/transmute_int_to_non_zero.rs:31:35
|
||||||
|
|
|
|
||||||
LL | let _: NonZeroI8 = unsafe { std::mem::transmute(int_i8) };
|
LL | let _: NonZero<i8> = unsafe { std::mem::transmute(int_i8) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI8::new_unchecked(int_i8)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i8)`
|
||||||
|
|
||||||
error: transmute from a `i16` to a `NonZeroI16`
|
error: transmute from a `i16` to a `NonZero<i16>`
|
||||||
--> tests/ui/transmute_int_to_non_zero.rs:33:34
|
--> tests/ui/transmute_int_to_non_zero.rs:33:36
|
||||||
|
|
|
|
||||||
LL | let _: NonZeroI16 = unsafe { std::mem::transmute(int_i16) };
|
LL | let _: NonZero<i16> = unsafe { std::mem::transmute(int_i16) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI16::new_unchecked(int_i16)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i16)`
|
||||||
|
|
||||||
error: transmute from a `i32` to a `NonZeroI32`
|
error: transmute from a `i32` to a `NonZero<i32>`
|
||||||
--> tests/ui/transmute_int_to_non_zero.rs:35:34
|
--> tests/ui/transmute_int_to_non_zero.rs:35:36
|
||||||
|
|
|
|
||||||
LL | let _: NonZeroI32 = unsafe { std::mem::transmute(int_i32) };
|
LL | let _: NonZero<i32> = unsafe { std::mem::transmute(int_i32) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI32::new_unchecked(int_i32)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i32)`
|
||||||
|
|
||||||
error: transmute from a `i64` to a `NonZeroI64`
|
error: transmute from a `i64` to a `NonZero<i64>`
|
||||||
--> tests/ui/transmute_int_to_non_zero.rs:37:34
|
--> tests/ui/transmute_int_to_non_zero.rs:37:36
|
||||||
|
|
|
|
||||||
LL | let _: NonZeroI64 = unsafe { std::mem::transmute(int_i64) };
|
LL | let _: NonZero<i64> = unsafe { std::mem::transmute(int_i64) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI64::new_unchecked(int_i64)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i64)`
|
||||||
|
|
||||||
error: transmute from a `i128` to a `NonZeroI128`
|
error: transmute from a `i128` to a `NonZero<i128>`
|
||||||
--> tests/ui/transmute_int_to_non_zero.rs:39:35
|
--> tests/ui/transmute_int_to_non_zero.rs:39:37
|
||||||
|
|
|
|
||||||
LL | let _: NonZeroI128 = unsafe { std::mem::transmute(int_i128) };
|
LL | let _: NonZero<i128> = unsafe { std::mem::transmute(int_i128) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZeroI128::new_unchecked(int_i128)`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `NonZero::new_unchecked(int_i128)`
|
||||||
|
|
||||||
error: aborting due to 10 previous errors
|
error: aborting due to 10 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue