Skip to content

Commit 7c0387e

Browse files
committed
Do not rewind parser and ignore following blocks
When encountering `pub ident`, attempt to identify the code that comes afterwards, wether it is a brace block (assume it is a struct), a paren list followed by a colon (assume struct) or a paren list followed by a block (assume a fn). Consume those blocks to avoid any further parser errors and return a `Placeholder` item in order to allow the parser to continue. In the case of unenclosed blocks, the behavior is the same as it is currently: no further errors are processed.
1 parent 547873a commit 7c0387e

File tree

14 files changed

+380
-55
lines changed

14 files changed

+380
-55
lines changed

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,9 @@ impl<'a> LoweringContext<'a> {
17571757
bounds,
17581758
items)
17591759
}
1760-
ItemKind::MacroDef(..) | ItemKind::Mac(..) => panic!("Shouldn't still be around"),
1760+
ItemKind::Placeholder | ItemKind::MacroDef(..) | ItemKind::Mac(..) => {
1761+
panic!("Shouldn't still be around")
1762+
}
17611763
}
17621764

17631765
// [1] `defaultness.has_value()` is never called for an `impl`, always `true` in order to

src/librustc/hir/map/def_collector.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
113113
return visit::walk_item(self, i);
114114
}
115115
ItemKind::Mod(..) => DefPathData::Module(i.ident.name.as_str()),
116+
ItemKind::Placeholder |
116117
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) =>
117118
DefPathData::ValueNs(i.ident.name.as_str()),
118119
ItemKind::MacroDef(..) => DefPathData::MacroDef(i.ident.name.as_str()),

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl<'a> Resolver<'a> {
269269
self.define(parent, ident, TypeNS, imported_binding);
270270
}
271271

272-
ItemKind::GlobalAsm(..) => {}
272+
ItemKind::GlobalAsm(..) | ItemKind::Placeholder => {}
273273

274274
ItemKind::Mod(..) if item.ident == keywords::Invalid.ident() => {} // Crate root
275275

src/librustc_resolve/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,8 @@ impl<'a> Resolver<'a> {
19471947
}
19481948
}
19491949

1950-
ItemKind::ExternCrate(_) | ItemKind::MacroDef(..) | ItemKind::GlobalAsm(_)=> {
1950+
ItemKind::ExternCrate(_) | ItemKind::MacroDef(..) | ItemKind::GlobalAsm(_) |
1951+
ItemKind::Placeholder => {
19511952
// do nothing, these are just around to be encoded
19521953
}
19531954

src/librustc_save_analysis/sig.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ impl Sig for ast::Item {
548548
// FIXME should implement this (e.g., pub use).
549549
ast::ItemKind::Use(_) => Err("import"),
550550
ast::ItemKind::Mac(..) | ast::ItemKind::MacroDef(_) => Err("Macro"),
551+
ast::ItemKind::Placeholder => Err("placeholder"),
551552
}
552553
}
553554
}

src/libsyntax/ast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,7 @@ pub enum ItemKind {
19771977

19781978
/// A macro definition.
19791979
MacroDef(MacroDef),
1980+
Placeholder,
19801981
}
19811982

19821983
impl ItemKind {
@@ -1998,6 +1999,7 @@ impl ItemKind {
19981999
ItemKind::Mac(..) |
19992000
ItemKind::MacroDef(..) |
20002001
ItemKind::Impl(..) |
2002+
ItemKind::Placeholder |
20012003
ItemKind::AutoImpl(..) => "item"
20022004
}
20032005
}

src/libsyntax/fold.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ pub fn noop_fold_item_kind<T: Folder>(i: ItemKind, folder: &mut T) -> ItemKind {
935935
),
936936
ItemKind::Mac(m) => ItemKind::Mac(folder.fold_mac(m)),
937937
ItemKind::MacroDef(def) => ItemKind::MacroDef(folder.fold_macro_def(def)),
938+
ItemKind::Placeholder => ItemKind::Placeholder,
938939
}
939940
}
940941

0 commit comments

Comments
 (0)