2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2011-06-24 16:19:58 -05:00
|
|
|
// Binop corner cases
|
|
|
|
|
2014-04-17 04:20:37 -05:00
|
|
|
#![feature(managed_boxes)]
|
|
|
|
|
2014-06-11 21:33:52 -05:00
|
|
|
use std::gc::GC;
|
|
|
|
|
2011-06-24 16:19:58 -05:00
|
|
|
fn test_nil() {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!((), ());
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!((!(() != ())));
|
|
|
|
assert!((!(() < ())));
|
|
|
|
assert!((() <= ()));
|
|
|
|
assert!((!(() > ())));
|
|
|
|
assert!((() >= ()));
|
2011-06-24 16:19:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_bool() {
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!((!(true < false)));
|
|
|
|
assert!((!(true <= false)));
|
|
|
|
assert!((true > false));
|
|
|
|
assert!((true >= false));
|
2011-07-27 07:19:39 -05:00
|
|
|
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!((false < true));
|
|
|
|
assert!((false <= true));
|
|
|
|
assert!((!(false > true)));
|
|
|
|
assert!((!(false >= true)));
|
2011-07-27 07:19:39 -05:00
|
|
|
|
|
|
|
// Bools support bitwise binops
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(false & false, false);
|
|
|
|
assert_eq!(true & false, false);
|
|
|
|
assert_eq!(true & true, true);
|
|
|
|
assert_eq!(false | false, false);
|
|
|
|
assert_eq!(true | false, true);
|
|
|
|
assert_eq!(true | true, true);
|
|
|
|
assert_eq!(false ^ false, false);
|
|
|
|
assert_eq!(true ^ false, true);
|
|
|
|
assert_eq!(true ^ true, false);
|
2011-06-24 16:19:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_box() {
|
2014-04-21 16:58:52 -05:00
|
|
|
assert_eq!(box(GC) 10i, box(GC) 10i);
|
2011-06-24 16:19:58 -05:00
|
|
|
}
|
|
|
|
|
2013-01-23 13:43:58 -06:00
|
|
|
fn test_ptr() {
|
|
|
|
unsafe {
|
2014-04-21 16:58:52 -05:00
|
|
|
let p1: *u8 = ::std::mem::transmute(0u);
|
|
|
|
let p2: *u8 = ::std::mem::transmute(0u);
|
|
|
|
let p3: *u8 = ::std::mem::transmute(1u);
|
2012-02-05 18:50:54 -06:00
|
|
|
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(p1, p2);
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(p1 != p3);
|
|
|
|
assert!(p1 < p3);
|
|
|
|
assert!(p1 <= p3);
|
|
|
|
assert!(p3 > p1);
|
|
|
|
assert!(p3 >= p3);
|
|
|
|
assert!(p1 <= p2);
|
|
|
|
assert!(p1 >= p2);
|
2013-01-23 13:43:58 -06:00
|
|
|
}
|
2011-06-24 16:19:58 -05:00
|
|
|
}
|
|
|
|
|
2014-05-29 19:45:07 -05:00
|
|
|
#[deriving(PartialEq, Show)]
|
2012-08-15 20:46:55 -05:00
|
|
|
struct p {
|
2013-02-22 18:08:16 -06:00
|
|
|
x: int,
|
|
|
|
y: int,
|
2012-09-05 17:58:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn p(x: int, y: int) -> p {
|
|
|
|
p {
|
|
|
|
x: x,
|
|
|
|
y: y
|
|
|
|
}
|
2012-06-25 14:20:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_class() {
|
2013-08-17 10:37:42 -05:00
|
|
|
let q = p(1, 2);
|
2013-02-22 18:08:16 -06:00
|
|
|
let mut r = p(1, 2);
|
2013-05-03 18:25:04 -05:00
|
|
|
|
2012-06-25 14:20:10 -05:00
|
|
|
unsafe {
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
println!("q = {:x}, r = {:x}",
|
core: Remove the cast module
This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.
* transmute - This function was moved to `mem`, but it is now marked as
#[unstable]. This is due to planned changes to the `transmute`
function and how it can be invoked (see the #[unstable] comment).
For more information, see RFC 5 and #12898
* transmute_copy - This function was moved to `mem`, with clarification that is
is not an error to invoke it with T/U that are different
sizes, but rather that it is strongly discouraged. This
function is now #[stable]
* forget - This function was moved to `mem` and marked #[stable]
* bump_box_refcount - This function was removed due to the deprecation of
managed boxes as well as its questionable utility.
* transmute_mut - This function was previously deprecated, and removed as part
of this commit.
* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
can be achieved with an `as` in safe code, so it was
removed.
* transmute_lifetime - This function was removed because it is likely a strong
indication that code is incorrect in the first place.
* transmute_mut_lifetime - This function was removed for the same reasons as
`transmute_lifetime`
* copy_lifetime - This function was moved to `mem`, but it is marked
`#[unstable]` now due to the likelihood of being removed in
the future if it is found to not be very useful.
* copy_mut_lifetime - This function was also moved to `mem`, but had the same
treatment as `copy_lifetime`.
* copy_lifetime_vec - This function was removed because it is not used today,
and its existence is not necessary with DST
(copy_lifetime will suffice).
In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.
transmute - #[unstable]
transmute_copy - #[stable]
forget - #[stable]
copy_lifetime - #[unstable]
copy_mut_lifetime - #[unstable]
[breaking-change]
2014-05-09 12:34:51 -05:00
|
|
|
(::std::mem::transmute::<*p, uint>(&q)),
|
|
|
|
(::std::mem::transmute::<*p, uint>(&r)));
|
2012-06-25 14:20:10 -05:00
|
|
|
}
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(q, r);
|
2012-06-25 14:20:10 -05:00
|
|
|
r.y = 17;
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!((r.y != q.y));
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(r.y, 17);
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!((q != r));
|
2012-06-25 14:20:10 -05:00
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2011-07-27 07:19:39 -05:00
|
|
|
test_nil();
|
|
|
|
test_bool();
|
|
|
|
test_box();
|
|
|
|
test_ptr();
|
2012-06-25 21:28:27 -05:00
|
|
|
test_class();
|
2011-08-09 18:28:10 -05:00
|
|
|
}
|