提交 b53454e2 编写于 作者: A Alex Crichton

Move std::{reflect,repr,Poly} to a libdebug crate

This commit moves reflection (as well as the {:?} format modifier) to a new
libdebug crate, all of which is marked experimental.

This is a breaking change because it now requires the debug crate to be
explicitly linked if the :? format qualifier is used. This means that any code
using this feature will have to add `extern crate debug;` to the top of the
crate. Any code relying on reflection will also need to do this.

Closes #12019

[breaking-change]
上级 911cc9c3
......@@ -51,7 +51,7 @@
TARGET_CRATES := libc std green rustuv native flate arena glob term semver \
uuid serialize sync getopts collections num test time rand \
workcache url log regex graphviz core rlibc alloc
workcache url log regex graphviz core rlibc alloc debug
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros fmt_macros
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc
......@@ -59,16 +59,17 @@ TOOLS := compiletest rustdoc rustc
DEPS_core :=
DEPS_rlibc :=
DEPS_alloc := core libc native:jemalloc
DEPS_debug := std
DEPS_std := core libc alloc native:rustrt native:backtrace
DEPS_graphviz := std
DEPS_green := std rand native:context_switch
DEPS_rustuv := std native:uv native:uv_support
DEPS_native := std
DEPS_syntax := std term serialize collections log fmt_macros
DEPS_syntax := std term serialize collections log fmt_macros debug
DEPS_rustc := syntax native:rustllvm flate arena serialize sync getopts \
collections time log graphviz
collections time log graphviz debug
DEPS_rustdoc := rustc native:hoedown serialize sync getopts collections \
test time
test time debug
DEPS_flate := std native:miniz
DEPS_arena := std collections
DEPS_graphviz := std
......@@ -79,7 +80,7 @@ DEPS_semver := std
DEPS_uuid := std serialize rand
DEPS_sync := std alloc
DEPS_getopts := std
DEPS_collections := std rand
DEPS_collections := std rand debug
DEPS_fourcc := syntax std
DEPS_hexfloat := syntax std
DEPS_num := std rand
......
......@@ -254,7 +254,7 @@ for (x, y) in it {
}
// yield and print the last pair from the iterator
println!("last: {:?}", it.next());
println!("last: {}", it.next());
// the iterator is now fully consumed
assert!(it.next().is_none());
......@@ -349,9 +349,9 @@ returning another `DoubleEndedIterator` with `next` and `next_back` exchanged.
~~~
let xs = [1, 2, 3, 4, 5, 6];
let mut it = xs.iter();
println!("{:?}", it.next()); // prints `Some(&1)`
println!("{:?}", it.next()); // prints `Some(&2)`
println!("{:?}", it.next_back()); // prints `Some(&6)`
println!("{}", it.next()); // prints `Some(1)`
println!("{}", it.next()); // prints `Some(2)`
println!("{}", it.next_back()); // prints `Some(6)`
// prints `5`, `4` and `3`
for &x in it.rev() {
......@@ -367,7 +367,7 @@ let xs = [1, 2, 3, 4];
let ys = [5, 6, 7, 8];
let mut it = xs.iter().chain(ys.iter()).map(|&x| x * 2);
println!("{:?}", it.next()); // prints `Some(2)`
println!("{}", it.next()); // prints `Some(2)`
// prints `16`, `14`, `12`, `10`, `8`, `6`, `4`
for x in it.rev() {
......@@ -398,17 +398,17 @@ underlying iterators are.
let xs = [1, 2, 3, 4, 5];
let ys = ~[7, 9, 11];
let mut it = xs.iter().chain(ys.iter());
println!("{:?}", it.idx(0)); // prints `Some(&1)`
println!("{:?}", it.idx(5)); // prints `Some(&7)`
println!("{:?}", it.idx(7)); // prints `Some(&11)`
println!("{:?}", it.idx(8)); // prints `None`
println!("{}", it.idx(0)); // prints `Some(1)`
println!("{}", it.idx(5)); // prints `Some(7)`
println!("{}", it.idx(7)); // prints `Some(11)`
println!("{}", it.idx(8)); // prints `None`
// yield two elements from the beginning, and one from the end
it.next();
it.next();
it.next_back();
println!("{:?}", it.idx(0)); // prints `Some(&3)`
println!("{:?}", it.idx(4)); // prints `Some(&9)`
println!("{:?}", it.idx(6)); // prints `None`
println!("{}", it.idx(0)); // prints `Some(3)`
println!("{}", it.idx(4)); // prints `Some(9)`
println!("{}", it.idx(6)); // prints `None`
~~~
......@@ -102,6 +102,7 @@ you were writing this Rust code:
~~~rust
# fn transform(p: Point) -> Point { p }
#[deriving(Show)]
struct Point {
x: int,
y: int,
......@@ -110,7 +111,7 @@ struct Point {
fn main() {
let p0 = Point { x: 5, y: 10};
let p1 = transform(p0);
println!("{:?}", p1);
println!("{}", p1);
}
~~~
......@@ -134,6 +135,7 @@ let p1 = transform(&p0);
This does work, but you don't need to create those references! The better way to write this is simply:
~~~rust
#[deriving(Show)]
struct Point {
x: int,
y: int,
......@@ -146,7 +148,7 @@ fn transform(p: Point) -> Point {
fn main() {
let p0 = Point { x: 5, y: 10};
let p1 = transform(p0);
println!("{:?}", p1);
println!("{}", p1);
}
~~~
......@@ -182,7 +184,7 @@ trait. Therefore, unboxed traits don't make any sense, and aren't allowed.
Sometimes, you need a recursive data structure. The simplest is known as a 'cons list':
~~~rust
#[deriving(Show)]
enum List<T> {
Nil,
Cons(T, Box<List<T>>),
......@@ -190,7 +192,7 @@ enum List<T> {
fn main() {
let list: List<int> = Cons(1, box Cons(2, box Cons(3, box Nil)));
println!("{:?}", list);
println!("{}", list);
}
~~~
......@@ -349,7 +351,7 @@ fn main() {
let origin = @Point { x: 0.0, y: 0.0 };
let p1 = box Point { x: 5.0, y: 3.0 };
println!("{:?}", compute_distance(origin, p1));
println!("{}", compute_distance(origin, p1));
}
~~~
......@@ -385,11 +387,11 @@ fn main() {
let mut x = box 5;
if *x < 10 {
let y = &x;
println!("Oh no: {:?}", y);
println!("Oh no: {}", y);
return;
}
*x -= 1;
println!("Oh no: {:?}", x);
println!("Oh no: {}", x);
}
~~~
......@@ -404,11 +406,11 @@ fn main() {
let y = &x;
*x -= 1;
println!("Oh no: {:?}", y);
println!("Oh no: {}", y);
return;
}
*x -= 1;
println!("Oh no: {:?}", x);
println!("Oh no: {}", x);
}
~~~
......
......@@ -280,7 +280,7 @@ fn fib(n: u64) -> u64 {
let mut delayed_fib = sync::Future::spawn(proc() fib(50));
make_a_sandwich();
println!("fib(50) = {:?}", delayed_fib.get())
println!("fib(50) = {}", delayed_fib.get())
# }
~~~
......
......@@ -405,14 +405,20 @@ will often see in examples, and its related family of macros: `print!`,
that [printf][pf] has. Unlike printf, `format!` will give you a compile-time
error when the types of the directives don't match the types of the arguments.
~~~~
# let mystery_object = ();
~~~
// `{}` will print the "default format" of a type
println!("{} is {}", "the answer", 43);
~~~
// `{:?}` will conveniently print any type
~~~~
extern crate debug;
# fn main() {
# let mystery_object = ();
// `{:?}` will conveniently print any type,
// but requires the `debug` crate to be linked in
println!("what is this thing: {:?}", mystery_object);
# }
~~~~
[pf]: http://en.cppreference.com/w/cpp/io/c/fprintf
......@@ -698,8 +704,8 @@ When an enum has simple integer discriminators, you can apply the `as` cast
operator to convert a variant to its discriminator value as an `int`:
~~~~
# enum Direction { North }
println!( "{:?} => {}", North, North as int );
# #[deriving(Show)] enum Direction { North }
println!( "{} => {}", North, North as int );
~~~~
It is possible to set the discriminator values to chosen constant values:
......@@ -2228,7 +2234,7 @@ method.
~~~~
# trait Printable { fn print(&self); }
impl Printable for int {
fn print(&self) { println!("{:?}", *self) }
fn print(&self) { println!("{}", *self) }
}
impl Printable for String {
......@@ -2253,11 +2259,11 @@ types to be exactly as it is for `int`, above:
~~~~
# trait Printable { fn print(&self); }
impl Printable for f32 {
fn print(&self) { println!("{:?}", *self) }
fn print(&self) { println!("{}", *self) }
}
impl Printable for bool {
fn print(&self) { println!("{:?}", *self) }
fn print(&self) { println!("{}", *self) }
}
# true.print();
......@@ -2270,8 +2276,11 @@ definition of `print` right in the trait definition, instead of just
giving its signature. That is, we can write the following:
~~~~
extern crate debug;
# fn main() {
trait Printable {
// Default method implementation
// Default method implementation
fn print(&self) { println!("{:?}", *self) }
}
......@@ -2289,6 +2298,7 @@ impl Printable for f32 {}
# ("foo".to_string()).print();
# true.print();
# 3.14159.print();
# }
~~~~
Here, the impls of `Printable` for `int`, `bool`, and `f32` don't
......
......@@ -74,8 +74,10 @@
extern crate core;
extern crate libc;
// Allow testing this library
#[cfg(test)] extern crate debug;
#[cfg(test)] extern crate sync;
#[cfg(test)] extern crate native;
#[cfg(test)] #[phase(syntax, link)] extern crate std;
......
......@@ -25,6 +25,7 @@
#![deny(deprecated_owned_vector)]
extern crate rand;
extern crate debug;
#[cfg(test)] extern crate test;
#[cfg(test)] #[phase(syntax, link)] extern crate log;
......
......@@ -27,6 +27,7 @@
* demonstrates adding and subtracting two `Point`s.
*
* ```rust
* #[deriving(Show)]
* struct Point {
* x: int,
* y: int
......@@ -44,8 +45,8 @@
* }
* }
* fn main() {
* println!("{:?}", Point {x: 1, y: 0} + Point {x: 2, y: 3});
* println!("{:?}", Point {x: 1, y: 0} - Point {x: 2, y: 3});
* println!("{}", Point {x: 1, y: 0} + Point {x: 2, y: 3});
* println!("{}", Point {x: 1, y: 0} - Point {x: 2, y: 3});
* }
* ```
*
......
......@@ -419,7 +419,7 @@ pub trait ImmutableVector<'a, T> {
* ```rust
* let v = &[1,2,3,4];
* for win in v.windows(2) {
* println!("{:?}", win);
* println!("{}", win);
* }
* ```
*
......@@ -444,7 +444,7 @@ pub trait ImmutableVector<'a, T> {
* ```rust
* let v = &[1,2,3,4,5];
* for win in v.chunks(2) {
* println!("{:?}", win);
* println!("{}", win);
* }
* ```
*
......
// 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 <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.
//! Implementation of the `{:?}` format qualifier
//!
//! This module contains the `Poly` trait which is used to implement the `{:?}`
//! format expression in formatting macros. This trait is defined for all types
//! automatically, so it is likely not necessary to use this module manually
use std::fmt;
use repr;
/// Format trait for the `?` character
pub trait Poly {
/// Formats the value using the given formatter.
#[experimental]
fn fmt(&self, &mut fmt::Formatter) -> fmt::Result;
}
#[doc(hidden)]
pub fn secret_poly<T: Poly>(x: &T, fmt: &mut fmt::Formatter) -> fmt::Result {
// FIXME #11938 - UFCS would make us able call the this method
// directly Poly::fmt(x, fmt).
x.fmt(fmt)
}
impl<T> Poly for T {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match (f.width, f.precision) {
(None, None) => {
match repr::write_repr(f, self) {
Ok(()) => Ok(()),
Err(..) => Err(fmt::WriteError),
}
}
// If we have a specified width for formatting, then we have to make
// this allocation of a new string
_ => {
let s = repr::repr_to_str(self);
f.pad(s.as_slice())
}
}
}
}
// 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 <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.
//! Debugging utilities for Rust programs
//!
//! This crate is intended to provide useful functionality when debugging
//! programs, such as reflection for printing values. This crate is currently
//! entirely experimental as its makeup will likely change over time.
//! Additionally, it is not guaranteed that functionality such as reflection
//! will persist into the future.
#![crate_id = "debug#0.11.0-pre"]
#![license = "MIT/ASL2"]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")]
#![experimental]
#![feature(managed_boxes, macro_rules, quad_precision_float)]
#![allow(experimental)]
pub mod fmt;
pub mod reflect;
pub mod repr;
// 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.
/*!
Runtime type reflection
*/
#![allow(missing_doc)]
use std::intrinsics::{Disr, Opaque, TyDesc, TyVisitor};
use std::mem;
/**
* Trait for visitor that wishes to reflect on data.
*
* To use this, create a struct that encapsulates the set of pointers you wish
* to walk through a data structure, and implement both `MovePtr` for it as well
* as `TyVisitor`; then build a MovePtrAdaptor wrapped around your struct.
*/
pub trait MovePtr {
fn move_ptr(&mut self, adjustment: |*u8| -> *u8);
fn push_ptr(&mut self);
fn pop_ptr(&mut self);
}
/// Helper function for alignment calculation.
#[inline]
pub fn align(size: uint, align: uint) -> uint {
((size + align) - 1u) & !(align - 1u)
}
/// Adaptor to wrap around visitors implementing MovePtr.
pub struct MovePtrAdaptor<V> {
inner: V
}
pub fn MovePtrAdaptor<V:TyVisitor + MovePtr>(v: V) -> MovePtrAdaptor<V> {
MovePtrAdaptor { inner: v }
}
impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> {
#[inline]
pub fn bump(&mut self, sz: uint) {
self.inner.move_ptr(|p| ((p as uint) + sz) as *u8)
}
#[inline]
pub fn align(&mut self, a: uint) {
self.inner.move_ptr(|p| align(p as uint, a) as *u8)
}
#[inline]
pub fn align_to<T>(&mut self) {
self.align(mem::min_align_of::<T>());
}
#[inline]
pub fn bump_past<T>(&mut self) {
self.bump(mem::size_of::<T>());
}
pub fn unwrap(self) -> V { self.inner }
}
/// Abstract type-directed pointer-movement using the MovePtr trait
impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
fn visit_bot(&mut self) -> bool {
self.align_to::<()>();
if ! self.inner.visit_bot() { return false; }
self.bump_past::<()>();
true
}
fn visit_nil(&mut self) -> bool {
self.align_to::<()>();
if ! self.inner.visit_nil() { return false; }
self.bump_past::<()>();
true
}
fn visit_bool(&mut self) -> bool {
self.align_to::<bool>();
if ! self.inner.visit_bool() { return false; }
self.bump_past::<bool>();
true
}
fn visit_int(&mut self) -> bool {
self.align_to::<int>();
if ! self.inner.visit_int() { return false; }
self.bump_past::<int>();
true
}
fn visit_i8(&mut self) -> bool {
self.align_to::<i8>();
if ! self.inner.visit_i8() { return false; }
self.bump_past::<i8>();
true
}
fn visit_i16(&mut self) -> bool {
self.align_to::<i16>();
if ! self.inner.visit_i16() { return false; }
self.bump_past::<i16>();
true
}
fn visit_i32(&mut self) -> bool {
self.align_to::<i32>();
if ! self.inner.visit_i32() { return false; }
self.bump_past::<i32>();
true
}
fn visit_i64(&mut self) -> bool {
self.align_to::<i64>();
if ! self.inner.visit_i64() { return false; }
self.bump_past::<i64>();
true
}
fn visit_uint(&mut self) -> bool {
self.align_to::<uint>();
if ! self.inner.visit_uint() { return false; }
self.bump_past::<uint>();
true
}
fn visit_u8(&mut self) -> bool {
self.align_to::<u8>();
if ! self.inner.visit_u8() { return false; }
self.bump_past::<u8>();
true
}
fn visit_u16(&mut self) -> bool {
self.align_to::<u16>();
if ! self.inner.visit_u16() { return false; }
self.bump_past::<u16>();
true
}
fn visit_u32(&mut self) -> bool {
self.align_to::<u32>();
if ! self.inner.visit_u32() { return false; }
self.bump_past::<u32>();
true
}
fn visit_u64(&mut self) -> bool {
self.align_to::<u64>();
if ! self.inner.visit_u64() { return false; }
self.bump_past::<u64>();
true
}
fn visit_f32(&mut self) -> bool {
self.align_to::<f32>();
if ! self.inner.visit_f32() { return false; }
self.bump_past::<f32>();
true
}
fn visit_f64(&mut self) -> bool {
self.align_to::<f64>();
if ! self.inner.visit_f64() { return false; }
self.bump_past::<f64>();
true
}
fn visit_f128(&mut self) -> bool {
self.align_to::<f128>();
if ! self.inner.visit_f128() { return false; }
self.bump_past::<f128>();
true
}
fn visit_char(&mut self) -> bool {
self.align_to::<char>();
if ! self.inner.visit_char() { return false; }
self.bump_past::<char>();
true
}
fn visit_estr_box(&mut self) -> bool {
true
}
fn visit_estr_uniq(&mut self) -> bool {
self.align_to::<~str>();
if ! self.inner.visit_estr_uniq() { return false; }
self.bump_past::<~str>();
true
}
fn visit_estr_slice(&mut self) -> bool {
self.align_to::<&'static str>();
if ! self.inner.visit_estr_slice() { return false; }
self.bump_past::<&'static str>();
true
}
fn visit_estr_fixed(&mut self, n: uint,
sz: uint,
align: uint) -> bool {
self.align(align);
if ! self.inner.visit_estr_fixed(n, sz, align) { return false; }
self.bump(sz);
true
}
fn visit_box(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<@u8>();
if ! self.inner.visit_box(mtbl, inner) { return false; }
self.bump_past::<@u8>();
true
}
fn visit_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<Box<u8>>();
if ! self.inner.visit_uniq(mtbl, inner) { return false; }
self.bump_past::<Box<u8>>();
true
}
fn visit_ptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<*u8>();
if ! self.inner.visit_ptr(mtbl, inner) { return false; }
self.bump_past::<*u8>();
true
}
fn visit_rptr(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<&'static u8>();
if ! self.inner.visit_rptr(mtbl, inner) { return false; }
self.bump_past::<&'static u8>();
true
}
fn visit_evec_box(&mut self, _mtbl: uint, _inner: *TyDesc) -> bool {
true
}
fn visit_evec_uniq(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<~[u8]>();
if ! self.inner.visit_evec_uniq(mtbl, inner) { return false; }
self.bump_past::<~[u8]>();
true
}
fn visit_evec_slice(&mut self, mtbl: uint, inner: *TyDesc) -> bool {
self.align_to::<&'static [u8]>();
if ! self.inner.visit_evec_slice(mtbl, inner) { return false; }
self.bump_past::<&'static [u8]>();
true
}
fn visit_evec_fixed(&mut self, n: uint, sz: uint, align: uint,
mtbl: uint, inner: *TyDesc) -> bool {
self.align(align);
if ! self.inner.visit_evec_fixed(n, sz, align, mtbl, inner) {
return false;
}
self.bump(sz);
true
}
fn visit_enter_rec(&mut self, n_fields: uint, sz: uint, align: uint) -> bool {
self.align(align);
if ! self.inner.visit_enter_rec(n_fields, sz, align) { return false; }
true
}
fn visit_rec_field(&mut self, i: uint, name: &str,
mtbl: uint, inner: *TyDesc) -> bool {
unsafe { self.align((*inner).align); }
if ! self.inner.visit_rec_field(i, name, mtbl, inner) {
return false;
}
unsafe { self.bump((*inner).size); }
true
}
fn visit_leave_rec(&mut self, n_fields: uint, sz: uint, align: uint) -> bool {
if ! self.inner.visit_leave_rec(n_fields, sz, align) { return false; }
true
}
fn visit_enter_class(&mut self, name: &str, named_fields: bool, n_fields: uint, sz: uint,
align: uint) -> bool {
self.align(align);
if ! self.inner.visit_enter_class(name, named_fields, n_fields, sz, align) {
return false;
}
true
}
fn visit_class_field(&mut self, i: uint, name: &str, named: bool, mtbl: uint,
inner: *TyDesc) -> bool {
unsafe { self.align((*inner).align); }
if ! self.inner.visit_class_field(i, name, named, mtbl, inner) {
return false;
}
unsafe { self.bump((*inner).size); }
true
}
fn visit_leave_class(&mut self, name: &str, named_fields: bool, n_fields: uint, sz: uint,
align: uint) -> bool {
if ! self.inner.visit_leave_class(name, named_fields, n_fields, sz, align) {
return false;
}
true
}
fn visit_enter_tup(&mut self, n_fields: uint, sz: uint, align: uint) -> bool {
self.align(align);
if ! self.inner.visit_enter_tup(n_fields, sz, align) { return false; }
true
}
fn visit_tup_field(&mut self, i: uint, inner: *TyDesc) -> bool {
unsafe { self.align((*inner).align); }
if ! self.inner.visit_tup_field(i, inner) { return false; }
unsafe { self.bump((*inner).size); }
true
}
fn visit_leave_tup(&mut self, n_fields: uint, sz: uint, align: uint) -> bool {
if ! self.inner.visit_leave_tup(n_fields, sz, align) { return false; }
true
}
fn visit_enter_fn(&mut self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool {
if ! self.inner.visit_enter_fn(purity, proto, n_inputs, retstyle) {
return false
}
true
}
fn visit_fn_input(&mut self, i: uint, mode: uint, inner: *TyDesc) -> bool {
if ! self.inner.visit_fn_input(i, mode, inner) { return false; }
true
}
fn visit_fn_output(&mut self, retstyle: uint, variadic: bool, inner: *TyDesc) -> bool {
if ! self.inner.visit_fn_output(retstyle, variadic, inner) { return false; }
true
}
fn visit_leave_fn(&mut self, purity: uint, proto: uint,
n_inputs: uint, retstyle: uint) -> bool {
if ! self.inner.visit_leave_fn(purity, proto, n_inputs, retstyle) {
return false;
}
true
}
fn visit_enter_enum(&mut self, n_variants: uint,
get_disr: unsafe extern fn(ptr: *Opaque) -> Disr,
sz: uint, align: uint)
-> bool {
self.align(align);
if ! self.inner.visit_enter_enum(n_variants, get_disr, sz, align) {
return false;
}
true
}
fn visit_enter_enum_variant(&mut self, variant: uint,
disr_val: Disr,
n_fields: uint,
name: &str) -> bool {
if ! self.inner.visit_enter_enum_variant(variant, disr_val,
n_fields, name) {
return false;
}
true
}
fn visit_enum_variant_field(&mut self, i: uint, offset: uint, inner: *TyDesc) -> bool {
self.inner.push_ptr();
self.bump(offset);
if ! self.inner.visit_enum_variant_field(i, offset, inner) { return false; }
self.inner.pop_ptr();
true
}
fn visit_leave_enum_variant(&mut self, variant: uint,
disr_val: Disr,
n_fields: uint,
name: &str) -> bool {
if ! self.inner.visit_leave_enum_variant(variant, disr_val,
n_fields, name) {
return false;
}
true
}
fn visit_leave_enum(&mut self, n_variants: uint,
get_disr: unsafe extern fn(ptr: *Opaque) -> Disr,
sz: uint, align: uint) -> bool {
if ! self.inner.visit_leave_enum(n_variants, get_disr, sz, align) {
return false;
}
self.bump(sz);
true
}
fn visit_trait(&mut self, name: &str) -> bool {
self.align_to::<Box<TyVisitor>>();
if ! self.inner.visit_trait(name) { return false; }
self.bump_past::<Box<TyVisitor>>();
true
}
fn visit_param(&mut self, i: uint) -> bool {
if ! self.inner.visit_param(i) { return false; }
true
}
fn visit_self(&mut self) -> bool {
self.align_to::<&'static u8>();
if ! self.inner.visit_self() { return false; }
self.align_to::<&'static u8>();
true
}
}
此差异已折叠。
......@@ -89,6 +89,7 @@
#![deny(missing_doc)]
#![deny(deprecated_owned_vector)]
#[cfg(test)] extern crate debug;
#[cfg(test)] #[phase(syntax, link)] extern crate log;
use std::cmp::Eq;
......
......@@ -51,8 +51,8 @@ pub fn new(size: uint) -> Stack {
// page. It isn't guaranteed, but that's why FFI is unsafe. buf.data is
// guaranteed to be aligned properly.
if !protect_last_page(&stack) {
fail!("Could not memory-protect guard page. stack={:?}, errno={}",
stack, errno());
fail!("Could not memory-protect guard page. stack={}, errno={}",
stack.data, errno());
}
let mut stk = Stack {
......
......@@ -59,6 +59,7 @@
extern crate alloc;
extern crate libc;
#[cfg(test)] extern crate debug;
use std::os;
use std::rt;
......
......@@ -65,7 +65,7 @@
```rust
let tuple_ptr = rand::random::<Box<(f64, char)>>();
println!("{:?}", tuple_ptr)
println!("{}", tuple_ptr)
```
*/
......@@ -80,8 +80,8 @@
#![feature(macro_rules, managed_boxes, phase)]
#![deny(deprecated_owned_vector)]
#[cfg(test)]
#[phase(syntax, link)] extern crate log;
#[cfg(test)] extern crate debug;
#[cfg(test)] #[phase(syntax, link)] extern crate log;
use std::io::IoResult;
use std::kinds::marker;
......@@ -152,7 +152,7 @@ fn next_u64(&mut self) -> u64 {
///
/// let mut v = [0u8, .. 13579];
/// task_rng().fill_bytes(v);
/// println!("{:?}", v);
/// println!("{}", v.as_slice());
/// ```
fn fill_bytes(&mut self, dest: &mut [u8]) {
// this could, in theory, be done by transmuting dest to a
......@@ -188,7 +188,7 @@ fn fill_bytes(&mut self, dest: &mut [u8]) {
/// let mut rng = task_rng();
/// let x: uint = rng.gen();
/// println!("{}", x);
/// println!("{:?}", rng.gen::<(f64, bool)>());
/// println!("{}", rng.gen::<(f64, bool)>());
/// ```
#[inline(always)]
fn gen<T: Rand>(&mut self) -> T {
......
......@@ -31,16 +31,17 @@
#![feature(macro_rules, globs, struct_variant, managed_boxes, quote,
default_type_params, phase)]
extern crate flate;
extern crate arena;
extern crate collections;
extern crate debug;
extern crate flate;
extern crate getopts;
extern crate graphviz;
extern crate syntax;
extern crate libc;
extern crate serialize;
extern crate sync;
extern crate getopts;
extern crate collections;
extern crate syntax;
extern crate time;
extern crate libc;
#[phase(syntax, link)]
extern crate log;
......
......@@ -16,17 +16,18 @@
#![feature(globs, struct_variant, managed_boxes, macro_rules, phase)]
extern crate syntax;
extern crate collections;
extern crate debug;
extern crate getopts;
extern crate libc;
#[phase(syntax, link)]
extern crate log;
extern crate rustc;
extern crate serialize;
extern crate sync;
extern crate getopts;
extern crate collections;
extern crate syntax;
extern crate testing = "test";
extern crate time;
#[phase(syntax, link)]
extern crate log;
extern crate libc;
use std::io;
use std::io::{File, MemWriter};
......
......@@ -44,6 +44,7 @@
#![allow(visible_private_types)]
#[cfg(test)] extern crate green;
#[cfg(test)] extern crate debug;
#[cfg(test)] extern crate realrustuv = "rustuv";
extern crate libc;
extern crate alloc;
......
......@@ -44,6 +44,7 @@ pub struct TaggedDoc<'a> {
pub doc: Doc<'a>,
}
#[deriving(Show)]
pub enum EbmlEncoderTag {
EsUint, // 0
EsU64, // 1
......@@ -323,7 +324,7 @@ fn _check_label(&mut self, lbl: &str) -> DecodeResult<()> {
}
fn next_doc(&mut self, exp_tag: EbmlEncoderTag) -> DecodeResult<Doc<'doc>> {
debug!(". next_doc(exp_tag={:?})", exp_tag);
debug!(". next_doc(exp_tag={})", exp_tag);
if self.pos >= self.parent.end {
return Err(Expected(format_strbuf!("no more documents in \
current node!")));
......@@ -339,8 +340,8 @@ fn next_doc(&mut self, exp_tag: EbmlEncoderTag) -> DecodeResult<Doc<'doc>> {
r_doc.end);
if r_tag != (exp_tag as uint) {
return Err(Expected(format_strbuf!("expected EBML doc with \
tag {:?} but found tag \
{:?}",
tag {} but found tag \
{}",
exp_tag,
r_tag)));
}
......@@ -370,7 +371,7 @@ fn push_doc<T>(&mut self, exp_tag: EbmlEncoderTag,
fn _next_uint(&mut self, exp_tag: EbmlEncoderTag) -> DecodeResult<uint> {
let r = doc_as_u32(try!(self.next_doc(exp_tag)));
debug!("_next_uint exp_tag={:?} result={}", exp_tag, r);
debug!("_next_uint exp_tag={} result={}", exp_tag, r);
Ok(r as uint)
}
......@@ -1085,7 +1086,7 @@ fn test_vuint_at() {
#[test]
fn test_option_int() {
fn test_v(v: Option<int>) {
debug!("v == {:?}", v);
debug!("v == {}", v);
let mut wr = MemWriter::new();
{
let mut ebml_w = writer::Encoder(&mut wr);
......@@ -1094,7 +1095,7 @@ fn test_v(v: Option<int>) {
let ebml_doc = reader::Doc(wr.get_ref());
let mut deser = reader::Decoder(ebml_doc);
let v1 = Decodable::decode(&mut deser).unwrap();
debug!("v1 == {:?}", v1);
debug!("v1 == {}", v1);
assert_eq!(v, v1);
}
......
......@@ -95,7 +95,7 @@ impl<'a> FromHex for &'a str {
* let hello_str = "Hello, World".as_bytes().to_hex();
* println!("{}", hello_str);
* let bytes = hello_str.as_slice().from_hex().unwrap();
* println!("{:?}", bytes);
* println!("{}", bytes);
* let result_str = String::from_utf8(bytes).unwrap();
* println!("{}", result_str);
* }
......
......@@ -1906,7 +1906,7 @@ fn read_enum_variant<T>(&mut self,
names: &[&str],
f: |&mut Decoder, uint| -> DecodeResult<T>)
-> DecodeResult<T> {
debug!("read_enum_variant(names={:?})", names);
debug!("read_enum_variant(names={})", names);
let name = match self.pop() {
String(s) => s,
Object(mut o) => {
......@@ -1961,7 +1961,7 @@ fn read_enum_struct_variant<T>(&mut self,
names: &[&str],
f: |&mut Decoder, uint| -> DecodeResult<T>)
-> DecodeResult<T> {
debug!("read_enum_struct_variant(names={:?})", names);
debug!("read_enum_struct_variant(names={})", names);
self.read_enum_variant(names, f)
}
......@@ -3013,7 +3013,7 @@ fn test_encode_hashmap_with_numeric_key() {
let bytes = mem_buf.unwrap();
let json_str = from_utf8(bytes.as_slice()).unwrap();
match from_str(json_str) {
Err(_) => fail!("Unable to parse json_str: {:?}", json_str),
Err(_) => fail!("Unable to parse json_str: {}", json_str),
_ => {} // it parsed and we are good to go
}
}
......@@ -3033,7 +3033,7 @@ fn test_prettyencode_hashmap_with_numeric_key() {
let bytes = mem_buf.unwrap();
let json_str = from_utf8(bytes.as_slice()).unwrap();
match from_str(json_str) {
Err(_) => fail!("Unable to parse json_str: {:?}", json_str),
Err(_) => fail!("Unable to parse json_str: {}", json_str),
_ => {} // it parsed and we are good to go
}
}
......@@ -3043,7 +3043,7 @@ fn test_hashmap_with_numeric_key_can_handle_double_quote_delimited_key() {
use Decodable;
let json_str = "{\"1\":true}";
let json_obj = match from_str(json_str) {
Err(_) => fail!("Unable to parse json_str: {:?}", json_str),
Err(_) => fail!("Unable to parse json_str: {}", json_str),
Ok(o) => o
};
let mut decoder = Decoder::new(json_obj);
......
......@@ -34,12 +34,15 @@
Some examples of the `format!` extension are:
```rust
format!("Hello"); // => "Hello".to_string()
format!("Hello, {:s}!", "world"); // => "Hello, world!".to_string()
format!("The number is {:d}", 1); // => "The number is 1".to_string()
format!("{:?}", ~[3, 4]); // => "~[3, 4]".to_string()
format!("{value}", value=4); // => "4".to_string()
format!("{} {}", 1, 2); // => "1 2".to_string()
# extern crate debug;
# fn main() {
format!("Hello"); // => "Hello"
format!("Hello, {:s}!", "world"); // => "Hello, world!"
format!("The number is {:d}", 1); // => "The number is 1"
format!("{:?}", (3, 4)); // => "(3, 4)"
format!("{value}", value=4); // => "4"
format!("{} {}", 1, 2); // => "1 2"
# }
```
From these, you can see that the first argument is a format string. It is
......@@ -62,7 +65,7 @@
iterator advances. This leads to behavior like this:
```rust
format!("{1} {} {0} {}", 1, 2); // => "2 1 1 2".to_string()
format!("{1} {} {0} {}", 1, 2); // => "2 1 1 2"
```
The internal iterator over the argument has not been advanced by the time the
......@@ -89,9 +92,12 @@
For example, the following `format!` expressions all use named argument:
```rust
format!("{argument}", argument = "test"); // => "test".to_string()
format!("{name} {}", 1, name = 2); // => "2 1".to_string()
format!("{a:s} {c:d} {b:?}", a="a", b=(), c=3); // => "a 3 ()".to_string()
# extern crate debug;
# fn main() {
format!("{argument}", argument = "test"); // => "test"
format!("{name} {}", 1, name = 2); // => "2 1"
format!("{a:s} {c:d} {b:?}", a="a", b=(), c=3); // => "a 3 ()"
# }
```
It is illegal to put positional parameters (those without names) after arguments
......@@ -101,18 +107,15 @@
### Argument types
Each argument's type is dictated by the format string. It is a requirement that
every argument is only ever referred to by one type. When specifying the format
of an argument, however, a string like `{}` indicates no type. This is allowed,
and if all references to one argument do not provide a type, then the format `?`
is used (the type's rust-representation is printed). For example, this is an
every argument is only ever referred to by one type. For example, this is an
invalid format string:
```notrust
{0:d} {0:s}
```
Because the first argument is both referred to as an integer as well as a
string.
This is invalid because the first argument is both referred to as an integer as
well as a string.
Because formatting is done via traits, there is no requirement that the
`d` format actually takes an `int`, but rather it simply requires a type which
......@@ -134,7 +137,7 @@
multiple actual types to be formatted via `{:d}` (like `i8` as well as `int`).
The current mapping of types to traits is:
* `?` ⇒ `Poly`
* *nothing* ⇒ `Show`
* `d` ⇒ `Signed`
* `i` ⇒ `Signed`
* `u` ⇒ `Unsigned`
......@@ -149,7 +152,11 @@
* `f` ⇒ `Float`
* `e` ⇒ `LowerExp`
* `E` ⇒ `UpperExp`
* *nothing* ⇒ `Show`
* `?` ⇒ `Poly`
> **Note**: The `Poly` formatting trait is provided by [libdebug](../../debug/)
> and is an experimental implementation that should not be relied upon. In order
> to use the `?` modifier, the libdebug crate must be linked against.
What this means is that any type of argument which implements the
`std::fmt::Binary` trait can then be formatted with `{:t}`. Implementations are
......@@ -330,7 +337,7 @@ fn my_fmt_fn(args: &fmt::Arguments) {
example:
```rust
format!("{0, select, other{#}}", "hello"); // => "hello".to_string()
format!("{0, select, other{#}}", "hello"); // => "hello"
```
This example is the equivalent of `{0:s}` essentially.
......@@ -485,7 +492,9 @@ fn my_fmt_fn(args: &fmt::Arguments) {
use io::Writer;
use io;
#[cfg(stage0)]
use option::None;
#[cfg(stage0)]
use repr;
use result::{Ok, Err};
use str::{Str, StrAllocating};
......@@ -516,6 +525,7 @@ fn my_fmt_fn(args: &fmt::Arguments) {
pub use core::fmt::{secret_pointer};
#[doc(hidden)]
#[cfg(stage0)]
pub fn secret_poly<T: Poly>(x: &T, fmt: &mut Formatter) -> Result {
// FIXME #11938 - UFCS would make us able call the this method
// directly Poly::fmt(x, fmt).
......@@ -523,6 +533,7 @@ pub fn secret_poly<T: Poly>(x: &T, fmt: &mut Formatter) -> Result {
}
/// Format trait for the `?` character
#[cfg(stage0)]
pub trait Poly {
/// Formats the value using the given formatter.
fn fmt(&self, &mut Formatter) -> Result;
......@@ -558,6 +569,7 @@ pub fn format_strbuf(args: &Arguments) -> string::String {
str::from_utf8(output.unwrap().as_slice()).unwrap().into_string()
}
#[cfg(stage0)]
impl<T> Poly for T {
fn fmt(&self, f: &mut Formatter) -> Result {
match (f.width, f.precision) {
......
......@@ -117,6 +117,7 @@
#[cfg(test)] extern crate rustuv;
#[cfg(test)] extern crate native;
#[cfg(test)] extern crate green;
#[cfg(test)] extern crate debug;
#[cfg(test)] #[phase(syntax, link)] extern crate log;
// Make and rand accessible for benchmarking/testcases
......
......@@ -773,30 +773,30 @@ fn format_arg(&self, sp: Span, argno: Position, arg: @ast::Expr)
Named(ref s) => self.name_types.get(s)
};
let fmt_fn = match *ty {
let (krate, fmt_fn) = match *ty {
Known(ref tyname) => {
match tyname.as_slice() {
"" => "secret_show",
"?" => "secret_poly",
"b" => "secret_bool",
"c" => "secret_char",
"d" | "i" => "secret_signed",
"e" => "secret_lower_exp",
"E" => "secret_upper_exp",
"f" => "secret_float",
"o" => "secret_octal",
"p" => "secret_pointer",
"s" => "secret_string",
"t" => "secret_binary",
"u" => "secret_unsigned",
"x" => "secret_lower_hex",
"X" => "secret_upper_hex",
"" => ("std", "secret_show"),
"?" => ("debug", "secret_poly"),
"b" => ("std", "secret_bool"),
"c" => ("std", "secret_char"),
"d" | "i" => ("std", "secret_signed"),
"e" => ("std", "secret_lower_exp"),
"E" => ("std", "secret_upper_exp"),
"f" => ("std", "secret_float"),
"o" => ("std", "secret_octal"),
"p" => ("std", "secret_pointer"),
"s" => ("std", "secret_string"),
"t" => ("std", "secret_binary"),
"u" => ("std", "secret_unsigned"),
"x" => ("std", "secret_lower_hex"),
"X" => ("std", "secret_upper_hex"),
_ => {
self.ecx
.span_err(sp,
format!("unknown format trait `{}`",
*tyname).as_slice());
"dummy"
("std", "dummy")
}
}
}
......@@ -815,7 +815,7 @@ fn format_arg(&self, sp: Span, argno: Position, arg: @ast::Expr)
};
let format_fn = self.ecx.path_global(sp, vec!(
self.ecx.ident_of("std"),
self.ecx.ident_of(krate),
self.ecx.ident_of("fmt"),
self.ecx.ident_of(fmt_fn)));
self.ecx.expr_call_global(sp, vec!(
......
......@@ -36,6 +36,7 @@
#[phase(syntax, link)]
extern crate log;
extern crate fmt_macros;
extern crate debug;
pub mod util {
pub mod interner;
......
......@@ -21,7 +21,9 @@
#![feature(phase)]
#![deny(deprecated_owned_vector)]
#[cfg(test)] extern crate debug;
#[cfg(test)] #[phase(syntax, link)] extern crate log;
extern crate serialize;
extern crate libc;
#[cfg(target_os = "macos")]
......
......@@ -412,8 +412,7 @@ fn exec_work<'a, T:Send +
&'a self, blk: proc(&mut Exec):Send -> T) -> Work<'a, T> {
let mut bo = Some(blk);
debug!("exec_work: looking up {} and {:?}", self.fn_name,
self.declared_inputs);
debug!("exec_work: looking up {}", self.fn_name);
let cached = {
let db = self.ctxt.db.deref().read();
db.deref().prepare(self.fn_name, &self.declared_inputs)
......@@ -425,8 +424,7 @@ fn exec_work<'a, T:Send +
self.all_fresh("discovered input", disc_in) &&
self.all_fresh("discovered output", disc_out) => {
debug!("Cache hit!");
debug!("Trying to decode: {:?} / {:?} / {}",
disc_in, disc_out, *res);
debug!("Trying to decode: {}", *res);
Work::from_value(json_decode(res.as_slice()))
}
......
......@@ -11,6 +11,8 @@
// Make sure Rust generates the correct calling convention for extern
// functions.
extern crate debug;
#[inline(never)]
#[cfg(target_arch = "x86_64")]
pub extern "win64" fn foo(a: int, b: int, c: int, d: int) {
......
......@@ -10,6 +10,7 @@
#![feature(phase)]
#[phase(syntax, link)] extern crate log;
extern crate debug;
pub fn foo<T>() {
fn death() -> int { fail!() }
......
......@@ -19,6 +19,7 @@
// version.
extern crate time;
extern crate debug;
use std::comm;
use std::os;
......
......@@ -15,6 +15,7 @@
// I *think* it's the same, more or less.
extern crate time;
extern crate debug;
use std::os;
use std::task;
......
......@@ -12,6 +12,7 @@
extern crate collections;
extern crate time;
extern crate debug;
use collections::SmallIntMap;
use std::os;
......
......@@ -10,6 +10,8 @@
#![feature(managed_boxes)]
extern crate debug;
struct clam {
x: @int,
y: @int,
......
......@@ -11,6 +11,8 @@
// Make sure that fn-to-block coercion isn't incorrectly lifted over
// other tycons.
extern crate debug;
fn coerce(b: ||) -> extern fn() {
fn lol(f: extern fn(v: ||) -> extern fn(),
g: ||) -> extern fn() { return f(g); }
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
struct defer<'a> {
x: &'a [&'a str],
}
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn foo(x: int) { println!("{:?}", x); }
fn main() {
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn main() {
let f: || -> int = || {
let i: int;
......
......@@ -10,6 +10,8 @@
// Test that we do not permit moves from &[] matched by a vec pattern.
extern crate debug;
#[deriving(Clone)]
struct Foo {
string: String
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn main() {
let x: int = 3;
let y: &mut int = &mut x; //~ ERROR cannot borrow
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
struct foo {
i: int,
}
......
......@@ -10,6 +10,8 @@
// error-pattern:mismatched types: expected `()` but found `bool`
extern crate debug;
fn main() {
let a = if true { true };
println!("{:?}", a);
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn main() {
println!("{:?}", x); //~ ERROR unresolved name `x`.
}
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
struct C {
x: int,
}
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
enum f { g(int, int) }
enum h { i(j, k) }
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn main() {
let foo = 100;
......
......@@ -8,4 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn main() { format!("{:?}", None); } //~ ERROR unconstrained type
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn main() {
format!("{:?}", None); //~ ERROR: cannot determine a type for this bounded
}
......@@ -8,5 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn force(f: || -> int) -> int { f() }
fn main() { println!("{:?}", force(|| {})); } //~ ERROR mismatched types
......@@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn main() {
let y: Box<int> = box 42;
......
......@@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn main() {
let y: Box<int> = box 42;
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn main() {
let x = box 5;
let y = x;
......
......@@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn send<T:Send>(ch: _chan<T>, data: T) {
println!("{:?}", ch);
......
......@@ -11,6 +11,8 @@
// a good test that we merge paths correctly in the presence of a
// variable that's used before it's declared
extern crate debug;
fn my_fail() -> ! { fail!(); }
fn main() {
......
......@@ -11,6 +11,8 @@
// Tests that if you move from `x.f` or `x[0]`, `x` is inaccessible.
// Also tests that we give a more specific error message.
extern crate debug;
struct Foo { f: String, y: int }
fn consume(_s: String) {}
fn touch<A>(_a: &A) {}
......
......@@ -12,6 +12,8 @@
// bound must be noncopyable. For details see
// http://smallcultfollowing.com/babysteps/blog/2013/04/30/the-case-of-the-recurring-closure/
extern crate debug;
struct R<'a> {
// This struct is needed to create the
// otherwise infinite type of a fn that
......
......@@ -10,6 +10,8 @@
#![feature(managed_boxes)]
extern crate debug;
use std::task;
struct Port<T>(@T);
......
......@@ -10,6 +10,9 @@
// Test that a class with a non-copyable field can't be
// copied
extern crate debug;
struct bar {
x: int,
}
......
......@@ -10,6 +10,8 @@
// error-pattern:non-scalar cast
extern crate debug;
struct foo {
x:int
}
......
......@@ -15,6 +15,8 @@
// error-pattern: transmute called on types with different size
extern crate debug;
use std::mem;
#[packed]
......
......@@ -15,6 +15,8 @@
// error-pattern: transmute called on types with different size
extern crate debug;
use std::mem;
#[packed]
......
......@@ -10,6 +10,8 @@
// error-pattern: mismatched types
extern crate debug;
enum bar { t1((), Option<Vec<int> >), t2, }
fn foo(t: bar) {
......
......@@ -10,6 +10,8 @@
#![feature(managed_boxes)]
extern crate debug;
use std::cell::Cell;
struct r {
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
struct r {
b: bool,
}
......
......@@ -10,6 +10,7 @@
#![feature(managed_boxes)]
extern crate debug;
use std::cell::Cell;
struct r {
......
......@@ -110,6 +110,6 @@ fn main() {
'\u205F', '\u3000'];
for c in chars.iter() {
let ws = c.is_whitespace();
println!("{:?} {:?}" , c , ws);
println!("{} {}" , c , ws);
}
}
......@@ -104,6 +104,6 @@ fn main() {
'\u2028', '\u2029', '\u202F', '\u205F', '\u3000'];
for c in chars.iter() {
let ws = c.is_whitespace();
println!("{:?} {:?}", c , ws);
println!("{} {}", c , ws);
}
}
......
......@@ -10,6 +10,8 @@
// error-pattern:called `Result::unwrap()` on an `Err` value
extern crate debug;
use std::result;
fn main() {
......
......@@ -12,6 +12,8 @@
// error-pattern:fail
extern crate debug;
fn failfn() {
fail!();
}
......
......@@ -12,6 +12,8 @@
#![feature(managed_boxes)]
extern crate debug;
use std::mem;
fn failfn() {
......
......@@ -12,6 +12,8 @@
#![feature(managed_boxes)]
extern crate debug;
fn failfn() {
fail!();
}
......
......@@ -12,6 +12,7 @@
#![feature(managed_boxes)]
extern crate debug;
fn failfn() {
fail!();
......
......@@ -12,6 +12,8 @@
#![feature(managed_boxes)]
extern crate debug;
fn failfn() {
fail!();
}
......
......@@ -12,6 +12,8 @@
#![feature(managed_boxes)]
extern crate debug;
fn failfn() {
fail!();
}
......
......@@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
struct pair<A,B> {
a: A, b: B
......
......@@ -8,9 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
struct Pair<T, U> { a: T, b: U }
struct Triple { x: int, y: int, z: int }
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn inty(fun: proc(int) -> int) -> int {
fun(100)
}
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn iter_vec<T>(v: Vec<T> , f: |&T|) { for x in v.iter() { f(x); } }
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn iter_vec<T>(v: Vec<T> , f: |&T|) { for x in v.iter() { f(x); } }
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
use std::mem::swap;
struct Ints {sum: Box<int>, values: Vec<int> }
......
......@@ -12,6 +12,7 @@
// storing closure data (as we used to do), the u64 would
// overwrite the u16.
extern crate debug;
struct Pair<A,B> {
a: A, b: B
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
use std::task;
pub fn main() {
......
......@@ -14,6 +14,7 @@
#![feature(phase)]
#[phase(syntax, link)]
extern crate log;
extern crate debug;
pub fn main() {
// only fails if println! evaluates its argument.
......
......@@ -10,6 +10,8 @@
// exec-env:RUST_LOG=conditional-debug-macro-on=4
extern crate debug;
pub fn main() {
// exits early if println! evaluates its arguments, otherwise it
// will hit the fail.
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
static x : [int, ..4] = [1,2,3,4];
static p : int = x[2];
static y : &'static [int] = &[1,2,3,4];
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
static x : [int, ..4] = [1,2,3,4];
static y : &'static [int] = &[1,2,3,4];
......
......@@ -10,6 +10,8 @@
#![feature(managed_boxes)]
extern crate debug;
use std::cell::Cell;
pub fn main() {
......
......@@ -10,6 +10,8 @@
#![feature(macro_rules)]
extern crate debug;
macro_rules! check {
($m:ident, $t:ty, $v:expr) => {{
mod $m {
......
......@@ -10,6 +10,8 @@
#![allow(dead_assignment)]
extern crate debug;
pub fn main() {
let x : &[int] = &[1,2,3,4,5];
let mut z = &[1,2,3,4,5];
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
pub fn main() {
let pi = 3.1415927;
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
use std::cell::RefCell;
pub fn main() {
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
struct Foo {
x: int,
y: int
......
......@@ -10,6 +10,8 @@
#![feature(managed_boxes)]
extern crate debug;
fn id<T>(t: T) -> T { return t; }
pub fn main() {
......
......@@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn id<T:Send>(t: T) -> T { return t; }
......
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn g<X>(x: X) -> X { return x; }
......
......@@ -10,6 +10,8 @@
#![feature(managed_boxes)]
extern crate debug;
fn f<T>(x: @T) -> @T { return x; }
pub fn main() { let x = f(@3); println!("{:?}", *x); }
......@@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn f<T>(x: Box<T>) -> Box<T> { return x; }
......
......@@ -8,8 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
enum noption<T> { some(T), }
......
......@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate debug;
fn get_third<T>(t: (T, T, T)) -> T { let (_, _, x) = t; return x; }
pub fn main() {
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册