Commit graph

168367 commits

Author SHA1 Message Date
Oli Scherer aa9eae50f3 Stable const things need a stability attribute 2022-05-19 12:30:38 +00:00
Oli Scherer cf5a803600 Rebase fallout 2022-05-19 12:26:06 +00:00
Jacob Pratt 5ff331142e Move check to existing pass
This alters the diagnostics a bit, as the trait method is still stable.
The only thing this check does is ensure that compilation fails if a
trait implementation is declared const-stable.
2022-05-19 12:21:45 +00:00
Jacob Pratt f0620c9503 Proper const stability check, default to unstable
Rather than deferring to const eval for checking if a trait is const, we
now check up-front. This allows the error to be emitted earlier, notably
at the same time as other stability checks.

Also included in this commit is a change of the default const stability
level to UNstable. Previously, an item that was `const` but did not
explicitly state it was unstable was implicitly stable.
2022-05-19 12:21:45 +00:00
Jacob Pratt a9dd4cfa6b Add and use stability helper methods
This avoids an ambiguity (when reading) where `.level.is_stable()` is
not immediately clear whether it is general stability or const
stability.
2022-05-19 12:21:45 +00:00
Jacob Pratt f53fc41cfc Fall back to being const-unstable when undeclared 2022-05-19 12:21:45 +00:00
bors 6913c7487e Auto merge of #97114 - klensy:cursor-ref, r=petrochenkov
use CursorRef more

This allows skipping clone of `TreeAndSpacing` (and `TokenTree`).
2022-05-19 09:27:55 +00:00
bors 67a9bcb31b Auto merge of #97103 - luqmana:asm-unwind-cleanup, r=Amanieu,tmiasko
Update MIR passes to handle unwinding Inline Asm

Some more follow up fixes from https://github.com/rust-lang/rust/pull/95864#issuecomment-1094165398

r? `@Amanieu`
2022-05-19 06:57:59 +00:00
Luqman Aden af7f53d6d0 Add mir-opt test for asm_unwind + panic=abort 2022-05-18 23:15:00 -07:00
bors 50872bdb99 Auto merge of #97033 - nbdd0121:unwind3, r=Amanieu
Remove libstd's calls to `C-unwind` foreign functions

Remove all libstd and its dependencies' usage of `extern "C-unwind"`.

This is a prerequiste of a WIP PR which will forbid libraries calling `extern "C-unwind"` functions to be compiled in `-Cpanic=unwind` and linked against `panic_abort` (this restriction is necessary to address soundness bug #96926).
Cargo will ensure all crates are compiled with the same `-Cpanic` but the std is only compiled `-Cpanic=unwind` but needs the ability to be linked into `-Cpanic=abort`.

Currently there are two places where `C-unwind` is used in libstd:
* `__rust_start_panic` is used for interfacing to the panic runtime. This could be `extern "Rust"`
* `_{rdl,rg}_oom`: a shim `__rust_alloc_error_handler` will be generated by codegen to call into one of these; they can also be `extern "Rust"` (in fact, the generated shim is used as `extern "Rust"`, so I am not even sure why these are not, probably because they used to `extern "C"` and was changed to `extern "C-unwind"` when we allow alloc error hooks to unwind, but they really should just be using Rust ABI).

For dependencies, there is only one `extern "C-unwind"` function call, in `unwind` crate. This can be expressed as a re-export.

More dicussions can be seen in the Zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/210922-project-ffi-unwind/topic/soundness.20in.20mixed.20panic.20mode

`@rustbot` label: T-libs F-c_unwind
2022-05-19 04:04:40 +00:00
bors e6327bc8b8 Auto merge of #97159 - JohnTitor:rollup-ibl51vw, r=JohnTitor
Rollup of 6 pull requests

Successful merges:

 - #96866 (Switch CI bucket uploads to intelligent tiering)
 - #97062 (Couple of refactorings to cg_ssa::base::codegen_crate)
 - #97127 (Revert "Auto merge of #96441 - ChrisDenton:sync-pipes, r=m-ou-se")
 - #97131 (Improve println! documentation)
 - #97139 (Move some settings DOM generation out of JS)
 - #97152 (Update cargo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-19 01:41:07 +00:00
Yuki Okushi 9babb1c0da
Rollup merge of #97152 - ehuss:update-cargo, r=ehuss
Update cargo

3 commits in 3f052d8eed98c6a24f8b332fb2e6e6249d12d8c1..a4c1cd0eb6b18082a7e693f5a665548fe1534be4
2022-05-12 15:19:04 +0000 to 2022-05-18 01:52:07 +0000
- Add notes about pre-stabilization to contributor unstable docs (rust-lang/cargo#10675)
- reference: Update syntax supported by `rustc-link-lib` (rust-lang/cargo#10674)
- Correct the release dates for 1.61 and 1.62 (rust-lang/cargo#10665)
2022-05-19 08:22:45 +09:00
Yuki Okushi 4a4c07a9e0
Rollup merge of #97139 - GuillaumeGomez:move-dom-settings-generation, r=notriddle
Move some settings DOM generation out of JS

The first commit reduce the JS size a bit by moving some DOM content generation into the HTML file directly.

The second commit is an update of the `browser-ui-test` version which improves `wait-for-*` command (if the element doesn't exist, it'll wait for it instead of failing).

r? ``@notriddle``
2022-05-19 08:22:44 +09:00
Yuki Okushi b7d72add46
Rollup merge of #97131 - gimbles:patch-2, r=Dylan-DPC
Improve println! documentation
2022-05-19 08:22:43 +09:00
Yuki Okushi 8aba26d34c
Rollup merge of #97127 - Mark-Simulacrum:revert-96441, r=m-ou-se
Revert "Auto merge of #96441 - ChrisDenton:sync-pipes, r=m-ou-se"

This reverts commit ddb7fbe843.

Partially addresses https://github.com/rust-lang/rust/issues/97124, but not marking as fixed as we're still pending on a beta backport (for 1.62, which is happening in https://github.com/rust-lang/rust/pull/97088).

r? ``@m-ou-se`` ``@ChrisDenton``
2022-05-19 08:22:43 +09:00
Yuki Okushi 330e03f682
Rollup merge of #97062 - bjorn3:cg_ssa_driver_refactor, r=compiler-errors
Couple of refactorings to cg_ssa::base::codegen_crate

This makes the code simpler and easier to read.
2022-05-19 08:22:42 +09:00
Yuki Okushi ca3bddd14e
Rollup merge of #96866 - Mark-Simulacrum:intelligent-tiering-ci, r=pietroalbini
Switch CI bucket uploads to intelligent tiering

We currently upload approximately 166 GB/day into this bucket (estimate based on
duration of storage and total current size). My estimate is that this change
should decrease our costs (which are currently in credits) and is in the worst
case (if all objects are brought into hot storage due to unanticipated frequent
access) only going to add an additional ~$4 to the monthly bill. If access is
rare (as expected) to most objects then we expect to save approximately
~$350/month (after this change takes full effect in ~168 days).

r? ``@pietroalbini``
2022-05-19 08:22:41 +09:00
bors d8a3fc4d71 Auto merge of #95643 - WaffleLapkin:ptr_convenience, r=joshtriplett
Add convenience byte offset/check align functions to pointers

This PR adds the following APIs:
```rust
impl *const T {
    // feature gates `pointer_byte_offsets` and `const_pointer_byte_offsets
    pub const unsafe fn byte_offset(self, count: isize) -> Self;
    pub const fn wrapping_byte_offset(self, count: isize) -> Self;
    pub const unsafe fn byte_offset_from(self, origin: *const T) -> isize;
    pub const unsafe fn byte_add(self, count: usize) -> Self;
    pub const unsafe fn byte_sub(self, count: usize) -> Self;
    pub const fn wrapping_byte_add(self, count: usize) -> Self;
    pub const fn wrapping_byte_sub(self, count: usize) -> Self;

    // feature gate `pointer_is_aligned`
    pub fn is_aligned(self) -> bool where T: Sized;
    pub fn is_aligned_to(self, align: usize) -> bool;
}
// ... and the same for` *mut T`
```

Note that all functions except `is_aligned` do **not** require `T: Sized` as their pointee-sized-offset counterparts.

cc `@oli-obk` (you may want to check that I've correctly placed `const`s)
cc `@RalfJung`
2022-05-18 23:18:03 +00:00
Eric Huss 6986a72547 Update cargo 2022-05-18 13:52:43 -07:00
Luqman Aden f45f826207 Update MIR passes that assumed inline can never unwind. 2022-05-18 13:42:23 -07:00
bors cd282d7f75 Auto merge of #97019 - b-naber:transition-to-valtrees-pt1, r=oli-obk
Transition to valtrees pt1

Compartmentalising https://github.com/rust-lang/rust/pull/96591 as much as possible.

r? `@oli-obk`
2022-05-18 20:12:07 +00:00
bors 07ae142d77 Auto merge of #96863 - SparrowLii:let, r=michaelwoerister
use `hir::Let` in `hir::Guard::IfLet`

This PR fixes the FIXME about using `hir::Let` in `hir::Guard::IfLet`
2022-05-18 17:48:46 +00:00
klensy 05f459ea82 fix rustfmt 2022-05-18 20:43:16 +03:00
klensy cc5f3e21ac use CursorRef more, to not to clone Trees 2022-05-18 18:43:48 +03:00
bors 10d9ecda48 Auto merge of #96800 - nbdd0121:const, r=nagisa
Permit `asm_const` and `asm_sym` to reference generic params

Related #96557

These constructs will be allowed:
```rust
fn foofoo<const N: usize>() {}

unsafe fn foo<const N: usize>() {
    asm!("/* {0} */", const N);
    asm!("/* {0} */", const N + 1);
    asm!("/* {0} */", sym foofoo::<N>);
}

fn barbar<T>() {}

unsafe fn bar<T>() {
    asm!("/* {0} */", const std::mem::size_of::<T>());
    asm!("/* {0} */", const std::mem::size_of::<(T, T)>());
    asm!("/* {0} */", sym barbar::<T>);
    asm!("/* {0} */", sym barbar::<(T, T)>);
}
```

`@Amanieu,` I didn't switch inline asms to use `DefKind::InlineAsm`, as I see little value doing that; given that no type inference is needed, it will only make typecking slower and more complex but will have no real gains. I did switch them to follow the same code path as inline asm during symbol resolution, though.
The `error: unconstrained generic constant` you mentioned in #76001 is due to the fact that `to_const` will actually add a wfness obligation to the constant, which we don't need for `asm_const`, so I have that removed.

`@rustbot` label: +A-inline-assembly +F-asm
2022-05-18 15:07:47 +00:00
bors 936eba3b34 Auto merge of #96867 - michaelwoerister:path-prefix-fixes-2, r=davidtwco
--remap-path-prefix: Fix duplicated path components in debuginfo

This PR fixes an issue with `--remap-path-prefix` where path components could appear twice in the remapped version of the path (e.g. https://github.com/rust-lang/rust/issues/78479). The underlying problem was that `--remap-path-prefix` is often used to map an absolute path to something that looks like a relative path, e.g.:

```
--remap-path-prefix=/home/calvin/.cargo/registry/src/github.com-1ecc6299db9ec823=crates.io",
```

and relative paths in debuginfo are interpreted as being relative to the compilation directory. So if Cargo invokes the compiler with `/home/calvin/.cargo/registry/src/github.com-1ecc6299db9ec823/some_crate-0.1.0/src/lib.rs` as input and `/home/calvin/.cargo/registry/src/github.com-1ecc6299db9ec823/some_crate-0.1.0` as the compiler's working directory, then debuginfo will state that the working directory was `crates.io/some_crate-0.1.0` and the file is question was `crates.io/some_crate-0.1.0/src/lib.rs`, which combined gives the path:

```
crates.io/some_crate-0.1.0/crates.io/some_crate-0.1.0/src/lib.rs
```

With this PR the compiler will detect this situation and set up debuginfo in LLVM in a way that makes it strip the duplicated path components when emitting DWARF.

The PR also extracts the logic for making remapped paths absolute into a common helper function that is now used by debuginfo too (instead of just during crate metadata generation).
2022-05-18 12:45:44 +00:00
Michael Woerister 6411fef3ab Properly apply path prefix remapping paths emitted into debuginfo. 2022-05-18 12:19:01 +02:00
bors e5732a2171 Auto merge of #97110 - Kobzol:pgo-pid-in-profile, r=lqd
Add PID to PGO profile data filename

After experimenting with PGO, it looks like the generated profile data files can be sometimes overwritten if there is a race condition, because multiple `rustc` processes are usually invoked in parallel by `cargo`. Adding the PID to the resulting profile filename pattern makes sure that the profiles will be stored in separate files.

This generates ~20 GiB more space on disk on the CI run, but that seems harmless (?). Merging the profiles is not a bottleneck, the perf. run took the same amount of time as usually (~1h 24m).

r? `@lqd`
2022-05-18 09:53:01 +00:00
Michael Woerister 9e7b0ff2e1 Add tests for FilePathMapping::to_embeddable_absolute_path(). 2022-05-18 11:42:43 +02:00
Michael Woerister 583880b0ff Move logic for making potentially remapped paths absolute into helper method. 2022-05-18 11:42:43 +02:00
Michael Woerister 90fce805a3 Add debug tracing to FilePathMapping::map_prefix 2022-05-18 11:42:43 +02:00
Guillaume Gomez 30b536e2c5 Update browser-ui-test version 2022-05-18 11:40:29 +02:00
Guillaume Gomez 72496d88d3 Move some DOM generation into the HTML settings file directly 2022-05-18 11:40:15 +02:00
bors a084b7ad35 Auto merge of #97135 - Dylan-DPC:rollup-06u9pqn, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #94639 (Suggest dereferencing non-lval mutable reference on assignment)
 - #95979 (update coherence docs, fix generator + opaque type ICE)
 - #96378 (Mention traits and types involved in unstable trait upcasting)
 - #96917 (Make HashMap fall back to RtlGenRandom if BCryptGenRandom fails)
 - #97101 (Add tracking issue for ExitCode::exit_process)
 - #97123 (Clean fix for #96223)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-18 07:12:11 +00:00
Dylan DPC a2c2720e09
Rollup merge of #97123 - ricked-twice:issue-96223-clean-fix, r=jackh726
Clean fix for #96223

Okay, so here we are (hopefully) 👍

Closes #96223

Thanks a lot to `@jackh726` for your help and explanation 🙏

- Modified `InferCtxt::mk_trait_obligation_with_new_self_ty` to take as argument a `Binder<(TraitPredicate, Ty)>` instead of a `Binder<TraitPredicate>` and a separate `Ty` with no bound vars.

- Modified all call places to avoid calling `Binder::no_bounds_var` or `Binder::skip_binder` when it is not safe.

r? `@jackh726`
2022-05-18 08:41:18 +02:00
Dylan DPC 2d95c6acab
Rollup merge of #97101 - coolreader18:exitcode-method-issue, r=yaahc
Add tracking issue for ExitCode::exit_process

r? `@yaahc`
2022-05-18 08:41:17 +02:00
Dylan DPC 927a40b1a7
Rollup merge of #96917 - marti4d:master, r=ChrisDenton
Make HashMap fall back to RtlGenRandom if BCryptGenRandom fails

With PR #84096, Rust `std::collections::hash_map::RandomState` changed from using `RtlGenRandom()` ([msdn](https://docs.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtlgenrandom)) to `BCryptGenRandom()` ([msdn](https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom)) as its source of secure randomness after much discussion ([here](https://github.com/rust-random/getrandom/issues/65#issuecomment-753634074), among other places).

Unfortunately, after that PR landed, Mozilla Firefox started experiencing fairly-rare crashes during startup while attempting to initialize the `env_logger` crate. ([docs for env_logger](https://docs.rs/env_logger/latest/env_logger/)) The root issue is that on some machines, `BCryptGenRandom()` will fail with an `Access is denied. (os error 5)` error message. ([Bugzilla issue 1754490](https://bugzilla.mozilla.org/show_bug.cgi?id=1754490)) (Discussion in issue #94098)

Note that this is happening upon startup of Firefox's unsandboxed Main Process, so this behavior is different and separate from previous issues ([like this](https://bugzilla.mozilla.org/show_bug.cgi?id=1746254)) where BCrypt DLLs were blocked by process sandboxing. In the case of sandboxing, we knew we were doing something abnormal and expected that we'd have to resort to abnormal measures to make it work.

However, in this case we are in a regular unsandboxed process just trying to initialize `env_logger` and getting a panic. We suspect that this may be caused by a virus scanner or some other security software blocking the loading of the BCrypt DLLs, but we're not completely sure as we haven't been able to replicate locally.

It is also possible that Firefox is not the only software affected by this; we just may be one of the pieces of Rust software that has the telemetry and crash reporting necessary to catch it.

I have read some of the historical discussion around using `BCryptGenRandom()` in Rust code, and I respect the decision that was made and agree that it was a good course of action, so I'm not trying to open a discussion about a return to `RtlGenRandom()`. Instead, I'd like to suggest that perhaps we use `RtlGenRandom()` as a "fallback RNG" in the case that BCrypt doesn't work.

This pull request implements this fallback behavior. I believe this would improve the robustness of this essential data structure within the standard library, and I see only 2 potential drawbacks:

1. Slight added overhead: It should be quite minimal though. The first call to `sys::rand::hashmap_random_keys()` will incur a bit of initialization overhead, and every call after will incur roughly 2 non-atomic global reads and 2 easily predictable branches. Both should be negligible compared to the actual cost of generating secure random numbers
2. `RtlGenRandom()` is deprecated by Microsoft: Technically true, but as mentioned in [this comment on GoLang](https://github.com/golang/go/issues/33542#issuecomment-626124873), this API is ubiquitous in Windows software and actually removing it would break lots of things. Also, Firefox uses it already in [our C++ code](https://searchfox.org/mozilla-central/rev/5f88c1d6977e03e22d3420d0cdf8ad0113c2eb31/mfbt/RandomNum.cpp#25), and [Chromium uses it in their code as well](https://source.chromium.org/chromium/chromium/src/+/main:base/rand_util_win.cc) (which transitively means that Microsoft uses it in their own web browser, Edge). If there did come a time when Microsoft truly removes this API, it should be easy enough for Rust to simply remove the fallback in the code I've added here
2022-05-18 08:41:16 +02:00
Dylan DPC 49048eab47
Rollup merge of #96378 - compiler-errors:trait-upcast-error, r=nagisa
Mention traits and types involved in unstable trait upcasting

Fixes #95972  by printing the traits being upcasted and the types being coerced that cause that upcasting...

---

the poor span mentioned in the original issue has nothing to do with trait upcasting diagnostic here...

>  The original example I had that made me run into this issue had an even longer expression there (multiple chained
iterator methods) which just got all highlighted as one big block saying "somewhere here trait coercion is used and it's not allowed".

I don't think I can solve that issue in general without fixing the ObligationCauseCode and span that gets passed into Coerce.
2022-05-18 08:41:15 +02:00
Dylan DPC 04f903859a
Rollup merge of #95979 - lcnr:coherence-docs, r=compiler-errors
update coherence docs, fix generator + opaque type ICE

the world is confusing, this makes it slightly less so
2022-05-18 08:41:14 +02:00
Dylan DPC 64c58a1a4a
Rollup merge of #94639 - compiler-errors:rval-mutref, r=wesleywiser
Suggest dereferencing non-lval mutable reference on assignment

1. Adds deref suggestions for LHS of assignment (or assign-binop) when it implements `DerefMut`
2. Fixes missing deref suggestions for LHS when it isn't a place expr

Fixes #46276
Fixes #93980
2022-05-18 08:41:13 +02:00
Michael Goulet 0de7568e41 Mention traits being upcasted, types being coerced 2022-05-17 21:34:03 -07:00
Michael Goulet d50d3fccdd better lvalue errors for things implementing DerefMut 2022-05-17 21:20:24 -07:00
bors 77972d2d01 Auto merge of #97126 - JohnTitor:rollup-7gdt2aw, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #96647 (rustdoc-json: Fix HRTBs for WherePredicate::BoundPredicate)
 - #96651 (Omit unnecessary help to add `#[cfg(test)]` when already annotated)
 - #96761 (rustdoc: don't build `rayon` for non-windows targets)
 - #97096 (Types with reachable constructors are reachable)
 - #97097 (Add tmm_reg clobbers)
 - #97113 (Search GUI fixes)
 - #97116 (interpret/validity: reject references to uninhabited types)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-05-18 03:42:04 +00:00
Michael Goulet b26580f214 better error for bad LHS in binop-assign 2022-05-17 20:21:54 -07:00
Michael Goulet a5c4f4cc4b Suggest deref non-lvalue mutable reference 2022-05-17 20:21:54 -07:00
Gim a47edcf72a
Update macros.rs 2022-05-18 07:31:58 +05:30
Mark Rousskov 6259670d50 Revert "Auto merge of #96441 - ChrisDenton:sync-pipes, r=m-ou-se"
This reverts commit ddb7fbe843, reversing
changes made to baaa3b6829.
2022-05-17 18:46:11 -04:00
Yuki Okushi 248890c32e
Rollup merge of #97116 - RalfJung:ref-validity, r=oli-obk
interpret/validity: reject references to uninhabited types

According to https://doc.rust-lang.org/reference/behavior-considered-undefined.html, this is definitely UB. And we can check this without actually looking up anything in memory, we just need the reference value and its type, making this a great candidate for a validity invariant IMO and my favorite resolution of https://github.com/rust-lang/unsafe-code-guidelines/issues/77.

With this PR, Miri with `-Zmiri-check-number-validity` implements all my preferred options for what the validity invariants of our types could be. :)

CTFE has been doing recursive checking anyway, so this is backwards compatible but might change the error output. I will submit a PR with the new Miri tests soon.

r? `@oli-obk`
2022-05-18 07:41:01 +09:00
Yuki Okushi b8dd27079c
Rollup merge of #97113 - GuillaumeGomez:search-ui-fixes, r=notriddle
Search GUI fixes

The first fix is about the duplicated "in":

![Screenshot from 2022-05-17 13-25-53](https://user-images.githubusercontent.com/3050060/168814186-a4e9064f-4325-469c-8bf6-46ea2737a24f.png)

The second fix is about the `<select>` broken style:

![Screenshot from 2022-05-17 13-37-03](https://user-images.githubusercontent.com/3050060/168814182-b1c5ae66-d8cf-4fd5-a227-5aa8cd8453ab.png)
![Screenshot from 2022-05-17 13-36-55](https://user-images.githubusercontent.com/3050060/168814184-be9e56f8-fad4-477c-899e-9abff4d4910c.png)

You can test it [here](https://rustdoc.crud.net/imperio/search-ui-fixes/doc/foo/index.html?search=test).

r? `@notriddle`
2022-05-18 07:41:00 +09:00
Yuki Okushi 7361b22b4c
Rollup merge of #97097 - chorman0773:add_tmm_clobers, r=joshtriplett
Add tmm_reg clobbers

This adds support for naming the 8 tile registers from intel AMX as clobbers from `asm!` invocations on x86_64 (only). It does not add the registers as input or output operands.
2022-05-18 07:40:59 +09:00