mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-02 04:48:13 +00:00
Merge pull request #19354 from ChayimFriedman2/rtn-prep
Preparation to Return Type Notation (RTN)
This commit is contained in:
commit
918740358b
8 changed files with 205 additions and 82 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
|
||||
{
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue