Skip to content

Commit

Permalink
Rollup merge of #113456 - spastorino:new-rpitit-31, r=compiler-errors
Browse files Browse the repository at this point in the history
Avoid calling report_forbidden_specialization for RPITITs

Fixes #113438

r? ``@compiler-errors``
  • Loading branch information
compiler-errors committed Jul 8, 2023
2 parents 37a05d8 + 24326ee commit cf1f8c5
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
13 changes: 11 additions & 2 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,14 @@ pub(super) fn check_specialization_validity<'tcx>(
let result = opt_result.unwrap_or(Ok(()));

if let Err(parent_impl) = result {
report_forbidden_specialization(tcx, impl_item, parent_impl);
if !tcx.is_impl_trait_in_trait(impl_item) {
report_forbidden_specialization(tcx, impl_item, parent_impl);
} else {
tcx.sess.delay_span_bug(
DUMMY_SP,
format!("parent item: {:?} not marked as default", parent_impl),
);
}
}
}

Expand Down Expand Up @@ -1485,7 +1492,9 @@ fn opaque_type_cycle_error(
}

for closure_def_id in visitor.closures {
let Some(closure_local_did) = closure_def_id.as_local() else { continue; };
let Some(closure_local_did) = closure_def_id.as_local() else {
continue;
};
let typeck_results = tcx.typeck(closure_local_did);

let mut label_match = |ty: Ty<'_>, span| {
Expand Down
30 changes: 30 additions & 0 deletions tests/ui/async-await/in-trait/missing-feature-flag.current.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
error[E0046]: not all trait items implemented, missing: `foo`
--> $DIR/missing-feature-flag.rs:14:1
|
LL | async fn foo(_: T) -> &'static str;
| ----------------------------------- `foo` from trait
...
LL | impl<T> MyTrait<T> for MyStruct {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation

error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/missing-feature-flag.rs:18:5
|
LL | impl<T> MyTrait<T> for MyStruct {}
| ------------------------------- parent `impl` is here
...
LL | async fn foo(_: i32) -> &'static str {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `foo`
|
= note: to specialize, `foo` in the parent `impl` must be marked `default`

error[E0308]: mismatched types
--> $DIR/missing-feature-flag.rs:18:42
|
LL | async fn foo(_: i32) -> &'static str {}
| ^^ expected `&str`, found `()`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0046, E0308, E0520.
For more information about an error, try `rustc --explain E0046`.
30 changes: 30 additions & 0 deletions tests/ui/async-await/in-trait/missing-feature-flag.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
error[E0046]: not all trait items implemented, missing: `foo`
--> $DIR/missing-feature-flag.rs:14:1
|
LL | async fn foo(_: T) -> &'static str;
| ----------------------------------- `foo` from trait
...
LL | impl<T> MyTrait<T> for MyStruct {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation

error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
--> $DIR/missing-feature-flag.rs:18:5
|
LL | impl<T> MyTrait<T> for MyStruct {}
| ------------------------------- parent `impl` is here
...
LL | async fn foo(_: i32) -> &'static str {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `foo`
|
= note: to specialize, `foo` in the parent `impl` must be marked `default`

error[E0308]: mismatched types
--> $DIR/missing-feature-flag.rs:18:42
|
LL | async fn foo(_: i32) -> &'static str {}
| ^^ expected `&str`, found `()`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0046, E0308, E0520.
For more information about an error, try `rustc --explain E0046`.
23 changes: 23 additions & 0 deletions tests/ui/async-await/in-trait/missing-feature-flag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// edition:2018
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
// revisions: current next

#![feature(async_fn_in_trait)]
#![feature(min_specialization)]

struct MyStruct;

trait MyTrait<T> {
async fn foo(_: T) -> &'static str;
}

impl<T> MyTrait<T> for MyStruct {}
//~^ ERROR: not all trait items implemented, missing: `foo` [E0046]

impl MyTrait<i32> for MyStruct {
async fn foo(_: i32) -> &'static str {}
//~^ ERROR: `foo` specializes an item from a parent `impl`, but that item is not marked `default` [E0520]
//~| ERROR: mismatched types [E0308]
}

fn main() {}

0 comments on commit cf1f8c5

Please sign in to comment.