Skip to content

Commit bdff946

Browse files
committed
Add universal_impl_trait feature gate
Move feature gate check to inside HIR lowering. Change error messages and update tests.
1 parent 109f2dd commit bdff946

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

src/librustc/hir/lowering.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,9 +771,21 @@ impl<'a> LoweringContext<'a> {
771771
use syntax::feature_gate::{emit_feature_err, GateIssue};
772772
match itctx {
773773
ImplTraitContext::Existential => {
774+
let has_feature = self.sess.features.borrow().conservative_impl_trait;
775+
if !t.span.allows_unstable() && !has_feature {
776+
emit_feature_err(&self.sess.parse_sess, "conservative_impl_trait",
777+
t.span, GateIssue::Language,
778+
"`impl Trait` in return position is experimental");
779+
}
774780
hir::TyImplTraitExistential(self.lower_bounds(bounds, itctx))
775781
},
776782
ImplTraitContext::Universal(def_id) => {
783+
let has_feature = self.sess.features.borrow().universal_impl_trait;
784+
if !t.span.allows_unstable() && !has_feature {
785+
emit_feature_err(&self.sess.parse_sess, "universal_impl_trait",
786+
t.span, GateIssue::Language,
787+
"`impl Trait` in argument position is experimental");
788+
}
777789
hir::TyImplTraitUniversal(def_id, self.lower_bounds(bounds, itctx))
778790
},
779791
ImplTraitContext::Disallowed => {

src/libsyntax/feature_gate.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ declare_features! (
275275
// Allows `impl Trait` in function return types.
276276
(active, conservative_impl_trait, "1.12.0", Some(34511)),
277277

278+
// Allows `impl Trait` in function arguments.
279+
(active, universal_impl_trait, "1.23.0", Some(34511)),
280+
278281
// The `!` type
279282
(active, never_type, "1.13.0", Some(35121)),
280283

@@ -1451,10 +1454,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
14511454
ast::TyKind::BareFn(ref bare_fn_ty) => {
14521455
self.check_abi(bare_fn_ty.abi, ty.span);
14531456
}
1454-
ast::TyKind::ImplTrait(..) => {
1455-
gate_feature_post!(&self, conservative_impl_trait, ty.span,
1456-
"`impl Trait` is experimental");
1457-
}
14581457
ast::TyKind::Never => {
14591458
gate_feature_post!(&self, never_type, ty.span,
14601459
"The `!` type is experimental");
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// gate-test-universal_impl_trait
12+
13+
fn foo(x: impl std::fmt::Debug) { print!("{:?}", x); }
14+
//~^ ERROR `impl Trait` in argument position is experimental
15+
16+
fn main() {}

src/test/compile-fail/impl-trait/feature-gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
// gate-test-conservative_impl_trait
1212

1313
fn foo() -> impl Fn() { || {} }
14-
//~^ ERROR `impl Trait` is experimental
14+
//~^ ERROR `impl Trait` in return position is experimental
1515

1616
fn main() {}

0 commit comments

Comments
 (0)