Skip to content

Commit 9f59ab5

Browse files
Restore cyclic closure message
1 parent 0817b1d commit 9f59ab5

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

compiler/rustc_hir_typeck/src/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
227227
);
228228
// Make sure that we didn't infer a signature that mentions itself.
229229
// This can happen when we elaborate certain supertrait bounds that
230-
// mention projections containing the `Self` type. See
230+
// mention projections containing the `Self` type. See #105401.
231231
struct MentionsTy<'tcx> {
232232
expected_ty: Ty<'tcx>,
233233
}

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_infer::infer::error_reporting::TypeErrCtxt;
3333
use rustc_infer::infer::{InferOk, TypeTrace};
3434
use rustc_middle::traits::select::OverflowError;
3535
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
36-
use rustc_middle::ty::error::ExpectedFound;
36+
use rustc_middle::ty::error::{ExpectedFound, TypeError};
3737
use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable};
3838
use rustc_middle::ty::print::{with_forced_trimmed_paths, FmtPrinter, Print};
3939
use rustc_middle::ty::{
@@ -1215,6 +1215,25 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
12151215
}
12161216
}
12171217

1218+
OutputTypeParameterMismatch(
1219+
found_trait_ref,
1220+
expected_trait_ref,
1221+
terr @ TypeError::CyclicTy(_),
1222+
) => {
1223+
let self_ty = found_trait_ref.self_ty().skip_binder();
1224+
let (cause, terr) = if let ty::Closure(def_id, _) = self_ty.kind() {
1225+
(
1226+
ObligationCause::dummy_with_span(tcx.def_span(def_id)),
1227+
TypeError::CyclicTy(self_ty),
1228+
)
1229+
} else {
1230+
(obligation.cause.clone(), terr)
1231+
};
1232+
self.report_and_explain_type_error(
1233+
TypeTrace::poly_trait_refs(&cause, true, expected_trait_ref, found_trait_ref),
1234+
terr,
1235+
)
1236+
}
12181237
OutputTypeParameterMismatch(found_trait_ref, expected_trait_ref, _) => {
12191238
let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref);
12201239
let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref);

src/test/ui/issues/issue-25439.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
error[E0631]: type mismatch in closure arguments
2-
--> $DIR/issue-25439.rs:8:5
1+
error[E0644]: closure/generator type that references itself
2+
--> $DIR/issue-25439.rs:8:9
33
|
44
LL | fix(|_, x| x);
5-
| ^^^ ------ found signature defined here
6-
| |
7-
| expected due to this
5+
| ^^^^^^ cyclic type of infinite size
86
|
9-
= note: expected closure signature `for<'a> fn(Helper<'a, [closure@$DIR/issue-25439.rs:8:9: 8:15]>, i32) -> _`
10-
found closure signature `fn(_, _) -> _`
7+
= note: closures cannot capture themselves or take themselves as argument;
8+
this error may be the result of a recent compiler bug-fix,
9+
see issue #46062 <https://github.com/rust-lang/rust/issues/46062>
10+
for more information
1111
note: required by a bound in `fix`
1212
--> $DIR/issue-25439.rs:3:33
1313
|
@@ -16,4 +16,4 @@ LL | fn fix<F>(f: F) -> i32 where F: Fn(Helper<F>, i32) -> i32 {
1616

1717
error: aborting due to previous error
1818

19-
For more information about this error, try `rustc --explain E0631`.
19+
For more information about this error, try `rustc --explain E0644`.
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
error[E0631]: type mismatch in closure arguments
2-
--> $DIR/unboxed-closure-no-cyclic-sig.rs:8:5
1+
error[E0644]: closure/generator type that references itself
2+
--> $DIR/unboxed-closure-no-cyclic-sig.rs:8:7
33
|
44
LL | g(|_| { });
5-
| ^ --- found signature defined here
6-
| |
7-
| expected due to this
5+
| ^^^ cyclic type of infinite size
86
|
9-
= note: expected closure signature `fn(Option<[closure@$DIR/unboxed-closure-no-cyclic-sig.rs:8:7: 8:10]>) -> _`
10-
found closure signature `fn(_) -> _`
7+
= note: closures cannot capture themselves or take themselves as argument;
8+
this error may be the result of a recent compiler bug-fix,
9+
see issue #46062 <https://github.com/rust-lang/rust/issues/46062>
10+
for more information
1111
note: required by a bound in `g`
1212
--> $DIR/unboxed-closure-no-cyclic-sig.rs:5:24
1313
|
@@ -16,4 +16,4 @@ LL | fn g<F>(_: F) where F: FnOnce(Option<F>) {}
1616

1717
error: aborting due to previous error
1818

19-
For more information about this error, try `rustc --explain E0631`.
19+
For more information about this error, try `rustc --explain E0644`.

0 commit comments

Comments
 (0)