Commit Graph

5187 Commits

Author SHA1 Message Date
Nicholas Nethercote
c7992aff25 Rename Handler as DiagCtxt. 2023-12-18 16:06:19 +11:00
Nicholas Nethercote
7045cad330 Split Handler::emit_diagnostic in two.
Currently, `emit_diagnostic` takes `&mut self`.

This commit changes it so `emit_diagnostic` takes `self` and the new
`emit_diagnostic_without_consuming` function takes `&mut self`.

I find the distinction useful. The former case is much more common, and
avoids a bunch of `mut` and `&mut` occurrences. We can also restrict the
latter with `pub(crate)` which is nice.
2023-12-15 10:13:12 +11:00
Guillaume Gomez
948c9047d5 Rollup merge of #118802 - ehuss:remove-edition-preview, r=TaKO8Ki
Remove edition umbrella features.

In the 2018 edition, there was an "umbrella" feature `#[feature(rust_2018_preview)]` which was used to enable several other features at once. This umbrella mechanism was not used in the 2021 edition and likely will not be used in 2024 either. During 2018 users reported that setting the feature was awkward, especially since they already needed to opt-in via the edition mechanism.

This PR removes this mechanism because I believe it will not be used (and will clean up and simplify the code). I believe that there are better ways to handle features and editions. In short:

- For highly experimental features, that may or may not be involved in an edition, they can implement regular feature gates like `tcx.features().my_feature`.
- For experimental features that *might* be involved in an edition, they should implement gates with `tcx.features().my_feature && span.at_least_rust_20xx()`. This requires the user to still specify `#![feature(my_feature)]`, to avoid disrupting testing of other edition features which are ready and have been accepted within the edition.
- For experimental features that have graduated to definitely be part of an edition, they should implement gates with `tcx.features().my_feature || span.at_least_rust_20xx()`, or just remove the feature check altogether and just check `span.at_least_rust_20xx()`.
- For relatively simple changes, they can skip the whole feature gating thing and just check `span.at_least_rust_20xx()`, and rely on the instability of the edition itself (which requires `-Zunstable-options`) to gate it.

I am working on documenting all of this in the rustc-dev-guide.
2023-12-11 11:40:36 +01:00
Nicholas Nethercote
1cb804b520 Add spacing information to delimiters.
This is an extension of the previous commit. It means the output of
something like this:
```
stringify!(let a: Vec<u32> = vec![];)
```
goes from this:
```
let a: Vec<u32> = vec![] ;
```
With this PR, it now produces this string:
```
let a: Vec<u32> = vec![];
```
2023-12-11 09:36:40 +11:00
Eric Huss
b9ad02421a Remove edition umbrella features. 2023-12-10 13:03:28 -08:00
surechen
1b9bf8adf3 remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
bors
9c809ce8de Auto merge of #118420 - compiler-errors:async-gen, r=eholk
Introduce support for `async gen` blocks

I'm delighted to demonstrate that `async gen` block are not very difficult to support. They're simply coroutines that yield `Poll<Option<T>>` and return `()`.

**This PR is WIP and in draft mode for now** -- I'm mostly putting it up to show folks that it's possible. This PR needs a lang-team experiment associated with it or possible an RFC, since I don't think it falls under the jurisdiction of the `gen` RFC that was recently authored by oli (https://github.com/rust-lang/rfcs/pull/3513, https://github.com/rust-lang/rust/issues/117078).

### Technical note on the pre-generator-transform yield type:

The reason that the underlying coroutines yield `Poll<Option<T>>` and not `Poll<T>` (which would make more sense, IMO, for the pre-transformed coroutine), is because the `TransformVisitor` that is used to turn coroutines into built-in state machine functions would have to destructure and reconstruct the latter into the former, which requires at least inserting a new basic block (for a `switchInt` terminator, to match on the `Poll` discriminant).

This does mean that the desugaring (at the `rustc_ast_lowering` level) of `async gen` blocks is a bit more involved. However, since we already need to intercept both `.await` and `yield` operators, I don't consider it much of a technical burden.

r? `@ghost`
2023-12-08 19:13:57 +00:00
Michael Goulet
3ffacf75fe Make some matches exhaustive to avoid bugs, fix tools 2023-12-08 17:23:26 +00:00
Michael Goulet
6ebb66cea9 coro_kind -> coroutine_kind 2023-12-08 17:23:25 +00:00
bors
77bb46dedb 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
Eric Holk
f114bb42ec Address code review feedback 2023-12-04 14:33:46 -08:00
Eric Holk
13d284d177 Option<CoroutineKind> 2023-12-04 13:03:37 -08:00
Eric Holk
97fdae1034 Merge Async and Gen into CoroutineKind 2023-12-04 12:48:01 -08:00
Nadrieril
a445ba8a9d Parse a pattern with no arm 2023-12-03 12:25:46 +01:00
Matthias Krüger
1ab7fc99af Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errors
Add `never_patterns` feature gate

This PR adds the feature gate and most basic parsing for the experimental `never_patterns` feature. See the tracking issue (https://github.com/rust-lang/rust/issues/118155) for details on the experiment.

`@scottmcm` has agreed to be my lang-team liaison for this experiment.
2023-11-29 12:34:47 +01:00
Nadrieril
f2f243109b Add never_patterns feature gate 2023-11-29 03:58:29 +01:00
Nicholas Nethercote
d84d8d2604 Rework ast::BinOpKind::to_string and ast::UnOp::to_string.
- Rename them both `as_str`, which is the typical name for a function
  that returns a `&str`. (`to_string` is appropriate for functions
  returning `String` or maybe `Cow<'a, str>`.)
- Change `UnOp::as_str` from an associated function (weird!) to a
  method.
- Avoid needless `self` dereferences.
2023-11-28 09:42:07 +11:00
Deadbeef
24ce52a199 Add Span to TraitBoundModifier 2023-11-24 14:32:05 +00:00
Nicholas Nethercote
c043d0169d Update itertools to 0.11.
Because the API for `with_position` improved in 0.11 and I want to use
it.
2023-11-22 08:13:21 +11:00
Dinu Blanovschi
494560cb57 fixes for rustfmt + ast visitor 2023-11-04 20:39:15 +01:00
Oli Scherer
a3be235fcc Add gen blocks to ast and do some broken ast lowering 2023-10-27 13:05:48 +00:00
bors
d5bf53b454 Auto merge of #116033 - bvanjoi:fix-116032, r=petrochenkov
report `unused_import` for empty reexports even it is pub

Fixes #116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing #115993.)
2023-10-23 20:24:09 +00:00
Caleb Cartwright
04bd7201a9 Merge commit '81fe905ca83cffe84322f27ca43950b617861ff7' into rustfmt-sync 2023-10-22 20:21:44 -05:00
bohan
4335c28677 use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
Oli Scherer
7a20da333b Rename lots of files that had generator in their name 2023-10-20 21:14:02 +00:00
Oli Scherer
1b9dd4b4ad s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Michael Goulet
f867858755 Fix spans for comments in rustfmt 2023-10-04 21:09:54 +00:00
Matthew Jasper
e0d90ccd45 Update tools and fulldeps tests 2023-09-11 15:51:19 +00:00
Camille GILLOT
45e19aa80c Use relative positions inside a SourceFile. 2023-09-03 12:56:10 +00:00
John Kåre Alsaker
eb349e35aa Use conditional synchronization for Lock 2023-08-30 06:10:02 +02:00
Frank King
af6a6a3c2c Parse unnamed fields and anonymous structs or unions
Anonymous structs or unions are only allowed in struct field
definitions.

Co-authored-by: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com>
2023-08-24 11:17:54 +08:00
bors
327903e669 Auto merge of #114481 - matthiaskrgr:rollup-58pczpl, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #113945 (Fix wrong span for trait selection failure error reporting)
 - #114351 ([rustc_span][perf] Remove unnecessary string joins and allocs.)
 - #114418 (bump parking_lot to 0.12)
 - #114434 (Improve spans for indexing expressions)
 - #114450 (Fix ICE failed to get layout for ReferencesError)
 - #114461 (Fix unwrap on None)
 - #114462 (interpret: add mplace_to_ref helper method)
 - #114472 (Reword `confusable_idents` lint)
 - #114477 (Account for `Rc` and `Arc` when suggesting to clone)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-08-04 20:31:40 +00:00
Matthias Krüger
6e87f866ec 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
e3d6bf8daa Auto merge of #114104 - oli-obk:syn2, r=compiler-errors
Lots of tiny incremental simplifications of `EmitterWriter` internals

ignore the first commit, it's https://github.com/rust-lang/rust/pull/114088 squashed and rebased, but it's needed to use to use `derive_setters`, as they need a newer `syn` version.

Then this PR starts out with removing many arguments that are almost always defaulted to `None` or `false` and replace them with builder methods that can set these fields in the few cases that want to set them.

After that it's one commit after the other that removes or merges things until everything becomes some very simple trait objects
2023-08-04 18:46:19 +00:00
Nilstrieb
aca22c73fd 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
Matthias Krüger
4cc22af56c Rollup merge of #114300 - MU001999:fix/turbofish-pat, r=estebank
Suggests turbofish in patterns

Fixes #114112

r? ```@estebank```
2023-08-03 17:29:07 +02:00
Nicholas Nethercote
14101ed5a5 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
Mu001999
35d875a3a0 Fix rustfmt dep 2023-08-03 00:13:41 +08:00
Oli Scherer
aac383e3ea Use builder pattern instead of lots of arguments for EmitterWriter::new 2023-07-31 09:34:30 +00:00
bors
1f369f8b6a Auto merge of #114115 - nnethercote:less-token-tree-cloning, r=petrochenkov
Less `TokenTree` cloning

`TokenTreeCursor` has this comment on it:
```
// FIXME: Many uses of this can be replaced with by-reference iterator to avoid clones.
```
This PR completes that FIXME. It doesn't have much perf effect, but at least we now know that.

r? `@petrochenkov`
2023-07-28 01:21:27 +00:00
Nicholas Nethercote
e60a9e2c97 Avoid into_trees usage in rustfmt.
Token tree cloning is only needed in one place.
2023-07-27 11:58:42 +10:00
Trevor Gross
08fd1644d2 Unite bless environment variables under RUSTC_BLESS
Currently, Clippy, Miri, Rustfmt, and rustc all use an environment variable to
indicate that output should be blessed, but they use different variable names.
In order to improve consistency, this patch applies the following changes:

- Emit `RUSTC_BLESS` within `prepare_cargo_test` so it is always
  available
- Change usage of `MIRI_BLESS` in the Miri subtree to use `RUSTC_BLESS`
- Change usage of `BLESS` in the Clippy subtree to `RUSTC_BLESS`
- Change usage of `BLESS` in the Rustfmt subtree to `RUSTC_BLESS`
- Adjust the blessable test in `rustc_errors` to use this same
  convention
- Update documentation where applicable

Any tools that uses `RUSTC_BLESS` should check that it is set to any value
other than `"0"`.
2023-07-26 16:54:02 -04:00
Oli Scherer
c0ee8f5fea Make x test src/tools/rustfmt --bless format rustfmt with the freshly built in-tree version 2023-07-26 08:22:52 +00:00
Oli Scherer
a3dfd82559 Use a builder instead of boolean/option arguments 2023-07-25 13:51:15 +00:00
Esteban Küber
6013a8014b On nightly, dump ICE backtraces to disk
Implement rust-lang/compiler-team#578.

When an ICE is encountered on nightly releases, the new rustc panic
handler will also write the contents of the backtrace to disk. If any
`delay_span_bug`s are encountered, their backtrace is also added to the
file. The platform and rustc version will also be collected.
2023-07-19 14:10:07 +00:00
Caleb Cartwright
78331eefaf Merge commit 'dca1cf90ad6b8e45afbed2061803befbb2d159e9' into sync-rustfmt 2023-07-01 02:49:12 -05:00
Nilstrieb
80bf3ea542 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
Caleb Cartwright
ed3e96e3d1 Merge commit '3f7c366fc0464e01ddcaefbd70647cb3da4202be' into rustfmt-sync 2023-06-19 23:13:56 -05:00
Maybe Waffle
dc7dc3e74c Implement become expression formatting in rustfmt 2023-06-19 12:54:34 +00:00
Matthias Krüger
48e380fa40 Rollup merge of #110989 - jyn514:bug-report-url, r=WaffleLapkin
Make the BUG_REPORT_URL configurable by tools

This greatly simplifies how hard it is to set a custom bug report url; previously tools had to copy
the entire hook implementation.

I haven't changed clippy in case they want to make the change upstream instead of the subtree, but
I'm happy to do so here if the maintainers want - cc ````@rust-lang/clippy````

Fixes https://github.com/rust-lang/rust/issues/109486.
2023-05-06 13:30:04 +02:00