]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoAdd link to documentation about feature gates
Josh Triplett [Tue, 2 Nov 2021 14:30:28 +0000 (15:30 +0100)]
Add link to documentation about feature gates

2 years agoClarify what to do with accepted feature gates
Josh Triplett [Mon, 1 Nov 2021 14:34:19 +0000 (15:34 +0100)]
Clarify what to do with accepted feature gates

The documentation only referenced `removed.rs`, but feature gates for
accepted features move to `accepted.rs`.

2 years agoAuto merge of #89062 - mikeleany:new-target, r=cjgillot
bors [Sun, 31 Oct 2021 18:57:14 +0000 (18:57 +0000)]
Auto merge of #89062 - mikeleany:new-target, r=cjgillot

Add new tier 3 target: `x86_64-unknown-none`

Adds support for compiling OS kernels or other bare-metal applications for the x86-64 architecture.

Below are details on how this target meets the requirements for tier 3:

> A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

I would be willing to be a target maintainer, though I would appreciate if others volunteered to help with that as well.

> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.

Uses the same naming as the LLVM target, and the same convention as many other bare-metal targets.

> Target names should not introduce undue confusion or ambiguity unless absolutely necessary to maintain ecosystem compatibility. For example, if the name of the target makes people extremely likely to form incorrect beliefs about what it targets, the name should be changed or augmented to disambiguate it.

I don't believe there is any ambiguity here.

> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.

I don't see any legal issues here.

> The target must not introduce license incompatibilities.
> Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).
> The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.
>If the target supports building host tools (such as rustc or cargo), those host tools must not depend on proprietary (non-FOSS) libraries, other than ordinary runtime libraries supplied by the platform and commonly used by other binaries built for the target. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.
> Targets should not require proprietary (non-FOSS) components to link a functional binary or library.
> "onerous" here is an intentionally subjective term. At a minimum, "onerous" legal/licensing terms include but are not limited to: non-disclosure requirements, non-compete requirements, contributor license agreements (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms, requirements conditional on the employer or employment of any particular Rust developers, revocable terms, any requirements that create liability for the Rust project or its developers or users, or any requirements that adversely affect the livelihood or prospects of the Rust project or its developers or users.

I see no issues with any of the above.

> Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.
> This requirement does not prevent part or all of this policy from being cited in an explicit contract or work agreement (e.g. to implement or maintain support for a target). This requirement exists to ensure that a developer or team responsible for reviewing and approving a target does not face any legal threats or obligations that would prevent them from freely exercising their judgment in such approval, even if such judgment involves subjective matters or goes beyond the letter of these requirements.

Only relevant to those making approval decisions.

> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

`core` and `alloc` can be used. `std` cannot be used as this is a bare-metal target.

> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running tests (even if they do not pass), the documentation must explain how to run tests for the target, using emulation if possible or dedicated hardware if necessary.

Use `--target=x86_64-unknown-none-elf` option to cross compile, just like any target. The target does not support running tests.

> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via `@)` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.
> Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications.

I don't foresee this being a problem.

> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.
> In particular, this may come up when working on closely related targets, such as variations of the same architecture with different features. Avoid introducing unconditional uses of features that another variation of the target may not have; use conditional compilation or runtime detection, as appropriate, to let each target run code supported by that target.

No other targets should be affected by the pull request.

2 years agoAuto merge of #86336 - camsteffen:char-array-pattern, r=joshtriplett
bors [Sun, 31 Oct 2021 15:45:39 +0000 (15:45 +0000)]
Auto merge of #86336 - camsteffen:char-array-pattern, r=joshtriplett

impl Pattern for char array

Closes #39511
Closes #86329

2 years agoAuto merge of #90437 - matthiaskrgr:rollup-vd8uqm6, r=matthiaskrgr
bors [Sun, 31 Oct 2021 12:28:45 +0000 (12:28 +0000)]
Auto merge of #90437 - matthiaskrgr:rollup-vd8uqm6, r=matthiaskrgr

Rollup of 4 pull requests

Successful merges:

 - #89068 (Restructure std::rt (part 2))
 - #89786 (Add #[must_use] to len and is_empty)
 - #90430 (Add #[must_use] to remaining std functions (A-N))
 - #90431 (Add #[must_use] to remaining std functions (O-Z))

Failed merges:

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

2 years agoRollup merge of #90431 - jkugelman:must-use-std-o-through-z, r=joshtriplett
Matthias Krüger [Sun, 31 Oct 2021 12:20:07 +0000 (13:20 +0100)]
Rollup merge of #90431 - jkugelman:must-use-std-o-through-z, r=joshtriplett

Add #[must_use] to remaining std functions (O-Z)

I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is half of the remaining items from the `std` crate, from O-Z.

`panicking::take_hook` has a side effect: it unregisters the current panic hook, returning it. I almost ignored it, but the documentation example shows `let _ = panic::take_hook();`, so following suit I went ahead and added a `#[must_use]`.

```rust
std::panicking   fn take_hook() -> Box<dyn Fn(&PanicInfo<'_>) + 'static + Sync + Send>;
```

I added these functions that clippy did not flag:

```rust
std::path::Path   fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool;
std::path::Path   fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool;
std::path::Path   fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> PathBuf;
std::path::Path   fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf;
```

Parent issue: #89692

r? `@joshtriplett`

2 years agoRollup merge of #90430 - jkugelman:must-use-std-a-through-n, r=joshtriplett
Matthias Krüger [Sun, 31 Oct 2021 12:20:06 +0000 (13:20 +0100)]
Rollup merge of #90430 - jkugelman:must-use-std-a-through-n, r=joshtriplett

Add #[must_use] to remaining std functions (A-N)

I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is half of the remaining items from the `std` crate, from A-N.

I added these functions myself. Clippy predictably ignored the `mut` ones, but I don't know why the rest weren't flagged. Check them closely, please? Maybe I overlooked good reasons.

```rust
std::backtrace::Backtrace                                   const fn disabled() -> Backtrace;
std::backtrace::Backtrace<'a>                               fn frames(&'a self) -> &'a [BacktraceFrame];
std::collections::hash_map::RawOccupiedEntryMut<'a, K, V>   fn key_mut(&mut self) -> &mut K;
std::collections::hash_map::RawOccupiedEntryMut<'a, K, V>   fn get_mut(&mut self) -> &mut V;
std::collections::hash_map::RawOccupiedEntryMut<'a, K, V>   fn get_key_value(&mut self) -> (&K, &V);
std::collections::hash_map::RawOccupiedEntryMut<'a, K, V>   fn get_key_value_mut(&mut self) -> (&mut K, &mut V);
std::env                                                    fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString>;
std::env                                                    fn split_paths<T: AsRef<OsStr> + ?Sized>(unparsed: &T) -> SplitPaths<'_>;
std::io::Error                                              fn get_mut(&mut self) -> Option<&mut (dyn error::Error + Send + Sync + 'static)>;
```

Parent issue: #89692

r? `@joshtriplett`

2 years agoRollup merge of #89786 - jkugelman:must-use-len-and-is_empty, r=joshtriplett
Matthias Krüger [Sun, 31 Oct 2021 12:20:05 +0000 (13:20 +0100)]
Rollup merge of #89786 - jkugelman:must-use-len-and-is_empty, r=joshtriplett

Add #[must_use] to len and is_empty

Parent issue: #89692

r? `@joshtriplett`

2 years agoRollup merge of #89068 - bjorn3:restructure_rt2, r=joshtriplett
Matthias Krüger [Sun, 31 Oct 2021 12:20:04 +0000 (13:20 +0100)]
Rollup merge of #89068 - bjorn3:restructure_rt2, r=joshtriplett

Restructure std::rt (part 2)

A couple more cleanups on top of https://github.com/rust-lang/rust/pull/89011

Blocked on #89011

2 years agoAuto merge of #90434 - matthiaskrgr:rollup-xbn393a, r=matthiaskrgr
bors [Sun, 31 Oct 2021 09:07:09 +0000 (09:07 +0000)]
Auto merge of #90434 - matthiaskrgr:rollup-xbn393a, r=matthiaskrgr

Rollup of 8 pull requests

Successful merges:

 - #89446 (Add paragraph to ControlFlow docs to menion it works with the ? operator (#88715))
 - #89677 (Stabilize `is_symlink()` for `Metadata` and `Path`)
 - #89833 (Add #[must_use] to Rc::downgrade)
 - #89835 (Add #[must_use] to expensive computations)
 - #89839 (Add #[must_use] to mem/ptr functions)
 - #89897 (Add #[must_use] to remaining core functions)
 - #89951 (Stabilize `option_result_unwrap_unchecked`)
 - #90427 (Add #[must_use] to alloc functions that would leak memory)

Failed merges:

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

2 years agoRollup merge of #90427 - jkugelman:must-use-alloc-leak, r=joshtriplett
Matthias Krüger [Sun, 31 Oct 2021 08:20:27 +0000 (09:20 +0100)]
Rollup merge of #90427 - jkugelman:must-use-alloc-leak, r=joshtriplett

Add #[must_use] to alloc functions that would leak memory

As [requested](https://github.com/rust-lang/rust/pull/89899#issuecomment-955600779) by `@joshtriplett.`

> Please do go ahead and add the ones whose only legitimate use for ignoring the return value is leaking memory. (In a separate PR please.) I think it's sufficiently error-prone to call something like alloc and ignore the result that it's legitimate to require `let _ =` for that.

I added `realloc` myself. Clippy ignored it because of its `mut` argument.

```rust
alloc/src/alloc.rs:123:1   alloc   unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8;
```

Parent issue: #89692

r? `@joshtriplett`

2 years agoRollup merge of #89951 - ojeda:stable-unwrap_unchecked, r=dtolnay
Matthias Krüger [Sun, 31 Oct 2021 08:20:27 +0000 (09:20 +0100)]
Rollup merge of #89951 - ojeda:stable-unwrap_unchecked, r=dtolnay

Stabilize `option_result_unwrap_unchecked`

Closes https://github.com/rust-lang/rust/issues/81383.

Stabilization report: https://github.com/rust-lang/rust/issues/81383#issuecomment-944498212.

```@rustbot``` label +A-option-result +T-libs-api

2 years agoRollup merge of #89897 - jkugelman:must-use-core, r=joshtriplett
Matthias Krüger [Sun, 31 Oct 2021 08:20:26 +0000 (09:20 +0100)]
Rollup merge of #89897 - jkugelman:must-use-core, r=joshtriplett

Add #[must_use] to remaining core functions

I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is everything remaining from the `core` crate.

Ignored by clippy for reasons unknown:

```rust
core::alloc::Layout   unsafe fn for_value_raw<T: ?Sized>(t: *const T) -> Self;
core::any             const fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str;
```

Ignored by clippy because of `mut`:

```rust
str   fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str);
```

<del>
Ignored by clippy presumably because a caller might want `f` called for side effects. That seems like a bad usage of `map` to me.

```rust
core::cell::Ref<'b, T>   fn map<U: ?Sized, F>(orig: Ref<'b, T>, f: F) -> Ref<'b, T>;
core::cell::Ref<'b, T>   fn map_split<U: ?Sized, V: ?Sized, F>(orig: Ref<'b, T>, f: F) -> (Ref<'b, U>, Ref<'b, V>);
```
</del>

Parent issue: #89692

r? ```@joshtriplett```

2 years agoRollup merge of #89839 - jkugelman:must-use-mem-ptr-functions, r=joshtriplett
Matthias Krüger [Sun, 31 Oct 2021 08:20:25 +0000 (09:20 +0100)]
Rollup merge of #89839 - jkugelman:must-use-mem-ptr-functions, r=joshtriplett

Add #[must_use] to mem/ptr functions

There's a lot of low-level / unsafe stuff here. Are there legit use cases for ignoring any of these return values?

* No regressions in `./x.py test --stage 1 library/std src/tools/clippy`.
* One regression in `./x.py test --stage 1 src/test/ui`. Fixed.
* I am unable to run `./x.py doc` on my machine so I'll need to wait for the CI to verify doctests pass. I eyeballed all the adjacent tests and they all look okay.

Parent issue: #89692

r? ```@joshtriplett```

2 years agoRollup merge of #89835 - jkugelman:must-use-expensive-computations, r=joshtriplett
Matthias Krüger [Sun, 31 Oct 2021 08:20:24 +0000 (09:20 +0100)]
Rollup merge of #89835 - jkugelman:must-use-expensive-computations, r=joshtriplett

Add #[must_use] to expensive computations

The unifying theme for this commit is weak, admittedly. I put together a list of "expensive" functions when I originally proposed this whole effort, but nobody's cared about that criterion. Still, it's a decent way to bite off a not-too-big chunk of work.

Given the grab bag nature of this commit, the messages I used vary quite a bit. I'm open to wording changes.

For some reason clippy flagged four `BTreeSet` methods but didn't say boo about equivalent ones on `HashSet`. I stared at them for a while but I can't figure out the difference so I added the `HashSet` ones in.

```rust
// Flagged by clippy.
alloc::collections::btree_set::BTreeSet<T>   fn difference<'a>(&'a self, other: &'a BTreeSet<T>) -> Difference<'a, T>;
alloc::collections::btree_set::BTreeSet<T>   fn symmetric_difference<'a>(&'a self, other: &'a BTreeSet<T>) -> SymmetricDifference<'a, T>
alloc::collections::btree_set::BTreeSet<T>   fn intersection<'a>(&'a self, other: &'a BTreeSet<T>) -> Intersection<'a, T>;
alloc::collections::btree_set::BTreeSet<T>   fn union<'a>(&'a self, other: &'a BTreeSet<T>) -> Union<'a, T>;

// Ignored by clippy, but not by me.
std::collections::HashSet<T, S>              fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S>;
std::collections::HashSet<T, S>              fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T, S>) -> SymmetricDifference<'a, T, S>
std::collections::HashSet<T, S>              fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a, T, S>;
std::collections::HashSet<T, S>              fn union<'a>(&'a self, other: &'a HashSet<T, S>) -> Union<'a, T, S>;
```

Parent issue: #89692

r? ```@joshtriplett```

2 years agoRollup merge of #89833 - jkugelman:must-use-rc-downgrade, r=joshtriplett
Matthias Krüger [Sun, 31 Oct 2021 08:20:23 +0000 (09:20 +0100)]
Rollup merge of #89833 - jkugelman:must-use-rc-downgrade, r=joshtriplett

Add #[must_use] to Rc::downgrade

Missed this in previous PR https://github.com/rust-lang/rust/pull/89796#issuecomment-941456006

Parent issue: #89692

r? ```@joshtriplett```

2 years agoRollup merge of #89677 - maxwase:is-symlink-stabilization, r=joshtriplett
Matthias Krüger [Sun, 31 Oct 2021 08:20:22 +0000 (09:20 +0100)]
Rollup merge of #89677 - maxwase:is-symlink-stabilization, r=joshtriplett

Stabilize `is_symlink()` for `Metadata` and `Path`

I'm not fully sure about `since` version, correct me if I'm wrong

Needs update after stabilization: [cargo-test-support](https://github.com/rust-lang/cargo/blob/8063672238a5b6c3a901c0fc17f3164692d0be85/crates/cargo-test-support/src/paths.rs#L202)

Linked issue: #85748

2 years agoRollup merge of #89446 - chrismit3s:issue-88715-fix, r=joshtriplett
Matthias Krüger [Sun, 31 Oct 2021 08:20:21 +0000 (09:20 +0100)]
Rollup merge of #89446 - chrismit3s:issue-88715-fix, r=joshtriplett

Add paragraph to ControlFlow docs to menion it works with the ? operator (#88715)

fixes #88715

r? ```@steveklabnik```

2 years agoAuto merge of #90391 - camelid:crate-size, r=jyn514
bors [Sun, 31 Oct 2021 05:52:42 +0000 (05:52 +0000)]
Auto merge of #90391 - camelid:crate-size, r=jyn514

rustdoc: Compute some fields of `clean::Crate` on-demand to reduce size

`clean::Crate` is frequently moved by-value -- for example, in `DocFolder`
implementations -- so reducing its size should improve performance.

This PR reduces the size of `clean::Crate` from 168 bytes to 104 bytes.

r? `@jyn514`

2 years agoAdd #[must_use] to remaining std functions (A-N)
John Kugelman [Sun, 31 Oct 2021 02:58:27 +0000 (22:58 -0400)]
Add #[must_use] to remaining std functions (A-N)

2 years agoAdd #[must_use] to remaining std functions (O-Z)
John Kugelman [Sun, 31 Oct 2021 03:37:32 +0000 (23:37 -0400)]
Add #[must_use] to remaining std functions (O-Z)

2 years agoAdd #[must_use] to alloc functions that would leak memory
John Kugelman [Sun, 31 Oct 2021 02:06:31 +0000 (22:06 -0400)]
Add #[must_use] to alloc functions that would leak memory

2 years agoAuto merge of #90306 - kornelski:slicecloneasset, r=joshtriplett
bors [Sun, 31 Oct 2021 01:56:40 +0000 (01:56 +0000)]
Auto merge of #90306 - kornelski:slicecloneasset, r=joshtriplett

track_caller for slice length assertions

`clone_from_slice` was missing `#[track_caller]`, and its assert did not report a useful location.

These are small generic methods, so hopefully track_caller gets inlined into nothingness, but it may be worth running a benchmark on this.

2 years agoAdd #[must_use] to len and is_empty
John Kugelman [Mon, 11 Oct 2021 20:15:50 +0000 (16:15 -0400)]
Add #[must_use] to len and is_empty

2 years agoAdd #[must_use] to mem/ptr functions
John Kugelman [Wed, 13 Oct 2021 02:28:14 +0000 (22:28 -0400)]
Add #[must_use] to mem/ptr functions

2 years agoAuto merge of #90424 - matthiaskrgr:rollup-jezzu4f, r=matthiaskrgr
bors [Sat, 30 Oct 2021 22:39:24 +0000 (22:39 +0000)]
Auto merge of #90424 - matthiaskrgr:rollup-jezzu4f, r=matthiaskrgr

Rollup of 4 pull requests

Successful merges:

 - #89789 (Add #[must_use] to thread::Builder)
 - #89899 (Add #[must_use] to remaining alloc functions)
 - #90401 (hermit: Implement Condvar::wait_timeout)
 - #90404 (hermitkernel-target: Set OS to "none")

Failed merges:

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

2 years agoRollup merge of #90404 - mkroening:hermit-kernel-no-os, r=joshtriplett
Matthias Krüger [Sat, 30 Oct 2021 22:33:26 +0000 (00:33 +0200)]
Rollup merge of #90404 - mkroening:hermit-kernel-no-os, r=joshtriplett

hermitkernel-target: Set OS to "none"

For our kernel targets, we should not set OS, as the kernel runs bare
metal without a circular dependency on std.

This also prepares us for unifying with
https://github.com/rust-lang/rust/pull/89062. This patch requires
libhermit-rs to change a `cfg`s from `target_os = "hermit"` to `target_os
= "none"`.

I tested this patch locally.

CC: `@stlankes`
2 years agoRollup merge of #90401 - mkroening:hermit-condvar, r=joshtriplett
Matthias Krüger [Sat, 30 Oct 2021 22:33:25 +0000 (00:33 +0200)]
Rollup merge of #90401 - mkroening:hermit-condvar, r=joshtriplett

hermit: Implement Condvar::wait_timeout

This implements `Condvar::wait_timeout` for the `hermit` target.

See
* https://github.com/hermitcore/rust/pull/2
* https://github.com/hermitcore/rust/pull/5

CC: `@stlankes`
2 years agoRollup merge of #89899 - jkugelman:must-use-alloc, r=joshtriplett
Matthias Krüger [Sat, 30 Oct 2021 22:33:24 +0000 (00:33 +0200)]
Rollup merge of #89899 - jkugelman:must-use-alloc, r=joshtriplett

Add #[must_use] to remaining alloc functions

I've run out of compelling reasons to group functions together across crates so I'm just going to go module-by-module. This is everything remaining from the `alloc` crate.

I ignored these because they might be used to purposefully leak memory... or other allocator shenanigans? I dunno. I'll add them if y'all tell me to.

```rust
alloc::alloc          unsafe fn alloc(layout: Layout) -> *mut u8;
alloc::alloc          unsafe fn alloc_zeroed(layout: Layout) -> *mut u8;
alloc::sync::Arc<T>   fn into_raw(this: Self) -> *const T;
```

I don't know why clippy ignored these. I added them myself:

```rust
alloc::collections::btree_map::BTreeMap<K, V>   fn range<T: ?Sized, R>(&self, range: R) -> Range<'_, K, V>;
alloc::collections::btree_set::BTreeSet<T>      fn range<K: ?Sized, R>(&self, range: R) -> Range<'_, T>;
```

I added these non-mutating `mut` functions:

```rust
alloc::collections::btree_map::BTreeMap<K, V>     fn range_mut<T: ?Sized, R>(&mut self, range: R) -> RangeMut<'_, K, V>;
alloc::collections::btree_map::BTreeMap<K, V>     fn iter_mut(&mut self) -> IterMut<'_, K, V>;
alloc::collections::btree_map::BTreeMap<K, V>     fn values_mut(&mut self) -> ValuesMut<'_, K, V>;
alloc::collections::linked_list::LinkedList<T>    fn iter_mut(&mut self) -> IterMut<'_, T>;
alloc::collections::linked_list::LinkedList<T>    fn cursor_front_mut(&mut self) -> CursorMut<'_, T>;
alloc::collections::linked_list::LinkedList<T>    fn cursor_back_mut(&mut self) -> CursorMut<'_, T>;
alloc::collections::linked_list::LinkedList<T>    fn front_mut(&mut self) -> Option<&mut T>;
alloc::collections::linked_list::LinkedList<T>    fn back_mut(&mut self) -> Option<&mut T>;
alloc::collections::linked_list::CursorMut<'a, T> fn current(&mut self) -> Option<&mut T>;
alloc::collections::linked_list::CursorMut<'a, T> fn peek_next(&mut self) -> Option<&mut T>;
alloc::collections::linked_list::CursorMut<'a, T> fn peek_prev(&mut self) -> Option<&mut T>;
alloc::collections::linked_list::CursorMut<'a, T> fn front_mut(&mut self) -> Option<&mut T>;
alloc::collections::linked_list::CursorMut<'a, T> fn back_mut(&mut self) -> Option<&mut T>;
```

I moved a few existing `#[must_use]`s from functions onto the iterator types they return: `IntoIterSorted`, `IntoKeys`, `IntoValues`.

Parent issue: #89692

r? `@joshtriplett`

2 years agoRollup merge of #89789 - jkugelman:must-use-thread-builder, r=joshtriplett
Matthias Krüger [Sat, 30 Oct 2021 22:33:23 +0000 (00:33 +0200)]
Rollup merge of #89789 - jkugelman:must-use-thread-builder, r=joshtriplett

Add #[must_use] to thread::Builder

I copied the wording of the [`fmt::Debug` builders](https://doc.rust-lang.org/src/core/fmt/builders.rs.html#444).

Affects:

```rust
std/src/thread/mod.rs:289:5   std::thread::Builder   fn new() -> Builder;
std/src/thread/mod.rs:318:5   std::thread::Builder   fn name(mut self, name: String) -> Builder;
std/src/thread/mod.rs:341:5   std::thread::Builder   fn stack_size(mut self, size: usize) -> Builder;
```

Parent issue: #89692

r? `@joshtriplett`

2 years agoAdd #[must_use] to remaining core functions
John Kugelman [Thu, 14 Oct 2021 22:54:55 +0000 (18:54 -0400)]
Add #[must_use] to remaining core functions

2 years agoAuto merge of #90422 - GuillaumeGomez:rollup-s1mdag0, r=GuillaumeGomez
bors [Sat, 30 Oct 2021 19:31:47 +0000 (19:31 +0000)]
Auto merge of #90422 - GuillaumeGomez:rollup-s1mdag0, r=GuillaumeGomez

Rollup of 5 pull requests

Successful merges:

 - #90156 (Remove underlines from non-top docblocks.)
 - #90183 (Show all Deref implementations recursively)
 - #90202 (Improve and test cross-crate hygiene)
 - #90375 (Use `is_global` in `candidate_should_be_dropped_in_favor_of`)
 - #90399 (Skipping verbose diagnostic suggestions when calling .as_ref() on type not implementing AsRef)

Failed merges:

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

2 years agoRollup merge of #90399 - yuvaldolev:as-ref-overly-verbose-diagnostic, r=estebank
Guillaume Gomez [Sat, 30 Oct 2021 18:30:28 +0000 (20:30 +0200)]
Rollup merge of #90399 - yuvaldolev:as-ref-overly-verbose-diagnostic, r=estebank

Skipping verbose diagnostic suggestions when calling .as_ref() on type not implementing AsRef

Addresses #89806

Skipping suggestions when calling `.as_ref()` for types that do not implement the `AsRef` trait.

r? `@estebank`

2 years agoRollup merge of #90375 - yanok:master, r=lcnr
Guillaume Gomez [Sat, 30 Oct 2021 18:30:27 +0000 (20:30 +0200)]
Rollup merge of #90375 - yanok:master, r=lcnr

Use `is_global` in `candidate_should_be_dropped_in_favor_of`

This manifistated in #90195 with compiler being unable to keep
one candidate for a trait impl, if where is a global impl and more
than one trait bound in the where clause.

Before #87280 `candidate_should_be_dropped_in_favor_of` was using
`TypeFoldable::is_global()` that was enough to discard the two
`ParamCandidate`s. But #87280 changed it to use
`TypeFoldable::is_known_global()` instead, which is pessimistic, so
now the compiler drops the global impl instead (because
`is_known_global` is not sure) and then can't decide between the
two `ParamCandidate`s.

Switching it to use `is_global` again solves the issue.

Fixes #90195.

2 years agoRollup merge of #90202 - matthewjasper:xcrate-hygiene, r=petrochenkov
Guillaume Gomez [Sat, 30 Oct 2021 18:30:27 +0000 (20:30 +0200)]
Rollup merge of #90202 - matthewjasper:xcrate-hygiene, r=petrochenkov

Improve and test cross-crate hygiene

- Decode the parent expansion for traits and enums in `rustc_resolve`, this was already being used for resolution in typeck
- Avoid suggesting importing names with def-site hygiene, since it's often not useful
- Add more tests

r? `@petrochenkov`

2 years agoRollup merge of #90183 - GuillaumeGomez:recurse-deref, r=jyn514
Guillaume Gomez [Sat, 30 Oct 2021 18:30:26 +0000 (20:30 +0200)]
Rollup merge of #90183 - GuillaumeGomez:recurse-deref, r=jyn514

Show all Deref implementations recursively

Fixes #87783.

This is a re-implementation of #80653, so taking the original PR comment:

This changes `rustdoc` to recursively follow `Deref` targets so that methods from all levels are added to the rendered output. This implementation displays the methods from all levels in the expanded state with separate sections for each level.

![image](https://user-images.githubusercontent.com/279572/103482863-46723b00-4ddb-11eb-972b-c463351a425c.png)

cc `@camelid`
r? `@jyn514`

2 years agoRollup merge of #90156 - jsha:less-border-bottom-2, r=GuillaumeGomez
Guillaume Gomez [Sat, 30 Oct 2021 18:30:25 +0000 (20:30 +0200)]
Rollup merge of #90156 - jsha:less-border-bottom-2, r=GuillaumeGomez

Remove underlines from non-top docblocks.

We still had a number of places where underlined section headings would
show up, like under Implementations.

Follow-up to #89506 (thanks `@yaymukund!)` and #90036. Related to #59829.

r? `@camelid`

Demo:

[Before](https://doc.rust-lang.org/nightly/std/string/struct.String.html#trait-implementations):

[![image](https://user-images.githubusercontent.com/220205/138402555-b0c0a3ea-ff50-4aad-bb74-6f9e57323807.png)](https://jacob.hoffman-andrews.com/rust/less-border-bottom-2/std/string/struct.String.html#trait-implementations)

[After](https://jacob.hoffman-andrews.com/rust/less-border-bottom-2/std/string/struct.String.html#trait-implementations):

[![image](https://user-images.githubusercontent.com/220205/138402669-d0835bd9-8813-4f0c-8697-f86e9759acec.png)](https://jacob.hoffman-andrews.com/rust/less-border-bottom-2/std/string/struct.String.html#trait-implementations)

2 years agorustdoc: Stop sorting external crates
Noah Lev [Sat, 30 Oct 2021 03:57:12 +0000 (20:57 -0700)]
rustdoc: Stop sorting external crates

Now that #73423 is fixed, sorting should no longer be necessary.
See also this discussion [1].

[1]: https://github.com/rust-lang/rust/pull/86889#discussion_r664134963

2 years agorustdoc: Remove `Crate.name` and instead compute it on-demand
Noah Lev [Fri, 29 Oct 2021 03:55:02 +0000 (20:55 -0700)]
rustdoc: Remove `Crate.name` and instead compute it on-demand

It is not as large as `Crate.src` was, but it's still 8 bytes, and
`clean::Crate` is moved by-value a lot.

2 years agorustdoc: Remove `Crate.src` and instead compute it on-demand
Noah Lev [Fri, 29 Oct 2021 03:48:48 +0000 (20:48 -0700)]
rustdoc: Remove `Crate.src` and instead compute it on-demand

It is only used in one place; `src` was about a third of `Crate`'s total
size; `Crate` is frequently moved by-value; and `src` can be easily
computed on-demand.

2 years agorustdoc: Document that `Crate` is always local
Noah Lev [Sat, 30 Oct 2021 02:59:49 +0000 (19:59 -0700)]
rustdoc: Document that `Crate` is always local

2 years agoAuto merge of #90205 - mati865:link-modifiers-in-rustc, r=petrochenkov
bors [Sat, 30 Oct 2021 16:22:49 +0000 (16:22 +0000)]
Auto merge of #90205 - mati865:link-modifiers-in-rustc, r=petrochenkov

Repace use of `static_nobundle` with `native_link_modifiers` within Rust codebase

This fixes warnings when building Rust and running tests:
```
warning: library kind `static-nobundle` has been superseded by specifying `-bundle` on library kind `static`. Try `static:-bundle`
warning: `rustc_llvm` (lib) generated 2 warnings (1 duplicate)
```

2 years agoRemove underlines from non-top docblocks.
Jacob Hoffman-Andrews [Fri, 22 Oct 2021 06:09:11 +0000 (23:09 -0700)]
Remove underlines from non-top docblocks.

We still had a number of places where underlined section headings would
show up, like under Implementations.

2 years agoDocument tests a bit more
Guillaume Gomez [Sat, 30 Oct 2021 14:30:14 +0000 (16:30 +0200)]
Document tests a bit more

2 years agoAuto merge of #90416 - matthiaskrgr:rollup-55lzqng, r=matthiaskrgr
bors [Sat, 30 Oct 2021 13:06:51 +0000 (13:06 +0000)]
Auto merge of #90416 - matthiaskrgr:rollup-55lzqng, r=matthiaskrgr

Rollup of 8 pull requests

Successful merges:

 - #89876 (Make most std::ops traits const on numeric types)
 - #90371 (Fix incorrect doc link)
 - #90374 (Unify titles in rustdoc book doc attributes chapter)
 - #90377 (Make `core::slice::from_raw_parts[_mut]` const)
 - #90395 (Restrict liveness of mutable borrow of inner infcx in ConstInferUnifier::consts)
 - #90396 (Prevent type flags assertions being thrown in default_anon_const_substs if errors occurred)
 - #90402 (Add a few query descriptions)
 - #90412 (Remove unnecessary `macro_use`s in rustdoc)

Failed merges:

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

2 years agoRollup merge of #90412 - jyn514:macro-use, r=camelid
Matthias Krüger [Sat, 30 Oct 2021 12:37:04 +0000 (14:37 +0200)]
Rollup merge of #90412 - jyn514:macro-use, r=camelid

Remove unnecessary `macro_use`s in rustdoc

2 years agoRollup merge of #90402 - wesleywiser:query_descriptions, r=oli-obk
Matthias Krüger [Sat, 30 Oct 2021 12:37:04 +0000 (14:37 +0200)]
Rollup merge of #90402 - wesleywiser:query_descriptions, r=oli-obk

Add a few query descriptions

2 years agoRollup merge of #90396 - b-naber:type_flags_ices_default_anon_consts, r=lcnr
Matthias Krüger [Sat, 30 Oct 2021 12:37:03 +0000 (14:37 +0200)]
Rollup merge of #90396 - b-naber:type_flags_ices_default_anon_consts, r=lcnr

Prevent type flags assertions being thrown in default_anon_const_substs if errors occurred

Fixes https://github.com/rust-lang/rust/issues/90364
Fixes https://github.com/rust-lang/rust/issues/88997

r? ``@lcnr``

2 years agoRollup merge of #90395 - b-naber:const-expr-type-relation, r=oli-obk
Matthias Krüger [Sat, 30 Oct 2021 12:37:02 +0000 (14:37 +0200)]
Rollup merge of #90395 - b-naber:const-expr-type-relation, r=oli-obk

Restrict liveness of mutable borrow of inner infcx in ConstInferUnifier::consts

Fixes https://github.com/rust-lang/rust/issues/89304

r? ``@oli-obk``

2 years agoRollup merge of #90377 - WaffleLapkin:const_slice_from_raw_parts, r=oli-obk
Matthias Krüger [Sat, 30 Oct 2021 12:37:01 +0000 (14:37 +0200)]
Rollup merge of #90377 - WaffleLapkin:const_slice_from_raw_parts, r=oli-obk

Make `core::slice::from_raw_parts[_mut]` const

Responses to #90012 seem to allow ``@rust-lang/wg-const-eval`` to decide on use of `const_eval_select`, so we can make `core::slice::from_raw_parts[_mut]` const :)

---
This PR marks the following APIs as const:
```rust
// core::slice
pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T];
pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T];
```
---

Resolves #90011
r? ``@oli-obk``

2 years agoRollup merge of #90374 - GuillaumeGomez:unify-rustdoc-book-titles, r=camelid
Matthias Krüger [Sat, 30 Oct 2021 12:37:00 +0000 (14:37 +0200)]
Rollup merge of #90374 - GuillaumeGomez:unify-rustdoc-book-titles, r=camelid

Unify titles in rustdoc book doc attributes chapter

As discussed in https://github.com/rust-lang/rust/pull/90339.

I wasn't able to find out where the link to the titles was used so let's see if the CI fails. :)

r? ``@camelid``

2 years agoRollup merge of #90371 - Veykril:patch-2, r=jyn514
Matthias Krüger [Sat, 30 Oct 2021 12:36:59 +0000 (14:36 +0200)]
Rollup merge of #90371 - Veykril:patch-2, r=jyn514

Fix incorrect doc link

Looks like a copy paste mistake

2 years agoRollup merge of #89876 - AlexApps99:const_ops, r=oli-obk
Matthias Krüger [Sat, 30 Oct 2021 12:36:58 +0000 (14:36 +0200)]
Rollup merge of #89876 - AlexApps99:const_ops, r=oli-obk

Make most std::ops traits const on numeric types

This PR makes existing implementations of `std::ops` traits (`Add`, `Sub`, etc) [`impl const`](https://github.com/rust-lang/rust/issues/67792) where possible.
This affects:
- All numeric primitives (`u*`, `i*`, `f*`)
- `NonZero*`
- `Wrapping`

This is under the `rustc_const_unstable` feature `const_ops`.
I will write tests once I know what can and can't be kept for the final version of this PR.

Since this is my first PR to rustc (and hopefully one of many), please give me feedback on how to better handle the PR process wherever possible. Thanks

[Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Const.20std.3A.3Aops.20traits.20PR)

2 years agoAuto merge of #89174 - ChrisDenton:automatic-verbatim-paths, r=dtolnay
bors [Sat, 30 Oct 2021 07:21:21 +0000 (07:21 +0000)]
Auto merge of #89174 - ChrisDenton:automatic-verbatim-paths, r=dtolnay

Automatically convert paths to verbatim for filesystem operations that support it

This allows using longer paths without the user needing to `canonicalize` or manually prefix paths. If the path is already verbatim then this has no effect.

Fixes: #32689
2 years agoAuto merge of #88268 - GuillaumeGomez:generics-search-index, r=notriddle,camelid...
bors [Sat, 30 Oct 2021 04:12:40 +0000 (04:12 +0000)]
Auto merge of #88268 - GuillaumeGomez:generics-search-index, r=notriddle,camelid,jyn514

rustdoc: Fix generics generation in search index

The generics were not added to the search index as they should, instead they were added as arguments. I used this opportunity to allow generics to have generics themselves (will come in very handy for my current rewrite of the search engine!).

r? `@jyn514`

2 years agorustdoc: Add static size assertion for `clean::Crate`
Noah Lev [Fri, 29 Oct 2021 03:58:53 +0000 (20:58 -0700)]
rustdoc: Add static size assertion for `clean::Crate`

2 years agoRemove unnecessary `macro_use`s in rustdoc
Joshua Nelson [Sat, 30 Oct 2021 02:07:37 +0000 (02:07 +0000)]
Remove unnecessary `macro_use`s in rustdoc

2 years agoAuto merge of #90403 - michaelwoerister:odht-0.3.1, r=Mark-Simulacrum
bors [Sat, 30 Oct 2021 01:01:19 +0000 (01:01 +0000)]
Auto merge of #90403 - michaelwoerister:odht-0.3.1, r=Mark-Simulacrum

Update odht crate to 0.3.1 (big-endian bugfix)

Update `odht` to 0.3.1 in order to get https://github.com/rust-lang/odht/pull/20 which fixes issue https://github.com/rust-lang/rust/issues/90123.

2 years agoAuto merge of #90346 - ferrocene:pa-short-circuit, r=oli-obk
bors [Fri, 29 Oct 2021 21:50:46 +0000 (21:50 +0000)]
Auto merge of #90346 - ferrocene:pa-short-circuit, r=oli-obk

Replace some operators in libcore with their short-circuiting equivalents

In libcore there are a few occurrences of bitwise operators used in boolean expressions instead of their short-circuiting equivalents. This makes it harder to perform some kinds of source code analysis over libcore, for example [MC/DC] code coverage (a requirement in safety-critical environments).

This PR aims to remove as many bitwise operators in boolean expressions from libcore as possible, without any performance regression and without other changes. This means not all bitwise operators are removed, only the ones that don't have any difference with their short-circuiting counterparts. This already simplifies achieving MC/DC coverage, and the other functions can be changed in future PRs.

The PR is best reviewed commit-by-commit, and each commit has the resulting assembly in the message.

## Checked integer methods

These methods recently switched to bitwise operators in PRs https://github.com/rust-lang/rust/pull/89459 and https://github.com/rust-lang/rust/pull/89351. I confirmed bitwise operators are needed in most of the functions, except these two:

* `{integer}::checked_div` ([Godbolt link (nightly)](https://rust.godbolt.org/z/17efh5jPc))
* `{integer}::checked_rem` ([Godbolt link (nightly)](https://rust.godbolt.org/z/85qGWc94K))

`@tspiteri` already mentioned this was the case in https://github.com/rust-lang/rust/pull/89459#issuecomment-932728384, but opted to also switch those two to bitwise operators for consistency. As that makes MC/DC analysis harder this PR proposes switching those two back to short-circuiting operators.

## `{unsigned_ints}::carrying_add`

[Godbolt link (1.56.0)](https://rust.godbolt.org/z/vG9vx8x48)

In this instance replacing the `|` with `||` produces the exact same assembly when optimizations are enabled, so switching to the short-circuiting operator shouldn't have any impact.

## `{unsigned_ints}::borrowing_sub`

[Godbolt link (1.56.0)](https://rust.godbolt.org/z/asEfKaGE4)

In this instance replacing the `|` with `||` produces the exact same assembly when optimizations are enabled, so switching to the short-circuiting operator shouldn't have any impact.

## String UTF-8 validation

[Godbolt link (1.56.0)](https://rust.godbolt.org/z/a4rEbTvvx)

In this instance replacing the `|` with `||` produces practically the same assembly, with the two operands for the "or" swapped:

```asm
; Old
mov  rax, qword ptr [rdi + rdx + 8]
or   rax, qword ptr [rdi + rdx]
test rax, r9
je   .LBB0_7

; New
mov  rax, qword ptr [rdi + rdx]
or   rax, qword ptr [rdi + rdx + 8]
test rax, r8
je   .LBB0_7
```

[MC/DC]: https://en.wikipedia.org/wiki/Modified_condition/decision_coverage

2 years agoApply changes proposed in the review
Maybe Waffle [Fri, 29 Oct 2021 20:45:09 +0000 (23:45 +0300)]
Apply changes proposed in the review

2 years agoUse proper issue number for `feature(const_slice_from_raw_parts)`
Maybe Waffle [Fri, 29 Oct 2021 19:45:10 +0000 (22:45 +0300)]
Use proper issue number for `feature(const_slice_from_raw_parts)`

2 years agoUnify titles in rustdoc book doc attributes chapter
Guillaume Gomez [Thu, 28 Oct 2021 12:44:47 +0000 (14:44 +0200)]
Unify titles in rustdoc book doc attributes chapter

2 years agoFix invalid handling of generics
Guillaume Gomez [Mon, 23 Aug 2021 20:19:43 +0000 (22:19 +0200)]
Fix invalid handling of generics

2 years agoAuto merge of #90390 - umanwizard:update-miri, r=RalfJung
bors [Fri, 29 Oct 2021 18:41:17 +0000 (18:41 +0000)]
Auto merge of #90390 - umanwizard:update-miri, r=RalfJung

Update miri

Fixes https://github.com/rust-lang/rust/issues/90298

2 years agohermitkernel-target: Set OS to "none"
Martin Kröning [Fri, 29 Oct 2021 16:06:43 +0000 (18:06 +0200)]
hermitkernel-target: Set OS to "none"

For our kernel targets, we should not set OS, as the kernel runs bare
metal without a circular dependency on std.

This also prepares us for unifying with
https://github.com/rust-lang/rust/pull/89062. This patch requires
libhermit-rs to change a `cfg`s from `target_os = "hermit"` to `target_os
= "none"`.

I tested this patch locally.

2 years agoUpdate odht crate to 0.3.1 (big-endian bugfix)
Michael Woerister [Fri, 29 Oct 2021 16:05:15 +0000 (18:05 +0200)]
Update odht crate to 0.3.1 (big-endian bugfix)

2 years agoAuto merge of #90389 - camelid:rustdoc-rayon, r=jyn514
bors [Fri, 29 Oct 2021 15:31:37 +0000 (15:31 +0000)]
Auto merge of #90389 - camelid:rustdoc-rayon, r=jyn514

rustdoc: Switch to mainline rayon

The rustc fork of rayon integrates with Cargo's jobserver to limit the
amount of parallelism. However, rustdoc's use case is concurrent I/O,
which is not CPU-heavy, so it should be able to use mainline rayon.

See [this discussion][1] for more details.

[1]: https://github.com/rust-lang/rust/issues/90227#issuecomment-952468618

Note: I chose rayon 1.3.1 so that the rayon version used elsewhere in
the workspace does not change.

r? `@Mark-Simulacrum`
cc `@jyn514`

2 years agohermit: Implement Condvar::wait_timeout
Martin Kröning [Sat, 29 May 2021 20:16:10 +0000 (22:16 +0200)]
hermit: Implement Condvar::wait_timeout

2 years agoAdd a few query descriptions
Wesley Wiser [Fri, 29 Oct 2021 15:15:45 +0000 (11:15 -0400)]
Add a few query descriptions

2 years agoExplicitly skipping suggestions for 'Pin' as it does not implement the 'AsRef' trait
Yuval Dolev [Fri, 29 Oct 2021 12:43:33 +0000 (15:43 +0300)]
Explicitly skipping suggestions for 'Pin' as it does not implement the 'AsRef' trait

2 years agoSkip suggestions for the AsRef trait
Yuval Dolev [Wed, 27 Oct 2021 21:05:38 +0000 (00:05 +0300)]
Skip suggestions for the AsRef trait

2 years agoFix panic when documenting libproc-macro
Guillaume Gomez [Sat, 23 Oct 2021 21:26:29 +0000 (23:26 +0200)]
Fix panic when documenting libproc-macro

2 years agoDon't display "Methods from Deref<...>" if no method is display (the ones which don...
Guillaume Gomez [Sat, 23 Oct 2021 20:57:02 +0000 (22:57 +0200)]
Don't display "Methods from Deref<...>" if no method is display (the ones which don't have `self` argument)

2 years agoRemove the Rc wrapping of deref_id_map
Guillaume Gomez [Sat, 23 Oct 2021 20:18:33 +0000 (22:18 +0200)]
Remove the Rc wrapping of deref_id_map

2 years agoAdd tests for recursive deref
Guillaume Gomez [Fri, 22 Oct 2021 20:39:33 +0000 (22:39 +0200)]
Add tests for recursive deref

2 years agoAuto merge of #90373 - tmiasko:union-qualification, r=oli-obk
bors [Fri, 29 Oct 2021 12:21:09 +0000 (12:21 +0000)]
Auto merge of #90373 - tmiasko:union-qualification, r=oli-obk

Use type based qualification for unions

Union field access is currently qualified based on the qualification of
a value previously assigned to the union. At the same time, every union
access transmutes the content of the union, which might result in a
different qualification.

For example, consider constants A and B as defined below, under the
current rules neither contains interior mutability, since a value used
in the initial assignment did not contain `UnsafeCell` constructor.

```rust
#![feature(untagged_unions)]

union U { i: u32, c: std::cell::Cell<u32> }
const A: U = U { i: 0 };
const B: std::cell::Cell<u32> = unsafe { U { i: 0 }.c };
```

To avoid the issue, the changes here propose to consider the content of
a union as opaque and use type based qualification for union types.

Fixes #90268.

`@rust-lang/wg-const-eval`

2 years agoRecursively document Deref
Guillaume Gomez [Fri, 22 Oct 2021 19:45:06 +0000 (21:45 +0200)]
Recursively document Deref

2 years agoignore type flags insertion in default_anon_const_substs if error occurred
b-naber [Fri, 29 Oct 2021 11:14:44 +0000 (13:14 +0200)]
ignore type flags insertion in default_anon_const_substs if error occurred

2 years agoadd test
b-naber [Fri, 29 Oct 2021 10:38:28 +0000 (12:38 +0200)]
add test

2 years agodon't mutably borrow inner infcx in all of ConstInferUnifier::consts
b-naber [Fri, 29 Oct 2021 10:32:06 +0000 (12:32 +0200)]
don't mutably borrow inner infcx in all of ConstInferUnifier::consts

2 years agoAuto merge of #90214 - tmiasko:indirect-mutation-qualif, r=ecstatic-morse,oli-obk
bors [Fri, 29 Oct 2021 08:38:39 +0000 (08:38 +0000)]
Auto merge of #90214 - tmiasko:indirect-mutation-qualif, r=ecstatic-morse,oli-obk

Consider indirect mutation during const qualification dataflow

Previously a local would be qualified if either one of two separate data
flow computations indicated so. First determined if a local could
contain the qualif, but ignored any forms of indirect mutation. Second
determined if a local could be mutably borrowed (and so indirectly
mutated), but which in turn ignored the qualif.

The end result was incorrect because the effect of indirect mutation was
effectivelly ignored in the all but the final stage of computation.

In the new implementation the indirect mutation is directly incorporated
into the qualif data flow. The local variable becomes immediately
qualified once it is mutably borrowed and borrowed place type can
contain the qualif.

In general we will now reject additional programs, program that were
prevously unintentionally accepted.

There are also some cases which are now accepted but were previously
rejected, because previous implementation didn't consider whether
borrowed place could have the qualif under the consideration.

Fixes #90124.

r? `@ecstatic-morse`

2 years agoAuto merge of #90380 - Mark-Simulacrum:revert-89558-query-stable-lint, r=lcnr
bors [Fri, 29 Oct 2021 04:55:51 +0000 (04:55 +0000)]
Auto merge of #90380 - Mark-Simulacrum:revert-89558-query-stable-lint, r=lcnr

Revert "Add rustc lint, warning when iterating over hashmaps"

Fixes perf regressions introduced in https://github.com/rust-lang/rust/pull/90235 by temporarily reverting the relevant PR.

2 years agoAuto merge of #90363 - camelid:build-impl-perf, r=jyn514
bors [Fri, 29 Oct 2021 01:50:08 +0000 (01:50 +0000)]
Auto merge of #90363 - camelid:build-impl-perf, r=jyn514

Improve perf measurements of `build_extern_trait_impl`

Before, it was only measuring one callsite of `build_impl`, and it
incremented the call count even if `build_impl` returned early because
the `did` was already inlined.

Now, it measures all calls, minus calls that return early.

2 years agorustdoc: Remove a single-use macro
Noah Lev [Fri, 29 Oct 2021 01:39:32 +0000 (18:39 -0700)]
rustdoc: Remove a single-use macro

I think the new code is simpler and easier to understand.

2 years agoUpdate miri
Brennan Vincent [Fri, 29 Oct 2021 01:38:43 +0000 (21:38 -0400)]
Update miri

2 years agorustdoc: Switch to mainline rayon
Noah Lev [Fri, 29 Oct 2021 01:19:01 +0000 (18:19 -0700)]
rustdoc: Switch to mainline rayon

The rustc fork of rayon integrates with Cargo's jobserver to limit the
amount of parallelism. However, rustdoc's use case is concurrent I/O,
which is not CPU-heavy, so it should be able to use mainline rayon.

See this discussion [1] for more details.

[1]: https://github.com/rust-lang/rust/issues/90227#issuecomment-952468618

Note: I chose rayon 1.3.1 so that the rayon version used elsewhere in
the workspace does not change.

2 years agoAuto merge of #90387 - matthiaskrgr:rollup-b2x8v0x, r=matthiaskrgr
bors [Thu, 28 Oct 2021 22:44:45 +0000 (22:44 +0000)]
Auto merge of #90387 - matthiaskrgr:rollup-b2x8v0x, r=matthiaskrgr

Rollup of 3 pull requests

Successful merges:

 - #90082 (Fix minor typos)
 - #90336 (Remove extra lines in examples for `Duration::try_from_secs_*`)
 - #90376 (Various cleanups around opaque types)

Failed merges:

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

2 years agoRollup merge of #90376 - oli-obk:🧹, r=spastorino
Matthias Krüger [Thu, 28 Oct 2021 22:30:31 +0000 (00:30 +0200)]
Rollup merge of #90376 - oli-obk:🧹, r=spastorino

Various cleanups around opaque types

Best reviewed commit by commit.

This PR has no functional changes.

Mostly it's moving logic from an extension trait in rustc_trait_selection to inherent impls on rustc_infer.

2 years agoRollup merge of #90336 - mbartlett21:patch-4, r=Mark-Simulacrum
Matthias Krüger [Thu, 28 Oct 2021 22:30:30 +0000 (00:30 +0200)]
Rollup merge of #90336 - mbartlett21:patch-4, r=Mark-Simulacrum

Remove extra lines in examples for `Duration::try_from_secs_*`

None of the other examples have extra lines below the `#![feature(...)]` statements, so I thought it appropriate that these examples shouldn't either.

2 years agoRollup merge of #90082 - noncombatant:patch-1, r=GuillaumeGomez
Matthias Krüger [Thu, 28 Oct 2021 22:30:30 +0000 (00:30 +0200)]
Rollup merge of #90082 - noncombatant:patch-1, r=GuillaumeGomez

Fix minor typos

2 years agoAdd -Zunstable-options instead of feature
Mateusz Mikuła [Thu, 28 Oct 2021 21:38:21 +0000 (23:38 +0200)]
Add -Zunstable-options instead of feature

2 years agoAdd comments to hygiene tests
Matthew Jasper [Thu, 28 Oct 2021 20:48:39 +0000 (21:48 +0100)]
Add comments to hygiene tests

2 years agoRemove `ModData` from rustc_metadata
Matthew Jasper [Thu, 28 Oct 2021 20:48:21 +0000 (21:48 +0100)]
Remove `ModData` from rustc_metadata

This avoids having to decode 2 `Lazy`s when decoding a modules exports.

2 years agoAuto merge of #90281 - xldenis:public-borrow-set, r=nikomatsakis
bors [Thu, 28 Oct 2021 19:34:01 +0000 (19:34 +0000)]
Auto merge of #90281 - xldenis:public-borrow-set, r=nikomatsakis

Add BorrowSet to public api

This PR adds `BorrowSet` to the public api so that verification tools can obtain the activation and reservation points of two phase borrows without having to redo calculations themselves (and thus potentially differently from rustc).

Turns out we already can obtain `MoveData` thanks to the public `HasMoveData` trait, so constructing a `BorrowSet` should not provide much of an issue. However, I can't speak to the soundness of this approach, is it safe to take an under-approximation of `MoveData`?

r? `@nikomatsakis`

2 years agoAuto merge of #90218 - JakobDegen:adt_significant_drop_fix, r=nikomatsakis
bors [Thu, 28 Oct 2021 16:03:13 +0000 (16:03 +0000)]
Auto merge of #90218 - JakobDegen:adt_significant_drop_fix, r=nikomatsakis

Fixes incorrect handling of ADT's drop requirements

Fixes #90024 and a bunch of duplicates.

The main issue was just that the contract of `NeedsDropTypes::adt_components` was inconsistent; the list of types it might return were the generic parameters themselves or the fields of the ADT, depending on the nature of the drop impl. This meant that the caller could not determine whether a `.subst()` call was still needed on those types; it called `.subst()` in all cases, and this led to ICEs when the returned types were the generic params.

First contribution of more than a few lines, so feedback definitely appreciated.

2 years agoRevert "Add rustc lint, warning when iterating over hashmaps"
Mark Rousskov [Thu, 28 Oct 2021 15:01:42 +0000 (11:01 -0400)]
Revert "Add rustc lint, warning when iterating over hashmaps"

2 years agoAdd test cases
Ilya Yanok [Thu, 28 Oct 2021 14:25:46 +0000 (14:25 +0000)]
Add test cases

2 years agoMake `core::slice::from_raw_parts[_mut]` const
Maybe Waffle [Thu, 28 Oct 2021 14:15:25 +0000 (17:15 +0300)]
Make `core::slice::from_raw_parts[_mut]` const

2 years agoMove instantiate_opaque_types to rustc_infer.
Oli Scherer [Thu, 28 Oct 2021 14:12:24 +0000 (14:12 +0000)]
Move instantiate_opaque_types to rustc_infer.

It does not depend on anything from rustc_trait_selection anymore.

2 years agoMove some functions into `rustc_infer`.
Oli Scherer [Thu, 28 Oct 2021 13:54:11 +0000 (13:54 +0000)]
Move some functions into `rustc_infer`.
They don't depend on trait selection anymore, so there is no need for an extension trait.