Skip to content

Conversation

ahomescu
Copy link
Contributor

Update the refactoring tool to build and run with the same Rust nightly as the transpiler.

Copy link
Contributor

@kkysen kkysen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I reviewed 100/127 files. I'll review the rest a bit later. Left a few comments, but it generally all looks fine to my cursory review so far.

@@ -135,7 +136,7 @@ impl<'c, 'lty, 'a: 'lty, 'tcx: 'a> IntraCtxt<'c, 'lty, 'a, 'tcx> {
};

let span = match &decl.local_info {
LocalInfo::User(ClearCrossCrate::Set(binding)) => Some(binding),
Some(box LocalInfo::User(ClearCrossCrate::Set(binding))) => Some(binding),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we're using the box keyword?

Comment on lines +81 to +83
let (defaultness, generics, sig, body) = expect!([i.kind]
ItemKind::Fn(box Fn { defaultness, generics, sig, body })
=> (defaultness, generics, sig, body));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's expect!?

Comment on lines 115 to +117
// Don't keep the old tokens. The callback could have made arbitrary changes to
// the signature and body of the function.
tokens: None,
tokens: i.tokens.clone(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment still up-to-date?

Comment on lines +39 to +44
if let ItemKind::Mod(_, ModKind::Loaded(ref mut items_ref, ..)) = i {
let items = mem::replace(items_ref, vec![]);
let mut curs = Cursor::from_vec(items);
(self.f)(&mut curs);
*items_ref = curs.into_vec();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to the indentation here?

Also, I think you could use mem::take instead of mem::replace here. Or not, cause the old code didn't do that.

Comment on lines +1 to +7
extern crate env_logger;
#[macro_use]
extern crate log;
#[macro_use]
extern crate clap;
extern crate c2rust_refactor;
extern crate shlex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need any of these in Rust anymore.

Comment on lines +522 to +525
let (path_qself, path_pattern) = match parse_path(&mut p) {
Some(p) => p,
None => return Err(Error::DefMismatch)
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let (path_qself, path_pattern) = match parse_path(&mut p) {
Some(p) => p,
None => return Err(Error::DefMismatch)
};
let (path_qself, path_pattern) = match parse_path(&mut p).ok_or(Error::DefMismatch)?;

Comment on lines 537 to +542
if self.try_match(&path_pattern, &def_path).is_err() {
return Err(Error::DefMismatch);
}
if self.try_match(&path_qself, &def_qself).is_err() {
return Err(Error::DefMismatch);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.try_match(&path_pattern, &def_path).is_err() {
return Err(Error::DefMismatch);
}
if self.try_match(&path_qself, &def_qself).is_err() {
return Err(Error::DefMismatch);
}
self.try_match(&path_pattern, &def_path).map_err(|_| Error::DefMismatch)?;
self.try_match(&path_qself, &def_qself).map_err(|_| Error::DefMismatch)?;

Comment on lines -49 to +51
!matches!([i.kind] ItemKind::Impl(_, _, _, _, None, _, _)) {
matches!(i.kind, ItemKind::Impl(box Impl { of_trait: None, .. })) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this is inverted?

Comment on lines +202 to +208
let (unsafety, polarity, generics, constness,
defaultness, of_trait, self_ty, mut items) = expect!([i.kind] ItemKind::Impl(box Impl {
unsafety, polarity, generics, constness,
defaultness, of_trait, self_ty, items
}) => (unsafety, polarity, generics, constness,
defaultness, of_trait, self_ty, items
));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to use let ... = i.kind else { panic!() } but I don't think that was in 1.65 yet.

let unused = result
.unused_unsafes
.as_deref()
.unwrap_or_else(|| &[])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does .unwrap_or_default() work?

@ahomescu ahomescu force-pushed the ahomescu/restore_refactor branch from 497f587 to a0477c2 Compare August 23, 2025 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants