Skip to content

Commit d2aced7

Browse files
committed
test
1 parent fe1a026 commit d2aced7

8 files changed

Lines changed: 330 additions & 39 deletions

File tree

.github/workflows/internal-testsuite.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123
export C2RUST_DIR=$PWD
124124
# Needs to be run from `tests/integration/` (or further inside)
125125
# to correctly load the `pyproject.toml`.
126-
(cd tests/integration && ./test.py curl json-c lua nginx zstd libxml2 python2 libmcs)
126+
(cd tests/integration && ./test.py nginx)
127127
128128
- uses: actions/upload-artifact@v4
129129
with:

c2rust-macros/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ impl VisitorImpls {
2626
let folder_ident = Ident::new(&folder_name, Span::call_site());
2727

2828
if !walk.stmts.is_empty() {
29-
let noop_fn_name = format!("noop_{}", method_name);
29+
let noop_fn_name = if method_name == "flat_map_trait_item" {
30+
String::from("noop_flat_map_assoc_item")
31+
} else {
32+
format!("noop_{}", method_name)
33+
};
3034
let noop_fn = Ident::new(&noop_fn_name, Span::call_site());
3135
self.tokens.extend(quote! {
3236
impl WalkAst for #ty {
@@ -84,7 +88,11 @@ impl VisitorImpls {
8488
let folder_ident = Ident::new(&folder_name, Span::call_site());
8589

8690
if !walk.stmts.is_empty() {
87-
let noop_fn_name = format!("noop_{}", method_name);
91+
let noop_fn_name = if method_name == "flat_map_trait_item" {
92+
String::from("noop_flat_map_assoc_item")
93+
} else {
94+
format!("noop_{}", method_name)
95+
};
8896
let noop_fn = Ident::new(&noop_fn_name, Span::call_site());
8997
self.tokens.extend(quote! {
9098
impl WalkAst for #ty {

c2rust-refactor/src/ast_manip/fold.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ pub trait MutVisitor: Sized {
130130
noop_flat_map_item(i, self)
131131
}
132132

133+
fn flat_map_trait_item(
134+
&mut self,
135+
i: P<AssocItem>,
136+
ctxt: AssocCtxt,
137+
) -> SmallVec<[P<AssocItem>; 1]> {
138+
noop_flat_map_assoc_item(i, self)
139+
}
140+
133141
fn visit_fn_header(&mut self, header: &mut FnHeader) {
134142
noop_visit_fn_header(header, self);
135143
}

c2rust-refactor/src/context.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::ops::Deref;
44

55
use rustc_ast::ptr::P;
66
use rustc_ast::{
7-
Expr, ExprKind, FnDecl, FnRetTy, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId, Path,
8-
QSelf, UseTreeKind, DUMMY_NODE_ID,
7+
AssocItem, Expr, ExprKind, FnDecl, FnRetTy, ForeignItem, ForeignItemKind, Item, ItemKind,
8+
NodeId, Path, QSelf, UseTreeKind, DUMMY_NODE_ID,
99
};
1010
use rustc_data_structures::fx::FxHashMap;
1111
use rustc_errors::{DiagnosticBuilder, Level};
@@ -1072,6 +1072,16 @@ impl<'a, 'tcx, 'b> TypeCompare<'a, 'tcx, 'b> {
10721072
pub fn compatible_types(&self, item1: &Item, item2: &Item, match_vis: bool) -> bool {
10731073
use rustc_ast::ItemKind::*;
10741074
match (&item1.kind, &item2.kind) {
1075+
(Impl(box ref impl1), Impl(box ref impl2)) => {
1076+
if impl1.items.len() != impl2.items.len() {
1077+
return false;
1078+
}
1079+
1080+
(impl1.items.iter())
1081+
.zip(impl2.items.iter())
1082+
.all(|(item1, item2)| self.compatible_assoc_items(item1, item2, match_vis))
1083+
}
1084+
10751085
// * Assure that these two items are in fact of the same type, just to be safe.
10761086
(TyAlias(box ref ta1), TyAlias(box ref ta2)) => {
10771087
match (
@@ -1226,6 +1236,40 @@ impl<'a, 'tcx, 'b> TypeCompare<'a, 'tcx, 'b> {
12261236
}
12271237
}
12281238

1239+
pub fn compatible_assoc_items(
1240+
&self,
1241+
item1: &AssocItem,
1242+
item2: &AssocItem,
1243+
match_vis: bool,
1244+
) -> bool {
1245+
use rustc_ast::AssocItemKind::*;
1246+
1247+
// Unlike for regular items, associated items must also match by name.
1248+
if item1.ident.as_str() != item2.ident.as_str() {
1249+
return false;
1250+
}
1251+
1252+
match (&item1.kind, &item2.kind) {
1253+
(Const(def1, ty1, expr1), Const(def2, ty2, expr2)) => match (
1254+
self.cx.opt_node_type(item1.id),
1255+
self.cx.opt_node_type(item2.id),
1256+
) {
1257+
(Some(ty1), Some(ty2)) => {
1258+
self.structural_eq_tys(ty1, ty2)
1259+
&& expr1.unnamed_equiv(expr2)
1260+
&& def1.unnamed_equiv(def2)
1261+
}
1262+
_ => {
1263+
self.structural_eq_ast_tys(ty1, ty2, match_vis)
1264+
&& expr1.unnamed_equiv(expr2)
1265+
&& def1.unnamed_equiv(def2)
1266+
}
1267+
},
1268+
1269+
_ => false,
1270+
}
1271+
}
1272+
12291273
/// Compare two function declarations for equivalent argument and return types,
12301274
/// ignoring argument names.
12311275
pub fn compatible_fn_prototypes(&self, decl1: &FnDecl, decl2: &FnDecl) -> bool {

0 commit comments

Comments
 (0)