Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure that the assert! macro doesn't ICE on non-booleans #31604

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ macro_rules! panic {
#[stable(feature = "rust1", since = "1.0.0")]
macro_rules! assert {
($cond:expr) => (
if !$cond {
panic!(concat!("assertion failed: ", stringify!($cond)))
}
assert!($cond, concat!("assertion failed: ", stringify!($cond)))
);
($cond:expr, $($arg:tt)+) => (
if !$cond {
($cond:expr, $($arg:tt)+) => ({
let cond: bool = $cond;
if !cond {
panic!($($arg)+)
}
);
});
}

/// Asserts that two expressions are equal to each other.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let m: ModuleRef = llvm::LLVMGetGlobalParent(fn_);
let p = "llvm.trap\0".as_ptr();
let t: ValueRef = llvm::LLVMGetNamedFunction(m, p as *const _);
assert!((t as isize != 0));
assert!(t as isize != 0);
let args: &[ValueRef] = &[];
self.count_insn("trap");
llvm::LLVMRustBuildCall(self.llbuilder, t,
Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax/print/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,12 @@ impl<'a> Printer<'a> {
} else {
self.top += 1;
self.top %= self.buf_len;
assert!((self.top != self.bottom));
assert!(self.top != self.bottom);
}
self.scan_stack[self.top] = x;
}
pub fn scan_pop(&mut self) -> usize {
assert!((!self.scan_stack_empty));
assert!(!self.scan_stack_empty);
let x = self.scan_stack[self.top];
if self.top == self.bottom {
self.scan_stack_empty = true;
Expand All @@ -428,11 +428,11 @@ impl<'a> Printer<'a> {
return x;
}
pub fn scan_top(&mut self) -> usize {
assert!((!self.scan_stack_empty));
assert!(!self.scan_stack_empty);
return self.scan_stack[self.top];
}
pub fn scan_pop_bottom(&mut self) -> usize {
assert!((!self.scan_stack_empty));
assert!(!self.scan_stack_empty);
let x = self.scan_stack[self.bottom];
if self.top == self.bottom {
self.scan_stack_empty = true;
Expand All @@ -444,7 +444,7 @@ impl<'a> Printer<'a> {
pub fn advance_right(&mut self) {
self.right += 1;
self.right %= self.buf_len;
assert!((self.right != self.left));
assert!(self.right != self.left);
}
pub fn advance_left(&mut self) -> io::Result<()> {
debug!("advance_left Vec<{},{}>, sizeof({})={}", self.left, self.right,
Expand Down Expand Up @@ -566,7 +566,7 @@ impl<'a> Printer<'a> {
Token::End => {
debug!("print End -> pop End");
let print_stack = &mut self.print_stack;
assert!((!print_stack.is_empty()));
assert!(!print_stack.is_empty());
print_stack.pop().unwrap();
Ok(())
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/compile-fail/assert_non_bool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
assert!(Ok(1)); //~ ERROR: mismatched types
assert!(true);
assert!(false);
}
11 changes: 1 addition & 10 deletions src/test/compile-fail/issue-14091-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern: cannot apply unary operator `!` to type `BytePos`

// Very

// sensitive
pub struct BytePos(pub u32);

// to particular

// line numberings / offsets

fn main() {
let x = BytePos(1);

assert!(x, x);
assert!(x, x); //~ ERROR: mismatched types
}
6 changes: 1 addition & 5 deletions src/test/compile-fail/issue-28308.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// this error is dispayed in `<std macros>`
// error-pattern:cannot apply unary operator `!` to type `&'static str`
// error-pattern:in this expansion of assert!

fn main() {
assert!("foo");
assert!("foo"); //~ERROR: mismatched types
}