Commit Graph

162232 Commits

Author SHA1 Message Date
bors
b3800860e1 Auto merge of #93101 - Mark-Simulacrum:library-backtrace, r=yaahc
Support configuring whether to capture backtraces at runtime

Tracking issue: https://github.com/rust-lang/rust/issues/93346

This adds a new API to the `std::panic` module which configures whether and how the default panic hook will emit a backtrace when a panic occurs.

After discussion with `@yaahc` on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/backtrace.20lib.20vs.2E.20panic), this PR chooses to avoid adjusting or seeking to provide a similar API for the (currently unstable) std::backtrace API. It seems likely that the users of that API may wish to expose more specific settings rather than just a global one (e.g., emulating the `env_logger`, `tracing` per-module configuration) to avoid the cost of capture in hot code. The API added here could plausibly be copied and/or re-exported directly from std::backtrace relatively easily, but I don't think that's the right call as of now.

```rust
mod panic {
    #[derive(Copy, Clone, Debug, PartialEq, Eq)]
    #[non_exhaustive]
    pub enum BacktraceStyle {
        Short,
        Full,
        Off,
    }
    fn set_backtrace_style(BacktraceStyle);
    fn get_backtrace_style() -> Option<BacktraceStyle>;
}
```

Several unresolved questions:

* Do we need to move to a thread-local or otherwise more customizable strategy for whether to capture backtraces? See [this comment](https://github.com/rust-lang/rust/pull/79085#issuecomment-727845826) for some potential use cases for this.
   * Proposed answer: no, leave this for third-party hooks.
* Bikeshed on naming of all the options, as usual.
* Should BacktraceStyle be moved into `std::backtrace`?
   * It's already somewhat annoying to import and/or re-type the `std::panic::` prefix necessary to use these APIs, probably adding a second module to the mix isn't worth it.

Note that PR #79085 proposed a much simpler API, but particularly in light of the desire to fully replace setting environment variables via `env::set_var` to control the backtrace API, a more complete API seems preferable. This PR likely subsumes that one.
2022-02-02 22:03:23 +00:00
bors
27f5d830eb Auto merge of #93594 - matthiaskrgr:rollup-lcvhpdv, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #92528 (Make `Fingerprint::combine_commutative` associative)
 - #93221 ([borrowck] Fix help on mutating &self in async fns)
 - #93542 (Prevent lifetime elision in type alias)
 - #93546 (Validate that values in switch int terminator are unique)
 - #93571 (better suggestion for duplicated `where` clause)
 - #93574 (don't suggest adding `let` due to bad assignment expressions inside of `while` loop)
 - #93590 (More let_else adoptions)
 - #93592 (Remove unused dep from rustc_arena)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-02 19:07:07 +00:00
Mark Rousskov
85930c8f44 Configure panic hook backtrace behavior 2022-02-02 13:46:42 -05:00
Matthias Krüger
93155c5956
Rollup merge of #93592 - est31:remove_unused_deps, r=bjorn3
Remove unused dep from rustc_arena
2022-02-02 19:34:08 +01:00
Matthias Krüger
3388e6d9fd
Rollup merge of #93590 - est31:let_else, r=lcnr
More let_else adoptions

Continuation of #89933, #91018, #91481, #93046.
2022-02-02 19:34:07 +01:00
Matthias Krüger
799bded9b4
Rollup merge of #93574 - compiler-errors:bad-let-suggestion, r=lcnr
don't suggest adding `let` due to bad assignment expressions inside of `while` loop

adds a check that our `lhs` expression is actually within the conditional part of the `while` loop, instead of anywhere in the `while` body.

fixes #93486
2022-02-02 19:34:06 +01:00
Matthias Krüger
ef500863bd
Rollup merge of #93571 - compiler-errors:better-where-suggestion, r=lcnr
better suggestion for duplicated `where` clause

fixes #93567
2022-02-02 19:34:05 +01:00
Matthias Krüger
b53eaf7ce5
Rollup merge of #93546 - tmiasko:validate-switch-int, r=oli-obk
Validate that values in switch int terminator are unique
2022-02-02 19:34:04 +01:00
Matthias Krüger
7e212c1ca9
Rollup merge of #93542 - GuillaumeGomez:lifetime-elision, r=oli-obk
Prevent lifetime elision in type alias

Fixes #93401.

Apparently, the problem has been fixed in the compiler.

r? `@oli-obk`
2022-02-02 19:34:03 +01:00
Matthias Krüger
b622552e10
Rollup merge of #93221 - alyssaverkade:fix-93093, r=wesleywiser
[borrowck] Fix help on mutating &self in async fns

Previously, when rustc was provided an async function that tried to
mutate through a shared reference to an implicit self (as shown in the
ui test), rustc would suggest modifying the parameter signature
to `&mut` + the fully qualified name of the ty (in the case of the repro
`S`). If a user modified their code to match the suggestion, the
compiler would not accept it.

This commit modifies the suggestion so that when rustc is provided the
ui test that is also attached in this commit, it suggests (correctly)
`&mut self`. We try to be careful about distinguishing between implicit
and explicit self annotations, since the latter seem to be handled
correctly already.

This is my first PR here so I'm pretty sure I probably missed something/could use better terminology. I also didn't try to make the match exhaustive since implicit self is the only real special case that I need to handle (that I'm aware of), and I'm pretty sure there's a cleaner way to do this so any advice would be greatly appreciated! (I'm also not terribly confident about how I wrote the ui tests)

here is your cc as requested `@compiler-errors`

This is an attempt to fix #93093
2022-02-02 19:34:02 +01:00
Matthias Krüger
21ffe45631
Rollup merge of #92528 - tmiasko:combine-commutative, r=michaelwoerister
Make `Fingerprint::combine_commutative` associative

The previous implementation swapped lower and upper 64-bits of a result
of modular addition, so the function was non-associative.

r? `@Aaron1011`
2022-02-02 19:34:01 +01:00
est31
3cb7618f58 Remove unused dep from rustc_arena 2022-02-02 17:37:14 +01:00
est31
670f5c6ef3 More let_else adoptions 2022-02-02 17:11:01 +01:00
bors
7cd14d2f56 Auto merge of #93312 - pierwill:map-all-local-trait-impls, r=cjgillot
Return an indexmap in `all_local_trait_impls` query

The data structure previously used here required that `DefId` be `Ord`. As part of #90317, we do not want `DefId` to implement `Ord`.
2022-02-02 15:36:12 +00:00
bors
dca1e7aa5a Auto merge of #93154 - michaelwoerister:fix-generic-closure-and-generator-debuginfo, r=wesleywiser
debuginfo: Make sure that type names for closure and generator environments are unique in debuginfo.

Before this change, closure/generator environments coming from different instantiations of the same generic function were all assigned the same name even though they were distinct types with potentially different data layout. Now we append the generic arguments of the originating function to the type name.

This commit also emits `{closure_env#0}` as the name of these types in order to disambiguate them from the accompanying closure function (which keeps being called `{closure#0}`). Previously both were assigned the same name.

NOTE: Changing debuginfo names like this can break pretty printers and other debugger plugins. I think it's OK in this particular case because the names we are changing were ambiguous anyway. In general though it would be great to have a process for doing changes like these.
2022-02-02 12:37:28 +00:00
bors
250384edc5 Auto merge of #93573 - matthiaskrgr:rollup-nrjmygz, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #92758 (librustdoc: impl core::fmt::Write for rustdoc::html::render::Buffer)
 - #92788 (Detect `::` -> `:` typo in type argument)
 - #93420 (Improve wrapping on settings page)
 - #93493 (Document valid values of the char type)
 - #93531 (Fix incorrect panic message in example)
 - #93559 (Add missing | between print options)
 - #93560 (Fix two incorrect "it's" (typos in comments))

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-02 09:39:18 +00:00
Michael Goulet
f35d43cdf0 better suggestion for duplicated where 2022-02-02 00:29:45 -08:00
Michael Goulet
bc23bbb990 don't suggest adding let due to expressions inside of while loop 2022-02-01 23:27:04 -08:00
Matthias Krüger
344bb59530
Rollup merge of #93560 - steffahn:a_typo, r=petrochenkov
Fix two incorrect "it's" (typos in comments)

Found one of these while reading the documentation online. The other came up because it's in the same file.
2022-02-02 07:11:09 +01:00
Matthias Krüger
c483b9f1bf
Rollup merge of #93559 - danielframpton:link-args-typo, r=oli-obk
Add missing | between print options

The help text for the newly stabilized print option is missing a | between stack-protector-strategies and link-args.
2022-02-02 07:11:08 +01:00
Matthias Krüger
b836b281a8
Rollup merge of #93531 - TheColdVoid:patch-1, r=m-ou-se
Fix incorrect panic message in example

The panic message when calling the `connect()` should probably be a  message about connection failure, not a message about binding address failure.
2022-02-02 07:11:07 +01:00
Matthias Krüger
a3deca4675
Rollup merge of #93493 - GKFX:char-docs-2, r=scottmcm
Document valid values of the char type

As discussed at #93392, the current documentation on what constitutes a valid char isn't very detailed and is partly on the MAX constant rather than the type itself.

This PR expands on that information, stating the actual numerical range, giving examples of what won't work, and also mentions how a `char` might be a valid USV but still not be a defined character (terminology checked against [Unicode 14.0, table 2-3](https://www.unicode.org/versions/Unicode14.0.0/ch02.pdf#M9.61673.TableTitle.Table.22.Types.of.Code.Points)).
2022-02-02 07:11:07 +01:00
Matthias Krüger
2484cb8327
Rollup merge of #93420 - jsha:adjust-settings-layout, r=GuillaumeGomez
Improve wrapping on settings page

Previously, the radio button choices for themes would wrap awkwardly on
narrow screens. With this change, the group of choices will prefer
bumping down to the next line together, leaving the setting name on its
own line.

Also fix some minor spacing issues:

 - Align the setting name vertically with the radio button choices.
 - Use margin instead of padding for most spacing choices.
 - Use no margin/padding on the right-hand side.

 Demo: https://rustdoc.crud.net/jsha/adjust-settings-layout/settings.html

 r? ``@GuillaumeGomez``

Before (narrow screen):

![image](https://user-images.githubusercontent.com/220205/151555533-7ab65216-d178-4dcc-8792-3c8fb9da8718.png)

After (narrow screen):

![image](https://user-images.githubusercontent.com/220205/151555702-ad79af32-f84b-4ee4-ae7a-1a2a463c0f6f.png)
2022-02-02 07:11:06 +01:00
Matthias Krüger
8ede21b09c
Rollup merge of #92788 - estebank:colon-colon, r=cjgillot
Detect `::` -> `:` typo in type argument

When writing `Vec<A:B>`, suggest `Vec<A::B>`.
2022-02-02 07:11:05 +01:00
Matthias Krüger
7117b457de
Rollup merge of #92758 - mfrw:mfrw/rustdoc-impl-write, r=GuillaumeGomez
librustdoc: impl core::fmt::Write for rustdoc::html::render::Buffer

Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>

Fixes: #92563
2022-02-02 07:11:04 +01:00
bors
d5f9c40e6a Auto merge of #93466 - cjgillot:query-dead, r=nagisa
Make dead code check a query.

Dead code check is run for each invocation of the compiler, even if no modifications were involved.
This PR makes dead code check a query keyed on the module. This allows to skip the check when a module has not changed.
To perform this, a query `live_symbols_and_ignored_derived_traits` is introduced to encapsulate the global analysis of finding live symbols. The second query `check_mod_deathness` outputs diagnostics for each module based on this first query's results.
2022-02-02 02:29:32 +00:00
Esteban Kuber
b26ad8d10f Detect :: -> : typo in type argument
When writing `Vec<A:B>`, suggest `Vec<A::B>`.
2022-02-02 01:19:24 +00:00
bors
1ea4851715 Auto merge of #93285 - JulianKnodt:const_eq_2, r=oli-obk
Continue work on associated const equality

This actually implements some more complex logic for assigning associated consts to values.
Inside of projection candidates, it now defers to a separate function for either consts or
types. To reduce amount of code, projections are now generic over T, where T is either a Type or
a Const. I can add some comments back later, but this was the fastest way to implement it.

It also now finds the correct type of consts in type_of.

---

The current main TODO is finding the const of the def id for the LeafDef.

Right now it works if the function isn't called, but once you use the trait impl with the bound it fails inside projection.
I was hoping to get some help in getting the `&'tcx ty::Const<'tcx>`, in addition to a bunch of other `todo!()`s which I think may not be hit.

r? `@oli-obk`

Updates #92827
2022-02-01 23:18:01 +00:00
George Bateman
d372baf3f9
Fix annotation of code blocks 2022-02-01 21:44:53 +00:00
Frank Steffahn
63b12aea27 Fix two incorrect "it's" 2022-02-01 22:32:02 +01:00
Daniel Frampton
e22729b464 Add missing | between print options 2022-02-01 12:40:01 -08:00
kadmin
78fb74a600 Fix w/ comments 2022-02-01 20:19:54 +00:00
bors
2681f253bc Auto merge of #93442 - yaahc:Termination-abstraction, r=Mark-Simulacrum
Change Termination::report return type to ExitCode

Related to https://github.com/rust-lang/rust/issues/43301

The goal of this change is to minimize the forward compatibility risks in stabilizing Termination. By using the opaque type `ExitCode` instead of an `i32` we leave room for us to evolve the API over time to provide what cross-platform consistency we can / minimize footguns when working with exit codes, where as stabilizing on `i32` would limit what changes we could make in the future in how we represent and construct exit codes.
2022-02-01 20:05:46 +00:00
bors
ad88831cd5 Auto merge of #93548 - matthiaskrgr:rollup-f7dkn3p, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #86374 (Enable combining `+crt-static` and `relocation-model=pic` on `x86_64-unknown-linux-gnu`)
 - #91828 (Implement `RawWaker` and `Waker` getters for underlying pointers)
 - #92021 (Eliminate duplicate codes of is_single_fp_element)
 - #92584 (add rustc lint, warning when iterating over hashmaps 2)
 - #93267 (implement a lint for suspicious auto trait impls)
 - #93290 (remove `TyS::same_type`)
 - #93436 (Update compiler_builtins to fix duplicate symbols in `armv7-linux-androideabi` rlib)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-01 16:55:43 +00:00
Matthias Krüger
019c140244
Rollup merge of #93436 - dcsommer:master, r=Mark-Simulacrum
Update compiler_builtins to fix duplicate symbols in `armv7-linux-androideabi` rlib

I ran `./x.py dist --host= --target=armv7-linux-androideabi` before this diff:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-3d9661a82c59c66a.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
2
```
And after:
```
$ nm build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/armv7-linux-androideabi/lib/libcompiler_builtins-ffd2745070943321.rlib 2> /dev/null | grep __sync_fetch_and_add_4 | wc -l
1
```
Fixes #93310

See also https://github.com/rust-lang/compiler-builtins/issues/449 and https://github.com/rust-lang/compiler-builtins/pull/450
2022-02-01 16:08:06 +01:00
Matthias Krüger
724ce3798f
Rollup merge of #93290 - lcnr:same_type, r=jackh726
remove `TyS::same_type`

This function ignored regions and constants in adts, but didn't do so for references or any other types. cc https://github.com/rust-lang/rust/pull/93148#discussion_r791408057
2022-02-01 16:08:05 +01:00
Matthias Krüger
eb01fe85f7
Rollup merge of #93267 - lcnr:auto-trait-lint, r=nikomatsakis
implement a lint for suspicious auto trait impls

cc https://github.com/rust-lang/rust/pull/85048#issuecomment-1019805102

r? ``@nikomatsakis``
2022-02-01 16:08:04 +01:00
Matthias Krüger
741b62af07
Rollup merge of #92584 - lcnr:query-stable-lint, r=estebank
add rustc lint, warning when iterating over hashmaps 2

first introduced in #89558 and reverted in #90380 due to its perf impact

r? ``@estebank``
2022-02-01 16:08:03 +01:00
Matthias Krüger
788f2969f6
Rollup merge of #92021 - woodenarrow:br_single_fp_element, r=Mark-Simulacrum
Eliminate duplicate codes of is_single_fp_element

There are duplicate codes of is_single_fp_element function. Merge these codes to TyAndLayout impl block.
![image](https://user-images.githubusercontent.com/95843988/146707753-ba9ffc41-5888-4a53-80cf-f4fe3bcbac54.png)
2022-02-01 16:08:03 +01:00
Matthias Krüger
a643e59800
Rollup merge of #91828 - oxalica:feat/waker-getters, r=dtolnay
Implement `RawWaker` and `Waker` getters for underlying pointers

implement #87021

New APIs:
- `RawWaker::data(&self) -> *const ()`
- `RawWaker::vtable(&self) -> &'static RawWakerVTable`
- ~`Waker::as_raw_waker(&self) -> &RawWaker`~ `Waker::as_raw(&self) -> &RawWaker`

This third one is an auxiliary function to make the two APIs above more useful. Since we can only get `&Waker` in `Future::poll`, without this, we need to `transmute` it into `&RawWaker` (relying on `repr(transparent)`) in order to access its data/vtable pointers.

~Not sure if it should be named `as_raw` or `as_raw_waker`. Seems we always use `as_<something-raw>` instead of just `as_raw`. But `as_raw_waker` seems not quite consistent with `Waker::from_raw`.~ As suggested in https://github.com/rust-lang/rust/pull/91828#discussion_r770729837, use `as_raw`.
2022-02-01 16:08:02 +01:00
Matthias Krüger
ce6c1484f8
Rollup merge of #86374 - bossmc:enable-static-pie-for-gnu, r=nagisa
Enable combining `+crt-static` and `relocation-model=pic` on `x86_64-unknown-linux-gnu`

Modern `gcc` versions support `-static-pie`, and `rustc` will already fall-back to `-static` if the local `gcc` is too old (and hence this change is optimistic rather than absolute).  This brings the `-musl` and `-gnu` targets to feature compatibility (albeit with different default settings).

Of note a `-static` or `-static-pie` binary based on glibc that uses NSS-backed functions (`gethostbyname` or `getpwuid` etc.) need to have access to the `libnss_X.so.2` libraries and any of their dynamic dependencies.

I wasn't sure about the `# only`/`# ignore` changes (I've not got a `gnux32` toolchain to test with hence not also enabling `-static-pie` there).
2022-02-01 16:08:01 +01:00
bors
686663a49e Auto merge of #93284 - eholk:disable-drop-range-analysis, r=pnkfelix
Disable drop range analysis

The previous PR, #93165, still performed the drop range analysis despite ignoring the results. Unfortunately, there were ICEs in the analysis as well, so some packages failed to build (see the issue #93197 for an example). This change further disables the analysis and just provides dummy results in that case.
2022-02-01 13:45:38 +00:00
Muhammad Falak R Wani
62bea63888
librustdoc: render: use render_into instead of creating a temp string
Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
2022-02-01 18:06:58 +05:30
Muhammad Falak R Wani
66d7e50cb6
librustdoc: inline and forward all methods for impl Write for Buffer
Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
2022-02-01 18:05:42 +05:30
Muhammad Falak R Wani
95bd87f849
librustdoc: impl core::fmt::Write for rustdoc::html::render::Buffer
Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
2022-02-01 18:05:42 +05:30
Camille GILLOT
4e7d47bb6c Make dead code check a query. 2022-02-01 13:11:03 +01:00
Guillaume Gomez
230846433d Add test to ensure lifetime is not elided in type alias 2022-02-01 12:29:46 +01:00
Guillaume Gomez
3e01b0a8fd Fix lifetime elision in type aliases 2022-02-01 12:29:22 +01:00
lcnr
7ebd48d006 remove TyS::same_type
it ignored regions and constants in adts,
but didn't do so for references or any other types.
This seemed quite weird
2022-02-01 11:21:26 +01:00
bors
547f2ba06b Auto merge of #86988 - thomcc:chunky-splitz-says-no-checking, r=the8472
Carefully remove bounds checks from some chunk iterator functions

So, I was writing code that requires the equivalent of `rchunks(N).rev()` (which isn't the same as forward `chunks(N)` — in particular, if the buffer length is not a multiple of `N`, I must handle the "remainder" first).

I happened to look at the codegen output of the function (I was actually interested in whether or not a nested loop was being unrolled — it was), and noticed that in the outer `rchunks(n).rev()` loop, LLVM seemed to be unable to remove the bounds checks from the iteration: https://rust.godbolt.org/z/Tnz4MYY8f (this panic was from the split_at in `RChunks::next_back`).

After doing some experimentation, it seems all of the `next_back` in the non-exact chunk iterators have the issue: (`Chunks::next_back`, `RChunks::next_back`, `ChunksMut::next_back`, and `RChunksMut::next_back`)...

Even worse, the forward `rchunks` iterators sometimes have the issue as well (... but only sometimes). For example https://rust.godbolt.org/z/oGhbqv53r has bounds checks, but if I uncomment the loop body, it manages to remove the check (which is bizarre, since I'd expect the opposite...). I suspect it's highly dependent on the surrounding code, so I decided to remove the bounds checks from them anyway. Overall, this change includes:
- All `next_back` functions on the non-`Exact` iterators (e.g. `R?Chunks(Mut)?`).
- All `next` functions on the non-exact rchunks iterators (e.g. `RChunks(Mut)?`).

I wasn't able to catch any of the other chunk iterators failing to remove the bounds checks (I checked iterations over `r?chunks(_exact)?(_mut)?` with constant chunk sizes under `-O3`, `-Os`, and `-Oz`), which makes sense, since these were the cases where it was harder to prove the bounds check correct to remove...

In fact, it took quite a bit of thinking to convince myself that using unchecked_ here was valid — so I'm not really surprised that LLVM had trouble (although compilers are slightly better at this sort of reasoning than humans). A consequence of that is the fact that the `// SAFETY` comment for these are... kinda long...

---

I didn't do this for, or even think about it for, any of the other iteration methods; just `next` and `next_back` (where it mattered). If this PR is accepted, I'll file a follow up for someone (possibly me) to look at the others later (in particular, `nth`/`nth_back` looked like they had similar logic), but I wanted to do this now, as IMO `next`/`next_back` are the most important here, since they're what gets used by the iteration protocol.

---

Note: While I don't expect this to impact performance directly, the panic is a side effect, which would otherwise not exist in these loops. That is, this could prevent the compiler from being able to move/remove/otherwise rework a loop over these iterators (as an example, it could not delete the code for a loop whose body computes a value which doesn't get used).

Also, some like to be able to have confidence this code has no panicking branches in the optimized code, and "no bounds checks" is kinda part of the selling point of Rust's iterators anyway.
2022-02-01 10:11:59 +00:00