about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2024-05-28Cache whether a body has inline constsOli Scherer-1/+7
2024-05-17Rename Unsafe to SafetySantiago Pastorino-1/+1
2024-05-13Warn against redundant use<...>Michael Goulet-6/+9
2024-05-09Add `ErrorGuaranteed` to `Recovered::Yes` and use it more.Nicholas Nethercote-1/+2
The starting point for this was identical comments on two different fields, in `ast::VariantData::Struct` and `hir::VariantData::Struct`: ``` // FIXME: investigate making this a `Option<ErrorGuaranteed>` recovered: bool ``` I tried that, and then found that I needed to add an `ErrorGuaranteed` to `Recovered::Yes`. Then I ended up using `Recovered` instead of `Option<ErrorGuaranteed>` for these two places and elsewhere, which required moving `ErrorGuaranteed` from `rustc_parse` to `rustc_ast`. This makes things more consistent, because `Recovered` is used in more places, and there are fewer uses of `bool` and `Option<ErrorGuaranteed>`. And safer, because it's difficult/impossible to set `recovered` to `Recovered::Yes` without having emitted an error.
2024-05-04Auto merge of #124401 - oli-obk:some_hir_cleanups, r=cjgillotbors-12/+14
Some hir cleanups It seemed odd to not put `AnonConst` in the arena, compared with the other types that we did put into an arena. This way we can also give it a `Span` without growing a lot of other HIR data structures because of the extra field. r? compiler
2024-04-30Remove `extern crate tracing` from numerous crates.Nicholas Nethercote-4/+1
2024-04-26Move `ConstArg::span` to `AnonConst::span`Oli Scherer-4/+3
2024-04-26put `hir::AnonConst` on the hir arenaOli Scherer-9/+12
2024-04-25ast: Generalize item kind visitingVadim Petrochenkov-1/+1
And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).
2024-04-17Rename `BindingAnnotation` to `BindingMode`Jules Bertholet-5/+5
2024-04-17Rollup merge of #122813 - nnethercote:nicer-quals, r=compiler-errorsMatthias Krüger-22/+15
Qualifier tweaking Adding and removing qualifiers in some cases that make things nicer. Details in individual commits. r? `@compiler-errors`
2024-04-16Avoid lots of `hir::HirId{,Map,Set}` qualifiers.Nicholas Nethercote-22/+15
Because they're a bit redundant.
2024-04-15Use a path instead of an ident (and stop manually resolving)Michael Goulet-4/+7
2024-04-15Add hir::Node::PreciseCapturingNonLifetimeArgMichael Goulet-2/+6
2024-04-15Validation and other thingsMichael Goulet-5/+4
2024-04-15Lower and resolve precise captures in HIRMichael Goulet-7/+40
2024-04-15Use dedicated PreciseCapturingArg for representing what goes in use<>Michael Goulet-46/+43
2024-04-15Begin AST lowering for precise capturesMichael Goulet-29/+50
2024-04-15Parsing , pre-lowering support for precise capturesMichael Goulet-1/+2
2024-04-08Thread pattern types through the HIROli Scherer-1/+1
2024-04-08Add pattern types to astOli Scherer-1/+4
2024-04-03rustc_index: Add a `ZERO` constant to index typesVadim Petrochenkov-4/+4
It is commonly used.
2024-03-27Implement `mut ref`/`mut ref mut`Jules Bertholet-2/+2
2024-03-22Rename `hir::Local` into `hir::LetStmt`Guillaume Gomez-1/+1
2024-03-21Fix bad span for explicit lifetime suggestionShoyu Vanilla-27/+36
Move verbose logic to a function Minor renaming
2024-03-15Auto merge of #122517 - petrochenkov:bodihash, r=oli-obkbors-17/+2
Fill in HIR hash for associated opaque types Fixes https://github.com/rust-lang/rust/issues/122508
2024-03-14Fill in HIR hash for associated opaque typesVadim Petrochenkov-17/+2
2024-03-14Rename `hir::StmtKind::Local` into `hir::StmtKind::Let`Guillaume Gomez-1/+1
2024-03-08Simplify ImplTraitContextMichael Goulet-26/+17
2024-03-08Make TAITs capture all higher-ranked lifetimes in scopeMichael Goulet-13/+14
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-06Rewrite the `untranslatable_diagnostic` lint.Nicholas Nethercote-0/+1
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-05Avoid using feed_unit_query from within queriesOli Scherer-1/+1
2024-02-28Rename `DiagnosticArgFromDisplay` as `DiagArgFromDisplay`.Nicholas Nethercote-3/+3
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-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-15Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.Nicholas Nethercote-1/+2
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-14Use fewer delayed bugs.Nicholas Nethercote-3/+1
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-11/+43
2024-02-10Remove unused fnMichael Goulet-6/+0
2024-02-10Add a helpful suggestionMichael Goulet-33/+30
2024-02-10No more associated type bounds in dyn traitMichael Goulet-53/+6
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-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