Commit Graph

216414 Commits

Author SHA1 Message Date
Dylan DPC
d9db35785d
Rollup merge of #107539 - PossiblyAShrub:unused-parens-in-index, r=lcnr
Emit warnings on unused parens in index expressions

Fixes: #96606.

I am not sure what the best term for "index expression" is. Is there a better term we could use?
2023-02-03 23:04:51 +05:30
Dylan DPC
e1bf3a1386
Rollup merge of #107427 - detrumi:builtin-impl-candidates, r=compiler-errors
Add candidates for DiscriminantKind builtin

Part of #107379
2023-02-03 23:04:50 +05:30
Dylan DPC
72213832f6
Rollup merge of #107082 - dtolnay:autotraits, r=lcnr
Autotrait bounds on dyn-safe trait methods

This PR is a successor to #106604 implementing the approach encouraged by https://github.com/rust-lang/rust/pull/106604#issuecomment-1387353737.

**I propose making it legal to use autotraits as trait bounds on the `Self` type of trait methods in a trait object.** https://github.com/rust-lang/rust/issues/51443#issuecomment-1374847313 justifies why this use case is particularly important in the context of the async-trait crate.

```rust
#![feature(auto_traits)]
#![deny(where_clauses_object_safety)]

auto trait AutoTrait {}

trait MyTrait {
    fn f(&self) where Self: AutoTrait;
}

fn main() {
    let _: &dyn MyTrait;
}
```

Previously this would fail with:

```console
error: the trait `MyTrait` cannot be made into an object
 --> src/main.rs:7:8
  |
7 |     fn f(&self) where Self: AutoTrait;
  |        ^
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
 --> src/main.rs:7:8
  |
6 | trait MyTrait {
  |       ------- this trait cannot be made into an object...
7 |     fn f(&self) where Self: AutoTrait;
  |        ^ ...because method `f` references the `Self` type in its `where` clause
  = help: consider moving `f` to another trait
```

In order for this to be sound without hitting #50781, **I further propose that we disallow handwritten autotrait impls that apply to trait objects.** Both of the following were previously allowed (_on nightly_) and no longer allowed in my proposal:

```rust
auto trait AutoTrait {}

trait MyTrait {}
impl AutoTrait for dyn MyTrait {}  // NOT ALLOWED

impl<T: ?Sized> AutoTrait for T {}  // NOT ALLOWED
```

(`impl<T> AutoTrait for T {}` remains allowed.)

After this change, traits with a default impl are implemented for a trait object **if and only if** the autotrait is one of the trait object's trait bounds (or a supertrait of a bound). In other words `dyn Trait + AutoTrait` always implements AutoTrait while `dyn Trait` never implements AutoTrait.

Fixes https://github.com/dtolnay/async-trait/issues/228.

r? `@lcnr`
2023-02-03 23:04:49 +05:30
David Tolnay
4501d3abe1
Autotrait bounds on dyn-safe trait methods 2023-02-03 08:33:40 -08:00
David Tolnay
9e1c600f74
Disallow impl autotrait for trait object 2023-02-03 08:33:40 -08:00
bors
a94b9fd0ac Auto merge of #107569 - petrochenkov:optattr, r=nnethercote
ast: Optimize list and value extraction primitives for attributes

It's not necessary to convert the whole attribute into a meta item to extract something specific.
2023-02-03 11:19:03 +00:00
Wilco Kusee
f29000eba9 Use new helper inside probe 2023-02-03 10:04:15 +01:00
bors
7c46fb2111 Auto merge of #107625 - matthiaskrgr:rollup-xr9oldy, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #106575 (Suggest `move` in nested closure when appropriate)
 - #106805 (Suggest `{var:?}` when finding `{?:var}` in inline format strings)
 - #107500 (Add tests to assert current behavior of large future sizes)
 - #107598 (Fix benchmarks in library/core with black_box)
 - #107602 (Parse and recover from type ascription in patterns)
 - #107608 (Use triple rather than arch for fuchsia test-runner)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-03 08:07:47 +00:00
Matthias Krüger
b6e8ebf33b
Rollup merge of #107608 - P1n3appl3:master, r=tmandry
Use triple rather than arch for fuchsia test-runner

This allows the user of the test-runner script to specify a full triple rather than just an architecture which helps with the transition from the two component to three component target triples for fuchsia.
2023-02-03 06:30:25 +01:00
Matthias Krüger
743ca67edf
Rollup merge of #107602 - estebank:anon-enum-access, r=compiler-errors
Parse and recover from type ascription in patterns

Reintroduce part of #106960, which was reverted in #107478.

r? `@compiler-errors`
2023-02-03 06:30:24 +01:00
Matthias Krüger
86015515b5
Rollup merge of #107598 - chenyukang:yukang/fix-core-bench, r=thomcc
Fix benchmarks in library/core with black_box

Fixes #107590
2023-02-03 06:30:24 +01:00
Matthias Krüger
22aa680c44
Rollup merge of #107500 - bryangarza:future-sizes-baseline-test, r=compiler-errors
Add tests to assert current behavior of large future sizes

Based on a couple of sources:
- https://swatinem.de/blog/future-size/
- https://github.com/rust-lang/rust/issues/62958
2023-02-03 06:30:23 +01:00
Matthias Krüger
2fdb3559c4
Rollup merge of #106805 - madsravn:master, r=compiler-errors
Suggest `{var:?}` when finding `{?:var}` in inline format strings

Link to issue: https://github.com/rust-lang/rust/issues/106572

This is my first PR to this project, so hopefully I can get some good pointers with me from the first PR.

Currently my idea was to test out whether or not this is the correct solution to this issue and then hopefully expand upon the idea to not only work for Debug formatting but for all of  them. If this is a valid solution, I will create a new issue to give a better error message to a broader range of wrong-order formatting.
2023-02-03 06:30:23 +01:00
Matthias Krüger
6b94f4dccc
Rollup merge of #106575 - estebank:issue-64008, r=pnkfelix
Suggest `move` in nested closure when appropriate

Fix #64008.
2023-02-03 06:30:22 +01:00
bors
5d32458343 Auto merge of #107543 - ehuss:protocol-sparse, r=jyn514
Enable Cargo's sparse protocol in CI

This enables the sparse protocol in CI in order to exercise and dogfood it. This is intended test the production server in a real-world situation.

Closes #107342
2023-02-03 04:49:50 +00:00
bors
f02439dea7 Auto merge of #107241 - clubby789:bootstrap-lto-off, r=simulacrum
Add `rust.lto=off` to bootstrap and set as compiler/library default

Closes #107202

The issue mentions `embed-bitcode=on`, but here c8e6a9e8b6/src/bootstrap/compile.rs (L379-L381)
it appears that this is always set for std stage 1+, so I'm unsure if changes are needed here.

`@rustbot` label +A-bootstrap
2023-02-03 01:19:04 +00:00
Joseph Ryan
eb5e9713b5 Use triple rather than arch for fuchsia test runner 2023-02-02 13:29:03 -08:00
bors
6c991b0740 Auto merge of #107000 - GuillaumeGomez:fix-items-in-doc-hidden-block, r=notriddle,petrochenkov
Fix handling of items inside a `doc(hidden)` block

Fixes #106373.

cc `@aDotInTheVoid`
r? `@notriddle`
2023-02-02 21:14:44 +00:00
Aidan Olsen
c3a71ede7c Emit warnings on unused parens/braces in index expressions 2023-02-02 12:46:31 -07:00
bors
f3126500f2 Auto merge of #107601 - matthiaskrgr:rollup-07zaafe, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #106919 (Recover `_` as `..` in field pattern)
 - #107493 (Improve diagnostic for missing space in range pattern)
 - #107515 (Improve pretty-printing of `HirIdValidator` errors)
 - #107524 (Remove both StorageLive and StorageDead in CopyProp.)
 - #107532 (Erase regions before doing uninhabited check in borrowck)
 - #107559 (Rename `rust_2015` → `is_rust_2015`)
 - #107577 (Reinstate the `hir-stats.rs` tests on stage 1.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-02 17:56:53 +00:00
Esteban Küber
0ba687a95e Parse and recover from type ascription in patterns 2023-02-02 17:18:48 +00:00
yukang
fe84cecf60 fix #107590, Fix benchmarks in library/core with black_box 2023-02-03 00:33:36 +08:00
Esteban Küber
e6b84eb797 Suggest move in nested closure when appropriate
Fix #64008.
2023-02-02 16:26:01 +00:00
Matthias Krüger
08181eabfe
Rollup merge of #107577 - nnethercote:reinstate-hir-stats, r=jyn514
Reinstate the `hir-stats.rs` tests on stage 1.

r? ```@the8472```
2023-02-02 17:14:08 +01:00
Matthias Krüger
3d92100955
Rollup merge of #107559 - WaffleLapkin:is_it_2015¿, r=davidtwco
Rename `rust_2015` → `is_rust_2015`

r? ```@compiler-errors```
https://github.com/rust-lang/rust/pull/107508#discussion_r1092300088
2023-02-02 17:14:08 +01:00
Matthias Krüger
3e0995a440
Rollup merge of #107532 - compiler-errors:erase-regions-in-uninhabited, r=jackh726
Erase regions before doing uninhabited check in borrowck

~Also, fingerprint query keys/values when debug assertions are enabled. This should make it easier to check for issues like this without `-Cincremental`, and make UI tests a bit cleaner.~ edit: moving that to a separate PR

Fixes #107505
2023-02-02 17:14:07 +01:00
Matthias Krüger
6917040cf0
Rollup merge of #107524 - cjgillot:both-storage, r=RalfJung
Remove both StorageLive and StorageDead in CopyProp.

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

https://github.com/rust-lang/rust/pull/106908 removed StorageDead without the accompanying StorageLive. In loops, execution would see repeated StorageLive, without any StorageDead, which is UB.

So when removing storage statements, we have to remove both StorageLive and StorageDead.

~I also added a MIR validation pass for StorageLive. It may be a bit overzealous.~
2023-02-02 17:14:06 +01:00
Matthias Krüger
230c9e91fd
Rollup merge of #107515 - Swatinem:hirvalidator, r=compiler-errors
Improve pretty-printing of `HirIdValidator` errors

This now uses `node_to_string` for both missing and seen Ids, which includes the snippet of code for which the Id was allocated. Also removes the duplicated printing of `HirId`, as `node_to_string` also includes that.
2023-02-02 17:14:06 +01:00
Matthias Krüger
e9c4e291c4
Rollup merge of #107493 - clubby789:range-fat-arrow-followup, r=estebank
Improve diagnostic for missing space in range pattern

Improves the diagnostic in #107425 by turning it into a note explaining the parsing issue.

r? `@compiler-errors`
2023-02-02 17:14:05 +01:00
Matthias Krüger
8f47954742
Rollup merge of #106919 - compiler-errors:underscore-typo-in-field-pat, r=jackh726
Recover `_` as `..` in field pattern
2023-02-02 17:14:05 +01:00
clubby789
4ab75de934 Improve diagnostic for missing space in range pattern 2023-02-02 13:18:12 +00:00
bors
97872b792c Auto merge of #107478 - compiler-errors:anon-enum-tys-are-ambiguous, r=estebank
Revert "Teach parser to understand fake anonymous enum syntax" and related commits

anonymous enum types are currently ambiguous in positions like:

* `|` operator: `a as fn() -> B | C`
* closure args: `|_: as fn() -> A | B`

I first tried to thread around `RecoverAnonEnum` into all these positions, but the resulting complexity in the compiler is IMO not worth it, or at least worth a bit more thinking time. In the mean time, let's revert this syntax for now, so we can go back to the drawing board.

Fixes #107461

cc: `@estebank` `@cjgillot` #106960

---
### Squashed revert commits:

Revert "review comment: Remove AST AnonTy"

This reverts commit 020cca8d36.

Revert "Ensure macros are not affected"

This reverts commit 12d18e4031.

Revert "Emit fewer errors on patterns with possible type ascription"

This reverts commit c847a01a3b.

Revert "Teach parser to understand fake anonymous enum syntax"

This reverts commit 2d82420665.
2023-02-02 12:01:17 +00:00
Mads Ravn
f922c8395d PR fixing wrong order of format parameters in strings. Issue #106572
Adding

Adding

Fixing small issues for PR

Adding tests

Removing unused binding

Changing the wording on note

Fixing PR comment
2023-02-02 12:56:04 +01:00
bors
a9985cf172 Auto merge of #107584 - matthiaskrgr:rollup-vav4ljz, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #107201 (Remove confusing 'while checking' note from opaque future type mismatches)
 - #107312 (Add Style Guide rules for let-else statements)
 - #107488 (Fix syntax in `-Zunpretty-expanded` output for derived `PartialEq`.)
 - #107531 (Inline CSS background images directly into the CSS)
 - #107576 (Add proc-macro boilerplate to crt-static test)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-02-02 09:05:18 +00:00
Maybe Waffle
a7f97a7689 Use rust_2018 instead of !is_rust_2015 2023-02-02 08:17:18 +00:00
Maybe Waffle
9fe8ae792e Rename rust_2015 => is_rust_2015 2023-02-02 08:17:13 +00:00
Michael Goulet
9dd5d3e8e4 Recover _ as .. in field pattern 2023-02-02 06:10:02 +00:00
Michael Goulet
39db65c526 Add a test 2023-02-02 05:54:35 +00:00
Michael Goulet
e4b2936983 Revert "Teach parser to understand fake anonymous enum syntax" and related commits
Revert "review comment: Remove AST AnonTy"

This reverts commit 020cca8d36.

Revert "Ensure macros are not affected"

This reverts commit 12d18e4031.

Revert "Emit fewer errors on patterns with possible type ascription"

This reverts commit c847a01a3b.

Revert "Teach parser to understand fake anonymous enum syntax"

This reverts commit 2d82420665.
2023-02-02 05:54:35 +00:00
Matthias Krüger
643fc97fd3
Rollup merge of #107576 - P1n3appl3:master, r=tmandry
Add proc-macro boilerplate to crt-static test

I was seeing this failure when running ui tests with with a `-Cpanic=abort` stdlib targeting fuchsia:

```
---- [ui] tests/ui/proc-macro/crt-static.rs stdout ----
normalized stderr:
warning: building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic

warning: 1 warning emitted

The actual stderr differed from the expected stderr.
```

`force-host` was enough to stop it from running/failing, not sure if I should also add `needs-unwind`?
2023-02-02 06:52:15 +01:00
Matthias Krüger
75ea3a9948
Rollup merge of #107531 - GuillaumeGomez:inline-images-in-css, r=notriddle
Inline CSS background images directly into the CSS

A nice advantage of this is that it removes a few entries in the list of static files.

r? ``@notriddle``
2023-02-02 06:52:15 +01:00
Matthias Krüger
150b9d753b
Rollup merge of #107488 - nnethercote:fix-PartialEq-syntax, r=RalfJung
Fix syntax in `-Zunpretty-expanded` output for derived `PartialEq`.

If you do `derive(PartialEq)` on a packed struct, the output shown by `-Zunpretty=expanded` includes expressions like this:
```
{ self.x } == { other.x }
```
This is invalid syntax. This doesn't break compilation, because the AST nodes are constructed within the compiler. But it does mean anyone using `-Zunpretty=expanded` output as a guide for hand-written impls could get a nasty surprise.

This commit fixes things by instead using this form:
```
({ self.x }) == ({ other.x })
```

r? ``@RalfJung``
2023-02-02 06:52:14 +01:00
Matthias Krüger
f838fa87b2
Rollup merge of #107312 - calebcartwright:style-let-else, r=joshtriplett
Add Style Guide rules for let-else statements

cc `@rust-lang/style` `@rust-lang/rustfmt`

[rendered](c694d07c64/src/doc/style-guide/src/statements.md (else-blocks-let-else-statements))
2023-02-02 06:52:13 +01:00
Matthias Krüger
480c4a18d5
Rollup merge of #107201 - compiler-errors:confusing-async-fn-note, r=estebank
Remove confusing 'while checking' note from opaque future type mismatches

Maybe I'm just misinterpreting the wording of the note. The only value I can see in this note is that it points out where the async's opaque future is coming from, but the way it's doing it is misleading IMO.

For example:

```rust
note: while checking the return type of the `async fn`
  --> $DIR/dont-suggest-missing-await.rs:7:24
   |
LL | async fn make_u32() -> u32 {
   |                        ^^^ checked the `Output` of this `async fn`, found opaque type
```

We point at the type `u32` in the HIR, but then say "found opaque type". We also say "while checking"... but we're typechecking a totally different function when we get this type mismatch!

r? ``@estebank`` but feel free to reassign and/or take your time reviewing this. I'd be inclined to also discuss reworking the presentation of this type mismatch to restore some of these labels in a way that makes it more clear what it's trying to point out.
2023-02-02 06:52:13 +01:00
bors
821b2a8e39 Auto merge of #106925 - imWildCat:imWildCat/remove-hardcoded-ios-macbi-target-version, r=wesleywiser
Remove hardcoded iOS version of clang target for Mac Catalyst

## Background

From `clang` 13.x, `-target x86_64-apple-ios13.0-macabi` fails while linking:

```
  = note: clang: error: invalid version number in '-target x86_64-apple-ios13.0-macabi'
```

<details>
<summary>Verbose output</summary>

```
error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="[removed]" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-Wl,-exported_symbols_list,/var/folders/p8/qpmzbsdn07g5gxykwfxxw7y40000gn/T/rustci8tkvp/list" "-target" "x86_64-apple-ios13.0-macabi" "/var/folders/p8/qpmzbsdn07g5gxykwfxxw7y40000gn/T/rustci8tkvp/symbols.o" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/deps/[user].[user].a2ccc648-cgu.0.rcgu.o" "-L" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/deps" "-L" "/path/to/my/[project]/[user]/target/release/deps" "-L" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/build/blake3-74e6ba91506ce712/out" "-L" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/build/blake3-74e6ba91506ce712/out" "-L" "/Users/[user]/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-apple-ios-macabi/lib" "/var/folders/p8/qpmzbsdn07g5gxykwfxxw7y40000gn/T/rustci8tkvp/libblake3-343c1616c8f62c66.rlib" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/deps/libcompiler_builtins-15d4f20b641cf9ef.rlib" "-framework" "Security" "-framework" "CoreFoundation" "-framework" "Security" "-liconv" "-lSystem" "-lobjc" "-framework" "Security" "-framework" "Foundation" "-lc" "-lm" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk" "-Wl,-syslibroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk" "-L" "/Users/[user]/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-apple-ios-macabi/lib" "-o" "/path/to/my/[project]/[user]/target/x86_64-apple-ios-macabi/release/deps/lib[user].dylib" "-Wl,-dead_strip" "-dynamiclib" "-Wl,-dylib" "-nodefaultlibs"
  = note: clang: error: invalid version number in '-target x86_64-apple-ios13.0-macabi'

warning: `[user]` (lib) generated 6 warnings
error: could not compile `[user]` due to previous error; 6 warnings emitted
```
</details>

### Minimal example

C code:

```c
#include <stdio.h>
void main() {
    int a = 1;
    int b = 2;
    int c = a + b;
    printf("%d", c);
}
```

`clang` command sample:

```
➜  202301 clang -target x86_64-apple-ios13.0-macabi main.c
clang: error: invalid version number in '-target x86_64-apple-ios13.0-macabi'
➜  202301 clang -target x86_64-apple-ios14.0-macabi main.c
main.c:2:1: warning: return type of 'main' is not 'int' [-Wmain-return-type]
void main() {
^
main.c:2:1: note: change return type to 'int'
void main() {
^~~~
int
1 warning generated.
➜  202301 clang -target x86_64-apple-ios15.0-macabi main.c
main.c:2:1: warning: return type of 'main' is not 'int' [-Wmain-return-type]
void main() {
^
main.c:2:1: note: change return type to 'int'
void main() {
^~~~
int
1 warning generated.
➜  202301 clang -target x86_64-apple-ios-macabi main.c
main.c:2:1: warning: return type of 'main' is not 'int' [-Wmain-return-type]
void main() {
^
main.c:2:1: note: change return type to 'int'
void main() {
^~~~
int
1 warning generated.

➜  202301 clang --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```

This PR is a simplified version of #96392, inspired by https://github.com/rust-lang/cc-rs/pull/727
2023-02-02 05:26:09 +00:00
Caleb Cartwright
10b9c1d3ca docs(style-guide): add rules for let-else statements 2023-02-01 21:16:54 -06:00
bors
131f0c6df6 Auto merge of #105670 - Xiretza:rustc_parse-diagnostics-4, r=davidtwco
rustc_parse: diagnostics migration, v4

This is all the `rustc_parse` migrations I have in store right now; unfortunately life is pretty busy right now, so I won't be able to do much more in the near future.

cc #100717

r? `@davidtwco`
2023-02-02 02:23:31 +00:00
Bryan Garza
1a65219a49 Bless tests after rebase 2023-02-02 01:38:14 +00:00
Bryan Garza
776918971d Update test to not trigger stack overflow 2023-02-02 01:20:12 +00:00
Bryan Garza
cb6de47d3b Move ignore-pass to large-arg test 2023-02-02 01:20:12 +00:00