Commit Graph

1308 Commits

Author SHA1 Message Date
bors
6b46c996e1 Auto merge of #113105 - matthiaskrgr:rollup-rci0uym, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #112207 (Add trustzone and virtualization target features for aarch32.)
 - #112454 (Make compiletest aware of targets without dynamic linking)
 - #112628 (Allow comparing `Box`es with different allocators)
 - #112692 (Provide more context for `rustc +nightly -Zunstable-options` on stable)
 - #112972 (Make `UnwindAction::Continue` explicit in MIR dump)
 - #113020 (Add tests impl via obj unless denied)
 - #113084 (Simplify some conditions)
 - #113103 (Normalize types when applying uninhabited predicate.)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-27 21:31:47 +00:00
Matthias Krüger
e992895c1d
Rollup merge of #112978 - compiler-errors:bad-block-sugg, r=davidtwco
Add suggestion for bad block fragment error

Makes it a bit clearer how to fix this parser restriction
2023-06-27 17:48:45 +02:00
Matthias Krüger
9f2c21c11f
Rollup merge of #112518 - chenyukang:yukang-fix-112458, r=davidtwco
Detect actual span for getting unexpected token from parsing macros

Fixes #112458
2023-06-27 17:48:44 +02:00
Maybe Waffle
ef05533c39 Simplify some conditions 2023-06-27 07:40:47 +00:00
Michael Goulet
2cc7782cfd Add suggestion for bad block fragment error 2023-06-23 19:18:20 +00:00
Maybe Waffle
d7713feb99 Syntatically accept become expressions 2023-06-19 12:54:34 +00:00
Michael Goulet
9ef580fa6f Handle interpolated literal errors 2023-06-15 01:55:37 +00:00
yukang
0220c0b765 Detect actual span for getting unexpected token from parsing macros 2023-06-11 14:36:20 +08:00
Matthias Krüger
46b64aaef0
Rollup merge of #112498 - SamZhang3:rust-reference-link-update, r=Nilstrieb
Update links to Rust Reference in diagnostic

Instead of linking to the [old Rust Reference site](https://static.rust-lang.org/doc/master/reference.html#literals), which is severely outdated (Rust 1.17), link to the [current website](https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html) in diagnostic about incorrect literals.
2023-06-11 01:57:28 +02:00
Hankai Zhang
6336da9a75 Use a better link 2023-06-10 14:46:11 -04:00
Hankai Zhang
e5fccf927d Update links to Rust Reference page on literals in diagnostic
Instead of linking to the old Rust Reference site on static.rust-lang.org,
link to the current website doc.rust-lang.org/stable/reference instead in
diagnostic about incorrect literals.
2023-06-10 12:34:16 -04:00
yukang
f54e75730b remove unwrap 2023-06-10 10:34:19 +08:00
yukang
e3071eaa60 reword the message to suggest surrounding with parentheses 2023-06-10 06:28:35 +08:00
yukang
3983881d4e take care module name for suggesting surround the struct literal in parentheses 2023-06-10 06:28:35 +08:00
est31
9fb266b525 Move parse_seq_to_before_end closure to own function 2023-06-09 00:08:03 +02:00
est31
1b90f5efaf Support float-like tuple indices in offset_of!()
The tokenizer gives us whole float literal tokens, we have to split them up
in order to be able to create field access from them.
2023-06-08 23:42:58 +02:00
est31
d74ec96e8d Move float breaking out of Parser::parse_expr_tuple_field_access_float
Purely a refactor in preparation of using it in offset_of!() parsing
2023-06-08 22:03:06 +02:00
许杰友 Jieyou Xu (Joe)
2a7c6a99ef
Fix suggestion for matching struct with .. on both ends 2023-06-03 15:02:13 +08:00
bors
70e04bd88d Auto merge of #111748 - nnethercote:Cow-DiagnosticMessage, r=WaffleLapkin
Use `Cow` in `{D,Subd}iagnosticMessage`.

Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment:
```
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
```
This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging.

This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths.

Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.

r? `@WaffleLapkin`
2023-05-29 07:10:44 +00:00
Nicholas Nethercote
781111ef35 Use Cow in {D,Subd}iagnosticMessage.
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment:
```
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
```
This commit answers that question in the affirmative. It's not the most
compelling change ever, but it might be worth merging.

This requires changing the `impl<'a> From<&'a str>` impls to `impl
From<&'static str>`, which involves a bunch of knock-on changes that
require/result in call sites being a little more precise about exactly
what kind of string they use to create errors, and not just `&str`. This
will result in fewer unnecessary allocations, though this will not have
any notable perf effects given that these are error paths.

Note that I was lazy within Clippy, using `to_string` in a few places to
preserve the existing string imprecision. I could have used `impl
Into<{D,Subd}iagnosticMessage>` in various places as is done in the
compiler, but that would have required changes to *many* call sites
(mostly changing `&format("...")` to `format!("...")`) which didn't seem
worthwhile.
2023-05-29 09:23:43 +10:00
许杰友 Jieyou Xu (Joe)
41f5a30690
Recover upon encountering mistyped Const in const param def 2023-05-28 16:55:21 +08:00
Matthias Krüger
97fae38bf9
Rollup merge of #111181 - bvanjoi:fix-issue-111148, r=davidtwco
fix(parse): return unpected when current token is EOF

close https://github.com/rust-lang/rust/issues/111148

#111148 panic occurred because [FatalError.raise()](https://github.com/bvanjoi/rust/blob/master/compiler/rustc_parse/src/parser/mod.rs#LL540C3-L540C3) was encountered which caused by `Eof` and `Pound`(the last token) had same span, when parsing `#` in `fn a<<i<Y<w<>#`.

<img width="825" alt="image" src="https://user-images.githubusercontent.com/30187863/236612589-9e2c6a0b-18cd-408c-b636-c12a51cbcf1c.png">

There are a few ways to solve this problem:

- Change the action assign for [self.last_unexpected_token_span](https://github.com/rust-lang/rust/blob/master/compiler/rustc_parse/src/parser/diagnostics.rs#L592), for example, if current token is `Eof`, then return Error directly.
- Avoid triggering the `FatalError` when the current token is `Eof`.

I have chosen the second option because executing `expected_one_of_not_found` when the token is `Eof` but not in `ediable` seems reasonable.
2023-05-27 20:40:28 +02:00
clubby789
f97fddab91 Ensure Fluent messages are in alphabetical order 2023-05-25 23:49:35 +00:00
Maybe Waffle
307799a711 Use is_some_and/is_ok_and in less obvious spots 2023-05-24 14:33:43 +00:00
Maybe Waffle
fb0f74a8c9 Use Option::is_some_and and Result::is_ok_and in the compiler 2023-05-24 14:20:41 +00:00
Dylan DPC
35bef062c7
Rollup merge of #111708 - jyn514:delay-span-bug-msg, r=compiler-errors
Give a more useful location for where a span_bug was delayed

Before:
```
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1335:29
              1: <rustc_errors::Handler>::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1124:9
...
```

After:
```
   = note: delayed at compiler/rustc_parse/src/parser/diagnostics.rs:2158:28
              0: <rustc_errors::HandlerInner>::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1335:29
              1: <rustc_errors::Handler>::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1124:9
...
```

This both makes the relevant frame easier to find without having to dig through diagnostic internals, and avoids the weird-looking formatting for the first frame.

Found while working on https://github.com/rust-lang/rust/issues/111529.
2023-05-20 12:21:00 +05:30
Dylan DPC
ee26abdafb
Rollup merge of #111054 - cjgillot:cfg-eval-recover, r=b-naber
Do not recover when parsing stmt in cfg-eval.

`parse_stmt` does recovery on its own. When parsing the statement fails, we always get `Ok(None)` instead of an `Err` variant with the diagnostic that we can emit.

To avoid this behaviour, we need to opt-out of recovery for cfg_eval.

Fixes https://github.com/rust-lang/rust/issues/105228
2023-05-18 17:37:08 +05:30
Dylan DPC
08efb9d652
Rollup merge of #111633 - nnethercote:avoid-ref-format, r=WaffleLapkin
Avoid `&format("...")` calls in error message code.

Some error message cleanups. Best reviewed one commit at a time.

r? `@davidtwco`
2023-05-18 10:52:35 +05:30
jyn
e6a7fdedd7 Give a more useful location for where a span_bug was delayed
Before:
```
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1335:29
              1: <rustc_errors::Handler>::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1124:9
...
```

After:
```
   = note: delayed at compiler/rustc_parse/src/parser/diagnostics.rs:2158:28
              0: <rustc_errors::HandlerInner>::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1335:29
              1: <rustc_errors::Handler>::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1124:9
```

This both makes the relevant frame easier to find without having to dig
through diagnostic internals, and avoids the weird-looking formatting
for the first frame.
2023-05-17 23:15:22 -05:00
Nicholas Nethercote
01e33a3600 Avoid &format("...") calls in error message code.
Error message all end up passing into a function as an `impl
Into<{D,Subd}iagnosticMessage>`. If an error message is creatd as
`&format("...")` that means we allocate a string (in the `format!`
call), then take a reference, and then clone (allocating again) the
reference to produce the `{D,Subd}iagnosticMessage`, which is silly.

This commit removes the leading `&` from a lot of these cases. This
means the original `String` is moved into the
`{D,Subd}iagnosticMessage`, avoiding the double allocations. This
requires changing some function argument types from `&str` to `String`
(when all arguments are `String`) or `impl
Into<{D,Subd}iagnosticMessage>` (when some arguments are `String` and
some are `&str`).
2023-05-16 17:59:56 +10:00
Michael Goulet
a5763ff8d3 Recover impl<T ?Sized> correctly 2023-05-15 17:14:59 +00:00
Matthias Krüger
7a1f3e7a88
Rollup merge of #111531 - chenyukang:yukang-fix-111416-ice, r=compiler-errors
Fix ice caused by shorthand fields in NoFieldsForFnCall

Fixes #111416
2023-05-15 10:58:39 +02:00
yukang
83789b8b06 fmt 2023-05-13 19:40:17 +08:00
yukang
ce6cfc37d0 Fix ice caused by shorthand fields in NoFieldsForFnCall 2023-05-13 18:06:16 +08:00
y21
7fe83345ef improve error for impl<..> impl Trait for Type 2023-05-13 10:51:21 +02:00
bohan
272dc5a6d5 fix(parse): return unpected when current token is EOF 2023-05-13 00:33:27 +08:00
Dylan DPC
8c51701b8a
Rollup merge of #111120 - chenyukang:yukang-suggest-let, r=Nilstrieb
Suggest let for possible binding with ty

Origin from https://github.com/rust-lang/rust/pull/109128#discussion_r1179866137

r? `@Nilstrieb`
2023-05-09 12:33:46 +05:30
Dylan DPC
dbd090c655
Rollup merge of #110694 - est31:builtin, r=petrochenkov
Implement builtin # syntax and use it for offset_of!(...)

Add `builtin #` syntax to the parser, as well as a generic infrastructure to support both item and expression position builtin syntaxes. The PR also uses this infrastructure for the implementation of the `offset_of!` macro, added by #106934.

cc `@petrochenkov` `@DrMeepster`

cc #110680 `builtin #` tracking issue
cc #106655 `offset_of!` tracking issue
2023-05-09 12:33:45 +05:30
yukang
4d219d0666 move sugg to derive session diagnostic 2023-05-09 11:51:04 +08:00
yukang
0e8703da3e make it more accurate by parsing ty 2023-05-08 15:07:36 +08:00
yukang
6b76588222 suggest struct when we get colon in fileds in enum 2023-05-08 14:58:09 +08:00
yukang
5e94b5faf1 code refactor and fix wrong suggestion 2023-05-08 14:56:36 +08:00
yukang
a7fc32ceaf fix ice in suggesting 2023-05-08 11:16:17 +08:00
yukang
20e6e6a493 cleanup 2023-05-08 10:56:20 +08:00
yukang
0bb43c63c3 Suggest let for possible binding with ty 2023-05-08 10:56:20 +08:00
Matthias Krüger
83b29ec743
Rollup merge of #111230 - zacklukem:eq-less-to-less-eq, r=compiler-errors
add hint for =< as <=

Adds a compiler hint for when `=<` is typed instead of `<=`

Example hint:
```rust
fn foo() {
    if 1 =< 3 {
        println!("Hello, World!");
    }
}
```
```
error: expected type, found `3`
 --> main.rs:2:13
  |
2 |     if 1 =< 3 {
  |          -- ^ expected type
  |          |
  |          help: did you mean: `<=`
```

This PR only emits the suggestion if there is no space between the `=` and `<`.  This hopefully narrows the scope of when this error is emitted, however this still allows this error to be emitted in cases such as this:
```
error: expected expression, found `;`
 --> main.rs:2:18
  |
2 |     if 1 =< [i32;; 3]>::hello() {
  |          --      ^ expected expression
  |          |
  |          help: did you mean: `<=`
```

Which could be a good reason not to merge since I haven't been able to think of any other ways of narrowing the scope of this diagnostic.

closes #111128
2023-05-06 13:30:05 +02:00
est31
83b4df4e61 Add feature gate 2023-05-05 21:44:48 +02:00
est31
5eb29c7f49 Migrate offset_of from a macro to builtin # syntax 2023-05-05 21:44:13 +02:00
est31
59ecbd2cea Add parsing for builtin # in expression and item context 2023-05-05 21:44:13 +02:00
Zachary Mayhew
a183ac6f90
add hint for =< as <= 2023-05-05 11:17:14 -04:00