Hans Kratz [Mon, 28 Feb 2022 09:34:06 +0000 (10:34 +0100)]
remove_dir_all(): try recursing first instead of trying to unlink()
This only affects the `slow` code path, if there is no `dirent.d_type` or if
the type is `DT_UNKNOWN`.
POSIX specifies that calling `unlink()` or `unlinkat(..., 0)` on a directory can
succeed:
> "The _path_ argument shall not name a directory unless the process has
> appropriate privileges and the implementation supports using _unlink()_ on
> directories."
This however can cause orphaned directories requiring an fsck e.g. on Illumos
UFS, so we have to avoid that in the common case. We now just try to recurse
into it first and unlink() if we can't open it as a directory.
bors [Fri, 4 Mar 2022 05:49:14 +0000 (05:49 +0000)]
Auto merge of #94096 - cjgillot:ensure-stability, r=lcnr
Ensure stability directives are checked in all cases
Split off #93017
Stability and deprecation were not checked in all cases, for instance if a type error happened.
This PR moves the check earlier in the pipeline to ensure the errors are emitted in all cases.
bors [Fri, 4 Mar 2022 02:53:40 +0000 (02:53 +0000)]
Auto merge of #94588 - Dylan-DPC:rollup-7pxd0i3, r=Dylan-DPC
Rollup of 10 pull requests
Successful merges:
- #88805 (Clarification of default socket flags)
- #93418 (rustdoc & doc: no `shortcut` for `rel="icon"`)
- #93913 (Remove the everybody loops pass)
- #93965 (Make regular stdio lock() return 'static handles)
- #94339 (ARM: Only allow using d16-d31 with asm! when supported by the target)
- #94404 (Make Ord and PartialOrd opt-out in `newtype_index`)
- #94466 (bootstrap: correct reading of flags for llvm)
- #94572 (Use `HandleOrNull` and `HandleOrInvalid` in the Windows FFI bindings.)
- #94575 (CTFE SwitchInt: update comment)
- #94582 (Fix a bug in `x.py fmt` that prevents some files being formatted.)
Dylan DPC [Fri, 4 Mar 2022 01:06:42 +0000 (02:06 +0100)]
Rollup merge of #94572 - sunfishcode:sunfishcode/handle-or, r=joshtriplett
Use `HandleOrNull` and `HandleOrInvalid` in the Windows FFI bindings.
Use the new `HandleOrNull` and `HandleOrInvalid` types that were introduced
as part of [I/O safety] in a few functions in the Windows FFI bindings.
This factors out an `unsafe` block and two `unsafe` function calls in the
Windows implementation code.
And, it helps test `HandleOrNull` and `HandleOrInvalid`, and indeed, it
turned up a bug: `OwnedHandle` also needs to be `#[repr(transparent)]`,
as it's used inside of `HandleOrNull` and `HandleOrInvalid` which are also
`#[repr(transparent)]`.
Dylan DPC [Fri, 4 Mar 2022 01:06:41 +0000 (02:06 +0100)]
Rollup merge of #94466 - jonhoo:bootstrap-proper-env-flags, r=Mark-Simulacrum
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
Dylan DPC [Fri, 4 Mar 2022 01:06:38 +0000 (02:06 +0100)]
Rollup merge of #93418 - ojeda:no-shortcut, r=camelid
rustdoc & doc: no `shortcut` for `rel="icon"`
According to https://html.spec.whatwg.org/multipage/links.html#rel-icon:
> For historical reasons, the `icon` keyword may be preceded by the keyword "`shortcut`".
And to https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types:
> **Warning:** The `shortcut` link type is often seen before `icon`, but this link type is non-conforming, ignored and **web authors must not use it anymore.**
While it was removed from the Rust logo case a while ago in commit 085679c ("Use theme-adaptive SVG favicon from other Rust sites"), it is still there for the custom logo case.
bors [Fri, 4 Mar 2022 00:27:23 +0000 (00:27 +0000)]
Auto merge of #94009 - compiler-errors:gat-rustdoc, r=GuillaumeGomez
Support GATs in Rustdoc
Implements:
1. Rendering GATs in trait definitions and impl blocks
2. Rendering GATs in types (e.g. in the return type of a function)
Fixes #92341
This is my first rustdoc PR, so I have absolutely no idea how to produce tests for this. Advice from the rustdoc team would be wonderful!
I tested locally and things looked correct:
![image](https://user-images.githubusercontent.com/3674314/153988325-9732cbf3-0645-4e1a-9e64-ddfd93877b55.png)
bors [Thu, 3 Mar 2022 21:40:28 +0000 (21:40 +0000)]
Auto merge of #94571 - matthiaskrgr:rollup-4ul5ydb, r=matthiaskrgr
Rollup of 8 pull requests
Successful merges:
- #92697 (Use cgroup quotas for calculating `available_parallelism`)
- #94057 (improve comments for `simplify_type`)
- #94547 (`parse_tt` cleanups)
- #94550 (rustdoc: Add test for higher kinded functions generated by macros)
- #94551 (Doc: Fix use of quote instead of backstick in Adapter::map.)
- #94554 (Fix invalid lint_node_id being put on a removed stmt)
- #94555 (all: fix some typos)
- #94563 (Remove a unnecessary `..` pattern)
Dan Gohman [Thu, 3 Mar 2022 19:07:23 +0000 (11:07 -0800)]
Use `HandleOrNull` and `HandleOrInvalid` in the Windows FFI bindings.
Use the new `HandleOrNull` and `HandleOrInvalid` types that were introduced
as part of [I/O safety] in a few functions in the Windows FFI bindings.
This factors out an `unsafe` block and two `unsafe` function calls in the
Windows implementation code.
And, it helps test `HandleOrNull` and `HandleOrInvalid`, which indeed turned
up a bug: `OwnedHandle` also needs to be `#[repr(transparent)]`, as it's
used inside of `HandleOrNull` and `HandleOrInvalid` which are also
`#[repr(transparent)]`.
Matthias Krüger [Thu, 3 Mar 2022 19:01:48 +0000 (20:01 +0100)]
Rollup merge of #94554 - Urgau:stmt-node-id-ice, r=petrochenkov
Fix invalid lint_node_id being put on a removed stmt
This pull-request remove a invalid `assign_id!` being put on an stmt node.
The problem is that this node is being removed away by a cfg making it unreachable when triggering a buffered lint.
The comment in the other match arm already tell to not assign a id because it could have a `#[cfg()]` so this is just respecting the comment.
Matthias Krüger [Thu, 3 Mar 2022 19:01:47 +0000 (20:01 +0100)]
Rollup merge of #94551 - darnuria:doc-map-backstick, r=dtolnay
Doc: Fix use of quote instead of backstick in Adapter::map.
A little commit to fix documentation rendering and semantics in https://doc.rust-lang.org/std/iter/struct.Map.html#notes-about-side-effects `"` where used around an expression instead \`.
Screenshot on doc.rust-lang.org:
![2022-03-03 11-21-43_backstick](https://user-images.githubusercontent.com/2827553/156546536-569b7692-7ac4-4388-8e93-c1628ddc6a0f.png)
Looking forward: Maybe reworking the doc to use assert_eq like the upper paragraph:
```
let v: Vec<i32> = vec![1, 2, 3].into_iter().map(|x| x + 1).rev().collect();
Matthias Krüger [Thu, 3 Mar 2022 19:01:44 +0000 (20:01 +0100)]
Rollup merge of #94057 - lcnr:simplify_type-uwu, r=nikomatsakis
improve comments for `simplify_type`
Should now correctly describe what's going on. Experimented with checking the invariant for projections
but that ended up requiring fairly involved changes. I assume that it is not possible to get unsoundness here,
at least for now and I can pretty much guarantee that it's impossible to trigger it by accident.
Matthias Krüger [Thu, 3 Mar 2022 19:01:43 +0000 (20:01 +0100)]
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
bors [Thu, 3 Mar 2022 18:59:32 +0000 (18:59 +0000)]
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.`
Jon Gjengset [Tue, 1 Mar 2022 00:40:08 +0000 (16:40 -0800)]
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.
bors [Thu, 3 Mar 2022 12:56:24 +0000 (12:56 +0000)]
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.
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>>`!)
bors [Thu, 3 Mar 2022 10:14:04 +0000 (10:14 +0000)]
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)
Matthias Krüger [Thu, 3 Mar 2022 10:02:54 +0000 (11:02 +0100)]
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.
Matthias Krüger [Thu, 3 Mar 2022 10:02:49 +0000 (11:02 +0100)]
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`.
bors [Thu, 3 Mar 2022 04:28:08 +0000 (04:28 +0000)]
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)
Dan Gohman [Thu, 3 Mar 2022 00:25:31 +0000 (16:25 -0800)]
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.
Dylan DPC [Thu, 3 Mar 2022 00:09:14 +0000 (01:09 +0100)]
Rollup merge of #94505 - cuviper:mono-item-sort-local, r=michaelwoerister,davidtwco
Restore the local filter on mono item sorting
In `CodegenUnit::items_in_deterministic_order`, there's a comment that
only local HirIds should be taken into account, but #90408 removed the
`as_local` call that sets others to None. Restoring that check fixes the
s390x hangs seen in [RHBZ 2058803].