From d6466ff13aef6af45f24f28e23f2f3dd36c96cf0 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 24 Mar 2015 15:36:59 -0400 Subject: Driveby cleanup of the impl for negation, which had some kind of surprising casts. This version more obviously corresponds to the builtin semantics. --- src/libcore/ops.rs | 24 ++---------------------- src/test/compile-fail/issue-13352.rs | 28 ++++++++++++++++++++++++++++ src/test/run-pass/issue-13352.rs | 26 -------------------------- 3 files changed, 30 insertions(+), 48 deletions(-) create mode 100644 src/test/compile-fail/issue-13352.rs delete mode 100644 src/test/run-pass/issue-13352.rs (limited to 'src') diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 26deb80d8c5..862eb16d0bf 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -485,6 +485,7 @@ pub trait Neg { macro_rules! neg_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] + #[allow(unsigned_negation)] impl Neg for $t { #[stable(feature = "rust1", since = "1.0.0")] type Output = $t; @@ -498,28 +499,7 @@ macro_rules! neg_impl { )*) } -macro_rules! neg_uint_impl { - ($t:ty, $t_signed:ty) => { - #[stable(feature = "rust1", since = "1.0.0")] - impl Neg for $t { - type Output = $t; - - #[inline] - fn neg(self) -> $t { -(self as $t_signed) as $t } - } - - forward_ref_unop! { impl Neg, neg for $t } - } -} - -neg_impl! { isize i8 i16 i32 i64 f32 f64 } - -neg_uint_impl! { usize, isize } -neg_uint_impl! { u8, i8 } -neg_uint_impl! { u16, i16 } -neg_uint_impl! { u32, i32 } -neg_uint_impl! { u64, i64 } - +neg_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// The `Not` trait is used to specify the functionality of unary `!`. /// diff --git a/src/test/compile-fail/issue-13352.rs b/src/test/compile-fail/issue-13352.rs new file mode 100644 index 00000000000..a8c8c8b40c1 --- /dev/null +++ b/src/test/compile-fail/issue-13352.rs @@ -0,0 +1,28 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// pretty-expanded FIXME #23616 + +#![feature(std_misc, libc)] + +extern crate libc; + +use std::thunk::Thunk; + +fn foo(_: Thunk) {} + +fn main() { + foo(loop { + unsafe { libc::exit(0 as libc::c_int); } + }); + 2_usize + (loop {}); + //~^ ERROR E0277 + //~| ERROR E0277 +} diff --git a/src/test/run-pass/issue-13352.rs b/src/test/run-pass/issue-13352.rs deleted file mode 100644 index af31fee048c..00000000000 --- a/src/test/run-pass/issue-13352.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2014 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// pretty-expanded FIXME #23616 - -#![feature(std_misc, libc)] - -extern crate libc; - -use std::thunk::Thunk; - -fn foo(_: Thunk) {} - -fn main() { - foo(loop { - unsafe { libc::exit(0 as libc::c_int); } - }); - 2_usize + (loop {}); -} -- cgit 1.4.1-3-g733a5