Skip to content

Commit 865b44a

Browse files
committed
Auto merge of #69614 - estebank:ice-age, r=davidtwco
`delay_span_bug` when codegen cannot select obligation Fix #69602, introduced in #60126 by letting the compiler continue past type checking after encountering errors.
2 parents 4a1b69d + 7b6f5ed commit 865b44a

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
lines changed

src/librustc/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ rustc_queries! {
650650
Codegen {
651651
query codegen_fulfill_obligation(
652652
key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
653-
) -> Vtable<'tcx, ()> {
653+
) -> Option<Vtable<'tcx, ()>> {
654654
no_force
655655
cache_on_disk_if { true }
656656
desc { |tcx|

src/librustc_infer/traits/codegen/mod.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc::ty::{self, TyCtxt};
1919
pub fn codegen_fulfill_obligation<'tcx>(
2020
ty: TyCtxt<'tcx>,
2121
(param_env, trait_ref): (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>),
22-
) -> Vtable<'tcx, ()> {
22+
) -> Option<Vtable<'tcx, ()>> {
2323
// Remove any references to regions; this helps improve caching.
2424
let trait_ref = ty.erase_regions(&trait_ref);
2525

@@ -47,11 +47,15 @@ pub fn codegen_fulfill_obligation<'tcx>(
4747
// leading to an ambiguous result. So report this as an
4848
// overflow bug, since I believe this is the only case
4949
// where ambiguity can result.
50-
bug!(
51-
"Encountered ambiguity selecting `{:?}` during codegen, \
52-
presuming due to overflow",
53-
trait_ref
54-
)
50+
infcx.tcx.sess.delay_span_bug(
51+
rustc_span::DUMMY_SP,
52+
&format!(
53+
"encountered ambiguity selecting `{:?}` during codegen, presuming due to \
54+
overflow or prior type error",
55+
trait_ref
56+
),
57+
);
58+
return None;
5559
}
5660
Err(e) => {
5761
bug!("Encountered error `{:?}` selecting `{:?}` during codegen", e, trait_ref)
@@ -71,7 +75,7 @@ pub fn codegen_fulfill_obligation<'tcx>(
7175
let vtable = infcx.drain_fulfillment_cx_or_panic(&mut fulfill_cx, &vtable);
7276

7377
info!("Cache miss: {:?} => {:?}", trait_ref, vtable);
74-
vtable
78+
Some(vtable)
7579
})
7680
}
7781

src/librustc_mir/monomorphize/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn custom_coerce_unsize_info<'tcx>(
1818
});
1919

2020
match tcx.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref)) {
21-
traits::VtableImpl(traits::VtableImplData { impl_def_id, .. }) => {
21+
Some(traits::VtableImpl(traits::VtableImplData { impl_def_id, .. })) => {
2222
tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap()
2323
}
2424
vtable => {

src/librustc_ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn resolve_associated_item<'tcx>(
7070
);
7171

7272
let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs);
73-
let vtbl = tcx.codegen_fulfill_obligation((param_env, ty::Binder::bind(trait_ref)));
73+
let vtbl = tcx.codegen_fulfill_obligation((param_env, ty::Binder::bind(trait_ref)))?;
7474

7575
// Now that we know which impl is being used, we can dispatch to
7676
// the actual function:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
trait TraitA {
2+
const VALUE: usize;
3+
}
4+
5+
struct A;
6+
impl TraitA for A {
7+
const VALUE: usize = 0;
8+
}
9+
10+
trait TraitB {
11+
type MyA: TraitA;
12+
const VALUE: usize = Self::MyA::VALUE;
13+
}
14+
15+
struct B;
16+
impl TraitB for B { //~ ERROR not all trait items implemented, missing: `MyA`
17+
type M = A; //~ ERROR type `M` is not a member of trait `TraitB`
18+
}
19+
20+
fn main() {
21+
let _ = [0; B::VALUE];
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0437]: type `M` is not a member of trait `TraitB`
2+
--> $DIR/issue-69602-type-err-during-codegen-ice.rs:17:5
3+
|
4+
LL | type M = A;
5+
| ^^^^^^^^^^^^^ not a member of trait `TraitB`
6+
7+
error[E0046]: not all trait items implemented, missing: `MyA`
8+
--> $DIR/issue-69602-type-err-during-codegen-ice.rs:16:1
9+
|
10+
LL | type MyA: TraitA;
11+
| ----------------- `MyA` from trait
12+
...
13+
LL | impl TraitB for B {
14+
| ^^^^^^^^^^^^^^^^^ missing `MyA` in implementation
15+
16+
error: aborting due to 2 previous errors
17+
18+
Some errors have detailed explanations: E0046, E0437.
19+
For more information about an error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)