summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/ty.rs
AgeCommit message (Collapse)AuthorLines
2023-02-14Do not eagerly recover for bad impl-trait in macrosMichael Goulet-2/+3
2023-01-16fix dropping diagnostic without emitEzra Shaw-1/+2
2023-01-15make error emitted on `impl &Trait` nicerEzra Shaw-4/+35
2022-12-29Auto merge of #106266 - matthiaskrgr:rollup-cxrdbzy, r=matthiaskrgrbors-2/+93
Rollup of 9 pull requests Successful merges: - #104531 (Provide a better error and a suggestion for `Fn` traits with lifetime params) - #105899 (`./x doc library --open` opens `std`) - #106190 (Account for multiple multiline spans with empty padding) - #106202 (Trim more paths in obligation types) - #106234 (rustdoc: simplify settings, help, and copy button CSS by not reusing) - #106236 (docs/test: add docs and a UI test for `E0514` and `E0519`) - #106259 (Update Clippy) - #106260 (Fix index out of bounds issues in rustdoc) - #106263 (Formatter should not try to format non-Rust files) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-12-29Rollup merge of #106221 - Nilstrieb:rptr-more-like-ref-actually, ↵Matthias Krüger-1/+1
r=compiler-errors Rename `Rptr` to `Ref` in AST and HIR The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
2022-12-29Provide a better error for `Fn` traits with lifetime paramsYutaro Ohno-2/+93
Currently, given `Fn`-family traits with lifetime params like `Fn<'a>(&'a str) -> bool`, many unhelpful errors show up. These are a bit confusing. This commit allows these situations to suggest simply using higher-ranked trait bounds like `for<'a> Fn(&'a str) -> bool`.
2022-12-28Rename `Rptr` to `Ref` in AST and HIRNilstrieb-1/+1
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already as well.
2022-12-28Rollup merge of #106176 - compiler-errors:fn-kw-as-fn-trait, r=estebankMatthias Krüger-3/+45
Recover `fn` keyword as `Fn` trait in bounds `impl fn()` -> `impl Fn()` Fixes #82515
2022-12-27Recover `fn` keyword as `Fn` trait in boundsMichael Goulet-3/+45
2022-12-13error parsing lifetime following by Sized and message + between themYiming Lei-0/+19
detect the pattern at the general site parse_impl_ty() this will fix #102598
2022-11-23Auto merge of #104410 - WaffleLapkin:unregress, r=estebankbors-1/+1
Fix perf regression by correctly matching keywords This should (hopefully) fix regression from #99918 r? `@estebank`
2022-11-22Split `MacArgs` in two.Nicholas Nethercote-1/+1
`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's used in two ways: - For representing attribute macro arguments (e.g. in `AttrItem`), where all three variants are used. - For representing function-like macros (e.g. in `MacCall` and `MacroDef`), where only the `Delimited` variant is used. In other words, `MacArgs` is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using `MacArgs::Empty` in a `MacCall`). This commit splits `MacArgs` in two: - `DelimArgs` is a new struct just for the "delimited arguments" case. It is now used in `MacCall` and `MacroDef`. - `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro case. Its `Delimited` variant now contains a `DelimArgs`. Various other related things are renamed as well. These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values.
2022-11-16Fix perf regression by correctly matching keywordsMaybe Waffle-1/+1
2022-11-11Recover from fn ptr tys with generic param listLeón Orell Valerian Liehr-3/+55
2022-11-11Auto merge of #99918 - WaffleLapkin:fnFnfun, r=estebankbors-2/+3
Recover wrong-cased keywords that start items (_this pr was inspired by [this tweet](https://twitter.com/Azumanga/status/1552982326409367561)_) r? `@estebank` We've talked a bit about this recovery, but I just wanted to make sure that this is the right approach :) For now I've only added the case insensitive recovery to `use`s, since most other items like `impl` blocks, modules, functions can start with multiple keywords which complicates the matter.
2022-11-09Make span_suggestions take IntoIteratorMichael Goulet-1/+1
2022-10-01Replace some `bool` params with an enumMaybe Waffle-2/+3
2022-10-01Recover wrong cased keywords starting functionsMaybe Waffle-2/+2
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