Skip to content

Commit 78c7f0f

Browse files
committed
fix some nameres bugs
1 parent 0ed87f4 commit 78c7f0f

File tree

3 files changed

+43
-14
lines changed
  • compiler

3 files changed

+43
-14
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
576576
}
577577

578578
fn lower_path_simple_eii(&mut self, id: NodeId, path: &Path) -> Option<DefId> {
579-
let res = self.resolver.get_partial_res(id).unwrap();
579+
let res = self.resolver.get_partial_res(id)?;
580580
let Some(did) = res.expect_full_res().opt_def_id() else {
581581
self.dcx().span_delayed_bug(path.span, "should have errored in resolve");
582582
return None;

compiler/rustc_builtin_macros/src/eii.rs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use rustc_ast::ptr::P;
22
use rustc_ast::token::{Delimiter, TokenKind};
33
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
4-
use rustc_ast::{DUMMY_NODE_ID, EIIImpl, EIIMacroFor, ItemKind, ast, token, tokenstream};
4+
use rustc_ast::{
5+
DUMMY_NODE_ID, EIIImpl, EIIMacroFor, ItemKind, Stmt, StmtKind, ast, token, tokenstream,
6+
};
57
use rustc_ast_pretty::pprust::path_to_string;
68
use rustc_expand::base::{Annotatable, ExtCtxt};
79
use rustc_span::{Ident, Span, kw, sym};
@@ -53,7 +55,13 @@ fn eii_(
5355
) -> Vec<Annotatable> {
5456
let span = ecx.with_def_site_ctxt(span);
5557

56-
let Annotatable::Item(item) = item else {
58+
let (item, stmt) = if let Annotatable::Item(item) = item {
59+
(item, false)
60+
} else if let Annotatable::Stmt(ref stmt) = item
61+
&& let StmtKind::Item(ref item) = stmt.kind
62+
{
63+
(item.clone(), true)
64+
} else {
5765
ecx.dcx()
5866
.emit_err(EIIMacroExpectedFunction { span, name: path_to_string(&meta_item.path) });
5967
return vec![item];
@@ -106,7 +114,7 @@ fn eii_(
106114
is_default: true, // important!
107115
});
108116

109-
return_items.push(Annotatable::Item(P(ast::Item {
117+
return_items.push(P(ast::Item {
110118
attrs: ThinVec::new(),
111119
id: ast::DUMMY_NODE_ID,
112120
span,
@@ -128,7 +136,7 @@ fn eii_(
128136
stmts: thin_vec![ast::Stmt {
129137
id: DUMMY_NODE_ID,
130138
kind: ast::StmtKind::Item(P(ast::Item {
131-
attrs: thin_vec![], // TODO: re-add some original attrs
139+
attrs: thin_vec![], // FIXME: re-add some original attrs
132140
id: DUMMY_NODE_ID,
133141
span: item_span,
134142
vis: ast::Visibility {
@@ -155,7 +163,7 @@ fn eii_(
155163
define_opaque: None,
156164
})),
157165
tokens: None,
158-
})))
166+
}))
159167
}
160168

161169
let decl_span = span.to(func.sig.span);
@@ -199,7 +207,7 @@ fn eii_(
199207
style: ast::AttrStyle::Outer,
200208
span,
201209
});
202-
let extern_block = Annotatable::Item(P(ast::Item {
210+
let extern_block = P(ast::Item {
203211
attrs: ast::AttrVec::default(),
204212
id: ast::DUMMY_NODE_ID,
205213
span,
@@ -218,7 +226,7 @@ fn eii_(
218226
})]),
219227
}),
220228
tokens: None,
221-
}));
229+
});
222230

223231
let mut macro_attrs = attrs.clone();
224232
macro_attrs.push(
@@ -246,7 +254,7 @@ fn eii_(
246254
},
247255
);
248256

249-
let macro_def = Annotatable::Item(P(ast::Item {
257+
let macro_def = P(ast::Item {
250258
attrs: macro_attrs,
251259
id: ast::DUMMY_NODE_ID,
252260
span,
@@ -286,12 +294,21 @@ fn eii_(
286294
},
287295
),
288296
tokens: None,
289-
}));
297+
});
290298

291299
return_items.push(extern_block);
292300
return_items.push(macro_def);
293301

294-
return_items
302+
if stmt {
303+
return_items
304+
.into_iter()
305+
.map(|i| {
306+
Annotatable::Stmt(P(Stmt { id: DUMMY_NODE_ID, kind: StmtKind::Item(i), span }))
307+
})
308+
.collect()
309+
} else {
310+
return_items.into_iter().map(|i| Annotatable::Item(i)).collect()
311+
}
295312
}
296313

297314
use crate::errors::{
@@ -305,10 +322,17 @@ pub(crate) fn eii_macro_for(
305322
meta_item: &ast::MetaItem,
306323
mut item: Annotatable,
307324
) -> Vec<Annotatable> {
308-
let Annotatable::Item(i) = &mut item else {
325+
let i = if let Annotatable::Item(ref mut item) = item {
326+
item
327+
} else if let Annotatable::Stmt(ref mut stmt) = item
328+
&& let StmtKind::Item(ref mut item) = stmt.kind
329+
{
330+
item
331+
} else {
309332
ecx.dcx().emit_err(EIIMacroForExpectedMacro { span });
310333
return vec![item];
311334
};
335+
312336
let ItemKind::MacroDef(_, d) = &mut i.kind else {
313337
ecx.dcx().emit_err(EIIMacroForExpectedMacro { span });
314338
return vec![item];
@@ -353,7 +377,13 @@ pub(crate) fn eii_macro(
353377
meta_item: &ast::MetaItem,
354378
mut item: Annotatable,
355379
) -> Vec<Annotatable> {
356-
let Annotatable::Item(i) = &mut item else {
380+
let i = if let Annotatable::Item(ref mut item) = item {
381+
item
382+
} else if let Annotatable::Stmt(ref mut stmt) = item
383+
&& let StmtKind::Item(ref mut item) = stmt.kind
384+
{
385+
item
386+
} else {
357387
ecx.dcx()
358388
.emit_err(EIIMacroExpectedFunction { span, name: path_to_string(&meta_item.path) });
359389
return vec![item];

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,6 @@ fn add_post_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor
19851985
/// used in any sections, so the linker will therefore pick relevant rlibs for linking, but
19861986
/// unused `#[no_mangle]` or `#[used]` can still be discard by GC sections.
19871987
///
1988-
// TODO: does EII solves this?
19891988
/// There's a few internal crates in the standard library (aka libcore and
19901989
/// libstd) which actually have a circular dependence upon one another. This
19911990
/// currently arises through "weak lang items" where libcore requires things

0 commit comments

Comments
 (0)