]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoAuto merge of #95425 - nnethercote:yet-more-parse_tt-improvements, r=petrochenkov
bors [Wed, 30 Mar 2022 19:08:01 +0000 (19:08 +0000)]
Auto merge of #95425 - nnethercote:yet-more-parse_tt-improvements, r=petrochenkov

Yet more `parse_tt` improvements

Including lots of comment improvements, and an overhaul of how `matches` work that gives big speedups.

r? `@petrochenkov`

2 years agoAuto merge of #95458 - calebcartwright:sync-rustfmt-subtree, r=calebcartwright
bors [Wed, 30 Mar 2022 15:57:58 +0000 (15:57 +0000)]
Auto merge of #95458 - calebcartwright:sync-rustfmt-subtree, r=calebcartwright

Sync rustfmt subtree

r? `@calebcartwright`

2 years agoAuto merge of #94963 - lcnr:inherent-impls-std, r=oli-obk,m-ou-se
bors [Wed, 30 Mar 2022 12:28:50 +0000 (12:28 +0000)]
Auto merge of #94963 - lcnr:inherent-impls-std, r=oli-obk,m-ou-se

allow arbitrary inherent impls for builtin types in core

Part of https://github.com/rust-lang/compiler-team/issues/487. Slightly adjusted after some talks with `@m-ou-se` about the requirements of `t-libs-api`.

This adds a crate attribute `#![rustc_coherence_is_core]` which allows arbitrary impls for builtin types in core.

For other library crates impls for builtin types should be avoided if possible. We do have to allow the existing stable impls however. To prevent us from accidentally adding more of these in the future, there is a second attribute `#[rustc_allow_incoherent_impl]` which has to be added to **all impl items**. This only supports impls for builtin types but can easily be extended to additional types in a future PR.

This implementation does not check for overlaps in these impls. Perfectly checking that requires us to check the coherence of these incoherent impls in every crate, as two distinct dependencies may add overlapping methods. It should be easy enough to detect if it goes wrong and the attribute is only intended for use inside of std.

The first two commits are mostly unrelated cleanups.

2 years agoAuto merge of #95241 - Gankra:cleaned-provenance, r=workingjubilee
bors [Wed, 30 Mar 2022 10:09:10 +0000 (10:09 +0000)]
Auto merge of #95241 - Gankra:cleaned-provenance, r=workingjubilee

Strict Provenance MVP

This patch series examines the question: how bad would it be if we adopted
an extremely strict pointer provenance model that completely banished all
int<->ptr casts.

The key insight to making this approach even *vaguely* pallatable is the

ptr.with_addr(addr) -> ptr

function, which takes a pointer and an address and creates a new pointer
with that address and the provenance of the input pointer. In this way
the "chain of custody" is completely and dynamically restored, making the
model suitable even for dynamic checkers like CHERI and Miri.

This is not a formal model, but lots of the docs discussing the model
have been updated to try to the *concept* of this design in the hopes
that it can be iterated on.

See #95228

2 years agoclippy: nameres for primitive type impls
lcnr [Wed, 30 Mar 2022 09:57:53 +0000 (11:57 +0200)]
clippy: nameres for primitive type impls

2 years agotypo
lcnr [Wed, 30 Mar 2022 09:24:26 +0000 (11:24 +0200)]
typo

2 years agorework error messages for incorrect inherent impls
lcnr [Tue, 29 Mar 2022 07:47:32 +0000 (09:47 +0200)]
rework error messages for incorrect inherent impls

2 years agofix rustdoc wrt builtin impls switch
lcnr [Fri, 18 Mar 2022 16:02:32 +0000 (17:02 +0100)]
fix rustdoc wrt builtin impls switch

2 years agoget clippy to compile again
lcnr [Fri, 18 Mar 2022 12:33:40 +0000 (13:33 +0100)]
get clippy to compile again

2 years agofix rustdoc
lcnr [Fri, 18 Mar 2022 10:45:00 +0000 (11:45 +0100)]
fix rustdoc

2 years agofix behavior for empty impls
lcnr [Fri, 18 Mar 2022 10:44:55 +0000 (11:44 +0100)]
fix behavior for empty impls

2 years agoupdate rustdoc
lcnr [Tue, 15 Mar 2022 15:56:46 +0000 (16:56 +0100)]
update rustdoc

2 years agoremove now unnecessary lang items
lcnr [Tue, 15 Mar 2022 15:56:28 +0000 (16:56 +0100)]
remove now unnecessary lang items

2 years agoupdate ui tests
lcnr [Tue, 15 Mar 2022 15:32:52 +0000 (16:32 +0100)]
update ui tests

2 years agorework implementation for inherent impls for builtin types
lcnr [Tue, 15 Mar 2022 15:30:30 +0000 (16:30 +0100)]
rework implementation for inherent impls for builtin types

2 years agoremove `NoMatchData::new`
lcnr [Fri, 11 Mar 2022 11:20:27 +0000 (12:20 +0100)]
remove `NoMatchData::new`

2 years agoupdate comment
lcnr [Fri, 11 Mar 2022 10:59:40 +0000 (11:59 +0100)]
update comment

2 years agoAuto merge of #95466 - Dylan-DPC:rollup-g7ddr8y, r=Dylan-DPC
bors [Wed, 30 Mar 2022 07:45:42 +0000 (07:45 +0000)]
Auto merge of #95466 - Dylan-DPC:rollup-g7ddr8y, r=Dylan-DPC

Rollup of 5 pull requests

Successful merges:

 - #95294 (Document Linux kernel handoff in std::io::copy and std::fs::copy)
 - #95443 (Clarify how `src/tools/x` searches for python)
 - #95452 (fix since field version for termination stabilization)
 - #95460 (Spellchecking compiler code)
 - #95461 (Spellchecking some comments)

Failed merges:

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

2 years agoRollup merge of #95461 - nyurik:spelling, r=lcnr
Dylan DPC [Wed, 30 Mar 2022 07:10:07 +0000 (09:10 +0200)]
Rollup merge of #95461 - nyurik:spelling, r=lcnr

Spellchecking some comments

This PR attempts to clean up some minor spelling mistakes in comments

2 years agoRollup merge of #95460 - nyurik:spelling-str, r=lcnr
Dylan DPC [Wed, 30 Mar 2022 07:10:06 +0000 (09:10 +0200)]
Rollup merge of #95460 - nyurik:spelling-str, r=lcnr

Spellchecking compiler code

Address some spelling mistakes in strings, private function names, and function params.

2 years agoRollup merge of #95452 - yaahc:termination-version-correction, r=ehuss
Dylan DPC [Wed, 30 Mar 2022 07:10:05 +0000 (09:10 +0200)]
Rollup merge of #95452 - yaahc:termination-version-correction, r=ehuss

fix since field version for termination stabilization

fixes incorrect version fields in stabilization of https://github.com/rust-lang/rust/pull/93840

r? `@ehuss`

2 years agoRollup merge of #95443 - jyn514:clarify-python-search-logic, r=Dylan-DPC
Dylan DPC [Wed, 30 Mar 2022 07:10:04 +0000 (09:10 +0200)]
Rollup merge of #95443 - jyn514:clarify-python-search-logic, r=Dylan-DPC

Clarify how `src/tools/x` searches for python

Before, it confusingly looked like `python` was chosen last instead of first.

2 years agoRollup merge of #95294 - sourcefrog:doc-copy, r=dtolnay
Dylan DPC [Wed, 30 Mar 2022 07:10:04 +0000 (09:10 +0200)]
Rollup merge of #95294 - sourcefrog:doc-copy, r=dtolnay

Document Linux kernel handoff in std::io::copy and std::fs::copy

2 years agoSpellchecking compiler code
Yuri Astrakhan [Wed, 30 Mar 2022 05:42:10 +0000 (01:42 -0400)]
Spellchecking compiler code

Address some spelling mistakes in strings, private function names, and function params.

2 years agoSpellchecking some comments
Yuri Astrakhan [Wed, 30 Mar 2022 05:39:38 +0000 (01:39 -0400)]
Spellchecking some comments

This PR attempts to clean up some minor spelling mistakes in comments

2 years agoAuto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis
bors [Wed, 30 Mar 2022 05:04:45 +0000 (05:04 +0000)]
Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis

Lazy type-alias-impl-trait take two

### user visible change 1: RPIT inference from recursive call sites

Lazy TAIT has an insta-stable change. The following snippet now compiles, because opaque types can now have their hidden type set from wherever the opaque type is mentioned.

```rust
fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return 42
    }
    let x: u32 = bar(false); // this errors on stable
    99
}
```

The return type of `bar` stays opaque, you can't do `bar(false) + 42`, you need to actually mention the hidden type.

### user visible change 2: divergence between RPIT and TAIT in return statements

Note that `return` statements and the trailing return expression are special with RPIT (but not TAIT). So

```rust
#![feature(type_alias_impl_trait)]
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        return vec![42];
    }
    std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator
}

fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return vec![42]
    }
    std::iter::empty().collect() // Works, magic (accidentally stabilized, not intended)
}
```

But when we are working with the return value of a recursive call, the behavior of RPIT and TAIT is the same:

```rust
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        return vec![];
    }
    let mut x = foo(false);
    x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator
    vec![]
}

fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return vec![];
    }
    let mut x = bar(false);
    x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator
    vec![]
}
```

### user visible change 3: TAIT does not merge types across branches

In contrast to RPIT, TAIT does not merge types across branches, so the following does not compile.

```rust
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        vec![42_i32]
    } else {
        std::iter::empty().collect()
        //~^ ERROR `Foo` cannot be built from an iterator over elements of type `_`
    }
}
```

It is easy to support, but we should make an explicit decision to include the additional complexity in the implementation (it's not much, see a721052457cf513487fb4266e3ade65c29b272d2 which needs to be reverted to enable this).

### PR formalities

previous attempt: #92007

This PR also includes #92306 and #93783, as they were reverted along with #92007 in #93893

fixes #93411
fixes #88236
fixes #89312
fixes #87340
fixes #86800
fixes #86719
fixes #84073
fixes #83919
fixes #82139
fixes #77987
fixes #74282
fixes #67830
fixes #62742
fixes #54895

2 years agoMerge commit '5ff7b632a95bac6955611d85040859128902c580' into sync-rustfmt-subtree
Caleb Cartwright [Wed, 30 Mar 2022 04:17:30 +0000 (23:17 -0500)]
Merge commit '5ff7b632a95bac6955611d85040859128902c580' into sync-rustfmt-subtree

2 years agoPreserve semicolon after macro call inside foreign mod
David Tolnay [Tue, 29 Mar 2022 19:59:07 +0000 (12:59 -0700)]
Preserve semicolon after macro call inside foreign mod

2 years agoAdd test of macro calls inside extern block
David Tolnay [Tue, 29 Mar 2022 20:09:28 +0000 (13:09 -0700)]
Add test of macro calls inside extern block

2 years agoWarn that platform-specific behavior may change
Martin Pool [Wed, 30 Mar 2022 02:43:40 +0000 (19:43 -0700)]
Warn that platform-specific behavior may change

2 years agofix unix typedef
Aria Beingessner [Wed, 30 Mar 2022 02:45:31 +0000 (22:45 -0400)]
fix unix typedef

2 years agoAuto merge of #95455 - RalfJung:miri, r=RalfJung
bors [Wed, 30 Mar 2022 02:41:44 +0000 (02:41 +0000)]
Auto merge of #95455 - RalfJung:miri, r=RalfJung

update miri

Fixes https://github.com/rust-lang/rust/issues/95357
r? `@ghost`

2 years agoupdate miri
Ralf Jung [Wed, 30 Mar 2022 02:13:33 +0000 (22:13 -0400)]
update miri

2 years agofixup feature position in liballoc
Aria Beingessner [Tue, 29 Mar 2022 21:45:54 +0000 (17:45 -0400)]
fixup feature position in liballoc

2 years agoclarify that WASM has address spaces
Aria Beingessner [Mon, 28 Mar 2022 18:26:24 +0000 (14:26 -0400)]
clarify that WASM has address spaces

2 years agofix doc link
Aria Beingessner [Mon, 28 Mar 2022 18:06:16 +0000 (14:06 -0400)]
fix doc link

2 years agorefine the definition of temporal provenance
Aria Beingessner [Mon, 28 Mar 2022 17:16:04 +0000 (13:16 -0400)]
refine the definition of temporal provenance

2 years agomark FIXMES for all the places found that are probably offset_from
Aria Beingessner [Mon, 28 Mar 2022 04:43:18 +0000 (00:43 -0400)]
mark FIXMES for all the places found that are probably offset_from

2 years agomore review fixes to ptr docs
Aria Beingessner [Mon, 28 Mar 2022 04:37:28 +0000 (00:37 -0400)]
more review fixes to ptr docs

2 years agoAdd even more details to top-level pointer docs
Aria Beingessner [Sun, 27 Mar 2022 19:06:06 +0000 (15:06 -0400)]
Add even more details to top-level pointer docs

2 years agocleanup some of the less terrifying library code
Aria Beingessner [Sat, 26 Mar 2022 21:03:40 +0000 (17:03 -0400)]
cleanup some of the less terrifying library code

2 years agoclean up pointer docs
Aria Beingessner [Sat, 26 Mar 2022 19:55:05 +0000 (15:55 -0400)]
clean up pointer docs

2 years agorevert changes that cast functions to raw pointers, portability hazard
Aria Beingessner [Wed, 23 Mar 2022 16:38:04 +0000 (12:38 -0400)]
revert changes that cast functions to raw pointers, portability hazard

2 years agoMake some linux/unix APIs better conform to strict provenance.
Alexis Beingessner [Wed, 23 Mar 2022 01:29:38 +0000 (21:29 -0400)]
Make some linux/unix APIs better conform to strict provenance.

This largely makes the stdlib conform to strict provenance on Ubuntu.
Some hairier things have been left alone for now.

2 years agoMake some rustc code conform to strict provenance.
Aria Beingessner [Tue, 22 Mar 2022 20:21:33 +0000 (16:21 -0400)]
Make some rustc code conform to strict provenance.

There's some really bad stuff around `ty` and pointer tagging stuff that
was too much work to handle here.

2 years agoMake the stdlib largely conform to strict provenance.
Aria Beingessner [Tue, 22 Mar 2022 05:24:55 +0000 (01:24 -0400)]
Make the stdlib largely conform to strict provenance.

Some things like the unwinders and system APIs are not fully conformant,
this only covers a lot of low-hanging fruit.

2 years agoIntroduce experimental APIs for conforming to "strict provenance".
Aria Beingessner [Tue, 22 Mar 2022 05:27:28 +0000 (01:27 -0400)]
Introduce experimental APIs for conforming to "strict provenance".

This patch series examines the question: how bad would it be if we adopted
an extremely strict pointer provenance model that completely banished all
int<->ptr casts.

The key insight to making this approach even *vaguely* pallatable is the

ptr.with_addr(addr) -> ptr

function, which takes a pointer and an address and creates a new pointer
with that address and the provenance of the input pointer. In this way
the "chain of custody" is completely and dynamically restored, making the
model suitable even for dynamic checkers like CHERI and Miri.

This is not a formal model, but lots of the docs discussing the model
have been updated to try to the *concept* of this design in the hopes
that it can be iterated on.

2 years agofix since field version for termination stabilization
Jane Lusby [Wed, 30 Mar 2022 00:10:49 +0000 (17:10 -0700)]
fix since field version for termination stabilization

2 years agoPre-allocate an empty `Lrc<NamedMatchVec>`.
Nicholas Nethercote [Tue, 29 Mar 2022 23:54:57 +0000 (10:54 +1100)]
Pre-allocate an empty `Lrc<NamedMatchVec>`.

This avoids some allocations.

2 years agoOverhaul how matches are recorded.
Nicholas Nethercote [Mon, 28 Mar 2022 06:13:56 +0000 (17:13 +1100)]
Overhaul how matches are recorded.

Currently, matches within a sequence are recorded in a new empty
`matches` vector. Then when the sequence finishes the matches are merged
into the `matches` vector of the parent.

This commit changes things so that a sequence mp inherits the matches
made so far. This means that additional matches from the sequence don't
need to be merged into the parent. `push_match` becomes more
complicated, and the current sequence depth needs to be tracked. But
it's a sizeable performance win because it avoids one or more
`push_match` calls on every iteration of a sequence.

The commit also removes `match_hi`, which is no longer necessary.

2 years agoImprove comments and rename many things for consistency.
Nicholas Nethercote [Fri, 25 Mar 2022 05:20:39 +0000 (16:20 +1100)]
Improve comments and rename many things for consistency.

In particular:
- Replace use of "item" with "matcher position/"mp".
- Replace use of "repetition" with "sequence".
- Replace `ms` with `matcher`.

2 years agoClarify comments about doc comments in macros.
Nicholas Nethercote [Tue, 29 Mar 2022 02:27:59 +0000 (13:27 +1100)]
Clarify comments about doc comments in macros.

2 years agoSimplify and rename `count_names`.
Nicholas Nethercote [Fri, 25 Mar 2022 05:23:26 +0000 (16:23 +1100)]
Simplify and rename `count_names`.

2 years agoAuto merge of #95448 - Dylan-DPC:rollup-wpj5yto, r=Dylan-DPC
bors [Tue, 29 Mar 2022 21:01:45 +0000 (21:01 +0000)]
Auto merge of #95448 - Dylan-DPC:rollup-wpj5yto, r=Dylan-DPC

Rollup of 4 pull requests

Successful merges:

 - #93840 (Stabilize Termination and ExitCode)
 - #95256 (Ensure io::Error's bitpacked repr doesn't accidentally impl UnwindSafe)
 - #95386 (Suggest wrapping patterns in enum variants)
 - #95437 (diagnostics: regression test for derive bounds)

Failed merges:

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

2 years agoRollup merge of #95437 - notriddle:notriddle/issue-79076, r=compiler-errors
Dylan DPC [Tue, 29 Mar 2022 20:46:36 +0000 (22:46 +0200)]
Rollup merge of #95437 - notriddle:notriddle/issue-79076, r=compiler-errors

diagnostics: regression test for derive bounds

Closes #79076

2 years agoRollup merge of #95386 - compiler-errors:try-wrapping, r=oli-obk
Dylan DPC [Tue, 29 Mar 2022 20:46:34 +0000 (22:46 +0200)]
Rollup merge of #95386 - compiler-errors:try-wrapping, r=oli-obk

Suggest wrapping patterns in enum variants

Structured suggestion to wrap a pattern in a single-field enum or struct:

```diff
 struct A;

 enum B {
   A(A),
 }

 fn main(b: B) {
   match b {
-    A => {}
+    B::A(A) => {}
   }
 }
```

Half of #94942, the other half I'm not exactly sure how to fix.

Also includes two drive-by changes (that I am open to splitting out into another PR, but thought they could be rolled up into this one):
07776c111f07b887cd46b752870cd3fd76b2ba7c: Makes sure not to suggest wrapping if it doesn't have tuple field constructor (i.e. has named fields)
8f2bbb18fd53e5008bb488302dbd354577698ede: Also suggest wrapping expressions in a tuple struct (not just enum variants)

2 years agoRollup merge of #95256 - thomcc:fix-unwind-safe, r=m-ou-se
Dylan DPC [Tue, 29 Mar 2022 20:46:33 +0000 (22:46 +0200)]
Rollup merge of #95256 - thomcc:fix-unwind-safe, r=m-ou-se

Ensure io::Error's bitpacked repr doesn't accidentally impl UnwindSafe

Sadly, I'm not sure how to easily test that we don't impl a trait, though (or can libstd use `where io::Error: !UnwindSafe` or something).

Fixes #95203

2 years agoRollup merge of #93840 - yaahc:termination-stabilization-celebration-station, r=josht...
Dylan DPC [Tue, 29 Mar 2022 20:46:31 +0000 (22:46 +0200)]
Rollup merge of #93840 - yaahc:termination-stabilization-celebration-station, r=joshtriplett

Stabilize Termination and ExitCode

From https://github.com/rust-lang/rust/issues/43301

This PR stabilizes the Termination trait and associated ExitCode type. It also adjusts the ExitCode feature flag to replace the placeholder flag with a more permanent name, as well as splitting off the `to_i32` method behind its own permanently unstable feature flag.

This PR stabilizes the termination trait with the following signature:

```rust
pub trait Termination {
    fn report(self) -> ExitCode;
}
```

The existing impls of `Termination` are effectively already stable due to the prior stabilization of `?` in main.

This PR also stabilizes the following APIs on exit code

```rust
#[derive(Clone, Copy, Debug)]
pub struct ExitCode(_);

impl ExitCode {
    pub const SUCCESS: ExitCode;
    pub const FAILURE: ExitCode;
}

impl From<u8> for ExitCode { /* ... */ }
```

---

All of the previous blockers have been resolved. The main ones that were resolved recently are:

* The trait's name: We decided against changing this since none of the alternatives seemed particularly compelling. Instead we decided to end the bikeshedding and stick with the current name. ([link to the discussion](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization/near/269793887))
* Issues around platform specific representations: We resolved this issue by changing the return type of `report` from `i32` to the opaque type `ExitCode`. That way we can change the underlying representation without affecting the API, letting us offer full support for platform specific exit code APIs in the future.
* Custom exit codes: We resolved this by adding `From<u8> for ExitCode`. We choose to only support u8 initially because it is the least common denominator between the sets of exit codes supported by our current platforms. In the future we anticipate adding platform specific extension traits to ExitCode for constructors from larger or negative numbers, as needed.

2 years agoClarify how `src/tools/x` searches for python
Joshua Nelson [Tue, 29 Mar 2022 18:50:17 +0000 (13:50 -0500)]
Clarify how `src/tools/x` searches for python

2 years agoIndicate the correct error code in the `compile_fail` block.
Thom Chiovoloni [Tue, 29 Mar 2022 18:45:49 +0000 (11:45 -0700)]
Indicate the correct error code in the `compile_fail` block.

Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2 years agoAuto merge of #95433 - Dylan-DPC:rollup-xdfit9h, r=Dylan-DPC
bors [Tue, 29 Mar 2022 17:48:40 +0000 (17:48 +0000)]
Auto merge of #95433 - Dylan-DPC:rollup-xdfit9h, r=Dylan-DPC

Rollup of 4 pull requests

Successful merges:

 - #94566 (Show ignore message in console and json output)
 - #95415 (diagnostics: regression test for HashMap iter_mut suggestion)
 - #95422 (Refactor: Use `format-args-capture` and remove an unnecessary nested block)
 - #95424 (:arrow_up: rust-analyzer)

Failed merges:

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

2 years agodiagnostics: regression test for derive bounds
Michael Howell [Tue, 29 Mar 2022 17:17:27 +0000 (10:17 -0700)]
diagnostics: regression test for derive bounds

Closes #79076

2 years agoAuto merge of #94566 - yanganto:show-ignore-message, r=m-ou-se
bors [Tue, 29 Mar 2022 15:18:57 +0000 (15:18 +0000)]
Auto merge of #94566 - yanganto:show-ignore-message, r=m-ou-se

Show ignore message in console and json output

- Provide ignore the message in console and JSON output
- Modify the ignore message style in the log file

related: #92714

2 years agoRollup merge of #95424 - lnicola:rust-analyzer-2022-03-29, r=lnicola
Dylan DPC [Tue, 29 Mar 2022 15:11:55 +0000 (17:11 +0200)]
Rollup merge of #95424 - lnicola:rust-analyzer-2022-03-29, r=lnicola

:arrow_up: rust-analyzer

r? `@ghost`

2 years agoRollup merge of #95422 - TaKO8Ki:use-format-args-capture-and-remove-unnecessary-nesti...
Dylan DPC [Tue, 29 Mar 2022 15:11:54 +0000 (17:11 +0200)]
Rollup merge of #95422 - TaKO8Ki:use-format-args-capture-and-remove-unnecessary-nesting-in-rustc-typeck, r=petrochenkov

Refactor: Use `format-args-capture` and remove an unnecessary nested block

2 years agoRollup merge of #95415 - notriddle:notriddle/issue-82081, r=Dylan-DPC
Dylan DPC [Tue, 29 Mar 2022 15:11:52 +0000 (17:11 +0200)]
Rollup merge of #95415 - notriddle:notriddle/issue-82081, r=Dylan-DPC

diagnostics: regression test for HashMap iter_mut suggestion

Closes #82081

2 years agoRollup merge of #94566 - yanganto:show-ignore-message, r=m-ou-se
Dylan DPC [Tue, 29 Mar 2022 15:11:51 +0000 (17:11 +0200)]
Rollup merge of #94566 - yanganto:show-ignore-message, r=m-ou-se

Show ignore message in console and json output

- Provide ignore the message in console and JSON output
- Modify the ignore message style in the log file

related: #92714

2 years agoRemove unnecessary .as_ref().
Mara Bos [Tue, 29 Mar 2022 13:53:09 +0000 (15:53 +0200)]
Remove unnecessary .as_ref().

2 years agoAuto merge of #95096 - GuillaumeGomez:rm-header-fn-field, r=camelid
bors [Tue, 29 Mar 2022 12:49:03 +0000 (12:49 +0000)]
Auto merge of #95096 - GuillaumeGomez:rm-header-fn-field, r=camelid

Remove header field from clean::Function

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

This is another take on https://github.com/rust-lang/rust/issues/89673 (compared to https://github.com/rust-lang/rust/pull/91217) but very different on the approach: I moved the header call in one place but still require to have the `clean::Item` so I can use the `DefId` to get what is missing.

cc `@jyn514` (you reviewed the original so maybe you want to take a look?)
r? `@camelid`

2 years agoRefactor after review
Antonio Yang [Tue, 29 Mar 2022 11:41:16 +0000 (19:41 +0800)]
Refactor after review

Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2 years agoMerge ItemKind::TyMethodItem branch with ItemKind::FunctionItem and ItemKind::MethodI...
Guillaume Gomez [Tue, 29 Mar 2022 10:09:42 +0000 (12:09 +0200)]
Merge ItemKind::TyMethodItem branch with ItemKind::FunctionItem and ItemKind::MethodItem in fn_header function

2 years agoAuto merge of #95375 - MarcusCalhoun-Lopez:i686_apple_darwin, r=m-ou-se
bors [Tue, 29 Mar 2022 10:08:03 +0000 (10:08 +0000)]
Auto merge of #95375 - MarcusCalhoun-Lopez:i686_apple_darwin, r=m-ou-se

Fix build on i686-apple-darwin systems

Replace `target_arch = "x86_64"` with `not(target_arch = "aarch64")` so that i686-apple-darwin systems dynamically choose implementation.

2 years agoAdd test to ensure foreign functions from dependencies are correctly handled
Guillaume Gomez [Sat, 19 Mar 2022 16:08:20 +0000 (17:08 +0100)]
Add test to ensure foreign functions from dependencies are correctly handled

2 years agoRemove header field from clean::Function
Guillaume Gomez [Fri, 18 Mar 2022 17:48:32 +0000 (18:48 +0100)]
Remove header field from clean::Function

2 years agoAuto merge of #95257 - compiler-errors:fn-borrow, r=lcnr
bors [Tue, 29 Mar 2022 07:27:14 +0000 (07:27 +0000)]
Auto merge of #95257 - compiler-errors:fn-borrow, r=lcnr

Add suggestion to borrow `Fn` and `FnMut` params/opaque/closures instead of move

I think that Closure/ParamTy/Opaque are all "opaque" enough that it's meaningful to suggest borrowing them instead of moving them at their usage sites when we see a move error. See the attached issue for example.

Is this suggestion too general? I could perhaps use the move site information to limit this to places like fn calls, but I don't know enough about mir borrowck to know if that's an easy change.

Fixes #90828

2 years ago:arrow_up: rust-analyzer
Laurențiu Nicola [Tue, 29 Mar 2022 05:31:05 +0000 (08:31 +0300)]
:arrow_up: rust-analyzer

2 years agoSuggest function borrow ignoring needs_note
Michael Goulet [Tue, 29 Mar 2022 02:30:39 +0000 (19:30 -0700)]
Suggest function borrow ignoring needs_note

`needs_note` is false if we've already suggested why the type is Copy...
but that has nothing to do with the diagnostic.

2 years agodrive-by: move Copy bound suggestion to its own function
Michael Goulet [Tue, 29 Mar 2022 01:35:23 +0000 (18:35 -0700)]
drive-by: move Copy bound suggestion to its own function

2 years agoAdd suggestion to borrow opaque Fn and FnMut instead of move
Michael Goulet [Wed, 23 Mar 2022 23:15:43 +0000 (16:15 -0700)]
Add suggestion to borrow opaque Fn and FnMut instead of move

2 years agoAuto merge of #95423 - ehuss:update-books, r=ehuss
bors [Tue, 29 Mar 2022 05:15:58 +0000 (05:15 +0000)]
Auto merge of #95423 - ehuss:update-books, r=ehuss

Update books

## nomicon

3 commits in f6d6126fc96ecf4a7f7d22da330df9506293b0d0..11f1165e8a2f5840467e748c8108dc53c948ee9a
2022-02-26 02:21:21 +0900 to 2022-03-19 16:02:00 -0400
- Make the Vec impl be slightly more careful with ZSTs and alignment.
- implement `IntoIterator` for `Vec` (rust-lang/nomicon#337)
- Add an explanation shared to exclusive transmute (rust-lang/nomicon#344)

## reference

2 commits in 0a2fe6651fbccc6416c5110fdf5b93fb3cb29247..c97d14fa6fed0baa9255432b8a93cb70614f80e3
2022-03-15 09:32:25 -0700 to 2022-03-19 18:18:10 -0700
- Fixed inconsistency in the usage of semicolon at end of scopes (rust-lang/reference#1182)
- Document ADX `target_feature` (rust-lang/reference#1172)

## book

23 commits in 036e88a4f135365de85358febe5324976a56030a..ea90bbaf53ba64ef4e2da9ac2352b298aec6bec8
2022-03-04 21:53:33 -0500 to 2022-03-28 21:59:34 -0400
- Fix nostarch snapshot
- Snapshot of chapter 7 for nostarch
- Add a forward reference to chapter 14, another example of pub use
- Clarify pub use example. Fixes rust-lang/book#2716.
- Fancy quotes
- Fix incorrectly worded sentence. Fixes rust-lang/book#3086.
- Reword description of how a listing came to be
- Call out binary+library crate practices
- Define binary and library crates more explicitly
- Clarify when a path is a crate name and when it should be literal crate
- Make it clearer the outer `mod` doesn't move to the file
- Don't wrap this example in main when copying. Fixes rust-lang/book#2930.
- Try to make clearer that `mod` is not an `import`
- Mention mod.rs file naming scheme
- Explain why submodule subdirectories are needed more
- Rename a separate example of serve_order to deliver_order
- Show an example that `use` only applies in its own scope
- quick modules guide
- Tweak a snippet of ch18-03
- Propagating edits to chapter 10 back
- Responses to nostarch questions of chapter 10
- Update src/ch04-01-what-is-ownership.md
- Add Danish translation link. Connects to rust-lang/book#3079.

## rust-by-example

2 commits in d504324f1e7dc7edb918ac39baae69f1f1513b8e..ec954f35eedf592cd173b21c05a7f80a65b61d8a
2022-03-07 09:26:32 -0300 to 2022-03-22 11:09:06 -0300
- PathBuf details and example (rust-lang/rust-by-example#1519)
- Move allow dead code attribute and add comment (rust-lang/rust-by-example#1518)

## rustc-dev-guide

1 commits in 0e4b961a9c708647bca231430ce1b199993e0196..155126b1d2e2cb01ddb1d7ba9489b90d7cd173ad
2022-03-14 08:40:37 -0700 to 2022-03-22 14:34:21 +0100
- update section for type system constants (rust-lang/rustc-dev-guide#1329)

## embedded-book

1 commits in d5fc1bce3f8eb398f9c25f1b15e0257d7537cd41..a6de8b6e3ea5d4f0de8b7b9a7e5c1405dc2c2ddb
2022-01-24 07:13:31 +0000 to 2022-03-17 21:21:39 +0000
- Update OpenOCD install instruction for rust-embedded/book#313  (rust-embedded/book#314)

2 years agoUpdate books
Eric Huss [Tue, 29 Mar 2022 05:16:31 +0000 (22:16 -0700)]
Update books

2 years agouse format-args-capture and remove an unnecessary nested block
Takayuki Maeda [Tue, 29 Mar 2022 03:15:09 +0000 (12:15 +0900)]
use format-args-capture and remove an unnecessary nested block

2 years agotests: ignore cargo fmt test for rust-lang/rust runs
Caleb Cartwright [Tue, 29 Mar 2022 01:29:05 +0000 (20:29 -0500)]
tests: ignore cargo fmt test for rust-lang/rust runs

2 years agoRevert "Use cargo-fmt in self_tests"
Caleb Cartwright [Tue, 29 Mar 2022 01:27:42 +0000 (20:27 -0500)]
Revert "Use cargo-fmt in self_tests"

This reverts commit c63d42e80473a0c18714b55058f27506fd24955c.

2 years agoAuto merge of #95417 - ehuss:doc-no_std-error, r=Dylan-DPC
bors [Tue, 29 Mar 2022 01:09:22 +0000 (01:09 +0000)]
Auto merge of #95417 - ehuss:doc-no_std-error, r=Dylan-DPC

bootstrap: better error message for no_std docs

Currently if one tries to build std documentation for a no_std target, you get a confusing error message:

`error: The argument '--package [<SPEC>...]' was provided more than once, but cannot be used multiple times`

This is because [`std_cargo`](https://github.com/rust-lang/rust/blob/600ec284838c52d1f6657c2cf0097b58970b133b/src/bootstrap/compile.rs#L299-L305) has a built-in `-p alloc` argument that conflicts with the `cargo rustdoc` command used in the Std doc step.

This just adds a better error message in this scenario. It may be possible to fix this correctly, but that would likely be a bit more of an invasive change that I don't have time for right now.

2 years agoAuto merge of #95249 - HeroicKatora:set-ptr-value, r=dtolnay
bors [Mon, 28 Mar 2022 22:47:31 +0000 (22:47 +0000)]
Auto merge of #95249 - HeroicKatora:set-ptr-value, r=dtolnay

Refactor set_ptr_value as with_metadata_of

Replaces `set_ptr_value` (#75091) with methods of reversed argument order:

```rust
impl<T: ?Sized> *mut T {
    pub fn with_metadata_of<U: ?Sized>(self, val: *mut U) -> *mut U;
}

impl<T: ?Sized> *const T {
    pub fn with_metadata_of<U: ?Sized>(self, val: *const U) -> *const U;
}
```

By reversing the arguments we achieve several clarifications:

- The function closely resembles `cast` with an argument to
  initialize the metadata. This is easier to teach and answers a long
  outstanding question that had restricted cast to `Sized` pointee
  targets. See multiples reviews of
  <https://github.com/rust-lang/rust/pull/47631>
- The 'object identity', in the form of provenance, is now preserved
  from the receiver argument to the result. This helps explain the method as
  a builder-style, instead of some kind of setter that would modify
  something in-place. Ensuring that the result has the identity of the
  `self` argument is also beneficial for an intuition of effects.
- An outstanding concern, 'Correct argument type', is avoided by not
  committing to any specific argument type. This is consistent with cast
  which does not require its receiver to be a 'raw address'.

Hopefully the usage examples in `sync/rc.rs` serve as sufficient examples of the style to convince the reader of the readability improvements of this style, when compared to the previous order of arguments.

I want to take the opportunity to motivate inclusion of this method _separate_ from metadata API, separate from `feature(ptr_metadata)`. It does _not_ involve the `Pointee` trait in any form. This may be regarded as a very, very light form that does not commit to any details of the pointee trait, or its associated metadata. There are several use cases for which this is already sufficient and no further inspection of metadata is necessary.

- Storing the coercion of `*mut T` into `*mut dyn Trait` as a way to dynamically cast some an arbitrary instance of the same type to a dyn trait instance. In particular, one can have a field of type `Option<*mut dyn io::Seek>` to memorize if a particular writer is seekable. Then a method `fn(self: &T) -> Option<&dyn Seek>` can be provided, which does _not_ involve the static trait bound `T: Seek`. This makes it possible to create an API that is capable of utilizing seekable streams and non-seekable streams (instead of a possible less efficient manner such as more buffering) through the same entry-point.

- Enabling more generic forms of unsizing for no-`std` smart pointers. Using the stable APIs only few concrete cases are available. One can unsize arrays to `[T]` by `ptr::slice_from_raw_parts` but unsizing a custom smart pointer to, e.g., `dyn Iterator`, `dyn Future`, `dyn Debug`, can't easily be done generically. Exposing `with_metadata_of` would allow smart pointers to offer their own `unsafe` escape hatch with similar parameters where the caller provides the unsized metadata. This is particularly interesting for embedded where `dyn`-trait usage can drastically reduce code size.

2 years agoAdd a useful assertion.
Nicholas Nethercote [Fri, 25 Mar 2022 04:32:34 +0000 (15:32 +1100)]
Add a useful assertion.

2 years agoFix build on i686-apple-darwin systems
Marcus Calhoun-Lopez [Mon, 28 Mar 2022 19:44:19 +0000 (12:44 -0700)]
Fix build on i686-apple-darwin systems

On 32-bit systems, fdopendir is called `_fdopendir$INODE64$UNIX2003`.
On 64-bit systems, fdopendir is called `_fdopendir$INODE64`.

2 years agoFix build on i686-apple-darwin systems
Marcus Calhoun-Lopez [Sun, 27 Mar 2022 18:18:01 +0000 (11:18 -0700)]
Fix build on i686-apple-darwin systems

Replace `target_arch = "x86_64"` with `not(target_arch = "aarch64")` so that i686-apple-darwin systems dynamically choose implementation.

2 years agobootstrap: better error message for no_std docs
Eric Huss [Mon, 28 Mar 2022 19:13:18 +0000 (12:13 -0700)]
bootstrap: better error message for no_std docs

2 years agodiagnostics: add regression test for #82081
Michael Howell [Mon, 28 Mar 2022 18:47:19 +0000 (11:47 -0700)]
diagnostics: add regression test for #82081

2 years agodiagnostics: do not suggest `map.iter_mut()()`
Michael Howell [Mon, 28 Mar 2022 18:47:01 +0000 (11:47 -0700)]
diagnostics: do not suggest `map.iter_mut()()`

2 years agoAuto merge of #95414 - Dylan-DPC:rollup-9hbshd0, r=Dylan-DPC
bors [Mon, 28 Mar 2022 18:42:59 +0000 (18:42 +0000)]
Auto merge of #95414 - Dylan-DPC:rollup-9hbshd0, r=Dylan-DPC

Rollup of 5 pull requests

Successful merges:

 - #93787 (parallel_compiler: hide dependencies behind feature)
 - #95318 (diagnostics: correct generic bounds with doubled colon)
 - #95328 (Fix yet another Box<T, A> ICE)
 - #95397 (Link to std::io's platform-specific behavior disclaimer)
 - #95407 (Inline u8::is_utf8_char_boundary)

Failed merges:

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

2 years agoRollup merge of #95407 - xfix:inline-u8-is_utf8_char_boundary, r=scottmcm
Dylan DPC [Mon, 28 Mar 2022 18:41:53 +0000 (20:41 +0200)]
Rollup merge of #95407 - xfix:inline-u8-is_utf8_char_boundary, r=scottmcm

Inline u8::is_utf8_char_boundary

Since Rust beta, Rust is incapable of inlining this function in the following example function.

```rust
pub fn safe_substr_to(s: &str, mut length: usize) -> &str {
    loop {
        if let Some(s) = s.get(..length) {
            return s;
        }
        length -= 1;
    }
}
```

When compiled with beta or nightly compiler on Godbolt with `-C opt-level=3` flag it prints the following assembly.

```asm
example::safe_substr_to:
        push    r15
        push    r14
        push    r12
        push    rbx
        push    rax
        mov     r14, rdi
        test    rdx, rdx
        je      .LBB0_8
        mov     rbx, rdx
        mov     r15, rsi
        mov     r12, qword ptr [rip + core::num::<impl u8>::is_utf8_char_boundary@GOTPCREL]
        jmp     .LBB0_4
.LBB0_2:
        je      .LBB0_9
.LBB0_3:
        add     rbx, -1
        je      .LBB0_8
.LBB0_4:
        cmp     rbx, r15
        jae     .LBB0_2
        movzx   edi, byte ptr [r14 + rbx]
        call    r12
        test    al, al
        je      .LBB0_3
        mov     r15, rbx
        jmp     .LBB0_9
.LBB0_8:
        xor     r15d, r15d
.LBB0_9:
        mov     rax, r14
        mov     rdx, r15
        add     rsp, 8
        pop     rbx
        pop     r12
        pop     r14
        pop     r15
        ret
```

`qword ptr [rip + core::num::<impl u8>::is_utf8_char_boundary@GOTPCREL]` is not inlined. `-C remark=all` outputs the following message:

```
note: /rustc/7bccde19767082c7865a12902fa614ed4f8fed73/library/core/src/str/mod.rs:214:25: inline: _ZN4core3num20_$LT$impl$u20$u8$GT$21is_utf8_char_boundary17hace9f12f5ba07a7fE will not be inlined into _ZN4core3str21_$LT$impl$u20$str$GT$16is_char_boundary17hf2587e9a6b8c5e43E because its definition is unavailable
```

Stable compiler outputs more reasonable code:

```asm
example::safe_substr_to:
        mov     rcx, rdx
        mov     rax, rdi
        test    rdx, rdx
        je      .LBB0_9
        mov     rdx, rsi
        jmp     .LBB0_4
.LBB0_2:
        cmp     rdx, rcx
        je      .LBB0_7
.LBB0_3:
        add     rcx, -1
        je      .LBB0_9
.LBB0_4:
        cmp     rcx, rdx
        jae     .LBB0_2
        cmp     byte ptr [rax + rcx], -64
        jl      .LBB0_3
        mov     rdx, rcx
.LBB0_7:
        ret
.LBB0_9:
        xor     edx, edx
        ret
```

2 years agoRollup merge of #95397 - dtolnay:disclaimer, r=m-ou-se
Dylan DPC [Mon, 28 Mar 2022 18:41:52 +0000 (20:41 +0200)]
Rollup merge of #95397 - dtolnay:disclaimer, r=m-ou-se

Link to std::io's platform-specific behavior disclaimer

This PR adds some links in standard library documentation to point to https://doc.rust-lang.org/std/io/index.html#platform-specific-behavior.

> ### Platform-specific behavior
>
> Many I/O functions throughout the standard library are documented to indicate what various library or syscalls they are delegated to. This is done to help applications both understand what’s happening under the hood as well as investigate any possibly unclear semantics. Note, however, that this is informative, not a binding contract. The implementation of many of these functions are subject to change over time and may call fewer or more syscalls/library functions.

Many of the `std::fs` APIs already link to this disclaimer when discussing system calls.

2 years agoRollup merge of #95328 - DrMeepster:box_gep_err, r=oli-obk
Dylan DPC [Mon, 28 Mar 2022 18:41:51 +0000 (20:41 +0200)]
Rollup merge of #95328 - DrMeepster:box_gep_err, r=oli-obk

Fix yet another Box<T, A> ICE

Fixes #95036.

This widens the special case from #94414 to make sure that boxes with a custom allocator are never directly dereferenced.

2 years agoRollup merge of #95318 - rust-lang:notriddle/issue-95208, r=wesleywiser
Dylan DPC [Mon, 28 Mar 2022 18:41:50 +0000 (20:41 +0200)]
Rollup merge of #95318 - rust-lang:notriddle/issue-95208, r=wesleywiser

diagnostics: correct generic bounds with doubled colon

Fixes #95208

2 years agoRollup merge of #93787 - klensy:really-not-a-features, r=wesleywiser
Dylan DPC [Mon, 28 Mar 2022 18:41:49 +0000 (20:41 +0200)]
Rollup merge of #93787 - klensy:really-not-a-features, r=wesleywiser

parallel_compiler: hide dependencies behind feature

Separate dependencies for `parallel_compiler` feature, so they will not be compiled if feature not selected, reducing number of compiled crates from 238 to 224.

2 years agorebase fallout
Oli Scherer [Mon, 28 Mar 2022 17:22:42 +0000 (17:22 +0000)]
rebase fallout

2 years agoAdd test for revealing auto traits in the defining scope
Oli Scherer [Thu, 17 Mar 2022 14:27:21 +0000 (14:27 +0000)]
Add test for revealing auto traits in the defining scope