diff --git a/compiler/rustc_builtin_macros/src/assert.rs b/compiler/rustc_builtin_macros/src/assert.rs index c659b1cff59b8..55fcdafcb0ada 100644 --- a/compiler/rustc_builtin_macros/src/assert.rs +++ b/compiler/rustc_builtin_macros/src/assert.rs @@ -1,9 +1,9 @@ mod context; use rustc_ast::ptr::P; -use rustc_ast::token::Delimiter; +use rustc_ast::token::{self, Delimiter}; use rustc_ast::tokenstream::{DelimSpan, TokenStream}; -use rustc_ast::{DelimArgs, Expr, ExprKind, MacCall, Path, PathSegment, UnOp, token}; +use rustc_ast::{DelimArgs, Expr, ExprKind, MacCall, Path, PathSegment}; use rustc_ast_pretty::pprust; use rustc_errors::PResult; use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult}; @@ -30,7 +30,7 @@ pub(crate) fn expand_assert<'cx>( // `core::panic` and `std::panic` are different macros, so we use call-site // context to pick up whichever is currently in scope. - let call_site_span = cx.with_call_site_ctxt(span); + let call_site_span = cx.with_call_site_ctxt(cond_expr.span); let panic_path = || { if use_panic_2021(span) { @@ -64,7 +64,7 @@ pub(crate) fn expand_assert<'cx>( }), })), ); - expr_if_not(cx, call_site_span, cond_expr, then, None) + expr_if_not(cx, call_site_span, cond_expr, then) } // If `generic_assert` is enabled, generates rich captured outputs // @@ -89,26 +89,30 @@ pub(crate) fn expand_assert<'cx>( )), )], ); - expr_if_not(cx, call_site_span, cond_expr, then, None) + expr_if_not(cx, call_site_span, cond_expr, then) }; ExpandResult::Ready(MacEager::expr(expr)) } +/// `assert!($cond_expr, $custom_message)` struct Assert { cond_expr: P, custom_message: Option, } -// if !{ ... } { ... } else { ... } -fn expr_if_not( - cx: &ExtCtxt<'_>, - span: Span, - cond: P, - then: P, - els: Option>, -) -> P { - cx.expr_if(span, cx.expr(span, ExprKind::Unary(UnOp::Not, cond)), then, els) +/// `match { true => {} _ => }` +fn expr_if_not(cx: &ExtCtxt<'_>, span: Span, cond: P, then: P) -> P { + // Instead of expanding to `if ! { }`, we expand to + // `match { true => {} _ }`. + // This allows us to always complain about mismatched types instead of "cannot apply unary + // operator `!` to type `X`" when passing an invalid ``, while also allowing `` to + // be `&true`. + let els = cx.expr_block(cx.block(span, thin_vec![])); + let mut arms = thin_vec![]; + arms.push(cx.arm(span, cx.pat_lit(span, cx.expr_bool(span, true)), els)); + arms.push(cx.arm(span, cx.pat_wild(span), then)); + cx.expr_match(span, cond, arms) } fn parse_assert<'a>(cx: &ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PResult<'a, Assert> { diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index bc0766705854a..7a0bb174863e4 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -697,7 +697,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { match (self.tcx.parent_hir_node(expr.hir_id), error) { (hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), init: Some(init), .. }), _) - if init.hir_id == expr.hir_id => + if init.hir_id == expr.hir_id && !ty.span.source_equal(init.span) => { // Point at `let` assignment type. err.span_label(ty.span, "expected due to this"); diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index bcb6ac13b8faf..3ab89b52491ab 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -457,7 +457,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { span, format!("this is an iterator with items of type `{}`", args.type_at(0)), ); - } else { + } else if !span.overlaps(cause.span) { let expected_ty = self.tcx.short_ty_string(expected_ty, path); err.span_label(span, format!("this expression has type `{expected_ty}`")); } @@ -1581,8 +1581,16 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { { let e = self.tcx.erase_regions(e); let f = self.tcx.erase_regions(f); - let expected = with_forced_trimmed_paths!(e.sort_string(self.tcx)); - let found = with_forced_trimmed_paths!(f.sort_string(self.tcx)); + let mut expected = with_forced_trimmed_paths!(e.sort_string(self.tcx)); + let mut found = with_forced_trimmed_paths!(f.sort_string(self.tcx)); + if let Some(def_id) = cause.span.ctxt().outer_expn_data().macro_def_id + && self.tcx.is_diagnostic_item(sym::assert_macro, def_id) + { + // When the type error comes from `assert!()`, the cause and effect are reversed + // because that macro expands to `match val { false => {panic!()}, _ => {} }`, which + // would say something like "expected `Type`, found `bool`", confusing the user. + (found, expected) = (expected, found); + } if expected == found { label_or_note(span, terr.to_string(self.tcx)); } else { @@ -2098,7 +2106,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { ) -> Option<(DiagStyledString, DiagStyledString, Option)> { match values { ValuePairs::Regions(exp_found) => self.expected_found_str(exp_found), - ValuePairs::Terms(exp_found) => self.expected_found_str_term(exp_found), + ValuePairs::Terms(exp_found) => self.expected_found_str_term(cause, exp_found), ValuePairs::Aliases(exp_found) => self.expected_found_str(exp_found), ValuePairs::ExistentialTraitRef(exp_found) => self.expected_found_str(exp_found), ValuePairs::ExistentialProjection(exp_found) => self.expected_found_str(exp_found), @@ -2139,14 +2147,26 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { fn expected_found_str_term( &self, + cause: &ObligationCause<'tcx>, exp_found: ty::error::ExpectedFound>, ) -> Option<(DiagStyledString, DiagStyledString, Option)> { let exp_found = self.resolve_vars_if_possible(exp_found); if exp_found.references_error() { return None; } + let (mut expected, mut found) = (exp_found.expected, exp_found.found); + if let Some(def_id) = cause.span.ctxt().outer_expn_data().macro_def_id + && self.tcx.is_diagnostic_item(sym::assert_macro, def_id) + { + // When the type error comes from `assert!()`, the cause and effect are reversed + // because that macro expands to `match val { false => {panic!()}, _ => {} }`, which + // would say something like + // = note: expected `Type` + // found `bool`" + (expected, found) = (found, expected); + } - Some(match (exp_found.expected.unpack(), exp_found.found.unpack()) { + Some(match (expected.unpack(), found.unpack()) { (ty::TermKind::Ty(expected), ty::TermKind::Ty(found)) => { let (mut exp, mut fnd) = self.cmp(expected, found); // Use the terminal width as the basis to determine when to compress the printed diff --git a/library/alloc/tests/str.rs b/library/alloc/tests/str.rs index 6f930ab08535c..5720d3ffd97b6 100644 --- a/library/alloc/tests/str.rs +++ b/library/alloc/tests/str.rs @@ -2297,21 +2297,21 @@ fn utf8_chars() { assert_eq!(schs.len(), 4); assert_eq!(schs.iter().cloned().collect::(), s); - assert!((from_utf8(s.as_bytes()).is_ok())); + assert!(from_utf8(s.as_bytes()).is_ok()); // invalid prefix - assert!((!from_utf8(&[0x80]).is_ok())); + assert!(!from_utf8(&[0x80]).is_ok()); // invalid 2 byte prefix - assert!((!from_utf8(&[0xc0]).is_ok())); - assert!((!from_utf8(&[0xc0, 0x10]).is_ok())); + assert!(!from_utf8(&[0xc0]).is_ok()); + assert!(!from_utf8(&[0xc0, 0x10]).is_ok()); // invalid 3 byte prefix - assert!((!from_utf8(&[0xe0]).is_ok())); - assert!((!from_utf8(&[0xe0, 0x10]).is_ok())); - assert!((!from_utf8(&[0xe0, 0xff, 0x10]).is_ok())); + assert!(!from_utf8(&[0xe0]).is_ok()); + assert!(!from_utf8(&[0xe0, 0x10]).is_ok()); + assert!(!from_utf8(&[0xe0, 0xff, 0x10]).is_ok()); // invalid 4 byte prefix - assert!((!from_utf8(&[0xf0]).is_ok())); - assert!((!from_utf8(&[0xf0, 0x10]).is_ok())); - assert!((!from_utf8(&[0xf0, 0xff, 0x10]).is_ok())); - assert!((!from_utf8(&[0xf0, 0xff, 0xff, 0x10]).is_ok())); + assert!(!from_utf8(&[0xf0]).is_ok()); + assert!(!from_utf8(&[0xf0, 0x10]).is_ok()); + assert!(!from_utf8(&[0xf0, 0xff, 0x10]).is_ok()); + assert!(!from_utf8(&[0xf0, 0xff, 0xff, 0x10]).is_ok()); } #[test] diff --git a/library/coretests/tests/bool.rs b/library/coretests/tests/bool.rs index 47f6459915b3e..bcd6dc2abac6c 100644 --- a/library/coretests/tests/bool.rs +++ b/library/coretests/tests/bool.rs @@ -71,14 +71,14 @@ fn test_bool() { #[test] pub fn test_bool_not() { if !false { - assert!((true)); + assert!(true); } else { - assert!((false)); + assert!(false); } if !true { - assert!((false)); + assert!(false); } else { - assert!((true)); + assert!(true); } } diff --git a/library/coretests/tests/ptr.rs b/library/coretests/tests/ptr.rs index 7cefb615d0371..345bec345d128 100644 --- a/library/coretests/tests/ptr.rs +++ b/library/coretests/tests/ptr.rs @@ -42,11 +42,11 @@ fn test() { let mut v1 = vec![0u16, 0u16, 0u16]; copy(v0.as_ptr().offset(1), v1.as_mut_ptr().offset(1), 1); - assert!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16)); + assert!(v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16); copy(v0.as_ptr().offset(2), v1.as_mut_ptr(), 1); - assert!((v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16)); + assert!(v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16); copy(v0.as_ptr(), v1.as_mut_ptr().offset(2), 1); - assert!((v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16)); + assert!(v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16); } } diff --git a/library/coretests/tests/tuple.rs b/library/coretests/tests/tuple.rs index ea1e281425c89..5d680d1047237 100644 --- a/library/coretests/tests/tuple.rs +++ b/library/coretests/tests/tuple.rs @@ -37,7 +37,7 @@ fn test_partial_ord() { assert!(!((1.0f64, 2.0f64) <= (f64::NAN, 3.0))); assert!(!((1.0f64, 2.0f64) > (f64::NAN, 3.0))); assert!(!((1.0f64, 2.0f64) >= (f64::NAN, 3.0))); - assert!(((1.0f64, 2.0f64) < (2.0, f64::NAN))); + assert!((1.0f64, 2.0f64) < (2.0, f64::NAN)); assert!(!((2.0f64, 2.0f64) < (2.0, f64::NAN))); } diff --git a/library/std/src/env/tests.rs b/library/std/src/env/tests.rs index d021726106872..ffbadf117c354 100644 --- a/library/std/src/env/tests.rs +++ b/library/std/src/env/tests.rs @@ -13,7 +13,7 @@ fn test_self_exe_path() { #[test] fn test() { - assert!((!Path::new("test-path").is_absolute())); + assert!(!Path::new("test-path").is_absolute()); #[cfg(not(target_env = "sgx"))] current_dir().unwrap(); diff --git a/library/std/tests/istr.rs b/library/std/tests/istr.rs index 9a127ae803e77..e481872977abf 100644 --- a/library/std/tests/istr.rs +++ b/library/std/tests/istr.rs @@ -5,7 +5,7 @@ fn test_stack_assign() { let t: String = "a".to_string(); assert_eq!(s, t); let u: String = "b".to_string(); - assert!((s != u)); + assert!(s != u); } #[test] @@ -19,7 +19,7 @@ fn test_heap_assign() { let t: String = "a big ol' string".to_string(); assert_eq!(s, t); let u: String = "a bad ol' string".to_string(); - assert!((s != u)); + assert!(s != u); } #[test] diff --git a/library/std/tests/seq-compare.rs b/library/std/tests/seq-compare.rs index 221f1c7cabde5..ec39c5b603ccc 100644 --- a/library/std/tests/seq-compare.rs +++ b/library/std/tests/seq-compare.rs @@ -1,15 +1,15 @@ #[test] fn seq_compare() { - assert!(("hello".to_string() < "hellr".to_string())); - assert!(("hello ".to_string() > "hello".to_string())); - assert!(("hello".to_string() != "there".to_string())); - assert!((vec![1, 2, 3, 4] > vec![1, 2, 3])); - assert!((vec![1, 2, 3] < vec![1, 2, 3, 4])); - assert!((vec![1, 2, 4, 4] > vec![1, 2, 3, 4])); - assert!((vec![1, 2, 3, 4] < vec![1, 2, 4, 4])); - assert!((vec![1, 2, 3] <= vec![1, 2, 3])); - assert!((vec![1, 2, 3] <= vec![1, 2, 3, 3])); - assert!((vec![1, 2, 3, 4] > vec![1, 2, 3])); + assert!("hello".to_string() < "hellr".to_string()); + assert!("hello ".to_string() > "hello".to_string()); + assert!("hello".to_string() != "there".to_string()); + assert!(vec![1, 2, 3, 4] > vec![1, 2, 3]); + assert!(vec![1, 2, 3] < vec![1, 2, 3, 4]); + assert!(vec![1, 2, 4, 4] > vec![1, 2, 3, 4]); + assert!(vec![1, 2, 3, 4] < vec![1, 2, 4, 4]); + assert!(vec![1, 2, 3] <= vec![1, 2, 3]); + assert!(vec![1, 2, 3] <= vec![1, 2, 3, 3]); + assert!(vec![1, 2, 3, 4] > vec![1, 2, 3]); assert_eq!(vec![1, 2, 3], vec![1, 2, 3]); - assert!((vec![1, 2, 3] != vec![1, 1, 3])); + assert!(vec![1, 2, 3] != vec![1, 1, 3]); } diff --git a/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs b/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs index adac2f27ea8cf..e6d55b9ff5162 100644 --- a/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs +++ b/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs @@ -129,13 +129,27 @@ impl<'tcx> LateLintPass<'tcx> for BoolAssertComparison { let mut suggestions = vec![(name_span, non_eq_mac.to_string()), (lit_span, String::new())]; - if bool_value ^ eq_macro { - let Some(sugg) = Sugg::hir_opt(cx, non_lit_expr) else { - return; - }; - suggestions.push((non_lit_expr.span, (!sugg).to_string())); + if let ty::Bool = non_lit_ty.kind() { + if bool_value ^ eq_macro { + let Some(sugg) = Sugg::hir_opt(cx, non_lit_expr) else { + return; + }; + suggestions.push((non_lit_expr.span, (!sugg).to_string())); + } + } else { + // If we have a `value` that is *not* `bool` but that `!value` *is*, we suggest + // `!!value`. + suggestions.push(( + non_lit_expr.span.shrink_to_lo(), + if bool_value ^ eq_macro { + "!".to_string() + } else { + "!!".to_string() + }, + )); } + diag.multipart_suggestion( format!("replace it with `{non_eq_mac}!(..)`"), suggestions, diff --git a/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs b/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs index d78299fe08be8..7adeed154d631 100644 --- a/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs +++ b/src/tools/clippy/clippy_lints/src/missing_asserts_for_indexing.rs @@ -10,7 +10,7 @@ use rustc_ast::{LitKind, RangeLimits}; use rustc_data_structures::packed::Pu128; use rustc_data_structures::unhash::UnindexMap; use rustc_errors::{Applicability, Diag}; -use rustc_hir::{BinOp, Block, Body, Expr, ExprKind, UnOp}; +use rustc_hir::{BinOp, Body, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::declare_lint_pass; use rustc_span::source_map::Spanned; @@ -134,9 +134,8 @@ fn assert_len_expr<'hir>( cx: &LateContext<'_>, expr: &'hir Expr<'hir>, ) -> Option<(LengthComparison, usize, &'hir Expr<'hir>)> { - if let Some(higher::If { cond, then, .. }) = higher::If::hir(expr) - && let ExprKind::Unary(UnOp::Not, condition) = &cond.kind - && let ExprKind::Binary(bin_op, left, right) = &condition.kind + if let higher::IfLetOrMatch::Match(cond, [_, then], _) = higher::IfLetOrMatch::parse(cx, expr)? + && let ExprKind::Binary(bin_op, left, right) = &cond.kind && let Some((cmp, asserted_len, slice_len)) = len_comparison(*bin_op, left, right) && let ExprKind::MethodCall(method, recv, [], _) = &slice_len.kind @@ -144,8 +143,7 @@ fn assert_len_expr<'hir>( && method.ident.name == sym::len // check if `then` block has a never type expression - && let ExprKind::Block(Block { expr: Some(then_expr), .. }, _) = then.kind - && cx.typeck_results().expr_ty(then_expr).is_never() + && cx.typeck_results().expr_ty(then.body).is_never() { Some((cmp, asserted_len, recv)) } else { @@ -337,21 +335,21 @@ fn report_indexes(cx: &LateContext<'_>, map: &UnindexMap // `v.len() < 5` and `v.len() <= 5` does nothing in terms of bounds checks. // The user probably meant `v.len() > 5` LengthComparison::LengthLessThanInt | LengthComparison::LengthLessThanOrEqualInt => Some( - format!("assert!({}.len() > {highest_index})", snippet(cx, slice.span, "..")), + format!("{}.len() > {highest_index}", snippet(cx, slice.span, "..")), ), // `5 < v.len()` == `v.len() > 5` LengthComparison::IntLessThanLength if asserted_len < highest_index => Some(format!( - "assert!({}.len() > {highest_index})", + "{}.len() > {highest_index}", snippet(cx, slice.span, "..") )), // `5 <= v.len() == `v.len() >= 5` LengthComparison::IntLessThanOrEqualLength if asserted_len <= highest_index => Some(format!( - "assert!({}.len() > {highest_index})", + "{}.len() > {highest_index}", snippet(cx, slice.span, "..") )), // `highest_index` here is rather a length, so we need to add 1 to it LengthComparison::LengthEqualInt if asserted_len < highest_index + 1 => Some(format!( - "assert!({}.len() == {})", + "{}.len() == {}", snippet(cx, slice.span, ".."), highest_index + 1 )), diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.fixed b/src/tools/clippy/tests/ui/bool_assert_comparison.fixed index b05166a055ee3..a9856f39c3289 100644 --- a/src/tools/clippy/tests/ui/bool_assert_comparison.fixed +++ b/src/tools/clippy/tests/ui/bool_assert_comparison.fixed @@ -91,7 +91,7 @@ fn main() { assert_eq!(a!(), "".is_empty()); assert_eq!("".is_empty(), b!()); assert_eq!(a, true); - assert!(b); + assert!(!!b); assert_ne!("a".len(), 1); assert!("a".is_empty()); @@ -111,7 +111,7 @@ fn main() { debug_assert_eq!(a!(), "".is_empty()); debug_assert_eq!("".is_empty(), b!()); debug_assert_eq!(a, true); - debug_assert!(b); + debug_assert!(!!b); debug_assert_ne!("a".len(), 1); debug_assert!("a".is_empty()); @@ -143,7 +143,7 @@ fn main() { use debug_assert_eq as renamed; renamed!(a, true); - debug_assert!(b); + debug_assert!(!!b); let non_copy = NonCopy; assert_eq!(non_copy, true); diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.stderr b/src/tools/clippy/tests/ui/bool_assert_comparison.stderr index 41183c61ee01d..80530f11ef7df 100644 --- a/src/tools/clippy/tests/ui/bool_assert_comparison.stderr +++ b/src/tools/clippy/tests/ui/bool_assert_comparison.stderr @@ -45,7 +45,7 @@ LL | assert_eq!(b, true); help: replace it with `assert!(..)` | LL - assert_eq!(b, true); -LL + assert!(b); +LL + assert!(!!b); | error: used `assert_ne!` with a literal bool @@ -141,7 +141,7 @@ LL | debug_assert_eq!(b, true); help: replace it with `debug_assert!(..)` | LL - debug_assert_eq!(b, true); -LL + debug_assert!(b); +LL + debug_assert!(!!b); | error: used `debug_assert_ne!` with a literal bool @@ -297,7 +297,7 @@ LL | renamed!(b, true); help: replace it with `debug_assert!(..)` | LL - renamed!(b, true); -LL + debug_assert!(b); +LL + debug_assert!(!!b); | error: used `assert_eq!` with a literal bool diff --git a/src/tools/clippy/tests/ui/const_is_empty.stderr b/src/tools/clippy/tests/ui/const_is_empty.stderr index 0afba940d8b4b..1a417b0e7ac4a 100644 --- a/src/tools/clippy/tests/ui/const_is_empty.stderr +++ b/src/tools/clippy/tests/ui/const_is_empty.stderr @@ -157,11 +157,17 @@ error: this expression always evaluates to true LL | let _ = val.is_empty(); | ^^^^^^^^^^^^^^ +error: this expression always evaluates to true + --> tests/ui/const_is_empty.rs:181:17 + | +LL | assert!(EMPTY_STR.is_empty()); + | ^^^^^^^^^^^^^^^^^^^^ + error: this expression always evaluates to true --> tests/ui/const_is_empty.rs:185:9 | LL | EMPTY_STR.is_empty(); | ^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 27 previous errors +error: aborting due to 28 previous errors diff --git a/src/tools/clippy/tests/ui/missing_asserts_for_indexing.stderr b/src/tools/clippy/tests/ui/missing_asserts_for_indexing.stderr index 2e63cd4a0e503..4987f06d6becc 100644 --- a/src/tools/clippy/tests/ui/missing_asserts_for_indexing.stderr +++ b/src/tools/clippy/tests/ui/missing_asserts_for_indexing.stderr @@ -2,7 +2,7 @@ error: indexing into a slice multiple times with an `assert` that does not cover --> tests/ui/missing_asserts_for_indexing.rs:30:5 | LL | assert!(v.len() < 5); - | -------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` + | ----------- help: provide the highest index that is indexed with: `v.len() > 4` LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | @@ -39,7 +39,7 @@ error: indexing into a slice multiple times with an `assert` that does not cover --> tests/ui/missing_asserts_for_indexing.rs:36:5 | LL | assert!(v.len() <= 5); - | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` + | ------------ help: provide the highest index that is indexed with: `v.len() > 4` LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | @@ -74,7 +74,7 @@ error: indexing into a slice multiple times with an `assert` that does not cover --> tests/ui/missing_asserts_for_indexing.rs:42:5 | LL | assert!(v.len() > 3); - | -------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` + | ----------- help: provide the highest index that is indexed with: `v.len() > 4` LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | @@ -109,7 +109,7 @@ error: indexing into a slice multiple times with an `assert` that does not cover --> tests/ui/missing_asserts_for_indexing.rs:48:5 | LL | assert!(v.len() >= 4); - | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` + | ------------ help: provide the highest index that is indexed with: `v.len() > 4` LL | v[0] + v[1] + v[2] + v[3] + v[4] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | @@ -144,7 +144,7 @@ error: indexing into a slice multiple times with an `assert` that does not cover --> tests/ui/missing_asserts_for_indexing.rs:66:13 | LL | assert!(v.len() >= 3); - | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 3)` + | ------------ help: provide the highest index that is indexed with: `v.len() > 3` LL | let _ = v[0]; | _____________^ LL | | @@ -167,7 +167,7 @@ error: indexing into a slice multiple times with an `assert` that does not cover --> tests/ui/missing_asserts_for_indexing.rs:80:13 | LL | assert!(v.len() >= 4); - | --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)` + | ------------ help: provide the highest index that is indexed with: `v.len() > 4` LL | let _ = v[0]; | _____________^ LL | | @@ -190,7 +190,7 @@ error: indexing into a slice multiple times with an `assert` that does not cover --> tests/ui/missing_asserts_for_indexing.rs:95:13 | LL | assert!(v1.len() >= 12); - | ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)` + | -------------- help: provide the highest index that is indexed with: `v1.len() > 12` LL | assert!(v2.len() >= 15); LL | let _ = v1[0] + v1[12]; | ^^^^^^^^^^^^^^ @@ -211,7 +211,7 @@ error: indexing into a slice multiple times with an `assert` that does not cover --> tests/ui/missing_asserts_for_indexing.rs:97:13 | LL | assert!(v2.len() >= 15); - | ----------------------- help: provide the highest index that is indexed with: `assert!(v2.len() > 15)` + | -------------- help: provide the highest index that is indexed with: `v2.len() > 15` ... LL | let _ = v2[5] + v2[15]; | ^^^^^^^^^^^^^^ @@ -232,7 +232,7 @@ error: indexing into a slice multiple times with an `assert` that does not cover --> tests/ui/missing_asserts_for_indexing.rs:103:13 | LL | assert!(v1.len() >= 12); - | ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)` + | -------------- help: provide the highest index that is indexed with: `v1.len() > 12` LL | assert!(v2.len() > 15); LL | let _ = v1[0] + v1[12]; | ^^^^^^^^^^^^^^ @@ -253,7 +253,7 @@ error: indexing into a slice multiple times with an `assert` that does not cover --> tests/ui/missing_asserts_for_indexing.rs:127:13 | LL | assert!(v1.len() == 2); - | ---------------------- help: provide the highest index that is indexed with: `assert!(v1.len() == 3)` + | ------------- help: provide the highest index that is indexed with: `v1.len() == 3` ... LL | let _ = v1[0] + v1[1] + v1[2]; | ^^^^^^^^^^^^^^^^^^^^^ @@ -279,7 +279,7 @@ error: indexing into a slice multiple times with an `assert` that does not cover --> tests/ui/missing_asserts_for_indexing.rs:131:13 | LL | assert!(2 == v3.len()); - | ---------------------- help: provide the highest index that is indexed with: `assert!(v3.len() == 3)` + | ------------- help: provide the highest index that is indexed with: `v3.len() == 3` ... LL | let _ = v3[0] + v3[1] + v3[2]; | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/tools/miri/tests/pass/binops.rs b/src/tools/miri/tests/pass/binops.rs index 0988d7ccc4c6e..0aff7acb29d44 100644 --- a/src/tools/miri/tests/pass/binops.rs +++ b/src/tools/miri/tests/pass/binops.rs @@ -2,23 +2,23 @@ fn test_nil() { assert_eq!((), ()); - assert!((!(() != ()))); - assert!((!(() < ()))); - assert!((() <= ())); - assert!((!(() > ()))); - assert!((() >= ())); + assert!(!(() != ())); + assert!(!(() < ())); + assert!(() <= ()); + assert!(!(() > ())); + assert!(() >= ()); } fn test_bool() { - assert!((!(true < false))); - assert!((!(true <= false))); - assert!((true > false)); - assert!((true >= false)); + assert!(!(true < false)); + assert!(!(true <= false)); + assert!(true > false); + assert!(true >= false); - assert!((false < true)); - assert!((false <= true)); - assert!((!(false > true))); - assert!((!(false >= true))); + assert!(false < true); + assert!(false <= true); + assert!(!(false > true)); + assert!(!(false >= true)); // Bools support bitwise binops assert_eq!(false & false, false); @@ -65,9 +65,9 @@ fn test_class() { assert_eq!(q, r); r.y = 17; - assert!((r.y != q.y)); + assert!(r.y != q.y); assert_eq!(r.y, 17); - assert!((q != r)); + assert!(q != r); } pub fn main() { diff --git a/tests/coverage/assert_not.cov-map b/tests/coverage/assert_not.cov-map index 397eaa17caf6d..4fd86e1404118 100644 --- a/tests/coverage/assert_not.cov-map +++ b/tests/coverage/assert_not.cov-map @@ -1,15 +1,18 @@ Function name: assert_not::main -Raw bytes (31): 0x[01, 01, 01, 0d, 00, 05, 01, 06, 01, 01, 12, 05, 02, 05, 00, 14, 09, 01, 05, 00, 14, 0d, 01, 05, 00, 16, 02, 01, 01, 00, 02] +Raw bytes (54): 0x[01, 01, 00, 0a, 01, 06, 01, 00, 0b, 05, 01, 05, 00, 0c, 01, 00, 0d, 00, 11, 09, 01, 05, 00, 0c, 05, 00, 0d, 00, 13, 0d, 01, 05, 00, 0c, 09, 00, 0d, 00, 13, 11, 01, 05, 00, 0c, 0d, 00, 0d, 00, 15, 11, 01, 01, 00, 02] Number of files: 1 - file 0 => global file 1 -Number of expressions: 1 -- expression 0 operands: lhs = Counter(3), rhs = Zero -Number of file 0 mappings: 5 -- Code(Counter(0)) at (prev + 6, 1) to (start + 1, 18) -- Code(Counter(1)) at (prev + 2, 5) to (start + 0, 20) -- Code(Counter(2)) at (prev + 1, 5) to (start + 0, 20) -- Code(Counter(3)) at (prev + 1, 5) to (start + 0, 22) -- Code(Expression(0, Sub)) at (prev + 1, 1) to (start + 0, 2) - = (c3 - Zero) -Highest counter ID seen: c3 +Number of expressions: 0 +Number of file 0 mappings: 10 +- Code(Counter(0)) at (prev + 6, 1) to (start + 0, 11) +- Code(Counter(1)) at (prev + 1, 5) to (start + 0, 12) +- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 17) +- Code(Counter(2)) at (prev + 1, 5) to (start + 0, 12) +- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 19) +- Code(Counter(3)) at (prev + 1, 5) to (start + 0, 12) +- Code(Counter(2)) at (prev + 0, 13) to (start + 0, 19) +- Code(Counter(4)) at (prev + 1, 5) to (start + 0, 12) +- Code(Counter(3)) at (prev + 0, 13) to (start + 0, 21) +- Code(Counter(4)) at (prev + 1, 1) to (start + 0, 2) +Highest counter ID seen: c4 diff --git a/tests/ui/binding/expr-match-generic.rs b/tests/ui/binding/expr-match-generic.rs index 975eec42fd054..dcc069b9fb329 100644 --- a/tests/ui/binding/expr-match-generic.rs +++ b/tests/ui/binding/expr-match-generic.rs @@ -5,7 +5,7 @@ type compare = extern "Rust" fn(T, T) -> bool; fn test_generic(expected: T, eq: compare) { let actual: T = match true { true => { expected.clone() }, _ => panic!("wat") }; - assert!((eq(expected, actual))); + assert!(eq(expected, actual)); } fn test_bool() { diff --git a/tests/ui/binding/expr-match.rs b/tests/ui/binding/expr-match.rs index 049beaaf51bf6..133995806634c 100644 --- a/tests/ui/binding/expr-match.rs +++ b/tests/ui/binding/expr-match.rs @@ -7,14 +7,14 @@ fn test_basic() { let mut rs: bool = match true { true => { true } false => { false } }; - assert!((rs)); + assert!(rs); rs = match false { true => { false } false => { true } }; - assert!((rs)); + assert!(rs); } fn test_inferrence() { let rs = match true { true => { true } false => { false } }; - assert!((rs)); + assert!(rs); } fn test_alt_as_alt_head() { @@ -25,7 +25,7 @@ fn test_alt_as_alt_head() { true => { false } false => { true } }; - assert!((rs)); + assert!(rs); } fn test_alt_as_block_result() { @@ -34,7 +34,7 @@ fn test_alt_as_block_result() { true => { false } false => { match true { true => { true } false => { false } } } }; - assert!((rs)); + assert!(rs); } pub fn main() { diff --git a/tests/ui/binop/binops.rs b/tests/ui/binop/binops.rs index 0adbb49b14a37..7142190a45b9a 100644 --- a/tests/ui/binop/binops.rs +++ b/tests/ui/binop/binops.rs @@ -5,23 +5,23 @@ fn test_nil() { assert_eq!((), ()); - assert!((!(() != ()))); - assert!((!(() < ()))); - assert!((() <= ())); - assert!((!(() > ()))); - assert!((() >= ())); + assert!(!(() != ())); + assert!(!(() < ())); + assert!(() <= ()); + assert!(!(() > ())); + assert!(() >= ()); } fn test_bool() { - assert!((!(true < false))); - assert!((!(true <= false))); - assert!((true > false)); - assert!((true >= false)); + assert!(!(true < false)); + assert!(!(true <= false)); + assert!(true > false); + assert!(true >= false); - assert!((false < true)); - assert!((false <= true)); - assert!((!(false > true))); - assert!((!(false >= true))); + assert!(false < true); + assert!(false <= true); + assert!(!(false > true)); + assert!(!(false >= true)); // Bools support bitwise binops assert_eq!(false & false, false); @@ -76,9 +76,9 @@ fn test_class() { } assert_eq!(q, r); r.y = 17; - assert!((r.y != q.y)); + assert!(r.y != q.y); assert_eq!(r.y, 17); - assert!((q != r)); + assert!(q != r); } pub fn main() { diff --git a/tests/ui/binop/structured-compare.rs b/tests/ui/binop/structured-compare.rs index 164760cd7a040..7d1eff453028a 100644 --- a/tests/ui/binop/structured-compare.rs +++ b/tests/ui/binop/structured-compare.rs @@ -17,14 +17,14 @@ pub fn main() { let a = (1, 2, 3); let b = (1, 2, 3); assert_eq!(a, b); - assert!((a != (1, 2, 4))); - assert!((a < (1, 2, 4))); - assert!((a <= (1, 2, 4))); - assert!(((1, 2, 4) > a)); - assert!(((1, 2, 4) >= a)); + assert!(a != (1, 2, 4)); + assert!(a < (1, 2, 4)); + assert!(a <= (1, 2, 4)); + assert!((1, 2, 4) > a); + assert!((1, 2, 4) >= a); let x = foo::large; let y = foo::small; - assert!((x != y)); + assert!(x != y); assert_eq!(x, foo::large); - assert!((x != foo::small)); + assert!(x != foo::small); } diff --git a/tests/ui/cfg/conditional-compile.rs b/tests/ui/cfg/conditional-compile.rs index a4f334dd696ab..dff280054d659 100644 --- a/tests/ui/cfg/conditional-compile.rs +++ b/tests/ui/cfg/conditional-compile.rs @@ -85,7 +85,7 @@ pub fn main() { pub fn main() { // Exercise some of the configured items in ways that wouldn't be possible // if they had the FALSE definition - assert!((b)); + assert!(b); let _x: t = true; let _y: tg = tg::bar; diff --git a/tests/ui/codemap_tests/issue-28308.rs b/tests/ui/codemap_tests/issue-28308.rs index 81493f8c45311..b0e04d0f1f6b1 100644 --- a/tests/ui/codemap_tests/issue-28308.rs +++ b/tests/ui/codemap_tests/issue-28308.rs @@ -1,4 +1,16 @@ fn main() { - assert!("foo"); - //~^ ERROR cannot apply unary operator `!` + assert!("foo"); //~ ERROR mismatched types + //~^ NOTE expected `bool`, found `str` + //~| NOTE in this expansion of assert! + let x = Some(&1); + assert!(x); //~ ERROR mismatched types + //~^ NOTE expected `bool`, found `Option<&{integer}>` + //~| NOTE expected enum `bool` + //~| NOTE in this expansion of assert! + //~| NOTE in this expansion of assert! + assert!(x, ""); //~ ERROR mismatched types + //~^ NOTE expected `bool`, found `Option<&{integer}>` + //~| NOTE expected enum `bool` + //~| NOTE in this expansion of assert! + //~| NOTE in this expansion of assert! } diff --git a/tests/ui/codemap_tests/issue-28308.stderr b/tests/ui/codemap_tests/issue-28308.stderr index efd8fa22fa5ce..bdafad7ccd7a5 100644 --- a/tests/ui/codemap_tests/issue-28308.stderr +++ b/tests/ui/codemap_tests/issue-28308.stderr @@ -1,11 +1,31 @@ -error[E0600]: cannot apply unary operator `!` to type `&'static str` - --> $DIR/issue-28308.rs:2:5 +error[E0308]: mismatched types + --> $DIR/issue-28308.rs:2:13 | LL | assert!("foo"); - | ^^^^^^^^^^^^^^ cannot apply unary operator `!` + | ^^^^^ expected `bool`, found `str` | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 1 previous error +error[E0308]: mismatched types + --> $DIR/issue-28308.rs:6:13 + | +LL | assert!(x); + | ^ expected `bool`, found `Option<&{integer}>` + | + = note: expected enum `bool` + found type `Option<&{integer}>` + = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0308]: mismatched types + --> $DIR/issue-28308.rs:11:13 + | +LL | assert!(x, ""); + | ^ expected `bool`, found `Option<&{integer}>` + | + = note: expected enum `bool` + found type `Option<&{integer}>` + = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0600`. +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/consts/control-flow/assert.stderr b/tests/ui/consts/control-flow/assert.stderr index 2f863daf760da..e0ae949b13c44 100644 --- a/tests/ui/consts/control-flow/assert.stderr +++ b/tests/ui/consts/control-flow/assert.stderr @@ -1,8 +1,8 @@ error[E0080]: evaluation of constant value failed - --> $DIR/assert.rs:5:15 + --> $DIR/assert.rs:5:23 | LL | const _: () = assert!(false); - | ^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: false', $DIR/assert.rs:5:15 + | ^^^^^ the evaluated program panicked at 'assertion failed: false', $DIR/assert.rs:5:15 | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/else-if.rs b/tests/ui/else-if.rs index 2161b28c58c93..26db3ec50306e 100644 --- a/tests/ui/else-if.rs +++ b/tests/ui/else-if.rs @@ -2,19 +2,19 @@ pub fn main() { if 1 == 2 { - assert!((false)); + assert!(false); } else if 2 == 3 { - assert!((false)); - } else if 3 == 4 { assert!((false)); } else { assert!((true)); } - if 1 == 2 { assert!((false)); } else if 2 == 2 { assert!((true)); } + assert!(false); + } else if 3 == 4 { assert!(false); } else { assert!(true); } + if 1 == 2 { assert!(false); } else if 2 == 2 { assert!(true); } if 1 == 2 { - assert!((false)); + assert!(false); } else if 2 == 2 { if 1 == 1 { - assert!((true)); - } else { if 2 == 1 { assert!((false)); } else { assert!((false)); } } + assert!(true); + } else { if 2 == 1 { assert!(false); } else { assert!(false); } } } if 1 == 2 { - assert!((false)); - } else { if 1 == 2 { assert!((false)); } else { assert!((true)); } } + assert!(false); + } else { if 1 == 2 { assert!(false); } else { assert!(true); } } } diff --git a/tests/ui/expr/block.rs b/tests/ui/expr/block.rs index bf626c9ead372..70f5c274c214d 100644 --- a/tests/ui/expr/block.rs +++ b/tests/ui/expr/block.rs @@ -4,7 +4,7 @@ // Tests for standalone blocks as expressions -fn test_basic() { let rs: bool = { true }; assert!((rs)); } +fn test_basic() { let rs: bool = { true }; assert!(rs); } struct RS { v1: isize, v2: isize } diff --git a/tests/ui/expr/if/expr-if.rs b/tests/ui/expr/if/expr-if.rs index ae869c4b77a38..68c2fc2213015 100644 --- a/tests/ui/expr/if/expr-if.rs +++ b/tests/ui/expr/if/expr-if.rs @@ -1,43 +1,43 @@ //@ run-pass // Tests for if as expressions -fn test_if() { let rs: bool = if true { true } else { false }; assert!((rs)); } +fn test_if() { let rs: bool = if true { true } else { false }; assert!(rs); } fn test_else() { let rs: bool = if false { false } else { true }; - assert!((rs)); + assert!(rs); } fn test_elseif1() { let rs: bool = if true { true } else if true { false } else { false }; - assert!((rs)); + assert!(rs); } fn test_elseif2() { let rs: bool = if false { false } else if true { true } else { false }; - assert!((rs)); + assert!(rs); } fn test_elseif3() { let rs: bool = if false { false } else if false { false } else { true }; - assert!((rs)); + assert!(rs); } fn test_inferrence() { let rs = if true { true } else { false }; - assert!((rs)); + assert!(rs); } fn test_if_as_if_condition() { let rs1 = if if false { false } else { true } { true } else { false }; - assert!((rs1)); + assert!(rs1); let rs2 = if if true { false } else { true } { false } else { true }; - assert!((rs2)); + assert!(rs2); } fn test_if_as_block_result() { let rs = if true { if false { false } else { true } } else { false }; - assert!((rs)); + assert!(rs); } pub fn main() { diff --git a/tests/ui/for-loop-while/break.rs b/tests/ui/for-loop-while/break.rs index 77774792262cd..442e07e148c57 100644 --- a/tests/ui/for-loop-while/break.rs +++ b/tests/ui/for-loop-while/break.rs @@ -8,18 +8,18 @@ pub fn main() { assert_eq!(i, 20); let xs = [1, 2, 3, 4, 5, 6]; for x in &xs { - if *x == 3 { break; } assert!((*x <= 3)); + if *x == 3 { break; } assert!(*x <= 3); } i = 0; - while i < 10 { i += 1; if i % 2 == 0 { continue; } assert!((i % 2 != 0)); } + while i < 10 { i += 1; if i % 2 == 0 { continue; } assert!(i % 2 != 0); } i = 0; loop { - i += 1; if i % 2 == 0 { continue; } assert!((i % 2 != 0)); + i += 1; if i % 2 == 0 { continue; } assert!(i % 2 != 0); if i >= 10 { break; } } let ys = vec![1, 2, 3, 4, 5, 6]; for x in &ys { if *x % 2 == 0 { continue; } - assert!((*x % 2 != 0)); + assert!(*x % 2 != 0); } } diff --git a/tests/ui/for-loop-while/while-cont.rs b/tests/ui/for-loop-while/while-cont.rs index 1640b7e1803bd..73a08c26f9af6 100644 --- a/tests/ui/for-loop-while/while-cont.rs +++ b/tests/ui/for-loop-while/while-cont.rs @@ -3,7 +3,7 @@ pub fn main() { let mut i = 1; while i > 0 { - assert!((i > 0)); + assert!(i > 0); println!("{}", i); i -= 1; continue; diff --git a/tests/ui/for-loop-while/while-loop-constraints-2.rs b/tests/ui/for-loop-while/while-loop-constraints-2.rs index 654f6769902bd..1d2d9c2ecfe60 100644 --- a/tests/ui/for-loop-while/while-loop-constraints-2.rs +++ b/tests/ui/for-loop-while/while-loop-constraints-2.rs @@ -11,5 +11,5 @@ pub fn main() { while false { x = y; y = z; } println!("{}", y); } - assert!((y == 42 && z == 50)); + assert!(y == 42 && z == 50); } diff --git a/tests/ui/generics/generic-tag-match.rs b/tests/ui/generics/generic-tag-match.rs index dd0291e9d8736..378b51df287b3 100644 --- a/tests/ui/generics/generic-tag-match.rs +++ b/tests/ui/generics/generic-tag-match.rs @@ -7,7 +7,7 @@ enum foo { arm(T), } fn altfoo(f: foo) { let mut hit = false; match f { foo::arm::(_x) => { println!("in arm"); hit = true; } } - assert!((hit)); + assert!(hit); } pub fn main() { altfoo::(foo::arm::(10)); } diff --git a/tests/ui/generics/post_monomorphization_error_backtrace.stderr b/tests/ui/generics/post_monomorphization_error_backtrace.stderr index 8a57979bca7d4..3921c32a9c892 100644 --- a/tests/ui/generics/post_monomorphization_error_backtrace.stderr +++ b/tests/ui/generics/post_monomorphization_error_backtrace.stderr @@ -1,8 +1,8 @@ error[E0080]: evaluation of `assert_zst::F::::V` failed - --> $DIR/post_monomorphization_error_backtrace.rs:6:23 + --> $DIR/post_monomorphization_error_backtrace.rs:6:31 | LL | const V: () = assert!(std::mem::size_of::() == 0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: std::mem::size_of::() == 0', $DIR/post_monomorphization_error_backtrace.rs:6:23 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: std::mem::size_of::() == 0', $DIR/post_monomorphization_error_backtrace.rs:6:23 | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -19,10 +19,10 @@ LL | assert_zst::() | ^^^^^^^^^^^^^^^^^ error[E0080]: evaluation of `assert_zst::F::::V` failed - --> $DIR/post_monomorphization_error_backtrace.rs:6:23 + --> $DIR/post_monomorphization_error_backtrace.rs:6:31 | LL | const V: () = assert!(std::mem::size_of::() == 0); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: std::mem::size_of::() == 0', $DIR/post_monomorphization_error_backtrace.rs:6:23 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: std::mem::size_of::() == 0', $DIR/post_monomorphization_error_backtrace.rs:6:23 | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/inline-const/const-expr-generic-err.stderr b/tests/ui/inline-const/const-expr-generic-err.stderr index dcd6b62bbfc1d..10d8d0191c0ff 100644 --- a/tests/ui/inline-const/const-expr-generic-err.stderr +++ b/tests/ui/inline-const/const-expr-generic-err.stderr @@ -1,8 +1,8 @@ error[E0080]: evaluation of `foo::::{constant#0}` failed - --> $DIR/const-expr-generic-err.rs:4:13 + --> $DIR/const-expr-generic-err.rs:4:21 | LL | const { assert!(std::mem::size_of::() == 0); } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: std::mem::size_of::() == 0', $DIR/const-expr-generic-err.rs:4:13 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: std::mem::size_of::() == 0', $DIR/const-expr-generic-err.rs:4:13 | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/issues/issue-14091-2.rs b/tests/ui/issues/issue-14091-2.rs index e2f6b18337266..23163b8cf481a 100644 --- a/tests/ui/issues/issue-14091-2.rs +++ b/tests/ui/issues/issue-14091-2.rs @@ -13,5 +13,5 @@ fn main() { let x = BytePos(1); assert!(x, x); - //~^ ERROR cannot apply unary operator `!` to type `BytePos` + //~^ ERROR mismatched types } diff --git a/tests/ui/issues/issue-14091-2.stderr b/tests/ui/issues/issue-14091-2.stderr index ac8947670592a..29e63cd35aaf7 100644 --- a/tests/ui/issues/issue-14091-2.stderr +++ b/tests/ui/issues/issue-14091-2.stderr @@ -1,18 +1,11 @@ -error[E0600]: cannot apply unary operator `!` to type `BytePos` - --> $DIR/issue-14091-2.rs:15:5 +error[E0308]: mismatched types + --> $DIR/issue-14091-2.rs:15:13 | LL | assert!(x, x); - | ^^^^^^^^^^^^^ cannot apply unary operator `!` + | ^ expected `bool`, found `BytePos` | -note: an implementation of `Not` might be missing for `BytePos` - --> $DIR/issue-14091-2.rs:6:1 - | -LL | pub struct BytePos(pub u32); - | ^^^^^^^^^^^^^^^^^^ must implement `Not` -note: the trait `Not` must be implemented - --> $SRC_DIR/core/src/ops/bit.rs:LL:COL = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0600`. +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/issues/issue-14091.stderr b/tests/ui/issues/issue-14091.stderr index 83879583b1f29..53251699eb404 100644 --- a/tests/ui/issues/issue-14091.stderr +++ b/tests/ui/issues/issue-14091.stderr @@ -1,8 +1,10 @@ error[E0308]: mismatched types - --> $DIR/issue-14091.rs:2:5 + --> $DIR/issue-14091.rs:2:13 | LL | assert!(1,1); - | ^^^^^^^^^^^^ expected `bool`, found integer + | ^ expected `bool`, found integer + | + = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error diff --git a/tests/ui/iterators/iter-range.rs b/tests/ui/iterators/iter-range.rs index 9594729c06cf0..ec99331753989 100644 --- a/tests/ui/iterators/iter-range.rs +++ b/tests/ui/iterators/iter-range.rs @@ -2,7 +2,7 @@ fn range_(a: isize, b: isize, mut it: F) where F: FnMut(isize) { - assert!((a < b)); + assert!(a < b); let mut i: isize = a; while i < b { it(i); i += 1; } } diff --git a/tests/ui/lazy-and-or.rs b/tests/ui/lazy-and-or.rs index f9dbeb68959a3..4691f9f27497b 100644 --- a/tests/ui/lazy-and-or.rs +++ b/tests/ui/lazy-and-or.rs @@ -1,12 +1,12 @@ //@ run-pass -fn incr(x: &mut isize) -> bool { *x += 1; assert!((false)); return false; } +fn incr(x: &mut isize) -> bool { *x += 1; assert!(false); return false; } pub fn main() { let x = 1 == 2 || 3 == 3; - assert!((x)); + assert!(x); let mut y: isize = 10; println!("{}", x || incr(&mut y)); assert_eq!(y, 10); - if true && x { assert!((true)); } else { assert!((false)); } + if true && x { assert!(true); } else { assert!(false); } } diff --git a/tests/ui/macros/syntax-extension-source-utils.rs b/tests/ui/macros/syntax-extension-source-utils.rs index a16ebdc750424..2f88e508058c1 100644 --- a/tests/ui/macros/syntax-extension-source-utils.rs +++ b/tests/ui/macros/syntax-extension-source-utils.rs @@ -16,7 +16,7 @@ pub fn main() { assert_eq!(line!(), 16); assert_eq!(column!(), 16); assert_eq!(indirect_line!(), 18); - assert!((file!().ends_with("syntax-extension-source-utils.rs"))); + assert!(file!().ends_with("syntax-extension-source-utils.rs")); assert_eq!(stringify!((2*3) + 5).to_string(), "(2*3) + 5".to_string()); assert!(include!("syntax-extension-source-utils-files/includeme.\ fragment").to_string() @@ -30,7 +30,7 @@ pub fn main() { include_bytes!("syntax-extension-source-utils-files/includeme.fragment") [1] == (42 as u8)); // '*' // The Windows tests are wrapped in an extra module for some reason - assert!((m1::m2::where_am_i().ends_with("m1::m2"))); + assert!(m1::m2::where_am_i().ends_with("m1::m2")); assert_eq!((35, "(2*3) + 5"), (line!(), stringify!((2*3) + 5))); } diff --git a/tests/ui/numbers-arithmetic/arith-unsigned.rs b/tests/ui/numbers-arithmetic/arith-unsigned.rs index 5a285ceca32db..4a1bae438ca2e 100644 --- a/tests/ui/numbers-arithmetic/arith-unsigned.rs +++ b/tests/ui/numbers-arithmetic/arith-unsigned.rs @@ -3,22 +3,22 @@ // Unsigned integer operations pub fn main() { - assert!((0u8 < 255u8)); - assert!((0u8 <= 255u8)); - assert!((255u8 > 0u8)); - assert!((255u8 >= 0u8)); + assert!(0u8 < 255u8); + assert!(0u8 <= 255u8); + assert!(255u8 > 0u8); + assert!(255u8 >= 0u8); assert_eq!(250u8 / 10u8, 25u8); assert_eq!(255u8 % 10u8, 5u8); - assert!((0u16 < 60000u16)); - assert!((0u16 <= 60000u16)); - assert!((60000u16 > 0u16)); - assert!((60000u16 >= 0u16)); + assert!(0u16 < 60000u16); + assert!(0u16 <= 60000u16); + assert!(60000u16 > 0u16); + assert!(60000u16 >= 0u16); assert_eq!(60000u16 / 10u16, 6000u16); assert_eq!(60005u16 % 10u16, 5u16); - assert!((0u32 < 4000000000u32)); - assert!((0u32 <= 4000000000u32)); - assert!((4000000000u32 > 0u32)); - assert!((4000000000u32 >= 0u32)); + assert!(0u32 < 4000000000u32); + assert!(0u32 <= 4000000000u32); + assert!(4000000000u32 > 0u32); + assert!(4000000000u32 >= 0u32); assert_eq!(4000000000u32 / 10u32, 400000000u32); assert_eq!(4000000005u32 % 10u32, 5u32); // 64-bit numbers have some flakiness yet. Not tested diff --git a/tests/ui/numbers-arithmetic/float2.rs b/tests/ui/numbers-arithmetic/float2.rs index 1b7add01cc631..515220fee9ffe 100644 --- a/tests/ui/numbers-arithmetic/float2.rs +++ b/tests/ui/numbers-arithmetic/float2.rs @@ -15,12 +15,12 @@ pub fn main() { let j = 3.1e+9f64; let k = 3.2e-10f64; assert_eq!(a, b); - assert!((c < b)); + assert!(c < b); assert_eq!(c, d); - assert!((e < g)); - assert!((f < h)); + assert!(e < g); + assert!(f < h); assert_eq!(g, 1000000.0f32); assert_eq!(h, i); - assert!((j > k)); - assert!((k < a)); + assert!(j > k); + assert!(k < a); } diff --git a/tests/ui/numbers-arithmetic/floatlits.rs b/tests/ui/numbers-arithmetic/floatlits.rs index 21f19b69c49e7..2dab224201193 100644 --- a/tests/ui/numbers-arithmetic/floatlits.rs +++ b/tests/ui/numbers-arithmetic/floatlits.rs @@ -4,9 +4,9 @@ pub fn main() { let f = 4.999999999999f64; - assert!((f > 4.90f64)); - assert!((f < 5.0f64)); + assert!(f > 4.90f64); + assert!(f < 5.0f64); let g = 4.90000000001e-10f64; - assert!((g > 5e-11f64)); - assert!((g < 5e-9f64)); + assert!(g > 5e-11f64); + assert!(g < 5e-9f64); } diff --git a/tests/ui/simd/const-err-trumps-simd-err.stderr b/tests/ui/simd/const-err-trumps-simd-err.stderr index 11cbcad227ff8..19606aeb50189 100644 --- a/tests/ui/simd/const-err-trumps-simd-err.stderr +++ b/tests/ui/simd/const-err-trumps-simd-err.stderr @@ -1,8 +1,8 @@ error[E0080]: evaluation of `get_elem::<4>::{constant#0}` failed - --> $DIR/const-err-trumps-simd-err.rs:16:13 + --> $DIR/const-err-trumps-simd-err.rs:16:21 | LL | const { assert!(LANE < 4); } // the error should be here... - | ^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: LANE < 4', $DIR/const-err-trumps-simd-err.rs:16:13 + | ^^^^^^^^ the evaluated program panicked at 'assertion failed: LANE < 4', $DIR/const-err-trumps-simd-err.rs:16:13 | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/structs-enums/class-impl-very-parameterized-trait.rs b/tests/ui/structs-enums/class-impl-very-parameterized-trait.rs index 0b37192fc3b34..6caec1e2034ef 100644 --- a/tests/ui/structs-enums/class-impl-very-parameterized-trait.rs +++ b/tests/ui/structs-enums/class-impl-very-parameterized-trait.rs @@ -102,6 +102,6 @@ pub fn main() { let mut spotty: cat = cat::new(2, 57, cat_type::tuxedo); for _ in 0_usize..6 { spotty.speak(); } assert_eq!(spotty.len(), 8); - assert!((spotty.contains_key(&2))); + assert!(spotty.contains_key(&2)); assert_eq!(spotty.get(&3), &cat_type::tuxedo); } diff --git a/tests/ui/structs-enums/class-implement-trait-cross-crate.rs b/tests/ui/structs-enums/class-implement-trait-cross-crate.rs index 7a5969451cb52..781ac6ad10d2c 100644 --- a/tests/ui/structs-enums/class-implement-trait-cross-crate.rs +++ b/tests/ui/structs-enums/class-implement-trait-cross-crate.rs @@ -53,7 +53,7 @@ fn cat(in_x : usize, in_y : isize, in_name: String) -> cat { pub fn main() { let mut nyan = cat(0_usize, 2, "nyan".to_string()); nyan.eat(); - assert!((!nyan.eat())); + assert!(!nyan.eat()); for _ in 1_usize..10_usize { nyan.speak(); }; - assert!((nyan.eat())); + assert!(nyan.eat()); } diff --git a/tests/ui/structs-enums/class-implement-traits.rs b/tests/ui/structs-enums/class-implement-traits.rs index 04a7b706edbce..3a514ff9d7581 100644 --- a/tests/ui/structs-enums/class-implement-traits.rs +++ b/tests/ui/structs-enums/class-implement-traits.rs @@ -57,7 +57,7 @@ fn make_speak(mut c: C) { pub fn main() { let mut nyan = cat(0_usize, 2, "nyan".to_string()); nyan.eat(); - assert!((!nyan.eat())); + assert!(!nyan.eat()); for _ in 1_usize..10_usize { make_speak(nyan.clone()); } diff --git a/tests/ui/structs-enums/classes-cross-crate.rs b/tests/ui/structs-enums/classes-cross-crate.rs index 0160d3fd85c08..6fb5f2e3cc9d7 100644 --- a/tests/ui/structs-enums/classes-cross-crate.rs +++ b/tests/ui/structs-enums/classes-cross-crate.rs @@ -7,7 +7,7 @@ use cci_class_4::kitties::cat; pub fn main() { let mut nyan = cat(0_usize, 2, "nyan".to_string()); nyan.eat(); - assert!((!nyan.eat())); + assert!(!nyan.eat()); for _ in 1_usize..10_usize { nyan.speak(); }; - assert!((nyan.eat())); + assert!(nyan.eat()); } diff --git a/tests/ui/structs-enums/classes.rs b/tests/ui/structs-enums/classes.rs index d1c1922f4b547..05976f6a759af 100644 --- a/tests/ui/structs-enums/classes.rs +++ b/tests/ui/structs-enums/classes.rs @@ -45,7 +45,7 @@ fn cat(in_x : usize, in_y : isize, in_name: String) -> cat { pub fn main() { let mut nyan = cat(0_usize, 2, "nyan".to_string()); nyan.eat(); - assert!((!nyan.eat())); + assert!(!nyan.eat()); for _ in 1_usize..10_usize { nyan.speak(); }; - assert!((nyan.eat())); + assert!(nyan.eat()); } diff --git a/tests/ui/structs-enums/tag.rs b/tests/ui/structs-enums/tag.rs index 16e6b2341cf61..542b517e66db7 100644 --- a/tests/ui/structs-enums/tag.rs +++ b/tests/ui/structs-enums/tag.rs @@ -25,6 +25,6 @@ impl PartialEq for colour { fn ne(&self, other: &colour) -> bool { !(*self).eq(other) } } -fn f() { let x = colour::red(1, 2); let y = colour::green; assert!((x != y)); } +fn f() { let x = colour::red(1, 2); let y = colour::green; assert!(x != y); } pub fn main() { f(); } diff --git a/tests/ui/tag-type-args.rs b/tests/ui/tag-type-args.rs index 75a54927443f2..e3bc89b759c8a 100644 --- a/tests/ui/tag-type-args.rs +++ b/tests/ui/tag-type-args.rs @@ -1,6 +1,6 @@ enum Quux { Bar } //~^ ERROR: parameter `T` is never used -fn foo(c: Quux) { assert!((false)); } //~ ERROR missing generics for enum `Quux` +fn foo(c: Quux) { assert!(false); } //~ ERROR missing generics for enum `Quux` fn main() { panic!(); } diff --git a/tests/ui/tag-type-args.stderr b/tests/ui/tag-type-args.stderr index def13832e1ae0..b56b13de6b11c 100644 --- a/tests/ui/tag-type-args.stderr +++ b/tests/ui/tag-type-args.stderr @@ -10,7 +10,7 @@ LL | enum Quux { Bar } error[E0107]: missing generics for enum `Quux` --> $DIR/tag-type-args.rs:4:11 | -LL | fn foo(c: Quux) { assert!((false)); } +LL | fn foo(c: Quux) { assert!(false); } | ^^^^ expected 1 generic argument | note: enum defined here, with 1 generic parameter: `T` @@ -20,7 +20,7 @@ LL | enum Quux { Bar } | ^^^^ - help: add missing generic argument | -LL | fn foo(c: Quux) { assert!((false)); } +LL | fn foo(c: Quux) { assert!(false); } | +++ error: aborting due to 2 previous errors diff --git a/tests/ui/tail-cps.rs b/tests/ui/tail-cps.rs index 6305e9ecdbcf1..fe99dadf7951c 100644 --- a/tests/ui/tail-cps.rs +++ b/tests/ui/tail-cps.rs @@ -1,6 +1,6 @@ //@ run-pass -fn checktrue(rs: bool) -> bool { assert!((rs)); return true; } +fn checktrue(rs: bool) -> bool { assert!(rs); return true; } pub fn main() { let k = checktrue; evenk(42, k); oddk(45, k); } diff --git a/tests/ui/transmutability/uninhabited.stderr b/tests/ui/transmutability/uninhabited.stderr index b8b7b67f78160..619ab79de8b9b 100644 --- a/tests/ui/transmutability/uninhabited.stderr +++ b/tests/ui/transmutability/uninhabited.stderr @@ -1,24 +1,24 @@ error[E0080]: evaluation of constant value failed - --> $DIR/uninhabited.rs:41:9 + --> $DIR/uninhabited.rs:41:17 | LL | assert!(false); - | ^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: false', $DIR/uninhabited.rs:41:9 + | ^^^^^ the evaluated program panicked at 'assertion failed: false', $DIR/uninhabited.rs:41:9 | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0080]: evaluation of constant value failed - --> $DIR/uninhabited.rs:63:9 + --> $DIR/uninhabited.rs:63:17 | LL | assert!(false); - | ^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: false', $DIR/uninhabited.rs:63:9 + | ^^^^^ the evaluated program panicked at 'assertion failed: false', $DIR/uninhabited.rs:63:9 | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0080]: evaluation of constant value failed - --> $DIR/uninhabited.rs:87:9 + --> $DIR/uninhabited.rs:87:17 | LL | assert!(false); - | ^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: false', $DIR/uninhabited.rs:87:9 + | ^^^^^ the evaluated program panicked at 'assertion failed: false', $DIR/uninhabited.rs:87:9 | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/weird-exprs.rs b/tests/ui/weird-exprs.rs index 08b5517aae22f..55a8d580a8b7b 100644 --- a/tests/ui/weird-exprs.rs +++ b/tests/ui/weird-exprs.rs @@ -34,7 +34,7 @@ fn what() { let i = &Cell::new(false); let dont = {||the(i)}; dont(); - assert!((i.get())); + assert!(i.get()); } fn zombiejesus() { @@ -69,8 +69,8 @@ fn notsure() { fn canttouchthis() -> usize { fn p() -> bool { true } - let _a = (assert!((true)) == (assert!(p()))); - let _c = (assert!((p())) == ()); + let _a = (assert!(true) == (assert!(p()))); + let _c = (assert!(p()) == ()); let _b: bool = (println!("{}", 0) == (return 0)); }