add unresolved-assoc-item diagnostic
This commit is contained in:
parent
cf52c4b2b3
commit
5878651e7e
@ -218,6 +218,9 @@ pub enum InferenceDiagnostic {
|
|||||||
/// Contains the type the field resolves to
|
/// Contains the type the field resolves to
|
||||||
field_with_same_name: Option<Ty>,
|
field_with_same_name: Option<Ty>,
|
||||||
},
|
},
|
||||||
|
UnresolvedAssocItem {
|
||||||
|
id: ExprOrPatId,
|
||||||
|
},
|
||||||
// FIXME: This should be emitted in body lowering
|
// FIXME: This should be emitted in body lowering
|
||||||
BreakOutsideOfLoop {
|
BreakOutsideOfLoop {
|
||||||
expr: ExprId,
|
expr: ExprId,
|
||||||
|
@ -340,6 +340,9 @@ impl InferenceContext<'_> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
let res = res.or(not_visible);
|
let res = res.or(not_visible);
|
||||||
|
if res.is_none() {
|
||||||
|
self.push_diagnostic(InferenceDiagnostic::UnresolvedAssocItem { id });
|
||||||
|
}
|
||||||
let (item, visible) = res?;
|
let (item, visible) = res?;
|
||||||
|
|
||||||
let (def, container) = match item {
|
let (def, container) = match item {
|
||||||
|
@ -62,6 +62,7 @@ diagnostics![
|
|||||||
UndeclaredLabel,
|
UndeclaredLabel,
|
||||||
UnimplementedBuiltinMacro,
|
UnimplementedBuiltinMacro,
|
||||||
UnreachableLabel,
|
UnreachableLabel,
|
||||||
|
UnresolvedAssocItem,
|
||||||
UnresolvedExternCrate,
|
UnresolvedExternCrate,
|
||||||
UnresolvedField,
|
UnresolvedField,
|
||||||
UnresolvedImport,
|
UnresolvedImport,
|
||||||
@ -217,6 +218,11 @@ pub struct UnresolvedMethodCall {
|
|||||||
pub field_with_same_name: Option<Type>,
|
pub field_with_same_name: Option<Type>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct UnresolvedAssocItem {
|
||||||
|
pub expr_or_pat: InFile<AstPtr<Either<ast::Expr, Either<ast::Pat, ast::SelfParam>>>>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PrivateField {
|
pub struct PrivateField {
|
||||||
pub expr: InFile<AstPtr<ast::Expr>>,
|
pub expr: InFile<AstPtr<ast::Expr>>,
|
||||||
|
@ -1695,6 +1695,13 @@ impl DefWithBody {
|
|||||||
.into(),
|
.into(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
&hir_ty::InferenceDiagnostic::UnresolvedAssocItem { id } => {
|
||||||
|
let expr_or_pat = match id {
|
||||||
|
ExprOrPatId::ExprId(expr) => expr_syntax(expr).map(AstPtr::wrap_left),
|
||||||
|
ExprOrPatId::PatId(pat) => pat_syntax(pat).map(AstPtr::wrap_right),
|
||||||
|
};
|
||||||
|
acc.push(UnresolvedAssocItem { expr_or_pat }.into())
|
||||||
|
}
|
||||||
&hir_ty::InferenceDiagnostic::BreakOutsideOfLoop {
|
&hir_ty::InferenceDiagnostic::BreakOutsideOfLoop {
|
||||||
expr,
|
expr,
|
||||||
is_break,
|
is_break,
|
||||||
|
52
crates/ide-diagnostics/src/handlers/unresolved_assoc_item.rs
Normal file
52
crates/ide-diagnostics/src/handlers/unresolved_assoc_item.rs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
|
||||||
|
|
||||||
|
// Diagnostic: unresolved-assoc-item
|
||||||
|
//
|
||||||
|
// This diagnostic is triggered if the referenced associated item does not exist.
|
||||||
|
pub(crate) fn unresolved_assoc_item(
|
||||||
|
ctx: &DiagnosticsContext<'_>,
|
||||||
|
d: &hir::UnresolvedAssocItem,
|
||||||
|
) -> Diagnostic {
|
||||||
|
Diagnostic::new_with_syntax_node_ptr(
|
||||||
|
ctx,
|
||||||
|
DiagnosticCode::RustcHardError("E0599"),
|
||||||
|
"no such associated item",
|
||||||
|
d.expr_or_pat.clone().map(Into::into),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::tests::check_diagnostics;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bare() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
struct S;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = S::Assoc;
|
||||||
|
//^^^^^^^^ error: no such associated item
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unimplemented_trait() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
struct S;
|
||||||
|
trait Foo {
|
||||||
|
const X: u32;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = S::X;
|
||||||
|
//^^^^ error: no such associated item
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -51,6 +51,7 @@ mod handlers {
|
|||||||
pub(crate) mod typed_hole;
|
pub(crate) mod typed_hole;
|
||||||
pub(crate) mod type_mismatch;
|
pub(crate) mod type_mismatch;
|
||||||
pub(crate) mod unimplemented_builtin_macro;
|
pub(crate) mod unimplemented_builtin_macro;
|
||||||
|
pub(crate) mod unresolved_assoc_item;
|
||||||
pub(crate) mod unresolved_extern_crate;
|
pub(crate) mod unresolved_extern_crate;
|
||||||
pub(crate) mod unresolved_field;
|
pub(crate) mod unresolved_field;
|
||||||
pub(crate) mod unresolved_method;
|
pub(crate) mod unresolved_method;
|
||||||
@ -371,7 +372,8 @@ pub fn diagnostics(
|
|||||||
AnyDiagnostic::TypeMismatch(d) => handlers::type_mismatch::type_mismatch(&ctx, &d),
|
AnyDiagnostic::TypeMismatch(d) => handlers::type_mismatch::type_mismatch(&ctx, &d),
|
||||||
AnyDiagnostic::UndeclaredLabel(d) => handlers::undeclared_label::undeclared_label(&ctx, &d),
|
AnyDiagnostic::UndeclaredLabel(d) => handlers::undeclared_label::undeclared_label(&ctx, &d),
|
||||||
AnyDiagnostic::UnimplementedBuiltinMacro(d) => handlers::unimplemented_builtin_macro::unimplemented_builtin_macro(&ctx, &d),
|
AnyDiagnostic::UnimplementedBuiltinMacro(d) => handlers::unimplemented_builtin_macro::unimplemented_builtin_macro(&ctx, &d),
|
||||||
AnyDiagnostic::UnreachableLabel(d) => handlers::unreachable_label:: unreachable_label(&ctx, &d),
|
AnyDiagnostic::UnreachableLabel(d) => handlers::unreachable_label::unreachable_label(&ctx, &d),
|
||||||
|
AnyDiagnostic::UnresolvedAssocItem(d) => handlers::unresolved_assoc_item::unresolved_assoc_item(&ctx, &d),
|
||||||
AnyDiagnostic::UnresolvedExternCrate(d) => handlers::unresolved_extern_crate::unresolved_extern_crate(&ctx, &d),
|
AnyDiagnostic::UnresolvedExternCrate(d) => handlers::unresolved_extern_crate::unresolved_extern_crate(&ctx, &d),
|
||||||
AnyDiagnostic::UnresolvedField(d) => handlers::unresolved_field::unresolved_field(&ctx, &d),
|
AnyDiagnostic::UnresolvedField(d) => handlers::unresolved_field::unresolved_field(&ctx, &d),
|
||||||
AnyDiagnostic::UnresolvedImport(d) => handlers::unresolved_import::unresolved_import(&ctx, &d),
|
AnyDiagnostic::UnresolvedImport(d) => handlers::unresolved_import::unresolved_import(&ctx, &d),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user