Commit graph

139135 commits

Author SHA1 Message Date
Dylan DPC
e2561c58a4
Rollup merge of #82296 - spastorino:pubrules, r=nikomatsakis
Support `pub` on `macro_rules`

This rebases and updates `since` version of #78166 from ``@petrochenkov``

r? ``@nikomatsakis``
2021-02-23 16:10:23 +01:00
Dylan DPC
2982ba50fc
Rollup merge of #82258 - tmiasko:foreign-hir-stats, r=davidtwco
Implement -Z hir-stats for nested foreign items

An attempt to compute HIR stats for crates with nested foreign items results in an ICE.

```rust
fn main() {
    extern "C" { fn f(); }
}
```

```
thread 'rustc' panicked at 'visit_nested_xxx must be manually implemented in this visitor'
```

Provide required implementation of visitor method.
2021-02-23 16:10:22 +01:00
Dylan DPC
547b3adfe4
Rollup merge of #82113 - m-ou-se:panic-format-lint, r=estebank
Improve non_fmt_panic lint.

This change:
- fixes the span used by this lint in the case the panic argument is a single macro expansion (e.g. `panic!(a!())`);
- adds a suggestion for `panic!(format!(..))` to remove `format!()` instead of adding `"{}", ` or using `panic_any` like it does now; and
- fixes the incorrect suggestion to replace `panic![123]` by `panic_any(123]`.

Fixes #82109.
Fixes #82110.
Fixes #82111.

Example output:
```
warning: panic message is not a string literal
 --> src/main.rs:8:12
  |
8 |     panic!(format!("error: {}", "oh no"));
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(non_fmt_panic)]` on by default
  = note: this is no longer accepted in Rust 2021
  = note: the panic!() macro supports formatting, so there's no need for the format!() macro here
help: remove the `format!(..)` macro call
  |
8 |     panic!("error: {}", "oh no");
  |           --                  --

```

r? `@estebank`
2021-02-23 16:10:21 +01:00
Dylan DPC
18d1284433
Rollup merge of #81629 - 1000teslas:issue-81365-fix, r=Aaron1011
Point out implicit deref coercions in borrow

Fixes #81365

`@Aaron1011` I'm not sure why my code shows the note even in an implicit `Deref` call. See the output for `issue-81365-8.rs`.
2021-02-23 16:10:20 +01:00
LeSeulArtichaut
a6eb836ff0 Use #[doc = include_str!()] in std 2021-02-23 15:54:55 +01:00
Aaron Hill
46db4bab0b
Skip emitting closure diagnostic when closure_kind_origins has no entry
Fixes #82438

This map is not guarnateed to have an entry for a closure.
2021-02-23 09:46:20 -05:00
bors
0196107543 Auto merge of #82127 - tgnottingham:tune-ahead-of-time-codegen, r=varkor
rustc_codegen_ssa: tune codegen according to available concurrency

This change tunes ahead-of-time codegening according to the amount of
concurrency available, rather than according to the number of CPUs on
the system. This can lower memory usage by reducing the number of
compiled LLVM modules in memory at once, particularly across several
rustc instances.

Previously, each rustc instance would assume that it should codegen
ahead of time to meet the demand of number-of-CPUs workers. But often, a
rustc instance doesn't have nearly that much concurrency available to
it, because the concurrency availability is split, via the jobserver,
across all active rustc instances spawned by the driving cargo process,
and is further limited by the `-j` flag argument. Therefore, each rustc
might have had several times the number of LLVM modules in memory than
it really needed to meet demand. If the modules were large, the effect
on memory usage would be noticeable.

With this change, the required amount of ahead-of-time codegen scales up
with the actual number of workers running within a rustc instance. Note
that the number of workers running can be less than the actual
concurrency available to a rustc instance. However, if more concurrency
is actually available, workers are spun up quickly as job tokens are
acquired, and the ahead-of-time codegen scales up quickly as well.
2021-02-23 14:38:45 +00:00
Corey Farwell
f94c15c5a3 Fix typo in sanitizer flag in unstable book. 2021-02-23 09:10:11 -05:00
Joshua Nelson
ea3118ca0d Fix link 2021-02-23 08:54:18 -05:00
Joshua Nelson
2179313dcf Convert core/num/mod.rs to intra-doc links 2021-02-23 08:54:16 -05:00
Dan Gohman
132ec261b0 Enable API documentation for std::os::wasi.
This adds API documentation support for `std::os::wasi` modeled after
how `std::os::unix` works, so that WASI can be documented [here] along
with the other platforms.

[here]: https://doc.rust-lang.org/stable/std/os/index.html

Two changes of particular interest:

 - This changes the `AsRawFd` for `io::Stdin` for WASI to return
   `libc::STDIN_FILENO` instead of `sys::stdio::Stdin.as_raw_fd()` (and
   similar for `Stdout` and `Stderr`), which matches how the `unix`
   version works. `STDIN_FILENO` etc. may not always be explicitly
   reserved at the WASI level, but as long as we have Rust's `std` and
   `libc`, I think it's reasonable to guarantee that we'll always use
   `libc::STDIN_FILENO` for stdin.

 - This duplicates the `osstr2str` utility function, rather than
   trying to share it across all the configurations that need it.
2021-02-23 05:40:08 -08:00
bors
a5c5c8f3b0 Auto merge of #6781 - matthiaskrgr:lintcheck_fix, r=matthiaskrgr
lintcheck fix build (forgot to pass function parameter) and runtime (…

…don't check metadata of directory if it does not exist)

Accidentally broke lintcheck in my previous commit.

changelog: None
2021-02-23 12:05:24 +00:00
Matthias Krüger
eaae95b613 lintcheck fix build (forgot to pass function parameter) and runtime (don't check metadata of directory if it does not exist) 2021-02-23 12:58:12 +01:00
bors
446d4533e8 Auto merge of #82102 - nagisa:nagisa/fix-dwo-name, r=davidtwco
Set path of the compile unit to the source directory

As part of the effort to implement split dwarf debug info, we ended up
setting the compile unit location to the output directory rather than
the source directory. Furthermore, it seems like we failed to remap the
prefixes for this as well!

The desired behaviour is to instead set the `DW_AT_GNU_dwo_name` to a
path relative to compiler's working directory. This still allows
debuggers to find the split dwarf files, while not changing the
behaviour of the code that is compiling with regular debug info, and not
changing the compiler's behaviour with regards to reproducibility.

Fixes #82074

cc `@alexcrichton` `@davidtwco`
2021-02-23 10:02:16 +00:00
bors
f02df27f04 Auto merge of #6780 - matthiaskrgr:lintcheck2, r=flip1995
lintcheck: fully rerun lintcheck if clippy was rebuilt since last log update

Automatically clean lintchecks shared target dir (will force clippy to recheck sources) if
the clippy binaries are older than the lintcheck logs.

Also updated lintcheck logs in the pr.

changelog: lintcheck: fully rerun lintcheck if clippy was rebuilt since last log update
2021-02-23 08:31:28 +00:00
Ömer Sinan Ağacan
fa74d489a2 Improve error msgs when found type is deref of expected
This improves help messages in two cases:

- When expected type is `T` and found type is `&T`, we now look through blocks
  and suggest dereferencing the expression of the block, rather than the whole
  block.

- In the above case, if the expression is an `&`, we not suggest removing the
  `&` instead of adding `*`.

Both of these are demonstrated in the regression test. Before this patch the
first error in the test would be:

    error[E0308]: `if` and `else` have incompatible types
     --> test.rs:8:9
      |
    5 | /     if true {
    6 | |         a
      | |         - expected because of this
    7 | |     } else {
    8 | |         b
      | |         ^ expected `usize`, found `&usize`
    9 | |     };
      | |_____- `if` and `else` have incompatible types
      |
    help: consider dereferencing the borrow
      |
    7 |     } else *{
    8 |         b
    9 |     };
      |

Now:

    error[E0308]: `if` and `else` have incompatible types
     --> test.rs:8:9
      |
    5 | /     if true {
    6 | |         a
      | |         - expected because of this
    7 | |     } else {
    8 | |         b
      | |         ^
      | |         |
      | |         expected `usize`, found `&usize`
      | |         help: consider dereferencing the borrow: `*b`
    9 | |     };
      | |_____- `if` and `else` have incompatible types

The second error:

    error[E0308]: `if` and `else` have incompatible types
      --> test.rs:14:9
       |
    11 | /     if true {
    12 | |         1
       | |         - expected because of this
    13 | |     } else {
    14 | |         &1
       | |         ^^ expected integer, found `&{integer}`
    15 | |     };
       | |_____- `if` and `else` have incompatible types
       |
    help: consider dereferencing the borrow
       |
    13 |     } else *{
    14 |         &1
    15 |     };
       |

now:

    error[E0308]: `if` and `else` have incompatible types
      --> test.rs:14:9
       |
    11 | /     if true {
    12 | |         1
       | |         - expected because of this
    13 | |     } else {
    14 | |         &1
       | |         ^-
       | |         ||
       | |         |help: consider removing the `&`: `1`
       | |         expected integer, found `&{integer}`
    15 | |     };
       | |_____- `if` and `else` have incompatible types

Fixes #82361
2021-02-23 10:50:06 +03:00
Matthias Krüger
363f6d3dc6 lintcheck: rerun if clippy changed
Automatically clean lintchecks shared target dir (will force clippy to recheck sources) if
the clippy binaries are older than the lintcheck logs.

Also update lintcheck logs
2021-02-23 08:32:50 +01:00
bors
cd64446196 Auto merge of #82076 - jyn514:update-bootstrap, r=Mark-Simulacrum
Update the bootstrap compiler

This updates the bootstrap compiler, notably leaving out a change to enable semicolon in macro expressions lint, because stdarch still depends on the old behavior.
2021-02-23 07:19:41 +00:00
kadmin
899f27d272 Small optimizations to obligation forest 2021-02-23 07:16:42 +00:00
bors
0984754dd7 Auto merge of #6777 - giraffate:remove_unneeded_blank_lines_from_doc, r=phansch
Remove unneeded blank lines from doc

Remove unneeded blank lines like below.
<img width="1142" alt="スクリーンショット 2021-02-22 23 01 17" src="https://user-images.githubusercontent.com/17407489/108719295-bb9ff800-7562-11eb-9338-8f2571e61c56.png">

changelog: none
2021-02-23 06:05:27 +00:00
bors
a3127fafb4 Auto merge of #6774 - Y-Nak:quick-fix-bless, r=phansch
Quick fix cargo dev bless

fixes #6757
r? `@phansch`

Trying to do a quick fix of `bless`, I'm not sure how much work it will need to do transition to `bless` built in `compiletest`, so please feel free to close this PR if it will not need so much.

changelog: none
2021-02-23 05:53:59 +00:00
bors
a4e595db8f Auto merge of #82430 - Dylan-DPC:rollup-nu4kfyc, r=Dylan-DPC
Rollup of 12 pull requests

Successful merges:

 - #79423 (Enable smart punctuation)
 - #81154 (Improve design of `assert_len`)
 - #81235 (Improve suggestion for tuple struct pattern matching errors.)
 - #81769 (Suggest `return`ing tail expressions that match return type)
 - #81837 (Slight perf improvement on char::to_ascii_lowercase)
 - #81969 (Avoid `cfg_if` in `std::os`)
 - #81984 (Make WASI's `hard_link` behavior match other platforms.)
 - #82091 (use PlaceRef abstractions more consistently)
 - #82128 (add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice)
 - #82166 (add s390x-unknown-linux-musl target)
 - #82234 (Remove query parameters when skipping search results)
 - #82255 (Make `treat_err_as_bug` Option<NonZeroUsize>)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-23 04:31:32 +00:00
Aaron Hill
c9d86aae83
Set RUST_BACKTRACE=0 when running treat-err-as-bug tests
These ensure that these tests pass regardless of what RUST_BACKTRACE is
set to in the user's shell.
2021-02-22 21:07:40 -05:00
Dylan DPC
0e5bca5f51
Rollup merge of #82255 - nhwn:nonzero-err-as-bug, r=davidtwco
Make `treat_err_as_bug` Option<NonZeroUsize>

`rustc -Z treat-err-as-bug=N` already requires `N` to be nonzero when the argument is parsed, so changing the type from `Option<usize>` to `Option<NonZeroUsize>` is a low-hanging fruit in terms of layout optimization.
2021-02-23 02:51:55 +01:00
Dylan DPC
8541435e8d
Rollup merge of #82234 - GuillaumeGomez:remove-query-param-on-esc, r=Nemo157
Remove query parameters when skipping search results

Fixes #81330.

This PR changes the following: when pressing ESC and that no other "action" was performed (understand: no closing the search result, or hiding a menu or something along the line), then we discard the URL query parameters (the `?whatever=dsjfs`). What do you think about this change ```@rust-lang/rustdoc``` ?

EDIT: finally we're simply removing the query parameter when we're skipping the search results.

r? ```@Nemo157```
2021-02-23 02:51:54 +01:00
Dylan DPC
8979fd4237
Rollup merge of #82166 - kaniini:s390x-musl-target, r=nagisa
add s390x-unknown-linux-musl target

This is the first step in bringup for Rust on s390x.

The libc and std crates need modifications as well, but getting this upstream makes that work easier.
2021-02-23 02:51:53 +01:00
Dylan DPC
b8d4354099
Rollup merge of #82128 - anall:feature/add_diagnostic_items, r=davidtwco
add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice

This is adding diagnostic items to be used by rust-lang/rust-clippy#6730, but my understanding is the clippy-side change does need to be done over there since I am adding a new clippy feature.

Add diagnostic items to the following types:
  OsString (os_string_type)
  PathBuf (path_buf_type)
  Owned (to_owned_trait)

As well as the to_vec method on slice/[T]
2021-02-23 02:51:51 +01:00
Dylan DPC
cc07061190
Rollup merge of #82091 - henryboisdequin:use-place-ref-more, r=RalfJung
use PlaceRef abstractions more consistently

Addresses this [comment](https://github.com/rust-lang/rust/pull/80865/files#r558978715)
Associated issue: #80647

r? ```@RalfJung```
2021-02-23 02:51:50 +01:00
Dylan DPC
7b9ef2fde4
Rollup merge of #81984 - sunfishcode:wasi-link, r=alexcrichton
Make WASI's `hard_link` behavior match other platforms.

Following #78026, `std::fs::hard_link` on most platforms does not follow
symlinks. Change the WASI implementation to also not follow symlinks.

r? ```@alexcrichton```
2021-02-23 02:51:49 +01:00
Dylan DPC
c3de8ab908
Rollup merge of #81969 - jonas-schievink:no-cfg-if, r=Mark-Simulacrum
Avoid `cfg_if` in `std::os`

rust-analyzer cannot currently load the `cfg_if` crate, which means that rust-analyzer is unable to see `std::os::{unix, windows, linux}` here. This works around that by avoiding `cfg_if`; the `#[cfg]` expressions are simple enough to reasonably write by hand.

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/6038
2021-02-23 02:51:48 +01:00
Dylan DPC
4af965e732
Rollup merge of #81837 - gilescope:to_ascii_speedups, r=dtolnay
Slight perf improvement on char::to_ascii_lowercase

`char::to_ascii_lowercase()` was checking if it was ascii and then if it was in the right range. Instead propose to check once (I think removing a compare and a shift in the process: [godbolt](https://godbolt.org/z/e5Tora) ).

before:
```
        test char::methods::bench_to_ascii_lowercase                    ... bench:      11,196 ns/iter (+/- 632)
        test char::methods::bench_to_ascii_uppercase                    ... bench:      11,656 ns/iter (+/- 671)
```
after:
```
         test char::methods::bench_to_ascii_lowercase                    ... bench:       9,612 ns/iter (+/- 979)
         test char::methods::bench_to_ascii_uppercase                    ... bench:       8,241 ns/iter (+/- 701)
```

(calling u8::to_ascii_lowercase and letting that flip the 5th bit is also an option, but it's more instructions. I'm thinking for things around ascii and char we want to be as efficient as possible.)
2021-02-23 02:51:47 +01:00
Dylan DPC
5d90e89c36
Rollup merge of #81769 - estebank:tail-expr-as-potential-return, r=lcnr
Suggest `return`ing tail expressions that match return type

Some newcomers are confused by the behavior of tail expressions,
interpreting that "leaving out the `;` makes it the return value".
To help them go in the right direction, suggest using `return` instead
when applicable.
2021-02-23 02:51:46 +01:00
Dylan DPC
8e51bd4315
Rollup merge of #81235 - reese:rw-tuple-diagnostics, r=estebank
Improve suggestion for tuple struct pattern matching errors.

Closes #80174

This change allows numbers to be parsed as field names when pattern matching on structs, which allows us to provide better error messages when tuple structs are matched using a struct pattern.

r? ``@estebank``
2021-02-23 02:51:44 +01:00
Dylan DPC
72e6d51583
Rollup merge of #81154 - dylni:improve-design-of-assert-len, r=KodrAus
Improve design of `assert_len`

It was discussed in the [tracking issue](https://github.com/rust-lang/rust/issues/76393#issuecomment-761765448) that `assert_len`'s name and usage are confusing. This PR improves them based on a suggestion by ``@scottmcm`` in that issue.

I also improved the documentation to make it clearer when you might want to use this method.

Old example:

```rust
let range = range.assert_len(slice.len());
```

New example:

```rust
let range = range.ensure_subset_of(..slice.len());
```

Fixes #81157
2021-02-23 02:51:43 +01:00
Dylan DPC
1c2a949736
Rollup merge of #79423 - camelid:smart-punct, r=jyn514
Enable smart punctuation

Closes #76690.
2021-02-23 02:51:42 +01:00
bors
b02a6193b3 Auto merge of #81937 - ssomers:btree_drainy_refactor_9b, r=Mark-Simulacrum
BTree: move more shared iterator code into navigate.rs

The functions in navigate.rs only exist to support iterators, and these look easier on my eyes if there is a shared `struct` with the recurring pair of handles.

r? `@Mark-Simulacrum`
2021-02-23 00:30:37 +00:00
Dan Gohman
e8dcc02dc5 Add a size() function to WASI's MetadataExt.
WASI's `filestat` type includes a size field, so expose it in
`MetadataExt` via a `size()` function, similar to the corresponding Unix
function.
2021-02-22 14:42:59 -08:00
Vadim Petrochenkov
fc9d578bc5 expand: Preserve order of inert attributes during expansion 2021-02-23 01:07:22 +03:00
Vadim Petrochenkov
c02d21033d Add tests 2021-02-23 00:45:53 +03:00
bors
11f838d64a Auto merge of #81978 - tmiasko:head-ctor, r=Mark-Simulacrum
Inline hot part of PatStack::head_ctor

When building rustc with `-Codegen-units=1` this inline hint ensures
that obtaining already initialized head constructor does not involve
a function call overhead and reduces the instruction count in
match-stress-enum-check full benchmark from 11.9G to 9.8G.

It shouldn't have significant impact on the currently default
configuration where it reflects existing inlining decisions.
2021-02-22 21:45:50 +00:00
Simon Vandel Sillesen
a6dccfeb23 New mir-opt pass to simplify gotos with const values
Fixes #77355
2021-02-22 21:03:57 +01:00
Jonas Schievink
7bc501687b Avoid cfg_if in std::os 2021-02-22 19:56:20 +01:00
Camelid
e4ac499b7e Remove many RefCells from DocContext
I left some of them so this change doesn't balloon in size and because
removing the RefCell in `DocContext.resolver` would require compiler
changes.

Thanks to `@jyn514` for making this a lot easier with #82020!
2021-02-22 10:02:56 -08:00
bors
a15f484b91 Auto merge of #81362 - ssomers:btree_drainy_refactor_8, r=Mark-Simulacrum
BTreeMap: gather and decompose reusable tree fixing functions

This is kind of pushing it as a standalone refactor, probably only useful for #81075 (or similar).
r? `@Mark-Simulacrum`
2021-02-22 17:56:43 +00:00
Simonas Kazlauskas
24c23f5404 Test hexagon-enum only when llvm target is present
See https://github.com/rust-lang/rust/pull/82379#issuecomment-783439754
2021-02-22 19:10:02 +02:00
0yoyoyo
75d1e303af Update test cases 2021-02-22 23:39:06 +09:00
Ömer Sinan Ağacan
2145a8770c Fix mir-cfg dumps
Fixes #81918
Fixes #82326 (duplicate)
Fixes #82325
2021-02-22 17:36:30 +03:00
Takayuki Nakata
e05965eb13 Remove unneeded blank lines from doc 2021-02-22 23:02:04 +09:00
Ömer Sinan Ağacan
c0c4436011 Remove a redundant macro
Turn the macro into a function. Also remove unused 'span' argument.
2021-02-22 16:55:20 +03:00
Richard Dodd
0d6640a5b0 Add impl Error for Arc 2021-02-22 12:49:42 +00:00