Skip to content

Commit e3e27ba

Browse files
committed
Create const block DefIds in typeck instead of ast lowering
1 parent 4dd07f4 commit e3e27ba

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

clippy_utils/src/consts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{clip, is_direct_expn_of, sext, unsext};
66
use rustc_ast::ast::{self, LitFloatType, LitKind};
77
use rustc_data_structures::sync::Lrc;
88
use rustc_hir::def::{DefKind, Res};
9-
use rustc_hir::{BinOp, BinOpKind, Block, ConstBlock, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp};
9+
use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp};
1010
use rustc_lexer::tokenize;
1111
use rustc_lint::LateContext;
1212
use rustc_middle::mir::interpret::{alloc_range, Scalar};
@@ -412,7 +412,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
412412
/// Simple constant folding: Insert an expression, get a constant or none.
413413
pub fn expr(&mut self, e: &Expr<'_>) -> Option<Constant<'tcx>> {
414414
match e.kind {
415-
ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.lcx.tcx.hir().body(body).value),
415+
ExprKind::ConstBlock(e) |
416416
ExprKind::DropTemps(e) => self.expr(e),
417417
ExprKind::Path(ref qpath) => {
418418
self.fetch_path_and_apply(qpath, e.hir_id, self.typeck_results.expr_ty(e), |this, result| {
@@ -491,7 +491,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
491491
/// leaves the local crate.
492492
pub fn expr_is_empty(&mut self, e: &Expr<'_>) -> Option<bool> {
493493
match e.kind {
494-
ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr_is_empty(self.lcx.tcx.hir().body(body).value),
494+
ExprKind::ConstBlock(e) |
495495
ExprKind::DropTemps(e) => self.expr_is_empty(e),
496496
ExprKind::Path(ref qpath) => {
497497
if !self

clippy_utils/src/hir_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl HirEqInterExpr<'_, '_, '_> {
295295
self.eq_expr(lx, rx) && self.eq_ty(lt, rt)
296296
},
297297
(&ExprKind::Closure(_l), &ExprKind::Closure(_r)) => false,
298-
(&ExprKind::ConstBlock(lb), &ExprKind::ConstBlock(rb)) => self.eq_body(lb.body, rb.body),
298+
(&ExprKind::ConstBlock(lb), &ExprKind::ConstBlock(rb)) => self.eq_expr(lb, rb),
299299
(&ExprKind::Continue(li), &ExprKind::Continue(ri)) => {
300300
both(&li.label, &ri.label, |l, r| l.ident.name == r.ident.name)
301301
},
@@ -770,7 +770,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
770770
self.hash_expr(self.cx.tcx.hir().body(body).value);
771771
},
772772
ExprKind::ConstBlock(ref l_id) => {
773-
self.hash_body(l_id.body);
773+
self.hash_expr(l_id);
774774
},
775775
ExprKind::DropTemps(e) | ExprKind::Yield(e, _) => {
776776
self.hash_expr(e);

tests/ui/arithmetic_side_effects.stderr

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
error: arithmetic operation that can potentially result in unexpected side-effects
2-
--> tests/ui/arithmetic_side_effects.rs:304:5
2+
--> tests/ui/arithmetic_side_effects.rs:188:36
33
|
4-
LL | _n += 1;
5-
| ^^^^^^^
4+
LL | let _ = const { let mut n = 1; n += 1; n };
5+
| ^^^^^^
66
|
77
= note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]`
99

10+
error: arithmetic operation that can potentially result in unexpected side-effects
11+
--> tests/ui/arithmetic_side_effects.rs:191:40
12+
|
13+
LL | let _ = const { let mut n = 1; n = n + 1; n };
14+
| ^^^^^
15+
16+
error: arithmetic operation that can potentially result in unexpected side-effects
17+
--> tests/ui/arithmetic_side_effects.rs:194:40
18+
|
19+
LL | let _ = const { let mut n = 1; n = 1 + n; n };
20+
| ^^^^^
21+
22+
error: arithmetic operation that can potentially result in unexpected side-effects
23+
--> tests/ui/arithmetic_side_effects.rs:200:59
24+
|
25+
LL | let _ = const { let mut n = 1; n = -1; n = -(-1); n = -n; n };
26+
| ^^
27+
28+
error: arithmetic operation that can potentially result in unexpected side-effects
29+
--> tests/ui/arithmetic_side_effects.rs:304:5
30+
|
31+
LL | _n += 1;
32+
| ^^^^^^^
33+
1034
error: arithmetic operation that can potentially result in unexpected side-effects
1135
--> tests/ui/arithmetic_side_effects.rs:305:5
1236
|
@@ -727,5 +751,5 @@ error: arithmetic operation that can potentially result in unexpected side-effec
727751
LL | one.sub_assign(1);
728752
| ^^^^^^^^^^^^^^^^^
729753

730-
error: aborting due to 121 previous errors
754+
error: aborting due to 125 previous errors
731755

0 commit comments

Comments
 (0)