propagate errors about failing to rewrite a macro
This commit is contained in:
parent
6ada5b51cc
commit
6f318e3cef
10 changed files with 228 additions and 4 deletions
|
|
@ -522,6 +522,9 @@ pub fn rewrite_block_with_visitor(
|
||||||
let inner_attrs = attrs.map(inner_attributes);
|
let inner_attrs = attrs.map(inner_attributes);
|
||||||
let label_str = rewrite_label(label);
|
let label_str = rewrite_label(label);
|
||||||
visitor.visit_block(block, inner_attrs.as_ref().map(|a| &**a), has_braces);
|
visitor.visit_block(block, inner_attrs.as_ref().map(|a| &**a), has_braces);
|
||||||
|
if visitor.macro_rewrite_failure {
|
||||||
|
context.macro_rewrite_failure.replace(true);
|
||||||
|
}
|
||||||
Some(format!("{}{}{}", prefix, label_str, visitor.buffer))
|
Some(format!("{}{}{}", prefix, label_str, visitor.buffer))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -747,6 +747,10 @@ pub fn format_impl(
|
||||||
|
|
||||||
visitor.format_missing(item.span.hi() - BytePos(1));
|
visitor.format_missing(item.span.hi() - BytePos(1));
|
||||||
|
|
||||||
|
if visitor.macro_rewrite_failure {
|
||||||
|
context.macro_rewrite_failure.replace(true);
|
||||||
|
}
|
||||||
|
|
||||||
let inner_indent_str = visitor.block_indent.to_string_with_newline(context.config);
|
let inner_indent_str = visitor.block_indent.to_string_with_newline(context.config);
|
||||||
let outer_indent_str = offset.block_only().to_string_with_newline(context.config);
|
let outer_indent_str = offset.block_only().to_string_with_newline(context.config);
|
||||||
|
|
||||||
|
|
@ -1106,6 +1110,10 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
|
||||||
|
|
||||||
visitor.format_missing(item.span.hi() - BytePos(1));
|
visitor.format_missing(item.span.hi() - BytePos(1));
|
||||||
|
|
||||||
|
if visitor.macro_rewrite_failure {
|
||||||
|
context.macro_rewrite_failure.replace(true);
|
||||||
|
}
|
||||||
|
|
||||||
let inner_indent_str = visitor.block_indent.to_string_with_newline(context.config);
|
let inner_indent_str = visitor.block_indent.to_string_with_newline(context.config);
|
||||||
let outer_indent_str = offset.block_only().to_string_with_newline(context.config);
|
let outer_indent_str = offset.block_only().to_string_with_newline(context.config);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,9 @@ impl Rewrite for ast::Item {
|
||||||
visitor.block_indent = shape.indent;
|
visitor.block_indent = shape.indent;
|
||||||
visitor.last_pos = self.span().lo();
|
visitor.last_pos = self.span().lo();
|
||||||
visitor.visit_item(self);
|
visitor.visit_item(self);
|
||||||
|
if visitor.macro_rewrite_failure {
|
||||||
|
context.macro_rewrite_failure.replace(true);
|
||||||
|
}
|
||||||
Some(visitor.buffer)
|
Some(visitor.buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -406,7 +409,15 @@ pub fn rewrite_macro_def(
|
||||||
";",
|
";",
|
||||||
|branch| branch.span.lo(),
|
|branch| branch.span.lo(),
|
||||||
|branch| branch.span.hi(),
|
|branch| branch.span.hi(),
|
||||||
|branch| branch.rewrite(context, arm_shape, multi_branch_style),
|
|branch| match branch.rewrite(context, arm_shape, multi_branch_style) {
|
||||||
|
Some(v) => Some(v),
|
||||||
|
// if the rewrite returned None because a macro could not be rewritten, then return the
|
||||||
|
// original body
|
||||||
|
None if *context.macro_rewrite_failure.borrow() == true => {
|
||||||
|
Some(context.snippet(branch.body).trim().to_string())
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
},
|
||||||
context.snippet_provider.span_after(span, "{"),
|
context.snippet_provider.span_after(span, "{"),
|
||||||
span.hi(),
|
span.hi(),
|
||||||
false,
|
false,
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
||||||
if contains_skip(get_attrs_from_stmt(stmt)) {
|
if contains_skip(get_attrs_from_stmt(stmt)) {
|
||||||
self.push_skipped_with_span(stmt.span());
|
self.push_skipped_with_span(stmt.span());
|
||||||
} else {
|
} else {
|
||||||
let rewrite = stmt.rewrite(&self.get_context(), self.shape());
|
let shape = self.shape().clone();
|
||||||
|
let rewrite = self.with_context(|ctx| stmt.rewrite(&ctx, shape));
|
||||||
self.push_rewrite(stmt.span(), rewrite)
|
self.push_rewrite(stmt.span(), rewrite)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -350,11 +351,14 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
||||||
let where_span_end = snippet
|
let where_span_end = snippet
|
||||||
.find_uncommented("{")
|
.find_uncommented("{")
|
||||||
.map(|x| BytePos(x as u32) + source!(self, item.span).lo());
|
.map(|x| BytePos(x as u32) + source!(self, item.span).lo());
|
||||||
let rw = format_impl(&self.get_context(), item, self.block_indent, where_span_end);
|
let block_indent = self.block_indent.clone();
|
||||||
|
let rw =
|
||||||
|
self.with_context(|ctx| format_impl(&ctx, item, block_indent, where_span_end));
|
||||||
self.push_rewrite(item.span, rw);
|
self.push_rewrite(item.span, rw);
|
||||||
}
|
}
|
||||||
ast::ItemKind::Trait(..) => {
|
ast::ItemKind::Trait(..) => {
|
||||||
let rw = format_trait(&self.get_context(), item, self.block_indent);
|
let block_indent = self.block_indent.clone();
|
||||||
|
let rw = self.with_context(|ctx| format_trait(&ctx, item, block_indent));
|
||||||
self.push_rewrite(item.span, rw);
|
self.push_rewrite(item.span, rw);
|
||||||
}
|
}
|
||||||
ast::ItemKind::TraitAlias(ref generics, ref generic_bounds) => {
|
ast::ItemKind::TraitAlias(ref generics, ref generic_bounds) => {
|
||||||
|
|
|
||||||
44
tests/source/issue-2977/impl.rs
Normal file
44
tests/source/issue-2977/impl.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
macro_rules! atomic_bits {
|
||||||
|
// the println macro cannot be rewritten because of the asm macro
|
||||||
|
($type:ty, $ldrex:expr, $strex:expr) => {
|
||||||
|
impl AtomicBits for $type {
|
||||||
|
unsafe fn load_excl(address: usize) -> Self {
|
||||||
|
let raw: $type;
|
||||||
|
asm!($ldrex
|
||||||
|
: "=r"(raw)
|
||||||
|
: "r"(address)
|
||||||
|
:
|
||||||
|
: "volatile");
|
||||||
|
raw
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn store_excl(self, address: usize) -> bool {
|
||||||
|
let status: $type;
|
||||||
|
println!("{}",
|
||||||
|
status);
|
||||||
|
status == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// the println macro should be rewritten here
|
||||||
|
($type:ty) => {
|
||||||
|
fn some_func(self) {
|
||||||
|
let status: $type;
|
||||||
|
println!("{}", status);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// unrewritale macro in func
|
||||||
|
($type:ty, $ldrex:expr) => {
|
||||||
|
unsafe fn load_excl(address: usize) -> Self {
|
||||||
|
let raw: $type;
|
||||||
|
asm!($ldrex
|
||||||
|
: "=r"(raw)
|
||||||
|
: "r"(address)
|
||||||
|
:
|
||||||
|
: "volatile");
|
||||||
|
raw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
44
tests/source/issue-2977/trait.rs
Normal file
44
tests/source/issue-2977/trait.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
macro_rules! atomic_bits {
|
||||||
|
// the println macro cannot be rewritten because of the asm macro
|
||||||
|
($type:ty, $ldrex:expr, $strex:expr) => {
|
||||||
|
trait $type {
|
||||||
|
unsafe fn load_excl(address: usize) -> Self {
|
||||||
|
let raw: $type;
|
||||||
|
asm!($ldrex
|
||||||
|
: "=r"(raw)
|
||||||
|
: "r"(address)
|
||||||
|
:
|
||||||
|
: "volatile");
|
||||||
|
raw
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn store_excl(self, address: usize) -> bool {
|
||||||
|
let status: $type;
|
||||||
|
println!("{}",
|
||||||
|
status);
|
||||||
|
status == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// the println macro should be rewritten here
|
||||||
|
($type:ty) => {
|
||||||
|
fn some_func(self) {
|
||||||
|
let status: $type;
|
||||||
|
println!("{}", status);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// unrewritale macro in func
|
||||||
|
($type:ty, $ldrex:expr) => {
|
||||||
|
unsafe fn load_excl(address: usize) -> Self {
|
||||||
|
let raw: $type;
|
||||||
|
asm!($ldrex
|
||||||
|
: "=r"(raw)
|
||||||
|
: "r"(address)
|
||||||
|
:
|
||||||
|
: "volatile");
|
||||||
|
raw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
tests/target/issue-2977/block.rs
Normal file
11
tests/target/issue-2977/block.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
macro_rules! atomic_bits {
|
||||||
|
($ldrex:expr) => {
|
||||||
|
execute(|| {
|
||||||
|
asm!($ldrex
|
||||||
|
: "=r"(raw)
|
||||||
|
: "r"(address)
|
||||||
|
:
|
||||||
|
: "volatile");
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
44
tests/target/issue-2977/impl.rs
Normal file
44
tests/target/issue-2977/impl.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
macro_rules! atomic_bits {
|
||||||
|
// the println macro cannot be rewritten because of the asm macro
|
||||||
|
($type:ty, $ldrex:expr, $strex:expr) => {
|
||||||
|
impl AtomicBits for $type {
|
||||||
|
unsafe fn load_excl(address: usize) -> Self {
|
||||||
|
let raw: $type;
|
||||||
|
asm!($ldrex
|
||||||
|
: "=r"(raw)
|
||||||
|
: "r"(address)
|
||||||
|
:
|
||||||
|
: "volatile");
|
||||||
|
raw
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn store_excl(self, address: usize) -> bool {
|
||||||
|
let status: $type;
|
||||||
|
println!("{}",
|
||||||
|
status);
|
||||||
|
status == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// the println macro should be rewritten here
|
||||||
|
($type:ty) => {
|
||||||
|
fn some_func(self) {
|
||||||
|
let status: $type;
|
||||||
|
println!("{}", status);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// unrewritale macro in func
|
||||||
|
($type:ty, $ldrex:expr) => {
|
||||||
|
unsafe fn load_excl(address: usize) -> Self {
|
||||||
|
let raw: $type;
|
||||||
|
asm!($ldrex
|
||||||
|
: "=r"(raw)
|
||||||
|
: "r"(address)
|
||||||
|
:
|
||||||
|
: "volatile");
|
||||||
|
raw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
tests/target/issue-2977/item.rs
Normal file
11
tests/target/issue-2977/item.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
macro_rules! atomic_bits {
|
||||||
|
($ldrex:expr) => {
|
||||||
|
some_macro!(pub fn foo() {
|
||||||
|
asm!($ldrex
|
||||||
|
: "=r"(raw)
|
||||||
|
: "r"(address)
|
||||||
|
:
|
||||||
|
: "volatile");
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
44
tests/target/issue-2977/trait.rs
Normal file
44
tests/target/issue-2977/trait.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
macro_rules! atomic_bits {
|
||||||
|
// the println macro cannot be rewritten because of the asm macro
|
||||||
|
($type:ty, $ldrex:expr, $strex:expr) => {
|
||||||
|
trait $type {
|
||||||
|
unsafe fn load_excl(address: usize) -> Self {
|
||||||
|
let raw: $type;
|
||||||
|
asm!($ldrex
|
||||||
|
: "=r"(raw)
|
||||||
|
: "r"(address)
|
||||||
|
:
|
||||||
|
: "volatile");
|
||||||
|
raw
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn store_excl(self, address: usize) -> bool {
|
||||||
|
let status: $type;
|
||||||
|
println!("{}",
|
||||||
|
status);
|
||||||
|
status == 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// the println macro should be rewritten here
|
||||||
|
($type:ty) => {
|
||||||
|
fn some_func(self) {
|
||||||
|
let status: $type;
|
||||||
|
println!("{}", status);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// unrewritale macro in func
|
||||||
|
($type:ty, $ldrex:expr) => {
|
||||||
|
unsafe fn load_excl(address: usize) -> Self {
|
||||||
|
let raw: $type;
|
||||||
|
asm!($ldrex
|
||||||
|
: "=r"(raw)
|
||||||
|
: "r"(address)
|
||||||
|
:
|
||||||
|
: "volatile");
|
||||||
|
raw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue