Change:
can be used to specialize code by comparing types explicitly (, ) or implicitly (). In release mode this works well; in debug mode though the unused impl is unnecessarily monomorphized and codegened, slowing compile time as well as run time. It isn't a major issue as it only affects debug mode, but I wondered if it was worth marking , , and the various downcast methods as to potentially reduce compile times and provide a nice debug mode runtime boost? See e.g. is present in IR/assembly:
It would be cool if this calls get inlined in . This would improve performance of debug builds of engines like bevy, compiled with weak optimizations.
I found that this function always promoted to const on ,source:'%23%5Binline(never)%5D%0Afn+printa()%7B%0A++++println!!(%22A%22)%0A%7D%0A%0A%23%5Binline(never)%5D%0Afn+printb()%7B%0A++++println!!(%22B%22)%0A%7D%0A%0A%23%5Bnomangle%5D%0Apub+fn+testcalc()%7B%0A++++use+std::any::TypeId%3B%0A%0A++++if+TypeId::of::%3Cu8%3E()+!!%3D+TypeId::of::%3Cu32%3E()%7B%0A++++++++printa()%3B%0A++++%7D%0A%0A++++if+TypeId::of::%3Cu8%3E()+%3D%3D+TypeId::of::%3Cu8%3E()%7B%0A++++++++printb()%3B%0A++++%7D%0A%7D%0A'),l:'5',n:'0',o:'Rust+source+%231',t:'0')),k:45.,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:nightly,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'1',libraryCode:'1',trim:'1'),fontScale:14,fontUsePx:'0',j:1,lang:rust,libs:!(),options:'-Copt-level%3D1',selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'rustc+nightly+(Editor+%231,+Compiler+%231)+Rust',t:'0')),k:31.,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compiler:1,editor:1,fontScale:14,fontUsePx:'0',wrap:'1'),l:'5',n:'0',o:'%231+with+rustc+nightly',t:'0')),k:22.,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4) Another problem is that ParialEq::eq isn't inlined even if I use . Also, manual implementation of PartialEq would remove ability to use it in pattern matching like: ,source:'%23!!%5Bfeature(consttypeid)%5D%0A%0A%23%5Binline(always)%5D%0Apub+const+fn+isbool%3CT:+!'static%3E()-%3Ebool%7B%0A++++use+std::any::TypeId%3B%0A%0A++++const+BOOLID:+TypeId+%3D+TypeId::of::%3Cbool%3E()%3B%0A++++match+TypeId::of::%3CT%3E()%7B%0A++++++++BOOLID+%3D%3E+true,%0A+++++++++%3D%3E+false,%0A++++%7D%0A%7D%0A%0Apub+fn+good()-%3Ebool%7B%0A++++isbool::%3Cbool%3E()%0A%7D%0A%0Apub+fn+bad()-%3Ebool%7B%0A++++isbool::%3Cu8%3E()%0A%7D'),l:'5',n:'0',o:'Rust+source+%231',t:'0')),k:45.,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:nightly,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'1',libraryCode:'1',trim:'1'),fontScale:14,fontUsePx:'0',j:1,lang:rust,libs:!(),options:'-Copt-level%3D1',selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'rustc+nightly+(Editor+%231,+Compiler+%231)+Rust',t:'0')),k:54.,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)
I think, we should close this issue in favor of Or in favor of which allows write such code:
I decided to add because we unlikely to get resolved soon, and still has soundness problems.
Adding wouldn't have any effect without optimizations unfortunately because there must run InlinerPass which doesn't run on debug. With New Pass Manager (which I hope would stabilized soon), users may set for fast debug builds and get profits from this change.

Discussion:
/// assert_eq!(is_string(&0), false); /// assert_eq!(is_string(&"cookie monster".to_string()), true); /// ``` <ins> #[inline] </ins> #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_type_id", issue = "77125")]