Skip to content

Commit 127f3e1

Browse files
committed
Auto merge of rust-lang#125918 - oli-obk:const_block_ice, r=compiler-errors
Revert: create const block bodies in typeck via query feeding as per the discussion in rust-lang#125806 (comment) It was a mistake to try to shoehorn const blocks and some specific anon consts into the same box and feed them during typeck. It turned out not simplifying anything (my hope was that we could feed `type_of` to start avoiding the huge HIR matcher, but that didn't work out), but instead making a few things more fragile. reverts the const-block-specific parts of rust-lang#124650 `@bors` rollup=never had a small perf impact previously fixes rust-lang#125846 r? `@compiler-errors`
2 parents 3e43cfc + abd0116 commit 127f3e1

File tree

3 files changed

+10
-34
lines changed

3 files changed

+10
-34
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, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp};
9+
use rustc_hir::{BinOp, BinOpKind, Block, ConstBlock, 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(e) | ExprKind::DropTemps(e) => self.expr(e),
415+
ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.lcx.tcx.hir().body(body).value), ExprKind::DropTemps(e) => self.expr(e),
416416
ExprKind::Path(ref qpath) => {
417417
self.fetch_path_and_apply(qpath, e.hir_id, self.typeck_results.expr_ty(e), |this, result| {
418418
let result = mir_to_const(this.lcx, result)?;
@@ -490,7 +490,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
490490
/// leaves the local crate.
491491
pub fn expr_is_empty(&mut self, e: &Expr<'_>) -> Option<bool> {
492492
match e.kind {
493-
ExprKind::ConstBlock(e) | ExprKind::DropTemps(e) => self.expr_is_empty(e),
493+
ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr_is_empty(self.lcx.tcx.hir().body(body).value), ExprKind::DropTemps(e) => self.expr_is_empty(e),
494494
ExprKind::Path(ref qpath) => {
495495
if !self
496496
.typeck_results

clippy_utils/src/hir_utils.rs

+3-3
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_expr(lb, rb),
298+
(&ExprKind::ConstBlock(lb), &ExprKind::ConstBlock(rb)) => self.eq_body(lb.body, rb.body),
299299
(&ExprKind::Continue(li), &ExprKind::Continue(ri)) => {
300300
both(&li.label, &ri.label, |l, r| l.ident.name == r.ident.name)
301301
},
@@ -769,8 +769,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
769769
// closures inherit TypeckResults
770770
self.hash_expr(self.cx.tcx.hir().body(body).value);
771771
},
772-
ExprKind::ConstBlock(l_id) => {
773-
self.hash_expr(l_id);
772+
ExprKind::ConstBlock(ref l_id) => {
773+
self.hash_body(l_id.body);
774774
},
775775
ExprKind::DropTemps(e) | ExprKind::Yield(e, _) => {
776776
self.hash_expr(e);

tests/ui/arithmetic_side_effects.stderr

+4-28
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,11 @@
1-
error: arithmetic operation that can potentially result in unexpected side-effects
2-
--> tests/ui/arithmetic_side_effects.rs:188:36
3-
|
4-
LL | let _ = const { let mut n = 1; n += 1; n };
5-
| ^^^^^^
6-
|
7-
= note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
8-
= help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]`
9-
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-
281
error: arithmetic operation that can potentially result in unexpected side-effects
292
--> tests/ui/arithmetic_side_effects.rs:304:5
303
|
314
LL | _n += 1;
325
| ^^^^^^^
6+
|
7+
= note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]`
339

3410
error: arithmetic operation that can potentially result in unexpected side-effects
3511
--> tests/ui/arithmetic_side_effects.rs:305:5
@@ -751,5 +727,5 @@ error: arithmetic operation that can potentially result in unexpected side-effec
751727
LL | one.sub_assign(1);
752728
| ^^^^^^^^^^^^^^^^^
753729

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

0 commit comments

Comments
 (0)