Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit eff35e5

Browse files
committed
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.
1 parent fa6ee93 commit eff35e5

File tree

8 files changed

+63
-3
lines changed

8 files changed

+63
-3
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,7 @@ impl TyKind {
20722072
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
20732073
pub enum TraitObjectSyntax {
20742074
Dyn,
2075+
DynStar,
20752076
None,
20762077
}
20772078

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_session::lint::builtin::{
1919
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, PATTERNS_IN_FNS_WITHOUT_BODY,
2020
};
2121
use rustc_session::lint::{BuiltinLintDiagnostics, LintBuffer};
22+
use rustc_session::parse::feature_err;
2223
use rustc_session::Session;
2324
use rustc_span::source_map::Spanned;
2425
use rustc_span::symbol::{kw, sym, Ident};
@@ -753,7 +754,19 @@ impl<'a> AstValidator<'a> {
753754
self.maybe_lint_missing_abi(sig_span, ty.id);
754755
}
755756
}
756-
TyKind::TraitObject(ref bounds, ..) => {
757+
TyKind::TraitObject(ref bounds, syntax, ..) => {
758+
if syntax == TraitObjectSyntax::DynStar
759+
&& !self.session.features_untracked().dyn_star
760+
{
761+
feature_err(
762+
&self.session.parse_sess,
763+
sym::dyn_star,
764+
ty.span,
765+
"dyn* trait objects are unstable",
766+
)
767+
.emit();
768+
}
769+
757770
let mut any_lifetime_bounds = false;
758771
for bound in bounds {
759772
if let GenericBound::Outlives(ref lifetime) = *bound {

compiler/rustc_feature/src/active.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ declare_features! (
380380
(active, doc_cfg_hide, "1.57.0", Some(43781), None),
381381
/// Allows `#[doc(masked)]`.
382382
(active, doc_masked, "1.21.0", Some(44027), None),
383+
/// Allows `dyn* Trait` objects.
384+
(active, dyn_star, "1.65.0", Some(91611), None),
383385
/// Allows `X..Y` patterns.
384386
(active, exclusive_range_pattern, "1.11.0", Some(37854), None),
385387
/// Allows exhaustive pattern matching on types that contain uninhabited types.

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,8 @@ impl<'a> Parser<'a> {
567567
self.check_keyword(kw::Dyn)
568568
&& (!self.token.uninterpolated_span().rust_2015()
569569
|| self.look_ahead(1, |t| {
570-
t.can_begin_bound() && !can_continue_type_after_non_fn_ident(t)
570+
(t.can_begin_bound() || t.kind == TokenKind::BinOp(token::Star))
571+
&& !can_continue_type_after_non_fn_ident(t)
571572
}))
572573
}
573574

@@ -576,10 +577,20 @@ impl<'a> Parser<'a> {
576577
/// Note that this does *not* parse bare trait objects.
577578
fn parse_dyn_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> {
578579
self.bump(); // `dyn`
580+
581+
// parse dyn* types
582+
let dyn_star = matches!(self.token.kind, TokenKind::BinOp(token::Star));
583+
let syntax = if dyn_star {
584+
self.bump(); // `*`
585+
TraitObjectSyntax::DynStar
586+
} else {
587+
TraitObjectSyntax::Dyn
588+
};
589+
579590
// Always parse bounds greedily for better error recovery.
580591
let bounds = self.parse_generic_bounds(None)?;
581592
*impl_dyn_multi = bounds.len() > 1 || self.prev_token.kind == TokenKind::BinOp(token::Plus);
582-
Ok(TyKind::TraitObject(bounds, TraitObjectSyntax::Dyn))
593+
Ok(TyKind::TraitObject(bounds, syntax))
583594
}
584595

585596
/// Parses a type starting with a path.

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ symbols! {
649649
dropck_parametricity,
650650
dylib,
651651
dyn_metadata,
652+
dyn_star,
652653
dyn_trait,
653654
e,
654655
edition_macro_pats,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Feature gate test for dyn_star
2+
3+
/// dyn* is not necessarily the final surface syntax (if we have one at all),
4+
/// but for now we will support it to aid in writing tests independently.
5+
pub fn dyn_star_parameter(_: &dyn* Send) {
6+
//~^ dyn* trait objects are unstable
7+
}
8+
9+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: dyn* trait objects are unstable
2+
--> $DIR/feature-gate-dyn_star.rs:5:31
3+
|
4+
LL | pub fn dyn_star_parameter(_: &dyn* Send) {
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
8+
= help: add `#![feature(dyn_star)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/dyn-star/syntax.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Make sure we can parse the `dyn* Trait` syntax
2+
//
3+
// check-pass
4+
5+
6+
#![feature(dyn_star)]
7+
8+
pub fn dyn_star_parameter(_: &dyn* Send) {
9+
}
10+
11+
fn main() {}

0 commit comments

Comments
 (0)