mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
⬆️ rust-analyzer
This commit is contained in:
parent
15b867b5db
commit
b2f6fd4f96
217 changed files with 12639 additions and 3059 deletions
39
crates/ide-diagnostics/src/handlers/expected_function.rs
Normal file
39
crates/ide-diagnostics/src/handlers/expected_function.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
use hir::HirDisplay;
|
||||
|
||||
use crate::{Diagnostic, DiagnosticsContext};
|
||||
|
||||
// Diagnostic: expected-function
|
||||
//
|
||||
// This diagnostic is triggered if a call is made on something that is not callable.
|
||||
pub(crate) fn expected_function(
|
||||
ctx: &DiagnosticsContext<'_>,
|
||||
d: &hir::ExpectedFunction,
|
||||
) -> Diagnostic {
|
||||
Diagnostic::new(
|
||||
"expected-function",
|
||||
format!("expected function, found {}", d.found.display(ctx.sema.db)),
|
||||
ctx.sema.diagnostics_display_range(d.call.clone().map(|it| it.into())).range,
|
||||
)
|
||||
.experimental()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests::check_diagnostics;
|
||||
|
||||
#[test]
|
||||
fn smoke_test() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
fn foo() {
|
||||
let x = 3;
|
||||
x();
|
||||
// ^^^ error: expected function, found i32
|
||||
""();
|
||||
// ^^^^ error: expected function, found &str
|
||||
foo();
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue