79 Commits

Author SHA1 Message Date
Matthias Krüger
185926c99f
Rollup merge of #146434 - folkertdev:c-variadic-inherent-methods, 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-18 17:20:56 +02:00
León Orell Valerian Liehr
31c0d96cb6
Move more early buffered lints to dyn lint diagnostics (2/N) 2025-09-14 12:38:11 +02:00
Folkert de Vries
01e83adc88
c-variadic: allow trait methods to be c-variadic
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-11 10:27:28 +02:00
Folkert de Vries
9196844f0d
c-variadic: reject functions with unsupported extern ABI 2025-09-09 21:38:38 +02:00
Folkert de Vries
0c96200f26
c-variadic: reject non-unsafe functions 2025-09-09 21:30:38 +02:00
Folkert de Vries
2b9fce8c8c
c-variadic: reject non-extern functions 2025-09-08 19:18:21 +02:00
Folkert de Vries
a093372e5e
disallow c-variadic associated functions (for now)
there is no reason this should not work, really, we're just cutting some scope for now
2025-09-08 18:41:22 +02:00
Folkert de Vries
1656f6c668
disallow c-variadic coroutines 2025-09-08 18:41:21 +02:00
Ralf Jung
f6d55aea2c stabilize extended_varargs_abi_support 2025-09-02 08:48:12 +02:00
Josh Triplett
690a5782f8 Migrate BuiltinLintDiag::MissingAbi to use LintDiagnostic directly 2025-08-22 02:01:01 -07:00
Pavel Grigorenko
2da0ec3453 Enforce correct number of arguments for "x86-interrupt" functions 2025-08-20 18:03:57 +03:00
Jacob Pratt
d077146a15
Rollup merge of #144907 - ShoyuVanilla:no-const-async, r=fmease
fix: Reject async assoc fns of const traits/impls in ast_passes

Fixes rust-lang/rust#117629
2025-08-15 18:13:28 -04:00
Shoyu Vanilla
2218ff1940 fix: Reject async assoc fns of const traits/impls in ast_passes 2025-08-15 16:31:10 +09:00
Stuart Cook
603b61df57
Rollup merge of #143075 - workingjubilee:interrupts-may-return-nevermore, 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-15 16:16:31 +10:00
Cameron Steffen
fa733909ed Move trait impl modifier errors to parsing
This is a technically a breaking change for what can be parsed in
`#[cfg(false)]`.
2025-08-11 16:58:21 -05:00
Stuart Cook
bcd50fd45f
Rollup merge of #137831 - estebank:auto-trait-err, r=compiler-errors
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-07 20:49:36 +10:00
Esteban Küber
91e606b715 Tweak auto trait errors
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-04 17:20:07 +00:00
Shoyu Vanilla
7d78968bd0 fix: Error on illegal [const]s inside blocks within legal positions 2025-08-04 01:48:28 +09:00
León Orell Valerian Liehr
1df99f22d3
AST lowering: More robustly deal with relaxed bounds 2025-07-18 03:13:21 +02:00
Deadbeef
69326878ee parse const trait Trait 2025-07-17 18:06:26 +08:00
Jubilee Young
0a4f87a144 compiler: rename {ast,hir}::BareFn* to FnPtr*
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-06 15:03:08 -07:00
klensy
c76d032f01 setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
Matthias Krüger
36c2b011cb
Rollup merge of #139858 - oli-obk:new-const-traits-syntax, r=fee1-dead
New const traits syntax

This PR only affects the AST and doesn't actually change anything semantically.

All occurrences of `~const` outside of libcore have been replaced by `[const]`. Within libcore we have to wait for rustfmt to be bumped in the bootstrap compiler. This will happen "automatically" (when rustfmt is run) during the bootstrap bump, as rustfmt converts `~const` into `[const]`. After this we can remove the `~const` support from the parser

Caveat discovered during impl: there is no legacy bare trait object recovery for `[const] Trait` as that snippet in type position goes down the slice /array parsing code and will error

r? ``@fee1-dead``

cc ``@nikomatsakis`` ``@traviscross`` ``@compiler-errors``
2025-06-27 22:13:00 +02:00
Jubilee Young
db33e98540 compiler: fixup error message for x86-interrupt invalid returns 2025-06-27 11:04:04 -07:00
Oli Scherer
eb7245a864 Change const trait bound syntax from ~const to [const] 2025-06-26 13:46:45 +00:00
Folkert de Vries
943d37958b
Error on invalid signatures for interrupt ABIs 2025-06-24 14:40:11 +02:00
Folkert de Vries
5f73ce2b7e
add extern "custom" functions 2025-06-12 20:27:10 +02:00
Obei Sideg
01cfa9aad5
Add hard error for extern without explicit ABI 2025-04-16 22:43:56 +03:00
Jana Dönszelmann
7e0f5b5016
Introduce new-style attribute parsers for several attributes
note: compiler compiles but librustdoc and clippy don't
2025-02-24 14:31:17 +01:00
Nicholas Nethercote
e52f5bf16d Remove -Zshow-span.
It's very old (added in #12087). It's strange, and it's not clear what
its use cases are. It only works with the crate root file because it
runs before expansion. I suspect it won't be missed.
2024-12-04 19:20:01 +11:00
León Orell Valerian Liehr
442f39582d
Move an impl-Trait check from AST validation to AST lowering 2024-10-27 07:41:52 +01:00
Matthias Krüger
b8cdca8cce
Rollup merge of #131550 - compiler-errors:extern-diags, r=spastorino
Make some tweaks to extern block diagnostics

Self-explanatory. See the diagnostic changes; I hope they make them a bit more descriptive.

r? spastorino
2024-10-14 17:06:38 +02:00
Michael Goulet
d6391d5d4d Note what qualifier 2024-10-11 11:30:08 -04:00
Michael Goulet
c085071631 Remove unadorned 2024-10-11 11:30:08 -04:00
Michael Goulet
40465d2449 Remove anon struct and union types 2024-10-01 13:55:46 -04:00
Michael Goulet
e3a0da1863 Remove unnamed field feature 2024-10-01 13:55:46 -04:00
Michael Goulet
594de02cba Properly deny const gen/async gen fns 2024-09-11 18:39:06 -04:00
Matthias Krüger
cfc5f25b3d
Rollup merge of #127054 - compiler-errors:bound-ordering, r=fmease
Reorder trait bound modifiers *after* `for<...>` binder in trait bounds

This PR suggests changing the grammar of trait bounds from:

```
[CONSTNESS] [ASYNCNESS] [?] [BINDER] [TRAIT_PATH]

const async ? for<'a> Sized
```

to

```
([BINDER] [CONSTNESS] [ASYNCNESS] | [?]) [TRAIT_PATH]
```

i.e., either

```
? Sized
```

or

```
for<'a> const async Sized
```

(but not both)

### Why?

I think it's strange that the binder applies "more tightly" than the `?` trait polarity. This becomes even weirder when considering that we (or at least, I) want to have `async` trait bounds expressed like:

```
where T: for<'a> async Fn(&'a ()) -> i32,
```

and not:

```
where T: async for<'a> Fn(&'a ()) -> i32,
```

### Fallout

No crates on crater use this syntax, presumably because it's literally useless. This will require modifying the reference grammar, though.

### Alternatives

If this is not desirable, then we can alternatively keep parsing `for<'a>` after the `?` but deprecate it with either an FCW (or an immediate hard error), and begin parsing `for<'a>` *before* the `?`.
2024-07-25 04:43:18 +02:00
Michael Goulet
3862095bd2 Just totally fully deny late-bound consts 2024-07-20 19:45:24 -04:00
Michael Goulet
2f5a84ea16 Don't allow unsafe statics outside of extern blocks 2024-07-18 18:02:29 -04:00
Michael Goulet
d0a1851ec2 Deny keyword lifetimes pre-expansion 2024-07-16 12:06:25 -04:00
Michael Goulet
de88bc5c89 And additionally enforce ? and async/const aren't mixed 2024-07-11 00:00:03 -04:00
Jubilee Young
43a6b018a2 compiler: Mention C-unwind in C-variadic error 2024-06-22 23:30:31 -07:00
Santiago Pastorino
22831ed117
Do not allow safe usafe on static and fn items 2024-06-21 09:12:13 -03:00
Michael Goulet
2e03130e11 Detect duplicates 2024-06-17 22:35:25 -04:00
Michael Goulet
f66558d2bf Add tests for illegal use bound syntax 2024-06-17 22:35:25 -04:00
Michael Goulet
b1efe1ab5d Rework precise capturing syntax 2024-06-17 22:35:25 -04:00
Santiago Pastorino
1afc7d716c
Make MISSING_UNSAFE_ON_EXTERN lint emit future compat info with suggestion to prepend unsafe 2024-06-05 09:36:01 -03:00
Santiago Pastorino
b4cbdb7246
Fail when using safe/unsafe items inside unadorned extern blocks 2024-06-04 14:19:43 -03:00
Jubilee
866630d004
Rollup merge of #124048 - veera-sivarajan:bugfix-123773-c23-variadics, r=compiler-errors
Support C23's Variadics Without a Named Parameter

Fixes #123773

This PR removes the static check that disallowed extern functions
with ellipsis (varargs) as the only parameter since this is now
valid in C23.

This will not break any existing code as mentioned in the proposal
document: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2975.pdf.

Also, adds a doc comment for `check_decl_cvariadic_pos()` and
fixes the name of the function (`varadic` -> `variadic`).
2024-05-26 15:28:26 -07:00