about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-05-03 09:22:55 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-05-28 13:38:43 +0000
commite3e27ba3dd5a5bd9b36f03527ef9fff82cb17dc4 (patch)
tree2a8d8f6a89edf60f2122b3745cb7dff888b9f57f
parent4dd07f4e4e921df60a41891c8ed9f63d11c5d48a (diff)
downloadrust-e3e27ba3dd5a5bd9b36f03527ef9fff82cb17dc4.tar.gz
rust-e3e27ba3dd5a5bd9b36f03527ef9fff82cb17dc4.zip
Create const block DefIds in typeck instead of ast lowering
-rw-r--r--clippy_utils/src/consts.rs6
-rw-r--r--clippy_utils/src/hir_utils.rs4
-rw-r--r--tests/ui/arithmetic_side_effects.stderr32
3 files changed, 33 insertions, 9 deletions
diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs
index 253ae3aca68..f5d3967d130 100644
--- a/clippy_utils/src/consts.rs
+++ b/clippy_utils/src/consts.rs
@@ -6,7 +6,7 @@ use crate::{clip, is_direct_expn_of, sext, unsext};
 use rustc_ast::ast::{self, LitFloatType, LitKind};
 use rustc_data_structures::sync::Lrc;
 use rustc_hir::def::{DefKind, Res};
-use rustc_hir::{BinOp, BinOpKind, Block, ConstBlock, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp};
+use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind, Node, QPath, UnOp};
 use rustc_lexer::tokenize;
 use rustc_lint::LateContext;
 use rustc_middle::mir::interpret::{alloc_range, Scalar};
@@ -412,7 +412,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
     /// Simple constant folding: Insert an expression, get a constant or none.
     pub fn expr(&mut self, e: &Expr<'_>) -> Option<Constant<'tcx>> {
         match e.kind {
-            ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr(self.lcx.tcx.hir().body(body).value),
+            ExprKind::ConstBlock(e) |
             ExprKind::DropTemps(e) => self.expr(e),
             ExprKind::Path(ref qpath) => {
                 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> {
     /// leaves the local crate.
     pub fn expr_is_empty(&mut self, e: &Expr<'_>) -> Option<bool> {
         match e.kind {
-            ExprKind::ConstBlock(ConstBlock { body, .. }) => self.expr_is_empty(self.lcx.tcx.hir().body(body).value),
+            ExprKind::ConstBlock(e) |
             ExprKind::DropTemps(e) => self.expr_is_empty(e),
             ExprKind::Path(ref qpath) => {
                 if !self
diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs
index 9f285621e0c..cc5ccd4053a 100644
--- a/clippy_utils/src/hir_utils.rs
+++ b/clippy_utils/src/hir_utils.rs
@@ -295,7 +295,7 @@ impl HirEqInterExpr<'_, '_, '_> {
                 self.eq_expr(lx, rx) && self.eq_ty(lt, rt)
             },
             (&ExprKind::Closure(_l), &ExprKind::Closure(_r)) => false,
-            (&ExprKind::ConstBlock(lb), &ExprKind::ConstBlock(rb)) => self.eq_body(lb.body, rb.body),
+            (&ExprKind::ConstBlock(lb), &ExprKind::ConstBlock(rb)) => self.eq_expr(lb, rb),
             (&ExprKind::Continue(li), &ExprKind::Continue(ri)) => {
                 both(&li.label, &ri.label, |l, r| l.ident.name == r.ident.name)
             },
@@ -770,7 +770,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
                 self.hash_expr(self.cx.tcx.hir().body(body).value);
             },
             ExprKind::ConstBlock(ref l_id) => {
-                self.hash_body(l_id.body);
+                self.hash_expr(l_id);
             },
             ExprKind::DropTemps(e) | ExprKind::Yield(e, _) => {
                 self.hash_expr(e);
diff --git a/tests/ui/arithmetic_side_effects.stderr b/tests/ui/arithmetic_side_effects.stderr
index 8039c0bfa24..df14ff396f6 100644
--- a/tests/ui/arithmetic_side_effects.stderr
+++ b/tests/ui/arithmetic_side_effects.stderr
@@ -1,13 +1,37 @@
 error: arithmetic operation that can potentially result in unexpected side-effects
-  --> tests/ui/arithmetic_side_effects.rs:304:5
+  --> tests/ui/arithmetic_side_effects.rs:188:36
    |
-LL |     _n += 1;
-   |     ^^^^^^^
+LL |     let _ = const { let mut n = 1; n += 1; n };
+   |                                    ^^^^^^
    |
    = note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::arithmetic_side_effects)]`
 
 error: arithmetic operation that can potentially result in unexpected side-effects
+  --> tests/ui/arithmetic_side_effects.rs:191:40
+   |
+LL |     let _ = const { let mut n = 1; n = n + 1; n };
+   |                                        ^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+  --> tests/ui/arithmetic_side_effects.rs:194:40
+   |
+LL |     let _ = const { let mut n = 1; n = 1 + n; n };
+   |                                        ^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+  --> tests/ui/arithmetic_side_effects.rs:200:59
+   |
+LL |     let _ = const { let mut n = 1; n = -1; n = -(-1); n = -n; n };
+   |                                                           ^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
+  --> tests/ui/arithmetic_side_effects.rs:304:5
+   |
+LL |     _n += 1;
+   |     ^^^^^^^
+
+error: arithmetic operation that can potentially result in unexpected side-effects
   --> tests/ui/arithmetic_side_effects.rs:305:5
    |
 LL |     _n += &1;
@@ -727,5 +751,5 @@ error: arithmetic operation that can potentially result in unexpected side-effec
 LL |     one.sub_assign(1);
    |     ^^^^^^^^^^^^^^^^^
 
-error: aborting due to 121 previous errors
+error: aborting due to 125 previous errors