Commit graph

107 commits

Author SHA1 Message Date
Michael Goulet ffd72b1700 Fix remaining cases 2024-06-21 19:00:18 -04:00
Santiago Pastorino 2a377122dd
Handle safety keyword for extern block inner items 2024-06-04 14:19:42 -03:00
Oli Scherer a04ac26a9d Allow type_of to return partially non-error types if the type was already tainted 2024-05-28 11:55:20 +00:00
Peter Jaszkowiak 4913ab8f77
Stabilize LazyCell and LazyLock (lazy_cell) 2024-02-20 20:55:13 -07:00
ardi 972633f530 Fix parsing of erroneously placed semicolons 2024-05-20 21:36:20 +02:00
Ross Smyth 6967d1c0fc Stabilize exclusive_range 2024-05-02 19:42:31 -04:00
Lieselotte b52e4bd997
Fix substitution parts having a shifted underline in some cases 2024-04-25 13:09:13 +02:00
Sasha Pourcelot 98332c108b Improve handling of expr->field errors
The current message for "`->` used for field access" is the following:

```rust
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `->`
 --> src/main.rs:2:6
  |
2 |     a->b;
  |      ^^ expected one of 8 possible tokens
```

(playground link[1])

This PR tries to address this by adding a dedicated error message and recovery. The proposed error message is:

```
error: `->` used for field access or method call
 --> ./tiny_test.rs:2:6
  |
2 |     a->b;
  |      ^^ help: try using `.` instead
  |
  = help: the `.` operator will dereference the value if needed
```

(feel free to bikeshed it as much as necessary)

[1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7f8b6f4433aa7866124123575456f54e

Signed-off-by: Sasha Pourcelot <sasha.pourcelot@protonmail.com>
2024-04-22 17:47:35 +02:00
Urgau 3ba0139c66 Remove useless configs in tests
Since they are never set and don't have impact on the test.

Or for the cfg-panic tests are already tested with check-cfg.
2024-04-07 01:16:45 +02:00
Matthias Krüger e9ec44251c
Rollup merge of #122910 - compiler-errors:unit-struct-in-path-pat-only, r=petrochenkov
Validate that we're only matching on unit struct for path pattern

Resolution doesn't validate that we only really take `CtorKind::Unit` in path patterns, since all it sees is `Res::SelfCtor(def_id)`. Check this instead during pattern typeck.

r? petrochenkov

Fixes #122809
2024-03-25 17:05:33 +01:00
Matthias Krüger 1164c2725e
Rollup merge of #122217 - estebank:issue-119685, r=fmease
Handle str literals written with `'` lexed as lifetime

Given `'hello world'` and `'1 str', provide a structured suggestion for a valid string literal:

```
error[E0762]: unterminated character literal
  --> $DIR/lex-bad-str-literal-as-char-3.rs:2:26
   |
LL |     println!('hello world');
   |                          ^^^^
   |
help: if you meant to write a `str` literal, use double quotes
   |
LL |     println!("hello world");
   |              ~           ~
```
```
error[E0762]: unterminated character literal
  --> $DIR/lex-bad-str-literal-as-char-1.rs:2:20
   |
LL |     println!('1 + 1');
   |                    ^^^^
   |
help: if you meant to write a `str` literal, use double quotes
   |
LL |     println!("1 + 1");
   |              ~     ~
```

Fix #119685.
2024-03-24 01:05:51 +01:00
Michael Goulet 08235b1603 Validate that we're only matching on unit struct for path pattern 2024-03-22 20:53:42 -04:00
Esteban Küber 6c31f6ce12 Provide structured suggestion for #![feature(foo)]
```
error: `S2<'_>` is forbidden as the type of a const generic parameter
  --> $DIR/lifetime-in-const-param.rs:5:23
   |
LL | struct S<'a, const N: S2>(&'a ());
   |                       ^^
   |
   = note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
   |
LL + #![feature(adt_const_params)]
   |
```

Fix #55941.
2024-03-18 16:08:58 +00:00
Esteban Küber 999a0dc300 review comment: str -> string in messages 2024-03-17 23:35:18 +00:00
Esteban Küber 4a10b01f95 Use shorter span for existing ' -> " structured suggestion 2024-03-17 23:35:18 +00:00
Daniel Sedlak 58f6aaa710 Improve diagnostics for parenthesized type arguments 2024-03-09 22:15:50 +01:00
Esteban Küber bde2dfb127 Detect more cases of = to : typo
When a `Local` is fully parsed, but not followed by a `;`, keep the `:` span
arround and mention it. If the type could continue being parsed as an
expression, suggest replacing the `:` with a `=`.

```
error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.`
 --> file.rs:2:32
  |
2 |     let _: std::env::temp_dir().join("foo");
  |          -                     ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=`
  |          |
  |          while parsing the type for `_`
  |          help: use `=` if you meant to assign
```

Fix #119665.
2024-03-01 02:03:00 +00:00
Vadim Petrochenkov 9f8d05f29f macro_rules: Preserve all metavariable spans in a global side table 2024-02-18 11:19:24 +03:00
许杰友 Jieyou Xu (Joe) ec2cc761bc
[AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
Oli Scherer eab2adb660 Continue to borrowck even if there were previous errors 2024-02-08 08:10:43 +00:00
Matthias Krüger ed27148812
Rollup merge of #116284 - RalfJung:no-nan-match, r=cjgillot
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern

These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.

This is part of implementing https://github.com/rust-lang/rfcs/pull/3535.

Closes https://github.com/rust-lang/rust/issues/41620 by removing the lint.

https://github.com/rust-lang/reference/pull/1456 updates the reference to match.
2024-02-05 11:07:26 +01:00
Oli Scherer 28f250d6a6 Remove a has_errors check that does not prevent follow up error noise 2024-01-31 16:51:42 +00:00
Lieselotte 6f014a81b2
Handle methodcalls & operators in patterns 2024-01-28 16:12:21 +01:00
Ralf Jung 1254ee48c4 remove illegal_floating_point_literal_pattern lint 2024-01-26 17:25:02 +01:00
George-lewis d56cdd48cb Bless tests
Update tests
2024-01-13 12:46:58 -05:00
Oli Scherer af7f8f9811 Silence follow up errors if astconv already errored 2024-01-11 09:03:26 +00:00
Oli Scherer 0978f6e010 Avoid silencing relevant follow-up errors 2024-01-09 21:08:16 +00:00
bors 5113ed28ea Auto merge of #118297 - shepmaster:warn-dead-tuple-fields, r=WaffleLapkin
Merge `unused_tuple_struct_fields` into `dead_code`

This implicitly upgrades the lint from `allow` to `warn` and places it into the `unused` lint group.

[Discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Moving.20.60unused_tuple_struct_fields.60.20from.20allow.20to.20warn)
2024-01-05 04:51:55 +00:00
Vadim Petrochenkov e1d12c8caf macro_rules: Less hacky heuristic for using tt metavariable spans 2024-01-04 03:53:56 +03:00
Jake Goulding 53eca9fa87 Adjust compiler tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
Lieselotte 7d6cd6bf1f
Don't expect bodyless arms if the pattern can never be a never pattern 2023-12-28 15:02:17 +01:00
Nicholas Nethercote 226edf64fa Improve an error involving attribute values.
Attribute values must be literals. The error you get when that doesn't
hold is pretty bad, e.g.:
```
unexpected expression: 1 + 1
```
You also get the same error if the attribute value is a literal, but an
invalid literal, e.g.:
```
unexpected expression: "foo"suffix
```

This commit does two things.
- Changes the error message to "attribute value must be a literal",
  which gives a better idea of what the problem is and how to fix it. It
  also no longer prints the invalid expression, because the carets below
  highlight it anyway.
- Separates the "not a literal" case from the "invalid literal" case.
  Which means invalid literals now get the specific error at the literal
  level, rather than at the attribute level.
2023-12-12 15:54:25 +11:00
bors 2b399b5275 Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errors
never_patterns: Parse match arms with no body

Never patterns are meant to signal unreachable cases, and thus don't take bodies:
```rust
let ptr: *const Option<!> = ...;
match *ptr {
    None => { foo(); }
    Some(!),
}
```
This PR makes rustc accept the above, and enforces that an arm has a body xor is a never pattern. This affects parsing of match arms even with the feature off, so this is delicate. (Plus this is my first non-trivial change to the parser).

~~The last commit is optional; it introduces a bit of churn to allow the new suggestions to be machine-applicable. There may be a better solution? I'm not sure.~~ EDIT: I removed that commit

r? `@compiler-errors`
2023-12-08 17:08:52 +00:00
Nadrieril 80bdcbf50a Parse a pattern with no arm 2023-12-03 12:25:46 +01:00
bors 225e36cff9 Auto merge of #118542 - chenyukang:yukang-fix-parser-ice-118531, r=cjgillot
Fix parser ICE from attrs

Fixes #118531,
Fixes #118530.
2023-12-03 03:05:17 +00:00
yukang 5ff428c1ff Fix parser ICE from attrs 2023-12-02 23:47:39 +08:00
Esteban Küber 4e524386e9 Always emit help when failing to parse enum variant 2023-11-29 18:47:32 +00:00
Esteban Küber bd1feb8cef Fix test and move to more appropriate directory 2023-11-29 18:47:32 +00:00
Esteban Küber db39068ad7 Change enum parse recovery 2023-11-29 18:47:31 +00:00
Esteban Küber 1994abed74 Bubble parse error when expecting ) 2023-11-29 18:47:31 +00:00
Esteban Küber 44fd3b4d46 Make parse_pat_ident not recover bad name 2023-11-29 18:47:31 +00:00
Nilstrieb 41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
Matthias Krüger ca3a02836e
Rollup merge of #117338 - workingjubilee:asmjs-meets-thanatos, r=b-naber
Remove asmjs

Fulfills [MCP 668](https://github.com/rust-lang/compiler-team/issues/668).

`asmjs-unknown-emscripten` does not work as-specified, and lacks essential upstream support for generating asm.js, so it should not exist at all.
2023-11-17 23:04:21 +01:00
Matthias Krüger a5d7f8bcf2
Rollup merge of #117990 - estebank:issue-100825-part-deux, r=Nilstrieb
Tweak error and move tests

r? `@Nilstrieb`

Split off #117565.
2023-11-17 00:41:24 +01:00
Esteban Küber 1c6bd0b12b Smaller span for unnessary mut suggestion 2023-11-16 16:58:41 +00:00
Esteban Küber f830fe313b Detect more => typos
Handle and recover `match expr { pat >= { arm } }`.
2023-11-14 00:46:37 +00:00
Guillaume Gomez c828371179
Rollup merge of #117282 - clubby789:recover-wrong-function-header, r=TaKO8Ki
Recover from incorrectly ordered/duplicated function keywords

Fixes #115714
2023-11-08 17:14:36 +01:00
bors 187d1afa9d Auto merge of #117297 - clubby789:fn-trait-missing-paren, r=TaKO8Ki
Give a better diagnostic for missing parens in Fn* bounds

Fixes #108109

It would be nice to try and recover here, but I'm not sure it's worth the effort, especially as the bounds on the recovered function would be incorrect.
2023-11-07 13:04:56 +00:00
clubby789 904aceec7d Give a better diagnostic for missing parens in Fn* bounds 2023-11-01 15:33:46 +00:00
clubby789 ca1bcb6466 Recover from missing param list in function definitions 2023-11-01 14:48:20 +00:00