File tree Expand file tree Collapse file tree 4 files changed +94
-2
lines changed
compiler/rustc_hir_analysis/src/check
tests/ui/async-await/in-trait Expand file tree Collapse file tree 4 files changed +94
-2
lines changed Original file line number Diff line number Diff line change @@ -722,7 +722,14 @@ pub(super) fn check_specialization_validity<'tcx>(
722722 let result = opt_result. unwrap_or ( Ok ( ( ) ) ) ;
723723
724724 if let Err ( parent_impl) = result {
725- report_forbidden_specialization ( tcx, impl_item, parent_impl) ;
725+ if !tcx. is_impl_trait_in_trait ( impl_item) {
726+ report_forbidden_specialization ( tcx, impl_item, parent_impl) ;
727+ } else {
728+ tcx. sess . delay_span_bug (
729+ DUMMY_SP ,
730+ format ! ( "parent item: {:?} not marked as default" , parent_impl) ,
731+ ) ;
732+ }
726733 }
727734}
728735
@@ -1485,7 +1492,9 @@ fn opaque_type_cycle_error(
14851492 }
14861493
14871494 for closure_def_id in visitor. closures {
1488- let Some ( closure_local_did) = closure_def_id. as_local ( ) else { continue ; } ;
1495+ let Some ( closure_local_did) = closure_def_id. as_local ( ) else {
1496+ continue ;
1497+ } ;
14891498 let typeck_results = tcx. typeck ( closure_local_did) ;
14901499
14911500 let mut label_match = |ty : Ty < ' _ > , span| {
Original file line number Diff line number Diff line change 1+ error[E0046]: not all trait items implemented, missing: `foo`
2+ --> $DIR/missing-feature-flag.rs:14:1
3+ |
4+ LL | async fn foo(_: T) -> &'static str;
5+ | ----------------------------------- `foo` from trait
6+ ...
7+ LL | impl<T> MyTrait<T> for MyStruct {}
8+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation
9+
10+ error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
11+ --> $DIR/missing-feature-flag.rs:18:5
12+ |
13+ LL | impl<T> MyTrait<T> for MyStruct {}
14+ | ------------------------------- parent `impl` is here
15+ ...
16+ LL | async fn foo(_: i32) -> &'static str {}
17+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `foo`
18+ |
19+ = note: to specialize, `foo` in the parent `impl` must be marked `default`
20+
21+ error[E0308]: mismatched types
22+ --> $DIR/missing-feature-flag.rs:18:42
23+ |
24+ LL | async fn foo(_: i32) -> &'static str {}
25+ | ^^ expected `&str`, found `()`
26+
27+ error: aborting due to 3 previous errors
28+
29+ Some errors have detailed explanations: E0046, E0308, E0520.
30+ For more information about an error, try `rustc --explain E0046`.
Original file line number Diff line number Diff line change 1+ error[E0046]: not all trait items implemented, missing: `foo`
2+ --> $DIR/missing-feature-flag.rs:14:1
3+ |
4+ LL | async fn foo(_: T) -> &'static str;
5+ | ----------------------------------- `foo` from trait
6+ ...
7+ LL | impl<T> MyTrait<T> for MyStruct {}
8+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation
9+
10+ error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
11+ --> $DIR/missing-feature-flag.rs:18:5
12+ |
13+ LL | impl<T> MyTrait<T> for MyStruct {}
14+ | ------------------------------- parent `impl` is here
15+ ...
16+ LL | async fn foo(_: i32) -> &'static str {}
17+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `foo`
18+ |
19+ = note: to specialize, `foo` in the parent `impl` must be marked `default`
20+
21+ error[E0308]: mismatched types
22+ --> $DIR/missing-feature-flag.rs:18:42
23+ |
24+ LL | async fn foo(_: i32) -> &'static str {}
25+ | ^^ expected `&str`, found `()`
26+
27+ error: aborting due to 3 previous errors
28+
29+ Some errors have detailed explanations: E0046, E0308, E0520.
30+ For more information about an error, try `rustc --explain E0046`.
Original file line number Diff line number Diff line change 1+ // edition:2018
2+ // [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
3+ // revisions: current next
4+
5+ #![ feature( async_fn_in_trait) ]
6+ #![ feature( min_specialization) ]
7+
8+ struct MyStruct ;
9+
10+ trait MyTrait < T > {
11+ async fn foo ( _: T ) -> & ' static str ;
12+ }
13+
14+ impl < T > MyTrait < T > for MyStruct { }
15+ //~^ ERROR: not all trait items implemented, missing: `foo` [E0046]
16+
17+ impl MyTrait < i32 > for MyStruct {
18+ async fn foo ( _: i32 ) -> & ' static str { }
19+ //~^ ERROR: `foo` specializes an item from a parent `impl`, but that item is not marked `default` [E0520]
20+ //~| ERROR: mismatched types [E0308]
21+ }
22+
23+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments