]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_ast_passes/ast_validation.rs
parse: allow `type Foo: Ord` syntactically.
[rust.git] / src / librustc_ast_passes / ast_validation.rs
index 8efd50ad0987efbd559cf6c2641cc49c3e43632f..a9844a7059e552f1fa9c2d7f629013cfc744d85f 100644 (file)
@@ -533,20 +533,6 @@ fn check_foreign_fn_headerless(&self, ident: Ident, span: Span, header: FnHeader
         }
     }
 
-    fn error_foreign_const(&self, ident: Ident, span: Span) {
-        self.err_handler()
-            .struct_span_err(ident.span, "extern items cannot be `const`")
-            .span_suggestion(
-                span.with_hi(ident.span.lo()),
-                "try using a static value",
-                "static ".to_string(),
-                Applicability::MachineApplicable,
-            )
-            .span_label(self.current_extern_span(), "in this `extern` block")
-            .note(MORE_EXTERN)
-            .emit();
-    }
-
     /// Reject C-varadic type unless the function is foreign,
     /// or free and `unsafe extern "C"` semantically.
     fn check_c_varadic_type(&self, fk: FnKind<'a>) {
@@ -983,6 +969,13 @@ fn visit_item(&mut self, item: &'a Item) {
                 let msg = "free static item without body";
                 self.error_item_without_body(item.span, "static", msg, " = <expr>;");
             }
+            ItemKind::TyAlias(_, ref bounds, ref body) => {
+                if body.is_none() {
+                    let msg = "free type alias without body";
+                    self.error_item_without_body(item.span, "type", msg, " = <type>;");
+                }
+                self.check_type_no_bounds(bounds, "this context");
+            }
             _ => {}
         }
 
@@ -1003,10 +996,7 @@ fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
             ForeignItemKind::Static(_, _, body) => {
                 self.check_foreign_kind_bodyless(fi.ident, "static", body.as_ref().map(|b| b.span));
             }
-            ForeignItemKind::Const(..) => {
-                self.error_foreign_const(fi.ident, fi.span);
-            }
-            ForeignItemKind::Macro(..) => {}
+            ForeignItemKind::Const(..) | ForeignItemKind::Macro(..) => {}
         }
 
         visit::walk_foreign_item(self, fi)
@@ -1048,7 +1038,7 @@ fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) {
             }
             GenericArgs::Parenthesized(ref data) => {
                 walk_list!(self, visit_ty, &data.inputs);
-                if let FunctionRetTy::Ty(ty) = &data.output {
+                if let FnRetTy::Ty(ty) = &data.output {
                     // `-> Foo` syntax is essentially an associated type binding,
                     // so it is also allowed to contain nested `impl Trait`.
                     self.with_impl_trait(None, |this| this.visit_ty(ty));
@@ -1267,13 +1257,8 @@ fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
             }
         }
 
-        match item.kind {
-            AssocItemKind::Const(..) => self.check_item_named(item.ident, "const"),
-            AssocItemKind::Static(..) => self
-                .err_handler()
-                .struct_span_err(item.span, "associated `static` items are not allowed")
-                .emit(),
-            _ => {}
+        if let AssocItemKind::Const(..) = item.kind {
+            self.check_item_named(item.ident, "const");
         }
 
         self.with_in_trait_impl(false, |this| visit::walk_assoc_item(this, item, ctxt));