Replace kw_span by full span.
This commit is contained in:
@@ -385,8 +385,8 @@ pub enum GenericParamKind {
|
|||||||
},
|
},
|
||||||
Const {
|
Const {
|
||||||
ty: P<Ty>,
|
ty: P<Ty>,
|
||||||
/// Span of the `const` keyword.
|
/// Span of the whole parameter definition, including default.
|
||||||
kw_span: Span,
|
span: Span,
|
||||||
/// Optional default value for the const generic param.
|
/// Optional default value for the const generic param.
|
||||||
default: Option<AnonConst>,
|
default: Option<AnonConst>,
|
||||||
},
|
},
|
||||||
@@ -410,10 +410,7 @@ impl GenericParam {
|
|||||||
self.ident.span
|
self.ident.span
|
||||||
}
|
}
|
||||||
GenericParamKind::Type { default: Some(ty) } => self.ident.span.to(ty.span),
|
GenericParamKind::Type { default: Some(ty) } => self.ident.span.to(ty.span),
|
||||||
GenericParamKind::Const { kw_span, default: Some(default), .. } => {
|
GenericParamKind::Const { span, .. } => *span,
|
||||||
kw_span.to(default.value.span)
|
|
||||||
}
|
|
||||||
GenericParamKind::Const { kw_span, default: None, ty } => kw_span.to(ty.span),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1350,9 +1350,10 @@ macro_rules! common_visitor_and_walkers {
|
|||||||
match kind {
|
match kind {
|
||||||
GenericParamKind::Lifetime => (),
|
GenericParamKind::Lifetime => (),
|
||||||
GenericParamKind::Type { default } => visit_opt!(vis, visit_ty, default),
|
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));
|
try_visit!(vis.visit_ty(ty));
|
||||||
visit_opt!(vis, visit_anon_const, default);
|
visit_opt!(vis, visit_anon_const, default);
|
||||||
|
try_visit!(visit_span(vis, span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(sp) = colon_span {
|
if let Some(sp) = colon_span {
|
||||||
|
|||||||
@@ -1960,7 +1960,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
|
|
||||||
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
|
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
|
||||||
}
|
}
|
||||||
GenericParamKind::Const { ty, kw_span: _, default } => {
|
GenericParamKind::Const { ty, span: _, default } => {
|
||||||
let ty = self
|
let ty = self
|
||||||
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault));
|
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault));
|
||||||
|
|
||||||
|
|||||||
@@ -909,11 +909,11 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara
|
|||||||
}
|
}
|
||||||
GenericParamKind::Type { default: None } => (),
|
GenericParamKind::Type { default: None } => (),
|
||||||
GenericParamKind::Lifetime => (),
|
GenericParamKind::Lifetime => (),
|
||||||
GenericParamKind::Const { ty: _, kw_span: _, default: Some(default) } => {
|
GenericParamKind::Const { ty: _, span: _, default: Some(default) } => {
|
||||||
ordered_params += " = ";
|
ordered_params += " = ";
|
||||||
ordered_params += &pprust::expr_to_string(&default.value);
|
ordered_params += &pprust::expr_to_string(&default.value);
|
||||||
}
|
}
|
||||||
GenericParamKind::Const { ty: _, kw_span: _, default: None } => (),
|
GenericParamKind::Const { ty: _, span: _, default: None } => (),
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ pub(crate) fn expand_deriving_coerce_pointee(
|
|||||||
GenericParamKind::Type { default: _ } => {
|
GenericParamKind::Type { default: _ } => {
|
||||||
cx.typaram(p.span(), p.ident, p.bounds.clone(), None)
|
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(
|
.const_param(
|
||||||
p.span(),
|
p.span(),
|
||||||
p.ident,
|
p.ident,
|
||||||
|
|||||||
@@ -664,10 +664,10 @@ impl<'a> TraitDef<'a> {
|
|||||||
|
|
||||||
cx.typaram(param.ident.span.with_ctxt(ctxt), param.ident, bounds, None)
|
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 {
|
let const_nodefault_kind = GenericParamKind::Const {
|
||||||
ty: ty.clone(),
|
ty: ty.clone(),
|
||||||
kw_span: kw_span.with_ctxt(ctxt),
|
span: span.with_ctxt(ctxt),
|
||||||
|
|
||||||
// We can't have default values inside impl block
|
// We can't have default values inside impl block
|
||||||
default: None,
|
default: None,
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ impl<'a> ExtCtxt<'a> {
|
|||||||
attrs: AttrVec::new(),
|
attrs: AttrVec::new(),
|
||||||
bounds,
|
bounds,
|
||||||
is_placeholder: false,
|
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,
|
colon_span: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,13 +114,18 @@ impl<'a> Parser<'a> {
|
|||||||
|
|
||||||
// Parse optional const generics default value.
|
// Parse optional const generics default value.
|
||||||
let default = if self.eat(exp!(Eq)) { Some(self.parse_const_arg()?) } else { None };
|
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 {
|
Ok(GenericParam {
|
||||||
ident,
|
ident,
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
attrs: preceding_attrs,
|
attrs: preceding_attrs,
|
||||||
bounds: Vec::new(),
|
bounds: Vec::new(),
|
||||||
kind: GenericParamKind::Const { ty, kw_span: const_span, default },
|
kind: GenericParamKind::Const { ty, span, default },
|
||||||
is_placeholder: false,
|
is_placeholder: false,
|
||||||
colon_span: None,
|
colon_span: None,
|
||||||
})
|
})
|
||||||
@@ -137,6 +142,11 @@ impl<'a> Parser<'a> {
|
|||||||
|
|
||||||
// Parse optional const generics default value.
|
// Parse optional const generics default value.
|
||||||
let default = if self.eat(exp!(Eq)) { Some(self.parse_const_arg()?) } else { None };
|
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()
|
self.dcx()
|
||||||
.struct_span_err(
|
.struct_span_err(
|
||||||
@@ -156,7 +166,7 @@ impl<'a> Parser<'a> {
|
|||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
attrs: preceding_attrs,
|
attrs: preceding_attrs,
|
||||||
bounds: Vec::new(),
|
bounds: Vec::new(),
|
||||||
kind: GenericParamKind::Const { ty, kw_span: mistyped_const_ident.span, default },
|
kind: GenericParamKind::Const { ty, span, default },
|
||||||
is_placeholder: false,
|
is_placeholder: false,
|
||||||
colon_span: None,
|
colon_span: None,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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.bindings.swap_remove(i);
|
||||||
forward_ty_ban_rib_const_param_ty.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.
|
// Const parameters can't have param bounds.
|
||||||
assert!(param.bounds.is_empty());
|
assert!(param.bounds.is_empty());
|
||||||
|
|
||||||
|
|||||||
@@ -2940,7 +2940,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
|||||||
let span = if let [.., bound] = ¶m.bounds[..] {
|
let span = if let [.., bound] = ¶m.bounds[..] {
|
||||||
bound.span()
|
bound.span()
|
||||||
} else if let GenericParam {
|
} else if let GenericParam {
|
||||||
kind: GenericParamKind::Const { ty, kw_span: _, default }, ..
|
kind: GenericParamKind::Const { ty, span: _, default }, ..
|
||||||
} = param {
|
} = param {
|
||||||
default.as_ref().map(|def| def.value.span).unwrap_or(ty.span)
|
default.as_ref().map(|def| def.value.span).unwrap_or(ty.span)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -886,13 +886,13 @@ pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool {
|
|||||||
(
|
(
|
||||||
Const {
|
Const {
|
||||||
ty: lt,
|
ty: lt,
|
||||||
kw_span: _,
|
|
||||||
default: ld,
|
default: ld,
|
||||||
|
span: _,
|
||||||
},
|
},
|
||||||
Const {
|
Const {
|
||||||
ty: rt,
|
ty: rt,
|
||||||
kw_span: _,
|
|
||||||
default: rd,
|
default: rd,
|
||||||
|
span: _,
|
||||||
},
|
},
|
||||||
) => eq_ty(lt, rt) && both(ld.as_ref(), rd.as_ref(), eq_anon_const),
|
) => eq_ty(lt, rt) && both(ld.as_ref(), rd.as_ref(), eq_anon_const),
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ impl Spanned for ast::GenericParam {
|
|||||||
fn span(&self) -> Span {
|
fn span(&self) -> Span {
|
||||||
let lo = match self.kind {
|
let lo = match self.kind {
|
||||||
_ if !self.attrs.is_empty() => self.attrs[0].span.lo(),
|
_ if !self.attrs.is_empty() => self.attrs[0].span.lo(),
|
||||||
ast::GenericParamKind::Const { kw_span, .. } => kw_span.lo(),
|
ast::GenericParamKind::Const { span, .. } => span.lo(),
|
||||||
_ => self.ident.span.lo(),
|
_ => self.ident.span.lo(),
|
||||||
};
|
};
|
||||||
let hi = if self.bounds.is_empty() {
|
let hi = if self.bounds.is_empty() {
|
||||||
|
|||||||
@@ -689,7 +689,7 @@ impl Rewrite for ast::GenericParam {
|
|||||||
|
|
||||||
let param_start = if let ast::GenericParamKind::Const {
|
let param_start = if let ast::GenericParamKind::Const {
|
||||||
ref ty,
|
ref ty,
|
||||||
kw_span,
|
span,
|
||||||
default,
|
default,
|
||||||
} = &self.kind
|
} = &self.kind
|
||||||
{
|
{
|
||||||
@@ -711,7 +711,7 @@ impl Rewrite for ast::GenericParam {
|
|||||||
default.rewrite_result(context, Shape::legacy(budget, shape.indent))?;
|
default.rewrite_result(context, Shape::legacy(budget, shape.indent))?;
|
||||||
param.push_str(&rewrite);
|
param.push_str(&rewrite);
|
||||||
}
|
}
|
||||||
kw_span.lo()
|
span.lo()
|
||||||
} else {
|
} else {
|
||||||
param.push_str(rewrite_ident(context, self.ident));
|
param.push_str(rewrite_ident(context, self.ident));
|
||||||
self.ident.span.lo()
|
self.ident.span.lo()
|
||||||
|
|||||||
Reference in New Issue
Block a user