Skip to content

Commit 26ff6db

Browse files
authored
Key rules on enum parameters (#560)
std::byte îs an enum
1 parent 99c13ad commit 26ff6db

7 files changed

Lines changed: 26 additions & 5 deletions

File tree

‎cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ std::string ClassOf(clang::QualType type) {
4949
return ClassOf(clang::QualType(qualifier.getAsType(), 0));
5050
}
5151
}
52+
if (auto tag = type->getAsTagDecl()) {
53+
return RulesLoader::ClassKey(tag);
54+
}
5255
return {};
5356
}
5457

‎rule-preprocessor/src/syntactic.rs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,10 @@ impl<'a> FnIrBuilder<'a> {
383383
for pred in wc.predicates() {
384384
let Some(ty) = pred.ty() else { continue };
385385
let name = ty.syntax().text().to_string();
386-
let bounds = extract_bounds(pred.type_bound_list());
387-
generics
388-
.entry(name)
389-
.and_modify(|existing| existing.extend(bounds.clone()))
390-
.or_insert(bounds);
386+
let Some(existing) = generics.get_mut(&name) else {
387+
continue;
388+
};
389+
existing.extend(extract_bounds(pred.type_bound_list()));
391390
}
392391
}
393392

‎rules/cstddef/src_cxx17.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ std::byte f2(const std::byte &a0, unsigned a1) { return a0 >> a1; }
1212
std::byte f3(std::byte &a0, unsigned a1) { return a0 <<= a1; }
1313

1414
std::byte f4(std::byte &a0, unsigned a1) { return a0 >>= a1; }
15+
16+
template <typename T1> std::byte f5(std::byte a0, T1 a1) { return a0 << a1; }

‎rules/cstddef/tgt_unsafe.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,10 @@ fn f4(a0: &mut u8, a1: u32) -> u8 {
4848
*a0 = n_;
4949
*a0
5050
}
51+
52+
fn f5<T1>(a0: u8, a1: T1) -> u8
53+
where
54+
u8: ::std::ops::Shl<T1, Output = u8>,
55+
{
56+
a0 << a1
57+
}

‎tests/unit/byte.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,9 @@ int main() {
1919
unsigned ushift4 = 3;
2020
b1 >>= ushift4;
2121
assert(b1 == std::byte(0x04));
22+
23+
int ishift = 1;
24+
std::byte shl2 = b1 << ishift;
25+
assert(shl2 == std::byte(0x08));
2226
return 0;
2327
}

‎tests/unit/out/refcount/byte.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ fn main_0() -> i32 {
3232
b1
3333
};
3434
assert!((b1 == ((4) as u8)));
35+
let mut ishift: i32 = 1;
36+
let mut shl2: u8 = b1 << ishift;
37+
assert!((shl2 == ((8) as u8)));
3538
return 0;
3639
}
3740
pub fn __cpp2rust_init_globals() {}

‎tests/unit/out/unsafe/byte.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ unsafe fn main_0() -> i32 {
3434
b1
3535
};
3636
assert!(((b1) == ((4) as u8)));
37+
let mut ishift: i32 = 1;
38+
let mut shl2: u8 = b1 << ishift;
39+
assert!(((shl2) == ((8) as u8)));
3740
return 0;
3841
}
3942
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)