rust-lang / rust-lang/rust-clippy
`multiple_bound_locations` triggers in macro-generated code
Open
Nobody has claimed this yet.
C-bug
I-false-positive
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
The lint multiple_bound_locations triggers in macro-generated code if a macro introduces additional trait bounds.
Lint Name
multiple_bound_locations
Reproducer
I tried this code:
use yew::prelude::*; // yew 0.21.0
#[hook]
pub fn use_foo<T: 'static>() {}
Code after macro expansion
#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
use yew::prelude::*;
#[cfg(not(doctest))]
/**
# Note
When used in function components and hooks, this hook is equivalent to:
```
pub fn use_foo<T: 'static>() {
/* implementation omitted */
}
```
*/
pub fn use_foo<'hook, T: 'static>() -> impl 'hook + ::yew::functional::Hook<Output = ()>
where
T: 'hook,
{
fn inner_fn<'hook, T: 'static>(_ctx: &mut ::yew::functional::HookContext)
where
T: 'hook,
{}
struct HookProvider<'hook, T: 'static>
where
T: 'hook,
{
_marker: ::std::marker::PhantomData<(T, &'hook ())>,
args: (),
}
#[automatically_derived]
impl<'hook, T: 'static> ::yew::functional::Hook for HookProvider<'hook, T>
where
T: 'hook,
{
type Output = ();
fn run(mut self, _ctx: &mut ::yew::functional::HookContext) -> Self::Output {
let () = self.args;
inner_fn::<T>(_ctx)
}
}
#[automatically_derived]
impl<'hook, T: 'static> HookProvider<'hook, T>
where
T: 'hook,
{
fn new() -> Self {
HookProvider {
_marker: ::std::marker::PhantomData,
args: (),
}
}
}
HookProvider::<T>::new()
}
I saw this happen:
$ cargo +nightly clippy
warning: bound is defined in more than one place
--> src/lib.rs:4:16
|
4 | pub fn use_foo<T: 'static>() {}
| ^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations
= note: `#[warn(clippy::multiple_bound_locations)]` on by default
warning: `test-yew` (lib) generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
I expected to see this happen: No warnings
Version
rustc 1.79.0-nightly (0ad927c0c 2024-03-21)
binary: rustc
commit-hash: 0ad927c0c07b65fc0dae37105e09c877c87c296a
commit-date: 2024-03-21
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2
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 multiple_bound_locations lint and reproduce the Yew 0.21.0 example using cargo +nightly clippy. Compare the source and macro-expanded code shown in the issue; done means the macro-generated duplicate bounds no longer produce a warning while the lint still reports applicable user-written bounds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100