rust-lang / rust-lang/rust-clippy
What about placeholders?
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Clippy has some suggestions that will contain a placeholder. Most of the time they are .. or _¹, but fortunately sometimes it is something more useful.
Eg. clippy might suggest to replace for i in 0..vec.len() by for <item> in &vec². useless_let_if_seq can also suggest let <mut> foo = (because checking whether the mut is still needed after our suggestion is actually hard).
A nice feature for a tool to replace suggestions automatically would be to ask the user what to write there. For that we might want to mark these placeholders somehow: <…> is nice but it has some problems:
- it's valid rust to write
a < b && c > d, but< b && c >is obviously not a placeholder; - there is no difference between something the user should rename (
<item>above) or might want to remove (<mut>above).
IMO, we should use different characters for placeholder markers such that:
- it's obvious for the user they need to change something and they can't just copy&paste a suggestion if so;
- it's trivial for
rustfixto detect placeholders; - there is a difference between
<item>and<mut>.
Unicode can help: eg. we could use ‹item› for something the user should change and ❪mut❫ for something the user should opt-in.
Some considerations though:
- we should chose characters present in common monospaced fonts (
‹›❪❫work for me™); - Unicode might not be available (Windows anyone?);
- this should be marked in the JSON errors rather than as text in the suggestion but I'm not felling like making an RFC for now since 1) rustc makes really few uses of
span_suggestiontoday, 2) Clippy suggestions still need a lot of work to be automatically fixable and have a working POC.
Cc @killercup.
1: we should kill that btw.
2: and in the future should be able to add a proper suggestion for all the vec[i] in the loop as well.
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
The issue names no files or tests. Start by reviewing rustfix handling and the JSON errors associated with span_suggestion, then establish how rename and opt-in placeholders should be represented. Done means an agreed marker scheme that rustfix can detect and that addresses the font and Windows concerns.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100