Skip to content

Commit 29c8732

Browse files
committed
Make the error for opaque types that have no hidden types a bit informative
1 parent 4d2e965 commit 29c8732

File tree

45 files changed

+115
-56
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+115
-56
lines changed

compiler/rustc_typeck/src/collect/type_of.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,12 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
724724
Some((_, ty)) => ty,
725725
None => {
726726
let span = tcx.def_span(def_id);
727-
tcx.sess.span_err(span, "could not find defining uses");
727+
let name = tcx.item_name(tcx.parent(def_id.to_def_id()).unwrap());
728+
let label = format!(
729+
"`{}` must be used in combination with a concrete type within the same module",
730+
name
731+
);
732+
tcx.sess.struct_span_err(span, "unconstrained opaque type").note(&label).emit();
728733
tcx.ty_error()
729734
}
730735
}

src/test/ui/generic-associated-types/issue-87258_a.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub trait Trait2 {
1616

1717
impl<'c, S: Trait2> Trait2 for &'c mut S {
1818
type FooFuture<'a> = impl Trait1;
19-
//~^ ERROR could not find defining uses
19+
//~^ ERROR unconstrained opaque type
2020
fn foo<'a>() -> Self::FooFuture<'a> {
2121
Struct(unimplemented!())
2222
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error: could not find defining uses
1+
error: unconstrained opaque type
22
--> $DIR/issue-87258_a.rs:18:26
33
|
44
LL | type FooFuture<'a> = impl Trait1;
55
| ^^^^^^^^^^^
6+
|
7+
= note: `FooFuture` must be used in combination with a concrete type within the same module
68

79
error: aborting due to previous error
810

src/test/ui/generic-associated-types/issue-87258_b.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub trait Trait2 {
1515
}
1616

1717
type Helper<'xenon, 'yttrium, KABOOM: Trait2> = impl Trait1;
18-
//~^ ERROR could not find defining uses
18+
//~^ ERROR unconstrained opaque type
1919

2020
impl<'c, S: Trait2> Trait2 for &'c mut S {
2121
type FooFuture<'a> = Helper<'c, 'a, S>;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error: could not find defining uses
1+
error: unconstrained opaque type
22
--> $DIR/issue-87258_b.rs:17:49
33
|
44
LL | type Helper<'xenon, 'yttrium, KABOOM: Trait2> = impl Trait1;
55
| ^^^^^^^^^^^
6+
|
7+
= note: `Helper` must be used in combination with a concrete type within the same module
68

79
error: aborting due to previous error
810

src/test/ui/generic-associated-types/issue-88595.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct C;
1818
impl<'a> A<'a> for C {
1919
type B<'b> = impl Clone;
2020
//~^ ERROR: lifetime bound not satisfied
21-
//~| ERROR: could not find defining uses
21+
//~| ERROR: unconstrained opaque type
2222

2323
fn a(&'a self) -> Self::B<'a> {} //~ ERROR: non-defining opaque type use in defining scope
2424
}

src/test/ui/generic-associated-types/issue-88595.stderr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ LL | impl<'a> A<'a> for C {
2929
LL | type B<'b> = impl Clone;
3030
| ^^
3131

32-
error: could not find defining uses
32+
error: unconstrained opaque type
3333
--> $DIR/issue-88595.rs:19:18
3434
|
3535
LL | type B<'b> = impl Clone;
3636
| ^^^^^^^^^^
37+
|
38+
= note: `B` must be used in combination with a concrete type within the same module
3739

3840
error: aborting due to 3 previous errors
3941

src/test/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
mod a {
44
type Foo = impl PartialEq<(Foo, i32)>;
5-
//~^ ERROR could not find defining uses
5+
//~^ ERROR unconstrained opaque type
66

77
struct Bar;
88

@@ -15,7 +15,7 @@ mod a {
1515

1616
mod b {
1717
type Foo = impl PartialEq<(Foo, i32)>;
18-
//~^ ERROR could not find defining uses
18+
//~^ ERROR unconstrained opaque type
1919

2020
struct Bar;
2121

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
error: could not find defining uses
1+
error: unconstrained opaque type
22
--> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:4:16
33
|
44
LL | type Foo = impl PartialEq<(Foo, i32)>;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `Foo` must be used in combination with a concrete type within the same module
68

7-
error: could not find defining uses
9+
error: unconstrained opaque type
810
--> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:17:16
911
|
1012
LL | type Foo = impl PartialEq<(Foo, i32)>;
1113
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
|
15+
= note: `Foo` must be used in combination with a concrete type within the same module
1216

1317
error: aborting due to 2 previous errors
1418

src/test/ui/impl-trait/two_tait_defining_each_other2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(type_alias_impl_trait)]
22

33
type A = impl Foo;
4-
//~^ ERROR could not find defining uses
4+
//~^ ERROR unconstrained opaque type
55
type B = impl Foo;
66

77
trait Foo {}

0 commit comments

Comments
 (0)