Introduce BareFnTy::decl_span and fix generics span.
This commit is contained in:
parent
5953c57f27
commit
db8a9274a9
4 changed files with 10 additions and 14 deletions
|
@ -1976,6 +1976,8 @@ pub struct BareFnTy {
|
|||
pub ext: Extern,
|
||||
pub generic_params: Vec<GenericParam>,
|
||||
pub decl: P<FnDecl>,
|
||||
/// Span of the `fn(...) -> ...` part.
|
||||
pub decl_span: Span,
|
||||
}
|
||||
|
||||
/// 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);
|
||||
}
|
||||
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);
|
||||
generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param));
|
||||
vis.visit_fn_decl(decl);
|
||||
vis.visit_span(decl_span);
|
||||
}
|
||||
TyKind::Tup(tys) => visit_vec(tys, |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,
|
||||
tokens: None,
|
||||
};
|
||||
let span_start = self.token.span;
|
||||
let ast::FnHeader { ext, unsafety, constness, asyncness } =
|
||||
self.parse_fn_front_matter(&inherited_vis)?;
|
||||
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 {
|
||||
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.
|
||||
|
|
|
@ -594,11 +594,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
|||
self.diagnostic_metadata.current_trait_object = Some(&bounds[..]);
|
||||
}
|
||||
TyKind::BareFn(ref bare_fn) => {
|
||||
let span = if bare_fn.generic_params.is_empty() {
|
||||
ty.span.shrink_to_lo()
|
||||
} else {
|
||||
ty.span
|
||||
};
|
||||
let span = ty.span.shrink_to_lo().to(bare_fn.decl_span.shrink_to_lo());
|
||||
self.with_generic_param_rib(
|
||||
&bare_fn.generic_params,
|
||||
NormalRibKind,
|
||||
|
@ -627,8 +623,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
|||
self.diagnostic_metadata.current_type_path = prev_ty;
|
||||
}
|
||||
fn visit_poly_trait_ref(&mut self, tref: &'ast PolyTraitRef, _: &'ast TraitBoundModifier) {
|
||||
let span =
|
||||
if tref.bound_generic_params.is_empty() { tref.span.shrink_to_lo() } else { tref.span };
|
||||
let span = tref.span.shrink_to_lo().to(tref.trait_ref.path.span.shrink_to_lo());
|
||||
self.with_generic_param_rib(
|
||||
&tref.bound_generic_params,
|
||||
NormalRibKind,
|
||||
|
@ -890,11 +885,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
|||
..
|
||||
}) = p
|
||||
{
|
||||
let span = if bound_generic_params.is_empty() {
|
||||
predicate_span.shrink_to_lo()
|
||||
} else {
|
||||
*predicate_span
|
||||
};
|
||||
let span = predicate_span.shrink_to_lo().to(bounded_ty.span.shrink_to_lo());
|
||||
this.with_generic_param_rib(
|
||||
&bound_generic_params,
|
||||
NormalRibKind,
|
||||
|
|
Loading…
Add table
Reference in a new issue