|
5 | 5 | use crate::consts::{constant_simple, Constant}; |
6 | 6 | use crate::ty::is_type_diagnostic_item; |
7 | 7 | use crate::{is_expn_of, match_def_path, paths}; |
8 | | -use hir::BinOpKind; |
9 | 8 | use if_chain::if_chain; |
10 | 9 | use rustc_ast::ast; |
11 | 10 | use rustc_hir as hir; |
@@ -138,97 +137,6 @@ impl<'hir> IfLet<'hir> { |
138 | 137 | } |
139 | 138 | } |
140 | 139 |
|
141 | | -/// A `let` chain, like `if true && let Some(true) = x {}` |
142 | | -#[derive(Debug)] |
143 | | -pub struct LetChain<'hir> { |
144 | | - pub conds: Vec<IfOrIfLetInChain<'hir>>, |
145 | | - pub if_then: &'hir Expr<'hir>, |
146 | | - pub if_else: Option<&'hir Expr<'hir>>, |
147 | | -} |
148 | | - |
149 | | -impl<'hir> LetChain<'hir> { |
150 | | - pub fn hir(expr: &Expr<'hir>) -> Option<Self> { |
151 | | - if let ExprKind::If(cond, if_then, if_else) = expr.kind { |
152 | | - let mut conds = vec![]; |
153 | | - let mut cursor = cond; |
154 | | - while let ExprKind::Binary(binop, lhs, rhs) = cursor.kind |
155 | | - && let BinOpKind::And = binop.node |
156 | | - { |
157 | | - cursor = lhs; |
158 | | - conds.push(IfOrIfLetInChain::hir(rhs)?); |
159 | | - } |
160 | | - |
161 | | - // The final lhs cannot be `&&` |
162 | | - conds.push(IfOrIfLetInChain::hir(cursor)?); |
163 | | - |
164 | | - return Some(Self { |
165 | | - conds, |
166 | | - if_then, |
167 | | - if_else, |
168 | | - }); |
169 | | - } |
170 | | - |
171 | | - None |
172 | | - } |
173 | | -} |
174 | | - |
175 | | -/// An `if let` or `if` expression in a let chain. |
176 | | -#[derive(Debug)] |
177 | | -pub enum IfOrIfLetInChain<'hir> { |
178 | | - If(IfInChain<'hir>), |
179 | | - IfLet(IfLetInChain<'hir>), |
180 | | -} |
181 | | - |
182 | | -impl<'hir> IfOrIfLetInChain<'hir> { |
183 | | - pub fn hir(expr: &Expr<'hir>) -> Option<Self> { |
184 | | - match expr.kind { |
185 | | - ExprKind::DropTemps(cond) => Some(IfInChain { cond }.into()), |
186 | | - ExprKind::Let(hir::Let { |
187 | | - pat: let_pat, |
188 | | - init: let_expr, |
189 | | - span: let_span, |
190 | | - .. |
191 | | - }) => Some( |
192 | | - IfLetInChain { |
193 | | - let_pat, |
194 | | - let_expr, |
195 | | - let_span: *let_span, |
196 | | - } |
197 | | - .into(), |
198 | | - ), |
199 | | - _ => None, |
200 | | - } |
201 | | - } |
202 | | -} |
203 | | - |
204 | | -impl<'hir> From<IfInChain<'hir>> for IfOrIfLetInChain<'hir> { |
205 | | - fn from(value: IfInChain<'hir>) -> Self { |
206 | | - Self::If(value) |
207 | | - } |
208 | | -} |
209 | | - |
210 | | -impl<'hir> From<IfLetInChain<'hir>> for IfOrIfLetInChain<'hir> { |
211 | | - fn from(value: IfLetInChain<'hir>) -> Self { |
212 | | - Self::IfLet(value) |
213 | | - } |
214 | | -} |
215 | | - |
216 | | -/// An `if` expression in a let chain. |
217 | | -#[derive(Debug)] |
218 | | -pub struct IfInChain<'hir> { |
219 | | - pub cond: &'hir Expr<'hir>, |
220 | | -} |
221 | | - |
222 | | -/// An `if let` expression in a let chain. |
223 | | -#[derive(Debug)] |
224 | | -pub struct IfLetInChain<'hir> { |
225 | | - pub let_span: Span, |
226 | | - /// `if let` pattern |
227 | | - pub let_pat: &'hir Pat<'hir>, |
228 | | - /// `if let` scrutinee |
229 | | - pub let_expr: &'hir Expr<'hir>, |
230 | | -} |
231 | | - |
232 | 140 | /// An `if let` or `match` expression. Useful for lints that trigger on one or the other. |
233 | 141 | #[derive(Debug)] |
234 | 142 | pub enum IfLetOrMatch<'hir> { |
|
0 commit comments