Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
WASM
Zig
Javascript
GIMPLE
Ygen
rust source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
mrustc (master)
rustc 1.0.0
rustc 1.1.0
rustc 1.10.0
rustc 1.11.0
rustc 1.12.0
rustc 1.13.0
rustc 1.14.0
rustc 1.15.1
rustc 1.16.0
rustc 1.17.0
rustc 1.18.0
rustc 1.19.0
rustc 1.2.0
rustc 1.20.0
rustc 1.21.0
rustc 1.22.0
rustc 1.23.0
rustc 1.24.0
rustc 1.25.0
rustc 1.26.0
rustc 1.27.0
rustc 1.27.1
rustc 1.28.0
rustc 1.29.0
rustc 1.3.0
rustc 1.30.0
rustc 1.31.0
rustc 1.32.0
rustc 1.33.0
rustc 1.34.0
rustc 1.35.0
rustc 1.36.0
rustc 1.37.0
rustc 1.38.0
rustc 1.39.0
rustc 1.4.0
rustc 1.40.0
rustc 1.41.0
rustc 1.42.0
rustc 1.43.0
rustc 1.44.0
rustc 1.45.0
rustc 1.45.2
rustc 1.46.0
rustc 1.47.0
rustc 1.48.0
rustc 1.49.0
rustc 1.5.0
rustc 1.50.0
rustc 1.51.0
rustc 1.52.0
rustc 1.53.0
rustc 1.54.0
rustc 1.55.0
rustc 1.56.0
rustc 1.57.0
rustc 1.58.0
rustc 1.59.0
rustc 1.6.0
rustc 1.60.0
rustc 1.61.0
rustc 1.62.0
rustc 1.63.0
rustc 1.64.0
rustc 1.65.0
rustc 1.66.0
rustc 1.67.0
rustc 1.68.0
rustc 1.69.0
rustc 1.7.0
rustc 1.70.0
rustc 1.71.0
rustc 1.72.0
rustc 1.73.0
rustc 1.74.0
rustc 1.75.0
rustc 1.76.0
rustc 1.77.0
rustc 1.78.0
rustc 1.79.0
rustc 1.8.0
rustc 1.80.0
rustc 1.81.0
rustc 1.82.0
rustc 1.9.0
rustc beta
rustc nightly
rustc-cg-gcc (master)
x86-64 GCCRS (GCC master)
x86-64 GCCRS (GCCRS master)
x86-64 GCCRS 14.1 (GCC)
x86-64 GCCRS 14.2 (GCC)
Options
Source code
use std::hint::black_box; pub fn main() { // Hack to prevent `rustc` from inling the `regular` function call let ptr: fn(_, _, _) -> u32 = regular; println!("{ptr:p}"); black_box(regular_bench()); } pub fn regular_bench() -> u32 { let (arg1, arg2, arg3) = black_box(("4", 24, Some("5"))); regular(arg1, arg2, arg3) } fn regular(arg1: &str, arg2: u32, arg3: Option<&str>) -> u32 { let x = arg1.parse::<u32>().unwrap() + arg2; let x = x + arg3.map(|x| x.parse::<u32>().unwrap()).unwrap_or(0); x }
rust source #2
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
mrustc (master)
rustc 1.0.0
rustc 1.1.0
rustc 1.10.0
rustc 1.11.0
rustc 1.12.0
rustc 1.13.0
rustc 1.14.0
rustc 1.15.1
rustc 1.16.0
rustc 1.17.0
rustc 1.18.0
rustc 1.19.0
rustc 1.2.0
rustc 1.20.0
rustc 1.21.0
rustc 1.22.0
rustc 1.23.0
rustc 1.24.0
rustc 1.25.0
rustc 1.26.0
rustc 1.27.0
rustc 1.27.1
rustc 1.28.0
rustc 1.29.0
rustc 1.3.0
rustc 1.30.0
rustc 1.31.0
rustc 1.32.0
rustc 1.33.0
rustc 1.34.0
rustc 1.35.0
rustc 1.36.0
rustc 1.37.0
rustc 1.38.0
rustc 1.39.0
rustc 1.4.0
rustc 1.40.0
rustc 1.41.0
rustc 1.42.0
rustc 1.43.0
rustc 1.44.0
rustc 1.45.0
rustc 1.45.2
rustc 1.46.0
rustc 1.47.0
rustc 1.48.0
rustc 1.49.0
rustc 1.5.0
rustc 1.50.0
rustc 1.51.0
rustc 1.52.0
rustc 1.53.0
rustc 1.54.0
rustc 1.55.0
rustc 1.56.0
rustc 1.57.0
rustc 1.58.0
rustc 1.59.0
rustc 1.6.0
rustc 1.60.0
rustc 1.61.0
rustc 1.62.0
rustc 1.63.0
rustc 1.64.0
rustc 1.65.0
rustc 1.66.0
rustc 1.67.0
rustc 1.68.0
rustc 1.69.0
rustc 1.7.0
rustc 1.70.0
rustc 1.71.0
rustc 1.72.0
rustc 1.73.0
rustc 1.74.0
rustc 1.75.0
rustc 1.76.0
rustc 1.77.0
rustc 1.78.0
rustc 1.79.0
rustc 1.8.0
rustc 1.80.0
rustc 1.81.0
rustc 1.82.0
rustc 1.9.0
rustc beta
rustc nightly
rustc-cg-gcc (master)
x86-64 GCCRS (GCC master)
x86-64 GCCRS (GCCRS master)
x86-64 GCCRS 14.1 (GCC)
x86-64 GCCRS 14.2 (GCC)
Options
Source code
use std::hint::black_box; pub fn main() { // Hack to prevent `rustc` from inling the `regular` function call let ptr: fn(_, _, _) -> u32 = regular; println!("{ptr:p}"); black_box(builder_bench()); } pub fn builder_bench() -> u32 { let (arg1, arg2, arg3) = black_box(("4", 24, Some("5"))); builder().arg1(arg1).arg2(arg2).maybe_arg3(arg3).call() } // Recursive expansion of builder macro // ===================================== #[cfg(rust_analyzer)] const _: () = { mod builder_top_level { use self::{crate as _, start_fn as _}; use crate::bon::__::ide::builder_top_level::*; } mod builder_top_level_builder_type { use crate::bon::__::ide::builder_top_level::builder_type::*; } mod builder_top_level_start_fn { use crate::bon::__::ide::builder_top_level::start_fn::*; } mod builder_top_level_finish_fn { use crate::bon::__::ide::builder_top_level::finish_fn::*; } mod builder_top_level_state_mod { use crate::bon::__::ide::builder_top_level::state_mod::*; } mod builder_top_level_on { use crate::bon::__::ide::builder_top_level::on::*; } mod builder_top_level_derive { use crate::bon::__::ide::builder_top_level::derive::*; } }; #[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)] fn regular(arg1: &str, arg2: u32, arg3: Option<&str>) -> u32 { let x = arg1.parse::<u32>().unwrap() + arg2; let x = x + arg3.map(|x| x.parse::<u32>().unwrap()).unwrap_or(0); x } #[inline(always)] #[allow(clippy::inline_always, clippy::use_self, clippy::missing_const_for_fn)] #[allow(deprecated)] fn builder<'f1, 'f2>() -> RegularBuilder<'f1, 'f2> { RegularBuilder { __private_fluttershy_phantom: ::core::marker::PhantomData, __private_fluttershy_named_members: ::core::default::Default::default(), } } #[allow(unnameable_types, unreachable_pub, clippy::redundant_pub_crate)] #[doc = "Tools for manipulating the type state of [`RegularBuilder`].\n\nSee the [detailed guide](https://bon-rs.com/guide/typestate-api) that describes how all the pieces here fit together."] #[allow(deprecated)] mod regular_builder { #[doc(inline)] pub(super) use crate::bon::__::{IsSet, IsUnset}; use crate::bon::__::{Set, Unset}; mod sealed { pub(in super::super) struct Sealed; } #[doc = "Builder's type state specifies if members are set or not (unset).\n\nYou can use the associated types of this trait to control the state of individual members with the [`IsSet`] and [`IsUnset`] traits. You can change the state of the members with the `Set*` structs available in this module."] pub(super) trait State: ::core::marker::Sized { #[doc = "Type state of the member `arg1`.\n\nIt can implement either [`IsSet`] or [`IsUnset`]"] type Arg1; #[doc = "Type state of the member `arg2`.\n\nIt can implement either [`IsSet`] or [`IsUnset`]"] type Arg2; #[doc = "Type state of the member `arg3`.\n\nIt can implement either [`IsSet`] or [`IsUnset`]"] type Arg3; #[doc(hidden)] const SEALED: sealed::Sealed; } #[doc = "Marker trait that indicates that all required members are set.\n\nIn this state, you can finish building by calling the method [`RegularBuilder::call()`](super::RegularBuilder::call())"] pub(super) trait IsComplete: State<Arg1: IsSet, Arg2: IsSet> { #[doc(hidden)] const SEALED: sealed::Sealed; } #[doc(hidden)] impl<S: State> IsComplete for S where S::Arg1: IsSet, S::Arg2: IsSet, { const SEALED: sealed::Sealed = sealed::Sealed; } #[deprecated = "this should not be used directly; it is an implementation detail; use the Set* type aliases to control the state of members instead"] #[doc(hidden)] #[allow(non_camel_case_types)] mod members { pub(in super::super) enum arg1 {} pub(in super::super) enum arg2 {} pub(in super::super) enum arg3 {} } #[doc = r" Represents a [`State`] that has [`IsUnset`] implemented for all members."] #[doc = r""] #[doc = r" This is the initial state of the builder before any setters are called."] pub(super) struct Empty(()); #[doc = "Represents a [`State`] that has [`IsSet`] implemented for [`State::Arg1`].\n\nThe state for all other members is left the same as in the input state."] pub(super) struct SetArg1<S: State = Empty>(::core::marker::PhantomData<fn() -> S>); #[doc = "Represents a [`State`] that has [`IsSet`] implemented for [`State::Arg2`].\n\nThe state for all other members is left the same as in the input state."] pub(super) struct SetArg2<S: State = Empty>(::core::marker::PhantomData<fn() -> S>); #[doc = "Represents a [`State`] that has [`IsSet`] implemented for [`State::Arg3`].\n\nThe state for all other members is left the same as in the input state."] pub(super) struct SetArg3<S: State = Empty>(::core::marker::PhantomData<fn() -> S>); #[doc(hidden)] impl State for Empty { type Arg1 = Unset<members::arg1>; type Arg2 = Unset<members::arg2>; type Arg3 = Unset<members::arg3>; const SEALED: sealed::Sealed = sealed::Sealed; } #[doc(hidden)] impl<S: State> State for SetArg1<S> { type Arg1 = Set<members::arg1>; type Arg2 = S::Arg2; type Arg3 = S::Arg3; const SEALED: sealed::Sealed = sealed::Sealed; } #[doc(hidden)] impl<S: State> State for SetArg2<S> { type Arg1 = S::Arg1; type Arg2 = Set<members::arg2>; type Arg3 = S::Arg3; const SEALED: sealed::Sealed = sealed::Sealed; } #[doc(hidden)] impl<S: State> State for SetArg3<S> { type Arg1 = S::Arg1; type Arg2 = S::Arg2; type Arg3 = Set<members::arg3>; const SEALED: sealed::Sealed = sealed::Sealed; } } #[must_use = "the builder does nothing until you call `call()` on it to finish building"] #[doc = "Use builder syntax to set the inputs and finish with [`call()`](Self::call())."] #[allow(unused_parens)] #[allow(clippy::struct_field_names, clippy::type_complexity)] #[allow(deprecated)] struct RegularBuilder<'f1, 'f2, S: regular_builder::State = regular_builder::Empty> { #[doc(hidden)] #[deprecated = "this field should not be used directly; it's an implementation detail if you found yourself needing it, then you are probably doing something wrong; feel free to open an issue/discussion in our GitHub repository (https://github.com/elastio/bon) or ask for help in our Discord server (https://bon-rs.com/discord)"] __private_fluttershy_phantom: ::core::marker::PhantomData<(fn() -> S,)>, #[doc(hidden)] #[deprecated = "this field should not be used directly; it's an implementation detail if you found yourself needing it, then you are probably doing something wrong; feel free to open an issue/discussion in our GitHub repository (https://github.com/elastio/bon) or ask for help in our Discord server (https://bon-rs.com/discord)"] __private_fluttershy_named_members: ( ::core::option::Option<&'f1 str>, ::core::option::Option<u32>, ::core::option::Option<&'f2 str>, ), } #[allow(unused_parens)] #[automatically_derived] #[allow(deprecated)] impl<'f1, 'f2, S: regular_builder::State> RegularBuilder<'f1, 'f2, S> { #[doc = r" Finishes building and performs the requested action."] #[inline(always)] #[allow( clippy::inline_always, clippy::future_not_send, clippy::missing_const_for_fn )] fn call(self) -> u32 where S: regular_builder::IsComplete, { let arg1: &'f1 str = unsafe { ::core::option::Option::unwrap_unchecked(self.__private_fluttershy_named_members.0) }; let arg2: u32 = unsafe { ::core::option::Option::unwrap_unchecked(self.__private_fluttershy_named_members.1) }; let arg3: Option<&'f2 str> = self.__private_fluttershy_named_members.2; regular(arg1, arg2, arg3) } #[doc = "| **Required** |\n| -- |\n\n"] #[allow( clippy::inline_always, clippy::impl_trait_in_params, clippy::missing_const_for_fn )] #[inline(always)] fn arg1(mut self, value: &'f1 str) -> RegularBuilder<'f1, 'f2, regular_builder::SetArg1<S>> where S::Arg1: regular_builder::IsUnset, { self.__private_fluttershy_named_members.0 = ::core::option::Option::Some(value); RegularBuilder { __private_fluttershy_phantom: ::core::marker::PhantomData, __private_fluttershy_named_members: self.__private_fluttershy_named_members, } } #[doc = "| **Required** |\n| -- |\n\n"] #[allow( clippy::inline_always, clippy::impl_trait_in_params, clippy::missing_const_for_fn )] #[inline(always)] fn arg2(mut self, value: u32) -> RegularBuilder<'f1, 'f2, regular_builder::SetArg2<S>> where S::Arg2: regular_builder::IsUnset, { self.__private_fluttershy_named_members.1 = ::core::option::Option::Some(value); RegularBuilder { __private_fluttershy_phantom: ::core::marker::PhantomData, __private_fluttershy_named_members: self.__private_fluttershy_named_members, } } #[doc = "| **Optional** |\n| -- |\n\n**See also** [`maybe_arg3()`](Self::maybe_arg3), which is a companion setter that accepts an `Option`.\n \n\n"] #[allow( clippy::inline_always, clippy::impl_trait_in_params, clippy::missing_const_for_fn )] #[inline(always)] fn arg3(self, value: &'f2 str) -> RegularBuilder<'f1, 'f2, regular_builder::SetArg3<S>> where S::Arg3: regular_builder::IsUnset, { self.maybe_arg3(Some(value)) } #[doc = "| **Optional** |\n| -- |\n\n**See also** [`arg3()`](Self::arg3), which is a companion setter that wraps the value with `Some` internally.\n \n\n"] #[allow( clippy::inline_always, clippy::impl_trait_in_params, clippy::missing_const_for_fn )] #[inline(always)] fn maybe_arg3( mut self, value: Option<&'f2 str>, ) -> RegularBuilder<'f1, 'f2, regular_builder::SetArg3<S>> where S::Arg3: regular_builder::IsUnset, { self.__private_fluttershy_named_members.2 = value; RegularBuilder { __private_fluttershy_phantom: ::core::marker::PhantomData, __private_fluttershy_named_members: self.__private_fluttershy_named_members, } } } mod bon { pub(crate) mod __ { #[derive(Debug)] pub(crate) struct Unset<Name>(Name); #[derive(Debug)] pub(crate) struct Set<Name>(Name); /// Marker trait that indicates that the member is set, i.e. at least /// one of its setters was called. pub(crate) trait IsSet {} /// Marker trait that indicates that the member is unset, i.e. none /// of its setters was called. pub(crate) trait IsUnset {} #[doc(hidden)] impl<Name> IsSet for Set<Name> {} #[doc(hidden)] impl<Name> IsUnset for Unset<Name> {} } }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree