Skip to content

Commit df98a52

Browse files
danielsntedinski
authored andcommitted
Relax the requirements for is_rust_box() to enable crate compilation (rust-lang#153)
1 parent 000c451 commit df98a52

File tree

1 file changed

+10
-6
lines changed
  • compiler/rustc_codegen_llvm/src/gotoc

1 file changed

+10
-6
lines changed

compiler/rustc_codegen_llvm/src/gotoc/utils.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'tcx> GotocCtx<'tcx> {
8585
// };
8686
// ```
8787
// And notice that its `.pointer` field is exactly what we want.
88-
assert!(e.typ().is_rust_box());
88+
assert!(e.typ().is_rust_box(), "expected rust box {:?}", e);
8989
let unique_ptr_typ =
9090
self.symbol_table.lookup_field_type_in_type(e.typ(), "0").unwrap().clone();
9191
assert!(unique_ptr_typ.is_rust_unique_pointer());
@@ -96,7 +96,7 @@ impl<'tcx> GotocCtx<'tcx> {
9696
/// `boxed_type the_box = >>> { .0=nondet(), .1={ ._marker=nondet(), .pointer=boxed_value } } <<<`
9797
/// `boxed_type` is the type of the resulting expression
9898
pub fn box_value(&self, boxed_value: Expr, boxed_type: Type) -> Expr {
99-
assert!(boxed_type.is_rust_box());
99+
assert!(boxed_type.is_rust_box(), "expected rust box {:?}", boxed_type);
100100
let get_field_type = |struct_typ, field| {
101101
self.symbol_table.lookup_field_type_in_type(struct_typ, field).unwrap().clone()
102102
};
@@ -119,11 +119,15 @@ impl<'tcx> GotocCtx<'tcx> {
119119
}
120120

121121
impl Type {
122-
/// Checks if the struct represents a Rust "Box"
122+
/// Best effort check if the struct represents a Rust "Box". May return false positives.
123123
pub fn is_rust_box(&self) -> bool {
124-
self.type_name().map_or(false, |name| {
125-
name.starts_with("tag-std::boxed::Box") || name.starts_with("tag-core::boxed::Box")
126-
})
124+
// We have seen variants on the name, including
125+
// tag-std::boxed::Box, tag-core::boxed::Box, tag-boxed::Box.
126+
// If we match on exact names, we're playing whack-a-mole trying to keep track of how this
127+
// can be reimported.
128+
// If we don't, we spuriously fail. https://github.com/model-checking/rmc/issues/113
129+
// TODO: find a better way of checking this https://github.com/model-checking/rmc/issues/152
130+
self.type_name().map_or(false, |name| name.contains("boxed::Box"))
127131
}
128132

129133
/// Checks if the struct represents a Rust "Unique"

0 commit comments

Comments
 (0)