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 13 pull requests #32771

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ecc0bd2
Fix LLVM assert when handling bad intrinsic monomorphizations
Amanieu Mar 31, 2016
313eb32
Address FIXMEs related to short lifetimes in `HashMap`.
frewsxcv Apr 1, 2016
a2f6d29
Remove error description of `move`
tclfs Apr 2, 2016
da4d7f5
Indicate `None` is code-like in doc comment.
frewsxcv Apr 3, 2016
a09a3ac
Remove outdated comment
sanxiyn Apr 4, 2016
2325cab
minor: update old comments
matklad Apr 4, 2016
a447124
Mention that it's not actually a data race
Manishearth Mar 27, 2016
cfe25ad
Fix the span for try shorthand expressions
marcusklaas Apr 3, 2016
6fee337
Add example doc for ToOwned trait
GuillaumeGomez Apr 5, 2016
8f463ea
doc: make env::consts summaries less confusing
tshepang Apr 5, 2016
d841c15
Doc fix: function takes argument by reference.
Mar 31, 2016
a7d15ce
Doc fix: list all module files Rust looks for.
Mar 31, 2016
922e666
avoid "==" in assert! when one of the values is a bool
tshepang Apr 6, 2016
b27b3e1
change constant patterns to have a warning cycle
nikomatsakis Apr 6, 2016
c9168f7
Rollup merge of #31762 - tshepang:in-which-case, r=steveklabnik
steveklabnik Apr 6, 2016
e55834b
Rollup merge of #32538 - Manishearth:no-data-race, r=steveklabnik
steveklabnik Apr 6, 2016
e9774e7
Rollup merge of #32634 - varunvats:docs-fix, r=steveklabnik
steveklabnik Apr 6, 2016
0f7d73e
Rollup merge of #32649 - Amanieu:intrinsic_monomorphization_assert, r…
steveklabnik Apr 6, 2016
9c59d6b
Rollup merge of #32668 - frewsxcv:hashmap-address-fixme, r=alexcrichton
steveklabnik Apr 6, 2016
ec3917a
Rollup merge of #32679 - tclfs:patch-1, r=steveklabnik
steveklabnik Apr 6, 2016
b959fdc
Rollup merge of #32691 - frewsxcv:patch-28, r=alexcrichton
steveklabnik Apr 6, 2016
a2a2cfd
Rollup merge of #32711 - marcusklaas:try-shorthand-span-fix, r=nagisa
steveklabnik Apr 6, 2016
426d633
Rollup merge of #32724 - sanxiyn:outdated-comment, r=dotdash
steveklabnik Apr 6, 2016
ba97265
Rollup merge of #32727 - matklad:fix-comment, r=alexcrichton
steveklabnik Apr 6, 2016
f02a4b7
Rollup merge of #32744 - GuillaumeGomez:patch-3, r=steveklabnik
steveklabnik Apr 6, 2016
1e05e36
Rollup merge of #32761 - tshepang:assert, r=steveklabnik
steveklabnik Apr 6, 2016
d326734
Rollup merge of #32766 - nikomatsakis:constant-pattern-warning-cycle,…
steveklabnik Apr 6, 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
11 changes: 7 additions & 4 deletions src/doc/book/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ thread may outlive the scope of `x`, leading to a dangling pointer.

To fix this, we use a `move` closure as mentioned in the error message. `move`
closures are explained in depth [here](closures.html#move-closures); basically
they move variables from their environment into themselves. This means that `x`
is now owned by the closure, and cannot be used in `main()` after the call to
`spawn()`.
they move variables from their environment into themselves.

```rust
use std::thread;
Expand Down Expand Up @@ -164,7 +162,7 @@ The same [ownership system](ownership.html) that helps prevent using pointers
incorrectly also helps rule out data races, one of the worst kinds of
concurrency bugs.

As an example, here is a Rust program that would have a data race in many
As an example, here is a Rust program that could have a data race in many
languages. It will not compile:

```ignore
Expand Down Expand Up @@ -197,6 +195,11 @@ thread, and the thread takes ownership of the reference, we'd have three owners!
`data` gets moved out of `main` in the first call to `spawn()`, so subsequent
calls in the loop cannot use this variable.

Note that this specific example will not cause a data race since different array
indices are being accessed. But this can't be determined at compile time, and in
a similar situation where `i` is a constant or is random, you would have a data
race.

So, we need some type that lets us have more than one owning reference to a
value. Usually, we'd use `Rc<T>` for this, which is a reference counted type
that provides shared ownership. It has some runtime bookkeeping that keeps track
Expand Down
22 changes: 14 additions & 8 deletions src/doc/book/crates-and-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ build deps examples libphrases-a7448e02a0468eaa.rlib native
`libphrases-hash.rlib` is the compiled crate. Before we see how to use this
crate from another crate, let’s break it up into multiple files.

# Multiple file crates
# Multiple File Crates

If each crate were just one file, these files would get very large. It’s often
easier to split up crates into multiple files, and Rust supports this in two
Expand Down Expand Up @@ -190,13 +190,19 @@ mod farewells;
```

Again, these declarations tell Rust to look for either
`src/english/greetings.rs` and `src/japanese/greetings.rs` or
`src/english/farewells/mod.rs` and `src/japanese/farewells/mod.rs`. Because
these sub-modules don’t have their own sub-modules, we’ve chosen to make them
`src/english/greetings.rs` and `src/japanese/farewells.rs`. Whew!

The contents of `src/english/greetings.rs` and `src/japanese/farewells.rs` are
both empty at the moment. Let’s add some functions.
`src/english/greetings.rs`, `src/english/farewells.rs`,
`src/japanese/greetings.rs` and `src/japanese/farewells.rs` or
`src/english/greetings/mod.rs`, `src/english/farewells/mod.rs`,
`src/japanese/greetings/mod.rs` and
`src/japanese/farewells/mod.rs`. Because these sub-modules don’t have
their own sub-modules, we’ve chosen to make them
`src/english/greetings.rs`, `src/english/farewells.rs`,
`src/japanese/greetings.rs` and `src/japanese/farewells.rs`. Whew!

The contents of `src/english/greetings.rs`,
`src/english/farewells.rs`, `src/japanese/greetings.rs` and
`src/japanese/farewells.rs` are all empty at the moment. Let’s add
some functions.

Put this in `src/english/greetings.rs`:

Expand Down
4 changes: 2 additions & 2 deletions src/doc/book/lifetimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ To fix this, we have to make sure that step four never happens after step
three. The ownership system in Rust does this through a concept called
lifetimes, which describe the scope that a reference is valid for.

When we have a function that takes a reference by argument, we can be implicit
or explicit about the lifetime of the reference:
When we have a function that takes an argument by reference, we can be
implicit or explicit about the lifetime of the reference:

```rust
// implicit
Expand Down
12 changes: 12 additions & 0 deletions src/libcollections/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ pub trait ToOwned {
type Owned: Borrow<Self>;

/// Creates owned data from borrowed data, usually by cloning.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// let s = "a"; // &str
/// let ss = s.to_owned(); // String
///
/// let v = &[1, 2]; // slice
/// let vv = v.to_owned(); // Vec
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn to_owned(&self) -> Self::Owned;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<T: ?Sized> *const T {
/// ```
/// let s: &str = "Follow the rabbit";
/// let ptr: *const u8 = s.as_ptr();
/// assert!(ptr.is_null() == false);
/// assert!(!ptr.is_null());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down Expand Up @@ -306,7 +306,7 @@ impl<T: ?Sized> *mut T {
/// ```
/// let mut s = [1, 2, 3];
/// let ptr: *mut u32 = s.as_mut_ptr();
/// assert!(ptr.is_null() == false);
/// assert!(!ptr.is_null());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ declare_lint! {

declare_lint! {
pub ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
Deny,
Warn,
"constants of struct or enum type can only be used in a pattern if \
the struct or enum has `#[derive(PartialEq, Eq)]`"
}
Expand Down
25 changes: 5 additions & 20 deletions src/librustc_resolve/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,8 @@ impl<'a, 'b, 'tcx:'b> DerefMut for UnusedImportCheckVisitor<'a, 'b, 'tcx> {

impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> {
// We have information about whether `use` (import) directives are actually
// used now. If an import is not used at all, we signal a lint error. If an
// import is only used for a single namespace, we remove the other namespace
// from the recorded privacy information. That means in privacy.rs, we will
// only check imports and namespaces which are used. In particular, this
// means that if an import could name either a public or private item, we
// will check the correct thing, dependent on how the import is used.
fn finalize_import(&mut self, id: ast::NodeId, span: Span) {
debug!("finalizing import uses for {:?}",
self.session.codemap().span_to_snippet(span));

// used now. If an import is not used at all, we signal a lint error.
fn check_import(&mut self, id: ast::NodeId, span: Span) {
if !self.used_imports.contains(&(id, TypeNS)) &&
!self.used_imports.contains(&(id, ValueNS)) {
self.session.add_lint(lint::builtin::UNUSED_IMPORTS,
Expand Down Expand Up @@ -95,23 +87,16 @@ impl<'a, 'b, 'v, 'tcx> Visitor<'v> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
hir::ItemUse(ref p) => {
match p.node {
ViewPathSimple(_, _) => {
self.finalize_import(item.id, p.span)
self.check_import(item.id, p.span)
}

ViewPathList(_, ref list) => {
for i in list {
self.finalize_import(i.node.id(), i.span);
self.check_import(i.node.id(), i.span);
}
}
ViewPathGlob(_) => {
if !self.used_imports.contains(&(item.id, TypeNS)) &&
!self.used_imports.contains(&(item.id, ValueNS)) {
self.session
.add_lint(lint::builtin::UNUSED_IMPORTS,
item.id,
p.span,
"unused import".to_string());
}
self.check_import(item.id, p.span)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trans/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
tcx.sess, span,
&format!("invalid monomorphization of `{}` intrinsic: \
expected basic integer type, found `{}`", name, sty));
C_null(llret_ty)
C_nil(ccx)
}
}

Expand All @@ -681,7 +681,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
tcx.sess, span,
&format!("invalid monomorphization of `{}` intrinsic: \
expected basic float type, found `{}`", name, sty));
C_null(llret_ty)
C_nil(ccx)
}
}

Expand Down Expand Up @@ -1475,7 +1475,7 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
($cond: expr, $($fmt: tt)*) => {
if !$cond {
emit_error!($($fmt)*);
return C_null(llret_ty)
return C_nil(bcx.ccx())
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,7 @@ fn robin_hood<'a, K: 'a, V: 'a>(bucket: FullBucketMut<'a, K, V>,
mut val: V)
-> &'a mut V {
let starting_index = bucket.index();
let size = {
let table = bucket.table(); // FIXME "lifetime too short".
table.size()
};
let size = bucket.table().size();
// Save the *starting point*.
let mut bucket = bucket.stash();
// There can be at most `size - dib` buckets to displace, because
Expand Down Expand Up @@ -744,10 +741,9 @@ impl<K, V, S> HashMap<K, V, S>
let h = bucket.hash();
let (b, k, v) = bucket.take();
self.insert_hashed_ordered(h, k, v);
{
let t = b.table(); // FIXME "lifetime too short".
if t.size() == 0 { break }
};
if b.table().size() == 0 {
break;
}
b.into_bucket()
}
Empty(b) => b.into_bucket()
Expand Down
18 changes: 9 additions & 9 deletions src/libstd/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn _var(key: &OsStr) -> Result<String, VarError> {
}

/// Fetches the environment variable `key` from the current process, returning
/// None if the variable isn't set.
/// `None` if the variable isn't set.
///
/// # Examples
///
Expand Down Expand Up @@ -617,7 +617,7 @@ pub mod consts {
#[stable(feature = "env", since = "1.0.0")]
pub const ARCH: &'static str = super::arch::ARCH;

/// The family of the operating system. In this case, `unix`.
/// The family of the operating system. Example value is `unix`.
///
/// Some possible values:
///
Expand All @@ -626,8 +626,8 @@ pub mod consts {
#[stable(feature = "env", since = "1.0.0")]
pub const FAMILY: &'static str = super::os::FAMILY;

/// A string describing the specific operating system in use: in this
/// case, `linux`.
/// A string describing the specific operating system in use.
/// Example value is `linux`.
///
/// Some possible values:
///
Expand All @@ -646,7 +646,7 @@ pub mod consts {
pub const OS: &'static str = super::os::OS;

/// Specifies the filename prefix used for shared libraries on this
/// platform: in this case, `lib`.
/// platform. Example value is `lib`.
///
/// Some possible values:
///
Expand All @@ -656,7 +656,7 @@ pub mod consts {
pub const DLL_PREFIX: &'static str = super::os::DLL_PREFIX;

/// Specifies the filename suffix used for shared libraries on this
/// platform: in this case, `.so`.
/// platform. Example value is `.so`.
///
/// Some possible values:
///
Expand All @@ -667,7 +667,7 @@ pub mod consts {
pub const DLL_SUFFIX: &'static str = super::os::DLL_SUFFIX;

/// Specifies the file extension used for shared libraries on this
/// platform that goes after the dot: in this case, `so`.
/// platform that goes after the dot. Example value is `so`.
///
/// Some possible values:
///
Expand All @@ -678,7 +678,7 @@ pub mod consts {
pub const DLL_EXTENSION: &'static str = super::os::DLL_EXTENSION;

/// Specifies the filename suffix used for executable binaries on this
/// platform: in this case, the empty string.
/// platform. Example value is `.exe`.
///
/// Some possible values:
///
Expand All @@ -690,7 +690,7 @@ pub mod consts {
pub const EXE_SUFFIX: &'static str = super::os::EXE_SUFFIX;

/// Specifies the file extension, if any, used for executable binaries
/// on this platform: in this case, the empty string.
/// on this platform. Example value is `exe`.
///
/// Some possible values:
///
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,7 @@ mod tests {
let tmpdir = tmpdir();
let dir = &tmpdir.join("fileinfo_false_on_dir");
check!(fs::create_dir(dir));
assert!(dir.is_file() == false);
assert!(!dir.is_file());
check!(fs::remove_dir(dir));
}

Expand Down
14 changes: 7 additions & 7 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,12 +1191,12 @@ impl<'a> Parser<'a> {
-> PResult<'a, TyKind> {
/*

[unsafe] [extern "ABI"] fn <'lt> (S) -> T
^~~~^ ^~~~^ ^~~~^ ^~^ ^
| | | | |
| | | | Return type
| | | Argument types
| | Lifetimes
[unsafe] [extern "ABI"] fn (S) -> T
^~~~^ ^~~~^ ^~^ ^
| | | |
| | | Return type
| | Argument types
| |
| ABI
Function Style
*/
Expand Down Expand Up @@ -2576,7 +2576,7 @@ impl<'a> Parser<'a> {
loop {
// expr?
while self.eat(&token::Question) {
let hi = self.span.hi;
let hi = self.last_span.hi;
e = self.mk_expr(lo, hi, ExprKind::Try(e), None);
}

Expand Down
2 changes: 1 addition & 1 deletion src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ mod tests {

assert_eq!(filtered.len(), 1);
assert_eq!(filtered[0].desc.name.to_string(), "1");
assert!(filtered[0].desc.ignore == false);
assert!(!filtered[0].desc.ignore);
}

#[test]
Expand Down
41 changes: 41 additions & 0 deletions src/test/compile-fail/bad-intrinsic-monomorphization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2016 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.

#![feature(repr_simd, platform_intrinsics, rustc_attrs, core_intrinsics)]
#![allow(warnings)]

// Bad monomorphizations could previously cause LLVM asserts even though the
// error was caught in the compiler.

extern "platform-intrinsic" {
fn simd_add<T>(x: T, y: T) -> T;
}

use std::intrinsics;

#[derive(Copy, Clone)]
struct Foo(i64);

unsafe fn test_cttz(v: Foo) -> Foo {
intrinsics::cttz(v)
//~^ ERROR `cttz` intrinsic: expected basic integer type, found `Foo`
}

unsafe fn test_fadd_fast(a: Foo, b: Foo) -> Foo {
intrinsics::fadd_fast(a, b)
//~^ ERROR `fadd_fast` intrinsic: expected basic float type, found `Foo`
}

unsafe fn test_simd_add(a: Foo, b: Foo) -> Foo {
simd_add(a, b)
//~^ ERROR `simd_add` intrinsic: expected SIMD input type, found non-SIMD `Foo`
}

fn main() {}
Loading