Skip to content

Commit a9d1c68

Browse files
committed
Merge branch 'master' into module_path
2 parents 725536d + 90ca1f6 commit a9d1c68

File tree

1,512 files changed

+4624
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,512 files changed

+4624
-29
lines changed

gcc/rust/ast/rust-ast-collector.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,11 @@ TokenCollector::visit (Trait &trait)
24492449
push (Rust::Token::make (TRAIT, trait.get_locus ()));
24502450
push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
24512451

2452-
visit (trait.get_generic_params ());
2452+
if (trait.has_generics ())
2453+
visit (trait.get_generic_params ());
2454+
if (!trait.get_type_param_bounds ().empty ())
2455+
push (Rust::Token::make ((COLON), trait.get_locus ()));
2456+
visit_items_joined_by_separator (trait.get_type_param_bounds (), PLUS);
24532457

24542458
visit_items_as_block (trait.get_trait_items (), {});
24552459
});

gcc/rust/ast/rust-ast.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ Crate::as_string () const
235235
return str + "\n";
236236
}
237237

238+
void
239+
Crate::inject_extern_crate (std::string name)
240+
{
241+
items.push_back (std::make_unique<AST::ExternCrate> (
242+
AST::ExternCrate (name, AST::Visibility::create_public (UNKNOWN_LOCATION),
243+
{}, UNKNOWN_LOCATION)));
244+
}
245+
238246
std::string
239247
Attribute::as_string () const
240248
{

gcc/rust/ast/rust-ast.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,6 +2116,8 @@ struct Crate : public GlobContainer
21162116
// TODO: is this the best way to do this?
21172117
}
21182118

2119+
void inject_extern_crate (std::string name);
2120+
21192121
NodeId get_node_id () const { return node_id; }
21202122
const std::vector<Attribute> &get_inner_attrs () const { return inner_attrs; }
21212123
std::vector<Attribute> &get_inner_attrs () { return inner_attrs; }

gcc/rust/expand/rust-macro-expand.cc

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ MacroExpander::expand_decl_macro (location_t invoc_locus,
112112

113113
if (matched_rule == nullptr)
114114
{
115-
rich_location r (line_table, invoc_locus);
116-
r.add_range (rules_def.get_locus ());
117-
rust_error_at (r, "Failed to match any rule within macro");
115+
if (!had_duplicate_error)
116+
{
117+
rich_location r (line_table, invoc_locus);
118+
r.add_range (rules_def.get_locus ());
119+
rust_error_at (r, "Failed to match any rule within macro");
120+
}
121+
had_duplicate_error = false;
118122
return AST::Fragment::create_error ();
119123
}
120124

@@ -535,6 +539,8 @@ MacroExpander::match_matcher (Parser<MacroInvocLexer> &parser,
535539

536540
const MacroInvocLexer &source = parser.get_token_source ();
537541

542+
std::unordered_map<std::string, location_t> duplicate_check;
543+
538544
for (auto &match : matcher.get_matches ())
539545
{
540546
size_t offs_begin = source.get_offs ();
@@ -548,6 +554,21 @@ MacroExpander::match_matcher (Parser<MacroInvocLexer> &parser,
548554
if (!match_fragment (parser, *fragment))
549555
return false;
550556

557+
auto duplicate_result = duplicate_check.insert (
558+
std::make_pair (fragment->get_ident ().as_string (),
559+
fragment->get_ident ().get_locus ()));
560+
561+
if (!duplicate_result.second)
562+
{
563+
// TODO: add range labels?
564+
rich_location r (line_table,
565+
fragment->get_ident ().get_locus ());
566+
r.add_range (duplicate_result.first->second);
567+
rust_error_at (r, "duplicate matcher binding");
568+
had_duplicate_error = true;
569+
return false;
570+
}
571+
551572
// matched fragment get the offset in the token stream
552573
size_t offs_end = source.get_offs ();
553574
sub_stack.insert_metavar (

gcc/rust/expand/rust-macro-expand.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ struct MacroExpander
300300
: cfg (cfg), crate (crate), session (session),
301301
sub_stack (SubstitutionScope ()),
302302
expanded_fragment (AST::Fragment::create_error ()),
303-
has_changed_flag (false), resolver (Resolver::Resolver::get ()),
303+
has_changed_flag (false), had_duplicate_error (false),
304+
resolver (Resolver::Resolver::get ()),
304305
mappings (Analysis::Mappings::get ())
305306
{}
306307

@@ -512,6 +513,9 @@ struct MacroExpander
512513
tl::optional<AST::MacroRulesDefinition &> last_def;
513514
tl::optional<AST::MacroInvocation &> last_invoc;
514515

516+
// used to avoid emitting excess errors
517+
bool had_duplicate_error;
518+
515519
public:
516520
Resolver::Resolver *resolver;
517521
Analysis::Mappings &mappings;

gcc/rust/resolve/rust-forever-stack.hxx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,20 +311,25 @@ ForeverStack<N>::get (Node &start, const Identifier &name)
311311

312312
auto candidate = current.rib.get (name.as_string ());
313313

314-
return candidate.map_or (
315-
[&resolved_definition] (Rib::Definition found) {
316-
if (found.is_variant ())
314+
if (candidate)
315+
{
316+
if (candidate->is_variant ())
317317
return KeepGoing::Yes;
318318
// for most namespaces, we do not need to care about various ribs -
319319
// they are available from all contexts if defined in the current
320320
// scope, or an outermore one. so if we do have a candidate, we can
321321
// return it directly and stop iterating
322-
resolved_definition = found;
322+
resolved_definition = *candidate;
323323

324324
return KeepGoing::No;
325-
},
326-
// if there was no candidate, we keep iterating
327-
KeepGoing::Yes);
325+
}
326+
else
327+
{
328+
if (current.rib.kind == Rib::Kind::Module)
329+
return KeepGoing::No;
330+
else
331+
return KeepGoing::Yes;
332+
}
328333
});
329334

330335
return resolved_definition;

gcc/rust/rust-session-manager.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ validate_crate_name (const std::string &crate_name, Error &error)
162162
return true;
163163
}
164164

165+
static bool
166+
has_attribute (AST::Crate crate, std::string attribute)
167+
{
168+
auto &crate_attrs = crate.get_inner_attrs ();
169+
auto has_attr = [&attribute] (AST::Attribute &attr) {
170+
return attr.as_string () == attribute;
171+
};
172+
return std::any_of (crate_attrs.begin (), crate_attrs.end (), has_attr);
173+
}
174+
165175
void
166176
Session::init ()
167177
{
@@ -658,6 +668,11 @@ Session::compile_crate (const char *filename)
658668

659669
Analysis::AttributeChecker ().go (parsed_crate);
660670

671+
if (!has_attribute (parsed_crate, std::string (Values::Attributes::NO_CORE)))
672+
{
673+
parsed_crate.inject_extern_crate ("core");
674+
}
675+
661676
if (last_step == CompileOptions::CompileStep::Expansion)
662677
return;
663678

gcc/rust/util/rust-attribute-values.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Attributes
3737
static constexpr auto &MUST_USE = "must_use";
3838
static constexpr auto &LANG = "lang";
3939
static constexpr auto &LINK_NAME = "link_name";
40+
static constexpr auto &NO_CORE = "no_core";
4041
static constexpr auto &LINK_SECTION = "link_section";
4142
static constexpr auto &NO_MANGLE = "no_mangle";
4243
static constexpr auto &EXPORT_NAME = "export_name";

gcc/testsuite/rust/borrowck/position_dependant_outlives.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck" }
2+
#![feature(no_core)]
3+
#![no_core]
4+
25

36
pub fn position_dependent_outlives<'a>(x: &'a mut i32, cond: bool) -> &'a mut i32 {
47
let y = &mut *x;

gcc/testsuite/rust/borrowck/reference.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
22
// { dg-enable-nn-line-numbers "" }
3+
#![feature(no_core)]
4+
#![no_core]
5+
36

47
#![feature(lang_items)]
58
#[lang = "sized"]

0 commit comments

Comments
 (0)