Skip to content

Avoid calling report_forbidden_specialization for RPITITs #113456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please delay a bug here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have delayed a bug, but please would rather if you check what I did what you meant and if the english wording is fine :).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a bug so it's fine.

Copy link
Member Author

@spastorino spastorino Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this to avoid calling report_forbidden_specialization because all it does https://github.com/spastorino/rust/blob/518f84ba766d503cb709f753a0a498d87b942dd0/compiler/rustc_hir_analysis/src/check/mod.rs#L172-L182 is emit an error about an impl element that is not marked as default and that doesn't make any sense for a synthesized RPIT.

@compiler-errors would you prefer a code comment about this instead?

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() {}