-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
A-lintArea: New lintsArea: New lintsC-an-interesting-projectCategory: Interesting projects, that usually are more involved design/code wise.Category: Interesting projects, that usually are more involved design/code wise.E-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.T-macrosType: Issues with macros and macro expansionType: Issues with macros and macro expansionT-middleType: Probably requires verifiying typesType: Probably requires verifiying types
Description
Problem
Hey there. I stumbled upon a possible use case for clippy: detecting mutation inside debug_assert!
(and its two sister macros).
Why might this be a problem? Consider this program:
fn main() {
let mut l = vec![0];
debug_assert!(l.pop().is_some());
println!("{:?}", l.len());
}
And notice the difference when it is compiled with an without optimization
$ rustc -O debug.rs && ./debug
1
$ rustc debug.rs && ./debug
0
Generally this is undesirable.
Solution
I wanted to ask how solvable this is. As I understand it, by the time the compiler has type information (which would be needed to approximately detect mutation), macros have long-since been expanded. Would it be possible to find out whether a potentially-mutating statement
- Was in the user's original source?
- Was originally inside one of the
debug_assert*
macros?
Any advice would be much appreciated!
Other Things
Perhaps this is not worth linting -- is there a significant class of false positive?
Also, the embarrassing evidence that this can be a problem.
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsC-an-interesting-projectCategory: Interesting projects, that usually are more involved design/code wise.Category: Interesting projects, that usually are more involved design/code wise.E-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.T-macrosType: Issues with macros and macro expansionType: Issues with macros and macro expansionT-middleType: Probably requires verifiying typesType: Probably requires verifiying types