Commit Graph

11370 Commits

Author SHA1 Message Date
bors
b8967b0d52 Auto merge of #94225 - matthiaskrgr:rollup-0728x8n, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #91192 (Some improvements to the async docs)
 - #94143 (rustc_const_eval: adopt let else in more places)
 - #94156 (Gracefully handle non-UTF-8 string slices when pretty printing)
 - #94186 (Update pin_static_ref stabilization version.)
 - #94189 (Implement LowerHex on Scalar to clean up their display in rustdoc)
 - #94190 (Use Metadata::modified instead of FileTime::from_last_modification_ti…)
 - #94203 (CTFE engine: Scalar: expose size-generic to_(u)int methods)
 - #94211 (Better error if the user tries to do assignment ... else)
 - #94215 (trait system: comments and small nonfunctional changes)
 - #94220 (Correctly handle miniz_oxide extern crate declaration)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-21 22:53:45 +00:00
Amanieu d'Antras
a60b79137c Add ignore-tidy-filelength 2022-02-21 19:18:00 +00:00
Matthias Krüger
9157775152
Rollup merge of #94215 - lcnr:leak-check, r=jackh726
trait system: comments and small nonfunctional changes

r? `@nikomatsakis` because of the leak-check check removal
2022-02-21 19:36:54 +01:00
Matthias Krüger
d3649f8d52
Rollup merge of #94211 - est31:let_else_destructuring_error, r=matthewjasper
Better error if the user tries to do assignment ... else

If the user tries to do assignment ... else, we now issue a more comprehensible error in the parser.

closes #93995
2022-02-21 19:36:53 +01:00
Matthias Krüger
f3a1a8cd4f
Rollup merge of #94203 - RalfJung:to_sized_int, r=oli-obk
CTFE engine: Scalar: expose size-generic to_(u)int methods

This matches the size-generic constructors `Scalar::from_(u)int`, and it would have helped in https://github.com/rust-lang/miri/pull/1978.

r? `@oli-obk`
2022-02-21 19:36:52 +01:00
Matthias Krüger
f639ba634b
Rollup merge of #94189 - GuillaumeGomez:scalar-lower-hex, r=RalfJung
Implement LowerHex on Scalar to clean up their display in rustdoc

Follow-up of https://github.com/rust-lang/rust/pull/94091.

r? ````@RalfJung````
2022-02-21 19:36:50 +01:00
Matthias Krüger
da25e1e59c
Rollup merge of #94156 - tmiasko:pp-str, r=petrochenkov
Gracefully handle non-UTF-8 string slices when pretty printing

Fixes #78520.
2022-02-21 19:36:48 +01:00
Matthias Krüger
ea7f7f7c4c
Rollup merge of #94143 - est31:let_else_const_eval, r=lcnr
rustc_const_eval: adopt let else in more places

Continuation of #89933, #91018, #91481, #93046, #93590, #94011.

I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This PR handles rustc_const_eval.
2022-02-21 19:36:48 +01:00
Amanieu d'Antras
fb5539b475 Add tests 2022-02-21 18:28:22 +00:00
Amanieu d'Antras
fc41d4bf35 Take CodegenFnAttrs into account when validating asm! register operands
Checking of asm! register operands now properly takes function
attributes such as #[target_feature] and #[instruction_set] into
account.
2022-02-21 18:28:22 +00:00
Amanieu d'Antras
1ceb104851 On ARM, use relocation_model to detect whether r9 should be reserved
The previous approach of checking for the reserve-r9 target feature
didn't actually work because LLVM only sets this feature very late when
initializing the per-function subtarget.
2022-02-21 18:28:22 +00:00
Amanieu d'Antras
2e8a7663b4 Simplify gating of BPF w registers behind the alu32 target feature
This is already handled by supported_types().
2022-02-21 18:28:22 +00:00
bors
03a8cc7df1 Auto merge of #93505 - lcnr:substsref-vs-ty-list, r=michaelwoerister
safely `transmute<&List<Ty<'tcx>>, &List<GenericArg<'tcx>>>`

This PR has 3 relevant steps which are is split in distinct commits.

The first commit now interns `List<Ty<'tcx>>` and `List<GenericArg<'tcx>>` together, potentially reusing memory while allowing free conversions between these two using `List<Ty<'tcx>>::as_substs()` and `SubstsRef<'tcx>::try_as_type_list()`.

Using this, we then use `&'tcx List<Ty<'tcx>>` instead of a `SubstsRef<'tcx>` for tuple fields, simplifying a bunch of code.

Finally, as tuple fields and other generic arguments now use a different `TypeFoldable<'tcx>` impl, we optimize the impl for `List<Ty<'tcx>>` improving perf by slightly less than 1% in tuple heavy benchmarks.
2022-02-21 16:03:38 +00:00
bors
1103d2e914 Auto merge of #94205 - Mark-Simulacrum:revert-93800, r=oli-obk
Revert #93800, fixing CI time regression

This reverts commit a240ccd81c (merge commit of #93800), reversing
changes made to 393fdc1048.

This PR was likely responsible for a relatively large regression in
dist-x86_64-msvc-alt builder times, from approximately 1.7 to 2.8 hours,
bringing that builder into the pool of the slowest builders we currently have.

This seems to be limited to the alt builder due to needing parallel-compiler
enabled, likely leading to slow LLVM compilation for some reason. See some
investigation in [this Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/msvc.28.3F.29.20builders.20running.20much.20slower).

cc `@lcnr` `@oli-obk` `@b-naber` (per original PRs review/author)

We can re-apply this PR once the regression is fixed, but it is sufficiently large that I don't think keeping this on master is viable in the meantime unless there's a very strong case to be made for it. Alternatively, we can disable that builder (it's not critical since it's an alt build), but that obviously carries its own costs.
2022-02-21 13:13:04 +00:00
Michael Woerister
e72e6399b1 debuginfo: Simplify TypeMap used during LLVM debuginfo generation.
The previous implementation was written before types were properly
normalized for code generation and had to assume a more complicated
relationship between types and their debuginfo -- generating separate
identifiers for debuginfo nodes that were based on normalized types.

Since types are now already normalized, we can use them as identifiers
for debuginfo nodes.
2022-02-21 13:03:36 +01:00
lcnr
6a1f5eab83 obligation forest docs 2022-02-21 12:00:26 +01:00
lcnr
ec0a0ca3f4 don't check for the leak_check twice 2022-02-21 12:00:26 +01:00
bors
a924ef73bc Auto merge of #94108 - compiler-errors:just-confirmation-normalization, r=jackh726
Normalize obligation and expected trait_refs in confirm_poly_trait_refs

Consolidate normalization the obligation and expected trait refs in `confirm_poly_trait_refs`. Also, _always_ normalize these trait refs -- we were already normalizing the obligation trait ref when confirming closure and generator candidates, but this does it for fn pointer confirmation as well.

This presumably does more work in the case that the obligation's trait ref is already normalized, but we can see from the perf runs in #94070, it actually (paradoxically, perhaps) improves performance when paired with logic that normalizes projections in fulfillment loop.
2022-02-21 10:06:24 +00:00
lcnr
15e95c0b7f rename function 2022-02-21 11:02:52 +01:00
lcnr
239f33ea5b add comment 2022-02-21 11:02:52 +01:00
Mario Carneiro
c1d75a27b2
fix names in feature(...) suggestion 2022-02-21 01:17:37 -08:00
est31
76ea566677 Better error if the user tries to do assignment ... else 2022-02-21 08:59:39 +01:00
est31
413f3f787c
Fix typo
Co-authored-by: lcnr <rust@lcnr.de>
2022-02-21 08:28:20 +01:00
lcnr
80f56cdc2a review 2022-02-21 07:09:11 +01:00
lcnr
c909b6dc22 add comment to Lift impls 2022-02-21 07:09:11 +01:00
lcnr
758f4e7158 optimize TypeFoldable for 2 element tuples 2022-02-21 07:09:11 +01:00
lcnr
1245131a11 use List<Ty<'tcx>> for tuples 2022-02-21 07:09:11 +01:00
lcnr
a9c1ab82f5 safely transmute<&List<Ty<'tcx>>, &List<GenericArg<'tcx>>> 2022-02-21 07:06:55 +01:00
bors
026d8ce7f5 Auto merge of #94066 - Mark-Simulacrum:factor-out-simple-def-kind, r=davidtwco
Remove SimpleDefKind

Now that rustc_query_system depends on rustc_hir, we can just directly make use of the regular DefKind.
2022-02-21 03:36:55 +00:00
Mark Rousskov
9f76214854 Revert "Auto merge of #93800 - b-naber:static-initializers-mir-val, r=oli-obk"
This reverts commit a240ccd81c, reversing
changes made to 393fdc1048.

This PR was likely responsible for a relatively large regression in
dist-x86_64-msvc-alt builder times, from approximately 1.7 to 2.8 hours,
bringing that builder into the pool of the slowest builders we currently have.

This seems to be limited to the alt builder due to needing parallel-compiler
enabled, likely leading to slow LLVM compilation for some reason.
2022-02-20 21:56:20 -05:00
Ralf Jung
1e3609b1ba CTFE engine: Scalar: expose size-generic to_(u)int methods 2022-02-20 21:36:15 -05:00
Mark Rousskov
2ee6d55c62 Preallocate a buffer in FmtPrinter 2022-02-20 19:32:19 -05:00
Mark Rousskov
efb99d780d Always format to internal String in FmtPrinter
This avoids monomorphizing for different parameters, decreasing generic code
instantiated downstream from rustc_middle.
2022-02-20 19:32:18 -05:00
Mark Rousskov
c6ad61a1bd Delete Decoder::read_map 2022-02-20 18:58:23 -05:00
Mark Rousskov
42904b0219 Delete Decoder::read_seq 2022-02-20 18:58:23 -05:00
Mark Rousskov
75614c06ee Delete Decoder::read_enum_variant 2022-02-20 18:58:23 -05:00
Mark Rousskov
8def096c4d Delete Decoder::read_map_elt_val 2022-02-20 18:58:23 -05:00
Mark Rousskov
025e1b581a Delete Decoder::read_map_elt_key 2022-02-20 18:58:23 -05:00
Mark Rousskov
38e6dad1d3 Delete Decoder::read_option 2022-02-20 18:58:23 -05:00
Mark Rousskov
24dc052132 Delete Decoder::read_seq_elt 2022-02-20 18:58:22 -05:00
Mark Rousskov
2d8595e0d7 Delete Decoder::read_tuple_arg 2022-02-20 18:58:22 -05:00
Mark Rousskov
886c72df37 Delete Decoder::read_tuple 2022-02-20 18:58:22 -05:00
Mark Rousskov
6f711a37e3 Use count! macro in tuple length computation 2022-02-20 18:58:22 -05:00
Mark Rousskov
19288951e1 Delete Decoder::read_struct_field 2022-02-20 18:58:22 -05:00
Mark Rousskov
c021ba48a7 Delete Decoder::read_struct 2022-02-20 18:58:22 -05:00
Mark Rousskov
a421b631ba Delete read_enum_variant_arg 2022-02-20 18:58:22 -05:00
Mark Rousskov
c87060a72d Delete read_enum_variant names 2022-02-20 18:58:22 -05:00
Mark Rousskov
c6bd6b444c Delete Decoder::read_enum 2022-02-20 18:58:22 -05:00
Mark Rousskov
60b71f56e7 Remove support for JSON deserialization to Rust
This is no longer used by the compiler itself, and removing this support opens
the door to massively simplifying the Decodable/Decoder API by dropping the
self-describing deserialization support (necessary for JSON).
2022-02-20 18:58:21 -05:00
bors
45e2c2881d Auto merge of #93678 - steffahn:better_unsafe_diagnostics, r=nagisa
Improve `unused_unsafe` lint

I’m going to add some motivation and explanation below, particularly pointing the changes in behavior from this PR.

_Edit:_ Looking for existing issues, looks like this PR fixes #88260.

_Edit2:_ Now also contains code that closes #90776.
2022-02-20 21:15:11 +00:00
Frank Steffahn
8f8689fb31 Improve unused_unsafe lint
Main motivation: Fixes some issues with the current behavior. This PR is
more-or-less completely re-implementing the unused_unsafe lint; it’s also only
done in the MIR-version of the lint, the set of tests for the `-Zthir-unsafeck`
version no longer succeeds (and is thus disabled, see `lint-unused-unsafe.rs`).

On current nightly,
```rs
unsafe fn unsf() {}

fn inner_ignored() {
    unsafe {
        #[allow(unused_unsafe)]
        unsafe {
            unsf()
        }
    }
}
```

doesn’t create any warnings. This situation is not unrealistic to come by, the
inner `unsafe` block could e.g. come from a macro. Actually, this PR even
includes removal of one unused `unsafe` in the standard library that was missed
in a similar situation. (The inner `unsafe` coming from an external macro hides
    the warning, too.)

The reason behind this problem is how the check currently works:
* While generating MIR, it already skips nested unsafe blocks (i.e. unsafe
  nested in other unsafe) so that the inner one is always the one considered
  unused
* To differentiate the cases of no unsafe operations inside the `unsafe` vs.
  a surrounding `unsafe` block, there’s some ad-hoc magic walking up the HIR to
  look for surrounding used `unsafe` blocks.

There’s a lot of problems with this approach besides the one presented above.
E.g. the MIR-building uses checks for `unsafe_op_in_unsafe_fn` lint to decide
early whether or not `unsafe` blocks in an `unsafe fn` are redundant and ought
to be removed.
```rs
unsafe fn granular_disallow_op_in_unsafe_fn() {
    unsafe {
        #[deny(unsafe_op_in_unsafe_fn)]
        {
            unsf();
        }
    }
}
```
```
error: call to unsafe function is unsafe and requires unsafe block (error E0133)
  --> src/main.rs:13:13
   |
13 |             unsf();
   |             ^^^^^^ call to unsafe function
   |
note: the lint level is defined here
  --> src/main.rs:11:16
   |
11 |         #[deny(unsafe_op_in_unsafe_fn)]
   |                ^^^^^^^^^^^^^^^^^^^^^^
   = note: consult the function's documentation for information on how to avoid undefined behavior

warning: unnecessary `unsafe` block
  --> src/main.rs:10:5
   |
9  | unsafe fn granular_disallow_op_in_unsafe_fn() {
   | --------------------------------------------- because it's nested under this `unsafe` fn
10 |     unsafe {
   |     ^^^^^^ unnecessary `unsafe` block
   |
   = note: `#[warn(unused_unsafe)]` on by default

```
Here, the intermediate `unsafe` was ignored, even though it contains a unsafe
operation that is not allowed to happen in an `unsafe fn` without an additional `unsafe` block.

Also closures were problematic and the workaround/algorithms used on current
nightly didn’t work properly. (I skipped trying to fully understand what it was
supposed to do, because this PR uses a completely different approach.)
```rs
fn nested() {
    unsafe {
        unsafe { unsf() }
    }
}
```
```
warning: unnecessary `unsafe` block
  --> src/main.rs:10:9
   |
9  |     unsafe {
   |     ------ because it's nested under this `unsafe` block
10 |         unsafe { unsf() }
   |         ^^^^^^ unnecessary `unsafe` block
   |
   = note: `#[warn(unused_unsafe)]` on by default
```

vs

```rs
fn nested() {
    let _ = || unsafe {
        let _ = || unsafe { unsf() };
    };
}
```
```
warning: unnecessary `unsafe` block
 --> src/main.rs:9:16
  |
9 |     let _ = || unsafe {
  |                ^^^^^^ unnecessary `unsafe` block
  |
  = note: `#[warn(unused_unsafe)]` on by default

warning: unnecessary `unsafe` block
  --> src/main.rs:10:20
   |
10 |         let _ = || unsafe { unsf() };
   |                    ^^^^^^ unnecessary `unsafe` block
```

*note that this warning kind-of suggests that **both** unsafe blocks are redundant*

--------------------------------------------------------------------------------

I also dislike the fact that it always suggests keeping the outermost `unsafe`.
E.g. for
```rs
fn granularity() {
    unsafe {
        unsafe { unsf() }
        unsafe { unsf() }
        unsafe { unsf() }
    }
}
```
I prefer if `rustc` suggests removing the more-course outer-level `unsafe`
instead of the fine-grained inner `unsafe` blocks, which it currently does on nightly:
```
warning: unnecessary `unsafe` block
  --> src/main.rs:10:9
   |
9  |     unsafe {
   |     ------ because it's nested under this `unsafe` block
10 |         unsafe { unsf() }
   |         ^^^^^^ unnecessary `unsafe` block
   |
   = note: `#[warn(unused_unsafe)]` on by default

warning: unnecessary `unsafe` block
  --> src/main.rs:11:9
   |
9  |     unsafe {
   |     ------ because it's nested under this `unsafe` block
10 |         unsafe { unsf() }
11 |         unsafe { unsf() }
   |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> src/main.rs:12:9
   |
9  |     unsafe {
   |     ------ because it's nested under this `unsafe` block
...
12 |         unsafe { unsf() }
   |         ^^^^^^ unnecessary `unsafe` block
```

--------------------------------------------------------------------------------

Needless to say, this PR addresses all these points. For context, as far as my
understanding goes, the main advantage of skipping inner unsafe blocks was that
a test case like
```rs
fn top_level_used() {
    unsafe {
        unsf();
        unsafe { unsf() }
        unsafe { unsf() }
        unsafe { unsf() }
    }
}
```
should generate some warning because there’s redundant nested `unsafe`, however
every single `unsafe` block _does_ contain some statement that uses it. Of course
this PR doesn’t aim change the warnings on this kind of code example, because
the current behavior, warning on all the inner `unsafe` blocks, makes sense in this case.

As mentioned, during MIR building all the unsafe blocks *are* kept now, and usage
is attributed to them. The way to still generate a warning like
```
warning: unnecessary `unsafe` block
  --> src/main.rs:11:9
   |
9  |     unsafe {
   |     ------ because it's nested under this `unsafe` block
10 |         unsf();
11 |         unsafe { unsf() }
   |         ^^^^^^ unnecessary `unsafe` block
   |
   = note: `#[warn(unused_unsafe)]` on by default

warning: unnecessary `unsafe` block
  --> src/main.rs:12:9
   |
9  |     unsafe {
   |     ------ because it's nested under this `unsafe` block
...
12 |         unsafe { unsf() }
   |         ^^^^^^ unnecessary `unsafe` block

warning: unnecessary `unsafe` block
  --> src/main.rs:13:9
   |
9  |     unsafe {
   |     ------ because it's nested under this `unsafe` block
...
13 |         unsafe { unsf() }
   |         ^^^^^^ unnecessary `unsafe` block
```

in this case is by emitting a `unused_unsafe` warning for all of the `unsafe`
blocks that are _within a **used** unsafe block_.

The previous code had a little HIR traversal already anyways to collect a set of
all the unsafe blocks (in order to afterwards determine which ones are unused
afterwards). This PR uses such a traversal to do additional things including logic
like _always_ warn for an `unsafe` block that’s inside of another **used**
unsafe block. The traversal is expanded to include nested closures in the same go,
this simplifies a lot of things.

The whole logic around `unsafe_op_in_unsafe_fn` is a little complicated, there’s
some test cases of corner-cases in this PR. (The implementation involves
differentiating between whether a used unsafe block was used exclusively by
operations where `allow(unsafe_op_in_unsafe_fn)` was active.) The main goal was
to make sure that code should compile successfully if all the `unused_unsafe`-warnings
are addressed _simultaneously_ (by removing the respective `unsafe` blocks)
no matter how complicated the patterns of `unsafe_op_in_unsafe_fn` being
disallowed and allowed throughout the function are.

--------------------------------------------------------------------------------

One noteworthy design decision I took here: An `unsafe` block
with `allow(unused_unsafe)` **is considered used** for the purposes of
linting about redundant contained unsafe blocks. So while
```rs

fn granularity() {
    unsafe { //~ ERROR: unnecessary `unsafe` block
        unsafe { unsf() }
        unsafe { unsf() }
        unsafe { unsf() }
    }
}
```
warns for the outer `unsafe` block,
```rs

fn top_level_ignored() {
    #[allow(unused_unsafe)]
    unsafe {
        #[deny(unused_unsafe)]
        {
            unsafe { unsf() } //~ ERROR: unnecessary `unsafe` block
            unsafe { unsf() } //~ ERROR: unnecessary `unsafe` block
            unsafe { unsf() } //~ ERROR: unnecessary `unsafe` block
        }
    }
}
```
warns on the inner ones.
2022-02-20 21:00:12 +01:00
bors
523a1b1d38 Auto merge of #94062 - Mark-Simulacrum:drop-print-cfg, r=oli-obk
Move ty::print methods to Drop-based scope guards

Primary goal is reducing codegen of the TLS access for each closure, which shaves ~3 seconds of bootstrap time over rustc as a whole.
2022-02-20 18:12:59 +00:00
Erik Desjardins
067f628286 add check for llvm 14 2022-02-20 11:37:22 -05:00
Guillaume Gomez
c358ffe7b3 Implement LowerHex on Scalar to clean up their display in rustdoc 2022-02-20 16:43:21 +01:00
bors
c1aa85475c Auto merge of #93934 - rusticstuff:inline_ensure_sufficient_stack, r=estebank
Allow inlining of `ensure_sufficient_stack()`

This functions is monomorphized a lot and allowing the compiler to inline it improves instructions count and max RSS significantly in my local tests.
2022-02-20 15:10:19 +00:00
Santiago Pastorino
cbfa7cebee
Move trait_map to Lowering Context 2022-02-20 11:52:57 -03:00
Santiago Pastorino
7e2dd672da
Move local_id_to_def_id to Lowering Context 2022-02-20 11:47:49 -03:00
Santiago Pastorino
a8d24742f8
Avoid call to lower_node_id when not needed 2022-02-20 10:17:29 -03:00
Camille GILLOT
04d5f41c97
Make node_id_to_hir_id owner-local. 2022-02-20 10:17:27 -03:00
bjorn3
0edcf1e249 Inline build_block 2022-02-20 13:39:44 +01:00
bjorn3
e142cdf4f6 Remove FunctionCx::new_block 2022-02-20 13:39:42 +01:00
bjorn3
e6d7a8d7d4 Remove build_sibling_block 2022-02-20 13:38:15 +01:00
bors
3b186511f6 Auto merge of #93816 - bjorn3:rlib_metadata_first, r=nagisa
Put crate metadata first in the rlib

This should make metadata lookup faster

Fixes https://github.com/rust-lang/rust/issues/93806
2022-02-20 11:32:40 +00:00
Tomasz Miąsko
f233323f6d Gracefully handle non-UTF-8 string slices when pretty printing 2022-02-20 08:42:33 +01:00
bors
a6fe969541 Auto merge of #93387 - JakobDegen:improve_partialeq, r=tmiasko
Extend uninhabited enum variant branch elimination to also affect fallthrough

The `uninhabited_enum_branching` mir opt eliminates branches on variants where the data is uninhabited. This change extends this pass to also ensure that the `otherwise` case points to a trivially unreachable bb if all inhabited variants are present in the non-otherwise branches.

I believe it was `@scottmcm` who said that LLVM eliminates some of this information in its SimplifyCFG pass. This is unfortunate, but this change should still be at least a small improvement in principle (I don't think it will show up on any benchmarks)
2022-02-20 05:24:52 +00:00
bors
25ad89e47b Auto merge of #94174 - matthiaskrgr:rollup-snyrlhy, r=matthiaskrgr
Rollup of 14 pull requests

Successful merges:

 - #93580 (Stabilize pin_static_ref.)
 - #93639 (Release notes for 1.59)
 - #93686 (core: Implement ASCII trim functions on byte slices)
 - #94002 (rustdoc: Avoid duplicating macros in sidebar)
 - #94019 (removing architecture requirements for RustyHermit)
 - #94023 (adapt static-nobundle test to use llvm-nm)
 - #94091 (Fix rustdoc const computed value)
 - #94093 (Fix pretty printing of enums without variants)
 - #94097 (Add module-level docs for `rustc_middle::query`)
 - #94112 (Optimize char_try_from_u32)
 - #94113 (document rustc_middle::mir::Field)
 - #94122 (Fix miniz_oxide types showing up in std docs)
 - #94142 (rustc_typeck: adopt let else in more places)
 - #94146 (Adopt let else in more places)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-20 02:19:41 +00:00
Matthias Krüger
f2d6770f77
Rollup merge of #94146 - est31:let_else, r=cjgillot
Adopt let else in more places

Continuation of #89933, #91018, #91481, #93046, #93590, #94011.

I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs #94139, #94142, #94143, #94144.
2022-02-20 00:37:34 +01:00
Matthias Krüger
7ca1c48bbb
Rollup merge of #94142 - est31:let_else_typeck, r=oli-obk
rustc_typeck: adopt let else in more places

Continuation of https://github.com/rust-lang/rust/pull/89933, https://github.com/rust-lang/rust/pull/91018, https://github.com/rust-lang/rust/pull/91481, https://github.com/rust-lang/rust/pull/93046, https://github.com/rust-lang/rust/pull/93590, https://github.com/rust-lang/rust/pull/94011.

I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This PR handles rustc_typeck.
2022-02-20 00:37:33 +01:00
Matthias Krüger
9246e8867c
Rollup merge of #94113 - Mizobrook-kan:issue-94025, r=estebank
document rustc_middle::mir::Field

cc #94025
2022-02-20 00:37:31 +01:00
Matthias Krüger
39a50d8290
Rollup merge of #94097 - pierwill:doc-rustc-middle-query, r=cjgillot
Add module-level docs for `rustc_middle::query`
2022-02-20 00:37:29 +01:00
Matthias Krüger
f2d4ffe81c
Rollup merge of #94093 - tmiasko:pp-no-variants, r=oli-obk
Fix pretty printing of enums without variants

92d20c4aad removed no-variants special case from `try_destructure_const` with expectation that this case would be handled gracefully when `read_discriminant` returns an error.

Alas in that case `read_discriminant` succeeds while returning a non-existing variant, so the special case is still necessary.

Fixes #94073.

r? ````@oli-obk````
2022-02-20 00:37:28 +01:00
Matthias Krüger
9e9cc66e42
Rollup merge of #94091 - GuillaumeGomez:rustdoc-const-computed-value, r=oli-obk
Fix rustdoc const computed value

Fixes #85088.

It looks like this now (instead of hexadecimal):

![Screenshot from 2022-02-17 17-55-39](https://user-images.githubusercontent.com/3050060/154532115-0f9861a0-406f-4c9c-957f-32bedd8aca7d.png)

r? ````@oli-obk````
2022-02-20 00:37:27 +01:00
bors
2690468727 Auto merge of #92911 - nbdd0121:unwind, r=Amanieu
Guard against unwinding in cleanup code

Currently the only safe guard we have against double unwind is the panic count (which is local to Rust). When double unwinds indeed happen (e.g. C++ exception + Rust panic, or two C++ exceptions), then the second unwind actually goes through and the first unwind is leaked. This can cause UB. cc rust-lang/project-ffi-unwind#6

E.g. given the following C++ code:
```c++
extern "C" void foo() {
    throw "A";
}

extern "C" void execute(void (*fn)()) {
    try {
        fn();
    } catch(...) {
    }
}
```

This program is well-defined to terminate:
```c++
struct dtor {
    ~dtor() noexcept(false) {
        foo();
    }
};

void a() {
    dtor a;
    dtor b;
}

int main() {
    execute(a);
    return 0;
}
```

But this Rust code doesn't catch the double unwind:
```rust
extern "C-unwind" {
    fn foo();
    fn execute(f: unsafe extern "C-unwind" fn());
}

struct Dtor;

impl Drop for Dtor {
    fn drop(&mut self) {
        unsafe { foo(); }
    }
}

extern "C-unwind" fn a() {
    let _a = Dtor;
    let _b = Dtor;
}

fn main() {
    unsafe { execute(a) };
}
```

To address this issue, this PR adds an unwind edge to an abort block, so that the Rust example aborts. This is similar to how clang guards against double unwind (except clang calls terminate per C++ spec and we abort).

The cost should be very small; it's an additional trap instruction (well, two for now, since we use TrapUnreachable, but that's a different issue) for each function with landing pads; if LLVM gains support to encode "abort/terminate" info directly in LSDA like GCC does, then it'll be free. It's an additional basic block though so compile time may be worse, so I'd like a perf run.

r? `@ghost`
`@rustbot` label: F-c_unwind
2022-02-19 23:25:06 +00:00
Michael Goulet
773fa7adbc Consolidate normalization in confirm_poly_trait_refs 2022-02-19 10:59:00 -08:00
est31
bb0a2f985c rustc_typeck: adopt let else in more places 2022-02-19 18:15:47 +01:00
est31
2ef8af6619 Adopt let else in more places 2022-02-19 17:27:43 +01:00
Tomasz Miąsko
c2da477853 Fix pretty printing of enums without variants
92d20c4aad removed no-variants special
case from try_destructure_const with expectation that this case would be
handled gracefully when read_discriminant returns an error.

Alas in that case read_discriminant succeeds while returning a
non-existing variant, so the special case is still necessary.
2022-02-19 17:10:11 +01:00
Erik Desjardins
c2e84fa5fc reduce default uninit_const_chunk_threshold to 16 (from 256) 2022-02-19 10:36:29 -05:00
Camille GILLOT
7afcf9fcd1 Add generator_kind table. 2022-02-19 15:41:41 +01:00
Camille GILLOT
381d32e7d6 Add fn_arg_names table. 2022-02-19 15:41:41 +01:00
Camille GILLOT
6cc96a45ac Add asyncness table. 2022-02-19 15:41:41 +01:00
Camille GILLOT
7bacdb760f Add rendered_const table. 2022-02-19 15:41:41 +01:00
Camille GILLOT
f8fd9733b6 Add mir_const_qualifs table. 2022-02-19 15:41:41 +01:00
Camille GILLOT
0b7ee3aca2 Drop ImplData. 2022-02-19 15:41:41 +01:00
Camille GILLOT
c7c306f94a Do not decode span when we only need the name. 2022-02-19 15:41:41 +01:00
Camille GILLOT
f07f1bfc60 Encode metadata using queries. 2022-02-19 15:41:36 +01:00
Camille GILLOT
227d912489 Stop interning stability. 2022-02-19 15:39:42 +01:00
Guillaume Gomez
c5ce3e1dbc Don't render Const computed values in hexadecimal for Display 2022-02-19 14:00:36 +01:00
Erik Desjardins
d5769e9843 switch to limiting the number of init/uninit chunks 2022-02-19 01:29:17 -05:00
Matthias Krüger
5a083dbbe6
Rollup merge of #94086 - tmiasko:char-try-from-scalar-int, r=davidtwco
Fix ScalarInt to char conversion

to avoid panic for invalid Unicode scalar values
2022-02-19 06:45:33 +01:00
Matthias Krüger
c28940e49d
Rollup merge of #94006 - pierwill:upvar-field, r=nikomatsakis
Use a `Field` in `ConstraintCategory::ClosureUpvar`

As part of #90317, we do not want `HirId` to implement `Ord`, `PartialOrd`. This line of code has made that difficult

1b27144afc/compiler/rustc_borrowck/src/region_infer/mod.rs (L2184)

since it sorts a [`ConstraintCategory::ClosureUpvar(HirId)`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.ConstraintCategory.html#variant.ClosureUpvar).

This PR makes that variant take a [`Field`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Field.html) instead.

r? `@nikomatsakis`
2022-02-19 06:45:32 +01:00
Matthias Krüger
78e4456e1f
Rollup merge of #93990 - lcnr:pre-89862-cleanup, r=estebank
pre #89862 cleanup

changes used in #89862 which can be landed without the rest of this PR being finished.

r? `@estebank`
2022-02-19 06:45:31 +01:00
Matthias Krüger
f19adc7acc
Rollup merge of #93658 - cchiw:issue-77443-fix, r=joshtriplett
Stabilize `#[cfg(panic = "...")]`

[Stabilization PR](https://rustc-dev-guide.rust-lang.org/stabilization_guide.html#stabilization-pr) for #77443
2022-02-19 06:45:29 +01:00
bors
1882597991 Auto merge of #94134 - matthiaskrgr:rollup-b132kjz, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #89892 (Suggest `impl Trait` return type when incorrectly using a generic return type)
 - #91675 (Add MemTagSanitizer Support)
 - #92806 (Add more information to `impl Trait` error)
 - #93497 (Pass `--test` flag through rustdoc to rustc so `#[test]` functions can be scraped)
 - #93814 (mips64-openwrt-linux-musl: correct soft-foat)
 - #93847 (kmc-solid: Use the filesystem thread-safety wrapper)
 - #93877 (asm: Allow the use of r8-r14 as clobbers on Thumb1)
 - #93892 (Only mark projection as ambiguous if GAT substs are constrained)
 - #93915 (Implement --check-cfg option (RFC 3013), take 2)
 - #93953 (Add the `known-bug` test directive, use it, and do some cleanup)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-19 02:07:43 +00:00
est31
5cc292eb1d rustc_const_eval: adopt let else in more places 2022-02-19 01:55:47 +01:00
Nixon Enraght-Moony
aa601574a5 rustdoc-json: Better Header Type
- Make ABI an enum, instead of being stringly typed
- Replace Qualifier HashSet with 3 bools
- Merge ABI field into header, as they always occor together
2022-02-18 23:31:33 +00:00
bors
5a1a3707ff Auto merge of #94050 - michaelwoerister:fix-unsized-tuple-debuginfo, r=pnkfelix
debuginfo: Support fat pointers to unsized tuples.

This PR makes fat pointer debuginfo generation handle the case of unsized tuples.

Fixes #93871
2022-02-18 23:18:12 +00:00
Matthias Krüger
576afec73a
Rollup merge of #93915 - Urgau:rfc-3013, r=petrochenkov
Implement --check-cfg option (RFC 3013), take 2

This pull-request implement RFC 3013: Checking conditional compilation at compile time (https://github.com/rust-lang/rfcs/pull/3013) and is based on the previous attempt https://github.com/rust-lang/rust/pull/89346 by `@mwkmwkmwk` that was closed due to inactivity.

I have address all the review comments from the previous attempt and added some more tests.

cc https://github.com/rust-lang/rust/issues/82450
r? `@petrochenkov`
2022-02-18 23:23:10 +01:00
Matthias Krüger
1e2f63de0a
Rollup merge of #93892 - compiler-errors:issue-92917, r=jackh726,nikomatsakis
Only mark projection as ambiguous if GAT substs are constrained

A slightly more targeted version of #92917, where we only give up with ambiguity if we infer something about the GATs substs when probing for a projection candidate.

fixes #93874
also note (but like the previous PR, does not fix) #91762

r? `@jackh726`
cc `@nikomatsakis` who reviewed #92917
2022-02-18 23:23:09 +01:00
Matthias Krüger
cb35370557
Rollup merge of #93877 - Amanieu:asm_fixes, r=nagisa
asm: Allow the use of r8-r14 as clobbers on Thumb1

Previously these were entirely disallowed, except for r11 which was allowed by accident.

cc `@hudson-ayers`
2022-02-18 23:23:08 +01:00
Matthias Krüger
32c8acd769
Rollup merge of #93814 - Itus-Shield:mips64-openwrt, r=bjorn3
mips64-openwrt-linux-musl: correct soft-foat

MIPS64 targets under OpenWrt require soft-float fpu support.

Rust-lang requires soft-float defined in tuple definition and
isn't over-ridden by toolchain compile-time CFLAGS/LDFLAGS

Set explicit soft-float for tuple.

Signed-off-by: Donald Hoskins <grommish@gmail.com>
2022-02-18 23:23:06 +01:00
Matthias Krüger
5c08c39121
Rollup merge of #92806 - compiler-errors:better-impl-trait-deny, r=estebank
Add more information to `impl Trait` error

Fixes #92458

Let me know if I went overboard here, or if the suggestions could use some refinement.

r? `@estebank`
Feel free to reassign to someone else
2022-02-18 23:23:04 +01:00
Matthias Krüger
0bb72a2c66
Rollup merge of #91675 - ivanloz:memtagsan, r=nagisa
Add MemTagSanitizer Support

Add support for the LLVM [MemTagSanitizer](https://llvm.org/docs/MemTagSanitizer.html).

On hardware which supports it (see caveats below), the MemTagSanitizer can catch bugs similar to AddressSanitizer and HardwareAddressSanitizer, but with lower overhead.

On a tag mismatch, a SIGSEGV is signaled with code SEGV_MTESERR / SEGV_MTEAERR.

# Usage

`-Zsanitizer=memtag -C target-feature="+mte"`

# Comments/Caveats

* MemTagSanitizer is only supported on AArch64 targets with hardware support
* Requires `-C target-feature="+mte"`
* LLVM MemTagSanitizer currently only performs stack tagging.

# TODO

* Tests
* Example
2022-02-18 23:23:03 +01:00
Matthias Krüger
f8b83a2aa6
Rollup merge of #89892 - Nilstrieb:suggest-return-impl-trait, r=jackh726
Suggest `impl Trait` return type when incorrectly using a generic return type

Address #85991

When there is a type mismatch error and the return type is generic, and that generic parameter is not used in the function parameters, suggest replacing that generic with the `impl Trait` syntax.

r? `@estebank`
2022-02-18 23:23:02 +01:00
Erik Desjardins
b7e5597491 Use undef for partially-uninit constants up to 1024 bytes
There needs to be some limit to avoid perf regressions on large arrays
with undef in each element (see comment in the code).
2022-02-18 15:57:10 -05:00
Amanieu d'Antras
11250b8661 asm: Allow the use of r8-r14 as clobbers on Thumb1
Previously these were entirely disallowed, except for r11 which was
allowed by accident.
2022-02-18 20:26:40 +00:00
mqy
997492538b rustdoc: several minor fixes 2022-02-19 03:47:41 +08:00
Nilstrieb
4bed7485da Suggest impl Trait return type
Address #85991

Suggest the `impl Trait` return type syntax if the user tried to return a generic parameter and we get a type mismatch

The suggestion is not emitted if the param appears in the function parameters, and only get the bounds that actually involve `T: ` directly

It also checks whether the generic param is contained in any where bound (where it isn't the self type), and if one is found (like `Option<T>: Send`), it is not suggested.

This also adds `TyS::contains`, which recursively vistits the type and looks if the other type is contained anywhere
2022-02-18 20:40:08 +01:00
Matthias Krüger
a144ea1c4b
Rollup merge of #93634 - matthiaskrgr:clippy_complexity_jan_2022, r=oli-obk
compiler: clippy::complexity fixes

useless_format
map_flatten
useless_conversion
needless_bool
filter_next
clone_on_copy
needless_option_as_deref
2022-02-18 16:23:33 +01:00
Matthias Krüger
cf3cd4c48a
Rollup merge of #93024 - compiler-errors:inline-mir-bad-bounds, r=estebank
Do not ICE when inlining a function with un-satisfiable bounds

Fixes #93008
This is kinda a hack... but it's the fix I thought had the least blast-radius.

We use `normalize_param_env_or_error` to verify that the predicates in the param env are self-consistent, since with RevealAll, a bad predicate like `<&'static () as Clone>` will be evaluated with an empty ParamEnv (since it references no generics), and we'll raise an error for it.
2022-02-18 16:23:30 +01:00
Matthias Krüger
659382fa47
Rollup merge of #92959 - asquared31415:test-non-fn-help, r=estebank
Add more info and suggestions to use of #[test] on invalid items

This pr changes the diagnostics for using `#[test]` on an item that can't be used as a test to explain that the attribute has no meaningful effect on non-functions and suggests the use of `#[cfg(test)]` for conditional compilation instead.

Example change:
```rs
#[test]
mod test {}
```
previously output
```
error: only functions may be used as tests
 --> src/lib.rs:2:1
  |
2 | mod test {}
  | ^^^^^^^^^^^
  ```
  now outputs
  ```
error: the `#[test]` attribute may only be used on a non-associated function
  --> $DIR/test-on-not-fn.rs:3:1
     |
LL | #[test]
     | ^^^^^^^
LL | mod test {}
     | ----------- expected a non-associated function, found a module
     |
     = note: the `#[test]` macro causes a a function to be run on a test and has no effect on non-functions
help: replace with conditional compilation to make the item only exist when tests are being run
     |
LL | #[cfg(test)]
     | ~~~~~~~~~~~~
   ```
2022-02-18 16:23:29 +01:00
Matthias Krüger
e3ded4fc4f
Rollup merge of #92933 - bjorn3:no_bin_lib_mixing, r=estebank
Deny mixing bin crate type with lib crate types

The produced library would get a main shim too which conflicts with the
main shim of the executable linking the library.

```
$ cat > main1.rs <<EOF
fn main() {}
pub fn bar() {}
EOF
$ cat > main2.rs <<EOF
extern crate main1;
fn main() {
    main1::bar();
}
EOF
$ rustc --crate-type bin --crate-type lib main1.rs
$ rustc -L. main2.rs
error: linking with `cc` failed: exit status: 1
[...]
  = note: /usr/bin/ld: /tmp/crate_bin_lib/libmain1.rlib(main1.main1.707747aa-cgu.0.rcgu.o): in function `main':
          main1.707747aa-cgu.0:(.text.main+0x0): multiple definition of `main'; main2.main2.02a148fe-cgu.0.rcgu.o:main2.02a148fe-cgu.0:(.text.main+0x0): first defined here
          collect2: error: ld returned 1 exit status
```
2022-02-18 16:23:28 +01:00
Matthias Krüger
dd111262b2
Rollup merge of #92683 - jackh726:issue-92033, r=estebank
Suggest copying trait associated type bounds on lifetime error

Closes #92033

Kind of the most simple suggestion to make - we don't try to be fancy. Turns out, it's still pretty useful (the couple existing tests that trigger this error end up fixed - for this error - upon applying the fix).

r? ``@estebank``
cc ``@nikomatsakis``
2022-02-18 16:23:28 +01:00
Jakob Degen
3a5c078895 Extend uninhabited match branch optimization to also work on fallthrough.
The `uninhabited_enum_branch` miropt now also checks whether the fallthrough
case is inhabited, and if not will ensure that it points to an unreachable
block.
2022-02-18 09:14:21 -05:00
bjorn3
932559cc21 Put crate metadata first in the rlib when possible
This should make metadata lookup faster
2022-02-18 14:33:36 +01:00
bors
b8c56fa8c3 Auto merge of #93766 - petrochenkov:doclinkregr, r=camelid,GuillaumeGomez
rustdoc: Collect traits in scope for lang items

Inherent impls on primitive types are not included in the list of all inherent impls in the crate (`inherent_impls_in_crate_untracked`), they are taken from the list of lang items instead, but such impls can also be inlined by rustdoc, e.g. if something derefs to a primitive type.

r? `@camelid`
Fixes https://github.com/rust-lang/rust/issues/93698
2022-02-18 10:26:45 +00:00
Vadim Petrochenkov
0da7adc828 rustdoc: Collect traits in scope for lang items 2022-02-18 16:11:23 +08:00
Mizobrook-kan
621020892e fix some typos 2022-02-18 15:38:03 +08:00
bors
feac2ecf1c Auto merge of #94088 - oli-obk:revert, r=jackh726
Revert #91403

fixes #94004

r? `@pnkfelix` `@cjgillot`
2022-02-18 07:35:37 +00:00
Mizobrook-kan
56aba3c625 document rustc_middle::mir::Field 2022-02-18 12:37:48 +08:00
Michael Goulet
207fb5f070 fix impl trait message, bless tests 2022-02-17 19:18:42 -08:00
Michael Goulet
f04f732503 Add more information to impl Trait deny error 2022-02-17 18:45:53 -08:00
Mark Rousskov
ddda851fd5 Remove SimpleDefKind 2022-02-17 18:08:45 -05:00
Matthias Krüger
6dc62f421d
Rollup merge of #94043 - DrMeepster:box_alloc_ice, r=oli-obk
Fix ICE when using Box<T, A> with pointer sized A

Fixes #78459

Note that using `Box<T, A>` with a more than pointer sized `A` or using a pointer sized `A` with a Box of a DST will produce a different ICE (#92054) which is not fixed by this PR.
2022-02-17 23:01:01 +01:00
Matthias Krüger
637d8b89e8
Rollup merge of #94011 - est31:let_else, r=lcnr
Even more let_else adoptions

Continuation of #89933, #91018, #91481, #93046, #93590.
2022-02-17 23:00:59 +01:00
Matthias Krüger
98c54c8cad
Rollup merge of #93758 - nnethercote:improve-folding-comments, r=BoxyUwU
Improve comments about type folding/visiting.

I have found this code confusing for years. I've always roughly
understood it, but never exactly. I just made my fourth(?) attempt and
finally cracked it.

This commit improves the comments. In particular, it explicitly
describes how you can't do a custom fold/visit of any type; there are
actually a handful of "types of interest" (e.g. `Ty`, `Predicate`,
`Region`, `Const`) that can be custom folded/visted, and all other types
just get a generic traversal. I think this was the part that eluded me
on all my prior attempts at understanding.

The commit also updates comments to account for some newer changes such
as the fallible/infallible folding distinction, does some minor
reorderings, and moves one `impl` to a better place.

r? `@BoxyUwU`
2022-02-17 23:00:55 +01:00
Matthias Krüger
67331708e8
Rollup merge of #93337 - Amanieu:asm_tracking, r=tmiasko
Update tracking issue numbers for inline assembly sub-features

The main tracking issue for inline assembly is [closed](https://github.com/rust-lang/rust/issues/72016#issuecomment-1022332954), further tracking of the remaining sub-features has been moved to separate tracking issues.
2022-02-17 23:00:55 +01:00
Jack Huey
3d19c8defd Suggest copying trait associated type bounds on lifetime error 2022-02-17 14:09:21 -05:00
pierwill
5cf827421e Add module-level docs for rustc_middle::query 2022-02-17 13:07:33 -06:00
Oli Scherer
86d17b98f2 Revert "Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk"
This reverts commit 3cfa4def7c, reversing
changes made to 5d8767cb22.
2022-02-17 16:00:04 +00:00
Tomasz Miąsko
8cd9dfad1e Fix ScalarInt to char conversion
to avoid panic for invalid Unicode scalar values
2022-02-17 16:50:31 +01:00
bors
30b3f35c42 Auto merge of #93577 - nikic:llvm-14, r=nagisa
Upgrade to LLVM 14

LLVM patch state:
 * [x] a55727f334 Backported.
 * [x] c3c82dc124 Backported as 917c47b3bf.
 * [x] 6e8f9ab632 No plan to upstream.
 * [x] 319f4b2d52 Backported.
 * [x] 8b2c25d321 No plan to upstream.
 * [x] 75fef2efd4 No plan to upstream.
 * [ ] adef757547 Upstreamed as 2d2ef384b2. Needs backport.
 * [x] 4b7c1b4910 No plan to upstream.
 * [x] 3f5ab0c061 No plan to upstream.
 * [x] 514d05500e No plan to upstream.
 * [ ] 54c5869585 Under review at https://reviews.llvm.org/D119695 and https://reviews.llvm.org/D119856.

Release timeline:
 * LLVM 14.0.0 final planned for Mar 15.
 * Rust 1.60.0 planned for Apr 7.

Compile-time:
  * https://perf.rust-lang.org/compare.html?start=250384edc5d78533e993f38c60d64e42b21684b2&end=b87df8d2c7c5d9ac448c585de10927ab2ee1b864
  * A slight improvement on average, though no big changes either way.
  * There are some larger max-rss improvements.

r? `@ghost`
2022-02-17 13:08:46 +00:00
Nicholas Nethercote
94f08492af Improve comments about type folding/visiting.
I have found this code confusing for years. I've always roughly
understood it, but never exactly. I just made my fourth(?) attempt and
finally cracked it.

This commit improves the comments. In particular, it explicitly
describes how you can't do a custom fold/visit of any type; there are
actually a handful of "types of interest" (e.g. `Ty`, `Predicate`,
`Region`, `Const`) that can be custom folded/visted, and all other types
just get a generic traversal. I think this was the part that eluded me
on all my prior attempts at understanding.

The commit also updates comments to account for some newer changes such
as the fallible/infallible folding distinction, does some minor
reorderings, and moves one `impl` to a better place.
2022-02-17 23:15:40 +11:00
Matthias Krüger
91f70a8fdf
Rollup merge of #94031 - danielhenrymantilla:diagnostics/union-drop-suggest-copy-bound-alternative, r=davidtwco
[diagnostics] Add mentions to `Copy` types being valid for `union` fields

This came up from some user on Discord which was using a `T : PrimitiveInt` generic type, and they wanted to use in a `union`. Rather than adding a `Copy` bound, they started pondering about the `ManuallyDrop<T>` road, and how to correctly use `unsafe` to perform the drops.

<img width="648" alt="Screen Shot 2022-02-15 at 22 28 34" src="https://user-images.githubusercontent.com/9920355/154152496-8f9be74b-ad59-4724-8f9e-48b446774e06.png">

  - [Discord link](https://discord.com/channels/442252698964721669/443150878111694848/943092778534072320)

So, it seemed like the error message for types with potential drop glue on `union` fields could be improved to also mention the `Copy` alternative, since in many cases where `union`s are concerned, people are dealing with PODs / `Copy` types anyways 🙂

___

``@rustbot`` modify labels: +A-diagnostics +D-terse
2022-02-17 06:30:03 +01:00
Matthias Krüger
a1a750b5ad
Rollup merge of #94030 - ChayimFriedman2:issue-94010, r=petrochenkov
Correctly mark the span of captured arguments in `format_args!()`

It should not include the braces, or misspelling suggestions will be wrong.

Fixes #94010.
2022-02-17 06:30:02 +01:00
Matthias Krüger
3e727054ad
Rollup merge of #93996 - notriddle:notriddle/magically-becomes-a-function, r=petrochenkov
Do not suggest "is a function" for free variables

Part of #82323
2022-02-17 06:30:01 +01:00
Matthias Krüger
2c0df80a2e
Rollup merge of #93981 - ChayimFriedman2:slice-pat-reference-option-result, r=davidtwco
Fix suggestion to slice if scurtinee is a reference to `Result` or `Option`

Fixes https://github.com/rust-lang/rust/pull/91343#issuecomment-1037718339 and https://github.com/rust-lang/rust/pull/91343#discussion_r761466979.
2022-02-17 06:30:00 +01:00
Matthias Krüger
351aa1b5da
Rollup merge of #93693 - rukai:91550, r=davidtwco
Suggest deriving required supertraits

closes https://github.com/rust-lang/rust/issues/91550

I chose to just hardcode handling for PartialOrd and PartialEq because that should be robust enough and I dont know how to go about doing it generically

r? rust-lang/diagnostics
2022-02-17 06:29:59 +01:00
bors
930fc4f59d Auto merge of #94040 - Mark-Simulacrum:destabilize-load-store, r=Amanieu
Destabilize cfg(target_has_atomic_load_store = ...)

This was not intended to be stabilized yet.

This keeps the cfg_target_has_atomic feature gate name since compiler-builtins otherwise depends on it and I'd rather not try to manage a bump across a crates.io published repository given the time-sensitivity here (we need to land this quickly to avoid a beta backport).

Closes https://github.com/rust-lang/rust/issues/32976

r? `@Amanieu`
2022-02-17 01:56:40 +00:00
DrMeepster
d0b508e1a7
add comment explaining the check 2022-02-16 16:52:06 -08:00
Eric Holk
074d757bc6 Consider mutations as borrows in drop tracking
This is needed to match MIR more conservative approximation of any
borrowed value being live across a suspend point (See #94067). This
change considers an expression such as `x.y = z` to be a borrow of `x`
and therefore keeps `x` live across suspend points.
2022-02-16 15:30:43 -08:00
Mark Rousskov
9763486034 Move ty::print methods to Drop-based scope guards 2022-02-16 17:24:23 -05:00
pierwill
f41722a2ad Use a Field in ConstraintCategory::ClosureUpvar 2022-02-16 15:57:03 -06:00
est31
60f969a4f2 Adopt let_else in even more places 2022-02-16 22:43:39 +01:00
Nikita Popov
0605a4122f Expose unstable llvm14-builtins-abi target feature for cfg use 2022-02-16 21:15:31 +01:00
Nikita Popov
70ddd2ff1c Update data layout for wasm32 targets
New address spaces were added in https://reviews.llvm.org/D111154.
2022-02-16 21:15:31 +01:00
Nikita Popov
a380581ff8 Update data layout for 32-bit msvc targets
https://reviews.llvm.org/D115942 changed the alignment of f80.
2022-02-16 21:15:30 +01:00
Matthias Krüger
237f16db45
Rollup merge of #94037 - tmiasko:verbose, r=Mark-Simulacrum
Fix inconsistent symbol mangling with -Zverbose

Always skip arguments that are the defaults of their respective
parameters, to avoid generating inconsistent symbols for builds
with `-Zverbose` flag and without it.
2022-02-16 18:59:34 +01:00
Matthias Krüger
bc4f117acc
Rollup merge of #94020 - tmiasko:pp, r=oli-obk
Support pretty printing of invalid constants

Make it possible to pretty print invalid constants by introducing a
fallible variant of `destructure_const` and falling back to debug
formatting when it fails.

Closes #93688.
2022-02-16 18:59:32 +01:00
Matthias Krüger
a5a1ffb178
Rollup merge of #94017 - fee1-dead:unub, r=bjorn3
Clarify confusing UB statement in MIR
2022-02-16 18:59:31 +01:00