From 20d8222e6a8a795272eea169c5415e5af28219fb Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Sun, 15 Feb 2015 21:30:45 +0100 Subject: libsyntax: Pass feature set in ExpansionConfig, not just enable_quotes. --- src/libsyntax/ext/base.rs | 9 +++++---- src/libsyntax/ext/expand.rs | 32 ++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 16 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 64ae6162ef4..2a3636abf87 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -439,7 +439,8 @@ impl BlockInfo { /// The base map of methods for expanding syntax extension /// AST nodes into full ASTs -fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv { +fn initial_syntax_expander_table<'feat>(ecfg: &expand::ExpansionConfig<'feat>) + -> SyntaxEnv { // utility function to simplify creating NormalTT syntax extensions fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension { NormalTT(box f, None) @@ -470,7 +471,7 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv { syntax_expanders.insert(intern("deriving"), Decorator(box ext::deriving::expand_deprecated_deriving)); - if ecfg.enable_quotes { + if ecfg.enable_quotes() { // Quasi-quoting expanders syntax_expanders.insert(intern("quote_tokens"), builtin_normal_expander( @@ -541,7 +542,7 @@ pub struct ExtCtxt<'a> { pub parse_sess: &'a parse::ParseSess, pub cfg: ast::CrateConfig, pub backtrace: ExpnId, - pub ecfg: expand::ExpansionConfig, + pub ecfg: expand::ExpansionConfig<'a>, pub use_std: bool, pub mod_path: Vec , @@ -554,7 +555,7 @@ pub struct ExtCtxt<'a> { impl<'a> ExtCtxt<'a> { pub fn new(parse_sess: &'a parse::ParseSess, cfg: ast::CrateConfig, - ecfg: expand::ExpansionConfig) -> ExtCtxt<'a> { + ecfg: expand::ExpansionConfig<'a>) -> ExtCtxt<'a> { let env = initial_syntax_expander_table(&ecfg); ExtCtxt { parse_sess: parse_sess, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 131bbc41005..267d732c9e6 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -22,6 +22,7 @@ use attr::AttrMetaMethods; use codemap; use codemap::{Span, Spanned, ExpnInfo, NameAndSpan, MacroBang, MacroAttribute}; use ext::base::*; +use feature_gate::{Features}; use fold; use fold::*; use parse; @@ -1407,28 +1408,35 @@ fn new_span(cx: &ExtCtxt, sp: Span) -> Span { } } -pub struct ExpansionConfig { +pub struct ExpansionConfig<'feat> { pub crate_name: String, - pub enable_quotes: bool, + pub features: Option<&'feat Features>, pub recursion_limit: usize, } -impl ExpansionConfig { - pub fn default(crate_name: String) -> ExpansionConfig { +impl<'feat> ExpansionConfig<'feat> { + pub fn default(crate_name: String) -> ExpansionConfig<'static> { ExpansionConfig { crate_name: crate_name, - enable_quotes: false, + features: None, recursion_limit: 64, } } + + pub fn enable_quotes(&self) -> bool { + match self.features { + Some(&Features { quote: true, .. }) => true, + _ => false, + } + } } -pub fn expand_crate(parse_sess: &parse::ParseSess, - cfg: ExpansionConfig, - // these are the macros being imported to this crate: - imported_macros: Vec, - user_exts: Vec, - c: Crate) -> Crate { +pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess, + cfg: ExpansionConfig<'feat>, + // these are the macros being imported to this crate: + imported_macros: Vec, + user_exts: Vec, + c: Crate) -> Crate { let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg); cx.use_std = std_inject::use_std(&c); @@ -1597,7 +1605,7 @@ mod test { // these following tests are quite fragile, in that they don't test what // *kind* of failure occurs. - fn test_ecfg() -> ExpansionConfig { + fn test_ecfg() -> ExpansionConfig<'static> { ExpansionConfig::default("test".to_string()) } -- cgit 1.4.1-3-g733a5 From 52bdda778ad595e661d06b16a193b3affe443d41 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Sun, 15 Feb 2015 22:14:03 +0100 Subject: Address the `asm!` case of #22234. --- src/libsyntax/ext/asm.rs | 7 +++++++ src/libsyntax/ext/expand.rs | 9 ++++++++- src/libsyntax/feature_gate.rs | 15 ++++++++++----- src/test/compile-fail/asm-gated2.rs | 15 +++++++++++++++ 4 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 src/test/compile-fail/asm-gated2.rs (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 1ceda2e08dd..d8cba139fb5 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -18,6 +18,7 @@ use codemap; use codemap::Span; use ext::base; use ext::base::*; +use feature_gate; use parse::token::InternedString; use parse::token; use ptr::P; @@ -48,6 +49,12 @@ static OPTIONS: &'static [&'static str] = &["volatile", "alignstack", "intel"]; pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> Box { + if !cx.ecfg.enable_asm() { + feature_gate::emit_feature_err( + &cx.parse_sess.span_diagnostic, "asm", sp, feature_gate::EXPLAIN_ASM); + return DummyResult::expr(sp); + } + let mut p = cx.new_parser_from_tts(tts); let mut asm = InternedString::new(""); let mut asm_str_style = None; diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 267d732c9e6..e31c1a32749 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1425,7 +1425,14 @@ impl<'feat> ExpansionConfig<'feat> { pub fn enable_quotes(&self) -> bool { match self.features { - Some(&Features { quote: true, .. }) => true, + Some(&Features { allow_quote: true, .. }) => true, + _ => false, + } + } + + pub fn enable_asm(&self) -> bool { + match self.features { + Some(&Features { allow_asm: true, .. }) => true, _ => false, } } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index ca7ae32f09e..9d14f894a46 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -156,7 +156,8 @@ pub struct Features { pub unboxed_closures: bool, pub rustc_diagnostic_macros: bool, pub visible_private_types: bool, - pub quote: bool, + pub allow_quote: bool, + pub allow_asm: bool, pub old_orphan_check: bool, pub simd_ffi: bool, pub unmarked_api: bool, @@ -172,7 +173,8 @@ impl Features { unboxed_closures: false, rustc_diagnostic_macros: false, visible_private_types: false, - quote: false, + allow_quote: false, + allow_asm: false, old_orphan_check: false, simd_ffi: false, unmarked_api: false, @@ -221,6 +223,9 @@ pub fn emit_feature_warn(diag: &SpanHandler, feature: &str, span: Span, explain: } } +pub const EXPLAIN_ASM: &'static str = + "inline assembly is not stable enough for use and is subject to change"; + struct MacroVisitor<'a> { context: &'a Context<'a> } @@ -231,8 +236,7 @@ impl<'a, 'v> Visitor<'v> for MacroVisitor<'a> { let id = path.segments.last().unwrap().identifier; if id == token::str_to_ident("asm") { - self.context.gate_feature("asm", path.span, "inline assembly is not \ - stable enough for use and is subject to change"); + self.context.gate_feature("asm", path.span, EXPLAIN_ASM); } else if id == token::str_to_ident("log_syntax") { @@ -594,7 +598,8 @@ fn check_crate_inner(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::C unboxed_closures: cx.has_feature("unboxed_closures"), rustc_diagnostic_macros: cx.has_feature("rustc_diagnostic_macros"), visible_private_types: cx.has_feature("visible_private_types"), - quote: cx.has_feature("quote"), + allow_quote: cx.has_feature("quote"), + allow_asm: cx.has_feature("asm"), old_orphan_check: cx.has_feature("old_orphan_check"), simd_ffi: cx.has_feature("simd_ffi"), unmarked_api: cx.has_feature("unmarked_api"), diff --git a/src/test/compile-fail/asm-gated2.rs b/src/test/compile-fail/asm-gated2.rs new file mode 100644 index 00000000000..d2ee01109f8 --- /dev/null +++ b/src/test/compile-fail/asm-gated2.rs @@ -0,0 +1,15 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + unsafe { + println!("{}", asm!("")); //~ ERROR inline assembly is not stable + } +} -- cgit 1.4.1-3-g733a5 From dc0797c0c99e7079170d0e09f82fc6f66b721932 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Sun, 15 Feb 2015 23:49:55 +0100 Subject: Address the other cases of #22234; fix #22234. The other cases: `concat_idents!`, `log_syntax!`, and `trace_macros!`, (these macros, with `asm!`, are handled (eagerly) in feature_gate.rs). --- src/libsyntax/ext/concat_idents.rs | 9 +++++++ src/libsyntax/ext/expand.rs | 21 +++++++++++++++ src/libsyntax/ext/log_syntax.rs | 8 ++++++ src/libsyntax/ext/trace_macros.rs | 10 ++++++++ src/libsyntax/feature_gate.rs | 38 +++++++++++++++++++++++----- src/test/compile-fail/concat_idents-gate.rs | 19 ++++++++++++++ src/test/compile-fail/concat_idents-gate2.rs | 17 +++++++++++++ src/test/compile-fail/log-syntax-gate2.rs | 13 ++++++++++ src/test/compile-fail/trace_macros-gate.rs | 30 ++++++++++++++++++++++ src/test/compile-fail/trace_macros-gate2.rs | 20 +++++++++++++++ src/test/compile-fail/trace_macros-gate3.rs | 20 +++++++++++++++ 11 files changed, 199 insertions(+), 6 deletions(-) create mode 100644 src/test/compile-fail/concat_idents-gate.rs create mode 100644 src/test/compile-fail/concat_idents-gate2.rs create mode 100644 src/test/compile-fail/log-syntax-gate2.rs create mode 100644 src/test/compile-fail/trace_macros-gate.rs create mode 100644 src/test/compile-fail/trace_macros-gate2.rs create mode 100644 src/test/compile-fail/trace_macros-gate3.rs (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 364cacd735c..63a8bd9ddf1 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -12,12 +12,21 @@ use ast; use codemap::Span; use ext::base::*; use ext::base; +use feature_gate; use parse::token; use parse::token::{str_to_ident}; use ptr::P; pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> Box { + if !cx.ecfg.enable_concat_idents() { + feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, + "concat_idents", + sp, + feature_gate::EXPLAIN_CONCAT_IDENTS); + return base::DummyResult::expr(sp); + } + let mut res_str = String::new(); for (i, e) in tts.iter().enumerate() { if i & 1 == 1 { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index e31c1a32749..72dc717910b 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1436,6 +1436,27 @@ impl<'feat> ExpansionConfig<'feat> { _ => false, } } + + pub fn enable_log_syntax(&self) -> bool { + match self.features { + Some(&Features { allow_log_syntax: true, .. }) => true, + _ => false, + } + } + + pub fn enable_concat_idents(&self) -> bool { + match self.features { + Some(&Features { allow_concat_idents: true, .. }) => true, + _ => false, + } + } + + pub fn enable_trace_macros(&self) -> bool { + match self.features { + Some(&Features { allow_trace_macros: true, .. }) => true, + _ => false, + } + } } pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess, diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs index 30301e3b8cc..8173dd93f74 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax/ext/log_syntax.rs @@ -11,12 +11,20 @@ use ast; use codemap; use ext::base; +use feature_gate; use print; pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt, sp: codemap::Span, tts: &[ast::TokenTree]) -> Box { + if !cx.ecfg.enable_log_syntax() { + feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, + "log_syntax", + sp, + feature_gate::EXPLAIN_LOG_SYNTAX); + return base::DummyResult::any(sp); + } cx.print_backtrace(); diff --git a/src/libsyntax/ext/trace_macros.rs b/src/libsyntax/ext/trace_macros.rs index 76f7b7b0d7b..3fcc6a8d692 100644 --- a/src/libsyntax/ext/trace_macros.rs +++ b/src/libsyntax/ext/trace_macros.rs @@ -12,6 +12,7 @@ use ast; use codemap::Span; use ext::base::ExtCtxt; use ext::base; +use feature_gate; use parse::token::keywords; @@ -19,6 +20,15 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt, sp: Span, tt: &[ast::TokenTree]) -> Box { + if !cx.ecfg.enable_trace_macros() { + feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, + "trace_macros", + sp, + feature_gate::EXPLAIN_TRACE_MACROS); + return base::DummyResult::any(sp); + } + + match tt { [ast::TtToken(_, ref tok)] if tok.is_keyword(keywords::True) => { cx.set_trace_macros(true); diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 9d14f894a46..5e29f3a6b69 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -158,6 +158,9 @@ pub struct Features { pub visible_private_types: bool, pub allow_quote: bool, pub allow_asm: bool, + pub allow_log_syntax: bool, + pub allow_concat_idents: bool, + pub allow_trace_macros: bool, pub old_orphan_check: bool, pub simd_ffi: bool, pub unmarked_api: bool, @@ -175,6 +178,9 @@ impl Features { visible_private_types: false, allow_quote: false, allow_asm: false, + allow_log_syntax: false, + allow_concat_idents: false, + allow_trace_macros: false, old_orphan_check: false, simd_ffi: false, unmarked_api: false, @@ -226,6 +232,15 @@ pub fn emit_feature_warn(diag: &SpanHandler, feature: &str, span: Span, explain: pub const EXPLAIN_ASM: &'static str = "inline assembly is not stable enough for use and is subject to change"; +pub const EXPLAIN_LOG_SYNTAX: &'static str = + "`log_syntax!` is not stable enough for use and is subject to change"; + +pub const EXPLAIN_CONCAT_IDENTS: &'static str = + "`concat_idents` is not stable enough for use and is subject to change"; + +pub const EXPLAIN_TRACE_MACROS: &'static str = + "`trace_macros` is not stable enough for use and is subject to change"; + struct MacroVisitor<'a> { context: &'a Context<'a> } @@ -235,23 +250,28 @@ impl<'a, 'v> Visitor<'v> for MacroVisitor<'a> { let ast::MacInvocTT(ref path, _, _) = mac.node; let id = path.segments.last().unwrap().identifier; + // Issue 22234: If you add a new case here, make sure to also + // add code to catch the macro during or after expansion. + // + // We still keep this MacroVisitor (rather than *solely* + // relying on catching cases during or after expansion) to + // catch uses of these macros within conditionally-compiled + // code, e.g. `#[cfg]`-guarded functions. + if id == token::str_to_ident("asm") { self.context.gate_feature("asm", path.span, EXPLAIN_ASM); } else if id == token::str_to_ident("log_syntax") { - self.context.gate_feature("log_syntax", path.span, "`log_syntax!` is not \ - stable enough for use and is subject to change"); + self.context.gate_feature("log_syntax", path.span, EXPLAIN_LOG_SYNTAX); } else if id == token::str_to_ident("trace_macros") { - self.context.gate_feature("trace_macros", path.span, "`trace_macros` is not \ - stable enough for use and is subject to change"); + self.context.gate_feature("trace_macros", path.span, EXPLAIN_TRACE_MACROS); } else if id == token::str_to_ident("concat_idents") { - self.context.gate_feature("concat_idents", path.span, "`concat_idents` is not \ - stable enough for use and is subject to change"); + self.context.gate_feature("concat_idents", path.span, EXPLAIN_CONCAT_IDENTS); } } } @@ -594,12 +614,18 @@ fn check_crate_inner(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::C check(&mut cx, krate); + // FIXME (pnkfelix): Before adding the 99th entry below, change it + // to a single-pass (instead of N calls to `.has_feature`). + Features { unboxed_closures: cx.has_feature("unboxed_closures"), rustc_diagnostic_macros: cx.has_feature("rustc_diagnostic_macros"), visible_private_types: cx.has_feature("visible_private_types"), allow_quote: cx.has_feature("quote"), allow_asm: cx.has_feature("asm"), + allow_log_syntax: cx.has_feature("log_syntax"), + allow_concat_idents: cx.has_feature("concat_idents"), + allow_trace_macros: cx.has_feature("trace_macros"), old_orphan_check: cx.has_feature("old_orphan_check"), simd_ffi: cx.has_feature("simd_ffi"), unmarked_api: cx.has_feature("unmarked_api"), diff --git a/src/test/compile-fail/concat_idents-gate.rs b/src/test/compile-fail/concat_idents-gate.rs new file mode 100644 index 00000000000..f4d97445725 --- /dev/null +++ b/src/test/compile-fail/concat_idents-gate.rs @@ -0,0 +1,19 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const XY_1: i32 = 10; + +fn main() { + const XY_2: i32 = 20; + let a = concat_idents!(X, Y_1); //~ ERROR `concat_idents` is not stable + let b = concat_idents!(X, Y_2); //~ ERROR `concat_idents` is not stable + assert_eq!(a, 10); + assert_eq!(b, 20); +} diff --git a/src/test/compile-fail/concat_idents-gate2.rs b/src/test/compile-fail/concat_idents-gate2.rs new file mode 100644 index 00000000000..d8f8f803edc --- /dev/null +++ b/src/test/compile-fail/concat_idents-gate2.rs @@ -0,0 +1,17 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const XY_1: i32 = 10; + +fn main() { + const XY_2: i32 = 20; + assert_eq!(10, concat_idents!(X, Y_1)); //~ ERROR `concat_idents` is not stable + assert_eq!(20, concat_idents!(X, Y_2)); //~ ERROR `concat_idents` is not stable +} diff --git a/src/test/compile-fail/log-syntax-gate2.rs b/src/test/compile-fail/log-syntax-gate2.rs new file mode 100644 index 00000000000..bb19e97ab0f --- /dev/null +++ b/src/test/compile-fail/log-syntax-gate2.rs @@ -0,0 +1,13 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + println!("{}", log_syntax!()); //~ ERROR `log_syntax!` is not stable +} diff --git a/src/test/compile-fail/trace_macros-gate.rs b/src/test/compile-fail/trace_macros-gate.rs new file mode 100644 index 00000000000..6473bcece91 --- /dev/null +++ b/src/test/compile-fail/trace_macros-gate.rs @@ -0,0 +1,30 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that the trace_macros feature gate is on. + +fn main() { + trace_macros!(); //~ ERROR `trace_macros` is not stable + trace_macros!(1); //~ ERROR `trace_macros` is not stable + trace_macros!(ident); //~ ERROR `trace_macros` is not stable + trace_macros!(for); //~ ERROR `trace_macros` is not stable + trace_macros!(true,); //~ ERROR `trace_macros` is not stable + trace_macros!(false 1); //~ ERROR `trace_macros` is not stable + + // Errors are signalled early for the above, before expansion. + // See trace_macros-gate2 and trace_macros-gate3. for examples + // of the below being caught. + + macro_rules! expando { + ($x: ident) => { trace_macros!($x) } + } + + expando!(true); +} diff --git a/src/test/compile-fail/trace_macros-gate2.rs b/src/test/compile-fail/trace_macros-gate2.rs new file mode 100644 index 00000000000..71cc45e132d --- /dev/null +++ b/src/test/compile-fail/trace_macros-gate2.rs @@ -0,0 +1,20 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that the trace_macros feature gate is on. + +fn main() { + // (Infrastructure does not attempt to detect uses in macro definitions.) + macro_rules! expando { + ($x: ident) => { trace_macros!($x) } + } + + expando!(true); //~ ERROR `trace_macros` is not stable +} diff --git a/src/test/compile-fail/trace_macros-gate3.rs b/src/test/compile-fail/trace_macros-gate3.rs new file mode 100644 index 00000000000..66d03cf9d80 --- /dev/null +++ b/src/test/compile-fail/trace_macros-gate3.rs @@ -0,0 +1,20 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that the trace_macros feature gate is on. + +pub fn main() { + println!("arg: {}", trace_macros!()); //~ ERROR `trace_macros` is not stable + println!("arg: {}", trace_macros!(1)); //~ ERROR `trace_macros` is not stable + println!("arg: {}", trace_macros!(ident)); //~ ERROR `trace_macros` is not stable + println!("arg: {}", trace_macros!(for)); //~ ERROR `trace_macros` is not stable + println!("arg: {}", trace_macros!(true,)); //~ ERROR `trace_macros` is not stable + println!("arg: {}", trace_macros!(false 1)); //~ ERROR `trace_macros` is not stable +} -- cgit 1.4.1-3-g733a5 From 531a06e593fdf4151c2b3f5673f24c7a0739e3f5 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 13 Feb 2015 19:05:11 +0530 Subject: Move ATTRIBUTE_WHITELIST and CRATE_ATTRS to KNOWN_ATTRIBUTES in syntax::feature_gate --- src/librustc/lint/builtin.rs | 59 +++--------------------------------- src/libsyntax/feature_gate.rs | 69 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 55 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index fe1d695ab7b..b17d35abcf6 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -47,6 +47,7 @@ use syntax::{abi, ast, ast_map}; use syntax::ast_util::is_shift_binop; use syntax::attr::{self, AttrMetaMethods}; use syntax::codemap::{self, Span}; +use syntax::feature_gate::{KNOWN_ATTRIBUTES, AttributeType}; use syntax::parse::token; use syntax::ast::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64}; use syntax::ast_util; @@ -640,67 +641,15 @@ impl LintPass for UnusedAttributes { } fn check_attribute(&mut self, cx: &Context, attr: &ast::Attribute) { - static ATTRIBUTE_WHITELIST: &'static [&'static str] = &[ - // FIXME: #14408 whitelist docs since rustdoc looks at them - "doc", - - // FIXME: #14406 these are processed in trans, which happens after the - // lint pass - "cold", - "export_name", - "inline", - "link", - "link_name", - "link_section", - "linkage", - "no_builtins", - "no_mangle", - "no_split_stack", - "no_stack_check", - "packed", - "static_assert", - "thread_local", - "no_debug", - "omit_gdb_pretty_printer_section", - "unsafe_no_drop_flag", - - // used in resolve - "prelude_import", - - // FIXME: #14407 these are only looked at on-demand so we can't - // guarantee they'll have already been checked - "deprecated", - "must_use", - "stable", - "unstable", - "rustc_on_unimplemented", - "rustc_error", - - // FIXME: #19470 this shouldn't be needed forever - "old_orphan_check", - "old_impl_check", - "rustc_paren_sugar", // FIXME: #18101 temporary unboxed closure hack - ]; - - static CRATE_ATTRS: &'static [&'static str] = &[ - "crate_name", - "crate_type", - "feature", - "no_start", - "no_main", - "no_std", - "no_builtins", - ]; - - for &name in ATTRIBUTE_WHITELIST { - if attr.check_name(name) { + for &(ref name, ty) in KNOWN_ATTRIBUTES { + if ty == AttributeType::Whitelisted && attr.check_name(name) { break; } } if !attr::is_used(attr) { cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute"); - if CRATE_ATTRS.contains(&&attr.name()[]) { + if KNOWN_ATTRIBUTES.contains(&(&attr.name()[], AttributeType::CrateLevel)) { let msg = match attr.node.style { ast::AttrOuter => "crate-level attribute should be an inner \ attribute: add an exclamation mark: #![foo]", diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index fd1ca11818c..d2eb2126f0f 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -23,6 +23,7 @@ //! becomes stable. use self::Status::*; +use self::AttributeType::*; use abi::RustIntrinsic; use ast::NodeId; @@ -152,6 +153,74 @@ enum Status { Accepted, } +// Attributes that have a special meaning to rustc or rustdoc +pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ + + // FIXME: #14408 whitelist docs since rustdoc looks at them + ("doc", Whitelisted), + + // FIXME: #14406 these are processed in trans, which happens after the + // lint pass + ("cold", Whitelisted), + ("export_name", Whitelisted), + ("inline", Whitelisted), + ("link", Whitelisted), + ("link_name", Whitelisted), + ("link_section", Whitelisted), + ("linkage", Whitelisted), + ("no_builtins", Whitelisted), + ("no_mangle", Whitelisted), + ("no_split_stack", Whitelisted), + ("no_stack_check", Whitelisted), + ("packed", Whitelisted), + ("static_assert", Whitelisted), + ("thread_local", Whitelisted), + ("no_debug", Whitelisted), + ("omit_gdb_pretty_printer_section", Whitelisted), + ("unsafe_no_drop_flag", Whitelisted), + + // used in resolve + ("prelude_import", Whitelisted), + + // FIXME: #14407 these are only looked at on-demand so we can't + // guarantee they'll have already been checked + ("deprecated", Whitelisted), + ("must_use", Whitelisted), + ("stable", Whitelisted), + ("unstable", Whitelisted), + ("rustc_on_unimplemented", Whitelisted), + ("rustc_error", Whitelisted), + + // FIXME: #19470 this shouldn't be needed forever + ("old_orphan_check", Whitelisted), + ("old_impl_check", Whitelisted), + ("rustc_paren_sugar", Whitelisted), // FIXME: #18101 temporary unboxed closure hack + + // Crate level attributes + ("crate_name", CrateLevel), + ("crate_type", CrateLevel), + ("feature", CrateLevel), + ("no_start", CrateLevel), + ("no_main", CrateLevel), + ("no_std", CrateLevel), + ("no_builtins", CrateLevel), +]; + +#[derive(PartialEq, Copy)] +pub enum AttributeType { + /// Normal, builtin attribute that is consumed + /// by the compiler before the unused_attribute check + Normal, + + /// Builtin attribute that may not be consumed by the compiler + /// before the unused_attribute check. These attributes + /// will be ignored by the unused_attribute lint + Whitelisted, + + /// Builtin attribute that is only allowed at the crate level + CrateLevel, +} + /// A set of features to be used by later passes. pub struct Features { pub unboxed_closures: bool, -- cgit 1.4.1-3-g733a5 From 38542cca29a0ed6f62b18d543386852e5a544adc Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 13 Feb 2015 20:40:24 +0530 Subject: Feature gate custom attributes (fixes #22203) --- src/libsyntax/feature_gate.rs | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/libsyntax') diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index d2eb2126f0f..5af9ca307de 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -134,6 +134,9 @@ static KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[ // Allows using the unsafe_no_drop_flag attribute (unlikely to // switch to Accepted; see RFC 320) ("unsafe_no_drop_flag", "1.0.0", Active), + + // Allows the use of custom attributes; RFC 572 + ("custom_attribute", "1.0.0", Active) ]; // (changing above list without updating src/doc/reference.md makes @cmr sad) @@ -155,6 +158,43 @@ enum Status { // Attributes that have a special meaning to rustc or rustdoc pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ + // Normal attributes + + ("warn", Normal), + ("allow", Normal), + ("forbid", Normal), + ("deny", Normal), + + ("macro_reexport", Normal), + ("macro_use", Normal), + ("plugin", Normal), + ("macro_export", Normal), + ("plugin_registrar", Normal), + + ("cfg", Normal), + ("main", Normal), + ("lang", Normal), + ("start", Normal), + ("test", Normal), + ("bench", Normal), + ("simd", Normal), + ("repr", Normal), + ("path", Normal), + ("staged_api", Normal), + ("abi", Normal), + ("rustc_move_fragments", Normal), + ("rustc_variance", Normal), + ("unsafe_destructor", Normal), + ("automatically_derived", Normal), + ("no_mangle", Normal), + ("no_link", Normal), + ("derive", Normal), + ("should_fail", Normal), + ("ignore", Normal), + ("no_implicit_prelude", Normal), + ("reexport_test_harness_main", Normal), + ("link_args", Normal), + ("macro_escape", Normal), // FIXME: #14408 whitelist docs since rustdoc looks at them ("doc", Whitelisted), @@ -199,11 +239,13 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ // Crate level attributes ("crate_name", CrateLevel), ("crate_type", CrateLevel), + ("crate_id", CrateLevel), ("feature", CrateLevel), ("no_start", CrateLevel), ("no_main", CrateLevel), ("no_std", CrateLevel), ("no_builtins", CrateLevel), + ("recursion_limit", CrateLevel), ]; #[derive(PartialEq, Copy)] @@ -557,6 +599,18 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { "unsafe_no_drop_flag has unstable semantics \ and may be removed in the future"); } + + // Custom attribute check + let name = attr.name(); + + if KNOWN_ATTRIBUTES.iter().all(|&(n, _)| n != name) { + self.gate_feature("custom_attribute", attr.span, + format!("The attribute `{}` is currently \ + unknown to the the compiler and \ + may have meaning \ + added to it in the future", + attr.name()).as_slice()); + } } fn visit_pat(&mut self, pattern: &ast::Pat) { -- cgit 1.4.1-3-g733a5 From 99e39f4927408d25c8b9033f33738b672d870bb6 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Sun, 15 Feb 2015 16:37:36 +0530 Subject: Clean up visit_attribute in feature_gate.rs - We shouldn't be using `check_name` here at all - `contains_name(ref_slice(foo), bar)` is redundant, `contains_name` just iterates over its first arg and calls `check_name` - match would be better than a bunch of ifs --- src/libsyntax/feature_gate.rs | 63 ++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 5af9ca307de..62eb5badb77 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -36,7 +36,6 @@ use visit; use visit::Visitor; use parse::token::{self, InternedString}; -use std::slice; use std::ascii::AsciiExt; // If you change this list without updating src/doc/reference.md, @cmr will be sad @@ -574,42 +573,32 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { } fn visit_attribute(&mut self, attr: &ast::Attribute) { - if attr.check_name("staged_api") { - self.gate_feature("staged_api", attr.span, - "staged_api is for use by rustc only"); - } else if attr.check_name("plugin") { - self.gate_feature("plugin", attr.span, - "compiler plugins are experimental \ - and possibly buggy"); - } - - if attr::contains_name(slice::ref_slice(attr), "lang") { - self.gate_feature("lang_items", - attr.span, - "language items are subject to change"); - } - - if attr.check_name("no_std") { - self.gate_feature("no_std", attr.span, - "no_std is experimental"); - } - - if attr.check_name("unsafe_no_drop_flag") { - self.gate_feature("unsafe_no_drop_flag", attr.span, - "unsafe_no_drop_flag has unstable semantics \ - and may be removed in the future"); - } - - // Custom attribute check - let name = attr.name(); - - if KNOWN_ATTRIBUTES.iter().all(|&(n, _)| n != name) { - self.gate_feature("custom_attribute", attr.span, - format!("The attribute `{}` is currently \ - unknown to the the compiler and \ - may have meaning \ - added to it in the future", - attr.name()).as_slice()); + match &*attr.name() { + "staged_api" => self.gate_feature("staged_api", attr.span, + "staged_api is for use by rustc only"), + "plugin" => self.gate_feature("plugin", attr.span, + "compiler plugins are experimental \ + and possibly buggy"), + "no_std" => self.gate_feature("no_std", attr.span, + "no_std is experimental"), + "unsafe_no_drop_flag" => self.gate_feature("unsafe_no_drop_flag", attr.span, + "unsafe_no_drop_flag has unstable \ + semantics and may be removed \ + in the future"), + "lang" => self.gate_feature("lang_items", + attr.span, + "language items are subject to change"), + name => { + // Custom attribute check + if KNOWN_ATTRIBUTES.iter().all(|&(n, _)| n != name) { + self.gate_feature("custom_attribute", attr.span, + format!("The attribute `{}` is currently \ + unknown to the the compiler and \ + may have meaning \ + added to it in the future", + attr.name()).as_slice()); + } + } } } -- cgit 1.4.1-3-g733a5 From 5ffb7db42307226503242dececdcfd7c52063d7c Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 17 Feb 2015 00:14:51 +0530 Subject: Add `Gated` attribute type --- src/librustc/lint/builtin.rs | 8 +++++-- src/libsyntax/feature_gate.rs | 56 +++++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 30 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index b17d35abcf6..b1eb4f01d84 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -642,8 +642,12 @@ impl LintPass for UnusedAttributes { fn check_attribute(&mut self, cx: &Context, attr: &ast::Attribute) { for &(ref name, ty) in KNOWN_ATTRIBUTES { - if ty == AttributeType::Whitelisted && attr.check_name(name) { - break; + match ty { + AttributeType::Whitelisted + | AttributeType::Gated(_, _) if attr.check_name(name) => { + break; + }, + _ => () } } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 62eb5badb77..6ef20a6a62b 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -166,20 +166,17 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ ("macro_reexport", Normal), ("macro_use", Normal), - ("plugin", Normal), ("macro_export", Normal), ("plugin_registrar", Normal), ("cfg", Normal), ("main", Normal), - ("lang", Normal), ("start", Normal), ("test", Normal), ("bench", Normal), ("simd", Normal), ("repr", Normal), ("path", Normal), - ("staged_api", Normal), ("abi", Normal), ("rustc_move_fragments", Normal), ("rustc_variance", Normal), @@ -195,6 +192,17 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ ("link_args", Normal), ("macro_escape", Normal), + + ("staged_api", Gated("staged_api", + "staged_api is for use by rustc only")), + ("plugin", Gated("plugin", + "compiler plugins are experimental \ + and possibly buggy")), + ("no_std", Gated("no_std", + "no_std is experimental")), + ("lang", Gated("lang_items", + "language items are subject to change")), + // FIXME: #14408 whitelist docs since rustdoc looks at them ("doc", Whitelisted), @@ -242,7 +250,6 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ ("feature", CrateLevel), ("no_start", CrateLevel), ("no_main", CrateLevel), - ("no_std", CrateLevel), ("no_builtins", CrateLevel), ("recursion_limit", CrateLevel), ]; @@ -258,6 +265,10 @@ pub enum AttributeType { /// will be ignored by the unused_attribute lint Whitelisted, + /// Is gated by a given feature gate and reason + /// These get whitelisted too + Gated(&'static str, &'static str), + /// Builtin attribute that is only allowed at the crate level CrateLevel, } @@ -573,33 +584,22 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { } fn visit_attribute(&mut self, attr: &ast::Attribute) { - match &*attr.name() { - "staged_api" => self.gate_feature("staged_api", attr.span, - "staged_api is for use by rustc only"), - "plugin" => self.gate_feature("plugin", attr.span, - "compiler plugins are experimental \ - and possibly buggy"), - "no_std" => self.gate_feature("no_std", attr.span, - "no_std is experimental"), - "unsafe_no_drop_flag" => self.gate_feature("unsafe_no_drop_flag", attr.span, - "unsafe_no_drop_flag has unstable \ - semantics and may be removed \ - in the future"), - "lang" => self.gate_feature("lang_items", - attr.span, - "language items are subject to change"), - name => { - // Custom attribute check - if KNOWN_ATTRIBUTES.iter().all(|&(n, _)| n != name) { - self.gate_feature("custom_attribute", attr.span, - format!("The attribute `{}` is currently \ - unknown to the the compiler and \ - may have meaning \ - added to it in the future", - attr.name()).as_slice()); + let name = &*attr.name(); + for &(n, ty) in KNOWN_ATTRIBUTES { + if n == name { + if let Gated(gate, desc) = ty { + self.gate_feature(gate, attr.span, desc); } + return; } + } + self.gate_feature("custom_attribute", attr.span, + format!("The attribute `{}` is currently \ + unknown to the the compiler and \ + may have meaning \ + added to it in the future", + name).as_slice()); } fn visit_pat(&mut self, pattern: &ast::Pat) { -- cgit 1.4.1-3-g733a5 From 0112f3b09834d8cc02489ec460c92dc2b25f4371 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 17 Feb 2015 00:19:35 +0530 Subject: move other attribute check to visit_attribute --- src/libsyntax/feature_gate.rs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 6ef20a6a62b..8aab41baeb5 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -202,6 +202,16 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ "no_std is experimental")), ("lang", Gated("lang_items", "language items are subject to change")), + ("rustc_on_unimplemented", Gated("on_unimplemented", + "the `#[rustc_on_unimplemented]` attribute \ + is an experimental feature")), + ("linkage", Gated("linkage", + "the `linkage` attribute is experimental \ + and not portable across platforms")), + ("thread_local", Gated("thread_local", + "`#[thread_local]` is an experimental feature, and does not \ + currently handle destructors. There is no corresponding \ + `#[task_local]` mapping to the task model")), // FIXME: #14408 whitelist docs since rustdoc looks at them ("doc", Whitelisted), @@ -214,14 +224,12 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ ("link", Whitelisted), ("link_name", Whitelisted), ("link_section", Whitelisted), - ("linkage", Whitelisted), ("no_builtins", Whitelisted), ("no_mangle", Whitelisted), ("no_split_stack", Whitelisted), ("no_stack_check", Whitelisted), ("packed", Whitelisted), ("static_assert", Whitelisted), - ("thread_local", Whitelisted), ("no_debug", Whitelisted), ("omit_gdb_pretty_printer_section", Whitelisted), ("unsafe_no_drop_flag", Whitelisted), @@ -235,7 +243,6 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ ("must_use", Whitelisted), ("stable", Whitelisted), ("unstable", Whitelisted), - ("rustc_on_unimplemented", Whitelisted), ("rustc_error", Whitelisted), // FIXME: #19470 this shouldn't be needed forever @@ -395,22 +402,6 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { } fn visit_item(&mut self, i: &ast::Item) { - for attr in &i.attrs { - if attr.name() == "thread_local" { - self.gate_feature("thread_local", i.span, - "`#[thread_local]` is an experimental feature, and does not \ - currently handle destructors. There is no corresponding \ - `#[task_local]` mapping to the task model"); - } else if attr.name() == "linkage" { - self.gate_feature("linkage", i.span, - "the `linkage` attribute is experimental \ - and not portable across platforms") - } else if attr.name() == "rustc_on_unimplemented" { - self.gate_feature("on_unimplemented", i.span, - "the `#[rustc_on_unimplemented]` attribute \ - is an experimental feature") - } - } match i.node { ast::ItemExternCrate(_) => { if attr::contains_name(&i.attrs[], "macro_reexport") { @@ -592,7 +583,6 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { } return; } - } self.gate_feature("custom_attribute", attr.span, format!("The attribute `{}` is currently \ -- cgit 1.4.1-3-g733a5 From 0129002d3afa2edb2dad4f2b4f615e73c60c68cc Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 17 Feb 2015 01:46:36 +0530 Subject: Add gating for rustc_* attrs --- src/libcore/lib.rs | 1 + src/libsyntax/feature_gate.rs | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 13 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 7243bd4f0cb..f1808bc1fb5 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -67,6 +67,7 @@ #![feature(simd, unsafe_destructor)] #![feature(staged_api)] #![feature(unboxed_closures)] +#![feature(rustc_attrs)] #[macro_use] mod macros; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 8aab41baeb5..f6424167bde 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -135,7 +135,10 @@ static KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[ ("unsafe_no_drop_flag", "1.0.0", Active), // Allows the use of custom attributes; RFC 572 - ("custom_attribute", "1.0.0", Active) + ("custom_attribute", "1.0.0", Active), + + // Allows the use of rustc_* attributes; RFC 572 + ("rustc_attrs", "1.0.0", Active), ]; // (changing above list without updating src/doc/reference.md makes @cmr sad) @@ -178,8 +181,6 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ ("repr", Normal), ("path", Normal), ("abi", Normal), - ("rustc_move_fragments", Normal), - ("rustc_variance", Normal), ("unsafe_destructor", Normal), ("automatically_derived", Normal), ("no_mangle", Normal), @@ -202,9 +203,6 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ "no_std is experimental")), ("lang", Gated("lang_items", "language items are subject to change")), - ("rustc_on_unimplemented", Gated("on_unimplemented", - "the `#[rustc_on_unimplemented]` attribute \ - is an experimental feature")), ("linkage", Gated("linkage", "the `linkage` attribute is experimental \ and not portable across platforms")), @@ -213,6 +211,19 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ currently handle destructors. There is no corresponding \ `#[task_local]` mapping to the task model")), + ("rustc_on_unimplemented", Gated("on_unimplemented", + "the `#[rustc_on_unimplemented]` attribute \ + is an experimental feature")), + ("rustc_variance", Gated("rustc_attrs", + "the `#[rustc_variance]` attribute \ + is an experimental feature")), + ("rustc_error", Gated("rustc_attrs", + "the `#[rustc_error]` attribute \ + is an experimental feature")), + ("rustc_move_fragments", Gated("rustc_attrs", + "the `#[rustc_move_fragments]` attribute \ + is an experimental feature")), + // FIXME: #14408 whitelist docs since rustdoc looks at them ("doc", Whitelisted), @@ -243,7 +254,6 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[ ("must_use", Whitelisted), ("stable", Whitelisted), ("unstable", Whitelisted), - ("rustc_error", Whitelisted), // FIXME: #19470 this shouldn't be needed forever ("old_orphan_check", Whitelisted), @@ -584,12 +594,19 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { return; } } - self.gate_feature("custom_attribute", attr.span, - format!("The attribute `{}` is currently \ - unknown to the the compiler and \ - may have meaning \ - added to it in the future", - name).as_slice()); + if name.starts_with("rustc_") { + self.gate_feature("rustc_attrs", attr.span, + "unless otherwise specified, attributes \ + with the prefix `rustc_` \ + are reserved for internal compiler diagnostics"); + } else { + self.gate_feature("custom_attribute", attr.span, + format!("The attribute `{}` is currently \ + unknown to the the compiler and \ + may have meaning \ + added to it in the future", + name).as_slice()); + } } fn visit_pat(&mut self, pattern: &ast::Pat) { -- cgit 1.4.1-3-g733a5 From 235f35b0b724a38a5583112825d46f50c5dde980 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 17 Feb 2015 13:58:34 -0800 Subject: std: Stabilize the `ascii` module This commit performs a stabilization pass over the `std::ascii` module taking the following actions: * the module name is now stable * `AsciiExt` is now stable after moving its type parameter to an `Owned` associated type * `AsciiExt::is_ascii` is now stable * `AsciiExt::to_ascii_uppercase` is now stable * `AsciiExt::to_ascii_lowercase` is now stable * `AsciiExt::eq_ignore_ascii_case` is now stable * `AsciiExt::make_ascii_uppercase` is added to possibly replace `OwnedAsciiExt::into_ascii_uppercase` (similarly for lowercase variants). * `escape_default` now returns an iterator and is stable * `EscapeDefault` is now stable Trait implementations are now also marked stable. Primarily it is still unstable to *implement* the `AsciiExt` trait due to it containing some unstable methods. [breaking-change] --- src/libstd/ascii.rs | 192 +++++++++++++++++++++++++++--------------- src/libstd/sys/common/wtf8.rs | 7 +- src/libsyntax/print/pprust.rs | 10 +-- src/libterm/lib.rs | 1 - 4 files changed, 132 insertions(+), 78 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 0a3abd5d1ac..4d38d17576d 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -12,15 +12,12 @@ //! Operations on ASCII strings and characters -#![unstable(feature = "std_misc", - reason = "unsure about placement and naming")] +#![stable(feature = "rust1", since = "1.0.0")] -use iter::IteratorExt; -use ops::FnMut; -use slice::SliceExt; -use str::StrExt; -use string::String; -use vec::Vec; +use prelude::v1::*; + +use mem; +use iter::Range; /// Extension methods for ASCII-subset only operations on owned strings #[unstable(feature = "std_misc", @@ -38,31 +35,50 @@ pub trait OwnedAsciiExt { } /// Extension methods for ASCII-subset only operations on string slices -#[unstable(feature = "std_misc", - reason = "would prefer to do this in a more general way")] -pub trait AsciiExt { +#[stable(feature = "rust1", since = "1.0.0")] +pub trait AsciiExt { + #[stable(feature = "rust1", since = "1.0.0")] + type Owned; + /// Check if within the ASCII range. + #[stable(feature = "rust1", since = "1.0.0")] fn is_ascii(&self) -> bool; /// Makes a copy of the string in ASCII upper case: /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', /// but non-ASCII letters are unchanged. - fn to_ascii_uppercase(&self) -> T; + #[stable(feature = "rust1", since = "1.0.0")] + fn to_ascii_uppercase(&self) -> Self::Owned; /// Makes a copy of the string in ASCII lower case: /// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', /// but non-ASCII letters are unchanged. - fn to_ascii_lowercase(&self) -> T; + #[stable(feature = "rust1", since = "1.0.0")] + fn to_ascii_lowercase(&self) -> Self::Owned; /// Check that two strings are an ASCII case-insensitive match. /// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`, /// but without allocating and copying temporary strings. + #[stable(feature = "rust1", since = "1.0.0")] fn eq_ignore_ascii_case(&self, other: &Self) -> bool; + + /// Convert this type to its ASCII upper case equivalent in-place. + /// + /// See `to_ascii_uppercase` for more information. + #[unstable(feature = "ascii")] + fn make_ascii_uppercase(&mut self); + + /// Convert this type to its ASCII lower case equivalent in-place. + /// + /// See `to_ascii_lowercase` for more information. + #[unstable(feature = "ascii")] + fn make_ascii_lowercase(&mut self); } -#[unstable(feature = "std_misc", - reason = "would prefer to do this in a more general way")] -impl AsciiExt for str { +#[stable(feature = "rust1", since = "1.0.0")] +impl AsciiExt for str { + type Owned = String; + #[inline] fn is_ascii(&self) -> bool { self.bytes().all(|b| b.is_ascii()) @@ -70,20 +86,28 @@ impl AsciiExt for str { #[inline] fn to_ascii_uppercase(&self) -> String { - // Vec::to_ascii_uppercase() preserves the UTF-8 invariant. - unsafe { String::from_utf8_unchecked(self.as_bytes().to_ascii_uppercase()) } + self.to_string().into_ascii_uppercase() } #[inline] fn to_ascii_lowercase(&self) -> String { - // Vec::to_ascii_lowercase() preserves the UTF-8 invariant. - unsafe { String::from_utf8_unchecked(self.as_bytes().to_ascii_lowercase()) } + self.to_string().into_ascii_lowercase() } #[inline] fn eq_ignore_ascii_case(&self, other: &str) -> bool { self.as_bytes().eq_ignore_ascii_case(other.as_bytes()) } + + fn make_ascii_uppercase(&mut self) { + let me: &mut [u8] = unsafe { mem::transmute(self) }; + me.make_ascii_uppercase() + } + + fn make_ascii_lowercase(&mut self) { + let me: &mut [u8] = unsafe { mem::transmute(self) }; + me.make_ascii_lowercase() + } } #[unstable(feature = "std_misc", @@ -102,9 +126,9 @@ impl OwnedAsciiExt for String { } } -#[unstable(feature = "std_misc", - reason = "would prefer to do this in a more general way")] -impl AsciiExt> for [u8] { +#[stable(feature = "rust1", since = "1.0.0")] +impl AsciiExt for [u8] { + type Owned = Vec; #[inline] fn is_ascii(&self) -> bool { self.iter().all(|b| b.is_ascii()) @@ -112,12 +136,12 @@ impl AsciiExt> for [u8] { #[inline] fn to_ascii_uppercase(&self) -> Vec { - self.iter().map(|b| b.to_ascii_uppercase()).collect() + self.to_vec().into_ascii_uppercase() } #[inline] fn to_ascii_lowercase(&self) -> Vec { - self.iter().map(|b| b.to_ascii_lowercase()).collect() + self.to_vec().into_ascii_lowercase() } #[inline] @@ -127,6 +151,18 @@ impl AsciiExt> for [u8] { a.eq_ignore_ascii_case(b) }) } + + fn make_ascii_uppercase(&mut self) { + for byte in self { + byte.make_ascii_uppercase(); + } + } + + fn make_ascii_lowercase(&mut self) { + for byte in self { + byte.make_ascii_lowercase(); + } + } } #[unstable(feature = "std_misc", @@ -134,48 +170,39 @@ impl AsciiExt> for [u8] { impl OwnedAsciiExt for Vec { #[inline] fn into_ascii_uppercase(mut self) -> Vec { - for byte in &mut self { - *byte = byte.to_ascii_uppercase(); - } + self.make_ascii_uppercase(); self } #[inline] fn into_ascii_lowercase(mut self) -> Vec { - for byte in &mut self { - *byte = byte.to_ascii_lowercase(); - } + self.make_ascii_lowercase(); self } } -#[unstable(feature = "std_misc", - reason = "would prefer to do this in a more general way")] +#[stable(feature = "rust1", since = "1.0.0")] impl AsciiExt for u8 { + type Owned = u8; #[inline] - fn is_ascii(&self) -> bool { - *self & 128 == 0u8 - } - + fn is_ascii(&self) -> bool { *self & 128 == 0u8 } #[inline] - fn to_ascii_uppercase(&self) -> u8 { - ASCII_UPPERCASE_MAP[*self as usize] - } - + fn to_ascii_uppercase(&self) -> u8 { ASCII_UPPERCASE_MAP[*self as usize] } #[inline] - fn to_ascii_lowercase(&self) -> u8 { - ASCII_LOWERCASE_MAP[*self as usize] - } - + fn to_ascii_lowercase(&self) -> u8 { ASCII_LOWERCASE_MAP[*self as usize] } #[inline] fn eq_ignore_ascii_case(&self, other: &u8) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase() } + #[inline] + fn make_ascii_uppercase(&mut self) { *self = self.to_ascii_uppercase(); } + #[inline] + fn make_ascii_lowercase(&mut self) { *self = self.to_ascii_lowercase(); } } -#[unstable(feature = "std_misc", - reason = "would prefer to do this in a more general way")] +#[stable(feature = "rust1", since = "1.0.0")] impl AsciiExt for char { + type Owned = char; #[inline] fn is_ascii(&self) -> bool { *self as u32 <= 0x7F @@ -203,6 +230,19 @@ impl AsciiExt for char { fn eq_ignore_ascii_case(&self, other: &char) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase() } + + #[inline] + fn make_ascii_uppercase(&mut self) { *self = self.to_ascii_uppercase(); } + #[inline] + fn make_ascii_lowercase(&mut self) { *self = self.to_ascii_lowercase(); } +} + +/// An iterator over the escaped version of a byte, constructed via +/// `std::ascii::escape_default`. +#[stable(feature = "rust1", since = "1.0.0")] +pub struct EscapeDefault { + range: Range, + data: [u8; 4], } /// Returns a 'default' ASCII and C++11-like literal escape of a `u8` @@ -214,34 +254,46 @@ impl AsciiExt for char { /// - Tab, CR and LF are escaped as '\t', '\r' and '\n' respectively. /// - Single-quote, double-quote and backslash chars are backslash-escaped. /// - Any other chars in the range [0x20,0x7e] are not escaped. -/// - Any other chars are given hex escapes. +/// - Any other chars are given hex escapes of the form '\xNN'. /// - Unicode escapes are never generated by this function. -#[unstable(feature = "std_misc", - reason = "needs to be updated to use an iterator")] -pub fn escape_default(c: u8, mut f: F) where - F: FnMut(u8), -{ - match c { - b'\t' => { f(b'\\'); f(b't'); } - b'\r' => { f(b'\\'); f(b'r'); } - b'\n' => { f(b'\\'); f(b'n'); } - b'\\' => { f(b'\\'); f(b'\\'); } - b'\'' => { f(b'\\'); f(b'\''); } - b'"' => { f(b'\\'); f(b'"'); } - b'\x20' ... b'\x7e' => { f(c); } - _ => { - f(b'\\'); - f(b'x'); - for &offset in &[4u, 0u] { - match ((c as i32) >> offset) & 0xf { - i @ 0 ... 9 => f(b'0' + (i as u8)), - i => f(b'a' + (i as u8 - 10)), - } - } +#[stable(feature = "rust1", since = "1.0.0")] +pub fn escape_default(c: u8) -> EscapeDefault { + let (data, len) = match c { + b'\t' => ([b'\\', b't', 0, 0], 2), + b'\r' => ([b'\\', b'r', 0, 0], 2), + b'\n' => ([b'\\', b'n', 0, 0], 2), + b'\\' => ([b'\\', b'\\', 0, 0], 2), + b'\'' => ([b'\\', b'\'', 0, 0], 2), + b'"' => ([b'\\', b'"', 0, 0], 2), + b'\x20' ... b'\x7e' => ([c, 0, 0, 0], 1), + _ => ([b'\\', b'x', hexify(c >> 4), hexify(c & 0xf)], 4), + }; + + return EscapeDefault { range: range(0, len), data: data }; + + fn hexify(b: u8) -> u8 { + match b { + 0 ... 9 => b'0' + b, + _ => b'a' + b - 10, } } } +#[stable(feature = "rust1", since = "1.0.0")] +impl Iterator for EscapeDefault { + type Item = u8; + fn next(&mut self) -> Option { self.range.next().map(|i| self.data[i]) } + fn size_hint(&self) -> (usize, Option) { self.range.size_hint() } +} +#[stable(feature = "rust1", since = "1.0.0")] +impl DoubleEndedIterator for EscapeDefault { + fn next_back(&mut self) -> Option { + self.range.next_back().map(|i| self.data[i]) + } +} +#[stable(feature = "rust1", since = "1.0.0")] +impl ExactSizeIterator for EscapeDefault {} + static ASCII_LOWERCASE_MAP: [u8; 256] = [ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 6047f94b3b4..b610f6c370b 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -817,7 +817,9 @@ impl<'a, S: Writer + Hasher> Hash for Wtf8 { } } -impl AsciiExt for Wtf8 { +impl AsciiExt for Wtf8 { + type Owned = Wtf8Buf; + fn is_ascii(&self) -> bool { self.bytes.is_ascii() } @@ -830,6 +832,9 @@ impl AsciiExt for Wtf8 { fn eq_ignore_ascii_case(&self, other: &Wtf8) -> bool { self.bytes.eq_ignore_ascii_case(&other.bytes) } + + fn make_ascii_uppercase(&mut self) { self.bytes.make_ascii_uppercase() } + fn make_ascii_lowercase(&mut self) { self.bytes.make_ascii_lowercase() } } #[cfg(test)] diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 583095e1574..4b021f2434f 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2761,15 +2761,13 @@ impl<'a> State<'a> { ast::LitStr(ref st, style) => self.print_string(&st, style), ast::LitByte(byte) => { let mut res = String::from_str("b'"); - ascii::escape_default(byte, |c| res.push(c as char)); + res.extend(ascii::escape_default(byte).map(|c| c as char)); res.push('\''); word(&mut self.s, &res[]) } ast::LitChar(ch) => { let mut res = String::from_str("'"); - for c in ch.escape_default() { - res.push(c); - } + res.extend(ch.escape_default()); res.push('\''); word(&mut self.s, &res[]) } @@ -2809,8 +2807,8 @@ impl<'a> State<'a> { ast::LitBinary(ref v) => { let mut escaped: String = String::new(); for &ch in &**v { - ascii::escape_default(ch as u8, - |ch| escaped.push(ch as char)); + escaped.extend(ascii::escape_default(ch as u8) + .map(|c| c as char)); } word(&mut self.s, &format!("b\"{}\"", escaped)[]) } diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index c4b3d2813af..276e2f3ca38 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -58,7 +58,6 @@ #![feature(path)] #![feature(rustc_private)] #![feature(staged_api)] -#![feature(std_misc)] #![feature(unicode)] #![feature(env)] #![cfg_attr(windows, feature(libc))] -- cgit 1.4.1-3-g733a5 From a2ebb24ee6cc76791ef834cb2d17ecac95756499 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 17 Feb 2015 11:05:44 -0800 Subject: std: Rename io/path features with old_ prefix This commit renames the features for the `std::old_io` and `std::old_path` modules to `old_io` and `old_path` to help facilitate migration to the new APIs. This is a breaking change as crates which mention the old feature names now need to be renamed to use the new feature names. [breaking-change] --- src/compiletest/compiletest.rs | 4 ++-- src/libgraphviz/lib.rs | 2 +- src/liblog/lib.rs | 2 +- src/librbml/lib.rs | 2 +- src/librustc/lib.rs | 4 ++-- src/librustc_back/lib.rs | 4 ++-- src/librustc_driver/lib.rs | 4 ++-- src/librustc_llvm/lib.rs | 2 +- src/librustc_trans/lib.rs | 4 ++-- src/librustdoc/lib.rs | 4 ++-- src/libserialize/lib.rs | 4 ++-- src/libstd/old_io/mod.rs | 2 +- src/libstd/old_path/mod.rs | 2 +- src/libsyntax/lib.rs | 4 ++-- src/libterm/lib.rs | 4 ++-- src/libtest/lib.rs | 4 ++-- src/rustbook/main.rs | 4 ++-- src/test/compile-fail/lint-uppercase-variables.rs | 17 ++++++++--------- 18 files changed, 36 insertions(+), 37 deletions(-) (limited to 'src/libsyntax') diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 6b6251a96c9..df94f7613eb 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -13,8 +13,8 @@ #![feature(box_syntax)] #![feature(collections)] #![feature(int_uint)] -#![feature(io)] -#![feature(path)] +#![feature(old_io)] +#![feature(old_path)] #![feature(rustc_private)] #![feature(unboxed_closures)] #![feature(std_misc)] diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index a1a271bc5ab..230deabee00 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -276,7 +276,7 @@ #![feature(int_uint)] #![feature(collections)] #![feature(core)] -#![feature(io)] +#![feature(old_io)] use self::LabelText::*; diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 5edb4a96a7d..4dab07acfd2 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -171,7 +171,7 @@ #![feature(box_syntax)] #![feature(int_uint)] #![feature(core)] -#![feature(io)] +#![feature(old_io)] #![feature(std_misc)] #![feature(env)] diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index 154dbbdb750..488d5999323 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -28,7 +28,7 @@ #![feature(collections)] #![feature(core)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index abf70813d36..fe9a81bb7c9 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -29,10 +29,10 @@ #![feature(core)] #![feature(hash)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(libc)] #![feature(env)] -#![feature(path)] +#![feature(old_path)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 54b3e8f2081..d589b063204 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -35,9 +35,9 @@ #![feature(core)] #![feature(hash)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(os)] -#![feature(path)] +#![feature(old_path)] #![feature(rustc_private)] #![feature(staged_api)] #![feature(env)] diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 9b8ca398b12..6357a2b115b 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -28,10 +28,10 @@ #![feature(core)] #![feature(env)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(libc)] #![feature(os)] -#![feature(path)] +#![feature(old_path)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 213e3565362..cc8ec4b40cb 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -29,7 +29,7 @@ #![feature(int_uint)] #![feature(libc)] #![feature(link_args)] -#![feature(path)] +#![feature(old_path)] #![feature(staged_api)] #![feature(std_misc)] diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 21557379e3a..4606200d058 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -30,10 +30,10 @@ #![feature(core)] #![feature(hash)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(env)] #![feature(libc)] -#![feature(path)] +#![feature(old_path)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index b09c3f730fc..883f10be3a1 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -25,10 +25,10 @@ #![feature(env)] #![feature(hash)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(libc)] #![feature(os)] -#![feature(path)] +#![feature(old_path)] #![feature(rustc_private)] #![feature(staged_api)] #![feature(std_misc)] diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 6cada2e5614..853da598ab5 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -29,8 +29,8 @@ Core encoding and decoding interfaces. #![feature(collections)] #![feature(core)] #![feature(int_uint)] -#![feature(io)] -#![feature(path)] +#![feature(old_io)] +#![feature(old_path)] #![feature(hash)] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/libstd/old_io/mod.rs b/src/libstd/old_io/mod.rs index 3673f590c0a..d3f31ed6b75 100644 --- a/src/libstd/old_io/mod.rs +++ b/src/libstd/old_io/mod.rs @@ -238,7 +238,7 @@ //! concerned with error handling; instead its caller is responsible for //! responding to errors that may occur while attempting to read the numbers. -#![unstable(feature = "io")] +#![unstable(feature = "old_io")] #![deny(unused_must_use)] pub use self::SeekStyle::*; diff --git a/src/libstd/old_path/mod.rs b/src/libstd/old_path/mod.rs index 17cfe1c8297..37de2993c4d 100644 --- a/src/libstd/old_path/mod.rs +++ b/src/libstd/old_path/mod.rs @@ -59,7 +59,7 @@ //! println!("path exists: {}", path.exists()); //! ``` -#![unstable(feature = "path")] +#![unstable(feature = "old_path")] use core::marker::Sized; use ffi::CString; diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index f4b0c867f42..e8bdcd62b58 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -30,9 +30,9 @@ #![feature(env)] #![feature(hash)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(libc)] -#![feature(path)] +#![feature(old_path)] #![feature(quote, unsafe_destructor)] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index c4b3d2813af..81534dbe4c4 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -54,8 +54,8 @@ #![feature(box_syntax)] #![feature(collections)] #![feature(int_uint)] -#![feature(io)] -#![feature(path)] +#![feature(old_io)] +#![feature(old_path)] #![feature(rustc_private)] #![feature(staged_api)] #![feature(std_misc)] diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 860ce209d45..0f90fbdfe0f 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -39,8 +39,8 @@ #![feature(env)] #![feature(hash)] #![feature(int_uint)] -#![feature(io)] -#![feature(path)] +#![feature(old_io)] +#![feature(old_path)] #![feature(rustc_private)] #![feature(staged_api)] #![feature(std_misc)] diff --git a/src/rustbook/main.rs b/src/rustbook/main.rs index a8466465f87..c0e9cac2813 100644 --- a/src/rustbook/main.rs +++ b/src/rustbook/main.rs @@ -11,9 +11,9 @@ #![feature(box_syntax)] #![feature(collections)] #![feature(core)] -#![feature(io)] +#![feature(old_io)] #![feature(os)] -#![feature(path)] +#![feature(old_path)] #![feature(rustdoc)] extern crate rustdoc; diff --git a/src/test/compile-fail/lint-uppercase-variables.rs b/src/test/compile-fail/lint-uppercase-variables.rs index 057b8e3acc6..b68d9dc4645 100644 --- a/src/test/compile-fail/lint-uppercase-variables.rs +++ b/src/test/compile-fail/lint-uppercase-variables.rs @@ -12,12 +12,14 @@ #![allow(dead_code)] #![deny(non_snake_case)] -#![feature(path)] -#![feature(io)] use std::old_io::File; use std::old_io::IoError; +mod foo { + pub enum Foo { Foo } +} + struct Something { X: usize //~ ERROR structure field `X` should have a snake case name such as `x` } @@ -30,13 +32,10 @@ fn main() { let Test: usize = 0; //~ ERROR variable `Test` should have a snake case name such as `test` println!("{}", Test); - let mut f = File::open(&Path::new("something.txt")); - let mut buff = [0u8; 16]; - match f.read(&mut buff) { - Ok(cnt) => println!("read this many bytes: {}", cnt), - Err(IoError{ kind: EndOfFile, .. }) => println!("Got end of file: {:?}", EndOfFile), -//~^ ERROR variable `EndOfFile` should have a snake case name such as `end_of_file` -//~^^ WARN `EndOfFile` is named the same as one of the variants of the type `std::old_io::IoErrorKind` + match foo::Foo::Foo { + Foo => {} +//~^ ERROR variable `Foo` should have a snake case name such as `foo` +//~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo` } test(1); -- cgit 1.4.1-3-g733a5