diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-04-12 13:32:15 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-04-12 16:17:31 +0000 |
| commit | f263f88beacce82ef7098dadd25e44eb349aa3c2 (patch) | |
| tree | f08b20c030db2911051c8f18aa491fbe8197460e /compiler | |
| parent | 9be9b5e09ad834e2ba9f2571ca17059e18f89b71 (diff) | |
| download | rust-f263f88beacce82ef7098dadd25e44eb349aa3c2.tar.gz rust-f263f88beacce82ef7098dadd25e44eb349aa3c2.zip | |
Split out a separate feature gate for impl trait in associated types
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ast_passes/src/feature_gate.rs | 30 | ||||
| -rw-r--r-- | compiler/rustc_feature/src/active.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_span/src/symbol.rs | 1 |
3 files changed, 23 insertions, 10 deletions
diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 007d64f681f..9cbc4b2e2dc 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -121,24 +121,34 @@ impl<'a> PostExpansionVisitor<'a> { } /// Feature gate `impl Trait` inside `type Alias = $type_expr;`. - fn check_impl_trait(&self, ty: &ast::Ty) { + fn check_impl_trait(&self, ty: &ast::Ty, in_associated_ty: bool) { struct ImplTraitVisitor<'a> { vis: &'a PostExpansionVisitor<'a>, + in_associated_ty: bool, } impl Visitor<'_> for ImplTraitVisitor<'_> { fn visit_ty(&mut self, ty: &ast::Ty) { if let ast::TyKind::ImplTrait(..) = ty.kind { - gate_feature_post!( - &self.vis, - type_alias_impl_trait, - ty.span, - "`impl Trait` in type aliases is unstable" - ); + if self.in_associated_ty { + gate_feature_post!( + &self.vis, + impl_trait_in_assoc_type, + ty.span, + "`impl Trait` in associated types is unstable" + ); + } else { + gate_feature_post!( + &self.vis, + type_alias_impl_trait, + ty.span, + "`impl Trait` in type aliases is unstable" + ); + } } visit::walk_ty(self, ty); } } - ImplTraitVisitor { vis: self }.visit_ty(ty); + ImplTraitVisitor { vis: self, in_associated_ty }.visit_ty(ty); } fn check_late_bound_lifetime_defs(&self, params: &[ast::GenericParam]) { @@ -294,7 +304,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } ast::ItemKind::TyAlias(box ast::TyAlias { ty: Some(ty), .. }) => { - self.check_impl_trait(&ty) + self.check_impl_trait(&ty, false) } _ => {} @@ -517,7 +527,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { ); } if let Some(ty) = ty { - self.check_impl_trait(ty); + self.check_impl_trait(ty, true); } false } diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 426c6727adc..eea185c12dd 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -416,6 +416,8 @@ declare_features! ( (active, half_open_range_patterns_in_slices, "1.66.0", Some(67264), None), /// Allows `if let` guard in match arms. (active, if_let_guard, "1.47.0", Some(51114), None), + /// Allows `impl Trait` to be used inside associated types (RFC 2515). + (active, impl_trait_in_assoc_type, "CURRENT_RUSTC_VERSION", Some(63063), None), /// Allows `impl Trait` as output type in `Fn` traits in return position of functions. (active, impl_trait_in_fn_trait_return, "1.64.0", Some(99697), None), /// Allows referencing `Self` and projections in impl-trait. diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 7affad9aa01..236f85a8e08 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -800,6 +800,7 @@ symbols! { ignore, impl_header_lifetime_elision, impl_lint_pass, + impl_trait_in_assoc_type, impl_trait_in_bindings, impl_trait_in_fn_trait_return, impl_trait_projections, |
