diff options
| author | bors <bors@rust-lang.org> | 2020-09-29 14:28:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-09-29 14:28:58 +0000 |
| commit | 4d52dc4790cfaf3f23ff219c9a9932be2bfcd53e (patch) | |
| tree | c2fc4321ad9cbfc7e4f3a8dc58e7df86850fbf90 /compiler | |
| parent | 9e34b729647f44bfbbc361949b14b5bea65e4996 (diff) | |
| parent | c0b105780e2534ebe1337f529d878dab75e3636f (diff) | |
| download | rust-4d52dc4790cfaf3f23ff219c9a9932be2bfcd53e.tar.gz rust-4d52dc4790cfaf3f23ff219c9a9932be2bfcd53e.zip | |
Auto merge of #76754 - varkor:diagnostic-cleanup-ii, r=ecstatic-morse
Clean up diagnostics for arithmetic operation errors Plus a small tweak to a range pattern error message.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_middle/src/mir/mod.rs | 56 | ||||
| -rw-r--r-- | compiler/rustc_typeck/src/check/pat.rs | 2 |
2 files changed, 31 insertions, 27 deletions
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 8ff75bf392e..f9d84bb852f 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1300,49 +1300,49 @@ impl<O> AssertKind<O> { match self { BoundsCheck { ref len, ref index } => write!( f, - "\"index out of bounds: the len is {{}} but the index is {{}}\", {:?}, {:?}", + "\"index out of bounds: the length is {{}} but the index is {{}}\", {:?}, {:?}", len, index ), OverflowNeg(op) => { - write!(f, "\"attempt to negate {{}} which would overflow\", {:?}", op) + write!(f, "\"attempt to negate `{{}}`, which would overflow\", {:?}", op) } - DivisionByZero(op) => write!(f, "\"attempt to divide {{}} by zero\", {:?}", op), + DivisionByZero(op) => write!(f, "\"attempt to divide `{{}}` by zero\", {:?}", op), RemainderByZero(op) => write!( f, - "\"attempt to calculate the remainder of {{}} with a divisor of zero\", {:?}", + "\"attempt to calculate the remainder of `{{}}` with a divisor of zero\", {:?}", op ), Overflow(BinOp::Add, l, r) => write!( f, - "\"attempt to compute `{{}} + {{}}` which would overflow\", {:?}, {:?}", + "\"attempt to compute `{{}} + {{}}`, which would overflow\", {:?}, {:?}", l, r ), Overflow(BinOp::Sub, l, r) => write!( f, - "\"attempt to compute `{{}} - {{}}` which would overflow\", {:?}, {:?}", + "\"attempt to compute `{{}} - {{}}`, which would overflow\", {:?}, {:?}", l, r ), Overflow(BinOp::Mul, l, r) => write!( f, - "\"attempt to compute `{{}} * {{}}` which would overflow\", {:?}, {:?}", + "\"attempt to compute `{{}} * {{}}`, which would overflow\", {:?}, {:?}", l, r ), Overflow(BinOp::Div, l, r) => write!( f, - "\"attempt to compute `{{}} / {{}}` which would overflow\", {:?}, {:?}", + "\"attempt to compute `{{}} / {{}}`, which would overflow\", {:?}, {:?}", l, r ), Overflow(BinOp::Rem, l, r) => write!( f, - "\"attempt to compute the remainder of `{{}} % {{}}` which would overflow\", {:?}, {:?}", + "\"attempt to compute the remainder of `{{}} % {{}}`, which would overflow\", {:?}, {:?}", l, r ), Overflow(BinOp::Shr, _, r) => { - write!(f, "\"attempt to shift right by {{}} which would overflow\", {:?}", r) + write!(f, "\"attempt to shift right by `{{}}`, which would overflow\", {:?}", r) } Overflow(BinOp::Shl, _, r) => { - write!(f, "\"attempt to shift left by {{}} which would overflow\", {:?}", r) + write!(f, "\"attempt to shift left by `{{}}`, which would overflow\", {:?}", r) } _ => write!(f, "\"{}\"", self.description()), } @@ -1353,36 +1353,40 @@ impl<O: fmt::Debug> fmt::Debug for AssertKind<O> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use AssertKind::*; match self { - BoundsCheck { ref len, ref index } => { - write!(f, "index out of bounds: the len is {:?} but the index is {:?}", len, index) - } - OverflowNeg(op) => write!(f, "attempt to negate {:#?} which would overflow", op), - DivisionByZero(op) => write!(f, "attempt to divide {:#?} by zero", op), - RemainderByZero(op) => { - write!(f, "attempt to calculate the remainder of {:#?} with a divisor of zero", op) - } + BoundsCheck { ref len, ref index } => write!( + f, + "index out of bounds: the length is {:?} but the index is {:?}", + len, index + ), + OverflowNeg(op) => write!(f, "attempt to negate `{:#?}`, which would overflow", op), + DivisionByZero(op) => write!(f, "attempt to divide `{:#?}` by zero", op), + RemainderByZero(op) => write!( + f, + "attempt to calculate the remainder of `{:#?}` with a divisor of zero", + op + ), Overflow(BinOp::Add, l, r) => { - write!(f, "attempt to compute `{:#?} + {:#?}` which would overflow", l, r) + write!(f, "attempt to compute `{:#?} + {:#?}`, which would overflow", l, r) } Overflow(BinOp::Sub, l, r) => { - write!(f, "attempt to compute `{:#?} - {:#?}` which would overflow", l, r) + write!(f, "attempt to compute `{:#?} - {:#?}`, which would overflow", l, r) } Overflow(BinOp::Mul, l, r) => { - write!(f, "attempt to compute `{:#?} * {:#?}` which would overflow", l, r) + write!(f, "attempt to compute `{:#?} * {:#?}`, which would overflow", l, r) } Overflow(BinOp::Div, l, r) => { - write!(f, "attempt to compute `{:#?} / {:#?}` which would overflow", l, r) + write!(f, "attempt to compute `{:#?} / {:#?}`, which would overflow", l, r) } Overflow(BinOp::Rem, l, r) => write!( f, - "attempt to compute the remainder of `{:#?} % {:#?}` which would overflow", + "attempt to compute the remainder of `{:#?} % {:#?}`, which would overflow", l, r ), Overflow(BinOp::Shr, _, r) => { - write!(f, "attempt to shift right by {:#?} which would overflow", r) + write!(f, "attempt to shift right by `{:#?}`, which would overflow", r) } Overflow(BinOp::Shl, _, r) => { - write!(f, "attempt to shift left by {:#?} which would overflow", r) + write!(f, "attempt to shift left by `{:#?}`, which would overflow", r) } _ => write!(f, "{}", self.description()), } diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 321472b8fe8..3e431a9c000 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -495,7 +495,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.tcx.sess, span, E0029, - "only char and numeric types are allowed in range patterns" + "only `char` and numeric types are allowed in range patterns" ); let msg = |ty| format!("this is of type `{}` but it should be `char` or numeric", ty); let mut one_side_err = |first_span, first_ty, second: Option<(bool, Ty<'tcx>, Span)>| { |
