From 71d1b3b8bc9df24b17c8c0699e4a5200706c1f7f Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 21 Oct 2026 14:25:42 +0100 Subject: [PATCH 1/6] Fall back to the tag in ClassOf --- cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp | 3 +++ rules/cstddef/src_cxx17.cpp | 2 ++ rules/cstddef/tgt_unsafe.rs | 7 +++++++ tests/unit/byte.cpp | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp b/cpp2rust/rule_preprocessing/cpp_rule_indexer.cpp index 346045ec57..3ccf982258 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/rules/cstddef/src_cxx17.cpp b/rules/cstddef/src_cxx17.cpp index 43a02e0e12..97d83a7ca4 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 573487aaaf..8b58d3acb3 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 14ca152ae0..b308b937e3 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; } From 6912a7b50e5fe33db81dea37062cf3d506ed2ddc Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 21 Oct 2026 19:55:17 +0100 Subject: [PATCH 2/6] Bound the std::byte shift amount without a where clause --- rules/cstddef/tgt_unsafe.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/rules/cstddef/tgt_unsafe.rs b/rules/cstddef/tgt_unsafe.rs index 8b58d3acb3..b191c9d1c4 100644 --- a/rules/cstddef/tgt_unsafe.rs +++ b/rules/cstddef/tgt_unsafe.rs @@ -49,9 +49,6 @@ fn f4(a0: &mut u8, a1: u32) -> u8 { *a0 } -fn f5(a0: u8, a1: T1) -> u8 -where - u8: ::std::ops::Shl, -{ - a0 << a1 +fn f5>(a0: u8, a1: T1) -> u8 { + a0 << a1.into() } From 8284ae29ea38d04628b626d06cdd3aae622b716d Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 21 Oct 2026 20:01:57 +0100 Subject: [PATCH 3/6] Name the conversion target of the std::byte shift amount --- rules/cstddef/tgt_unsafe.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/cstddef/tgt_unsafe.rs b/rules/cstddef/tgt_unsafe.rs index b191c9d1c4..7517255eb3 100644 --- a/rules/cstddef/tgt_unsafe.rs +++ b/rules/cstddef/tgt_unsafe.rs @@ -50,5 +50,5 @@ fn f4(a0: &mut u8, a1: u32) -> u8 { } fn f5>(a0: u8, a1: T1) -> u8 { - a0 << a1.into() + a0 << Into::::into(a1) } From 05e5f8332738467c9b18b39db820bdb7a4e96d2e Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 21 Oct 2026 20:07:18 +0100 Subject: [PATCH 4/6] Update tests --- tests/unit/out/refcount/byte.rs | 3 +++ tests/unit/out/unsafe/byte.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/unit/out/refcount/byte.rs b/tests/unit/out/refcount/byte.rs index 4b56680eed..8f5ac380f1 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 << Into::::into(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 eb4a392075..d4463ae6d7 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 << Into::::into(ishift); + assert!(((shl2) == ((8) as u8))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} From 2e87f6b6121bbe35baffd3122d89bb106beed5a2 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 21 Oct 2026 21:22:09 +0100 Subject: [PATCH 5/6] Convert a1 into u8 instead of i64 --- rules/cstddef/tgt_unsafe.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/cstddef/tgt_unsafe.rs b/rules/cstddef/tgt_unsafe.rs index 7517255eb3..49389cc3e5 100644 --- a/rules/cstddef/tgt_unsafe.rs +++ b/rules/cstddef/tgt_unsafe.rs @@ -49,6 +49,6 @@ fn f4(a0: &mut u8, a1: u32) -> u8 { *a0 } -fn f5>(a0: u8, a1: T1) -> u8 { - a0 << Into::::into(a1) +fn f5>(a0: u8, a1: T1) -> u8 { + a0 << Into::::into(a1) } From 465927dab41cdb4826ffc20f05b6c6f107c4ef23 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Wed, 21 Oct 2026 21:28:12 +0100 Subject: [PATCH 6/6] Accept non-generic arguments in where clause --- rule-preprocessor/src/syntactic.rs | 9 ++++----- rules/cstddef/tgt_unsafe.rs | 7 +++++-- tests/unit/out/refcount/byte.rs | 2 +- tests/unit/out/unsafe/byte.rs | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/rule-preprocessor/src/syntactic.rs b/rule-preprocessor/src/syntactic.rs index f56a31fd06..608322a310 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/tgt_unsafe.rs b/rules/cstddef/tgt_unsafe.rs index 49389cc3e5..8b58d3acb3 100644 --- a/rules/cstddef/tgt_unsafe.rs +++ b/rules/cstddef/tgt_unsafe.rs @@ -49,6 +49,9 @@ fn f4(a0: &mut u8, a1: u32) -> u8 { *a0 } -fn f5>(a0: u8, a1: T1) -> u8 { - a0 << Into::::into(a1) +fn f5(a0: u8, a1: T1) -> u8 +where + u8: ::std::ops::Shl, +{ + a0 << a1 } diff --git a/tests/unit/out/refcount/byte.rs b/tests/unit/out/refcount/byte.rs index 8f5ac380f1..d4ce70a8a9 100644 --- a/tests/unit/out/refcount/byte.rs +++ b/tests/unit/out/refcount/byte.rs @@ -33,7 +33,7 @@ fn main_0() -> i32 { }; assert!((b1 == ((4) as u8))); let mut ishift: i32 = 1; - let mut shl2: u8 = b1 << Into::::into(ishift); + let mut shl2: u8 = b1 << ishift; assert!((shl2 == ((8) as u8))); return 0; } diff --git a/tests/unit/out/unsafe/byte.rs b/tests/unit/out/unsafe/byte.rs index d4463ae6d7..dced97ec27 100644 --- a/tests/unit/out/unsafe/byte.rs +++ b/tests/unit/out/unsafe/byte.rs @@ -35,7 +35,7 @@ unsafe fn main_0() -> i32 { }; assert!(((b1) == ((4) as u8))); let mut ishift: i32 = 1; - let mut shl2: u8 = b1 << Into::::into(ishift); + let mut shl2: u8 = b1 << ishift; assert!(((shl2) == ((8) as u8))); return 0; }