Skip to content

Commit b6b5671

Browse files
committed
attribute expansion: Fix spurious stripping of tail expression
This commit fixes the issue reported in #391, but highlights another one, which will be reported.
1 parent 41f402f commit b6b5671

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

gcc/rust/ast/rust-ast.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ struct Literal
249249
BYTE_STRING,
250250
INT,
251251
FLOAT,
252-
BOOL
252+
BOOL,
253+
ERROR
253254
};
254255

255256
private:
@@ -274,11 +275,11 @@ struct Literal
274275

275276
static Literal create_error ()
276277
{
277-
return Literal ("", CHAR, PrimitiveCoreType::CORETYPE_UNKNOWN);
278+
return Literal ("", ERROR, PrimitiveCoreType::CORETYPE_UNKNOWN);
278279
}
279280

280281
// Returns whether literal is in an invalid state.
281-
bool is_error () const { return value_as_string == ""; }
282+
bool is_error () const { return type == ERROR; }
282283
};
283284

284285
/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to

gcc/rust/hir/rust-ast-lower-expr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ class ASTLoweringExpr : public ASTLoweringBase
359359
case AST::Literal::LitType::BOOL:
360360
type = HIR::Literal::LitType::BOOL;
361361
break;
362+
// Error literals should have been stripped during expansion
363+
case AST::Literal::LitType::ERROR:
364+
gcc_unreachable ();
365+
break;
362366
}
363367
auto crate_num = mappings->get_current_crate ();
364368
Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
fn foo (e: &str) -> &str {
2-
&"" // { dg-bogus "cannot strip expression in this position - outer attributes not allowed" "#391" { xfail *-*-* } }
1+
// { dg-additional-options "-w" }
2+
3+
fn foo(e: &str) -> &str { // { dg-bogus "expected" "#391" { xfail *-*-* } }
4+
&"" // { dg-bogus "expected" "#391" { xfail *-*-* } }
35
}

0 commit comments

Comments
 (0)