about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src
AgeCommit message (Collapse)AuthorLines
2024-03-08Rollup merge of #119365 - nbdd0121:asm-goto, r=AmanieuMatthias Krüger-4/+33
Add asm goto support to `asm!` Tracking issue: #119364 This PR implements asm-goto support, using the syntax described in "future possibilities" section of [RFC2873](https://rust-lang.github.io/rfcs/2873-inline-asm.html#asm-goto). Currently I have only implemented the `label` part, not the `fallthrough` part (i.e. fallthrough is implicit). This doesn't reduce the expressive though, since you can use label-break to get arbitrary control flow or simply set a value and rely on jump threading optimisation to get the desired control flow. I can add that later if deemed necessary. r? ``@Amanieu`` cc ``@ojeda``
2024-03-08Simplify ImplTraitContextMichael Goulet-29/+22
2024-03-08Make TAITs capture all higher-ranked lifetimes in scopeMichael Goulet-15/+26
2024-03-07Rollup merge of #121089 - oli-obk:create_def_feed, r=petrochenkovGuillaume Gomez-1/+1
Remove `feed_local_def_id` best reviewed commit by commit Basically I returned `TyCtxtFeed` from `create_def` and then preserved that in the local caches based on https://github.com/rust-lang/rust/pull/121084 r? ````@petrochenkov````
2024-03-06Rollup merge of #121382 - nnethercote:rework-untranslatable_diagnostic-lint, ↵Matthias Krüger-0/+3
r=davidtwco Rework `untranslatable_diagnostic` lint Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This PR changes it to check calls to any function with an `impl Into<{D,Subd}iagnosticMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. It also lets us add `#[rustc_lint_diagnostics]` to a number of functions that don't have an `impl Into<{D,Subd}iagnosticMessage>`, such as `Diag::span`. r? ``@davidtwco``
2024-03-06Add postfix match MatchSource to HIRRoss Smyth-2/+5
2024-03-06Add MatchKind member to the Match expr for pretty printing & fmtRoss Smyth-1/+1
2024-03-06Rewrite the `untranslatable_diagnostic` lint.Nicholas Nethercote-0/+3
Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This commit changes it to check calls to any function with an `impl Into<{D,Subd}iagMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. The commit also adds `#[allow(rustc::untranslatable_diagnostic)`] attributes to places that need it that are caught by the improved lint. These places that might be easy to convert to translatable diagnostics. Finally, it also: - Expands and corrects some comments. - Does some minor formatting improvements. - Adds missing `DecorateLint` cases to `tests/ui-fulldeps/internal-lints/diagnostics.rs`.
2024-03-05Use `ControlFlow` in AST visitors.Jason Newcomb-8/+11
2024-03-05Avoid using feed_unit_query from within queriesOli Scherer-1/+1
2024-03-05Rollup merge of #121664 - compiler-errors:adjust-error-yield-lowering, ↵Matthias Krüger-9/+43
r=spastorino Adjust error `yield`/`await` lowering Adjust the lowering of `yield`/`await` outside of their correct scopes so that we no longer make orpan HIR exprs. Previously, `yield EXPR` would be lowered directly to `hir::TyKind::Error` (which I'll call `<error>`) which means that `EXPR` was not present in the HIR, but now we lower it to `{ EXPR; <error> }` so that `EXPR` is not orphaned. Fixes #121096
2024-03-05Rename `SubdiagnosticMessageOp` as `SubdiagMessageOp`.Nicholas Nethercote-2/+2
2024-03-05Rename all `ParseSess` variables/fields/lifetimes as `psess`.Nicholas Nethercote-8/+4
Existing names for values of this type are `sess`, `parse_sess`, `parse_session`, and `ps`. `sess` is particularly annoying because that's also used for `Session` values, which are often co-located, and it can be difficult to know which type a value named `sess` refers to. (That annoyance is the main motivation for this change.) `psess` is nice and short, which is good for a name used this much. The commit also renames some `parse_sess_created` values as `psess_created`.
2024-02-29AST: Refactor type alias where clausesLeón Orell Valerian Liehr-9/+10
2024-02-28Rename `DiagnosticArgFromDisplay` as `DiagArgFromDisplay`.Nicholas Nethercote-6/+5
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-2/+2
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-27Refactor `LoweringContext::get_delegation_sig_id`.Nicholas Nethercote-6/+2
I find the function much easier to read this way. Thanks to @kadiwa4 for the suggestion.
2024-02-27Adjust error yield/await loweringMichael Goulet-9/+43
2024-02-25Add `ErrorGuaranteed` to `ast::ExprKind::Err`Lieselotte-4/+2
2024-02-25Add `ast::ExprKind::Dummy`Lieselotte-1/+8
2024-02-24Add asm label support to AST and HIRGary Guo-4/+33
2024-02-23compiler: clippy::complexity fixesMatthias Krüger-1/+1
2024-02-23Revert some `span_bug`s to `span_delayed_bug`.Nicholas Nethercote-1/+3
Fixes #121410. Fixes #121414. Fixes #121418. Fixes #121431.
2024-02-21Convert `delayed_bug`s to `bug`s.Nicholas Nethercote-3/+1
I have a suspicion that quite a few delayed bug paths are impossible to reach, so I did an experiment. I converted every `delayed_bug` to a `bug`, ran the full test suite, then converted back every `bug` that was hit. A surprising number were never hit. The next commit will convert some more back, based on human judgment.
2024-02-20Reduce capabilities of `Diagnostic`.Nicholas Nethercote-2/+7
Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-16Move trait into attr so it's greppableMichael Goulet-2/+2
2024-02-16Use extension trait deriveMichael Goulet-9/+2
2024-02-16Rollup merge of #121109 - nnethercote:TyKind-Err-guar-2, r=oli-obkGuillaume Gomez-1/+2
Add an ErrorGuaranteed to ast::TyKind::Err (attempt 2) This makes it more like `hir::TyKind::Err`, and avoids a `has_errors` assertion in `LoweringContext::lower_ty_direct`. r? ```@oli-obk```
2024-02-15Rollup merge of #121120 - nnethercote:LitKind-Err-guar, r=fmeaseGuillaume Gomez-3/+9
Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`. Similar to recent work doing the same for `ExprKind::Err` (#120586) and `TyKind::Err` (#121109). r? `@oli-obk`
2024-02-15Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.Nicholas Nethercote-3/+9
This mostly works well, and eliminates a couple of delayed bugs. One annoying thing is that we should really also add an `ErrorGuaranteed` to `proc_macro::bridge::LitKind::Err`. But that's difficult because `proc_macro` doesn't have access to `ErrorGuaranteed`, so we have to fake it.
2024-02-15Add an `ErrorGuaranteed` to `ast::TyKind::Err`.Nicholas Nethercote-1/+2
This makes it more like `hir::TyKind::Err`, and avoids a `span_delayed_bug` call in `LoweringContext::lower_ty_direct`. It also requires adding `ast::TyKind::Dummy`, now that `ast::TyKind::Err` can't be used for that purpose in the absence of an error emission. There are a couple of cases that aren't as neat as I would have liked, marked with `FIXME` comments.
2024-02-15Reinstate some delayed bugs.Nicholas Nethercote-1/+3
These were changed to `has_errors` assertions in #121071 because that seemed reasonable, but evidently not. Fixes #121103. Fixes #121108.
2024-02-14Use fewer delayed bugs.Nicholas Nethercote-7/+3
For some cases where it's clear that an error has already occurred, e.g.: - there's a comment stating exactly that, or - things like HIR lowering, where we are lowering an error kind The commit also tweaks some comments around delayed bug sites.
2024-02-12Lowering field access for anonymous adtsFrank King-16/+11
2024-02-12Lower anonymous structs or unions to HIRFrank King-12/+47
2024-02-10Remove unused fnMichael Goulet-6/+0
2024-02-10Add a helpful suggestionMichael Goulet-33/+32
2024-02-10No more associated type bounds in dyn traitMichael Goulet-56/+8
2024-02-10Rollup merge of #120850 - petrochenkov:empimpres, r=cjgillotMatthias Krüger-1/+6
ast_lowering: Fix regression in `use ::{}` imports. Fixes https://github.com/rust-lang/rust/issues/120789
2024-02-10Rollup merge of #120584 - compiler-errors:u, r=lcnrMatthias Krüger-13/+11
For a rigid projection, recursively look at the self type's item bounds to fix the `associated_type_bounds` feature Given a deeply nested rigid projection like `<<<T as Trait1>::Assoc1 as Trait2>::Assoc2 as Trait3>::Assoc3`, this PR adjusts both trait solvers to look at the item bounds for all of `Assoc3`, `Assoc2`, and `Assoc1` in order to satisfy a goal. We do this because the item bounds for projections may contain relevant bounds for *other* nested projections when the `associated_type_bounds` (ATB) feature is enabled. For example: ```rust #![feature(associated_type_bounds)] trait Trait1 { type Assoc1: Trait2<Assoc2: Foo>; // Item bounds for `Assoc1` are: // `<Self as Trait1>::Assoc1: Trait2` // `<<Self as Trait1>::Assoc1 as Trait2>::Assoc2: Foo` } trait Trait2 { type Assoc2; } trait Foo {} fn hello<T: Trait1>(x: <<T as Trait1>::Assoc1 as Trait2>::Assoc2) { fn is_foo(_: impl Foo) {} is_foo(x); // Currently fails with: // ERROR the trait bound `<<Self as Trait1>::Assoc1 as Trait2>::Assoc2: Foo` is not satisfied } ``` This has been a long-standing place of brokenness for ATBs, and is also part of the reason why ATBs currently desugar so differently in various positions (i.e. sometimes desugaring to param-env bounds, sometimes desugaring to RPITs, etc). For example, in RPIT and TAIT position, `impl Foo<Bar: Baz>` currently desugars to `impl Foo<Bar = impl Baz>` because we do not currently take advantage of these nested item bounds if we desugared them into a single set of item bounds on the opaque. This is obviously both strange and unnecessary if we just take advantage of these bounds as we should. ## Approach This PR repeatedly peels off each projection of a given goal's self type and tries to match its item bounds against a goal, repeating with the self type of the projection. This is pretty straightforward to implement in the new solver, only requiring us to loop on the self type of a rigid projection to discover inner rigid projections, and we also need to introduce an extra probe so we can normalize them. In the old solver, we can do essentially the same thing, however we rely on the fact that projections *should* be normalized already. This is obviously not always the case -- however, in the case that they are not fully normalized, such as a projection which has both infer vars and, we bail out with ambiguity if we hit an infer var for the self type. ## Caveats ⚠️ In the old solver, this has the side-effect of actually stalling some higher-ranked trait goals of the form `for<'a> <?0 as Tr<'a>>: Tr2`. Because we stall them, they no longer are eagerly treated as error -- this cause some existing `known-bug` tests to go from fail -> pass. I'm pretty unconvinced that this is a problem since we make code that we expect to pass in the *new* solver also pass in the *old* solver, though this obviously doesn't solve the *full* problem. ## And then also... We also adjust the desugaring of ATB to always desugar to a regular associated bound, rather than sometimes to an impl Trait **except** for when the ATB is present in a `dyn Trait`. We need to lower `dyn Trait<Assoc: Bar>` to `dyn Trait<Assoc = impl Bar>` because object types need all of their associated types specified. I would also be in favor of splitting out the ATB feature and/or removing support for object types in order to stabilize just the set of positions for which the ATB feature is consistent (i.e. always elaborates to a bound).
2024-02-09ast_lowering: Fix regression in `use ::{}` imports.Vadim Petrochenkov-1/+6
2024-02-09Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwcoMatthias Krüger-2/+0
Invert diagnostic lints. That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has been converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted. r? ````@davidtwco````
2024-02-09Don't unnecessarily lower associated type bounds to impl traitMichael Goulet-13/+11
2024-02-08Rollup merge of #120750 - compiler-errors:itctx-by-val, r=cjgillotMatthias Krüger-92/+90
No need to take `ImplTraitContext` by ref We used to mutate `ImplTraitContext`, so it used to be `&mut` mutable ref. Then I think it used to have non-`Copy` data in it, so we took it by `&` ref. Now, none of that remains, so just copy it around.
2024-02-08Rollup merge of #120734 - nnethercote:SubdiagnosticMessageOp, r=compiler-errorsMatthias Krüger-9/+5
Add `SubdiagnosticMessageOp` as a trait alias. It avoids a lot of repetition. r? matthewjasper
2024-02-08Add `SubdiagnosticMessageOp` as a trait alias.Nicholas Nethercote-9/+5
It avoids a lot of repetition.
2024-02-07No need to take ImplTraitContext by refMichael Goulet-92/+90
2024-02-07hir: Add some FIXMEs for future workVadim Petrochenkov-0/+1
2024-02-07hir: Make sure all `HirId`s have corresponding HIR `Node`sVadim Petrochenkov-7/+38
2024-02-06Rollup merge of #120609 - petrochenkov:nousestem2, r=compiler-errorsMatthias Krüger-9/+23
hir: Stop keeping prefixes for most of `use` list stems And make sure all other imports have non-empty resolution lists. Addresses one of FIXMEs in https://github.com/rust-lang/rust/pull/120206.