Skip to content

Commit c53f2de

Browse files
committed
Introduce new parsing infrastructure and types for parsed attributes
1 parent 7c50917 commit c53f2de

File tree

30 files changed

+1413
-283
lines changed

30 files changed

+1413
-283
lines changed

Cargo.lock

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,13 +3396,15 @@ dependencies = [
33963396
"rustc_abi",
33973397
"rustc_ast",
33983398
"rustc_ast_pretty",
3399+
"rustc_attr_parsing",
33993400
"rustc_data_structures",
34003401
"rustc_errors",
34013402
"rustc_fluent_macro",
34023403
"rustc_hir",
34033404
"rustc_index",
34043405
"rustc_macros",
34053406
"rustc_middle",
3407+
"rustc_parse",
34063408
"rustc_session",
34073409
"rustc_span",
34083410
"rustc_target",
@@ -3450,16 +3452,11 @@ version = "0.0.0"
34503452
dependencies = [
34513453
"rustc_abi",
34523454
"rustc_ast",
3453-
"rustc_ast_pretty",
34543455
"rustc_data_structures",
3455-
"rustc_errors",
3456-
"rustc_feature",
3457-
"rustc_fluent_macro",
3458-
"rustc_lexer",
34593456
"rustc_macros",
34603457
"rustc_serialize",
3461-
"rustc_session",
34623458
"rustc_span",
3459+
"thin-vec",
34633460
]
34643461

34653462
[[package]]
@@ -3474,11 +3471,13 @@ dependencies = [
34743471
"rustc_errors",
34753472
"rustc_feature",
34763473
"rustc_fluent_macro",
3474+
"rustc_hir",
34773475
"rustc_lexer",
34783476
"rustc_macros",
34793477
"rustc_serialize",
34803478
"rustc_session",
34813479
"rustc_span",
3480+
"thin-vec",
34823481
]
34833482

34843483
[[package]]
@@ -3867,6 +3866,7 @@ dependencies = [
38673866
"rustc_abi",
38683867
"rustc_arena",
38693868
"rustc_ast",
3869+
"rustc_attr_data_structures",
38703870
"rustc_data_structures",
38713871
"rustc_index",
38723872
"rustc_macros",
@@ -3913,6 +3913,7 @@ dependencies = [
39133913
"rustc_abi",
39143914
"rustc_ast",
39153915
"rustc_ast_pretty",
3916+
"rustc_attr_parsing",
39163917
"rustc_hir",
39173918
"rustc_span",
39183919
]
@@ -4423,6 +4424,7 @@ version = "0.0.0"
44234424
dependencies = [
44244425
"field-offset",
44254426
"measureme",
4427+
"rustc_attr_data_structures",
44264428
"rustc_data_structures",
44274429
"rustc_errors",
44284430
"rustc_hir",
@@ -4443,6 +4445,7 @@ dependencies = [
44434445
"parking_lot",
44444446
"rustc-rayon-core",
44454447
"rustc_ast",
4448+
"rustc_attr_data_structures",
44464449
"rustc_data_structures",
44474450
"rustc_errors",
44484451
"rustc_feature",

compiler/rustc_ast_lowering/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ doctest = false
1111
rustc_abi = { path = "../rustc_abi" }
1212
rustc_ast = { path = "../rustc_ast" }
1313
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
14+
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
1415
rustc_data_structures = { path = "../rustc_data_structures" }
1516
rustc_errors = { path = "../rustc_errors" }
1617
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1718
rustc_hir = { path = "../rustc_hir" }
1819
rustc_index = { path = "../rustc_index" }
1920
rustc_macros = { path = "../rustc_macros" }
2021
rustc_middle = { path = "../rustc_middle" }
22+
rustc_parse = { path = "../rustc_parse" }
2123
rustc_session = { path = "../rustc_session" }
2224
rustc_span = { path = "../rustc_span" }
2325
rustc_target = { path = "../rustc_target" }

compiler/rustc_ast_lowering/src/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
108108
};
109109
let span = self.lower_span(l.span);
110110
let source = hir::LocalSource::Normal;
111-
self.lower_attrs(hir_id, &l.attrs);
111+
self.lower_attrs(hir_id, &l.attrs, l.span);
112112
self.arena.alloc(hir::LetStmt { hir_id, ty, pat, init, els, span, source })
113113
}
114114

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
7777
self.attrs.insert(
7878
ex.hir_id.local_id,
7979
&*self.arena.alloc_from_iter(
80-
e.attrs
81-
.iter()
82-
.map(|a| self.lower_attr(a))
80+
self.lower_attrs_vec(&e.attrs, e.span)
81+
.into_iter()
8382
.chain(old_attrs.iter().cloned()),
8483
),
8584
);
@@ -98,7 +97,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
9897
}
9998

10099
let expr_hir_id = self.lower_node_id(e.id);
101-
self.lower_attrs(expr_hir_id, &e.attrs);
100+
self.lower_attrs(expr_hir_id, &e.attrs, e.span);
102101

103102
let kind = match &e.kind {
104103
ExprKind::Array(exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
@@ -670,7 +669,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
670669
let guard = arm.guard.as_ref().map(|cond| self.lower_expr(cond));
671670
let hir_id = self.next_id();
672671
let span = self.lower_span(arm.span);
673-
self.lower_attrs(hir_id, &arm.attrs);
672+
self.lower_attrs(hir_id, &arm.attrs, arm.span);
674673
let is_never_pattern = pat.is_never_pattern();
675674
let body = if let Some(body) = &arm.body
676675
&& !is_never_pattern
@@ -839,6 +838,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
839838
style: AttrStyle::Outer,
840839
span: unstable_span,
841840
}],
841+
span,
842842
);
843843
}
844844
}
@@ -1672,7 +1672,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16721672

16731673
fn lower_expr_field(&mut self, f: &ExprField) -> hir::ExprField<'hir> {
16741674
let hir_id = self.lower_node_id(f.id);
1675-
self.lower_attrs(hir_id, &f.attrs);
1675+
self.lower_attrs(hir_id, &f.attrs, f.span);
16761676
hir::ExprField {
16771677
hir_id,
16781678
ident: self.lower_ident(f.ident),
@@ -1935,7 +1935,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19351935
//
19361936
// Also, add the attributes to the outer returned expr node.
19371937
let expr = self.expr_drop_temps_mut(for_span, match_expr);
1938-
self.lower_attrs(expr.hir_id, &e.attrs);
1938+
self.lower_attrs(expr.hir_id, &e.attrs, e.span);
19391939
expr
19401940
}
19411941

@@ -1992,7 +1992,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19921992
let val_ident = Ident::with_dummy_span(sym::val);
19931993
let (val_pat, val_pat_nid) = self.pat_ident(span, val_ident);
19941994
let val_expr = self.expr_ident(span, val_ident, val_pat_nid);
1995-
self.lower_attrs(val_expr.hir_id, &attrs);
1995+
self.lower_attrs(val_expr.hir_id, &attrs, span);
19961996
let continue_pat = self.pat_cf_continue(unstable_span, val_pat);
19971997
self.arm(continue_pat, val_expr)
19981998
};
@@ -2023,7 +2023,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20232023
let ret_expr = self.checked_return(Some(from_residual_expr));
20242024
self.arena.alloc(self.expr(try_span, ret_expr))
20252025
};
2026-
self.lower_attrs(ret_expr.hir_id, &attrs);
2026+
self.lower_attrs(ret_expr.hir_id, &attrs, ret_expr.span);
20272027

20282028
let break_pat = self.pat_cf_break(try_span, residual_local);
20292029
self.arm(break_pat, ret_expr)

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use rustc_index::{IndexSlice, IndexVec};
1111
use rustc_middle::span_bug;
1212
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
1313
use rustc_span::edit_distance::find_best_match_for_name;
14-
use rustc_span::{DesugaringKind, Ident, Span, Symbol, kw, sym};
14+
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, kw, sym};
15+
use rustc_target::spec::abi;
1516
use smallvec::{SmallVec, smallvec};
1617
use thin_vec::ThinVec;
1718
use tracing::instrument;
@@ -93,7 +94,8 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
9394
debug_assert_eq!(self.resolver.node_id_to_def_id[&CRATE_NODE_ID], CRATE_DEF_ID);
9495
self.with_lctx(CRATE_NODE_ID, |lctx| {
9596
let module = lctx.lower_mod(&c.items, &c.spans);
96-
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
97+
// FIXME(jdonszelman): is dummy span ever a problem here?
98+
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, DUMMY_SP);
9799
hir::OwnerNode::Crate(module)
98100
})
99101
}
@@ -157,7 +159,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
157159
let mut ident = i.ident;
158160
let vis_span = self.lower_span(i.vis.span);
159161
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
160-
let attrs = self.lower_attrs(hir_id, &i.attrs);
162+
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span);
161163
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, vis_span, &i.kind);
162164
let item = hir::Item {
163165
owner_id: hir_id.expect_owner(),
@@ -644,7 +646,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
644646
fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
645647
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
646648
let owner_id = hir_id.expect_owner();
647-
let attrs = self.lower_attrs(hir_id, &i.attrs);
649+
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span);
648650
let item = hir::ForeignItem {
649651
owner_id,
650652
ident: self.lower_ident(i.ident),
@@ -702,7 +704,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
702704

703705
fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
704706
let hir_id = self.lower_node_id(v.id);
705-
self.lower_attrs(hir_id, &v.attrs);
707+
self.lower_attrs(hir_id, &v.attrs, v.span);
706708
hir::Variant {
707709
hir_id,
708710
def_id: self.local_def_id(v.id),
@@ -764,7 +766,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
764766
) -> hir::FieldDef<'hir> {
765767
let ty = self.lower_ty(&f.ty, ImplTraitContext::Disallowed(ImplTraitPosition::FieldTy));
766768
let hir_id = self.lower_node_id(f.id);
767-
self.lower_attrs(hir_id, &f.attrs);
769+
self.lower_attrs(hir_id, &f.attrs, f.span);
768770
hir::FieldDef {
769771
span: self.lower_span(f.span),
770772
hir_id,
@@ -783,7 +785,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
783785

784786
fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
785787
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
786-
let attrs = self.lower_attrs(hir_id, &i.attrs);
788+
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span);
787789
let trait_item_def_id = hir_id.expect_owner();
788790

789791
let (generics, kind, has_default) = match &i.kind {
@@ -916,7 +918,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
916918
let has_value = true;
917919
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
918920
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
919-
let attrs = self.lower_attrs(hir_id, &i.attrs);
921+
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span);
920922

921923
let (generics, kind) = match &i.kind {
922924
AssocItemKind::Const(box ConstItem { generics, ty, expr, .. }) => self.lower_generics(
@@ -1076,7 +1078,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10761078

10771079
fn lower_param(&mut self, param: &Param) -> hir::Param<'hir> {
10781080
let hir_id = self.lower_node_id(param.id);
1079-
self.lower_attrs(hir_id, &param.attrs);
1081+
self.lower_attrs(hir_id, &param.attrs, param.span);
10801082
hir::Param {
10811083
hir_id,
10821084
pat: self.lower_pat(&param.pat),

0 commit comments

Comments
 (0)