Skip to content
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

attribute expansion: Fix spurious stripping of tail expression #1022

Merged
merged 1 commit into from
Mar 17, 2022
Merged
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
7 changes: 4 additions & 3 deletions gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ struct Literal
BYTE_STRING,
INT,
FLOAT,
BOOL
BOOL,
ERROR
};

private:
Expand All @@ -274,11 +275,11 @@ struct Literal

static Literal create_error ()
{
return Literal ("", CHAR, PrimitiveCoreType::CORETYPE_UNKNOWN);
return Literal ("", ERROR, PrimitiveCoreType::CORETYPE_UNKNOWN);
}

// 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
Expand Down
4 changes: 4 additions & 0 deletions gcc/rust/hir/rust-ast-lower-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ class ASTLoweringExpr : public ASTLoweringBase
case AST::Literal::LitType::BOOL:
type = HIR::Literal::LitType::BOOL;
break;
// Error literals should have been stripped during expansion
case AST::Literal::LitType::ERROR:
gcc_unreachable ();
break;
}
auto crate_num = mappings->get_current_crate ();
Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
Expand Down
6 changes: 4 additions & 2 deletions gcc/testsuite/rust/compile/xfail/slice1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
fn foo (e: &str) -> &str {
&"" // { dg-bogus "cannot strip expression in this position - outer attributes not allowed" "#391" { xfail *-*-* } }
// { dg-additional-options "-w" }

fn foo(e: &str) -> &str { // { dg-bogus "expected" "#391" { xfail *-*-* } }
&"" // { dg-bogus "expected" "#391" { xfail *-*-* } }
}