Skip to content

Commit 770d9f6

Browse files
authored
Unrolled build for #143380
Rollup merge of #143380 - cjgillot:kw_span, r=compiler-errors Replace kw_span by full span for generic const parameters. Small simplification extracted from #127241
2 parents 837c5dd + 3380bfd commit 770d9f6

File tree

13 files changed

+31
-23
lines changed

13 files changed

+31
-23
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ pub enum GenericParamKind {
385385
},
386386
Const {
387387
ty: P<Ty>,
388-
/// Span of the `const` keyword.
389-
kw_span: Span,
388+
/// Span of the whole parameter definition, including default.
389+
span: Span,
390390
/// Optional default value for the const generic param.
391391
default: Option<AnonConst>,
392392
},
@@ -410,10 +410,7 @@ impl GenericParam {
410410
self.ident.span
411411
}
412412
GenericParamKind::Type { default: Some(ty) } => self.ident.span.to(ty.span),
413-
GenericParamKind::Const { kw_span, default: Some(default), .. } => {
414-
kw_span.to(default.value.span)
415-
}
416-
GenericParamKind::Const { kw_span, default: None, ty } => kw_span.to(ty.span),
413+
GenericParamKind::Const { span, .. } => *span,
417414
}
418415
}
419416
}

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,9 +1350,10 @@ macro_rules! common_visitor_and_walkers {
13501350
match kind {
13511351
GenericParamKind::Lifetime => (),
13521352
GenericParamKind::Type { default } => visit_opt!(vis, visit_ty, default),
1353-
GenericParamKind::Const { ty, default, kw_span: _ } => {
1353+
GenericParamKind::Const { ty, default, span } => {
13541354
try_visit!(vis.visit_ty(ty));
13551355
visit_opt!(vis, visit_anon_const, default);
1356+
try_visit!(visit_span(vis, span));
13561357
}
13571358
}
13581359
if let Some(sp) = colon_span {

compiler/rustc_ast_lowering/src/lib.rs

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

19611961
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
19621962
}
1963-
GenericParamKind::Const { ty, kw_span: _, default } => {
1963+
GenericParamKind::Const { ty, span: _, default } => {
19641964
let ty = self
19651965
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault));
19661966

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,11 +909,11 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara
909909
}
910910
GenericParamKind::Type { default: None } => (),
911911
GenericParamKind::Lifetime => (),
912-
GenericParamKind::Const { ty: _, kw_span: _, default: Some(default) } => {
912+
GenericParamKind::Const { ty: _, span: _, default: Some(default) } => {
913913
ordered_params += " = ";
914914
ordered_params += &pprust::expr_to_string(&default.value);
915915
}
916-
GenericParamKind::Const { ty: _, kw_span: _, default: None } => (),
916+
GenericParamKind::Const { ty: _, span: _, default: None } => (),
917917
}
918918
first = false;
919919
}

compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub(crate) fn expand_deriving_coerce_pointee(
124124
GenericParamKind::Type { default: _ } => {
125125
cx.typaram(p.span(), p.ident, p.bounds.clone(), None)
126126
}
127-
GenericParamKind::Const { ty, kw_span: _, default: _ } => cx
127+
GenericParamKind::Const { ty, span: _, default: _ } => cx
128128
.const_param(
129129
p.span(),
130130
p.ident,

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

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

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

672672
// We can't have default values inside impl block
673673
default: None,

compiler/rustc_expand/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'a> ExtCtxt<'a> {
172172
attrs: AttrVec::new(),
173173
bounds,
174174
is_placeholder: false,
175-
kind: ast::GenericParamKind::Const { ty, kw_span: DUMMY_SP, default },
175+
kind: ast::GenericParamKind::Const { ty, span: DUMMY_SP, default },
176176
colon_span: None,
177177
}
178178
}

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(exp!(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(exp!(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
@@ -1656,7 +1656,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
16561656
forward_ty_ban_rib.bindings.swap_remove(i);
16571657
forward_ty_ban_rib_const_param_ty.bindings.swap_remove(i);
16581658
}
1659-
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
1659+
GenericParamKind::Const { ref ty, span: _, ref default } => {
16601660
// Const parameters can't have param bounds.
16611661
assert!(param.bounds.is_empty());
16621662

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2940,7 +2940,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
29402940
let span = if let [.., bound] = &param.bounds[..] {
29412941
bound.span()
29422942
} else if let GenericParam {
2943-
kind: GenericParamKind::Const { ty, kw_span: _, default }, ..
2943+
kind: GenericParamKind::Const { ty, span: _, default }, ..
29442944
} = param {
29452945
default.as_ref().map(|def| def.value.span).unwrap_or(ty.span)
29462946
} else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,13 +886,13 @@ pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool {
886886
(
887887
Const {
888888
ty: lt,
889-
kw_span: _,
890889
default: ld,
890+
span: _,
891891
},
892892
Const {
893893
ty: rt,
894-
kw_span: _,
895894
default: rd,
895+
span: _,
896896
},
897897
) => eq_ty(lt, rt) && both(ld.as_ref(), rd.as_ref(), eq_anon_const),
898898
_ => false,

src/tools/rustfmt/src/spanned.rs

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

690690
let param_start = if let ast::GenericParamKind::Const {
691691
ref ty,
692-
kw_span,
692+
span,
693693
default,
694694
} = &self.kind
695695
{
@@ -711,7 +711,7 @@ impl Rewrite for ast::GenericParam {
711711
default.rewrite_result(context, Shape::legacy(budget, shape.indent))?;
712712
param.push_str(&rewrite);
713713
}
714-
kw_span.lo()
714+
span.lo()
715715
} else {
716716
param.push_str(rewrite_ident(context, self.ident));
717717
self.ident.span.lo()

0 commit comments

Comments
 (0)