mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
add diagnostic for dangling impl
This commit is contained in:
parent
afe6e5ba0f
commit
0b97ae26bf
@ -315,10 +315,21 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxErro
|
||||
}
|
||||
|
||||
fn validate_trait_object_ref_ty(ty: ast::RefType, errors: &mut Vec<SyntaxError>) {
|
||||
if let Some(ast::Type::DynTraitType(ty)) = ty.ty() {
|
||||
if let Some(err) = validate_trait_object_ty(ty) {
|
||||
errors.push(err);
|
||||
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(),
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
25
crates/syntax/test_data/parser/validation/dangling_impl.rast
Normal file
25
crates/syntax/test_data/parser/validation/dangling_impl.rast
Normal file
@ -0,0 +1,25 @@
|
||||
SOURCE_FILE@0..17
|
||||
FN@0..17
|
||||
FN_KW@0..2 "fn"
|
||||
WHITESPACE@2..3 " "
|
||||
NAME@3..4
|
||||
IDENT@3..4 "f"
|
||||
PARAM_LIST@4..14
|
||||
L_PAREN@4..5 "("
|
||||
PARAM@5..13
|
||||
WILDCARD_PAT@5..6
|
||||
UNDERSCORE@5..6 "_"
|
||||
COLON@6..7 ":"
|
||||
WHITESPACE@7..8 " "
|
||||
REF_TYPE@8..13
|
||||
AMP@8..9 "&"
|
||||
IMPL_TRAIT_TYPE@9..13
|
||||
IMPL_KW@9..13 "impl"
|
||||
TYPE_BOUND_LIST@13..13
|
||||
R_PAREN@13..14 ")"
|
||||
WHITESPACE@14..15 " "
|
||||
BLOCK_EXPR@15..17
|
||||
STMT_LIST@15..17
|
||||
L_CURLY@15..16 "{"
|
||||
R_CURLY@16..17 "}"
|
||||
error 9..13: At least one trait must be specified
|
@ -0,0 +1 @@
|
||||
fn f(_: &impl) {}
|
Loading…
x
Reference in New Issue
Block a user