File tree Expand file tree Collapse file tree
compiler/rustc_trait_selection/src/traits Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -314,6 +314,11 @@ pub fn dyn_compatibility_violations_for_assoc_item(
314314 trait_def_id : DefId ,
315315 item : ty:: AssocItem ,
316316) -> Vec < DynCompatibilityViolation > {
317+ // `final` assoc functions don't prevent a trait from being dyn-compatible
318+ if tcx. defaultness ( item. def_id ) . is_final ( ) {
319+ return Vec :: new ( ) ;
320+ }
321+
317322 // Any item that has a `Self: Sized` requisite is otherwise exempt from the regulations.
318323 if tcx. generics_require_sized_self ( item. def_id ) {
319324 return Vec :: new ( ) ;
Original file line number Diff line number Diff line change 1+ //@ check-pass
2+
3+ #![ feature( final_associated_functions) ]
4+
5+ trait Foo {
6+ final fn bar < T : std:: fmt:: Debug > ( & self , t : T ) {
7+ println ! ( "{:?}" , t) ;
8+ }
9+
10+ fn baz ( & self ) { }
11+ }
12+
13+ impl Foo for ( ) { }
14+ impl Foo for i32 { }
15+
16+ fn foo ( x : & dyn Foo ) {
17+ x. bar ( 42 ) ;
18+ x. baz ( ) ;
19+ }
20+
21+ fn main ( ) {
22+ foo ( & ( ) ) ;
23+ foo ( & 42 ) ;
24+ }
You can’t perform that action at this time.
0 commit comments