Commit Graph

812 Commits

Author SHA1 Message Date
Nilstrieb
c65ebae221
Migrate all diagnostics 2022-10-23 10:09:44 +02:00
Dylan DPC
e11511dfa6
Rollup merge of #103051 - davidtwco:translation-tidying-up, r=compiler-errors
translation: doc comments with derives, subdiagnostic-less enum variants, more derive use

- Adds support for `doc` attributes in the diagnostic derives so that documentation comments don't result in the derive failing.
- Adds support for enum variants in the subdiagnostic derive to not actually correspond to an addition to a diagnostic.
- Made use of the derive in more places in the `rustc_ast_lowering`, `rustc_ast_passes`, `rustc_lint`, `rustc_session`, `rustc_infer` - taking advantage of recent additions like eager subdiagnostics, multispan suggestions, etc.

cc #100717
2022-10-21 17:29:58 +05:30
Santiago Pastorino
49ce8a22b0
Do anonymous lifetimes remapping correctly for nested rpits 2022-10-19 16:49:39 -03:00
Santiago Pastorino
fb5475887f
Extract orig_opt_local_def_id as a function 2022-10-19 16:49:39 -03:00
Yuki Okushi
6e7d206a7b
Rollup merge of #103168 - Amanieu:stable_asm_sym, r=davidtwco
Stabilize asm_sym

Tracking issue #93333

Reference PR: https://github.com/rust-lang/reference/pull/1270
2022-10-18 21:21:32 +09:00
Amanieu d'Antras
430bd6200d Stabilize asm_sym 2022-10-17 22:38:37 +01:00
David Wood
2a4b587a68 ast_lowering: use derive more
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17 09:54:24 +01:00
Dylan DPC
b79ad57ad7
Rollup merge of #102998 - nathanwhit:let-chains-drop-order, r=eholk
Drop temporaries created in a condition, even if it's a let chain

Fixes #100513.

During the lowering from AST to HIR we wrap expressions acting as conditions in a `DropTemps` expression so that any temporaries created in the condition are dropped after the condition is executed. Effectively this means we transform

```rust
if Some(1).is_some() { .. }
```

into (roughly)

```rust
if { let _t = Some(1).is_some(); _t } { .. }
```

so that if we create any temporaries, they're lifted into the new scope surrounding the condition, so for example something along the lines of

```rust
if { let temp = Some(1); let _t = temp.is_some(); _t }.
```

Before this PR, if the condition contained any let expressions we would not introduce that new scope, instead leaving the condition alone. This meant that in a let-chain like

```rust
if get_drop("first").is_some() && let None = get_drop("last") {
        println!("second");
} else { .. }
```

the temporary created for `get_drop("first")` would be lifted into the _surrounding block_, which caused it to be dropped after the execution of the entire `if` expression.

After this PR, we wrap everything but the `let` expression in terminating scopes. The upside to this solution is that it's minimally invasive, but the downside is that in the worst case, an expression with `let` exprs interspersed like

```rust
if get_drop("first").is_some()
    && let Some(_a) = get_drop("fifth")
    && get_drop("second").is_some()
    && let Some(_b) = get_drop("fourth") { .. }
```

gets _multiple_ new scopes, roughly

```rust
if { let _t = get_drop("first").is_some(); _t }
    && let Some(_a) = get_drop("fifth")
    && { let _t = get_drop("second").is_some(); _t }
    && let Some(_b) = get_drop("fourth") { .. }
```

so instead of all of the temporaries being dropped at the end of the entire condition, they will be dropped right after they're evaluated (before the subsequent `let` expr). So while I'd say the drop behavior around let-chains is _less_ surprising after this PR, it still might not exactly match what people might expect.

For tests, I've just extended the drop order tests added in #100526. I'm not sure if that's the best way to go about it, though, so suggestions are welcome.
2022-10-15 15:45:32 +05:30
bors
46244f335b Auto merge of #99292 - Aaron1011:stability-use-tree, r=cjgillot
Correctly handle path stability for 'use tree' items

PR #95956 started checking the stability of path segments.
However, this was not applied to 'use tree' items
(e.g. 'use some::path::{ItemOne, ItemTwo}') due to the way
that we desugar these items in HIR lowering.

This PR modifies 'use tree' lowering to preserve resolution
information, which is needed by stability checking.
2022-10-15 04:27:15 +00:00
Nathan Whitaker
709a08ade6 Lower condition directly from AST to HIR 2022-10-13 18:20:39 -07:00
Nathan Whitaker
ad8b242724 Let chains should still drop temporaries
by the end of the condition's execution
2022-10-12 17:57:32 -07:00
Dylan DPC
dc9f6f3243
Rollup merge of #102623 - davidtwco:translation-eager, r=compiler-errors
translation: eager translation

Part of #100717. See [Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20lists!/near/295010720) for additional context.

- **Store diagnostic arguments in a `HashMap`**: Eager translation will enable subdiagnostics to be translated multiple times with different arguments - this requires the ability to replace the value of one argument with a new value, which is better suited to a `HashMap` than the previous storage, a `Vec`.
- **Add `AddToDiagnostic::add_to_diagnostic_with`**: `AddToDiagnostic::add_to_diagnostic_with` is similar to the previous `AddToDiagnostic::add_to_diagnostic` but takes a function that can be used by the caller to modify diagnostic messages originating from the subdiagnostic (such as performing translation eagerly). `add_to_diagnostic` now just calls `add_to_diagnostic_with` with an empty closure.
- **Add `DiagnosticMessage::Eager`**: Add variant of `DiagnosticMessage` for eagerly translated messages
(messages in the target language which don't need translated by the emitter during emission). Also adds `eager_subdiagnostic` function which is intended to be invoked by the diagnostic derive for subdiagnostic fields which are marked as needing eager translation.
- **Support `#[subdiagnostic(eager)]`**: Add support for `eager` argument to the `subdiagnostic` attribute which generates a call to `eager_subdiagnostic`.
- **Finish migrating `rustc_query_system`**: Using eager translation, migrate the remaining repeated cycle stack diagnostic.
- **Split formatting initialization and use in diagnostic derives**: Diagnostic derives have previously had to take special care when ordering the generated code so that fields were not used after a move.

  This is unlikely for most fields because a field is either annotated with a subdiagnostic attribute and is thus likely a `Span` and copiable, or is a argument, in which case it is only used once by `set_arg`
anyway.

  However, format strings for code in suggestions can result in fields being used after being moved if not ordered carefully. As a result, the derive currently puts `set_arg` calls last (just before emission), such as:

      let diag = { /* create diagnostic */ };

      diag.span_suggestion_with_style(
          span,
          fluent::crate::slug,
          format!("{}", __binding_0),
          Applicability::Unknown,
          SuggestionStyle::ShowAlways
      );
      /* + other subdiagnostic additions */

      diag.set_arg("foo", __binding_0);
      /* + other `set_arg` calls */

      diag.emit();

  For eager translation, this doesn't work, as the message being translated eagerly can assume that all arguments are available - so arguments _must_ be set first.

  Format strings for suggestion code are now separated into two parts - an initialization line that performs the formatting into a variable, and a usage in the subdiagnostic addition.

  By separating these parts, the initialization can happen before arguments are set, preserving the desired order so that code compiles, while still enabling arguments to be set before subdiagnostics are added.

      let diag = { /* create diagnostic */ };

      let __code_0 = format!("{}", __binding_0);
      /* + other formatting */

      diag.set_arg("foo", __binding_0);
      /* + other `set_arg` calls */

      diag.span_suggestion_with_style(
          span,
          fluent::crate::slug,
          __code_0,
          Applicability::Unknown,
          SuggestionStyle::ShowAlways
      );
      /* + other subdiagnostic additions */

      diag.emit();

- **Remove field ordering logic in diagnostic derive:** Following the approach taken in earlier commits to separate formatting initialization from use in the subdiagnostic derive, simplify the diagnostic derive by removing the field-ordering logic that previously solved this problem.

r? ```@compiler-errors```
2022-10-12 22:13:23 +05:30
Eric Holk
3db41d13f0 wip: trying to enable #[track_caller] on async fn 2022-10-11 16:37:54 -07:00
Vadim Petrochenkov
1a8f177772 rustc_hir: Less error-prone methods for accessing PartialRes resolution 2022-10-11 09:04:52 +04:00
David Wood
b4ac26289f errors: AddToDiagnostic::add_to_diagnostic_with
`AddToDiagnostic::add_to_diagnostic_with` is similar to the previous
`AddToDiagnostic::add_to_diagnostic` but takes a function that can be
used by the caller to modify diagnostic messages originating from the
subdiagnostic (such as performing translation eagerly).

`add_to_diagnostic` now just calls `add_to_diagnostic_with` with an
empty closure.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10 14:20:16 +01:00
Michael Goulet
d3bd6beb97 Rename AssocItemKind::TyAlias to AssocItemKind::Type 2022-10-10 02:31:37 +00:00
Yuki Okushi
24424d0acb
Rollup merge of #102829 - compiler-errors:rename-impl-item-kind, r=TaKO8Ki
rename `ImplItemKind::TyAlias` to `ImplItemKind::Type`

The naming of this variant seems inconsistent given that this is not really a "type alias", and the associated type variant for `TraitItemKind` is just called `Type`.
2022-10-10 00:09:42 +09:00
Michael Goulet
70f3c79c50 ImplItemKind::TyAlias => ImplItemKind::Type 2022-10-09 07:09:57 +00:00
bors
0152393048 Auto merge of #99324 - reez12g:issue-99144, r=jyn514
Enable doctests in compiler/ crates

Helps with https://github.com/rust-lang/rust/issues/99144
2022-10-06 03:01:57 +00:00
reez12g
488eb4209e Temporarily reinstate doctest=false 2022-10-05 09:53:49 +09:00
Santiago Pastorino
b2bef02bcd
create def ids for impl traits during ast lowering 2022-09-30 15:12:01 -03:00
reez12g
a1999b76aa Mark ignore(illustrative) on docs in compiler/rustc_ast_lowering/src/expr.rs 2022-09-29 16:49:13 +09:00
reez12g
9a4c5abe45 Remove from compiler/ crates 2022-09-29 16:49:04 +09:00
Camille GILLOT
337a73da6e Do not overwrite binders for another HirId. 2022-09-27 18:58:37 +02:00
Pietro Albini
3975d55d98
remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
Michael Goulet
e99f6fee44 Only lower async fn body if it actually has a body 2022-09-25 23:03:15 +00:00
Takayuki Maeda
8fe936099a separate definitions and HIR owners
fix a ui test

use `into`

fix clippy ui test

fix a run-make-fulldeps test

implement `IntoQueryParam<DefId>` for `OwnerId`

use `OwnerId` for more queries

change the type of `ParentOwnerIterator::Item` to `(OwnerId, OwnerNode)`
2022-09-24 23:21:19 +09:00
bors
4d44e09cb1 Auto merge of #102165 - matthiaskrgr:rollup-n5oquhe, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #100734 (Split out async_fn_in_trait into a separate feature)
 - #101664 (Note if mismatched types have a similar name)
 - #101815 (Migrated the rustc_passes annotation without effect diagnostic infrastructure)
 - #102042 (Distribute rust-docs-json via rustup.)
 - #102066 (rustdoc: remove unnecessary `max-width` on headers)
 - #102095 (Deduplicate two functions that would soon have been three)
 - #102104 (Set 'exec-env:RUST_BACKTRACE=0' in const-eval-select tests)
 - #102112 (Allow full relro on powerpc64-unknown-linux-gnu)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-23 09:33:23 +00:00
khyperia
9a206a78eb Improve the help message for an invalid calling convention 2022-09-22 22:18:30 +02:00
Dan Johnson
d0a07495be Split out async_fn_in_trait into a separate feature
PR #101224 added support for async fn in trait desuraging behind the
return_position_impl_trait_in_trait feature.

Split this out so that it's behind its own feature gate, since async fn
in trait doesn't need to follow the same stabilization schedule.
2022-09-21 19:26:23 -07:00
Jhonny Bill Mena
e52e2344dc FIX - adopt new Diagnostic naming in newly migrated modules
FIX - ambiguous Diagnostic link in docs

UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic

[Gardening] FIX - formatting via `x fmt`

FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way

DELETE - unneeded allow attributes in Handler method

FIX - broken test

FIX - Rebase conflict

UPDATE - rename residual _SessionDiagnostic and fix LintDiag link
2022-09-21 11:43:22 -04:00
Jhonny Bill Mena
5f91719f75 UPDATE - rename SessionSubdiagnostic macro to Subdiagnostic
Also renames:
- sym::AddSubdiagnostic to sym:: Subdiagnostic
- rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
a3396b2070 UPDATE - rename DiagnosticHandler macro to Diagnostic 2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
191fac6826 UPDATE - rename AddSubdiagnostic trait to AddToDiagnostic 2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
19b348fed4 UPDATE - rename DiagnosticHandler trait to IntoDiagnostic 2022-09-21 11:39:52 -04:00
Santiago Pastorino
550bd0945f
Simplify rpitit handling on lower_fn_decl 2022-09-19 09:30:39 -03:00
Dylan DPC
3ad81e0dd8
Rollup merge of #93628 - est31:stabilize_let_else, r=joshtriplett
Stabilize `let else`

🎉  **Stabilizes the `let else` feature, added by [RFC 3137](https://github.com/rust-lang/rfcs/pull/3137).** 🎉

Reference PR: https://github.com/rust-lang/reference/pull/1156

closes #87335 (`let else` tracking issue)

FCP: https://github.com/rust-lang/rust/pull/93628#issuecomment-1029383585

----------

## Stabilization report

### Summary

The feature allows refutable patterns in `let` statements if the expression is
followed by a diverging `else`:

```Rust
fn get_count_item(s: &str) -> (u64, &str) {
    let mut it = s.split(' ');
    let (Some(count_str), Some(item)) = (it.next(), it.next()) else {
        panic!("Can't segment count item pair: '{s}'");
    };
    let Ok(count) = u64::from_str(count_str) else {
        panic!("Can't parse integer: '{count_str}'");
    };
    (count, item)
}
assert_eq!(get_count_item("3 chairs"), (3, "chairs"));
```

### Differences from the RFC / Desugaring

Outside of desugaring I'm not aware of any differences between the implementation and the RFC. The chosen desugaring has been changed from the RFC's [original](https://rust-lang.github.io/rfcs/3137-let-else.html#reference-level-explanations). You can read a detailed discussion of the implementation history of it in `@cormacrelf` 's [summary](https://github.com/rust-lang/rust/pull/93628#issuecomment-1041143670) in this thread, as well as the [followup](https://github.com/rust-lang/rust/pull/93628#issuecomment-1046598419). Since that followup, further changes have happened to the desugaring, in #98574, #99518, #99954. The later changes were mostly about the drop order: On match, temporaries drop in the same order as they would for a `let` declaration. On mismatch, temporaries drop before the `else` block.

### Test cases

In chronological order as they were merged.

Added by df9a2e0687 (#87688):

* [`ui/pattern/usefulness/top-level-alternation.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/pattern/usefulness/top-level-alternation.rs) to ensure the unreachable pattern lint visits patterns inside `let else`.

Added by 5b95df4bdc (#87688):

* [`ui/let-else/let-else-bool-binop-init.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-bool-binop-init.rs) to ensure that no lazy boolean expressions (using `&&` or `||`) are allowed in the expression, as the RFC mandates.
* [`ui/let-else/let-else-brace-before-else.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-brace-before-else.rs) to ensure that no `}` directly preceding the `else` is allowed in the expression, as the RFC mandates.
* [`ui/let-else/let-else-check.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-check.rs) to ensure that `#[allow(...)]` attributes added to the entire `let` statement apply for the `else` block.
* [`ui/let-else/let-else-irrefutable.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-irrefutable.rs) to ensure that the `irrefutable_let_patterns` lint fires.
* [`ui/let-else/let-else-missing-semicolon.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-missing-semicolon.rs) to ensure the presence of semicolons at the end of the `let` statement.
* [`ui/let-else/let-else-non-diverging.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-non-diverging.rs) to ensure the `else` block diverges.
* [`ui/let-else/let-else-run-pass.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-run-pass.rs) to ensure the feature works in some simple test case settings.
* [`ui/let-else/let-else-scope.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-scope.rs) to ensure the bindings created by the outer `let` expression are not available in the `else` block of it.

Added by bf7c32a447 (#89965):

* [`ui/let-else/issue-89960.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/issue-89960.rs) as a regression test for the ICE-on-error bug #89960 . Later in 102b9125e1 this got removed in favour of more comprehensive tests.

Added by 856541963c (#89974):

* [`ui/let-else/let-else-if.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-if.rs) to test for the improved error message that points out that `let else if` is not possible.

Added by 9b45713b6c:

* [`ui/let-else/let-else-allow-unused.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-allow-unused.rs) as a regression test for #89807, to ensure that `#[allow(...)]` attributes added to the entire `let` statement apply for bindings created by the `let else` pattern.

Added by 61bcd8d307 (#89841):

* [`ui/let-else/let-else-non-copy.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-non-copy.rs) to ensure that a copy is performed out of non-copy wrapper types. This mirrors `if let` behaviour. The test case bases on rustc internal changes originally meant for #89933 but then removed from the PR due to the error prior to the improvements of #89841.
* [`ui/let-else/let-else-source-expr-nomove-pass.rs `](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-source-expr-nomove-pass.rs) to ensure that while there is a move of the binding in the successful case, the `else` case can still access the non-matching value. This mirrors `if let` behaviour.

Added by 102b9125e1 (#89841):

* [`ui/let-else/let-else-ref-bindings.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-ref-bindings.rs) and [`ui/let-else/let-else-ref-bindings-pass.rs `](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-ref-bindings-pass.rs) to check `ref` and `ref mut` keywords in the pattern work correctly and error when needed.

Added by 2715c5f984 (#89841):

* Match ergonomic tests adapted from the `rfc2005` test suite.

Added by fec8a507a2 (#89841):

* [`ui/let-else/let-else-deref-coercion-annotated.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-deref-coercion-annotated.rs) and [`ui/let-else/let-else-deref-coercion.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-deref-coercion.rs) to check deref coercions.

#### Added since this stabilization report was originally written (2022-02-09)

Added by 76ea566677 (#94211):

* [`ui/let-else/let-else-destructuring.rs`](https://github.com/rust-lang/rust/blob/1.63.0/src/test/ui/let-else/let-else-destructuring.rs) to give a nice error message if an user tries to do an assignment with a (possibly refutable) pattern and an `else` block, like asked for in #93995.

Added by e7730dcb7e (#94208):

* [`ui/let-else/let-else-allow-in-expr.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-allow-in-expr.rs) to test whether `#[allow(unused_variables)]` works in the expr, as well as its non presence, as well as putting it on the entire `let else` *affects* the expr, too. This was adding a missing test as pointed out by the stabilization report.
* Expansion of `ui/let-else/let-else-allow-unused.rs` and `ui/let-else/let-else-check.rs` to ensure that non-presence of `#[allow(unused)]` does issue the unused lint. This was adding a missing test case as pointed out by the stabilization report.

Added by 5bd71063b3 (#94208):

* [`ui/let-else/let-else-slicing-error.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-slicing-error.rs), a regression test for #92069, which got fixed without addition of a regression test. This resolves a missing test as pointed out by the stabilization report.

Added by 5374688e1d (#98574):

* [`src/test/ui/async-await/async-await-let-else.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/async-await/async-await-let-else.rs) to test the interaction of async/await with `let else`

Added by 6c529ded86 (#98574):

* [`src/test/ui/let-else/let-else-temporary-lifetime.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs) as a (partial) regression test for #98672

Added by 9b56640106 (#99518):

* [`src/test/ui/let-else/let-else-temp-borrowck.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs) as a regression test for #93951
* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a partial regression test for #98672 (especially regarding `else` drop order)

Added by baf9a7cb57 (#99518):

* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a partial regression test for #93951, similar to `let-else-temp-borrowck.rs`

Added by 60be2de8b7 (#99518):

* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a program that can now be compiled thanks to borrow checker implications of #99518

Added by 47a7a91c96 (#100132):

* [`src/test/ui/let-else/issue-100103.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-100103.rs), as a regression test for #100103, to ensure that there is no ICE when doing `Err(...)?` inside else blocks.

Added by e3c5bd617d (#100443):

* [`src/test/ui/let-else/let-else-then-diverge.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-then-diverge.rs), to verify that there is no unreachable code error with the current desugaring.

Added by 981852677c (#100443):

* [`src/test/ui/let-else/issue-94176.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-94176.rs), to make sure that a correct span is emitted for a missing trailing expression error. Regression test for #94176.

Added by e182d12a84 (#100434):

* [src/test/ui/unpretty/pretty-let-else.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/unpretty/pretty-let-else.rs), as a regression test to ensure pretty printing works for `let else` (this bug surfaced in many different ways)

Added by e26285603c (#99954):

* [`src/test/ui/let-else/let-else-temporary-lifetime.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs) extended to contain & borrows as well, as this was identified as an earlier issue with the desugaring: https://github.com/rust-lang/rust/issues/98672#issuecomment-1200196921

Added by 2d8460ef43 (#99291):

* [`src/test/ui/let-else/let-else-drop-order.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-drop-order.rs) a matrix based test for various drop order behaviour of `let else`. Especially, it verifies equality of `let` and `let else` drop orders, [resolving](https://github.com/rust-lang/rust/pull/93628#issuecomment-1238498468) a [stabilization blocker](https://github.com/rust-lang/rust/pull/93628#issuecomment-1055738523).

Added by 1b87ce0d40 (#101410):

* Edit to `src/test/ui/let-else/let-else-temporary-lifetime.rs` to add the `-Zvalidate-mir` flag, as a regression test for #99228

Added by af591ebe4d (#101410):

* [`src/test/ui/let-else/issue-99975.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-99975.rs) as a regression test for the ICE #99975.

Added by this PR:

* `ui/let-else/let-else.rs`, a simple run-pass check, similar to `ui/let-else/let-else-run-pass.rs`.

### Things not currently tested

* ~~The `#[allow(...)]` tests check whether allow works, but they don't check whether the non-presence of allow causes a lint to fire.~~ → *test added by e7730dcb7eb29a10ee73f269f4dc6e9d606db0da*
* ~~There is no `#[allow(...)]` test for the expression, as there are tests for the pattern and the else block.~~ → *test added by e7730dcb7eb29a10ee73f269f4dc6e9d606db0da*
* ~~`let-else-brace-before-else.rs` forbids the `let ... = {} else {}` pattern and there is a rustfix to obtain `let ... = ({}) else {}`. I'm not sure whether the `.fixed` files are checked by the tooling that they compile. But if there is no such check, it would be neat to make sure that `let ... = ({}) else {}` compiles.~~ → *test added by e7730dcb7eb29a10ee73f269f4dc6e9d606db0da*
* ~~#92069 got closed as fixed, but no regression test was added. Not sure it's worth to add one.~~ → *test added by 5bd71063b3810d977aa376d1e6dd7cec359330cc*
* ~~consistency between `let else` and `if let` regarding lifetimes and drop order: https://github.com/rust-lang/rust/pull/93628#issuecomment-1055738523~~ → *test added by 2d8460ef43d902f34ba2133fe38f66ee8d2fdafc*

Edit: they are all tested now.

### Possible future work / Refutable destructuring assignments

[RFC 2909](https://rust-lang.github.io/rfcs/2909-destructuring-assignment.html) specifies destructuring assignment, allowing statements like `FooBar { a, b, c } = foo();`.
As it was stabilized, destructuring assignment only allows *irrefutable* patterns, which before the advent of `let else` were the only patterns that `let` supported.
So the combination of `let else` and destructuring assignments gives reason to think about extensions of the destructuring assignments feature that allow refutable patterns, discussed in #93995.

A naive mapping of `let else` to destructuring assignments in the form of `Some(v) = foo() else { ... };` might not be the ideal way. `let else` needs a diverging `else` clause as it introduces new bindings, while assignments have a default behaviour to fall back to if the pattern does not match, in the form of not performing the assignment. Thus, there is no good case to require divergence, or even an `else` clause at all, beyond the need for having *some* introducer syntax so that it is clear to readers that the assignment is not a given (enums and structs look similar). There are better candidates for introducer syntax however than an empty `else {}` clause, like `maybe` which could be added as a keyword on an edition boundary:

```Rust
let mut v = 0;
maybe Some(v) = foo(&v);
maybe Some(v) = foo(&v) else { bar() };
```

Further design discussion is left to an RFC, or the linked issue.
2022-09-17 15:31:06 +05:30
Guillaume Gomez
8ba133fa7b
Rollup merge of #101825 - spastorino:fix-rpit-changes, r=oli-obk
Fix back RPIT changes

r? `@oli-obk`

cc `@compiler-errors`
2022-09-16 13:07:17 +02:00
est31
173eb6f407 Only enable the let_else feature on bootstrap
On later stages, the feature is already stable.

Result of running:

rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-15 21:06:45 +02:00
est31
bca3cf7e86 Stabilize the let_else feature 2022-09-15 21:06:45 +02:00
bors
750bd1a7ff Auto merge of #101313 - SparrowLii:mk_attr_id, r=cjgillot
make `mk_attr_id` part of `ParseSess`

Updates #48685

The current `mk_attr_id` uses the `AtomicU32` type, which is not very efficient and adds a lot of lock contention in a parallel environment.

This PR refers to the task list in #48685, uses `mk_attr_id` as a method of the `AttrIdGenerator` struct, and adds a new field `attr_id_generator` to `ParseSess`.

`AttrIdGenerator` uses the `WorkerLocal`, which has two advantages: 1. `Cell` is more efficient than `AtomicU32`, and does not increase any lock contention. 2. We put the index of the work thread in the first few bits of the generated `AttrId`, so that the `AttrId` generated in different threads can be easily guaranteed to be unique.

cc `@cjgillot`
2022-09-14 20:52:18 +00:00
Santiago Pastorino
45d8049387
Get rid of 'b lifetime in lower_param_bounds_mut 2022-09-14 17:40:51 -03:00
Santiago Pastorino
861055094c
Pass ImplTraitContext as &, there's no need for that to be &mut 2022-09-14 17:39:52 -03:00
Santiago Pastorino
669f2d4550
Revert "Rollup merge of #101496 - spastorino:lower_lifetime_binder_api_changes, r=oli-obk"
This reverts commit 953a6b3da7, reversing
changes made to b5ffbd32d4.
2022-09-14 17:26:37 -03:00
bors
a0d1df4a5d Auto merge of #101709 - nnethercote:simplify-visitors-more, r=cjgillot
Simplify visitors more

A successor to #100392.

r? `@cjgillot`
2022-09-14 05:21:14 +00:00
SparrowLii
1a3ecbdb6a make mk_attr_id part of ParseSess 2022-09-14 08:49:10 +08:00
Lukas Markeffsky
2b7fb8d941 Impove diagnostic for .await-ing non-futures 2022-09-12 16:54:25 +02:00
Nicholas Nethercote
925363f13d Remove unused span argument from walk_fn. 2022-09-12 13:24:27 +10:00
Nicholas Nethercote
6568ef338e Remove path_span argument to the visit_path_segment methods.
The `visit_path_segment` method of both the AST and HIR visitors has a
`path_span` argument that isn't necessary. This commit removes it.

There are two very small and inconsequential functional changes.

- One call to `NodeCollector::insert` now is passed a path segment
  identifier span instead of a full path span. This span is only used in
a panic message printed in the case of an internal compiler bug.

- Likewise, one call to `LifetimeCollectVisitor::record_elided_anchor`
  now uses a path segment identifier span instead of a full path span.
  This span is used to make some `'_` lifetimes.
2022-09-12 13:24:25 +10:00
bors
fa521a4691 Auto merge of #101688 - cjgillot:verify-hir-parent, r=petrochenkov
Assert that HIR nodes are not their own parent.

Fixes https://github.com/rust-lang/rust/issues/101505.
Replaces #101513

r? `@petrochenkov` `@nnethercote`
2022-09-12 00:41:56 +00:00
Camille GILLOT
51f486931f Assert that HIR nodes are not their own parent. 2022-09-11 20:12:51 +02:00
Michael Goulet
ec170bef0d Rebase fallout 2022-09-09 01:31:46 +00:00
Michael Goulet
526511e86b Appease clippy again 2022-09-09 01:31:46 +00:00
Michael Goulet
55df9201fe Tweak feature error, add test 2022-09-09 01:31:46 +00:00
Camille GILLOT
05812df603 Handle generic parameters. 2022-09-09 01:31:46 +00:00
Michael Goulet
cdf78073c5 Deeply check that method signatures match, and allow for nested RPITITs 2022-09-09 01:31:46 +00:00
Michael Goulet
1f03edeabe Bless tests, fix ICE with ImplTraitPlaceholder 2022-09-09 01:31:45 +00:00
Michael Goulet
70775304cd Address nits 2022-09-09 01:31:45 +00:00
Michael Goulet
249ede4195 Address rebase issues, make async fn in trait work 2022-09-09 01:31:45 +00:00
Michael Goulet
5be30f9d79 Make async fn in traits work 2022-09-09 01:31:45 +00:00
Michael Goulet
d34cb98fb0 Lower RPITIT to ImplTraitPlaceholder item 2022-09-09 01:31:44 +00:00
Michael Goulet
1499c089df
Rollup merge of #101499 - spastorino:add-lowering-arena, r=oli-obk
Introduce lowering_arena to avoid creating AST nodes on the fly

`@oli-obk` requested this and other changes as a way of simplifying https://github.com/rust-lang/rust/pull/101345. This is just going to make the diff of https://github.com/rust-lang/rust/pull/101345 smaller.

r? `@oli-obk` `@cjgillot`
2022-09-08 14:41:08 -07:00
Santiago Pastorino
d9a1faaa9c
Introduce lowering_arena to avoid creating AST nodes on the fly 2022-09-08 13:34:55 -03:00
bors
87788097b7 Auto merge of #101577 - Dylan-DPC:rollup-l9xw7i7, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #98933 (Opaque types' generic params do not imply anything about their hidden type's lifetimes)
 - #101041 (translations(rustc_session): migrates rustc_session to use SessionDiagnostic - Pt. 2)
 - #101424 (Adjust and slightly generalize operator error suggestion)
 - #101496 (Allow lower_lifetime_binder receive a closure)
 - #101501 (Allow lint passes to be bound by `TyCtxt`)
 - #101515 (Recover from typo where == is used in place of =)
 - #101545 (Remove unnecessary `PartialOrd` and `Ord`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-08 15:53:14 +00:00
Dylan DPC
953a6b3da7
Rollup merge of #101496 - spastorino:lower_lifetime_binder_api_changes, r=oli-obk
Allow lower_lifetime_binder receive a closure

``@oli-obk`` requested this and other changes as a way of simplifying https://github.com/rust-lang/rust/pull/101345. This is just going to make the diff of https://github.com/rust-lang/rust/pull/101345 smaller.

r? ``@oli-obk`` ``@cjgillot``
2022-09-08 20:48:36 +05:30
Nicholas Nethercote
e67f39f8bc Introduce DotDotPos.
This shrinks `hir::Pat` from 88 to 72 bytes.
2022-09-08 15:25:50 +10:00
Nicholas Nethercote
4314615ff8 Arena-allocate hir::Lifetime.
This shrinks `hir::Ty` from 72 to 48 bytes.

`visit_lifetime` is added to the HIR stats collector because these types
are now stored in memory on their own, instead of being within other
types.
2022-09-08 15:07:19 +10:00
Santiago Pastorino
36fa12f1a4
Allow lower_lifetime_binder receive a closure 2022-09-07 18:01:01 -03:00
Matthias Krüger
0a1c816dcd
Rollup merge of #101503 - spastorino:add-debug-calls, r=compiler-errors
Add debug calls

`@oli-obk` requested this and other changes as a way of simplifying https://github.com/rust-lang/rust/pull/101345. This is just going to make the diff of https://github.com/rust-lang/rust/pull/101345 smaller.

r? `@oli-obk` `@cjgillot`
2022-09-07 21:48:16 +02:00
Matthias Krüger
9361297dfc
Rollup merge of #101493 - spastorino:borrow-mut-impl-trait-context, r=oli-obk
Pass ImplTraitContext as &mut to avoid the need of ImplTraitContext::reborrow

`@oli-obk` requested this and other changes as a way of simplifying #101345. This is just going to make the diff of #101345 smaller.

r? `@oli-obk` `@cjgillot`
2022-09-07 21:48:14 +02:00
Santiago Pastorino
e3a738a942
Add instrument and debug calls 2022-09-07 10:46:14 -03:00
Yuki Okushi
a12e29af92
Rollup merge of #101468 - spastorino:fix-ice-rpit-hrtb-without-dyn, r=cjgillot
fix RPIT ICE for implicit HRTB when missing dyn

Closes #101297

r? `@cjgillot`

cc `@nikomatsakis`
2022-09-07 07:43:52 +09:00
Santiago Pastorino
2166a36245
Pass ImplTraitContext as &mut to avoid the need of ImplTraitContext::reborrow later on 2022-09-06 15:22:16 -03:00
Santiago Pastorino
3f45dc1472
fix RPIT ICE for implicit HRTB when missing dyn 2022-09-06 11:00:29 -03:00
bors
6c358c67d4 Auto merge of #101241 - camsteffen:refactor-binding-annotations, r=cjgillot
`BindingAnnotation` refactor

* `ast::BindingMode` is deleted and replaced with `hir::BindingAnnotation` (which is moved to `ast`)
* `BindingAnnotation` is changed from an enum to a tuple struct e.g. `BindingAnnotation(ByRef::No, Mutability::Mut)`
* Associated constants added for convenience `BindingAnnotation::{NONE, REF, MUT, REF_MUT}`

One goal is to make it more clear that `BindingAnnotation` merely represents syntax `ref mut` and not the actual binding mode. This was especially confusing since we had `ast::BindingMode`->`hir::BindingAnnotation`->`thir::BindingMode`.

I wish there were more symmetry between `ByRef` and `Mutability` (variant) naming (maybe `Mutable::Yes`?), and I also don't love how long the name `BindingAnnotation` is, but this seems like the best compromise. Ideas welcome.
2022-09-06 03:16:29 +00:00
Yuki Okushi
0d8a1f4cbf
Rollup merge of #101447 - cjgillot:no-remap-resolver, r=spastorino
Remove generics_def_id_map from the resolver.

This is internal state for lowering.  This does not belong in the resolver.

r? ``@spastorino``
2022-09-06 08:36:10 +09:00
bors
b44197abb0 Auto merge of #101261 - TaKO8Ki:separate-receiver-from-arguments-in-hir, r=cjgillot
Separate the receiver from arguments in HIR

Related to #100232

cc `@cjgillot`
2022-09-05 16:21:40 +00:00
bors
2dc703fd6e Auto merge of #101228 - nnethercote:simplify-hir-PathSegment, r=petrochenkov
Simplify `hir::PathSegment`

r? `@petrochenkov`
2022-09-05 13:36:54 +00:00
Takayuki Maeda
87c6da363f separate the receiver from arguments in HIR 2022-09-05 22:25:49 +09:00
Camille GILLOT
037ab1d183 Remove generics_def_id_map from the resolver. 2022-09-05 13:32:13 +02:00
Dylan DPC
5d55009b79
Rollup merge of #101142 - nnethercote:improve-hir-stats, r=davidtwco
Improve HIR stats

#100398 improve the AST stats collection done by `-Zhir-stats`. This PR does the same for HIR stats collection.

r? `@davidtwco`
2022-09-05 14:15:51 +05:30
Nicholas Nethercote
08a00eb0da Address review comments. 2022-09-05 14:20:29 +10:00
Nicholas Nethercote
bb0ae3c446 Make hir::PathSegment::hir_id non-optional. 2022-09-05 14:20:25 +10:00
Nicholas Nethercote
6d850d936b Make hir::PathSegment::res non-optional. 2022-09-05 14:20:25 +10:00
Cameron Steffen
02ba216e3c Refactor and re-use BindingAnnotation 2022-09-02 12:55:05 -05:00
Oli Scherer
ee3c835018 Always import all tracing macros for the entire crate instead of piecemeal by module 2022-09-01 14:54:27 +00:00
Oli Scherer
d3b22c7267 Directly use the instrument macro instead of its full path 2022-09-01 14:53:46 +00:00
bors
eac6c33bc6 Auto merge of #100869 - nnethercote:replace-ThinVec, r=spastorino
Replace `rustc_data_structures::thin_vec::ThinVec` with `thin_vec::ThinVec`

`rustc_data_structures::thin_vec::ThinVec` looks like this:
```
pub struct ThinVec<T>(Option<Box<Vec<T>>>);
```
It's just a zero word if the vector is empty, but requires two
allocations if it is non-empty. So it's only usable in cases where the
vector is empty most of the time.

This commit removes it in favour of `thin_vec::ThinVec`, which is also
word-sized, but stores the length and capacity in the same allocation as
the elements. It's good in a wider variety of situation, e.g. in enum
variants where the vector is usually/always non-empty.

The commit also:
- Sorts some `Cargo.toml` dependency lists, to make additions easier.
- Sorts some `use` item lists, to make additions easier.
- Changes `clean_trait_ref_with_bindings` to take a
  `ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this
  avoid some unnecessary allocations.

r? `@spastorino`
2022-09-01 08:01:06 +00:00
bors
b32223fec1 Auto merge of #100707 - dzvon:fix-typo, r=davidtwco
Fix a bunch of typo

This PR will fix some typos detected by [typos].

I only picked the ones I was sure were spelling errors to fix, mostly in
the comments.

[typos]: https://github.com/crate-ci/typos
2022-09-01 05:39:58 +00:00
Dezhi Wu
b1430fb7ca Fix a bunch of typo
This PR will fix some typos detected by [typos].

I only picked the ones I was sure were spelling errors to fix, mostly in
the comments.

[typos]: https://github.com/crate-ci/typos
2022-08-31 18:24:55 +08:00
Matthias Krüger
78e5d05ea0
Rollup merge of #101049 - JeanCASPAR:remove-span_fatal-from-ast_lowering, r=davidtwco
Remove span fatal from ast lowering

Now the crate `rustc_ast_lowering` is fully migrated to `SessionDiagnostic`.

r? ``@davidtwco``
2022-08-31 07:57:59 +02:00
JeanCASPAR
79d4f09942
Change fatal diagnostic to an error.
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2022-08-30 14:26:09 +02:00
Nilstrieb
d1ef8180f9 Revert let_chains stabilization
This reverts commit 3266460749.

This is the revert against master, the beta revert was already done in #100538.
2022-08-29 19:34:11 +02:00
Nicholas Nethercote
b38106b6d8 Replace rustc_data_structures::thin_vec::ThinVec with thin_vec::ThinVec.
`rustc_data_structures::thin_vec::ThinVec` looks like this:
```
pub struct ThinVec<T>(Option<Box<Vec<T>>>);
```
It's just a zero word if the vector is empty, but requires two
allocations if it is non-empty. So it's only usable in cases where the
vector is empty most of the time.

This commit removes it in favour of `thin_vec::ThinVec`, which is also
word-sized, but stores the length and capacity in the same allocation as
the elements. It's good in a wider variety of situation, e.g. in enum
variants where the vector is usually/always non-empty.

The commit also:
- Sorts some `Cargo.toml` dependency lists, to make additions easier.
- Sorts some `use` item lists, to make additions easier.
- Changes `clean_trait_ref_with_bindings` to take a
  `ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this
  avoid some unnecessary allocations.
2022-08-29 15:42:13 +10:00
Nicholas Nethercote
22379bd9db Use &'hir Mod everywhere.
For consistency, and because it makes HIR measurement simpler and more
accurate.
2022-08-29 06:35:14 +10:00
Nicholas Nethercote
a847d5e4ce Use &'hir Ty everywhere.
For consistency, and because it makes HIR measurement simpler and more
accurate.
2022-08-29 06:35:14 +10:00
Nicholas Nethercote
db35b685a7 Use &'hir Expr everywhere.
For consistency, and because it makes HIR measurement simpler and more
accurate.
2022-08-29 06:35:14 +10:00
Jean CASPAR
e89d4fcc7d remove span_fatal from ast_lowering 2022-08-27 09:15:55 +02:00
Michael Goulet
bc1d205e4c
Rollup merge of #100724 - JeanCASPAR:migrate-ast_lowering-to-session-diagnostic, r=davidtwco
Migrate ast lowering to session diagnostic

I migrated the whole rustc_ast_lowering crate to session diagnostic *except* the for the use of `span_fatal` at /compiler/rustc_ast_lowering/src/expr.rs#L1268 because `#[fatal(...)]` is not yet supported (see https://github.com/rust-lang/rust/pull/100694).
2022-08-26 15:56:21 -07:00
Nicholas Nethercote
6087dc2054 Remove the symbol from ast::LitKind::Err.
Because it's never used meaningfully.
2022-08-23 16:56:24 +10:00
Jean CASPAR
5fef1b865f Resolve conflicts 2022-08-22 19:34:19 +02:00
Jean CASPAR
9472df10d0 Changes made in response to feedback 2022-08-22 19:24:14 +02:00
Jean CASPAR
e701c72a63 Migrate all span_err(...) in ast_lowering to SessionDiagnostic 2022-08-22 19:21:41 +02:00
Jean CASPAR
5164966591 Migrate ast_lowering::pat to SessionDiagnostic 2022-08-22 19:21:41 +02:00
Jean CASPAR
d75fd91d50 Migrate ast_lowering::ast to SessionDiagnostic 2022-08-22 19:21:39 +02:00
Jean CASPAR
1382d307d3 Migrate ast_lowering::expr to SessionDiagnostic 2022-08-22 19:21:39 +02:00
Jean CASPAR
0043d10c71 Migrate ast_lowering::lib and ast_lowering::item to SessionDiagnostic 2022-08-22 19:19:59 +02:00
Jean CASPAR
73ae38bac1 Migrate ast_lowering::path to SessionDiagnostic 2022-08-22 19:19:58 +02:00
Nicholas Nethercote
619b8abaa6 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.
2022-08-22 07:35:33 +10:00
Matthias Krüger
d5dca26a94
Rollup merge of #100018 - nnethercote:clean-up-LitKind, r=petrochenkov
Clean up `LitKind`

r? ``@petrochenkov``
2022-08-17 12:32:49 +02:00
Dylan DPC
2e78db3858
Rollup merge of #100610 - nnethercote:ast-and-parser-tweaks, r=spastorino
Ast and parser tweaks

r? `@spastorino`
2022-08-16 18:16:13 +05:30
bors
14a459bf37 Auto merge of #100441 - nnethercote:shrink-ast-Attribute, r=petrochenkov
Shrink `ast::Attribute`.

r? `@ghost`
2022-08-16 07:54:22 +00:00
bors
8556e6620e Auto merge of #100611 - matthiaskrgr:rollup-rxj10ur, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #100338 (when there are 3 or more return statements in the loop)
 - #100384 (Add support for generating unique profraw files by default when using `-C instrument-coverage`)
 - #100460 (Update the minimum external LLVM to 13)
 - #100567 (Add missing closing quote)
 - #100590 (Suggest adding an array length if possible)
 - #100600 (Rename Machine memory hooks to suggest when they run)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-16 05:13:38 +00:00
Matthias Krüger
76dd1663d9
Rollup merge of #100590 - TaKO8Ki:suggest-adding-array-length, r=compiler-errors
Suggest adding an array length if possible

fixes #100448
2022-08-16 06:05:59 +02:00
Nicholas Nethercote
5d3cc1713a 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`.
2022-08-16 13:41:34 +10:00
bors
ef9810a3e2 Auto merge of #100237 - cjgillot:no-special-hash-hir, r=nagisa
Remove manual implementations of HashStable for hir::Expr and hir::Ty.

We do not need to force hashing HIR bodies inside those nodes. The contents of bodies are not accessible from the `hir_owner` query which used `hash_without_bodies`. When the content of a body is required, the access is still done using `hir_owner_nodes`, which continues hashing HIR bodies.
2022-08-16 02:32:47 +00:00
Nicholas Nethercote
3e04fed6fa Remove {ast,hir}::WhereEqPredicate::id.
These fields are unused.
2022-08-16 12:13:23 +10:00
Nicholas Nethercote
85a6cd6a47 Shrink ast::Attribute. 2022-08-16 11:10:13 +10:00
Takayuki Maeda
4d1b5f0d99 suggest adding an array length if possible 2022-08-16 00:16:14 +09:00
bors
6ce76091c7 Auto merge of #96745 - ehuss:even-more-attribute-validation, r=cjgillot
Visit attributes in more places.

This adds 3 loosely related changes (I can split PRs if desired):

- Attribute checking on pattern struct fields.
- Attribute checking on struct expression fields.
- Lint level visiting on pattern struct fields, struct expression fields, and generic parameters.

There are still some lints which ignore lint levels in various positions. This is a consequence of how the lints themselves are implemented. For example, lint levels on associated consts don't work with `unused_braces`.
2022-08-15 05:50:54 +00:00
Mark Rousskov
154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
Eric Huss
7b36047239 Make Node::ExprField a child of Node::Expr.
This was incorrectly inserting the ExprField as a sibling of the struct
expression.

This required adjusting various parts which were looking at parent node
of a field expression to find the struct.
2022-08-11 21:48:39 -07:00
Eric Huss
dcd5177fd4 Add visitors for PatField and ExprField.
This helps simplify the code. It also fixes it to use the correct parent
when lowering. One consequence is the `non_snake_case` lint needed
to change the way it looked for parent nodes in a struct pattern.

This also includes a small fix to use the correct `Target` for
expression field attribute validation.
2022-08-11 21:48:39 -07:00
Eric Huss
b651c1cebe Check attributes on struct expression fields.
Attributes on struct expression fields were not being checked for
validity. This adds the fields as HIR nodes so that `CheckAttrVisitor`
can visit those nodes to check their attributes.
2022-08-11 21:48:39 -07:00
Eric Huss
1b464c73b7 Check attributes on pattern fields.
Attributes on pattern struct fields were not being checked for validity.
This adds the fields as HIR nodes so that the `CheckAttrVisitor` can
visit those nodes to check their attributes.
2022-08-11 21:48:39 -07:00
Matthias Krüger
8237efc52d
Rollup merge of #100392 - nnethercote:simplify-visitors, r=cjgillot
Simplify visitors

By removing some unused arguments.

r? `@cjgillot`
2022-08-11 22:53:08 +02:00
Matthias Krüger
e221aafae6
Rollup merge of #100307 - nnethercote:fix-96847, r=cjgillot
Fix #96847

r? `@petrochenkov`
2022-08-11 22:53:05 +02:00
Nicholas Nethercote
ce78042a42 Avoid lowering a MacArgs::Eq twice.
Fixes #96847.
2022-08-11 21:06:40 +10:00
Nicholas Nethercote
232bd80130 Simplify rustc_ast::visit::Visitor::visit_poly_trait_ref.
It is passed an argument that is never used.
2022-08-11 11:10:01 +10:00
Nicholas Nethercote
8c5303898e Simplify rustc_hir::intravisit::Visitor::visit_variant_data.
It has four arguments that are never used. This avoids lots of argument
passing in functions that feed into `visit_variant_data`.
2022-08-11 10:54:01 +10:00
Camille GILLOT
9701845287 Do not consider method call receiver as an argument in AST. 2022-08-10 18:34:54 +02:00
Santiago Pastorino
750a04ea7f
Add docs for get_remapped_def_id 2022-08-09 16:39:02 -03:00
Santiago Pastorino
457ff7c56c
Iterate def_ids map backwards to try first the latest mappings (it's a stack) 2022-08-09 16:33:19 -03:00
Camille GILLOT
5d75ca5ef4 Remove unused hashing infra. 2022-08-07 17:51:55 +02:00
Camille GILLOT
f6af4efec5 Use start_point instead of next_point to point to elided lifetime ampersand. 2022-08-07 14:35:11 +02:00
Santiago Pastorino
4170d7390b
Fix typo 2022-08-04 15:13:47 -03:00
Santiago Pastorino
065e497630
Improve opt_local_def_id docs 2022-08-04 15:13:44 -03:00
Santiago Pastorino
bf1c7da147
Improve record_def_id_remap docs 2022-08-04 12:47:19 -03:00
Santiago Pastorino
ece52451f6
Do not collect lifetimes with Infer resolution 2022-08-04 12:40:00 -03:00
Santiago Pastorino
45991f9175
Use span_bug instead of panic 2022-08-04 12:07:03 -03:00
Santiago Pastorino
5e71659983
Add docs to record_elided_anchor 2022-08-04 11:27:02 -03:00
Santiago Pastorino
f8b1b2bdfb
Extract record_elided_anchor 2022-08-04 11:27:02 -03:00
Santiago Pastorino
9f10f589a7
Move new_remapping inside with_hir_id_owner 2022-08-04 11:27:02 -03:00
Santiago Pastorino
1ece866cf1
Add documentation for create_lifetime_defs 2022-08-04 11:27:02 -03:00
Santiago Pastorino
2f353d1f72
Add more debug calls 2022-08-04 11:27:01 -03:00
Santiago Pastorino
cab67404a4
Add documentation about lifetime args 2022-08-04 11:27:01 -03:00
Santiago Pastorino
a3bfdc77a7
Add documentation about lifetime_defs 2022-08-04 11:27:01 -03:00
Santiago Pastorino
9c7de6fb3c
Move hir_bounds after lifetime_defs 2022-08-04 11:27:01 -03:00
Santiago Pastorino
3f7db370ef
captures -> collected_lifetimes 2022-08-04 11:27:00 -03:00
Santiago Pastorino
12fa3393a5
Move lifetimes_in_bounds call to outside with_hir_id_owner block in lower_async_fn_ret_ty 2022-08-04 11:27:00 -03:00