-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom MIR: Allow optional RET type annotation #109392
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually quite like this solution
@bors r=JakobDegen rollup |
Custom MIR: Allow optional RET type annotation This currently doesn't compile because the type of `RET` is inferred, which fails if RET is a composite type and fields are initialised separately. ```rust #![feature(custom_mir, core_intrinsics)] extern crate core; use core::intrinsics::mir::*; #[custom_mir(dialect = "runtime", phase = "optimized")] fn fn0() -> (i32, bool) { mir! ({ RET.0 = 0; RET.1 = true; Return() }) } ``` ``` error[E0282]: type annotations needed --> src/lib.rs:8:9 | 8 | RET.0 = 0; | ^^^ cannot infer type For more information about this error, try `rustc --explain E0282`. ``` This PR allows the user to manually specify the return type with `type RET = ...;` if required: ```rust #[custom_mir(dialect = "runtime", phase = "optimized")] fn fn0() -> (i32, bool) { mir! ( type RET = (i32, bool); { RET.0 = 0; RET.1 = true; Return() } ) } ``` The syntax is not optimal, I'm happy to see other suggestions. Ideally I wanted it to be a normal type annotation like `let RET: ...;`, but this runs into the multiple parsing options error during macro expansion, as it can be parsed as a normal `let` declaration as well. r? `@oli-obk` or `@tmiasko` or `@JakobDegen`
Custom MIR: Allow optional RET type annotation This currently doesn't compile because the type of `RET` is inferred, which fails if RET is a composite type and fields are initialised separately. ```rust #![feature(custom_mir, core_intrinsics)] extern crate core; use core::intrinsics::mir::*; #[custom_mir(dialect = "runtime", phase = "optimized")] fn fn0() -> (i32, bool) { mir! ({ RET.0 = 0; RET.1 = true; Return() }) } ``` ``` error[E0282]: type annotations needed --> src/lib.rs:8:9 | 8 | RET.0 = 0; | ^^^ cannot infer type For more information about this error, try `rustc --explain E0282`. ``` This PR allows the user to manually specify the return type with `type RET = ...;` if required: ```rust #[custom_mir(dialect = "runtime", phase = "optimized")] fn fn0() -> (i32, bool) { mir! ( type RET = (i32, bool); { RET.0 = 0; RET.1 = true; Return() } ) } ``` The syntax is not optimal, I'm happy to see other suggestions. Ideally I wanted it to be a normal type annotation like `let RET: ...;`, but this runs into the multiple parsing options error during macro expansion, as it can be parsed as a normal `let` declaration as well. r? ``@oli-obk`` or ``@tmiasko`` or ``@JakobDegen``
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#109373 (Set LLVM `LLVM_UNREACHABLE_OPTIMIZE` to `OFF`) - rust-lang#109392 (Custom MIR: Allow optional RET type annotation) - rust-lang#109394 (adapt tests/codegen/vec-shrink-panik for LLVM 17) - rust-lang#109412 (rustdoc: Add GUI test for "Auto-hide item contents for large items" setting) - rust-lang#109452 (Ignore the vendor directory for tidy tests.) - rust-lang#109457 (Remove comment about reusing rib allocations) - rust-lang#109461 (rustdoc: remove redundant `.content` prefix from span/a colors) - rust-lang#109477 (`HirId` to `LocalDefId` cleanup) - rust-lang#109489 (More general captures) - rust-lang#109494 (Do not feed param_env for RPITITs impl side) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This currently doesn't compile because the type of
RET
is inferred, which fails if RET is a composite type and fields are initialised separately.This PR allows the user to manually specify the return type with
type RET = ...;
if required:The syntax is not optimal, I'm happy to see other suggestions. Ideally I wanted it to be a normal type annotation like
let RET: ...;
, but this runs into the multiple parsing options error during macro expansion, as it can be parsed as a normallet
declaration as well.r? @oli-obk or @tmiasko or @JakobDegen