From 71120ef1e5cb885ee45e6148970db6ce93ce1aca Mon Sep 17 00:00:00 2001 From: Matthias Krüger Date: Sun, 19 Aug 2018 15:30:23 +0200 Subject: Fix typos found by codespell. --- src/libsyntax/ext/expand.rs | 2 +- src/libsyntax/ext/tt/macro_parser.rs | 4 ++-- src/libsyntax/ext/tt/quoted.rs | 2 +- src/libsyntax/parse/parser.rs | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index ffa2730d686..b24c2d86981 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -321,7 +321,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { // we'll be able to immediately resolve most of imported macros. self.resolve_imports(); - // Resolve paths in all invocations and produce ouput expanded fragments for them, but + // Resolve paths in all invocations and produce output expanded fragments for them, but // do not insert them into our input AST fragment yet, only store in `expanded_fragments`. // The output fragments also go through expansion recursively until no invocations are left. // Unresolved macros produce dummy outputs as a recovery measure. diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 82f88d1d864..7d98fa661c0 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -637,7 +637,7 @@ pub fn parse( // A queue of possible matcher positions. We initialize it with the matcher position in which // the "dot" is before the first token of the first token tree in `ms`. `inner_parse_loop` then - // processes all of these possible matcher positions and produces posible next positions into + // processes all of these possible matcher positions and produces possible next positions into // `next_items`. After some post-processing, the contents of `next_items` replenish `cur_items` // and we start over again. // @@ -726,7 +726,7 @@ pub fn parse( ), ); } - // If there are no posible next positions AND we aren't waiting for the black-box parser, + // If there are no possible next positions AND we aren't waiting for the black-box parser, // then their is a syntax error. else if bb_items.is_empty() && next_items.is_empty() { return Failure(parser.span, parser.token); diff --git a/src/libsyntax/ext/tt/quoted.rs b/src/libsyntax/ext/tt/quoted.rs index 357fc77a3a7..cc635a29275 100644 --- a/src/libsyntax/ext/tt/quoted.rs +++ b/src/libsyntax/ext/tt/quoted.rs @@ -323,7 +323,7 @@ where } // `tree` is followed by an `ident`. This could be `$meta_var` or the `$crate` special - // metavariable that names the crate of the invokation. + // metavariable that names the crate of the invocation. Some(tokenstream::TokenTree::Token(ident_span, ref token)) if token.is_ident() => { let (ident, is_raw) = token.ident().unwrap(); let span = ident_span.with_lo(span.lo()); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 345464c6664..b6d876ebc9e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3535,8 +3535,8 @@ impl<'a> Parser<'a> { if arm_start_lines.lines[0].end_col == expr_lines.lines[0].end_col && expr_lines.lines.len() == 2 && self.token == token::FatArrow => { - // We check wether there's any trailing code in the parse span, if there - // isn't, we very likely have the following: + // We check whether there's any trailing code in the parse span, + // if there isn't, we very likely have the following: // // X | &Y => "y" // | -- - missing comma @@ -3934,7 +3934,7 @@ impl<'a> Parser<'a> { } /// A wrapper around `parse_pat` with some special error handling for the - /// "top-level" patterns in a match arm, `for` loop, `let`, &c. (in contast + /// "top-level" patterns in a match arm, `for` loop, `let`, &c. (in contrast /// to subpatterns within such). fn parse_top_level_pat(&mut self) -> PResult<'a, P> { let pat = self.parse_pat()?; @@ -4322,7 +4322,7 @@ impl<'a> Parser<'a> { // If `break_on_semi` is `Break`, then we will stop consuming tokens after // finding (and consuming) a `;` outside of `{}` or `[]` (note that this is // approximate - it can mean we break too early due to macros, but that - // shoud only lead to sub-optimal recovery, not inaccurate parsing). + // should only lead to sub-optimal recovery, not inaccurate parsing). // // If `break_on_block` is `Break`, then we will stop consuming tokens // after finding (and consuming) a brace-delimited block. @@ -4887,7 +4887,7 @@ impl<'a> Parser<'a> { fn parse_generic_bounds_common(&mut self, allow_plus: bool) -> PResult<'a, GenericBounds> { let mut bounds = Vec::new(); loop { - // This needs to be syncronized with `Token::can_begin_bound`. + // This needs to be synchronized with `Token::can_begin_bound`. let is_bound_start = self.check_path() || self.check_lifetime() || self.check(&token::Question) || self.check_keyword(keywords::For) || -- cgit 1.4.1-3-g733a5 From 00920c0024860cec91b71a8a1fe57d1af37938f9 Mon Sep 17 00:00:00 2001 From: Jakub Kozlowski Date: Wed, 15 Aug 2018 00:24:55 +0100 Subject: Stabilize macro_vis_matcher --- .../src/language-features/macro-vis-matcher.md | 14 -------------- src/doc/unstable-book/src/language-features/plugin.md | 1 - src/librustc/lib.rs | 2 +- src/librustc_data_structures/lib.rs | 2 +- src/librustc_lint/lib.rs | 2 +- src/librustc_mir/lib.rs | 2 +- src/libstd/lib.rs | 2 +- src/libsyntax/ext/tt/macro_rules.rs | 14 +------------- src/libsyntax/feature_gate.rs | 8 ++------ .../compile-fail-fulldeps/auxiliary/lint_for_crate.rs | 2 +- .../auxiliary/lint_group_plugin_test.rs | 2 +- .../auxiliary/lint_plugin_test.rs | 2 +- .../run-pass-fulldeps/auxiliary/lint_for_crate.rs | 2 +- .../proc-macro/auxiliary/issue-40001-plugin.rs | 2 +- src/test/run-pass/macro-first-set.rs | 2 +- src/test/run-pass/macro-pub-matcher.rs | 3 ++- .../ui-fulldeps/auxiliary/lint_group_plugin_test.rs | 2 +- src/test/ui-fulldeps/auxiliary/lint_plugin_test.rs | 2 +- src/test/ui-fulldeps/auxiliary/lint_tool_test.rs | 2 +- .../feature-gates/feature-gate-macro-vis-matcher.rs | 19 ------------------- .../feature-gate-macro-vis-matcher.stderr | 11 ----------- src/test/ui/issues/issue-42755.rs | 2 +- src/test/ui/lint/unreachable_pub-pub_crate.rs | 2 +- src/test/ui/lint/unreachable_pub.rs | 2 +- 24 files changed, 22 insertions(+), 82 deletions(-) delete mode 100644 src/doc/unstable-book/src/language-features/macro-vis-matcher.md delete mode 100644 src/test/ui/feature-gates/feature-gate-macro-vis-matcher.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-macro-vis-matcher.stderr (limited to 'src/libsyntax') diff --git a/src/doc/unstable-book/src/language-features/macro-vis-matcher.md b/src/doc/unstable-book/src/language-features/macro-vis-matcher.md deleted file mode 100644 index 7918a356843..00000000000 --- a/src/doc/unstable-book/src/language-features/macro-vis-matcher.md +++ /dev/null @@ -1,14 +0,0 @@ -# `macro_vis_matcher` - -The tracking issue for this feature is: [#41022] - -With this feature gate enabled, the [list of fragment specifiers][frags] gains one more entry: - -* `vis`: a visibility qualifier. Examples: nothing (default visibility); `pub`; `pub(crate)`. - -A `vis` variable may be followed by a comma, ident, type, or path. - -[#41022]: https://github.com/rust-lang/rust/issues/41022 -[frags]: ../book/first-edition/macros.html#syntactic-requirements - ------------------------- diff --git a/src/doc/unstable-book/src/language-features/plugin.md b/src/doc/unstable-book/src/language-features/plugin.md index 19ece095090..b408d5d0805 100644 --- a/src/doc/unstable-book/src/language-features/plugin.md +++ b/src/doc/unstable-book/src/language-features/plugin.md @@ -183,7 +183,6 @@ that warns about any item named `lintme`. ```rust,ignore #![feature(plugin_registrar)] #![feature(box_syntax, rustc_private)] -#![feature(macro_vis_matcher)] #![feature(macro_at_most_once_rep)] extern crate syntax; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index b6f4bd6dc40..c92f7eb5954 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -47,7 +47,7 @@ #![feature(drain_filter)] #![feature(iterator_find_map)] #![cfg_attr(windows, feature(libc))] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![feature(never_type)] #![feature(exhaustive_patterns)] #![feature(extern_types)] diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 5699512326a..c3ee48d20f6 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -25,7 +25,7 @@ #![feature(unsize)] #![feature(specialization)] #![feature(optin_builtin_traits)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![cfg_attr(not(stage0), feature(nll))] #![feature(allow_internal_unstable)] #![feature(vec_resize_with)] diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 801604d1379..15eb4730c1d 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -26,7 +26,7 @@ #![cfg_attr(test, feature(test))] #![feature(box_patterns)] #![feature(box_syntax)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![cfg_attr(not(stage0), feature(nll))] #![feature(quote)] #![feature(rustc_diagnostic_macros)] diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index bda80ff562c..19fc087f128 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -26,7 +26,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![feature(const_fn)] #![feature(core_intrinsics)] #![feature(decl_macro)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![feature(exhaustive_patterns)] #![feature(range_contains)] #![feature(rustc_diagnostic_macros)] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index b0069f826ee..ade297219d2 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -270,7 +270,7 @@ #![feature(libc)] #![feature(link_args)] #![feature(linkage)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![feature(needs_panic_runtime)] #![feature(never_type)] #![cfg_attr(not(stage0), feature(nll))] diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 770561fe326..2c738ac2a04 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -964,7 +964,7 @@ fn is_legal_fragment_specifier(sess: &ParseSess, frag_span: Span) -> bool { match frag_name { "item" | "block" | "stmt" | "expr" | "pat" | "lifetime" | - "path" | "ty" | "ident" | "meta" | "tt" | "" => true, + "path" | "ty" | "ident" | "meta" | "tt" | "vis" | "" => true, "literal" => { if !features.macro_literal_matcher && !attr::contains_name(attrs, "allow_internal_unstable") { @@ -977,18 +977,6 @@ fn is_legal_fragment_specifier(sess: &ParseSess, } true }, - "vis" => { - if !features.macro_vis_matcher && - !attr::contains_name(attrs, "allow_internal_unstable") { - let explain = feature_gate::EXPLAIN_VIS_MATCHER; - emit_feature_err(sess, - "macro_vis_matcher", - frag_span, - GateIssue::Language, - explain); - } - true - }, _ => false, } } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index e8245a553eb..9e80564f579 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -342,9 +342,6 @@ declare_features! ( // Allows overlapping impls of marker traits (active, overlapping_marker_traits, "1.18.0", Some(29864), None), - // Allows use of the :vis macro fragment specifier - (active, macro_vis_matcher, "1.18.0", Some(41022), None), - // rustc internal (active, abi_thiscall, "1.19.0", None, None), @@ -648,6 +645,8 @@ declare_features! ( (accepted, repr_transparent, "1.28.0", Some(43036), None), // Defining procedural macros in `proc-macro` crates (accepted, proc_macro, "1.29.0", Some(38356), None), + // Allows use of the :vis macro fragment specifier + (accepted, macro_vis_matcher, "1.29.0", Some(41022), None), // Allows importing and reexporting macros with `use`, // enables macro modularization in general. (accepted, use_extern_macros, "1.30.0", Some(35896), None), @@ -1363,9 +1362,6 @@ pub const EXPLAIN_DEPR_CUSTOM_DERIVE: &'static str = pub const EXPLAIN_DERIVE_UNDERSCORE: &'static str = "attributes of the form `#[derive_*]` are reserved for the compiler"; -pub const EXPLAIN_VIS_MATCHER: &'static str = - ":vis fragment specifier is experimental and subject to change"; - pub const EXPLAIN_LITERAL_MATCHER: &'static str = ":literal fragment specifier is experimental and subject to change"; diff --git a/src/test/compile-fail-fulldeps/auxiliary/lint_for_crate.rs b/src/test/compile-fail-fulldeps/auxiliary/lint_for_crate.rs index 7303af73cac..c965a3ed86c 100644 --- a/src/test/compile-fail-fulldeps/auxiliary/lint_for_crate.rs +++ b/src/test/compile-fail-fulldeps/auxiliary/lint_for_crate.rs @@ -12,7 +12,7 @@ #![feature(plugin_registrar, rustc_private)] #![feature(box_syntax)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![feature(macro_at_most_once_rep)] #[macro_use] extern crate rustc; diff --git a/src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs b/src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs index 3f3997726c9..8ccb5878c40 100644 --- a/src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs +++ b/src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs @@ -12,7 +12,7 @@ #![feature(plugin_registrar)] #![feature(box_syntax, rustc_private)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![feature(macro_at_most_once_rep)] // Load rustc as a plugin to get macros diff --git a/src/test/compile-fail-fulldeps/auxiliary/lint_plugin_test.rs b/src/test/compile-fail-fulldeps/auxiliary/lint_plugin_test.rs index ab39709c529..315dad7eea5 100644 --- a/src/test/compile-fail-fulldeps/auxiliary/lint_plugin_test.rs +++ b/src/test/compile-fail-fulldeps/auxiliary/lint_plugin_test.rs @@ -12,7 +12,7 @@ #![feature(plugin_registrar)] #![feature(box_syntax, rustc_private)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![feature(macro_at_most_once_rep)] extern crate syntax; diff --git a/src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs b/src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs index fa208e14b7d..601003827c6 100644 --- a/src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs +++ b/src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs @@ -12,7 +12,7 @@ #![feature(plugin_registrar, rustc_private)] #![feature(box_syntax)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![feature(macro_at_most_once_rep)] #[macro_use] extern crate rustc; diff --git a/src/test/run-pass-fulldeps/proc-macro/auxiliary/issue-40001-plugin.rs b/src/test/run-pass-fulldeps/proc-macro/auxiliary/issue-40001-plugin.rs index 56c163b8ce3..fe9ac5fd635 100644 --- a/src/test/run-pass-fulldeps/proc-macro/auxiliary/issue-40001-plugin.rs +++ b/src/test/run-pass-fulldeps/proc-macro/auxiliary/issue-40001-plugin.rs @@ -9,7 +9,7 @@ // except according to those terms. #![feature(box_syntax, plugin, plugin_registrar, rustc_private)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![feature(macro_at_most_once_rep)] #![crate_type = "dylib"] diff --git a/src/test/run-pass/macro-first-set.rs b/src/test/run-pass/macro-first-set.rs index c371a33257f..9216040ab6e 100644 --- a/src/test/run-pass/macro-first-set.rs +++ b/src/test/run-pass/macro-first-set.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] //{{{ issue 40569 ============================================================== diff --git a/src/test/run-pass/macro-pub-matcher.rs b/src/test/run-pass/macro-pub-matcher.rs index 32145277252..db8331358b9 100644 --- a/src/test/run-pass/macro-pub-matcher.rs +++ b/src/test/run-pass/macro-pub-matcher.rs @@ -9,7 +9,8 @@ // except according to those terms. #![allow(dead_code, unused_imports)] -#![feature(macro_vis_matcher, crate_visibility_modifier)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] +#![feature(crate_visibility_modifier)] /** Ensure that `:vis` matches can be captured in existing positions, and passed diff --git a/src/test/ui-fulldeps/auxiliary/lint_group_plugin_test.rs b/src/test/ui-fulldeps/auxiliary/lint_group_plugin_test.rs index 3f3997726c9..8ccb5878c40 100644 --- a/src/test/ui-fulldeps/auxiliary/lint_group_plugin_test.rs +++ b/src/test/ui-fulldeps/auxiliary/lint_group_plugin_test.rs @@ -12,7 +12,7 @@ #![feature(plugin_registrar)] #![feature(box_syntax, rustc_private)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![feature(macro_at_most_once_rep)] // Load rustc as a plugin to get macros diff --git a/src/test/ui-fulldeps/auxiliary/lint_plugin_test.rs b/src/test/ui-fulldeps/auxiliary/lint_plugin_test.rs index ab39709c529..315dad7eea5 100644 --- a/src/test/ui-fulldeps/auxiliary/lint_plugin_test.rs +++ b/src/test/ui-fulldeps/auxiliary/lint_plugin_test.rs @@ -12,7 +12,7 @@ #![feature(plugin_registrar)] #![feature(box_syntax, rustc_private)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![feature(macro_at_most_once_rep)] extern crate syntax; diff --git a/src/test/ui-fulldeps/auxiliary/lint_tool_test.rs b/src/test/ui-fulldeps/auxiliary/lint_tool_test.rs index 01fa2f3459e..d7895bd8781 100644 --- a/src/test/ui-fulldeps/auxiliary/lint_tool_test.rs +++ b/src/test/ui-fulldeps/auxiliary/lint_tool_test.rs @@ -10,7 +10,7 @@ #![feature(plugin_registrar)] #![feature(box_syntax, rustc_private)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![feature(macro_at_most_once_rep)] extern crate syntax; diff --git a/src/test/ui/feature-gates/feature-gate-macro-vis-matcher.rs b/src/test/ui/feature-gates/feature-gate-macro-vis-matcher.rs deleted file mode 100644 index 5d6f2acea83..00000000000 --- a/src/test/ui/feature-gates/feature-gate-macro-vis-matcher.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017 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 MSP430 interrupt ABI cannot be used when msp430_interrupt -// feature gate is not used. - -macro_rules! m { ($v:vis) => {} } -//~^ ERROR :vis fragment specifier is experimental and subject to change - -fn main() { - m!(pub); -} diff --git a/src/test/ui/feature-gates/feature-gate-macro-vis-matcher.stderr b/src/test/ui/feature-gates/feature-gate-macro-vis-matcher.stderr deleted file mode 100644 index 9d98091674e..00000000000 --- a/src/test/ui/feature-gates/feature-gate-macro-vis-matcher.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0658]: :vis fragment specifier is experimental and subject to change (see issue #41022) - --> $DIR/feature-gate-macro-vis-matcher.rs:14:19 - | -LL | macro_rules! m { ($v:vis) => {} } - | ^^^^^^ - | - = help: add #![feature(macro_vis_matcher)] to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/issues/issue-42755.rs b/src/test/ui/issues/issue-42755.rs index 7547c4a17be..dd53a1c71a5 100644 --- a/src/test/ui/issues/issue-42755.rs +++ b/src/test/ui/issues/issue-42755.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] macro_rules! foo { ($($p:vis)*) => {} //~ ERROR repetition matches empty token tree diff --git a/src/test/ui/lint/unreachable_pub-pub_crate.rs b/src/test/ui/lint/unreachable_pub-pub_crate.rs index 0a1926f8ae5..0089617b11c 100644 --- a/src/test/ui/lint/unreachable_pub-pub_crate.rs +++ b/src/test/ui/lint/unreachable_pub-pub_crate.rs @@ -16,7 +16,7 @@ // compile-pass -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![allow(unused)] #![warn(unreachable_pub)] diff --git a/src/test/ui/lint/unreachable_pub.rs b/src/test/ui/lint/unreachable_pub.rs index 5bb67670d85..7fd4a901090 100644 --- a/src/test/ui/lint/unreachable_pub.rs +++ b/src/test/ui/lint/unreachable_pub.rs @@ -11,7 +11,7 @@ // compile-pass #![feature(crate_visibility_modifier)] -#![feature(macro_vis_matcher)] +#![cfg_attr(stage0, feature(macro_vis_matcher))] #![allow(unused)] #![warn(unreachable_pub)] -- cgit 1.4.1-3-g733a5 From 5bf2ad3018de1f5a94bed2685211f3694f94249c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 19 Aug 2018 21:25:08 -0700 Subject: syntax: Optimize some literal parsing Currently in the `wasm-bindgen` project we have a very very large crate that's procedurally generated, `web-sys`. To generate this crate we parse all of a browser's WebIDL and we then generate bindings for all of the APIs contained within. The resulting Rust file is 18MB large (wow!) and currently takes a very long time to compile in debug mode. On the nightly compiler a *debug* build takes 90s for the crate to finish. I was curious what was taking so long and upon investigating a *massive* portion of the time was spent in the `lit_token` method of the compiler, primarily formatting strings via `format!`. Upon some more investigation it looks like the `byte_str_lit` was allocating an error message once per byte, causing a very large number of allocations to happen for large literals, of which wasm-bindgen generates quite a few (some are MB large). This commit fixes the issue by lazily allocating the error message, only doing so if the error message is actually needed (which should be never). As a result, the debug mode compilation time for our `web-sys` crate decreased from 90s to 20s, a very nice improvement! (although we've still got some work to do). --- src/libsyntax/parse/mod.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index d029509f0c1..2795d5c8f91 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -532,7 +532,7 @@ fn byte_lit(lit: &str) -> (u8, usize) { fn byte_str_lit(lit: &str) -> Lrc> { let mut res = Vec::with_capacity(lit.len()); - let error = |i| format!("lexer should have rejected {} at {}", lit, i); + let error = |i| panic!("lexer should have rejected {} at {}", lit, i); /// Eat everything up to a non-whitespace fn eat>(it: &mut iter::Peekable) { @@ -551,12 +551,11 @@ fn byte_str_lit(lit: &str) -> Lrc> { loop { match chars.next() { Some((i, b'\\')) => { - let em = error(i); - match chars.peek().expect(&em).1 { + match chars.peek().unwrap_or_else(|| error(i)).1 { b'\n' => eat(&mut chars), b'\r' => { chars.next(); - if chars.peek().expect(&em).1 != b'\n' { + if chars.peek().unwrap_or_else(|| error(i)).1 != b'\n' { panic!("lexer accepted bare CR"); } eat(&mut chars); @@ -573,8 +572,7 @@ fn byte_str_lit(lit: &str) -> Lrc> { } }, Some((i, b'\r')) => { - let em = error(i); - if chars.peek().expect(&em).1 != b'\n' { + if chars.peek().unwrap_or_else(|| error(i)).1 != b'\n' { panic!("lexer accepted bare CR"); } chars.next(); -- cgit 1.4.1-3-g733a5