Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! 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 {
    pub source: TypeRefId,
    pub kind: TyLoweringDiagnosticKind,
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum TyLoweringDiagnosticKind {
    PathDiagnostic(PathLoweringDiagnostic),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GenericArgsProhibitedReason {
    Module,
    TyParam,
    SelfTy,
    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,
    },
    /// 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,
    },
    ElidedLifetimesInPath {
        generics_source: PathGenericsSource,
        def: GenericDefId,
        expected_count: u32,
        hard_error: bool,
    },
    /// An elided lifetimes was used (either implicitly, by not specifying lifetimes, or explicitly, by using `'_`),
    /// but lifetime elision could not find a lifetime to replace it with.
    ElisionFailure {
        generics_source: PathGenericsSource,
        def: GenericDefId,
        expected_count: u32,
    },
    MissingLifetime {
        generics_source: PathGenericsSource,
        def: GenericDefId,
        expected_count: u32,
    },
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IncorrectGenericsLenKind {
    Lifetimes,
    TypesAndConsts,
}