Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #123023

Closed
wants to merge 19 commits into from

Conversation

matthiaskrgr
Copy link
Member

Successful merges:

r? @ghost
@rustbot modify labels: rollup

Create a similar rollup

estebank and others added 19 commits March 21, 2024 00:03
```
error: unconstrained generic constant
  --> $DIR/const-argument-if-length.rs:18:10
   |
LL |     pad: [u8; is_zst::<T>()],
   |          ^^^^^^^^^^^^^^^^^^^
   |
help: try adding a `where` bound
   |
LL | pub struct AtLeastByte<T: ?Sized> where [(); is_zst::<T>()]: {
   |                                   ++++++++++++++++++++++++++
```

Detect when the constant expression isn't `usize` and suggest casting:

```
error: unconstrained generic constant
 --> f300.rs:6:10
  |
6 |     bb::<{!N}>();
  |          ^^^^
-Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs:3539:36
  |
help: try adding a `where` bound
  |
5 | fn b<const N: bool>() where [(); {!N} as usize]: {
  |                       ++++++++++++++++++++++++++
```

Fix rust-lang#122395.
These headers and flags were historically needed, but are now unnecessary due
to various changes in how coverage information is stored in MIR.
In user-facing Rust, `dyn` always has at least one predicate following
it. Unfortunately, because we filter out marker traits from receivers at
callsites and `dyn Sync` is, for example, legal, this results in us
having `dyn` types with no predicates on occasion in our alias set
encoding. This patch handles cases where there are no predicates in a
`dyn` type which are relevant to its alias set.

Fixes rust-lang#122998
…spans.

This makes `-Zprint-type-sizes`'s output easier to read, because the
name of an `async fn` is more immediately recognizable than its span.

I also deleted the comment "FIXME(eddyb) should use `def_span`." because
it appears to have already been fixed by commit 67727aa.
Previously, we only rewrote `&self` and `&mut self` receivers. By
instantiating the method from the trait definition, we can make this
work work with arbitrary legal receivers instead.
I will be on vacation for the next three weeks. I will re-add myself
when I return.
It has a single call site, and afterwards all the calls to
`parse_expr_tuple_field_access` are in a single method, which is nice.
Pass in the span for the field rather than using `prev_token`.
Also rename it `mk_expr_tuple_field_access`, because it doesn't do any
actual parsing, it just creates an expression with what it's given.

Not much of a clarity win by itself, but unlocks additional subsequent
simplifications.
For the `MiddleDot` case, current behaviour:
- For a case like `1.2`, `sym1` is `1` and `sym2` is `2`, and `self.token`
  holds `1.2`.
- It creates a new ident token from `sym1` that it puts into `self.token`.
- Then it does `bump_with` with a new dot token, which moves the `sym1`
  token into `prev_token`.
- Then it does `bump_with` with a new ident token from `sym2`, which moves the
  `dot` token into `prev_token` and discards the `sym1` token.
- Then it does `bump`, which puts whatever is next into `self.token`,
  moves the `sym2` token into `prev_token`, and discards the `dot` token
  altogether.

New behaviour:
- Skips creating and inserting the `sym1` and dot tokens, because they are
  unnecessary.
- This also demonstrates that the comment about `Spacing::Alone` is
  wrong -- that value is never used. That comment was added in rust-lang#77250,
  and AFAICT it has always been incorrect.

The commit also expands comments. I found this code hard to read
previously, the examples in comments make it easier.
…st, r=Nadrieril

Provide structured suggestion for unconstrained generic constant

```
error: unconstrained generic constant
  --> $DIR/const-argument-if-length.rs:18:10
   |
LL |     pad: [u8; is_zst::<T>()],
   |          ^^^^^^^^^^^^^^^^^^^
   |
help: try adding a `where` bound
   |
LL | pub struct AtLeastByte<T: ?Sized> where [(); is_zst::<T>()]: {
   |                                   ++++++++++++++++++++++++++
```

Detect when the constant expression isn't `usize` and suggest casting:

```
error: unconstrained generic constant
 --> f300.rs:6:10
  |
6 |     bb::<{!N}>();
  |          ^^^^
-Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs:3539:36
  |
help: try adding a `where` bound
  |
5 | fn b<const N: bool>() where [(); {!N} as usize]: {
  |                       ++++++++++++++++++++++++++
```

Fix rust-lang#122395.
…_expr, r=est31

Tweak `parse_dot_suffix_expr`

I find this function hard to understand, so I rewrote it.

r? `@est31`
…-errors

In `pretty_print_type()`, print `async fn` futures' paths instead of spans.

This makes `-Zprint-type-sizes`'s output easier to read, because the name of an `async fn` is more immediately recognizable than its span. This change will also synergize with my other `-Zprint-type-sizes` PR rust-lang#122922 which prints the type of child futures being awaited.

I also deleted the comment "FIXME(eddyb) should use `def_span`." because it appears to have already been fixed by commit 67727aa.
…pratt

Clarify transmute example

The example claims using an iterator will copy the entire vector, but this is not true in practice thanks to internal specializations in the stdlib (see https://godbolt.org/z/cnxo3MYs5 for confirmation that this doesn't reallocate nor iterate over the vec's elements). Since neither the copy nor the optimization is guaranteed I opted for saying that they _may_ happen.
…ulacrum

Clean up unnecessary headers/flags in coverage mir-opt tests

During rust-lang#122542, I noticed that some of the headers and flags I had copied over from `tests/mir-opt/instrument_coverage.rs`  were unnecessary. And while working to remove those, I noticed even more that could be removed or replaced.
CFI: Handle dyn with no principal

In user-facing Rust, `dyn` always has at least one predicate following it. Unfortunately, because we filter out marker traits from receivers at callsites and `dyn Sync` is, for example, legal, this results in us having `dyn` types with no predicates on occasion in our alias set encoding. This patch handles cases where there are no predicates in a `dyn` type which are relevant to its alias set.

Fixes rust-lang#122998

r? workingjubilee
…compiler-errors

CFI: Support complex receivers

Right now, we only support rewriting `&self` and `&mut self` into `&dyn MyTrait` and `&mut dyn MyTrait`. This expands it to handle the full gamut of receivers by calculating the receiver based on *substitution* rather than based on a rewrite. This means that, for example, `Arc<Self>` will become `Arc<dyn MyTrait>` appropriately with this change.

This approach also allows us to support associated type constraints as well, so we will correctly rewrite `&self` into `&dyn MyTrait<T=i32>`, for example.

r? `@workingjubilee`
… r=nnethercote

Temporarily remove nnethercote from the review rotation.

I will be on vacation for the next three weeks. I will re-add myself when I return.

r? `@nnethercote`
@rustbot rustbot added A-meta Area: Issues about the rust-lang/rust repository. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. rollup A PR which is a rollup labels Mar 25, 2024
@matthiaskrgr
Copy link
Member Author

@bors r+ rollup=never p=8

@bors
Copy link
Contributor

bors commented Mar 25, 2024

📌 Commit 778e707 has been approved by matthiaskrgr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 25, 2024
@bors
Copy link
Contributor

bors commented Mar 25, 2024

⌛ Testing commit 778e707 with merge 33c0005...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 25, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#122802 (Provide structured suggestion for unconstrained generic constant)
 - rust-lang#122858 (Tweak `parse_dot_suffix_expr`)
 - rust-lang#122923 (In `pretty_print_type()`, print `async fn` futures' paths instead of spans.)
 - rust-lang#122990 (Clarify transmute example)
 - rust-lang#122995 (Clean up unnecessary headers/flags in coverage mir-opt tests)
 - rust-lang#123003 (CFI: Handle dyn with no principal)
 - rust-lang#123005 (CFI: Support complex receivers)
 - rust-lang#123020 (Temporarily remove nnethercote from the review rotation.)

r? `@ghost`
`@rustbot` modify labels: rollup
@rust-log-analyzer
Copy link
Collaborator

The job test-various failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
test [mir-opt] tests/mir-opt/inline/polymorphic_recursion.rs ... ok

failures:

---- [mir-opt] tests/mir-opt/inline_coroutine_body.rs stdout ----
5       debug permit => (_1.0: ActionPermit<'_, T>);
6       debug ctx => (*(_1.1: &mut std::task::Context<'_>));
7       let mut _0: ();
-       let mut _2: {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6};
+       let mut _2: {async fn body of ActionPermit<'_, T>::perform()};
9       let mut _3: ActionPermit<'_, T>;
-       let mut _5: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6};
+       let mut _5: &mut {async fn body of ActionPermit<'_, T>::perform()};
11       let _6: ();
12       let mut _7: std::task::Poll<()>;
-       let mut _8: std::pin::Pin<&mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6}>;
+       let mut _8: std::pin::Pin<&mut {async fn body of ActionPermit<'_, T>::perform()}>;
14       let mut _9: &mut std::task::Context<'_>;
15       let mut _10: &mut std::task::Context<'_>;
16       scope 1 {

17           debug fut => _2;
-           let _4: std::pin::Pin<&mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6}>;
+           let _4: std::pin::Pin<&mut {async fn body of ActionPermit<'_, T>::perform()}>;
19           scope 2 {
20               debug fut => _4;
21               scope 4 {
22               }
22               }
23 +             scope 7 (inlined ActionPermit::<'_, T>::perform::{closure#0}) {
24 +                 debug _task_context => _31;
- +                 debug self => ((*(_8.0: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6})).0: ActionPermit<'_, T>);
+ +                 debug self => ((*(_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()})).0: ActionPermit<'_, T>);
26 +                 let _11: ActionPermit<'_, T>;
27 +                 let mut _12: std::future::Ready<()>;
28 +                 let mut _13: std::future::Ready<()>;
43 +                 let mut _30: ();
44 +                 let mut _31: &mut std::task::Context<'_>;
45 +                 let mut _32: u32;
45 +                 let mut _32: u32;
- +                 let mut _33: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6};
- +                 let mut _34: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6};
- +                 let mut _35: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6};
- +                 let mut _36: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6};
- +                 let mut _37: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6};
- +                 let mut _38: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6};
- +                 let mut _39: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6};
- +                 let mut _40: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6};
+ +                 let mut _33: &mut {async fn body of ActionPermit<'_, T>::perform()};
+ +                 let mut _34: &mut {async fn body of ActionPermit<'_, T>::perform()};
+ +                 let mut _35: &mut {async fn body of ActionPermit<'_, T>::perform()};
+ +                 let mut _36: &mut {async fn body of ActionPermit<'_, T>::perform()};
+ +                 let mut _37: &mut {async fn body of ActionPermit<'_, T>::perform()};
+ +                 let mut _38: &mut {async fn body of ActionPermit<'_, T>::perform()};
+ +                 let mut _39: &mut {async fn body of ActionPermit<'_, T>::perform()};
+ +                 let mut _40: &mut {async fn body of ActionPermit<'_, T>::perform()};
54 +                 scope 8 {
- +                     debug self => (((*(_8.0: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6})) as variant#3).0: ActionPermit<'_, T>);
+ +                     debug self => (((*(_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()})) as variant#3).0: ActionPermit<'_, T>);
56 +                     let mut _15: std::future::Ready<()>;
57 +                     scope 9 {
- +                         debug __awaitee => (((*(_8.0: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6})) as variant#3).1: std::future::Ready<()>);
+ +                         debug __awaitee => (((*(_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()})) as variant#3).1: std::future::Ready<()>);
59 +                         let _26: ();
60 +                         scope 10 {

71 +             }
72           }
73           scope 3 {
73           scope 3 {
- +             scope 6 (inlined Pin::<&mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6}>::new_unchecked) {
+ +             scope 6 (inlined Pin::<&mut {async fn body of ActionPermit<'_, T>::perform()}>::new_unchecked) {
75 +                 debug pointer => _5;
77           }

93           StorageLive(_4);
94           StorageLive(_5);
94           StorageLive(_5);
95           _5 = &mut _2;
- -         _4 = Pin::<&mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6}>::new_unchecked(move _5) -> [return: bb2, unwind unreachable];
+ -         _4 = Pin::<&mut {async fn body of ActionPermit<'_, T>::perform()}>::new_unchecked(move _5) -> [return: bb2, unwind unreachable];
98 - 
99 -     bb2: {


- +         _4 = Pin::<&mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6}> { __pointer: _5 };
+ +         _4 = Pin::<&mut {async fn body of ActionPermit<'_, T>::perform()}> { __pointer: _5 };
101           StorageDead(_5);
102           StorageLive(_6);
103           StorageLive(_7);
106           StorageLive(_9);
106           StorageLive(_9);
107           _10 = deref_copy (_1.1: &mut std::task::Context<'_>);
108           _9 = &mut (*_10);
- -         _7 = <{async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6} as Future>::poll(move _8, move _9) -> [return: bb3, unwind unreachable];
+ -         _7 = <{async fn body of ActionPermit<'_, T>::perform()} as Future>::poll(move _8, move _9) -> [return: bb3, unwind unreachable];
110 +         StorageLive(_11);
111 +         StorageLive(_15);
112 +         StorageLive(_16);
123 +         StorageLive(_38);
124 +         StorageLive(_39);
125 +         StorageLive(_40);
125 +         StorageLive(_40);
- +         _33 = deref_copy (_8.0: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6});
+ +         _33 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
127 +         _32 = discriminant((*_33));
128 +         switchInt(move _32) -> [0: bb3, 1: bb13, 3: bb12, otherwise: bb8];

164   
165 +     bb3: {
166 +         _31 = move _9;
166 +         _31 = move _9;
- +         _34 = deref_copy (_8.0: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6});
- +         _35 = deref_copy (_8.0: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6});
+ +         _34 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
+ +         _35 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
169 +         (((*_34) as variant#3).0: ActionPermit<'_, T>) = move ((*_35).0: ActionPermit<'_, T>);
170 +         StorageLive(_12);
171 +         StorageLive(_13);
183 -         StorageDead(_2);
184 -         return;
185 +         StorageDead(_13);
185 +         StorageDead(_13);
- +         _36 = deref_copy (_8.0: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6});
+ +         _36 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
187 +         (((*_36) as variant#3).1: std::future::Ready<()>) = move _12;
188 +         goto -> bb5;

194 +         StorageLive(_19);
195 +         StorageLive(_20);
196 +         StorageLive(_21);
196 +         StorageLive(_21);
- +         _37 = deref_copy (_8.0: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6});
+ +         _37 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
198 +         _21 = &mut (((*_37) as variant#3).1: std::future::Ready<()>);
199 +         _20 = &mut (*_21);
200 +         _19 = Pin::<&mut std::future::Ready<()>>::new_unchecked(move _20) -> [return: bb6, unwind unreachable];
236 +         StorageDead(_12);
237 +         StorageDead(_28);
238 +         StorageDead(_29);
238 +         StorageDead(_29);
- +         _38 = deref_copy (_8.0: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6});
+ +         _38 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
240 +         discriminant((*_38)) = 3;
241 +         goto -> bb2;

251 +         StorageDead(_18);
252 +         StorageDead(_17);
253 +         StorageDead(_12);
253 +         StorageDead(_12);
- +         _39 = deref_copy (_8.0: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6});
+ +         _39 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
255 +         drop((((*_39) as variant#3).0: ActionPermit<'_, T>)) -> [return: bb11, unwind unreachable];
257 + 

258 +     bb11: {
258 +     bb11: {
259 +         _7 = Poll::<()>::Ready(move _30);
- +         _40 = deref_copy (_8.0: &mut {async fn body@$DIR/inline_coroutine_body.rs:25:28: 27:6});
+ +         _40 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
261 +         discriminant((*_40)) = 1;
262 +         goto -> bb2;

thread '[mir-opt] tests/mir-opt/inline_coroutine_body.rs' panicked at src/tools/compiletest/src/runtest.rs:4351:21:
thread '[mir-opt] tests/mir-opt/inline_coroutine_body.rs' panicked at src/tools/compiletest/src/runtest.rs:4351:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-abort.diff


failures:
    [mir-opt] tests/mir-opt/inline_coroutine_body.rs

@bors
Copy link
Contributor

bors commented Mar 25, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-meta Area: Issues about the rust-lang/rust repository. PG-exploit-mitigations Project group: Exploit mitigations rollup A PR which is a rollup S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants