Skip to content

Clippy misses integer arithmetic error for a specific type #8968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Chralt98 opened this issue Jun 8, 2022 · 6 comments
Closed

Clippy misses integer arithmetic error for a specific type #8968

Chralt98 opened this issue Jun 8, 2022 · 6 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@Chralt98
Copy link

Chralt98 commented Jun 8, 2022

Summary

I expected an clippy error when using a specific type, which resolves to be an integer (u128).

Reproducer

I tried this code:

pub type SpecificIntegerType = u128;
pub const NewValue: SpecificIntegerType = 42;

...

let test_arithmetic_integer_error = NewValue + NewValue;

When running with -Dclippy::integer_arithmetic

I expected to see this happen:

error: integer arithmetic detected

Instead, this happened:

No error.

Version

rustc 1.62.0-nightly

Additional Labels

No response

@Chralt98 Chralt98 added the C-bug Category: Clippy is not doing the correct thing label Jun 8, 2022
@Alexendoo Alexendoo added the I-false-negative Issue: The lint should have been triggered on code, but wasn't label Jun 8, 2022
@Alexendoo
Copy link
Member

It appears to trigger the lint for https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5ae8ae28263bb35ccc1987355557aa80

Is there some other context needed?

@Chralt98
Copy link
Author

Chralt98 commented Jun 8, 2022

Currently I can't reproduce the error in the rust playground, but I try to describe it with the specific code.

Here is the code, where I would expect a clippy integer arithmetic error. The ValidityBond is a BalanceOf, what you can see here

This BalanceOf type alias references to the following trait type.

type Balance: Balance + MaybeSerializeDeserialize + Debug + MaxEncodedLen;

Where Balance is that:

pub trait Balance:
	AtLeast32BitUnsigned + FullCodec + Copy + Default + Debug + scale_info::TypeInfo
{
}
impl<T: AtLeast32BitUnsigned + FullCodec + Copy + Default + Debug + scale_info::TypeInfo> Balance
	for T
{
}

Reference to the BalanceType is here.

The constant ValidityBond is assigned here. And finally Balance is the u128 type, which you can see here.

@Jarcho
Copy link
Contributor

Jarcho commented Jun 9, 2022

integer_arithmetic can't lint on generic types as other types could be substituted there.

@Chralt98
Copy link
Author

Chralt98 commented Jun 9, 2022

Thank you for your answer. What a pitty!

@Jarcho
Copy link
Contributor

Jarcho commented Jun 9, 2022

There should be a lint for using any arithmetic operators soonish. Somebody was working on it.

@c410-f3r
Copy link
Contributor

With #9130 merged, this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

4 participants