Skip to content

Commit 80d2bdb

Browse files
committed
Rename all ParseSess variables/fields/lifetimes as psess.
Existing names for values of this type are `sess`, `parse_sess`, `parse_session`, and `ps`. `sess` is particularly annoying because that's also used for `Session` values, which are often co-located, and it can be difficult to know which type a value named `sess` refers to. (That annoyance is the main motivation for this change.) `psess` is nice and short, which is good for a name used this much. The commit also renames some `parse_sess_created` values as `psess_created`.
1 parent 4260f7e commit 80d2bdb

File tree

98 files changed

+653
-687
lines changed

Some content is hidden

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

98 files changed

+653
-687
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
125125
let lit_kind = match LitKind::from_token_lit(*token_lit) {
126126
Ok(lit_kind) => lit_kind,
127127
Err(err) => {
128-
let guar = report_lit_error(
129-
&self.tcx.sess.parse_sess,
130-
err,
131-
*token_lit,
132-
e.span,
133-
);
128+
let guar =
129+
report_lit_error(&self.tcx.sess.psess, err, *token_lit, e.span);
134130
LitKind::Err(guar)
135131
}
136132
};
@@ -721,7 +717,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
721717
sym::track_caller,
722718
span,
723719
)))),
724-
id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(),
720+
id: self.tcx.sess.psess.attr_id_generator.mk_attr_id(),
725721
style: AttrStyle::Outer,
726722
span: unstable_span,
727723
}],
@@ -1756,7 +1752,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17561752

17571753
// `#[allow(unreachable_code)]`
17581754
let attr = attr::mk_attr_nested_word(
1759-
&self.tcx.sess.parse_sess.attr_id_generator,
1755+
&self.tcx.sess.psess.attr_id_generator,
17601756
AttrStyle::Outer,
17611757
sym::allow,
17621758
sym::unreachable_code,

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ fn validate_generic_param_order(
835835

836836
impl<'a> Visitor<'a> for AstValidator<'a> {
837837
fn visit_attribute(&mut self, attr: &Attribute) {
838-
validate_attr::check_attr(&self.session.parse_sess, attr);
838+
validate_attr::check_attr(&self.session.psess, attr);
839839
}
840840

841841
fn visit_ty(&mut self, ty: &'a Ty) {

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
507507
check_incompatible_features(sess, features);
508508
let mut visitor = PostExpansionVisitor { sess, features };
509509

510-
let spans = sess.parse_sess.gated_spans.spans.borrow();
510+
let spans = sess.psess.gated_spans.spans.borrow();
511511
macro_rules! gate_all {
512512
($gate:ident, $msg:literal) => {
513513
if let Some(spans) = spans.get(&sym::$gate) {

compiler/rustc_attr/src/builtin.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,9 @@ pub fn cfg_matches(
524524
) -> bool {
525525
eval_condition(cfg, sess, features, &mut |cfg| {
526526
try_gate_cfg(cfg.name, cfg.span, sess, features);
527-
match sess.parse_sess.check_config.expecteds.get(&cfg.name) {
527+
match sess.psess.check_config.expecteds.get(&cfg.name) {
528528
Some(ExpectedValues::Some(values)) if !values.contains(&cfg.value) => {
529-
sess.parse_sess.buffer_lint_with_diagnostic(
529+
sess.psess.buffer_lint_with_diagnostic(
530530
UNEXPECTED_CFGS,
531531
cfg.span,
532532
lint_node_id,
@@ -541,8 +541,8 @@ pub fn cfg_matches(
541541
),
542542
);
543543
}
544-
None if sess.parse_sess.check_config.exhaustive_names => {
545-
sess.parse_sess.buffer_lint_with_diagnostic(
544+
None if sess.psess.check_config.exhaustive_names => {
545+
sess.psess.buffer_lint_with_diagnostic(
546546
UNEXPECTED_CFGS,
547547
cfg.span,
548548
lint_node_id,
@@ -555,7 +555,7 @@ pub fn cfg_matches(
555555
}
556556
_ => { /* not unexpected */ }
557557
}
558-
sess.parse_sess.config.contains(&(cfg.name, cfg.value))
558+
sess.psess.config.contains(&(cfg.name, cfg.value))
559559
})
560560
}
561561

@@ -598,7 +598,7 @@ pub fn eval_condition(
598598
features: Option<&Features>,
599599
eval: &mut impl FnMut(Condition) -> bool,
600600
) -> bool {
601-
let dcx = &sess.parse_sess.dcx;
601+
let dcx = &sess.psess.dcx;
602602
match &cfg.kind {
603603
ast::MetaItemKind::List(mis) if cfg.name_or_empty() == sym::version => {
604604
try_gate_cfg(sym::version, cfg.span, sess, features);
@@ -626,7 +626,7 @@ pub fn eval_condition(
626626
};
627627

628628
// See https://github.com/rust-lang/rust/issues/64796#issuecomment-640851454 for details
629-
if sess.parse_sess.assume_incomplete_release {
629+
if sess.psess.assume_incomplete_release {
630630
RustcVersion::CURRENT > min_version
631631
} else {
632632
RustcVersion::CURRENT >= min_version

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn parse_asm_args<'a>(
4545
sp: Span,
4646
is_global_asm: bool,
4747
) -> PResult<'a, AsmArgs> {
48-
let dcx = &p.sess.dcx;
48+
let dcx = &p.psess.dcx;
4949

5050
if p.token == token::Eof {
5151
return Err(dcx.create_err(errors::AsmRequiresTemplate { span: sp }));
@@ -296,7 +296,7 @@ pub fn parse_asm_args<'a>(
296296
fn err_duplicate_option(p: &mut Parser<'_>, symbol: Symbol, span: Span) {
297297
// Tool-only output
298298
let full_span = if p.token.kind == token::Comma { span.to(p.token.span) } else { span };
299-
p.sess.dcx.emit_err(errors::AsmOptAlreadyprovided { span, symbol, full_span });
299+
p.psess.dcx.emit_err(errors::AsmOptAlreadyprovided { span, symbol, full_span });
300300
}
301301

302302
/// Try to set the provided option in the provided `AsmArgs`.
@@ -368,7 +368,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
368368
p.expect(&token::OpenDelim(Delimiter::Parenthesis))?;
369369

370370
if p.eat(&token::CloseDelim(Delimiter::Parenthesis)) {
371-
return Err(p.sess.dcx.create_err(errors::NonABI { span: p.token.span }));
371+
return Err(p.psess.dcx.create_err(errors::NonABI { span: p.token.span }));
372372
}
373373

374374
let mut new_abis = Vec::new();
@@ -379,7 +379,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
379379
}
380380
Err(opt_lit) => {
381381
let span = opt_lit.map_or(p.token.span, |lit| lit.span);
382-
let mut err = p.sess.dcx.struct_span_err(span, "expected string literal");
382+
let mut err = p.psess.dcx.struct_span_err(span, "expected string literal");
383383
err.span_label(span, "not a string literal");
384384
return Err(err);
385385
}
@@ -495,15 +495,15 @@ fn expand_preparsed_asm(
495495
};
496496

497497
if template_str.contains(".intel_syntax") {
498-
ecx.parse_sess().buffer_lint(
498+
ecx.psess().buffer_lint(
499499
lint::builtin::BAD_ASM_STYLE,
500500
find_span(".intel_syntax"),
501501
ecx.current_expansion.lint_node_id,
502502
"avoid using `.intel_syntax`, Intel syntax is the default",
503503
);
504504
}
505505
if template_str.contains(".att_syntax") {
506-
ecx.parse_sess().buffer_lint(
506+
ecx.psess().buffer_lint(
507507
lint::builtin::BAD_ASM_STYLE,
508508
find_span(".att_syntax"),
509509
ecx.current_expansion.lint_node_id,

compiler/rustc_builtin_macros/src/cfg_accessible.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl MultiItemModifier for Expander {
4646
) -> ExpandResult<Vec<Annotatable>, Annotatable> {
4747
let template = AttributeTemplate { list: Some("path"), ..Default::default() };
4848
validate_attr::check_builtin_meta_item(
49-
&ecx.sess.parse_sess,
49+
&ecx.sess.psess,
5050
meta_item,
5151
ast::AttrStyle::Outer,
5252
sym::cfg_accessible,

compiler/rustc_builtin_macros/src/cfg_eval.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ impl CfgEval<'_, '_> {
195195
// Re-parse the tokens, setting the `capture_cfg` flag to save extra information
196196
// to the captured `AttrTokenStream` (specifically, we capture
197197
// `AttrTokenTree::AttributesData` for all occurrences of `#[cfg]` and `#[cfg_attr]`)
198-
let mut parser =
199-
rustc_parse::stream_to_parser(&self.cfg.sess.parse_sess, orig_tokens, None);
198+
let mut parser = rustc_parse::stream_to_parser(&self.cfg.sess.psess, orig_tokens, None);
200199
parser.capture_cfg = true;
201200
match parse_annotatable_with(&mut parser) {
202201
Ok(a) => annotatable = a,

compiler/rustc_builtin_macros/src/cmdline_attrs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use rustc_ast::{self as ast, AttrItem, AttrStyle};
77
use rustc_session::parse::ParseSess;
88
use rustc_span::FileName;
99

10-
pub fn inject(krate: &mut ast::Crate, parse_sess: &ParseSess, attrs: &[String]) {
10+
pub fn inject(krate: &mut ast::Crate, psess: &ParseSess, attrs: &[String]) {
1111
for raw_attr in attrs {
1212
let mut parser = rustc_parse::new_parser_from_source_str(
13-
parse_sess,
13+
psess,
1414
FileName::cli_crate_attr_source_code(raw_attr),
1515
raw_attr.clone(),
1616
);
@@ -25,12 +25,12 @@ pub fn inject(krate: &mut ast::Crate, parse_sess: &ParseSess, attrs: &[String])
2525
};
2626
let end_span = parser.token.span;
2727
if parser.token != token::Eof {
28-
parse_sess.dcx.emit_err(errors::InvalidCrateAttr { span: start_span.to(end_span) });
28+
psess.dcx.emit_err(errors::InvalidCrateAttr { span: start_span.to(end_span) });
2929
continue;
3030
}
3131

3232
krate.attrs.push(mk_attr(
33-
&parse_sess.attr_id_generator,
33+
&psess.attr_id_generator,
3434
AttrStyle::Inner,
3535
path,
3636
args,

compiler/rustc_builtin_macros/src/concat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn expand_concat(
4343
guar = Some(guarantee);
4444
}
4545
Err(err) => {
46-
guar = Some(report_lit_error(&cx.sess.parse_sess, err, token_lit, e.span));
46+
guar = Some(report_lit_error(&cx.sess.psess, err, token_lit, e.span));
4747
}
4848
},
4949
// We also want to allow negative numeric literals.
@@ -52,7 +52,7 @@ pub fn expand_concat(
5252
Ok(LitKind::Int(i, _)) => accumulator.push_str(&format!("-{i}")),
5353
Ok(LitKind::Float(f, _)) => accumulator.push_str(&format!("-{f}")),
5454
Err(err) => {
55-
guar = Some(report_lit_error(&cx.sess.parse_sess, err, token_lit, e.span));
55+
guar = Some(report_lit_error(&cx.sess.psess, err, token_lit, e.span));
5656
}
5757
_ => missing_literal.push(e.span),
5858
}

compiler/rustc_builtin_macros/src/concat_bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn invalid_type_err(
5555
Ok(LitKind::Int(_, _)) => dcx.emit_err(ConcatBytesNonU8 { span }),
5656
Ok(LitKind::ByteStr(..) | LitKind::Byte(_)) => unreachable!(),
5757
Ok(LitKind::Err(guar)) => guar,
58-
Err(err) => report_lit_error(&cx.sess.parse_sess, err, token_lit, span),
58+
Err(err) => report_lit_error(&cx.sess.psess, err, token_lit, span),
5959
}
6060
}
6161

0 commit comments

Comments
 (0)