Unnamed repository; edit this file 'description' to name the repository.
Add dangling impl
- Adds dangling impl diagnostics
- Rename validation test from dangling_impl to dangling_iml_ref
5 files changed, 54 insertions, 31 deletions
diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs index 0377e7c0e6..85eefac734 100644 --- a/crates/syntax/src/validation.rs +++ b/crates/syntax/src/validation.rs @@ -37,6 +37,7 @@ pub(crate) fn validate(root: &SyntaxNode, errors: &mut Vec<SyntaxError>) { ast::FnPtrType(it) => validate_trait_object_fn_ptr_ret_ty(it, errors), ast::MacroRules(it) => validate_macro_rules(it, errors), ast::LetExpr(it) => validate_let_expr(it, errors), + ast::ImplTraitType(it) => validate_impl_object_ty(it, errors), _ => (), } } @@ -315,21 +316,10 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxErro } fn validate_trait_object_ref_ty(ty: ast::RefType, errors: &mut Vec<SyntaxError>) { - match ty.ty() { - Some(ast::Type::DynTraitType(ty)) => { - if let Some(err) = validate_trait_object_ty(ty) { - errors.push(err); - } - } - Some(ast::Type::ImplTraitType(ty)) => { - if ty.type_bound_list().map_or(0, |tbl| tbl.bounds().count()) == 0 { - errors.push(SyntaxError::new( - "At least one trait must be specified", - ty.syntax().text_range(), - )); - } + if let Some(ast::Type::DynTraitType(ty)) = ty.ty() { + if let Some(err) = validate_trait_object_ty(ty) { + errors.push(err); } - _ => {} } } @@ -372,6 +362,15 @@ fn validate_trait_object_ty(ty: ast::DynTraitType) -> Option<SyntaxError> { } } +fn validate_impl_object_ty(ty: ast::ImplTraitType, errors: &mut Vec<SyntaxError>) { + if ty.type_bound_list().map_or(0, |tbl| tbl.bounds().count()) == 0 { + errors.push(SyntaxError::new( + "At least one trait must be specified", + ty.syntax().text_range(), + )); + } +} + fn validate_macro_rules(mac: ast::MacroRules, errors: &mut Vec<SyntaxError>) { if let Some(vis) = mac.visibility() { errors.push(SyntaxError::new( diff --git a/crates/syntax/test_data/parser/validation/dangling_impl.rast b/crates/syntax/test_data/parser/validation/dangling_impl.rast index dbe6535ac6..2db07ae12a 100644 --- a/crates/syntax/test_data/parser/validation/dangling_impl.rast +++ b/crates/syntax/test_data/parser/validation/dangling_impl.rast @@ -1,25 +1,23 @@ [email protected] "fn" - [email protected] "&" - [email protected] "impl" - [email protected] ")" - [email protected] " " - [email protected] "{" - [email protected] "}" -error 9..13: At least one trait must be specified + [email protected] "impl" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "}" +error 8..12: At least one trait must be specified diff --git a/crates/syntax/test_data/parser/validation/dangling_impl.rs b/crates/syntax/test_data/parser/validation/dangling_impl.rs index 0b440b4c5a..61706d9e41 100644 --- a/crates/syntax/test_data/parser/validation/dangling_impl.rs +++ b/crates/syntax/test_data/parser/validation/dangling_impl.rs @@ -1 +1 @@ -fn f(_: &impl) {}
\ No newline at end of file +fn f(_: impl) {}
\ No newline at end of file diff --git a/crates/syntax/test_data/parser/validation/dangling_impl_reference.rast b/crates/syntax/test_data/parser/validation/dangling_impl_reference.rast new file mode 100644 index 0000000000..dbe6535ac6 --- /dev/null +++ b/crates/syntax/test_data/parser/validation/dangling_impl_reference.rast @@ -0,0 +1,25 @@ + [email protected] "fn" + [email protected] " " + [email protected] "f" + [email protected] "(" + [email protected] "_" + [email protected] ":" + [email protected] " " + [email protected] "&" + [email protected] "impl" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "}" +error 9..13: At least one trait must be specified diff --git a/crates/syntax/test_data/parser/validation/dangling_impl_reference.rs b/crates/syntax/test_data/parser/validation/dangling_impl_reference.rs new file mode 100644 index 0000000000..0b440b4c5a --- /dev/null +++ b/crates/syntax/test_data/parser/validation/dangling_impl_reference.rs @@ -0,0 +1 @@ +fn f(_: &impl) {}
\ No newline at end of file |