Commit Graph

685 Commits

Author SHA1 Message Date
bors a48396984a Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstrieb
Format all the let-chains in compiler crates

Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped).

This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/374997516), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else.

I will also add this commit to the ignore list after it has landed.

The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree.
```
~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates
~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif
```

cc `@rust-lang/rustfmt`
r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :>

cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.
2023-10-15 13:23:55 +00:00
Matthias Krüger 6fef4f089f
Rollup merge of #116696 - c410-f3r:in-doc, r=petrochenkov
Misc improvements

cc https://github.com/rust-lang/rust/pull/116323#discussion_r1355282195

r? `@petrochenkov`
2023-10-14 13:36:28 +02:00
Caio 6b59f6fbea Misc improvements 2023-10-13 10:22:33 -03:00
Michael Goulet b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Nicholas Nethercote 7528fdc4c4 Don't `escape_debug` the condition of `assert!`.
The assertion in `assert-long-condition.rs` used to be fail like this, all on
one line:
```
thread 'main' panicked at 'assertion failed: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18\n                                + 19 + 20 + 21 + 22 + 23 + 24 + 25 == 0', tests/ui/macros/assert-long-condition.rs:7:5
```
The `\n` and subsequent indent is because the condition is pretty-printed, and
the pretty-printer inserts a newline. Printing the newline in this way is
arguably reasonable given that the message appears within single quotes, which
is very similar to a string literal.

However, after the assertion printing improvements that were released in 1.73,
the assertion now fails like this:
```
thread 'main' panicked at tests/ui/macros/assert-long-condition.rs:7:5:
assertion failed: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18\n                                + 19 + 20 + 21 + 22 + 23 + 24 + 25 == 0
```
Now that there are no single quotes around the pretty-printed condition, the
`\n` is quite strange.

This commit gets rid of the `\n`, by removing the `escape_debug` done on the
pretty-printed message. This results in the following:
```
thread 'main' panicked at tests/ui/macros/assert-long-condition.rs:7:5:
assertion failed: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18
                                + 19 + 20 + 21 + 22 + 23 + 24 + 25 == 0
```
The overly-large indent is still strange, but that's a separate pretty-printing issue.

This change helps with #108341.
2023-10-10 09:08:11 +11:00
Nicholas Nethercote 7326cd98b9 Factor out the two `entry_point_type` functions.
They are very similar, and each one has a comment about the importance
of being kept in sync with the other. This commit removes the
duplication.
2023-10-01 20:45:09 +11:00
Nicholas Nethercote 373cc2160a Change `depth` arg to `at_root`.
This will facilitate a subsequent refactoring.
2023-09-29 17:49:16 +10:00
Ralf Jung ad509633a2 ConstParamTy: require Eq 2023-09-24 23:38:07 +02:00
Matthias Krüger 864f7aafe4
Rollup merge of #115891 - RalfJung:structural-trait-derive, r=nnethercote
simplify inject_impl_of_structural_trait

There's a comment at `inject_impl_of_structural_trait` saying we cannot use `TraitDef`, but that comment is outdated -- we *can* use `TraitDef` nowadays since it has the `skip_path_as_bound` flag. (The flag needed some fixing, though.)
2023-09-18 18:27:20 +02:00
Ralf Jung 0522bde4bc simplify inject_impl_of_structural_trait 2023-09-18 07:45:46 +02:00
Dylan DPC 0900712fe0
Rollup merge of #115611 - lukas-code:format!("{r#ident}"), r=compiler-errors
add diagnostic for raw identifiers in format string

Format strings don't support raw identifiers (e.g. `format!("{r#type}")`), but they do support keywords in the format string directly (e.g. `format!("{type}")`). This PR improves the error output when attempting to use a raw identifier in a format string and adds a machine-applicable suggestion to remove the `r#`.

fixes https://github.com/rust-lang/rust/issues/115466
2023-09-17 11:23:25 +00:00
Guillaume Gomez e39c39346b Fix invalid markdown codeblock label 2023-09-16 11:37:41 +02:00
bors dac91a82e1 Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naber
Improve invalid let expression handling

- Move all of the checks for valid let expression positions to parsing.
- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location.
- Suppress some later errors and MIR construction for invalid let expressions.
- Fix a (drop) scope issue that was also responsible for #104172.

Fixes #104172
Fixes #104868
2023-09-14 19:56:55 +00:00
Matthew Jasper 333388fd3c Move let expression checking to parsing
There was an incomplete version of the check in parsing and a second
version in AST validation. This meant that some, but not all, invalid
uses were allowed inside macros/disabled cfgs. It also means that later
passes have a hard time knowing when the let expression is in a valid
location, sometimes causing ICEs.

- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a
  valid location.
- Suppress later errors and MIR construction for invalid let
  expressions.
2023-09-11 15:51:18 +00:00
Andy Caldwell 679267f2ac
Rename the feature, but not the attribute, to `coverage_attribute` 2023-09-08 12:46:09 +01:00
Andy Caldwell 8e03371fc3
Rework no_coverage to coverage(off) 2023-09-08 12:46:06 +01:00
Lukas Markeffsky d990eee0c8 add diagnostic for raw identifiers in format string 2023-09-06 18:55:45 +02:00
Ben Kimock f26293dca4 Load include_bytes! directly into an Lrc 2023-08-27 20:16:19 -04:00
Vadim Petrochenkov 7353c96be8 rustc: Move `features` from `Session` to `GlobalCtxt`
Removes two pieces of mutable state.
Follow up to #114622.
2023-08-11 16:51:50 +08:00
bors e286f25ec0 Auto merge of #114507 - sebastiantoh:issue-114235, r=jackh726
Add suggestion to quote inlined format argument as string literal

Fixes #114235
2023-08-11 01:41:30 +00:00
David Tolnay 704aa56ba0
Generate better function argument names in global_allocator expansion 2023-08-06 07:36:05 -07:00
David Tolnay e57a89174c
Delete some useless casts from global_allocator expansion 2023-08-05 23:10:38 -07:00
Sebastian Toh d003fd9859 Add suggestion to quote inlined format argument as string literal 2023-08-05 17:29:06 +08:00
Matthias Krüger 99e4127d85
Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
Improve spans for indexing expressions

fixes #114388

Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.

r? compiler-errors
2023-08-04 21:31:57 +02:00
bors ec5b882c2f Auto merge of #114414 - cjgillot:early-unnameable-test, r=petrochenkov
Make test harness lint about unnnameable tests.

Implementation of https://github.com/rust-lang/rust/pull/113734#discussion_r1283073418

About the options suggested in https://github.com/rust-lang/rust/issues/36629#issuecomment-404753945: adding this case to unused_attribute was just more complicated. I'll try to understand a bit more what you had in mind in https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397241123

This was just simpler to do in a standalone PR. I'll remove the corresponding changes from https://github.com/rust-lang/rust/pull/113734 later.

r? `@petrochenkov`
2023-08-04 14:13:11 +00:00
Nilstrieb 5706be1854 Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary
left-hand-side and then something on the right, which is the main part
of the expression. Method calls already have a span for that right part,
but indexing does not. This means that long method chains that use
indexing have really bad spans, especially when the indexing panics and
that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an
extra span which is then put into the `fn_span` field in THIR.
2023-08-04 13:17:39 +02:00
Camille GILLOT 2a0a1f918d Make test harness lint about unnnameable tests. 2023-08-03 13:07:30 +00:00
Nicholas Nethercote d75ee2a6bc Remove `MacDelimiter`.
It's the same as `Delimiter`, minus the `Invisible` variant. I'm
generally in favour of using types to make impossible states
unrepresentable, but this one feels very low-value, and the conversions
between the two types are annoying and confusing.

Look at the change in `src/tools/rustfmt/src/expr.rs` for an example:
the old code converted from `MacDelimiter` to `Delimiter` and back
again, for no good reason. This suggests the author was confused about
the types.
2023-08-03 09:03:30 +10:00
Matthias Krüger 23815467a2 inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
León Orell Valerian Liehr afd009a8d8
Parse generic const items 2023-07-28 22:21:33 +02:00
David Wood 75df62d4a2
builtin_macros: raw str in diagnostic output
If a raw string was used in the `env!` invocation, then it should also
be shown in the diagnostic messages as a raw string.

Signed-off-by: David Wood <david@davidtw.co>
2023-07-25 11:12:52 +01:00
David Wood c06a7eb2a6
builtin_macros: expect raw strings too
`expr_to_string` allows raw strings through so this code should be
expected to handle those.

Signed-off-by: David Wood <david@davidtw.co>
2023-07-24 15:06:50 +01:00
Matthias Krüger adf759bf6a fix couple of clippy findings:
filter_map_identity
iter_kv_map
needless_question_mark
redundant_at_rest_pattern
filter_next
derivable_impls
2023-07-23 10:50:14 +02:00
David Tolnay 56633b3f51
Add a comparison between match *self and intrinsics::unreachable() 2023-07-16 15:33:29 -07:00
David Tolnay f441adc89a
Generate safe stable code for derives on empty enums
Generate `match *self {}` instead of `unsafe { core::intrinsics::unreachable() }`.

This is:

    1. safe
    2. stable

for the benefit of everyone looking at these derived impls through `cargo expand`.

Both expansions compile to the same code at all optimization levels (including `0`).
2023-07-16 15:02:08 -07:00
bors 4a07b2baf5 Auto merge of #113557 - Amanieu:no-builtins-prelude, r=petrochenkov
Hide `compiler_builtins` in the prelude

This crate is a private implementation detail. We only need to insert it into the crate graph for linking and should not expose any of its public API.

Fixes #113533
2023-07-16 13:19:14 +00:00
Amanieu d'Antras 07f855d781 Hide `compiler_builtins` in the prelude
This crate is a private implementation detail. We only need to insert it
into the crate graph for linking and should not expose any of its public
API.

Fixes #113533
2023-07-14 16:53:36 +01:00
Mark Rousskov cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
He1pa 453603a4b5 fix typo 2023-06-28 10:52:48 +08:00
He1pa 8af8a95a64 Migrate some rustc_builtin_macros to SessionDiagnostic 2023-06-25 01:32:30 +08:00
bors ed1ce580ec Auto merge of #112802 - lukas-code:fancy-bool, r=Nilstrieb
use ErrorGuaranteed instead of booleans in rustc_builtin_macros

implements https://github.com/rust-lang/rust/pull/112366#discussion_r1233821873

No functional changes.

Best reviewed with whitespace diff disabled.

r? `@Nilstrieb`
2023-06-24 11:43:41 +00:00
Nilstrieb c6710d15f1
Rollup merge of #112790 - WaffleLapkin:syntactically, r=Nilstrieb
Syntactically accept `become` expressions (explicit tail calls experiment)

This adds `ast::ExprKind::Become`, implements parsing and properly gates the feature.

cc `@scottmcm`
2023-06-21 07:37:02 +02:00
Lukas Markeffsky d50875e24a use `ErrorGuaranteed` instead of booleans 2023-06-19 21:34:59 +02:00
bors 689511047a Auto merge of #112366 - lukas-code:test, r=Nilstrieb
`#[test]` function signature verification improvements

This PR contains two improvements to the expansion of the `#[test]` macro.

The first one fixes https://github.com/rust-lang/rust/issues/112360 by correctly recovering item statements if the signature verification fails.

The second one forbids non-lifetime generics on `#[test]` functions. These were previously allowed if the function returned `()`, but always caused an inference error:

before:
```text
error[E0282]: type annotations needed
 --> src/lib.rs:2:1
  |
1 | #[test]
  | ------- in this procedural macro expansion
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^ cannot infer type
```

after:
```text
error: functions used as tests can not have any non-lifetime generic parameters
 --> src/lib.rs:2:1
  |
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^
```

Also includes some basic tests for test function signature verification, because I couldn't find any (???) in the test suite.
2023-06-19 13:39:46 +00:00
Maybe Waffle d7713feb99 Syntatically accept `become` expressions 2023-06-19 12:54:34 +00:00
asquared31415 3dc793e625 fix ICE on specific malformed asm clobber_abi 2023-06-16 19:51:01 -04:00
clubby789 053e6b80c7 Remove accidental comment 2023-06-07 17:16:34 +00:00
Lukas Markeffsky 774f7825cb Deny non-lifetime generics for test functions.
Previously, these were allowed if the function returned `()`, but always led to an ambiguity error.
2023-06-07 00:04:04 +02:00
Lukas Markeffsky 4bf00613ee Fix ICE for nested test function with arguments. 2023-06-06 23:28:15 +02: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