Skip to content
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

Account for return-position impl Trait in trait in opt_suggest_box_span #105846

Merged
merged 1 commit into from
Jan 5, 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
14 changes: 11 additions & 3 deletions compiler/rustc_hir_typeck/src/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None
}
})?;
let opaque_ty = self.tcx.mk_opaque(rpit_def_id, substs);

if !self.can_coerce(first_ty, expected) || !self.can_coerce(second_ty, expected) {
return None;
Expand All @@ -540,13 +539,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
let pred = pred.kind().rebind(match pred.kind().skip_binder() {
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) => {
assert_eq!(trait_pred.trait_ref.self_ty(), opaque_ty);
// FIXME(rpitit): This will need to be fixed when we move to associated types
assert!(matches!(
*trait_pred.trait_ref.self_ty().kind(),
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
if def_id == rpit_def_id && substs == substs
));
ty::PredicateKind::Clause(ty::Clause::Trait(
trait_pred.with_self_ty(self.tcx, ty),
))
}
ty::PredicateKind::Clause(ty::Clause::Projection(mut proj_pred)) => {
assert_eq!(proj_pred.projection_ty.self_ty(), opaque_ty);
assert!(matches!(
*proj_pred.projection_ty.self_ty().kind(),
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
if def_id == rpit_def_id && substs == substs
));
proj_pred = proj_pred.with_self_ty(self.tcx, ty);
ty::PredicateKind::Clause(ty::Clause::Projection(proj_pred))
}
Expand Down
49 changes: 49 additions & 0 deletions src/test/ui/impl-trait/in-trait/box-coerce-span-in-default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// check-pass

#![feature(return_position_impl_trait_in_trait)]
//~^ WARN the feature `return_position_impl_trait_in_trait` is incomplete

struct TestA {}
struct TestB {}

impl TestTrait for TestA {
type Output = ();
}
impl TestTrait for TestB {
type Output = ();
}

trait TestTrait {
type Output;
}

impl<A, B> TestTrait for GreeterOutput<A, B>
where
A: TestTrait<Output = ()>,
B: TestTrait<Output = ()>,
{
type Output = ();
}

enum GreeterOutput<A, B>
where
A: TestTrait<Output = ()>,
B: TestTrait<Output = ()>,
{
SayHello(A),
SayGoodbye(B),
}

trait Greeter {
fn test_func(&self, func: &str) -> impl TestTrait<Output = ()> {
match func {
"SayHello" => GreeterOutput::SayHello(TestA {}),
"SayGoodbye" => GreeterOutput::SayGoodbye(TestB {}),
_ => GreeterOutput::SayHello(TestA {}),
}
}
}

fn main() {
println!("Hello, world!");
}
11 changes: 11 additions & 0 deletions src/test/ui/impl-trait/in-trait/box-coerce-span-in-default.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `return_position_impl_trait_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/box-coerce-span-in-default.rs:3:12
|
LL | #![feature(return_position_impl_trait_in_trait)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
= note: `#[warn(incomplete_features)]` on by default

warning: 1 warning emitted