attribute expansion: Fix spurious stripping of tail expression

This commit fixes the issue reported in #391, but highlights another
one, which will be reported.
This commit is contained in:
Arthur Cohen 2022-03-14 11:33:53 +01:00
parent 41f402f0b1
commit b6b567171c
3 changed files with 12 additions and 5 deletions

View File

@ -249,7 +249,8 @@ public:
BYTE_STRING, BYTE_STRING,
INT, INT,
FLOAT, FLOAT,
BOOL BOOL,
ERROR
}; };
private: private:
@ -274,11 +275,11 @@ public:
static Literal create_error () static Literal create_error ()
{ {
return Literal ("", CHAR, PrimitiveCoreType::CORETYPE_UNKNOWN); return Literal ("", ERROR, PrimitiveCoreType::CORETYPE_UNKNOWN);
} }
// Returns whether literal is in an invalid state. // Returns whether literal is in an invalid state.
bool is_error () const { return value_as_string == ""; } bool is_error () const { return type == ERROR; }
}; };
/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to /* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to

View File

@ -359,6 +359,10 @@ public:
case AST::Literal::LitType::BOOL: case AST::Literal::LitType::BOOL:
type = HIR::Literal::LitType::BOOL; type = HIR::Literal::LitType::BOOL;
break; break;
// Error literals should have been stripped during expansion
case AST::Literal::LitType::ERROR:
gcc_unreachable ();
break;
} }
auto crate_num = mappings->get_current_crate (); auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),

View File

@ -1,3 +1,5 @@
fn foo (e: &str) -> &str { // { dg-additional-options "-w" }
&"" // { dg-bogus "cannot strip expression in this position - outer attributes not allowed" "#391" { xfail *-*-* } }
fn foo(e: &str) -> &str { // { dg-bogus "expected" "#391" { xfail *-*-* } }
&"" // { dg-bogus "expected" "#391" { xfail *-*-* } }
} }