rust-lang / rust-lang/rust-clippy
clippy::eval_order_dependence leaks from macro and is too sensitive
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
I wrote a frontend framework that flows the dependency injection context of logical containers to their content children. It does this through expressions of the following shape:
let c = …;
let c_0;
let c_1;
Parent {
container: {
let constructed = Container::new(c.as_ref());
c_0 = constructed.1;
constructed.0
},
content: {
let constructed = Content::new(c_0.as_ref());
c_1 = constructed.1;
constructed.0
},
}
From the expansion I can see that the lint is attached to the c_0 in c_0.as_ref(), which has Span::mixed_site() resolution everywhere it appears and as such should be suppressed in the input.
(I use Span-bending to map the location to an input token instead, to make it easier to debug these issues. This does not seem to affect whether other lints are suppressed.)
Additionally, I believe this lint should not flag cases where there is only a single assignment to a previously unassigned binding.
(I suppose that's my main and most actionable point here, hence the highlight.)
The alternative in this case would be to construct and bind everything via let bindings in advance which, at least in my eyes, would make more deeply nested expressions harder to follow. (There are various expressions in my template grammar that require a separate nested storage context, i.e. a nested generated and usually generated struct type, for therein contained child components and field bindings.)
Lint Name
eval_order_dependence
Reproducer
Since the actual example for the macro leak is somewhat extensive, I created a branch in my repository for the issue report here: https://github.com/Tamschi/Asteracea/tree/reports/clippy--eval_order_dependence
The test dependency_injection_by_container_ is the expanded form that shows the location of the warning in more detail (in this revision and line).
dependency_injection_by_container is one of the tests where the warning leaks out from the macro.
Version
rustc 1.61.0-nightly (532d3cda9 2022-02-23)
binary: rustc
commit-hash: 532d3cda90b8a729cd982548649d32803d265052
commit-date: 2022-02-23
host: x86_64-pc-windows-msvc
release: 1.61.0-nightly
LLVM version: 14.0.0
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the eval_order_dependence lint implementation and its tests, then inspect the dependency_injection_by_container_ reproducer at the referenced line and the dependency_injection_by_container test. Determine why the warning escapes the macro and whether a single assignment should be exempt. Done means regression coverage for both behaviors and an agreed lint result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100