Skip to content
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

Rollup of 15 pull requests #35944

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fe34c03
Implement `read_offset` and `write_offset`
tbu- Aug 15, 2016
7a92d0a
Move `flock.rs` from librustdoc to librustc_data_structures.
michaelwoerister Aug 12, 2016
0c44405
Clarify `read_offset` and `write_offset` documentation
tbu- Aug 17, 2016
2d8d2a1
Implement From<char> for u32, and From<u8> for char
SimonSapin Aug 17, 2016
a2ff0e2
Add some features to flock.
michaelwoerister Aug 15, 2016
82678c5
Implement TryFrom<u32> for char
SimonSapin Aug 17, 2016
d1d8258
Implement copy-on-write scheme for managing the incremental compilati…
michaelwoerister Aug 11, 2016
ef6aab2
Reduce duplication in std::sys::unix::rand.
habnabit Jul 29, 2016
0a70944
Use the kernel arc4rand for FreeBSD OsRng.
habnabit Aug 14, 2016
b40754f
modify fds-are-cloexec test to open a file that exists
Aug 21, 2016
1802011
Add tests for `std::fs::File::{read,write}_offset`
tbu- Aug 22, 2016
c95236f
Use `FnvHashMap` in more places
jonas-schievink Aug 22, 2016
95d3cf3
incr.comp.: Move lock files out of directory being locked
michaelwoerister Aug 22, 2016
0f9cb1b
Change a weird line break in `core::str`
tbu- Aug 23, 2016
f863ea3
Update rust-installer. Fixes #35840
brson Aug 23, 2016
66a2578
Mark panicking tests as `should_panic` instead of `no_run`.
frewsxcv Aug 23, 2016
6b95606
rustc_trans: do not generate allocas for unused locals.
eddyb Aug 23, 2016
4e48924
Rename `{read,write}_offset` to `{read,write}_at`, add a tracking issue
tbu- Aug 23, 2016
dfe660e
Add E0478 error explanation
GuillaumeGomez Aug 23, 2016
012fb89
Add error code test checkup
GuillaumeGomez Aug 23, 2016
9747fa4
Add new error code tests
GuillaumeGomez Aug 23, 2016
2cad78d
replace `Div` example with something more evocative of division
matthew-piziak Aug 23, 2016
5ec6f39
Update E0195 to new error format
creativcoder Aug 10, 2016
702ea71
typeck: use NoExpectation to check return type of diverging fn
Aug 21, 2016
6a9db47
Fix debug line info for macro expansions.
vadimcn Aug 23, 2016
f81abcf
Rollup merge of #35238 - vadimcn:macro-debug-locs, r=@michaelwoerister
eddyb Aug 23, 2016
cf9cf3f
Rollup merge of #35704 - tbu-:pr_pread_pwrite, r=sfackler
eddyb Aug 23, 2016
d86838e
Rollup merge of #35718 - michaelwoerister:incr-comp-dir-locking, r=ni…
eddyb Aug 23, 2016
dadd8ee
Rollup merge of #35755 - SimonSapin:char_convert, r=alexcrichton
eddyb Aug 23, 2016
3ccb439
Rollup merge of #35883 - durka:gh35849, r=eddyb
eddyb Aug 23, 2016
bf298cc
Rollup merge of #35884 - habnabit:freebsd-arc4rand, r=alexcrichton
eddyb Aug 23, 2016
7340b76
Rollup merge of #35885 - durka:gh35753, r=nagisa
eddyb Aug 23, 2016
6ae1215
Rollup merge of #35909 - jonas-schievink:more-fnv, r=eddyb
eddyb Aug 23, 2016
289d4f1
Rollup merge of #35910 - tbu-:pr_weird_linebreak, r=alexcrichton
eddyb Aug 23, 2016
23e10d5
Rollup merge of #35912 - brson:rust-installer, r=alexcrichton
eddyb Aug 23, 2016
152db5b
Rollup merge of #35913 - frewsxcv:panic, r=steveklabnik
eddyb Aug 23, 2016
c7af92c
Rollup merge of #35916 - eddyb:mir-no-dead-allocas, r=Aatch
eddyb Aug 23, 2016
d4d1974
Rollup merge of #35920 - GuillaumeGomez:err_codes, r=jonathandturner
eddyb Aug 23, 2016
151e900
Rollup merge of #35936 - matthew-piziak:div-rational-example, r=Guill…
eddyb Aug 23, 2016
26432c6
Rollup merge of #35939 - creativcoder:e0195, r=jonathandturner
eddyb Aug 23, 2016
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
7 changes: 3 additions & 4 deletions mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ DEPS_rustc := syntax fmt_macros flate arena serialize getopts rbml \
rustc_const_math syntax_pos rustc_errors
DEPS_rustc_back := std syntax flate log libc
DEPS_rustc_borrowck := rustc log graphviz syntax syntax_pos rustc_errors rustc_mir
DEPS_rustc_data_structures := std log serialize
DEPS_rustc_data_structures := std log serialize libc
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \
rustc_typeck rustc_mir rustc_resolve log syntax serialize rustc_llvm \
rustc_trans rustc_privacy rustc_lint rustc_plugin \
Expand All @@ -137,9 +137,8 @@ DEPS_rustc_save_analysis := rustc log syntax syntax_pos serialize
DEPS_rustc_typeck := rustc syntax syntax_pos rustc_platform_intrinsics rustc_const_math \
rustc_const_eval rustc_errors

DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts \
test rustc_lint rustc_const_eval syntax_pos

DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts test \
rustc_lint rustc_const_eval syntax_pos rustc_data_structures

TOOL_DEPS_compiletest := test getopts log serialize
TOOL_DEPS_rustdoc := rustdoc
Expand Down
4 changes: 2 additions & 2 deletions src/doc/book/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ Here are some common macros you’ll see in Rust code.
This macro causes the current thread to panic. You can give it a message
to panic with:

```rust,no_run
```rust,should_panic
panic!("oh no!");
```

Expand All @@ -688,7 +688,7 @@ These two macros are used in tests. `assert!` takes a boolean. `assert_eq!`
takes two values and checks them for equality. `true` passes, `false` `panic!`s.
Like this:

```rust,no_run
```rust,should_panic
// A-ok!

assert!(true);
Expand Down
43 changes: 37 additions & 6 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use prelude::v1::*;

use char_private::is_printable;
use convert::TryFrom;
use mem::transmute;

// UTF-8 ranges and tags for encoding characters
Expand Down Expand Up @@ -123,12 +124,7 @@ pub const MAX: char = '\u{10ffff}';
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_u32(i: u32) -> Option<char> {
// catch out-of-bounds and surrogates
if (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF) {
None
} else {
Some(unsafe { from_u32_unchecked(i) })
}
char::try_from(i).ok()
}

/// Converts a `u32` to a `char`, ignoring validity.
Expand Down Expand Up @@ -176,6 +172,41 @@ pub unsafe fn from_u32_unchecked(i: u32) -> char {
transmute(i)
}

#[stable(feature = "char_convert", since = "1.12.0")]
impl From<char> for u32 {
#[inline]
fn from(c: char) -> Self {
c as u32
}
}

#[stable(feature = "char_convert", since = "1.12.0")]
impl From<u8> for char {
#[inline]
fn from(i: u8) -> Self {
i as char
}
}

#[unstable(feature = "try_from", issue = "33417")]
impl TryFrom<u32> for char {
type Err = CharTryFromError;

#[inline]
fn try_from(i: u32) -> Result<Self, Self::Err> {
if (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF) {
Err(CharTryFromError(()))
} else {
Ok(unsafe { from_u32_unchecked(i) })
}
}
}

/// The error type returned when a conversion from u32 to char fails.
#[unstable(feature = "try_from", issue = "33417")]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct CharTryFromError(());

/// Converts a digit in the given radix to a `char`.
///
/// A 'radix' here is sometimes also called a 'base'. A radix of two
Expand Down
61 changes: 52 additions & 9 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,25 +421,68 @@ mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
///
/// # Examples
///
/// A trivial implementation of `Div`. When `Foo / Foo` happens, it ends up
/// calling `div`, and therefore, `main` prints `Dividing!`.
/// Implementing a `Div`idable rational number struct:
///
/// ```
/// use std::ops::Div;
///
/// struct Foo;
/// // The uniqueness of rational numbers in lowest terms is a consequence of
/// // the fundamental theorem of arithmetic.
/// #[derive(Eq)]
/// #[derive(PartialEq, Debug)]
/// struct Rational {
/// nominator: usize,
/// denominator: usize,
/// }
///
/// impl Div for Foo {
/// type Output = Foo;
/// impl Rational {
/// fn new(nominator: usize, denominator: usize) -> Self {
/// if denominator == 0 {
/// panic!("Zero is an invalid denominator!");
/// }
///
/// fn div(self, _rhs: Foo) -> Foo {
/// println!("Dividing!");
/// self
/// // Reduce to lowest terms by dividing by the greatest common
/// // divisor.
/// let gcd = gcd(nominator, denominator);
/// Rational {
/// nominator: nominator / gcd,
/// denominator: denominator / gcd,
/// }
/// }
/// }
///
/// impl Div for Rational {
/// // The division of rational numbers is a closed operation.
/// type Output = Self;
///
/// fn div(self, rhs: Self) -> Self {
/// if rhs.nominator == 0 {
/// panic!("Cannot divide by zero-valued `Rational`!");
/// }
///
/// let nominator = self.nominator * rhs.denominator;
/// let denominator = self.denominator * rhs.nominator;
/// Rational::new(nominator, denominator)
/// }
/// }
///
/// // Euclid's two-thousand-year-old algorithm for finding the greatest common
/// // divisor.
/// fn gcd(x: usize, y: usize) -> usize {
/// let mut x = x;
/// let mut y = y;
/// while y != 0 {
/// let t = y;
/// y = x % y;
/// x = t;
/// }
/// x
/// }
///
/// fn main() {
/// Foo / Foo;
/// assert_eq!(Rational::new(1, 2), Rational::new(2, 4));
/// assert_eq!(Rational::new(1, 2) / Rational::new(3, 4),
/// Rational::new(2, 3));
/// }
/// ```
///
Expand Down
5 changes: 3 additions & 2 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,9 @@ pub fn next_code_point<'a, I: Iterator<Item = &'a u8>>(bytes: &mut I) -> Option<
/// Reads the last code point out of a byte iterator (assuming a
/// UTF-8-like encoding).
#[inline]
fn next_code_point_reverse<'a,
I: DoubleEndedIterator<Item = &'a u8>>(bytes: &mut I) -> Option<u32> {
fn next_code_point_reverse<'a, I>(bytes: &mut I) -> Option<u32>
where I: DoubleEndedIterator<Item = &'a u8>,
{
// Decode UTF-8
let w = match bytes.next_back() {
None => return None,
Expand Down
18 changes: 18 additions & 0 deletions src/libcoretest/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
// except according to those terms.

use std::char;
use std::convert::TryFrom;

#[test]
fn test_convert() {
assert_eq!(u32::from('a'), 0x61);
assert_eq!(char::from(b'\0'), '\0');
assert_eq!(char::from(b'a'), 'a');
assert_eq!(char::from(b'\xFF'), '\u{FF}');
assert_eq!(char::try_from(0_u32), Ok('\0'));
assert_eq!(char::try_from(0x61_u32), Ok('a'));
assert_eq!(char::try_from(0xD7FF_u32), Ok('\u{D7FF}'));
assert!(char::try_from(0xD800_u32).is_err());
assert!(char::try_from(0xDFFF_u32).is_err());
assert_eq!(char::try_from(0xE000_u32), Ok('\u{E000}'));
assert_eq!(char::try_from(0x10FFFF_u32), Ok('\u{10FFFF}'));
assert!(char::try_from(0x110000_u32).is_err());
assert!(char::try_from(0xFFFF_FFFF_u32).is_err());
}

#[test]
fn test_is_lowercase() {
Expand Down
32 changes: 31 additions & 1 deletion src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,37 @@ fn main() {
```
"##,

E0478: r##"
A lifetime bound was not satisfied.

Erroneous code example:

// Check that the explicit lifetime bound (`'b`, in this example) must
// outlive all the superbound from the trait (`'a`, in this example).

```compile_fail,E0478
trait Wedding<'t>: 't { }

struct Prince<'kiss, 'SnowWhite> {
child: Box<Wedding<'kiss> + 'SnowWhite>,
// error: lifetime bound not satisfied
}
```

In this example, the `'SnowWhite` lifetime is supposed to outlive the `'kiss`
lifetime but the declaration of the `Prince` struct doesn't enforce it. To fix
this issue, you need to specify it:

```
trait Wedding<'t>: 't { }

struct Prince<'kiss, 'SnowWhite: 'kiss> { // You say here that 'b must live
// longer than 'a.
child: Box<Wedding<'kiss> + 'SnowWhite>, // And now it's all good!
}
```
"##,

E0496: r##"
A lifetime name is shadowing another lifetime name. Erroneous code example:

Expand Down Expand Up @@ -1715,7 +1746,6 @@ register_diagnostics! {
E0475, // index of slice outside its lifetime
E0476, // lifetime of the source pointer does not outlive lifetime bound...
E0477, // the type `..` does not fulfill the required lifetime...
E0478, // lifetime bound not satisfied
E0479, // the type `..` (provided as the value of a type parameter) is...
E0480, // lifetime of method receiver does not outlive the method call
E0481, // lifetime of function argument does not outlive the function call
Expand Down
15 changes: 15 additions & 0 deletions src/librustc/hir/svh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use std::fmt;
use std::hash::{Hash, Hasher};
use serialize::{Encodable, Decodable, Encoder, Decoder};

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct Svh {
Expand Down Expand Up @@ -51,3 +52,17 @@ impl fmt::Display for Svh {
f.pad(&self.to_string())
}
}

impl Encodable for Svh {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_u64(self.as_u64().to_le())
}
}

impl Decodable for Svh {
fn decode<D: Decoder>(d: &mut D) -> Result<Svh, D::Error> {
d.read_u64()
.map(u64::from_le)
.map(Svh::new)
}
}
7 changes: 4 additions & 3 deletions src/librustc/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@

use ty::{self, Ty, TyCtxt, TypeFoldable};
use ty::fold::TypeFolder;
use std::collections::hash_map::{self, Entry};
use util::nodemap::FnvHashMap;
use std::collections::hash_map::Entry;

use super::InferCtxt;
use super::unify_key::ToType;

pub struct TypeFreshener<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
freshen_count: u32,
freshen_map: hash_map::HashMap<ty::InferTy, Ty<'tcx>>,
freshen_map: FnvHashMap<ty::InferTy, Ty<'tcx>>,
}

impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
Expand All @@ -49,7 +50,7 @@ impl<'a, 'gcx, 'tcx> TypeFreshener<'a, 'gcx, 'tcx> {
TypeFreshener {
infcx: infcx,
freshen_count: 0,
freshen_map: hash_map::HashMap::new(),
freshen_map: FnvHashMap(),
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use ty::{self, TyCtxt};
use hir::def::Def;
use hir::def_id::{DefId};
use lint;
use util::nodemap::FnvHashSet;

use std::collections::HashSet;
use syntax::{ast, codemap};
use syntax::attr;
use syntax_pos;
Expand All @@ -48,7 +48,7 @@ fn should_explore<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
struct MarkSymbolVisitor<'a, 'tcx: 'a> {
worklist: Vec<ast::NodeId>,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
live_symbols: Box<HashSet<ast::NodeId>>,
live_symbols: Box<FnvHashSet<ast::NodeId>>,
struct_has_extern_repr: bool,
ignore_non_const_paths: bool,
inherited_pub_visibility: bool,
Expand All @@ -61,7 +61,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
MarkSymbolVisitor {
worklist: worklist,
tcx: tcx,
live_symbols: box HashSet::new(),
live_symbols: box FnvHashSet(),
struct_has_extern_repr: false,
ignore_non_const_paths: false,
inherited_pub_visibility: false,
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}

fn mark_live_symbols(&mut self) {
let mut scanned = HashSet::new();
let mut scanned = FnvHashSet();
while !self.worklist.is_empty() {
let id = self.worklist.pop().unwrap();
if scanned.contains(&id) {
Expand Down Expand Up @@ -395,7 +395,7 @@ fn create_and_seed_worklist<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
access_levels: &privacy::AccessLevels,
krate: &hir::Crate)
-> Box<HashSet<ast::NodeId>> {
-> Box<FnvHashSet<ast::NodeId>> {
let worklist = create_and_seed_worklist(tcx, access_levels, krate);
let mut symbol_visitor = MarkSymbolVisitor::new(tcx, worklist);
symbol_visitor.mark_live_symbols();
Expand All @@ -413,7 +413,7 @@ fn get_struct_ctor_id(item: &hir::Item) -> Option<ast::NodeId> {

struct DeadVisitor<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
live_symbols: Box<HashSet<ast::NodeId>>,
live_symbols: Box<FnvHashSet<ast::NodeId>>,
}

impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
Expand Down
8 changes: 7 additions & 1 deletion src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.ir.tcx.region_maps.call_site_extent(id, body.id),
&self.fn_ret(id));

if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
if fn_ret.is_never() {
// FIXME(durka) this rejects code like `fn foo(x: !) -> ! { x }`
if self.live_on_entry(entry_ln, self.s.clean_exit_var).is_some() {
span_err!(self.ir.tcx.sess, sp, E0270,
"computation may converge in a function marked as diverging");
}
} else if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
let param_env = ParameterEnvironment::for_item(self.ir.tcx, id);
let t_ret_subst = fn_ret.subst(self.ir.tcx, &param_env.free_substs);
let is_nil = self.ir.tcx.infer_ctxt(None, Some(param_env),
Expand Down
Loading