Skip to content

Update to support 2022-07-11 rustc_middle #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions c2rust-ast-builder/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ impl Make<Ident> for &str {

impl Make<Ident> for String {
fn make(self, mk: &Builder) -> Ident {
Ident::new(&*self, mk.span)
Ident::new(&self, mk.span)
}
}

impl Make<Ident> for &String {
fn make(self, mk: &Builder) -> Ident {
Ident::new(&*self, mk.span)
Ident::new(self, mk.span)
}
}

Expand All @@ -209,7 +209,7 @@ impl<'a> Make<Path> for &'a str {

impl<'a> Make<Visibility> for &'a str {
fn make(self, mk_: &Builder) -> Visibility {
let kind = match self {
match self {
"pub" => Visibility::Public(VisPublic {
pub_token: token::Pub(mk_.span),
}),
Expand All @@ -230,8 +230,7 @@ impl<'a> Make<Visibility> for &'a str {
path: Box::new(mk().path("super")),
}),
_ => panic!("unrecognized string for Visibility: {:?}", self),
};
kind
}
}
}

Expand All @@ -251,7 +250,7 @@ impl<'a> Make<Extern> for &'a str {
}
}

impl<'a> Make<Extern> for Abi {
impl Make<Extern> for Abi {
fn make(self, _mk: &Builder) -> Extern {
Extern::Explicit(self.name.to_token_stream().to_string())
}
Expand Down Expand Up @@ -379,13 +378,13 @@ impl Make<NestedMeta> for Lit {

impl Make<Lit> for String {
fn make(self, mk: &Builder) -> Lit {
Lit::Str(LitStr::new(&*self, mk.span))
Lit::Str(LitStr::new(&self, mk.span))
}
}

impl Make<Lit> for &String {
fn make(self, mk: &Builder) -> Lit {
Lit::Str(LitStr::new(&*self, mk.span))
Lit::Str(LitStr::new(self, mk.span))
}
}

Expand Down Expand Up @@ -884,7 +883,7 @@ impl Builder {
let rhs = rhs.make(&self);

match op {
BinOp::Lt(_) | BinOp::Shl(_) if has_rightmost_cast(&*lhs) => lhs = mk().paren_expr(lhs),
BinOp::Lt(_) | BinOp::Shl(_) if has_rightmost_cast(&lhs) => lhs = mk().paren_expr(lhs),
_ => {}
}

Expand Down Expand Up @@ -2596,13 +2595,13 @@ fn has_rightmost_cast(expr: &Expr) -> bool {
attrs: _,
op: _,
ref expr,
}) => has_rightmost_cast(&**expr),
}) => has_rightmost_cast(expr),
Expr::Binary(ExprBinary {
attrs: _,
left: _,
op: _,
ref right,
}) => has_rightmost_cast(&**right),
}) => has_rightmost_cast(right),
_ => false,
}
}
Expand Down
13 changes: 5 additions & 8 deletions c2rust-transpile/src/c_ast/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,18 +1011,15 @@ impl ConversionContext {

let label_name = from_value::<Rc<str>>(node.extras[0].clone())
.expect("unnamed label in C source code");
match self
if let Some(old_label_name) = self
.typed_context
.label_names
.insert(CStmtId(new_id), label_name.clone())
{
Some(old_label_name) => {
panic!(
"Duplicate label name with id {}. Old name: {}. New name: {}",
new_id, old_label_name, label_name,
);
}
None => {}
panic!(
"Duplicate label name with id {}. Old name: {}. New name: {}",
new_id, old_label_name, label_name,
);
}

let label_stmt = CStmtKind::Label(substmt);
Expand Down
10 changes: 5 additions & 5 deletions c2rust-transpile/src/c_ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ impl CExprKind {
}
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CastKind {
BitCast,
LValueToRValue,
Expand Down Expand Up @@ -1296,7 +1296,7 @@ impl UnOp {
}

/// Represents a binary operator in C (6.5.5 Multiplicative operators - 6.5.14 Logical OR operator)
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BinOp {
Multiply, // *
Divide, // /
Expand Down Expand Up @@ -1521,7 +1521,7 @@ pub struct AsmOperand {
}

/// Type qualifiers (6.7.3)
#[derive(Debug, Copy, Clone, Default, PartialEq)]
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
pub struct Qualifiers {
/// The `const` qualifier, which marks lvalues as non-assignable.
///
Expand Down Expand Up @@ -1557,7 +1557,7 @@ impl Qualifiers {
}

/// Qualified type
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct CQualTypeId {
pub qualifiers: Qualifiers,
pub ctype: CTypeId,
Expand All @@ -1580,7 +1580,7 @@ impl CQualTypeId {
/// Represents a type in C (6.2.5 Types)
///
/// Reflects the types in <http://clang.llvm.org/doxygen/classclang_1_1Type.html>
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CTypeKind {
Void,

Expand Down
9 changes: 3 additions & 6 deletions c2rust-transpile/src/c_ast/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,9 @@ impl<W: Write> Printer<W> {
self.writer.write_all(b"__thread ")?;
}
self.print_qtype(typ, Some(ident.as_str()), context)?;
match initializer {
Some(init) => {
self.writer.write_all(b" = ")?;
self.print_expr(init, context)?;
}
None => {}
if let Some(init) = initializer {
self.writer.write_all(b" = ")?;
self.print_expr(init, context)?;
}
self.writer.write_all(b";")?;
if newline {
Expand Down
2 changes: 1 addition & 1 deletion c2rust-transpile/src/rust_ast/comment_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ pub fn insert_comment_attrs(attrs: &mut Vec<Attribute>, new_comments: SmallVec<[
}

for c in new_comments {
let lit = Lit::new(proc_macro2::Literal::string(&*c));
let lit = Lit::new(proc_macro2::Literal::string(c));
let mut tokens = TokenStream::new();
eq.to_tokens(&mut tokens);
lit.to_tokens(&mut tokens);
Expand Down
12 changes: 6 additions & 6 deletions c2rust-transpile/src/translator/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fn parse_constraints(
if !(is_explicit_reg || is_tied) {
// Attempt to parse machine-specific constraints
if let Some((machine_constraints, is_mem)) =
translate_machine_constraint(&*constraints, arch)
translate_machine_constraint(&constraints, arch)
{
constraints = machine_constraints.into();
mem_only = is_mem;
Expand Down Expand Up @@ -368,7 +368,7 @@ fn rewrite_reserved_reg_operands(
for (i, operand) in operands.iter().enumerate() {
if operand.is_positional() {
total_positional += 1;
} else if let Some((reg, mods)) = reg_is_reserved(&*operand.constraints, arch) {
} else if let Some((reg, mods)) = reg_is_reserved(&operand.constraints, arch) {
rewrite_idxs.push((i, reg.to_owned(), mods.to_owned()));
}
}
Expand Down Expand Up @@ -615,7 +615,7 @@ fn rewrite_asm<F: Fn(&str) -> bool, M: Fn(usize) -> usize>(
out.push_str(input_op_mapper(idx).to_string().as_str());
if !new_modifiers.is_empty() {
out.push(':');
out.push_str(&*new_modifiers);
out.push_str(&new_modifiers);
}
out.push_str(if mem_only { "}]" } else { "}" });
// Push the rest of the chunk
Expand Down Expand Up @@ -739,7 +739,7 @@ impl<'c> Translation<'c> {
for (i, input) in inputs.iter().enumerate() {
let (_dir_spec, _mem_only, parsed) = parse_constraints(&input.constraints, arch)?;
// Only pair operands with an explicit register or index
if is_regname_or_int(&*parsed) {
if is_regname_or_int(&parsed) {
inputs_by_register.insert(parsed, (i, input.clone()));
} else {
other_inputs.push((parsed, (i, input.clone())));
Expand Down Expand Up @@ -807,7 +807,7 @@ impl<'c> Translation<'c> {

// Determine whether the assembly is in AT&T syntax
let att_syntax = match arch {
Arch::X86OrX86_64 => asm_is_att_syntax(&*rewritten_asm),
Arch::X86OrX86_64 => asm_is_att_syntax(&rewritten_asm),
_ => false,
};

Expand Down Expand Up @@ -926,7 +926,7 @@ impl<'c> Translation<'c> {

// Emit dir_spec(constraint), quoting constraint if needed
push_expr(&mut tokens, mk().ident_expr(operand.dir_spec.to_string()));
let constraints_ident = if is_regname_or_int(&*operand.constraints) {
let constraints_ident = if is_regname_or_int(&operand.constraints) {
mk().lit_expr(operand.constraints.trim_matches('"'))
} else {
mk().ident_expr(operand.constraints)
Expand Down
2 changes: 1 addition & 1 deletion c2rust-transpile/src/translator/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<'c> Translation<'c> {
let mut visitor = CommentLocator {
ast_context: &self.ast_context,
comment_context: &self.comment_context,
comment_store: &mut *self.comment_store.borrow_mut(),
comment_store: &mut self.comment_store.borrow_mut(),
spans: &mut spans,
top_decls: &top_decls,
last_id: None,
Expand Down
8 changes: 5 additions & 3 deletions c2rust-transpile/src/translator/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ impl<'c> Translation<'c> {
if (val as i32) < 0 {
mk().unary_expr(
"-",
mk().lit_expr(mk().int_lit((val as i32).abs() as u128, "i32")),
mk().lit_expr(
mk().int_lit((val as i32).unsigned_abs() as u128, "i32"),
),
)
} else {
mk().lit_expr(mk().int_lit(val as u128, "i32"))
Expand All @@ -121,8 +123,8 @@ impl<'c> Translation<'c> {

mk().call_expr(fn_path, args)
}
CTypeKind::Double => mk().lit_expr(mk().float_lit(&*str, "f64")),
CTypeKind::Float => mk().lit_expr(mk().float_lit(&*str, "f32")),
CTypeKind::Double => mk().lit_expr(mk().float_lit(&str, "f64")),
CTypeKind::Float => mk().lit_expr(mk().float_lit(&str, "f32")),
ref k => panic!("Unsupported floating point literal type {:?}", k),
};
Ok(WithStmts::new_val(val))
Expand Down
2 changes: 1 addition & 1 deletion c2rust-transpile/src/translator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use crate::PragmaVec;
pub const INNER_SUFFIX: &str = "_Inner";
pub const PADDING_SUFFIX: &str = "_PADDING";

#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum DecayRef {
Yes,
Default,
Expand Down
1 change: 1 addition & 0 deletions dynamic_instrumentation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cargo-util = "0.1"
indexmap = "1.8"
lazy_static = "1.4"
log = "0.4"
semver = "1.0.12" # needed b/c cargo 0.62 > semver 1.0.10 fails `cargo doc`

[build-dependencies]
rustc-private-link = { path = "../rustc-private-link" }
Expand Down
Loading