Commit Graph

38 Commits

Author SHA1 Message Date
Takayuki Maeda 62ded071d5 cancel a not emitted error after parsing const generic args 2022-03-22 16:06:56 +09:00
Takayuki Maeda 9a6532276e replace self.clone() with self.create_snapshot_for_diagnostic() 2022-03-10 22:11:00 +09:00
Takayuki Maeda 2db8236857 add doc comments 2022-03-10 19:34:42 +09:00
Takayuki Maeda 3ded25204b implement SnapshotParser struct 2022-03-09 23:13:04 +09:00
Takayuki Maeda 192acb4b98 take over unclosed_delims 2022-03-09 16:04:14 +09:00
Takayuki Maeda 3514741358 remove an unnecessary comment 2022-03-09 14:10:34 +09:00
Takayuki Maeda a34015c0d0 implement and use diagnostic_snapshot 2022-03-09 13:48:40 +09:00
Takayuki Maeda 527b1f3c2f initialize unclosed_delims field 2022-03-09 12:59:46 +09:00
Takayuki Maeda 529fd2da89 suggest adding { .. } around a const function with arguments 2022-03-08 17:07:35 +09:00
Caio e3e902bb06 4 - Make more use of let_chains
Continuation of #94376.

cc #53667
2022-02-28 07:49:56 -03:00
Michael Goulet 6b52ac240a Suggest {} around more bad const generic exprs 2022-02-25 17:16:58 -08:00
Eduard-Mihai Burtescu 0b9d70cf6d rustc_errors: take self by value in DiagnosticBuilder::cancel. 2022-02-23 06:08:06 +00:00
Matthias Krüger f372476d2c Rollup merge of #91150 - dtolnay:qpath, r=davidtwco
Let qpath contain NtTy: `<$:ty as $:ty>::…`

Example:

```rust
macro_rules! m {
    (<$type:ty as $trait:ty>::$name:ident) => {
        <$type as $trait>::$name
    };
}

fn main() {
    let _: m!(<str as ToOwned>::Owned);
}
```

Previous behavior:

```console
error: expected identifier, found `ToOwned`
 --> src/main.rs:3:19
  |
3 |         <$type as $trait>::$name
  |                   ^^^^^^ expected identifier
...
8 |     let _: m!(<str as ToOwned>::Owned);
  |            ---------------------------
  |            |
  |            this macro call doesn't expand to a type
  |            in this macro invocation
```

The <code>expected identifier, found \`ToOwned\`</code> error is particularly silly. I think it should be fine to accept this code as long as $trait is of the form `TyKind::Path(None, path)`; if it is any other kind of `NtTy`, we'll keep the same behavior as before.
2022-01-18 22:00:43 +01:00
kadmin 1c1ce2fbda Add term to ExistentialProjection
Also prevent ICE when adding a const in associated const equality.
2022-01-17 20:01:22 +00:00
kadmin 67f56671d0 Use Term in ProjectionPredicate
ProjectionPredicate should be able to handle both associated types and consts so this adds the
first step of that. It mainly just pipes types all the way down, not entirely sure how to handle
consts, but hopefully that'll come with time.
2022-01-17 17:44:56 +00:00
kadmin fb57b7518d Add term
Instead of having a separate enum variant for types and consts have one but have either a const
or type.
2022-01-17 17:20:57 +00:00
kadmin 0765999622 add eq constraints on associated constants 2022-01-17 17:20:57 +00:00
David Tolnay 87a7defa8e Reject generic arguments on mod style interpolated path 2021-11-25 15:05:07 -08:00
David Tolnay 0cbb00f898 Let qpath contain NtTy: <$:ty as $:ty>::rest 2021-11-25 15:03:59 -08:00
Esteban Küber 7190bc3097 Account for incorrect impl Foo<const N: ty> {} syntax
Fix #84946
2021-11-24 20:02:09 +00:00
Michael Howell befdfb5c71 Improve error messages for bad type constraints
Co-authored-by: Esteban Kuber <esteban@kuber.com.ar>
2021-09-28 13:02:45 -07:00
Michael Howell d8e9db0dcf feat(rustc_parse): recover from pre-RFC-2000 const generics syntax
Fixes #89013
2021-09-16 15:06:31 -07:00
Fabian Wolff 6a6a605a61 Fix handling of unmatched angle brackets in parser 2021-06-05 00:31:28 +02:00
Ömer Sinan Ağacan fb631a55c2 Fix turbofish recovery with multiple generic args
check_mistyped_turbofish_with_multiple_type_params was previously
expecting type arguments between angle brackets, which is not right, as
we can also see const expressions. We now use generic argument parser
instead of type parser.

Test with one, two, and three generic arguments added to check
consistentcy between

1. check_no_chained_comparison: Called after parsing a nested binop
   application like `x < A > ...` where angle brackets are interpreted as
   binary operators and `A` is an expression.

2. check_mistyped_turbofish_with_multiple_type_params: called by
   `parse_full_stmt` when we expect to see a semicolon after parsing an
   expression but don't see it.

   (In `T2<1, 2>::C;`, the expression is `T2 < 1`)
2021-02-27 13:46:49 +03:00
Esteban Küber 2e846d6f61 Point only at generic arguments when they are unexpected 2021-01-26 15:59:43 -08:00
b-naber 728d257839 improve diagnostics for angle args 2021-01-22 17:07:27 +01:00
Patryk Wychowaniec d2f8e398f1 Rework diagnostics for wrong number of generic args 2021-01-10 13:07:40 +01:00
Julian Knodt 61f33bfd29 first pass at default values for const generics
- Adds optional default values to const generic parameters in the AST
  and HIR
- Parses these optional default values
- Adds a `const_generics_defaults` feature gate
2021-01-01 10:55:10 +01:00
Matthias Krüger d12a358673 use matches!() macro in more places 2020-12-24 13:35:12 +01:00
mibac138 3548be94c0 Gracefully handle confusing -> with : in function return type 2020-12-03 18:19:42 +01:00
mibac138 5404deeb64 Gracefully handle mistyping -> as => in function return type 2020-12-01 12:12:48 +01:00
bors cfed9184f4 Auto merge of #79266 - b-naber:gat_trait_path_parser, r=petrochenkov
Generic Associated Types in Trait Paths - Ast part

The Ast part of https://github.com/rust-lang/rust/pull/78978

r? `@petrochenkov`
2020-11-27 00:18:24 +00:00
b-naber 823dbb38e4 ast and parser 2020-11-25 19:55:41 +01:00
varkor efcbf1b00b Permit standalone generic parameters as const generic arguments in macros 2020-11-18 13:16:35 +00:00
Joshua Nelson 57c6ed0c07 Fix even more clippy warnings 2020-10-30 10:13:39 -04:00
varkor ac1454001c Suggest expressions that look like const generic arguments should be enclosed in brackets
Co-Authored-By: Esteban Kuber <github@kuber.com.ar>
2020-10-26 21:54:45 +00:00
Aaron Hill 55082ce413 Attach TokenStream to ast::Path 2020-09-10 17:33:06 -04:00
mark 9e5f7d5631 mv compiler to compiler/ 2020-08-30 18:45:07 +03:00