Skip to content

Rollup of 9 pull requests #30722

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

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion COPYRIGHT
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terms.

Longer version:

The Rust Project is copyright 2015, The Rust Project
The Rust Project is copyright 2016, The Rust Project
Developers (given in the file AUTHORS.txt).

Licensed under the Apache License, Version 2.0
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015 The Rust Project Developers
Copyright (c) 2016 The Rust Project Developers

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
44 changes: 30 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ Read ["Installing Rust"] from [The Book].

### Building on Windows

There are two prominent ABIs in use on Windows: the native (MSVC) ABI used by
Visual Studio, and the GNU ABI used by the GCC toolchain. Which version of Rust
you need depends largely on what C/C++ libraries you want to interoperate with:
for interop with software produced by Visual Studio use the MSVC build of Rust;
for interop with GNU software built using the MinGW/MSYS2 toolchain use the GNU
build.


#### MinGW

[MSYS2](http://msys2.github.io/) can be used to easily build Rust on Windows:

1. Grab the latest MSYS2 installer and go through the installer.
Expand All @@ -63,12 +73,15 @@ Read ["Installing Rust"] from [The Book].
```sh
# Update package mirrors (may be needed if you have a fresh install of MSYS2)
$ pacman -Sy pacman-mirrors
```

# Choose one based on platform:
# *** see the note below ***
$ pacman -S mingw-w64-i686-toolchain
$ pacman -S mingw-w64-x86_64-toolchain
Download [MinGW from
here](http://mingw-w64.org/doku.php/download/mingw-builds), and choose the
`threads=win32,exceptions=dwarf/seh` flavor when installing. After installing,
add its `bin` directory to your `PATH`. This is due to #28260, in the future,
installing from pacman should be just fine.

```
# Make git available in MSYS2 (if not already available on path)
$ pacman -S git

Expand All @@ -84,16 +97,19 @@ Read ["Installing Rust"] from [The Book].
$ ./configure
$ make && make install
```
> ***Note:*** gcc versions >= 5 currently have issues building LLVM on Windows
> resulting in a segmentation fault when building Rust. In order to avoid this
> it may be necessary to obtain an earlier version of gcc such as 4.9.x.
> Msys's `pacman` will install the latest version, so for the time being it is
> recommended to skip gcc toolchain installation step above and use [Mingw-Builds]
> project's installer instead. Be sure to add gcc `bin` directory to the path
> before running `configure`.
> For more information on this see issue #28260.

[Mingw-Builds]: http://sourceforge.net/projects/mingw-w64/

#### MSVC

MSVC builds of Rust additionally require an installation of Visual Studio 2013
(or later) so `rustc` can use its linker. Make sure to check the “C++ tools”
option. In addition, `cmake` needs to be installed to build LLVM.

With these dependencies installed, the build takes two steps:

```sh
$ ./configure
$ make && make install
```

## Building Documentation

Expand Down
21 changes: 17 additions & 4 deletions src/doc/book/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -1573,11 +1573,11 @@ fn main() {

let matches = match opts.parse(&args[1..]) {
Ok(m) => { m }
Err(e) => { panic!(e.to_string()) }
Err(e) => { panic!(e.to_string()) }
};
if matches.opt_present("h") {
print_usage(&program, opts);
return;
return;
}
let data_path = args[1].clone();
let city = args[2].clone();
Expand Down Expand Up @@ -1795,6 +1795,10 @@ To convert this to proper error handling, we need to do the following:
Let's try it:

```rust,ignore
use std::error::Error

// The rest of the code before this is unchanged

fn search<P: AsRef<Path>>
(file_path: P, city: &str)
-> Result<Vec<PopulationCount>, Box<Error+Send+Sync>> {
Expand Down Expand Up @@ -1903,8 +1907,13 @@ let city = if !matches.free.is_empty() {
return;
};

for pop in search(&data_file, &city) {
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
match search(&data_file, &city) {
Ok(pops) => {
for pop in pops {
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
}
}
Err(err) => println!("{}", err)
}
...
```
Expand All @@ -1927,6 +1936,10 @@ that it is generic on some type parameter `R` that satisfies
`io::Read`. Another way is to just use trait objects:

```rust,ignore
use std::io;

// The rest of the code before this is unchanged

fn search<P: AsRef<Path>>
(file_path: &Option<P>, city: &str)
-> Result<Vec<PopulationCount>, Box<Error+Send+Sync>> {
Expand Down
29 changes: 29 additions & 0 deletions src/doc/book/structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,35 @@ fn main() {
}
```

Your structure can still contain `&mut` pointers, which will let
you do some kinds of mutation:

```rust
struct Point {
x: i32,
y: i32,
}

struct PointRef<'a> {
x: &'a mut i32,
y: &'a mut i32,
}

fn main() {
let mut point = Point { x: 0, y: 0 };

{
let r = PointRef { x: &mut point.x, y: &mut point.y };

*r.x = 5;
*r.y = 6;
}

assert_eq!(5, point.x);
assert_eq!(6, point.y);
}
```

# Update syntax

A `struct` can include `..` to indicate that you want to use a copy of some
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book/the-stack-and-the-heap.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ instead.
# Which to use?

So if the stack is faster and easier to manage, why do we need the heap? A big
reason is that Stack-allocation alone means you only have LIFO semantics for
reason is that Stack-allocation alone means you only have 'Last In First Out (LIFO)' semantics for
reclaiming storage. Heap-allocation is strictly more general, allowing storage
to be taken from and returned to the pool in arbitrary order, but at a
complexity cost.
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub unsafe fn from_u32_unchecked(i: u32) -> char {
///
/// A 'radix' here is sometimes also called a 'base'. A radix of two
/// indicates a binary number, a radix of ten, decimal, and a radix of
/// sixteen, hexicdecimal, to give some common values. Arbitrary
/// sixteen, hexadecimal, to give some common values. Arbitrary
/// radicum are supported.
///
/// `from_digit()` will return `None` if the input is not a digit in
Expand Down
4 changes: 4 additions & 0 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use hash::Hash;
use hash::Hasher;

/// Types that can be transferred across thread boundaries.
///
/// This trait is automatically derived when the compiler determines it's appropriate.
#[stable(feature = "rust1", since = "1.0.0")]
#[lang = "send"]
#[rustc_on_unimplemented = "`{Self}` cannot be sent between threads safely"]
Expand Down Expand Up @@ -219,6 +221,8 @@ pub trait Copy : Clone {
/// wrapper around the value(s) which can be mutated when behind a `&`
/// reference; not doing this is undefined behavior (for example,
/// `transmute`-ing from `&T` to `&mut T` is invalid).
///
/// This trait is automatically derived when the compiler determines it's appropriate.
#[stable(feature = "rust1", since = "1.0.0")]
#[lang = "sync"]
#[rustc_on_unimplemented = "`{Self}` cannot be shared between threads safely"]
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#![feature(staged_api)]
#![feature(str_char)]

#[macro_use]
extern crate syntax;
#[macro_use]
extern crate rustc;
Expand Down Expand Up @@ -153,4 +154,5 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
store.register_renamed("unknown_features", "unused_features");

store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
store.register_removed("negate_unsigned", "cast a signed value instead");
}
63 changes: 30 additions & 33 deletions src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(non_snake_case)]

use middle::{infer};
use middle::def_id::DefId;
use middle::subst::Substs;
Expand All @@ -24,13 +26,19 @@ use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
use syntax::{abi, ast};
use syntax::attr::{self, AttrMetaMethods};
use syntax::codemap::{self, Span};
use syntax::feature_gate::{emit_feature_err, GateIssue};
use syntax::ast::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};

use rustc_front::hir;
use rustc_front::intravisit::{self, Visitor};
use rustc_front::util::is_shift_binop;

register_long_diagnostics! {
E0519: r##"
It is not allowed to negate an unsigned integer.
You can negate a signed integer and cast it to an unsigned integer.
"##
}

declare_lint! {
UNUSED_COMPARISONS,
Warn,
Expand Down Expand Up @@ -73,30 +81,24 @@ impl LateLintPass for TypeLimits {
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
match e.node {
hir::ExprUnary(hir::UnNeg, ref expr) => {
match expr.node {
hir::ExprLit(ref lit) => {
match lit.node {
ast::LitInt(_, ast::UnsignedIntLit(_)) => {
check_unsigned_negation_feature(cx, e.span);
},
ast::LitInt(_, ast::UnsuffixedIntLit(_)) => {
if let ty::TyUint(_) = cx.tcx.node_id_to_type(e.id).sty {
check_unsigned_negation_feature(cx, e.span);
}
},
_ => ()
}
},
_ => {
let t = cx.tcx.node_id_to_type(expr.id);
match t.sty {
ty::TyUint(_) => {
check_unsigned_negation_feature(cx, e.span);
},
_ => ()
}
if let hir::ExprLit(ref lit) = expr.node {
match lit.node {
ast::LitInt(_, ast::UnsignedIntLit(_)) => {
forbid_unsigned_negation(cx, e.span);
},
ast::LitInt(_, ast::UnsuffixedIntLit(_)) => {
if let ty::TyUint(_) = cx.tcx.node_id_to_type(e.id).sty {
forbid_unsigned_negation(cx, e.span);
}
},
_ => ()
}
};
} else {
let t = cx.tcx.node_id_to_type(expr.id);
if let ty::TyUint(_) = t.sty {
forbid_unsigned_negation(cx, e.span);
}
}
// propagate negation, if the negation itself isn't negated
if self.negated_expr_id != e.id {
self.negated_expr_id = expr.id;
Expand Down Expand Up @@ -322,15 +324,10 @@ impl LateLintPass for TypeLimits {
}
}

fn check_unsigned_negation_feature(cx: &LateContext, span: Span) {
if !cx.sess().features.borrow().negate_unsigned {
emit_feature_err(
&cx.sess().parse_sess.span_diagnostic,
"negate_unsigned",
span,
GateIssue::Language,
"unary negation of unsigned integers may be removed in the future");
}
fn forbid_unsigned_negation(cx: &LateContext, span: Span) {
span_err!(cx.sess(), span, E0519,
"unary negation of unsigned integer");
cx.sess().span_help(span, "use a cast or the `!` operator");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_unicode/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl char {
///
/// A 'radix' here is sometimes also called a 'base'. A radix of two
/// indicates a binary number, a radix of ten, decimal, and a radix of
/// sixteen, hexicdecimal, to give some common values. Arbitrary
/// sixteen, hexadecimal, to give some common values. Arbitrary
/// radicum are supported.
///
/// Compared to `is_numeric()`, this function only recognizes the characters
Expand Down Expand Up @@ -185,7 +185,7 @@ impl char {
///
/// A 'radix' here is sometimes also called a 'base'. A radix of two
/// indicates a binary number, a radix of ten, decimal, and a radix of
/// sixteen, hexicdecimal, to give some common values. Arbitrary
/// sixteen, hexadecimal, to give some common values. Arbitrary
/// radicum are supported.
///
/// 'Digit' is defined to be only the following characters:
Expand Down
5 changes: 1 addition & 4 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Option<u32>, Status
("slice_patterns", "1.0.0", Some(23121), Active),

// Allows use of unary negate on unsigned integers, e.g. -e for e: u8
("negate_unsigned", "1.0.0", Some(29645), Active),
("negate_unsigned", "1.0.0", Some(29645), Removed),

// Allows the definition of associated constants in `trait` or `impl`
// blocks.
Expand Down Expand Up @@ -540,7 +540,6 @@ pub struct Features {
pub allow_pushpop_unsafe: bool,
pub simd_ffi: bool,
pub unmarked_api: bool,
pub negate_unsigned: bool,
/// spans of #![feature] attrs for stable language features. for error reporting
pub declared_stable_lang_features: Vec<Span>,
/// #![feature] attrs for non-language (library) features
Expand Down Expand Up @@ -577,7 +576,6 @@ impl Features {
allow_pushpop_unsafe: false,
simd_ffi: false,
unmarked_api: false,
negate_unsigned: false,
declared_stable_lang_features: Vec::new(),
declared_lib_features: Vec::new(),
const_fn: false,
Expand Down Expand Up @@ -1166,7 +1164,6 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &Handler,
allow_pushpop_unsafe: cx.has_feature("pushpop_unsafe"),
simd_ffi: cx.has_feature("simd_ffi"),
unmarked_api: cx.has_feature("unmarked_api"),
negate_unsigned: cx.has_feature("negate_unsigned"),
declared_stable_lang_features: accepted_features,
declared_lib_features: unknown_features,
const_fn: cx.has_feature("const_fn"),
Expand Down
Loading