diff options
| author | Eric Holk <ericholk@microsoft.com> | 2022-04-07 18:06:53 -0700 |
|---|---|---|
| committer | Eric Holk <ericholk@microsoft.com> | 2022-09-12 16:55:55 -0700 |
| commit | eff35e59c698df379806add4c9f2c1d8d3fe55ca (patch) | |
| tree | 66d66c6c1604d75452a40ddb9b1f2e0d87ef86aa /compiler/rustc_parse/src | |
| parent | fa6ee9375242ae784dab1837dfc0b92f43e787ce (diff) | |
| download | rust-eff35e59c698df379806add4c9f2c1d8d3fe55ca.tar.gz rust-eff35e59c698df379806add4c9f2c1d8d3fe55ca.zip | |
Introduce dyn_star feature flag
The primary purpose of this commit is to introduce the dyn_star flag so we can begin experimenting with implementation. In order to have something to do in the feature gate test, we also add parser support for `dyn* Trait` objects. These are currently treated just like `dyn Trait` objects, but this will change in the future. Note that for now `dyn* Trait` is experimental syntax to enable implementing some of the machinery needed for async fn in dyn traits without fully supporting the feature.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 4a2cf74905b..ffe3618bc49 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -567,7 +567,8 @@ impl<'a> Parser<'a> { self.check_keyword(kw::Dyn) && (!self.token.uninterpolated_span().rust_2015() || self.look_ahead(1, |t| { - t.can_begin_bound() && !can_continue_type_after_non_fn_ident(t) + (t.can_begin_bound() || t.kind == TokenKind::BinOp(token::Star)) + && !can_continue_type_after_non_fn_ident(t) })) } @@ -576,10 +577,20 @@ impl<'a> Parser<'a> { /// Note that this does *not* parse bare trait objects. fn parse_dyn_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> { self.bump(); // `dyn` + + // parse dyn* types + let dyn_star = matches!(self.token.kind, TokenKind::BinOp(token::Star)); + let syntax = if dyn_star { + self.bump(); // `*` + TraitObjectSyntax::DynStar + } else { + TraitObjectSyntax::Dyn + }; + // Always parse bounds greedily for better error recovery. let bounds = self.parse_generic_bounds(None)?; *impl_dyn_multi = bounds.len() > 1 || self.prev_token.kind == TokenKind::BinOp(token::Plus); - Ok(TyKind::TraitObject(bounds, TraitObjectSyntax::Dyn)) + Ok(TyKind::TraitObject(bounds, syntax)) } /// Parses a type starting with a path. |
