Skip to content

Commit 7259619

Browse files
committed
Do not duplicate const keyword on parameters
1 parent 9b26683 commit 7259619

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/formatting/spanned.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ impl Spanned for ast::Param {
117117

118118
impl Spanned for ast::GenericParam {
119119
fn span(&self) -> Span {
120-
let lo = if self.attrs.is_empty() {
120+
let lo = if let ast::GenericParamKind::Const { ty: _, kw_span } = self.kind {
121+
kw_span.lo()
122+
} else if self.attrs.is_empty() {
121123
self.ident.span.lo()
122124
} else {
123125
self.attrs[0].span.lo()

src/formatting/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl Rewrite for ast::GenericParam {
559559
_ => {}
560560
}
561561

562-
if let rustc_ast::ast::GenericParamKind::Const { ref ty } = &self.kind {
562+
if let ast::GenericParamKind::Const { ref ty, kw_span: _ } = &self.kind {
563563
result.push_str("const ");
564564
result.push_str(rewrite_ident(context, self.ident));
565565
result.push_str(": ");

tests/source/const_generics.rs

+8
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@ type Foo<const N: usize> = [i32; N + 1];
3434
pub trait Foo: Bar<{Baz::COUNT}> {
3535
const ASD: usize;
3636
}
37+
38+
// #4263
39+
fn const_generics_on_params<
40+
// AAAA
41+
const BBBB: usize,
42+
/* CCCC */
43+
const DDDD: usize,
44+
>() {}

tests/target/const_generics.rs

+9
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ type Foo<const N: usize> = [i32; N + 1];
2626
pub trait Foo: Bar<{ Baz::COUNT }> {
2727
const ASD: usize;
2828
}
29+
30+
// #4263
31+
fn const_generics_on_params<
32+
// AAAA
33+
const BBBB: usize,
34+
/* CCCC */
35+
const DDDD: usize,
36+
>() {
37+
}

0 commit comments

Comments
 (0)