Auto merge of #109010 - compiler-errors:rtn, r=eholk
Initial support for return type notation (RTN) See: https://smallcultfollowing.com/babysteps/blog/2023/02/13/return-type-notation-send-bounds-part-2/ 1. Only supports `T: Trait<method(): Send>` style bounds, not `<T as Trait>::method(): Send`. Checking validity and injecting an implicit binder for all of the late-bound method generics is harder to do for the latter. * I'd add this in a follow-up. 3. ~Doesn't support RTN in general type position, i.e. no `let x: <T as Trait>::method() = ...`~ * I don't think we actually want this. 5. Doesn't add syntax for "eliding" the function args -- i.e. for now, we write `method(): Send` instead of `method(..): Send`. * May be a hazard if we try to add it in the future. I'll probably add it in a follow-up later, with a structured suggestion to change `method()` to `method(..)` once we add it. 7. ~I'm not in love with the feature gate name 😺~ * I renamed it to `return_type_notation` ✔️ Follow-up PRs will probably add support for `where T::method(): Send` bounds. I'm not sure if we ever want to support return-type-notation in arbitrary type positions. I may also make the bounds require `..` in the args list later. r? `@ghost`
This commit is contained in:
commit
7402519c63
49 changed files with 880 additions and 174 deletions
|
@ -328,7 +328,7 @@ pub struct GenericArgs<'hir> {
|
|||
/// Were arguments written in parenthesized form `Fn(T) -> U`?
|
||||
/// This is required mostly for pretty-printing and diagnostics,
|
||||
/// but also for changing lifetime elision rules to be "function-like".
|
||||
pub parenthesized: bool,
|
||||
pub parenthesized: GenericArgsParentheses,
|
||||
/// The span encompassing arguments and the surrounding brackets `<>` or `()`
|
||||
/// Foo<A, B, AssocTy = D> Fn(T, U, V) -> W
|
||||
/// ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^
|
||||
|
@ -340,11 +340,16 @@ pub struct GenericArgs<'hir> {
|
|||
|
||||
impl<'hir> GenericArgs<'hir> {
|
||||
pub const fn none() -> Self {
|
||||
Self { args: &[], bindings: &[], parenthesized: false, span_ext: DUMMY_SP }
|
||||
Self {
|
||||
args: &[],
|
||||
bindings: &[],
|
||||
parenthesized: GenericArgsParentheses::No,
|
||||
span_ext: DUMMY_SP,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inputs(&self) -> &[Ty<'hir>] {
|
||||
if self.parenthesized {
|
||||
if self.parenthesized == GenericArgsParentheses::ParenSugar {
|
||||
for arg in self.args {
|
||||
match arg {
|
||||
GenericArg::Lifetime(_) => {}
|
||||
|
@ -417,6 +422,17 @@ impl<'hir> GenericArgs<'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug)]
|
||||
#[derive(HashStable_Generic)]
|
||||
pub enum GenericArgsParentheses {
|
||||
No,
|
||||
/// Bounds for `feature(return_type_notation)`, like `T: Trait<method(..): Send>`,
|
||||
/// where the args are explicitly elided with `..`
|
||||
ReturnTypeNotation,
|
||||
/// parenthesized function-family traits, like `T: Fn(u32) -> i32`
|
||||
ParenSugar,
|
||||
}
|
||||
|
||||
/// A modifier on a bound, currently this is only used for `?Sized`, where the
|
||||
/// modifier is `Maybe`. Negative bounds should also be handled here.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Hash, Debug)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue