Skip to content

Commit 82e3402

Browse files
committed
Introduce new attribute parsers and rewrite several
1 parent ecda83b commit 82e3402

File tree

108 files changed

+3362
-1678
lines changed

Some content is hidden

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

108 files changed

+3362
-1678
lines changed

Cargo.lock

+13-6
Original file line numberDiff line numberDiff line change
@@ -3345,13 +3345,15 @@ version = "0.0.0"
33453345
dependencies = [
33463346
"rustc_ast",
33473347
"rustc_ast_pretty",
3348+
"rustc_attr_parsing",
33483349
"rustc_data_structures",
33493350
"rustc_errors",
33503351
"rustc_fluent_macro",
33513352
"rustc_hir",
33523353
"rustc_index",
33533354
"rustc_macros",
33543355
"rustc_middle",
3356+
"rustc_parse",
33553357
"rustc_session",
33563358
"rustc_span",
33573359
"rustc_target",
@@ -3398,16 +3400,11 @@ version = "0.0.0"
33983400
dependencies = [
33993401
"rustc_abi",
34003402
"rustc_ast",
3401-
"rustc_ast_pretty",
34023403
"rustc_data_structures",
3403-
"rustc_errors",
3404-
"rustc_feature",
3405-
"rustc_fluent_macro",
3406-
"rustc_lexer",
34073404
"rustc_macros",
34083405
"rustc_serialize",
3409-
"rustc_session",
34103406
"rustc_span",
3407+
"thin-vec",
34113408
]
34123409

34133410
[[package]]
@@ -3422,11 +3419,13 @@ dependencies = [
34223419
"rustc_errors",
34233420
"rustc_feature",
34243421
"rustc_fluent_macro",
3422+
"rustc_hir",
34253423
"rustc_lexer",
34263424
"rustc_macros",
34273425
"rustc_serialize",
34283426
"rustc_session",
34293427
"rustc_span",
3428+
"thin-vec",
34303429
]
34313430

34323431
[[package]]
@@ -3479,6 +3478,7 @@ dependencies = [
34793478
"rustc_expand",
34803479
"rustc_feature",
34813480
"rustc_fluent_macro",
3481+
"rustc_hir",
34823482
"rustc_index",
34833483
"rustc_lexer",
34843484
"rustc_lint_defs",
@@ -3730,6 +3730,7 @@ dependencies = [
37303730
"rustc_abi",
37313731
"rustc_ast",
37323732
"rustc_ast_pretty",
3733+
"rustc_attr_data_structures",
37333734
"rustc_data_structures",
37343735
"rustc_error_codes",
37353736
"rustc_error_messages",
@@ -3763,6 +3764,7 @@ dependencies = [
37633764
"rustc_errors",
37643765
"rustc_feature",
37653766
"rustc_fluent_macro",
3767+
"rustc_hir",
37663768
"rustc_lexer",
37673769
"rustc_lint_defs",
37683770
"rustc_macros",
@@ -3814,6 +3816,7 @@ dependencies = [
38143816
"rustc_abi",
38153817
"rustc_arena",
38163818
"rustc_ast",
3819+
"rustc_attr_data_structures",
38173820
"rustc_data_structures",
38183821
"rustc_index",
38193822
"rustc_macros",
@@ -3860,6 +3863,7 @@ dependencies = [
38603863
"rustc_abi",
38613864
"rustc_ast",
38623865
"rustc_ast_pretty",
3866+
"rustc_attr_parsing",
38633867
"rustc_hir",
38643868
"rustc_span",
38653869
]
@@ -4387,6 +4391,7 @@ dependencies = [
43874391
"parking_lot",
43884392
"rustc-rayon-core",
43894393
"rustc_ast",
4394+
"rustc_attr_data_structures",
43904395
"rustc_data_structures",
43914396
"rustc_errors",
43924397
"rustc_feature",
@@ -4437,6 +4442,7 @@ version = "0.0.0"
44374442
dependencies = [
44384443
"bitflags",
44394444
"rustc_abi",
4445+
"rustc_ast",
44404446
"rustc_data_structures",
44414447
"rustc_hir",
44424448
"rustc_middle",
@@ -4530,6 +4536,7 @@ dependencies = [
45304536
"punycode",
45314537
"rustc-demangle",
45324538
"rustc_abi",
4539+
"rustc_ast",
45334540
"rustc_data_structures",
45344541
"rustc_errors",
45354542
"rustc_hir",

compiler/rustc_ast_lowering/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ doctest = false
1010
# tidy-alphabetical-start
1111
rustc_ast = { path = "../rustc_ast" }
1212
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
13+
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
1314
rustc_data_structures = { path = "../rustc_data_structures" }
1415
rustc_errors = { path = "../rustc_errors" }
1516
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1617
rustc_hir = { path = "../rustc_hir" }
1718
rustc_index = { path = "../rustc_index" }
1819
rustc_macros = { path = "../rustc_macros" }
1920
rustc_middle = { path = "../rustc_middle" }
21+
rustc_parse = { path = "../rustc_parse" }
2022
rustc_session = { path = "../rustc_session" }
2123
rustc_span = { path = "../rustc_span" }
2224
rustc_target = { path = "../rustc_target" }

compiler/rustc_ast_lowering/src/block.rs

+1-1
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

+21-18
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)),
@@ -647,7 +646,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
647646
let guard = arm.guard.as_ref().map(|cond| self.lower_expr(cond));
648647
let hir_id = self.next_id();
649648
let span = self.lower_span(arm.span);
650-
self.lower_attrs(hir_id, &arm.attrs);
649+
self.lower_attrs(hir_id, &arm.attrs, arm.span);
651650
let is_never_pattern = pat.is_never_pattern();
652651
let body = if let Some(body) = &arm.body
653652
&& !is_never_pattern
@@ -805,15 +804,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
805804
span,
806805
Some(Lrc::clone(&self.allow_gen_future)),
807806
);
808-
self.lower_attrs(inner_hir_id, &[Attribute {
809-
kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new(
810-
sym::track_caller,
811-
span,
812-
)))),
813-
id: self.tcx.sess.psess.attr_id_generator.mk_attr_id(),
814-
style: AttrStyle::Outer,
815-
span: unstable_span,
816-
}]);
807+
self.lower_attrs(
808+
inner_hir_id,
809+
&[Attribute {
810+
kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new(
811+
sym::track_caller,
812+
span,
813+
)))),
814+
id: self.tcx.sess.psess.attr_id_generator.mk_attr_id(),
815+
style: AttrStyle::Outer,
816+
span: unstable_span,
817+
}],
818+
span,
819+
);
817820
}
818821
}
819822

@@ -1618,7 +1621,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16181621

16191622
fn lower_expr_field(&mut self, f: &ExprField) -> hir::ExprField<'hir> {
16201623
let hir_id = self.lower_node_id(f.id);
1621-
self.lower_attrs(hir_id, &f.attrs);
1624+
self.lower_attrs(hir_id, &f.attrs, f.span);
16221625
hir::ExprField {
16231626
hir_id,
16241627
ident: self.lower_ident(f.ident),
@@ -1881,7 +1884,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18811884
//
18821885
// Also, add the attributes to the outer returned expr node.
18831886
let expr = self.expr_drop_temps_mut(for_span, match_expr);
1884-
self.lower_attrs(expr.hir_id, &e.attrs);
1887+
self.lower_attrs(expr.hir_id, &e.attrs, e.span);
18851888
expr
18861889
}
18871890

@@ -1938,7 +1941,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19381941
let val_ident = Ident::with_dummy_span(sym::val);
19391942
let (val_pat, val_pat_nid) = self.pat_ident(span, val_ident);
19401943
let val_expr = self.expr_ident(span, val_ident, val_pat_nid);
1941-
self.lower_attrs(val_expr.hir_id, &attrs);
1944+
self.lower_attrs(val_expr.hir_id, &attrs, span);
19421945
let continue_pat = self.pat_cf_continue(unstable_span, val_pat);
19431946
self.arm(continue_pat, val_expr)
19441947
};
@@ -1968,7 +1971,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19681971
} else {
19691972
self.arena.alloc(self.expr(try_span, hir::ExprKind::Ret(Some(from_residual_expr))))
19701973
};
1971-
self.lower_attrs(ret_expr.hir_id, &attrs);
1974+
self.lower_attrs(ret_expr.hir_id, &attrs, ret_expr.span);
19721975

19731976
let break_pat = self.pat_cf_break(try_span, residual_local);
19741977
self.arm(break_pat, ret_expr)

compiler/rustc_ast_lowering/src/item.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_index::{IndexSlice, IndexVec};
1010
use rustc_middle::span_bug;
1111
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
1212
use rustc_span::edit_distance::find_best_match_for_name;
13-
use rustc_span::{DesugaringKind, Ident, Span, Symbol, kw, sym};
13+
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, kw, sym};
1414
use rustc_target::spec::abi;
1515
use smallvec::{SmallVec, smallvec};
1616
use thin_vec::ThinVec;
@@ -93,7 +93,8 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
9393
debug_assert_eq!(self.resolver.node_id_to_def_id[&CRATE_NODE_ID], CRATE_DEF_ID);
9494
self.with_lctx(CRATE_NODE_ID, |lctx| {
9595
let module = lctx.lower_mod(&c.items, &c.spans);
96-
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
96+
// FIXME(jdonszelman): is dummy span ever a problem here?
97+
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, DUMMY_SP);
9798
hir::OwnerNode::Crate(module)
9899
})
99100
}
@@ -157,7 +158,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
157158
let mut ident = i.ident;
158159
let vis_span = self.lower_span(i.vis.span);
159160
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
160-
let attrs = self.lower_attrs(hir_id, &i.attrs);
161+
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span);
161162
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, vis_span, &i.kind);
162163
let item = hir::Item {
163164
owner_id: hir_id.expect_owner(),
@@ -610,7 +611,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
610611
fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
611612
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
612613
let owner_id = hir_id.expect_owner();
613-
let attrs = self.lower_attrs(hir_id, &i.attrs);
614+
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span);
614615
let item = hir::ForeignItem {
615616
owner_id,
616617
ident: self.lower_ident(i.ident),
@@ -668,7 +669,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
668669

669670
fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
670671
let hir_id = self.lower_node_id(v.id);
671-
self.lower_attrs(hir_id, &v.attrs);
672+
self.lower_attrs(hir_id, &v.attrs, v.span);
672673
hir::Variant {
673674
hir_id,
674675
def_id: self.local_def_id(v.id),
@@ -730,7 +731,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
730731
) -> hir::FieldDef<'hir> {
731732
let ty = self.lower_ty(&f.ty, ImplTraitContext::Disallowed(ImplTraitPosition::FieldTy));
732733
let hir_id = self.lower_node_id(f.id);
733-
self.lower_attrs(hir_id, &f.attrs);
734+
self.lower_attrs(hir_id, &f.attrs, f.span);
734735
hir::FieldDef {
735736
span: self.lower_span(f.span),
736737
hir_id,
@@ -749,7 +750,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
749750

750751
fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
751752
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
752-
let attrs = self.lower_attrs(hir_id, &i.attrs);
753+
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span);
753754
let trait_item_def_id = hir_id.expect_owner();
754755

755756
let (generics, kind, has_default) = match &i.kind {
@@ -882,7 +883,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
882883
let has_value = true;
883884
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
884885
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
885-
let attrs = self.lower_attrs(hir_id, &i.attrs);
886+
let attrs = self.lower_attrs(hir_id, &i.attrs, i.span);
886887

887888
let (generics, kind) = match &i.kind {
888889
AssocItemKind::Const(box ConstItem { generics, ty, expr, .. }) => self.lower_generics(
@@ -1039,7 +1040,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10391040

10401041
fn lower_param(&mut self, param: &Param) -> hir::Param<'hir> {
10411042
let hir_id = self.lower_node_id(param.id);
1042-
self.lower_attrs(hir_id, &param.attrs);
1043+
self.lower_attrs(hir_id, &param.attrs, param.span);
10431044
hir::Param {
10441045
hir_id,
10451046
pat: self.lower_pat(&param.pat),

0 commit comments

Comments
 (0)