Commit graph

49 commits

Author SHA1 Message Date
Michael Goulet
eb3707e4b4 Stabilize precise_capturing_in_traits 2025-03-23 14:11:04 +00:00
Gary Guo
292c622507 Stabilize asm_goto 2025-03-17 11:12:10 +00:00
Matthias Krüger
a500a43367
Rollup merge of #137824 - estebank:rtn-sugg, r=compiler-errors
Tweak invalid RTN errors

Make suggestions verbose.

When encountering `method(type)` bound, suggest `method(..)` instead of `method()`.

```
error: argument types not allowed with return type notation
  --> $DIR/bad-inputs-and-output.rs:9:23
   |
LL | fn foo<T: Trait<method(i32): Send>>() {}
   |                       ^^^^^
   |
help: remove the input types
   |
LL - fn foo<T: Trait<method(i32): Send>>() {}
LL + fn foo<T: Trait<method(..): Send>>() {}
   |
```

When encountering both return type and arg list that isn't `..`, suggest replacing both.

```
error: return type not allowed with return type notation
  --> $DIR/bad-inputs-and-output.rs:12:25
   |
LL | fn bar<T: Trait<method() -> (): Send>>() {}
   |                         ^^^^^^
   |
help: use the right argument notation and remove the return type
   |
LL - fn bar<T: Trait<method() -> (): Send>>() {}
LL + fn bar<T: Trait<method(..): Send>>() {}
   |
```

When encountering a return type, suggest removing it including the leading whitespace.

```
error: return type not allowed with return type notation
  --> $DIR/bad-inputs-and-output.rs:24:45
   |
LL | fn bay_path<T: Trait>() where T::method(..) -> (): Send {}
   |                                             ^^^^^
   |
help: remove the return type
   |
LL - fn bay_path<T: Trait>() where T::method(..) -> (): Send {}
LL + fn bay_path<T: Trait>() where T::method(..): Send {}
   |
```

r? ``@compiler-errors``
2025-03-01 16:03:18 +01:00
Esteban Küber
adb5ecabdb Tweak invalid RTN errors
Make suggestions verbose.

When encountering `method(type)` bound, suggest `method(..)` instead of `method()`.

```
error: argument types not allowed with return type notation
  --> $DIR/bad-inputs-and-output.rs:9:23
   |
LL | fn foo<T: Trait<method(i32): Send>>() {}
   |                       ^^^^^
   |
help: remove the input types
   |
LL - fn foo<T: Trait<method(i32): Send>>() {}
LL + fn foo<T: Trait<method(..): Send>>() {}
   |
```

When encountering both return type and arg list that isn't `..`, suggest replacing both.

```
error: return type not allowed with return type notation
  --> $DIR/bad-inputs-and-output.rs:12:25
   |
LL | fn bar<T: Trait<method() -> (): Send>>() {}
   |                         ^^^^^^
   |
help: use the right argument notation and remove the return type
   |
LL - fn bar<T: Trait<method() -> (): Send>>() {}
LL + fn bar<T: Trait<method(..): Send>>() {}
   |
```

When encountering a return type, suggest removing it including the leading whitespace.

```
error: return type not allowed with return type notation
  --> $DIR/bad-inputs-and-output.rs:24:45
   |
LL | fn bay_path<T: Trait>() where T::method(..) -> (): Send {}
   |                                             ^^^^^
   |
help: remove the return type
   |
LL - fn bay_path<T: Trait>() where T::method(..) -> (): Send {}
LL + fn bay_path<T: Trait>() where T::method(..): Send {}
   |
```
2025-02-28 21:18:53 +00:00
Esteban Küber
86945c0a54 Tweak incorrect ABI suggestion
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-28 03:35:13 +00:00
Folkert de Vries
fbd30ea35f
show supported register classes
in inline assembly, show the supported register classes when an invalid one is found
2025-01-29 12:15:12 +01:00
Esteban Küber
148a77dfde review comments: rewordings 2024-12-09 21:55:13 +00:00
Esteban Küber
550bcae8aa Detect struct S(ty = val);
Emit a specific error for unsupported default field value syntax in tuple structs.
2024-12-09 21:55:12 +00:00
Esteban Küber
9ac95c10c0 Introduce default_field_values feature
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-12-09 21:55:01 +00:00
Matthias Krüger
3f86eddf83
Rollup merge of #131664 - taiki-e:s390x-asm-vreg-inout, r=Amanieu
Support input/output in vector registers of s390x inline assembly (under asm_experimental_reg feature)

This extends currently clobber-only vector registers (`vreg`) support to allow passing `#[repr(simd)]` types, floats (f32/f64/f128), and integers (i32/i64/i128) as input/output.

This is unstable and gated under new `#![feature(asm_experimental_reg)]` (tracking issue: https://github.com/rust-lang/rust/issues/133416). If the feature is not enabled, only clober is supported as before.

| Architecture | Register class | Target feature | Allowed types |
| ------------ | -------------- | -------------- | -------------- |
| s390x | `vreg` | `vector` | `i32`, `f32`, `i64`, `f64`, `i128`, `f128`, `i8x16`, `i16x8`, `i32x4`, `i64x2`, `f32x4`, `f64x2` |

This matches the list of types that are supported by the vector registers in LLVM:
https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/SystemZ/SystemZRegisterInfo.td#L301-L313

In addition to `core::simd` types and floats listed above, custom `#[repr(simd)]` types of the same size and type are also allowed. All allowed types other than i32/f32/i64/f64/i128, and relevant target features are currently unstable.

Currently there is no SIMD type for s390x in `core::arch`, but this is tracked in https://github.com/rust-lang/rust/issues/130869.

cc https://github.com/rust-lang/rust/issues/130869 about vector facility support in s390x
cc https://github.com/rust-lang/rust/issues/125398 & https://github.com/rust-lang/rust/issues/116909 about f128 support in asm

`@rustbot` label +O-SystemZ +A-inline-assembly
2024-11-25 07:01:37 +01:00
Gary Guo
0178ba2c25 Make asm_goto_with_outputs a separate feature gate 2024-11-24 15:24:01 +00:00
Taiki Endo
c024d8ccdf Make s390x non-clobber-only vector register support unstable 2024-11-24 21:42:22 +09:00
Luca Versari
b462c68aee Fix ICE when passing DefId-creating args to legacy_const_generics. 2024-11-16 01:07:51 +01:00
Folkert
8419c0956e stabilize asm_const 2024-08-13 23:18:31 +02:00
Pavel Grigorenko
67602980de rustc_ast_lowering: make asm-related unstability messages translatable 2024-08-10 14:32:55 +03:00
Pavel Grigorenko
290df4fa56 rustc_ast_lowering: make "yield syntax is experimental" translatable 2024-08-10 14:32:55 +03:00
Pavel Grigorenko
334a097137 rustc_ast_lowering: make "using _ for array lengths is unstable" translatable 2024-08-10 14:32:55 +03:00
Michael Goulet
82b4af7511 Make sure we deny unimplemented RTN on qpath segments 2024-06-28 14:20:44 -04:00
Michael Goulet
b1a0c0b123 Change RTN to use .. again 2024-06-28 14:20:43 -04:00
Matthias Krüger
8b72058985
Rollup merge of #126746 - compiler-errors:no-rpitit, r=oli-obk
Deny `use<>` for RPITITs

Precise capturing `use<>` syntax is currently a no-op on RPITITs, since GATs have no variance, so all captured lifetimes are captured invariantly.

We don't currently *need* to support `use<>` on RPITITs, since `use<>` is initially intended for migrating RPIT *overcaptures* from edition 2021->2024, but since RPITITs currently capture all in-scope lifetimes, we'll never need to write `use<>` on an RPITIT.

Eventually, though, it would be desirable to support precise capturing on RPITITs, since RPITITs overcapturing by default can be annoying to some folks. But let's separate that (which will likely require some delicate types team work for adding variances to GATs and adjusting the refinement rules) from the stabilization of the feature for edition 2024.

r? oli-obk cc ``@traviscross``

Tracking:

- https://github.com/rust-lang/rust/issues/123432
2024-06-25 18:02:58 +02:00
Michael Goulet
6521c3971d Deny use<> for RPITITs 2024-06-24 12:03:09 -04:00
Michael Goulet
ffd72b1700 Fix remaining cases 2024-06-21 19:00:18 -04:00
Michael Goulet
f66558d2bf Add tests for illegal use bound syntax 2024-06-17 22:35:25 -04:00
est31
c6e946d0f0 Change wording 2024-04-29 14:53:38 +02:00
est31
4284bca720 Add a note to the ArbitraryExpressionInPattern error 2024-04-28 21:27:26 +02:00
Oli Scherer
aef0f4024a Error on using yield without also using #[coroutine] on the closure
And suggest adding the `#[coroutine]` to the closure
2024-04-24 08:05:29 +00:00
Michael Goulet
42ba57c013 Validation and other things 2024-04-15 16:45:01 -04:00
Gary Guo
93fa8579c6 Add asm label support to AST and HIR 2024-02-24 18:49:39 +00:00
Michael Goulet
fde695a2d1 Add a helpful suggestion 2024-02-10 03:31:34 +00:00
Michael Goulet
973bbfbd23 No more associated type bounds in dyn trait 2024-02-10 03:23:51 +00:00
bors
4a2fe4491e Auto merge of #120361 - compiler-errors:async-closures, r=oli-obk
Rework support for async closures; allow them to return futures that borrow from the closure's captures

This PR implements a new lowering for async closures via `TyKind::CoroutineClosure` which handles the curious relationship between the closure and the coroutine that it returns.

I wrote up a bunch in [this hackmd](https://hackmd.io/`@compiler-errors/S1HvqQxca)` which will be copied to the dev guide after this PR lands, and hopefully left sufficient comments in the source code explaining why this change is as large as it is.

This also necessitates that they begin implementing the `AsyncFn`-family of traits, rather than the `Fn`-family of traits -- if you need `Fn` implementations, you should probably use the non-sugar `|| async {}` syntax instead.

Notably this PR does not yet implement `async Fn()` syntax sugar for bounds, but I expect to add those soon (**edit:** #120392). For now, users must use `AsyncFn()` traits directly, which necessitates adding the `async_fn_traits` feature gate as well. I will add this as a follow-up very soon.

r? oli-obk

This is based on top of #120322, but that PR is minimal.
2024-02-06 15:04:01 +00:00
Michael Goulet
a20421734b Make async closures directly lower to ClosureKind::CoroutineClosure 2024-02-06 02:22:58 +00:00
Michael Goulet
3913c9a0ca Error on incorrect item kind in async bound 2024-01-31 16:59:19 +00:00
Michael Goulet
f1ee076f81 Async closures will move params into the future always 2024-01-16 17:12:10 +00:00
clubby789
f1b8b7d7ae Add error code for missing base expression in struct update syntax 2024-01-09 19:25:54 +00:00
Michael Goulet
7e38b70cc0 Split note, fix const/static impl trait error 2024-01-07 18:00:03 +00:00
León Orell Valerian Liehr
3d0297a1e1
Deny defaults for higher-ranked generic parameters 2024-01-01 21:58:25 +01:00
bohan
e16efbd23a fallback default to None during ast-loweing for lifetime binder 2023-12-26 16:10:29 +08:00
Nadrieril
70deb9a57f Disallow arm bodies on never patterns 2023-12-03 12:25:46 +01:00
Nadrieril
06a8ed10b6 Disallow guards on never patterns 2023-12-03 12:25:46 +01:00
Nadrieril
a2dcb3a6d9 Disallow an arm without a body (except for never patterns)
Parsing now accepts a match arm without a body, so we must make sure to
only accept that if the pattern is a never pattern.
2023-12-03 12:25:46 +01:00
Oli Scherer
e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Michael Goulet
ef04c9795b Deprecate E0706 2023-10-13 21:01:36 +00:00
Esteban Küber
041e54bd92 Tweak wording of E0562
Fix #80476.
2023-10-04 19:51:43 +00:00
yukang
f9a9ff20a2 cleanup on messages 2023-09-12 07:27:17 +08:00
clubby789
f97fddab91 Ensure Fluent messages are in alphabetical order 2023-05-25 23:49:35 +00:00
Michael Goulet
8b592db27a Add (..) syntax for RTN 2023-03-28 01:14:28 +00:00
Michael Goulet
104aacb49f Add tests and error messages 2023-03-28 01:02:15 +00:00
est31
7e2ecb3cd8 Simplify message paths
This makes it easier to open the messages file while developing on features.

The commit was the result of automatted changes:

for p in compiler/rustc_*; do mv $p/locales/en-US.ftl $p/messages.ftl; rmdir $p/locales; done

for p in compiler/rustc_*; do sed -i "s#\.\./locales/en-US.ftl#../messages.ftl#" $p/src/lib.rs; done
2023-03-11 22:51:57 +01:00
Renamed from compiler/rustc_ast_lowering/locales/en-US.ftl (Browse further)