about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/item.rs
AgeCommit message (Collapse)AuthorLines
2025-03-11Auto merge of #128440 - oli-obk:defines, r=lcnrbors-5/+50
Add `#[define_opaques]` attribute and require it for all type-alias-impl-trait sites that register a hidden type Instead of relying on the signature of items to decide whether they are constraining an opaque type, the opaque types that the item constrains must be explicitly listed. A previous version of this PR used an actual attribute, but had to keep the resolved `DefId`s in a side table. Now we just lower to fields in the AST that have no surface syntax, instead a builtin attribute macro fills in those fields where applicable. Note that for convenience referencing opaque types in associated types from associated methods on the same impl will not require an attribute. If that causes problems `#[defines()]` can be used to overwrite the default of searching for opaques in the signature. One wart of this design is that closures and static items do not have generics. So since I stored the opaques in the generics of functions, consts and methods, I would need to add a custom field to closures and statics to track this information. During a T-types discussion we decided to just not do this for now. fixes #131298
2025-03-11Error on `define_opaques` entries without any opaques actually referencedOli Scherer-1/+1
2025-03-11Test invalid `define_opaques` attributesOli Scherer-11/+15
2025-03-11Implement `#[define_opaque]` attribute for functions.Oli Scherer-5/+46
2025-03-10Delegation: fix ICE with invalid MethodCall generationBryanskiy-2/+2
2025-03-03Rollup merge of #132388 - frank-king:feature/where-cfg, r=petrochenkovMatthias Krüger-0/+1
Implement `#[cfg]` in `where` clauses This PR implements #115590, which supports `#[cfg]` attributes in `where` clauses. The biggest change is, that it adds `AttrsVec` and `NodeId` to the `ast::WherePredicate` and `HirId` to the `hir::WherePredicate`.
2025-03-01Implment `#[cfg]` and `#[cfg_attr]` in `where` clausesFrank King-0/+1
2025-02-28Tweak incorrect ABI suggestionEsteban Küber-1/+1
Provide a better suggestion message, and make the suggestion verbose. ``` error[E0703]: invalid ABI: found `riscv-interrupt` --> $DIR/riscv-discoverability-guidance.rs:17:8 | LL | extern "riscv-interrupt" fn isr() {} | ^^^^^^^^^^^^^^^^^ invalid ABI | = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions help: there's a similarly named valid ABI `"riscv-interrupt-m"` | LL | extern "riscv-interrupt-m" fn isr() {} | ++ ```
2025-02-24Introduce new parsing infrastructure and types for parsed attributesJana Dönszelmann-9/+10
fixup docs in parser
2025-02-22Make a fake body to store typeck results for global_asmMichael Goulet-1/+4
2025-02-22Make asm a named fieldMichael Goulet-1/+3
2025-02-11compiler: remove rustc_abi::lookup and AbiUnsupportedJubilee Young-1/+1
These can be entirely replaced by the FromStr implementation.
2025-02-11Auto merge of #136851 - jhpratt:rollup-ftijn95, r=jhprattbors-86/+80
Rollup of 11 pull requests Successful merges: - #136606 (Fix long lines which rustfmt fails to format) - #136663 (Stabilize `NonZero::count_ones`) - #136672 (library: doc: core::alloc::Allocator: trivial typo fix) - #136704 (Improve examples for file locking) - #136721 (cg_llvm: Reduce visibility of some items outside the `llvm` module) - #136813 (rustc_target: Add the fp16 target feature for AArch32) - #136830 (fix i686-unknown-hurd-gnu x87 footnote) - #136832 (Fix platform support table for i686-unknown-uefi) - #136835 (Stop using span hack for contracts feature gating) - #136837 (Overhaul how contracts are lowered on fn-like bodies) - #136839 (fix ensure_monomorphic_enough) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-10Don't ICE when failing to lower contracts for associated impl itemsMichael Goulet-86/+80
2025-02-09compiler: remove `abi`-specific `extern "{abi}"` suggestionsJubilee Young-9/+4
These are either residue of a long-term migration away from something, or are simply trying too hard to be specifically useful: nearest-match suggestions for ABI strings should handle this.
2025-02-09compiler: gate `extern "{abi}"` in ast_loweringJubilee Young-5/+11
By moving this stability check into AST lowering, we effectively make it impossible to accidentally miss, as it must happen to generate HIR. Also, we put the ABI-stability code next to code that actually uses it! This allows code that wants to reason about backend ABI implementations to stop worrying about high-level concerns like syntax stability, while still leaving it as the authority on what ABIs actually exist. It also makes it easy to refactor things to have more consistent errors. For now, we only apply this to generalize the existing messages a bit.
2025-02-09Auto merge of #136751 - bjorn3:update_rustfmt, r=Mark-Simulacrumbors-14/+23
Update bootstrap compiler and rustfmt The rustfmt version we previously used formats things differently from what the latest nightly rustfmt does. This causes issues for subtrees that get formatted both in-tree and in their own repo. Updating the rustfmt used in-tree solves those issues. Also bumped the bootstrap compiler as the stage0 update command always updates both at the same time.
2025-02-08Rustfmtbjorn3-14/+23
2025-02-07compiler: use rustc_abi in rustc_ast_*Jubilee Young-11/+11
2025-02-03Desugars contract into the internal AST extensionsFelix S. Klock II-67/+48
Check ensures on early return due to Try / Yeet Expand these two expressions to include a call to contract checking
2025-02-03Express contracts as part of function header and lower it to the contract ↵Celina G. Val-4/+108
lang items includes post-developed commit: do not suggest internal-only keywords as corrections to parse failures. includes post-developed commit: removed tabs that creeped in into rustfmt tool source code. includes post-developed commit, placating rustfmt self dogfooding. includes post-developed commit: add backquotes to prevent markdown checking from trying to treat an attr as a markdown hyperlink/ includes post-developed commit: fix lowering to keep contracts from being erroneously inherited by nested bodies (like closures). Rebase Conflicts: - compiler/rustc_parse/src/parser/diagnostics.rs - compiler/rustc_parse/src/parser/item.rs - compiler/rustc_span/src/hygiene.rs Remove contracts keywords from diagnostic messages
2025-01-22Enforce that all spans are lowered in ast loweringOli Scherer-0/+1
2025-01-15Treat safe target_feature functions as unsafe by defaultOli Scherer-5/+19
2025-01-14Add hir::HeaderSafety to make follow up commits simplerOli Scherer-1/+5
2025-01-04rustc_intrinsic: support functions without body; they are implicitly marked ↵Ralf Jung-19/+39
as must-be-overridden
2025-01-04turn hir::ItemKind::Fn into a named-field variantRalf Jung-6/+6
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-5/+2
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-15Add hir::AttributeJonathan Dönszelmann-3/+3
2024-12-10Keep track of parse errors in `mod`s and don't emit resolve errors for paths ↵Esteban Küber-1/+1
involving them When we expand a `mod foo;` and parse `foo.rs`, we now track whether that file had an unrecovered parse error that reached the end of the file. If so, we keep that information around. When resolving a path like `foo::bar`, we do not emit any errors for "`bar` not found in `foo`", as we know that the parse error might have caused `bar` to not be parsed and accounted for. When this happens in an existing project, every path referencing `foo` would be an irrelevant compile error. Instead, we now skip emitting anything until `foo.rs` is fixed. Tellingly enough, we didn't have any test for errors caused by `mod` expansion. Fix #97734.
2024-12-09Detect `struct S(ty = val);`Esteban Küber-8/+25
Emit a specific error for unsupported default field value syntax in tuple structs.
2024-12-09Introduce `default_field_values` featureEsteban Küber-0/+1
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ``` Add lint for default fields that will always fail const-eval We *allow* this to happen for API writers that might want to rely on users' getting a compile error when using the default field, different to the error that they would get when the field isn't default. We could change this to *always* error instead of being a lint, if we wanted. This will *not* catch errors for partially evaluated consts, like when the expression relies on a const parameter. Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`: - Suggest adding a base expression if there are missing fields. - Suggest enabling the feature if all the missing fields have optional values. - Suggest removing `..` if there are no missing fields.
2024-11-25Refactor `where` predicates, and reserve for attributes supportFrank King-25/+21
2024-11-21Implement the unsafe-fields RFC.Luca Versari-0/+1
Co-Authored-By: Jacob Pratt <jacob@jhpratt.dev>
2024-10-28Add duplicate lowering checkAdwin White-8/+4
2024-10-28Lower AST node id only onceAdwin White-5/+9
2024-10-24Remove associated type based effects logicMichael Goulet-186/+19
2024-10-23nightly feature tracking: get rid of the per-feature bool fieldsRalf Jung-2/+2
2024-10-19Make sure that outer opaques capture inner opaques's lifetimes even with ↵Michael Goulet-1/+1
precise capturing syntax
2024-10-14Move trait bound modifiers into ast::PolyTraitRefMichael Goulet-2/+2
2024-10-02Move in_trait into OpaqueTyOriginMichael Goulet-2/+0
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-43/+31
2024-09-11Also fix if in elseMichael Goulet-6/+4
2024-08-27Rollup merge of #129626 - compiler-errors:explicit-named, r=fmeaseMatthias Krüger-12/+1
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 #126013 - nnethercote:unreachable_pub, r=UrgauMatthias Krüger-1/+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-26Remove ParamMode::ExplicitNamedMichael Goulet-12/+1
2024-08-21Simplify some redundant field namesMichael Goulet-1/+1
2024-08-16Use FnSig instead of raw FnDecl for ForeignItemKind::FnMichael Goulet-7/+17
2024-08-16Add `warn(unreachable_pub)` to `rustc_ast_lowering`.Nicholas Nethercote-1/+1
2024-07-31minor `effects` cleanupsDeadbeef-1/+0
2024-07-29Reformat `use` declarations.Nicholas Nethercote-5/+6
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.