1
Fork 0

Fix function and variable names

This commit is contained in:
xordi 2021-08-31 09:06:14 +02:00
parent aee4f1fc0c
commit 83f1454ade
2 changed files with 20 additions and 20 deletions

View file

@ -40,23 +40,23 @@ fn is_bool_lit(e: &Expr<'_>) -> bool {
) && !e.span.from_expansion() ) && !e.span.from_expansion()
} }
fn impl_not_trait_with_bool_out(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { fn is_impl_not_trait_with_bool_out(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
let ty = cx.typeck_results().expr_ty(e); let ty = cx.typeck_results().expr_ty(e);
cx.tcx cx.tcx
.lang_items() .lang_items()
.not_trait() .not_trait()
.filter(|id| implements_trait(cx, ty, *id, &[])) .filter(|trait_id| implements_trait(cx, ty, *trait_id, &[]))
.and_then(|id| { .and_then(|trait_id| {
cx.tcx.associated_items(id).find_by_name_and_kind( cx.tcx.associated_items(trait_id).find_by_name_and_kind(
cx.tcx, cx.tcx,
Ident::from_str("Output"), Ident::from_str("Output"),
ty::AssocKind::Type, ty::AssocKind::Type,
id, trait_id,
) )
}) })
.map_or(false, |item| { .map_or(false, |assoc_item| {
let proj = cx.tcx.mk_projection(item.def_id, cx.tcx.mk_substs_trait(ty, &[])); let proj = cx.tcx.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(ty, &[]));
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj); let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);
nty.is_bool() nty.is_bool()
@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for BoolAssertComparison {
return; return;
} }
if !impl_not_trait_with_bool_out(cx, a) || !impl_not_trait_with_bool_out(cx, b) { if !is_impl_not_trait_with_bool_out(cx, a) || !is_impl_not_trait_with_bool_out(cx, b) {
// At this point the expression which is not a boolean // At this point the expression which is not a boolean
// literal does not implement Not trait with a bool output, // literal does not implement Not trait with a bool output,
// so we cannot suggest to rewrite our code // so we cannot suggest to rewrite our code

View file

@ -16,28 +16,28 @@ macro_rules! b {
// Implements the Not trait but with an output type // Implements the Not trait but with an output type
// that's not bool. Should not suggest a rewrite // that's not bool. Should not suggest a rewrite
#[derive(Debug)] #[derive(Debug)]
enum A { enum ImplNotTraitWithoutBool {
VariantX(bool), VariantX(bool),
VariantY(u32), VariantY(u32),
} }
impl PartialEq<bool> for A { impl PartialEq<bool> for ImplNotTraitWithoutBool {
fn eq(&self, other: &bool) -> bool { fn eq(&self, other: &bool) -> bool {
match *self { match *self {
A::VariantX(b) => b == *other, ImplNotTraitWithoutBool::VariantX(b) => b == *other,
_ => false, _ => false,
} }
} }
} }
impl Not for A { impl Not for ImplNotTraitWithoutBool {
type Output = Self; type Output = Self;
fn not(self) -> Self::Output { fn not(self) -> Self::Output {
match self { match self {
A::VariantX(b) => A::VariantX(!b), ImplNotTraitWithoutBool::VariantX(b) => ImplNotTraitWithoutBool::VariantX(!b),
A::VariantY(0) => A::VariantY(1), ImplNotTraitWithoutBool::VariantY(0) => ImplNotTraitWithoutBool::VariantY(1),
A::VariantY(_) => A::VariantY(0), ImplNotTraitWithoutBool::VariantY(_) => ImplNotTraitWithoutBool::VariantY(0),
} }
} }
} }
@ -45,15 +45,15 @@ impl Not for A {
// This type implements the Not trait with an Output of // This type implements the Not trait with an Output of
// type bool. Using assert!(..) must be suggested // type bool. Using assert!(..) must be suggested
#[derive(Debug)] #[derive(Debug)]
struct B; struct ImplNotTraitWithBool;
impl PartialEq<bool> for B { impl PartialEq<bool> for ImplNotTraitWithBool {
fn eq(&self, other: &bool) -> bool { fn eq(&self, other: &bool) -> bool {
false false
} }
} }
impl Not for B { impl Not for ImplNotTraitWithBool {
type Output = bool; type Output = bool;
fn not(self) -> Self::Output { fn not(self) -> Self::Output {
@ -62,8 +62,8 @@ impl Not for B {
} }
fn main() { fn main() {
let a = A::VariantX(true); let a = ImplNotTraitWithoutBool::VariantX(true);
let b = B {}; let b = ImplNotTraitWithBool;
assert_eq!("a".len(), 1); assert_eq!("a".len(), 1);
assert_eq!("a".is_empty(), false); assert_eq!("a".is_empty(), false);