Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/lower/diagnostics.rs')
-rw-r--r--crates/hir-ty/src/lower/diagnostics.rs43
1 files changed, 41 insertions, 2 deletions
diff --git a/crates/hir-ty/src/lower/diagnostics.rs b/crates/hir-ty/src/lower/diagnostics.rs
index 5f299aca3a..a5a13d64e0 100644
--- a/crates/hir-ty/src/lower/diagnostics.rs
+++ b/crates/hir-ty/src/lower/diagnostics.rs
@@ -1,6 +1,7 @@
//! This files contains the declaration of diagnostics kinds for ty and path lowering.
use hir_def::type_ref::TypeRefId;
+use hir_def::{GenericDefId, GenericParamId};
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct TyLoweringDiagnostic {
@@ -21,13 +22,51 @@ pub enum GenericArgsProhibitedReason {
PrimitiveTy,
Const,
Static,
+ LocalVariable,
/// When there is a generic enum, within the expression `Enum::Variant`,
/// either `Enum` or `Variant` are allowed to have generic arguments, but not both.
EnumVariant,
}
+/// A path can have many generic arguments: each segment may have one associated with the
+/// segment, and in addition, each associated type binding may have generic arguments. This
+/// enum abstracts over both.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum PathGenericsSource {
+ /// Generic arguments directly on the segment.
+ Segment(u32),
+ /// Generic arguments on an associated type, e.g. `Foo<Assoc<A, B> = C>` or `Foo<Assoc<A, B>: Bound>`.
+ AssocType { segment: u32, assoc_type: u32 },
+}
+
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum PathLoweringDiagnostic {
- GenericArgsProhibited { segment: u32, reason: GenericArgsProhibitedReason },
- ParenthesizedGenericArgsWithoutFnTrait { segment: u32 },
+ GenericArgsProhibited {
+ segment: u32,
+ reason: GenericArgsProhibitedReason,
+ },
+ ParenthesizedGenericArgsWithoutFnTrait {
+ segment: u32,
+ },
+ /// The expected lifetimes & types and consts counts can be found by inspecting the `GenericDefId`.
+ IncorrectGenericsLen {
+ generics_source: PathGenericsSource,
+ provided_count: u32,
+ expected_count: u32,
+ kind: IncorrectGenericsLenKind,
+ def: GenericDefId,
+ },
+ IncorrectGenericsOrder {
+ generics_source: PathGenericsSource,
+ param_id: GenericParamId,
+ arg_idx: u32,
+ /// Whether the `GenericArgs` contains a `Self` arg.
+ has_self_arg: bool,
+ },
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum IncorrectGenericsLenKind {
+ Lifetimes,
+ TypesAndConsts,
}