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

Delay a bug when encountering an impl with unconstrained generics in codegen_select #133368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 15 additions & 6 deletions compiler/rustc_traits/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,21 @@ pub(crate) fn codegen_select_candidate<'tcx>(
}

let impl_source = infcx.resolve_vars_if_possible(impl_source);
let impl_source = infcx.tcx.erase_regions(impl_source);
if impl_source.has_infer() {
// Unused lifetimes on an impl get replaced with inference vars, but never resolved,
// causing the return value of a query to contain inference vars. We do not have a concept
// for this and will in fact ICE in stable hashing of the return value. So bail out instead.
infcx.tcx.dcx().has_errors().unwrap();
let impl_source = tcx.erase_regions(impl_source);
if impl_source.has_non_region_infer() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a drive by to make it clear what it's looking for. no functional change.

// Unused generic types or consts on an impl get replaced with inference vars,
// but never resolved, causing the return value of a query to contain inference
// vars. We do not have a concept for this and will in fact ICE in stable hashing
// of the return value. So bail out instead.
match impl_source {
ImplSource::UserDefined(impl_) => {
tcx.dcx().span_delayed_bug(
tcx.def_span(impl_.impl_def_id),
"this impl has unconstrained generic parameters",
);
}
_ => unreachable!(),
}
return Err(CodegenObligationError::FulfillmentError);
}

Expand Down
18 changes: 0 additions & 18 deletions tests/crashes/126646.rs

This file was deleted.

20 changes: 20 additions & 0 deletions tests/ui/traits/resolve-impl-before-constrain-check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Need a different module so we try to build the mir for `test`
// before analyzing `mod foo`.

mod foo {
pub trait Callable {
fn call();
}

impl<V: ?Sized> Callable for () {
//~^ ERROR the type parameter `V` is not constrained by the impl trait, self type, or predicates
fn call() {}
}
}
use foo::*;

fn test() -> impl Sized {
<() as Callable>::call()
}

fn main() {}
9 changes: 9 additions & 0 deletions tests/ui/traits/resolve-impl-before-constrain-check.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0207]: the type parameter `V` is not constrained by the impl trait, self type, or predicates
--> $DIR/resolve-impl-before-constrain-check.rs:9:10
|
LL | impl<V: ?Sized> Callable for () {
| ^ unconstrained type parameter

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0207`.
Loading