From 479babf8740a4d3cf6fc03a5f4a2fca00d387501 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 15 Dec 2020 15:37:49 +0100 Subject: [PATCH] Reject visibilities on `macro_rules!` --- crates/syntax/src/validation.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs index 6f45149bf65..2ddaeb17662 100644 --- a/crates/syntax/src/validation.rs +++ b/crates/syntax/src/validation.rs @@ -3,7 +3,9 @@ mod block; use crate::{ - algo, ast, match_ast, AstNode, SyntaxError, + algo, + ast::{self, VisibilityOwner}, + match_ast, AstNode, SyntaxError, SyntaxKind::{CONST, FN, INT_NUMBER, TYPE_ALIAS}, SyntaxNode, SyntaxToken, TextSize, T, }; @@ -99,6 +101,7 @@ pub(crate) fn validate(root: &SyntaxNode) -> Vec { ast::RefType(it) => validate_trait_object_ref_ty(it, &mut errors), ast::PtrType(it) => validate_trait_object_ptr_ty(it, &mut errors), ast::FnPtrType(it) => validate_trait_object_fn_ptr_ret_ty(it, &mut errors), + ast::MacroRules(it) => validate_macro_rules(it, &mut errors), _ => (), } } @@ -350,3 +353,12 @@ fn validate_trait_object_ty(ty: ast::DynTraitType) -> Option { } None } + +fn validate_macro_rules(mac: ast::MacroRules, errors: &mut Vec) { + if let Some(vis) = mac.visibility() { + errors.push(SyntaxError::new( + "visibilities are not allowed on `macro_rules!` items", + vis.syntax().text_range(), + )); + } +}