Skip to content
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
6 changes: 6 additions & 0 deletions gcc/rust/ast/rust-ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4128,6 +4128,12 @@ AttrInputMetaItemContainer::separate_cfg_attrs () const

for (auto it = items.begin () + 1; it != items.end (); ++it)
{
if ((*it)->get_kind () == MetaItemInner::Kind::MetaItem
&& static_cast<MetaItem &> (**it).get_item_kind ()
== MetaItem::ItemKind::PathExpr
&& !static_cast<MetaItemPathExpr &> (**it).get_expr ().is_literal ())
continue;

Attribute attr = (*it)->to_attribute ();
if (attr.is_empty ())
{
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,7 @@ class TraitItem : public AssociatedItem
return std::unique_ptr<TraitItem> (clone_associated_item_impl ());
}

NodeId get_node_id () const { return node_id; }
NodeId get_node_id () const override { return node_id; }
location_t get_locus () const override { return locus; }
};

Expand Down
6 changes: 5 additions & 1 deletion gcc/rust/ast/rust-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ class MetaItemPathExpr : public MetaItem
// we have no idea use which of them, just simply return UNKNOWN_LOCATION
// now.
// Maybe we will figure out when we really need the location in the future.
location_t get_locus () const override { return UNKNOWN_LOCATION; }
location_t get_locus () const override
{
rust_unreachable ();
return UNKNOWN_LOCATION;
}

void accept_vis (ASTVisitor &vis) override;

Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/ast/rust-path.h
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ class TypePath : public TypeNoBounds
TraitBound *to_trait_bound (bool in_parens) const override;

location_t get_locus () const override final { return locus; }
NodeId get_node_id () const { return node_id; }
NodeId get_node_id () const override { return node_id; }

void mark_for_strip () override {}
bool is_marked_for_strip () const override { return false; }
Expand Down
35 changes: 25 additions & 10 deletions gcc/rust/util/rust-attributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,20 @@ check_proc_macro_non_root (AST::AttrVec attributes, location_t loc)
void
AttributeChecker::check_attribute (const AST::Attribute &attribute)
{
if (!attribute.empty_input ())
{
const auto &attr_input = attribute.get_attr_input ();
auto type = attr_input.get_attr_input_type ();
if (type == AST::AttrInput::AttrInputType::TOKEN_TREE)
{
const auto &option = static_cast<const AST::DelimTokenTree &> (
attribute.get_attr_input ());
std::unique_ptr<AST::AttrInputMetaItemContainer> meta_item (
option.parse_to_meta_item ());
AST::DefaultASTVisitor::visit (meta_item);
}
}

BuiltinAttrDefinition result;

// This checker does not check non-builtin attributes
Expand Down Expand Up @@ -353,10 +367,6 @@ void
AttributeChecker::visit (AST::DelimTokenTree &)
{}

void
AttributeChecker::visit (AST::AttrInputMetaItemContainer &)
{}

void
AttributeChecker::visit (AST::IdentifierExpr &)
{}
Expand Down Expand Up @@ -420,8 +430,16 @@ AttributeChecker::visit (AST::MetaItemLitExpr &)
{}

void
AttributeChecker::visit (AST::MetaItemPathExpr &)
{}
AttributeChecker::visit (AST::MetaItemPathExpr &attribute)
{
if (!attribute.get_expr ().is_literal ())
{
rust_error_at (attribute.get_expr ().get_locus (),
"malformed %<path%> attribute input");
rust_inform (attribute.get_expr ().get_locus (),
"must be of the form: %<#[path = \"file\"]%>");
}
}

void
AttributeChecker::visit (AST::BorrowExpr &)
Expand Down Expand Up @@ -647,6 +665,7 @@ AttributeChecker::visit (AST::TypeBoundWhereClauseItem &)
void
AttributeChecker::visit (AST::Module &module)
{
check_attributes (module.get_outer_attrs ());
check_proc_macro_non_function (module.get_outer_attrs ());
for (auto &item : module.get_items ())
{
Expand Down Expand Up @@ -861,10 +880,6 @@ void
AttributeChecker::visit (AST::MetaItemPath &)
{}

void
AttributeChecker::visit (AST::MetaItemSeq &)
{}

void
AttributeChecker::visit (AST::MetaWord &)
{}
Expand Down
2 changes: 0 additions & 2 deletions gcc/rust/util/rust-attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ class AttributeChecker : public AST::DefaultASTVisitor
void visit (AST::Crate &crate) override;
void visit (AST::Token &tok) override;
void visit (AST::DelimTokenTree &delim_tok_tree) override;
void visit (AST::AttrInputMetaItemContainer &input) override;
void visit (AST::IdentifierExpr &ident_expr) override;
void visit (AST::Lifetime &lifetime) override;
void visit (AST::LifetimeParam &lifetime_param) override;
Expand Down Expand Up @@ -220,7 +219,6 @@ class AttributeChecker : public AST::DefaultASTVisitor
void visit (AST::MacroRulesDefinition &rules_def) override;
void visit (AST::MacroInvocation &macro_invoc) override;
void visit (AST::MetaItemPath &meta_item) override;
void visit (AST::MetaItemSeq &meta_item) override;
void visit (AST::MetaWord &meta_item) override;
void visit (AST::MetaNameValueStr &meta_item) override;
void visit (AST::MetaListPaths &meta_item) override;
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/attr_malformed_path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#[cfg_attr(target_arch = "x86_64", path = (target_arch = "x86", path = "x86.rs"))]
mod imp {}
// { dg-error "malformed .path. attribute input" "" { target *-*-* } .-2 }
Loading