Commit graph

6941 commits

Author SHA1 Message Date
bors eba3228b2a Auto merge of #86251 - Smittyvb:thir-tree-again, r=oli-obk
Support -Z unpretty=thir-tree again

Currently `-Z unpretty=thir-tree` is broken after some THIR refactorings. This re-implements it, making it easier to debug THIR-related issues.

We have to do analyzes before getting the THIR, since trying to create THIR from invalid HIR can ICE. But doing those analyzes requires the THIR to be built and stolen. We work around this by creating a separate query to construct the THIR tree string representation.

Closes https://github.com/rust-lang/project-thir-unsafeck/issues/8, fixes #85552.
2021-07-28 09:01:11 +00:00
bors aea2e446f0 Auto merge of #86735 - jhpratt:rfc-3107, r=petrochenkov
Implement RFC 3107: `#[derive(Default)]` on enums with a `#[default]` attribute

This PR implements RFC 3107, which permits `#[derive(Default)]` on enums where a unit variant has a `#[default]` attribute. See comments for current status.
2021-07-28 05:59:30 +00:00
bors 8b50cc9a2c Auto merge of #85769 - jhpratt:stabilize-const-transmute-union, r=RalfJung
Stabilize `const_fn_transmute`, `const_fn_union`

This PR stabilizes the `const_fn_transmute` and `const_fn_union` features. It _does not_ stabilize any methods (obviously aside from `transmute`) that are blocked on only these features.

Closes #53605. Closes #51909.
2021-07-28 00:53:17 +00:00
Jacob Pratt 7bf791d162
Stabilize const_fn_union 2021-07-27 16:03:33 -04:00
Jacob Pratt 36f02f3523
Stabilize const_fn_transmute 2021-07-27 16:03:09 -04:00
bors 2faabf5793 Auto merge of #80367 - camelid:check_match-combine-loop, r=Nadrieril
Combine two loops in `check_match`

Suggested by Nadrieril in
https://github.com/rust-lang/rust/pull/79051#discussion_r548778186.

Opening to get a perf run. Hopefully this code doesn't require everything in the
first loop to be done before running the second! (It shouldn't though.)

cc `@Nadrieril`
2021-07-27 19:56:18 +00:00
Jacob Pratt 72465b0a32
Prohibit #[default] in invalid places 2021-07-27 15:47:49 -04:00
Jacob Pratt 5ae2371ceb
Indicate E0665 is no longer emitted 2021-07-27 15:47:49 -04:00
Jacob Pratt eef2856eaf
Add machine-applicable suggestions
This avoids the need for tools like rust-analyzer to implement these
suggestions themselves.
2021-07-27 15:47:49 -04:00
Jacob Pratt c70147fd66
Permit deriving default on enums with #[default] 2021-07-27 15:47:47 -04:00
bors fd853c00e2 Auto merge of #83484 - JulianKnodt:infer, r=oli-obk,lcnr
Add hir::GenericArg::Infer

In order to extend inference to consts, make an Infer type on hir::GenericArg.
2021-07-27 16:24:45 +00:00
Yuki Okushi 54367b90fc
Rollup merge of #87499 - ibraheemdev:patch-6, r=dtolnay
Remove ASCII fast path from `rustc_lexer::{is_id_continue, is_id_start}`

`unicode_xid` now has a fast path built-in: 122b38775c
2021-07-27 19:52:50 +09:00
Yuki Okushi a981cffb23
Rollup merge of #87497 - midgleyc:long-E0544, r=GuillaumeGomez
Add long explanation for E0544.

Helps with #61137
2021-07-27 19:52:49 +09:00
Yuki Okushi d25439481c
Rollup merge of #87427 - RalfJung:no-mir-for, r=oli-obk
get rid of NoMirFor error variant

The only place where we throw that error, it is very quickly caught again and turned into a different error. So raise that other error immediately.
2021-07-27 19:52:46 +09:00
Yuki Okushi 4e1ebf23cd
Rollup merge of #86764 - estebank:issue-86756, r=pnkfelix
Avoid ICE on type error recovery

Fix #86756
2021-07-27 19:52:41 +09:00
Yuki Okushi 99a6474bc4
Rollup merge of #86450 - tmiasko:move-size-limit, r=pnkfelix
Add flag to configure `large_assignments` lint

The `large_assignments` lints detects moves over specified limit.  The
limit is configured through `move_size_limit = "N"` attribute placed at
the root of a crate. When attribute is absent, the lint is disabled.

Make it possible to enable the lint without making any changes to the
source code, through a new flag `-Zmove-size-limit=N`.  For example, to
detect moves exceeding 1023 bytes in a cargo crate, including all
dependencies one could use:

```
$ env RUSTFLAGS=-Zmove-size-limit=1024 cargo build -vv
```

Lint tracking issue #83518.
2021-07-27 19:52:40 +09:00
bors 998cfe5aad Auto merge of #85305 - MarcusDunn:master, r=pnkfelix
Stabilize bindings_after_at

attempting to stabilze bindings_after_at [#65490](https://github.com/rust-lang/rust/issues/65490), im pretty new to the whole thing so any pointers are greatly appreciated.
2021-07-27 05:53:31 +00:00
bors 7d6bf861f8 Auto merge of #83491 - jyn514:remove-pretty, r=pnkfelix
Remove unstable `--pretty` flag

It doesn't do anything `--unpretty` doesn't, and due to a bug, also
didn't show up in `--help`. I don't think there's any reason to keep it
around, I haven't seen anyone using it.

Closes https://github.com/rust-lang/rust/issues/36473.
2021-07-27 03:12:40 +00:00
Ibraheem Ahmed a397fdcc38
Remove ASCII fast path from rustc_lexer::{is_id_continue, is_id_start} 2021-07-26 20:17:28 -04:00
Chris Midgley b21024f7b9 Add long explanation for E0544. 2021-07-26 22:59:16 +01:00
bors 8bebfe5cc2 Auto merge of #87480 - GuillaumeGomez:rollup-3ly8t5d, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #87436 (Suggest `;` on parse error where applicable)
 - #87444 (Flatten nested `format!` calls)
 - #87447 (Miri: santiy check that null pointer can never have an AllocId)
 - #87457 (freebsd remove compiler workaround.)
 - #87458 (Fix help message for modification to &T created by &{t})
 - #87464 (Remove unnecessary `structhead` parameter from `render_union`)
 - #87473 (Notify the Rust 2021 edition working group in zulip of edition bugs)
 - #87474 (Add missing whitespace after attribute in HTML template)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-26 21:50:24 +00:00
kadmin 8759f00c73 Actually infer args in visitors 2021-07-26 21:15:18 +00:00
bors 08095fc1f8 Auto merge of #87469 - sexxi-goose:union, r=nikomatsakis
2229: Don't capture preicese paths on top of a union

- Accessing fields of a union require unsafe block
- As part of 2229 we don't allow precision where we need an unsafe block
to capture.

Fixes: #87378

r? `@nikomatsakis`
2021-07-26 19:04:01 +00:00
Guillaume Gomez f9d00b4a78
Rollup merge of #87458 - ibraheemdev:help-msg-block-borrow, r=oli-obk
Fix help message for modification to &T created by &{t}

Previous:
```rust
error[E0594]: cannot assign to `*x` which is behind a `&` reference
 --> src/main.rs:3:5
  |
2 |     let x: &usize = &mut{0};
  |                     ------- help: consider changing this to be a mutable reference: `&mut mut{0}`
3 |     *x = 1;
  |     ^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written
```
2021-07-26 16:04:36 +02:00
Guillaume Gomez e3c6cd23cf
Rollup merge of #87457 - devnexen:fbsd_remove_workaround, r=petrochenkov
freebsd remove compiler workaround.

related issue #43575
2021-07-26 16:04:35 +02:00
Guillaume Gomez fc0b4848cb
Rollup merge of #87447 - RalfJung:not-null, r=oli-obk
Miri: santiy check that null pointer can never have an AllocId
2021-07-26 16:04:34 +02:00
Guillaume Gomez 4205077537
Rollup merge of #87436 - ebobrow:suggest-semicolon, r=oli-obk
Suggest `;` on parse error where applicable

fixes #87197
2021-07-26 16:04:26 +02:00
Aman Arora 75edcd9e07 2229: Don't capture preicese paths on top of a union
- Accessing fields of a union require unsafe block
- As part of 2229 we don't allow precision where we need an unsafe block
to capture.

Fixes: #87378

r? @nikomatsakis
2021-07-26 02:01:52 -04:00
bors 9cf1944217 Auto merge of #87439 - ThibsG:FixDocTypo, r=jonas-schievink
Fix doc typo

Just a typo in doc that has a bad rendering here: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_typeck/expr_use_visitor/struct.ExprUseVisitor.html#method.walk_captures
2021-07-26 05:51:40 +00:00
bors 3bcce82d14 Auto merge of #87424 - RalfJung:const-check, r=oli-obk
rename const checking visitor module to check_consts::check

This avoids naming ambiguities with "const validation" which is in `interpret/validity.rs` and checks *values*.

r? `@oli-obk`
2021-07-26 03:10:42 +00:00
ibraheemdev b4a873f548 fmt 2021-07-25 13:35:06 -04:00
ibraheemdev 70f282d469 fix help message for modification to &T created by &{t} 2021-07-25 13:17:47 -04:00
David Carlier 76d1453b5b freebsd remove compiler workaround.
related issue #43575
2021-07-25 17:38:44 +01:00
bors 478126c0f3 Auto merge of #86438 - FabianWolff:issue-83693, r=jackh726
Fix the ICE described in #83693

This pull request fixes #83693 and fixes #84768.
2021-07-25 16:17:58 +00:00
bors 70f74719a9 Auto merge of #85646 - Moxinilian:separate-const-switch, r=cjgillot
MIR opt: separate constant predecessors of a switch

For each block S ending with a switch, this pass copies S for each of S's predecessors that seem to assign the value being switched over as a const. This is done using a somewhat simple heuristic to determine what seems to be a const transitively.

More precisely, this is what the pass does:
- find a block that ends in a switch
- track if there is an unique place set before the current basic block that determines the result of the switch (this is the part that resolves switching over discriminants)
- if there is, iterate over the parents that have a reasonable terminator and find if the found determining place is likely to be (transitively) set from a const within that parent block
- if so, add the corresponding edge to a vector of edges to duplicate
- once this is done, iterate over the found edges: copy the target block and replace the reference to the target block in the origin block with the new block

This pass is not optimal and could probably duplicate in more cases, but the intention was mostly to address cases like in #85133 or #85365, to avoid creating new enums that get destroyed immediately afterwards (notably making the new try v2 `?` desugar zero-cost).

A benefit of this pass working the way it does is that it is easy to ensure its correctness: the worst that can happen is for it to needlessly copy a basic block, which is likely to be destroyed by cleanup passes afterwards. The complex parts where aliasing matters are only heuristics and the hard work is left to further passes like ConstProp.

# LLVM blocker

Unfortunately, I believe it would be unwise to enable this optimization by default for now. Indeed, currently switch lowering passes like SimplifyCFG in LLVM lose the information on the set of possible variant values, which means it tends to actually generate worse code with this optimization enabled. A fix would have to be done in LLVM itself. This is something I also want to look into. I have opened [a bug report at the LLVM bug tracker](https://bugs.llvm.org/show_bug.cgi?id=50455).

When this is done, I hope we can enable this pass by default. It should be fairly fast and I think it is beneficial in many cases. Notably, it should be a sound alternative to simplify-arm-identity. By the way, ConstProp only seems to pick up the optimization in functions that are not generic. This is however most likely an issue in ConstProp that I will look into afterwards.

This is my first contribution to rustc, and I would like to thank everyone on the Zulip mir-opt chat for the help and support, and especially `@scottmcm` for the guidance.
2021-07-25 13:51:48 +00:00
bors 6489ee1041 Auto merge of #83723 - cjgillot:ownernode, r=petrochenkov
Store all HIR owners in the same container

This replaces the previous storage in a BTreeMap for each of Item/ImplItem/TraitItem/ForeignItem.
This should allow for a more compact storage.

Based on https://github.com/rust-lang/rust/pull/83114
2021-07-25 11:11:02 +00:00
Camille GILLOT f798510d02 Only check macro attributes when checking the crate root. 2021-07-25 12:23:37 +02:00
Camille GILLOT 6709648d17 Use more of OwnerNode. 2021-07-25 12:23:37 +02:00
Camille GILLOT b88083a58c Use OwnerNode in indexing. 2021-07-25 12:23:36 +02:00
Camille GILLOT fee421685d Introduce OwnerNode::Crate. 2021-07-25 12:22:47 +02:00
Camille GILLOT 36a28060f1 Merge the BTreeMap in hir::Crate. 2021-07-25 12:18:56 +02:00
Ralf Jung f4861f3251 Miri: santiy check that null pointer can never have an AllocId 2021-07-25 11:31:57 +02:00
kadmin 3605675bb1 Add inferred args to typeck 2021-07-25 07:28:51 +00:00
kadmin 417b098cfc Add generic arg infer 2021-07-25 07:28:51 +00:00
bors 71a6c7c803 Auto merge of #87381 - Aaron1011:note-semi-trailing-macro, r=petrochenkov
Display an extra note for trailing semicolon lint with trailing macro

Currently, we parse macros at the end of a block
(e.g. `fn foo() { my_macro!() }`) as expressions, rather than
statements. This means that a macro invoked in this position
cannot expand to items or semicolon-terminated expressions.

In the future, we might want to start parsing these kinds of macros
as statements. This would make expansion more 'token-based'
(i.e. macro expansion behaves (almost) as if you just textually
replaced the macro invocation with its output). However,
this is a breaking change (see PR #78991), so it will require
further discussion.

Since the current behavior will not be changing any time soon,
we need to address the interaction with the
`SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint. Since we are parsing
the result of macro expansion as an expression, we will emit a lint
if there's a trailing semicolon in the macro output. However, this
results in a somewhat confusing message for users, since it visually
looks like there should be no problem with having a semicolon
at the end of a block
(e.g. `fn foo() { my_macro!() }` => `fn foo() { produced_expr; }`)

To help reduce confusion, this commit adds a note explaining
that the macro is being interpreted as an expression. Additionally,
we suggest adding a semicolon after the macro *invocation* - this
will cause us to parse the macro call as a statement. We do *not*
use a structured suggestion for this, since the user may actually
want to remove the semicolon from the macro definition (allowing
the block to evaluate to the expression produced by the macro).
2021-07-25 04:34:58 +00:00
Smitty e8165e7f1b Support -Z unpretty=thir-tree again 2021-07-24 17:18:15 -04:00
bors d9aa287672 Auto merge of #86580 - BoxyUwU:cgd-subst-ice, r=nikomatsakis
dont provide fwd declared params to cg defaults

Fixes #83938

```rust
#![feature(const_evaluatable_checked, const_generics, const_generics_defaults)]
#![allow(incomplete_features)]

pub struct Bar<const N: usize, const M: usize = { N + 1 }>;
pub fn foo<const N1: usize>() -> Bar<N1> { loop {} }

fn main() {}
```
This PR makes this code no longer ICE, it was ICE'ing previously because when building substs for `Bar<N1>` we would subst the anon ct: `ConstKind::Unevaluated({N + 1}, substs: [N, M])` with substs of `[N1]`. the anon const has forward declared params supplied though so we end up trying to substitute the provided `M` param which causes the ICE.

This PR doesn't handle the predicates of the const so
```rust
trait Foo<const N: usize> { const Assoc: usize; }
pub struct Bar<const N: usize = { <()>::Assoc }> where (): Foo<N>;
```
Resolves to `<() as Foo<N>>::Assoc` which can allow for using fwd declared params indirectly.

```rust
trait Foo<const N: usize> {}
struct Bar<const N: usize = { 2 + 3 }> where (): Foo<N>;
```
This code also ICEs under this PR because instantiating the default's predicates causes an ICE as predicates_of contains predicates with fwd declared params

PR was briefly discussed [in this zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/evil.20preds.20in.20param.20env.20.2386580)
2021-07-24 20:01:51 +00:00
ThibsG d1872194c8 Fix doc typo 2021-07-24 20:49:20 +02:00
Elliot Bobrow e0995a5a8d fix code to suggest ; on parse error 2021-07-24 10:58:55 -07:00
Manish Goregaokar 075d3a15b4
Rollup merge of #87403 - LeSeulArtichaut:assign-dropping-union, r=oli-obk
Implement `AssignToDroppingUnionField` in THIR unsafeck

r? ``@oli-obk`` cc rust-lang/project-thir-unsafeck#7
2021-07-24 09:52:01 -07:00