diff options
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ast/src/ast.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_ast/src/visit.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_ast_lowering/src/lib.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_ast_passes/src/ast_validation.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_builtin_macros/src/deriving/generic/mod.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/build.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/generics.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/late/diagnostics.rs | 2 |
10 files changed, 26 insertions, 18 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index ac6daba3901..491a9bbda79 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -385,8 +385,8 @@ pub enum GenericParamKind { }, Const { ty: P<Ty>, - /// Span of the `const` keyword. - kw_span: Span, + /// Span of the whole parameter definition, including default. + span: Span, /// Optional default value for the const generic param. default: Option<AnonConst>, }, @@ -410,10 +410,7 @@ impl GenericParam { self.ident.span } GenericParamKind::Type { default: Some(ty) } => self.ident.span.to(ty.span), - GenericParamKind::Const { kw_span, default: Some(default), .. } => { - kw_span.to(default.value.span) - } - GenericParamKind::Const { kw_span, default: None, ty } => kw_span.to(ty.span), + GenericParamKind::Const { span, .. } => *span, } } } diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 42de5b727c5..5dd6882b025 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -1350,9 +1350,10 @@ macro_rules! common_visitor_and_walkers { match kind { GenericParamKind::Lifetime => (), GenericParamKind::Type { default } => visit_opt!(vis, visit_ty, default), - GenericParamKind::Const { ty, default, kw_span: _ } => { + GenericParamKind::Const { ty, default, span } => { try_visit!(vis.visit_ty(ty)); visit_opt!(vis, visit_anon_const, default); + try_visit!(visit_span(vis, span)); } } if let Some(sp) = colon_span { diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index d14e27982ef..0706bdb119f 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1960,7 +1960,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { (hir::ParamName::Plain(self.lower_ident(param.ident)), kind) } - GenericParamKind::Const { ty, kw_span: _, default } => { + GenericParamKind::Const { ty, span: _, default } => { let ty = self .lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault)); diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index da248251203..53e2a1c695a 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -909,11 +909,11 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara } GenericParamKind::Type { default: None } => (), GenericParamKind::Lifetime => (), - GenericParamKind::Const { ty: _, kw_span: _, default: Some(default) } => { + GenericParamKind::Const { ty: _, span: _, default: Some(default) } => { ordered_params += " = "; ordered_params += &pprust::expr_to_string(&default.value); } - GenericParamKind::Const { ty: _, kw_span: _, default: None } => (), + GenericParamKind::Const { ty: _, span: _, default: None } => (), } first = false; } diff --git a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs index 3a20b39798d..6082e376435 100644 --- a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs +++ b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs @@ -124,7 +124,7 @@ pub(crate) fn expand_deriving_coerce_pointee( GenericParamKind::Type { default: _ } => { cx.typaram(p.span(), p.ident, p.bounds.clone(), None) } - GenericParamKind::Const { ty, kw_span: _, default: _ } => cx + GenericParamKind::Const { ty, span: _, default: _ } => cx .const_param( p.span(), p.ident, diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index d642851bb77..d201ca196d6 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -664,10 +664,10 @@ impl<'a> TraitDef<'a> { cx.typaram(param.ident.span.with_ctxt(ctxt), param.ident, bounds, None) } - GenericParamKind::Const { ty, kw_span, .. } => { + GenericParamKind::Const { ty, span, .. } => { let const_nodefault_kind = GenericParamKind::Const { ty: ty.clone(), - kw_span: kw_span.with_ctxt(ctxt), + span: span.with_ctxt(ctxt), // We can't have default values inside impl block default: None, diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index a333f2c7cb7..85683c1a03f 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -172,7 +172,7 @@ impl<'a> ExtCtxt<'a> { attrs: AttrVec::new(), bounds, is_placeholder: false, - kind: ast::GenericParamKind::Const { ty, kw_span: DUMMY_SP, default }, + kind: ast::GenericParamKind::Const { ty, span: DUMMY_SP, default }, colon_span: None, } } diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs index af1d1a1ec66..86326341a75 100644 --- a/compiler/rustc_parse/src/parser/generics.rs +++ b/compiler/rustc_parse/src/parser/generics.rs @@ -114,13 +114,18 @@ impl<'a> Parser<'a> { // Parse optional const generics default value. let default = if self.eat(exp!(Eq)) { Some(self.parse_const_arg()?) } else { None }; + let span = if let Some(ref default) = default { + const_span.to(default.value.span) + } else { + const_span.to(ty.span) + }; Ok(GenericParam { ident, id: ast::DUMMY_NODE_ID, attrs: preceding_attrs, bounds: Vec::new(), - kind: GenericParamKind::Const { ty, kw_span: const_span, default }, + kind: GenericParamKind::Const { ty, span, default }, is_placeholder: false, colon_span: None, }) @@ -137,6 +142,11 @@ impl<'a> Parser<'a> { // Parse optional const generics default value. let default = if self.eat(exp!(Eq)) { Some(self.parse_const_arg()?) } else { None }; + let span = if let Some(ref default) = default { + mistyped_const_ident.span.to(default.value.span) + } else { + mistyped_const_ident.span.to(ty.span) + }; self.dcx() .struct_span_err( @@ -156,7 +166,7 @@ impl<'a> Parser<'a> { id: ast::DUMMY_NODE_ID, attrs: preceding_attrs, bounds: Vec::new(), - kind: GenericParamKind::Const { ty, kw_span: mistyped_const_ident.span, default }, + kind: GenericParamKind::Const { ty, span, default }, is_placeholder: false, colon_span: None, }) diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index c2bea4e0fdc..08c4a485f26 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1656,7 +1656,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { forward_ty_ban_rib.bindings.swap_remove(i); forward_ty_ban_rib_const_param_ty.bindings.swap_remove(i); } - GenericParamKind::Const { ref ty, kw_span: _, ref default } => { + GenericParamKind::Const { ref ty, span: _, ref default } => { // Const parameters can't have param bounds. assert!(param.bounds.is_empty()); diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 6230b8cfbec..a4022691995 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -2940,7 +2940,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { let span = if let [.., bound] = ¶m.bounds[..] { bound.span() } else if let GenericParam { - kind: GenericParamKind::Const { ty, kw_span: _, default }, .. + kind: GenericParamKind::Const { ty, span: _, default }, .. } = param { default.as_ref().map(|def| def.value.span).unwrap_or(ty.span) } else { |
