about summary refs log tree commit diff
path: root/compiler/rustc_ast_passes/src/ast_validation.rs
AgeCommit message (Collapse)AuthorLines
2025-09-18Rollup merge of #146434 - folkertdev:c-variadic-inherent-methods, ↵Matthias Krüger-6/+1
r=workingjubilee c-variadic: allow c-variadic inherent and trait methods tracking issue: https://github.com/rust-lang/rust/issues/44930 Continuing the work of https://github.com/rust-lang/rust/pull/146342, allow inherent and trait methods to be c-variadic. However, a trait that contains a c-variadic method is no longer dyn-compatible. There is, presumably, some way to make c-variadic methods dyn-compatible. However currently, we don't have confidence that it'll work reliably: when methods from a `dyn` object are cast to a function pointer, a `ReifyShim` is created. If that shim is c-variadic, it would need to forward the C variable argument list. That does appear to work, because the `va_list` is not represented in MIR at all in this case, so the registers from the call site are untouched by the shim and can be read by the actual implementation. That just does not seem like a solid implementation. Also, intuitively, why would c-variadic function, primarily needed for FFI, need to be used with `dyn` objects at all? We can revisit this limitation if a need arises. r? `@workingjubilee`
2025-09-14Move more early buffered lints to dyn lint diagnostics (2/N)León Orell Valerian Liehr-1/+1
2025-09-11c-variadic: allow trait methods to be c-variadicFolkert de Vries-33/+26
but a C-variadic method makes a trait dyn-incompatible. That is because methods from dyn traits, when cast to a function pointer, create a shim. That shim can't really forward the c-variadic arguments.
2025-09-11c-variadic: allow inherent methods to be c-variadicFolkert de Vries-26/+28
2025-09-09c-variadic: reject functions with unsupported extern ABIFolkert de Vries-2/+5
2025-09-09c-variadic: reject non-unsafe functionsFolkert de Vries-9/+14
2025-09-08Refactor how to get the span of a function headerFolkert de Vries-1/+1
2025-09-08c-variadic: reject non-extern functionsFolkert de Vries-1/+2
2025-09-08clarify control flow of `check_c_variadic_type`Folkert de Vries-7/+16
2025-09-08disallow c-variadic associated functions (for now)Folkert de Vries-5/+9
there is no reason this should not work, really, we're just cutting some scope for now
2025-09-08disallow c-variadic coroutinesFolkert de Vries-0/+9
2025-09-03simplify `check_c_variadic_type`Folkert de Vries-23/+19
2025-08-22Rollup merge of #145747 - joshtriplett:builtin-diag-dyn, r=jdonszelmannJacob Pratt-3/+3
Refactor lint buffering to avoid requiring a giant enum Lint buffering currently relies on a giant enum `BuiltinLintDiag` containing all the lints that might potentially get buffered. In addition to being an unwieldy enum in a central crate, this also makes `rustc_lint_defs` a build bottleneck: it depends on various types from various crates (with a steady pressure to add more), and many crates depend on it. Having all of these variants in a separate crate also prevents detecting when a variant becomes unused, which we can do with a dedicated type defined and used in the same crate. Refactor this to use a dyn trait, to allow using `LintDiagnostic` types directly. Because the existing `BuiltinLintDiag` requires some additional types in order to decorate some variants, which are only available later in `rustc_lint`, use an enum `DecorateDiagCompat` to handle both the `dyn LintDiagnostic` case and the `BuiltinLintDiag` case. --- With the infrastructure in place, use it to migrate three of the enum variants to use `LintDiagnostic` directly, as a proof of concept and to demonstrate that the net result is a reduction in code size and a removal of a boilerplate-heavy layer of indirection. Also remove an unused `BuiltinLintDiag` variant.
2025-08-22Migrate `BuiltinLintDiag::MissingAbi` to use `LintDiagnostic` directlyJosh Triplett-1/+1
2025-08-22Refactor lint buffering to avoid requiring a giant enumJosh Triplett-2/+2
Lint buffering currently relies on a giant enum `BuiltinLintDiag` containing all the lints that might potentially get buffered. In addition to being an unwieldy enum in a central crate, this also makes `rustc_lint_defs` a build bottleneck: it depends on various types from various crates (with a steady pressure to add more), and many crates depend on it. Having all of these variants in a separate crate also prevents detecting when a variant becomes unused, which we can do with a dedicated type defined and used in the same crate. Refactor this to use a dyn trait, to allow using `LintDiagnostic` types directly. This requires boxing, but all of this is already on the slow path (emitting an error). Because the existing `BuiltinLintDiag` requires some additional types in order to decorate some variants, which are only available later in `rustc_lint`, use an enum `DecorateDiagCompat` to handle both the `dyn LintDiagnostic` case and the `BuiltinLintDiag` case.
2025-08-22Move validate_attr to `rustc_attr_parsing`Jonathan Brouwer-1/+1
2025-08-21Rollup merge of #145662 - GrigorenkoPV:x86-interrupt, r=compiler-errorsJacob Pratt-0/+11
Enforce correct number of arguments for `"x86-interrupt"` functions Tracking issue: rust-lang/rust#40180 Partially fixes rust-lang/rust#132835 `````@rustbot````` label: +F-abi_x86_interrupt +A-LLVM +O-x86_64 +O-x86_32 +A-ABI
2025-08-20Enforce correct number of arguments for `"x86-interrupt"` functionsPavel Grigorenko-0/+11
2025-08-19Prevent impossible combinations in `ast::ModKind`.Nicholas Nethercote-1/+1
`ModKind::Loaded` has an `inline` field and a `had_parse_error` field. If the `inline` field is `Inline::Yes` then `had_parse_error` must be `Ok(())`. This commit moves the `had_parse_error` field into the `Inline::No` variant. This makes it impossible to create the nonsensical combination of `inline == Inline::Yes` and `had_parse_error = Err(_)`.
2025-08-15Rollup merge of #144907 - ShoyuVanilla:no-const-async, r=fmeaseJacob Pratt-0/+16
fix: Reject async assoc fns of const traits/impls in ast_passes Fixes rust-lang/rust#117629
2025-08-15fix: Reject async assoc fns of const traits/impls in ast_passesShoyu Vanilla-0/+16
2025-08-15Rollup merge of #143075 - workingjubilee:interrupts-may-return-nevermore, ↵Stuart Cook-2/+14
r=davidtwco compiler: Allow `extern "interrupt" fn() -> !` While reviewing rust-lang/rust#142633 I overlooked a few details because I was kind of excited. - Fixes rust-lang/rust#143072
2025-08-14cleanup: Remove useless `[T].iter().last()`Esteban Küber-1/+1
2025-08-11Extract ast TraitImplHeaderCameron Steffen-16/+10
2025-08-11Move trait impl modifier errors to parsingCameron Steffen-34/+5
This is a technically a breaking change for what can be parsed in `#[cfg(false)]`.
2025-08-11Factor out InherentImplCannotUnsafeCameron Steffen-7/+11
2025-08-09remove `P`Deadbeef-2/+1
2025-08-07Rollup merge of #137831 - estebank:auto-trait-err, r=compiler-errorsStuart Cook-6/+10
Tweak auto trait errors Make suggestions to remove params and super traits verbose and make spans more accurate. ``` error[E0567]: auto traits cannot have generic parameters --> $DIR/auto-trait-validation.rs:6:19 | LL | auto trait Generic<T> {} | -------^^^ | | | auto trait cannot have generic parameters error[E0568]: auto traits cannot have super traits or lifetime bounds --> $DIR/auto-trait-validation.rs:8:20 | LL | auto trait Bound : Copy {} | ----- ^^^^ | | | auto traits cannot have super traits or lifetime bounds ``` ``` error[E0380]: auto traits cannot have associated items --> $DIR/issue-23080.rs:5:8 | LL | unsafe auto trait Trait { | ----- auto traits cannot have associated items LL | fn method(&self) { | ^^^^^^ ```
2025-08-04Tweak auto trait errorsEsteban Küber-6/+10
Make suggestions to remove params and super traits tool-only, and make the suggestion span more accurate. ``` error[E0567]: auto traits cannot have generic parameters --> $DIR/auto-trait-validation.rs:6:19 | LL | auto trait Generic<T> {} | -------^^^ | | | auto trait cannot have generic parameters error[E0568]: auto traits cannot have super traits or lifetime bounds --> $DIR/auto-trait-validation.rs:8:20 | LL | auto trait Bound : Copy {} | ----- ^^^^ | | | auto traits cannot have super traits or lifetime bounds ``` ``` error[E0380]: auto traits cannot have associated items --> $DIR/issue-23080.rs:5:8 | LL | unsafe auto trait Trait { | ----- auto traits cannot have associated items LL | fn method(&self) { | ^^^^^^ ```
2025-08-04fix: Error on illegal `[const]`s inside blocks within legal positionsShoyu Vanilla-16/+31
2025-07-28use let chains in ast, borrowck, codegen, const_evalKivooeo-10/+10
2025-07-18AST lowering: More robustly deal with relaxed boundsLeón Orell Valerian Liehr-23/+0
2025-07-17parse `const trait Trait`Deadbeef-15/+23
2025-07-06compiler: rename {ast,hir}::BareFn* to FnPtr*Jubilee Young-4/+4
Fix some comments and related types and locals where it is obvious, e.g. - bare_fn -> fn_ptr - LifetimeBinderKind::BareFnType -> LifetimeBinderKind::FnPtrType Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2025-07-03Replace kw_span by full span.Camille GILLOT-2/+2
2025-06-27compiler: allow interrupts to return () or !Jubilee Young-2/+14
2025-06-24Error on invalid signatures for interrupt ABIsFolkert de Vries-17/+70
2025-06-16Fold unnecessary visit_struct_field_def in AstValidatorMichael Goulet-18/+2
2025-06-12add `extern "custom"` functionsFolkert de Vries-4/+85
2025-05-28Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.Nicholas Nethercote-3/+3
So they match the order of the parts in the source code, e.g.: ``` struct Foo<T, U> { t: T, u: U } <-><----> <------------> / | \ ident generics variant_data ```
2025-05-04Initial support for dynamically linked cratesBryanskiy-2/+6
2025-05-03Report the `unsafe_attr_outside_unsafe` lint at the closest nodeUrgau-1/+1
2025-05-03Have `AstValidation` track a linting node idUrgau-0/+7
2025-04-18Rollup merge of #139615 - nnethercote:rm-name_or_empty, r=jdonszelmannMatthias Krüger-3/+2
Remove `name_or_empty` Another step towards #137978. r? ``@jdonszelmann``
2025-04-17Replace infallible `name_or_empty` methods with fallible `name` methods.Nicholas Nethercote-3/+2
I'm removing empty identifiers everywhere, because in practice they always mean "no identifier" rather than "empty identifier". (An empty identifier is impossible.) It's better to use `Option` to mean "no identifier" because you then can't forget about the "no identifier" possibility. Some specifics: - When testing an attribute for a single name, the commit uses the `has_name` method. - When testing an attribute for multiple names, the commit uses the new `has_any_name` method. - When using `match` on an attribute, the match arms now have `Some` on them. In the tests, we now avoid printing empty identifiers by not printing the identifier in the `error:` line at all, instead letting the carets point out the problem.
2025-04-16Add hard error for `extern` without explicit ABIObei Sideg-5/+7
2025-04-07Rollup merge of #139035 - nnethercote:PatKind-Missing, r=oli-obkStuart Cook-1/+1
Add new `PatKind::Missing` variants To avoid some ugly uses of `kw::Empty` when handling "missing" patterns, e.g. in bare fn tys. Helps with #137978. Details in the individual commits. r? ``@oli-obk``
2025-04-02Reduce scope of `AstValidator::with_*` calls.Nicholas Nethercote-91/+88
`AstValidator` has several `with_*` methods, each one setting a field that adjust how checking takes place for items within certain other items. E.g. `with_in_trait_impl` is used to adjust the checking done on items inside an `impl` item. Weirdly, the scopes used for most of the `with_*` calls are very broad, and include things that aren't "inside" the item, such as visibility, unsafety, and constness. This commit minimizes the scope of these `with_*` calls so they only apply to the things inside the item.
2025-04-02Rename span-related names in `AstValidator`.Nicholas Nethercote-36/+43
A bunch of span-related names in `AstValidator` don't end in `span`, which goes against the usual naming conventions and makes the code surprisingly hard to read. E.g. a name like `body` doesn't sound like it's a span. This commit adds `_span` suffixes.
2025-04-02Factor some code out of `AstValidator::visit_items`.Nicholas Nethercote-19/+20
Currently it uses `walk_item` on some item kinds. For other item kinds it visits the fields individually. For the latter group, this commit adds `visit_attrs_vis` and `visit_attrs_vis_ident` which bundle up visits to the fields that don't need special handling. This makes it clearer that they haven't been forgotten about. Also, it's better to do the attribute visits at the start because attributes precede the items in the source code. Because of this, a couple of tests have their output improved: errors appear in an order that matches the source code order.