diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-11-26 09:41:56 +0100 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-11-30 09:44:06 +0100 |
| commit | 75ce28a9745940bbc56110911cfd83b2498bcef6 (patch) | |
| tree | 5cdb7da83aa13d0664c554b34d0852c89e1e345f | |
| parent | 507ea97a3e245887bc8cbea0f0fe8474d082bd0e (diff) | |
| download | rust-75ce28a9745940bbc56110911cfd83b2498bcef6.tar.gz rust-75ce28a9745940bbc56110911cfd83b2498bcef6.zip | |
Show auto-applicable correction warning for short circuiting in constants
| -rw-r--r-- | src/librustc_mir/hair/cx/expr.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 5acff380f28..1dfd77dee1f 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -23,6 +23,7 @@ use rustc::hir; use rustc::hir::def_id::LocalDefId; use rustc::mir::{BorrowKind}; use syntax_pos::Span; +use syntax::errors::Applicability; impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { type Output = Expr<'tcx>; @@ -373,6 +374,17 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, // they can handle that kind of control-flow. (hir::BinOpKind::And, hir::Constness::Const) => { cx.control_flow_destroyed = true; + cx.tcx.sess.struct_span_warn( + op.span, + "boolean short circuiting operators in constants do + not actually short circuit. Thus new const eval features + are not accessible in constants." + ).span_suggestion_with_applicability( + op.span, + "use a bit operator instead", + "&".into(), + Applicability::MachineApplicable, + ).emit(); ExprKind::Binary { op: BinOp::BitAnd, lhs: lhs.to_ref(), @@ -381,6 +393,17 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, } (hir::BinOpKind::Or, hir::Constness::Const) => { cx.control_flow_destroyed = true; + cx.tcx.sess.struct_span_warn( + op.span, + "boolean short circuiting operators in constants do + not actually short circuit. Thus new const eval features + are not accessible in constants." + ).span_suggestion_with_applicability( + op.span, + "use a bit operator instead", + "|".into(), + Applicability::MachineApplicable, + ).emit(); ExprKind::Binary { op: BinOp::BitOr, lhs: lhs.to_ref(), |
