@@ -9,6 +9,24 @@ use rustc_span::def_id::LocalDefId;
9
9
use rustc_span:: Span ;
10
10
use rustc_trait_selection:: traits;
11
11
12
+ #[ derive( Debug , Copy , Clone ) ]
13
+ pub ( super ) enum DeclOrigin {
14
+ // from an `if let` expression
15
+ LetExpr ,
16
+ // from `let x = ..`
17
+ LocalDecl ,
18
+ }
19
+
20
+ /// Provides context for checking patterns in declarations. More specifically this
21
+ /// allows us to infer array types if the pattern is irrefutable and allows us to infer
22
+ /// the size of the array. See issue #76342.
23
+ #[ derive( Debug , Copy , Clone ) ]
24
+ pub ( crate ) struct DeclContext {
25
+ // whether we're in a let-else context
26
+ pub ( super ) has_else : bool ,
27
+ pub ( super ) origin : DeclOrigin ,
28
+ }
29
+
12
30
/// A declaration is an abstraction of [hir::Local] and [hir::Let].
13
31
///
14
32
/// It must have a hir_id, as this is how we connect gather_locals to the check functions.
@@ -19,19 +37,28 @@ pub(super) struct Declaration<'a> {
19
37
pub span : Span ,
20
38
pub init : Option < & ' a hir:: Expr < ' a > > ,
21
39
pub els : Option < & ' a hir:: Block < ' a > > ,
40
+ pub origin : DeclOrigin ,
22
41
}
23
42
24
43
impl < ' a > From < & ' a hir:: Local < ' a > > for Declaration < ' a > {
25
44
fn from ( local : & ' a hir:: Local < ' a > ) -> Self {
26
45
let hir:: Local { hir_id, pat, ty, span, init, els, source : _ } = * local;
27
- Declaration { hir_id, pat, ty, span, init, els }
46
+ Declaration { hir_id, pat, ty, span, init, els, origin : DeclOrigin :: LocalDecl }
28
47
}
29
48
}
30
49
31
50
impl < ' a > From < & ' a hir:: Let < ' a > > for Declaration < ' a > {
32
51
fn from ( let_expr : & ' a hir:: Let < ' a > ) -> Self {
33
52
let hir:: Let { hir_id, pat, ty, span, init } = * let_expr;
34
- Declaration { hir_id, pat, ty, span, init : Some ( init) , els : None }
53
+ Declaration {
54
+ hir_id,
55
+ pat,
56
+ ty,
57
+ span,
58
+ init : Some ( init) ,
59
+ els : None ,
60
+ origin : DeclOrigin :: LetExpr ,
61
+ }
35
62
}
36
63
}
37
64
0 commit comments