Commit graph

135377 commits

Author SHA1 Message Date
bors
1e88a1769f Auto merge of #80205 - tomprogrammer:prettyprint-pattern-mut-binding, r=davidtwco
Fix pretty printing an AST representing `&(mut ident)`

The PR fixes a misguiding help diagnostic in the parser that I reported in #80186. I discovered that the parsers recovery and reporting logic was correct but the pretty printer produced wrong code for the example. (Details in https://github.com/rust-lang/rust/issues/80186#issuecomment-748498676)

Example:
```rust
#![allow(unused_variables)]
fn main() {
    let mut &x = &0;
}
```

The AST fragment

`PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..), Mutability::Not)`

was printed to be `&mut ident`. But this wouldn't round trip through parsing again, because then it would be:

`PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Not), ..), Mutability::Mut)`

Now the pretty-printer prints `&(mut ident)`. Reparsing that code results in the AST fragment

`PatKind::Ref(PatKind::Paren(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..)), Mutability::Not)`

which I think should behave like the original pattern.

Old diagnostic:
```
error: `mut` must be attached to each individual binding
 --> src/main.rs:3:9
  |
3 |     let mut &x = &0;
  |         ^^^^^^ help: add `mut` to each binding: `&mut x`
  |
  = note: `mut` may be followed by `variable` and `variable @ pattern`
```

New diagnostic:

```
error: `mut` must be attached to each individual binding
 --> src/main.rs:3:9
  |
3 |     let mut &x = &0;
  |         ^^^^^^ help: add `mut` to each binding: `&(mut x)`
  |
  = note: `mut` may be followed by `variable` and `variable @ pattern`
```

Fixes #80186
2020-12-21 10:21:01 +00:00
bors
463ce40428 Auto merge of #80206 - poliorcetics:rustdoc-default-langstring, r=GuillaumeGomez,jyn514
impl Default for LangString, replacing all_false by default

Fix #80015

`@rustbot` label C-cleanup  T-rustdoc  A-markdown-parsing
2020-12-21 07:00:17 +00:00
bors
15d1f81196 Auto merge of #80253 - Dylan-DPC:rollup-bkmn74z, r=Dylan-DPC
Rollup of 11 pull requests

Successful merges:

 - #80159 (Add array search aliases)
 - #80166 (Edit rustc_middle docs)
 - #80170 (Fix ICE when lookup method in trait for type that have bound vars)
 - #80171 (Edit rustc_middle::ty::TyKind docs)
 - #80199 (also const-check FakeRead)
 - #80211 (Handle desugaring in impl trait bound suggestion)
 - #80236 (Use pointer type in AtomicPtr::swap implementation)
 - #80239 (Update Clippy)
 - #80240 (make sure installer only creates directories in DESTDIR)
 - #80244 (Cleanup markdown span handling)
 - #80250 (Minor cleanups in LateResolver)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-21 04:08:35 +00:00
Dylan DPC
0947e05723
Rollup merge of #80250 - bugadani:resolver-cleanup, r=petrochenkov
Minor cleanups in LateResolver

 - Avoid calculating hash twice
 - Avoid creating a closure in every iteration of a loop
 - Reserve space for path in advance
 - Some readability changes
2020-12-21 02:47:52 +01:00
Dylan DPC
823210901d
Rollup merge of #80244 - jyn514:spans, r=bugadani
Cleanup markdown span handling

1. Get rid of `locate()` in markdown handling

This function was unfortunate for several reasons:

- It used `unsafe` because it wanted to tell whether a string came from
  the same *allocation* as another, not just whether it was a textual match.
- It recalculated spans even though they were already available from pulldown
- It sometimes *failed* to calculate the span, which meant it was always possible for the span to be `None`, even though in practice that should never happen.

This has several cleanups:

- Make the span required
- Pass through the span from pulldown in the `HeadingLinks` and `Footnotes` iterators
- Only add iterator bounds on the `impl Iterator`, not on `new` and the struct itself.

2. Remove unnecessary scope in `markdown_links`

I recommend reading a single commit at a time.

cc ``@bugadani`` - this will conflict with https://github.com/rust-lang/rust/pull/77859, I'll try to make sure that gets merged first.
2020-12-21 02:47:50 +01:00
Dylan DPC
c4b34eebef
Rollup merge of #80240 - yshui:master, r=Mark-Simulacrum
make sure installer only creates directories in DESTDIR

Fixes #80238

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2020-12-21 02:47:49 +01:00
Dylan DPC
ce93f5a8bb
Rollup merge of #80239 - flip1995:clippyup, r=Manishearth
Update Clippy

Biweekly Clippy update.

r? ``@Manishearth``
2020-12-21 02:47:47 +01:00
Dylan DPC
328e89c022
Rollup merge of #80236 - tmiasko:atomic-swap, r=oli-obk
Use pointer type in AtomicPtr::swap implementation

Closes #80234.
2020-12-21 02:47:45 +01:00
Dylan DPC
2528acb5f7
Rollup merge of #80211 - wabain:async-fn-trait-bound-suggestion, r=petrochenkov
Handle desugaring in impl trait bound suggestion

Fixes #79843.

When an associated type of a generic function parameter needs extra bounds, the diagnostics may suggest replacing an `impl Trait` with a named type parameter so that it can be referenced in the where clause. On stable and nightly, the suggestion can be malformed, for instance transforming:

```rust
async fn run(_: &(), foo: impl Foo) -> std::io::Result<()>
```

Into:

```rust
async fn run(_: &, F: Foo(), foo: F) -> std::io::Result<()> where <F as Foo>::Bar: Send
                 ^^^^^^^^         ^                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

Where we want something like:

```rust
async fn run<F: Foo>(_: &(), foo: F) -> std::io::Result<()> where <F as Foo>::Bar: Send
            ^^^^^^^^              ^                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

The problem is that the elided lifetime of `&()` is added as a generic parameter when desugaring the async fn; the suggestion code sees this as an existing generic parameter and tries to use its span as an anchor to inject `F` into the parameter list. There doesn't seem to be an entirely principled way to check which generic parameters in the HIR were explicitly named in the source, so this commit changes the heuristics when generating the suggestion to only consider type parameters whose spans are contained within the span of the `Generics` when determining how to insert an additional type parameter into the declaration. (And to be safe it also excludes parameters whose spans are marked as originating from desugaring, although that doesn't seem to handle this elided lifetime.)
2020-12-21 02:47:44 +01:00
Dylan DPC
000c51611c
Rollup merge of #80199 - RalfJung:const-fake, r=oli-obk
also const-check FakeRead

We need to const-check all statements, including `FakeRead`, to avoid issues like https://github.com/rust-lang/rust/issues/77694.

Fixes https://github.com/rust-lang/rust/issues/77694.
r? ``@oli-obk``
2020-12-21 02:47:42 +01:00
Dylan DPC
432b3550d2
Rollup merge of #80171 - pierwill:pierwill-rustcmiddle-tykind, r=lcnr
Edit rustc_middle::ty::TyKind docs

- Add a definition for this enum.
- Fix typo and missing punctuation.
- Spell out "algebraic data type".
2020-12-21 02:47:41 +01:00
Dylan DPC
d729e76492
Rollup merge of #80170 - ldm0:fixice, r=lcnr
Fix ICE when lookup method in trait for type that have bound vars

Closes #77910
2020-12-21 02:47:39 +01:00
Dylan DPC
251d435e2b
Rollup merge of #80166 - pierwill:pierwill-rustcmiddle-place, r=petrochenkov
Edit rustc_middle docs

Re-word doc comment for rustc_middle::hir::place::Projection.

Also adds:

- Missing end stop punctuation, and
- Documentation links to `rustc_middle::mir::Place`.
2020-12-21 02:47:37 +01:00
Dylan DPC
635ea920f1
Rollup merge of #80159 - jyn514:array, r=m-ou-se
Add array search aliases

Missed this in https://github.com/rust-lang/rust/pull/80068. This one will really fix https://github.com/rust-lang/rust/issues/46075.

The last alias especially I'm a little unsure about - maybe fuzzy search should be fixed in rustdoc instead? Happy to make that change although I'd have to figure out how.

r? ``@m-ou-se`` although cc ``@GuillaumeGomez`` for the search issue.
2020-12-21 02:47:33 +01:00
bors
c8135455c4 Auto merge of #80088 - operutka:fix-cmsg-len-uclibc, r=dtolnay
Fix failing build of std on armv5te-unknown-linux-uclibceabi due to missing cmsg_len_zero

I'm getting the following error when trying to build `std` on `armv5te-unknown-linux-uclibceabi`:

```
error[E0425]: cannot find value `cmsg_len_zero` in this scope
   --> /home/operutka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/ext/net/ancillary.rs:376:47
    |
376 |             let data_len = (*cmsg).cmsg_len - cmsg_len_zero;
    |                                               ^^^^^^^^^^^^^ not found in this scope
```

Obviously, this branch:
```rust
cfg_if::cfg_if! {
    if #[cfg(any(target_os = "android", all(target_os = "linux", target_env = "gnu")))] {
        let cmsg_len_zero = libc::CMSG_LEN(0) as libc::size_t;
    } else if #[cfg(any(
                  target_os = "dragonfly",
                  target_os = "emscripten",
                  target_os = "freebsd",
                  all(target_os = "linux", target_env = "musl",),
                  target_os = "netbsd",
                  target_os = "openbsd",
              ))] {
        let cmsg_len_zero = libc::CMSG_LEN(0) as libc::socklen_t;
    }
}
```

does not cover the case `all(target_os = "linux", target_env = "uclibc")`.
2020-12-21 01:16:20 +00:00
Tomasz Miąsko
bb9b322b8a Update stdarch submodule 2020-12-21 00:00:00 +00:00
Dániel Buga
6d71cc6750 Move std_path construction into condition 2020-12-20 23:55:03 +01:00
Dániel Buga
66c2872901 Inline a single-use closure 2020-12-20 23:17:56 +01:00
Caleb Cartwright
8cfaf94a61 update rustfmt to v1.4.30 2020-12-20 16:17:35 -06:00
Camelid
dc58fc4de0
Remove I-prioritize from Zulip topic
It doesn't add anything since every topic in
`t-compiler/wg-prioritization/alerts` is about prioritization.
And it makes it harder to see the issue title, which is what the topic
is actually about.
2020-12-20 14:08:55 -08:00
Dániel Buga
f499601dd8 Create closure outside of the loop 2020-12-20 22:49:53 +01:00
Joshua Nelson
60d5567160 Fix incorrect logic when merging matches 2020-12-20 15:59:42 -05:00
Dániel Buga
89bc399d56 Add missing semicolon 2020-12-20 21:41:35 +01:00
Dániel Buga
91ea623f49 Remove unnecessary cloned 2020-12-20 21:41:15 +01:00
Dániel Buga
62f593bda9 Precompute vector length in smart_resolve_path_fragment 2020-12-20 21:38:41 +01:00
Dániel Buga
93d5a8025d Clean up with_generic_param_rib, avoid double hashing 2020-12-20 21:08:55 +01:00
Joshua Nelson
1e15c2fde5 Remove unnecessary scope 2020-12-20 15:05:45 -05:00
Joshua Nelson
65f4f39dd8 Get rid of locate() in markdown handling
This function was unfortunate for several reasons:

- It used `unsafe` because it wanted to tell whether a string came from
  the same *allocation* as another, not just whether it was a textual
  match.
- It recalculated spans even though they were already available from
  pulldown
- It sometimes *failed* to calculate the span, which meant it was always
  possible for the span to be `None`, even though in practice that
  should never happen.

This commit has several cleanups:

- Make the span required
- Pass through the span from pulldown in the `HeadingLinks` and
  `Footnotes` iterators
- Only add iterator bounds on the `impl Iterator`, not on `new` and the
  struct itself.
2020-12-20 15:05:41 -05:00
bors
c609b2eaf3 Auto merge of #78317 - est31:linear_in_impl_count, r=matthewjasper
Turn quadratic time on number of impl blocks into linear time

Previously, if you had a lot of inherent impl blocks on a type like:

```Rust
struct Foo;

impl Foo { fn foo_1() {} }
// ...
impl Foo { fn foo_100_000() {} }
```

The compiler would be very slow at processing it, because
an internal algorithm would run in O(n^2), where n is the number
of impl blocks. Now, we add a new algorithm that allocates but
is faster asymptotically.

Comparing rustc nightly with a local build of rustc as of this PR (results in seconds):

| N | real time before | real time after |
| - | - | - |
| 4_000 | 0.57 | 0.46 |
| 8_000  | 1.31  | 0.84 |
| 16_000  | 3.56 | 1.69 |
| 32_000 | 10.60 | 3.73 |

I've tuned up the numbers to make the effect larger than the startup noise of rustc, but the asymptotic difference should hold for smaller n as well.

Note: current state of the PR omits error messages if there are other errors present already. For now, I'm mainly interested in a perf run to study whether this issue is present at all. Please queue one for this PR. Thanks!
2020-12-20 19:54:15 +00:00
pierwill
f318f02112 Edit rustc_middle docs
Re-word doc comment for rustc_middle::hir::place::Projection.

Also adds:

- Missing end stop punctuation, and
- Documentation links to `rustc_middle::mir::Place`.
2020-12-20 11:22:29 -08:00
pierwill
32baf233c5
Fix typo
Fix typo in rustc_middle::ty::inhabitedness::DefIdForest docs.
2020-12-20 09:53:26 -08:00
Yuxuan Shui
fbc9d50d75
make sure installer only creates directories in DESTDIR
Fixes #80238

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2020-12-20 17:16:02 +00:00
pierwill
b228be20c2 Edit rustc_middle::ty::TyKind docs
- Add a definition for this enum.
- Fix typo and missing punctuation.
- Spell out "algebraic data type".
2020-12-20 09:14:44 -08:00
bors
b0e5c7d1fe Auto merge of #74699 - notriddle:fd-non-negative, r=m-ou-se
Mark `-1` as an available niche for file descriptors

Based on discussion from <https://internals.rust-lang.org/t/can-the-standard-library-shrink-option-file/12768>, the file descriptor `-1` is chosen based on the POSIX API designs that use it as a sentinel to report errors. A bigger niche could've been chosen, particularly on Linux, but would not necessarily be portable.

This PR also adds a test case to ensure that the -1 niche (which is kind of hacky and has no obvious test case) works correctly. It requires the "upper" bound, which is actually -1, to be expressed in two's complement.
2020-12-20 16:36:23 +00:00
Donough Liu
00bb2935fc Move test from compile-fail to ui/binop 2020-12-21 00:27:53 +08:00
flip1995
520761afa5
Merge commit '4911ab124c481430672a3833b37075e6435ec34d' into clippyup 2020-12-20 17:19:49 +01:00
bors
4911ab124c Auto merge of #6482 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2020-12-20 16:00:11 +00:00
flip1995
53d6e0caaa
Bump nightly to 2020-12-20 2020-12-20 16:54:22 +01:00
flip1995
883a3d10c8
Merge remote-tracking branch 'upstream/master' into rustup 2020-12-20 16:48:04 +01:00
Ralf Jung
7f3e18cc2b make sure [CONST; N] drops N times 2020-12-20 15:15:29 +01:00
Ralf Jung
f8d4883dbe add test that repeating non-Copy constants works 2020-12-20 15:15:28 +01:00
Ralf Jung
54a3ed3114 use exhaustive match for checking Rvalue::Repeat 2020-12-20 15:15:28 +01:00
bors
2ad5292aea Auto merge of #80213 - jryans:bootstrap-skip-dsymutil, r=nagisa
Skip `dsymutil` by default for compiler bootstrap

`dsymutil` adds time to builds on Apple platforms for no clear benefit, and also makes it more difficult for debuggers to find debug info (which `@pnkfelix` highlighted on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/does.20lldb.20%28or.20gdb%29.20work.20on.20rustc.20on.20Mac.3F/near/220482092)). The compiler currently defaults to running `dsymutil` to preserve its historical default, but when compiling the compiler itself, we skip it by default since we know it's safe to do so in that case.

r? `@nagisa`
2020-12-20 13:47:23 +00:00
Donough Liu
4eb28c358c
Update compiler/rustc_typeck/src/check/op.rs
Co-authored-by: lcnr <bastian_kauschke@hotmail.de>
2020-12-20 21:45:23 +08:00
Thomas Bahn
b05ab18aec Fix pretty printing an AST representing &(mut ident)
`PatKind::Ref(PatKind::Ident(BindingMode::ByValue(Mutability::Mut), ..), ..)`
is an AST representing `&(mut ident)`. It was errorneously printed as
`&mut ident` which reparsed into a syntactically different AST.

This affected help diagnostics in the parser.
2020-12-20 13:11:07 +01:00
Mara Bos
094b1da3a1
Check that c_int is i32 in FileDesc::new. 2020-12-20 11:56:51 +00:00
Donough Liu
a33f6ac9a0 Fix ICE on suggesting calling function 2020-12-20 19:53:22 +08:00
bors
59aaa2a04b Auto merge of #80123 - DrMeepster:maybe_uninit_write_slice, r=RalfJung
Fix memory leak in test "mem::uninit_write_slice_cloned_no_drop"

This fixes #80116. I replaced the `Rc` based method I was using with a type that panics when dropped.
2020-12-20 10:08:56 +00:00
pierwill
9f8c8e4a42 Add module-level docs to rustc_middle::ty 2020-12-20 00:09:57 -08:00
pierwill
51d1806545
docs: Fix outdated crate reference 2020-12-19 23:32:51 -08:00