]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoRollup merge of #94045 - ehuss:update-books, r=ehuss
Matthias Krüger [Wed, 16 Feb 2022 17:59:35 +0000 (18:59 +0100)]
Rollup merge of #94045 - ehuss:update-books, r=ehuss

Update books

## nomicon

3 commits in 9493715a6280a1f74be759c7e1ef9999b5d13e6f..90993eeac93dbf9388992de92965f99cf6f29a03
2022-01-27 19:00:32 -0800 to 2022-02-13 12:44:12 +0900
- Fix a small typo in exception-safety.md (rust-lang/nomicon#341)
- Make `Vec::new` public in vec-alloc.md (rust-lang/nomicon#336)
- Fix a syntax error in leaking.md (rust-lang/nomicon#335)

## reference

6 commits in 411c2f0d5cebf48453ae2d136ad0c5e611d39aec..70fc73a6b908e08e66aa0306856c5211312f6c05
2022-01-30 12:46:37 -0800 to 2022-02-14 19:33:01 -0800
- Document pre-Rust-2021 special case for IntoIterator method lookup (rust-lang/reference#1154)
- Mention std::is_aarch64_feature_detected (rust-lang/reference#1061)
- Fix link to the Bastion of the Turbofish (rust-lang/reference#1161)
- Improve associated constant item CTFE timing section (rust-lang/reference#1147)
- document `#![feature(const_generics_defaults)]` (rust-lang/reference#1098)
- Update patterns allowed in @ patterns (rust-lang/reference#1158)

## book

6 commits in 98904efaa4fc968db8ff59cf2744d9f7ed158166..67b768c0b660a069a45f0e5d8ae2f679df1022ab
2022-01-29 21:22:31 -0500 to 2022-02-09 21:52:41 -0500
- Snapshot of ch18 for nostarch
- Remove mention of destructuring references as that's not covered currently
- Add note that exhaustiveness checking doesn't extend to match guards
- Change match guard example to actually be unexpressable with patterns alone
- Corrected listing number from 9-10 to 9-13
- Remove duplicate paragraph after No Starch related changes

## rustc-dev-guide

3 commits in 8763adb62c712df69b1d39ea3e692b6d696cc4d9..62f58394ba7b203f55ac35ddcc4c0b79578f5706
2022-01-26 14:01:40 -0800 to 2022-02-11 08:42:50 -0500
- Correction, building stage3 compiler (rust-lang/rustc-dev-guide#1298)
- Triage some date references (rust-lang/rustc-dev-guide#1293)
- mention test folders for cfg(bootstrap) (rust-lang/rustc-dev-guide#1294)

2 years agoRollup merge of #94037 - tmiasko:verbose, r=Mark-Simulacrum
Matthias Krüger [Wed, 16 Feb 2022 17:59:34 +0000 (18:59 +0100)]
Rollup merge of #94037 - tmiasko:verbose, r=Mark-Simulacrum

Fix inconsistent symbol mangling with -Zverbose

Always skip arguments that are the defaults of their respective
parameters, to avoid generating inconsistent symbols for builds
with `-Zverbose` flag and without it.

2 years agoRollup merge of #94027 - GuillaumeGomez:update-browser-ui-test, r=notriddle
Matthias Krüger [Wed, 16 Feb 2022 17:59:33 +0000 (18:59 +0100)]
Rollup merge of #94027 - GuillaumeGomez:update-browser-ui-test, r=notriddle

Update browser UI test version

Might help a bit with https://github.com/rust-lang/rust/issues/93784 (still need to figure out what's going on with the driver).

r? ```@notriddle```

2 years agoRollup merge of #94020 - tmiasko:pp, r=oli-obk
Matthias Krüger [Wed, 16 Feb 2022 17:59:32 +0000 (18:59 +0100)]
Rollup merge of #94020 - tmiasko:pp, r=oli-obk

Support pretty printing of invalid constants

Make it possible to pretty print invalid constants by introducing a
fallible variant of `destructure_const` and falling back to debug
formatting when it fails.

Closes #93688.

2 years agoRollup merge of #94017 - fee1-dead:unub, r=bjorn3
Matthias Krüger [Wed, 16 Feb 2022 17:59:31 +0000 (18:59 +0100)]
Rollup merge of #94017 - fee1-dead:unub, r=bjorn3

Clarify confusing UB statement in MIR

2 years agoRollup merge of #94015 - GuillaumeGomez:check-option, r=notriddle
Matthias Krüger [Wed, 16 Feb 2022 17:59:30 +0000 (18:59 +0100)]
Rollup merge of #94015 - GuillaumeGomez:check-option, r=notriddle

rustdoc --check option documentation

Part of #92763.

r? ```@notriddle```

2 years agoRollup merge of #93962 - joboet:branchless_slice_ord, r=Mark-Simulacrum
Matthias Krüger [Wed, 16 Feb 2022 17:59:29 +0000 (18:59 +0100)]
Rollup merge of #93962 - joboet:branchless_slice_ord, r=Mark-Simulacrum

Make [u8]::cmp implementation branchless

The current implementation generates rather ugly assembly code, branching when the common parts are equal. By performing the comparison of the lengths upfront using a subtraction, the assembly gets much prettier: https://godbolt.org/z/4e5fnEKGd.

This will probably not impact speed too much, as the expensive part is in most cases the `memcmp`, but it sure looks better (I'm porting a sorting algorithm currently, and that branch just bothered me).

2 years agoRollup merge of #93382 - GuillaumeGomez:search-input-padding, r=jsha
Matthias Krüger [Wed, 16 Feb 2022 17:59:28 +0000 (18:59 +0100)]
Rollup merge of #93382 - GuillaumeGomez:search-input-padding, r=jsha

Add a bit more padding in search box

As asked in https://github.com/rust-lang/rust/pull/93113#issuecomment-1021565703, here is a bit more padding.

You can check it [here](https://rustdoc.crud.net/imperio/search-input-padding/foo/index.html).

r? `@camelid`

2 years agoRollup merge of #92366 - jhpratt:derive-default-enum, r=Mark-Simulacrum
Matthias Krüger [Wed, 16 Feb 2022 17:59:27 +0000 (18:59 +0100)]
Rollup merge of #92366 - jhpratt:derive-default-enum, r=Mark-Simulacrum

Resolve concern of `derive_default_enum`

This resolves the concern in favor of prohibiting multiple instances of
the attribute. This is similar to non-helper attributes as introduced in
#88681.

``@rustbot`` label +S-waiting-on-review +T-libs-api

2 years agoAuto merge of #94044 - ehuss:update-cargo, r=ehuss
bors [Wed, 16 Feb 2022 12:51:41 +0000 (12:51 +0000)]
Auto merge of #94044 - ehuss:update-cargo, r=ehuss

Update cargo

5 commits in c082648646cbb2be266df9ecbcdc253058158d68..ea2a21c994ca1e4d4c49412827b3cf4dcb158b1d
2022-02-08 14:55:05 +0000 to 2022-02-15 04:24:07 +0000
- cargo-new should not add ignore rule on Cargo.lock inside subdirs (rust-lang/cargo#10379)
- Add a badge for github actions (rust-lang/cargo#10385)
- Remove outdated badges (rust-lang/cargo#10380)
- Remove `strip = "off"` (and undocumented `strip = "n"`/`strip = "no"`) (rust-lang/cargo#10376)
- Fix unmatched backticks (rust-lang/cargo#10375)

2 years agoUpdate cargo
Eric Huss [Wed, 16 Feb 2022 04:31:20 +0000 (20:31 -0800)]
Update cargo

2 years agoUpdate books
Eric Huss [Wed, 16 Feb 2022 04:17:31 +0000 (20:17 -0800)]
Update books

2 years agoAuto merge of #93800 - b-naber:static-initializers-mir-val, r=oli-obk
bors [Wed, 16 Feb 2022 03:03:03 +0000 (03:03 +0000)]
Auto merge of #93800 - b-naber:static-initializers-mir-val, r=oli-obk

Treat static refs as `mir::ConstantKind::Val`

With the upcoming introduction of Valtrees we want to treat more values as `mir::ConstantKind::Val` directly.

r? `@lcnr`

cc `@oli-obk`

2 years agoFix inconsistent symbol mangling with -Zverbose
Tomasz Miąsko [Wed, 16 Feb 2022 00:00:00 +0000 (00:00 +0000)]
Fix inconsistent symbol mangling with -Zverbose

Always skip arguments that are the defaults of their respective
parameters, to avoid generating inconsistent symbols for builds
with `-Zverbose` flag and without it.

2 years agoAuto merge of #94021 - tmiasko:inline, r=nagisa
bors [Tue, 15 Feb 2022 23:48:43 +0000 (23:48 +0000)]
Auto merge of #94021 - tmiasko:inline, r=nagisa

Inline a few trivial conversion functions

2 years agoSupport pretty printing of invalid constants
Tomasz Miąsko [Tue, 15 Feb 2022 12:58:34 +0000 (13:58 +0100)]
Support pretty printing of invalid constants

Make it possible to pretty print invalid constants by introducing a
fallible variant of `destructure_const` and falling back to debug
formatting when it fails.

2 years agotry to bless 32bit mir tests manually
b-naber [Mon, 14 Feb 2022 15:48:05 +0000 (16:48 +0100)]
try to bless 32bit mir tests manually

2 years agoAuto merge of #93439 - abrown:cf-protection, r=nagisa
bors [Tue, 15 Feb 2022 21:20:49 +0000 (21:20 +0000)]
Auto merge of #93439 - abrown:cf-protection, r=nagisa

Add support for control-flow protection

This change adds a flag for configuring control-flow protection in the LLVM backend. In Clang, this flag is exposed as `-fcf-protection` with options `none|branch|return|full`. This convention is followed for `rustc`, though as a codegen option: `rustc -Z cf-protection=<none|branch|return|full>`. Tracking issue for future work is #93754.

2 years agoAdd documentation for rustdoc --check option
Guillaume Gomez [Tue, 15 Feb 2022 10:48:41 +0000 (11:48 +0100)]
Add documentation for rustdoc --check option

2 years agoFix GUI test
Guillaume Gomez [Tue, 15 Feb 2022 19:54:52 +0000 (20:54 +0100)]
Fix GUI test

2 years agoUpdate browser-ui-test version
Guillaume Gomez [Tue, 15 Feb 2022 20:31:31 +0000 (21:31 +0100)]
Update browser-ui-test version

2 years agouse AllocId and Ty in ExprKind::StaticRef and delay ConstValue construction
b-naber [Wed, 9 Feb 2022 15:18:57 +0000 (16:18 +0100)]
use AllocId and Ty in ExprKind::StaticRef and delay ConstValue construction

2 years agobless mir-opt tests
b-naber [Wed, 9 Feb 2022 13:21:49 +0000 (14:21 +0100)]
bless mir-opt tests

2 years agouse mir::Visitor when collecting alloc_ids in pretty printing
b-naber [Wed, 9 Feb 2022 13:21:25 +0000 (14:21 +0100)]
use mir::Visitor when collecting alloc_ids in pretty printing

2 years agobless tests
b-naber [Wed, 9 Feb 2022 10:43:47 +0000 (11:43 +0100)]
bless tests

2 years agotreat mir::ConstantKind::Val correctly in check_static_ptr
b-naber [Wed, 9 Feb 2022 10:43:04 +0000 (11:43 +0100)]
treat mir::ConstantKind::Val correctly in check_static_ptr

2 years agouse ConstantKind::Val in StaticRef
b-naber [Tue, 8 Feb 2022 11:14:44 +0000 (12:14 +0100)]
use ConstantKind::Val in StaticRef

2 years agoAuto merge of #93820 - compiler-errors:gat-wfcheck, r=jackh726
bors [Tue, 15 Feb 2022 19:03:38 +0000 (19:03 +0000)]
Auto merge of #93820 - compiler-errors:gat-wfcheck, r=jackh726

Rework GAT `where` clause check

rework the GAT where check to use a fixed-point algorithm, and check all GATs in a trait at once

fixes #93278

r? `@jackh726`
cc `@nikomatsakis`

2 years agoInline LocalExpnId::from_raw and LocalExpnId::as_raw
Tomasz Miąsko [Tue, 15 Feb 2022 00:00:00 +0000 (00:00 +0000)]
Inline LocalExpnId::from_raw and LocalExpnId::as_raw

2 years agoInline Target::deref
Tomasz Miąsko [Sat, 12 Feb 2022 00:00:00 +0000 (00:00 +0000)]
Inline Target::deref

2 years agoInline GenericArg conversion functions
Tomasz Miąsko [Thu, 10 Feb 2022 00:00:00 +0000 (00:00 +0000)]
Inline GenericArg conversion functions

2 years agoInline UnifyKey::index and UnifyKey::from_index
Tomasz Miąsko [Thu, 10 Feb 2022 00:00:00 +0000 (00:00 +0000)]
Inline UnifyKey::index and UnifyKey::from_index

2 years agoAdd removed comments back in self-outlives-lint
Michael Goulet [Mon, 14 Feb 2022 17:08:06 +0000 (09:08 -0800)]
Add removed comments back in self-outlives-lint

2 years agoadd some more comments to GAT where clause check
Michael Goulet [Sat, 12 Feb 2022 22:55:53 +0000 (14:55 -0800)]
add some more comments to GAT where clause check

2 years agoadd test for issue-93278, bless
Michael Goulet [Wed, 9 Feb 2022 06:28:00 +0000 (22:28 -0800)]
add test for issue-93278, bless

2 years agomake the gat wfcheck algorithm a loop
Michael Goulet [Fri, 11 Feb 2022 08:17:22 +0000 (00:17 -0800)]
make the gat wfcheck algorithm a loop

2 years agocheck associated types too
Michael Goulet [Fri, 11 Feb 2022 08:11:49 +0000 (00:11 -0800)]
check associated types too

2 years agocheck all GATs at once
Michael Goulet [Fri, 11 Feb 2022 08:08:17 +0000 (00:08 -0800)]
check all GATs at once

2 years agorename some variables in gat wfcheck
Michael Goulet [Fri, 11 Feb 2022 07:42:28 +0000 (23:42 -0800)]
rename some variables in gat wfcheck

2 years agointroduce gather_gat_bounds
Michael Goulet [Fri, 11 Feb 2022 07:36:37 +0000 (23:36 -0800)]
introduce gather_gat_bounds

2 years agoAuto merge of #94024 - matthiaskrgr:rollup-0hwxm0w, r=matthiaskrgr
bors [Tue, 15 Feb 2022 16:48:26 +0000 (16:48 +0000)]
Auto merge of #94024 - matthiaskrgr:rollup-0hwxm0w, r=matthiaskrgr

Rollup of 5 pull requests

Successful merges:

 - #93899 (Describe VecDeque with more consistent names)
 - #93949 (Add basic platform support to library/{panic_}unwind for m68k)
 - #93999 (suggest using raw strings when invalid escapes appear in literals)
 - #94001 (llvm: migrate to new parameter-bearing uwtable attr)
 - #94014 (Move transmute_undefined_repr back to nursery)

Failed merges:

 - #94020 (Support pretty printing of invalid constants)

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

2 years agoRollup merge of #94014 - flip1995:clippy_transmute_lint_regroup, r=dtolnay
Matthias Krüger [Tue, 15 Feb 2022 15:02:37 +0000 (16:02 +0100)]
Rollup merge of #94014 - flip1995:clippy_transmute_lint_regroup, r=dtolnay

Move transmute_undefined_repr back to nursery

There's still open discussion if this lint is ready to be enabled by
default. We want to give us more time to figure this out and prevent
this lint from getting to stable as an enabled-by-default lint.

cc https://github.com/rust-lang/rust-clippy/pull/8432

r? `@Manishearth` `@dtolnay`

I think this is the way to go here. We can re-enable this lint with the next sync, if we should decide to do so. But I would hold of for this release.

We have until Friday (beta branching) to decide if we want to merge this.

2 years agoRollup merge of #94001 - durin42:llvm-15-uwtable, r=nikic
Matthias Krüger [Tue, 15 Feb 2022 15:02:37 +0000 (16:02 +0100)]
Rollup merge of #94001 - durin42:llvm-15-uwtable, r=nikic

llvm: migrate to new parameter-bearing uwtable attr

In https://reviews.llvm.org/D114543 the uwtable attribute gained a flag
so that we can ask for sync uwtables instead of async, as the former are
much cheaper. The default is async, so that's what I've done here, but I
left a TODO that we might be able to do better.

While in here I went ahead and dropped support for removing uwtable
attributes in rustc: we never did it, so I didn't write the extra C++
bridge code to make it work. Maybe I should have done the same thing
with the `sync|async` parameter but we'll see.

2 years agoRollup merge of #93999 - barzamin:suggest-raw-strings, r=jackh726
Matthias Krüger [Tue, 15 Feb 2022 15:02:35 +0000 (16:02 +0100)]
Rollup merge of #93999 - barzamin:suggest-raw-strings, r=jackh726

suggest using raw strings when invalid escapes appear in literals

i'd guess about 70% of "bad escape" cases occur when someone meant to use a raw string literal because they're passing it directly to `Regex::new()`.
this emits an advisory (`Applicability::MaybeIncorrect`) `help:` suggestion to the user that they use an `r""` string, on top of the normal notes about looking at the string literal documentation/spec.

2 years agoRollup merge of #93949 - glaubitz:m68k-unwind, r=Mark-Simulacrum
Matthias Krüger [Tue, 15 Feb 2022 15:02:35 +0000 (16:02 +0100)]
Rollup merge of #93949 - glaubitz:m68k-unwind, r=Mark-Simulacrum

Add basic platform support to library/{panic_}unwind for m68k

This PR adds basic platform support for m68k for library/{panic_}unwind for m68k.

Register information for UNWIND_DATA_REG has been extracted from LLVM.

2 years agoRollup merge of #93899 - ssomers:vecdeque_naming, r=m-ou-se
Matthias Krüger [Tue, 15 Feb 2022 15:02:34 +0000 (16:02 +0100)]
Rollup merge of #93899 - ssomers:vecdeque_naming, r=m-ou-se

Describe VecDeque with more consistent names

The public documentation of VecDeque starts describing itself as a "queue". In method descriptions, it's ~~never~~ sometimes named queue again, or `VecDeque` (IMO a sometimes useful and often noisy notation) or "deque" or "vector". In examples, `deque`, `v` (hidden in `range_mut`) or `vector`. Here is a subjective attempt at more consistency.

2 years agoAuto merge of #93148 - nnethercote:Uniq, r=fee1-dead
bors [Tue, 15 Feb 2022 11:59:37 +0000 (11:59 +0000)]
Auto merge of #93148 - nnethercote:Uniq, r=fee1-dead

Overhaul interning.

A number of types are interned and `eq` and `hash` are implemented on
the pointer rather than the contents. But this is not well enforced
within the type system like you might expect.

This PR introduces a new type `Interned` which encapsulates this concept
more rigorously, and uses it to convert a couple of the less common
interned types.

r? `@fee1-dead`

2 years agoClarify confusing UB statement in MIR
Deadbeef [Tue, 15 Feb 2022 11:22:37 +0000 (22:22 +1100)]
Clarify confusing UB statement in MIR

2 years agoClean up rustdoc command line args doc
Guillaume Gomez [Tue, 15 Feb 2022 10:46:52 +0000 (11:46 +0100)]
Clean up rustdoc command line args doc

2 years agoMove transmute_undefined_repr back to nursery
flip1995 [Tue, 15 Feb 2022 09:54:38 +0000 (10:54 +0100)]
Move transmute_undefined_repr back to nursery

There's still open discussion if this lint is ready to be enabled by
default. We want to give us more time to figure this out and prevent
this lint from getting to stable as an enabled-by-default lint.

2 years agoAuto merge of #93176 - danielhenrymantilla:stack-pinning-macro, r=m-ou-se
bors [Tue, 15 Feb 2022 09:32:03 +0000 (09:32 +0000)]
Auto merge of #93176 - danielhenrymantilla:stack-pinning-macro, r=m-ou-se

Add a stack-`pin!`-ning macro to `core::pin`.

  - https://github.com/rust-lang/rust/issues/93178

`pin!` allows pinning a value to the stack. Thanks to being implemented in the stdlib, which gives access to `macro` macros, and to the private `.pointer` field of the `Pin` wrapper, [it was recently discovered](https://rust-lang.zulipchat.com/#narrow/stream/187312-wg-async-foundations/topic/pin!.20.E2.80.94.20the.20.22definitive.22.20edition.20.28a.20rhs-compatible.20pin-nin.2E.2E.2E/near/268731241) ([archive link](https://zulip-archive.rust-lang.org/stream/187312-wg-async-foundations/topic/A.20rhs-compatible.20pin-ning.20macro.html#268731241)), contrary to popular belief, that it is actually possible to implement and feature such a macro:

```rust
let foo: Pin<&mut PhantomPinned> = pin!(PhantomPinned);
stuff(foo);
```
or, directly:

```rust
stuff(pin!(PhantomPinned));
```

  - For context, historically, this used to require one of the two following syntaxes:

      - ```rust
        let foo = PhantomPinned;
        pin!(foo);
        stuff(foo);
        ```

      -  ```rust
         pin! {
             let foo = PhantomPinned;
         }
         stuff(foo);
         ```

This macro thus allows, for instance, doing things like:

```diff
fn block_on<T>(fut: impl Future<Output = T>) -> T {
    // Pin the future so it can be polled.
-   let mut fut = Box::pin(fut);
+   let mut fut = pin!(fut);

    // Create a new context to be passed to the future.
    let t = thread::current();
    let waker = Arc::new(ThreadWaker(t)).into();
    let mut cx = Context::from_waker(&waker);

    // Run the future to completion.
    loop {
        match fut.as_mut().poll(&mut cx) {
            Poll::Ready(res) => return res,
            Poll::Pending => thread::park(),
        }
    }
}
```

  - _c.f._, https://doc.rust-lang.org/1.58.1/alloc/task/trait.Wake.html

And so on, and so forth.

I don't think such an API can get better than that, barring full featured language support (`&pin` references or something), so I see no reason not to start experimenting with featuring this in the stdlib already 🙂

  - cc `@rust-lang/wg-async-foundations` \[EDIT: this doesn't seem to have pinged anybody 😩, thanks `@yoshuawuyts` for the real ping\]

r? `@joshtriplett`

___

# Docs preview

https://user-images.githubusercontent.com/9920355/150605731-1f45c2eb-c9b0-4ce3-b17f-2784fb75786e.mp4

___

# Implementation

The implementation ends up being dead simple (so much it's embarrassing):

```rust
pub macro pin($value:expr $(,)?) {
    Pin { pointer: &mut { $value } }
}
```

_and voilà_!

  - The key for it working lies in [the rules governing the scope of anonymous temporaries](https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension).

<details><summary>Comments and context</summary>

This is `Pin::new_unchecked(&mut { $value })`, so, for starters, let's
review such a hypothetical macro (that any user-code could define):
```rust
macro_rules! pin {( $value:expr ) => (
    match &mut { $value } { at_value => unsafe { // Do not wrap `$value` in an `unsafe` block.
        $crate::pin::Pin::<&mut _>::new_unchecked(at_value)
    }}
)}
```

Safety:
  - `type P = &mut _`. There are thus no pathological `Deref{,Mut}` impls that would break `Pin`'s invariants.
  - `{ $value }` is braced, making it a _block expression_, thus **moving** the given `$value`, and making it _become an **anonymous** temporary_.
    By virtue of being anonynomous, it can no longer be accessed, thus preventing any attemps to `mem::replace` it or `mem::forget` it, _etc._

This gives us a `pin!` definition that is sound, and which works, but only in certain scenarios:

  - If the `pin!(value)` expression is _directly_ fed to a function call:
    `let poll = pin!(fut).poll(cx);`

  - If the `pin!(value)` expression is part of a scrutinee:

    ```rust
    match pin!(fut) { pinned_fut => {
        pinned_fut.as_mut().poll(...);
        pinned_fut.as_mut().poll(...);
    }} // <- `fut` is dropped here.
    ```

Alas, it doesn't work for the more straight-forward use-case: `let` bindings.

```rust
let pinned_fut = pin!(fut); // <- temporary value is freed at the end of this statement
pinned_fut.poll(...) // error[E0716]: temporary value dropped while borrowed
                     // note: consider using a `let` binding to create a longer lived value
```

  - Issues such as this one are the ones motivating https://github.com/rust-lang/rfcs/pull/66

This makes such a macro incredibly unergonomic in practice, and the reason most macros out there had to take the path of being a statement/binding macro (_e.g._, `pin!(future);`) instead of featuring the more intuitive ergonomics of an expression macro.

Luckily, there is a way to avoid the problem. Indeed, the problem stems from the fact that a temporary is dropped at the end of its enclosing statement when it is part of the parameters given to function call, which has precisely been the case with our `Pin::new_unchecked()`!

For instance,

```rust
let p = Pin::new_unchecked(&mut <temporary>);
```

becomes:

```rust
let p = { let mut anon = <temporary>; &mut anon };
```

However, when using a literal braced struct to construct the value, references to temporaries can then be taken. This makes Rust change the lifespan of such temporaries so that they are, instead, dropped _at the end of the enscoping block_.

For instance,
```rust
let p = Pin { pointer: &mut <temporary> };
```

becomes:

```rust
let mut anon = <temporary>;
let p = Pin { pointer: &mut anon };
```

which is *exactly* what we want.

Finally, we don't hit problems _w.r.t._ the privacy of the `pointer` field, or the unqualified `Pin` name, thanks to `decl_macro`s being _fully_ hygienic (`def_site` hygiene).

</details>

___

# TODO

  - [x] Add compile-fail tests with attempts to break the `Pin` invariants thanks to the macro (_e.g._, try to access the private `.pointer` field, or see what happens if such a pin is used outside its enscoping scope (borrow error));
  - [ ] Follow-up stuff:
      - [ ] Try to experiment with adding `pin!` to the prelude: this may require to be handled with some extra care, as it may lead to issues reminiscent of those of `assert_matches!`: https://github.com/rust-lang/rust/issues/82913
      - [x] Create the tracking issue.

2 years agoAuto merge of #93918 - jonhoo:bootstrap-native-envflags, r=Mark-Simulacrum
bors [Tue, 15 Feb 2022 07:04:10 +0000 (07:04 +0000)]
Auto merge of #93918 - jonhoo:bootstrap-native-envflags, r=Mark-Simulacrum

bootstrap: tidy up flag handling for llvm build

This tidies up the logic in `src/bootstrap/native.rs` such that:

 - `CMAKE_*_LINKER_FLAGS` is not overridden if we add to it twice.
 - `CMAKE_*_FLAGS` also include the standard `*FLAGS` environment
   variables, which CMake respects when we _don't_ set `CMAKE_*_FLAGS`.
 - `llvm.ldflags` from `config.toml` appends to the ldflags Rust's
   bootstrap logic adds, rather than replacing them.

It also takes a second stab at #89983 by moving `-static-libstdc++` to just be passed as a linker flag, since that's what it is.

Fixes #93880. Fixes #70468. Closes #89983.

2 years agoAddress review comments.
Nicholas Nethercote [Tue, 8 Feb 2022 03:12:29 +0000 (14:12 +1100)]
Address review comments.

2 years agoOverhaul `Const`.
Nicholas Nethercote [Wed, 2 Feb 2022 03:24:45 +0000 (14:24 +1100)]
Overhaul `Const`.

Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as
this:
```
pub struct Const<'tcx>(&'tcx Interned<ConstS>);
```
This now matches `Ty` and `Predicate` more closely, including using
pointer-based `eq` and `hash`.

Notable changes:
- `mk_const` now takes a `ConstS`.
- `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a
  we need separate arena for it, because we can't use the `Dropless` one any
  more.
- Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes
- Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes.
- Lots of tedious sigil fiddling.

2 years agoRemove unnecessary `RegionKind::` quals.
Nicholas Nethercote [Tue, 1 Feb 2022 01:57:04 +0000 (12:57 +1100)]
Remove unnecessary `RegionKind::` quals.

The variant names are exported, so we can use them directly (possibly
with a `ty::` qualifier). Lots of places already do this, this commit
just increases consistency.

2 years agoOverhaul `RegionKind` and `Region`.
Nicholas Nethercote [Fri, 28 Jan 2022 00:25:15 +0000 (11:25 +1100)]
Overhaul `RegionKind` and `Region`.

Specifically, change `Region` from this:
```
pub type Region<'tcx> = &'tcx RegionKind;
```
to this:
```
pub struct Region<'tcx>(&'tcx Interned<RegionKind>);
```

This now matches `Ty` and `Predicate` more closely.

Things to note
- Regions have always been interned, but we haven't been using pointer-based
  `Eq` and `Hash`. This is now happening.
- I chose to impl `Deref` for `Region` because it makes pattern matching a lot
  nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`.
- Various methods are moved from `RegionKind` to `Region`.
- There is a lot of tedious sigil changes.
- A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a
  `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`.
- A couple of test outputs change slightly, I'm not sure why, but the new
  outputs are a little better.

2 years agoOverhaul `PredicateInner` and `Predicate`.
Nicholas Nethercote [Thu, 27 Jan 2022 06:00:16 +0000 (17:00 +1100)]
Overhaul `PredicateInner` and `Predicate`.

Specifically, change `Ty` from this:
```
pub struct Predicate<'tcx> { inner: &'tcx PredicateInner<'tcx> }
```
to this:
```
pub struct Predicate<'tcx>(&'tcx Interned<PredicateS<'tcx>>)
```
where `PredicateInner` is renamed as `PredicateS`.

 This (plus a few other minor changes) makes the parallels with `Ty` and
`TyS` much clearer, and makes the uniqueness more explicit.

2 years agoOverhaul `TyS` and `Ty`.
Nicholas Nethercote [Tue, 25 Jan 2022 03:13:38 +0000 (14:13 +1100)]
Overhaul `TyS` and `Ty`.

Specifically, change `Ty` from this:
```
pub type Ty<'tcx> = &'tcx TyS<'tcx>;
```
to this
```
pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>);
```
There are two benefits to this.
- It's now a first class type, so we can define methods on it. This
  means we can move a lot of methods away from `TyS`, leaving `TyS` as a
  barely-used type, which is appropriate given that it's not meant to
  be used directly.
- The uniqueness requirement is now explicit, via the `Interned` type.
  E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather
  than via `TyS`, which wasn't obvious at all.

Much of this commit is boring churn. The interesting changes are in
these files:
- compiler/rustc_middle/src/arena.rs
- compiler/rustc_middle/src/mir/visit.rs
- compiler/rustc_middle/src/ty/context.rs
- compiler/rustc_middle/src/ty/mod.rs

Specifically:
- Most mentions of `TyS` are removed. It's very much a dumb struct now;
  `Ty` has all the smarts.
- `TyS` now has `crate` visibility instead of `pub`.
- `TyS::make_for_test` is removed in favour of the static `BOOL_TY`,
  which just works better with the new structure.
- The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls
  of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned`
  (pointer-based, for the `Equal` case) and partly on `TyS`
  (contents-based, for the other cases).
- There are many tedious sigil adjustments, i.e. adding or removing `*`
  or `&`. They seem to be unavoidable.

2 years agoRename `PtrKey` as `Interned` and improve it.
Nicholas Nethercote [Fri, 4 Feb 2022 03:26:29 +0000 (14:26 +1100)]
Rename `PtrKey` as `Interned` and improve it.

In particular, there's now more protection against incorrect usage,
because you can only create one via `Interned::new_unchecked`, which
makes it more obvious that you must be careful.

There are also some tests.

2 years agoRename `Interned` as `InternedInSet`.
Nicholas Nethercote [Fri, 4 Feb 2022 03:27:17 +0000 (14:27 +1100)]
Rename `Interned` as `InternedInSet`.

This will let us introduce a more widely-used `Interned` type in the
next commit.

2 years agoAuto merge of #93863 - pierwill:fix-93676, r=Mark-Simulacrum
bors [Tue, 15 Feb 2022 04:39:37 +0000 (04:39 +0000)]
Auto merge of #93863 - pierwill:fix-93676, r=Mark-Simulacrum

Update `sha1`, `sha2`, and `md-5` dependencies

This replaces the deprecated [`cpuid-bool`](https://crates.io/crates/cpuid-bool) dependency with [`cpufeatures`](https://crates.io/crates/cpufeatures), while adding [`crypto-common`](https://crates.io/crates/crypto-common) as a new dependency.

Closes #93676.

2 years agoAuto merge of #93752 - eholk:drop-tracking-break-continue, r=nikomatsakis
bors [Tue, 15 Feb 2022 02:27:37 +0000 (02:27 +0000)]
Auto merge of #93752 - eholk:drop-tracking-break-continue, r=nikomatsakis

Generator drop tracking: improve break and continue handling

This PR fixes two related issues.

One, sometimes break or continue have a block target instead of an expression target. This seems to mainly happen with try blocks. Since the drop tracking analysis only works on expressions, if we see a block target for break or continue, we substitute the last expression of the block as the target instead.

Two, break and continue were incorrectly being treated as the same, so continue would also show up as an exit from the loop or block. This patch corrects the way continue is handled by keeping a stack of loop entry points and uses those to find the target of the continue.

Fixes #93197

r? `@nikomatsakis`

2 years agoMake [u8]::cmp implementation branchless
joboet [Sun, 13 Feb 2022 12:19:18 +0000 (13:19 +0100)]
Make [u8]::cmp implementation branchless

2 years agollvm: migrate to new parameter-bearing uwtable attr
Augie Fackler [Mon, 14 Feb 2022 19:01:19 +0000 (14:01 -0500)]
llvm: migrate to new parameter-bearing uwtable attr

In https://reviews.llvm.org/D114543 the uwtable attribute gained a flag
so that we can ask for sync uwtables instead of async, as the former are
much cheaper. The default is async, so that's what I've done here, but I
left a TODO that we might be able to do better.

While in here I went ahead and dropped support for removing uwtable
attributes in rustc: we never did it, so I didn't write the extra C++
bridge code to make it work. Maybe I should have done the same thing
with the `sync|async` parameter but we'll see.

2 years agosuggest using raw string literals when invalid escapes appear
Erin Petra Sofiya Moon [Mon, 14 Feb 2022 19:21:43 +0000 (14:21 -0500)]
suggest using raw string literals when invalid escapes appear

i'd guess about 70% of "bad escape" cases occur when someone meant to
use a raw string literal because they're passing it directly to
Regex::new(). this emits an advisory (Applicability::MaybeIncorrect)
help: suggestion to the user that they use an r"" string,
on top of the normal notes about looking at the
string literal documentation/spec.

2 years agoUpdate unsafe_pin_internals unstable version.
Mara Bos [Mon, 14 Feb 2022 19:17:21 +0000 (19:17 +0000)]
Update unsafe_pin_internals unstable version.

2 years agoAuto merge of #93652 - spastorino:fix-negative-overlap-check-regions, r=nikomatsakis
bors [Mon, 14 Feb 2022 18:28:04 +0000 (18:28 +0000)]
Auto merge of #93652 - spastorino:fix-negative-overlap-check-regions, r=nikomatsakis

Fix negative overlap check regions

r? `@nikomatsakis`

2 years agoAdd a comment to justify why the `pointer` field is `pub`.
Daniel Henry-Mantilla [Mon, 14 Feb 2022 16:35:27 +0000 (17:35 +0100)]
Add a comment to justify why the `pointer` field is `pub`.

Addresses https://github.com/rust-lang/rust/pull/93176/files#r795258110.

2 years agoAdd support for control-flow protection
Andrew Brown [Fri, 28 Jan 2022 17:48:59 +0000 (09:48 -0800)]
Add support for control-flow protection

This change adds a flag for configuring control-flow protection in the
LLVM backend. In Clang, this flag is exposed as `-fcf-protection` with
options `none|branch|return|full`. This convention is followed for
`rustc`, though as a codegen option: `rustc -Z
cf-protection=<none|branch|return|full>`.

Co-authored-by: BlackHoleFox <blackholefoxdev@gmail.com>
2 years agoMark `unsafe_pin_internals` as `incomplete`.
Daniel Henry-Mantilla [Mon, 24 Jan 2022 00:34:46 +0000 (01:34 +0100)]
Mark `unsafe_pin_internals` as `incomplete`.

This thus still makes it technically possible to enable the feature, and thus
to trigger UB without `unsafe`, but this is fine since incomplete features are
known to be potentially unsound (labelled "may not be safe").

This follows from the discussion at https://github.com/rust-lang/rust/pull/93176#discussion_r799413561

2 years agoReplace `def_site`-&-privacy implementation with a stability-based one.
Daniel Henry-Mantilla [Sat, 22 Jan 2022 20:07:00 +0000 (21:07 +0100)]
Replace `def_site`-&-privacy implementation with a stability-based one.

Since `decl_macro`s and/or `Span::def_site()` is deemed quite unstable,
no public-facing macro that relies on it can hope to be, itself, stabilized.

We circumvent the issue by no longer relying on field privacy for safety and,
instead, relying on an unstable feature-gate to act as the gate keeper for
non users of the macro (thanks to `allow_internal_unstable`).

This is technically not correct (since a `nightly` user could technically enable
the feature and cause unsoundness with it); or, in other words, this makes the
feature-gate used to gate the access to the field be (technically unsound, and
in practice) `unsafe`. Hence it having `unsafe` in its name.

Back to the macro, we go back to `macro_rules!` / `mixed_site()`-span rules thanks
to declaring the `decl_macro` as `semitransparent`, which is a hack to basically have
`pub macro_rules!`

Co-Authored-By: Mara Bos <m-ou.se@m-ou.se>
2 years agoImprove documentation.
Daniel Henry-Mantilla [Sat, 22 Jan 2022 13:47:49 +0000 (14:47 +0100)]
Improve documentation.

Co-Authored-By: Mara Bos <m-ou.se@m-ou.se>
2 years agoreveal_defining_opaque_types field doesn't exist after rebase
Santiago Pastorino [Mon, 14 Feb 2022 16:02:22 +0000 (13:02 -0300)]
reveal_defining_opaque_types field doesn't exist after rebase

2 years agoInline loose_check fn on call site
Santiago Pastorino [Thu, 10 Feb 2022 19:39:52 +0000 (16:39 -0300)]
Inline loose_check fn on call site

2 years agoAdd comments about outlives_env
Santiago Pastorino [Thu, 10 Feb 2022 19:38:27 +0000 (16:38 -0300)]
Add comments about outlives_env

2 years agoAdd failing test that should pass
Santiago Pastorino [Thu, 10 Feb 2022 14:55:23 +0000 (11:55 -0300)]
Add failing test that should pass

2 years agoCall the method fork instead of clone and add proper comments
Santiago Pastorino [Wed, 9 Feb 2022 22:37:10 +0000 (19:37 -0300)]
Call the method fork instead of clone and add proper comments

2 years agoUpdate `macro:print` typed-query rustdoc test to include `pin!` results
Daniel Henry-Mantilla [Mon, 31 Jan 2022 16:48:47 +0000 (17:48 +0100)]
Update `macro:print` typed-query rustdoc test to include `pin!` results

2 years agoWrite {ui,} tests for `pin_macro` and `pin!`
Daniel Henry-Mantilla [Mon, 24 Jan 2022 00:41:37 +0000 (01:41 +0100)]
Write {ui,} tests for `pin_macro` and `pin!`

2 years agoAdd a stack-`pin!`-ning macro to the `pin` module.
Daniel Henry-Mantilla [Fri, 21 Jan 2022 15:28:23 +0000 (16:28 +0100)]
Add a stack-`pin!`-ning macro to the `pin` module.

Add a type annotation to improve error messages with type mismatches

Add a link to the temporary-lifetime-extension section of the reference

2 years agoProperly check regions on negative overlap check
Santiago Pastorino [Wed, 2 Feb 2022 17:36:45 +0000 (14:36 -0300)]
Properly check regions on negative overlap check

2 years agoAdd debug calls for negative impls in coherence
Santiago Pastorino [Fri, 4 Feb 2022 01:40:29 +0000 (22:40 -0300)]
Add debug calls for negative impls in coherence

2 years agoMove FIXME text to the right place
Santiago Pastorino [Wed, 2 Feb 2022 17:38:39 +0000 (14:38 -0300)]
Move FIXME text to the right place

2 years agoRemove extra negative_impl_exists check
Santiago Pastorino [Wed, 2 Feb 2022 17:32:21 +0000 (14:32 -0300)]
Remove extra negative_impl_exists check

2 years agoAuto merge of #93298 - lcnr:issue-92113, r=cjgillot
bors [Mon, 14 Feb 2022 14:47:20 +0000 (14:47 +0000)]
Auto merge of #93298 - lcnr:issue-92113, r=cjgillot

make `find_similar_impl_candidates` even fuzzier

continues the good work of `@BGR360` in #92223. I might have overshot a bit and we're now slightly too fuzzy :sweat_smile:

with this we can now also simplify `simplify_type`, which is nice :3

2 years agoAuto merge of #93938 - BoxyUwU:fix_res_self_ty, r=lcnr
bors [Mon, 14 Feb 2022 12:26:43 +0000 (12:26 +0000)]
Auto merge of #93938 - BoxyUwU:fix_res_self_ty, r=lcnr

Make `Res::SelfTy` a struct variant and update docs

I found pattern matching on a `(Option<DefId>, Option<(DefId, bool)>)` to not be super readable, additionally the doc comments on the types in a tuple variant aren't visible anywhere at use sites as far as I can tell (using rust analyzer + vscode)

The docs incorrectly assumed that the `DefId` in `Option<(DefId, bool)>` would only ever be for an impl item and I also found the code examples to be somewhat unclear about which `DefId` was being talked about.

r? `@lcnr` since you reviewed the last PR changing these docs

2 years agoupdate two rustdoc comments
Ellen [Mon, 14 Feb 2022 11:27:30 +0000 (11:27 +0000)]
update two rustdoc comments

2 years agoDescribe VecDeque with more consistent names
Stein Somers [Fri, 11 Feb 2022 10:55:46 +0000 (11:55 +0100)]
Describe VecDeque with more consistent names

2 years agofurther update `fuzzy_match_tys`
lcnr [Fri, 11 Feb 2022 15:12:22 +0000 (16:12 +0100)]
further update `fuzzy_match_tys`

2 years agofast_reject: remove `StripReferences`
lcnr [Tue, 25 Jan 2022 11:50:00 +0000 (12:50 +0100)]
fast_reject: remove `StripReferences`

2 years agofuzzify `fuzzy_match_tys`
lcnr [Tue, 25 Jan 2022 11:09:01 +0000 (12:09 +0100)]
fuzzify `fuzzy_match_tys`

2 years agoMake `find_similar_impl_candidates` a little fuzzier.
Ben Reeves [Thu, 23 Dec 2021 08:31:04 +0000 (02:31 -0600)]
Make `find_similar_impl_candidates` a little fuzzier.

2 years agoAuto merge of #93937 - bjorn3:simplifications3, r=cjgillot
bors [Mon, 14 Feb 2022 05:55:26 +0000 (05:55 +0000)]
Auto merge of #93937 - bjorn3:simplifications3, r=cjgillot

Remove Config::stderr

1. It captured stdout and not stderr
2. It isn't used anywhere
3. All error messages should go to the DiagnosticOutput instead
4. It modifies thread local state

Marking as blocked as it will conflict a bit with https://github.com/rust-lang/rust/pull/93936.

2 years agoUpdate `sha1`, `sha2`, and `md5` dependencies
pierwill [Thu, 10 Feb 2022 16:54:01 +0000 (10:54 -0600)]
Update `sha1`, `sha2`, and `md5` dependencies

This removes the `cpuid-bool` dependency, which is deprecated,
while adding `crypto-common` as a new dependency.

2 years agoAuto merge of #83822 - petrochenkov:linkandro, r=davidtwco
bors [Sun, 13 Feb 2022 20:46:42 +0000 (20:46 +0000)]
Auto merge of #83822 - petrochenkov:linkandro, r=davidtwco

rustc_target: Remove compiler-rt linking hack on Android

`compiler-rt` did some significant work last year trying to eliminate this kind of duplicated symbols, so the flag may be no longer necessary.
Tested locally with AArch64 Android, seems to work, CI will check the rest of the targets.

2 years agoAuto merge of #93837 - nikic:arm-update, r=Mark-Simulacrum
bors [Sun, 13 Feb 2022 17:41:31 +0000 (17:41 +0000)]
Auto merge of #93837 - nikic:arm-update, r=Mark-Simulacrum

Update dist-(arm|armv7|armhf)-linux to Ubuntu 20.04

I believe this should be safe, as actual artifacts will be produced by a cross toolchain. The build ran through cleanly locally.

This came up in https://github.com/rust-lang/rust/pull/93577, where the host GCC ICEd during the LLD build. (Though I wonder why we build LLD for the host at all...)

r? `@Mark-Simulacrum`

2 years agoAuto merge of #93685 - Mark-Simulacrum:drop-time, r=Mark-Simulacrum
bors [Sun, 13 Feb 2022 15:12:21 +0000 (15:12 +0000)]
Auto merge of #93685 - Mark-Simulacrum:drop-time, r=Mark-Simulacrum

Drop time dependency from bootstrap

This was only used for the inclusion of 'current' dates into our manpages, but
it is not clear that this is practically necessary. The manpage is essentially
never updated, and so we can likely afford to keep a manual date in these files.
It also seems possible to just omit it, but that may cause other tools trouble,
so avoid doing that for now.

This is largely done to reduce bootstrap complexity; the time crate is not particularly
small and in #92480 would have started pulling in num-threads, which does runtime
thread count detection. I would prefer to avoid that, so filing this to just drop the nearly
unused dependency entirely.

r? `@pietroalbini`

2 years agorustc_target: Remove compiler-rt linking hack on Android
Vadim Petrochenkov [Sat, 3 Apr 2021 18:39:25 +0000 (21:39 +0300)]
rustc_target: Remove compiler-rt linking hack on Android

2 years agoAuto merge of #91673 - ChrisDenton:path-absolute, r=Mark-Simulacrum
bors [Sun, 13 Feb 2022 12:03:52 +0000 (12:03 +0000)]
Auto merge of #91673 - ChrisDenton:path-absolute, r=Mark-Simulacrum

`std::path::absolute`

Implements #59117 by adding a `std::path::absolute` function that creates an absolute path without reading the filesystem. This is intended to be a drop-in replacement for [`std::fs::canonicalize`](https://doc.rust-lang.org/std/fs/fn.canonicalize.html) in cases where it isn't necessary to resolve symlinks. It can be used on paths that don't exist or where resolving symlinks is unwanted. It can also be used to avoid circumstances where `canonicalize` might otherwise fail.

On Windows this is a wrapper around [`GetFullPathNameW`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew). On Unix it partially implements the POSIX [pathname resolution](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13) specification, stopping just short of actually resolving symlinks.

2 years agoRemove Config::stderr
bjorn3 [Fri, 25 Jun 2021 10:58:21 +0000 (12:58 +0200)]
Remove Config::stderr

1. It captured stdout and not stderr
2. It isn't used anywhere
3. All error messages should go to the DiagnosticOutput instead
4. It modifies thread local state