Bad suggestion in dependency_on_unit_never_type_fallback for fragment coming from a macro input
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
The following in 2021:
#![warn(dependency_on_unit_never_type_fallback)]
pub fn foo<T: Default>() -> Result<T, ()> {
Err(())
}
macro_rules! m {
($x: ident) => {
pub fn test() -> Result<(), ()> {
$x()?;
Ok(())
}
};
}
m!(foo);
produces a suggestion that results in the following change:
@@ -13,6 +13,6 @@
};
}
-m!(foo);
+m!(foo::<()>);
However, this is not valid because foo::<()> is not an ident, and you get an error about no rules matching.
Possible solutions
I don't know if this is fixable, since I can't think of a suggestion that would actually be valid in this scenario. At a minimum, I would say that it should not give a suggestion in this scenario (or at least make it MaybeIncorrect).
Meta
rustc 1.85.0-nightly (7442931d4 2024-11-30)
binary: rustc
commit-hash: 7442931d49b199ad0a1cc0f8ca54e327b5139b66
commit-date: 2024-11-30
host: aarch64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.4
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 minimal reproduction in the issue and inspect the rustc implementation of the dependency_on_unit_never_type_fallback lint, particularly how its suggestion spans macro inputs. Confirm that the generated edit is invalid for the macro_rules! m! pattern, then add or update a regression test so this case produces no suggestion or marks it MaybeIncorrect.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100