Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not report cycle error when inferring return type for suggestion #100389

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4359,6 +4359,7 @@ dependencies = [
"rustc_serialize",
"rustc_session",
"rustc_span",
"rustc_target",
"tracing",
]

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ rustc_queries! {
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.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_query_impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_query_impl/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,23 @@ impl<'tcx> Value<'tcx> for AdtSizedConstraint<'_> {
}
}
}

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) }
}
}
14 changes: 14 additions & 0 deletions src/test/ui/suggestions/return-cycle-2.rs
Original file line number Diff line number Diff line change
@@ -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() {}
12 changes: 12 additions & 0 deletions src/test/ui/suggestions/return-cycle-2.stderr
Original file line number Diff line number Diff line change
@@ -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`.
14 changes: 14 additions & 0 deletions src/test/ui/suggestions/return-cycle.rs
Original file line number Diff line number Diff line change
@@ -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() {}
12 changes: 12 additions & 0 deletions src/test/ui/suggestions/return-cycle.stderr
Original file line number Diff line number Diff line change
@@ -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`.