Commit Graph

121197 Commits

Author SHA1 Message Date
Ralf Jung
32481bc80a
Rollup merge of #72757 - petrochenkov:shebang, r=varkor
rustc_lexer: Optimize shebang detection slightly

Sorry, I just couldn't resist.
It shouldn't make any difference in practice.

Also, documented a previously unnoticed case with doc comments treated as regular comments during shebang detection.
2020-05-30 23:08:58 +02:00
Ralf Jung
8f1c0d0a10
Rollup merge of #72728 - o01eg:fix-72661, r=Mark-Simulacrum
Make bootstrap aware of relative libdir in stage0 compiler

Follows up #72692

Fixes #72661
2020-05-30 23:08:57 +02:00
Ralf Jung
278e26eaf6
Rollup merge of #72669 - petrochenkov:smclean, r=Mark-Simulacrum
rustc_session: Cleanup session creation

Noticed while reviewing https://github.com/rust-lang/rust/pull/72618.
2020-05-30 23:08:55 +02:00
Ralf Jung
65a02f1841
Rollup merge of #72668 - awoimbee:give-fn-parenthetical-notation-parentheses, r=estebank
Fix missing parentheses Fn notation error

Fixes  #72611
Well, fixes the error output, I think E0658 is the right error to throw in this case so I didn't change that
2020-05-30 23:08:53 +02:00
Ralf Jung
ffe329250b
Rollup merge of #72666 - ivanloz:profile_emit_flag, r=matthewjasper
Add -Z profile-emit=<path> for Gcov gcda output.

Adds a -Z flag to control the file path that the Gcov gcda output is
written to during runtime. This flag expects a path and filename, e.g.
-Z profile-emit=gcov/out/lib.gcda.

This works similar to GCC/Clang's -fprofile-dir flag which allows
control over the output path for gcda coverage files.
2020-05-30 23:08:51 +02:00
Ralf Jung
320de71cdd
Rollup merge of #72657 - flip1995:impl_lint_pass-ty, r=matthewjasper
Allow types (with lifetimes/generics) in impl_lint_pass

cc https://github.com/rust-lang/rust-clippy/pull/5279#discussion_r430790267

This allows to implement `LintPass` for types with lifetimes and/or generics. The only thing, I'm not sure of is the `LintPass::name` function, which now includes the lifetime(s) (which will be `'_` most of the time) in the name returned for the lint pass, if it exists. But I don't think that this should be a problem, since the `LintPass::name` is never used for output for the user (?).
2020-05-30 23:08:49 +02:00
Ralf Jung
5f0aefda49
Rollup merge of #72650 - GuillaumeGomez:sort-sidebar-elements, r=kinnison
Sort sidebar elements

r? @kinnison
2020-05-30 23:08:47 +02:00
Ralf Jung
40fb1913e7
Rollup merge of #72637 - euclio:env-hygiene, r=davidtwco
expand `env!` with def-site context

Similar to #66349.

Fixes rust-lang/rust-clippy#5619.
2020-05-30 23:08:46 +02:00
Ralf Jung
fadfcb644e
Rollup merge of #72625 - Amanieu:asm-srcloc, r=petrochenkov
Improve inline asm error diagnostics

Previously we were just using the raw LLVM error output (with line, caret, etc) as the diagnostic message, which ends up looking rather out of place with our existing diagnostics.

The new diagnostics properly format the diagnostics and also take advantage of LLVM's per-line `srcloc` attribute to map an error in inline assembly directly to the relevant line of source code.

Incidentally also fixes #71639 by disabling `srcloc` metadata during LTO builds since we don't know what crate it might have come from. We can only resolve `srcloc`s from the currently crate since it indexes into the source map for the current crate.

Fixes #72664
Fixes #71639

r? @petrochenkov

### Old style

```rust
#![feature(llvm_asm)]

fn main() {
    unsafe {
        let _x: i32;
        llvm_asm!(
            "mov $0, $1
             invalid_instruction $0, $1
             mov $0, $1"
             : "=&r" (_x)
             : "r" (0)
             :: "intel"
        );
    }
}
```

```
error: <inline asm>:3:14: error: invalid instruction mnemonic 'invalid_instruction'
             invalid_instruction ecx, eax
             ^~~~~~~~~~~~~~~~~~~

  --> src/main.rs:6:9
   |
6  | /         llvm_asm!(
7  | |             "mov $0, $1
8  | |              invalid_instruction $0, $1
9  | |              mov $0, $1"
...  |
12 | |              :: "intel"
13 | |         );
   | |__________^
```

### New style

```rust
#![feature(asm)]

fn main() {
    unsafe {
        asm!(
            "mov {0}, {1}
             invalid_instruction {0}, {1}
             mov {0}, {1}",
            out(reg) _,
            in(reg) 0i64,
        );
    }
}
```

```
error: invalid instruction mnemonic 'invalid_instruction'
 --> test.rs:7:14
  |
7 |              invalid_instruction {0}, {1}
  |              ^
  |
note: instantiated into assembly here
 --> <inline asm>:3:14
  |
3 |              invalid_instruction rax, rcx
  |              ^^^^^^^^^^^^^^^^^^^
```
2020-05-30 23:08:44 +02:00
Ralf Jung
f1661d23e3
Rollup merge of #72543 - estebank:opaque-missing-lts-in-fn, r=nikomatsakis
Account for missing lifetime in opaque and trait object return types

When encountering an opaque closure return type that needs to bound a
lifetime to the function's arguments, including borrows and type params,
provide appropriate suggestions that lead to working code.

Get the user from

```rust
fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce()
where
    G: Get<T>
{
    move || {
        *dest = g.get();
    }
}
```

to

```rust
fn foo<'a, G: 'a, T>(g: G, dest: &'a mut T) -> impl FnOnce() +'a
where
    G: Get<T>
{
    move || {
        *dest = g.get();
    }
}
```
2020-05-30 23:08:42 +02:00
Esteban Küber
83f6f22358 Tweak wording and spans of 'static dyn Trait/impl Trait requirements 2020-05-30 10:22:27 -07:00
Esteban Küber
6dcd744df0 Consider all possible one letter lifetimes in suggestion 2020-05-30 10:22:27 -07:00
Esteban Küber
224ad326ea Account for enclosing item when suggesting new lifetime name 2020-05-30 10:22:27 -07:00
Esteban Küber
8f7ee34379 Tweak type parameter errors to reduce verbosity 2020-05-30 10:22:26 -07:00
Esteban Küber
1d9472b470 Update nll tests 2020-05-30 10:22:26 -07:00
Esteban Küber
731ea85f21 review comment: tweak wording and account for span overlap 2020-05-30 10:22:26 -07:00
Esteban Küber
65f492be12 Account for returned dyn Trait evaluating to 'static lifetime
Provide a suggestion for `dyn Trait + '_` when possible.
2020-05-30 10:22:26 -07:00
Esteban Küber
a724d9a4fb Fix NLL output 2020-05-30 10:21:58 -07:00
Esteban Küber
99d9ccd547 Improve output of argument anonymous borrow missing annotation involving opaque return type
Go from

```
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
  --> file8.rs:22:5
   |
22 | /     move || {
23 | |         *dest = g.get();
24 | |     }
   | |_____^
   |
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the function body at 18:1...
  --> file8.rs:18:1
   |
18 | / fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
19 | | where
20 | |     G: Get<T>
21 | | {
...  |
24 | |     }
25 | | }
   | |_^
note: ...so that the types are compatible
  --> file8.rs:22:5
   |
22 | /     move || { //~ ERROR cannot infer an appropriate lifetime
23 | |         *dest = g.get();
24 | |     }
   | |_____^
   = note: expected  `&mut T`
              found  `&mut T`
note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 18:8...
  --> file8.rs:18:8
   |
18 | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
   |        ^^
note: ...so that return value is valid for the call
  --> file8.rs:18:45
   |
18 | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
   |                                             ^^^^^^^^^^^^^^^^^^^^^^^
```

to

```
error[E0621]: explicit lifetime required in the type of `dest`
  --> file8.rs:18:45
   |
18 | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
   |                                  ------     ^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
   |                                  |
   |                                  help: add explicit lifetime `'a` to the type of `dest`: `&'a mut T`
   ```
2020-05-30 10:21:58 -07:00
Esteban Küber
f49ebbb891 Account for missing lifetime in opaque return type
When encountering an opaque closure return type that needs to bound a
lifetime to the function's arguments, including borrows and type params,
provide appropriate suggestions that lead to working code.

Get the user from

```rust
fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce()
where
    G: Get<T>
{
    move || {
        *dest = g.get();
    }
}
```

to

```rust
fn foo<'a, G: 'a, T>(g: G, dest: &'a mut T) -> impl FnOnce() +'a
where
    G: Get<T>
{
    move || {
        *dest = g.get();
    }
}
```
2020-05-30 10:19:41 -07:00
Arthur Woimbée
c54d4fe93f Test ui suggestion fn trait notation 2020-05-30 18:40:42 +02:00
Arthur Woimbée
5a813b6dd6 Fix missing parentheses Fn notation error 2020-05-30 18:40:41 +02:00
Ralf Jung
0fb6e63c04 encode_utf8_raw is not always valid UTF-8; clarify comments 2020-05-30 17:27:34 +02:00
marmeladema
372ba2a03d Use LocalDefId instead of NodeId in resolve_str_path_error 2020-05-30 16:11:58 +01:00
bors
74e8046834 Auto merge of #72778 - RalfJung:rollup-f01z68m, r=RalfJung
Rollup of 9 pull requests

Successful merges:

 - #72299 (more `LocalDefId`s)
 - #72368 (Resolve overflow behavior for RangeFrom)
 - #72441 (Fix ICE with explicit late-bound lifetimes)
 - #72499 (Override Box::<[T]>::clone_from)
 - #72521 (Properly handle InlineAsmOperand::SymFn when collecting monomorphized items)
 - #72540 (mir: adjust conditional in recursion limit check)
 - #72563 (multiple Return terminators are possible)
 - #72585 (Only capture tokens for items with outer attributes)
 - #72607 (Eagerly lower asm sub-expressions to HIR even if there is an error)

Failed merges:

r? @ghost
2020-05-30 12:49:47 +00:00
Felix S Klock II
a8e4236edc
add fixme suggested by eddyb 2020-05-30 08:19:35 -04:00
Ralf Jung
69310dea89
Rollup merge of #72607 - Amanieu:fix-72570, r=oli-obk
Eagerly lower asm sub-expressions to HIR even if there is an error

Fixes #72570

r? @oli-obk
2020-05-30 13:45:15 +02:00
Ralf Jung
e4c35246fc
Rollup merge of #72585 - Aaron1011:feature/opt-item-tokens, r=petrochenkov
Only capture tokens for items with outer attributes

Suggested by @petrochenkov in https://github.com/rust-lang/rust/issues/43081#issuecomment-633389225
2020-05-30 13:45:13 +02:00
Ralf Jung
6238e79fb6
Rollup merge of #72563 - RalfJung:multi-return, r=matthewjasper
multiple Return terminators are possible

@ecstatic-morse mentioned in https://github.com/rust-lang/rust/issues/72515 that multiple `Return` terminators are possible. Update the docs accordingly.

Cc @rust-lang/wg-mir-opt
2020-05-30 13:45:11 +02:00
Ralf Jung
f96e3e2069
Rollup merge of #72540 - davidtwco:issue-67552-mono-collector-comparison, r=varkor
mir: adjust conditional in recursion limit check

Fixes #67552.

This PR adjusts the condition used in the recursion limit check of
the monomorphization collector, from `>` to `>=`.

In #67552, the test case had infinite indirect recursion, repeating a
handful of functions (from the perspective of the monomorphization
collector): `rec` -> `identity` -> `Iterator::count` -> `Iterator::fold`
-> `Iterator::next` -> `rec`.

During this process, `resolve_associated_item` was invoked for
`Iterator::fold` (during the construction of an `Instance`), and
ICE'd due to substitutions needing inference. However, previous
iterations of this recursion would have called this function for
`Iterator::fold` - and did! - and succeeded in doing so (trivially
checkable from debug logging, `()` is present where `_` is in the substs
of the failing execution).

The expected outcome of this test case would be a recursion limit error
(which is present when the `identity` fn indirection is removed), and
the recursion depth of `rec` is increasing (other functions finish
collecting their neighbours and thus have their recursion depths reset).

When the ICE occurs, the recursion depth of `rec` is 256 (which matches
the recursion limit), which suggests perhaps that a different part of
the compiler is using a `>=` comparison and returning a different result
on this recursion rather than what it returned in every previous
recursion, thus stopping the monomorphization collector from reporting
an error on the next recursion, where `recursion_depth_of_rec > 256`
would have been true.

With grep and some educated guesses, we can determine that
the recursion limit check at line 818 in
`src/librustc_trait_selection/traits/project.rs` is the other check that
is using a different comparison. Modifying either comparison to be `>` or
`>=` respectively will fix the error, but changing the monomorphization
collector produces the nicer error.
2020-05-30 13:45:10 +02:00
Ralf Jung
43ae54de9c
Rollup merge of #72521 - Amanieu:fix-72484, r=petrochenkov
Properly handle InlineAsmOperand::SymFn when collecting monomorphized items

Fixes #72484
2020-05-30 13:45:08 +02:00
Ralf Jung
8d64fd80ad
Rollup merge of #72499 - mendess:master, r=dtolnay
Override Box::<[T]>::clone_from

Avoid dropping and reallocating when cloning to an existing box if the lengths are the same.

It would be nice if this could also be specialized for `Copy` but I don't know how that works since it's not on stable. Will gladly look into it if it's deemed as a good idea.

This is my first PR with code, hope I did everything right 😄
2020-05-30 13:45:06 +02:00
Ralf Jung
49ca99de93
Rollup merge of #72441 - doctorn:late-bound-lifetime-ice, r=nikomatsakis
Fix ICE with explicit late-bound lifetimes

Rather than returning an explicit late-bound lifetime as a generic argument count mismatch (which is not necessarily true), this PR propagates the presence of explicit late-bound lifetimes.

This avoids an ICE that can occur due to the presence of explicit late-bound lifetimes when building generic substitutions by explicitly ignoring them.

r? @varkor

cc @davidtwco (this removes a check you introduced in #60892)

Resolves #72278
2020-05-30 13:45:04 +02:00
Ralf Jung
93d45a01e7
Rollup merge of #72368 - CAD97:rangeto, r=dtolnay
Resolve overflow behavior for RangeFrom

This specifies a documented unspecified implementation detail of `RangeFrom` and makes it consistently implement the specified behavior.

Specifically, `(u8::MAX).next()` is defined to cause an overflow, and resolve that overflow in the same manner as the `Step::forward` implementation.

The inconsistency that has existed is `<RangeFrom as Iterator>::nth`. The existing behavior should be plain to see after #69659: the skipping part previously always panicked if it caused an overflow, but the final step (to set up the state for further iteration) has always been debug-checked.

The inconsistency, then, is that `RangeFrom::nth` does not implement the same behavior as the naive (and default) implementation of just calling `next` multiple times. This PR aligns `RangeFrom::nth` to have identical behavior to the naive implementation. It also lines up with the standard behavior of primitive math in Rust everywhere else in the language: debug checked overflow.

cc @Amanieu

---

Followup to #69659. Closes #25708 (by documenting the panic as intended).

The documentation wording is preliminary and can probably be improved.

This will probably need an FCP, as it changes observable stable behavior.
2020-05-30 13:45:02 +02:00
Ralf Jung
35db8196f9
Rollup merge of #72299 - lcnr:sized_help, r=petrochenkov
more `LocalDefId`s
2020-05-30 13:45:00 +02:00
marmeladema
4b7e44f893 rustdoc: remove calls to local_def_id_from_node_id 2020-05-30 12:30:58 +01:00
Oliver Scherer
0aa7f4d2f2 Make TLS accesses explicit in MIR 2020-05-30 12:59:05 +02:00
Bastian Kauschke
49b1b4c438 more LocalDefIds 2020-05-30 12:22:29 +02:00
Ralf Jung
9c627c33dd also expose and use encode_utf16_raw for wtf8 2020-05-30 12:11:21 +02:00
Ralf Jung
3182cdf9ba wtf8: use encode_utf8_raw 2020-05-30 11:53:50 +02:00
Ralf Jung
72d85db6ee expose char::encode_utf8_raw for libstd 2020-05-30 11:49:31 +02:00
Yuki Okushi
77503578e1
Return early to avoid ICE 2020-05-30 18:48:54 +09:00
Ralf Jung
8ef9392828 multiple Return terminators are possible 2020-05-30 11:22:56 +02:00
bors
91fb72a8a9 Auto merge of #72768 - JohnTitor:rollup-6kwokh6, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #72033 (Update RELEASES.md for 1.44.0)
 - #72162 (Add Extend::{extend_one,extend_reserve})
 - #72419 (Miri read_discriminant: return a scalar instead of raw underlying bytes)
 - #72621 (Don't bail out of trait selection when predicate references an error)
 - #72677 (Fix diagnostics for `@ ..` binding pattern in tuples and tuple structs)
 - #72710 (Add test to make sure -Wunused-crate-dependencies works with tests)
 - #72724 (Revert recursive `TokenKind::Interpolated` expansion for now)
 - #72741 (Remove unused mut from long-linker-command-lines test)
 - #72750 (Remove remaining calls to `as_local_node_id`)
 - #72752 (remove mk_bool)

Failed merges:

r? @ghost
2020-05-30 07:56:05 +00:00
Ralf Jung
f8d3805733 miri validation: clarify valid values of 'char' 2020-05-30 09:33:05 +02:00
Felix S. Klock II
5e5a3d5867 Use the virtual name for libstd files in StableSourceFileId and also in the
encoded build artifacts.

Fix #70924.
2020-05-29 23:41:47 -04:00
Felix S. Klock II
da09fd3db0 Split payload of FileName::Real to track both real and virutalized paths.
Such splits arise from metadata refs into libstd.

This way, we can (in a follow on commit) continue to emit the virtual name into
things like the like the StableSourceFileId that ends up in incremetnal build
artifacts, while still using the devirtualized file path when we want to access
the file.

Note that this commit is intended to be a refactoring; the actual fix to the bug
in question is in a follow-on commit.
2020-05-29 23:41:45 -04:00
Yuki Okushi
025058f2aa
Rollup merge of #72752 - lcnr:remove-mk_bool, r=estebank
remove mk_bool
2020-05-30 12:39:24 +09:00
Yuki Okushi
c20a97dd53
Rollup merge of #72750 - marmeladema:remove-as-local-node-id, r=petrochenkov
Remove remaining calls to `as_local_node_id`

Split out from https://github.com/rust-lang/rust/pull/72552

cc https://github.com/rust-lang/rust/issues/50928
2020-05-30 12:39:23 +09:00
Yuki Okushi
990195faf8
Rollup merge of #72741 - tmiasko:unused-mut, r=Mark-Simulacrum
Remove unused mut from long-linker-command-lines test
2020-05-30 12:39:21 +09:00