]> git.lizzy.rs Git - rust.git/log
rust.git
18 months agoRename `NestedMetaItem::[Ll]iteral` as `NestedMetaItem::[Ll]it`.
Nicholas Nethercote [Thu, 24 Nov 2022 04:00:09 +0000 (15:00 +1100)]
Rename `NestedMetaItem::[Ll]iteral` as `NestedMetaItem::[Ll]it`.

We already use a mix of `Literal` and `Lit`. The latter is better
because it is shorter without causing any ambiguity.

18 months agoRename `ast::Lit` as `ast::MetaItemLit`.
Nicholas Nethercote [Wed, 23 Nov 2022 04:39:42 +0000 (15:39 +1100)]
Rename `ast::Lit` as `ast::MetaItemLit`.

18 months agoFix rustfmt
Esteban Küber [Thu, 3 Nov 2022 21:22:35 +0000 (14:22 -0700)]
Fix rustfmt

18 months agoSplit `MacArgs` in two.
Nicholas Nethercote [Fri, 18 Nov 2022 00:24:21 +0000 (11:24 +1100)]
Split `MacArgs` in two.

`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's
used in two ways:
- For representing attribute macro arguments (e.g. in `AttrItem`), where all
  three variants are used.
- For representing function-like macros (e.g. in `MacCall` and `MacroDef`),
  where only the `Delimited` variant is used.

In other words, `MacArgs` is used in two quite different places due to them
having partial overlap. I find this makes the code hard to read. It also leads
to various unreachable code paths, and allows invalid values (such as
accidentally using `MacArgs::Empty` in a `MacCall`).

This commit splits `MacArgs` in two:
- `DelimArgs` is a new struct just for the "delimited arguments" case. It is
  now used in `MacCall` and `MacroDef`.
- `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro
  case. Its `Delimited` variant now contains a `DelimArgs`.

Various other related things are renamed as well.

These changes make the code clearer, avoids several unreachable paths, and
disallows the invalid values.

19 months agoBox `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and patterns.
Nicholas Nethercote [Thu, 8 Sep 2022 00:52:51 +0000 (10:52 +1000)]
Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and patterns.

19 months agoUse `token::Lit` in `ast::ExprKind::Lit`.
Nicholas Nethercote [Mon, 10 Oct 2022 02:40:56 +0000 (13:40 +1100)]
Use `token::Lit` in `ast::ExprKind::Lit`.

Instead of `ast::Lit`.

Literal lowering now happens at two different times. Expression literals
are lowered when HIR is crated. Attribute literals are lowered during
parsing.

This commit changes the language very slightly. Some programs that used
to not compile now will compile. This is because some invalid literals
that are removed by `cfg` or attribute macros will no longer trigger
errors. See this comment for more details:
https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773

19 months agoIntroduce `ExprKind::IncludedBytes`
clubby789 [Mon, 31 Oct 2022 18:30:09 +0000 (18:30 +0000)]
Introduce `ExprKind::IncludedBytes`

19 months agoAuto merge of #103217 - mejrs:track, r=eholk
bors [Tue, 1 Nov 2022 21:09:45 +0000 (21:09 +0000)]
Auto merge of #103217 - mejrs:track, r=eholk

Track where diagnostics were created.

This implements the `-Ztrack-diagnostics` flag, which uses `#[track_caller]` to track where diagnostics are created. It is meant as a debugging tool much like `-Ztreat-err-as-bug`.

For example, the following code...

```rust
struct A;
struct B;

fn main(){
    let _: A = B;
}
```
...now emits the following error message:

```
error[E0308]: mismatched types
 --> src\main.rs:5:16
  |
5 |     let _: A = B;
  |            -   ^ expected struct `A`, found struct `B`
  |            |
  |            expected due to this
-Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31
```

20 months agomerge rustc history
Ralf Jung [Fri, 21 Oct 2022 08:18:54 +0000 (10:18 +0200)]
merge rustc history

20 months agoImplement -Ztrack-diagnostics
mejrs [Tue, 18 Oct 2022 22:08:20 +0000 (00:08 +0200)]
Implement -Ztrack-diagnostics

20 months agomerge rustc history
Ralf Jung [Wed, 12 Oct 2022 17:53:57 +0000 (19:53 +0200)]
merge rustc history

20 months agoFix unclosed HTML tag in rustfmt doc
Guillaume Gomez [Mon, 10 Oct 2022 16:29:17 +0000 (18:29 +0200)]
Fix unclosed HTML tag in rustfmt doc

20 months agomerge rustc history
Ralf Jung [Mon, 10 Oct 2022 15:50:32 +0000 (17:50 +0200)]
merge rustc history

20 months agoRename AssocItemKind::TyAlias to AssocItemKind::Type
Michael Goulet [Mon, 10 Oct 2022 02:05:24 +0000 (02:05 +0000)]
Rename AssocItemKind::TyAlias to AssocItemKind::Type

21 months agoAuto merge of #96709 - jackh726:gats-stabilization, r=compiler-errors
bors [Tue, 13 Sep 2022 09:39:41 +0000 (09:39 +0000)]
Auto merge of #96709 - jackh726:gats-stabilization, r=compiler-errors

Stabilize generic associated types

Closes #44265

r? `@nikomatsakis`

# ⚡ Status of the discussion ⚡

* [x] There have been several serious concerns raised, [summarized here](https://github.com/rust-lang/rust/pull/96709#issuecomment-1129311660).
* [x] There has also been a [deep-dive comment](https://github.com/rust-lang/rust/pull/96709#issuecomment-1167220240) explaining some of the "patterns of code" that are enabled by GATs, based on use-cases posted to this thread or on the tracking issue.
* [x] We have modeled some aspects of GATs in [a-mir-formality](https://github.com/nikomatsakis/a-mir-formality) to give better confidence in how they will be resolved in the future. [You can read a write-up here](https://github.com/rust-lang/types-team/blob/master/minutes/2022-07-08-implied-bounds-and-wf-checking.md).
* [x] The major points of the discussion have been [summarized on the GAT initiative repository](https://rust-lang.github.io/generic-associated-types-initiative/mvp.html).
* [x] [FCP has been proposed](https://github.com/rust-lang/rust/pull/96709#issuecomment-1129311660) and we are awaiting final decisions and discussion amidst the relevant team members.

# Stabilization proposal

This PR proposes the stabilization of `#![feature(generic_associated_types)]`. While there a number of future additions to be made and bugs to be fixed (both discussed below), properly doing these will require significant language design and will ultimately likely be backwards-compatible. Given the overwhelming desire to have some form of generic associated types (GATs) available on stable and the stability of the "simple" uses, stabilizing the current subset of GAT features is almost certainly the correct next step.

Tracking issue: #44265
Initiative: https://rust-lang.github.io/generic-associated-types-initiative/
RFC: https://github.com/rust-lang/rfcs/blob/master/text/1598-generic_associated_types.md
Version: 1.65 (2022-08-22 => beta, 2022-11-03 => stable).

## Motivation

There are a myriad of potential use cases for GATs. Stabilization unblocks probable future language features (e.g. async functions in traits), potential future standard library features (e.g. a `LendingIterator` or some form of `Iterator` with a lifetime generic), and a plethora of user use cases (some of which can be seen just by scrolling through the tracking issue and looking at all the issues linking to it).

There are a myriad of potential use cases for GATs. First, there are many users that have chosen to not use GATs primarily because they are not stable (some of which can be seen just by scrolling through the tracking issue and looking at all the issues linking to it). Second, while language feature desugaring isn't *blocked* on stabilization, it gives more confidence on using the feature. Likewise, library features like `LendingIterator` are not necessarily blocked on stabilization to be implemented unstably; however few, if any, public-facing APIs actually use unstable features.

This feature has a long history of design, discussion, and developement - the RFC was first introduced roughly 6 years ago. While there are still a number of features left to implement and bugs left to fix, it's clear that it's unlikely those will have backwards-incompatibility concerns. Additionally, the bugs that do exist do not strongly impede the most-common use cases.

## What is stabilized

The primary language feature stabilized here is the ability to have generics on associated types, as so. Additionally, where clauses on associated types will now be accepted, regardless if the associated type is generic or not.

```rust
trait ATraitWithGATs {
    type Assoc<'a, T> where T: 'a;
}

trait ATraitWithoutGATs<'a, T> {
    type Assoc where T: 'a;
}
```

When adding an impl for a trait with generic associated types, the generics for the associated type are copied as well. Note that where clauses are allowed both after the specified type and before the equals sign; however, the latter is a warn-by-default deprecation.

```rust
struct X;
struct Y;

impl ATraitWithGATs for X {
    type Assoc<'a, T> = &'a T
      where T: 'a;
}
impl ATraitWithGATs for Y {
    type Assoc<'a, T>
      where T: 'a
    = &'a T;
}
```

To use a GAT in a function, generics are specified on the associated type, as if it was a struct or enum. GATs can also be specified in trait bounds:

```rust
fn accepts_gat<'a, T>(t: &'a T) -> T::Assoc<'a, T>
  where for<'x> T: ATraitWithGATs<Assoc<'a, T> = &'a T> {
    ...
}
```

GATs can also appear in trait methods. However, depending on how they are used, they may confer where clauses on the associated type definition. More information can be found [here](https://github.com/rust-lang/rust/issues/87479). Briefly, where clauses are required when those bounds can be proven in the methods that *construct* the GAT or other associated types that use the GAT in the trait. This allows impls to have maximum flexibility in the types defined for the associated type.

To take a relatively simple example:

```rust
trait Iterable {
    type Item<'a>;
    type Iterator<'a>: Iterator<Item = Self::Item<'a>>;

    fn iter<'x>(&'x self) -> Self::Iterator<'x>;
    //^ We know that `Self: 'a` for `Iterator<'a>`, so we require that bound on `Iterator`
    //  `Iterator` uses `Self::Item`, so we also require a `Self: 'a` on `Item` too
}
```

A couple well-explained examples are available in a previous [blog post](https://blog.rust-lang.org/2021/08/03/GATs-stabilization-push.html).

## What isn't stabilized/implemented

### Universal type/const quantification

Currently, you can write a bound like `X: for<'a> Trait<Assoc<'a> = &'a ()>`. However, you cannot currently write `for<T> X: Trait<Assoc<T> = T>` or `for<const N> X: Trait<Assoc<N> = [usize; N]>`.

Here is an example where this is needed:

```rust
trait Foo {}

trait Trait {
    type Assoc<F: Foo>;
}

trait Trait2: Sized {
    fn foo<F: Foo, T: Trait<Assoc<F> = F>>(_t: T);
}
```

In the above example, the *caller* must specify `F`, which is likely not what is desired.

### Object-safe GATs

Unlike non-generic associated types, traits with GATs are not currently object-safe. In other words the following are not allowed:

```rust
trait Trait {
    type Assoc<'a>;
}

fn foo(t: &dyn for<'a> Trait<Assoc<'a> = &'a ()>) {}
         //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not allowed

let ty: Box<dyn for<'a> Trait<Assoc<'a> = &'a ()>>;
          //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not allowed
```

### Higher-kinded types

You cannot write currently (and there are no current plans to implement this):

```rust
struct Struct<'a> {}

fn foo(s: for<'a> Struct<'a>) {}
```

## Tests

There are many tests covering GATs that can be found in  `src/test/ui/generic-associated-types`. Here, I'll list (in alphanumeric order) tests highlight some important behavior or contain important patterns.

- `./parse/*`: Parsing of GATs in traits and impls, and the trait path with GATs
- `./collections-project-default.rs`: Interaction with associated type defaults
- `./collections.rs`: The `Collection` pattern
- `./const-generics-gat-in-trait-return-type-*.rs`: Const parameters
- `./constraint-assoc-type-suggestion.rs`: Emit correct syntax in suggestion
- `./cross-crate-bounds.rs`: Ensure we handles bounds across crates the same
- `./elided-in-expr-position.rs`: Disallow lifetime elision in return position
- `./gat-in-trait-path-undeclared-lifetime.rs`: Ensure we error on undeclared lifetime in trait path
- `./gat-in-trait-path.rs`: Base trait path case
- `./gat-trait-path-generic-type-arg.rs`: Don't allow shadowing of parameters
- `./gat-trait-path-parenthesised-args.rs`: Don't allow paranthesized args in trait path
- `./generic-associated-types-where.rs`: Ensure that we require where clauses from trait to be met on impl
- `./impl_bounds.rs`: Check that the bounds on GATs in an impl are checked
- `./issue-76826.rs`: `Windows` pattern
- `./issue-78113-lifetime-mismatch-dyn-trait-box.rs`: Implicit 'static diagnostics
- `./issue-84931.rs`: Ensure that we have a where clause on GAT to ensure trait parameter lives long enough
- `./issue-87258_a.rs`: Unconstrained opaque type with TAITs
- `./issue-87429-2.rs`: Ensure we can use bound vars in the bounds
- `./issue-87429-associated-type-default.rs`: Ensure bounds hold with associated type defaults, for both trait and impl
- `./issue-87429-specialization.rs`: Check that bounds hold under specialization
- `./issue-88595.rs`: Under the outlives lint, we require a bound for both trait and GAT lifetime when trait lifetime is used in function
- `./issue-90014.rs`: Lifetime bounds are checked with TAITs
- `./issue-91139.rs`: Under migrate mode, but not NLL, we don't capture implied bounds from HRTB lifetimes used in a function and GATs
- `./issue-91762.rs`: We used to too eagerly pick param env candidates when normalizing with GATs. We now require explicit parameters specified.
- `./issue-95305.rs`: Disallow lifetime elision in trait paths
- `./iterable.rs`: `Iterable` pattern
- `./method-unsatified-assoc-type-predicate.rs`: Print predicates with GATs correctly in method resolve error
- `./missing_lifetime_const.rs`: Ensure we must specify lifetime args (not elidable)
- `./missing-where-clause-on-trait.rs`: Ensure we don't allow stricter bounds on impl than trait
- `./parameter_number_and_kind_impl.rs`: Ensure paramters on GAT in impl match GAT in trait
- `./pointer_family.rs`: `PointerFamily` pattern
- `./projection-bound-cycle.rs`: Don't allow invalid cycles to prove bounds
- `./self-outlives-lint.rs`: Ensures that an e.g. `Self: 'a` is written on the traits GAT if that bound can be implied from the GAT usage in the trait
- `./shadowing.rs`: Don't allow lifetime shadowing in params
- `./streaming_iterator.rs`: `StreamingIterator`(`LendingIterator`) pattern
- `./trait-objects.rs`: Disallow trait objects for traits with GATs
- `./variance_constraints.rs`: Require that GAT substs be invariant

## Remaining bugs and open issues

A full list of remaining open issues can be found at: https://github.com/rust-lang/rust/labels/F-generic_associated_types

There are some `known-bug` tests in-tree at `src/test/ui/generic-associated-types/bugs`.

Here I'll categorize most of those that GAT bugs (or involve a pattern found more with GATs), but not those that include GATs but not a GAT issue in and of itself. (I also won't include issues directly for things listed elsewhere here.)

Using the concrete type of a GAT instead of the projection type can give errors, since lifetimes are chosen to be early-bound vs late-bound.
- #85533
- #87803

In certain cases, we can run into cycle or overflow errors. This is more generally a problem with associated types.
- #87755
- #87758

Bounds on an associatd type need to be proven by an impl, but where clauses need to be proven by the usage. This can lead to confusion when users write one when they mean the other.
- #87831
- #90573

We sometimes can't normalize closure signatures fully. Really an asociated types issue, but might happen a bit more frequently with GATs, since more obvious place for HRTB lifetimes.
- #88382

When calling a function, we assign types to parameters "too late", after we already try (and fail) to normalize projections. Another associated types issue that might pop up more with GATs.
- #88460
- #96230

We don't fully have implied bounds for lifetimes appearing in GAT trait paths, which can lead to unconstrained type errors.
- #88526

Suggestion for adding lifetime bounds can suggest unhelpful fixes (`T: 'a` instead of `Self: 'a`), but the next compiler error after making the suggested change is helpful.
- #90816
- #92096
- #95268

We can end up requiring that `for<'a> I: 'a` when we really want `for<'a where I: 'a> I: 'a`. This can leave unhelpful errors than effectively can't be satisfied unless `I: 'static`. Requires bigger changes and not only GATs.
- #91693

Unlike with non-generic associated types, we don't eagerly normalize with param env candidates. This is intended behavior (for now), to avoid accidentaly stabilizing picking arbitrary impls.
- #91762

Some Iterator adapter patterns (namely `filter`) require Polonius or unsafe to work.
- #92985

## Potential Future work

### Universal type/const quantification

No work has been done to implement this. There are also some questions around implied bounds.

###  Object-safe GATs

The intention is to make traits with GATs object-safe. There are some design work to be done around well-formedness rules and general implementation.

### GATified std lib types

It would be helpful to either introduce new std lib traits (like `LendingIterator`) or to modify existing ones (adding a `'a` generic to `Iterator::Item`). There also a number of other candidates, like `Index`/`IndexMut` and `Fn`/`FnMut`/`FnOnce`.

### Reduce the need for `for<'a>`

Seen [here](https://github.com/rust-lang/rfcs/pull/1598#issuecomment-2611378730). One possible syntax:

```rust
trait Iterable {
    type Iter<'a>: Iterator<Item = Self::Item<'a>>;
}

fn foo<T>() where T: Iterable, T::Item<let 'a>: Display { } //note the `let`!
```

### Better implied bounds on higher-ranked things

Currently if we have a `type Item<'a> where self: 'a`, and a `for<'a> T: Iterator<Item<'a> = &'a ()`, this requires `for<'a> Self: 'a`. Really, we want `for<'a where T: 'a> ...`

There was some mentions of this all the back in the RFC thread [here](https://github.com/rust-lang/rfcs/pull/1598#issuecomment-264340514).

## Alternatives

### Make generics on associated type in bounds a binder

Imagine the bound `for<'a> T: Trait<Item<'a>= &'a ()>`. It might be that `for<'a>` is "too large" and it should instead be `T: Trait<for<'a> Item<'a>= &'a ()>`. Brought up in RFC thread [here](https://github.com/rust-lang/rfcs/pull/1598#issuecomment-229443863) and in a few places since.

Another related question: Is `for<'a>` the right syntax? Maybe `where<'a>`? Also originally found in RFC thread [here](https://github.com/rust-lang/rfcs/pull/1598#issuecomment-261639969).

### Stabilize lifetime GATs first

This has been brought up a few times. The idea is to only allow GATs with lifetime parameters to in initial stabilization. This was probably most useful prior to actual implementation. At this point, lifetimes, types, and consts are all implemented and work. It feels like an arbitrary split without strong reason.

## History

* On 2016-04-30, [RFC opened](https://github.com/rust-lang/rfcs/pull/1598)
* On 2017-09-02, RFC merged and [tracking issue opened](https://github.com/rust-lang/rust/issues/44265)
* On 2017-10-23, [Move Generics from MethodSig to TraitItem and ImplItem](https://github.com/rust-lang/rust/pull/44766)
* On 2017-12-01, [Generic Associated Types Parsing & Name Resolution](https://github.com/rust-lang/rust/pull/45904)
* On 2017-12-15, [https://github.com/rust-lang/rust/pull/46706](https://github.com/rust-lang/rust/pull/46706)
* On 2018-04-23, [Feature gate where clauses on associated types](https://github.com/rust-lang/rust/pull/49368)
* On 2018-05-10, [Extend tests for RFC1598 (GAT)](https://github.com/rust-lang/rust/pull/49423)
* On 2018-05-24, [Finish implementing GATs (Chalk)](https://github.com/rust-lang/chalk/pull/134)
* On 2019-12-21, [Make GATs less ICE-prone](https://github.com/rust-lang/rust/pull/67160)
* On 2020-02-13, [fix lifetime shadowing check in GATs](https://github.com/rust-lang/rust/pull/68938)
* On 2020-06-20, [Projection bound validation](https://github.com/rust-lang/rust/pull/72788)
* On 2020-10-06, [Separate projection bounds and predicates](https://github.com/rust-lang/rust/pull/73905)
* On 2021-02-05, [Generic associated types in trait paths](https://github.com/rust-lang/rust/pull/79554)
* On 2021-02-06, [Trait objects do not work with generic associated types](https://github.com/rust-lang/rust/issues/81823)
* On 2021-04-28, [Make traits with GATs not object safe](https://github.com/rust-lang/rust/pull/84622)
* On 2021-05-11, [Improve diagnostics for GATs](https://github.com/rust-lang/rust/pull/82272)
* On 2021-07-16, [Make GATs no longer an incomplete feature](https://github.com/rust-lang/rust/pull/84623)
* On 2021-07-16, [Replace associated item bound vars with placeholders when projecting](https://github.com/rust-lang/rust/pull/86993)
* On 2021-07-26, [GATs: Decide whether to have defaults for `where Self: 'a`](https://github.com/rust-lang/rust/issues/87479)
* On 2021-08-25, [Normalize projections under binders](https://github.com/rust-lang/rust/pull/85499)
* On 2021-08-03, [The push for GATs stabilization](https://blog.rust-lang.org/2021/08/03/GATs-stabilization-push.html)
* On 2021-08-12, [Detect stricter constraints on gats where clauses in impls vs trait](https://github.com/rust-lang/rust/pull/88336)
* On 2021-09-20, [Proposal: Change syntax of where clauses on type aliases](https://github.com/rust-lang/rust/issues/89122)
* On 2021-11-06, [Implementation of GATs outlives lint](https://github.com/rust-lang/rust/pull/89970)
* On 2021-12-29. [Parse and suggest moving where clauses after equals for type aliases](https://github.com/rust-lang/rust/pull/92118)
* On 2022-01-15, [Ignore static lifetimes for GATs outlives lint](https://github.com/rust-lang/rust/pull/92865)
* On 2022-02-08, [Don't constrain projection predicates with inference vars in GAT substs](https://github.com/rust-lang/rust/pull/92917)
* On 2022-02-15, [Rework GAT where clause check](https://github.com/rust-lang/rust/pull/93820)
* On 2022-02-19, [Only mark projection as ambiguous if GAT substs are constrained](https://github.com/rust-lang/rust/pull/93892)
* On 2022-03-03, [Support GATs in Rustdoc](https://github.com/rust-lang/rust/pull/94009)
* On 2022-03-06, [Change location of where clause on GATs](https://github.com/rust-lang/rust/pull/90076)
* On 2022-05-04, [A shiny future with GATs blog post](https://jackh726.github.io/rust/2022/05/04/a-shiny-future-with-gats.html)
* On 2022-05-04, [Stabilization PR](https://github.com/rust-lang/rust/pull/96709)

21 months agorustfmt: BindingAnnotation change
Cameron Steffen [Tue, 30 Aug 2022 22:39:36 +0000 (17:39 -0500)]
rustfmt: BindingAnnotation change

21 months agoStabilize GATs
Jack Huey [Wed, 4 May 2022 14:22:19 +0000 (10:22 -0400)]
Stabilize GATs

21 months agoSunset RLS
Eric Huss [Sun, 21 Aug 2022 04:19:43 +0000 (21:19 -0700)]
Sunset RLS

21 months agoRollup merge of #99332 - jyn514:stabilize-label-break-value, r=petrochenkov
Yuki Okushi [Wed, 24 Aug 2022 23:50:54 +0000 (08:50 +0900)]
Rollup merge of #99332 - jyn514:stabilize-label-break-value, r=petrochenkov

Stabilize `#![feature(label_break_value)]`

See the stabilization report in https://github.com/rust-lang/rust/issues/48594#issuecomment-1186213313.

21 months agoStabilize `#![feature(label_break_value)]`
Joshua Nelson [Thu, 14 Jul 2022 13:30:38 +0000 (08:30 -0500)]
Stabilize `#![feature(label_break_value)]`

 # Stabilization proposal

The feature was implemented in https://github.com/rust-lang/rust/pull/50045 by est31 and has been in nightly since 2018-05-16 (over 4 years now).
There are [no open issues][issue-label] other than the tracking issue. There is a strong consensus that `break` is the right keyword and we should not use `return`.

There have been several concerns raised about this feature on the tracking issue (other than the one about tests, which has been fixed, and an interaction with try blocks, which has been fixed).
1. nrc's original comment about cost-benefit analysis: https://github.com/rust-lang/rust/issues/48594#issuecomment-422235234
2. joshtriplett's comments about seeing use cases: https://github.com/rust-lang/rust/issues/48594#issuecomment-422281176
3. withoutboats's comments that Rust does not need more control flow constructs: https://github.com/rust-lang/rust/issues/48594#issuecomment-450050630

Many different examples of code that's simpler using this feature have been provided:
- A lexer by rpjohnst which must repeat code without label-break-value: https://github.com/rust-lang/rust/issues/48594#issuecomment-422502014
- A snippet by SergioBenitez which avoids using a new function and adding several new return points to a function: https://github.com/rust-lang/rust/issues/48594#issuecomment-427628251. This particular case would also work if `try` blocks were stabilized (at the cost of making the code harder to optimize).
- Several examples by JohnBSmith: https://github.com/rust-lang/rust/issues/48594#issuecomment-434651395
- Several examples by Centril: https://github.com/rust-lang/rust/issues/48594#issuecomment-440154733
- An example by petrochenkov where this is used in the compiler itself to avoid duplicating error checking code: https://github.com/rust-lang/rust/issues/48594#issuecomment-443557569
- Amanieu recently provided another example related to complex conditions, where try blocks would not have helped: https://github.com/rust-lang/rust/issues/48594#issuecomment-1184213006

Additionally, petrochenkov notes that this is strictly more powerful than labelled loops due to macros which accidentally exit a loop instead of being consumed by the macro matchers: https://github.com/rust-lang/rust/issues/48594#issuecomment-450246249

nrc later resolved their concern, mostly because of the aforementioned macro problems.
joshtriplett suggested that macros could be able to generate IR directly
(https://github.com/rust-lang/rust/issues/48594#issuecomment-451685983) but there are no open RFCs,
and the design space seems rather speculative.

joshtriplett later resolved his concerns, due to a symmetry between this feature and existing labelled break: https://github.com/rust-lang/rust/issues/48594#issuecomment-632960804

withoutboats has regrettably left the language team.

joshtriplett later posted that the lang team would consider starting an FCP given a stabilization report: https://github.com/rust-lang/rust/issues/48594#issuecomment-1111269353

[issue-label]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AF-label_break_value+

 ## Report

+ Feature gate:
    - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/src/test/ui/feature-gates/feature-gate-label_break_value.rs
+ Diagnostics:
    - https://github.com/rust-lang/rust/blob/6b2d3d5f3cd1e553d87b5496632132565b6779d3/compiler/rustc_parse/src/parser/diagnostics.rs#L2629
    - https://github.com/rust-lang/rust/blob/f65bf0b2bb1a99f73095c01a118f3c37d3ee614c/compiler/rustc_resolve/src/diagnostics.rs#L749
    - https://github.com/rust-lang/rust/blob/f65bf0b2bb1a99f73095c01a118f3c37d3ee614c/compiler/rustc_resolve/src/diagnostics.rs#L1001
    - https://github.com/rust-lang/rust/blob/111df9e6eda1d752233482c1309d00d20a4bbf98/compiler/rustc_passes/src/loops.rs#L254
    - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/compiler/rustc_parse/src/parser/expr.rs#L2079
    - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/compiler/rustc_parse/src/parser/expr.rs#L1569
+ Tests:
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_continue.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_unlabeled_break.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_illegal_uses.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/lint/unused_labels.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/run-pass/for-loop-while/label_break_value.rs

 ## Interactions with other features

Labels follow the hygiene of local variables.

label-break-value is permitted within `try` blocks:
```rust
let _: Result<(), ()> = try {
    'foo: {
        Err(())?;
        break 'foo;
    }
};
```

label-break-value is disallowed within closures, generators, and async blocks:
```rust
'a: {
    || break 'a
    //~^ ERROR use of unreachable label `'a`
    //~| ERROR `break` inside of a closure
}
```

label-break-value is disallowed on [_BlockExpression_]; it can only occur as a [_LoopExpression_]:
```rust
fn labeled_match() {
    match false 'b: { //~ ERROR block label not supported here
        _ => {}
    }
}

macro_rules! m {
    ($b:block) => {
        'lab: $b; //~ ERROR cannot use a `block` macro fragment here
        unsafe $b; //~ ERROR cannot use a `block` macro fragment here
        |x: u8| -> () $b; //~ ERROR cannot use a `block` macro fragment here
    }
}

fn foo() {
    m!({});
}
```

[_BlockExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/block-expr.html
[_LoopExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/loop-expr.html

22 months agoUse `AttrVec` in more places.
Nicholas Nethercote [Wed, 17 Aug 2022 02:34:33 +0000 (12:34 +1000)]
Use `AttrVec` in more places.

In some places we use `Vec<Attribute>` and some places we use
`ThinVec<Attribute>` (a.k.a. `AttrVec`). This results in various points
where we have to convert between `Vec` and `ThinVec`.

This commit changes the places that use `Vec<Attribute>` to use
`AttrVec`. A lot of this is mechanical and boring, but there are
some interesting parts:
- It adds a few new methods to `ThinVec`.
- It implements `MapInPlace` for `ThinVec`, and introduces a macro to
  avoid the repetition of this trait for `Vec`, `SmallVec`, and
  `ThinVec`.

Overall, it makes the code a little nicer, and has little effect on
performance. But it is a precursor to removing
`rustc_data_structures::thin_vec::ThinVec` and replacing it with
`thin_vec::ThinVec`, which is implemented more efficiently.

22 months agoRollup merge of #100379 - davidtwco:triagebot-diag, r=Mark-Simulacrum
Matthias Krüger [Wed, 17 Aug 2022 10:32:50 +0000 (12:32 +0200)]
Rollup merge of #100379 - davidtwco:triagebot-diag, r=Mark-Simulacrum

triagebot: add translation-related mention groups

- Move some code around so that triagebot can ping relevant parties when translation logic is modified.
- Add mention groups to triagebot for translation-related files/folders.
- Auto-label pull requests with changes to translation-related files/folders with `A-translation`.

r? `@Mark-Simulacrum`

22 months agoRollup merge of #100018 - nnethercote:clean-up-LitKind, r=petrochenkov
Matthias Krüger [Wed, 17 Aug 2022 10:32:49 +0000 (12:32 +0200)]
Rollup merge of #100018 - nnethercote:clean-up-LitKind, r=petrochenkov

Clean up `LitKind`

r? ``@petrochenkov``

22 months agoRename some things related to literals.
Nicholas Nethercote [Mon, 1 Aug 2022 06:46:08 +0000 (16:46 +1000)]
Rename some things related to literals.

- Rename `ast::Lit::token` as `ast::Lit::token_lit`, because its type is
  `token::Lit`, which is not a token. (This has been confusing me for a
  long time.)
  reasonable because we have an `ast::token::Lit` inside an `ast::Lit`.
- Rename `LitKind::{from,to}_lit_token` as
  `LitKind::{from,to}_token_lit`, to match the above change and
  `token::Lit`.

22 months agoShrink `ast::Attribute`.
Nicholas Nethercote [Thu, 11 Aug 2022 11:06:11 +0000 (21:06 +1000)]
Shrink `ast::Attribute`.

22 months agoerrors: move translation logic into module
David Wood [Wed, 10 Aug 2022 16:30:47 +0000 (17:30 +0100)]
errors: move translation logic into module

Just moving code around so that triagebot can ping relevant parties when
translation logic is modified.

Signed-off-by: David Wood <david.wood@huawei.com>
22 months agoDo not consider method call receiver as an argument in AST.
Camille GILLOT [Sun, 7 Aug 2022 13:21:11 +0000 (15:21 +0200)]
Do not consider method call receiver as an argument in AST.

22 months agoRemove `TreeAndSpacing`.
Nicholas Nethercote [Thu, 28 Jul 2022 00:31:04 +0000 (10:31 +1000)]
Remove `TreeAndSpacing`.

A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is
not quite right. `Spacing` makes sense for `TokenTree::Token`, but does
not make sense for `TokenTree::Delimited`, because a
`TokenTree::Delimited` cannot be joined with another `TokenTree`.

This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`,
changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the
`TreeAndSpacing` typedef.

The commit removes these two impls:
- `impl From<TokenTree> for TokenStream`
- `impl From<TokenTree> for TreeAndSpacing`

These were useful, but also resulted in code with many `.into()` calls
that was hard to read, particularly for anyone not highly familiar with
the relevant types. This commit makes some other changes to compensate:
- `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`.
- `TokenStream::token_{alone,joint}()` are added.
- `TokenStream::delimited` is added.

This results in things like this:
```rust
TokenTree::token(token::Semi, stmt.span).into()
```
changing to this:
```rust
TokenStream::token_alone(token::Semi, stmt.span)
```
This makes the type of the result, and its spacing, clearer.

These changes also simplifies `Cursor` and `CursorRef`, because they no longer
need to distinguish between `next` and `next_with_spacing`.

23 months agoAdd rustfmt test for formatting `for<>` before closures
Maybe Waffle [Sun, 3 Jul 2022 12:11:46 +0000 (16:11 +0400)]
Add rustfmt test for formatting `for<>` before closures

23 months agoimplement rustfmt formatting for `for<>` closure binders
Maybe Waffle [Thu, 30 Jun 2022 13:40:38 +0000 (17:40 +0400)]
implement rustfmt formatting for `for<>` closure binders

23 months agoast: Add span to `Extern`
Nixon Enraght-Moony [Sat, 2 Jul 2022 17:25:55 +0000 (18:25 +0100)]
ast: Add span to `Extern`

23 months agoMerge commit 'c4416f20dcaec5d93077f72470e83e150fb923b1' into sync-rustfmt
Caleb Cartwright [Thu, 23 Jun 2022 03:14:32 +0000 (22:14 -0500)]
Merge commit 'c4416f20dcaec5d93077f72470e83e150fb923b1' into sync-rustfmt

2 years agoRollup merge of #97757 - xFrednet:rfc-2383-expect-with-force-warn, r=wesleywiser...
Matthias Krüger [Thu, 16 Jun 2022 07:10:20 +0000 (09:10 +0200)]
Rollup merge of #97757 - xFrednet:rfc-2383-expect-with-force-warn, r=wesleywiser,flip1995

Support lint expectations for `--force-warn` lints (RFC 2383)

Rustc has a `--force-warn` flag, which overrides lint level attributes and forces the diagnostics to always be warn. This means, that for lint expectations, the diagnostic can't be suppressed as usual. This also means that the expectation would not be fulfilled, even if a lint had been triggered in the expected scope.

This PR now also tracks the expectation ID in the `ForceWarn` level. I've also made some minor adjustments, to possibly catch more bugs and make the whole implementation more robust.

This will probably conflict with https://github.com/rust-lang/rust/pull/97718. That PR should ideally be reviewed and merged first. The conflict itself will be trivial to fix.

---

r? `@wesleywiser`

cc: `@flip1995` since you've helped with the initial review and also discussed this topic with me. :upside_down_face:

Follow-up of: https://github.com/rust-lang/rust/pull/87835

Issue: https://github.com/rust-lang/rust/issues/85549

Yeah, and that's it.

2 years agoSupport lint expectations for `--force-warn` lints (RFC 2383)
xFrednet [Sun, 5 Jun 2022 10:33:45 +0000 (12:33 +0200)]
Support lint expectations for `--force-warn` lints (RFC 2383)

2 years agoMerge commit '7b73b60faca71d01d900e49831fcb84553e93019' into sync-rustfmt
Caleb Cartwright [Mon, 13 Jun 2022 03:03:05 +0000 (22:03 -0500)]
Merge commit '7b73b60faca71d01d900e49831fcb84553e93019' into sync-rustfmt

2 years agoMerge crate and restricted visibilities
Jacob Pratt [Sat, 21 May 2022 18:45:14 +0000 (14:45 -0400)]
Merge crate and restricted visibilities

2 years agoRemove feature: `crate` visibility modifier
Jacob Pratt [Sat, 21 May 2022 17:53:26 +0000 (13:53 -0400)]
Remove feature: `crate` visibility modifier

2 years agoRemove `crate` visibility modifier in libs, tests
Jacob Pratt [Sat, 21 May 2022 01:06:44 +0000 (21:06 -0400)]
Remove `crate` visibility modifier in libs, tests

2 years agoFix typo
ydah [Fri, 20 May 2022 01:39:10 +0000 (10:39 +0900)]
Fix typo

This PR is fixes typo "avaiable" to "available".

2 years agofix rustfmt
klensy [Wed, 18 May 2022 16:02:06 +0000 (19:02 +0300)]
fix rustfmt

2 years agoast: Introduce some traits to get AST node properties generically
Vadim Petrochenkov [Sun, 1 May 2022 17:58:24 +0000 (20:58 +0300)]
ast: Introduce some traits to get AST node properties generically

And use them to avoid constructing some artificial `Nonterminal` tokens during expansion

2 years agoRollup merge of #96543 - nnethercote:rm-make_token_stream-hacks, r=Aaron1011
Yuki Okushi [Wed, 11 May 2022 04:16:30 +0000 (13:16 +0900)]
Rollup merge of #96543 - nnethercote:rm-make_token_stream-hacks, r=Aaron1011

Remove hacks in `make_token_stream`.

`make_tokenstream` has three commented hacks, and a comment at the top
referring to #67062. These hacks have no observable effect, at least as judged
by running the test suite. The hacks were added in #82608, with an explanation
[here](https://github.com/rust-lang/rust/pull/82608#issuecomment-812877329). It
appears that one of the following is true: (a) they never did anything useful,
(b) they do something useful but we have no test coverage for them, or (c)
something has changed in the meantime that means they are no longer necessary.

This commit removes the hacks and the comments, in the hope that (b) is not
true.

r? `@Aaron1011`

2 years agoRemove some unnecessary invisible delimiter checks.
Nicholas Nethercote [Wed, 11 May 2022 00:14:49 +0000 (10:14 +1000)]
Remove some unnecessary invisible delimiter checks.

These seem to have no useful effect... they don't seem useful from a
code inspection point of view, and they affect anything in the test
suite.

2 years agoFix the rustfmt build
Scott McMurray [Mon, 25 Apr 2022 02:25:30 +0000 (19:25 -0700)]
Fix the rustfmt build

2 years agorustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`
Vadim Petrochenkov [Tue, 26 Apr 2022 12:40:14 +0000 (15:40 +0300)]
rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`

2 years agoMake explicit an unreachable `NoDelim` case in `rustfmt`.
Nicholas Nethercote [Tue, 26 Apr 2022 05:09:11 +0000 (15:09 +1000)]
Make explicit an unreachable `NoDelim` case in `rustfmt`.

2 years agoAvoid producing `NoDelim` values in `MacArgs::delim()`.
Nicholas Nethercote [Tue, 26 Apr 2022 05:21:15 +0000 (15:21 +1000)]
Avoid producing `NoDelim` values in `MacArgs::delim()`.

2 years agoVisit generics inside visit_fn.
Camille GILLOT [Fri, 19 Nov 2021 21:03:43 +0000 (22:03 +0100)]
Visit generics inside visit_fn.

2 years agoRollup merge of #94461 - jhpratt:2024-edition, r=pnkfelix
Dylan DPC [Fri, 15 Apr 2022 18:50:43 +0000 (20:50 +0200)]
Rollup merge of #94461 - jhpratt:2024-edition, r=pnkfelix

Create (unstable) 2024 edition

[On Zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Deprecating.20macro.20scoping.20shenanigans/near/272860652), there was a small aside regarding creating the 2024 edition now as opposed to later. There was a reasonable amount of support and no stated opposition.

This change creates the 2024 edition in the compiler and creates a prelude for the 2024 edition. There is no current difference between the 2021 and 2024 editions. Cargo and other tools will need to be updated separately, as it's not in the same repository. This change permits the vast majority of work towards the next edition to proceed _now_ instead of waiting until 2024.

For sanity purposes, I've merged the "hello" UI tests into a single file with multiple revisions. Otherwise we'd end up with a file per edition, despite them being essentially identical.

````@rustbot```` label +T-lang +S-waiting-on-review

Not sure on the relevant team, to be honest.

2 years agoerrors: lazily load fallback fluent bundle
David Wood [Tue, 12 Apr 2022 08:34:40 +0000 (09:34 +0100)]
errors: lazily load fallback fluent bundle

Loading the fallback bundle in compilation sessions that won't go on to
emit any errors unnecessarily degrades compile time performance, so
lazily create the Fluent bundle when it is first required.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agosession: opt for enabling directionality markers
David Wood [Sun, 3 Apr 2022 03:53:01 +0000 (04:53 +0100)]
session: opt for enabling directionality markers

Add an option for enabling and disabling Fluent's directionality
isolation markers in output. Disabled by default as these can render in
some terminals and applications.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoerrors: implement sysroot/testing bundle loading
David Wood [Mon, 28 Mar 2022 08:36:20 +0000 (09:36 +0100)]
errors: implement sysroot/testing bundle loading

Extend loading of Fluent bundles so that bundles can be loaded from the
sysroot based on the language requested by the user, or using a nightly
flag.

Sysroot bundles are loaded from `$sysroot/share/locale/$locale/*.ftl`.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoerrors: implement fallback diagnostic translation
David Wood [Sat, 26 Mar 2022 07:27:43 +0000 (07:27 +0000)]
errors: implement fallback diagnostic translation

This commit updates the signatures of all diagnostic functions to accept
types that can be converted into a `DiagnosticMessage`. This enables
existing diagnostic calls to continue to work as before and Fluent
identifiers to be provided. The `SessionDiagnostic` derive just
generates normal diagnostic calls, so these APIs had to be modified to
accept Fluent identifiers.

In addition, loading of the "fallback" Fluent bundle, which contains the
built-in English messages, has been implemented.

Each diagnostic now has "arguments" which correspond to variables in the
Fluent messages (necessary to render a Fluent message) but no API for
adding arguments has been added yet. Therefore, diagnostics (that do not
require interpolation) can be converted to use Fluent identifiers and
will be output as before.

2 years agospan: move `MultiSpan`
David Wood [Thu, 24 Mar 2022 02:03:04 +0000 (02:03 +0000)]
span: move `MultiSpan`

`MultiSpan` contains labels, which are more complicated with the
introduction of diagnostic translation and will use types from
`rustc_errors` - however, `rustc_errors` depends on `rustc_span` so
`rustc_span` cannot use types like `DiagnosticMessage` without
dependency cycles. Introduce a new `rustc_error_messages` crate that can
contain `DiagnosticMessage` and `MultiSpan`.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoCreate 2024 edition
Jacob Pratt [Mon, 28 Feb 2022 23:13:24 +0000 (18:13 -0500)]
Create 2024 edition

2 years agoMerge commit '5ff7b632a95bac6955611d85040859128902c580' into sync-rustfmt-subtree
Caleb Cartwright [Wed, 30 Mar 2022 04:17:30 +0000 (23:17 -0500)]
Merge commit '5ff7b632a95bac6955611d85040859128902c580' into sync-rustfmt-subtree

2 years agoTake &mut Diagnostic in emit_diagnostic.
Camille GILLOT [Sun, 20 Mar 2022 17:26:09 +0000 (18:26 +0100)]
Take &mut Diagnostic in emit_diagnostic.

Taking a Diagnostic by move would break the usual pattern
`diag.label(..).emit()`.

2 years agoRollup merge of #94960 - codehorseman:master, r=oli-obk
Dylan DPC [Thu, 17 Mar 2022 21:55:05 +0000 (22:55 +0100)]
Rollup merge of #94960 - codehorseman:master, r=oli-obk

Fix many spelling mistakes

Signed-off-by: codehorseman <cricis@yeah.net>
2 years agorustc_error: make ErrorReported impossible to construct
mark [Sun, 23 Jan 2022 00:49:12 +0000 (18:49 -0600)]
rustc_error: make ErrorReported impossible to construct

There are a few places were we have to construct it, though, and a few
places that are more invasive to change. To do this, we create a
constructor with a long obvious name.

2 years agoresolve the conflict in compiler/rustc_session/src/parse.rs
codehorseman [Wed, 16 Mar 2022 12:12:30 +0000 (20:12 +0800)]
resolve the conflict in compiler/rustc_session/src/parse.rs

Signed-off-by: codehorseman <cricis@yeah.net>
2 years agoAuto merge of #94584 - pnkfelix:inject-use-suggestion-sites, r=ekuber
bors [Tue, 15 Mar 2022 03:56:33 +0000 (03:56 +0000)]
Auto merge of #94584 - pnkfelix:inject-use-suggestion-sites, r=ekuber

More robust fallback for `use` suggestion

Our old way to suggest where to add `use`s would first look for pre-existing `use`s in the relevant crate/module, and if there are *no* uses, it would fallback on trying to use another item as the basis for the suggestion.

But this was fragile, as illustrated in issue #87613

This PR instead identifies span of the first token after any inner attributes, and uses *that* as the fallback for the `use` suggestion.

Fix #87613

2 years agoplacate rustfmt in rustfmt.
Felix S. Klock II [Mon, 7 Mar 2022 21:37:35 +0000 (16:37 -0500)]
placate rustfmt in rustfmt.

2 years agoRollup merge of #94617 - pierwill:update-itertools, r=Mark-Simulacrum
Matthias Krüger [Sun, 6 Mar 2022 14:41:26 +0000 (15:41 +0100)]
Rollup merge of #94617 - pierwill:update-itertools, r=Mark-Simulacrum

Update `itertools`

Update to 0.10.1

2 years agoChange syntax for TyAlias where clauses
Jack Huey [Tue, 19 Oct 2021 22:45:48 +0000 (18:45 -0400)]
Change syntax for TyAlias where clauses

2 years agoPlacate tidy in submodule.
Felix S. Klock II [Fri, 4 Mar 2022 22:05:30 +0000 (17:05 -0500)]
Placate tidy in submodule.

2 years agoUpdate `itertools`
pierwill [Fri, 4 Mar 2022 17:54:28 +0000 (11:54 -0600)]
Update `itertools`

Update to 0.10.1

2 years agoAdjusted diagnostic output so that if there is no `use` in a item sequence,
Felix S. Klock II [Thu, 20 Jan 2022 19:07:54 +0000 (14:07 -0500)]
Adjusted diagnostic output so that if there is no `use` in a item sequence,
then we just suggest the first legal position where you could inject a use.

To do this, I added `inject_use_span` field to `ModSpans`, and populate it in
parser (it is the span of the first token found after inner attributes, if any).
Then I rewrote the use-suggestion code to utilize it, and threw out some stuff
that is now unnecessary with this in place. (I think the result is easier to
understand.)

Then I added a test of issue 87613.

2 years agoAssociate multiple with a crate too.
Felix S. Klock II [Thu, 3 Mar 2022 23:45:25 +0000 (18:45 -0500)]
Associate multiple with a crate too.

2 years agorefactor: prepare to associate multiple spans with a module.
Felix S. Klock II [Thu, 20 Jan 2022 16:06:45 +0000 (11:06 -0500)]
refactor: prepare to associate multiple spans with a module.

2 years agoEnable rustc_pass_by_value for Span
Mark Rousskov [Wed, 23 Feb 2022 13:11:17 +0000 (08:11 -0500)]
Enable rustc_pass_by_value for Span

2 years agorustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.
Eduard-Mihai Burtescu [Wed, 26 Jan 2022 03:39:14 +0000 (03:39 +0000)]
rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.

2 years agorustc_errors: add `downgrade_to_delayed_bug` to `Diagnostic` itself.
Eduard-Mihai Burtescu [Sun, 23 Jan 2022 23:11:37 +0000 (23:11 +0000)]
rustc_errors: add `downgrade_to_delayed_bug` to `Diagnostic` itself.

2 years agorustc_errors: only box the `diagnostic` field in `DiagnosticBuilder`.
Eduard-Mihai Burtescu [Mon, 24 Jan 2022 11:23:14 +0000 (11:23 +0000)]
rustc_errors: only box the `diagnostic` field in `DiagnosticBuilder`.

2 years agoAdd term to ExistentialProjection
kadmin [Thu, 13 Jan 2022 07:39:58 +0000 (07:39 +0000)]
Add term to ExistentialProjection

Also prevent ICE when adding a const in associated const equality.

2 years agoAdd term
kadmin [Fri, 7 Jan 2022 03:58:32 +0000 (03:58 +0000)]
Add term

Instead of having a separate enum variant for types and consts have one but have either a const
or type.

2 years agoadd eq constraints on associated constants
kadmin [Fri, 30 Jul 2021 08:56:45 +0000 (08:56 +0000)]
add eq constraints on associated constants

2 years agoAuto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu
bors [Mon, 17 Jan 2022 09:40:29 +0000 (09:40 +0000)]
Auto merge of #92816 - tmiasko:rm-llvm-asm, r=Amanieu

Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in #87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in #91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes #70173.
Closes #92794.
Closes #87612.
Closes #82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`

2 years agofix(rustfmt): resolve generated file formatting issue
Caleb Cartwright [Sat, 15 Jan 2022 00:18:37 +0000 (18:18 -0600)]
fix(rustfmt): resolve generated file formatting issue

2 years agoRemove LLVM-style inline assembly from rustfmt
Tomasz Miąsko [Wed, 12 Jan 2022 00:00:00 +0000 (00:00 +0000)]
Remove LLVM-style inline assembly from rustfmt

2 years agoCompute most of Public/Exported access level in rustc_resolve
Lamb [Mon, 26 Jul 2021 03:38:16 +0000 (05:38 +0200)]
Compute most of Public/Exported access level in rustc_resolve

Mak DefId to AccessLevel map in resolve for export

hir_id to accesslevel in resolve and applied in privacy
using local def id
removing tracing probes
making function not recursive and adding comments

Move most of Exported/Public res to rustc_resolve

moving public/export res to resolve

fix missing stability attributes in core, std and alloc

move code to access_levels.rs

return for some kinds instead of going through them

Export correctness, macro changes, comments

add comment for import binding

add comment for import binding

renmae to access level visitor, remove comments, move fn as closure, remove new_key

fmt

fix rebase

fix rebase

fmt

fmt

fix: move macro def to rustc_resolve

fix: reachable AccessLevel for enum variants

fmt

fix: missing stability attributes for other architectures

allow unreachable pub in rustfmt

fix: missing impl access level + renaming export to reexport

Missing impl access level was found thanks to a test in clippy

2 years agoMerge commit '4a053f206fd6799a25823c307f7d7f9d897be118' into sync-rustfmt-subtree
Caleb Cartwright [Thu, 30 Dec 2021 02:49:39 +0000 (20:49 -0600)]
Merge commit '4a053f206fd6799a25823c307f7d7f9d897be118' into sync-rustfmt-subtree

2 years agoRemove unnecessary sigils around `Ident::as_str()` calls.
Nicholas Nethercote [Wed, 15 Dec 2021 05:13:11 +0000 (16:13 +1100)]
Remove unnecessary sigils around `Ident::as_str()` calls.

2 years agoRemove unnecessary sigils around `Symbol::as_str()` calls.
Nicholas Nethercote [Wed, 15 Dec 2021 03:39:23 +0000 (14:39 +1100)]
Remove unnecessary sigils around `Symbol::as_str()` calls.

2 years agoRemove `SymbolStr`.
Nicholas Nethercote [Tue, 14 Dec 2021 21:32:21 +0000 (08:32 +1100)]
Remove `SymbolStr`.

By changing `as_str()` to take `&self` instead of `self`, we can just
return `&str`. We're still lying about lifetimes, but it's a smaller lie
than before, where `SymbolStr` contained a (fake) `&'static str`!

2 years agoMerge commit '8da837185714cefbb261e93e9846afb11c1dc60e' into sync-rustfmt-subtree
Caleb Cartwright [Fri, 3 Dec 2021 03:35:30 +0000 (21:35 -0600)]
Merge commit '8da837185714cefbb261e93e9846afb11c1dc60e' into sync-rustfmt-subtree

2 years agoChange how the fn params span is calculated
Esteban Kuber [Wed, 24 Nov 2021 17:11:15 +0000 (17:11 +0000)]
Change how the fn params span is calculated

Use the available Generics span field to avoid issues with `T: Fn()` bounds.

This is necessary to land #85346.

2 years agoMerge commit 'ea199bacef07213dbe008841b89c450e3bf0c638' into rustfmt-sync
Caleb Cartwright [Mon, 8 Nov 2021 02:37:34 +0000 (20:37 -0600)]
Merge commit 'ea199bacef07213dbe008841b89c450e3bf0c638' into rustfmt-sync

2 years agoast: Fix naming conventions in AST structures
Vadim Petrochenkov [Sun, 7 Nov 2021 08:43:49 +0000 (16:43 +0800)]
ast: Fix naming conventions in AST structures

TraitKind -> Trait
TyAliasKind -> TyAlias
ImplKind -> Impl
FnKind -> Fn

All `*Kind`s in AST are supposed to be enums.

Tuple structs are converted to braced structs for the types above, and fields are reordered in syntactic order.

Also, mutable AST visitor now correctly visit spans in defaultness, unsafety, impl polarity and constness.

2 years agofix doc issue in rustfmt
Caleb Cartwright [Thu, 21 Oct 2021 22:22:54 +0000 (17:22 -0500)]
fix doc issue in rustfmt

2 years agoensure cargo-fmt tests are excluded from root workspace
Caleb Cartwright [Wed, 20 Oct 2021 15:12:22 +0000 (10:12 -0500)]
ensure cargo-fmt tests are excluded from root workspace

2 years agoMerge commit 'efa8f5521d3813cc897ba29ea0ef98c7aef66bb6' into rustfmt-subtree
Caleb Cartwright [Wed, 20 Oct 2021 05:11:59 +0000 (00:11 -0500)]
Merge commit 'efa8f5521d3813cc897ba29ea0ef98c7aef66bb6' into rustfmt-subtree

2 years agoMigrate to 2021
Mark Rousskov [Sun, 19 Sep 2021 16:49:55 +0000 (12:49 -0400)]
Migrate to 2021

2 years agoRollup merge of #88775 - pnkfelix:revert-anon-union-parsing, r=davidtwco
Manish Goregaokar [Wed, 15 Sep 2021 21:56:58 +0000 (14:56 -0700)]
Rollup merge of #88775 - pnkfelix:revert-anon-union-parsing, r=davidtwco

Revert anon union parsing

Revert PR #84571 and #85515, which implemented anonymous union parsing in a manner that broke the context-sensitivity for the `union` keyword and thus broke stable Rust code.

Fix #88583.

2 years agoAuto merge of #84373 - cjgillot:resolve-span, r=michaelwoerister,petrochenkov
bors [Sat, 11 Sep 2021 23:35:28 +0000 (23:35 +0000)]
Auto merge of #84373 - cjgillot:resolve-span, r=michaelwoerister,petrochenkov

Encode spans relative to the enclosing item

The aim of this PR is to avoid recomputing queries when code is moved without modification.

MCP at https://github.com/rust-lang/compiler-team/issues/443

This is achieved by :
1. storing the HIR owner LocalDefId information inside the span;
2. encoding and decoding spans relative to the enclosing item in the incremental on-disk cache;
3. marking a dependency to the `source_span(LocalDefId)` query when we translate a span from the short (`Span`) representation to its explicit (`SpanData`) representation.

Since all client code uses `Span`, step 3 ensures that all manipulations
of span byte positions actually create the dependency edge between
the caller and the `source_span(LocalDefId)`.
This query return the actual absolute span of the parent item.
As a consequence, any source code motion that changes the absolute byte position of a node will either:
- modify the distance to the parent's beginning, so change the relative span's hash;
- dirty `source_span`, and trigger the incremental recomputation of all code that
  depends on the span's absolute byte position.

With this scheme, I believe the dependency tracking to be accurate.

For the moment, the spans are marked during lowering.
I'd rather do this during def-collection,
but the AST MutVisitor is not practical enough just yet.
The only difference is that we attach macro-expanded spans
to their expansion point instead of the macro itself.

2 years agoKeep a parent LocalDefId in SpanData.
Camille GILLOT [Sun, 18 Apr 2021 12:27:04 +0000 (14:27 +0200)]
Keep a parent LocalDefId in SpanData.

2 years agoIgnore automatically derived impls of `Clone` and `Debug` in dead code analysis
Fabian Wolff [Fri, 21 May 2021 17:35:49 +0000 (19:35 +0200)]
Ignore automatically derived impls of `Clone` and `Debug` in dead code analysis

2 years agoRevert "Allow formatting `Anonymous{Struct, Union}` declarations"
Felix S. Klock II [Wed, 8 Sep 2021 17:40:32 +0000 (13:40 -0400)]
Revert "Allow formatting `Anonymous{Struct, Union}` declarations"

This reverts commit 64acb7d92135ae722dfce89f0ca9d7cf6576de66.

2 years agoAuto merge of #88493 - chenyukang:fix-duplicated-diagnostic, r=estebank
bors [Mon, 6 Sep 2021 00:14:41 +0000 (00:14 +0000)]
Auto merge of #88493 - chenyukang:fix-duplicated-diagnostic, r=estebank

Fix #88256 remove duplicated diagnostics

Fix #88256

2 years agoFix #88256, remove duplicated diagnostic
yukang [Sat, 4 Sep 2021 11:26:25 +0000 (19:26 +0800)]
Fix #88256, remove duplicated diagnostic

2 years agoDetect bare blocks with type ascription that were meant to be a `struct` literal
Esteban Kuber [Thu, 2 Sep 2021 18:34:03 +0000 (18:34 +0000)]
Detect bare blocks with type ascription that were meant to be a `struct` literal

Address part of #34255.

Potential improvement: silence the other knock down errors in
`issue-34255-1.rs`.