mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 10:39:45 +00:00
Add dangling impl
- Adds dangling impl diagnostics - Rename validation test from dangling_impl to dangling_iml_ref
This commit is contained in:
parent
0b97ae26bf
commit
af959f9031
5 changed files with 54 additions and 31 deletions
|
|
@ -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);
|
||||
}
|
||||
if let Some(ast::Type::DynTraitType(ty)) = ty.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(),
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue