Commit Graph

196 Commits

Author SHA1 Message Date
clubby789
be0b42fabe Recover from incorrectly ordered/duplicated function keywords 2023-10-27 18:29:43 +00:00
Matthias Krüger
4e4e5619af
Rollup merge of #117175 - oli-obk:gen_fn_split, r=compiler-errors
Rename AsyncCoroutineKind to CoroutineSource

pulled out of https://github.com/rust-lang/rust/pull/116447

Also refactors the printing infra of `CoroutineSource` to be ready for easily extending it with a `Gen` variant for `gen` blocks
2023-10-25 23:37:11 +02:00
Oli Scherer
92b41eeee6 Rename in preparation for moving the async printing out of CoroutineSource 2023-10-25 16:37:14 +00:00
Matthias Krüger
96074bec97
Rollup merge of #117133 - compiler-errors:coherence-constrained, r=oli-obk
Merge `impl_wf_inference` (`check_mod_impl_wf`) check into coherence checking

Problem here is that we call `collect_impl_trait_in_trait_types` when checking `check_mod_impl_wf` which is performed before coherence. Due to the `tcx.sess.track_errors`, since we end up reporting an error, we never actually proceed to coherence checking, where we would be emitting a more useful impl overlap error.

This change means that we may report more errors in some cases, but can at least proceed far enough to leave a useful message for overlapping traits with RPITITs in them.

Fixes #116982

r? types
2023-10-25 17:40:29 +02:00
bors
848a387967 Auto merge of #116482 - matthewjasper:thir-unsafeck-inline-constants, r=b-naber
Fix inline const pattern unsafety checking in THIR

Fix THIR unsafety checking of inline constants.
- Steal THIR in THIR unsafety checking (if enabled) instead of MIR lowering.
- Represent inline constants in THIR patterns.
2023-10-25 00:03:57 +00:00
Michael Goulet
a947654a96 Merge impl_wf_inference into coherence checking 2023-10-24 17:01:25 +00:00
Michael Goulet
90e3aaeca2 Remove incomplete features from RPITIT/AFIT tests 2023-10-24 15:27:06 +00:00
bors
a56bd2b944 Auto merge of #116849 - oli-obk:error_shenanigans, r=cjgillot
Avoid a `track_errors` by bubbling up most errors from `check_well_formed`

I believe `track_errors` is mostly papering over issues that a sufficiently convoluted query graph can hit. I made this change, while the actual change I want to do is to stop bailing out early on errors, and instead use this new `ErrorGuaranteed` to invoke `check_well_formed` for individual items before doing all the `typeck` logic on them.

This works towards resolving https://github.com/rust-lang/rust/issues/97477 and various other ICEs, as well as allowing us to use parallel rustc more (which is currently rather limited/bottlenecked due to the very sequential nature in which we do `rustc_hir_analysis::check_crate`)

cc `@SparrowLii` `@Zoxc` for the new `try_par_for_each_in` function
2023-10-23 09:59:40 +00:00
bors
9372999916 Auto merge of #116256 - apekros:issue-114912, r=cjgillot
Add test for rust-lang#114912

Closes #114912
2023-10-22 11:57:18 +00:00
Lukas Markeffsky
ccc4638d73 fix spans for removing .await on for expressions 2023-10-21 13:18:00 +02:00
Oli Scherer
af93c20c06 Rename lots of files that had generator in their name 2023-10-20 21:14:02 +00:00
Oli Scherer
e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer
60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Oli Scherer
fd9ef69adf Avoid a track_errors by bubbling up most errors from check_well_formed 2023-10-20 08:46:27 +00:00
Michael Goulet
ea73f10867 Don't ICE when encountering unresolved regions in fully_resolve 2023-10-18 20:39:29 +00:00
Matthew Jasper
5cc83fd4a5 Fix inline const pattern unsafety checking in THIR
THIR unsafety checking was getting a cycle of
function unsafety checking
-> building THIR for the function
-> evaluating pattern inline constants in the function
-> building MIR for the inline constant
-> checking unsafety of functions (so that THIR can be stolen)
This is fixed by not stealing THIR when generating MIR but instead when
unsafety checking.
This leaves an issue with pattern inline constants not being unsafety
checked because they are evaluated away when generating THIR.
To fix that we now represent inline constants in THIR patterns and
visit them in THIR unsafety checking.
2023-10-16 15:57:59 +00:00
Matthias Krüger
24116aebe0
Rollup merge of #116704 - compiler-errors:afit-lint-plus, r=tmandry
Fix AFIT lint message to mention pitfall

Addresses https://github.com/rust-lang/rust/pull/116184#issuecomment-1745194387 by adding a short note. Not sure exactly of the wording -- I don't think this should be a blocker for the stabilization PR since we can iterate on this lint's messaging in the next few weeks in the worst case.

r? `@tmandry` cc `@traviscross` `@jonhoo`
2023-10-14 13:36:29 +02:00
Michael Goulet
59315b8a63 Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
Michael Goulet
362b75badf Fix AFIT lint message to mention pitfall 2023-10-13 19:13:18 +00:00
Ali MJ Al-Nasrawy
a8830631b9 remove trailing dots 2023-10-08 10:06:17 +00:00
Ali MJ Al-Nasrawy
996ffcb718 always show and explain sub region 2023-10-08 09:59:51 +00:00
Ali MJ Al-Nasrawy
5be0b2283a improve the suggestion of generic_bound_failure 2023-10-08 09:56:57 +00:00
Matthias Krüger
c1c5ab717e
Rollup merge of #116428 - Alexendoo:note-duplicate-diagnostics, r=compiler-errors,estebank
Add a note to duplicate diagnostics

Helps explain why there may be a difference between manual testing and the test suite output and highlights them as something to potentially look into

For existing duplicate diagnostics I just blessed them other than a few files that had other `NOTE` annotations in
2023-10-05 19:24:35 +02:00
Jubilee
d7b02c3d40
Rollup merge of #116431 - estebank:issue-80476, r=compiler-errors
Tweak wording of E0562

Fix #80476.
2023-10-05 00:56:30 -07:00
bors
5236c8e1fa Auto merge of #116273 - compiler-errors:refine2, r=tmandry
Only trigger `refining_impl_trait` lint on reachable traits

Public but unreachable traits don't matter 😸

r? `@tmandry`
2023-10-05 03:00:30 +00:00
bors
b781645332 Auto merge of #116184 - compiler-errors:afit-lint, r=tmandry
Add `async_fn_in_trait` lint

cc https://github.com/rust-lang/rust/pull/115822#issuecomment-1731168465

Mostly unsure what the messaging should be. Feedback required.

r? `@tmandry`
2023-10-05 01:14:25 +00:00
Alex Macleod
5453a9f34d Add a note to duplicate diagnostics 2023-10-05 01:04:41 +00:00
Esteban Küber
041e54bd92 Tweak wording of E0562
Fix #80476.
2023-10-04 19:51:43 +00:00
bors
65519f5fc0 Auto merge of #116360 - compiler-errors:async-span, r=oli-obk
Point to full `async fn` for future

Semi-follow-up to https://github.com/rust-lang/rust/pull/116296#discussion_r1342007575

cc `@asquared31415`
2023-10-04 09:55:02 +00:00
Matthias Krüger
535cd8d511
Rollup merge of #114654 - estebank:suggest-pin-macro, r=davidtwco
Suggest `pin!()` instead of `Pin::new()` when appropriate

When encountering a type that needs to be pinned but that is `!Unpin`, suggest using the `pin!()` macro.

Fix #57994.
2023-10-03 16:24:15 +02:00
Michael Goulet
2934fe07b7 Point to full async fn for future 2023-10-03 02:25:32 +00:00
Michael Goulet
c373d206cd Address review nits 2023-10-03 00:51:13 +00:00
Michael Goulet
90dfa24415 Only reachable traits 2023-10-03 00:37:18 +00:00
Travis Cross
afea0b4eab Fill in prose to describe the async_fn_in_trait lint
We're stabilizing `async fn` in trait (AFIT), but we have some
reservations about how people might use this in the definitions of
publicly-visible traits, so we're going to lint about that.

This is a bit of an odd lint for `rustc`.  We normally don't lint just
to have people confirm that they understand how Rust works.  But in
this one exceptional case, this seems like the right thing to do as
compared to the other plausible alternatives.

In this commit, we describe the nature of this odd lint.
2023-10-03 00:37:18 +00:00
Michael Goulet
28d58f6524 Bless tests 2023-10-03 00:37:18 +00:00
Michael Goulet
ec79720c1e Add async_fn_in_trait lint 2023-10-03 00:37:18 +00:00
Michael Goulet
06d9602d33 Only trigger refine lint on reachable traits 2023-09-29 18:36:41 +00:00
apekros
e71ee500d1 Add test for rust-lang#114912 2023-09-29 22:39:02 +10:00
bors
c5450191f3 Auto merge of #115759 - oli-obk:open_drop_from_non-ADT, r=lcnr
Reveal opaque types before drop elaboration

fixes https://github.com/rust-lang/rust/issues/113594

r? `@cjgillot`

cc `@JakobDegen`

This pass was introduced in https://github.com/rust-lang/rust/pull/110714

I moved it before drop elaboration (which only cares about the hidden types of things, not the opaque TAIT or RPIT type) and set it to run unconditionally (instead of depending on the optimization level and whether the inliner is active)
2023-09-29 11:59:51 +00:00
bors
7b4d9e155f Auto merge of #115659 - compiler-errors:itp, r=cjgillot
Stabilize `impl_trait_projections`

Closes #115659

## TL;DR:

This allows us to mention `Self` and `T::Assoc` in async fn and return-position `impl Trait`, as you would expect you'd be able to.

Some examples:
```rust
#![feature(return_position_impl_trait_in_trait, async_fn_in_trait)]
// (just needed for final tests below)

// ---------------------------------------- //

struct Wrapper<'a, T>(&'a T);

impl Wrapper<'_, ()> {
    async fn async_fn() -> Self {
        //^ Previously rejected because it returns `-> Self`, not `-> Wrapper<'_, ()>`.
        Wrapper(&())
    }

    fn impl_trait() -> impl Iterator<Item = Self> {
        //^ Previously rejected because it mentions `Self`, not `Wrapper<'_, ()>`.
        std::iter::once(Wrapper(&()))
    }
}

// ---------------------------------------- //

trait Trait<'a> {
    type Assoc;
    fn new() -> Self::Assoc;
}
impl Trait<'_> for () {
    type Assoc = ();
    fn new() {}
}

impl<'a, T: Trait<'a>> Wrapper<'a, T> {
    async fn mk_assoc() -> T::Assoc {
        //^ Previously rejected because `T::Assoc` doesn't mention `'a` in the HIR,
        //  but ends up resolving to `<T as Trait<'a>>::Assoc`, which does rely on `'a`.
        // That's the important part -- the elided trait.
        T::new()
    }

    fn a_few_assocs() -> impl Iterator<Item = T::Assoc> {
        //^ Previously rejected for the same reason
        [T::new(), T::new(), T::new()].into_iter()
    }
}

// ---------------------------------------- //

trait InTrait {
    async fn async_fn() -> Self;

    fn impl_trait() -> impl Iterator<Item = Self>;
}

impl InTrait for &() {
    async fn async_fn() -> Self { &() }
    //^ Previously rejected just like inherent impls

    fn impl_trait() -> impl Iterator<Item = Self> {
        //^ Previously rejected just like inherent impls
        [&()].into_iter()
    }
}
```

## Technical:

Lifetimes in return-position `impl Trait` (and `async fn`) are duplicated as early-bound generics local to the opaque in order to make sure we are able to substitute any late-bound lifetimes from the function in the opaque's hidden type. (The [dev guide](https://rustc-dev-guide.rust-lang.org/return-position-impl-trait-in-trait.html#aside-opaque-lifetime-duplication) has a small section about why this is necessary -- this was written for RPITITs, but it applies to all RPITs)

Prior to #103491, all of the early-bound lifetimes not local to the opaque were replaced with `'static` to avoid issues where relating opaques caused their *non-captured* lifetimes to be related. This `'static` replacement led to strange and possibly unsound behaviors (https://github.com/rust-lang/rust/issues/61949#issuecomment-508836314) (https://github.com/rust-lang/rust/issues/53613) when referencing the `Self` type alias in an impl or indirectly referencing a lifetime parameter via a projection type (via a `T::Assoc` projection without an explicit trait), since lifetime resolution is performed on the HIR, when neither `T::Assoc`-style projections or `Self` in impls are expanded.

Therefore an error was implemented in #62849 to deny this subtle behavior as a known limitation of the compiler. It was attempted by `@cjgillot` to fix this in #91403, which was subsequently unlanded. Then it was re-attempted to much success (🎉) in #103491, which is where we currently are in the compiler.

The PR above (#103491) fixed this issue technically by *not* replacing the opaque's parent lifetimes with `'static`, but instead using variance to properly track which lifetimes are captured and are not. The PR gated any of the "side-effects" of the PR behind a feature gate (`impl_trait_projections`) presumably to avoid having to involve T-lang or T-types in the PR as well. `@cjgillot` can clarify this if I'm misunderstanding what their intention was with the feature gate.

Since we're not replacing (possibly *invariant*!) lifetimes with `'static` anymore, there are no more soundness concerns here. Therefore, this PR removes the feature gate.

Tests:
* `tests/ui/async-await/feature-self-return-type.rs`
* `tests/ui/impl-trait/feature-self-return-type.rs`
* `tests/ui/async-await/issues/issue-78600.rs`
* `tests/ui/impl-trait/capture-lifetime-not-in-hir.rs`

---

r? cjgillot on the impl (not much, just removing the feature gate)

I'm gonna mark this as FCP for T-lang and T-types.
2023-09-28 21:35:18 +00:00
Oli Scherer
6ea2db7c2d Strip OpaqueCast during RevealAll. 2023-09-28 16:13:38 +00:00
Milo
35f9345076 add test
fix tidy

remove dir
2023-09-26 20:15:28 +00:00
Camille GILLOT
211d2ed07b Bless tests. 2023-09-23 13:47:30 +00:00
Camille GILLOT
a626caaad9 Revert duplication of tests. 2023-09-23 13:34:07 +00:00
Michael Goulet
79d685325c Check types live across yields in generators too 2023-09-23 04:19:14 +00:00
Matthias Krüger
952d6608fc
Rollup merge of #116062 - eduardosm:start-fn-diag, r=WaffleLapkin
Change `start` to `#[start]` in some diagnosis

They refer to a function with the `start` attribute, but not necessarily named `start`.
2023-09-22 23:12:37 +02:00
bors
959b2c703d Auto merge of #115696 - RalfJung:closure-ty-print, r=oli-obk
adjust how closure/generator types are printed

I saw `&[closure@$DIR/issue-20862.rs:2:5]` and I thought it is a slice type, because that's usually what `&[_]` is... it took me a while to realize that this is just a confusing printer and actually there's no slice. Let's use something that cannot be mistaken for a regular type.
2023-09-22 15:19:38 +00:00
Eduardo Sánchez Muñoz
17dfabff9c Change start to #[start] in some diagnosis
They refer to a function with the `start` attribute, but not necessarily named `start`.
2023-09-22 15:58:43 +02:00
Matthias Krüger
06608c7860
Rollup merge of #116036 - Enselic:split-large_moves, r=oli-obk
tests/ui: Split large_moves.rs and move to lint/large_assignments

To make failing tests easier to debug with `--emit=mir`, etc.

Don't bother with `revisions: attribute option` for both tests though. Seems sufficient to just have that on one of the tests.

`git show -M --find-renames=40%` makes the diff easier to review. Or note that before this change we had one test with 4 errors, now we have 2 tests with 2 errors each.

r? `@oli-obk`

Part of https://github.com/rust-lang/rust/issues/83518
2023-09-22 12:15:26 +02:00
Ralf Jung
c4ec12f4b7 adjust how closure/generator types and rvalues are printed 2023-09-21 22:20:58 +02:00