1
Fork 0

Restore cyclic closure message

This commit is contained in:
Michael Goulet 2022-12-07 03:03:35 +00:00
parent 0817b1d3ed
commit 9f59ab55e6
4 changed files with 37 additions and 18 deletions

View file

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

View file

@ -33,7 +33,7 @@ use rustc_infer::infer::error_reporting::TypeErrCtxt;
use rustc_infer::infer::{InferOk, TypeTrace}; use rustc_infer::infer::{InferOk, TypeTrace};
use rustc_middle::traits::select::OverflowError; use rustc_middle::traits::select::OverflowError;
use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::abstract_const::NotConstEvaluatable;
use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable};
use rustc_middle::ty::print::{with_forced_trimmed_paths, FmtPrinter, Print}; use rustc_middle::ty::print::{with_forced_trimmed_paths, FmtPrinter, Print};
use rustc_middle::ty::{ use rustc_middle::ty::{
@ -1215,6 +1215,25 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
} }
OutputTypeParameterMismatch(
found_trait_ref,
expected_trait_ref,
terr @ TypeError::CyclicTy(_),
) => {
let self_ty = found_trait_ref.self_ty().skip_binder();
let (cause, terr) = if let ty::Closure(def_id, _) = self_ty.kind() {
(
ObligationCause::dummy_with_span(tcx.def_span(def_id)),
TypeError::CyclicTy(self_ty),
)
} else {
(obligation.cause.clone(), terr)
};
self.report_and_explain_type_error(
TypeTrace::poly_trait_refs(&cause, true, expected_trait_ref, found_trait_ref),
terr,
)
}
OutputTypeParameterMismatch(found_trait_ref, expected_trait_ref, _) => { OutputTypeParameterMismatch(found_trait_ref, expected_trait_ref, _) => {
let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref); let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref);
let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref); let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref);

View file

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

View file

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