diff options
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/syntax_error.rs | 4 | ||||
-rw-r--r-- | crates/ra_syntax/src/validation.rs | 23 |
2 files changed, 26 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/syntax_error.rs b/crates/ra_syntax/src/syntax_error.rs index d6eca2ad7..1f60a7aab 100644 --- a/crates/ra_syntax/src/syntax_error.rs +++ b/crates/ra_syntax/src/syntax_error.rs | |||
@@ -82,6 +82,7 @@ pub enum SyntaxErrorKind { | |||
82 | InvalidBlockAttr, | 82 | InvalidBlockAttr, |
83 | InvalidMatchInnerAttr, | 83 | InvalidMatchInnerAttr, |
84 | InvalidTupleIndexFormat, | 84 | InvalidTupleIndexFormat, |
85 | VisibilityNotAllowed, | ||
85 | } | 86 | } |
86 | 87 | ||
87 | impl fmt::Display for SyntaxErrorKind { | 88 | impl fmt::Display for SyntaxErrorKind { |
@@ -99,6 +100,9 @@ impl fmt::Display for SyntaxErrorKind { | |||
99 | } | 100 | } |
100 | ParseError(msg) => write!(f, "{}", msg.0), | 101 | ParseError(msg) => write!(f, "{}", msg.0), |
101 | EscapeError(err) => write!(f, "{}", err), | 102 | EscapeError(err) => write!(f, "{}", err), |
103 | VisibilityNotAllowed => { | ||
104 | write!(f, "unnecessary visibility qualifier") | ||
105 | } | ||
102 | } | 106 | } |
103 | } | 107 | } |
104 | } | 108 | } |
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs index ab4f15908..2d596763e 100644 --- a/crates/ra_syntax/src/validation.rs +++ b/crates/ra_syntax/src/validation.rs | |||
@@ -6,7 +6,7 @@ use rustc_lexer::unescape; | |||
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | ast, match_ast, AstNode, SyntaxError, SyntaxErrorKind, | 8 | ast, match_ast, AstNode, SyntaxError, SyntaxErrorKind, |
9 | SyntaxKind::{BYTE, BYTE_STRING, CHAR, INT_NUMBER, STRING}, | 9 | SyntaxKind::{BYTE, BYTE_STRING, CHAR, CONST_DEF, FN_DEF, INT_NUMBER, STRING, TYPE_ALIAS_DEF}, |
10 | SyntaxNode, SyntaxToken, TextUnit, T, | 10 | SyntaxNode, SyntaxToken, TextUnit, T, |
11 | }; | 11 | }; |
12 | 12 | ||
@@ -102,6 +102,7 @@ pub(crate) fn validate(root: &SyntaxNode) -> Vec<SyntaxError> { | |||
102 | ast::BlockExpr(it) => { block::validate_block_expr(it, &mut errors) }, | 102 | ast::BlockExpr(it) => { block::validate_block_expr(it, &mut errors) }, |
103 | ast::FieldExpr(it) => { validate_numeric_name(it.name_ref(), &mut errors) }, | 103 | ast::FieldExpr(it) => { validate_numeric_name(it.name_ref(), &mut errors) }, |
104 | ast::RecordField(it) => { validate_numeric_name(it.name_ref(), &mut errors) }, | 104 | ast::RecordField(it) => { validate_numeric_name(it.name_ref(), &mut errors) }, |
105 | ast::Visibility(it) => { validate_visibility(it, &mut errors) }, | ||
105 | _ => (), | 106 | _ => (), |
106 | } | 107 | } |
107 | } | 108 | } |
@@ -206,3 +207,23 @@ fn validate_numeric_name(name_ref: Option<ast::NameRef>, errors: &mut Vec<Syntax | |||
206 | name_ref?.syntax().first_child_or_token()?.into_token().filter(|it| it.kind() == INT_NUMBER) | 207 | name_ref?.syntax().first_child_or_token()?.into_token().filter(|it| it.kind() == INT_NUMBER) |
207 | } | 208 | } |
208 | } | 209 | } |
210 | |||
211 | fn validate_visibility(vis: ast::Visibility, errors: &mut Vec<SyntaxError>) { | ||
212 | let parent = match vis.syntax().parent() { | ||
213 | Some(it) => it, | ||
214 | None => return, | ||
215 | }; | ||
216 | match parent.kind() { | ||
217 | FN_DEF | CONST_DEF | TYPE_ALIAS_DEF => (), | ||
218 | _ => return, | ||
219 | } | ||
220 | let impl_block = match parent.parent().and_then(|it| it.parent()).and_then(ast::ImplBlock::cast) | ||
221 | { | ||
222 | Some(it) => it, | ||
223 | None => return, | ||
224 | }; | ||
225 | if impl_block.target_trait().is_some() { | ||
226 | errors | ||
227 | .push(SyntaxError::new(SyntaxErrorKind::VisibilityNotAllowed, vis.syntax.text_range())) | ||
228 | } | ||
229 | } | ||