Commit Graph

163987 Commits

Author SHA1 Message Date
Matthias Krüger
a638f50d8d
Rollup merge of #92697 - the8472:cgroups, r=joshtriplett
Use cgroup quotas for calculating `available_parallelism`

Automated tests for this are possible but would require a bunch of assumptions. It requires root + a recent kernel, systemd and maybe docker. And even then it would need a helper binary since the test has to run in a separate process.

Limitations

* only supports cgroup v2 and assumes it's mounted under `/sys/fs/cgroup`
* procfs must be available
* the quota gets mixed into `sched_getaffinity`, so if the latter doesn't work then quota information gets ignored too

Manually tested via

```
// spawn a new cgroup scope for the current user
$ sudo systemd-run -p CPUQuota="300%" --uid=$(id -u) -tdS

// quota.rs
#![feature(available_parallelism)]
fn main() {
    println!("{:?}", std:🧵:available_parallelism()); // prints Ok(3)
}
```

strace:

```
sched_getaffinity(3041643, 32, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]) = 32
openat(AT_FDCWD, "/proc/self/cgroup", O_RDONLY|O_CLOEXEC) = 3
statx(0, NULL, AT_STATX_SYNC_AS_STAT, STATX_ALL, NULL) = -1 EFAULT (Bad address)
statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0444, stx_size=0, ...}) = 0
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "0::/system.slice/run-u31477.serv"..., 128) = 36
read(3, "", 92)                         = 0
close(3)                                = 0
statx(AT_FDCWD, "/sys/fs/cgroup/system.slice/run-u31477.service/cgroup.controllers", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0444, stx_size=0, ...}) = 0
openat(AT_FDCWD, "/sys/fs/cgroup/system.slice/run-u31477.service/cpu.max", O_RDONLY|O_CLOEXEC) = 3
statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "300000 100000\n", 20)          = 14
read(3, "", 6)                          = 0
close(3)                                = 0
openat(AT_FDCWD, "/sys/fs/cgroup/system.slice/cpu.max", O_RDONLY|O_CLOEXEC) = 3
statx(3, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0
lseek(3, 0, SEEK_CUR)                   = 0
read(3, "max 100000\n", 20)             = 11
read(3, "", 9)                          = 0
close(3)                                = 0
openat(AT_FDCWD, "/sys/fs/cgroup/cpu.max", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
sched_getaffinity(0, 128, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]) = 40
```

r? ```````@joshtriplett```````
cc ```````@yoshuawuyts```````

Tracking issue and previous discussion: #74479
2022-03-03 20:01:43 +01:00
Camille GILLOT
c680d39b1e Bless nll tests. 2022-03-03 19:59:52 +01:00
bors
10913c0001 Auto merge of #87835 - xFrednet:rfc-2383-expect-attribute-with-ids, r=wesleywiser
Implementation of the `expect` attribute (RFC 2383)

This is an implementation of the `expect` attribute as described in [RFC-2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html). The attribute allows the suppression of lint message by expecting them. Unfulfilled lint expectations (meaning no expected lint was caught) will emit the `unfulfilled_lint_expectations` lint at the `expect` attribute.

### Example
#### input
```rs
// required feature flag
#![feature(lint_reasons)]

#[expect(unused_mut)] // Will warn about an unfulfilled expectation
#[expect(unused_variables)] // Will be fulfilled by x
fn main() {
    let x = 0;
}
```

#### output

```txt
warning: this lint expectation is unfulfilled
  --> $DIR/trigger_lint.rs:3:1
   |
LL | #[expect(unused_mut)] // Will warn about an unfulfilled expectation
   |          ^^^^^^^^^^
   |
   = note: `#[warn(unfulfilled_lint_expectations)]` on by default
```

### Implementation

This implementation introduces `Expect` as a new lint level for diagnostics, which have been expected. All lint expectations marked via the `expect` attribute are collected in the [`LintLevelsBuilder`] and assigned an ID that is stored in the new lint level. The `LintLevelsBuilder` stores all found expectations and the data needed to emit the `unfulfilled_lint_expectations` in the [`LintLevelsMap`] which is the result of the [`lint_levels()`] query.

The [`rustc_errors::HandlerInner`] is the central error handler in rustc and handles the emission of all diagnostics. Lint message with the level `Expect` are suppressed during this emission, while the expectation ID is stored in a set which marks them as fulfilled. The last step is then so simply check if all expectations collected by the [`LintLevelsBuilder`] in the [`LintLevelsMap`] have been marked as fulfilled in the [`rustc_errors::HandlerInner`]. Otherwise, a new lint message will be emitted.

The implementation of the `LintExpectationId` required some special handling to make it stable between sessions. Lints can be emitted during [`EarlyLintPass`]es. At this stage, it's not possible to create a stable identifier. The level instead stores an unstable identifier, which is later converted to a stable `LintExpectationId`.

### Followup TO-DOs
All open TO-DOs have been marked with `FIXME` comments in the code. This is the combined list of them:

* [ ] The current implementation doesn't cover cases where the `unfulfilled_lint_expectations` lint is actually expected by another `expect` attribute.
   * This should be easily possible, but I wanted to get some feedback before putting more work into this.
   * This could also be done in a new PR to not add to much more code to this one
* [ ] Update unstable documentation to reflect this change.
* [ ] Update unstable expectation ids in [`HandlerInner::stashed_diagnostics`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/struct.HandlerInner.html#structfield.stashed_diagnostics)

### Open questions
I also have a few open questions where I would like to get feedback on:
1. The RFC discussion included a suggestion to change the `expect` attribute to something else. (Initiated by `@Ixrec` [here](https://github.com/rust-lang/rfcs/pull/2383#issuecomment-378424091), suggestion from `@scottmcm` to use `#[should_lint(...)]` [here](https://github.com/rust-lang/rfcs/pull/2383#issuecomment-378648877)). No real conclusion was drawn on that point from my understanding. Is this still open for discussion, or was this discarded with the merge of the RFC?
2. How should the expect attribute deal with the new `force-warn` lint level?

---

This approach was inspired by a discussion with `@LeSeulArtichaut.`

RFC tracking issue: #54503

Mentoring/Implementation issue: #85549

[`LintLevelsBuilder`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/levels/struct.LintLevelsBuilder.html
[`LintLevelsMap`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/lint/struct.LintLevelMap.html
[`lint_levels()`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.lint_levels
[`rustc_errors::HandlerInner`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/struct.HandlerInner.html
[`EarlyLintPass`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.EarlyLintPass.html
2022-03-03 18:59:32 +00:00
Jubilee Young
934345be2a
Add autovectorization codegen test
Co-authored-by: Scott McMurray <scottmcm@users.noreply.github.com>
2022-03-03 18:50:20 +00:00
Scott McMurray
8e985376d4
Redo the array-equality codegen tests for the different threshold 2022-03-03 18:30:34 +00:00
Vin Singh
9d45e0e0b4
Revert #26494 regression 2022-03-03 18:30:27 +00:00
bjorn3
e8f790fec7 Remove unused Default and Clone derives in config.rs 2022-03-03 18:59:26 +01:00
bjorn3
7f5bdf3ccb Remove some dead code from toolstate.rs 2022-03-03 18:59:26 +01:00
pierwill
c08a9a4f1d Make Ord, PartialOrd opt-out in newtype_index
Also remove `step` impl if `ORD_IMPL = off`
2022-03-03 11:52:40 -06:00
Camille GILLOT
42ffdd973e Make unknown feature error deterministic. 2022-03-03 18:50:28 +01:00
Camille GILLOT
27d8cd7db0 Cleanup feature gates. 2022-03-03 18:50:28 +01:00
Camille GILLOT
3c7947ee43 Gate stability attrs with other attributes. 2022-03-03 18:50:26 +01:00
Jon Gjengset
9c05f0b72c bootstrap: correct reading of flags for llvm
First, this reverts the `CFLAGS`/`CXXFLAGS` of #93918. Those flags are
already read by `cc` and populated into `Build` earlier on in the
process. We shouldn't be overriding that based on `CFLAGS`, since `cc`
also respects overrides like `CFLAGS_{TARGET}` and `HOST_CFLAGS`, which
we want to take into account.

Second, this adds the same capability to specify target-specific
versions of `LDFLAGS` as we have through `cc` for the `C*` flags:
https://github.com/alexcrichton/cc-rs#external-configuration-via-environment-variables

Note that this also necessitated an update to compiletest to treat
CXXFLAGS separately from CFLAGS.
2022-03-03 09:42:23 -08:00
bjorn3
2f84484aac Remove the everybody loops pass
It isn't used anymore by rustdoc
2022-03-03 18:23:09 +01:00
Camille GILLOT
969f8735dc Bless test. 2022-03-03 18:22:31 +01:00
Camille GILLOT
71838827b6 Force ensure stability_index. 2022-03-03 18:22:31 +01:00
Camille GILLOT
6f8e9f416a Move query providers. 2022-03-03 18:22:31 +01:00
Camille GILLOT
1b4b5e066b Remove useless map. 2022-03-03 18:14:34 +01:00
Camille GILLOT
fbcf7d415b Move the set of features to the features query. 2022-03-03 18:08:30 +01:00
Takayuki Maeda
ff19c05832 remove a unnecessary .. pattern 2022-03-04 00:57:38 +09:00
bors
32cbc7630b Auto merge of #84944 - lcnr:obligation-dedup, r=jackh726
remove obligation dedup from `impl_or_trait_obligations`

Looking at the examples from #38528 they all seem to compile fine even without this and it seems like this might be unnecessary effort
2022-03-03 15:43:42 +00:00
bors
4566094913 Auto merge of #94512 - RalfJung:sdiv-ub, r=oli-obk
Miri/CTFE: properly treat overflow in (signed) division/rem as UB

To my surprise, it looks like LLVM treats overflow of signed div/rem as UB. From what I can tell, MIR `Div`/`Rem` directly lowers to the corresponding LLVM operation, so to make that correct we also have to consider these overflows UB in the CTFE/Miri interpreter engine.

r? `@oli-obk`
2022-03-03 12:56:24 +00:00
cuishuang
00fffdddd2 all: fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-03-03 19:47:23 +08:00
Mara Bos
af86b55735 Remove unnecessary #![feature]s from doctest. 2022-03-03 12:09:18 +01:00
Mara Bos
c021ac35fa Update test. 2022-03-03 12:09:18 +01:00
Mara Bos
dadf2adbe9 Rename JoinHandle::is_running to is_finished and update docs.
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-03-03 12:09:17 +01:00
Loïc BRANSTETT
50e61a1a66 Add support for values() with --check-cfg 2022-03-03 12:00:28 +01:00
Loïc BRANSTETT
516488484e Fix invalid lint_node_id being put on a removed stmt 2022-03-03 11:52:09 +01:00
Nicholas Nethercote
97eb1b4669 Change initial_matcher_pos() into MatcherPos::new(). 2022-03-03 21:47:02 +11:00
Nicholas Nethercote
e5f3fd6250 Use a better return type for inner_parse_loop.
Because `inner_parse_loop` has only one way to not succeed, not three.
2022-03-03 21:46:59 +11:00
Nicholas Nethercote
643ba50004 Introduce MatcherPosRepetition.
There are three `Option` fields in `MatcherPos` that are only used in
tandem. This commit combines them, making the code slightly easier to
read. (It also makes clear that the `sep` field arguably should have
been `Option<Option<Token>>`!)
2022-03-03 21:45:52 +11:00
Nicholas Nethercote
b9fabc3f9c Add a static size assertion for MatcherPos. 2022-03-03 21:45:45 +11:00
Nicholas Nethercote
11c565f14b Improve if/else formatting in macro_parser.rs.
To avoid the strange style where comments force `else` onto its own
line.

The commit also removes several else-after-return constructs, which can
be hard to read.
2022-03-03 21:45:42 +11:00
Guillaume Gomez
e3f04de3d4 Add test for higher kinded functions generated by macros 2022-03-03 11:32:07 +01:00
Axel Viala
37c1eb0a47 Doc: Fix use of quote instead of backstick in Adapter::map. 2022-03-03 11:25:01 +01:00
bors
06460fe72c Auto merge of #94548 - matthiaskrgr:rollup-spa38z8, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #93562 (Update the documentation for `{As,Into,From}Raw{Fd,Handle,Socket}`.)
 - #94101 (rustdoc: add test cases for hidden enum variants)
 - #94484 (8 - Make more use of `let_chains`)
 - #94522 (Remove out-of-context line at end of E0284 message)
 - #94534 (Re-export (unstable) core::ffi types from std::ffi)
 - #94536 (Move transmute_undefined_repr back to nursery again)
 - #94537 (Use ? operator in one instance instead of manual match)
 - #94544 (Add some examples to comments in mbe code)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-03 10:14:04 +00:00
Matthias Krüger
88aa75ba8e
Rollup merge of #94544 - mark-i-m:macro-comments, r=petrochenkov
Add some examples to comments in mbe code

I found these things non-obvious when re-familiarizing myself with the code.

r? `@petrochenkov`
2022-03-03 11:02:56 +01:00
Matthias Krüger
98c9ee8917
Rollup merge of #94537 - est31:master, r=notriddle
Use ? operator in one instance instead of manual match

As suggested [here](https://github.com/rust-lang/rust/pull/94139#discussion_r818102403).

r? `@notriddle`
2022-03-03 11:02:55 +01:00
Matthias Krüger
250e7e1efe
Rollup merge of #94536 - dtolnay:transmute, r=Manishearth
Move transmute_undefined_repr back to nursery again

This PR reapplies #94014, which was reverted unintentionally I think by #94329. The combination of https://github.com/rust-lang/rust-clippy/pull/8432 + https://github.com/rust-lang/rust-clippy/pull/8497 in clippy should prevent this from happening again.

r? `@Manishearth`
2022-03-03 11:02:54 +01:00
Matthias Krüger
6f1730c9e3
Rollup merge of #94534 - bstrie:cffistd, r=Mark-Simulacrum
Re-export (unstable) core::ffi types from std::ffi
2022-03-03 11:02:53 +01:00
Matthias Krüger
845516cd3b
Rollup merge of #94522 - thinety:fix-e0284-message, r=Dylan-DPC
Remove out-of-context line at end of E0284 message

Removed the last line of E0284 message because it was out of context (probably kept by accident when changing whole error message).
2022-03-03 11:02:52 +01:00
Matthias Krüger
dbf0372b72
Rollup merge of #94484 - c410-f3r:more-let-chains, r=jackh726
8 - Make more use of `let_chains`

Continuation of #94376.

cc #53667
2022-03-03 11:02:51 +01:00
Matthias Krüger
850511d483
Rollup merge of #94101 - notriddle:notriddle/strip-test-cases, r=GuillaumeGomez
rustdoc: add test cases for hidden enum variants
2022-03-03 11:02:50 +01:00
Matthias Krüger
afd6f5c478
Rollup merge of #93562 - sunfishcode:sunfishcode/io-docs, r=joshtriplett
Update the documentation for `{As,Into,From}Raw{Fd,Handle,Socket}`.

This change weakens the descriptions of the
`{as,into,from}_raw_{fd,handle,socket}` descriptions from saying that
they *do* express ownership relations to say that they are *typically used*
in ways that express ownership relations. This is needed since, for
example, std's own [`RawFd`] implements `{As,From,Into}Fd` without any of
the ownership relationships.

This adds proper `# Safety` comments to `from_raw_{fd,handle,socket}`,
adds the requirement that raw handles be not opened with the
`FILE_FLAG_OVERLAPPED` flag, and merges the `OwnedHandle::from_raw_handle`
comment into the main `FromRawHandle::from_raw_handle` comment.

And, this changes `HandleOrNull` and `HandleOrInvalid` to not implement
`FromRawHandle`, since they are intended for limited use in FFI situations,
and not for generic use, and they have constraints that are stronger than
the those of `FromRawHandle`.

[`RawFd`]: https://doc.rust-lang.org/stable/std/os/unix/io/type.RawFd.html
2022-03-03 11:02:49 +01:00
bors
2f8d1a835b Auto merge of #94541 - Dylan-DPC:rollup-564wbq3, r=Dylan-DPC
Rollup of 9 pull requests

Successful merges:

 - #92061 (update char signess for openbsd)
 - #93072 (Compatible variants suggestion with desugaring)
 - #93354 (Add documentation about `BorrowedFd::to_owned`.)
 - #93663 (Rename `BorrowedFd::borrow_raw_fd` to `BorrowedFd::borrow_raw`.)
 - #94375 (Adt copy suggestions)
 - #94433 (Improve allowness of the unexpected_cfgs lint)
 - #94499 (Documentation was missed when demoting Windows XP to no_std only)
 - #94505 (Restore the local filter on mono item sorting)
 - #94529 (Unused doc comments blocks)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-03-03 04:28:08 +00:00
Erik Desjardins
a381aefebb make test work on noopt builder 2022-03-02 22:46:23 -05:00
mark
88b99224c1 add some examples to comments in mbe code 2022-03-02 21:33:43 -06:00
Dan Gohman
8253cfef7a Remove the comment about FILE_FLAG_OVERLAPPED.
There may eventually be something to say about `FILE_FLAG_OVERLAPPED` here,
however this appears to be independent of the other changes in this PR,
so remove them from this PR so that it can be discussed separately.
2022-03-02 16:25:31 -08:00
Ralf Jung
24fc1151ee bless clippy 2022-03-02 19:20:27 -05:00
Dylan DPC
878a4ff90e
Rollup merge of #94529 - GuillaumeGomez:unused-doc-comments-blocks, r=estebank
Unused doc comments blocks

Fixes #77030.
2022-03-03 01:09:15 +01:00