about summary refs log tree commit diff
path: root/src/libsyntax/parse
AgeCommit message (Collapse)AuthorLines
2018-01-14syntax: Rewrite parsing of implsVadim Petrochenkov-154/+125
Properly parse impls for the never type `!` Recover from missing `for` in `impl Trait for Type` Prohibit inherent default impls and default impls of auto traits Change wording in more diagnostics to use "auto traits" Some minor code cleanups in the parser
2018-01-13Re-add support for `impl Trait for ..` to the parserVadim Petrochenkov-1/+5
2018-01-13Address review.leonardo.yvens-4/+4
2018-01-13Parse `auto trait` inside fns.leonardo.yvens-12/+16
Also refactored parsing auto traits.
2018-01-13Remove `impl Foo for ..` in favor of `auto trait Foo`leonardo.yvens-38/+19
No longer parse it. Remove AutoTrait variant from AST and HIR. Remove backwards compatibility lint. Remove coherence checks, they make no sense for the new syntax. Remove from rustdoc.
2018-01-13Auto merge of #47242 - estebank:issue-15980, r=petrochenkovbors-11/+42
`struct` pattern parsing and diagnostic tweaks - Recover from struct parse error on match and point out missing match body. - Point at struct when finding non-identifier while parsing its fields. - Add label to "expected identifier, found {}" error. Fix #15980.
2018-01-13Rollup merge of #47298 - cramertj:path-as-modrs, r=nikomatsakiskennytm-4/+8
Treat #[path] files as mod.rs files Fixes https://github.com/rust-lang/rust/issues/46936, cc @briansmith, @SergioBenitez, @nikomatsakis. This (insta-stable) change treats files included via `#[path = "bla.rs"] mod foo;` as though they were `mod.rs` files. Namely, it allows them to include `mod` statements and looks for the child modules in sibling directories, rather than in relative `modname/childmodule.rs` files as happens for non-`mod.rs` files. This change makes the `non_modrs_mods` feature backwards compatible with the existing usage in https://github.com/briansmith/ring, several versions of which are currently broken in beta. If we decide to merge, this change should be backported to beta. cc https://github.com/rust-lang/rust/issues/37872 r? @jseyfried
2018-01-09Treat #[path] files as mod.rs filesTaylor Cramer-4/+8
2018-01-09Rollup merge of #47210 - ↵kennytm-1/+1
zackmdavis:the_3rd_of_2_hardest_problems_in_computer_science, r=QuietMisdreavus fix the doc-comment-decoration-trimming edge-case rustdoc ICE This `horizontal_trim` function strips the leading whitespace from doc-comments that have a left-asterisk-margin: ``` /** * You know what I mean— * * comments like this! */ ``` The index of the column of asterisks is `i`, and if trimming is deemed possible, we slice each line from `i+1` to the end of the line. But if, in particular, `i` was 0 _and_ there was an empty line (as in the example given in the reporting issue), we ended up panicking trying to slice an empty string from 0+1 (== 1). Let's tighten our check to say that we can't trim when `i` is even the same as the length of the line, not just when it's greater. (Any such cases would panic trying to slice `line` from `line.len()+1`.) Resolves #47197.
2018-01-08Auto merge of #47232 - keatinge:master, r=petrochenkovbors-2/+14
Add help message for incorrect pattern syntax When I was getting started with rust I often made the mistake of using `||` instead of `|` to match multiple patterns and spent a long time staring at my code wondering what was wrong. for example: ``` fn main() { let x = 1; match x { 1 || 2 => println!("1 or 2"), _ => println!("Something else"), } } ``` If you compile this with current rustc you will see ``` error: expected one of `...`, `..=`, `..`, `=>`, `if`, or `|`, found `||` --> test.rs:5:11 | 5 | 1 || 2 => println!("1 or 2"), | -^^ unexpected token | | | expected one of `...`, `..=`, `..`, `=>`, `if`, or `|` here error: aborting due to previous error ``` With my proposed change it will show: ``` error: unexpected token `||` after pattern --> test.rs:5:11 | 5 | 1 || 2 => println!("1 or 2"), | ^^ | = help: did you mean to use `|` to specify multiple patterns instead? error: aborting due to previous error ```
2018-01-07`struct` pattern parsing and diagnostic tweaksEsteban Küber-11/+42
- Recover from struct parse error on match and point out missing match body. - Point at struct when finding non-identifier while parsing its fields. - Add label to "expected identifier, found {}" error.
2018-01-07Auto merge of #47156 - petrochenkov:extpath, r=nikomatsakisbors-4/+12
Support `extern` in paths Implement the primary alternative to https://github.com/rust-lang/rust/pull/46613 + https://github.com/rust-lang/rust/pull/45771, achieving the same effect without requiring changes to other imports. Both need to be experimentally evaluated before making further progress. The PR also adds docs for all these related features into the unstable book. cc https://github.com/rust-lang/rust/issues/44660 r? @nikomatsakis
2018-01-06Fix tidy errorkeatinge-2/+5
2018-01-06Use span_suggestion instead of span_err_helpkeatinge-3/+3
2018-01-06wherein careful doc-decoration arithmetic proves quite the ICE-breakerZack M. Davis-1/+1
This `horizontal_trim` function strips the leading whitespace from doc-comments that have a left-asterisk-margin: /** * You know what I mean— * * comments like this! */ The index of the column of asterisks is `i`, and if trimming is deemed possible, we slice each line from `i+1` to the end of the line. But if, in particular, `i` was 0 _and_ there was an empty line (as in the example given in the reporting issue), we ended up panicking trying to slice an empty string from 0+1 (== 1). Let's tighten our check to say that we can't trim when `i` is even the same as the length of the line, not just when it's greater. (Any such cases would panic trying to slice `line` from `line.len()+1`.) Resolves #47197.
2018-01-06fix stylekeatinge-4/+2
2018-01-06Emit non-fatal error insteadkeatinge-8/+10
2018-01-06fix capitalizationkeatinge-2/+2
2018-01-06Add help message for incorrect pattern syntaxkeatinge-1/+10
2018-01-04rustc: use {U,I}size instead of {U,I}s shorthands.Eduard-Mihai Burtescu-2/+2
2018-01-03Support `extern` in pathsVadim Petrochenkov-4/+12
2018-01-01Auto merge of #46895 - ricochet1k:macro-lifetimes, r=jseyfriedbors-13/+33
Allow lifetimes in macros This is a resurrection of PR #41927 which was a resurrection of #33135, which is intended to fix #34303. In short, this allows macros_rules! to use :lifetime as a matcher to match 'lifetimes. Still to do: - [x] Feature gate
2017-12-30in which leading zeroes on tuple-struct accesses are abjuredZack M. Davis-3/+12
Resolves #47073.
2017-12-30refactor lifetime out of is_lifetimeMatt Peterson-19/+20
2017-12-28CleanupMatt Peterson-4/+3
2017-12-28Fix testsMatt Peterson-9/+27
2017-12-28replace parse_lifetime with expect_lifetimeMichael Hewson-1/+1
made `parser::Parser::expect_lifetime` public, so it can be called from `macro_parser::parse_nt`
2017-12-28Resurrecting #33135Michael Hewson-0/+2
Started rebasing @sgrif's PR #33135 off of current master. (Well, actually merging it into a new branch based off current master.) The following files still need to be fixed or at least reviewed: - `src/libsyntax/ext/tt/macro_parser.rs`: calls `Parser::parse_lifetime`, which doesn't exist anymore - `src/libsyntax/parse/parser.rs`: @sgrif added an error message to `Parser::parse_lifetime`. Code has since been refactored, so I just took it out for now. - `src/libsyntax/ext/tt/transcribe.rs`: This code has been refactored bigtime. Not sure whether @sgrif's changes here are still necessary. Took it out for this commit.
2017-12-22Auto merge of #46732 - estebank:silence-recovered-blocks, r=petrochenkovbors-2/+6
Do not emit type errors on recovered blocks When a parse error occurs on a block, the parser will recover and create a block with the statements collected until that point. Now a flag stating that a recovery has been performed in this block is propagated so that the type checker knows that the type of the block (which will be identified as `()`) shouldn't be checked against the expectation to reduce the amount of irrelevant diagnostic errors shown to the user. Fix #44579.
2017-12-21Do not emit type errors on recovered blocksEsteban Küber-2/+6
When a parse error occurs on a block, the parser will recover and create a block with the statements collected until that point. Now a flag stating that a recovery has been performed in this block is propagated so that the type checker knows that the type of the block (which will be identified as `()`) shouldn't be checked against the expectation to reduce the amount of irrelevant diagnostic errors shown to the user.
2017-12-21Auto merge of #45930 - jplatte:generics_refactoring, r=eddybbors-24/+30
Generics refactoring (groundwork for const generics) These changes were suggested by @eddyb. After this change, the `Generics` contain one `Vec` of an enum for the generic parameters, rather than two separate `Vec`s for lifetime and type parameters. Type params and const params will need to be in a shared `Vec` to preserve their ordering, and moving lifetimes into the same `Vec` should simplify the code that processes `Generics`.
2017-12-21Add GenericParam, refactor Generics in ast, hir, rustdocJonas Platte-24/+30
The Generics now contain one Vec of an enum for the generic parameters, rather than two separate Vec's for lifetime and type parameters. Additionally, places that previously used Vec<LifetimeDef> now use Vec<GenericParam> instead.
2017-12-21Rollup merge of #46827 - petrochenkov:assocrecov2, r=estebankGuillaume Gomez-11/+51
syntax: Follow-up to the incorrect qpath recovery PR cc https://github.com/rust-lang/rust/pull/46788 Add tests checking that "priority" of qpath recovery is higher than priority of unary and binary operators Fix regressed parsing of paths with fn-like generic arguments r? @estebank
2017-12-21Auto merge of #46531 - cramertj:no-mo-modrs, r=nikomatsakisbors-43/+99
Implement non-mod.rs mod statements Fixes https://github.com/rust-lang/rust/issues/45385, cc https://github.com/rust-lang/rust/issues/44660 This will fail tidy right now because it doesn't recognize my UI tests as feature-gate tests. However, I'm not sure if compile-fail will work out either because compile-fail usually requires there to be error patterns in the top-level file, which isn't possible with this feature. What's the recommended way to handle this?
2017-12-20Fix parsing of paths with fn-like generic argumentsVadim Petrochenkov-9/+11
2017-12-20Move impls for qpath recovery trait from `ast.rs`Vadim Petrochenkov-2/+40
2017-12-19Implement non-mod.rs mod statementsTaylor Cramer-43/+99
2017-12-19Remove a token after closing delimiter from the span of macro in type positiontopecongiro-1/+1
2017-12-17syntax: recovery for incorrect associated item paths like `[T; N]::clone`Vadim Petrochenkov-20/+50
2017-12-17syntax: Rename `P::unwrap` into `P::into_inner`Vadim Petrochenkov-2/+2
2017-12-16in which `..` is suggested for erroneous `...` in struct field patternsZack M. Davis-1/+13
Resolves #46718.
2017-12-14When attempting to write str with single quote suggest double quotesEsteban Küber-1/+27
2017-12-14add trait aliases to ASTAlex Burka-14/+25
2017-12-14Use PathBuf instead of String where applicableOliver Schneider-32/+36
2017-12-09Use Try syntax for Option in place of macros or matchMatt Brubeck-4/+1
2017-12-07Auto merge of #46497 - AgustinCB:issue-46311, r=petrochenkovbors-13/+1
Modify message for keyword as identifier name This is a temporary solution to #46311. The message is generic enough to cover both cases and is probably a fine enough solution to the specific problem described in the task. However, the underlying reason for this to be wrong is that `next_token_inner` returns `Lifetime` even if the token is a label. That's not simple, as the syntax for both can be quite similar and it may need to take a look to the next token to make a decision. I'm not sure I have enough knowledge about the project to be able to solve that (yet!), so I thought I'll fix the immediate problem first.
2017-12-07address commentsAgustin Chiappe Berrini-3/+9
2017-12-07Auto merge of #46187 - notriddle:patch-1, r=QuietMisdreavusbors-1/+1
Rename C-like enum to Field-less enum There is no need to reference the C programming language to explain this concept.
2017-12-06and refactor to just move the checkingAgustin Chiappe Berrini-21/+3
2017-12-02Auto merge of #46381 - estebank:expected-span, r=nikomatsakisbors-5/+22
Point to next token when it is in the expected line r? @nikomatsakis