From f2fc9209d05f4e6f59c289635af2d107e40a51f5 Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Sun, 5 Jul 2015 06:40:49 -0400 Subject: [PATCH 1/9] liblibc: correct Linux ioctl request type --- src/liblibc/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 6e01796ad8227..a67372a63adb6 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -6121,7 +6121,7 @@ pub mod funcs { use types::os::arch::c95::{c_char, c_uchar, c_int, c_uint, c_ulong, size_t}; extern { - pub fn ioctl(d: c_int, request: c_ulong, ...) -> c_int; + pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int; pub fn sysctl(name: *mut c_int, namelen: c_uint, oldp: *mut c_void, @@ -6153,12 +6153,12 @@ pub mod funcs { #[cfg(any(target_os = "linux", target_os = "android"))] pub mod bsd44 { use types::common::c95::{c_void}; - use types::os::arch::c95::{c_uchar, c_int, size_t}; + use types::os::arch::c95::{c_uchar, c_int, c_ulong, size_t}; extern { #[cfg(not(all(target_os = "android", target_arch = "aarch64")))] pub fn getdtablesize() -> c_int; - pub fn ioctl(d: c_int, request: c_int, ...) -> c_int; + pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int; pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int; pub fn mincore(addr: *mut c_void, len: size_t, vec: *mut c_uchar) From 0e714c19839412474ef7b7741a19f942c4327645 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sun, 5 Jul 2015 22:41:23 +0300 Subject: [PATCH 2/9] rustc_trans: always use normalizing_infer_ctxt. --- src/librustc_trans/trans/_match.rs | 2 +- src/librustc_trans/trans/common.rs | 2 +- src/test/run-pass/issue-26805.rs | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 src/test/run-pass/issue-26805.rs diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs index c2397ec31cffa..936b0070dfccf 100644 --- a/src/librustc_trans/trans/_match.rs +++ b/src/librustc_trans/trans/_match.rs @@ -1351,7 +1351,7 @@ fn is_discr_reassigned(bcx: Block, discr: &ast::Expr, body: &ast::Expr) -> bool reassigned: false }; { - let infcx = infer::new_infer_ctxt(bcx.tcx(), &bcx.tcx().tables, None, false); + let infcx = infer::normalizing_infer_ctxt(bcx.tcx(), &bcx.tcx().tables); let mut visitor = euv::ExprUseVisitor::new(&mut rc, &infcx); visitor.walk_expr(body); } diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index e1c1ac9a772eb..a4559708bf4e8 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -936,7 +936,7 @@ pub fn normalize_and_test_predicates<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, predicates); let tcx = ccx.tcx(); - let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, true); + let infcx = infer::normalizing_infer_ctxt(tcx, &tcx.tables); let mut selcx = traits::SelectionContext::new(&infcx); let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut(); let cause = traits::ObligationCause::dummy(); diff --git a/src/test/run-pass/issue-26805.rs b/src/test/run-pass/issue-26805.rs new file mode 100644 index 0000000000000..c996c8f65ac8b --- /dev/null +++ b/src/test/run-pass/issue-26805.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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. + +struct NonOrd; + +fn main() { + let _: Box> = Box::new(vec![NonOrd].into_iter()); +} From 8cb1faaa907395d9bcf81919d7e94f3b7560dccf Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 6 Jul 2015 12:14:49 -0400 Subject: [PATCH 3/9] Link to test suite information from CONTRIBUTING.md Fixes #24802 --- CONTRIBUTING.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0bcb3219858c9..7bf144c713315 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -108,6 +108,10 @@ will run all the tests on every platform we support. If it all works out, [merge-queue]: http://buildbot.rust-lang.org/homu/queue/rust +Speaking of tests, Rust has a comprehensive test suite. More information about +it can be found +[here](https://github.com/rust-lang/rust-wiki-backup/blob/master/Note-testsuite.md). + ## Writing Documentation Documentation improvements are very welcome. The source of `doc.rust-lang.org` From fb6eeb6ce8980c23daec0361e61dfe406f535eb5 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 6 Jul 2015 12:27:32 -0400 Subject: [PATCH 4/9] Document _ in bindings Fixes #25786 --- src/doc/trpl/patterns.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/doc/trpl/patterns.md b/src/doc/trpl/patterns.md index 7a1f8bf21bf34..9603eec7aca71 100644 --- a/src/doc/trpl/patterns.md +++ b/src/doc/trpl/patterns.md @@ -282,6 +282,38 @@ This ‘destructuring’ behavior works on any compound data type, like [tuples]: primitive-types.html#tuples [enums]: enums.html +# Ignoring bindings + +You can use `_` in a pattern to disregard the value. For example, here’s a +`match` against a `Result`: + +```rust +# let some_value: Result = Err("There was an error"); +match some_value { + Ok(value) => println!("got a value: {}", value), + Err(_) => println!("an error occurred"), +} +``` + +In the first arm, we bind the value inside the `Ok` variant to `value`. But +in the `Err` arm, we use `_` to disregard the specific error, and just print +a general error message. + +`_` is valid in any pattern that creates a binding. This can be useful to +ignore parts of a larger structure: + +```rust +fn coordinate() -> (i32, i32, i32) { + // generate and return some sort of triple tuple +# (1, 2, 3) +} + +let (x, _, z) = coordinate(); +``` + +Here, we bind the first and last element of the tuple to `x` and `z`, but +ignore the middle element. + # Mix and Match Whew! That’s a lot of different ways to match things, and they can all be From ee43c5e2f0d838de2721b8c5a30aa25d882398d9 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Fri, 3 Jul 2015 12:56:51 -0400 Subject: [PATCH 5/9] FFI panic is UB I incorrectly stated that it's an abort. --- src/doc/trpl/ffi.md | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/doc/trpl/ffi.md b/src/doc/trpl/ffi.md index 442a1f062ef47..cbedf86371414 100644 --- a/src/doc/trpl/ffi.md +++ b/src/doc/trpl/ffi.md @@ -533,19 +533,10 @@ attribute turns off Rust's name mangling, so that it is easier to link to. # FFI and panics -It’s important to be mindful of `panic!`s when working with FFI. This code, -when called from C, will `abort`: - -```rust -#[no_mangle] -pub extern fn oh_no() -> ! { - panic!("Oops!"); -} -# fn main() {} -``` - -If you’re writing code that may panic, you should run it in another thread, -so that the panic doesn’t bubble up to C: +It’s important to be mindful of `panic!`s when working with FFI. A `panic!` +across an FFI boundary is undefined behavior. If you’re writing code that may +panic, you should run it in another thread, so that the panic doesn’t bubble up +to C: ```rust use std::thread; From c2f4f11443ba9e8eb0b69f245bcfc7eb985082fa Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 6 Jul 2015 22:01:20 +0200 Subject: [PATCH 6/9] reference: do not display the extra space --- src/doc/reference.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index a3e13acccae28..c5bffd0f0db44 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2876,7 +2876,6 @@ operand. ``` # let mut x = 0; # let y = 0; - x = y; ``` From dd78ffe828ac1ea09949bc9c5bc07082088ceba4 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 6 Jul 2015 22:10:21 +0200 Subject: [PATCH 7/9] reference: make 'Move and copied types' section more simple --- src/doc/reference.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index a3e13acccae28..199a0894b6ec9 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2509,9 +2509,8 @@ Here are some examples: #### Moved and copied types When a [local variable](#variables) is used as an -[rvalue](#lvalues,-rvalues-and-temporaries) the variable will either be moved -or copied, depending on its type. All values whose type implements `Copy` are -copied, all others are moved. +[rvalue](#lvalues,-rvalues-and-temporaries), the variable will be copied +if its type implements `Copy`. All others are moved. ### Literal expressions From 720da310a92242290df5623bf3d5e2ea5f83e7f8 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 6 Jul 2015 14:46:21 -0400 Subject: [PATCH 8/9] Add note about special make targets --- CONTRIBUTING.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0bcb3219858c9..a2ac20deb2e5f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -83,6 +83,21 @@ feature. We use the 'fork and pull' model described there. Please make pull requests against the `master` branch. +Compiling all of `make check` can take a while. When testing your pull request, +consider using one of the more specialized `make` targets to cut down on the +amount of time you have to wait. You need to have built the compiler at least +once before running these will work, but that’s only one full build rather than +one each time. + + $ make -j8 rustc-stage1 && make check-stage1 + +is one such example, which builds just `rustc`, and then runs the tests. If +you’re adding something to the standard library, try + + $ make -j8 check-stage1-std NO_REBUILD=1 + +This will not rebuild the compiler, but will run the tests. + All pull requests are reviewed by another person. We have a bot, @rust-highfive, that will automatically assign a random person to review your request. From 3a6cd649b4d82c564bdd7699441aeb4d49058dc9 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Mon, 6 Jul 2015 13:39:03 -0400 Subject: [PATCH 9/9] Significantly improve formatter trait docs Each formatting trait now has an example of implementation, as well as a fuller description of what it's supposed to output. It also contains a link to the module-level documentation which Fixes #25765 --- src/libcore/fmt/mod.rs | 311 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 300 insertions(+), 11 deletions(-) diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index f735ed7b78b17..0bb519ec09519 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -267,11 +267,16 @@ impl<'a> Display for Arguments<'a> { } } -/// Format trait for the `?` character. Useful for debugging, all types -/// should implement this. +/// Format trait for the `?` character. +/// +/// `Debug` should format the output in a programmer-facing, debugging context. /// /// Generally speaking, you should just `derive` a `Debug` implementation. /// +/// For more information on formatters, see [the module-level documentation][module]. +/// +/// [module]: ../index.html +/// /// # Examples /// /// Deriving an implementation: @@ -327,8 +332,39 @@ pub trait Debug { fn fmt(&self, &mut Formatter) -> Result; } -/// When a value can be semantically expressed as a String, this trait may be -/// used. It corresponds to the default format, `{}`. +/// Format trait for an empty format, `{}`. +/// +/// `Display` is similar to [`Debug`][debug], but `Display` is for user-facing +/// output, and so cannot be derived. +/// +/// [debug]: trait.Debug.html +/// +/// For more information on formatters, see [the module-level documentation][module]. +/// +/// [module]: ../index.html +/// +/// # Examples +/// +/// Implementing `Display` on a type: +/// +/// ``` +/// use std::fmt; +/// +/// struct Point { +/// x: i32, +/// y: i32, +/// } +/// +/// impl fmt::Display for Point { +/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +/// write!(f, "({}, {})", self.x, self.y) +/// } +/// } +/// +/// let origin = Point { x: 0, y: 0 }; +/// +/// println!("The origin is: {}", origin); +/// ``` #[rustc_on_unimplemented = "`{Self}` cannot be formatted with the default \ formatter; try using `:?` instead if you are using \ a format string"] @@ -339,7 +375,43 @@ pub trait Display { fn fmt(&self, &mut Formatter) -> Result; } -/// Format trait for the `o` character +/// Format trait for the `o` character. +/// +/// The `Octal` trait should format its output as a number in base-8. +/// +/// For more information on formatters, see [the module-level documentation][module]. +/// +/// [module]: ../index.html +/// +/// # Examples +/// +/// Basic usage with `i32`: +/// +/// ``` +/// let x = 42; // 42 is '52' in octal +/// +/// assert_eq!(format!("{:o}", x), "52"); +/// ``` +/// +/// Implementing `Octal` on a type: +/// +/// ``` +/// use std::fmt; +/// +/// struct Length(i32); +/// +/// impl fmt::Octal for Length { +/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +/// let val = self.0; +/// +/// write!(f, "{:o}", val) // delegate to i32's implementation +/// } +/// } +/// +/// let l = Length(9); +/// +/// println!("l as octal is: {:o}", l); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait Octal { /// Formats the value using the given formatter. @@ -347,7 +419,43 @@ pub trait Octal { fn fmt(&self, &mut Formatter) -> Result; } -/// Format trait for the `b` character +/// Format trait for the `b` character. +/// +/// The `Binary` trait should format its output as a number in binary. +/// +/// For more information on formatters, see [the module-level documentation][module]. +/// +/// [module]: ../index.html +/// +/// # Examples +/// +/// Basic usage with `i32`: +/// +/// ``` +/// let x = 42; // 42 is '101010' in binary +/// +/// assert_eq!(format!("{:b}", x), "101010"); +/// ``` +/// +/// Implementing `Binary` on a type: +/// +/// ``` +/// use std::fmt; +/// +/// struct Length(i32); +/// +/// impl fmt::Binary for Length { +/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +/// let val = self.0; +/// +/// write!(f, "{:b}", val) // delegate to i32's implementation +/// } +/// } +/// +/// let l = Length(107); +/// +/// println!("l as binary is: {:b}", l); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait Binary { /// Formats the value using the given formatter. @@ -355,7 +463,44 @@ pub trait Binary { fn fmt(&self, &mut Formatter) -> Result; } -/// Format trait for the `x` character +/// Format trait for the `x` character. +/// +/// The `LowerHex` trait should format its output as a number in hexidecimal, with `a` through `f` +/// in lower case. +/// +/// For more information on formatters, see [the module-level documentation][module]. +/// +/// [module]: ../index.html +/// +/// # Examples +/// +/// Basic usage with `i32`: +/// +/// ``` +/// let x = 42; // 42 is '2a' in hex +/// +/// assert_eq!(format!("{:x}", x), "2a"); +/// ``` +/// +/// Implementing `LowerHex` on a type: +/// +/// ``` +/// use std::fmt; +/// +/// struct Length(i32); +/// +/// impl fmt::LowerHex for Length { +/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +/// let val = self.0; +/// +/// write!(f, "{:x}", val) // delegate to i32's implementation +/// } +/// } +/// +/// let l = Length(9); +/// +/// println!("l as hex is: {:x}", l); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait LowerHex { /// Formats the value using the given formatter. @@ -363,7 +508,44 @@ pub trait LowerHex { fn fmt(&self, &mut Formatter) -> Result; } -/// Format trait for the `X` character +/// Format trait for the `X` character. +/// +/// The `UpperHex` trait should format its output as a number in hexidecimal, with `A` through `F` +/// in upper case. +/// +/// For more information on formatters, see [the module-level documentation][module]. +/// +/// [module]: ../index.html +/// +/// # Examples +/// +/// Basic usage with `i32`: +/// +/// ``` +/// let x = 42; // 42 is '2A' in hex +/// +/// assert_eq!(format!("{:X}", x), "2A"); +/// ``` +/// +/// Implementing `UpperHex` on a type: +/// +/// ``` +/// use std::fmt; +/// +/// struct Length(i32); +/// +/// impl fmt::UpperHex for Length { +/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +/// let val = self.0; +/// +/// write!(f, "{:X}", val) // delegate to i32's implementation +/// } +/// } +/// +/// let l = Length(9); +/// +/// println!("l as hex is: {:X}", l); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait UpperHex { /// Formats the value using the given formatter. @@ -371,7 +553,44 @@ pub trait UpperHex { fn fmt(&self, &mut Formatter) -> Result; } -/// Format trait for the `p` character +/// Format trait for the `p` character. +/// +/// The `Pointer` trait should format its output as a memory location. This is commonly presented +/// as hexidecimal. +/// +/// For more information on formatters, see [the module-level documentation][module]. +/// +/// [module]: ../index.html +/// +/// # Examples +/// +/// Basic usage with `&i32`: +/// +/// ``` +/// let x = &42; +/// +/// let address = format!("{:p}", x); // this produces something like '0x7f06092ac6d0' +/// ``` +/// +/// Implementing `Pointer` on a type: +/// +/// ``` +/// use std::fmt; +/// +/// struct Length(i32); +/// +/// impl fmt::Pointer for Length { +/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +/// // use `as` to convert to a `*const T`, which implements Pointer, which we can use +/// +/// write!(f, "{:p}", self as *const Length) +/// } +/// } +/// +/// let l = Length(42); +/// +/// println!("l is in memory here: {:p}", l); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait Pointer { /// Formats the value using the given formatter. @@ -379,7 +598,42 @@ pub trait Pointer { fn fmt(&self, &mut Formatter) -> Result; } -/// Format trait for the `e` character +/// Format trait for the `e` character. +/// +/// The `LowerExp` trait should format its output in scientific notation with a lower-case `e`. +/// +/// For more information on formatters, see [the module-level documentation][module]. +/// +/// [module]: ../index.html +/// +/// # Examples +/// +/// Basic usage with `i32`: +/// +/// ``` +/// let x = 42.0; // 42.0 is '4.2e1' in scientific notation +/// +/// assert_eq!(format!("{:e}", x), "4.2e1"); +/// ``` +/// +/// Implementing `LowerExp` on a type: +/// +/// ``` +/// use std::fmt; +/// +/// struct Length(i32); +/// +/// impl fmt::LowerExp for Length { +/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +/// let val = self.0; +/// write!(f, "{}e1", val / 10) +/// } +/// } +/// +/// let l = Length(100); +/// +/// println!("l in scientific notation is: {:e}", l); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait LowerExp { /// Formats the value using the given formatter. @@ -387,7 +641,42 @@ pub trait LowerExp { fn fmt(&self, &mut Formatter) -> Result; } -/// Format trait for the `E` character +/// Format trait for the `E` character. +/// +/// The `UpperExp` trait should format its output in scientific notation with an upper-case `E`. +/// +/// For more information on formatters, see [the module-level documentation][module]. +/// +/// [module]: ../index.html +/// +/// # Examples +/// +/// Basic usage with `f32`: +/// +/// ``` +/// let x = 42.0; // 42.0 is '4.2E1' in scientific notation +/// +/// assert_eq!(format!("{:E}", x), "4.2E1"); +/// ``` +/// +/// Implementing `UpperExp` on a type: +/// +/// ``` +/// use std::fmt; +/// +/// struct Length(i32); +/// +/// impl fmt::UpperExp for Length { +/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +/// let val = self.0; +/// write!(f, "{}E1", val / 10) +/// } +/// } +/// +/// let l = Length(100); +/// +/// println!("l in scientific notation is: {:E}", l); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait UpperExp { /// Formats the value using the given formatter.