Do not report cycle error when inferring return type for suggestion

This commit is contained in:
Michael Goulet 2022-08-10 20:53:06 +00:00
parent 40336865fe
commit 5309375d2c
8 changed files with 75 additions and 0 deletions

View File

@ -4359,6 +4359,7 @@ dependencies = [
"rustc_serialize",
"rustc_session",
"rustc_span",
"rustc_target",
"tracing",
]

View File

@ -770,6 +770,7 @@
desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() }
separate_provide_extern
cycle_delay_bug
}
/// Performs lint checking for the module.

View File

@ -20,6 +20,7 @@ rustc_query_system = { path = "../rustc_query_system" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
tracing = "0.1"
[features]

View File

@ -43,3 +43,23 @@ fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> Self {
}
}
}
impl<'tcx> Value<'tcx> for ty::Binder<'_, ty::FnSig<'_>> {
fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> Self {
let err = tcx.ty_error();
// FIXME(compiler-errors): It would be nice if we could get the
// query key, so we could at least generate a fn signature that
// has the right arity.
let fn_sig = ty::Binder::dummy(tcx.mk_fn_sig(
[].into_iter(),
err,
false,
rustc_hir::Unsafety::Normal,
rustc_target::spec::abi::Abi::Rust,
));
// SAFETY: This is never called when `Self` is not `ty::Binder<'tcx, ty::FnSig<'tcx>>`.
// FIXME: Represent the above fact in the trait system somehow.
unsafe { std::mem::transmute::<ty::PolyFnSig<'tcx>, ty::Binder<'_, ty::FnSig<'_>>>(fn_sig) }
}
}

View File

@ -0,0 +1,14 @@
use std::marker::PhantomData;
struct Token<T>(PhantomData<T>);
impl<T> Token<T> {
fn as_ref(_: i32, _: i32) -> _ {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| NOTE not allowed in type signatures
//~| HELP replace with the correct return type
Token(PhantomData::<&T>)
}
}
fn main() {}

View File

@ -0,0 +1,12 @@
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/return-cycle-2.rs:6:34
|
LL | fn as_ref(_: i32, _: i32) -> _ {
| ^
| |
| not allowed in type signatures
| help: replace with the correct return type: `Token<&'static T>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0121`.

View File

@ -0,0 +1,14 @@
use std::marker::PhantomData;
struct Token<T>(PhantomData<T>);
impl<T> Token<T> {
fn new() -> _ {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
//~| NOTE not allowed in type signatures
//~| HELP replace with the correct return type
Token(PhantomData::<()>)
}
}
fn main() {}

View File

@ -0,0 +1,12 @@
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> $DIR/return-cycle.rs:6:17
|
LL | fn new() -> _ {
| ^
| |
| not allowed in type signatures
| help: replace with the correct return type: `Token<()>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0121`.