summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/ty.rs
AgeCommit message (Collapse)AuthorLines
2022-09-27Structured suggestion for missing mut/const in pointerMichael Goulet-4/+7
2022-09-13Address code review commentsEric Holk-3/+1
2022-09-12Introduce dyn_star feature flagEric Holk-2/+13
The primary purpose of this commit is to introduce the dyn_star flag so we can begin experimenting with implementation. In order to have something to do in the feature gate test, we also add parser support for `dyn* Trait` objects. These are currently treated just like `dyn Trait` objects, but this will change in the future. Note that for now `dyn* Trait` is experimental syntax to enable implementing some of the machinery needed for async fn in dyn traits without fully supporting the feature.
2022-08-22Rollup merge of #99915 - WaffleLapkin:recover_keyword_bounds, r=compiler-errorsDylan DPC-1/+21
Recover keywords in trait bounds (_this pr was inspired by [this tweet](https://twitter.com/Azumanga/status/1552982326409367561)_) Recover keywords in trait bound, motivational example: ```rust fn f(_: impl fn()) {} // mistyped, meant `Fn` ``` <details><summary>Current nightly (3 needless and confusing errors!)</summary> <p> ```text error: expected identifier, found keyword `fn` --> ./t.rs:1:15 | 1 | fn _f(_: impl fn()) {} | ^^ expected identifier, found keyword | help: escape `fn` to use it as an identifier | 1 | fn _f(_: impl r#fn()) {} | ++ error: expected one of `:` or `|`, found `)` --> ./t.rs:1:19 | 1 | fn _f(_: impl fn()) {} | ^ expected one of `:` or `|` error: expected one of `!`, `(`, `)`, `,`, `?`, `for`, `~`, lifetime, or path, found keyword `fn` --> ./t.rs:1:15 | 1 | fn _f(_: impl fn()) {} | -^^ expected one of 9 possible tokens | | | help: missing `,` error: at least one trait must be specified --> ./t.rs:1:10 | 1 | fn _f(_: impl fn()) {} | ^^^^ ``` </p> </details> This PR: ```text error: expected identifier, found keyword `fn` --> ./t.rs:1:15 | 1 | fn _f(_: impl fn()) {} | ^^ expected identifier, found keyword | help: escape `fn` to use it as an identifier | 1 | fn _f(_: impl r#fn()) {} | ++ error[E0405]: cannot find trait `r#fn` in this scope --> ./t.rs:1:15 | 1 | fn _f(_: impl fn()) {} | ^^ help: a trait with a similar name exists (notice the capitalization): `Fn` | ::: /home/waffle/projects/repos/rust/library/core/src/ops/function.rs:74:1 | 74 | pub trait Fn<Args>: FnMut<Args> { | ------------------------------- similarly named trait `Fn` defined here ``` It would be nice to have suggestion in the first error like "have you meant `Fn` trait", instead of a separate error, but the recovery is deep inside ident parsing, which makes it a lot harder to do. r? `@compiler-errors`
2022-08-21recover `const Tr` bounds (no `~`)Maybe Waffle-0/+14
2022-08-17Box the `MacCall` in various types.Nicholas Nethercote-2/+2
2022-07-29Recover keywords in boundsMaybe Waffle-1/+7
For example, this fixes a error for `impl fn()` (notice the capitalization)
2022-06-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-4/+4
2022-06-02Rollup merge of #97166 - nnethercote:move-conditions-out, r=estebankYuki Okushi-5/+10
Move conditions out of recover/report functions. `Parser` has six recover/report functions that are passed a boolean, and nothing is done if the boolean has a particular value. This PR moves the tests outside the functions. This has the following effects. - The number of lines of code goes down. - Some `use` items become shorter. - Avoids the strangeness whereby 11 out of 12 calls to `maybe_recover_from_bad_qpath` pass `true` as the second argument. - Makes it clear at the call site that only one of `maybe_recover_from_bad_type_plus` and `maybe_report_ambiguous_plus` will be run. r? `@estebank`
2022-05-20Introduce BareFnTy::decl_span and fix generics span.Camille GILLOT-1/+3
2022-05-19Move condition out of `maybe_report_ambiguous_plus` and ↵Nicholas Nethercote-2/+5
`maybe_recover_from_bad_type_plus`.
2022-05-19Move condition out of `maybe_recover_from_question_mark`.Nicholas Nethercote-2/+4
2022-05-19Move condition out of `maybe_recover_from_bad_qpath`.Nicholas Nethercote-1/+1
2022-05-02fix most compiler/ doctestsElliot Roberts-11/+11
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-14/+14
2022-03-26Stablize `const_extern_fn` for "Rust" and "C"Aaron Hill-0/+3
All other ABIs are left unstable for now. cc #64926
2022-03-04Do not recover from `Ty?` in macro parsingEsteban Kuber-11/+23
Follow up to #92746. Address #94510.
2022-02-23rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".Eduard-Mihai Burtescu-1/+2
2022-01-14Parse `Ty?` as `Option<Ty>` and provide structured suggestionEsteban Kuber-0/+26
Swift has specific syntax that desugars to `Option<T>` similar to our `?` operator, which means that people might try to use it in Rust. Parse it and gracefully recover.
2021-12-13Use Inherited Visibility instead of None when no vis is presentAlexis Bourget-1/+6
2021-12-13Change error for pub in fn decl if already presentAlexis Bourget-1/+2
2021-11-24Account for incorrect `impl Foo<const N: ty> {}` syntaxEsteban Küber-6/+32
Fix #84946
2021-10-17Some "parenthesis" and "parentheses" fixesr00ster91-1/+1
2021-09-09Revert "Implement Anonymous{Struct, Union} in the AST"Felix S. Klock II-13/+0
This reverts commit 059b68dd677808e14e560802d235ad40beeba71e. Note that this was manually adjusted to retain some of the refactoring introduced by commit 059b68dd677808e14e560802d235ad40beeba71e, so that it could likewise retain the correction introduced in commit 5b4bc05fa57be19bb5962f4b7c0f165e194e3151
2021-08-27Introduce `~const`Deadbeef-26/+20
- [x] Removed `?const` and change uses of `?const` - [x] Added `~const` to the AST. It is gated behind const_trait_impl. - [x] Validate `~const` in ast_validation. - [ ] Add enum `BoundConstness` to the HIR. (With variants `NotConst` and `ConstIfConst` allowing future extensions) - [ ] Adjust trait selection and pre-existing code to use `BoundConstness`. - [ ] Optional steps (*for this PR, obviously*) - [ ] Fix #88155 - [ ] Do something with constness bounds in chalk
2021-07-02Recover from `&dyn mut ...` parse errorsFabian Wolff-1/+21
2021-06-04Remove incorrect assertion in type parsing codeFabian Wolff-1/+0
2021-05-16Implement Anonymous{Struct, Union} in the ASTjedel1043-0/+13
Add unnamed_fields feature gate and gate unnamed fields on parsing
2021-05-03Handle incorrect placement of parentheses in trait bounds more gracefullyEsteban Küber-3/+36
Fix #84772.
2021-03-17Add pub as optional check_front_matterIvan Tham-2/+2
async-pub check created a regression for default
2021-02-27Recover from X<Y,Z> when parsing const exprÖmer Sinan Ağacan-2/+10
This adds recovery when in array type syntax user writes [X; Y<Z, ...>] instead of [X; Y::<Z, ...>] Fixes #82566 Note that whenever we parse an expression and know that the next token cannot be `,`, we should be calling check_mistyped_turbofish_with_multiple_type_params for this recovery. Previously we only did this for statement parsing (e.g. `let x = f<a, b>;`). We now also do it when parsing the length field in array type syntax.
2020-12-17Address review commentsmibac138-7/+21
2020-12-03Gracefully handle confusing -> with : in function return typemibac138-13/+65
2020-12-01Gracefully handle mistyping -> as => in function return typemibac138-0/+21
2020-10-25Tweak invalid `fn` header and body parsingEsteban Küber-1/+13
* Recover empty `fn` bodies when encountering `}` * Recover trailing `>` in return types * Recover from non-type in array type `[<BAD TOKEN>; LEN]`
2020-09-21fix typo in docs and commentsyuk1ty-1/+1
2020-09-15improve diagnostics for lifetime after `&mut`SNCPlay42-1/+27
2020-09-10Attach `TokenStream` to `ast::Ty`Aaron Hill-1/+1
A `Ty` does not have outer attributes, so we only capture tokens when parsing a `macro_rules!` matcher
2020-08-30mv compiler to compiler/mark-0/+631