hir_ty/lower/
diagnostics.rs

1//! This files contains the declaration of diagnostics kinds for ty and path lowering.
2
3use hir_def::type_ref::TypeRefId;
4use hir_def::{GenericDefId, GenericParamId};
5
6#[derive(Debug, PartialEq, Eq, Clone)]
7pub struct TyLoweringDiagnostic {
8    pub source: TypeRefId,
9    pub kind: TyLoweringDiagnosticKind,
10}
11
12#[derive(Debug, PartialEq, Eq, Clone)]
13pub enum TyLoweringDiagnosticKind {
14    PathDiagnostic(PathLoweringDiagnostic),
15}
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum GenericArgsProhibitedReason {
19    Module,
20    TyParam,
21    SelfTy,
22    PrimitiveTy,
23    Const,
24    Static,
25    LocalVariable,
26    /// When there is a generic enum, within the expression `Enum::Variant`,
27    /// either `Enum` or `Variant` are allowed to have generic arguments, but not both.
28    EnumVariant,
29}
30
31/// A path can have many generic arguments: each segment may have one associated with the
32/// segment, and in addition, each associated type binding may have generic arguments. This
33/// enum abstracts over both.
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub enum PathGenericsSource {
36    /// Generic arguments directly on the segment.
37    Segment(u32),
38    /// Generic arguments on an associated type, e.g. `Foo<Assoc<A, B> = C>` or `Foo<Assoc<A, B>: Bound>`.
39    AssocType { segment: u32, assoc_type: u32 },
40}
41
42#[derive(Debug, PartialEq, Eq, Clone)]
43pub enum PathLoweringDiagnostic {
44    GenericArgsProhibited {
45        segment: u32,
46        reason: GenericArgsProhibitedReason,
47    },
48    ParenthesizedGenericArgsWithoutFnTrait {
49        segment: u32,
50    },
51    /// The expected lifetimes & types and consts counts can be found by inspecting the `GenericDefId`.
52    IncorrectGenericsLen {
53        generics_source: PathGenericsSource,
54        provided_count: u32,
55        expected_count: u32,
56        kind: IncorrectGenericsLenKind,
57        def: GenericDefId,
58    },
59    IncorrectGenericsOrder {
60        generics_source: PathGenericsSource,
61        param_id: GenericParamId,
62        arg_idx: u32,
63        /// Whether the `GenericArgs` contains a `Self` arg.
64        has_self_arg: bool,
65    },
66    ElidedLifetimesInPath {
67        generics_source: PathGenericsSource,
68        def: GenericDefId,
69        expected_count: u32,
70        hard_error: bool,
71    },
72    /// An elided lifetimes was used (either implicitly, by not specifying lifetimes, or explicitly, by using `'_`),
73    /// but lifetime elision could not find a lifetime to replace it with.
74    ElisionFailure {
75        generics_source: PathGenericsSource,
76        def: GenericDefId,
77        expected_count: u32,
78    },
79    MissingLifetime {
80        generics_source: PathGenericsSource,
81        def: GenericDefId,
82        expected_count: u32,
83    },
84}
85
86#[derive(Debug, Clone, Copy, PartialEq, Eq)]
87pub enum IncorrectGenericsLenKind {
88    Lifetimes,
89    TypesAndConsts,
90}