Skip to content

Commit 8f12485

Browse files
committed
review comments
1 parent 96f5584 commit 8f12485

7 files changed

+32
-40
lines changed

src/librustc_typeck/check/mod.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -1741,8 +1741,7 @@ fn get_owner_return_paths(
17411741
/// If all the return expressions evaluate to `!`, then we explain that the error will go away
17421742
/// after changing it. This can happen when a user uses `panic!()` or similar as a placeholder.
17431743
fn opaque_type_cycle_error(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) {
1744-
let mut err =
1745-
struct_span_err!(tcx.sess, span, E0720, "cannot resolve opaque type to a concrete type");
1744+
let mut err = struct_span_err!(tcx.sess, span, E0720, "cannot resolve opaque type");
17461745

17471746
let mut label = false;
17481747
if let Some((hir_id, visitor)) = get_owner_return_paths(tcx, def_id) {
@@ -1751,7 +1750,6 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) {
17511750
.returns
17521751
.iter()
17531752
.filter_map(|expr| tables.node_type_opt(expr.hir_id))
1754-
.map(|ty| tcx.infer_ctxt().enter(|infcx| infcx.resolve_vars_if_possible(&ty)))
17551753
.all(|ty| matches!(ty.kind, ty::Never))
17561754
{
17571755
let spans = visitor
@@ -1782,9 +1780,6 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) {
17821780
.iter()
17831781
.filter_map(|e| tables.node_type_opt(e.hir_id).map(|t| (e.span, t)))
17841782
.filter(|(_, ty)| !matches!(ty.kind, ty::Never))
1785-
.map(|(sp, ty)| {
1786-
(sp, tcx.infer_ctxt().enter(|infcx| infcx.resolve_vars_if_possible(&ty)))
1787-
})
17881783
{
17891784
struct VisitTypes(Vec<DefId>);
17901785
impl<'tcx> ty::fold::TypeVisitor<'tcx> for VisitTypes {
@@ -1812,7 +1807,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'tcx>, def_id: LocalDefId, span: Span) {
18121807
}
18131808
}
18141809
if !label {
1815-
err.span_label(span, "cannot resolve to a concrete type");
1810+
err.span_label(span, "cannot resolve opaque type");
18161811
}
18171812
err.emit();
18181813
}
@@ -1824,9 +1819,9 @@ fn binding_opaque_type_cycle_error(
18241819
span: Span,
18251820
partially_expanded_type: Ty<'tcx>,
18261821
) {
1827-
let mut err =
1828-
struct_span_err!(tcx.sess, span, E0720, "cannot resolve opaque type to a concrete type");
1829-
err.span_label(span, "cannot resolve to a concrete type");
1822+
let mut err = struct_span_err!(tcx.sess, span, E0720, "cannot resolve opaque type");
1823+
err.span_label(span, "cannot resolve opaque type");
1824+
// Find the the owner that declared this `impl Trait` type.
18301825
let hir_id = tcx.hir().as_local_hir_id(def_id);
18311826
let mut prev_hir_id = hir_id;
18321827
let mut hir_id = tcx.hir().get_parent_node(hir_id);
@@ -1855,15 +1850,12 @@ fn binding_opaque_type_cycle_error(
18551850
let hir_id = tcx.hir().as_local_hir_id(def_id);
18561851
let tables =
18571852
tcx.typeck_tables_of(tcx.hir().local_def_id(tcx.hir().get_parent_item(hir_id)));
1858-
let ty = tables.node_type_opt(expr.hir_id);
1859-
if let Some(ty) =
1860-
tcx.infer_ctxt().enter(|infcx| infcx.resolve_vars_if_possible(&ty))
1861-
{
1853+
if let Some(ty) = tables.node_type_opt(expr.hir_id) {
18621854
err.span_label(
18631855
expr.span,
18641856
&format!(
18651857
"this is of type `{}`, which doesn't constrain \
1866-
`{}` enough to arrive to a concrete type",
1858+
`{}` enough to arrive to a concrete type",
18671859
ty, partially_expanded_type
18681860
),
18691861
);

src/test/ui/impl-trait/binding-without-value.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0720]: cannot resolve opaque type to a concrete type
1+
error[E0720]: cannot resolve opaque type
22
--> $DIR/binding-without-value.rs:5:13
33
|
44
LL | let _ : impl Copy;
5-
| - ^^^^^^^^^ cannot resolve to a concrete type
5+
| - ^^^^^^^^^ cannot resolve opaque type
66
| |
77
| this binding might not have a concrete type
88
|

src/test/ui/impl-trait/issues/infinite-impl-trait-issue-38064.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0720]: cannot resolve opaque type to a concrete type
1+
error[E0720]: cannot resolve opaque type
22
--> $DIR/infinite-impl-trait-issue-38064.rs:8:13
33
|
44
LL | fn foo() -> impl Quux {
@@ -10,7 +10,7 @@ LL | Foo(bar())
1010
LL | fn bar() -> impl Quux {
1111
| --------- returning this opaque type `foo::Foo<impl Quux>`
1212

13-
error[E0720]: cannot resolve opaque type to a concrete type
13+
error[E0720]: cannot resolve opaque type
1414
--> $DIR/infinite-impl-trait-issue-38064.rs:14:13
1515
|
1616
LL | fn foo() -> impl Quux {

src/test/ui/impl-trait/recursive-impl-trait-type-direct.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0720]: cannot resolve opaque type to a concrete type
1+
error[E0720]: cannot resolve opaque type
22
--> $DIR/recursive-impl-trait-type-direct.rs:5:14
33
|
44
LL | fn test() -> impl Sized {

src/test/ui/impl-trait/recursive-impl-trait-type-indirect.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0720]: cannot resolve opaque type to a concrete type
1+
error[E0720]: cannot resolve opaque type
22
--> $DIR/recursive-impl-trait-type-indirect.rs:7:22
33
|
44
LL | fn option(i: i32) -> impl Sized {
@@ -9,7 +9,7 @@ LL | if i < 0 { None } else { Some((option(i - 1), i)) }
99
| |
1010
| returning here with type `std::option::Option<(impl Sized, i32)>`
1111

12-
error[E0720]: cannot resolve opaque type to a concrete type
12+
error[E0720]: cannot resolve opaque type
1313
--> $DIR/recursive-impl-trait-type-indirect.rs:12:15
1414
|
1515
LL | fn tuple() -> impl Sized {
@@ -18,7 +18,7 @@ LL |
1818
LL | (tuple(),)
1919
| ---------- returning here with type `(impl Sized,)`
2020

21-
error[E0720]: cannot resolve opaque type to a concrete type
21+
error[E0720]: cannot resolve opaque type
2222
--> $DIR/recursive-impl-trait-type-indirect.rs:17:15
2323
|
2424
LL | fn array() -> impl Sized {
@@ -27,7 +27,7 @@ LL |
2727
LL | [array()]
2828
| --------- returning here with type `[impl Sized; 1]`
2929

30-
error[E0720]: cannot resolve opaque type to a concrete type
30+
error[E0720]: cannot resolve opaque type
3131
--> $DIR/recursive-impl-trait-type-indirect.rs:22:13
3232
|
3333
LL | fn ptr() -> impl Sized {
@@ -36,7 +36,7 @@ LL |
3636
LL | &ptr() as *const _
3737
| ------------------ returning here with type `*const impl Sized`
3838

39-
error[E0720]: cannot resolve opaque type to a concrete type
39+
error[E0720]: cannot resolve opaque type
4040
--> $DIR/recursive-impl-trait-type-indirect.rs:27:16
4141
|
4242
LL | fn fn_ptr() -> impl Sized {
@@ -45,7 +45,7 @@ LL |
4545
LL | fn_ptr as fn() -> _
4646
| ------------------- returning here with type `fn() -> impl Sized`
4747

48-
error[E0720]: cannot resolve opaque type to a concrete type
48+
error[E0720]: cannot resolve opaque type
4949
--> $DIR/recursive-impl-trait-type-indirect.rs:32:25
5050
|
5151
LL | fn closure_capture() -> impl Sized {
@@ -56,7 +56,7 @@ LL | | x;
5656
LL | | }
5757
| |_____- returning here with type `[closure@$DIR/recursive-impl-trait-type-indirect.rs:35:5: 37:6 x:impl Sized]`
5858

59-
error[E0720]: cannot resolve opaque type to a concrete type
59+
error[E0720]: cannot resolve opaque type
6060
--> $DIR/recursive-impl-trait-type-indirect.rs:40:29
6161
|
6262
LL | fn closure_ref_capture() -> impl Sized {
@@ -67,7 +67,7 @@ LL | | &x;
6767
LL | | }
6868
| |_____- returning here with type `[closure@$DIR/recursive-impl-trait-type-indirect.rs:43:5: 45:6 x:impl Sized]`
6969

70-
error[E0720]: cannot resolve opaque type to a concrete type
70+
error[E0720]: cannot resolve opaque type
7171
--> $DIR/recursive-impl-trait-type-indirect.rs:48:21
7272
|
7373
LL | fn closure_sig() -> impl Sized {
@@ -76,7 +76,7 @@ LL |
7676
LL | || closure_sig()
7777
| ---------------- returning here with type `[closure@$DIR/recursive-impl-trait-type-indirect.rs:50:5: 50:21]`
7878

79-
error[E0720]: cannot resolve opaque type to a concrete type
79+
error[E0720]: cannot resolve opaque type
8080
--> $DIR/recursive-impl-trait-type-indirect.rs:53:23
8181
|
8282
LL | fn generator_sig() -> impl Sized {
@@ -85,7 +85,7 @@ LL |
8585
LL | || generator_sig()
8686
| ------------------ returning here with type `[closure@$DIR/recursive-impl-trait-type-indirect.rs:55:5: 55:23]`
8787

88-
error[E0720]: cannot resolve opaque type to a concrete type
88+
error[E0720]: cannot resolve opaque type
8989
--> $DIR/recursive-impl-trait-type-indirect.rs:58:27
9090
|
9191
LL | fn generator_capture() -> impl Sized {
@@ -97,7 +97,7 @@ LL | | x;
9797
LL | | }
9898
| |_____- returning here with type `[generator@$DIR/recursive-impl-trait-type-indirect.rs:61:5: 64:6 x:impl Sized {()}]`
9999

100-
error[E0720]: cannot resolve opaque type to a concrete type
100+
error[E0720]: cannot resolve opaque type
101101
--> $DIR/recursive-impl-trait-type-indirect.rs:67:35
102102
|
103103
LL | fn substs_change<T: 'static>() -> impl Sized {
@@ -106,7 +106,7 @@ LL |
106106
LL | (substs_change::<&T>(),)
107107
| ------------------------ returning here with type `(impl Sized,)`
108108

109-
error[E0720]: cannot resolve opaque type to a concrete type
109+
error[E0720]: cannot resolve opaque type
110110
--> $DIR/recursive-impl-trait-type-indirect.rs:72:24
111111
|
112112
LL | fn generator_hold() -> impl Sized {
@@ -119,7 +119,7 @@ LL | | x;
119119
LL | | }
120120
| |_____- returning here with type `[generator@$DIR/recursive-impl-trait-type-indirect.rs:74:5: 78:6 {impl Sized, ()}]`
121121

122-
error[E0720]: cannot resolve opaque type to a concrete type
122+
error[E0720]: cannot resolve opaque type
123123
--> $DIR/recursive-impl-trait-type-indirect.rs:86:26
124124
|
125125
LL | fn mutual_recursion() -> impl Sync {
@@ -131,7 +131,7 @@ LL | mutual_recursion_b()
131131
LL | fn mutual_recursion_b() -> impl Sized {
132132
| ---------- returning this opaque type `impl Sized`
133133

134-
error[E0720]: cannot resolve opaque type to a concrete type
134+
error[E0720]: cannot resolve opaque type
135135
--> $DIR/recursive-impl-trait-type-indirect.rs:91:28
136136
|
137137
LL | fn mutual_recursion() -> impl Sync {

src/test/ui/impl-trait/recursive-impl-trait-type-through-non-recursive.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0720]: cannot resolve opaque type to a concrete type
1+
error[E0720]: cannot resolve opaque type
22
--> $DIR/recursive-impl-trait-type-through-non-recursive.rs:7:22
33
|
44
LL | fn id<T>(t: T) -> impl Sized { t }
@@ -9,7 +9,7 @@ LL | fn recursive_id() -> impl Sized {
99
LL | id(recursive_id2())
1010
| ------------------- returning here with type `impl Sized`
1111

12-
error[E0720]: cannot resolve opaque type to a concrete type
12+
error[E0720]: cannot resolve opaque type
1313
--> $DIR/recursive-impl-trait-type-through-non-recursive.rs:11:23
1414
|
1515
LL | fn id<T>(t: T) -> impl Sized { t }
@@ -20,7 +20,7 @@ LL | fn recursive_id2() -> impl Sized {
2020
LL | id(recursive_id())
2121
| ------------------ returning here with type `impl Sized`
2222

23-
error[E0720]: cannot resolve opaque type to a concrete type
23+
error[E0720]: cannot resolve opaque type
2424
--> $DIR/recursive-impl-trait-type-through-non-recursive.rs:17:24
2525
|
2626
LL | fn wrap<T>(t: T) -> impl Sized { (t,) }
@@ -31,7 +31,7 @@ LL | fn recursive_wrap() -> impl Sized {
3131
LL | wrap(recursive_wrap2())
3232
| ----------------------- returning here with type `impl Sized`
3333

34-
error[E0720]: cannot resolve opaque type to a concrete type
34+
error[E0720]: cannot resolve opaque type
3535
--> $DIR/recursive-impl-trait-type-through-non-recursive.rs:21:25
3636
|
3737
LL | fn wrap<T>(t: T) -> impl Sized { (t,) }

src/test/ui/impl-trait/where-allowed-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0720]: cannot resolve opaque type to a concrete type
1+
error[E0720]: cannot resolve opaque type
22
--> $DIR/where-allowed-2.rs:6:30
33
|
44
LL | fn in_adt_in_return() -> Vec<impl Debug> { panic!() }
55
| ^^^^^^^^^^ -------- this returned value is of `!` type
66
| |
7-
| cannot resolve to a concrete type
7+
| cannot resolve opaque type
88
|
99
= help: this error will resolve once the item's body returns a concrete type
1010

0 commit comments

Comments
 (0)