diff options
author | bors <bors@rust-lang.org> | 2023-03-31 18:04:12 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2023-03-31 18:04:12 +0000 |
commit | 7402519c6303000d49f67a57c96b6863c88a9163 (patch) | |
tree | d96f0a14a6c2dd6aeafe33278687acd12b6e2cca /compiler/rustc_ast | |
parent | 480068c2359ea65df4481788b5ce717a548ce171 (diff) | |
parent | 8b592db27afdc9edac084520bca98508da53c996 (diff) | |
download | rust-7402519c6303000d49f67a57c96b6863c88a9163.tar.gz |
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` :heavy_check_mark:
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`
Diffstat (limited to 'compiler/rustc_ast')
-rw-r--r-- | compiler/rustc_ast/src/ast.rs | 16 | ||||
-rw-r--r-- | compiler/rustc_ast/src/mut_visit.rs | 1 | ||||
-rw-r--r-- | compiler/rustc_ast/src/visit.rs | 1 |
3 files changed, 12 insertions, 6 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index cc0fc7b8358..9b6bfaadef0 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -167,6 +167,9 @@ pub enum GenericArgs { AngleBracketed(AngleBracketedArgs), /// The `(A, B)` and `C` in `Foo(A, B) -> C`. Parenthesized(ParenthesizedArgs), + /// Associated return type bounds, like `T: Trait<method(..): Send>` + /// which applies the `Send` bound to the return-type of `method`. + ReturnTypeNotation(Span), } impl GenericArgs { @@ -178,6 +181,7 @@ impl GenericArgs { match self { AngleBracketed(data) => data.span, Parenthesized(data) => data.span, + ReturnTypeNotation(span) => *span, } } } @@ -231,15 +235,15 @@ impl AngleBracketedArg { } } -impl Into<Option<P<GenericArgs>>> for AngleBracketedArgs { - fn into(self) -> Option<P<GenericArgs>> { - Some(P(GenericArgs::AngleBracketed(self))) +impl Into<P<GenericArgs>> for AngleBracketedArgs { + fn into(self) -> P<GenericArgs> { + P(GenericArgs::AngleBracketed(self)) } } -impl Into<Option<P<GenericArgs>>> for ParenthesizedArgs { - fn into(self) -> Option<P<GenericArgs>> { - Some(P(GenericArgs::Parenthesized(self))) +impl Into<P<GenericArgs>> for ParenthesizedArgs { + fn into(self) -> P<GenericArgs> { + P(GenericArgs::Parenthesized(self)) } } diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 46e46ab575e..514978f5569 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -561,6 +561,7 @@ pub fn noop_visit_generic_args<T: MutVisitor>(generic_args: &mut GenericArgs, vi match generic_args { GenericArgs::AngleBracketed(data) => vis.visit_angle_bracketed_parameter_data(data), GenericArgs::Parenthesized(data) => vis.visit_parenthesized_parameter_data(data), + GenericArgs::ReturnTypeNotation(_span) => {} } } diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 608f87ab6eb..e5a0ad1f1e4 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -481,6 +481,7 @@ where walk_list!(visitor, visit_ty, &data.inputs); walk_fn_ret_ty(visitor, &data.output); } + GenericArgs::ReturnTypeNotation(_span) => {} } } |