Skip to content

Commit cdc5b94

Browse files
Pass down the parsing session
Signed-off-by: Jonathan Brouwer <[email protected]>
1 parent 764a2e5 commit cdc5b94

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ impl<'sess> AttributeParser<'sess, Early> {
699699
let ast::AttrKind::Normal(normal_attr) = &attr.kind else {
700700
panic!("parse_single called on a doc attr")
701701
};
702-
let meta_parser = MetaItemParser::from_attr(normal_attr, parser.dcx());
702+
let meta_parser = MetaItemParser::from_attr(normal_attr, &sess.psess);
703703
let path = meta_parser.path();
704704
let args = meta_parser.args();
705705
let mut cx: AcceptContext<'_, 'sess, Early> = AcceptContext {
@@ -806,7 +806,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
806806
ast::AttrKind::Normal(n) => {
807807
attr_paths.push(PathParser::Ast(&n.item.path));
808808

809-
let parser = MetaItemParser::from_attr(n, self.dcx());
809+
let parser = MetaItemParser::from_attr(n, &self.sess.psess);
810810
let path = parser.path();
811811
let args = parser.args();
812812
let parts = path.segments().map(|i| i.name).collect::<Vec<_>>();

compiler/rustc_attr_parsing/src/parser.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_ast::{AttrArgs, DelimArgs, Expr, ExprKind, LitKind, MetaItemLit, Norma
1212
use rustc_ast_pretty::pprust;
1313
use rustc_errors::DiagCtxtHandle;
1414
use rustc_hir::{self as hir, AttrPath};
15+
use rustc_session::parse::ParseSess;
1516
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
1617

1718
pub struct SegmentIterator<'a> {
@@ -123,18 +124,18 @@ impl<'a> ArgParser<'a> {
123124
}
124125
}
125126

126-
pub fn from_attr_args<'sess>(value: &'a AttrArgs, dcx: DiagCtxtHandle<'sess>) -> Self {
127+
pub fn from_attr_args<'sess>(value: &'a AttrArgs, psess: &'sess ParseSess) -> Self {
127128
match value {
128129
AttrArgs::Empty => Self::NoArgs,
129130
AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => {
130-
Self::List(MetaItemListParser::new(args, dcx))
131+
Self::List(MetaItemListParser::new(args, psess))
131132
}
132133
AttrArgs::Delimited(args) => {
133134
Self::List(MetaItemListParser { sub_parsers: vec![], span: args.dspan.entire() })
134135
}
135136
AttrArgs::Eq { eq_span, expr } => Self::NameValue(NameValueParser {
136137
eq_span: *eq_span,
137-
value: expr_to_lit(dcx, &expr, *eq_span),
138+
value: expr_to_lit(psess.dcx(), &expr, *eq_span),
138139
value_span: expr.span,
139140
}),
140141
}
@@ -249,10 +250,10 @@ impl<'a> Debug for MetaItemParser<'a> {
249250
impl<'a> MetaItemParser<'a> {
250251
/// Create a new parser from a [`NormalAttr`], which is stored inside of any
251252
/// [`ast::Attribute`](rustc_ast::Attribute)
252-
pub fn from_attr<'sess>(attr: &'a NormalAttr, dcx: DiagCtxtHandle<'sess>) -> Self {
253+
pub fn from_attr<'sess>(attr: &'a NormalAttr, psess: &'sess ParseSess) -> Self {
253254
Self {
254255
path: PathParser::Ast(&attr.item.path),
255-
args: ArgParser::from_attr_args(&attr.item.args, dcx),
256+
args: ArgParser::from_attr_args(&attr.item.args, psess),
256257
}
257258
}
258259
}
@@ -337,7 +338,7 @@ fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr, span: Span) -> MetaItemLit
337338
struct MetaItemListParserContext<'a, 'sess> {
338339
// the tokens inside the delimiters, so `#[some::attr(a b c)]` would have `a b c` inside
339340
inside_delimiters: Peekable<TokenStreamIter<'a>>,
340-
dcx: DiagCtxtHandle<'sess>,
341+
psess: &'sess ParseSess,
341342
}
342343

343344
impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
@@ -414,7 +415,7 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
414415
Some(TokenTree::Delimited(.., Delimiter::Invisible(_), inner_tokens)) => {
415416
MetaItemListParserContext {
416417
inside_delimiters: inner_tokens.iter().peekable(),
417-
dcx: self.dcx,
418+
psess: self.psess,
418419
}
419420
.value()
420421
}
@@ -447,7 +448,7 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
447448
self.inside_delimiters.next();
448449
return MetaItemListParserContext {
449450
inside_delimiters: inner_tokens.iter().peekable(),
450-
dcx: self.dcx,
451+
psess: self.psess,
451452
}
452453
.next();
453454
}
@@ -468,7 +469,7 @@ impl<'a, 'sess> MetaItemListParserContext<'a, 'sess> {
468469
args: ArgParser::List(MetaItemListParser::new_tts(
469470
inner_tokens.iter(),
470471
dspan.entire(),
471-
self.dcx,
472+
self.psess,
472473
)),
473474
}
474475
}
@@ -521,12 +522,12 @@ pub struct MetaItemListParser<'a> {
521522
}
522523

523524
impl<'a> MetaItemListParser<'a> {
524-
fn new<'sess>(delim: &'a DelimArgs, dcx: DiagCtxtHandle<'sess>) -> Self {
525-
MetaItemListParser::new_tts(delim.tokens.iter(), delim.dspan.entire(), dcx)
525+
fn new<'sess>(delim: &'a DelimArgs, psess: &'sess ParseSess) -> Self {
526+
MetaItemListParser::new_tts(delim.tokens.iter(), delim.dspan.entire(), psess)
526527
}
527528

528-
fn new_tts<'sess>(tts: TokenStreamIter<'a>, span: Span, dcx: DiagCtxtHandle<'sess>) -> Self {
529-
MetaItemListParserContext { inside_delimiters: tts.peekable(), dcx }.parse(span)
529+
fn new_tts<'sess>(tts: TokenStreamIter<'a>, span: Span, psess: &'sess ParseSess) -> Self {
530+
MetaItemListParserContext { inside_delimiters: tts.peekable(), psess }.parse(span)
530531
}
531532

532533
/// Lets you pick and choose as what you want to parse each element in the list

0 commit comments

Comments
 (0)