Skip to content

Rollup of 6 pull requests #31523

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

Merged
merged 13 commits into from
Feb 10, 2016
Merged
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
91 changes: 45 additions & 46 deletions src/doc/book/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ fn map<F, T, A>(option: Option<T>, f: F) -> Option<A> where F: FnOnce(T) -> A {
```

Indeed, `map` is [defined as a method][2] on `Option<T>` in the standard library.
As a method, it has a slighly different signature: methods take `self`, `&self`,
As a method, it has a slightly different signature: methods take `self`, `&self`,
or `&mut self` as their first argument.

Armed with our new combinator, we can rewrite our `extension_explicit` method
Expand Down Expand Up @@ -1592,7 +1592,7 @@ fn print_usage(program: &str, opts: Options) {

fn main() {
let args: Vec<String> = env::args().collect();
let program = args[0].clone();
let program = &args[0];

let mut opts = Options::new();
opts.optflag("h", "help", "Show this usage message.");
Expand All @@ -1605,10 +1605,10 @@ fn main() {
print_usage(&program, opts);
return;
}
let data_path = args[1].clone();
let city = args[2].clone();
let data_path = &args[1];
let city = &args[2];

// Do stuff with information
// Do stuff with information
}
```

Expand Down Expand Up @@ -1640,7 +1640,6 @@ sure to add `extern crate csv;` to the top of your file.)

```rust,ignore
use std::fs::File;
use std::path::Path;

// This struct represents the data in each row of the CSV file.
// Type based decoding absolves us of a lot of the nitty gritty error
Expand All @@ -1666,7 +1665,7 @@ fn print_usage(program: &str, opts: Options) {

fn main() {
let args: Vec<String> = env::args().collect();
let program = args[0].clone();
let program = &args[0];

let mut opts = Options::new();
opts.optflag("h", "help", "Show this usage message.");
Expand All @@ -1678,25 +1677,24 @@ fn main() {

if matches.opt_present("h") {
print_usage(&program, opts);
return;
}
return;
}

let data_file = args[1].clone();
let data_path = Path::new(&data_file);
let city = args[2].clone();
let data_path = &args[1];
let city: &str = &args[2];

let file = File::open(data_path).unwrap();
let mut rdr = csv::Reader::from_reader(file);
let file = File::open(data_path).unwrap();
let mut rdr = csv::Reader::from_reader(file);

for row in rdr.decode::<Row>() {
let row = row.unwrap();
for row in rdr.decode::<Row>() {
let row = row.unwrap();

if row.city == city {
println!("{}, {}: {:?}",
row.city, row.country,
row.population.expect("population count"));
}
}
if row.city == city {
println!("{}, {}: {:?}",
row.city, row.country,
row.population.expect("population count"));
}
}
}
```

Expand Down Expand Up @@ -1745,6 +1743,8 @@ Note that we opt to handle the possibility of a missing population count by
simply ignoring that row.

```rust,ignore
use std::path::Path;

struct Row {
// unchanged
}
Expand Down Expand Up @@ -1782,27 +1782,26 @@ fn search<P: AsRef<Path>>(file_path: P, city: &str) -> Vec<PopulationCount> {
}

fn main() {
let args: Vec<String> = env::args().collect();
let program = args[0].clone();
let args: Vec<String> = env::args().collect();
let program = &args[0];

let mut opts = Options::new();
opts.optflag("h", "help", "Show this usage message.");
let mut opts = Options::new();
opts.optflag("h", "help", "Show this usage message.");

let matches = match opts.parse(&args[1..]) {
Ok(m) => { m }
Err(e) => { panic!(e.to_string()) }
};
if matches.opt_present("h") {
print_usage(&program, opts);
return;
}
let matches = match opts.parse(&args[1..]) {
Ok(m) => { m }
Err(e) => { panic!(e.to_string()) }
};
if matches.opt_present("h") {
print_usage(&program, opts);
return;
}

let data_file = args[1].clone();
let data_path = Path::new(&data_file);
let city = args[2].clone();
for pop in search(&data_path, &city) {
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
}
let data_path = &args[1];
let city = &args[2];
for pop in search(data_path, city) {
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
}
}

```
Expand Down Expand Up @@ -1912,7 +1911,7 @@ First, here's the new usage:

```rust,ignore
fn print_usage(program: &str, opts: Options) {
println!("{}", opts.usage(&format!("Usage: {} [options] <city>", program)));
println!("{}", opts.usage(&format!("Usage: {} [options] <city>", program)));
}
```
The next part is going to be only a little harder:
Expand All @@ -1924,16 +1923,16 @@ opts.optopt("f", "file", "Choose an input file, instead of using STDIN.", "NAME"
opts.optflag("h", "help", "Show this usage message.");
...
let file = matches.opt_str("f");
let data_file = file.as_ref().map(Path::new);
let data_file = &file.as_ref().map(Path::new);

let city = if !matches.free.is_empty() {
matches.free[0].clone()
&matches.free[0]
} else {
print_usage(&program, opts);
return;
print_usage(&program, opts);
return;
};

match search(&data_file, &city) {
match search(data_file, city) {
Ok(pops) => {
for pop in pops {
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
Expand Down
2 changes: 1 addition & 1 deletion src/libbacktrace/ansidecl.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* ANSI and traditional C compatability macros
/* ANSI and traditional C compatibility macros
Copyright (C) 1991-2015 Free Software Foundation, Inc.
This file is part of the GNU C Library.

Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// }
// ```
//
// Since Rust doesn't acutally have dependent types and polymorphic recursion,
// Since Rust doesn't actually have dependent types and polymorphic recursion,
// we make do with lots of unsafety.

use alloc::heap;
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,7 @@ impl str {
// Σ maps to σ, except at the end of a word where it maps to ς.
// This is the only conditional (contextual) but language-independent mapping
// in `SpecialCasing.txt`,
// so hard-code it rather than have a generic "condition" mechanim.
// so hard-code it rather than have a generic "condition" mechanism.
// See https://github.com/rust-lang/rust/issues/26035
map_uppercase_sigma(self, i, &mut s)
} else {
Expand Down
8 changes: 7 additions & 1 deletion src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ use boxed::Box;
/// mem::forget(story);
///
/// // We can re-build a String out of ptr, len, and capacity. This is all
/// // unsafe becuase we are responsible for making sure the components are
/// // unsafe because we are responsible for making sure the components are
/// // valid:
/// let s = unsafe { String::from_raw_parts(ptr as *mut _, len, capacity) } ;
///
Expand Down Expand Up @@ -1842,6 +1842,12 @@ impl fmt::Write for String {
}

/// A draining iterator for `String`.
///
/// This struct is created by the [`drain()`] method on [`String`]. See its
/// documentation for more.
///
/// [`drain()`]: struct.String.html#method.drain
/// [`String`]: struct.String.html
#[stable(feature = "drain", since = "1.6.0")]
pub struct Drain<'a> {
/// Will be used as &'a mut String in the destructor
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//!
//! - Impl the `As*` traits for reference-to-reference conversions
//! - Impl the `Into` trait when you want to consume the value in the conversion
//! - The `From` trait is the most flexible, usefull for values _and_ references conversions
//! - The `From` trait is the most flexible, useful for values _and_ references conversions
//!
//! As a library writer, you should prefer implementing `From<T>` rather than
//! `Into<U>`, as `From` provides greater flexibility and offer the equivalent `Into`
Expand Down
7 changes: 7 additions & 0 deletions src/libcore/num/dec2flt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ from_str_float_impl!(f32);
from_str_float_impl!(f64);

/// An error which can be returned when parsing a float.
///
/// This error is used as the error type for the [`FromStr`] implementation
/// for [`f32`] and [`f64`].
///
/// [`FromStr`]: ../str/trait.FromStr.html
/// [`f32`]: ../primitive.f32.html
/// [`f64`]: ../primitive.f64.html
#[derive(Debug, Clone, PartialEq)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct ParseFloatError {
Expand Down
13 changes: 12 additions & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2160,7 +2160,13 @@ impl usize {
intrinsics::mul_with_overflow }
}

/// Used for representing the classification of floating point numbers
/// A classification of floating point numbers.
///
/// This `enum` is used as the return type for [`f32::classify()`] and [`f64::classify()`]. See
/// their documentation for more.
///
/// [`f32::classify()`]: ../primitive.f32.html#method.classify
/// [`f64::classify()`]: ../primitive.f64.html#method.classify
#[derive(Copy, Clone, PartialEq, Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum FpCategory {
Expand Down Expand Up @@ -2387,6 +2393,11 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32)
}

/// An error which can be returned when parsing an integer.
///
/// This error is used as the error type for the `from_str_radix()` functions
/// on the primitive integer types, such as [`i8::from_str_radix()`].
///
/// [`i8::from_str_radix()`]: ../std/primitive.i8.html#method.from_str_radix
#[derive(Debug, Clone, PartialEq)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct ParseIntError { kind: IntErrorKind }
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,7 @@ impl StrExt for str {
let mut matcher = pat.into_searcher(self);
if let Some((a, b)) = matcher.next_reject() {
i = a;
j = b; // Rember earliest known match, correct it below if
j = b; // Remember earliest known match, correct it below if
// last match is different
}
if let Some((_, b)) = matcher.next_reject_back() {
Expand Down
19 changes: 1 addition & 18 deletions src/libcore/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! A finite heterogeneous sequence, `(T, U, ..)`
//!
//! To access a single element of a tuple one can use the `.0`
//! field access syntax.
//!
//! Indexing starts from zero, so `.0` returns first value, `.1`
//! returns second value, and so on. In general, a tuple with *N*
//! elements has field accessors from 0 to *N* - 1.
//!
//! If every type inside a tuple implements one of the following
//! traits, then a tuple itself also implements it.
//!
//! * `Clone`
//! * `PartialEq`
//! * `Eq`
//! * `PartialOrd`
//! * `Ord`
//! * `Default`
// See src/libstd/primitive_docs.rs for documentation.

use clone::Clone;
use cmp::*;
Expand Down
2 changes: 1 addition & 1 deletion src/librbml/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
//!
//! - `Opaque` (`17`): An opaque, custom-format tag.
//! Used to wrap ordinary custom tags or data in the auto-serialized context.
//! Rustc typically uses this to encode type informations.
//! Rustc typically uses this to encode type information.
//!
//! First 0x20 tags are reserved by RBML; custom tags start at 0x20.

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub fn pat_contains_bindings(dm: &DefMap, pat: &hir::Pat) -> bool {
}

/// Checks if the pattern contains any `ref` or `ref mut` bindings,
/// and if yes wether its containing mutable ones or just immutables ones.
/// and if yes whether its containing mutable ones or just immutables ones.
pub fn pat_contains_ref_binding(dm: &RefCell<DefMap>, pat: &hir::Pat) -> Option<hir::Mutability> {
let mut result = None;
pat_bindings(dm, pat, |mode, _, _, _| {
Expand All @@ -172,7 +172,7 @@ pub fn pat_contains_ref_binding(dm: &RefCell<DefMap>, pat: &hir::Pat) -> Option<
}

/// Checks if the patterns for this arm contain any `ref` or `ref mut`
/// bindings, and if yes wether its containing mutable ones or just immutables ones.
/// bindings, and if yes whether its containing mutable ones or just immutables ones.
pub fn arm_contains_ref_binding(dm: &RefCell<DefMap>, arm: &hir::Arm) -> Option<hir::Mutability> {
arm.pats.iter()
.filter_map(|pat| pat_contains_ref_binding(dm, pat))
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@ impl<'tcx> ctxt<'tcx> {
/// Given the did of an ADT, return a reference to its definition.
pub fn lookup_adt_def(&self, did: DefId) -> AdtDef<'tcx> {
// when reverse-variance goes away, a transmute::<AdtDefMaster,AdtDef>
// woud be needed here.
// would be needed here.
self.lookup_adt_def_master(did)
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ macro_rules! make_mir_visitor {
}

// The `super_xxx` methods comprise the default behavior and are
// not meant to be overidden.
// not meant to be overridden.

fn super_mir(&mut self,
mir: & $($mutability)* Mir<'tcx>) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
}

// Returns a ValueRef of the "eh_unwind_resume" lang item if one is defined,
// otherwise declares it as an external funtion.
// otherwise declares it as an external function.
pub fn eh_unwind_resume(&self) -> ValueRef {
use trans::attributes;
assert!(self.ccx.sess().target.target.options.custom_unwind_resume);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("select_all_obligations_and_apply_defaults: defaults={:?}", default_map);

// We loop over the unsolved variables, resolving them and if they are
// and unconstrainted numberic type we add them to the set of unbound
// and unconstrainted numeric type we add them to the set of unbound
// variables. We do this so we only apply literal fallback to type
// variables without defaults.
for ty in &unsolved_variables {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl OpenOptions {
/// No file is allowed to exist at the target location, also no (dangling)
/// symlink.
///
/// This option is usefull because it as atomic. Otherwise between checking
/// This option is useful because it as atomic. Otherwise between checking
/// whether a file exists and creating a new one, the file may have been
/// created by another process (a TOCTOU race condition / attack).
///
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/memchr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ mod fallback {
// Scan for a single byte value by reading two `usize` words at a time.
//
// Split `text` in three parts
// - unaligned inital part, before the first word aligned address in text
// - unaligned initial part, before the first word aligned address in text
// - body, scan by 2 words at a time
// - the last remaining part, < 2 word size
let len = text.len();
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Numeric traits and functions for generic mathematics
//! Additional functionality for numerics.
//!
//! These are implemented for the primitive numeric types in `std::{u8, u16,
//! u32, u64, usize, i8, i16, i32, i64, isize, f32, f64}`.
//! This module provides some extra types that are useful when doing numerical
//! work. See the individual documentation for each piece for more information.

#![stable(feature = "rust1", since = "1.0.0")]
#![allow(missing_docs)]
Expand Down
Loading