Commit Graph

100 Commits

Author SHA1 Message Date
bors
330727467b Auto merge of #112682 - spastorino:new-rpitit-21, r=compiler-errors
Add bidirectional where clauses on RPITIT synthesized GATs

Given the following:

```rust
struct MyStruct<'a, T>(&'a T);

trait MyTrait<'a, T> {
    fn my_fn<'b, 'c, 'd, V>(item: &'c String) -> impl Sized + 'a + 'b + 'c where V: 'b, V: 'd;
}

impl<'a, T> MyTrait<'a, T> for MyStruct<'a, T> {
    fn my_fn<'b, 'c, 'd, V>(_: &'c String) -> impl Sized + 'a + 'b + 'c
    where
        V: 'b,
        V: 'd,
    {
        unimplemented!();
    }
}
```

We need the desugaring to be:

```rust
trait MyTrait<'a, T> {
    type MyFn<'bf, 'df, Vf, 'a2, 'b2, 'c2>: Sized + 'a2 + 'b2 + 'c2 where Vf: 'b2, 'a2: 'a, 'a: 'a2, 'b2: 'bf, 'bf: 'b2;

    fn my_fn<'b, 'c, 'd, V>(item: &'c String) -> MyStruct<'a>::MyFn<'b, 'd, V, 'a, 'b, 'c> where V: 'b, V: 'd {
        type opaque<'a3, 'b3, 'c3>;
    };
}

impl<'a, T> MyIter<'a, T> for MyStruct<'a, T> {
    type MyFn<'bf, 'df, Vf, 'a2, 'b2, 'c2> = impl Sized + 'a2 + 'b2 + 'c2 where Vf: b2, 'a2: 'a, 'a: 'a2, 'b2: 'bf, 'bf: 'b2;

    fn my_fn<'b, 'c, 'd, V>(_: &'c String) -> MyStruct<'a>::MyFn<'a, 'b, 'c, V> where V: 'b, V: 'd {
        type opaque<'a3, 'b3, 'c3>;
        unimplemented!();
    }
}
```

This PR adds the where clauses for the `MyFn` generated GATs.

This is a draft with a very ugly solution so we can make comments over concrete code.

r? `@compiler-errors`
2023-06-29 21:24:51 +00:00
Santiago Pastorino
4925b57782
Add bidirectional where clauses on RPITIT synthesized GATs 2023-06-29 14:26:26 -03:00
bors
a20a04e5d6 Auto merge of #113108 - compiler-errors:normalize-opaques-with-late-bound-vars-again, r=jackh726
Normalize opaques with late-bound vars again

We have a hack in the compiler where if an opaque has escaping late-bound vars, we skip revealing it even though we *could* reveal it from a technical perspective. First of all, this is weird, since we really should be revealing all opaques in `Reveal::All` mode. Second of all, it causes subtle bugs (linked below).

I attempted to fix this in #100980, which was unfortunately reverted due to perf regressions on codebases that used really deeply nested futures in some interesting ways. The worst of which was #103423, which caused the project to hang on build. Another one was #104842, which was just a slow-down, but not a hang. I took some time afterwards to investigate how to rework `normalize_erasing_regions` to take advantage of better caching, but that effort kinda fizzled out (#104133).

However, recently, I was made aware of more bugs whose root cause is not revealing opaques during codegen. That made me want to fix this again -- in the process, interestingly, I took the the minimized example from https://github.com/rust-lang/rust/issues/103423#issuecomment-1292947043, and it doesn't seem to hang any more...

Thinking about this harder, there have been some changes to the way we lower and typecheck async futures that may have reduced the pathologically large number of outlives obligations (see description of #103423) that we were encountering when normalizing opaques with bound vars the last time around:
* #104321 (lower `async { .. }` directly as a generator that implements `Future`, removing the `from_generator` shim)
* #104833 (removing an `identity_future` fn that was wrapping desugared future generators)

... so given that I can see:
* No significant regression on rust perf bot (https://github.com/rust-lang/rust/pull/107620#issuecomment-1600070317)
* No timeouts in crater run I did (https://github.com/rust-lang/rust/pull/107620#issuecomment-1605428952, rechecked failing crates in https://github.com/rust-lang/rust/pull/107620#issuecomment-1605973434)

... and given that this PR:
* Fixes #104601
* Fixes #107557
* Fixes #109464
* Allows us to remove a `DefiningAnchor::Bubble` from codegen (75a8f68183)

I'm inclined to give this another shot at landing this. Best case, it just works -- worst case, we get more examples to study how we need to improve the compiler to make this work.

r? types
2023-06-29 15:37:11 +00:00
Michael Goulet
bfc6ca8207 More tests 2023-06-27 21:36:15 +00:00
Michael Goulet
858a861fff Make associated type bounds in supertrait position implied 2023-06-27 18:28:07 +00:00
Michael Goulet
4a175523b1
Rollup merge of #112981 - spastorino:new-rpitit-22, r=compiler-errors
Fix return type notation errors with -Zlower-impl-trait-in-trait-to-assoc-ty

This just adjust the way we check for RPITITs and uses the new helper method to do the "old" and "new" check at once.

r? `@compiler-errors`
2023-06-23 19:47:21 -07:00
Michael Goulet
4a01a38466
Rollup merge of #111087 - ibraheemdev:patch-15, r=dtolnay
Implement `Sync` for `mpsc::Sender`

`mpsc::Sender` is currently `!Sync` because the previous implementation contained an optimization where the channel started out as single-producer and was dynamically upgraded on the first clone, which relied on a unique reference to the sender. This optimization is one of the main reasons the old implementation was so complex and was removed in #93563. `mpsc::Sender` can now soundly implement `Sync`.

Note for any potential confusion, this chance does *not* add MPMC behavior. This only affects the already `Send + Clone` *sender*, not *receiver*.

It's technically possible to rely on the `!Sync` behavior in the same way as a `PhantomData<*mut T>`, but that seems very unlikely in practice. Either way, this change is insta-stable and needs an FCP.

`@rustbot` label +T-libs-api -T-libs
2023-06-23 19:47:19 -07:00
Santiago Pastorino
d77e55bbb9
Fix return type notation errors with -Zlower-impl-trait-in-trait-to-assoc-ty 2023-06-23 17:34:33 -03:00
Ibraheem Ahmed
4ceca09586 update failing ui tests 2023-06-20 19:46:01 -04:00
许杰友 Jieyou Xu (Joe)
edafbaffb2
Adjust UI tests for unit_bindings
- Either explicitly annotate `let x: () = expr;` where `x` has unit
  type, or remove the unit binding to leave only `expr;` instead.
- Fix disjoint-capture-in-same-closure test
2023-06-12 20:24:48 +08:00
Matthias Krüger
17cc282880
Rollup merge of #112323 - compiler-errors:dont-mention-set-fields, r=WaffleLapkin
Don't mention already-set fields in struct constructor missing field error

Fixes #111149
2023-06-09 08:15:55 +02:00
Michael Goulet
140c011ca6 Don't mention already set fields 2023-06-05 21:00:08 +00:00
Michael Goulet
bbc536d3ac Emit an error when RTN is used with ty/ct params 2023-06-05 19:52:04 +00:00
Arpad Borsos
75b557a2c4
Fix type-inference regression in #112225
The type inference of argument-position closures and async blocks
regressed in 1.70 as the evaluation order of async blocks changed, as
they are not implicitly wrapped in an identity-function anymore.

Fixes #112225 by making sure the evaluation order stays the same as it
used to.
2023-06-04 10:56:00 +02:00
Caio
25e395653d Move tests 2023-05-24 19:35:59 -03:00
Michael Goulet
e54bc1c5ff Don't ICE on RPITIT when promoting trait preds to associated type bounds 2023-05-23 03:43:09 +00:00
Dylan DPC
05ca3e31df
Rollup merge of #111451 - compiler-errors:note-cast-origin, r=b-naber
Note user-facing types of coercion failure

When coercing, for example, `Box<A>` into `Box<dyn B>`, make sure that any failure notes mention *those* specific types, rather than mentioning inner types, like "the cast from `A` to `dyn B`".

I expect end-users are often confused when we skip layers of types and only mention the "innermost" part of a coercion, especially when other notes point at HIR, e.g. #111406.
2023-05-13 11:05:33 +05:30
Michael Goulet
14bf909e71 Note base types of coercion 2023-05-12 00:10:52 +00:00
Urgau
61ff2718f7 Adjust tests for new drop and forget lints 2023-05-10 19:36:02 +02:00
Michael Goulet
a9051d861c Tweak borrow suggestion 2023-05-08 03:36:30 +00:00
Michael Goulet
76802e31a1 Error message for ambiguous RTN from super bounds 2023-05-03 21:09:50 +00:00
Michael Goulet
20a83144b2 Support RTN on associated methods from supertraits 2023-05-03 19:41:15 +00:00
Michael Goulet
7411468ff8 Mark RPITIT and AFIT as no longer incomplete 2023-05-02 05:04:50 +00:00
Matthias Krüger
1b262b8b56
Rollup merge of #110823 - compiler-errors:tweak-await-span, r=b-naber
Tweak await span to not contain dot

Fixes a discrepancy between method calls and await expressions where the latter are desugared to have a span that *contains* the dot (i.e. `.await`) but method call identifiers don't contain the dot. This leads to weird suggestions suggestions in borrowck -- see linked issue.

Fixes #110761

This mostly touches a bunch of tests to tighten their `await` span.
2023-05-01 01:09:47 +02:00
bors
f2299490c1 Auto merge of #108106 - the8472:layout-opt, r=wesleywiser
Improve niche placement by trying two strategies and picking the better result

Fixes #104807
Fixes #105371

Determining which sort order is better requires calculating the struct size (so we can calculate the niche offset). But that in turn depends on the field order, so happens after sorting. So the simple way to solve that is to run the whole thing twice and pick the better result.

1st commit is just code motion, the meat is in the later ones.
2023-04-29 08:55:04 +00:00
Michael Goulet
4e05cfb5ff Don't duplicate anonymous lifetimes for async fn in traits 2023-04-28 20:21:03 +00:00
The 8472
1a51ec6864 bless tests 2023-04-27 22:29:04 +02:00
Michael Goulet
6d6c904431 Make async removal span more resilient to macro expansions 2023-04-27 18:25:07 +00:00
Michael Goulet
6c9249f689 Don't call await a method 2023-04-27 17:18:12 +00:00
Michael Goulet
e6077fc1b8 tweak removal span 2023-04-27 17:18:12 +00:00
Michael Goulet
f0fc4f9acf Tweak await span 2023-04-27 17:18:11 +00:00
Michael Goulet
12a2f24b15 Remove a bunch of orphaned test files 2023-04-27 17:17:38 +00:00
Matthias Krüger
7d046551a7
Rollup merge of #110555 - compiler-errors:subst-missing-trait-items, r=cjgillot
Substitute missing trait items suggestion correctly

Properly substitute missing item suggestions, so that when they reference generics from their parent trait they actually have the right time for the impl.

Also, some other minor tweaks like using `/* Type */` to signify a GAT's type is actually missing, and fixing generic arg suggestions for GATs in general.
2023-04-21 06:44:29 +02:00
Maybe Waffle
cac143f0e3 Extend and use hir::Node::body_id 2023-04-19 19:13:45 +00:00
Michael Goulet
73038d3a64 Make missing impl item suggestions more obvious that they're missing 2023-04-19 17:57:37 +00:00
Michael Goulet
204c516293 Substitute missing item suggestion correctly 2023-04-19 17:47:39 +00:00
Matthias Krüger
e413c2e770
Rollup merge of #110259 - ndrewxie:issue-109964-fix-gitstuff, r=cjgillot
Added diagnostic for pin! macro in addition to Box::pin if Unpin isn't implemented

I made a PR earlier, but accidentally renamed a branch and that deleted the PR... sorry for the duplicate

Currently, if an operation on `Pin<T>` is performed that requires `T` to implement `Unpin`, the diagnostic suggestion is to use `Box::pin` ("note: consider using `Box::pin`").

This PR suggests pin! as well, as that's another valid way of pinning a value, and avoids a heap allocation. Appropriate diagnostic suggestions were included to highlight the difference in semantics (local pinning for pin! vs non-local for Box::pin).

Fixes #109964
2023-04-13 21:58:37 +02:00
bors
d8fc819247 Auto merge of #109466 - davidlattimore:inline-arg-via-var-debug-info, r=wesleywiser
Preserve argument indexes when inlining MIR

We store argument indexes on VarDebugInfo. Unlike the previous method of relying on the variable index to know whether a variable is an argument, this survives MIR inlining.

We also no longer check if var.source_info.scope is the outermost scope. When a function gets inlined, the arguments to the inner function will no longer be in the outermost scope. What we care about though is whether they were in the outermost scope prior to inlining, which we know by whether we assigned an argument index.

Fixes #83217

I considered using `Option<NonZeroU16>` instead of `Option<u16>` to store the index. I didn't because `TypeFoldable` isn't implemented for `NonZeroU16` and because it looks like due to padding, it currently wouldn't make any difference. But I indexed from 1 anyway because (a) it'll make it easier if later it becomes worthwhile to use a `NonZeroU16` and because the arguments were previously indexed from 1, so it made for a smaller change.

This is my first PR on rust-lang/rust, so apologies if I've gotten anything not quite right.
2023-04-13 01:51:27 +00:00
Andrew Xie
9e0e4c31aa Added diagnostic for pin! macro in addition to Box::pin if Unpin isn't implemented 2023-04-12 18:03:11 -04:00
Oli Scherer
f263f88bea Split out a separate feature gate for impl trait in associated types 2023-04-12 16:17:31 +00:00
David Lattimore
a6292676eb Preserve argument indexes when inlining MIR
We store argument indexes on VarDebugInfo. Unlike the previous method of
relying on the variable index to know whether a variable is an argument,
this survives MIR inlining.

We also no longer check if var.source_info.scope is the outermost scope.
When a function gets inlined, the arguments to the inner function will
no longer be in the outermost scope. What we care about though is
whether they were in the outermost scope prior to inlining, which we
know by whether we assigned an argument index.
2023-04-11 11:07:48 +10:00
Nilstrieb
9e579cc10c Add test 2023-04-03 20:45:02 +02:00
Santiago Pastorino
eb7f64582d
Specialization involving RPITITs is broken so ignore the diagnostic differences for them 2023-03-28 17:54:24 -03:00
Santiago Pastorino
1c9ad28dd2
Do not feed param_env for RPITITs impl side 2023-03-22 14:06:22 -03:00
Santiago Pastorino
3b04ad2753
Do not suggest bounds restrictions for synthesized RPITITs 2023-03-21 13:18:32 -03:00
Matthias Krüger
d86fd83ef6
Rollup merge of #109277 - spastorino:new-rpitit-14, r=compiler-errors
Fix generics_of for impl's RPITIT synthesized associated type

The only useful commit is the last one.

This makes `generics_of` for the impl side RPITIT copy from the trait's associated type and avoid the fn on the impl side which was previously wrongly used.
This solution is better but we still need to fix resolution of the generated generics.

r? ``@compiler-errors``
2023-03-20 09:46:53 +01:00
Santiago Pastorino
640c20272e
Fix generics_of for impl's RPITIT synthesized associated type 2023-03-17 20:01:57 -03:00
Santiago Pastorino
9139ed076d
Fix impl_trait_ty_to_ty substs 2023-03-17 16:28:00 -03:00
Santiago Pastorino
e0302bbc3b
Add revisions for -Zlower-impl-trait-in-trait-to-assoc-ty fixed tests 2023-03-17 16:01:53 -03:00
Michael Goulet
0949da8f4e Install projection from RPITIT to default trait method opaque correctly 2023-03-16 01:56:49 +00:00