From: Andrew Cann Date: Mon, 1 Aug 2016 12:15:54 +0000 (+0800) Subject: Control usage of `!` through a feature gate. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=5096a8c5c01f8d1d7edece23bab6898bd3016f2c;hp=0e1c2aa52e7ec3f162ab4436c2ed0746d1992109;p=rust.git Control usage of `!` through a feature gate. Adds the `bang_type` feature gate. `!` in a non-return-type position now relies on that feature. --- diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index fabb3900ec6..74ef378f23d 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -87,6 +87,7 @@ #![feature(staged_api)] #![feature(unboxed_closures)] #![feature(question_mark)] +#![cfg_attr(not(stage0), feature(bang_type))] #[macro_use] mod macros; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index ad52184a6dc..efedc7229e6 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -284,7 +284,10 @@ pub fn new() -> Features { // Allows tuple structs and variants in more contexts, // Permits numeric fields in struct expressions and patterns. - (active, relaxed_adts, "1.12.0", Some(35626)) + (active, relaxed_adts, "1.12.0", Some(35626)), + + // The `!` type + (active, bang_type, "1.13.0", Some(35121)) ); declare_features! ( @@ -963,11 +966,25 @@ fn visit_ty(&mut self, ty: &ast::Ty) { gate_feature_post!(&self, conservative_impl_trait, ty.span, "`impl Trait` is experimental"); } + ast::TyKind::Empty => { + gate_feature_post!(&self, bang_type, ty.span, + "The `!` type is experimental"); + }, _ => {} } visit::walk_ty(self, ty) } + fn visit_fn_ret_ty(&mut self, ret_ty: &ast::FunctionRetTy) { + if let ast::FunctionRetTy::Ty(ref output_ty) = *ret_ty { + match output_ty.node { + ast::TyKind::Empty => return, + _ => (), + }; + visit::walk_ty(self, output_ty) + } + } + fn visit_expr(&mut self, e: &ast::Expr) { match e.node { ast::ExprKind::Box(_) => { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 1d40e3e395e..228409b8207 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -4,7 +4,8 @@ // // Licensed under the Apache License, Version 2.0 or the MIT license -// , at your +// , at your, +// "The `!` type is experimental"); // option. This file may not be copied, modified, or distributed // except according to those terms. @@ -128,6 +129,9 @@ fn visit_macro_def(&mut self, macro_def: &MacroDef) { fn visit_vis(&mut self, vis: &Visibility) { walk_vis(self, vis) } + fn visit_fn_ret_ty(&mut self, ret_ty: &FunctionRetTy) { + walk_fn_ret_ty(self, ret_ty) + } } #[macro_export] @@ -510,7 +514,7 @@ pub fn walk_fn_decl(visitor: &mut V, function_declaration: &FnDecl) visitor.visit_pat(&argument.pat); visitor.visit_ty(&argument.ty) } - walk_fn_ret_ty(visitor, &function_declaration.output) + visitor.visit_fn_ret_ty(&function_declaration.output) } pub fn walk_fn_kind(visitor: &mut V, function_kind: FnKind) { diff --git a/src/test/run-fail/adjust_empty.rs b/src/test/run-fail/adjust_empty.rs index 207c159b4ef..6d81099ceda 100644 --- a/src/test/run-fail/adjust_empty.rs +++ b/src/test/run-fail/adjust_empty.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(bang_type)]