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

Hack to not crash when matching on a &mut Option<T> with a refinement #783

Merged
merged 1 commit into from
Sep 11, 2024
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
13 changes: 11 additions & 2 deletions crates/flux-middle/src/rty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub use expr::{
AggregateKind, AliasReft, BinOp, BoundReft, Constant, ESpan, EarlyReftParam, Expr, ExprKind,
FieldProj, HoleKind, KVar, KVid, Lambda, Loc, Name, Path, UnOp, Var,
};
use flux_common::bug;
use flux_common::{bug, tracked_span_bug};
use itertools::Itertools;
pub use normalize::SpecFuncDefns;
use rustc_data_structures::unord::UnordMap;
Expand Down Expand Up @@ -1321,7 +1321,7 @@ impl TyS {
if let TyKind::Indexed(BaseTy::Adt(adt_def, args), idx) = self.kind() {
(adt_def, args, idx)
} else {
bug!("expected adt")
tracked_span_bug!("expected adt `{self:?}`")
}
}

Expand Down Expand Up @@ -1559,6 +1559,15 @@ impl BaseTy {
| BaseTy::Never => Sort::unit(),
}
}

#[track_caller]
pub fn expect_adt(&self) -> (&AdtDef, &[GenericArg]) {
if let BaseTy::Adt(adt_def, args) = self {
(adt_def, args)
} else {
tracked_span_bug!("expected adt `{self:?}`")
}
}
}

impl<'tcx> ToRustc<'tcx> for BaseTy {
Expand Down
3 changes: 2 additions & 1 deletion crates/flux-refineck/src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,8 @@ impl<'ck, 'genv, 'tcx, M: Mode> Checker<'ck, 'genv, 'tcx, M> {
let ty = env
.lookup_place(&mut infcx.at(stmt_span), place)
.with_span(stmt_span)?;
let (adt_def, ..) = ty.expect_adt();
// HACK(nilehmann, mut-ref-unfolding) place should be unfolded here.
let (adt_def, ..) = ty.as_bty_skipping_existentials().unwrap().expect_adt();
Ok(Ty::discr(adt_def.clone(), place.clone()))
}
Rvalue::Aggregate(AggregateKind::Adt(def_id, variant_idx, args, _), operands) => {
Expand Down
Loading