Commit Graph

1205 Commits

Author SHA1 Message Date
bors
f1b1ed7e18 Auto merge of #108471 - clubby789:unbox-the-syntax, r=Nilstrieb,est31
Remove `box_syntax`

r? `@Nilstrieb`

This removes the feature `box_syntax`, which allows the use of `box <expr>` to create a Box, and finalises removing use of the feature from the compiler. `box_patterns` (allowing the use of `box <pat>` in a pattern) is unaffected.
It also removes `ast::ExprKind::Box` - the only way to create a 'box' expression now is with the rustc-internal `#[rustc_box]` attribute.
As a temporary measure to help users move away, `box <expr>` now parses the inner expression, and emits a `MachineApplicable` lint to replace it with `Box::new`

Closes #49733
2023-03-13 10:41:50 +00:00
Matthias Krüger
98fea68470
Rollup merge of #109029 - compiler-errors:parse-gating, r=jackh726
Gate usages of `dyn*` and const closures in macros

We silently accepted `dyn*` and const closures in macros as long as they didn't expand to anything containing these experimental features, unlike other gated features such as `for<'a>` binders on closures, etc. Let's not do that, to make sure nobody begins relying on this.
2023-03-12 20:44:51 +01:00
clubby789
8b186dfdb7 Add recovery for use of removed box syntax 2023-03-12 13:26:37 +00:00
clubby789
0932452fa4 Remove box_syntax from AST and use in tools 2023-03-12 13:19:46 +00:00
est31
7e2ecb3cd8 Simplify message paths
This makes it easier to open the messages file while developing on features.

The commit was the result of automatted changes:

for p in compiler/rustc_*; do mv $p/locales/en-US.ftl $p/messages.ftl; rmdir $p/locales; done

for p in compiler/rustc_*; do sed -i "s#\.\./locales/en-US.ftl#../messages.ftl#" $p/src/lib.rs; done
2023-03-11 22:51:57 +01:00
Michael Goulet
c3159b851a Gate const closures even when they appear in macros 2023-03-11 21:29:28 +00:00
Michael Goulet
bd4355500a Gate all usages of dyn*, even in macros 2023-03-11 21:29:28 +00:00
Matthias Krüger
4ad32304c7
Rollup merge of #108900 - bvanjoi:issue-108275, r=petrochenkov
fix(lexer): print whitespace warning for \x0c

- close https://github.com/rust-lang/rust/issues/108275
- discussion: https://github.com/rust-lang/rust/pull/108403
2023-03-10 19:59:19 +01:00
bohan
d223c26bce fix(lexer): not skipped whitespace warning for '\x0c' 2023-03-09 22:44:58 +08:00
Matthias Krüger
bec7011a2c
Rollup merge of #108854 - Ezrashaw:improve-int-idents, r=oli-obk
feat/refactor: improve errors in case of ident with number at start

Improve parser code when we parse a integer (or float) literal but expect an identifier. We emit an error message saying that identifiers can't begin with numbers. This PR just improves that code and expands it to all identifiers. Note that I haven't implemented error recovery (this didn't exist before anyway), I might do that in a follow up PR.
2023-03-09 12:11:53 +01:00
Ezra Shaw
252e0b3385
feat/refactor: improve errors in case of ident with number at start 2023-03-09 21:29:32 +13:00
Maybe Waffle
775bacd1b8 Simplify sort_by calls 2023-03-07 18:13:41 +00:00
Matthias Krüger
dd6f03de9a
Rollup merge of #108715 - chenyukang:yukang/cleanup-parser-delims, r=compiler-errors
Remove unclosed_delims from parser

After landing https://github.com/rust-lang/rust/pull/108297
we could remove `unclosed_delims` from the parser now.
2023-03-04 20:48:17 +01:00
Dylan DPC
035aa2816a
Rollup merge of #108298 - TaKO8Ki:fix-104440, r=cjgillot
Fix ICE: check if snippet is `)`

Fixes #107705
2023-03-04 15:24:37 +05:30
yukang
d1073fab35 Remove unclosed_delims from parser 2023-03-03 23:09:36 +00:00
est31
6df5ae4fb0 Match unmatched backticks in comments in compiler/ 2023-03-03 08:39:00 +01:00
Takayuki Maeda
871ee18086 check if snippet is ) 2023-03-03 14:34:11 +09:00
y21
0758c05c97 recover from for-else and while-else 2023-03-01 13:26:59 +01:00
bors
bcb610da7f Auto merge of #108587 - matthiaskrgr:rollup-rw6po59, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #108376 (compiler/rustc_session: fix sysroot detection logic)
 - #108400 (add llvm cgu instructions stats to perf)
 - #108496 (fix #108495, postfix decrement and prefix decrement has no warning)
 - #108505 (Further unify validity intrinsics)
 - #108520 (Small cleanup to `one_bound_for_assoc_type`)
 - #108560 (Some `infer/mod.rs` cleanups)
 - #108563 (Make mailmap more correct)
 - #108564 (Fix `x clean` with specific paths)
 - #108571 (Add contains_key to SortedIndexMultiMap)
 - #108578 (Update Fuchsia platform team members)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-03-01 06:23:19 +00:00
Matthias Krüger
1c3cc8bba5
Rollup merge of #108496 - nx2k3:issue-108495-dec, r=WaffleLapkin
fix #108495, postfix decrement and prefix decrement has no warning

Fixes #108495
2023-03-01 01:21:56 +01:00
Matthias Krüger
371904bba6
Rollup merge of #108297 - chenyukang:yukang/delim-error-exit, r=petrochenkov
Exit when there are unmatched delims to avoid noisy diagnostics

From https://github.com/rust-lang/rust/pull/104012#issuecomment-1311764832
r? ``@petrochenkov``
2023-03-01 01:20:22 +01:00
Maybe Waffle
031206bc1d micro fmt changes 2023-02-28 19:28:14 +04:00
yukang
f808877bbf refactor parse_token_trees to not return unmatched_delims 2023-02-28 07:57:17 +00:00
yukang
88de2e1115 no need to return unmatched_delims from tokentrees 2023-02-28 07:57:17 +00:00
yukang
9ce7472db4 rename unmatched_braces to unmatched_delims 2023-02-28 07:57:17 +00:00
yukang
65ad5f8de7 remove duplicated diagnostic for unclosed delimiter 2023-02-28 07:57:17 +00:00
yukang
f01d0c02e7 Exit when there are unmatched delims to avoid noisy diagnostics 2023-02-28 07:55:19 +00:00
nx2k3
a4830266b0 handle only postfix decrement 2023-02-27 17:31:55 +00:00
nx2k3
0883973d2a check double negation 2023-02-27 13:25:03 +00:00
Matthias Krüger
69b1b94d0c
Rollup merge of #108477 - y21:replace-semi-with-comma-sugg, r=compiler-errors
Make `match` arm comma suggestion more clear

Fixes #108472
2023-02-27 06:11:53 +01:00
nx2k3
13a741afac fix some comments 2023-02-26 16:24:08 +00:00
nx2k3
46ea12a499 fix #108495, postfix decrement and prefix decrement has no warning 2023-02-26 16:17:23 +00:00
Matthias Krüger
786a75a65f
Rollup merge of #108418 - est31:parser_function_names, r=Nilstrieb
Replace parse_[sth]_expr with parse_expr_[sth] function names

This resolves an inconsistency in naming style for functions on the parser, where:

* functions parsing specific kinds of items are named `parse_item_[sth]` and
* functions parsing specific kinds of *expressions* are named `parse_[sth]_expr`

favoring the style used by functions for items. There are multiple advantages of that style:

* functions of both categories are collected in the same place in the [rustdoc output](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/parser/struct.Parser.html).
* it helps with autocompletion, as you can narrow down your search for a function to those about expressions.
* it mirrors rust's path syntax where less specific things come first, then it gets more specific, i.e. `std::collections::hash_map::Entry`.

The disadvantage is that it doesn't "read like a sentence" any more. But I think the advantages weigh more greatly.

This change was mostly application of this command:

```
sed -i -E 's/(fn |\.)parse_([[:alnum:]_]+)_expr/\1parse_expr_\2/' compiler/rustc_parse/src/parser/*.rs
```

Plus very minor fixes outside of `rustc_parse`, and an invocation of `x fmt`.
2023-02-26 12:04:59 +01:00
y21
32da026c35 generalize help message 2023-02-26 11:58:49 +01:00
est31
2850116636 Replace parse_[sth]_expr with parse_expr_[sth] function names
This resolves an inconsistency in naming style for functions
on the parser, between functions parsing specific kinds of items
and those for expressions, favoring the parse_item_[sth] style
used by functions for items. There are multiple advantages
of that style:

* functions of both categories are collected in the same place
  in the rustdoc output.
* it helps with autocompletion, as you can narrow down your
  search for a function to those about expressions.
* it mirrors rust's path syntax where less specific things
  come first, then it gets more specific, i.e.
  std::collections::hash_map::Entry

The disadvantage is that it doesn't "read like a sentence"
any more, but I think the advantages weigh more greatly.

This change was mostly application of this command:

sed -i -E 's/(fn |\.)parse_([[:alnum:]_]+)_expr/\1parse_expr_\2/' compiler/rustc_parse/src/parser/*.rs

Plus very minor fixes outside of rustc_parse, and an invocation
of x fmt.
2023-02-24 05:12:03 +01:00
Yutaro Ohno
0e42298674 parser: provide better errors on closures with braces missing
We currently provide wrong suggestions and unhelpful errors on closure
bodies with braces missing. For example, given the following code:

```
fn main() {
    let _x = Box::new(|x|x+1;);
}
```

the current output is like this:

```
error: expected expression, found `)`
 --> ./main.rs:2:30
  |
2 |     let _x = Box::new(|x|x+1;);
  |                              ^ expected expression

error: closure bodies that contain statements must be surrounded by braces
 --> ./main.rs:2:25
  |
2 |     let _x = Box::new(|x|x+1;);
  |                         ^
3 | }
  | ^
  |

...

help: try adding braces
  |
2 ~     let _x = Box::new(|x| {x+1;);
3 ~ }}

...

error: expected `;`, found `}`
 --> ./main.rs:2:32
  |
2 |     let _x = Box::new(|x|x+1;);
  |                                ^ help: add `;` here
3 | }
  | - unexpected token

error: aborting due to 3 previous errors
```

This commit allows outputting correct suggestions and errors. The above
code would output like this:

```
error: closure bodies that contain statements must be surrounded by braces
 --> ./main.rs:2:25
  |
2 |     let _x = Box::new(|x|x+1;);
  |                         ^    ^
  |
note: statement found outside of a block
 --> ./main.rs:2:29
  |
2 |     let _x = Box::new(|x|x+1;);
  |                          ---^ this `;` turns the preceding closure into a statement
  |                          |
  |                          this expression is a statement because of the trailing semicolon
note: the closure body may be incorrectly delimited
 --> ./main.rs:2:23
  |
2 |     let _x = Box::new(|x|x+1;);
  |                       ^^^^^^ - ...but likely you meant the closure to end here
  |                       |
  |                       this is the parsed closure...
help: try adding braces
  |
2 |     let _x = Box::new(|x| {x+1;});
  |                           +    +

error: aborting due to previous error
```
2023-02-23 19:05:13 +09:00
David Wood
d1fcf61117 errors: generate typed identifiers in each crate
Instead of loading the Fluent resources for every crate in
`rustc_error_messages`, each crate generates typed identifiers for its
own diagnostics and creates a static which are pulled together in the
`rustc_driver` crate and provided to the diagnostic emitter.

Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-22 09:15:53 +00:00
Nicholas Nethercote
7e855d5f31 Use ThinVec in a few more AST types. 2023-02-21 11:51:56 +11:00
Nicholas Nethercote
549f1c60af Use ThinVec in ast::ExprKind::Match. 2023-02-21 11:51:56 +11:00
Nicholas Nethercote
912b825002 Use ThinVec in ast::PatKind::Struct. 2023-02-21 11:51:56 +11:00
Nicholas Nethercote
1807027248 Use ThinVec in ast::AngleBracketedArgs. 2023-02-21 11:51:56 +11:00
Nicholas Nethercote
b14b7ba5dd Use ThinVec in ast::Block. 2023-02-21 11:51:56 +11:00
Nicholas Nethercote
4143b101f9 Use ThinVec in various AST types.
This commit changes the sequence parsers to produce `ThinVec`, which
triggers numerous conversions.
2023-02-21 11:51:56 +11:00
Nicholas Nethercote
6a56c3a930 Use ThinVec in ast::Impl and related types. 2023-02-21 11:51:55 +11:00
Nicholas Nethercote
068db466e8 Use ThinVec in ast::WhereClause. 2023-02-21 11:51:55 +11:00
Nicholas Nethercote
dd7aff5cc5 Use ThinVec in ast::Generics and related types. 2023-02-21 11:51:55 +11:00
Nicholas Nethercote
06228d6e93 Upgrade thin-vec from 0.2.9 to 0.2.12.
Because 0.2.10 added supports for `ThinVec::splice`, and 0.2.12 is the
latest release.
2023-02-21 11:51:55 +11:00
Matthias Krüger
226ce31edd
Rollup merge of #108200 - jhpratt:restricted-damerau-levenshtein-distance, r=tmiasko
Use restricted Damerau-Levenshtein distance for diagnostics

This replaces the existing Levenshtein algorithm with the Damerau-Levenshtein algorithm. This means that "ab" to "ba" is one change (a transposition) instead of two (a deletion and insertion). More specifically, this is a _restricted_ implementation, in that "ca" to "abc" cannot be performed as "ca" → "ac" → "abc", as there is an insertion in the middle of a transposition. I believe that errors like that are sufficiently rare that it's not worth taking into account.

This was first brought up [on IRLO](https://internals.rust-lang.org/t/18227) when it was noticed that the diagnostic for `prinltn!` (transposed L and T) was `print!` and not `println!`. Only a single existing UI test was effected, with the result being an objective improvement.

~~I have left the method name and various other references to the Levenshtein algorithm untouched, as the exact manner in which the edit distance is calculated should not be relevant to the caller.~~

r? ``@estebank``

``@rustbot`` label +A-diagnostics +C-enhancement
2023-02-20 14:32:55 +01:00
Jacob Pratt
20282c1b20
Reduce limit on macro_rules! diagnostic 2023-02-19 04:17:58 +00:00
Jacob Pratt
378c4ab9ab
Make public API, docs algorithm-agnostic 2023-02-19 04:11:10 +00:00