`unnameable_types` should show where the type is reachable
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
// This is just the documentation sample for the lint
#![deny(unnameable_types)]
mod m {
pub struct S;
}
pub fn get_unnameable() -> m::S { m::S }
Current output
error: struct `S` is reachable but cannot be named
--> src/lib.rs:5:5
|
5 | pub struct S;
| ^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
|
note: the lint level is defined here
--> src/lib.rs:2:9
|
2 | #![deny(unnameable_types)]
| ^^^^^^^^^^^^^^^^
Desired output
error: struct `S` is reachable but cannot be named
--> src/lib.rs:5:5
|
5 | pub struct S;
| ^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
|
note: `S` is reachable from here
|
8 | pub fn get_unnameable() -> m::S { m::S }
| ^^^^ returns a value of type `S`
|
note: the lint level is defined here
--> src/lib.rs:2:9
|
2 | #![deny(unnameable_types)]
| ^^^^^^^^^^^^^^^^
Rationale and extra context
The output should give at least one example of how the type is reachable. This will:
- Help understand why the lint is not a false-positive (a reaction I had when first enabling it — “surely these can't be…”).
- If the desired outcome is that the type is not reachable, help the user make it not reachable.
Right now, this is a pure “hidden action at a distance” situation: there is no way to discover where the type is reachable other than by searching for uses of it (which can be difficult).
Other cases
No response
Rust Version
rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-apple-darwin
release: 1.79.0
LLVM version: 18.1.7
Anything else?
@rustbot label +A-lint +A-visibility +L-unnameable_types
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
Locate the compiler implementation and tests for the unnameable_types lint, then reproduce the issue with the provided Rust sample. Trace how the lint identifies reachable types and add a diagnostic example showing where S is reachable; done means the output includes that note while retaining the existing lint and level diagnostics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100