Commit Graph

13801 Commits

Author SHA1 Message Date
Matthias Krüger
992ca9b601
Rollup merge of #97627 - lcnr:comment-tick, r=Dylan-DPC
update explicit impls error msg
2022-06-02 23:39:04 +02:00
bors
42bcd41d4d Auto merge of #97598 - spastorino:simplify-universal-impl-trait-lowering, r=cjgillot
Simplify universal impl trait lowering

Closes #96644

r? `@cjgillot`
2022-06-02 21:37:38 +00:00
Esteban Küber
8567b686f9 On E0204 suggest missing type param bounds
```
error[E0204]: the trait `Copy` may not be implemented for this type
  --> f42.rs:9:17
   |
9  | #[derive(Debug, Copy, Clone)]
   |                 ^^^^
10 | pub struct AABB<K>{
11 |     pub loc: Vector2<K>,
   |     ------------------- this field does not implement `Copy`
12 |     pub size: Vector2<K>
   |     -------------------- this field does not implement `Copy`
   |
note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
  --> f42.rs:11:5
   |
11 |     pub loc: Vector2<K>,
   |     ^^^^^^^^^^^^^^^^^^^
note: the `Copy` impl for `Vector2<K>` requires that `K: Debug`
  --> f42.rs:12:5
   |
12 |     pub size: Vector2<K>
   |     ^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `K`
   |
10 | pub struct AABB<K: Debug>{
   |                  +++++++
```

Fix #89137.
2022-06-02 12:54:04 -07:00
Ralf Jung
7676f07d0e take back half-baked noaliasing check in Assignment 2022-06-02 15:14:35 -04:00
bors
e71440575c Auto merge of #97575 - nnethercote:lazify-SourceFile-lines, r=Mark-Simulacrum
Lazify `SourceFile::lines`.

`SourceFile::lines` is a big part of metadata. It's stored in a compressed form
(a difference list) to save disk space. Decoding it is a big fraction of
compile time for very small crates/programs.

This commit introduces a new type `SourceFileLines` which has a `Lines`
form and a `Diffs` form. The latter is used when the metadata is first
read, and it is only decoded into the `Lines` form when line data is
actually needed. This avoids the decoding cost for many files,
especially in `std`. It's a performance win of up to 15% for tiny
crates/programs where metadata decoding is a high part of compilation
costs.

A `RefCell` is needed because the methods that access lines data (which can
trigger decoding) take `&self` rather than `&mut self`. To allow for this,
`SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather
than returning the lines slice.

r? `@Mark-Simulacrum`
2022-06-02 18:45:29 +00:00
Camille GILLOT
be40b58895 Stop warning against unrelated labels. 2022-06-02 19:24:26 +02:00
Camille GILLOT
257d8fce3e Do not report mixed label/lifetime shadowing. 2022-06-02 19:24:12 +02:00
Camille GILLOT
6e1b0105c6 Diagnose shadowing on AST. 2022-06-02 19:23:39 +02:00
bors
44e9516c85 Auto merge of #97654 - Dylan-DPC:rollup-w6zrzxf, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #97420 (Be a little nicer with casts when formatting `fn` pointers)
 - #97450 ([RFC 2011] Basic compiler infrastructure)
 - #97599 (Fix JSON reexport ICE)
 - #97617 (Rustdoc anonymous reexports)
 - #97636 (Revert #96682.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-02 16:04:42 +00:00
Ralf Jung
d5a590f537 comment
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2022-06-02 11:12:12 -04:00
Ralf Jung
fafccdced3 add cast kind of from_exposed_addr (int-to-ptr casts) 2022-06-02 10:46:13 -04:00
Dylan DPC
1d71237646
Rollup merge of #97636 - nnethercote:revert-96682, r=dtolnay
Revert #96682.

The change was "Show invisible delimiters (within comments) when pretty
printing". It's useful to show these delimiters, but is a breaking
change for some proc macros.

Fixes #97608.

r? ``@petrochenkov``
2022-06-02 15:27:01 +02:00
Dylan DPC
15bf62b475
Rollup merge of #97450 - c410-f3r:assert-compiler, r=oli-obk
[RFC 2011] Basic compiler infrastructure

Splitting https://github.com/rust-lang/rust/pull/96496 into smaller pieces as was done in https://github.com/rust-lang/rust/pull/97233. Hope review will be easier.

This PR practically contains no logic and only serves as a building ground for the actual code that will be placed in a posterior step.

* Adds `context.rs` to place the new `assert!` logic. Has a lot of unused elements but all of them are used by the implementation.
* Creates an unstable flag because the feature is not yet complete and also to allow external feedback.
* Creates the necessary `sym` identifiers that are mostly based on the library elements -> https://github.com/rust-lang/rust/blob/master/library/core/src/asserting.rs
* Modifies `assert.rs` to branch to `context.rs` if the unstable flag is enabled.
* Adds a test to satisfy tidy but the test does nothing in reality.
2022-06-02 15:26:58 +02:00
bors
20976bae5c Auto merge of #97293 - est31:remove_box, r=oli-obk
Add #[rustc_box] and use it inside alloc

This commit adds an alternative content boxing syntax, and uses it inside alloc.

```Rust
#![feature(box_syntax)]

fn foo() {
    let foo = box bar;
}
```

is equivalent to

```Rust
#![feature(rustc_attrs)]

fn foo() {
    let foo = #[rustc_box] Box::new(bar);
}
```

The usage inside the very performance relevant code in
liballoc is the only remaining relevant usage of box syntax
in the compiler (outside of tests, which are comparatively easy to port).

box syntax was originally designed to be used by all Rust
developers. This introduces a replacement syntax more tailored
to only being used inside the Rust compiler, and with it,
lays the groundwork for eventually removing box syntax.

[Earlier work](https://github.com/rust-lang/rust/pull/87781#issuecomment-894714878) by `@nbdd0121` to lower `Box::new` to `box` during THIR -> MIR building ran into borrow checker problems, requiring the lowering to be adjusted in a way that led to [performance regressions](https://github.com/rust-lang/rust/pull/87781#issuecomment-894872367). The proposed change in this PR lowers `#[rustc_box] Box::new` -> `box` in the AST -> HIR lowering step, which is way earlier in the compiler, and thus should cause less issues both performance wise as well as regarding type inference/borrow checking/etc. Hopefully, future work can move the lowering further back in the compiler, as long as there are no performance regressions.
2022-06-02 13:20:19 +00:00
Caio
aa115eba12 Basic compiler infra 2022-06-02 09:00:04 -03:00
Takayuki Maeda
28988902a2 fix wrong suggestion for adding where clauses 2022-06-02 20:50:01 +09:00
bors
9598b4b594 Auto merge of #97644 - Dylan-DPC:rollup-xaeio91, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #96894 (Apply track_caller to closure on `expect_non_local()`)
 - #97023 (Diagnose anonymous lifetimes errors more uniformly between async and regular fns)
 - #97397 (Stabilize `box_into_pin`)
 - #97587 (Migrate more diagnostics to use the `#[derive(SessionDiagnostic)]`)
 - #97603 (Arc make_mut doc comment spelling correction.)
 - #97635 (Fix file metadata documentation for Windows)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-02 10:39:24 +00:00
lcnr
d7645f4245 don't use a span_note for ignored impls 2022-06-02 11:13:31 +02:00
Dylan DPC
19dc28c23e
Rollup merge of #97587 - pvdrz:maybe-recover-from-bad-qpath-stage-2, r=davidtwco
Migrate more diagnostics to use the `#[derive(SessionDiagnostic)]`

r? ``@davidtwco``
2022-06-02 11:13:24 +02:00
Dylan DPC
5c041f98fa
Rollup merge of #97023 - cjgillot:uniform-anon, r=estebank
Diagnose anonymous lifetimes errors more uniformly between async and regular fns

Async fns and regular fns are desugared differently.  For the former, we create a generic parameter at HIR level.  For the latter, we just create an anonymous region for typeck.

I plan to migrate regular fns to the async fn desugaring.

Before that, this PR attempts to merge the diagnostics for both cases.

r? ```@estebank```
2022-06-02 11:13:22 +02:00
Dylan DPC
ddc5d2c9d2
Rollup merge of #96894 - JohnTitor:expect-non-local-track-caller, r=petrochenkov
Apply track_caller to closure on `expect_non_local()`

r? `@petrochenkov`

Alternatively we could remove the closure by replicating the same logic of `map_id()`. I'm happy to switch to it if you'd like.
2022-06-02 11:13:21 +02:00
lcnr
681736a6b2 generic_arg_contains_target: ignore closures 2022-06-02 10:19:15 +02:00
lcnr
69d575e58d eagerly fetch the typeck_results 2022-06-02 10:19:15 +02:00
lcnr
bc0d12cc6c use verbose suggestions 2022-06-02 10:19:15 +02:00
lcnr
3fe346e7a3 add new emit_inference_failure_err 2022-06-02 10:19:15 +02:00
lcnr
721fc73208 remove the old emit_inference_failure_err 2022-06-02 10:19:15 +02:00
bors
5e6bb83268 Auto merge of #96737 - ChrisDenton:win-manifest, r=wesleywiser
Add Windows application manifest to rustc-main

Windows allows setting some runtime options using a manifest file. The format of the XML file is documented here: https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests

The manifest file in this PR does three things:

* Declares which Windows versions we support. This may help avoid unnecessary compatibility shims.
* Uses the UTF-8 code page. While Rust itself uses UTF-16 APIs, other code may rely on the code page.
* Makes the application long path aware (if also enabled by the user). This allows for the current directory to be longer than `PATH_MAX`.

These changes only affect the `rustc` process and not any other DLLs or compiled programs.
2022-06-02 07:58:29 +00:00
Nicholas Nethercote
72de7c4102 Address review comments. 2022-06-02 12:22:04 +10:00
Nicholas Nethercote
77e1069a5d Revert #96682.
The change was "Show invisible delimiters (within comments) when pretty
printing". It's useful to show these delimiters, but is a breaking
change for some proc macros.

Fixes #97608.
2022-06-02 11:22:16 +10:00
Esteban Küber
ad63f907e9 Make output more specific 2022-06-01 17:46:55 -07:00
Yuki Okushi
b78c118b09
Rollup merge of #97626 - RalfJung:expose, r=tmiasko
rename PointerAddress → PointerExposeAddress

`PointerAddress` sounds a bit too much like `ptr.addr()`, but this corresponds to `ptr.expose_addr()`.

r? `@tmiasko`
2022-06-02 06:44:29 +09:00
Yuki Okushi
2c1990d0b8
Rollup merge of #97605 - estebank:suggestion-filename, r=oli-obk
Mention filename in suggestion when it differs from primary span
2022-06-02 06:44:28 +09:00
Yuki Okushi
d126de111b
Rollup merge of #97166 - nnethercote:move-conditions-out, r=estebank
Move conditions out of recover/report functions.

`Parser` has six recover/report functions that are passed a boolean, and
nothing is done if the boolean has a particular value.

This PR moves the tests outside the functions. This has the following effects.
- The number of lines of code goes down.
- Some `use` items become shorter.
- Avoids the strangeness whereby 11 out of 12 calls to
  `maybe_recover_from_bad_qpath` pass `true` as the second argument.
- Makes it clear at the call site that only one of
  `maybe_recover_from_bad_type_plus` and `maybe_report_ambiguous_plus` will be
  run.

r? `@estebank`
2022-06-02 06:44:27 +09:00
Esteban Küber
196a30ebff Fix typo 2022-06-01 13:04:35 -07:00
Santiago Pastorino
15a82d6917
Always assert that impl_trait_def|bounds are empty at start 2022-06-01 15:38:37 -03:00
lcnr
79c3011d9d update explicit impls error msg 2022-06-01 20:36:20 +02:00
Ralf Jung
4dc5d457d8 rename PointerAddress → PointerExposeAddress 2022-06-01 14:08:17 -04:00
Santiago Pastorino
67deaf9fea
instrument lower_fn_decl 2022-06-01 15:02:15 -03:00
Santiago Pastorino
2de2520e94
Split extend + inner chain into to extend calls 2022-06-01 14:48:14 -03:00
Santiago Pastorino
b3bc438f56
Add debug_assert comment
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2022-06-01 14:43:16 -03:00
Esteban Küber
532671b8ee More accurately handle suggestions
* Confirm the path segment being modified is an `enum`
* Check whether type has type param before suggesting changing `Self`
* Wording changes
* Add clarifying comments
* Suggest removing args from `Self` if the type doesn't have type params
2022-06-01 10:41:50 -07:00
Esteban Küber
9b2d80a197 Provide more context when denying invalid type params 2022-06-01 10:41:50 -07:00
Esteban Küber
f023b920b1 Rework prohibit_generics 2022-06-01 10:41:50 -07:00
bors
b5a2d27f8f Auto merge of #97624 - matthiaskrgr:rollup-rtcqjx9, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #96271 (suggest `?` when method is missing on `Result<T, _>` but found on `T`)
 - #97264 (Suggest `extern crate foo` when failing to resolve `use foo`)
 - #97592 (rustdoc: also index impl trait and raw pointers)
 - #97621 (update Miri)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-01 17:25:29 +00:00
Esteban Küber
310b1a9062 Mention filename in suggestion when it differs from primary span 2022-06-01 09:52:03 -07:00
Matthias Krüger
daedae7b23
Rollup merge of #97264 - TaKO8Ki:suggest-extern-crate-when-failing-to-resolve-use-crate, r=estebank
Suggest `extern crate foo` when failing to resolve `use foo`

closes #97095

r? ``@estebank``
2022-06-01 17:11:05 +02:00
Matthias Krüger
7d4cf710e2
Rollup merge of #96271 - compiler-errors:suggest-question-mark, r=estebank
suggest `?` when method is missing on `Result<T, _>` but found on `T`

The wording needs help, I think.

Fixes #95729
2022-06-01 17:11:04 +02:00
Yuki Okushi
85fdef087c
Rollup merge of #97616 - TaKO8Ki:remove-unnecessary-option, r=Dylan-DPC
Remove an unnecessary `Option`
2022-06-01 23:36:53 +09:00
Yuki Okushi
2c3a8cf0a4
Rollup merge of #97611 - azdavis:master, r=Dylan-DPC
Tweak insert docs

For `{Hash, BTree}Map::insert`, I always have to take a few extra seconds to think about the slight weirdness about the fact that if we "did not" insert (which "sounds" false), we return true, and if we "did" insert, (which "sounds" true), we return false.

This tweaks the doc comments for the `insert` methods of those types (as well as what looks like a rustc internal data structure that I found just by searching the codebase for "If the set did") to first use the "Returns whether _something_" pattern used in e.g. `remove`, where we say that `remove` "returns whether the value was present".
2022-06-01 23:36:52 +09:00
Yuki Okushi
2f99f1b3a4
Rollup merge of #97562 - compiler-errors:comment-poly_project_and_unify_type, r=lcnr
Fix comment in `poly_project_and_unify_type`

Renamed some variants to match `ProjectAndUnifyResult`
2022-06-01 23:36:50 +09:00
Yuki Okushi
9c61f817eb
Rollup merge of #97399 - SparrowLii:arg_index, r=oli-obk
simplify code of finding arg index in `opt_const_param_of`

From the FIXME in the impl of `opt_const_param_of`. Part of the code is simplified by blending two iterator statements and using `let...else` statement.
2022-06-01 23:36:47 +09:00
Yuki Okushi
2ab919ad9c
Rollup merge of #97216 - RalfJung:null-ptr-check, r=oli-obk
Ensure we never consider the null pointer dereferencable

This replaces the checks that are being removed in https://github.com/rust-lang/rust/pull/97188. Those checks were too early and hence incorrect.
2022-06-01 23:36:46 +09:00
Christian Poveda
0fa70a8e2a
rename sp to span 2022-06-01 07:14:33 -05:00
Takayuki Maeda
8d007aa06d remove an unnecessary Option 2022-06-01 17:06:07 +09:00
Ariel Davis
b02146a370 Tweak insert docs 2022-05-31 22:08:14 -07:00
est31
0a24b9493b Remove #[rustc_box] attr during lowering 2022-06-01 02:44:12 +02:00
Nicholas Nethercote
0b81d7cdc6 Lazify SourceFile::lines.
`SourceFile::lines` is a big part of metadata. It's stored in a compressed form
(a difference list) to save disk space. Decoding it is a big fraction of
compile time for very small crates/programs.

This commit introduces a new type `SourceFileLines` which has a `Lines`
form and a `Diffs` form. The latter is used when the metadata is first
read, and it is only decoded into the `Lines` form when line data is
actually needed. This avoids the decoding cost for many files,
especially in `std`. It's a performance win of up to 15% for tiny
crates/programs where metadata decoding is a high part of compilation
costs.

A `Lock` is needed because the methods that access lines data (which can
trigger decoding) take `&self` rather than `&mut self`. To allow for this,
`SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather
than returning the lines slice.
2022-06-01 10:36:39 +10:00
est31
cfc21deebd Add #[rustc_box]
This commit adds an alternative content boxing syntax,
and uses it inside alloc.

The usage inside the very performance relevant code in
liballoc is the only remaining relevant usage of box syntax
in the compiler (outside of tests, which are comparatively
easy to port).

box syntax was originally designed to be used by all Rust
developers. This introduces a replacement syntax more tailored
to only being used inside the Rust compiler, and with it,
lays the groundwork for eventually removing box syntax.
2022-06-01 02:28:34 +02:00
Christian Poveda
e1d63d1d7c
migrate check_for_for_in_in_typo diagnostic 2022-05-31 16:28:05 -05:00
Santiago Pastorino
15f2b119b1
Fix lower_generics rustdocs 2022-05-31 17:40:50 -03:00
Christian Poveda
9ce04e3783
merge diagnostics about incorrect uses of .await 2022-05-31 15:07:44 -05:00
Santiago Pastorino
2ade55d908
Inline lower_generics_mut and remove GenericsCtor 2022-05-31 16:57:16 -03:00
Santiago Pastorino
d327db9319
Remove ImplTraitContext::reborrow 2022-05-31 16:49:27 -03:00
Santiago Pastorino
208ffbbe86
derive Copy, Clone, PartialEq, Eq for ImplTraitContext 2022-05-31 16:47:53 -03:00
Christian Poveda
a06ba45487
migrate error_on_incorrect_await diagnostic 2022-05-31 14:32:07 -05:00
Santiago Pastorino
bd3a097d64
Move lower_generics definition to item.rs 2022-05-31 15:33:51 -03:00
Santiago Pastorino
d5ab8b2f5b
Rename add_implicit_generics to lower_generics 2022-05-31 15:32:05 -03:00
Santiago Pastorino
e080298e35
Replace calls to lower_generics with calls to add_implicit_generics 2022-05-31 15:30:14 -03:00
Christian Poveda
2a0496cbc8
use suggestion_short for incorrect semicolon diagnostic 2022-05-31 12:56:26 -05:00
Santiago Pastorino
190b4a7152
Add itctx: ImplTraitContext arg to add_implicit_generics 2022-05-31 14:55:49 -03:00
Santiago Pastorino
1a71103c93
Take and restore fields in with_hir_id_owner calls 2022-05-31 14:53:32 -03:00
Christian Poveda
93a427e3ca
migrate recover_from_await_method_call diagnostic 2022-05-31 12:33:35 -05:00
Michael Goulet
c00d9bf324 Fix comment in poly_project_and_unify_type 2022-05-31 10:13:05 -07:00
Christian Poveda
29ed9a56e3
migrate maybe_consume_incorrect_semicolon diagnostic 2022-05-31 11:45:44 -05:00
Christian Poveda
bd4d1cd7a2
migrate maybe_recover_from_bad_qpath_stage_2 diagnostic 2022-05-31 11:22:26 -05:00
Santiago Pastorino
3d6eae8cd2
Move defs and bounds from Universal to LoweringContext 2022-05-31 12:40:34 -03:00
Yuki Okushi
c7db4b08ff
Apply track_caller to closure on expect_non_local() 2022-05-31 23:57:13 +09:00
Dylan DPC
38d8167d2e
Rollup merge of #97371 - ChayimFriedman2:closure-non-block-add-semicolon, r=oli-obk
Suggest adding a semicolon to a closure without block

This transforms `|| expr` into `|| { expr; }`.

Closes #97359.
2022-05-31 07:57:34 +02:00
bors
47365c0d65 Auto merge of #97566 - compiler-errors:rollup-qfxw4j8, r=compiler-errors
Rollup of 6 pull requests

Successful merges:

 - #89685 (refactor: VecDeques Iter fields to private)
 - #97172 (Optimize the diagnostic generation for `extern unsafe`)
 - #97395 (Miri call ABI check: ensure type size+align stay the same)
 - #97431 (don't do `Sized` and other return type checks on RPIT's real type)
 - #97555 (Source code page: line number click adds `NaN`)
 - #97558 (Fix typos in comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-31 01:17:00 +00:00
Tomasz Miąsko
dff602fc18 Add a pointer to address cast kind
A pointer to address cast are often special-cased.
Introduce a dedicated cast kind to make them easy distinguishable.
2022-05-31 00:00:00 +00:00
Michael Goulet
b3dc31ca9c
Rollup merge of #97558 - stoeckmann:typos, r=compiler-errors
Fix typos in comment

Just two typos in HashingControls' description.
2022-05-30 15:57:31 -07:00
Michael Goulet
6718723c96
Rollup merge of #97431 - compiler-errors:issue-97413, r=oli-obk
don't do `Sized` and other return type checks on RPIT's real type

Fixes an ICE where we're doing `Sized` check against the RPIT's real type, instead of against the opaque type. This differs from what we're doing in MIR typeck, which causes ICE #97226.

This regressed in #96516 -- this adjusts that fix to be a bit more conservative. That PR was backported and thus the ICE is also present in stable. Not sure if it's worth to beta and/or stable backport, probably not the latter but I could believe the former.

r? `@oli-obk`

cc: another attempt to fix this ICE #97413. I believe this PR addresses the root cause.
2022-05-30 15:57:29 -07:00
Michael Goulet
12ba87b996
Rollup merge of #97395 - RalfJung:call-abi, r=oli-obk
Miri call ABI check: ensure type size+align stay the same

We should almost certainly not accept calls where caller and callee disagree on the size or alignment of the type.

The checks we do *almost* imply that, except that `ScalarPair` types can have `repr(align)` and thus differ in size/align even when they are pairs of the same primitive type.

r? ``@oli-obk``
2022-05-30 15:57:28 -07:00
Michael Goulet
22da719762
Rollup merge of #97172 - SparrowLii:unsafe_extern, r=compiler-errors
Optimize the diagnostic generation for `extern unsafe`

This PR does the following about diagnostic generation when parsing foreign mod:
1. Fixes the FIXME about avoiding depending on the error message text.
2. Continue parsing when `unsafe` is followed by `{` (just like `unsafe extern {...}`).
3. Add test case.
2022-05-30 15:57:27 -07:00
bors
7be9ec2765 Auto merge of #97357 - davidtwco:diagnostic-translation-typed-subdiagnostic-simplification, r=oli-obk
errors: simplify referring to fluent attributes

To render the message of a Fluent attribute, the identifier of the Fluent message must be known. `DiagnosticMessage::FluentIdentifier` contains both the message's identifier and optionally the identifier of an attribute. Generated constants for each attribute would therefore need to be named uniquely (amongst all error messages) or be able to refer to only the attribute identifier which will be combined with a message identifier later. In this commit, the latter strategy is implemented as part of the `Diagnostic` type's functions for adding subdiagnostics of various kinds.

r? `@oli-obk`
2022-05-30 22:49:36 +00:00
Michael Goulet
2a61f0cc45 address comments 2022-05-30 14:23:15 -07:00
Michael Goulet
aeb765b299 better enum suggestions 2022-05-30 13:52:40 -07:00
Chayim Refael Friedman
6afaffb9c2 Check for can_have_side_effects() and in_external_macro() inside suggest_missing_semicolon() 2022-05-30 20:35:51 +00:00
bors
c35035cefc Auto merge of #97025 - ouz-a:mini-derefer-generator, r=davidtwco
Add validation layer for Derefer

_Follow up work to #96549 #96116 #95857 #95649_

This adds validation for Derefer making sure it is always the first projection.

r? rust-lang/mir-opt
2022-05-30 20:06:25 +00:00
Tobias Stoeckmann
56662bcdff Fix typos in comment 2022-05-30 21:21:32 +02:00
ouz-a
e71913e847 validate derefer, run derefer inside generator 2022-05-30 18:36:14 +03:00
Urgau
163374644b Handle more cases in cfg_accessible 2022-05-30 16:51:38 +02:00
David Wood
f669b78ffc errors: simplify referring to fluent attributes
To render the message of a Fluent attribute, the identifier of the
Fluent message must be known. `DiagnosticMessage::FluentIdentifier`
contains both the message's identifier and optionally the identifier of
an attribute. Generated constants for each attribute would therefore
need to be named uniquely (amongst all error messages) or be able to
refer to only the attribute identifier which will be combined with a
message identifier later. In this commit, the latter strategy is
implemented as part of the `Diagnostic` type's functions for adding
subdiagnostics of various kinds.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-30 13:38:19 +01:00
Dylan DPC
65bdfe3b41
Rollup merge of #97531 - compiler-errors:for-loop-pat-mismatch, r=davidtwco
Note pattern mismatch coming from `for` loop desugaring

Fixes #97163
2022-05-30 14:33:52 +02:00
Dylan DPC
106d5fde92
Rollup merge of #97504 - JohnTitor:cleanup-deps, r=davidtwco
Ensure source file present when calculating max line number

Resubmission of #89268, fixes #71363
The behavior difference of `simulate-remapped-rust-src-base` is not something we should take into account here, so limiting targets to run the test makes sense, I think.

r? `@davidtwco,` and `@estebank,` you might be interested in this change
2022-05-30 14:33:50 +02:00
bors
5c780b98d1 Auto merge of #96964 - oli-obk:const_trait_mvp, r=compiler-errors
Replace `#[default_method_body_is_const]` with `#[const_trait]`

pulled out of #96077

related issues:  #67792 and #92158

cc `@fee1-dead`

This is groundwork to only allowing `impl const Trait` for traits that are marked with `#[const_trait]`. This is necessary to prevent adding a new default method from becoming a breaking change (as it could be a non-const fn).
2022-05-30 09:19:03 +00:00
Oli Scherer
2f96fbe220 update diagnostic message on removed attribute
Co-authored-by: fee1-dead <ent3rm4n@gmail.com>
2022-05-30 08:52:25 +00:00
Oli Scherer
0e3d8d2b13 Default methods of traits are also AssocFn defs as they essentially desugar to a method in a new impl block 2022-05-30 08:52:25 +00:00
Oli Scherer
ecaf7b7cee Reduce the scope of a mutable variable 2022-05-30 08:52:25 +00:00
Oli Scherer
4d390de4a3 Add a helper function for checking whether a default function in a trait can be treated as const 2022-05-30 08:52:25 +00:00
Deadbeef
257f06587c Remove #[default..] and add #[const_trait] 2022-05-30 08:52:24 +00:00
SparrowLii
0be2ca96fa Optimize the diagnostic generation for extern unsafe 2022-05-30 15:56:43 +08:00
Scott McMurray
a5394aa27a Use CallConv::Cold in cranelift for extern "rust-cold" 2022-05-30 00:19:24 -07:00
Scott McMurray
e90be842fb Add support for emitting functions with coldcc in LLVM
The eventual goal is to try using this for things like the internal panicking stuff, to see whether it helps.
2022-05-30 00:19:23 -07:00
Michael Goulet
f20bbc1fb0
Rollup merge of #97536 - est31:remove_unused_lifetimes, r=compiler-errors
Remove unused lifetimes from expand_macro

The function doesn't need the lifetimes
of the two arguments be bound together.
2022-05-29 16:25:05 -07:00
Michael Goulet
56026e2fc6
Rollup merge of #97493 - compiler-errors:issue-97490, r=oli-obk
Use `type_is_copy_modulo_regions` check in intrisicck

This one canoncalizes region variables correctly, preventing an ICE

Fixes #97490
2022-05-29 16:25:02 -07:00
est31
311aacf0d0 Remove unused lifetimes from expand_macro
The function doesn't need the lifetimes
of the two arguments be bound together.
2022-05-29 23:53:24 +02:00
Michael Goulet
46d34cc922 Use type_is_copy_modulo_regions check in intrisicck 2022-05-29 13:06:50 -07:00
Michael Goulet
2e25c2346b Note pattern mismatch coming from for-loop desugaring 2022-05-29 13:01:59 -07:00
bors
bef2b7cd1c Auto merge of #97214 - Mark-Simulacrum:stage0-bump, r=pietroalbini
Finish bumping stage0

It looks like the last time had left some remaining cfg's -- which made me think
that the stage0 bump was actually successful. This brings us to a released 1.62
beta though.

This now brings us to cfg-clean, with the exception of check-cfg-features in bootstrap;
I'd prefer to leave that for a separate PR at this time since it's likely to be more tricky.

cc https://github.com/rust-lang/rust/pull/97147#issuecomment-1132845061

r? `@pietroalbini`
2022-05-29 16:28:21 +00:00
bors
9d1aeaeb82 Auto merge of #94214 - nikic:rust-opaque-pointers, r=cuviper
Prepare Rust for opaque pointers

Fix one codegen bug with opaque pointers, and update our IR tests to accept both typed pointer and opaque pointer IR. This is a bit annoying, but unavoidable if we want decent test coverage on both LLVM 14 and LLVM 15.

This prepares Rust for when LLVM will enable opaque pointers by default.
2022-05-29 14:12:42 +00:00
bors
abc7681a76 Auto merge of #97456 - Bryysen:issue-97319-fix, r=compiler-errors
Improve error message for E0081

Closes #97319
2022-05-29 12:00:30 +00:00
Camille GILLOT
3162b33ce5 Handle anonymous lifetimes properly in diagnostics. 2022-05-29 12:16:09 +02:00
Camille GILLOT
7b86c6f21e Fortify check for number of generic parameters. 2022-05-29 12:16:09 +02:00
Camille GILLOT
da175c743c Make lifetime errors more precise in the presence of Fresh lifetimes. 2022-05-29 12:16:09 +02:00
Camille GILLOT
8da27078d3 Stop pretty-printing anonymous lifetimes. 2022-05-29 12:16:09 +02:00
bors
0f06824013 Auto merge of #97287 - compiler-errors:type-interner, r=jackh726,oli-obk
Move things to `rustc_type_ir`

Finishes some work proposed in https://github.com/rust-lang/compiler-team/issues/341.

r? `@ghost`
2022-05-29 08:20:13 +00:00
Yuki Okushi
5a4e9363a3
Ensure source file present when calculating max line number
Co-authored-by: Ross MacArthur <ross@macarthur.io>
2022-05-29 11:29:49 +09:00
bors
84288ed6d5 Auto merge of #97500 - GuillaumeGomez:rollup-ms1bvps, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #96950 (Add regression test for #96395)
 - #97028 (Add support for embedding pretty printers via `#[debugger_visualizer]` attribute)
 - #97478 (Remove FIXME on `ExtCtxt::fn_decl()`)
 - #97479 (Make some tests check-pass)
 - #97482 (ptr::invalid is not equivalent to a int2ptr cast)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-29 00:40:45 +00:00
Guillaume Gomez
a777d50b24
Rollup merge of #97478 - JohnTitor:fixme-fn-decl, r=compiler-errors
Remove FIXME on `ExtCtxt::fn_decl()`

`ExtCtxt::fn_decl()` is used like `self.fn_decl(..)` or `self.cx.fn_decl(..)`, coverting it to an assoc fn, for example, makes it inconvenience (e.g. `self.cx.fn_decl(..)` would be longer to represent). Given that, it doesn't seem a "FIXME" thing and unused `self` is okay, I think.
2022-05-29 01:12:30 +02:00
Guillaume Gomez
239287f013
Rollup merge of #97028 - ridwanabdillahi:pretty-printer, r=michaelwoerister
Add support for embedding pretty printers via `#[debugger_visualizer]` attribute

Initial support for [RFC 3191](https://github.com/rust-lang/rfcs/pull/3191) in PR https://github.com/rust-lang/rust/pull/91779 was scoped to supporting embedding NatVis files using a new attribute. This PR implements the pretty printer support as stated in the RFC mentioned above.

This change includes embedding pretty printers in the `.debug_gdb_scripts` just as the pretty printers for rustc are embedded today. Also added additional tests for embedded pretty printers. Additionally cleaned up error checking so all error checking is done up front regardless of the current target.

RFC: https://github.com/rust-lang/rfcs/pull/3191
2022-05-29 01:12:30 +02:00
bors
14f477e78a Auto merge of #97472 - cuviper:rebase-rustc-rayon, r=Mark-Simulacrum
Update to rebased rustc-rayon 0.4

In rayon-rs/rayon#938, miri uncovered a race in `rustc-rayon-core` that had already been fixed in the regular `rayon-core`. I have now rebased that fork onto the latest rayon branch, and published as 0.4. I also updated `indexmap` to bump the dependency.

`Cargo.lock` changes:

    Updating indexmap v1.8.0 -> v1.8.2
    Updating rayon v1.5.1 -> v1.5.3
    Updating rayon-core v1.9.1 -> v1.9.3
    Updating rustc-rayon v0.3.2 -> v0.4.0
    Updating rustc-rayon-core v0.3.2 -> v0.4.1
2022-05-28 22:24:53 +00:00
ltdk
5fabdb8f7f Add E0788 for improper #[no_coverage] usage 2022-05-28 17:20:43 -04:00
Bryysen
f671bc969f Improve error message for E0081
Previously whenever a duplicate discriminant was detected for an Enum,
we would print the discriminant bits in the diagnostic without any
casting. This caused us to display incorrect values for negative
discriminants. After this PR we format the discriminant signedness
correctly. Also reworded some of the original error
messages.
2022-05-28 23:05:45 +02:00
Michael Goulet
4638915940 Make TyCtxt implement Interner, make HashStable generic and move to rustc_type_ir 2022-05-28 12:16:05 -07:00
Michael Goulet
f05a92d158 Remove some comments, inline interner fn 2022-05-28 11:38:22 -07:00
Michael Goulet
34e05812e0 Fix TyKind lint, make consts no longer fn, etc 2022-05-28 11:38:22 -07:00
Michael Goulet
a056a953f0 Initial fixes on top of type interner commit 2022-05-28 11:38:22 -07:00
Wilco Kusee
a7015fe816 Move things to rustc_type_ir 2022-05-28 11:38:22 -07:00
bors
116201eefe Auto merge of #97461 - eddyb:proc-macro-less-payload, r=bjorn3
proc_macro: don't pass a client-side function pointer through the server.

Before this PR, `proc_macro::bridge::Client<F>` contained both:
* the C ABI entry-point `run`, that the server can call to start the client
* some "payload" `f: F` passed to that entry-point
  * in practice, this was always a (client-side Rust ABI) `fn` pointer to the actual function the proc macro author wrote, i.e. `#[proc_macro] fn foo(input: TokenStream) -> TokenStream`

In other words, the client was passing one of its (Rust) `fn` pointers to the server, which was passing it back to the client, for the client to call (see later below for why that was ever needed).

I was inspired by `@nnethercote's` attempt to remove the `get_handle_counters` field from `Client` (see https://github.com/rust-lang/rust/pull/97004#issuecomment-1139273301), which combined with removing the `f` ("payload") field, could theoretically allow for a `#[repr(transparent)]` `Client` that mostly just newtypes the C ABI entry-point `fn` pointer <sub>(and in the context of e.g. wasm isolation, that's *all* you want, since you can reason about it from outside the wasm VM, as just a 32-bit "function table index", that you can pass to the wasm VM to call that function)</sub>.

<hr/>

So this PR removes that "payload". But it's not a simple refactor: the reason the field existed in the first place is because monomorphizing over a function type doesn't let you call the function without having a value of that type, because function types don't implement anything like `Default`, i.e.:
```rust
extern "C" fn ffi_wrapper<A, R, F: Fn(A) -> R>(arg: A) -> R {
    let f: F = ???; // no way to get a value of `F`
    f(arg)
}
```
That could be solved with something like this, if it was allowed:
```rust
extern "C" fn ffi_wrapper<
    A, R,
    F: Fn(A) -> R,
    const f: F // not allowed because the type is a generic param
>(arg: A) -> R {
    f(arg)
}
```

Instead, this PR contains a workaround in `proc_macro::bridge::selfless_reify` (see its module-level comment for more details) that can provide something similar to the `ffi_wrapper` example above, but limited to `F` being `Copy` and ZST (and requiring an `F` value to prove the caller actually can create values of `F` and it's not uninhabited or some other unsound situation).

<hr/>

Hopefully this time we don't have a performance regression, and this has a chance to land.

cc `@mystor` `@bjorn3`
2022-05-28 16:49:52 +00:00
bors
4f39fb1f34 Auto merge of #97383 - dingxiangfei2009:restore-region-scope-tree-query, r=dingxiangfei2009
Try to cache region_scope_tree as a query

This PR will attempt to restore `region_scope_tree` as a query so that caching works again. It seems that `region_scope_tree` could be re-computed for nested items after all, which could explain the performance regression introduced by #95563.

cc `@Mark-Simulacrum` `@pnkfelix` I will try to trigger a perf run here.
2022-05-28 14:30:25 +00:00
bors
68314177e7 Auto merge of #97158 - JakobDegen:dse, r=tmiasko,cjgillot
Split dead store elimination off dest prop

This splits off a part of #96451 . I've added this in as its own pass for now, so that it actually runs, can be tested, etc. In the dest prop PR, I'll stop invoking this as its own pass, so that it doesn't get invoked twice.

r? `@tmiasko`
2022-05-28 11:49:42 +00:00
Yuki Okushi
643c508e86
Remove FIXME on ExtCtxt::fn_decl() 2022-05-28 18:12:34 +09:00
Nikita Popov
1ff051a9c5 Fix documentation of basic stack protector
A stack protector is used for N >= 8, not N > 8.
2022-05-28 10:43:36 +02:00
Dylan DPC
7e7dd1c069
Rollup merge of #97327 - davidtwco:diagnostic-translation-compile-time-validation, r=oli-obk
macros: introduce `fluent_messages` macro

Adds a new `fluent_messages` macro which performs compile-time validation of the compiler's Fluent resources (i.e. that the resources parse and don't multiply define the same messages) and generates constants that make using those messages in diagnostics more ergonomic.

For example, given the following invocation of the macro..

```rust
fluent_messages! {
    typeck => "./typeck.ftl",
}
```

..where `typeck.ftl` has the following contents..

```fluent
typeck-field-multiply-specified-in-initializer =
    field `{$ident}` specified more than once
    .label = used more than once
    .label-previous-use = first use of `{$ident}`
```

...then the macro parse the Fluent resource, emitting a diagnostic if it fails to do so...

```text
error: could not parse Fluent resource
  --> $DIR/test.rs:35:28
   |
LL |         missing_message => "./missing-message.ftl",
   |                            ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: see additional errors emitted

error: expected a message field for "missing-message"
 --> ./missing-message.ftl:1:1
  |
1 | missing-message =
  | ^^^^^^^^^^^^^^^^^^
  |
```
...or generating the following code if it succeeds:

```rust
pub static DEFAULT_LOCALE_RESOURCES: &'static [&'static str] = &[
    include_str!("./typeck.ftl"),
];

mod fluent_generated {
    mod typeck {
        pub const field_multiply_specified_in_initializer: DiagnosticMessage =
            DiagnosticMessage::fluent("typeck-field-multiply-specified-in-initializer");
        pub const field_multiply_specified_in_initializer_label_previous_use: DiagnosticMessage =
            DiagnosticMessage::fluent_attr(
                "typeck-field-multiply-specified-in-initializer",
                "previous-use-label"
            );
    }
}
```

When emitting a diagnostic, the generated constants can be used as follows:

```rust
let mut err = sess.struct_span_err(
    span,
    fluent::typeck::field_multiply_specified_in_initializer
);
err.span_label(
    span,
    fluent::typeck::field_multiply_specified_in_initializer_label
);
err.span_label(
    previous_use_span,
    fluent::typeck::field_multiply_specified_in_initializer_label_previous_use
);
err.emit();
```

I'd like to reduce the verbosity of referring to labels/notes/helps with this scheme (though it wasn't much better before), but I'll leave that for a follow-up.

r? `@oli-obk`
cc `@pvdrz` `@compiler-errors`
2022-05-28 08:45:52 +02:00
bors
ed76b773b5 Auto merge of #97284 - b-naber:constraint-dyn-impl-suggestion, r=estebank
Add suggestion for relaxing static lifetime bounds on dyn trait impls in NLL

This PR introduces suggestions for relaxing static lifetime bounds on impls of dyn trait items for NLL similar to what is already available in lexical region diagnostics.

Fixes https://github.com/rust-lang/rust/issues/95701

r? `@estebank`
2022-05-28 04:04:29 +00:00
Josh Stone
ab57e36268 Update to rebased rustc-rayon 0.4 2022-05-27 20:20:41 -07:00
Matthias Krüger
0804ef6563
Rollup merge of #97458 - estebank:use-self-in-derive-macro, r=compiler-errors
Modify `derive(Debug)` to use `Self` in struct literal to avoid redundant error

Reduce verbosity in #97343.
2022-05-28 01:11:50 +02:00
Matthias Krüger
e96397b63f
Rollup merge of #97453 - lcnr:comment, r=jackh726
rename `TyKind` to `RegionKind` in comment in rustc_middle
2022-05-28 01:11:48 +02:00
Eduard-Mihai Burtescu
78a83b0d5f proc_macro: don't pass a client-side function pointer through the server. 2022-05-27 19:29:21 +00:00
bors
ebbcbfc236 Auto merge of #96790 - lqd:update_jemalloc, r=Mark-Simulacrum
Update jemalloc to v5.3

Now that `jemalloc` version 5.3 has been released, this PR updates `tikv-jemalloc-sys` to the corresponding release.

The crates.io publishing issue seems to have been resolved for the `jemalloc-sys` package, and version 5.3.0 is now also available under the historical name (and should become the preferred crate to be used). Therefore, this PR also switches back to using `jemalloc-sys` instead of  `tikv-jemalloc-sys`.
2022-05-27 18:28:12 +00:00
Esteban Küber
f2a1b7b772 Modify derive(Debug) to use Self in struct literal to avoid redundant error
#97343
2022-05-27 10:48:12 -07:00
lcnr
4781246a2c fix comment 2022-05-27 16:36:59 +02:00
Mark Rousskov
b454991ac4 Finish bumping stage0
It looks like the last time had left some remaining cfg's -- which made me think
that the stage0 bump was actually successful. This brings us to a released 1.62
beta though.
2022-05-27 07:36:17 -04:00
bors
56fd680cf9 Auto merge of #96046 - oli-obk:const_typeck, r=cjgillot
Move various checks to typeck so them failing causes the typeck result to get tainted

Fixes #69487
fixes #79047

cc `@RalfJung` this gets rid of the `Transmute` invalid program error variant
2022-05-27 11:31:37 +00:00
bors
f558990814 Auto merge of #97004 - nnethercote:proc-macro-tweaks, r=eddyb
Proc macro tweaks

Various improvements I spotted while looking through the proc macro code.

r? `@eddyb`
2022-05-27 06:09:45 +00:00
Nicholas Nethercote
bc70d0db92 Rename ProcMacroDerive as DeriveProcMacro.
So it matches the existing `AttrProcMacro` and `BangProcMacro` types.
2022-05-27 15:58:35 +10:00
Nicholas Nethercote
dbdc7dd0dc Rename ProcMacro trait as BangProcMacro.
Similar to the existing `AttrProcMacro` trait.
2022-05-27 15:58:35 +10:00
Nicholas Nethercote
1a9514d5ce Simplify types in proc_macro_harness.rs.
This gives the more obvious derive/attr/bang distinction, and reduces
code size slightly.
2022-05-27 15:58:35 +10:00
bors
4f68efad64 Auto merge of #96298 - petrochenkov:fromgen, r=estebank
libcore: Add `iter::from_generator` which is like `iter::from_fn`, but for coroutines instead of functions

An equally useful little helper.

I didn't follow any of the async-wg work, so I don't know why something like this wasn't added before.
2022-05-27 01:01:15 +00:00
X
cd76f2e609
remove trailing space
Co-authored-by: Rémy Rakic <remy.rakic+github@gmail.com>
2022-05-27 08:46:40 +08:00
Vadim Petrochenkov
5bf23f64cc libcore: Add iter::from_generator which is like iter::from_fn, but for coroutines instead of functions 2022-05-27 01:51:31 +03:00
bors
b2c9872c6c Auto merge of #97386 - nnethercote:optimize-pos-adjustments, r=bjorn3
Optimize position adjustments

A small improvement.

r? `@bjorn3`
2022-05-26 22:01:19 +00:00
Matthias Krüger
2cacc325bc
Rollup merge of #97424 - matthiaskrgr:clippy_complexity_may26, r=oli-obk
clippy::complexity fixes

clone_on_copy
useless_format
bind_instead_of_map
filter_map_identity
useless_conversion
map_flatten
unnecessary_unwrap
2022-05-26 20:59:43 +02:00
Michael Goulet
126ef8ee31 don't do Sized/other fn signature checks on RPIT's real type 2022-05-26 10:21:20 -07:00
Niko Matsakis
5ced8918fa
Update compiler/rustc_typeck/src/check/region.rs 2022-05-26 10:44:29 -04:00
bors
1ab98933fa Auto merge of #97168 - SparrowLii:accesses, r=cjgillot
omit `record_accesses` function when collecting `MonoItem`s

This PR fixes the FIXME in the impl of `record_accesses` function.
[Edit] We can call `instantiation_mode` when push the `MonoItem` into `neighbors`. This avoids extra local variables `accesses: SmallVec<[_; 128]>`
2022-05-26 11:15:15 +00:00
Matthias Krüger
5fc8a8e227 clippy::complexity fixes
clone_on_copy
useless_format
bind_instead_of_map
filter_map_identity
useless_conversion
map_flatten
unnecessary_unwrap
2022-05-26 13:14:24 +02:00
b-naber
3c6c8d5a8d rebase, use Ty in CallArgument and re-insert static_assert_size on ConstraintCategory 2022-05-26 10:11:58 +02:00
bors
99c4758747 Auto merge of #97369 - tmiasko:codgen-ssa-atomic-ordering, r=michaelwoerister
rustc_codegen_ssa: cleanup `AtomicOrdering`

* Remove unused `NotAtomic` ordering.
* Rename `Monotonic` to `Relaxed` - a Rust specific name.
* Derive copy and clone.
2022-05-26 02:00:17 +00:00
SparrowLii
480e6036c5 call instantiation_mode when pushing a new mono_item 2022-05-26 09:36:54 +08:00
Nicholas Nethercote
2b91c40c19 Avoid adjusting file positions twice.
`imported_source_files` adjusts lots of file positions, and then calls
`new_imported_source_file`, which then adjust them all again. This
commit combines the two adjustments into one, for a small perf win.
2022-05-26 08:56:49 +10:00
Nicholas Nethercote
3e810c64d0 Augment a comment. 2022-05-26 08:56:49 +10:00
Vadim Petrochenkov
2984bf674f Simplify implementation of -Z gcc-ld
- The logic is now unified for all targets (wasm targets should also be supported now)
- Additional "symlink" files like `ld64` are eliminated
- lld-wrapper is used for propagating the correct lld flavor
- Cleanup "unwrap or exit" logic in lld-wrapper
2022-05-25 23:55:22 +03:00
ridwanabdillahi
7ac62ce75c Respond to PR comments. 2022-05-25 10:44:56 -07:00
b-naber
5f65331b3e suggest constraining dyn trait in impl in NLL 2022-05-25 18:13:17 +02:00
b-naber
c1072d2a9a make TraitObject visitors public 2022-05-25 18:13:16 +02:00
b-naber
99fa572ab1 add def_id and substs to ConstraintCategory::CallArgument 2022-05-25 18:13:03 +02:00
Dylan DPC
e98f8f8fef
Rollup merge of #97400 - JohnTitor:typo-fix-substructure, r=cjgillot
Fix a typo on Struct `Substructure`
2022-05-25 17:37:23 +02:00
Dylan DPC
8a3ad4942c
Rollup merge of #97351 - b-naber:adt-const-params-structural-match-violation, r=michaelwoerister
Output correct type responsible for structural match violation

Previously we included the outermost type that caused a structural match violation in the error message and stated that that type must be annotated with `#[derive(Eq, PartialEq)]` even if it already had that annotation. This PR outputs the correct type in the error message.

Fixes https://github.com/rust-lang/rust/issues/97278
2022-05-25 17:37:21 +02:00
Dylan DPC
006707834f
Rollup merge of #97328 - petrochenkov:nativice, r=michaelwoerister
rustc: Fix ICE in native library error reporting

Fixes https://github.com/rust-lang/rust/issues/97299
2022-05-25 17:37:20 +02:00
Dylan DPC
d858d280e4
Rollup merge of #97302 - compiler-errors:writeback-ascending, r=cjgillot
Do writeback of Closure params before visiting the parent expression

This means that given the expression:

```
let x = |a: Vec<_>| {};
```

We will visit the HIR node for `a` before `x`, and report the ambiguity on the former instead of the latter. This also moves writeback for struct field ids and const blocks before, but the ordering of this and walking the expr doesn't seem to matter.
2022-05-25 17:37:18 +02:00
Nikita Popov
373789b059 Don't use global initializer if type does not match
This was relying on the presence of a bitcast to avoid using the
constant global initializer for a load using a different type.
With opaque pointers, we need to check this explicitly.
2022-05-25 17:28:58 +02:00
Oli Scherer
6ba8da6aae Fall through to check other arguments instead of bailing out on the first error 2022-05-25 14:01:06 +00:00
Yuki Okushi
611948b968
Fix a typo on Struct Substructure 2022-05-25 22:25:37 +09:00
SparrowLii
1b4714f587 simplify code of finding arg index 2022-05-25 21:09:04 +08:00
Ralf Jung
d7a2d9ae0e Miri call ABI check: ensure type size+align stay the same 2022-05-25 15:08:07 +02:00
bors
fe9c64d0af Auto merge of #97388 - Dylan-DPC:rollup-tfuc4tf, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #95953 (Modify MIR building to drop repeat expressions with length zero)
 - #96913 (RFC3239: Implement `cfg(target)` - Part 2)
 - #97233 ([RFC 2011] Library code)
 - #97370 (Minor improvement on else-no-if diagnostic)
 - #97384 (Fix metadata stats.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-25 11:17:34 +00:00
Dylan DPC
3c11bf3d2b
Rollup merge of #97384 - nnethercote:fix-metadata-stats, r=bjorn3
Fix metadata stats.

This commit:
- Counts some things that weren't being counted previously, and adds
  an assertion that ensure everything is counted.
- Reorders things so the `eprintln`s order matches the code order.
- Adds percentages, and makes clear that the zero bytes count is orthogonal to
  the other measurements.

Example of the new output:
```
55463779 metadata bytes, of which 18054531 bytes (32.6%) are zero
             preamble:       30 bytes ( 0.0%)
                  dep:        0 bytes ( 0.0%)
          lib feature:    17458 bytes ( 0.0%)
            lang item:      337 bytes ( 0.0%)
      diagnostic item:     1788 bytes ( 0.0%)
           native lib:        0 bytes ( 0.0%)
      foreign modules:     5113 bytes ( 0.0%)
       def-path table:   720180 bytes ( 1.3%)
               traits:      359 bytes ( 0.0%)
                impls:    64624 bytes ( 0.1%)
     incoherent_impls:      130 bytes ( 0.0%)
                  mir: 16137354 bytes (29.1%)
                 item: 23773099 bytes (42.9%)
interpret_alloc_index:      599 bytes ( 0.0%)
      proc-macro-data:        0 bytes ( 0.0%)
               tables: 10081135 bytes (18.2%)
 debugger visualizers:        0 bytes ( 0.0%)
     exported symbols:     5666 bytes ( 0.0%)
              hygiene:  1539390 bytes ( 2.8%)
      def-path hashes:  2752564 bytes ( 5.0%)
           source_map:   363540 bytes ( 0.7%)
                final:      413 bytes ( 0.0%)
```
r? `@bjorn3`
2022-05-25 10:48:31 +02:00
Dylan DPC
fe727e4dfc
Rollup merge of #97370 - compiler-errors:else-no-if-2, r=Dylan-DPC
Minor improvement on else-no-if diagnostic

Don't suggest wrapping in block since it's highly likely to be a missing `if` after `else`. Also rework message a bit (open to further suggestions).

cc: https://github.com/rust-lang/rust/pull/97298#discussion_r880933431

r? `@estebank`
2022-05-25 10:48:30 +02:00
Dylan DPC
c12a36adc6
Rollup merge of #96913 - Urgau:rfc3239-part2, r=petrochenkov
RFC3239: Implement `cfg(target)` - Part 2

This pull-request implements the compact `cfg(target(..))` part of [RFC 3239](https://github.com/rust-lang/rust/issues/96901).

I recommend reviewing this PR on a per commit basics, because of some moving parts.

cc `@GuillaumeGomez`
r? `@petrochenkov`
2022-05-25 10:48:28 +02:00
Dylan DPC
11faf2e12a
Rollup merge of #95953 - JakobDegen:repeat-leak, r=oli-obk
Modify MIR building to drop repeat expressions with length zero

Closes #74836 .

Previously, when a user wrote `[foo; 0]` we used to simply leak `foo`. The goal is to fix that. This PR changes MIR building to make `[foo; 0]` equivalent to `{ drop(foo); [] }` in all cases. Of course, this is a breaking change (see below). A crater run did not indicate any regressions though, and given that the previous behavior was almost definitely not what any user wanted, it seems unlikely that anyone was relying on this.

Note that const generics are in general unaffected by this. Inserting the extra `drop` is only meaningful/necessary when `foo` is of a non-`Copy` type, and array repeat expressions with const generic repetition count must always be `Copy`.

Besides the obvious change to behavior associated with the additional drop, there are three categories of examples where this also changes observable behavior. In all of these cases, the new behavior is consistent with what you would get by replacing `[foo; 0]` with `{ drop(foo); [] }`. As such, none of these give the user new powers to express more things.

**No longer allowed in const (breaking)**:

```rust
const _: [String; 0] = [String::new(); 0];
```

This compiles on stable today. Because we now introduce the drop of `String`, this no longer compiles as `String` may not be dropped in a const context.

**Reduced dataflow (non-breaking)**:

```rust
let mut x: i32 = 0;
let r = &x;
let a = [r; 0];
x = 5;
let _b = a;
```

Borrowck rejects this code on stable because it believes there is dataflow between `a` and `r`, and so the lifetime of `r` has to extend to the last statement. This change removes the dataflow and the above code is allowed to compile.

**More const promotion (non-breaking)**:

```rust
let _v: &'static [String; 0] = &[String::new(); 0];
```

This does not compile today because `String` having drop glue keeps it from being const promoted (despite that drop glue never being executed). After this change, this is allowed to compile.

### Alternatives

A previous attempt at this tried to reduce breakage by various tricks. This is still a possibility, but given that crater showed no regressions it seems unclear why we would want to introduce this complexity.

Disallowing `[foo; 0]` completely is also an option, but obviously this is more of a breaking change. I do not know how often this is actually used though.

r? `@oli-obk`
2022-05-25 10:48:27 +02:00
bors
4a99c5f504 Auto merge of #97345 - lcnr:fast_reject, r=nnethercote
add a deep fast_reject routine

continues the work on #97136.

r? `@nnethercote`

Actually agree with you on the match structure 😆 let's see how that impacted perf 😅
2022-05-25 08:36:46 +00:00
Tomasz Miąsko
ef83e689a8 rustc_codegen_ssa: derive copy and clone for various enums 2022-05-25 10:34:35 +02:00
Tomasz Miąsko
f4c92cc4d1 rustc_codegen_ssa: cleanup AtomicOrdering
* Remove unused `NotAtomic` ordering.
* Rename `Monotonic` to `Relaxed` - a Rust specific name.
2022-05-25 10:34:35 +02:00
Nicholas Nethercote
9a926e5d6c Fix metadata stats.
This commit:
- Counts some things that weren't being counted previously, and adds
  an assertion that ensure everything is counted.
- Reorders things so the `eprintln`s order matches the code order.
- Adds percentages, and makes clear that the zero bytes count is orthogonal to
  the other measurements.

Example of the new output:
```
55463779 metadata bytes, of which 18054531 bytes (32.6%) are zero
             preamble:       30 bytes ( 0.0%)
                  dep:        0 bytes ( 0.0%)
          lib feature:    17458 bytes ( 0.0%)
            lang item:      337 bytes ( 0.0%)
      diagnostic item:     1788 bytes ( 0.0%)
           native lib:        0 bytes ( 0.0%)
      foreign modules:     5113 bytes ( 0.0%)
       def-path table:   720180 bytes ( 1.3%)
               traits:      359 bytes ( 0.0%)
                impls:    64624 bytes ( 0.1%)
     incoherent_impls:      130 bytes ( 0.0%)
                  mir: 16137354 bytes (29.1%)
                 item: 23773099 bytes (42.9%)
interpret_alloc_index:      599 bytes ( 0.0%)
      proc-macro-data:        0 bytes ( 0.0%)
               tables: 10081135 bytes (18.2%)
 debugger visualizers:        0 bytes ( 0.0%)
     exported symbols:     5666 bytes ( 0.0%)
              hygiene:  1539390 bytes ( 2.8%)
      def-path hashes:  2752564 bytes ( 5.0%)
           source_map:   363540 bytes ( 0.7%)
                final:      413 bytes ( 0.0%)
```
2022-05-25 16:36:43 +10:00
Rémy Rakic
adab1350e7 update jemalloc-sys to jemalloc v5.3 2022-05-25 08:25:15 +02:00
bors
cbdce42320 Auto merge of #97382 - Dylan-DPC:rollup-2t4ov4z, r=Dylan-DPC
Rollup of 5 pull requests

Successful merges:

 - #93604 (Make llvm-libunwind a per-target option)
 - #97026 (Change orderings of `Debug` for the Atomic types to `Relaxed`.)
 - #97105 (Add tests for lint on type dependent on consts)
 - #97323 (Introduce stricter checks for might_permit_raw_init under a debug flag )
 - #97379 (Add aliases for `current_dir`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-25 06:14:15 +00:00
Ding Xiang Fei
4c6074fbb0
try to cache region_scope_tree as a query 2022-05-25 13:52:32 +08:00
lcnr
bff7b5130d move fast reject test out of SelectionContext::match_impl.
`match_impl` has two call sites. For one of them (within `rematch_impl`)
the fast reject test isn't necessary, because any rejection would
represent a compiler bug.

This commit moves the fast reject test to the other `match_impl` call
site, in `assemble_candidates_from_impls`. This lets us move the fast
reject test outside the `probe` call in that function. This avoids the
taking of useless snapshots when the fast reject test succeeds, which
gives a performance win when compiling the `bitmaps` and `nalgebra`
crates.

Co-authored-by: name <n.nethercote@gmail.com>
2022-05-25 07:40:38 +02:00
lcnr
a76277c6c4 add a deep fast_reject routine 2022-05-25 07:40:38 +02:00
Dylan DPC
02c0c768c1
Rollup merge of #97323 - 5225225:strict_init_checks, r=oli-obk
Introduce stricter checks for might_permit_raw_init under a debug flag

This is intended to be a version of the strict checks tried out in #79296, but also checking number validity (under the assumption that `let _ = std::mem::uninitialized::<u32>()` is UB, which seems to be what https://github.com/rust-lang/unsafe-code-guidelines/issues/71 is leaning towards.)
2022-05-25 07:31:44 +02:00
Dylan DPC
89bdbd0294
Rollup merge of #97105 - JulianKnodt:const_dep_gen_const_expr, r=lcnr
Add tests for lint on type dependent on consts

r? `@lcnr`
2022-05-25 07:31:43 +02:00
bors
9fadabc879 Auto merge of #97376 - compiler-errors:lazy-polymorphic, r=jackh726
Make `Lazy*<T>` types in `rustc_metadata` not care about lifetimes until decode

This allows us to remove the `'tcx` lifetime from `CrateRoot`. This is necessary because of #97287, which makes the `'tcx` lifetime on `Ty` invariant instead of covariant, so [this hack](0a437b2ca0/compiler/rustc_metadata/src/rmeta/decoder.rs (L89-92)) no longer holds under that PR.

Introduces a trait called `ParameterizedOverTcx` which has a generic associated type that allows a type to be parameterized over that lifetime. This means we can decode, for example, `Lazy<Ty<'static>>` into any `Ty<'tcx>` depending on the `TyCtxt<'tcx>` we pass into the decode function.
2022-05-25 03:53:39 +00:00
Jakob Degen
bf153a241d Add dead store elimination pass 2022-05-24 22:50:21 -04:00
Takayuki Maeda
b2480a0251 suggest extern crate foo when failing to resolve use foo
fix ci error
2022-05-25 09:58:19 +09:00
Michael Goulet
d1a9a95517 Make Lazy not care about lifetimes until decode 2022-05-24 15:54:44 -07:00
Michael Goulet
d61d30d9a2 Minor improvement on else-no-if diagnostic 2022-05-24 15:22:13 -07:00
Yuki Okushi
896a59d8db
Rollup merge of #97266 - est31:unknown_lints_cfg_attr, r=lcnr
Make weird name lints trigger behind cfg_attr

The weird name lints (`unknown_lints`, `renamed_and_removed_lints`), the lints that lint the linting, were previously not firing for lint level declarations behind `cfg_attr`, as they were only running before expansion.

Now, this will give a `unknown_lints` warning:

```Rust
#[cfg_attr(all(), allow(this_lint_does_not_exist))]
fn foo() {}
```

Lint level declarations behind a `cfg_attr` whose condition is not applying are still ignored. So this still won't give a warning:

```Rust
#[cfg_attr(any(), allow(this_lint_does_not_exist))]
fn foo() {}
```

Furthermore, this PR also makes the weird name lints respect level delcarations for *them* that were hidden by `cfg_attr`, making them consistent to other lints. So this will now not issue a warning:

```Rust
#[cfg_attr(all(), allow(unknown_lints))]
mod foo {
    #[allow(does_not_exist)]
    fn foo() {
    }
}
```

Fixes #97094
2022-05-25 07:08:42 +09:00
Chayim Refael Friedman
bf0193d580 Suggest adding a semicolon to a closure without block
This transforms `|| expr` into `|| { expr; }`.
2022-05-24 21:57:51 +00:00