Skip to content

Commit bc71824

Browse files
authored
Unrolled build for rust-lang#133368
Rollup merge of rust-lang#133368 - compiler-errors:codegen-select-unconstrained-params, r=lcnr Delay a bug when encountering an impl with unconstrained generics in `codegen_select` Despite its name, `codegen_select` is what powers `Instance::try_resolve`, which is used in pre-codegen contexts to try to resolve a method where possible. One place that it's used is in the "recursion MIR lint" that detects recursive MIR bodies. If we encounter an impl in `codegen_select` that contains unconstrained generic parameters, we expect that impl to caused an error to be reported; however, there's no temporal guarantee that this error is reported *before* we call `codegen_select`. This is what a delayed bug is *for*, and this PR makes us use a delayed bug rather than asserting something about errors already having been emitted. Fixes rust-lang#126646
2 parents eddb717 + 50fb40a commit bc71824

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

compiler/rustc_traits/src/codegen.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,21 @@ pub(crate) fn codegen_select_candidate<'tcx>(
7474
}
7575

7676
let impl_source = infcx.resolve_vars_if_possible(impl_source);
77-
let impl_source = infcx.tcx.erase_regions(impl_source);
78-
if impl_source.has_infer() {
79-
// Unused lifetimes on an impl get replaced with inference vars, but never resolved,
80-
// causing the return value of a query to contain inference vars. We do not have a concept
81-
// for this and will in fact ICE in stable hashing of the return value. So bail out instead.
82-
infcx.tcx.dcx().has_errors().unwrap();
77+
let impl_source = tcx.erase_regions(impl_source);
78+
if impl_source.has_non_region_infer() {
79+
// Unused generic types or consts on an impl get replaced with inference vars,
80+
// but never resolved, causing the return value of a query to contain inference
81+
// vars. We do not have a concept for this and will in fact ICE in stable hashing
82+
// of the return value. So bail out instead.
83+
match impl_source {
84+
ImplSource::UserDefined(impl_) => {
85+
tcx.dcx().span_delayed_bug(
86+
tcx.def_span(impl_.impl_def_id),
87+
"this impl has unconstrained generic parameters",
88+
);
89+
}
90+
_ => unreachable!(),
91+
}
8392
return Err(CodegenObligationError::FulfillmentError);
8493
}
8594

tests/crashes/126646.rs

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Need a different module so we try to build the mir for `test`
2+
// before analyzing `mod foo`.
3+
4+
mod foo {
5+
pub trait Callable {
6+
fn call();
7+
}
8+
9+
impl<V: ?Sized> Callable for () {
10+
//~^ ERROR the type parameter `V` is not constrained by the impl trait, self type, or predicates
11+
fn call() {}
12+
}
13+
}
14+
use foo::*;
15+
16+
fn test() -> impl Sized {
17+
<() as Callable>::call()
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0207]: the type parameter `V` is not constrained by the impl trait, self type, or predicates
2+
--> $DIR/resolve-impl-before-constrain-check.rs:9:10
3+
|
4+
LL | impl<V: ?Sized> Callable for () {
5+
| ^ unconstrained type parameter
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0207`.

0 commit comments

Comments
 (0)