Commit Graph

78832 Commits

Author SHA1 Message Date
bors
e38554cd80 Auto merge of #51145 - petrochenkov:npbot, r=alexcrichton
resolve: Make sure indeterminate and inconsistent macro resolutions always generate errors

Addresses the issue described in https://github.com/rust-lang/rust/pull/50911#issuecomment-392560525

I haven't come up with a minimized reproduction yet, but confirmed that `npbot` now generates the correct error with `![feature(use_extern_macros)]`.
2018-05-31 03:18:00 +00:00
bors
c1287c0183 Auto merge of #51220 - nikomatsakis:issue-51008-false-positive-lifetime-must-be-declared, r=cramertj
reset anonymous-lifetime-mode as we enter `()` scopes

Background:

The anonymous lifetime mode is used to prohibit elided lifetimes where
they didn't used to be permitted, and instead require that `'_` be
used. For example:

```rust
impl Trait for Ref<T> { .. }
//             ^^^^^^ ERROR: should be `Ref<'_, T>`
```

When we are parsing the parts of the impl header, we enter into an alternate mode called `CreateParameter`. In this mode, we give an error for things like `Ref<T>`, but for elided lifetimes in a reference type like `&T` we make the elided lifetime into an in-band lifetime:

4f99f37b7e/src/librustc/hir/lowering.rs (L4017-L4035)

This was not intended to change behavior because we only enter into that mode in contexts where elision was not historically permitted. However, the problem is that we fail to reset the mode when we enter into bounds like `Fn(&u32)`, where elision *was* allowed -- the same occurs for fn types like `fn(&u32`). This PR restores the original mode in those contexts.

Fixes #51008

r? @cramertj
2018-05-31 01:06:33 +00:00
Nicholas Nethercote
a5ffcf6dd8 Inline NodeIndex methods.
Because they are small and hot.
2018-05-31 09:22:07 +10:00
Nicholas Nethercote
f46d0213e4 Remove ObligationForest::cache_list.
It's never used in a meaningful way.
2018-05-31 09:22:07 +10:00
bors
e1eed38fed Auto merge of #51138 - spastorino:add-polonius-compare-mode, r=pnkfelix
Add polonius compare mode

**This is now ready to review/merge**
2018-05-30 22:59:21 +00:00
bors
5d0631a643 Auto merge of #51215 - eddyb:visit-for-a-lifetime, r=nikomatsakis
rustc: don't visit lifetime parameters through visit_lifetime.

Ideally we'd also not use the `Lifetime` struct for parameters, but I'll leave that to @varkor (#48149).
Fixes #51185 (discovered while auditing all the `visit_lifetime` implementations).
r? @nikomatsakis
2018-05-30 20:34:23 +00:00
uuttff8
d6b8c67ee6
mod.rs isn't beautiful 2018-05-30 22:24:24 +03:00
Vadim Petrochenkov
345e7c3597 resolve: Make sure indeterminate and inconsistent macro resolutions always generate errors 2018-05-30 22:21:50 +03:00
Niko Matsakis
da69bbce68 also reset anon-param-mode for fn() types 2018-05-30 14:54:51 -04:00
Niko Matsakis
9acb351f57 reset the "anonymous lifetime mode" for parenthesized where clauses
Background:

The anonymous lifetime mode is used to prohibit elided lifetimes where
they didn't used to be permitted, and instead require that `'_` be
used. For example:

```rust
impl Trait for Ref<T> { .. }
//             ^^^^^^ ERROR: should be `Ref<'_, T>`
```

When we are parsing the parts of the impl header, we enter into an
alternate mode called `CreateParameter`. In this mode, we give an
error for things like `Ref<T>`, but for elided lifetimes in a
reference type like `&T` we make the elided lifetime into an in-band
lifetime:

4f99f37b7e/src/librustc/hir/lowering.rs (L4017-L4035)

This was not intended to change behavior because we only enter into
that mode in contexts where elision was not historically
permitted. However, the problem is that we fail to reset the mode when
we enter into bounds like `Fn(&u32)`, where elision *was* allowed --
the same occurs for fn types like `fn(&u32`). This PR restores the
original mode in those contexts.
2018-05-30 14:54:51 -04:00
Guillaume Girol
cb2a0d61ad std::fs::DirEntry.metadata(): use fstatat instead of lstat when possible 2018-05-30 20:52:30 +02:00
Santiago Pastorino
b39a1d6f1a
Run rustfmt 2018-05-30 14:36:23 -03:00
Santiago Pastorino
b970feedc2
Add compare-mode to x.py 2018-05-30 14:35:43 -03:00
Eduard-Mihai Burtescu
06d88cda08 rustc: rename mir::LocalDecl's syntactic_source_info to source_info. 2018-05-30 20:30:10 +03:00
Eduard-Mihai Burtescu
6c53972478 rustc: turn mir::LocalDecl's visibility_source_info into a SourceScope. 2018-05-30 20:30:10 +03:00
Eduard-Mihai Burtescu
3da186b67f rustc: use syntactic (instead of visibility) source info where appropriate. 2018-05-30 20:30:10 +03:00
Eduard-Mihai Burtescu
0895590c53 rustc: rename mir::LocalDecl's source_info to visibility_source_info. 2018-05-30 20:30:10 +03:00
Eduard-Mihai Burtescu
b10c157bd8 rustc: turn mir::LocalDecl's syntactic_scope into a SourceInfo. 2018-05-30 20:30:10 +03:00
Eduard-Mihai Burtescu
ca1ac6b6fb rustc: rename mir::SourceScopeInfo to mir::SourceScopeLocalData. 2018-05-30 20:30:09 +03:00
Eduard-Mihai Burtescu
85d44c4276 rustc: rename mir::VisibilityScope to mir::SourceScope. 2018-05-30 20:30:09 +03:00
Eduard-Mihai Burtescu
5c76b64546 rustc: don't visit lifetime parameters through visit_lifetime. 2018-05-30 20:29:38 +03:00
Eduard-Mihai Burtescu
a1433f2f88 syntax: remove overloading of fold_lifetime{,_def}{,s}. 2018-05-30 20:29:38 +03:00
Santiago Pastorino
9df0a41321
Add polonius compare mode 2018-05-30 14:03:31 -03:00
bors
fddb46eda3 Auto merge of #51100 - estebank:as-ref, r=oli-obk
Suggest using `as_ref` on some borrow errors [hack]

When encountering the following code:

```rust
struct Foo;
fn takes_ref(_: &Foo) {}
let ref opt = Some(Foo);

opt.map(|arg| takes_ref(arg));
```

Suggest using `opt.as_ref().map(|arg| takes_ref(arg));` instead.

This is a stop gap solution until we expand typeck to deal with these
cases in a more graceful way.

#43861
2018-05-30 16:48:53 +00:00
Esteban Küber
a19a03a31f Suggest using as_ref on some borrow errors [hack]
When encountering the following code:

```rust
struct Foo;
fn takes_ref(_: &Foo) {}
let ref opt = Some(Foo);

opt.map(|arg| takes_ref(arg));
```

Suggest using `opt.as_ref().map(|arg| takes_ref(arg));` instead.

This is a stop gap solution until we expand typeck to deal with these
cases in a more graceful way.
2018-05-30 09:47:09 -07:00
bors
74d09399c1 Auto merge of #50955 - steveklabnik:update-libbacktrace, r=alexcrichton
Update libbacktrace

We haven't updated libbacktrace in two years. This is just blindly updating to the latest HEAD; I'd like to see what travis says. It at least builds on my machine, running some tests...

This perpetuates the patches from https://github.com/rust-lang/rust/pull/30908
2018-05-30 14:19:15 +00:00
Alex Crichton
7c14a54bc8 Replace libbacktrace with a submodule
While we're at it update the `backtrace` crate from crates.io. It turns out that
the submodule's configure script has gotten a lot more finnicky as of late so
also switch over to using the `cc` crate manually which allows to avoid some
hacks around the configure script as well
2018-05-30 05:58:23 -07:00
Alex Crichton
1402a106bd std: Delete bundled libbacktrace module 2018-05-30 05:58:20 -07:00
bors
4f99f37b7e Auto merge of #50880 - glandium:oom, r=SimonSapin
OOM handling changes

As discussed in https://github.com/rust-lang/rust/issues/49668#issuecomment-384893456 and subsequent.

This does have codegen implications. Even without the hooks, and with a handler that ignores the arguments, the compiler doesn't eliminate calling `rust_oom` with the `Layout`. Even if it managed to eliminate that, with the hooks, I don't know if the compiler would be able to figure out it can skip it if the hook is never set.

A couple implementation notes:
- I went with explicit enums rather than bools because it makes it clearer in callers what is being requested.
- I didn't know what `feature` to put the hook setting functions behind. (and surprisingly, the compile went through without any annotation on the functions)
- There's probably some bikeshedding to do on the naming.

Cc: @Simonsapin, @sfackler
2018-05-30 11:35:00 +00:00
Nicolas Koch
c5ee3b6df1 Remobve unused import 2018-05-30 12:09:20 +02:00
bors
20af72b943 Auto merge of #51106 - davidtwco:issue-50934, r=nikomatsakis
Optimize the way that loans are killed in borrowck dataflow

Fixes #50934.
r? @nikomatsakis
2018-05-30 09:24:20 +00:00
bors
2408095f34 Auto merge of #51017 - estebank:crate-name-in-path, r=michaelwoerister
Use crate name for reexported `extern crate` paths

Fix #43189.
2018-05-30 07:10:16 +00:00
Nicolas Koch
9b6940d0b4 fs: copy: Use File::set_permissions instead of fs::set_permissions
We already got the open file descriptor at this point.
Don't make the kernel resolve the path again.
2018-05-30 06:33:54 +02:00
bors
8372e7b37e Auto merge of #50783 - pnkfelix:issue-27282-match-borrows-its-input-take-three, r=nikomatsakis
every match arm reads the match's borrowed input

This PR changes the `match` codegen under NLL (and just NLL, at least for now) to make the following adjustments:
 * It adds a `-Z disable-ast-check-for-mutation-in-guard` which, as described, turns off the naive (conservative but also not 100% sound) check for mutation in guards of match arms.
 * We now borrow the match input at the outset and emit a special `ReadForMatch` statement (that, according to the *static* semantics, reads that borrowed match input) at the start of each match arm. The intent here is to catch cases where the match guard mutates the match input, either via an independent borrow or via `ref mut` borrows in that arm's pattern.
 * In order to ensure that `ref mut` borrows do not actually conflict with the emitted `ReadForMatch` statements, I expanded the two-phase-borrow system slightly, and also changed the MIR code gen so that under NLL, when there is a guard on a match arm, then each pattern variable ends up having *three* temporaries associated with it:
   1. The first temporary will hold the substructure being matched; this is what we will move the (substructural) value into *if* the guard succeeds.
   2. The second temporary also corresponds to the same value as the first, but we are just constructing this temporarily for use during the scope of the guard; it is unaliased and its sole referrer is the third temporary.
   3. The third temporary is a reference to the second temporary.
   * (This sounds complicated, I know, but its actually *simpler* than what I was doing before and had checked into the repo, which was to sometimes construct the final value and then take a reference to it before evaluating the guard. See also PR #49870.)

Fix #27282

This also provides a path towards resolving #24535 aka rust-lang/rfcs#1006, at least once the `-Z disable-ast-check-for-mutation-in-guard` is just turned on by default (under NLL, that is. It is not sound under AST-borrowck).
 * But I did not want to make `#![feature(nll)]` imply that as part of this PR; that seemed like too drastic a change to me.
2018-05-30 02:11:59 +00:00
Mike Hommey
a4d899b4a1 Add hooks allowing to override the oom behavior 2018-05-30 10:57:38 +09:00
bors
ec99b220fe Auto merge of #50772 - nicokoch:fastcopy, r=alexcrichton
fs: copy: use copy_file_range on Linux

Linux 4.5 introduced a new system call [copy_file_range](http://man7.org/linux/man-pages/man2/copy_file_range.2.html) to copy data from one file to another.

This PR uses the new system call (if available). This has several advantages:

1. No need to constantly copy data from userspace to kernel space, if the buffer is small or the file is large
2. On some filesystems, like BTRFS, the kernel can leverage internal fs mechanisms for huge performance gains
3. Filesystems on the network dont need to copy data between the host and the client machine (they have to in the current read/write implementation)

I have created a small library that also implements the new system call for some huge performance gains here: https://github.com/nicokoch/fastcopy
Benchmark results are in the README
2018-05-29 23:49:11 +00:00
Guillaume Gomez
c7312fbae4 Fixes some style issues in rustdoc "implementations on Foreign types" 2018-05-30 01:12:23 +02:00
Nicolas Koch
c7d6a0130b Fix additional nits:
- compute bytes_to_copy more elegantly
  - add assert that written is 0 in fallback case
2018-05-29 23:42:42 +02:00
Felix S. Klock II
9d5cdc958d Review feedback: Adding test cases suggested by arielb1. 2018-05-29 23:02:40 +02:00
Felix S. Klock II
324ced89e8 Review feedback: Fix typo. 2018-05-29 23:02:40 +02:00
Felix S. Klock II
2f7f7ac14e Review feedback, remove fixme comment. 2018-05-29 23:02:40 +02:00
Felix S. Klock II
7f0c8f6638 Review feedback: Remove a fixme/tbd note and just add a note for the post-NLL future.
Driveby: just inline the two-line `fn inject_borrow` into its one call
site and remove its definition.
2018-05-29 23:02:40 +02:00
Felix S. Klock II
a4a5fa2934 Review feedback: update fixme comment to reflect reality. 2018-05-29 23:02:40 +02:00
Felix S. Klock II
2b5aa90500 review feedback: fix indentation of pattern candidates to match code elsewhere in file. 2018-05-29 23:02:40 +02:00
Felix S. Klock II
98d5e134f9 Tests illustrating the bug fixes for #27282 and #24535. 2018-05-29 23:02:40 +02:00
Felix S. Klock II
5eebd36c93 Test update: Fallout from ReadForMatch statements + changes to codegen under NLL. 2018-05-29 23:02:40 +02:00
Felix S. Klock II
3bc5073dbb Expand two-phase-borrows so that a case like this still compiles:
```rust
fn main() {
    fn reuse<X>(_: &mut X) {}
    let mut t = 2f64;
    match t {
        ref mut _b if { false } => { reuse(_b); }
        _ => {}
    }
}
```

Note: The way this is currently written is confusing; when `autoref`
is off, then the arm body bindings (introduced by
`bind_matched_candidate_for_arm_body`) are *also* used for the guard.
(Any attempt to fix this needs to still ensure that the bindings used
by the guard are introduced before the guard is evaluated.)

(Once we turn NLL on by default, we can presumably simplify all of
that.)
2018-05-29 23:02:40 +02:00
Felix S. Klock II
638acd300f Fallout from allowing some mutation in guards.
For some reason, allowing restricted mutation in match arms exposed an
obvious case where a unique borrow can indeed fail, namely something
like:

```rust
match b {
    ...
    ref mut r if { (|| { let bar = &mut *r; **bar = false; })(); false } => { &mut *r }
    //                             ~~~~~~~
    //                                |
    // This ends up holding a `&unique` borrow of `r`, but there ends up being an
    // implicit shared borrow in the guard thanks to rust-lang/rust#49870
    ...
}
```
2018-05-29 23:02:40 +02:00
Felix S. Klock II
5c30dc85c2 rust-lang/rust#41962 has a new error with my new code. Incorporate that into my code.
In particular, I am adding an implicit injected borrow on the pattern
matches, and when we go around the loop, the compiler is reporting
that this injected borrow is conflicting with the move of the original
value when the match succeeds.
2018-05-29 23:02:40 +02:00
Felix S. Klock II
173315e353 rust-lang/rust#27282: emit ReadForMatch on each match arm.
Also, turn on ReadForMatch emission by default (when using NLL).
2018-05-29 23:02:39 +02:00