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.
This commit is contained in:
Eric Holk 2022-04-07 18:06:53 -07:00
parent fa6ee93752
commit eff35e59c6
8 changed files with 63 additions and 3 deletions

View file

@ -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.