diff --git a/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp b/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp index 346045ec5..3ccf98225 100644 --- a/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp +++ b/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp @@ -49,6 +49,9 @@ std::string ClassOf(clang::QualType type) { return ClassOf(clang::QualType(qualifier.getAsType(), 0)); } } + if (auto tag = type->getAsTagDecl()) { + return RulesLoader::ClassKey(tag); + } return {}; } diff --git a/rule-preprocessor/src/syntactic.rs b/rule-preprocessor/src/syntactic.rs index f56a31fd0..608322a31 100644 --- a/rule-preprocessor/src/syntactic.rs +++ b/rule-preprocessor/src/syntactic.rs @@ -383,11 +383,10 @@ impl<'a> FnIrBuilder<'a> { for pred in wc.predicates() { let Some(ty) = pred.ty() else { continue }; let name = ty.syntax().text().to_string(); - let bounds = extract_bounds(pred.type_bound_list()); - generics - .entry(name) - .and_modify(|existing| existing.extend(bounds.clone())) - .or_insert(bounds); + let Some(existing) = generics.get_mut(&name) else { + continue; + }; + existing.extend(extract_bounds(pred.type_bound_list())); } } diff --git a/rules/cstddef/src_cxx17.cpp b/rules/cstddef/src_cxx17.cpp index 43a02e0e1..97d83a7ca 100644 --- a/rules/cstddef/src_cxx17.cpp +++ b/rules/cstddef/src_cxx17.cpp @@ -12,3 +12,5 @@ std::byte f2(const std::byte &a0, unsigned a1) { return a0 >> a1; } std::byte f3(std::byte &a0, unsigned a1) { return a0 <<= a1; } std::byte f4(std::byte &a0, unsigned a1) { return a0 >>= a1; } + +template std::byte f5(std::byte a0, T1 a1) { return a0 << a1; } diff --git a/rules/cstddef/tgt_unsafe.rs b/rules/cstddef/tgt_unsafe.rs index 573487aaa..8b58d3acb 100644 --- a/rules/cstddef/tgt_unsafe.rs +++ b/rules/cstddef/tgt_unsafe.rs @@ -48,3 +48,10 @@ fn f4(a0: &mut u8, a1: u32) -> u8 { *a0 = n_; *a0 } + +fn f5(a0: u8, a1: T1) -> u8 +where + u8: ::std::ops::Shl, +{ + a0 << a1 +} diff --git a/tests/unit/byte.cpp b/tests/unit/byte.cpp index 14ca152ae..b308b937e 100644 --- a/tests/unit/byte.cpp +++ b/tests/unit/byte.cpp @@ -19,5 +19,9 @@ int main() { unsigned ushift4 = 3; b1 >>= ushift4; assert(b1 == std::byte(0x04)); + + int ishift = 1; + std::byte shl2 = b1 << ishift; + assert(shl2 == std::byte(0x08)); return 0; } diff --git a/tests/unit/out/refcount/byte.rs b/tests/unit/out/refcount/byte.rs index 4b56680ee..d4ce70a8a 100644 --- a/tests/unit/out/refcount/byte.rs +++ b/tests/unit/out/refcount/byte.rs @@ -32,6 +32,9 @@ fn main_0() -> i32 { b1 }; assert!((b1 == ((4) as u8))); + let mut ishift: i32 = 1; + let mut shl2: u8 = b1 << ishift; + assert!((shl2 == ((8) as u8))); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/byte.rs b/tests/unit/out/unsafe/byte.rs index eb4a39207..dced97ec2 100644 --- a/tests/unit/out/unsafe/byte.rs +++ b/tests/unit/out/unsafe/byte.rs @@ -34,6 +34,9 @@ unsafe fn main_0() -> i32 { b1 }; assert!(((b1) == ((4) as u8))); + let mut ishift: i32 = 1; + let mut shl2: u8 = b1 << ishift; + assert!(((shl2) == ((8) as u8))); return 0; } pub unsafe fn __cpp2rust_init_globals() {}