Skip to content

Commit 8133ae4

Browse files
committed
Replace kw_span by full span.
1 parent 7d97c59 commit 8133ae4

File tree

12 files changed

+29
-21
lines changed

12 files changed

+29
-21
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ pub enum GenericParamKind {
351351
Const {
352352
ty: P<Ty>,
353353
/// Span of the `const` keyword.
354-
kw_span: Span,
354+
span: Span,
355355
/// Optional default value for the const generic param
356356
default: Option<AnonConst>,
357357
},
@@ -375,10 +375,7 @@ impl GenericParam {
375375
self.ident.span
376376
}
377377
GenericParamKind::Type { default: Some(ty) } => self.ident.span.to(ty.span),
378-
GenericParamKind::Const { kw_span, default: Some(default), .. } => {
379-
kw_span.to(default.value.span)
380-
}
381-
GenericParamKind::Const { kw_span, default: None, ty } => kw_span.to(ty.span),
378+
GenericParamKind::Const { span, .. } => *span,
382379
}
383380
}
384381
}

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,9 @@ pub fn noop_flat_map_generic_param<T: MutVisitor>(
941941
GenericParamKind::Type { default } => {
942942
visit_opt(default, |default| vis.visit_ty(default));
943943
}
944-
GenericParamKind::Const { ty, kw_span: _, default } => {
944+
GenericParamKind::Const { ty, span, default } => {
945945
vis.visit_ty(ty);
946+
vis.visit_span(span);
946947
visit_opt(default, |default| vis.visit_anon_const(default));
947948
}
948949
}

compiler/rustc_ast/src/visit.rs

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

compiler/rustc_ast_lowering/src/lib.rs

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

22102210
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
22112211
}
2212-
GenericParamKind::Const { ty, kw_span: _, default } => {
2212+
GenericParamKind::Const { ty, span: _, default } => {
22132213
let ty = self
22142214
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault));
22152215

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,11 +889,11 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara
889889
}
890890
GenericParamKind::Type { default: None } => (),
891891
GenericParamKind::Lifetime => (),
892-
GenericParamKind::Const { ty: _, kw_span: _, default: Some(default) } => {
892+
GenericParamKind::Const { ty: _, span: _, default: Some(default) } => {
893893
ordered_params += " = ";
894894
ordered_params += &pprust::expr_to_string(&default.value);
895895
}
896-
GenericParamKind::Const { ty: _, kw_span: _, default: None } => (),
896+
GenericParamKind::Const { ty: _, span: _, default: None } => (),
897897
}
898898
first = false;
899899
}

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

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

669669
cx.typaram(param.ident.span.with_ctxt(ctxt), param.ident, bounds, None)
670670
}
671-
GenericParamKind::Const { ty, kw_span, .. } => {
671+
GenericParamKind::Const { ty, span, .. } => {
672672
let const_nodefault_kind = GenericParamKind::Const {
673673
ty: ty.clone(),
674-
kw_span: kw_span.with_ctxt(ctxt),
674+
span: span.with_ctxt(ctxt),
675675

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

compiler/rustc_parse/src/parser/generics.rs

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

117117
// Parse optional const generics default value.
118118
let default = if self.eat(&token::Eq) { Some(self.parse_const_arg()?) } else { None };
119+
let span = if let Some(ref default) = default {
120+
const_span.to(default.value.span)
121+
} else {
122+
const_span.to(ty.span)
123+
};
119124

120125
Ok(GenericParam {
121126
ident,
122127
id: ast::DUMMY_NODE_ID,
123128
attrs: preceding_attrs,
124129
bounds: Vec::new(),
125-
kind: GenericParamKind::Const { ty, kw_span: const_span, default },
130+
kind: GenericParamKind::Const { ty, span, default },
126131
is_placeholder: false,
127132
colon_span: None,
128133
})
@@ -139,6 +144,11 @@ impl<'a> Parser<'a> {
139144

140145
// Parse optional const generics default value.
141146
let default = if self.eat(&token::Eq) { Some(self.parse_const_arg()?) } else { None };
147+
let span = if let Some(ref default) = default {
148+
mistyped_const_ident.span.to(default.value.span)
149+
} else {
150+
mistyped_const_ident.span.to(ty.span)
151+
};
142152

143153
self.dcx()
144154
.struct_span_err(
@@ -158,7 +168,7 @@ impl<'a> Parser<'a> {
158168
id: ast::DUMMY_NODE_ID,
159169
attrs: preceding_attrs,
160170
bounds: Vec::new(),
161-
kind: GenericParamKind::Const { ty, kw_span: mistyped_const_ident.span, default },
171+
kind: GenericParamKind::Const { ty, span, default },
162172
is_placeholder: false,
163173
colon_span: None,
164174
})

compiler/rustc_resolve/src/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
14981498
.bindings
14991499
.remove(&Ident::with_dummy_span(param.ident.name));
15001500
}
1501-
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
1501+
GenericParamKind::Const { ref ty, span: _, ref default } => {
15021502
// Const parameters can't have param bounds.
15031503
assert!(param.bounds.is_empty());
15041504

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2547,7 +2547,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
25472547
let span = if let [.., bound] = &param.bounds[..] {
25482548
bound.span()
25492549
} else if let GenericParam {
2550-
kind: GenericParamKind::Const { ty, kw_span: _, default }, ..
2550+
kind: GenericParamKind::Const { ty, span: _, default }, ..
25512551
} = param {
25522552
default.as_ref().map(|def| def.value.span).unwrap_or(ty.span)
25532553
} else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,13 +762,13 @@ pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool {
762762
(
763763
Const {
764764
ty: lt,
765-
kw_span: _,
766765
default: ld,
766+
span: _,
767767
},
768768
Const {
769769
ty: rt,
770-
kw_span: _,
771770
default: rd,
771+
span: _,
772772
},
773773
) => eq_ty(lt, rt) && both(ld, rd, eq_anon_const),
774774
_ => false,

src/tools/rustfmt/src/spanned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl Spanned for ast::GenericParam {
120120
fn span(&self) -> Span {
121121
let lo = match self.kind {
122122
_ if !self.attrs.is_empty() => self.attrs[0].span.lo(),
123-
ast::GenericParamKind::Const { kw_span, .. } => kw_span.lo(),
123+
ast::GenericParamKind::Const { span, .. } => span.lo(),
124124
_ => self.ident.span.lo(),
125125
};
126126
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
@@ -603,7 +603,7 @@ impl Rewrite for ast::GenericParam {
603603

604604
let param_start = if let ast::GenericParamKind::Const {
605605
ref ty,
606-
kw_span,
606+
span,
607607
default,
608608
} = &self.kind
609609
{
@@ -621,7 +621,7 @@ impl Rewrite for ast::GenericParam {
621621
let rewrite = default.rewrite(context, Shape::legacy(budget, shape.indent))?;
622622
param.push_str(&rewrite);
623623
}
624-
kw_span.lo()
624+
span.lo()
625625
} else {
626626
param.push_str(rewrite_ident(context, self.ident));
627627
self.ident.span.lo()

0 commit comments

Comments
 (0)