Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a6c6b29

Browse files
committedApr 15, 2024
Method resolution constrains hidden types instead of rejecting method candidates
1 parent 31271ed commit a6c6b29

File tree

11 files changed

+20
-132
lines changed

11 files changed

+20
-132
lines changed
 

‎compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14481448
let impl_ty = self.normalize(span, tcx.type_of(impl_def_id).instantiate(tcx, args));
14491449
let self_ty = self.normalize(span, self_ty);
14501450
match self.at(&self.misc(span), self.param_env).eq(
1451-
DefineOpaqueTypes::No,
1451+
DefineOpaqueTypes::Yes,
14521452
impl_ty,
14531453
self_ty,
14541454
) {

‎compiler/rustc_hir_typeck/src/method/confirm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
499499
args,
500500
})),
501501
);
502-
match self.at(&cause, self.param_env).sup(DefineOpaqueTypes::No, method_self_ty, self_ty) {
502+
match self.at(&cause, self.param_env).sup(DefineOpaqueTypes::Yes, method_self_ty, self_ty) {
503503
Ok(InferOk { obligations, value: () }) => {
504504
self.register_predicates(obligations);
505505
}

‎compiler/rustc_hir_typeck/src/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14881488
self.probe(|_| {
14891489
// First check that the self type can be related.
14901490
let sub_obligations = match self.at(&ObligationCause::dummy(), self.param_env).sup(
1491-
DefineOpaqueTypes::No,
1491+
DefineOpaqueTypes::Yes,
14921492
probe.xform_self_ty,
14931493
self_ty,
14941494
) {

‎tests/ui/impl-trait/issues/issue-70877.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ fn ham() -> Foo {
2727

2828
fn oof(_: Foo) -> impl std::fmt::Debug {
2929
let mut bar = ham();
30-
let func = bar.next().unwrap();
31-
return func(&"oof"); //~ ERROR opaque type's hidden type cannot be another opaque type
30+
let func = bar.next().unwrap(); //~ ERROR: type annotations needed
31+
return func(&"oof");
3232
}
3333

3434
fn main() {
+9-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
error: opaque type's hidden type cannot be another opaque type from the same scope
2-
--> $DIR/issue-70877.rs:31:12
1+
error[E0282]: type annotations needed
2+
--> $DIR/issue-70877.rs:30:9
33
|
4+
LL | let func = bar.next().unwrap();
5+
| ^^^^
46
LL | return func(&"oof");
5-
| ^^^^^^^^^^^^ one of the two opaque types used here has to be outside its defining scope
7+
| ------------ type must be known at this point
68
|
7-
note: opaque type whose hidden type is being assigned
8-
--> $DIR/issue-70877.rs:28:19
9+
help: consider giving `func` an explicit type
910
|
10-
LL | fn oof(_: Foo) -> impl std::fmt::Debug {
11-
| ^^^^^^^^^^^^^^^^^^^^
12-
note: opaque type being used as hidden type
13-
--> $DIR/issue-70877.rs:4:15
14-
|
15-
LL | type FooRet = impl std::fmt::Debug;
16-
| ^^^^^^^^^^^^^^^^^^^^
11+
LL | let func: /* Type */ = bar.next().unwrap();
12+
| ++++++++++++
1713

1814
error: aborting due to 1 previous error
1915

16+
For more information about this error, try `rustc --explain E0282`.

‎tests/ui/impl-trait/method-resolution.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//@ check-pass
2+
13
trait Trait {}
24

35
impl Trait for u32 {}
@@ -9,11 +11,9 @@ impl Bar<u32> {
911
}
1012

1113
fn foo(x: bool) -> Bar<impl Sized> {
12-
//~^ ERROR: cycle detected
1314
if x {
1415
let x = foo(false);
1516
x.foo();
16-
//~^ ERROR: no method named `foo` found
1717
}
1818
todo!()
1919
}

‎tests/ui/impl-trait/method-resolution.stderr

-36
This file was deleted.

‎tests/ui/methods/opaque_param_in_ufc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#![feature(type_alias_impl_trait)]
2+
3+
//@ check-pass
4+
25
struct Foo<T>(T);
36

47
impl Foo<u32> {
@@ -15,14 +18,11 @@ fn bar() -> Bar {
1518
impl Foo<Bar> {
1619
fn foo() -> Bar {
1720
Self::method();
18-
//~^ ERROR: no function or associated item named `method` found for struct `Foo<Bar>`
1921
Foo::<Bar>::method();
20-
//~^ ERROR: no function or associated item named `method` found for struct `Foo<Bar>`
2122
let x = Foo(bar());
2223
Foo::method2(x);
2324
let x = Self(bar());
2425
Self::method2(x);
25-
//~^ ERROR: no function or associated item named `method2` found for struct `Foo<Bar>`
2626
todo!()
2727
}
2828
}

‎tests/ui/methods/opaque_param_in_ufc.stderr

-36
This file was deleted.

‎tests/ui/type-alias-impl-trait/method_resolution2.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#![feature(type_alias_impl_trait)]
2+
//@ check-pass
23

34
type Foo = impl Sized;
4-
//~^ ERROR: cycle
55

66
struct Bar<T>(T);
77

88
impl Bar<Foo> {
99
fn bar(self) {
1010
self.foo()
11-
//~^ ERROR: no method named `foo`
1211
}
1312
}
1413

‎tests/ui/type-alias-impl-trait/method_resolution2.stderr

-36
This file was deleted.

0 commit comments

Comments
 (0)
Failed to load comments.