Commit graph

2905 commits

Author SHA1 Message Date
bors a6bd5246da Auto merge of #80267 - 0urobor0s:ouro/61592, r=jyn514
Rustdoc render public underscore_imports as Re-exports

Fixes #61592
2020-12-31 09:07:52 +00:00
bors cb4553bdae Rustdoc render public underscore_imports as Re-exports
Fixes #61592
2020-12-31 09:07:51 +00:00
bors 923e3d2400 Auto merge of #80500 - jyn514:track-caller, r=nagisa
Add `#[track_caller]` to `bug!` and `register_renamed`

Before:

```
thread 'rustc' panicked at 'compiler/rustc_lint/src/context.rs:267:18: invalid lint renaming of broken_intra_doc_links to rustdoc::broken_intra_doc_links', compiler/rustc_middle/src/util/bug.rs:34:26
```

After:

```
thread 'rustc' panicked at 'src/librustdoc/core.rs:455:24: invalid lint renaming of broken_intra_doc_links to rustdoc::broken_intra_doc_links', compiler/rustc_middle/src/util/bug.rs:35:26
```

The reason I added it to `register_renamed` too is that any panic in
that function will be the caller's fault.
2020-12-31 03:17:50 +00:00
Yuki Okushi 7008911080 FIx ICE on wf check for foreign fns 2020-12-31 11:25:53 +09:00
bors 9775ffef2a Auto merge of #80530 - m-ou-se:rollup-zit69ko, r=m-ou-se
Rollup of 9 pull requests

Successful merges:

 - #78934 (refactor: removing library/alloc/src/vec/mod.rs ignore-tidy-filelength)
 - #79479 (Add `Iterator::intersperse`)
 - #80128 (Edit rustc_ast::ast::FieldPat docs)
 - #80424 (Don't give an error when creating a file for the first time)
 - #80458 (Some Promotion Refactoring)
 - #80488 (Do not create dangling &T in Weak<T>::drop)
 - #80491 (Miri: make size/align_of_val work for dangling raw ptrs)
 - #80495 (Rename kw::Invalid -> kw::Empty)
 - #80513 (Add regression test for #80062)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-30 21:25:15 +00:00
max-heller 947b279bc6 Take type defaults into account in suggestions to reorder generic parameters 2020-12-30 16:00:25 -05:00
Mara Bos 9e8edc8c22
Rollup merge of #80495 - jyn514:rename-empty, r=petrochenkov
Rename kw::Invalid -> kw::Empty

See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471
for context.

r? `@petrochenkov`
2020-12-30 20:56:58 +00:00
Mara Bos 067f1b7030
Rollup merge of #80491 - RalfJung:dangling-of-val, r=oli-obk
Miri: make size/align_of_val work for dangling raw ptrs

This is needed for https://github.com/rust-lang/rust/issues/80365#issuecomment-752128105.

r? `@oli-obk`
2020-12-30 20:56:56 +00:00
Mara Bos 46111c1901
Rollup merge of #80458 - RalfJung:promotion-refactor, r=oli-obk
Some Promotion Refactoring

Clean up promotion a bit:
* factor out some common code
* more exhaustive matches

This *should* not break anything... the only potentially-breaking change is that `BorrowKind::Shallow | BorrowKind::Unique` are now rejected for internal references.

r? ``@oli-obk``
2020-12-30 20:56:52 +00:00
Mara Bos 3d7cdf667e
Rollup merge of #80128 - pierwill:pierwill-docs-fieldpat, r=jyn514
Edit rustc_ast::ast::FieldPat docs

Punctuation fixes.
2020-12-30 20:56:49 +00:00
bors e226704685 Auto merge of #80511 - Mark-Simulacrum:bump-stage0, r=pietroalbini
Bump bootstrap compiler to 1.50 beta

r? `@pietroalbini`
2020-12-30 18:32:31 +00:00
mark 40bf3c0f09 Implement edition-based macro pat feature 2020-12-30 09:57:49 -06:00
bors 507bff92fa Auto merge of #80510 - JohnTitor:rollup-gow7y0l, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #80185 (Fix ICE when pointing at multi bytes character)
 - #80260 (slightly more typed interface to panic implementation)
 - #80311 (Improvements to NatVis support)
 - #80337 (Use `desc` as a doc-comment for queries if there are no doc comments)
 - #80381 (Revert "Cleanup markdown span handling")
 - #80492 (remove empty wraps, don't return Results from from infallible functions)
 - #80509 (where possible, pass slices instead of &Vec or &String (clippy::ptr_arg))

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-30 15:30:56 +00:00
Joshua Nelson edeac1778c Rename kw::Invalid -> kw::Empty
See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471
for context.
2020-12-30 09:50:02 -05:00
Mark Rousskov fe031180d0 Bump bootstrap compiler to 1.50 beta 2020-12-30 09:27:19 -05:00
Yuki Okushi 41fa0dba27
Rollup merge of #80509 - matthiaskrgr:ptr_arg, r=varkor
where possible, pass slices instead of &Vec or &String (clippy::ptr_arg)
2020-12-30 22:49:26 +09:00
Yuki Okushi 07083739fb
Rollup merge of #80492 - matthiaskrgr:tasty_wraps, r=varkor
remove empty wraps, don't return Results from from infallible functions

This makes code easier to understand because it is more obvious when a function actually can't fail (return Err or None)

Make functions that only ever return Some(x), return x directly
Remove return type from functions that return Option<(), Err> but would only ever return Ok(()).

Found with `clippy::unnecessary_wraps`
2020-12-30 22:49:24 +09:00
Yuki Okushi 18ac1ecac9
Rollup merge of #80337 - jyn514:add-query-desc, r=varkor
Use `desc` as a doc-comment for queries if there are no doc comments

This at least gives *some* idea of what the query does even if it's not very readable. Some examples:

![image](https://user-images.githubusercontent.com/23638587/103021399-13e15c00-4518-11eb-8121-940774ae2fd1.png)
![image](https://user-images.githubusercontent.com/23638587/103021448-222f7800-4518-11eb-8ee6-cc10795fdc22.png)
![image](https://user-images.githubusercontent.com/23638587/103021434-1d6ac400-4518-11eb-885b-59d00c57bc70.png)

I want to turn `{}` into either `_` or the stringified expr, but [I'm not sure how to do that](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Evaluate.20format.20string.20in.20proc-macro). In the meantime, this is better than having no docs at all.
2020-12-30 22:49:21 +09:00
Yuki Okushi 4ae99cc843 Fix ICE when pointing at multi bytes character 2020-12-30 22:33:13 +09:00
bors bbcaed03bf Auto merge of #79684 - usbalbin:const_copy, r=oli-obk
Make copy[_nonoverlapping] const

Constifies
* `intrinsics::copy` and `intrinsics::copy_nonoverlapping`
* `ptr::read` and `ptr::read_unaligned`
  * `*const T::read` and `*const T::read_unaligned`
  * `*mut T::read` and `*mut T::read_unaligned`
* `MaybeUninit::assume_init_read`
2020-12-30 12:43:02 +00:00
Matthias Krüger e5ead5fc58 remove unused return types such as empty Results or Options that would always be Some(..)
remove unused return type of dropck::check_drop_obligations()
don't wrap return type in Option in get_macro_by_def_id() since we would always return Some(..)
remove redundant return type of back::write::optimize()
don't Option-wrap return type of compute_type_parameters() since we always return Some(..)
don't return empty Result in assemble_generator_candidates()
don't return empty Result in assemble_closure_candidates()
don't return empty result in assemble_fn_pointer_candidates()
don't return empty result in assemble_candidates_from_impls()
don't return empty result in assemble_candidates_from_auto_impls()
don't return emtpy result in assemble_candidates_for_trait_alias()
don't return empty result in assemble_builtin_bound_candidates()
don't return empty results in assemble_extension_candidates_for_traits_in_scope() and assemble_extension_candidates_for_trait()
remove redundant wrapping of return type of StripItem::strip() since it always returns Some(..)
remove unused return type of assemble_extension_candidates_for_all_traits()
2020-12-30 13:15:40 +01:00
Matthias Krüger bdc9291ed9 where possible, pass slices instead of &Vec or &String (clippy::ptr_arg) 2020-12-30 13:11:52 +01:00
bors d107a87d34 Auto merge of #80503 - JohnTitor:rollup-b26vglu, r=JohnTitor
Rollup of 13 pull requests

Successful merges:

 - #79812 (Lint on redundant trailing semicolon after item)
 - #80348 (remove redundant clones (clippy::redundant_clone))
 - #80358 (Edit rustc_span documentation)
 - #80457 (Add missing commas to `rustc_ast_pretty::pp` docs)
 - #80461 (Add llvm-libunwind change to bootstrap CHANGELOG)
 - #80464 (Use Option::map_or instead of open coding it)
 - #80465 (Fix typo in ffi-pure.md)
 - #80467 (More uses of the matches! macro)
 - #80469 (Fix small typo in time comment)
 - #80472 (Use sans-serif font for the "all items" page links)
 - #80477 (Make forget intrinsic safe)
 - #80482 (don't clone copy types)
 - #80487 (don't redundantly repeat field names)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-30 09:51:42 +00:00
Yuki Okushi 3812909919
Rollup merge of #80487 - matthiaskrgr:field_names, r=jyn514
don't redundantly repeat field names

r? `@Dylan-DPC`
2020-12-30 18:15:29 +09:00
Yuki Okushi 039b62e888
Rollup merge of #80482 - matthiaskrgr:cl0ne_on_copy, r=jyn514
don't clone copy types

r? `@Dylan-DPC`
2020-12-30 18:15:27 +09:00
Yuki Okushi 9576ee97d1
Rollup merge of #80477 - tmiasko:safe-forget, r=oli-obk
Make forget intrinsic safe
2020-12-30 18:15:25 +09:00
Yuki Okushi 231727d6e7
Rollup merge of #80467 - LingMan:more_matches, r=oli-obk
More uses of the matches! macro

`@rustbot` modify labels +C-cleanup +T-compiler
2020-12-30 18:15:20 +09:00
Yuki Okushi 30ddc91d41
Rollup merge of #80464 - LingMan:map_or, r=oli-obk
Use Option::map_or instead of open coding it

``@rustbot`` modify labels +C-cleanup +T-compiler
2020-12-30 18:15:16 +09:00
Yuki Okushi d8cabe1855
Rollup merge of #80457 - camelid:pretty-docs-commas, r=jonas-schievink
Add missing commas to `rustc_ast_pretty::pp` docs
2020-12-30 18:15:13 +09:00
Yuki Okushi 6064be7ced
Rollup merge of #80358 - pierwill:edit_rustc_span, r=lcnr
Edit rustc_span documentation

Various changes to the `rustc_span` docs, including the following:

- Additions to top-level docs
- Edits to the source_map module docs
- Edits to documentation for `Span` and `SpanData`
- Added intra-docs links
- Documentation for Levenshtein distances
- Fixed missing punctuation
2020-12-30 18:15:11 +09:00
Yuki Okushi a309468a8c
Rollup merge of #80348 - matthiaskrgr:less_clones, r=Dylan-DPC
remove redundant clones (clippy::redundant_clone)
2020-12-30 18:15:04 +09:00
Yuki Okushi 3fe423663b
Rollup merge of #79812 - Aaron1011:lint-item-trailing-semi, r=oli-obk
Lint on redundant trailing semicolon after item

We now lint on code like this:

```rust
fn main() {
    fn foo() {};
    struct Bar {};
}
```

Previously, this caused warnings in Cargo, so it was disabled.
2020-12-30 18:15:03 +09:00
bors b9c403be11 Auto merge of #79472 - Aaron1011:new-remove-pretty-print-hack, r=petrochenkov
Replace pretty-print/compare/retokenize hack with targeted workarounds

Based on https://github.com/rust-lang/rust/pull/78296
cc https://github.com/rust-lang/rust/issues/43081

The 'pretty-print/compare/retokenize' hack is used to try to avoid passing an outdated `TokenStream` to a proc-macro when the underlying AST is modified in some way (e.g. cfg-stripping before derives). Unfortunately, retokenizing throws away spans (including hygiene information), which causes issues of its own. Every improvement to the accuracy of the pretty-print/retokenize comparison has resulted in non-trivial ecosystem breakage due to hygiene changes. In extreme cases, users deliberately wrote unhygienic `macro_rules!` macros (likely because they did not realize that the compiler's behavior was a bug).

Additionaly, the comparison between the original and pretty-printed/retoknized token streams comes at a non-trivial runtime cost, as shown by https://github.com/rust-lang/rust/pull/79338

This PR removes the pretty-print/compare/retokenize logic from `nt_to_tokenstream`. We only discard the original `TokenStream` under two circumstances:
* Inner attributes are used (detected by examining the AST)
* `cfg`/`cfg_attr` processing modifies the AST. This is detected by making the visitor update a flag when it performs a modification, instead of trying to detect the modification after-the-fact. Note that a 'matching' `cfg` (e.g. `#[cfg(not(FALSE)]`) does not actually get removed from the AST, allowing us to preserve the original `TokenStream`.

In all other cases, we preserve the original `TokenStream`.

This could use a bit of refactoring/renaming - opening for a Crater run.

r? `@ghost`
2020-12-30 07:04:49 +00:00
Joshua Nelson 56ea926b1c Add #[track_caller] to bug! and register_renamed
Before:

```
thread 'rustc' panicked at 'compiler/rustc_lint/src/context.rs:267:18: invalid lint renaming of broken_intra_doc_links to rustdoc::broken_intra_doc_links', compiler/rustc_middle/src/util/bug.rs:34:26
```

After:

```
thread 'rustc' panicked at 'src/librustdoc/core.rs:455:24: invalid lint renaming of broken_intra_doc_links to rustdoc::broken_intra_doc_links', compiler/rustc_middle/src/util/bug.rs:35:26
```

The reason I added it to `register_renamed` too is that any panic in
that function will be the caller's fault.
2020-12-29 23:18:11 -05:00
Joshua Nelson e67f9d3105 Use desc as a doc-comment if none exist yet
- Replace {} with the stringified expr

  Giant thank you to `@danielhenrymantilla` for figuring out how to make
  this work ❤️

- Note that this is just an approximation and it would be better to add
  a doc-comment
2020-12-29 21:13:06 -05:00
Ralf Jung 95aed7ab3b Miri: make size/align_of_val work for dangling raw ptrs 2020-12-29 22:46:17 +01:00
Aaron Hill c857cbeb06
Lint on redundant trailing semicolon after item
We now lint on code like this:

```rust
fn main() {
    fn foo() {};
    struct Bar {};
}
```

Previously, this caused warnings in Cargo, so it was disabled.
2020-12-29 16:30:02 -05:00
Matthias Krüger 0c3af22e08 don't redundantly repeat field names 2020-12-29 22:26:58 +01:00
Vadim Petrochenkov 4d2d0bad4e Remove compile-fail test suite 2020-12-29 23:39:56 +03:00
Matthias Krüger 17a8c1017f don't clone copy types 2020-12-29 19:40:03 +01:00
LingMan 7a41532ef9 More uses of the matches! macro 2020-12-29 17:18:52 +01:00
Ralf Jung 51cec58040 fix a comment 2020-12-29 16:32:38 +01:00
Aaron Hill 530a629635
Remove pretty-print/reparse hack, and add derive-specific hack 2020-12-29 09:36:42 -05:00
bors e2a2592885 Auto merge of #79084 - simonvandel:instcombine-perf, r=oli-obk
Small perf changes for InstCombine
2020-12-29 06:21:18 +00:00
LingMan 3dae414cb6 Use Option::map_or instead of open coding it 2020-12-29 04:27:37 +01:00
Tomasz Miąsko 5718cc2f9b Make forget intrinsic safe 2020-12-29 00:00:00 +00:00
Ralf Jung 4a90a58c34 make more matches exhaustive 2020-12-28 23:29:16 +01:00
Camelid 8d5dc8c2f0
Add missing commas to rustc_ast_pretty::pp docs 2020-12-28 14:23:20 -08:00
Simon Vandel Sillesen 0010fc8fec use exhaustive pattern match to prevent future bugs 2020-12-28 23:19:35 +01:00
Ralf Jung c177e68015 merge two match'es for more exhaustiveness 2020-12-28 22:44:04 +01:00
Ralf Jung 122e91c4fb promotion: factor some common code into validate_ref 2020-12-28 22:09:08 +01:00
Mara Bos 8b43932ae2
Rollup merge of #80403 - 0xflotus:patch-1, r=jyn514
fix: small typo error in chalk/mod.rs
2020-12-28 19:09:27 +00:00
Mara Bos 803b37597e
Rollup merge of #80402 - camelid:inferty-docs, r=matthewjasper
Document `InferTy` & co.

I finally figured out what `TyVid` means! The name is quite opaque, so I
decided to document it and related types.

I don't know that much about `InferTy` & co., but I was able to *infer*
( :) ) from the names and what I know generally about type inference to
add some basic documentation.
2020-12-28 19:09:25 +00:00
bors 2987785df3 Auto merge of #80439 - Dylan-DPC:rollup-rdxcvon, r=Dylan-DPC
Rollup of 11 pull requests

Successful merges:

 - #79662 (Move some more code out of CodegenBackend::{codegen_crate,link})
 - #79815 (Update RELEASES.md for 1.49.0)
 - #80284 (Suggest fn ptr rather than fn item and suggest to use `Fn` trait bounds rather than the unique closure type in E0121)
 - #80331 (Add more comments to trait queries)
 - #80344 (use matches!() macro in more places)
 - #80353 (BTreeMap: test split_off (and append) more thoroughly)
 - #80362 (Document rustc_macros on nightly-rustc)
 - #80399 (Remove FIXME in rustc_privacy)
 - #80408 (Sync rustc_codegen_cranelift)
 - #80411 (rustc_span: Remove `Symbol::with`)
 - #80434 (bootstrap: put the component name in the tarball temp dir path)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-28 15:57:50 +00:00
Dylan DPC 80934aba15
Rollup merge of #80411 - petrochenkov:nosymwith, r=matthewjasper
rustc_span: Remove `Symbol::with`

A subset of https://github.com/rust-lang/rust/pull/79425 that is a pure refactoring.
2020-12-28 14:13:21 +01:00
Dylan DPC 55b52ee339
Rollup merge of #80408 - bjorn3:sync_cg_clif-2020-12-27, r=bjorn3
Sync rustc_codegen_cranelift

The highlight of this sync are two JIT mode improvements. The first is that it is now possible to use JIT mode when using `-Zcodegen-backend` instead of the custom driver using `-Cllvm-args=mode=jit`. The second one is a new JIT mode that lazily compiles functions when they are called the first time: https://github.com/bjorn3/rustc_codegen_cranelift/pull/1120

In addition this includes a few small runtime performance improvements and various fixes for rustc changes that didn't cause compilation to fail.

r? ``@ghost``

``@rustbot`` label +A-codegen +A-cranelift +T-compiler
2020-12-28 14:13:19 +01:00
Dylan DPC 70b1a29b80
Rollup merge of #80399 - jyn514:hir-id-cleanup, r=marmeladema
Remove FIXME in rustc_privacy

#71104 has been fixed.

r? ``@marmeladema`` if you have time, otherwise ``@petrochenkov``
2020-12-28 14:13:17 +01:00
Dylan DPC c51172f38a
Rollup merge of #80344 - matthiaskrgr:matches, r=Dylan-DPC
use matches!() macro in more places
2020-12-28 14:13:12 +01:00
Dylan DPC 3f8c979c4b
Rollup merge of #80331 - jyn514:docs, r=varkor
Add more comments to trait queries

This also adds back a comment that was mistakenly removed in
ac9dfc3e77.
2020-12-28 14:13:10 +01:00
Dylan DPC 12ac312351
Rollup merge of #80284 - ThePuzzlemaker:issue-80179-fix, r=varkor
Suggest fn ptr rather than fn item and suggest to use `Fn` trait bounds rather than the unique closure type in E0121

Previously, using `_` as a return type in a function that returned a function/closure would provide a diagnostic that would cause a papercut. For example:
```rust
fn f() -> i32 { 0 }
fn fn_ptr() -> _ { f }
fn closure() -> _ { || 0 }
```
would result in this diagnostic:
```rust
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
 --> <anon>:2:16
  |
2 | fn fn_ptr() -> _ { f }
  |                ^
  |                |
  |                not allowed in type signatures
  |                help: replace with the correct return type: `fn() -> i32 {f}`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
 --> <anon>:3:17
  |
3 | fn closure() -> _ { || 0 }
  |                 ^
  |                 |
  |                 not allowed in type signatures
  |                 help: replace with the correct return type: `[closure@<anon>:3:21: 3:25]`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0121`.
```
As can be seen, it was suggested to use the function definition return type `fn() -> i32 { f }` which is not valid syntax as a return type. Additionally, closures cause a papercut as unique closure types (notated in this case as `[closure@<anon>:3:21: 3:25]`) are not valid syntax either.

Instead, this PR implements this version of the diagnostic (this example is for the same code featured above):
```rust
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
 --> <anon>:2:16
  |
2 | fn fn_ptr() -> _ { f }
  |                ^
  |                |
  |                not allowed in type signatures
  |                help: replace with the correct return type: `fn() -> i32`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
 --> <anon>:3:17
  |
3 | fn closure() -> _ { || 0 }
  |                 ^ not allowed in type signatures
  |
  = help: consider using an `Fn`, `FnMut`, or `FnOnce` trait bound
  = note: for more information on `Fn` traits and closure types, see https://doc.rust-lang.org/book/ch13-01-closures.html

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0121`.
```
As can be seen in this diagnostic, the papercut for returning a function item is fixed by suggesting the usage of a function pointer as the return type. As for closures, it's suggested to use an `Fn`, `FnMut`, or `FnOnce` trait bound (with further reading on closures and `Fn` traits in *The Book* for beginners). I did not implement a suggestion to use `impl Fn() -> i32` syntax as that was out-of-scope for my abilities at the moment, therefore someone in the future may want to implement that. Also, it's possible to use either `impl Trait` syntax, generics, or generics with a `where` clause, and some users may not want to use `impl Trait` syntax for their own reasons.

This PR fixes #80179.
2020-12-28 14:13:08 +01:00
Dylan DPC 98d80bda01
Rollup merge of #79662 - bjorn3:move_more_code_out_of_codegen_backend, r=oli-obk
Move some more code out of CodegenBackend::{codegen_crate,link}

Kind of a follow up to #77795
2020-12-28 14:12:59 +01:00
bors 76aca6659a Auto merge of #78454 - bugadani:cyclic, r=oli-obk
MIR Body: Cache result of `is_cyclic` call
2020-12-28 11:25:33 +00:00
Camelid cdad0c80ef
Also show the displayed version of IntVar and FloatVar
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-12-27 11:05:40 -08:00
Vadim Petrochenkov 0ae998e122 rustc_span: Remove Symbol::with 2020-12-27 18:10:58 +03:00
bjorn3 52cf01c815 Merge commit 'dbee13661efa269cb4cd57bb4c6b99a19732b484' into sync_cg_clif-2020-12-27 2020-12-27 10:30:38 +01:00
0xflotus cb177852c1
fix: small typo error in chalk/mod.rs 2020-12-27 03:22:23 +01:00
Camelid 6aea014fbf
Document InferTy & co. 2020-12-26 17:55:39 -08:00
Joshua Nelson 53da233aec Remove FIXME in rustc_privacy 2020-12-26 19:34:10 -05:00
Bastian Kauschke 18fa7789cd update error codes 2020-12-26 18:24:10 +01:00
Bastian Kauschke 06cc9c26da stabilize min_const_generics 2020-12-26 18:24:10 +01:00
Albin Hedman 1b77f8e6ea Constify intrinsics::copy[_nonoverlapping] 2020-12-26 02:22:29 +01:00
bors 931aa27922 Auto merge of #80246 - matthewjasper:projection-cycle-caching, r=Mark-Simulacrum
Prevent caching normalization results with a cycle

When normalizing a projection which results in a cycle, we would cache the result of `project_type` without the nested obligations (because they're not needed for inference). This would result in the nested obligations only being handled once in fulfill, which would avoid the cycle error. `get_paranoid_cache_value_obligation` used to add an obligation that resulted in a cycle in this case previously, but was removed by #73905.

This PR makes the projection cache not cache the value of a projection if it was ever normalized in a cycle (except in a snapshot that's rolled back).

Fixes #79714.

r? `@nikomatsakis`
2020-12-26 00:11:30 +00:00
pierwill a8775d44e9 Edit rustc_span documentation
Various changes to the `rustc_span` docs, including the following:

- Additions to top-level docs
- Edits to the source_map module docs
- Edits to documentation for `Span` and `SpanData`
- Added intra-docs links
- Documentation for Levenshtein distances
- Fixed missing punctuation
2020-12-25 14:02:52 -08:00
bors bb178237c5 Auto merge of #80235 - RalfJung:validate-promoteds, r=oli-obk
validate promoteds

Turn on const-value validation for promoteds. This is made possible now that https://github.com/rust-lang/rust/issues/67534 is resolved.

I don't think this is a breaking change. We don't promote any unsafe operation any more (since https://github.com/rust-lang/rust/pull/77526 landed). We *do* promote `const fn` calls under some circumstances (in `const`/`static` initializers), but union field access and similar operations are not allowed in `const fn`. So now is a perfect time to add this check. :D

r? `@oli-obk`
Fixes https://github.com/rust-lang/rust/issues/67465
2020-12-25 18:25:48 +00:00
bors 1832bdd7de Auto merge of #80296 - wesleywiser:revert_missing_fragment_specifier_hard_error, r=Mark-Simulacrum
Revert missing fragment specifier hard error

Closes #76605

Reopens #40107

r? `@Mark-Simulacrum`
2020-12-25 14:09:08 +00:00
bors 198ec340f6 Auto merge of #80187 - 0dvictor:nativelib, r=bjorn3
Exclude unnecessary info from CodegenResults

`foreign_module` and `wasm_import_module` are not needed for linking, and hence can be removed from CodegenResults.

Fixes #77857
2020-12-25 08:17:21 +00:00
bors 9a40539c38 Auto merge of #80364 - Dylan-DPC:rollup-0y96okz, r=Dylan-DPC
Rollup of 11 pull requests

Successful merges:

 - #79213 (Stabilize `core::slice::fill`)
 - #79999 (Refactored verbose print into a function)
 - #80160 (Implemented a compiler diagnostic for move async mistake)
 - #80274 (Rename rustc_middle::lint::LintSource)
 - #80280 (Add installation commands to `x` tool README)
 - #80319 (Fix elided lifetimes shown as `'_` on async functions)
 - #80327 (Updated the match with the matches macro)
 - #80330 (Fix typo in simplify_try.rs)
 - #80340 (Don't unnecessarily override attrs for Module)
 - #80342 (Fix typo)
 - #80352 (BTreeMap: make test cases more explicit on failure)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-25 05:23:24 +00:00
Dylan DPC 3cf289bd5f
Rollup merge of #80342 - pierwill:patch-1, r=lcnr
Fix typo
2020-12-25 03:39:49 +01:00
Dylan DPC 704f81e3cb
Rollup merge of #80330 - eltociear:patch-2, r=lcnr
Fix typo in simplify_try.rs

assigment -> assignment
2020-12-25 03:39:46 +01:00
Dylan DPC 2dab627d77
Rollup merge of #80327 - PankajChaudhary5:PankajChaudhary, r=GuillaumeGomez
Updated the match with the matches macro

r?````@GuillaumeGomez````
2020-12-25 03:39:43 +01:00
Dylan DPC b295b8e67b
Rollup merge of #80274 - pierwill:lintlevelsource, r=petrochenkov
Rename rustc_middle::lint::LintSource

Rename [`rustc_middle::lint::LintSource`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/lint/enum.LintSource.html) to `rustc_middle::lint::LintLevelSource`.

This enum represents the source of a *lint level*, not a lint. This should improve code readability.

Update: Also documents `rustc_middle::lint::LevelSource` to clarify.
2020-12-25 03:39:36 +01:00
Dylan DPC 299c2fc695
Rollup merge of #80160 - diondokter:move_async_fix, r=davidtwco
Implemented a compiler diagnostic for move async mistake

Fixes #79694

First time contributing, so I hope I'm doing everything right.
(If not, please correct me!)

This code performs a check when a move capture clause is parsed. The check is to detect if the user has reversed the async move keywords and to provide a diagnostic with a suggestion to fix it.

Checked code:
```rust
fn main() {
    move async { };
}
```

Previous output:
```txt
PS C:\Repos\move_async_test> cargo build
   Compiling move_async_test v0.1.0 (C:\Repos\move_async_test)
error: expected one of `|` or `||`, found keyword `async`
 --> src\main.rs:2:10
  |
2 |     move async { };
  |          ^^^^^ expected one of `|` or `||`

error: aborting due to previous error

error: could not compile `move_async_test`
```

New output:
```txt
PS C:\Repos\move_async_test> cargo +dev build
   Compiling move_async_test v0.1.0 (C:\Repos\move_async_test)
error: the order of `move` and `async` is incorrect
 --> src\main.rs:2:13
  |
2 |     let _ = move async { };
  |             ^^^^^^^^^^
  |
help: try switching the order
  |
2 |     let _ = async move { };
  |             ^^^^^^^^^^

error: aborting due to previous error

error: could not compile `move_async_test`
```

Is there a file/module where these kind of things are tested?
Would love some feedback 😄
2020-12-25 03:39:35 +01:00
Dylan DPC 787b016957
Rollup merge of #79999 - hencrice:yenlinc/79799, r=oli-obk
Refactored verbose print into a function

Also handle Tuple and Array separately, which was not explicitly checked.

Fixes #79799.
2020-12-25 03:39:33 +01:00
bors cae1f4ddf2 Auto merge of #79762 - Swatinem:remap-doctest-coverage, r=Swatinem
Remap instrument-coverage line numbers in doctests

This uses the `SourceMap::doctest_offset_line` method to re-map line
numbers from doctests. Remapping columns is not yet done, and rustdoc
still does not output the correct filename when running doctests in a
workspace.

Part of #79417 although I dont consider that fixed until both filenames
and columns are mapped correctly.

r? `@richkadel`

I might jump on zulip the comming days. Still need to figure out how to properly write tests for this, and deal with other doctest issues in the meantime.
2020-12-25 02:37:08 +00:00
Matthias Krüger d12a358673 use matches!() macro in more places 2020-12-24 13:35:12 +01:00
Matthias Krüger 6e852cc4ce remove redundant clones (clippy::redundant_clone) 2020-12-24 12:59:22 +01:00
bors 2acf6ee6d2 Auto merge of #80295 - GuillaumeGomez:beautify-rework, r=petrochenkov
Rework beautify_doc_string so that it returns a Symbol instead of a String

This commit comes from https://github.com/rust-lang/rust/pull/80261, the goal here is to inspect the impact on performance of this change on its own.

The idea of rewriting `beautify_doc_string` is to not go through `String` if we don't need to update the doc comment to be able to keep the original `Symbol` and also to have better performance.

r? `@jyn514`
2020-12-24 11:30:24 +00:00
bors c34c015fe2 Auto merge of #77692 - PankajChaudhary5:issue-76630, r=davidtwco
Added better error message for shared borrow treated as unique for purposes of lifetimes

Part of Issue #76630

r? `@jyn514`
2020-12-24 07:32:19 +00:00
bors 49b315123e Auto merge of #79589 - tgnottingham:shared_dep_graph, r=michaelwoerister
rustc_query_system: reduce dependency graph memory usage

This change implements, at a high level, two space optimizations to the dependency graph.

The first optimization is sharing graph data with the previous dependency graph. Whenever we intern a node, we know whether that node is new (not in the previous graph) or not, and if not, the color of the node in the previous graph.

Red and green nodes have their `DepNode` present in the previous graph, so for that piece of node data, we can just store the index of the node in the previous graph rather than duplicate the `DepNode`. Green nodes additionally have the the same result `Fingerprint`, so we can avoid duplicating that too. Finally, we distinguish between "light" and "dark" green nodes, where the latter are nodes that were marked green because all of their dependencies were marked green. These nodes can additionally share edges with the previous graph, because we know that their set of dependencies is the same (technically, light green and red nodes can have the same dependencies too, but we don't try to figure out whether or not that's the case).

Also, some effort is made to pack data tightly, and to avoid storing `DepNode`s as map keys more than once.

The second optimization is storing edges in a more compact representation, as in the `SerializedDepGraph`, that is, in a single vector, rather than one `EdgesVec` per node. An `EdgesVec` is a `SmallVec` with an inline buffer for 8 elements. Each `EdgesVec` is, at minimum, 40 bytes, and has a per-node overhead of up to 40 bytes. In the ideal case of exactly 8 edges, then 32 bytes are used for edges, and the overhead is 8 bytes. But most of the time, the overhead is higher.

In contrast, using a single vector to store all edges, and having each node specify its start and end elements as 4 byte indices into the vector has a constant overhead of 8 bytes--the best case scenario for the per-node `EdgesVec` approach.

The downside of this approach is that `EdgesVec`s built up during query execution have to be copied into the vector, whereas before, we could just take ownership over them. However, we mostly make up for this because the single vector representation enables a more efficient implementation of `DepGraph::serialize`.
2020-12-24 01:06:36 +00:00
pierwill df94bfceb1
Fix typo 2020-12-23 13:08:15 -08:00
Yenlin Chen ecba49c1bd Fixed formatting 2020-12-23 19:10:59 +00:00
Yenlin Chen f459b0fea5 Addressed feedbacks
Also updated the mir-opt test output files.
2020-12-23 18:55:37 +00:00
Joshua Nelson 979d3ce6ea Add more comments to trait queries
This also adds back a comment that was mistakenly removed in
ac9dfc3e77.
2020-12-23 10:56:24 -05:00
Ikko Ashimine 87397080b6
Fix typo in simplify_try.rs
assigment -> assignment
2020-12-23 21:11:59 +09:00
PankajChaudhary5 c625d3183c Updated the match with the matches macro 2020-12-23 11:02:04 +05:30
Camelid 5b32ab671a Update and improve rustc_codegen_{llvm,ssa} docs
These docs were very out of date and misleading. They even said that
they codegen'd the *AST*!

For some reason, the `rustc_codegen_ssa::base` docs were exactly
identical to the `rustc_codegen_llvm::base` docs. They didn't really
make sense, because they had LLVM-specific information even though
`rustc_codegen_ssa` is supposed to be somewhat generic. So I removed
them as they were misleading.
2020-12-22 19:42:23 -08:00
Victor Ding 732afd41cf Exclude unnecessary info from CodegenResults
`foreign_module` and `wasm_import_module` are not needed for linking,
and hence can be removed from CodegenResults.
2020-12-23 12:51:10 +11:00
bors 89886e6936 Auto merge of #80314 - GuillaumeGomez:rollup-9rc48vx, r=GuillaumeGomez
Rollup of 17 pull requests

Successful merges:

 - #80136 (Add test for issue #74824)
 - #80203 (Edit rustc_middle::lint::LintSource docs)
 - #80204 (docs: Edit rustc_middle::ty::query::on_disk_cache)
 - #80219 (Fix labels for 'Library Tracking Issue' template)
 - #80222 (Fix rustc-std-workspace-core documentation)
 - #80223 (docs: Fix outdated crate reference)
 - #80225 (Add module-level docs to rustc_middle::ty)
 - #80241 (Fix typo)
 - #80248 (Remove `I-prioritize` from Zulip topic)
 - #80266 (Remove redundant test)
 - #80272 (rustc_span: Provide a reserved identifier check for a specific edition)
 - #80285 (Update books)
 - #80286 (docs: Edit rustc_middle::middle::privacy)
 - #80297 (Add some intra-doc links to compiler docs)
 - #80298 (Improve the code quality by using matches macro)
 - #80299 (Turn helper method into a closure)
 - #80302 (docs: Update rustc_middle::middle::region::ScopeTree)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-23 00:41:46 +00:00
Guillaume Gomez 67f8244975
Rollup merge of #80302 - pierwill:fix-80287, r=lcnr
docs: Update rustc_middle::middle::region::ScopeTree

Correct return type in docs for [`yield_in_source`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/middle/region/struct.ScopeTree.html#method.yield_in_scope) method.

Closes #80287.
2020-12-23 00:14:01 +01:00
Guillaume Gomez f711f3ff5f
Rollup merge of #80299 - LingMan:helper, r=lcnr
Turn helper method into a closure

`replace_prefix` is currently implemented as a method but has no real relation
to the struct it is implemented on. Turn it into a closure and move it into the
only method from which it is called.

`@rustbot` modify labels +C-cleanup +T-compiler
r? `@lcnr`
2020-12-23 00:13:59 +01:00
Guillaume Gomez 5af144ece1
Rollup merge of #80298 - PankajChaudhary5:PankajChaudhary, r=GuillaumeGomez
Improve the code quality by using matches macro

Improved the code quality by using matches macro
r? `@GuillaumeGomez`
2020-12-23 00:13:56 +01:00
Guillaume Gomez 125156ca0f
Rollup merge of #80297 - jyn514:more-docs, r=bjorn3
Add some intra-doc links to compiler docs

r? `@pierwill`
2020-12-23 00:13:53 +01:00
Guillaume Gomez 174a9fad2f
Rollup merge of #80286 - pierwill:rustc-middle-privacy, r=petrochenkov
docs: Edit rustc_middle::middle::privacy

Add descriptions of `AccessLevel` and `AccessLevels`.

Add missing punctuation.
2020-12-23 00:13:52 +01:00
Guillaume Gomez aa7cb4ff00
Rollup merge of #80272 - petrochenkov:kwed, r=oli-obk
rustc_span: Provide a reserved identifier check for a specific edition

while keeping edition evaluation lazy because it may be expensive.

Needed for https://github.com/rust-lang/rust/pull/80226.
2020-12-23 00:13:48 +01:00
Guillaume Gomez 558926142c
Rollup merge of #80241 - pierwill:patch-12, r=lcnr
Fix typo

Fix typo in rustc_middle::ty::inhabitedness::DefIdForest docs.
2020-12-23 00:13:43 +01:00
Guillaume Gomez e116732b4b
Rollup merge of #80225 - pierwill:patch-11, r=lcnr
Add module-level docs to rustc_middle::ty

I thought it would be nice to point out `Ty` and `TyCtxt` on the module page, and link out to the [rustc-dev-guide chapter](https://rustc-dev-guide.rust-lang.org/ty.html).
2020-12-23 00:13:41 +01:00
Guillaume Gomez f9f8446130
Rollup merge of #80223 - pierwill:patch-10, r=lcnr
docs: Fix outdated crate reference
2020-12-23 00:13:40 +01:00
Guillaume Gomez 8a35d3a08e
Rollup merge of #80204 - pierwill:pierwill-rustcmiddle-ondisk, r=varkor
docs: Edit rustc_middle::ty::query::on_disk_cache

Expand abbreviations for "incremental compliation".

Also added the word "to" to the description of CacheEncoder.
2020-12-23 00:13:34 +01:00
Guillaume Gomez f84ec97485
Rollup merge of #80203 - pierwill:pierwill-rustcmiddle-lint, r=oli-obk
Edit rustc_middle::lint::LintSource docs

Edit punctuation in doc comment for [rustc_middle::lint::LintSource::CommandLine](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/lint/enum.LintSource.html#variant.CommandLine).
2020-12-23 00:13:33 +01:00
Tyson Nottingham 03eb75f759 rustc_query_system: avoid race condition when using edge_count 2020-12-22 14:12:57 -08:00
Tyson Nottingham 22ed75158b rustc_query_system: add more comments for dependency graph 2020-12-22 14:12:57 -08:00
Tyson Nottingham d6b2aaed7d rustc_query_system: rename intern_node to intern_new_node 2020-12-22 14:12:57 -08:00
Tyson Nottingham 712fcae13a rustc_query_system: remove inline annotation from edge_count
This isn't called frequently enough to justify inlining.
2020-12-22 14:12:57 -08:00
Tyson Nottingham 4f76266295 rustc_query_system: minor cleanup
Remove effectively unused parameter and delete out of date comment.
2020-12-22 14:12:57 -08:00
Tyson Nottingham dd1ab840d2 rustc_query_system: use more space-efficient edges representation
Use single vector of edges rather than per-node vector. There is a small
hit to instruction counts (< 0.5%), but the memory savings make up for it.
2020-12-22 14:12:57 -08:00
Tyson Nottingham ea47269f5f rustc_query_system: share previous graph edges with current graph
Reduce memory consumption by sharing the previous dependency graph's
edges with the current graph when it is known to be valid to do so. It
is known to be valid whenever we mark a node green because all of its
dependencies were green. It is *not* known to be valid when we mark a
node green because we re-executed its query and its result was the same
as in the previous compilation session. In that case, the dependency set
might have changed (we don't try to determine whether or not it changed
and whether or not we can share).
2020-12-22 14:12:57 -08:00
Tyson Nottingham f6d6b0c96d rustc_query_system: share previous graph data with current graph
Reduce memory consumption by taking advantage of red/green algorithm
properties to share the previous dependency graph's node data with the
current graph instead of storing node data redundantly. Red nodes can
share the `DepNode`, and green nodes can share the `DepNode` and
`Fingerprint`. Edges will be shared when possible in a later change.
2020-12-22 14:12:57 -08:00
bors 969b42d8c0 Auto merge of #80242 - Nadrieril:explain-and-factor-splitting, r=varkor
Clarify constructor splitting in exhaustiveness checking

I reworked the explanation of the algorithm completely to make it properly account for the various extensions we've added. This includes constructor splitting, which was previously not clearly included in the algorithm. This makes wildcards less magical; I added some detailed examples; and this distinguishes clearly between constructors that only make sense in patterns (like ranges) and those that make sense for values (like `Some`). This reformulation had been floating around in my mind for a while, and I'm quite happy with how it turned out. Let me know how you feel about it.
I also factored out all three cases of splitting (wildcards, ranges and slices) into dedicated structs to encapsulate the complicated bits.
I measured no perf impact but I don't trust my local measurements for refactors since https://github.com/rust-lang/rust/pull/79284.

r? `@varkor`
`@rustbot` modify labels: +A-exhaustiveness-checking
2020-12-22 21:51:04 +00:00
ThePuzzlemaker 4f6be466fd
Suggest fn ptr rather than fn item and suggest to use Fn trait bounds rather than the unique closure type in E0121
This is a squash of the titular commit along with these minor commits:
- Improve note
- Improve note pt2
2020-12-22 13:26:28 -06:00
bors bb1fbbf844 Auto merge of #80177 - tgnottingham:foreign_defpathhash_registration, r=Aaron1011
rustc_query_system: explicitly register reused dep nodes

Register nodes that we've reused from the previous session explicitly
with `OnDiskCache`. Previously, we relied on this happening as a side
effect of accessing the nodes in the `PreviousDepGraph`. For the sake of
performance and avoiding unintended side effects, register explictily.
2020-12-22 19:02:28 +00:00
pierwill f078f7cd64 docs: Update rustc_middle::middle::region::ScopeTree
This corrects the return type in docs for yield_in_source method.

Closes #80287.
2020-12-22 10:57:05 -08:00
PankajChaudhary5 57b5f8cbb9 Improve the code quality by using matches macro 2020-12-22 20:52:38 +05:30
Nadrieril be23694622 Fix a comment 2020-12-22 15:20:24 +00:00
Nadrieril 85fdb34d3a Apply suggestions from code review
Co-authored-by: varkor <github@varkor.com>
2020-12-22 15:20:24 +00:00
Nadrieril 1c176d1150 Simplify field filtering 2020-12-22 15:20:23 +00:00
Nadrieril 53e03fb7c1 Make the special "missing patterns" constructor real 2020-12-22 15:20:23 +00:00
Nadrieril 2a541cea35 Completely rework the explanation of the algorithm 2020-12-22 15:20:23 +00:00
Nadrieril 43d445c8d1 Pass Matrix explicitly instead of via PatCtxt 2020-12-22 15:20:23 +00:00
Nadrieril 8b38b6859a Inline the constructor-specific split functions 2020-12-22 15:20:23 +00:00
Nadrieril 3141f2d78c Inline all_constructors 2020-12-22 15:20:23 +00:00
Nadrieril bbb4ac0651 Rebrand MissingConstructors as SplitWildcard 2020-12-22 15:20:23 +00:00
Nadrieril 9d0c2ed913 Factor out SplitVarLenSlice used for slice splitting 2020-12-22 15:20:23 +00:00
Nadrieril 7948f91910 Run the annoying lint separately 2020-12-22 15:20:23 +00:00
Nadrieril 5a24b2c2c7 Factor out SplitIntRange used for integer range splitting 2020-12-22 15:20:23 +00:00
LingMan ef75761fb1 Turn helper method into a closure
`replace_prefix` is currently implemented as a method but has no real relation
to the struct it is implemented on. Turn it into a closure and move it into the
only method from which it is called.
2020-12-22 16:18:34 +01:00
Guillaume Gomez 64afdedfb8 Rework beautify_doc_string so that it returns a Symbol instead of a String 2020-12-22 16:05:38 +01:00
Joshua Nelson 9cd992f394 Add some intra-doc links to compiler docs 2020-12-22 09:54:23 -05:00
Wesley Wiser 56154a1147 Add example to lint docs 2020-12-22 09:33:16 -05:00
Wesley Wiser f1eb88b28a Revert "Promote missing_fragment_specifier to hard error"
This reverts commit 02eae432e7.
2020-12-22 09:33:16 -05:00
Wesley Wiser 9414f0b833 Revert "Remove missing_fragment_specifier lint"
This reverts commit 5ba961018c.
2020-12-22 08:35:52 -05:00
bors 75e1acb63a Auto merge of #78242 - Nadrieril:rename-overlapping_endpoints-lint, r=varkor
Rename `overlapping_patterns` lint

As discussed in https://github.com/rust-lang/rust/issues/65477. I also tweaked a few things along the way.

r? `@varkor`
`@rustbot` modify labels: +A-exhaustiveness-checking
2020-12-22 10:32:03 +00:00
pierwill 80aa551d66 docs: Edit rustc_middle::middle::privacy
Add descriptions of `AccessLevel` and `AccessLevels`.

Add missing punctuation.
2020-12-21 20:05:05 -08:00
bors 9310aff66c Auto merge of #80208 - bugadani:generics-of-alloc, r=matthewjasper
Reserve necessary space for params in generics_of

Always reserve space for the exact number of generic parameters we need in generics_of. As far as I can see, the default is 0/4 elements based on has_self, and the vector grows on after that.
2020-12-22 00:20:14 +00:00
pierwill d3900d3775 Document rustc_middle::lint::LevelSource
This is to clarify the difference between `LevelSource`
and `LintLevelSource`.

Appease x.py fmt.
2020-12-21 15:03:00 -08:00
pierwill aec3575aa7 Rename rustc_middle::lint::LintSource
Rename rustc_middle::lint::LintSource to rustc_middle::lint::LintLevelSource.
2020-12-21 14:30:50 -08:00
Vadim Petrochenkov 00ff7fe6bd rustc_span: Provide a reserved identifier check for a specific edition
Edition evaluation is kept lazy because it may be expensive.
2020-12-21 22:35:47 +03:00
bors 11c94a1977 Auto merge of #79270 - RalfJung:array-repeat-consts, r=oli-obk
Acknowledge that `[CONST; N]` is stable

When `const_in_array_repeat_expressions` (RFC 2203) got unstably implemented as part of https://github.com/rust-lang/rust/pull/61749, accidentally, the special case of repeating a *constant* got stabilized immediately. That is why the following code works on stable:

```rust
const EMPTY: Vec<i32> = Vec::new();

pub const fn bar() -> [Vec<i32>; 2] {
    [EMPTY; 2]
}

fn main() {
    let x = bar();
}
```

In contrast, if we had written `[expr; 2]` for some expression that is not *literally* a constant but could be evaluated at compile-time (e.g. `(EMPTY,).0`), this would have failed.

We could take back this stabilization as it was clearly accidental. However, I propose we instead just officially accept this and stabilize a small subset of RFC 2203, while leaving the more complex case of general expressions that could be evaluated at compile-time unstable. Making that case work well is pretty much blocked on inline `const` expressions (to avoid relying too much on [implicit promotion](https://github.com/rust-lang/const-eval/blob/master/promotion.md)), so it could take a bit until it comes to full fruition. `[CONST; N]` is an uncontroversial subset of this feature that has no semantic ambiguities, does not rely on promotion, and basically provides the full expressive power of RFC 2203 but without the convenience (people have to define constants to repeat them, possibly using associated consts if generics are involved).

Well, I said "no semantic ambiguities", that is only almost true... the one point I am not sure about is `[CONST; 0]`. There are two possible behaviors here: either this is equivalent to `let x = CONST; [x; 0]`, or it is a NOP (if we argue that the constant is never actually instantiated). The difference between the two is that if `CONST` has a destructor, it should run in the former case (but currently doesn't, due to https://github.com/rust-lang/rust/issues/74836); but should not run if it is considered a NOP. For regular `[x; 0]` there seems to be consensus on running drop (there isn't really an alternative); any opinions for the `CONST` special case? Should this instantiate the const only to immediately run its destructors? That seems somewhat silly to me. After all, the `let`-expansion does *not* work in general, for `N > 1`.

Cc `@rust-lang/lang` `@rust-lang/wg-const-eval`
Cc https://github.com/rust-lang/rust/issues/49147
2020-12-21 13:12:36 +00:00
Dion Dokter a272d621bc Implemented a compiler diagnostic for move async mistake
Ran the tidy check

Following the diagnostic guide better

Diagnostic generation is now relegated to its own function in the diagnostics module.
Added tests

Fixed the ui test
2020-12-21 12:57:08 +01:00
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
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