rust/compiler
Michael Goulet d72d44d8ed
Rollup merge of #129629 - compiler-errors:rtn-in-path, r=jackh726
Implement Return Type Notation (RTN)'s path form in where clauses

Implement return type notation (RTN) in path position for where clauses. We already had RTN in associated type position ([e.g.](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=627a4fb8e2cb334863fbd08ed3722c09)), but per [the RFC](https://rust-lang.github.io/rfcs/3654-return-type-notation.html#where-rtn-can-be-used-for-now):

> As a standalone type, RTN can only be used as the Self type of a where-clause [...]

Specifically, in order to enable code like:

```rust
trait Foo {
    fn bar() -> impl Sized;
}

fn is_send(_: impl Send) {}

fn test<T>()
where
    T: Foo,
    T::bar(..): Send,
{
    is_send(T::bar());
}
```

* In the resolver, when we see a `TyKind::Path` whose final segment is `GenericArgs::ParenthesizedElided` (i.e. `(..)`), resolve that path in the *value* namespace, since we're looking for a method.
* When lowering where clauses in HIR lowering, we first try to intercept an RTN self type via `lower_ty_maybe_return_type_notation`. If we find an RTN type, we lower it manually in a way that respects its higher-ranked-ness (see below) and resolves to the corresponding RPITIT. Anywhere else, we'll emit the same "return type notation not allowed in this position yet" error we do when writing RTN in every other position.
* In `resolve_bound_vars`, we add some special treatment for RTN types in where clauses. Specifically, we need to add new lifetime variables to our binders for the early- and late-bound vars we encounter on the method. This implements the higher-ranked desugaring [laid out in the RFC](https://rust-lang.github.io/rfcs/3654-return-type-notation.html#converting-to-higher-ranked-trait-bounds).

This PR also adds a bunch of tests, mostly negative ones (testing error messages).

In a follow-up PR, I'm going to mark RTN as no longer incomplete, since this PR basically finishes the impl surface that we should initially stabilize, and the RFC was accepted.

cc [RFC 3654](https://github.com/rust-lang/rfcs/pull/3654) and https://github.com/rust-lang/rust/issues/109417
2024-09-21 15:18:56 -04:00
..
rustc disable size asserts in the compiler when randomizing layouts 2024-08-31 23:56:45 +02:00
rustc_abi Auto merge of #127546 - workingjubilee:5-level-paging-exists, r=saethlin 2024-09-21 16:20:10 +00:00
rustc_arena Remove unnecessary lifetimes from Arena. 2024-09-13 15:33:19 +10:00
rustc_ast Rollup merge of #130314 - compiler-errors:mac-prec, r=davidtwco 2024-09-17 17:28:33 +02:00
rustc_ast_ir
rustc_ast_lowering Add missing diagnostics and flesh out tests 2024-09-20 22:18:57 -04:00
rustc_ast_passes stabilize const_extern_fn 2024-09-14 18:07:06 +02:00
rustc_ast_pretty Add initial support for raw lifetimes 2024-09-06 10:32:48 -04:00
rustc_attr Remove needless returns detected by clippy in the compiler 2024-09-09 13:32:22 +02:00
rustc_baked_icu_data
rustc_borrowck Begin experimental support for pin reborrowing 2024-09-18 12:36:31 -07:00
rustc_builtin_macros Rename and reorder lots of lifetimes. 2024-09-13 15:46:20 +10:00
rustc_codegen_cranelift add C-cmse-nonsecure-entry ABI 2024-09-21 13:04:14 +02:00
rustc_codegen_gcc Reorder ConstMethods. 2024-09-19 20:10:42 +10:00
rustc_codegen_llvm remove #[cmse_nonsecure_entry] 2024-09-21 13:05:21 +02:00
rustc_codegen_ssa Rollup merge of #127766 - folkertdev:c-cmse-nonsecure-entry, r=jackh726 2024-09-21 15:18:55 -04:00
rustc_const_eval layout computation: eagerly error for unexpected unsized fields 2024-09-16 15:53:21 +02:00
rustc_data_structures Add an internal lint that warns when accessing untracked data 2024-09-03 19:14:19 +02:00
rustc_driver
rustc_driver_impl Auto merge of #124895 - obeis:static-mut-hidden-ref, r=compiler-errors 2024-09-20 17:25:34 +00:00
rustc_error_codes mark E0775 as no longer emitte by the compiler 2024-09-21 13:09:09 +02:00
rustc_error_messages
rustc_errors Add suggestions for expressions in patterns 2024-09-18 20:38:43 +02:00
rustc_expand Remove unnecessary lifetimes from rustc_expand. 2024-09-13 15:33:21 +10:00
rustc_feature remove #[cmse_nonsecure_entry] 2024-09-21 13:05:21 +02:00
rustc_fluent_macro fluent_macro: fix diagnostics for fluent parse failures 2024-09-17 14:49:33 +00:00
rustc_fs_util
rustc_graphviz
rustc_hir Allow shortening reborrows 2024-09-19 15:34:00 -07:00
rustc_hir_analysis Rollup merge of #129629 - compiler-errors:rtn-in-path, r=jackh726 2024-09-21 15:18:56 -04:00
rustc_hir_pretty
rustc_hir_typeck Auto merge of #127546 - workingjubilee:5-level-paging-exists, r=saethlin 2024-09-21 16:20:10 +00:00
rustc_incremental Also fix if in else 2024-09-11 17:24:01 -04:00
rustc_index assert that unexpectedly unsized fields are sized in the param env 2024-09-17 00:06:56 +02:00
rustc_index_macros
rustc_infer Rollup merge of #130114 - eduardosm:needless-returns, r=compiler-errors 2024-09-11 15:53:22 -07:00
rustc_interface Rollup merge of #129988 - arnaudgolfouse:modify-locale_resources, r=davidtwco 2024-09-17 17:28:32 +02:00
rustc_lexer Add initial support for raw lifetimes 2024-09-06 10:32:48 -04:00
rustc_lint Auto merge of #130599 - jieyouxu:snake_case_binary_cleanup, r=petrochenkov 2024-09-21 11:16:38 +00:00
rustc_lint_defs Auto merge of #124895 - obeis:static-mut-hidden-ref, r=compiler-errors 2024-09-20 17:25:34 +00:00
rustc_llvm Update the minimum external LLVM to 18 2024-09-18 13:53:31 -07:00
rustc_log
rustc_macros
rustc_metadata Encode coroutine_by_move_body_def_id in crate metadata 2024-09-16 19:59:04 -04:00
rustc_middle Rollup merge of #127766 - folkertdev:c-cmse-nonsecure-entry, r=jackh726 2024-09-21 15:18:55 -04:00
rustc_mir_build Rollup merge of #130526 - eholk:pin-reborrow, r=compiler-errors 2024-09-20 19:46:38 +02:00
rustc_mir_dataflow Rollup merge of #130294 - nnethercote:more-lifetimes, r=lcnr 2024-09-14 18:12:13 +02:00
rustc_mir_transform Rollup merge of #130201 - compiler-errors:foreign-synthetic-body, r=lcnr 2024-09-17 17:28:32 +02:00
rustc_monomorphize Rollup merge of #130235 - compiler-errors:nested-if, r=michaelwoerister 2024-09-12 20:37:16 +10:00
rustc_next_trait_solver add comment 2024-09-20 14:49:03 +00:00
rustc_parse Add suggestions for expressions in patterns 2024-09-18 20:38:43 +02:00
rustc_parse_format
rustc_passes remove #[cmse_nonsecure_entry] 2024-09-21 13:05:21 +02:00
rustc_pattern_analysis Revert warning empty patterns as unreachable 2024-09-11 18:36:45 +02:00
rustc_privacy Rename and reorder lots of lifetimes. 2024-09-13 15:46:20 +10:00
rustc_query_impl Rename and reorder lots of lifetimes. 2024-09-13 15:46:20 +10:00
rustc_query_system chore: Fix typos in 'compiler' (batch 2) 2024-09-02 07:50:22 +02:00
rustc_resolve Flesh out some TODOs 2024-09-20 22:18:57 -04:00
rustc_sanitizers Only expect mono consts in CFI 2024-09-20 20:38:13 -04:00
rustc_serialize Auto merge of #129777 - nnethercote:unreachable_pub-4, r=Urgau 2024-09-03 01:27:20 +00:00
rustc_session Rollup merge of #128961 - GKFX:issue-128930-explain-missing-option, r=jieyouxu 2024-09-17 17:28:31 +02:00
rustc_smir add C-cmse-nonsecure-entry ABI 2024-09-21 13:04:14 +02:00
rustc_span Rollup merge of #130526 - eholk:pin-reborrow, r=compiler-errors 2024-09-20 19:46:38 +02:00
rustc_symbol_mangling Rollup merge of #130485 - compiler-errors:impossible-types, r=BoxyUwU 2024-09-20 06:43:38 +02:00
rustc_target disallow cmse ABIs on unsupported platforms 2024-09-21 13:05:23 +02:00
rustc_trait_selection Auto merge of #127546 - workingjubilee:5-level-paging-exists, r=saethlin 2024-09-21 16:20:10 +00:00
rustc_traits Add warn(unreachable_pub) to rustc_traits. 2024-09-03 08:49:54 +10:00
rustc_transmute layout computation: eagerly error for unexpected unsized fields 2024-09-16 15:53:21 +02:00
rustc_ty_utils add C-cmse-nonsecure-entry ABI 2024-09-21 13:04:14 +02:00
rustc_type_ir Rollup merge of #130311 - heiseish:issue-70849-fix, r=fmease 2024-09-14 20:22:41 +10:00
rustc_type_ir_macros
stable_mir add C-cmse-nonsecure-entry ABI 2024-09-21 13:04:14 +02:00