Skip to content

Commit d3621ee

Browse files
committed
internal: refactor unimplemented builtin macro diagnostic
1 parent dec207f commit d3621ee

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

crates/hir/src/diagnostics.rs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ macro_rules! diagnostics {
3232
}
3333

3434
diagnostics![
35-
UnresolvedModule,
35+
InactiveCode,
36+
MacroError,
37+
MissingFields,
38+
UnimplementedBuiltinMacro,
3639
UnresolvedExternCrate,
3740
UnresolvedImport,
3841
UnresolvedMacroCall,
42+
UnresolvedModule,
3943
UnresolvedProcMacro,
40-
MacroError,
41-
MissingFields,
42-
InactiveCode,
4344
];
4445

4546
#[derive(Debug)]
@@ -88,26 +89,7 @@ pub struct MacroError {
8889

8990
#[derive(Debug)]
9091
pub struct UnimplementedBuiltinMacro {
91-
pub file: HirFileId,
92-
pub node: SyntaxNodePtr,
93-
}
94-
95-
impl Diagnostic for UnimplementedBuiltinMacro {
96-
fn code(&self) -> DiagnosticCode {
97-
DiagnosticCode("unimplemented-builtin-macro")
98-
}
99-
100-
fn message(&self) -> String {
101-
"unimplemented built-in macro".to_string()
102-
}
103-
104-
fn display_source(&self) -> InFile<SyntaxNodePtr> {
105-
InFile::new(self.file, self.node.clone())
106-
}
107-
108-
fn as_any(&self) -> &(dyn Any + Send + 'static) {
109-
self
110-
}
92+
pub node: InFile<SyntaxNodePtr>,
11193
}
11294

11395
// Diagnostic: no-such-field

crates/hir/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,12 @@ impl Module {
606606
let node = ast.to_node(db.upcast());
607607
// Must have a name, otherwise we wouldn't emit it.
608608
let name = node.name().expect("unimplemented builtin macro with no name");
609-
let ptr = SyntaxNodePtr::from(AstPtr::new(&name));
610-
sink.push(UnimplementedBuiltinMacro { file: ast.file_id, node: ptr });
609+
acc.push(
610+
UnimplementedBuiltinMacro {
611+
node: ast.with_value(SyntaxNodePtr::from(AstPtr::new(&name))),
612+
}
613+
.into(),
614+
);
611615
}
612616
}
613617
}

crates/ide/src/diagnostics.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod unresolved_extern_crate;
99
mod unresolved_import;
1010
mod unresolved_macro_call;
1111
mod unresolved_proc_macro;
12+
mod unimplemented_builtin_macro;
1213
mod macro_error;
1314
mod inactive_code;
1415
mod missing_fields;
@@ -185,11 +186,6 @@ pub(crate) fn diagnostics(
185186
.with_code(Some(d.code())),
186187
);
187188
})
188-
.on::<hir::diagnostics::UnimplementedBuiltinMacro, _>(|d| {
189-
let display_range = sema.diagnostics_display_range(d.display_source()).range;
190-
res.borrow_mut()
191-
.push(Diagnostic::hint(display_range, d.message()).with_code(Some(d.code())));
192-
})
193189
// Only collect experimental diagnostics when they're enabled.
194190
.filter(|diag| !(diag.is_experimental() && config.disable_experimental))
195191
.filter(|diag| !config.disabled.contains(diag.code().as_str()));
@@ -229,6 +225,7 @@ pub(crate) fn diagnostics(
229225
AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d),
230226
AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d),
231227
AnyDiagnostic::UnresolvedProcMacro(d) => unresolved_proc_macro::unresolved_proc_macro(&ctx, &d),
228+
AnyDiagnostic::UnimplementedBuiltinMacro(d) => unimplemented_builtin_macro::unimplemented_builtin_macro(&ctx, &d),
232229
AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d),
233230
AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d),
234231

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::{
2+
diagnostics::{Diagnostic, DiagnosticsContext},
3+
Severity,
4+
};
5+
6+
// Diagnostic: unimplemented-builtin-macro
7+
//
8+
// This diagnostic is shown for builtin macros which are not yet implemented by rust-analyzer
9+
pub(super) fn unimplemented_builtin_macro(
10+
ctx: &DiagnosticsContext<'_>,
11+
d: &hir::UnimplementedBuiltinMacro,
12+
) -> Diagnostic {
13+
Diagnostic::new(
14+
"unimplemented-builtin-macro",
15+
"unimplemented built-in macro".to_string(),
16+
ctx.sema.diagnostics_display_range(d.node.clone()).range,
17+
)
18+
.severity(Severity::WeakWarning)
19+
}

0 commit comments

Comments
 (0)