Skip to content

Commit 1948288

Browse files
authored
Rollup merge of rust-lang#100389 - compiler-errors:return-type-suggestion-cycle, r=cjgillot
Do not report cycle error when inferring return type for suggestion The UI test is a good example of a case where this happens. The cycle is due to needing the value of the return type `-> _` to compute the variances of items in the crate, but then needing the variances of the items in the crate to do typechecking to infer what `-> _`'s real type is. Since we're already gonna emit an error in astconv, just delay the cycle bug as an error.
2 parents 989e4ff + 5309375 commit 1948288

File tree

8 files changed

+75
-0
lines changed

8 files changed

+75
-0
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4359,6 +4359,7 @@ dependencies = [
43594359
"rustc_serialize",
43604360
"rustc_session",
43614361
"rustc_span",
4362+
"rustc_target",
43624363
"tracing",
43634364
]
43644365

compiler/rustc_middle/src/query/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ rustc_queries! {
770770
desc { |tcx| "computing function signature of `{}`", tcx.def_path_str(key) }
771771
cache_on_disk_if { key.is_local() }
772772
separate_provide_extern
773+
cycle_delay_bug
773774
}
774775

775776
/// Performs lint checking for the module.

compiler/rustc_query_impl/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ rustc_query_system = { path = "../rustc_query_system" }
2020
rustc_serialize = { path = "../rustc_serialize" }
2121
rustc_session = { path = "../rustc_session" }
2222
rustc_span = { path = "../rustc_span" }
23+
rustc_target = { path = "../rustc_target" }
2324
tracing = "0.1"
2425

2526
[features]

compiler/rustc_query_impl/src/values.rs

+20
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,23 @@ impl<'tcx> Value<'tcx> for AdtSizedConstraint<'_> {
4343
}
4444
}
4545
}
46+
47+
impl<'tcx> Value<'tcx> for ty::Binder<'_, ty::FnSig<'_>> {
48+
fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> Self {
49+
let err = tcx.ty_error();
50+
// FIXME(compiler-errors): It would be nice if we could get the
51+
// query key, so we could at least generate a fn signature that
52+
// has the right arity.
53+
let fn_sig = ty::Binder::dummy(tcx.mk_fn_sig(
54+
[].into_iter(),
55+
err,
56+
false,
57+
rustc_hir::Unsafety::Normal,
58+
rustc_target::spec::abi::Abi::Rust,
59+
));
60+
61+
// SAFETY: This is never called when `Self` is not `ty::Binder<'tcx, ty::FnSig<'tcx>>`.
62+
// FIXME: Represent the above fact in the trait system somehow.
63+
unsafe { std::mem::transmute::<ty::PolyFnSig<'tcx>, ty::Binder<'_, ty::FnSig<'_>>>(fn_sig) }
64+
}
65+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::marker::PhantomData;
2+
3+
struct Token<T>(PhantomData<T>);
4+
5+
impl<T> Token<T> {
6+
fn as_ref(_: i32, _: i32) -> _ {
7+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
8+
//~| NOTE not allowed in type signatures
9+
//~| HELP replace with the correct return type
10+
Token(PhantomData::<&T>)
11+
}
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
2+
--> $DIR/return-cycle-2.rs:6:34
3+
|
4+
LL | fn as_ref(_: i32, _: i32) -> _ {
5+
| ^
6+
| |
7+
| not allowed in type signatures
8+
| help: replace with the correct return type: `Token<&'static T>`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0121`.
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::marker::PhantomData;
2+
3+
struct Token<T>(PhantomData<T>);
4+
5+
impl<T> Token<T> {
6+
fn new() -> _ {
7+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types
8+
//~| NOTE not allowed in type signatures
9+
//~| HELP replace with the correct return type
10+
Token(PhantomData::<()>)
11+
}
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
2+
--> $DIR/return-cycle.rs:6:17
3+
|
4+
LL | fn new() -> _ {
5+
| ^
6+
| |
7+
| not allowed in type signatures
8+
| help: replace with the correct return type: `Token<()>`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)