Introduce BareFnTy::decl_span and fix generics span.
This commit is contained in:
parent
5953c57f27
commit
db8a9274a9
@ -1976,6 +1976,8 @@ pub struct BareFnTy {
|
|||||||
pub ext: Extern,
|
pub ext: Extern,
|
||||||
pub generic_params: Vec<GenericParam>,
|
pub generic_params: Vec<GenericParam>,
|
||||||
pub decl: P<FnDecl>,
|
pub decl: P<FnDecl>,
|
||||||
|
/// Span of the `fn(...) -> ...` part.
|
||||||
|
pub decl_span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The various kinds of type recognized by the compiler.
|
/// The various kinds of type recognized by the compiler.
|
||||||
|
@ -460,10 +460,11 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
|
|||||||
vis.visit_mt(mt);
|
vis.visit_mt(mt);
|
||||||
}
|
}
|
||||||
TyKind::BareFn(bft) => {
|
TyKind::BareFn(bft) => {
|
||||||
let BareFnTy { unsafety, ext: _, generic_params, decl } = bft.deref_mut();
|
let BareFnTy { unsafety, ext: _, generic_params, decl, decl_span } = bft.deref_mut();
|
||||||
visit_unsafety(unsafety, vis);
|
visit_unsafety(unsafety, vis);
|
||||||
generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param));
|
generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param));
|
||||||
vis.visit_fn_decl(decl);
|
vis.visit_fn_decl(decl);
|
||||||
|
vis.visit_span(decl_span);
|
||||||
}
|
}
|
||||||
TyKind::Tup(tys) => visit_vec(tys, |ty| vis.visit_ty(ty)),
|
TyKind::Tup(tys) => visit_vec(tys, |ty| vis.visit_ty(ty)),
|
||||||
TyKind::Paren(ty) => vis.visit_ty(ty),
|
TyKind::Paren(ty) => vis.visit_ty(ty),
|
||||||
|
@ -518,6 +518,7 @@ impl<'a> Parser<'a> {
|
|||||||
kind: rustc_ast::VisibilityKind::Inherited,
|
kind: rustc_ast::VisibilityKind::Inherited,
|
||||||
tokens: None,
|
tokens: None,
|
||||||
};
|
};
|
||||||
|
let span_start = self.token.span;
|
||||||
let ast::FnHeader { ext, unsafety, constness, asyncness } =
|
let ast::FnHeader { ext, unsafety, constness, asyncness } =
|
||||||
self.parse_fn_front_matter(&inherited_vis)?;
|
self.parse_fn_front_matter(&inherited_vis)?;
|
||||||
let decl = self.parse_fn_decl(|_| false, AllowPlus::No, recover_return_sign)?;
|
let decl = self.parse_fn_decl(|_| false, AllowPlus::No, recover_return_sign)?;
|
||||||
@ -531,7 +532,8 @@ impl<'a> Parser<'a> {
|
|||||||
if let ast::Async::Yes { span, .. } = asyncness {
|
if let ast::Async::Yes { span, .. } = asyncness {
|
||||||
self.error_fn_ptr_bad_qualifier(whole_span, span, "async");
|
self.error_fn_ptr_bad_qualifier(whole_span, span, "async");
|
||||||
}
|
}
|
||||||
Ok(TyKind::BareFn(P(BareFnTy { ext, unsafety, generic_params: params, decl })))
|
let decl_span = span_start.to(self.token.span);
|
||||||
|
Ok(TyKind::BareFn(P(BareFnTy { ext, unsafety, generic_params: params, decl, decl_span })))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Emit an error for the given bad function pointer qualifier.
|
/// Emit an error for the given bad function pointer qualifier.
|
||||||
|
@ -594,11 +594,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
|||||||
self.diagnostic_metadata.current_trait_object = Some(&bounds[..]);
|
self.diagnostic_metadata.current_trait_object = Some(&bounds[..]);
|
||||||
}
|
}
|
||||||
TyKind::BareFn(ref bare_fn) => {
|
TyKind::BareFn(ref bare_fn) => {
|
||||||
let span = if bare_fn.generic_params.is_empty() {
|
let span = ty.span.shrink_to_lo().to(bare_fn.decl_span.shrink_to_lo());
|
||||||
ty.span.shrink_to_lo()
|
|
||||||
} else {
|
|
||||||
ty.span
|
|
||||||
};
|
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&bare_fn.generic_params,
|
&bare_fn.generic_params,
|
||||||
NormalRibKind,
|
NormalRibKind,
|
||||||
@ -627,8 +623,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
|||||||
self.diagnostic_metadata.current_type_path = prev_ty;
|
self.diagnostic_metadata.current_type_path = prev_ty;
|
||||||
}
|
}
|
||||||
fn visit_poly_trait_ref(&mut self, tref: &'ast PolyTraitRef, _: &'ast TraitBoundModifier) {
|
fn visit_poly_trait_ref(&mut self, tref: &'ast PolyTraitRef, _: &'ast TraitBoundModifier) {
|
||||||
let span =
|
let span = tref.span.shrink_to_lo().to(tref.trait_ref.path.span.shrink_to_lo());
|
||||||
if tref.bound_generic_params.is_empty() { tref.span.shrink_to_lo() } else { tref.span };
|
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&tref.bound_generic_params,
|
&tref.bound_generic_params,
|
||||||
NormalRibKind,
|
NormalRibKind,
|
||||||
@ -890,11 +885,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
|||||||
..
|
..
|
||||||
}) = p
|
}) = p
|
||||||
{
|
{
|
||||||
let span = if bound_generic_params.is_empty() {
|
let span = predicate_span.shrink_to_lo().to(bounded_ty.span.shrink_to_lo());
|
||||||
predicate_span.shrink_to_lo()
|
|
||||||
} else {
|
|
||||||
*predicate_span
|
|
||||||
};
|
|
||||||
this.with_generic_param_rib(
|
this.with_generic_param_rib(
|
||||||
&bound_generic_params,
|
&bound_generic_params,
|
||||||
NormalRibKind,
|
NormalRibKind,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user