Skip to content

Commit 24057f7

Browse files
committed
Replace kw_span by full span.
1 parent 80d0d92 commit 24057f7

File tree

12 files changed

+30
-22
lines changed

12 files changed

+30
-22
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ pub enum GenericParamKind {
353353
},
354354
Const {
355355
ty: P<Ty>,
356-
/// Span of the `const` keyword.
357-
kw_span: Span,
356+
/// Span of the whole parameter definition, including default.
357+
span: Span,
358358
/// Optional default value for the const generic param.
359359
default: Option<AnonConst>,
360360
},
@@ -378,10 +378,7 @@ impl GenericParam {
378378
self.ident.span
379379
}
380380
GenericParamKind::Type { default: Some(ty) } => self.ident.span.to(ty.span),
381-
GenericParamKind::Const { kw_span, default: Some(default), .. } => {
382-
kw_span.to(default.value.span)
383-
}
384-
GenericParamKind::Const { kw_span, default: None, ty } => kw_span.to(ty.span),
381+
GenericParamKind::Const { span, .. } => *span,
385382
}
386383
}
387384
}

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,9 @@ pub fn walk_flat_map_generic_param<T: MutVisitor>(
950950
GenericParamKind::Type { default } => {
951951
visit_opt(default, |default| vis.visit_ty(default));
952952
}
953-
GenericParamKind::Const { ty, kw_span: _, default } => {
953+
GenericParamKind::Const { ty, span, default } => {
954954
vis.visit_ty(ty);
955+
vis.visit_span(span);
955956
visit_opt(default, |default| vis.visit_anon_const(default));
956957
}
957958
}

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ pub fn walk_generic_param<'a, V: Visitor<'a>>(
753753
match kind {
754754
GenericParamKind::Lifetime => (),
755755
GenericParamKind::Type { default } => visit_opt!(visitor, visit_ty, default),
756-
GenericParamKind::Const { ty, default, kw_span: _ } => {
756+
GenericParamKind::Const { ty, default, span: _ } => {
757757
try_visit!(visitor.visit_ty(ty));
758758
visit_opt!(visitor, visit_anon_const, default);
759759
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21082108

21092109
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
21102110
}
2111-
GenericParamKind::Const { ty, kw_span: _, default } => {
2111+
GenericParamKind::Const { ty, span: _, default } => {
21122112
let ty = self
21132113
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault));
21142114

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,11 +826,11 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara
826826
}
827827
GenericParamKind::Type { default: None } => (),
828828
GenericParamKind::Lifetime => (),
829-
GenericParamKind::Const { ty: _, kw_span: _, default: Some(default) } => {
829+
GenericParamKind::Const { ty: _, span: _, default: Some(default) } => {
830830
ordered_params += " = ";
831831
ordered_params += &pprust::expr_to_string(&default.value);
832832
}
833-
GenericParamKind::Const { ty: _, kw_span: _, default: None } => (),
833+
GenericParamKind::Const { ty: _, span: _, default: None } => (),
834834
}
835835
first = false;
836836
}

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,10 @@ impl<'a> TraitDef<'a> {
667667

668668
cx.typaram(param.ident.span.with_ctxt(ctxt), param.ident, bounds, None)
669669
}
670-
GenericParamKind::Const { ty, kw_span, .. } => {
670+
GenericParamKind::Const { ty, span, .. } => {
671671
let const_nodefault_kind = GenericParamKind::Const {
672672
ty: ty.clone(),
673-
kw_span: kw_span.with_ctxt(ctxt),
673+
span: span.with_ctxt(ctxt),
674674

675675
// We can't have default values inside impl block
676676
default: None,

compiler/rustc_parse/src/parser/generics.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,18 @@ impl<'a> Parser<'a> {
114114

115115
// Parse optional const generics default value.
116116
let default = if self.eat(&token::Eq) { Some(self.parse_const_arg()?) } else { None };
117+
let span = if let Some(ref default) = default {
118+
const_span.to(default.value.span)
119+
} else {
120+
const_span.to(ty.span)
121+
};
117122

118123
Ok(GenericParam {
119124
ident,
120125
id: ast::DUMMY_NODE_ID,
121126
attrs: preceding_attrs,
122127
bounds: Vec::new(),
123-
kind: GenericParamKind::Const { ty, kw_span: const_span, default },
128+
kind: GenericParamKind::Const { ty, span, default },
124129
is_placeholder: false,
125130
colon_span: None,
126131
})
@@ -137,6 +142,11 @@ impl<'a> Parser<'a> {
137142

138143
// Parse optional const generics default value.
139144
let default = if self.eat(&token::Eq) { Some(self.parse_const_arg()?) } else { None };
145+
let span = if let Some(ref default) = default {
146+
mistyped_const_ident.span.to(default.value.span)
147+
} else {
148+
mistyped_const_ident.span.to(ty.span)
149+
};
140150

141151
self.dcx()
142152
.struct_span_err(
@@ -156,7 +166,7 @@ impl<'a> Parser<'a> {
156166
id: ast::DUMMY_NODE_ID,
157167
attrs: preceding_attrs,
158168
bounds: Vec::new(),
159-
kind: GenericParamKind::Const { ty, kw_span: mistyped_const_ident.span, default },
169+
kind: GenericParamKind::Const { ty, span, default },
160170
is_placeholder: false,
161171
colon_span: None,
162172
})

compiler/rustc_resolve/src/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
15521552
.bindings
15531553
.remove(&Ident::with_dummy_span(param.ident.name));
15541554
}
1555-
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
1555+
GenericParamKind::Const { ref ty, span: _, ref default } => {
15561556
// Const parameters can't have param bounds.
15571557
assert!(param.bounds.is_empty());
15581558

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2564,7 +2564,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
25642564
let span = if let [.., bound] = &param.bounds[..] {
25652565
bound.span()
25662566
} else if let GenericParam {
2567-
kind: GenericParamKind::Const { ty, kw_span: _, default }, ..
2567+
kind: GenericParamKind::Const { ty, span: _, default }, ..
25682568
} = param {
25692569
default.as_ref().map(|def| def.value.span).unwrap_or(ty.span)
25702570
} else {

src/tools/clippy/clippy_utils/src/ast_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,13 +804,13 @@ pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool {
804804
(
805805
Const {
806806
ty: lt,
807-
kw_span: _,
808807
default: ld,
808+
span: _,
809809
},
810810
Const {
811811
ty: rt,
812-
kw_span: _,
813812
default: rd,
813+
span: _,
814814
},
815815
) => eq_ty(lt, rt) && both(ld.as_ref(), rd.as_ref(), eq_anon_const),
816816
_ => false,

src/tools/rustfmt/src/spanned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Spanned for ast::GenericParam {
121121
fn span(&self) -> Span {
122122
let lo = match self.kind {
123123
_ if !self.attrs.is_empty() => self.attrs[0].span.lo(),
124-
ast::GenericParamKind::Const { kw_span, .. } => kw_span.lo(),
124+
ast::GenericParamKind::Const { span, .. } => span.lo(),
125125
_ => self.ident.span.lo(),
126126
};
127127
let hi = if self.bounds.is_empty() {

src/tools/rustfmt/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ impl Rewrite for ast::GenericParam {
656656

657657
let param_start = if let ast::GenericParamKind::Const {
658658
ref ty,
659-
kw_span,
659+
span,
660660
default,
661661
} = &self.kind
662662
{
@@ -678,7 +678,7 @@ impl Rewrite for ast::GenericParam {
678678
default.rewrite_result(context, Shape::legacy(budget, shape.indent))?;
679679
param.push_str(&rewrite);
680680
}
681-
kw_span.lo()
681+
span.lo()
682682
} else {
683683
param.push_str(rewrite_ident(context, self.ident));
684684
self.ident.span.lo()

0 commit comments

Comments
 (0)