Skip to content

Commit c2a630e

Browse files
committed
Add dangling impl
- Adds dangling impl diagnostics - Rename validation test from dangling_impl to dangling_iml_ref
1 parent 1840f57 commit c2a630e

File tree

5 files changed

+54
-31
lines changed

5 files changed

+54
-31
lines changed

src/tools/rust-analyzer/crates/syntax/src/validation.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub(crate) fn validate(root: &SyntaxNode, errors: &mut Vec<SyntaxError>) {
3737
ast::FnPtrType(it) => validate_trait_object_fn_ptr_ret_ty(it, errors),
3838
ast::MacroRules(it) => validate_macro_rules(it, errors),
3939
ast::LetExpr(it) => validate_let_expr(it, errors),
40+
ast::ImplTraitType(it) => validate_impl_object_ty(it, errors),
4041
_ => (),
4142
}
4243
}
@@ -315,21 +316,10 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxErro
315316
}
316317

317318
fn validate_trait_object_ref_ty(ty: ast::RefType, errors: &mut Vec<SyntaxError>) {
318-
match ty.ty() {
319-
Some(ast::Type::DynTraitType(ty)) => {
320-
if let Some(err) = validate_trait_object_ty(ty) {
321-
errors.push(err);
322-
}
323-
}
324-
Some(ast::Type::ImplTraitType(ty)) => {
325-
if ty.type_bound_list().map_or(0, |tbl| tbl.bounds().count()) == 0 {
326-
errors.push(SyntaxError::new(
327-
"At least one trait must be specified",
328-
ty.syntax().text_range(),
329-
));
330-
}
319+
if let Some(ast::Type::DynTraitType(ty)) = ty.ty() {
320+
if let Some(err) = validate_trait_object_ty(ty) {
321+
errors.push(err);
331322
}
332-
_ => {}
333323
}
334324
}
335325

@@ -372,6 +362,15 @@ fn validate_trait_object_ty(ty: ast::DynTraitType) -> Option<SyntaxError> {
372362
}
373363
}
374364

365+
fn validate_impl_object_ty(ty: ast::ImplTraitType, errors: &mut Vec<SyntaxError>) {
366+
if ty.type_bound_list().map_or(0, |tbl| tbl.bounds().count()) == 0 {
367+
errors.push(SyntaxError::new(
368+
"At least one trait must be specified",
369+
ty.syntax().text_range(),
370+
));
371+
}
372+
}
373+
375374
fn validate_macro_rules(mac: ast::MacroRules, errors: &mut Vec<SyntaxError>) {
376375
if let Some(vis) = mac.visibility() {
377376
errors.push(SyntaxError::new(
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
SOURCE_FILE@0..17
2-
FN@0..17
1+
SOURCE_FILE@0..16
2+
FN@0..16
33
44
55
66
7-
PARAM_LIST@4..14
7+
PARAM_LIST@4..13
88
9-
PARAM@5..13
9+
PARAM@5..12
1010
1111
1212
1313
14-
15-
16-
17-
18-
19-
20-
21-
22-
23-
24-
25-
error 9..13: At least one trait must be specified
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
error 8..12: At least one trait must be specified
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fn f(_: &impl) {}
1+
fn f(_: impl) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn f(_: &impl) {}

0 commit comments

Comments
 (0)