summary refs log tree commit diff
path: root/src/test/ui/parser
AgeCommit message (Collapse)AuthorLines
2021-10-14Revert "Stabilize `arbitrary_enum_discriminant`"Mark Rousskov-0/+59
This reverts commit 7a62f29f3171767090949778ce0f161e930706b9.
2021-10-14Add regression test for ice 89574Gary Guo-4/+37
2021-09-16regression test for issue #88583.Felix S. Klock II-0/+15
(cherry picked from commit 35370a7ba3d52bfe2a6121a0eaccbc240ed9559d)
2021-09-03Auto merge of #88386 - estebank:unmatched-delims, r=jackh726bors-56/+56
Point at unclosed delimiters as part of the primary MultiSpan Both the place where the parser encounters a needed closed delimiter and the unclosed opening delimiter are important, so they should get the same level of highlighting in the output. _Context: https://twitter.com/mwk4/status/1430631546432675840_
2021-09-01Auto merge of #87688 - camsteffen:let-else, r=cjgillotbors-31/+31
Introduce `let...else` Tracking issue: #87335 The trickiest part for me was enforcing the diverging else block with clear diagnostics. Perhaps the obvious solution is to expand to `let _: ! = ..`, but I decided against this because, when a "mismatched type" error is found in typeck, there is no way to trace where in the HIR the expected type originated, AFAICT. In order to pass down this information, I believe we should introduce `Expectation::LetElseNever(HirId)` or maybe add `HirId` to `Expectation::HasType`, but I left that as a future enhancement. For now, I simply assert that the block is `!` with a custom `ObligationCauseCode`, and I think this is clear enough, at least to start. The downside here is that the error points at the entire block rather than the specific expression with the wrong type. I left a todo to this effect. Overall, I believe this PR is feature-complete with regard to the RFC.
2021-08-30Fix testsCameron Steffen-31/+31
2021-08-28fix(rustc_parse): incorrect span information for macro path exprMichael Howell-0/+27
Old error output: 3 | let _: usize = $f; | ----- ^ expected `usize`, found struct `Baz` | | | expected due to this New error output: 3 | let _: usize = $f; | ----- ^^ expected `usize`, found struct `Baz` | | | expected due to this
2021-08-28fix(rustc_parse): incorrect span information for macro block exprMichael Howell-0/+35
Old error output: = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) help: wrap this expression in parentheses | 4 | break '_l $f(;) | ^ ^ New error output: = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) help: wrap this expression in parentheses | 4 | break '_l ($f); | ^ ^
2021-08-27Point at unclosed delimiters as part of the primary MultiSpanEsteban Kuber-56/+56
Both the place where the parser encounters a needed closed delimiter and the unclosed opening delimiter are important, so they should get the same level of highlighting in the output.
2021-08-27Fix more testsDeadbeef-9/+9
2021-08-18Auto merge of #86860 - fee1-dead:stabilize, r=LeSeulArtichautbors-59/+0
Stabilize `arbitrary_enum_discriminant` Closes #60553. ---- ## Stabilization Report _copied from https://github.com/rust-lang/rust/issues/60553#issuecomment-865922311_ ### Summary Enables a user to specify *explicit* discriminants on arbitrary enums. Previously, this was hard to achieve: ```rust #[repr(u8)] enum Foo { A(u8) = 0, B(i8) = 1, C(bool) = 42, } ``` Someone would need to add 41 hidden variants in between as a workaround with implicit discriminants. In conjunction with [RFC 2195](https://github.com/rust-lang/rfcs/blob/master/text/2195-really-tagged-unions.md), this feature would provide more flexibility for FFI and unsafe code involving enums. ### Test cases Most tests are in [`src/test/ui/enum-discriminant`](https://github.com/rust-lang/rust/tree/master/src/test/ui/enum-discriminant), there are two [historical](https://github.com/rust-lang/rust/blob/master/src/test/ui/parser/tag-variant-disr-non-nullary.rs) [tests](https://github.com/rust-lang/rust/blob/master/src/test/ui/parser/issue-17383.rs) that are now covered by the feature (removed by this pr due to them being obsolete). ### Edge cases The feature is well defined and does not have many edge cases. One [edge case](https://github.com/rust-lang/rust/issues/70509) was related to another unstable feature named `repr128` and is resolved. ### Previous PRs The [implementation PR](https://github.com/rust-lang/rust/pull/60732) added documentation to the Unstable Book, https://github.com/rust-lang/reference/pull/1055 was opened as a continuation of https://github.com/rust-lang/reference/pull/639. ### Resolution of unresolved questions The questions are resolved in https://github.com/rust-lang/rust/issues/60553#issuecomment-511235271. ---- (someone please add `needs-fcp`)
2021-08-12Rollup merge of #87885 - m-ou-se:edition-guide-links, r=rylevGuillaume Gomez-16/+16
Link to edition guide instead of issues for 2021 lints. This changes the 2021 lints to not link to github issues, but to the edition guide instead. Fixes #86996
2021-08-11Modify structured suggestion outputEsteban Küber-225/+227
* On suggestions that include deletions, use a diff inspired output format * When suggesting addition, use `+` as underline * Color highlight modified span
2021-08-09Link to edition guide instead of issues for 2021 lints.Mara Bos-16/+16
2021-08-08Auto merge of #87235 - poliorcetics:issue-87217-fn-quali-order, r=nagisabors-0/+132
Improve diagnostics for wrongly ordered keywords in function declaration Fix #87217 `@rustbot` label A-diagnostics T-compiler
2021-08-04Auto merge of #86197 - FabianWolff:trailing-whitespace, r=JohnTitorbors-1/+1
Remove unnecessary trailing whitespace from error messages Some error messages currently contain unnecessary trailing whitespace. There are some legitimate reasons for having trailing whitespace in the output, such as for uniform indentation of possibly-empty input lines, but the whitespace I have addressed here occurs in a line used only for spacing, and I see no reason why that should have trailing whitespace (spacing lines inserted in other places also don't have trailing whitespace). I have also removed a superfluous call to `buffer.putc()`, which has no effect because the same character is already placed there by `draw_col_separator()`. Use `git diff --ignore-space-at-eol` to see my changes; otherwise the diff is quite large due to the whitespace removed from expected outputs in `src/test/ui/`.
2021-08-04Remove trailing whitespace from error messagesFabian Wolff-1/+1
2021-08-04Auto merge of #87026 - FabianWolff:issue-86948, r=estebankbors-17/+67
Allow labeled loops as value expressions for `break` Fixes #86948. This is currently allowed: ```rust return 'label: loop { break 'label 42; }; break ('label: loop { break 'label 42; }); break 1 + 'label: loop { break 'label 42; }; break 'outer 'inner: loop { break 'inner 42; }; ``` But not this: ```rust break 'label: loop { break 'label 42; }; ``` I have fixed this, so that the above now parses as an unlabeled break with a labeled loop as its value expression.
2021-08-03Use a multipart suggestion for the parenthesesFabian Wolff-3/+5
2021-08-03Rollup merge of #87646 - JohnTitor:fix-parser-ice, r=oli-obkYuki Okushi-0/+28
Fix a parser ICE on invalid `fn` body Fixes #87635 A better fix would add a check for `fn` body on `expected_one_of_not_found` but I haven't come up with a graceful way. Any idea? r? ```@oli-obk``` ```@estebank```
2021-08-02Rollup merge of #87659 - FabianWolff:issue-87397, r=davidtwcoCameron Steffen-8/+12
Fix invalid suggestions for non-ASCII characters in byte constants Fixes #87397.
2021-08-02Better message for invalid keyword placement in fnAlexis Bourget-0/+132
After this commit, `unsafe async fn ...` now suggests the `async unsafe` fix instead of misunderstanding the issue. This is not perfect for repeated keywords (`const async const`) and for keywords that are misplaced after `extern "some abi"` because of the way `check_fn_font_matter` works, but changing it breaks so many tests and diagnostics it has been judged too high a cost for this PR.
2021-07-31Require parentheses to avoid confusions around labeled break and loop ↵Fabian Wolff-17/+65
expressions
2021-07-31Fix invalid suggestions for non-ASCII characters in byte constantsFabian Wolff-8/+12
2021-07-31Fix a parser ICE on invalid `fn` bodyYuki Okushi-0/+28
2021-07-30Use multispan suggestions more oftenEsteban Küber-14/+29
* Use more accurate span for `async move` suggestion * Use more accurate span for deref suggestion * Use `multipart_suggestion` more often
2021-07-28Stabilize `arbitrary_enum_discriminant`Deadbeef-59/+0
2021-07-27Auto merge of #83484 - JulianKnodt:infer, r=oli-obk,lcnrbors-3/+16
Add hir::GenericArg::Infer In order to extend inference to consts, make an Infer type on hir::GenericArg.
2021-07-26Actually infer args in visitorskadmin-3/+16
2021-07-26Rollup merge of #87436 - ebobrow:suggest-semicolon, r=oli-obkGuillaume Gomez-7/+61
Suggest `;` on parse error where applicable fixes #87197
2021-07-25Add generic arg inferkadmin-2/+2
2021-07-24fix code to suggest `;` on parse errorElliot Bobrow-7/+61
2021-07-19Auto merge of #87225 - estebank:cleanup, r=oli-obkbors-1/+5
Various diagnostics clean ups/tweaks * Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-07-19Various diagnostics clean ups/tweaksEsteban Küber-1/+5
* Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-07-18Auto merge of #87071 - inquisitivecrystal:inclusive-range, r=estebankbors-0/+20
Add diagnostics for mistyped inclusive range Inclusive ranges are correctly typed as `..=`. However, it's quite easy to think of it as being like `==`, and type `..==` instead. This PR adds helpful diagnostics for this case. Resolves #86395 (there are some other cases there, but I think those should probably have separate issues). r? `@estebank`
2021-07-17Auto merge of #86761 - Alexhuszagh:master, r=estebankbors-0/+9
Update Rust Float-Parsing Algorithms to use the Eisel-Lemire algorithm. # Summary Rust, although it implements a correct float parser, has major performance issues in float parsing. Even for common floats, the performance can be 3-10x [slower](https://arxiv.org/pdf/2101.11408.pdf) than external libraries such as [lexical](https://github.com/Alexhuszagh/rust-lexical) and [fast-float-rust](https://github.com/aldanor/fast-float-rust). Recently, major advances in float-parsing algorithms have been developed by Daniel Lemire, along with others, and implement a fast, performant, and correct float parser, with speeds up to 1200 MiB/s on Apple's M1 architecture for the [canada](https://github.com/lemire/simple_fastfloat_benchmark/blob/0e2b5d163d4074cc0bde2acdaae78546d6e5c5f1/data/canada.txt) dataset, 10x faster than Rust's 130 MiB/s. In addition, [edge-cases](https://github.com/rust-lang/rust/issues/85234) in Rust's [dec2flt](https://github.com/rust-lang/rust/tree/868c702d0c9a471a28fb55f0148eb1e3e8b1dcc5/library/core/src/num/dec2flt) algorithm can lead to over a 1600x slowdown relative to efficient algorithms. This is due to the use of Clinger's correct, but slow [AlgorithmM and Bellepheron](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.45.4152&rep=rep1&type=pdf), which have been improved by faster big-integer algorithms and the Eisel-Lemire algorithm, respectively. Finally, this algorithm provides substantial improvements in the number of floats the Rust core library can parse. Denormal floats with a large number of digits cannot be parsed, due to use of the `Big32x40`, which simply does not have enough digits to round a float correctly. Using a custom decimal class, with much simpler logic, we can parse all valid decimal strings of any digit count. ```rust // Issue in Rust's dec2fly. "2.47032822920623272088284396434110686182e-324".parse::<f64>(); // Err(ParseFloatError { kind: Invalid }) ``` # Solution This pull request implements the Eisel-Lemire algorithm, modified from [fast-float-rust](https://github.com/aldanor/fast-float-rust) (which is licensed under Apache 2.0/MIT), along with numerous modifications to make it more amenable to inclusion in the Rust core library. The following describes both features in fast-float-rust and improvements in fast-float-rust for inclusion in core. **Documentation** Extensive documentation has been added to ensure the code base may be maintained by others, which explains the algorithms as well as various associated constants and routines. For example, two seemingly magical constants include documentation to describe how they were derived as follows: ```rust // Round-to-even only happens for negative values of q // when q ≥ −4 in the 64-bit case and when q ≥ −17 in // the 32-bitcase. // // When q ≥ 0,we have that 5^q ≤ 2m+1. In the 64-bit case,we // have 5^q ≤ 2m+1 ≤ 2^54 or q ≤ 23. In the 32-bit case,we have // 5^q ≤ 2m+1 ≤ 2^25 or q ≤ 10. // // When q < 0, we have w ≥ (2m+1)×5^−q. We must have that w < 2^64 // so (2m+1)×5^−q < 2^64. We have that 2m+1 > 2^53 (64-bit case) // or 2m+1 > 2^24 (32-bit case). Hence,we must have 2^53×5^−q < 2^64 // (64-bit) and 2^24×5^−q < 2^64 (32-bit). Hence we have 5^−q < 2^11 // or q ≥ −4 (64-bit case) and 5^−q < 2^40 or q ≥ −17 (32-bitcase). // // Thus we have that we only need to round ties to even when // we have that q ∈ [−4,23](in the 64-bit case) or q∈[−17,10] // (in the 32-bit case). In both cases,the power of five(5^|q|) // fits in a 64-bit word. const MIN_EXPONENT_ROUND_TO_EVEN: i32; const MAX_EXPONENT_ROUND_TO_EVEN: i32; ``` This ensures maintainability of the code base. **Improvements for Disguised Fast-Path Cases** The fast path in float parsing algorithms attempts to use native, machine floats to represent both the significant digits and the exponent, which is only possible if both can be exactly represented without rounding. In practice, this means that the significant digits must be 53-bits or less and the then exponent must be in the range `[-22, 22]` (for an f64). This is similar to the existing dec2flt implementation. However, disguised fast-path cases exist, where there are few significant digits and an exponent above the valid range, such as `1.23e25`. In this case, powers-of-10 may be shifted from the exponent to the significant digits, discussed at length in https://github.com/rust-lang/rust/issues/85198. **Digit Parsing Improvements** Typically, integers are parsed from string 1-at-a-time, requiring unnecessary multiplications which can slow down parsing. An approach to parse 8 digits at a time using only 3 multiplications is described in length [here](https://johnnylee-sde.github.io/Fast-numeric-string-to-int/). This leads to significant performance improvements, and is implemented for both big and little-endian systems. **Unsafe Changes** Relative to fast-float-rust, this library makes less use of unsafe functionality and clearly documents it. This includes the refactoring and documentation of numerous unsafe methods undesirably marked as safe. The original code would look something like this, which is deceptively marked as safe for unsafe functionality. ```rust impl AsciiStr { #[inline] pub fn step_by(&mut self, n: usize) -> &mut Self { unsafe { self.ptr = self.ptr.add(n) }; self } } ... #[inline] fn parse_scientific(s: &mut AsciiStr<'_>) -> i64 { // the first character is 'e'/'E' and scientific mode is enabled let start = *s; s.step(); ... } ``` The new code clearly documents safety concerns, and does not mark unsafe functionality as safe, leading to better safety guarantees. ```rust impl AsciiStr { /// Advance the view by n, advancing it in-place to (n..). pub unsafe fn step_by(&mut self, n: usize) -> &mut Self { // SAFETY: same as step_by, safe as long n is less than the buffer length self.ptr = unsafe { self.ptr.add(n) }; self } } ... /// Parse the scientific notation component of a float. fn parse_scientific(s: &mut AsciiStr<'_>) -> i64 { let start = *s; // SAFETY: the first character is 'e'/'E' and scientific mode is enabled unsafe { s.step(); } ... } ``` This allows us to trivially demonstrate the new implementation of dec2flt is safe. **Inline Annotations Have Been Removed** In the previous implementation of dec2flt, inline annotations exist practically nowhere in the entire module. Therefore, these annotations have been removed, which mostly does not impact [performance](https://github.com/aldanor/fast-float-rust/issues/15#issuecomment-864485157). **Fixed Correctness Tests** Numerous compile errors in `src/etc/test-float-parse` were present, due to deprecation of `time.clock()`, as well as the crate dependencies with `rand`. The tests have therefore been reworked as a [crate](https://github.com/Alexhuszagh/rust/tree/master/src/etc/test-float-parse), and any errors in `runtests.py` have been patched. **Undefined Behavior** An implementation of `check_len` which relied on undefined behavior (in fast-float-rust) has been refactored, to ensure that the behavior is well-defined. The original code is as follows: ```rust #[inline] pub fn check_len(&self, n: usize) -> bool { unsafe { self.ptr.add(n) <= self.end } } ``` And the new implementation is as follows: ```rust /// Check if the slice at least `n` length. fn check_len(&self, n: usize) -> bool { n <= self.as_ref().len() } ``` Note that this has since been fixed in [fast-float-rust](https://github.com/aldanor/fast-float-rust/pull/29). **Inferring Binary Exponents** Rather than explicitly store binary exponents, this new implementation infers them from the decimal exponent, reducing the amount of static storage required. This removes the requirement to store [611 i16s](https://github.com/rust-lang/rust/blob/868c702d0c9a471a28fb55f0148eb1e3e8b1dcc5/library/core/src/num/dec2flt/table.rs#L8). # Code Size The code size, for all optimizations, does not considerably change relative to before for stripped builds, however it is **significantly** smaller prior to stripping the resulting binaries. These binary sizes were calculated on x86_64-unknown-linux-gnu. **new** Using rustc version 1.55.0-dev. opt-level|size|size(stripped) |:-:|:-:|:-:| 0|400k|300K 1|396k|292K 2|392k|292K 3|392k|296K s|396k|292K z|396k|292K **old** Using rustc version 1.53.0-nightly. opt-level|size|size(stripped) |:-:|:-:|:-:| 0|3.2M|304K 1|3.2M|292K 2|3.1M|284K 3|3.1M|284K s|3.1M|284K z|3.1M|284K # Correctness The dec2flt implementation passes all of Rust's unittests and comprehensive float parsing tests, along with numerous other tests such as Nigel Toa's comprehensive float [tests](https://github.com/nigeltao/parse-number-fxx-test-data) and Hrvoje Abraham [strtod_tests](https://github.com/ahrvoje/numerics/blob/master/strtod/strtod_tests.toml). Therefore, it is unlikely that this algorithm will incorrectly round parsed floats. # Issues Addressed This will fix and close the following issues: - resolves #85198 - resolves #85214 - resolves #85234 - fixes #31407 - fixes #31109 - fixes #53015 - resolves #68396 - closes https://github.com/aldanor/fast-float-rust/issues/15
2021-07-17Changed dec2flt to use the Eisel-Lemire algorithm.Alex Huszagh-0/+9
Implementation is based off fast-float-rust, with a few notable changes. - Some unsafe methods have been removed. - Safe methods with inherently unsafe functionality have been removed. - All unsafe functionality is documented and provably safe. - Extensive documentation has been added for simpler maintenance. - Inline annotations on internal routines has been removed. - Fixed Python errors in src/etc/test-float-parse/runtests.py. - Updated test-float-parse to be a library, to avoid missing rand dependency. - Added regression tests for #31109 and #31407 in core tests. - Added regression tests for #31109 and #31407 in ui tests. - Use the existing slice primitive to simplify shared dec2flt methods - Remove Miri ignores from dec2flt, due to faster parsing times. - resolves #85198 - resolves #85214 - resolves #85234 - fixes #31407 - fixes #31109 - fixes #53015 - resolves #68396 - closes https://github.com/aldanor/fast-float-rust/issues/15
2021-07-16Make GATs no longer incompleteJack Huey-21/+11
2021-07-14Suggest a path separator if a stray colon is found in a match armFabian Wolff-0/+134
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2021-07-11Add diagnostics test for mistyped inclusive rangesinquisitivecrystal-0/+20
2021-07-08Rollup merge of #86932 - rylev:fix-ice-86895, r=estebankYuki Okushi-0/+11
Fix ICE when misplaced visibility cannot be properly parsed Fixes #86895 The issue was that a failure to parse the visibility was causing the original error to be dropped before being emitted. The resulting error isn't quite as nice as when the visibility is parsed properly, but I'm not sure which error to prioritize here. Displaying both errors might be too confusing. r? ```@estebank```
2021-07-07Fix ICE when misplaced visibility cannot be properly parsedRyan Levick-0/+11
2021-07-02Recover from `&dyn mut ...` parse errorsFabian Wolff-0/+24
2021-06-30Move some UI tests to more suitable subdirsYuki Okushi-0/+193
2021-06-26Auto merge of #86586 - Smittyvb:https-everywhere, r=petrochenkovbors-1/+1
Use HTTPS links where possible While looking at #86583, I wondered how many other (insecure) HTTP links were in `rustc`. This changes most other `http` links to `https`. While most of the links are in comments or documentation, there are a few other HTTP links that are used by CI that are changed to HTTPS. Notes: - I didn't change any to or in licences - Some links don't support HTTPS :( - Some `http` links were dead, in those cases I upgraded them to their new places (all of which used HTTPS)
2021-06-25Address PR feedbackRyan Levick-32/+32
2021-06-25Change how edition based future compatibility warnings are handledRyan Levick-32/+32
2021-06-23Use HTTPS links where possibleSmitty-1/+1
2021-06-22Auto merge of #85193 - pnkfelix:readd-support-for-inner-attrs-within-match, ↵bors-10/+2
r=nikomatsakis Re-add support for parsing (and pretty-printing) inner-attributes in match body Re-add support for parsing (and pretty-printing) inner-attributes within body of a `match`. In other words, we can do `match EXPR { #![inner_attr] ARM_1 ARM_2 ... }` again. I believe this unbreaks the only four crates that crater flagged as broken by PR #83312. (I am putting this up so that the lang-team can check it out and decide whether it changes their mind about what to do regarding PR #83312.)
2021-06-20Update rustfix for compiletest.Eric Huss-9/+11