]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoAdd soundness test for dropping scoped thread results before joining.
Mara Bos [Wed, 9 Mar 2022 10:47:53 +0000 (11:47 +0100)]
Add soundness test for dropping scoped thread results before joining.

2 years agoRemove outdated comment.
Mara Bos [Wed, 9 Mar 2022 10:47:46 +0000 (11:47 +0100)]
Remove outdated comment.

2 years agoProperly abort when thread result panics on drop.
Mara Bos [Sat, 5 Mar 2022 17:07:20 +0000 (18:07 +0100)]
Properly abort when thread result panics on drop.

2 years agoFix soundness issue in scoped threads.
Mara Bos [Sat, 5 Mar 2022 16:19:04 +0000 (17:19 +0100)]
Fix soundness issue in scoped threads.

2 years agonormalization change and rebase
b-naber [Tue, 8 Mar 2022 14:05:50 +0000 (15:05 +0100)]
normalization change and rebase

2 years agoRename is_{some,ok,err}_with to is_{some,ok,err}_and.
Mara Bos [Wed, 9 Mar 2022 10:20:36 +0000 (11:20 +0100)]
Rename is_{some,ok,err}_with to is_{some,ok,err}_and.

2 years agobless tests
b-naber [Wed, 16 Feb 2022 09:56:01 +0000 (10:56 +0100)]
bless tests

2 years agotreat all mir::Constant values as ConstantKind::Val
b-naber [Wed, 16 Feb 2022 09:54:36 +0000 (10:54 +0100)]
treat all mir::Constant values as ConstantKind::Val

2 years agoEnable issue-23036.rs on wasm32
Nikita Popov [Wed, 9 Mar 2022 09:03:58 +0000 (10:03 +0100)]
Enable issue-23036.rs on wasm32

2 years agoUse new pass manager on s390x with LLVM 14
Nikita Popov [Wed, 9 Mar 2022 09:00:07 +0000 (10:00 +0100)]
Use new pass manager on s390x with LLVM 14

The problematic compile-time issue should be resolved with this
version.

2 years agoAuto merge of #94515 - estebank:tweak-move-error, r=davidtwco
bors [Wed, 9 Mar 2022 08:58:47 +0000 (08:58 +0000)]
Auto merge of #94515 - estebank:tweak-move-error, r=davidtwco

Tweak move error

Point at method definition that causes type to be consumed.

Fix #94056.

2 years agoUpdate LLVM submodule
Nikita Popov [Wed, 9 Mar 2022 08:51:12 +0000 (09:51 +0100)]
Update LLVM submodule

2 years agoAuto merge of #94761 - Dylan-DPC:rollup-v4emqsy, r=Dylan-DPC
bors [Wed, 9 Mar 2022 06:30:19 +0000 (06:30 +0000)]
Auto merge of #94761 - Dylan-DPC:rollup-v4emqsy, r=Dylan-DPC

Rollup of 6 pull requests

Successful merges:

 - #94312 (Edit `rustc_trait_selection::infer::lattice` docs)
 - #94583 (Add a team for '`@rustbot` ping fuchsia')
 - #94686 (Do not allow `#[rustc_legacy_const_generics]` on methods)
 - #94699 (BTree: remove dead data needlessly complicating insert)
 - #94756 (Use `unreachable!` for an unreachable code path)
 - #94759 (Update cargo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoRollup merge of #94759 - ehuss:update-cargo, r=ehuss
Dylan DPC [Wed, 9 Mar 2022 05:38:53 +0000 (06:38 +0100)]
Rollup merge of #94759 - ehuss:update-cargo, r=ehuss

Update cargo

11 commits in 3d6970d50e30e797b8e26b2b9b1bdf92dc381f34..65c82664263feddc5fe2d424be0993c28d46377a
2022-02-28 19:29:07 +0000 to 2022-03-09 02:32:56 +0000
- Remove remaining 2 warn(clippy::*) instances (rust-lang/cargo#10438)
- Use `available_parallelism` instead of `num_cpus` (rust-lang/cargo#10427)
- Wait up to one second while waiting for curl (rust-lang/cargo#10456)
- Improve code coverage (rust-lang/cargo#10460)
- Don't recommend leaking tokens into the console history (rust-lang/cargo#10458)
- fix some typos (rust-lang/cargo#10454)
- Use `extend` instead of `push`ing in a loop (rust-lang/cargo#10453)
- Use locked_version more (rust-lang/cargo#10449)
- Disable dependabot (rust-lang/cargo#10443)
- Update git2 dependencies (rust-lang/cargo#10442)
- Stop gating stable features (rust-lang/cargo#10434)

2 years agoRollup merge of #94756 - ChrisDenton:unreachable, r=yaahc
Dylan DPC [Wed, 9 Mar 2022 05:38:53 +0000 (06:38 +0100)]
Rollup merge of #94756 - ChrisDenton:unreachable, r=yaahc

Use `unreachable!` for an unreachable code path

Closes #73212

2 years agoRollup merge of #94699 - ssomers:btree_prune_insert, r=Dylan-DPC
Dylan DPC [Wed, 9 Mar 2022 05:38:52 +0000 (06:38 +0100)]
Rollup merge of #94699 - ssomers:btree_prune_insert, r=Dylan-DPC

BTree: remove dead data needlessly complicating insert

Possibly needless instructions generated

r? rust-lang/libs
r? ``@Amanieu``
cc ``@frank-king``

2 years agoRollup merge of #94686 - ChayimFriedman2:issue-94629, r=jackh726
Dylan DPC [Wed, 9 Mar 2022 05:38:51 +0000 (06:38 +0100)]
Rollup merge of #94686 - ChayimFriedman2:issue-94629, r=jackh726

Do not allow `#[rustc_legacy_const_generics]` on methods

It caused an ICE since `item` was `None`.

Fixes #94629.

2 years agoRollup merge of #94583 - dtolnay:fuchsia, r=Mark-Simulacrum
Dylan DPC [Wed, 9 Mar 2022 05:38:50 +0000 (06:38 +0100)]
Rollup merge of #94583 - dtolnay:fuchsia, r=Mark-Simulacrum

Add a team for '@rustbot ping fuchsia'

I was looking for this in response to https://github.com/rust-lang/rust/pull/93858#issuecomment-1041367498.

Depends on https://github.com/rust-lang/team/pull/710.

2 years agoRollup merge of #94312 - pierwill:fix-94311-lattice-docs, r=jackh726
Dylan DPC [Wed, 9 Mar 2022 05:38:50 +0000 (06:38 +0100)]
Rollup merge of #94312 - pierwill:fix-94311-lattice-docs, r=jackh726

Edit `rustc_trait_selection::infer::lattice` docs

Closes #94311.

Removes mentions of outdated/missing type and filename (`infer.rs` and `LatticeValue`).

2 years agoUpdate cargo
Eric Huss [Wed, 9 Mar 2022 04:28:22 +0000 (20:28 -0800)]
Update cargo

2 years agoAuto merge of #94750 - cuviper:dirent64_min, r=joshtriplett
bors [Wed, 9 Mar 2022 02:17:58 +0000 (02:17 +0000)]
Auto merge of #94750 - cuviper:dirent64_min, r=joshtriplett

unix: reduce the size of DirEntry

On platforms where we call `readdir` instead of `readdir_r`, we store
the name as an allocated `CString` for variable length. There's no point
carrying around a full `dirent64` with its fixed-length `d_name` too.

2 years agoUse `unreachable!` for an unreachable code path
Chris Denton [Wed, 9 Mar 2022 00:47:24 +0000 (00:47 +0000)]
Use `unreachable!` for an unreachable code path

2 years agoImprove rustdoc book
Loïc BRANSTETT [Tue, 8 Mar 2022 22:11:37 +0000 (23:11 +0100)]
Improve rustdoc book

2 years agoUpdate GUI tests for impl blocks path changes
Guillaume Gomez [Tue, 8 Mar 2022 17:11:29 +0000 (18:11 +0100)]
Update GUI tests for impl blocks path changes

2 years agoUnify inherent impl blocks by wrapping them into a div
Guillaume Gomez [Tue, 8 Mar 2022 16:40:24 +0000 (17:40 +0100)]
Unify inherent impl blocks by wrapping them into a div

2 years agoAuto merge of #94751 - Dylan-DPC:rollup-zr7viw0, r=Dylan-DPC
bors [Tue, 8 Mar 2022 22:06:07 +0000 (22:06 +0000)]
Auto merge of #94751 - Dylan-DPC:rollup-zr7viw0, r=Dylan-DPC

Rollup of 5 pull requests

Successful merges:

 - #94689 (Use impl substs in `#[rustc_on_unimplemented]`)
 - #94714 (Enable `close_read_wakes_up` test on Windows)
 - #94723 (Add core::hint::must_use)
 - #94724 (unix: Avoid name conversions in `remove_dir_all_recursive`)
 - #94730 (Reverted atomic_mut_ptr feature removal causing compilation break)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoRollup merge of #94730 - msabansal:sabansal/b-atomic-mut-ptr, r=Dylan-DPC
Dylan DPC [Tue, 8 Mar 2022 21:44:01 +0000 (22:44 +0100)]
Rollup merge of #94730 - msabansal:sabansal/b-atomic-mut-ptr, r=Dylan-DPC

Reverted atomic_mut_ptr feature removal causing compilation break

Fixes a regression introduced as part of https://github.com/rust-lang/rust/pull/94546

Std no longer compiles on nightly while using the following commnd:

export RUSTFLAGS='-C target-feature=+atomics,+bulk-memory'
cargo build --target wasm32-unknown-unknown -Z build-std=panic_abort,std

I can help add tests to avoid future breaks but i couldn't understand the test framework

2 years agoRollup merge of #94724 - cuviper:rmdirall-cstr, r=Dylan-DPC
Dylan DPC [Tue, 8 Mar 2022 21:44:00 +0000 (22:44 +0100)]
Rollup merge of #94724 - cuviper:rmdirall-cstr, r=Dylan-DPC

unix: Avoid name conversions in `remove_dir_all_recursive`

Each recursive call was creating an `OsString` for a `&Path`, only for
it to be turned into a `CString` right away. Instead we can directly
pass `.name_cstr()`, saving two allocations each time.

2 years agoRollup merge of #94723 - dtolnay:mustuse, r=Mark-Simulacrum
Dylan DPC [Tue, 8 Mar 2022 21:43:59 +0000 (22:43 +0100)]
Rollup merge of #94723 - dtolnay:mustuse, r=Mark-Simulacrum

Add core::hint::must_use

The example code in this documentation is minimized from a real-world situation in the `anyhow` crate where this function would have been valuable.

Having this provided by the standard library is especially useful for proc macros, even more than for macro_rules. That's because proc macro crates aren't allowed to export anything other than macros, so they couldn't make their own `must_use` function for their macro-generated code to call.

<br>

## Rendered documentation

> An identity function that causes an `unused_must_use` warning to be triggered if the given value is not used (returned, stored in a variable, etc) by the caller.
>
> This is primarily intended for use in macro-generated code, in which a [`#[must_use]` attribute][must_use] either on a type or a function would not be convenient.
>
> [must_use]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute
>
> ### Example
>
> ```rust
> #![feature(hint_must_use)]
>
> use core::fmt;
>
> pub struct Error(/* ... */);
>
> #[macro_export]
> macro_rules! make_error {
>     ($($args:expr),*) => {
>         core::hint::must_use({
>             let error = $crate::make_error(core::format_args!($($args),*));
>             error
>         })
>     };
> }
>
> // Implementation detail of make_error! macro.
> #[doc(hidden)]
> pub fn make_error(args: fmt::Arguments<'_>) -> Error {
>     Error(/* ... */)
> }
>
> fn demo() -> Option<Error> {
>     if true {
>         // Oops, meant to write `return Some(make_error!("..."));`
>         Some(make_error!("..."));
>     }
>     None
> }
> ```
>
> In the above example, we'd like an `unused_must_use` lint to apply to the value created by `make_error!`. However, neither `#[must_use]` on a struct nor `#[must_use]` on a function is appropriate here, so the macro expands using `core::hint::must_use` instead.
>
> - We wouldn't want `#[must_use]` on the `struct Error` because that would make the following unproblematic code trigger a warning:
>
>   ```rust
>   fn f(arg: &str) -> Result<(), Error>
>
>   #[test]
>   fn t() {
>       // Assert that `f` returns error if passed an empty string.
>       // A value of type `Error` is unused here but that's not a problem.
>       f("").unwrap_err();
>   }
>   ```
>
> - Using `#[must_use]` on `fn make_error` can't help because the return value *is* used, as the right-hand side of a `let` statement. The `let` statement looks useless but is in fact necessary for ensuring that temporaries within the `format_args` expansion are not kept alive past the creation of the `Error`, as keeping them alive past that point can cause autotrait issues in async code:
>
>   ```rust
>   async fn f() {
>       // Using `let` inside the make_error expansion causes temporaries like
>       // `unsync()` to drop at the semicolon of that `let` statement, which
>       // is prior to the await point. They would otherwise stay around until
>       // the semicolon on *this* statement, which is after the await point,
>       // and the enclosing Future would not implement Send.
>       log(make_error!("look: {:p}", unsync())).await;
>   }
>
>   async fn log(error: Error) {/* ... */}
>
>   // Returns something without a Sync impl.
>   fn unsync() -> *const () {
>       0 as *const ()
>   }
>   ```

2 years agoRollup merge of #94714 - ChrisDenton:win-close_read_wakes_up, r=Mark-Simulacrum
Dylan DPC [Tue, 8 Mar 2022 21:43:57 +0000 (22:43 +0100)]
Rollup merge of #94714 - ChrisDenton:win-close_read_wakes_up, r=Mark-Simulacrum

Enable `close_read_wakes_up` test on Windows

I wonder if we could/should try enabling this again? It was closed by #38867 due to #31657. I've tried running this test (along with other tests) on my machine a number of times and haven't seen this fail yet,

Caveat: the worst that can happen is this succeeds initially but then causes random hangs in CI. This is not a great failure mode and would be a reason not to do this.

If this does work out, closes #39006

r? `@Mark-Simulacrum`

2 years agoRollup merge of #94689 - compiler-errors:on-unimplemented-substs, r=petrochenkov
Dylan DPC [Tue, 8 Mar 2022 21:43:56 +0000 (22:43 +0100)]
Rollup merge of #94689 - compiler-errors:on-unimplemented-substs, r=petrochenkov

Use impl substs in `#[rustc_on_unimplemented]`

We were using the trait-ref substs instead of impl substs in `rustc_on_unimplemented`, even when computing the `rustc_on_unimplemented` attached to an impl block. Let's not do that.

This PR also untangles impl and trait def-ids in the logic in `on_unimplemented` a bit.

Fixes #94675

2 years agounix: reduce the size of DirEntry
Josh Stone [Tue, 8 Mar 2022 21:36:01 +0000 (13:36 -0800)]
unix: reduce the size of DirEntry

On platforms where we call `readdir` instead of `readdir_r`, we store
the name as an allocated `CString` for variable length. There's no point
carrying around a full `dirent64` with its fixed-length `d_name` too.

2 years agoUpdate for changes to other lints
David Koloski [Tue, 8 Mar 2022 19:57:03 +0000 (19:57 +0000)]
Update for changes to other lints

2 years agoAuto merge of #94702 - b-naber:static-refs-mir, r=lcnr
bors [Tue, 8 Mar 2022 19:25:19 +0000 (19:25 +0000)]
Auto merge of #94702 - b-naber:static-refs-mir, r=lcnr

Reinstate #93800

https://github.com/rust-lang/rust/pull/93800 caused a regression in an alt builder with parallel enabled. https://github.com/rust-lang/rust/pull/94205 reverted that PR because of the regression. For an unknown reason the regression has disappeared, so we reinstate the changes in https://github.com/rust-lang/rust/pull/93800 here.

r? `@Mark-Simulacrum`

2 years agoFix docs, fix incorrect lint source in note
David Koloski [Wed, 2 Mar 2022 00:10:39 +0000 (00:10 +0000)]
Fix docs, fix incorrect lint source in note

2 years agoFill out documentation for new lint
David Koloski [Mon, 28 Feb 2022 22:28:45 +0000 (22:28 +0000)]
Fill out documentation for new lint

2 years agoSwitch the primary diagnostic to `unknown_lints`
David Koloski [Mon, 28 Feb 2022 20:29:06 +0000 (20:29 +0000)]
Switch the primary diagnostic to `unknown_lints`

This also affects the `non_exhaustive_omitted_patterns` and
`must_not_suspend` lints as they are not stable. This also changes the
diagnostic level to pull from `unknown_lints` instead of always being
allow or deny.

2 years agoTreat unstable lints as unknown
David Koloski [Wed, 23 Feb 2022 04:53:17 +0000 (04:53 +0000)]
Treat unstable lints as unknown

This change causes unstable lints to be ignored if the `unknown_lints`
lint is allowed. To achieve this, it also changes lints to apply as soon
as they are processed. Previously, lints in the same set were processed
as a batch and then all simultaneously applied.

Implementation of https://github.com/rust-lang/compiler-team/issues/469

2 years agoAdd core::hint::must_use
David Tolnay [Tue, 8 Mar 2022 00:37:59 +0000 (16:37 -0800)]
Add core::hint::must_use

2 years agoDo not suggest `let_else` if no bindings would be introduced
Esteban Kuber [Tue, 8 Mar 2022 17:20:05 +0000 (17:20 +0000)]
Do not suggest `let_else` if no bindings would be introduced

2 years agoAuto merge of #92260 - jyn514:less-python-logic, r=Mark-Simulacrum
bors [Tue, 8 Mar 2022 17:04:45 +0000 (17:04 +0000)]
Auto merge of #92260 - jyn514:less-python-logic, r=Mark-Simulacrum

Move some more bootstrap logic from python to rust

Same rationale as https://github.com/rust-lang/rust/pull/76544; it would be nice to make python entirely optional at some point.

This also removes $ROOT as an option for the build directory; I haven't been using it, and like Alex
said in https://github.com/rust-lang/rust/pull/76544#discussion_r488248930 it seems like a misfeature.

This allows running `cargo run` from src/bootstrap, although that still gives
lots of compile errors if you don't use the beta toolchain. It's not exactly the same as using `x.py`, since it won't have `BOOTSTRAP_DOWNLOAD_RUSTC` set, but it's pretty close. Doing this from the top-level directory requires https://github.com/rust-lang/cargo/issues/7290 to be fixed, or using `cargo run -p bootstrap`.

The next steps for making python optional are to move download-ci-llvm and download-rustc support into rustbuild, likely be shelling out as the python scripts do today.

It would also be nice (although not required) to move submodule support there, but that would require taking bootstrap out of the workspace to avoid errors from crates that haven't been cloned yet.

r? `@Mark-Simulacrum`

2 years agoSuggest `if let`/`let_else` for refutable pat in `let`
Esteban Kuber [Tue, 8 Mar 2022 05:54:38 +0000 (05:54 +0000)]
Suggest `if let`/`let_else` for refutable pat in `let`

2 years agomention ignored fields of ExprKind::StaticRef
b-naber [Tue, 8 Mar 2022 14:44:06 +0000 (15:44 +0100)]
mention ignored fields of ExprKind::StaticRef

2 years agoadd `#[rustc_pass_by_value]` to more types
lcnr [Tue, 8 Mar 2022 14:39:52 +0000 (15:39 +0100)]
add `#[rustc_pass_by_value]` to more types

2 years agoAuto merge of #94734 - matthiaskrgr:rollup-28shqhy, r=matthiaskrgr
bors [Tue, 8 Mar 2022 10:24:46 +0000 (10:24 +0000)]
Auto merge of #94734 - matthiaskrgr:rollup-28shqhy, r=matthiaskrgr

Rollup of 8 pull requests

Successful merges:

 - #91993 (Tweak output for non-exhaustive `match` expression)
 - #92385 (Add Result::{ok, err, and, or, unwrap_or} as const)
 - #94559 (Remove argument from closure in thread::Scope::spawn.)
 - #94580 (Emit `unused_attributes` if a level attr only has a reason)
 - #94586 (Generalize `get_nullable_type` to allow types where null is all-ones.)
 - #94708 (diagnostics: only talk about `Cargo.toml` if running under Cargo)
 - #94712 (promot debug_assert to assert)
 - #94726 (:arrow_up: rust-analyzer)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoRollup merge of #94726 - lnicola:rust-analyzer-2022-03-08, r=lnicola
Matthias Krüger [Tue, 8 Mar 2022 10:04:56 +0000 (11:04 +0100)]
Rollup merge of #94726 - lnicola:rust-analyzer-2022-03-08, r=lnicola

:arrow_up: rust-analyzer

r? `@ghost`

2 years agoRollup merge of #94712 - kckeiks:remove-rwlock-read-error-assumption, r=Mark-Simulacrum
Matthias Krüger [Tue, 8 Mar 2022 10:04:55 +0000 (11:04 +0100)]
Rollup merge of #94712 - kckeiks:remove-rwlock-read-error-assumption, r=Mark-Simulacrum

promot debug_assert to assert

Fixes #94705

2 years agoRollup merge of #94708 - notriddle:notriddle/cargo-toml-warning, r=lcnr
Matthias Krüger [Tue, 8 Mar 2022 10:04:54 +0000 (11:04 +0100)]
Rollup merge of #94708 - notriddle:notriddle/cargo-toml-warning, r=lcnr

diagnostics: only talk about `Cargo.toml` if running under Cargo

Fixes #94646

2 years agoRollup merge of #94586 - sunfishcode:sunfishcode/io-lifetimes-tests, r=davidtwco
Matthias Krüger [Tue, 8 Mar 2022 10:04:53 +0000 (11:04 +0100)]
Rollup merge of #94586 - sunfishcode:sunfishcode/io-lifetimes-tests, r=davidtwco

Generalize `get_nullable_type` to allow types where null is all-ones.

Generalize get_nullable_type to accept types that have an all-ones bit
pattern as their sentry "null" value.

This will allow [`OwnedFd`], [`BorrowedFd`], [`OwnedSocket`], and
[`BorrowedSocket`] to be marked with
`#[rustc_nonnull_optimization_guaranteed]`, which will allow
`Option<OwnedFd>`, `Option<BorrowedFd>`, `Option<OwnedSocket>`, and
`Option<BorrowedSocket>` to be used in FFI declarations, as described
in the [I/O safety RFC].

For example, it will allow a function like `open` on Unix and `WSASocketW`
on Windows to be declared using `Option<OwnedFd>` and `Option<OwnedSocket>`
return types, respectively.

The actual change to add `#[rustc_nonnull_optimization_guaranteed]`
to the abovementioned types will be a separate PR, as it'll depend on
having this patch in the stage0 compiler.

Also, update the diagnostics to mention that "niche optimizations" are
used in libstd as well as libcore, as `rustc_layout_scalar_valid_range_start`
and `rustc_layout_scalar_valid_range_end` are already in use in libstd.

[`OwnedFd`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/fd/owned.rs#L49
[`BorrowedFd`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/fd/owned.rs#L29
[`OwnedSocket`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/windows/io/socket.rs#L51
[`BorrowedSocket`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/windows/io/socket.rs#L29
[I/O safety RFC]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md#ownedfd-and-borrowedfdfd-1

2 years agoRollup merge of #94580 - xFrednet:55112-only-reason-in-lint-attr, r=lcnr
Matthias Krüger [Tue, 8 Mar 2022 10:04:52 +0000 (11:04 +0100)]
Rollup merge of #94580 - xFrednet:55112-only-reason-in-lint-attr, r=lcnr

Emit `unused_attributes` if a level attr only has a reason

Fixes a comment from `compiler/rustc_lint/src/levels.rs`. Lint level attributes that only contain a reason will also trigger the `unused_attribute` lint. The lint now also checks for the `expect` lint level.

That's it, have a great rest of the day for everyone reasoning this :upside_down_face:

cc: #55112

2 years agoRollup merge of #94559 - m-ou-se:thread-scope-spawn-closure-without-arg, r=Mark-Simul...
Matthias Krüger [Tue, 8 Mar 2022 10:04:51 +0000 (11:04 +0100)]
Rollup merge of #94559 - m-ou-se:thread-scope-spawn-closure-without-arg, r=Mark-Simulacrum

Remove argument from closure in thread::Scope::spawn.

This implements ```@danielhenrymantilla's``` [suggestion](https://github.com/rust-lang/rust/issues/93203#issuecomment-1040798286) for improving the scoped threads interface.

Summary:

The `Scope` type gets an extra lifetime argument, which represents basically its own lifetime that will be used in `&'scope Scope<'scope, 'env>`:

```diff
- pub struct Scope<'env> { .. };
+ pub struct Scope<'scope, 'env: 'scope> { .. }

  pub fn scope<'env, F, T>(f: F) -> T
  where
-     F: FnOnce(&Scope<'env>) -> T;
+     F: for<'scope> FnOnce(&'scope Scope<'scope, 'env>) -> T;
```

This simplifies the `spawn` function, which now no longer passes an argument to the closure you give it, and now uses the `'scope` lifetime for everything:

```diff
-     pub fn spawn<'scope, F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T>
+     pub fn spawn<F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T>
      where
-         F: FnOnce(&Scope<'env>) -> T + Send + 'env,
+         F: FnOnce() -> T + Send + 'scope,
-         T: Send + 'env;
+         T: Send + 'scope;
```

The only difference the user will notice, is that their closure now takes no arguments anymore, even when spawning threads from spawned threads:

```diff
  thread::scope(|s| {
-     s.spawn(|_| {
+     s.spawn(|| {
          ...
      });
-     s.spawn(|s| {
+     s.spawn(|| {
          ...
-         s.spawn(|_| ...);
+         s.spawn(|| ...);
      });
  });
```

<details><summary>And, as a bonus, errors get <em>slightly</em> better because now any lifetime issues point to the outermost <code>s</code> (since there is only one <code>s</code>), rather than the innermost <code>s</code>, making it clear that the lifetime lasts for the entire <code>thread::scope</code>.

</summary>

```diff
  error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function
   --> src/main.rs:9:21
    |
- 7 |         s.spawn(|s| {
-   |                  - has type `&Scope<'1>`
+ 6 |     thread::scope(|s| {
+   |                    - lifetime `'1` appears in the type of `s`
  9 |             s.spawn(|| println!("{:?}", a)); // might run after `a` is dropped
    |                     ^^                  - `a` is borrowed here
    |                     |
    |                     may outlive borrowed value `a`
    |
  note: function requires argument type to outlive `'1`
   --> src/main.rs:9:13
    |
  9 |             s.spawn(|| println!("{:?}", a)); // might run after `a` is dropped
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: to force the closure to take ownership of `a` (and any other referenced variables), use the `move` keyword
    |
  9 |             s.spawn(move || println!("{:?}", a)); // might run after `a` is dropped
    |                     ++++
"
```
</details>

The downside is that the signature of `scope` and `Scope` gets slightly more complex, but in most cases the user wouldn't need to write those, as they just use the argument provided by `thread::scope` without having to name its type.

Another downside is that this does not work nicely in Rust 2015 and Rust 2018, since in those editions, `s` would be captured by reference and not by copy. In those editions, the user would need to use `move ||` to capture `s` by copy. (Which is what the compiler suggests in the error.)

2 years agoRollup merge of #92385 - clarfonthey:const_option, r=fee1-dead
Matthias Krüger [Tue, 8 Mar 2022 10:04:50 +0000 (11:04 +0100)]
Rollup merge of #92385 - clarfonthey:const_option, r=fee1-dead

Add Result::{ok, err, and, or, unwrap_or} as const

Already opened tracking issue #92384.

I don't think that this should actually cause any issues as long as the constness is unstable, but we may want to double-check that this doesn't get interpreted as a weird `Drop` bound even for non-const usages.

2 years agoRollup merge of #91993 - estebank:match-span-suggestion, r=oli-obk
Matthias Krüger [Tue, 8 Mar 2022 10:04:49 +0000 (11:04 +0100)]
Rollup merge of #91993 - estebank:match-span-suggestion, r=oli-obk

Tweak output for non-exhaustive `match` expression

* Provide structured suggestion when missing `match` arms
* Move pointing at the missing variants *after* the main error

<img width="1164" alt="" src="https://user-images.githubusercontent.com/1606434/146312085-b57ef4a3-6e96-4f32-aa2a-803637d9eeba.png">

2 years agoFix for issue #93283
Miguel Perez [Tue, 8 Mar 2022 09:16:18 +0000 (10:16 +0100)]
Fix for issue #93283

2 years agotreat literals in ExprKind::StaticRef as mir::ConstantKind::Val
b-naber [Mon, 7 Mar 2022 12:51:59 +0000 (13:51 +0100)]
treat literals in ExprKind::StaticRef as mir::ConstantKind::Val

2 years agoAuto merge of #94716 - RalfJung:miri, r=RalfJung
bors [Tue, 8 Mar 2022 07:44:03 +0000 (07:44 +0000)]
Auto merge of #94716 - RalfJung:miri, r=RalfJung

update Miri

Fixes https://github.com/rust-lang/rust/issues/94687
r? `@rust-lang/miri`

2 years agoReverted atomic-mut-ptr feature removal causing compilation break
Sandeep Bansal [Tue, 8 Mar 2022 07:41:52 +0000 (23:41 -0800)]
Reverted atomic-mut-ptr feature removal causing compilation break

2 years agoonly emit pointer-like metadata for BZST-allocator Box
Michael Goulet [Tue, 8 Mar 2022 07:06:59 +0000 (23:06 -0800)]
only emit pointer-like metadata for BZST-allocator Box

2 years ago:arrow_up: rust-analyzer
Laurențiu Nicola [Tue, 8 Mar 2022 06:44:23 +0000 (08:44 +0200)]
:arrow_up: rust-analyzer

2 years agounix: Avoid name conversions in `remove_dir_all_recursive`
Josh Stone [Tue, 8 Mar 2022 02:51:53 +0000 (18:51 -0800)]
unix: Avoid name conversions in `remove_dir_all_recursive`

Each recursive call was creating an `OsString` for a `&Path`, only for
it to be turned into a `CString` right away. Instead we can directly
pass `.name_cstr()`, saving two allocations each time.

2 years agoupdate Miri
Ralf Jung [Tue, 8 Mar 2022 01:49:03 +0000 (20:49 -0500)]
update Miri

2 years agoStatically compile libstdc++ everywhere if asked
Jon Gjengset [Tue, 8 Mar 2022 00:59:10 +0000 (16:59 -0800)]
Statically compile libstdc++ everywhere if asked

PR #93918 made it so that `-static-libstdc++` was only set in one place,
and was only set during linking, but accidentally also made it so that
it is no longer passed when building LLD or sanitizers, only when
building LLVM itself. This moves the logic for setting
`-static-libstdc++` in the linker flags back to `configure_cmake` so
that it takes effect for all CMake invocations in `native.rs`.

As a side-effect, this also causes libstdc++ to be statically compiled
into sanitizers and LLD if `llvm-tools-enabled` is set but
`llvm-static-stdcpp` is not, even though previously it was only linked
statically if `llvm-static-stdcpp` was set explicitly. But that seems
more like the expected behavior anyway.

2 years agoAuto merge of #90887 - jackh726:issue-90729, r=nikomatsakis
bors [Tue, 8 Mar 2022 00:53:41 +0000 (00:53 +0000)]
Auto merge of #90887 - jackh726:issue-90729, r=nikomatsakis

Try to normalize associated types before processing obligations

Closes #90729

r? `@nikomatsakis`

2 years agoBless test
Jack Huey [Mon, 7 Mar 2022 21:24:41 +0000 (16:24 -0500)]
Bless test

2 years agoChange wording of suggestion to add missing `match` arm
Esteban Kuber [Thu, 16 Dec 2021 22:46:13 +0000 (22:46 +0000)]
Change wording of suggestion to add missing `match` arm

2 years agoPoint at uncovered variants in enum definition in `note` instead of a `span_label`
Esteban Kuber [Thu, 16 Dec 2021 05:06:44 +0000 (05:06 +0000)]
Point at uncovered variants in enum definition in `note` instead of a `span_label`

This makes the order of the output always consistent:

1. Place of the `match` missing arms
2. The `enum` definition span
3. The structured suggestion to add a fallthrough arm

2 years agoWhen finding a match expr with multiple arms that requires more, suggest it
Esteban Kuber [Thu, 16 Dec 2021 02:28:09 +0000 (02:28 +0000)]
When finding a match expr with multiple arms that requires more, suggest it

Given

```rust
match Some(42) {
    Some(0) => {}
    Some(1) => {}
}
```

suggest

```rust
match Some(42) {
    Some(0) => {}
    Some(1) => {}
    None | Some(_) => todo!(),
}
```

2 years agoWhen finding a match expr with a single arm that requires more, suggest it
Esteban Kuber [Thu, 16 Dec 2021 02:14:17 +0000 (02:14 +0000)]
When finding a match expr with a single arm that requires more, suggest it

Given

```rust
match Some(42) {
    Some(0) => {}
}
```

suggest

```rust
match Some(42) {
    Some(0) => {}
    None | Some(_) => todo!(),
}
```

2 years agoWhen encountering a match expr with no arms, suggest it
Esteban Kuber [Thu, 16 Dec 2021 02:05:58 +0000 (02:05 +0000)]
When encountering a match expr with no arms, suggest it

Given

```rust
match Some(42) {}
```

suggest

```rust
match Some(42) { None | Some(_) => todo!(), }
```

2 years agoEnable `close_read_wakes_up` on Windows
Chris Denton [Mon, 7 Mar 2022 22:35:17 +0000 (22:35 +0000)]
Enable `close_read_wakes_up` on Windows

2 years agoUse `f` instead of `|| f()`.
Mara Bos [Mon, 7 Mar 2022 22:14:02 +0000 (22:14 +0000)]
Use `f` instead of `|| f()`.

Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2 years agocopy over `std::path::absolute` instead of adding `canonicalize` hacks
Joshua Nelson [Thu, 3 Mar 2022 12:12:32 +0000 (06:12 -0600)]
copy over `std::path::absolute` instead of adding `canonicalize` hacks

this also fixes a bug where bootstrap would try to use the fake `rustc` binary built by bootstrap -
cargo puts it in a different directory when using `cargo run` instead of x.py

2 years agofix weird bug when `out` would get overridden by unit tests
Joshua Nelson [Mon, 7 Feb 2022 03:24:47 +0000 (21:24 -0600)]
fix weird bug when `out` would get overridden by unit tests

2 years agoDon't depend on python for RUST_BOOTSTRAP_CONFIG
Joshua Nelson [Mon, 7 Feb 2022 00:10:49 +0000 (18:10 -0600)]
Don't depend on python for RUST_BOOTSTRAP_CONFIG

2 years agoMove some more bootstrap logic from python to rust
Joshua Nelson [Fri, 24 Dec 2021 19:03:02 +0000 (13:03 -0600)]
Move some more bootstrap logic from python to rust

Same rationale as https://github.com/rust-lang/rust/pull/76544;
it would be nice to make python entirely optional at some point.

This also removes $ROOT as an option for the build directory; I haven't been using it, and like Alex
said in https://github.com/rust-lang/rust/pull/76544#discussion_r488248930 it seems like a
misfeature.

This allows running `cargo run` from src/bootstrap, although that still gives
lots of compile errors if you don't use the beta toolchain.

2 years agoAuto merge of #94709 - martingms:link-to-chunked-opt-pr, r=nnethercote
bors [Mon, 7 Mar 2022 21:20:05 +0000 (21:20 +0000)]
Auto merge of #94709 - martingms:link-to-chunked-opt-pr, r=nnethercote

Add link to closed PR for future optimizers of ChunkedBitSet relations

While optimizing these operations proved unfruitful w.r.t. improving compiler performance right now, faster versions might be needed at a later time. This PR adds a link in the FIXME to save any future optimizers some time, as requested by `@nnethercote` in https://github.com/rust-lang/rust/pull/94625.

r? `@nnethercote`

2 years agoBless issue-91130 test
Jack Huey [Sat, 26 Feb 2022 03:48:47 +0000 (22:48 -0500)]
Bless issue-91130 test

2 years agoTry to normalize associated types before processing obligations
Jack Huey [Sat, 13 Nov 2021 23:45:03 +0000 (18:45 -0500)]
Try to normalize associated types before processing obligations

2 years agopromot debug_assert to assert
Fausto [Mon, 7 Mar 2022 20:48:35 +0000 (15:48 -0500)]
promot debug_assert to assert

2 years agoAdd comment linking to closed PR for future optimizers
Martin Gammelsæter [Mon, 7 Mar 2022 18:06:42 +0000 (19:06 +0100)]
Add comment linking to closed PR for future optimizers

While optimizing these operations proved unfruitful w.r.t. improving
compiler performance right now, faster versions might be needed at a
later time.

2 years agoAuto merge of #94706 - matthiaskrgr:rollup-l5erynr, r=matthiaskrgr
bors [Mon, 7 Mar 2022 18:06:31 +0000 (18:06 +0000)]
Auto merge of #94706 - matthiaskrgr:rollup-l5erynr, r=matthiaskrgr

Rollup of 4 pull requests

Successful merges:

 - #93350 (libunwind: readd link attrs to _Unwind_Backtrace)
 - #93827 (Stabilize const_fn_fn_ptr_basics, const_fn_trait_bound, and const_impl_trait)
 - #94696 (Remove whitespaces and use CSS to align line numbers to the right instead)
 - #94700 (rustdoc: Update minifier version)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agodiagnostics: only talk about `Cargo.toml` if running under Cargo
Michael Howell [Mon, 7 Mar 2022 17:50:47 +0000 (10:50 -0700)]
diagnostics: only talk about `Cargo.toml` if running under Cargo

Fixes #94646

2 years agoRollup merge of #94700 - GuillaumeGomez:update-minifier, r=notriddle
Matthias Krüger [Mon, 7 Mar 2022 17:39:04 +0000 (18:39 +0100)]
Rollup merge of #94700 - GuillaumeGomez:update-minifier, r=notriddle

rustdoc: Update minifier version

This new version includes a fix for the CSS minifier which was badly handling inline media queries like ``@import` 'i';`.

r? `@notriddle`

2 years agoRollup merge of #94696 - GuillaumeGomez:align-line-numbers-right, r=notriddle
Matthias Krüger [Mon, 7 Mar 2022 17:39:03 +0000 (18:39 +0100)]
Rollup merge of #94696 - GuillaumeGomez:align-line-numbers-right, r=notriddle

Remove whitespaces and use CSS to align line numbers to the right instead

Instead of generating whitespaces to create padding, we simply use the CSS rule: `text-align: right`.

Nice side-effect: it reduces the generated HTML size from **75.004** to **74.828** (MegaBytes) on the std source pages (it's not much but it's always a nice plus :laughing: ).

There are no changes in the generated UI.

r? `@notriddle`

2 years agoRollup merge of #93827 - eholk:stabilize-const_fn-features, r=wesleywiser
Matthias Krüger [Mon, 7 Mar 2022 17:39:02 +0000 (18:39 +0100)]
Rollup merge of #93827 - eholk:stabilize-const_fn-features, r=wesleywiser

Stabilize const_fn_fn_ptr_basics, const_fn_trait_bound, and const_impl_trait

# Stabilization Report

This PR serves as a request for stabilization for three const evaluation features:

1. `const_fn_fn_ptr_basics`
2. `const_fn_trait_bound`
3. `const_impl_trait`

These are being stabilized together because they are relatively minor and related updates to existing functionality.

## `const_fn_fn_ptr_basics`

Allows creating, passing, and casting function pointers in a `const fn`.

The following is an example of what is now allowed:

```rust
const fn get_function() -> fn() {
    fn foo() {
        println!("Hello, World!");
    }

    foo
}
```

Casts between function pointer types are allowed, as well as transmuting from integers:

```rust
const fn get_function() -> fn() {
    unsafe {
        std::mem::transmute(0x1234usize)
    }
}
```

However, casting from a function pointer to an integer is not allowed:

```rust
const fn fn_to_usize(f: fn()) -> usize {
    f as usize  //~ pointers cannot be cast to integers during const eval
}
```

Calling function pointers is also not allowed.

```rust
const fn call_fn_ptr(f: fn()) {
    f() //~ function pointers are not allowed in const fn
}
```

### Test Coverage

The following tests include code that exercises this feature:

- `src/test/ui/consts/issue-37550.rs`
- `src/test/ui/consts/issue-46553.rs`
- `src/test/ui/consts/issue-56164.rs`
- `src/test/ui/consts/min_const_fn/allow_const_fn_ptr_run_pass.rs`
- `src/test/ui/consts/min_const_fn/cast_fn.rs`
- `src/test/ui/consts/min_const_fn/cmp_fn_pointers.rs`

## `const_fn_trait_bound`

Allows trait bounds in `const fn`. Additionally, this feature allows creating and passing `dyn Trait` objects.

Examples such as the following are allowed by this feature:

```rust
const fn do_thing<T: Foo>(_x: &T) {
    // ...
}
```

Previously only `Sized` was allowed as a trait bound.

There is no way to call methods from the trait because trait methods cannot currently be marked as const. Allowing trait bounds in const functions does allow the const function to use the trait's associated types and constants.

This feature also allowes `dyn Trait` types. These work equivalently to non-const code. Similar to other pointers in const code, the value of a `dyn Trait` pointer cannot be observed.

Note that due to https://github.com/rust-lang/rust/issues/90912, it was already possible to do the example above as follows:

```rust
const fn do_thing<T>(_x: &T) where (T,): Foo {
    // ...
}
```

### Test Coverage

The following tests include code that exercises `const_fn_trait_bound`:

- `src/test/ui/consts/const-fn.rs`
- `src/test/ui/consts/issue-88071.rs`
- `src/test/ui/consts/min_const_fn/min_const_fn.rs`
- `src/test/ui/consts/min_const_fn/min_const_fn_dyn.rs`
- `src/test/ui/nll/issue-55825-const-fn.rs`
- Many of the tests in `src/test/ui/rfc-2632-const-trait-impl/` also exercise this feature.

## `const_impl_trait`

Allows argument and return position `impl Trait` in a `const fn`, such as in the following example:

```rust
const fn do_thing(x: impl Foo) -> impl Foo {
    x
}
```

Similar to generic parameters and function pointers, this allows the creation of such opaque types, but not doing anything with them beyond accessing associated types and constants.

### Test Coverage

The following tests exercise this feature:

- `src/test/ui/type-alias-impl-trait/issue-53096.rs`
- `src/test/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs`

## Documentation

These features are documented along with the other const evaluation features in the Rust Reference at https://doc.rust-lang.org/stable/reference/const_eval.html.

There is a PR that updates this documentation to reflect the capabilities enabled by these features at https://github.com/rust-lang/reference/pull/1166.

Tracking issues: #57563, #63997, #93706

2 years agoRollup merge of #93350 - gburgessiv:master, r=Mark-Simulacrum
Matthias Krüger [Mon, 7 Mar 2022 17:39:02 +0000 (18:39 +0100)]
Rollup merge of #93350 - gburgessiv:master, r=Mark-Simulacrum

libunwind: readd link attrs to _Unwind_Backtrace

It seems the removal of these in 1c07096a45a15de64216f12ec726333870e372b1 was unintended; readding them fixes the build.

fixes rust-lang/rust#93349

r? `@alexcrichton`

2 years agoUpdate tests
Eric Holk [Fri, 4 Mar 2022 19:29:57 +0000 (11:29 -0800)]
Update tests

2 years agoBump stabilization version to 1.61.0
Eric Holk [Sat, 26 Feb 2022 00:17:25 +0000 (16:17 -0800)]
Bump stabilization version to 1.61.0

2 years agoStabilize const_impl_trait as well
Eric Holk [Sat, 12 Feb 2022 02:04:44 +0000 (18:04 -0800)]
Stabilize const_impl_trait as well

2 years agoRemove dead/useless code
Eric Holk [Fri, 11 Feb 2022 19:36:02 +0000 (11:36 -0800)]
Remove dead/useless code

2 years agoUpdate and fix clippy tests
Eric Holk [Fri, 11 Feb 2022 03:23:43 +0000 (19:23 -0800)]
Update and fix clippy tests

2 years agoUpdate tests after feature stabilization
Eric Holk [Wed, 9 Feb 2022 18:53:40 +0000 (10:53 -0800)]
Update tests after feature stabilization

2 years agoStabilize const_fn_fn_ptr_basics and const_fn_trait_bound
Eric Holk [Wed, 9 Feb 2022 00:33:15 +0000 (16:33 -0800)]
Stabilize const_fn_fn_ptr_basics and const_fn_trait_bound

2 years agoDo not allow `#[rustc_legacy_const_generics]` on methods
Chayim Refael Friedman [Mon, 7 Mar 2022 16:31:03 +0000 (16:31 +0000)]
Do not allow `#[rustc_legacy_const_generics]` on methods

It caused an ICE since `item` was `None`.

2 years agoAuto merge of #94690 - nnethercote:clarify-Layout-interning, r=fee1-dead
bors [Mon, 7 Mar 2022 15:25:42 +0000 (15:25 +0000)]
Auto merge of #94690 - nnethercote:clarify-Layout-interning, r=fee1-dead

Clarify `Layout` interning.

`Layout` is another type that is sometimes interned, sometimes not, and
we always use references to refer to it so we can't take any advantage
of the uniqueness properties for hashing or equality checks.

This commit renames `Layout` as `LayoutS`, and then introduces a new
`Layout` that is a newtype around an `Interned<LayoutS>`. It also
interns more layouts than before. Previously layouts within layouts
(via the `variants` field) were never interned, but now they are. Hence
the lifetime on the new `Layout` type.

Unlike other interned types, these ones are in `rustc_target` instead of
`rustc_middle`. This reflects the existing structure of the code, which
does layout-specific stuff in `rustc_target` while `TyAndLayout` is
generic over the `Ty`, allowing the type-specific stuff to occur in
`rustc_middle`.

The commit also adds a `HashStable` impl for `Interned`, which was
needed. It hashes the contents, unlike the `Hash` impl which hashes the
pointer.

r? `@fee1-dead`

2 years agoUpdate minifier version
Guillaume Gomez [Mon, 7 Mar 2022 14:10:24 +0000 (15:10 +0100)]
Update minifier version

2 years agoAuto merge of #94695 - matthiaskrgr:rollup-5pi3acz, r=matthiaskrgr
bors [Mon, 7 Mar 2022 13:02:31 +0000 (13:02 +0000)]
Auto merge of #94695 - matthiaskrgr:rollup-5pi3acz, r=matthiaskrgr

Rollup of 4 pull requests

Successful merges:

 - #94553 (add tests for #94502)
 - #94614 (Remove ordering traits from `rustc_span::hygiene::LocalExpnId`)
 - #94685 (interpret: move saturating_add/sub into (pub) helper method)
 - #94688 (Erase regions when checking for missing Copy predicates)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoAdd missing documentation for std::char types
Guillaume Gomez [Fri, 30 Jul 2021 09:25:12 +0000 (11:25 +0200)]
Add missing documentation for std::char types

2 years agoBTree: remove dead data needlessly complicating insert
Stein Somers [Mon, 7 Mar 2022 10:31:16 +0000 (11:31 +0100)]
BTree: remove dead data needlessly complicating insert

2 years agoAdd GUI test to ensure that line numbers text is aligned to the right
Guillaume Gomez [Mon, 7 Mar 2022 11:08:14 +0000 (12:08 +0100)]
Add GUI test to ensure that line numbers text is aligned to the right