mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Merge #10804
10804: fix: Diagnose using `derive` on non-adt items r=Veykril a=Veykril Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
2fafe0e37c
6 changed files with 99 additions and 27 deletions
|
@ -32,6 +32,7 @@ diagnostics![
|
|||
BreakOutsideOfLoop,
|
||||
InactiveCode,
|
||||
IncorrectCase,
|
||||
InvalidDeriveTarget,
|
||||
MacroError,
|
||||
MismatchedArgCount,
|
||||
MissingFields,
|
||||
|
@ -98,6 +99,11 @@ pub struct UnimplementedBuiltinMacro {
|
|||
pub node: InFile<SyntaxNodePtr>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct InvalidDeriveTarget {
|
||||
pub node: InFile<SyntaxNodePtr>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct NoSuchField {
|
||||
pub field: InFile<AstPtr<ast::RecordExprField>>,
|
||||
|
|
|
@ -83,10 +83,10 @@ pub use crate::{
|
|||
attrs::{HasAttrs, Namespace},
|
||||
diagnostics::{
|
||||
AddReferenceHere, AnyDiagnostic, BreakOutsideOfLoop, InactiveCode, IncorrectCase,
|
||||
MacroError, MismatchedArgCount, MissingFields, MissingMatchArms, MissingOkOrSomeInTailExpr,
|
||||
MissingUnsafe, NoSuchField, RemoveThisSemicolon, ReplaceFilterMapNextWithFindMap,
|
||||
UnimplementedBuiltinMacro, UnresolvedExternCrate, UnresolvedImport, UnresolvedMacroCall,
|
||||
UnresolvedModule, UnresolvedProcMacro,
|
||||
InvalidDeriveTarget, MacroError, MismatchedArgCount, MissingFields, MissingMatchArms,
|
||||
MissingOkOrSomeInTailExpr, MissingUnsafe, NoSuchField, RemoveThisSemicolon,
|
||||
ReplaceFilterMapNextWithFindMap, UnimplementedBuiltinMacro, UnresolvedExternCrate,
|
||||
UnresolvedImport, UnresolvedMacroCall, UnresolvedModule, UnresolvedProcMacro,
|
||||
},
|
||||
has_source::HasSource,
|
||||
semantics::{PathResolution, Semantics, SemanticsScope, TypeInfo},
|
||||
|
@ -654,6 +654,21 @@ impl Module {
|
|||
.into(),
|
||||
);
|
||||
}
|
||||
DefDiagnosticKind::InvalidDeriveTarget { ast, id } => {
|
||||
let node = ast.to_node(db.upcast());
|
||||
let derive = node.attrs().nth(*id as usize);
|
||||
match derive {
|
||||
Some(derive) => {
|
||||
acc.push(
|
||||
InvalidDeriveTarget {
|
||||
node: ast.with_value(SyntaxNodePtr::from(AstPtr::new(&derive))),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
None => stdx::never!("derive diagnostic on item without derive attribute"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for decl in self.declarations(db) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue