diff options
| author | bors <bors@rust-lang.org> | 2018-10-29 10:19:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-10-29 10:19:17 +0000 |
| commit | d586d5d2f51489821b471f20959333558c24b129 (patch) | |
| tree | 4718a64c5fb2dcbb8b42cedd7049c3cdd21e9eb6 /src/libsyntax/parse | |
| parent | 4e88b7363b7858960ccfd87326ece9d00bf4d973 (diff) | |
| parent | eb00b4792cdd1d48d48ca8588a96f9bce3f0fd41 (diff) | |
| download | rust-d586d5d2f51489821b471f20959333558c24b129.tar.gz rust-d586d5d2f51489821b471f20959333558c24b129.zip | |
Auto merge of #55462 - pietroalbini:rollup, r=pietroalbini
Rollup of 9 pull requests Successful merges: - #54965 (update tcp stream documentation) - #55269 (fix typos in various places) - #55384 (Avoid unnecessary allocations in `float_lit` and `integer_lit`.) - #55423 (back out bogus `Ok`-wrapping suggestion on `?` arm type mismatch) - #55426 (Make a bunch of trivial methods of NonNull be `#[inline]`) - #55438 (Avoid directly catching BaseException in bootstrap configure script) - #55439 (Remove unused sys import from generate-deriving-span-tests) - #55440 (Remove unreachable code in hasClass function in Rustdoc) - #55447 (Fix invalid path in generate-deriving-span-tests.py.) Failed merges: r? @ghost
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index a4b8ab86f37..77a2ae6acf0 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -494,8 +494,17 @@ fn float_lit(s: &str, suffix: Option<Symbol>, diag: Option<(Span, &Handler)>) -> Option<ast::LitKind> { debug!("float_lit: {:?}, {:?}", s, suffix); // FIXME #2252: bounds checking float literals is deferred until trans - let s = s.chars().filter(|&c| c != '_').collect::<String>(); - filtered_float_lit(Symbol::intern(&s), suffix, diag) + + // Strip underscores without allocating a new String unless necessary. + let s2; + let s = if s.chars().any(|c| c == '_') { + s2 = s.chars().filter(|&c| c != '_').collect::<String>(); + &s2 + } else { + s + }; + + filtered_float_lit(Symbol::intern(s), suffix, diag) } /// Parse a string representing a byte literal into its final form. Similar to `char_lit` @@ -591,8 +600,14 @@ fn integer_lit(s: &str, suffix: Option<Symbol>, diag: Option<(Span, &Handler)>) -> Option<ast::LitKind> { // s can only be ascii, byte indexing is fine - let s2 = s.chars().filter(|&c| c != '_').collect::<String>(); - let mut s = &s2[..]; + // Strip underscores without allocating a new String unless necessary. + let s2; + let mut s = if s.chars().any(|c| c == '_') { + s2 = s.chars().filter(|&c| c != '_').collect::<String>(); + &s2 + } else { + s + }; debug!("integer_lit: {}, {:?}", s, suffix); |
