summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2024-08-27Rollup merge of #129626 - compiler-errors:explicit-named, r=fmeaseMatthias Krüger-2/+0
Remove `ParamMode::ExplicitNamed` This was introduced as a hack to improve a diagnostics suggestion in #61679. It was subsequently broken, but also it was an incomplete hack that I don't believe we need to support, so let's just remove it.
2024-08-27Rollup merge of #129625 - compiler-errors:generic-args-mode, r=fmeaseMatthias Krüger-1/+1
Rename `ParenthesizedGenericArgs` to `GenericArgsMode` A bit easier to digest name. Broken out of a PR implementing return type notation.
2024-08-27Rollup merge of #126013 - nnethercote:unreachable_pub, r=UrgauMatthias Krüger-0/+1
Add `#[warn(unreachable_pub)]` to a bunch of compiler crates By default `unreachable_pub` identifies things that need not be `pub` and tells you to make them `pub(crate)`. But sometimes those things don't need any kind of visibility. So they way I did these was to remove the visibility entirely for each thing the lint identifies, and then add `pub(crate)` back in everywhere the compiler said it was necessary. (Or occasionally `pub(super)` when context suggested that was appropriate.) Tedious, but results in more `pub` removal. There are plenty more crates to do but this seems like enough for a first PR. r? `@compiler-errors`
2024-08-26Rename ParenthesizedGenericArgs to GenericArgsModeMichael Goulet-1/+1
2024-08-26Remove ParamMode::ExplicitNamedMichael Goulet-2/+0
2024-08-19Retroactively feature gate `ConstArgKind::Path`Boxy-3/+4
2024-08-16Add `warn(unreachable_pub)` to `rustc_ast_lowering`.Nicholas Nethercote-0/+1
2024-08-10rustc_ast_lowering: make "using `_` for array lengths is unstable" translatablePavel Grigorenko-2/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+6
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-26Rollup merge of #128226 - oli-obk:option_vs_empty_slice, r=petrochenkovTrevor Gross-3/+3
Remove redundant option that was just encoding that a slice was empty There is already a sanity check ensuring we don't put empty attribute lists into the HIR: https://github.com/rust-lang/rust/blob/6ef11b81c2c02c3c4b7556d1991a98572fe9af87/compiler/rustc_ast_lowering/src/lib.rs#L661-L667
2024-07-26Remove redundant option that was just encoding that a slice was emptyOli Scherer-3/+3
2024-07-25Support ?Trait bounds in supertraits and dyn Trait under a feature gateBryanskiy-15/+13
2024-07-16Add `ConstArgKind::Path` and make `ConstArg` its own HIR nodeNoah Lev-33/+117
This is a very large commit since a lot needs to be changed in order to make the tests pass. The salient changes are: - `ConstArgKind` gets a new `Path` variant, and all const params are now represented using it. Non-param paths still use `ConstArgKind::Anon` to prevent this change from getting too large, but they will soon use the `Path` variant too. - `ConstArg` gets a distinct `hir_id` field and its own variant in `hir::Node`. This affected many parts of the compiler that expected the parent of an `AnonConst` to be the containing context (e.g., an array repeat expression). They have been changed to check the "grandparent" where necessary. - Some `ast::AnonConst`s now have their `DefId`s created in rustc_ast_lowering rather than `DefCollector`. This is because in some cases they will end up becoming a `ConstArgKind::Path` instead, which has no `DefId`. We have to solve this in a hacky way where we guess whether the `AnonConst` could end up as a path const since we can't know for sure until after name resolution (`N` could refer to a free const or a nullary struct). If it has no chance as being a const param, then we create a `DefId` in `DefCollector` -- otherwise we decide during ast_lowering. This will have to be updated once all path consts use `ConstArgKind::Path`. - We explicitly use `ConstArgHasType` for array lengths, rather than implicitly relying on anon const type feeding -- this is due to the addition of `ConstArgKind::Path`. - Some tests have their outputs changed, but the changes are for the most part minor (including removing duplicate or almost-duplicate errors). One test now ICEs, but it is for an incomplete, unstable feature and is now tracked at #127009.
2024-07-16Use `ConstArg` for const param defaultsNoah Lev-1/+1
Now everything that actually affects the type system (i.e., excluding const blocks, enum variant discriminants, etc.) *should* be using `ConstArg`.
2024-07-16Use `ConstArg` for array lengthsNoah Lev-2/+2
2024-07-16Use `ConstArg` for assoc item constraintsNoah Lev-1/+1
2024-07-16Setup ast_lowering functions for `ConstArg`Noah Lev-50/+64
2024-07-16hir: Create `hir::ConstArgKind` enumNoah Lev-3/+3
This will allow lowering const params to a dedicated enum variant, rather than to an `AnonConst` that is later examined during `ty` lowering.
2024-07-16Add `current_def_id_parent` to `LoweringContext`Noah Lev-6/+26
This is needed to track anon const parents properly once we implement `ConstArgKind::Path` (which requires moving anon const def-creation outside of `DefCollector`): Why do we need this in addition to [`Self::current_hir_id_owner`]? Currently (as of June 2024), anonymous constants are not HIR owners; however, they do get their own DefIds. Some of these DefIds have to be created during AST lowering, rather than def collection, because we can't tell until after name resolution whether an anonymous constant will end up instead being a [`rustc_hir::ConstArgKind::Path`]. However, to compute which generics are available to an anonymous constant nested inside another, we need to make sure that the parent is recorded as the parent anon const, not the enclosing item. So we need to track parent defs differently from HIR owners, since they will be finer-grained in the case of anon consts.
2024-07-03Rollup merge of #127092 - compiler-errors:rtn-dots-redux, r=estebankMatthias Krüger-15/+10
Change return-type-notation to use `(..)` Aligns the syntax with the current wording of [RFC 3654](https://github.com/rust-lang/rfcs/pull/3654). Also implements rustfmt support (along with making a match exhaustive). Tracking: * https://github.com/rust-lang/rust/issues/109417
2024-06-28Change RTN to use .. againMichael Goulet-15/+10
2024-06-28implement new effects desugaringDeadbeef-76/+15
2024-06-24Deny use<> for RPITITsMichael Goulet-0/+20
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-2/+2
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-17Delay a bug and mark precise_capturing as not incompleteMichael Goulet-1/+5
2024-06-17Detect duplicatesMichael Goulet-4/+7
2024-06-17Rework precise capturing syntaxMichael Goulet-68/+64
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-1/+3
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
2024-06-07Rollup merge of #124214 - carbotaniuman:parse_unsafe_attrs, r=michaelwoeristerMatthias Krüger-0/+1
Parse unsafe attributes Initial parse implementation for #123757 This is the initial work to parse unsafe attributes, which is represented as an extra `unsafety` field in `MetaItem` and `AttrItem`. There's two areas in the code where it appears that parsing is done manually and not using the parser stuff, and I'm not sure how I'm supposed to thread the change there.
2024-06-07Revert "Cache whether a body has inline consts"Oli Scherer-7/+1
This reverts commit eae5031ecbda434e92966099e0dc93917de03eff.
2024-06-06Parse unsafe attributescarbotaniuman-0/+1
2024-06-04Handle safety keyword for extern block inner itemsSantiago Pastorino-1/+1
2024-05-31Rollup merge of #125635 - fmease:mv-type-binding-assoc-item-constraint, ↵Matthias Krüger-30/+21
r=compiler-errors Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanup Rename `hir::TypeBinding` and `ast::AssocConstraint` to `AssocItemConstraint` and update all items and locals using the old terminology. Motivation: The terminology *type binding* is extremely outdated. "Type bindings" not only include constraints on associated *types* but also on associated *constants* (feature `associated_const_equality`) and on RPITITs of associated *functions* (feature `return_type_notation`). Hence the word *item* in the new name. Furthermore, the word *binding* commonly refers to a mapping from a binder/identifier to a "value" for some definition of "value". Its use in "type binding" made sense when equality constraints (e.g., `AssocTy = Ty`) were the only kind of associated item constraint. Nowadays however, we also have *associated type bounds* (e.g., `AssocTy: Bound`) for which the term *binding* doesn't make sense. --- Old terminology (HIR, rustdoc): ``` `TypeBinding`: (associated) type binding ├── `Constraint`: associated type bound └── `Equality`: (associated) equality constraint (?) ├── `Ty`: (associated) type binding └── `Const`: associated const equality (constraint) ``` Old terminology (AST, abbrev.): ``` `AssocConstraint` ├── `Bound` └── `Equality` ├── `Ty` └── `Const` ``` New terminology (AST, HIR, rustdoc): ``` `AssocItemConstraint`: associated item constraint ├── `Bound`: associated type bound └── `Equality`: associated item equality constraint OR associated item binding (for short) ├── `Ty`: associated type equality constraint OR associated type binding (for short) └── `Const`: associated const equality constraint OR associated const binding (for short) ``` r? compiler-errors
2024-05-30Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanupLeón Orell Valerian Liehr-30/+21
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