Skip to content

Commit 802a00a

Browse files
authored
Don't ICE when normalizing associated refinements on dynamic objects (#1522)
1 parent 670ec37 commit 802a00a

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

crates/flux-infer/src/projections.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use flux_middle::{
1717
use flux_rustc_bridge::{ToRustc, lowering::Lower};
1818
use itertools::izip;
1919
use rustc_hir::def_id::DefId;
20-
use rustc_infer::traits::Obligation;
20+
use rustc_infer::traits::{BuiltinImplSource, Obligation};
2121
use rustc_middle::{
2222
traits::{ImplSource, ObligationCause},
2323
ty::{TyCtxt, Variance},
@@ -804,6 +804,7 @@ fn normalize_alias_reft<'tcx>(
804804
let trait_ref = alias_reft.to_rustc_trait_ref(tcx);
805805
let trait_ref = tcx.erase_and_anonymize_regions(trait_ref);
806806
let trait_pred = Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
807+
807808
let impl_source = selcx
808809
.select(&trait_pred)
809810
.map_err(|e| query_bug!("error selecting {trait_pred:?}: {e:?}"))?;
@@ -824,7 +825,7 @@ fn normalize_alias_reft<'tcx>(
824825
.apply(refine_args);
825826
Ok((true, e))
826827
}
827-
Some(ImplSource::Builtin(..)) => {
828+
Some(ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, _)) => {
828829
let e = genv
829830
.builtin_assoc_reft_body(infcx.typing_env(param_env), alias_reft)
830831
.apply(refine_args);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Test that we don't fail when normalizing an associated refinement on a dynamic object
2+
3+
#[flux::assoc(fn blueberry_assoc(x: int) -> bool)]
4+
pub trait MyTrait {
5+
#[flux::sig(fn(&Self, x: i32{Self::blueberry_assoc(x)}))]
6+
fn blueberry(&self, x: i32);
7+
}
8+
9+
fn foo(s: &dyn MyTrait) {
10+
s.blueberry(0); //~ ERROR refinement type error
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Test that we don't fail when normalizing an associated refinement on a dynamic object
2+
3+
#[flux::assoc(fn blueberry_assoc(x: int) -> bool)]
4+
pub trait MyTrait {
5+
#[flux::sig(fn(&Self) -> i32{v: Self::blueberry_assoc(v) })]
6+
fn blueberry(&self) -> i32;
7+
}
8+
9+
fn foo(s: &dyn MyTrait) {
10+
s.blueberry();
11+
}

0 commit comments

Comments
 (0)