mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-02 04:48:13 +00:00
Emit an error when RTN is used in an incorrect place
We miss one place: associated type bindings aka. `impl Trait<Type(..): Send>`, but we also miss it for Fn-style parenthesizes error so I left it out for now.
This commit is contained in:
parent
eaa0a39831
commit
5076ef7d9b
4 changed files with 80 additions and 2 deletions
52
crates/ide-diagnostics/src/handlers/bad_rtn.rs
Normal file
52
crates/ide-diagnostics/src/handlers/bad_rtn.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
use ide_db::Severity;
|
||||
|
||||
use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
|
||||
|
||||
// Diagnostic: bad-rtn
|
||||
//
|
||||
// This diagnostic is shown when a RTN (Return Type Notation, `Type::method(..): Send`) is written in an improper place.
|
||||
pub(crate) fn bad_rtn(ctx: &DiagnosticsContext<'_>, d: &hir::BadRtn) -> Diagnostic {
|
||||
Diagnostic::new_with_syntax_node_ptr(
|
||||
ctx,
|
||||
DiagnosticCode::Ra("bad-rtn", Severity::Error),
|
||||
"return type notation not allowed in this position yet",
|
||||
d.rtn.map(Into::into),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests::check_diagnostics;
|
||||
|
||||
#[test]
|
||||
fn fn_traits_also_emit() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
//- minicore: fn
|
||||
fn foo<
|
||||
A: Fn(..),
|
||||
// ^^^^ error: return type notation not allowed in this position yet
|
||||
>() {}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_rtn() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
mod module {
|
||||
pub struct Type;
|
||||
}
|
||||
trait Trait {}
|
||||
|
||||
fn foo()
|
||||
where
|
||||
module(..)::Type: Trait
|
||||
// ^^^^ error: return type notation not allowed in this position yet
|
||||
{
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
mod handlers {
|
||||
pub(crate) mod await_outside_of_async;
|
||||
pub(crate) mod bad_rtn;
|
||||
pub(crate) mod break_outside_of_loop;
|
||||
pub(crate) mod expected_function;
|
||||
pub(crate) mod generic_args_prohibited;
|
||||
|
|
@ -493,6 +494,7 @@ pub fn semantic_diagnostics(
|
|||
AnyDiagnostic::ParenthesizedGenericArgsWithoutFnTrait(d) => {
|
||||
handlers::parenthesized_generic_args_without_fn_trait::parenthesized_generic_args_without_fn_trait(&ctx, &d)
|
||||
}
|
||||
AnyDiagnostic::BadRtn(d) => handlers::bad_rtn::bad_rtn(&ctx, &d),
|
||||
};
|
||||
res.push(d)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue