]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_ast_lowering/item.rs
ast: move Generics into AssocItemKinds
[rust.git] / src / librustc_ast_lowering / item.rs
index 8cc3479dd1ba379415c2f548e02e65fe14a4d3d0..073f0c6bc4775c5f91f7492fc6bfd9fa94b2e3e0 100644 (file)
@@ -272,7 +272,7 @@ fn lower_item_kind(
                 let ty = self.lower_ty(
                     t,
                     if self.sess.features_untracked().impl_trait_in_bindings {
-                        ImplTraitContext::OpaqueTy(None)
+                        ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc)
                     } else {
                         ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
                     },
@@ -283,7 +283,7 @@ fn lower_item_kind(
                 let ty = self.lower_ty(
                     t,
                     if self.sess.features_untracked().impl_trait_in_bindings {
-                        ImplTraitContext::OpaqueTy(None)
+                        ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc)
                     } else {
                         ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
                     },
@@ -299,7 +299,7 @@ fn lower_item_kind(
                     // `impl Future<Output = T>` here because lower_body
                     // only cares about the input argument patterns in the function
                     // declaration (decl), not the return types.
-                    let asyncness = header.asyncness.node;
+                    let asyncness = header.asyncness;
                     let body_id =
                         this.lower_maybe_async_body(span, &decl, asyncness, body.as_deref());
 
@@ -327,8 +327,14 @@ fn lower_item_kind(
                 }
                 Some(bounds) => {
                     let ty = hir::OpaqueTy {
-                        generics: self.lower_generics(generics, ImplTraitContext::OpaqueTy(None)),
-                        bounds: self.lower_param_bounds(bounds, ImplTraitContext::OpaqueTy(None)),
+                        generics: self.lower_generics(
+                            generics,
+                            ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc),
+                        ),
+                        bounds: self.lower_param_bounds(
+                            bounds,
+                            ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc),
+                        ),
                         impl_trait_fn: None,
                         origin: hir::OpaqueTyOrigin::TypeAlias,
                     };
@@ -754,31 +760,25 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'hir> {
 
         let (generics, kind) = match i.kind {
             AssocItemKind::Const(ref ty, ref default) => {
-                let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed());
                 let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
-                (
-                    generics,
-                    hir::TraitItemKind::Const(
-                        ty,
-                        default.as_ref().map(|x| self.lower_const_body(i.span, Some(x))),
-                    ),
-                )
+                let body = default.as_ref().map(|x| self.lower_const_body(i.span, Some(x)));
+                (hir::Generics::empty(), hir::TraitItemKind::Const(ty, body))
             }
-            AssocItemKind::Fn(ref sig, None) => {
+            AssocItemKind::Fn(ref sig, ref generics, None) => {
                 let names = self.lower_fn_params_to_names(&sig.decl);
                 let (generics, sig) =
-                    self.lower_method_sig(&i.generics, sig, trait_item_def_id, false, None);
+                    self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
                 (generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
             }
-            AssocItemKind::Fn(ref sig, Some(ref body)) => {
+            AssocItemKind::Fn(ref sig, ref generics, Some(ref body)) => {
                 let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
                 let (generics, sig) =
-                    self.lower_method_sig(&i.generics, sig, trait_item_def_id, false, None);
+                    self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
                 (generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Provided(body_id)))
             }
-            AssocItemKind::TyAlias(ref bounds, ref default) => {
+            AssocItemKind::TyAlias(ref generics, ref bounds, ref default) => {
                 let ty = default.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed()));
-                let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed());
+                let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
                 let kind = hir::TraitItemKind::Type(
                     self.lower_param_bounds(bounds, ImplTraitContext::disallowed()),
                     ty,
@@ -800,10 +800,10 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'hir> {
     }
 
     fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemRef {
-        let (kind, has_default) = match i.kind {
-            AssocItemKind::Const(_, ref default) => (hir::AssocItemKind::Const, default.is_some()),
-            AssocItemKind::TyAlias(_, ref default) => (hir::AssocItemKind::Type, default.is_some()),
-            AssocItemKind::Fn(ref sig, ref default) => {
+        let (kind, has_default) = match &i.kind {
+            AssocItemKind::Const(_, default) => (hir::AssocItemKind::Const, default.is_some()),
+            AssocItemKind::TyAlias(_, _, default) => (hir::AssocItemKind::Type, default.is_some()),
+            AssocItemKind::Fn(sig, _, default) => {
                 (hir::AssocItemKind::Method { has_self: sig.decl.has_self() }, default.is_some())
             }
             AssocItemKind::Macro(..) => unimplemented!(),
@@ -827,34 +827,30 @@ fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem<'hir> {
 
         let (generics, kind) = match i.kind {
             AssocItemKind::Const(ref ty, ref expr) => {
-                let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed());
                 let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
                 (
-                    generics,
+                    hir::Generics::empty(),
                     hir::ImplItemKind::Const(ty, self.lower_const_body(i.span, expr.as_deref())),
                 )
             }
-            AssocItemKind::Fn(ref sig, ref body) => {
+            AssocItemKind::Fn(ref sig, ref generics, ref body) => {
                 self.current_item = Some(i.span);
-                let body_id = self.lower_maybe_async_body(
-                    i.span,
-                    &sig.decl,
-                    sig.header.asyncness.node,
-                    body.as_deref(),
-                );
+                let asyncness = sig.header.asyncness;
+                let body_id =
+                    self.lower_maybe_async_body(i.span, &sig.decl, asyncness, body.as_deref());
                 let impl_trait_return_allow = !self.is_in_trait_impl;
                 let (generics, sig) = self.lower_method_sig(
-                    &i.generics,
+                    generics,
                     sig,
                     impl_item_def_id,
                     impl_trait_return_allow,
-                    sig.header.asyncness.node.opt_return_id(),
+                    asyncness.opt_return_id(),
                 );
 
                 (generics, hir::ImplItemKind::Method(sig, body_id))
             }
-            AssocItemKind::TyAlias(_, ref ty) => {
-                let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed());
+            AssocItemKind::TyAlias(ref generics, _, ref ty) => {
+                let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
                 let kind = match ty {
                     None => {
                         let ty = self.arena.alloc(self.ty(i.span, hir::TyKind::Err));
@@ -899,13 +895,13 @@ fn lower_impl_item_ref(&mut self, i: &AssocItem) -> hir::ImplItemRef<'hir> {
             defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
             kind: match &i.kind {
                 AssocItemKind::Const(..) => hir::AssocItemKind::Const,
-                AssocItemKind::TyAlias(_, ty) => {
+                AssocItemKind::TyAlias(_, _, ty) => {
                     match ty.as_deref().and_then(|ty| ty.kind.opaque_top_hack()) {
                         None => hir::AssocItemKind::Type,
                         Some(_) => hir::AssocItemKind::OpaqueTy,
                     }
                 }
-                AssocItemKind::Fn(sig, _) => {
+                AssocItemKind::Fn(sig, _, _) => {
                     hir::AssocItemKind::Method { has_self: sig.decl.has_self() }
                 }
                 AssocItemKind::Macro(..) => unimplemented!(),
@@ -1033,12 +1029,12 @@ fn lower_maybe_async_body(
         &mut self,
         span: Span,
         decl: &FnDecl,
-        asyncness: IsAsync,
+        asyncness: Async,
         body: Option<&Block>,
     ) -> hir::BodyId {
         let closure_id = match asyncness {
-            IsAsync::Async { closure_id, .. } => closure_id,
-            IsAsync::NotAsync => return self.lower_fn_body_block(span, decl, body),
+            Async::Yes { closure_id, .. } => closure_id,
+            Async::No => return self.lower_fn_body_block(span, decl, body),
         };
 
         self.lower_body(|this| {
@@ -1248,7 +1244,7 @@ fn lower_method_sig(
     fn lower_fn_header(&mut self, h: FnHeader) -> hir::FnHeader {
         hir::FnHeader {
             unsafety: self.lower_unsafety(h.unsafety),
-            asyncness: self.lower_asyncness(h.asyncness.node),
+            asyncness: self.lower_asyncness(h.asyncness),
             constness: self.lower_constness(h.constness),
             abi: self.lower_extern(h.ext),
         }
@@ -1276,10 +1272,10 @@ fn error_on_invalid_abi(&self, abi: StrLit) {
             .emit();
     }
 
-    fn lower_asyncness(&mut self, a: IsAsync) -> hir::IsAsync {
+    fn lower_asyncness(&mut self, a: Async) -> hir::IsAsync {
         match a {
-            IsAsync::Async { .. } => hir::IsAsync::Async,
-            IsAsync::NotAsync => hir::IsAsync::NotAsync,
+            Async::Yes { .. } => hir::IsAsync::Async,
+            Async::No => hir::IsAsync::NotAsync,
         }
     }