Skip to content
Open
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
20 changes: 14 additions & 6 deletions gcc/rust/expand/rust-cfg-strip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -828,9 +828,13 @@ CfgStrip::visit (AST::ArrayIndexExpr &expr)

const auto &array_expr = expr.get_array_expr ();
if (array_expr.is_marked_for_strip ())
rust_error_at (array_expr.get_locus (),
"cannot strip expression in this position - outer "
"attributes not allowed");
{
rust_error_at (array_expr.get_locus (),
"cannot strip expression in this position - outer "
"attributes not allowed");
expr.mark_for_strip ();
return;
}

const auto &index_expr = expr.get_index_expr ();
if (index_expr.is_marked_for_strip ())
Expand Down Expand Up @@ -1044,9 +1048,13 @@ CfgStrip::visit (AST::CallExpr &expr)

auto &function = expr.get_function_expr ();
if (function.is_marked_for_strip ())
rust_error_at (function.get_locus (),
"cannot strip expression in this position - outer "
"attributes not allowed");
{
rust_error_at (function.get_locus (),
"cannot strip expression in this position - outer "
"attributes not allowed");
expr.mark_for_strip ();
return;
}

/* spec says outer attributes are specifically allowed for elements
* of call expressions, so full stripping possible */
Expand Down
15 changes: 15 additions & 0 deletions gcc/testsuite/rust/compile/issue-4167.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![feature(no_core)]
#![no_core]
macro_rules! the_macro {
( $foo:stmt ; $bar:stmt ; ) => {
#[cfg(foo)]
$foo

$foo[cfg(bar)]
$bar
};
}

fn the_function() {
the_macro!( (); (); ); // { dg-error "cannot strip expression in this position" }
}
Loading