Use Arena inside hir::TraitMethod.

This commit is contained in:
Camille GILLOT 2019-11-30 15:28:32 +01:00
parent deac631d7f
commit 66f9198047
4 changed files with 6 additions and 5 deletions

View File

@ -850,7 +850,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
visitor.visit_ty(ty);
walk_list!(visitor, visit_nested_body, default);
}
TraitItemKind::Method(ref sig, TraitMethod::Required(ref param_names)) => {
TraitItemKind::Method(ref sig, TraitMethod::Required(param_names)) => {
visitor.visit_id(trait_item.hir_id);
visitor.visit_fn_decl(&sig.decl);
for &param_name in param_names {

View File

@ -787,6 +787,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
AssocItemKind::Fn(ref sig, None) => {
let names = self.lower_fn_params_to_names(&sig.decl);
let names: &[Ident] = self.arena.alloc_from_iter(names.into_iter());
let (generics, sig) =
self.lower_method_sig(&i.generics, sig, trait_item_def_id, false, None);
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))

View File

@ -1946,9 +1946,9 @@ pub struct TraitItem<'hir> {
/// Represents a trait method's body (or just argument names).
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum TraitMethod {
pub enum TraitMethod<'hir> {
/// No default body in the trait, just a signature.
Required(HirVec<Ident>),
Required(&'hir [Ident]),
/// Both signature and body are provided in the trait.
Provided(BodyId),
@ -1960,7 +1960,7 @@ pub enum TraitItemKind<'hir> {
/// An associated constant with an optional value (otherwise `impl`s must contain a value).
Const(&'hir Ty, Option<BodyId>),
/// A method with an optional body.
Method(FnSig<'hir>, TraitMethod),
Method(FnSig<'hir>, TraitMethod<'hir>),
/// An associated type with (possibly empty) bounds and optional concrete
/// type.
Type(GenericBounds, Option<&'hir Ty>),

View File

@ -336,7 +336,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
}
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::TraitItem<'_>) {
if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(pnames)) = &item.kind {
if let hir::TraitItemKind::Method(_, hir::TraitMethod::Required(pnames)) = item.kind {
self.check_snake_case(cx, "trait method", &item.ident);
for param_name in pnames {
self.check_snake_case(cx, "variable", param_name);