mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 10:39:45 +00:00
add diagnostic for dangling dyn
This commit is contained in:
parent
9df88ff0f6
commit
afe6e5ba0f
3 changed files with 42 additions and 8 deletions
|
|
@ -340,17 +340,25 @@ fn validate_trait_object_fn_ptr_ret_ty(ty: ast::FnPtrType, errors: &mut Vec<Synt
|
|||
|
||||
fn validate_trait_object_ty(ty: ast::DynTraitType) -> Option<SyntaxError> {
|
||||
let tbl = ty.type_bound_list()?;
|
||||
let bounds_count = tbl.bounds().count();
|
||||
|
||||
if tbl.bounds().count() > 1 {
|
||||
let dyn_token = ty.dyn_token()?;
|
||||
let potential_parenthesis =
|
||||
algo::skip_trivia_token(dyn_token.prev_token()?, Direction::Prev)?;
|
||||
let kind = potential_parenthesis.kind();
|
||||
if !matches!(kind, T!['('] | T![<] | T![=]) {
|
||||
return Some(SyntaxError::new("ambiguous `+` in a type", ty.syntax().text_range()));
|
||||
match bounds_count {
|
||||
0 => Some(SyntaxError::new(
|
||||
"At least one trait is required for an object type",
|
||||
ty.syntax().text_range(),
|
||||
)),
|
||||
_ if bounds_count > 1 => {
|
||||
let dyn_token = ty.dyn_token()?;
|
||||
let preceding_token =
|
||||
algo::skip_trivia_token(dyn_token.prev_token()?, Direction::Prev)?;
|
||||
|
||||
if !matches!(preceding_token.kind(), T!['('] | T![<] | T![=]) {
|
||||
return Some(SyntaxError::new("ambiguous `+` in a type", ty.syntax().text_range()));
|
||||
}
|
||||
None
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn validate_macro_rules(mac: ast::MacroRules, errors: &mut Vec<SyntaxError>) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue