Add an option to not automatically pad const-generics braces with spaces
Open
Nobody has claimed this yet.
A-whitespace
C-feature-request
P-low
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
By which I mean, given this code from a crate of mine:
impl<T, const N: usize> Index<usize> for StaticVec<T, {N}> {
type Output = T;
///Asserts that `index` is less than the current length of the StaticVec,
///and if so returns the value at that position as a constant reference.
#[inline(always)]
fn index(&self, index: usize) -> &Self::Output {
assert!(index < self.length);
unsafe { self.data.get_unchecked(index).get_ref() }
}
}
Rustfmt will always make it look like this:
impl<T, const N: usize> Index<usize> for StaticVec<T, { N }> {
type Output = T;
///Asserts that `index` is less than the current length of the StaticVec,
///and if so returns the value at that position as a constant reference.
#[inline(always)]
fn index(&self, index: usize) -> &Self::Output {
assert!(index < self.length);
unsafe { self.data.get_unchecked(index).get_ref() }
}
}
The difference being { N } instead of the original {N}. Note that I'm not even sure if this is intentional behavior in the sense of being specific to const generics, or just something more general to do with brace spacing.
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 tracing rustfmt's brace-spacing handling for const generics and reviewing existing formatting options and their tests. Done means a configuration option can preserve {N} when requested while the current default behavior remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100