about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_expand/src')
-rw-r--r--compiler/rustc_expand/src/base.rs18
-rw-r--r--compiler/rustc_expand/src/build.rs6
-rw-r--r--compiler/rustc_expand/src/config.rs12
-rw-r--r--compiler/rustc_expand/src/expand.rs24
-rw-r--r--compiler/rustc_expand/src/mbe/diagnostics.rs14
-rw-r--r--compiler/rustc_expand/src/mbe/macro_check.rs91
-rw-r--r--compiler/rustc_expand/src/mbe/macro_rules.rs34
-rw-r--r--compiler/rustc_expand/src/mbe/metavar_expr.rs76
-rw-r--r--compiler/rustc_expand/src/mbe/quoted.rs3
-rw-r--r--compiler/rustc_expand/src/module.rs16
-rw-r--r--compiler/rustc_expand/src/parse/tests.rs30
-rw-r--r--compiler/rustc_expand/src/proc_macro.rs2
-rw-r--r--compiler/rustc_expand/src/proc_macro_server.rs34
-rw-r--r--compiler/rustc_expand/src/tests.rs26
14 files changed, 187 insertions, 199 deletions
diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs
index 984c7403720..6d205a82675 100644
--- a/compiler/rustc_expand/src/base.rs
+++ b/compiler/rustc_expand/src/base.rs
@@ -1135,13 +1135,13 @@ impl<'a> ExtCtxt<'a> {
         expand::MacroExpander::new(self, true)
     }
     pub fn new_parser_from_tts(&self, stream: TokenStream) -> parser::Parser<'a> {
-        rustc_parse::stream_to_parser(&self.sess.parse_sess, stream, MACRO_ARGUMENTS)
+        rustc_parse::stream_to_parser(&self.sess.psess, stream, MACRO_ARGUMENTS)
     }
     pub fn source_map(&self) -> &'a SourceMap {
-        self.sess.parse_sess.source_map()
+        self.sess.psess.source_map()
     }
-    pub fn parse_sess(&self) -> &'a ParseSess {
-        &self.sess.parse_sess
+    pub fn psess(&self) -> &'a ParseSess {
+        &self.sess.psess
     }
     pub fn call_site(&self) -> Span {
         self.current_expansion.id.expn_data().call_site
@@ -1216,11 +1216,7 @@ impl<'a> ExtCtxt<'a> {
 /// Resolves a `path` mentioned inside Rust code, returning an absolute path.
 ///
 /// This unifies the logic used for resolving `include_X!`.
-pub fn resolve_path(
-    sess: &Session,
-    path: impl Into<PathBuf>,
-    span: Span,
-) -> PResult<'_, PathBuf> {
+pub fn resolve_path(sess: &Session, path: impl Into<PathBuf>, span: Span) -> PResult<'_, PathBuf> {
     let path = path.into();
 
     // Relative paths are resolved relative to the file in which they are found
@@ -1281,7 +1277,7 @@ pub fn expr_to_spanned_string<'a>(
                 Ok((err, true))
             }
             Ok(ast::LitKind::Err(guar)) => Err(guar),
-            Err(err) => Err(report_lit_error(&cx.sess.parse_sess, err, token_lit, expr.span)),
+            Err(err) => Err(report_lit_error(&cx.sess.psess, err, token_lit, expr.span)),
             _ => Ok((cx.dcx().struct_span_err(expr.span, err_msg), false)),
         },
         ast::ExprKind::Err(guar) => Err(guar),
@@ -1487,7 +1483,7 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
                             };
 
                             if crate_matches {
-                                sess.parse_sess.buffer_lint_with_diagnostic(
+                                sess.psess.buffer_lint_with_diagnostic(
                                         PROC_MACRO_BACK_COMPAT,
                                         item.ident.span,
                                         ast::CRATE_NODE_ID,
diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs
index 9ce2084c847..989b7b485c9 100644
--- a/compiler/rustc_expand/src/build.rs
+++ b/compiler/rustc_expand/src/build.rs
@@ -665,7 +665,7 @@ impl<'a> ExtCtxt<'a> {
 
     // Builds `#[name]`.
     pub fn attr_word(&self, name: Symbol, span: Span) -> ast::Attribute {
-        let g = &self.sess.parse_sess.attr_id_generator;
+        let g = &self.sess.psess.attr_id_generator;
         attr::mk_attr_word(g, ast::AttrStyle::Outer, name, span)
     }
 
@@ -673,13 +673,13 @@ impl<'a> ExtCtxt<'a> {
     //
     // Note: `span` is used for both the identifier and the value.
     pub fn attr_name_value_str(&self, name: Symbol, val: Symbol, span: Span) -> ast::Attribute {
-        let g = &self.sess.parse_sess.attr_id_generator;
+        let g = &self.sess.psess.attr_id_generator;
         attr::mk_attr_name_value_str(g, ast::AttrStyle::Outer, name, val, span)
     }
 
     // Builds `#[outer(inner)]`.
     pub fn attr_nested_word(&self, outer: Symbol, inner: Symbol, span: Span) -> ast::Attribute {
-        let g = &self.sess.parse_sess.attr_id_generator;
+        let g = &self.sess.psess.attr_id_generator;
         attr::mk_attr_nested_word(g, ast::AttrStyle::Outer, outer, inner, span)
     }
 }
diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs
index 435135d1959..921fea14312 100644
--- a/compiler/rustc_expand/src/config.rs
+++ b/compiler/rustc_expand/src/config.rs
@@ -241,14 +241,14 @@ impl<'a> StripUnconfigured<'a> {
     /// the attribute is incorrect.
     pub(crate) fn expand_cfg_attr(&self, attr: &Attribute, recursive: bool) -> Vec<Attribute> {
         let Some((cfg_predicate, expanded_attrs)) =
-            rustc_parse::parse_cfg_attr(attr, &self.sess.parse_sess)
+            rustc_parse::parse_cfg_attr(attr, &self.sess.psess)
         else {
             return vec![];
         };
 
         // Lint on zero attributes in source.
         if expanded_attrs.is_empty() {
-            self.sess.parse_sess.buffer_lint(
+            self.sess.psess.buffer_lint(
                 rustc_lint_defs::builtin::UNUSED_ATTRIBUTES,
                 attr.span,
                 ast::CRATE_NODE_ID,
@@ -324,14 +324,14 @@ impl<'a> StripUnconfigured<'a> {
         };
         let tokens = Some(LazyAttrTokenStream::new(AttrTokenStream::new(trees)));
         let attr = attr::mk_attr_from_item(
-            &self.sess.parse_sess.attr_id_generator,
+            &self.sess.psess.attr_id_generator,
             item,
             tokens,
             attr.style,
             item_span,
         );
         if attr.has_name(sym::crate_type) {
-            self.sess.parse_sess.buffer_lint(
+            self.sess.psess.buffer_lint(
                 rustc_lint_defs::builtin::DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
                 attr.span,
                 ast::CRATE_NODE_ID,
@@ -339,7 +339,7 @@ impl<'a> StripUnconfigured<'a> {
             );
         }
         if attr.has_name(sym::crate_name) {
-            self.sess.parse_sess.buffer_lint(
+            self.sess.psess.buffer_lint(
                 rustc_lint_defs::builtin::DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
                 attr.span,
                 ast::CRATE_NODE_ID,
@@ -355,7 +355,7 @@ impl<'a> StripUnconfigured<'a> {
     }
 
     pub(crate) fn cfg_true(&self, attr: &Attribute) -> (bool, Option<MetaItem>) {
-        let meta_item = match validate_attr::parse_meta(&self.sess.parse_sess, attr) {
+        let meta_item = match validate_attr::parse_meta(&self.sess.psess, attr) {
             Ok(meta_item) => meta_item,
             Err(err) => {
                 err.emit();
diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs
index 9bc7b4bdd1e..8a01704b766 100644
--- a/compiler/rustc_expand/src/expand.rs
+++ b/compiler/rustc_expand/src/expand.rs
@@ -691,10 +691,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
                         // fixed prior to stabilization
                         // Fake tokens when we are invoking an inner attribute, and
                         // we are invoking it on an out-of-line module or crate.
-                        Annotatable::Crate(krate) => rustc_parse::fake_token_stream_for_crate(
-                            &self.cx.sess.parse_sess,
-                            krate,
-                        ),
+                        Annotatable::Crate(krate) => {
+                            rustc_parse::fake_token_stream_for_crate(&self.cx.sess.psess, krate)
+                        }
                         Annotatable::Item(item_inner)
                             if matches!(attr.style, AttrStyle::Inner)
                                 && matches!(
@@ -705,10 +704,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
                                     )
                                 ) =>
                         {
-                            rustc_parse::fake_token_stream_for_item(
-                                &self.cx.sess.parse_sess,
-                                item_inner,
-                            )
+                            rustc_parse::fake_token_stream_for_item(&self.cx.sess.psess, item_inner)
                         }
                         _ => item.to_tokens(),
                     };
@@ -728,7 +724,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
                     }
                 }
                 SyntaxExtensionKind::LegacyAttr(expander) => {
-                    match validate_attr::parse_meta(&self.cx.sess.parse_sess, &attr) {
+                    match validate_attr::parse_meta(&self.cx.sess.psess, &attr) {
                         Ok(meta) => {
                             let items = match expander.expand(self.cx, span, &meta, item, false) {
                                 ExpandResult::Ready(items) => items,
@@ -962,8 +958,8 @@ pub fn ensure_complete_parse<'a>(
         // Avoid emitting backtrace info twice.
         let def_site_span = parser.token.span.with_ctxt(SyntaxContext::root());
 
-        let semi_span = parser.sess.source_map().next_point(span);
-        let add_semicolon = match &parser.sess.source_map().span_to_snippet(semi_span) {
+        let semi_span = parser.psess.source_map().next_point(span);
+        let add_semicolon = match &parser.psess.source_map().span_to_snippet(semi_span) {
             Ok(snippet) if &snippet[..] != ";" && kind_name == "expression" => {
                 Some(span.shrink_to_hi())
             }
@@ -1700,7 +1696,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
         let mut span: Option<Span> = None;
         while let Some(attr) = attrs.next() {
             rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
-            validate_attr::check_attr(&self.cx.sess.parse_sess, attr);
+            validate_attr::check_attr(&self.cx.sess.psess, attr);
 
             let current_span = if let Some(sp) = span { sp.to(attr.span) } else { attr.span };
             span = Some(current_span);
@@ -1710,7 +1706,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
             }
 
             if attr.is_doc_comment() {
-                self.cx.sess.parse_sess.buffer_lint_with_diagnostic(
+                self.cx.sess.psess.buffer_lint_with_diagnostic(
                     UNUSED_DOC_COMMENTS,
                     current_span,
                     self.cx.current_expansion.lint_node_id,
@@ -1722,7 +1718,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
                 // `#[cfg]` and `#[cfg_attr]` are special - they are
                 // eagerly evaluated.
                 if attr_name != sym::cfg && attr_name != sym::cfg_attr {
-                    self.cx.sess.parse_sess.buffer_lint_with_diagnostic(
+                    self.cx.sess.psess.buffer_lint_with_diagnostic(
                         UNUSED_ATTRIBUTES,
                         attr.span,
                         self.cx.current_expansion.lint_node_id,
diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs
index 053063b690e..d8b8a0fa96a 100644
--- a/compiler/rustc_expand/src/mbe/diagnostics.rs
+++ b/compiler/rustc_expand/src/mbe/diagnostics.rs
@@ -24,12 +24,12 @@ pub(super) fn failed_to_match_macro<'cx>(
     arg: TokenStream,
     lhses: &[Vec<MatcherLoc>],
 ) -> Box<dyn MacResult + 'cx> {
-    let sess = &cx.sess.parse_sess;
+    let psess = &cx.sess.psess;
 
     // An error occurred, try the expansion again, tracking the expansion closely for better diagnostics.
     let mut tracker = CollectTrackerAndEmitter::new(cx, sp);
 
-    let try_success_result = try_match_macro(sess, name, &arg, lhses, &mut tracker);
+    let try_success_result = try_match_macro(psess, name, &arg, lhses, &mut tracker);
 
     if try_success_result.is_ok() {
         // Nonterminal parser recovery might turn failed matches into successful ones,
@@ -58,7 +58,7 @@ pub(super) fn failed_to_match_macro<'cx>(
         err.span_label(cx.source_map().guess_head_span(def_span), "when calling this macro");
     }
 
-    annotate_doc_comment(cx.sess.dcx(), &mut err, sess.source_map(), span);
+    annotate_doc_comment(cx.sess.dcx(), &mut err, psess.source_map(), span);
 
     if let Some(span) = remaining_matcher.span() {
         err.span_note(span, format!("while trying to match {remaining_matcher}"));
@@ -87,7 +87,7 @@ pub(super) fn failed_to_match_macro<'cx>(
     // Check whether there's a missing comma in this macro call, like `println!("{}" a);`
     if let Some((arg, comma_span)) = arg.add_comma() {
         for lhs in lhses {
-            let parser = parser_from_cx(sess, arg.clone(), Recovery::Allowed);
+            let parser = parser_from_cx(psess, arg.clone(), Recovery::Allowed);
             let mut tt_parser = TtParser::new(name);
 
             if let Success(_) =
@@ -246,10 +246,10 @@ pub(super) fn emit_frag_parse_err(
     if e.span.is_dummy() {
         // Get around lack of span in error (#30128)
         e.replace_span_with(site_span, true);
-        if !parser.sess.source_map().is_imported(arm_span) {
+        if !parser.psess.source_map().is_imported(arm_span) {
             e.span_label(arm_span, "in this macro arm");
         }
-    } else if parser.sess.source_map().is_imported(parser.token.span) {
+    } else if parser.psess.source_map().is_imported(parser.token.span) {
         e.span_label(site_span, "in this macro invocation");
     }
     match kind {
@@ -262,7 +262,7 @@ pub(super) fn emit_frag_parse_err(
                 );
 
                 if parser.token == token::Semi {
-                    if let Ok(snippet) = parser.sess.source_map().span_to_snippet(site_span) {
+                    if let Ok(snippet) = parser.psess.source_map().span_to_snippet(site_span) {
                         e.span_suggestion_verbose(
                             site_span,
                             "surround the macro invocation with `{}` to interpret the expansion as a statement",
diff --git a/compiler/rustc_expand/src/mbe/macro_check.rs b/compiler/rustc_expand/src/mbe/macro_check.rs
index 8174cb03d33..19405dcfd6c 100644
--- a/compiler/rustc_expand/src/mbe/macro_check.rs
+++ b/compiler/rustc_expand/src/mbe/macro_check.rs
@@ -193,25 +193,25 @@ struct MacroState<'a> {
 /// Checks that meta-variables are used correctly in a macro definition.
 ///
 /// Arguments:
-/// - `sess` is used to emit diagnostics and lints
+/// - `psess` is used to emit diagnostics and lints
 /// - `node_id` is used to emit lints
 /// - `span` is used when no spans are available
 /// - `lhses` and `rhses` should have the same length and represent the macro definition
 pub(super) fn check_meta_variables(
-    sess: &ParseSess,
+    psess: &ParseSess,
     node_id: NodeId,
     span: Span,
     lhses: &[TokenTree],
     rhses: &[TokenTree],
 ) -> Result<(), ErrorGuaranteed> {
     if lhses.len() != rhses.len() {
-        sess.dcx.span_bug(span, "length mismatch between LHSes and RHSes")
+        psess.dcx.span_bug(span, "length mismatch between LHSes and RHSes")
     }
     let mut guar = None;
     for (lhs, rhs) in iter::zip(lhses, rhses) {
         let mut binders = Binders::default();
-        check_binders(sess, node_id, lhs, &Stack::Empty, &mut binders, &Stack::Empty, &mut guar);
-        check_occurrences(sess, node_id, rhs, &Stack::Empty, &binders, &Stack::Empty, &mut guar);
+        check_binders(psess, node_id, lhs, &Stack::Empty, &mut binders, &Stack::Empty, &mut guar);
+        check_occurrences(psess, node_id, rhs, &Stack::Empty, &binders, &Stack::Empty, &mut guar);
     }
     guar.map_or(Ok(()), Err)
 }
@@ -220,7 +220,7 @@ pub(super) fn check_meta_variables(
 /// sets `valid` to false in case of errors.
 ///
 /// Arguments:
-/// - `sess` is used to emit diagnostics and lints
+/// - `psess` is used to emit diagnostics and lints
 /// - `node_id` is used to emit lints
 /// - `lhs` is checked as part of a LHS
 /// - `macros` is the stack of possible outer macros
@@ -228,7 +228,7 @@ pub(super) fn check_meta_variables(
 /// - `ops` is the stack of Kleene operators from the LHS
 /// - `guar` is set in case of errors
 fn check_binders(
-    sess: &ParseSess,
+    psess: &ParseSess,
     node_id: NodeId,
     lhs: &TokenTree,
     macros: &Stack<'_, MacroState<'_>>,
@@ -244,7 +244,7 @@ fn check_binders(
         // MetaVar(fragment) and not as MetaVarDecl(y, fragment).
         TokenTree::MetaVar(span, name) => {
             if macros.is_empty() {
-                sess.dcx.span_bug(span, "unexpected MetaVar in lhs");
+                psess.dcx.span_bug(span, "unexpected MetaVar in lhs");
             }
             let name = MacroRulesNormalizedIdent::new(name);
             // There are 3 possibilities:
@@ -252,13 +252,13 @@ fn check_binders(
                 // 1. The meta-variable is already bound in the current LHS: This is an error.
                 let mut span = MultiSpan::from_span(span);
                 span.push_span_label(prev_info.span, "previous declaration");
-                buffer_lint(sess, span, node_id, "duplicate matcher binding");
+                buffer_lint(psess, span, node_id, "duplicate matcher binding");
             } else if get_binder_info(macros, binders, name).is_none() {
                 // 2. The meta-variable is free: This is a binder.
                 binders.insert(name, BinderInfo { span, ops: ops.into() });
             } else {
                 // 3. The meta-variable is bound: This is an occurrence.
-                check_occurrences(sess, node_id, lhs, macros, binders, ops, guar);
+                check_occurrences(psess, node_id, lhs, macros, binders, ops, guar);
             }
         }
         // Similarly, this can only happen when checking a toplevel macro.
@@ -267,7 +267,7 @@ fn check_binders(
                 // FIXME: Report this as a hard error eventually and remove equivalent errors from
                 // `parse_tt_inner` and `nameize`. Until then the error may be reported twice, once
                 // as a hard error and then once as a buffered lint.
-                sess.buffer_lint(
+                psess.buffer_lint(
                     MISSING_FRAGMENT_SPECIFIER,
                     span,
                     node_id,
@@ -275,14 +275,15 @@ fn check_binders(
                 );
             }
             if !macros.is_empty() {
-                sess.dcx.span_bug(span, "unexpected MetaVarDecl in nested lhs");
+                psess.dcx.span_bug(span, "unexpected MetaVarDecl in nested lhs");
             }
             let name = MacroRulesNormalizedIdent::new(name);
             if let Some(prev_info) = get_binder_info(macros, binders, name) {
                 // Duplicate binders at the top-level macro definition are errors. The lint is only
                 // for nested macro definitions.
                 *guar = Some(
-                    sess.dcx
+                    psess
+                        .dcx
                         .emit_err(errors::DuplicateMatcherBinding { span, prev: prev_info.span }),
                 );
             } else {
@@ -293,13 +294,13 @@ fn check_binders(
         TokenTree::MetaVarExpr(..) => {}
         TokenTree::Delimited(.., ref del) => {
             for tt in &del.tts {
-                check_binders(sess, node_id, tt, macros, binders, ops, guar);
+                check_binders(psess, node_id, tt, macros, binders, ops, guar);
             }
         }
         TokenTree::Sequence(_, ref seq) => {
             let ops = ops.push(seq.kleene);
             for tt in &seq.tts {
-                check_binders(sess, node_id, tt, macros, binders, &ops, guar);
+                check_binders(psess, node_id, tt, macros, binders, &ops, guar);
             }
         }
     }
@@ -323,7 +324,7 @@ fn get_binder_info<'a>(
 /// errors.
 ///
 /// Arguments:
-/// - `sess` is used to emit diagnostics and lints
+/// - `psess` is used to emit diagnostics and lints
 /// - `node_id` is used to emit lints
 /// - `rhs` is checked as part of a RHS
 /// - `macros` is the stack of possible outer macros
@@ -331,7 +332,7 @@ fn get_binder_info<'a>(
 /// - `ops` is the stack of Kleene operators from the RHS
 /// - `guar` is set in case of errors
 fn check_occurrences(
-    sess: &ParseSess,
+    psess: &ParseSess,
     node_id: NodeId,
     rhs: &TokenTree,
     macros: &Stack<'_, MacroState<'_>>,
@@ -342,24 +343,24 @@ fn check_occurrences(
     match *rhs {
         TokenTree::Token(..) => {}
         TokenTree::MetaVarDecl(span, _name, _kind) => {
-            sess.dcx.span_bug(span, "unexpected MetaVarDecl in rhs")
+            psess.dcx.span_bug(span, "unexpected MetaVarDecl in rhs")
         }
         TokenTree::MetaVar(span, name) => {
             let name = MacroRulesNormalizedIdent::new(name);
-            check_ops_is_prefix(sess, node_id, macros, binders, ops, span, name);
+            check_ops_is_prefix(psess, node_id, macros, binders, ops, span, name);
         }
         TokenTree::MetaVarExpr(dl, ref mve) => {
             let Some(name) = mve.ident().map(MacroRulesNormalizedIdent::new) else {
                 return;
             };
-            check_ops_is_prefix(sess, node_id, macros, binders, ops, dl.entire(), name);
+            check_ops_is_prefix(psess, node_id, macros, binders, ops, dl.entire(), name);
         }
         TokenTree::Delimited(.., ref del) => {
-            check_nested_occurrences(sess, node_id, &del.tts, macros, binders, ops, guar);
+            check_nested_occurrences(psess, node_id, &del.tts, macros, binders, ops, guar);
         }
         TokenTree::Sequence(_, ref seq) => {
             let ops = ops.push(seq.kleene);
-            check_nested_occurrences(sess, node_id, &seq.tts, macros, binders, &ops, guar);
+            check_nested_occurrences(psess, node_id, &seq.tts, macros, binders, &ops, guar);
         }
     }
 }
@@ -388,7 +389,7 @@ enum NestedMacroState {
 /// definitions, and sets `valid` to false in case of errors.
 ///
 /// Arguments:
-/// - `sess` is used to emit diagnostics and lints
+/// - `psess` is used to emit diagnostics and lints
 /// - `node_id` is used to emit lints
 /// - `tts` is checked as part of a RHS and may contain macro definitions
 /// - `macros` is the stack of possible outer macros
@@ -396,7 +397,7 @@ enum NestedMacroState {
 /// - `ops` is the stack of Kleene operators from the RHS
 /// - `guar` is set in case of errors
 fn check_nested_occurrences(
-    sess: &ParseSess,
+    psess: &ParseSess,
     node_id: NodeId,
     tts: &[TokenTree],
     macros: &Stack<'_, MacroState<'_>>,
@@ -434,7 +435,7 @@ fn check_nested_occurrences(
             (NestedMacroState::MacroRulesNot, &TokenTree::MetaVar(..)) => {
                 state = NestedMacroState::MacroRulesNotName;
                 // We check that the meta-variable is correctly used.
-                check_occurrences(sess, node_id, tt, macros, binders, ops, guar);
+                check_occurrences(psess, node_id, tt, macros, binders, ops, guar);
             }
             (NestedMacroState::MacroRulesNotName, TokenTree::Delimited(.., del))
             | (NestedMacroState::MacroName, TokenTree::Delimited(.., del))
@@ -443,11 +444,11 @@ fn check_nested_occurrences(
                 let macro_rules = state == NestedMacroState::MacroRulesNotName;
                 state = NestedMacroState::Empty;
                 let rest =
-                    check_nested_macro(sess, node_id, macro_rules, &del.tts, &nested_macros, guar);
+                    check_nested_macro(psess, node_id, macro_rules, &del.tts, &nested_macros, guar);
                 // If we did not check the whole macro definition, then check the rest as if outside
                 // the macro definition.
                 check_nested_occurrences(
-                    sess,
+                    psess,
                     node_id,
                     &del.tts[rest..],
                     macros,
@@ -465,7 +466,7 @@ fn check_nested_occurrences(
             (NestedMacroState::Macro, &TokenTree::MetaVar(..)) => {
                 state = NestedMacroState::MacroName;
                 // We check that the meta-variable is correctly used.
-                check_occurrences(sess, node_id, tt, macros, binders, ops, guar);
+                check_occurrences(psess, node_id, tt, macros, binders, ops, guar);
             }
             (NestedMacroState::MacroName, TokenTree::Delimited(.., del))
                 if del.delim == Delimiter::Parenthesis =>
@@ -473,7 +474,7 @@ fn check_nested_occurrences(
                 state = NestedMacroState::MacroNameParen;
                 nested_binders = Binders::default();
                 check_binders(
-                    sess,
+                    psess,
                     node_id,
                     tt,
                     &nested_macros,
@@ -487,7 +488,7 @@ fn check_nested_occurrences(
             {
                 state = NestedMacroState::Empty;
                 check_occurrences(
-                    sess,
+                    psess,
                     node_id,
                     tt,
                     &nested_macros,
@@ -498,7 +499,7 @@ fn check_nested_occurrences(
             }
             (_, tt) => {
                 state = NestedMacroState::Empty;
-                check_occurrences(sess, node_id, tt, macros, binders, ops, guar);
+                check_occurrences(psess, node_id, tt, macros, binders, ops, guar);
             }
         }
     }
@@ -512,14 +513,14 @@ fn check_nested_occurrences(
 /// stopped checking because we detected we were not in a macro definition anymore.
 ///
 /// Arguments:
-/// - `sess` is used to emit diagnostics and lints
+/// - `psess` is used to emit diagnostics and lints
 /// - `node_id` is used to emit lints
 /// - `macro_rules` specifies whether the macro is `macro_rules`
 /// - `tts` is checked as a list of (LHS) => {RHS}
 /// - `macros` is the stack of outer macros
 /// - `guar` is set in case of errors
 fn check_nested_macro(
-    sess: &ParseSess,
+    psess: &ParseSess,
     node_id: NodeId,
     macro_rules: bool,
     tts: &[TokenTree],
@@ -541,8 +542,8 @@ fn check_nested_macro(
         let lhs = &tts[i];
         let rhs = &tts[i + 2];
         let mut binders = Binders::default();
-        check_binders(sess, node_id, lhs, macros, &mut binders, &Stack::Empty, guar);
-        check_occurrences(sess, node_id, rhs, macros, &binders, &Stack::Empty, guar);
+        check_binders(psess, node_id, lhs, macros, &mut binders, &Stack::Empty, guar);
+        check_occurrences(psess, node_id, rhs, macros, &binders, &Stack::Empty, guar);
         // Since the last semicolon is optional for `macro_rules` macros and decl_macro are not terminated,
         // we increment our checked position by how many token trees we already checked (the 3
         // above) before checking for the separator.
@@ -559,7 +560,7 @@ fn check_nested_macro(
 /// Checks that a meta-variable occurrence is valid.
 ///
 /// Arguments:
-/// - `sess` is used to emit diagnostics and lints
+/// - `psess` is used to emit diagnostics and lints
 /// - `node_id` is used to emit lints
 /// - `macros` is the stack of possible outer macros
 /// - `binders` contains the binders of the associated LHS
@@ -567,7 +568,7 @@ fn check_nested_macro(
 /// - `span` is the span of the meta-variable to check
 /// - `name` is the name of the meta-variable to check
 fn check_ops_is_prefix(
-    sess: &ParseSess,
+    psess: &ParseSess,
     node_id: NodeId,
     macros: &Stack<'_, MacroState<'_>>,
     binders: &Binders,
@@ -590,11 +591,11 @@ fn check_ops_is_prefix(
             for ops in acc.iter().rev() {
                 occurrence_ops.extend_from_slice(ops);
             }
-            ops_is_prefix(sess, node_id, span, name, &binder.ops, &occurrence_ops);
+            ops_is_prefix(psess, node_id, span, name, &binder.ops, &occurrence_ops);
             return;
         }
     }
-    buffer_lint(sess, span.into(), node_id, format!("unknown macro variable `{name}`"));
+    buffer_lint(psess, span.into(), node_id, format!("unknown macro variable `{name}`"));
 }
 
 /// Returns whether `binder_ops` is a prefix of `occurrence_ops`.
@@ -609,14 +610,14 @@ fn check_ops_is_prefix(
 /// It occurs under the Kleene stack ["*", "+"] and is bound under ["*"] only.
 ///
 /// Arguments:
-/// - `sess` is used to emit diagnostics and lints
+/// - `psess` is used to emit diagnostics and lints
 /// - `node_id` is used to emit lints
 /// - `span` is the span of the meta-variable being check
 /// - `name` is the name of the meta-variable being check
 /// - `binder_ops` is the stack of Kleene operators for the binder
 /// - `occurrence_ops` is the stack of Kleene operators for the occurrence
 fn ops_is_prefix(
-    sess: &ParseSess,
+    psess: &ParseSess,
     node_id: NodeId,
     span: Span,
     name: MacroRulesNormalizedIdent,
@@ -628,7 +629,7 @@ fn ops_is_prefix(
             let mut span = MultiSpan::from_span(span);
             span.push_span_label(binder.span, "expected repetition");
             let message = format!("variable '{name}' is still repeating at this depth");
-            buffer_lint(sess, span, node_id, message);
+            buffer_lint(psess, span, node_id, message);
             return;
         }
         let occurrence = &occurrence_ops[i];
@@ -637,20 +638,20 @@ fn ops_is_prefix(
             span.push_span_label(binder.span, "expected repetition");
             span.push_span_label(occurrence.span, "conflicting repetition");
             let message = "meta-variable repeats with different Kleene operator";
-            buffer_lint(sess, span, node_id, message);
+            buffer_lint(psess, span, node_id, message);
             return;
         }
     }
 }
 
 fn buffer_lint(
-    sess: &ParseSess,
+    psess: &ParseSess,
     span: MultiSpan,
     node_id: NodeId,
     message: impl Into<DiagnosticMessage>,
 ) {
     // Macros loaded from other crates have dummy node ids.
     if node_id != DUMMY_NODE_ID {
-        sess.buffer_lint(META_VARIABLE_MISUSE, span, node_id, message);
+        psess.buffer_lint(META_VARIABLE_MISUSE, span, node_id, message);
     }
 }
diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs
index c11d538048a..c8631d96810 100644
--- a/compiler/rustc_expand/src/mbe/macro_rules.rs
+++ b/compiler/rustc_expand/src/mbe/macro_rules.rs
@@ -78,7 +78,7 @@ impl<'a> ParserAnyMacro<'a> {
         // but `m!()` is allowed in expression positions (cf. issue #34706).
         if kind == AstFragmentKind::Expr && parser.token == token::Semi {
             if is_local {
-                parser.sess.buffer_lint_with_diagnostic(
+                parser.psess.buffer_lint_with_diagnostic(
                     SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
                     parser.token.span,
                     lint_node_id,
@@ -195,7 +195,7 @@ fn expand_macro<'cx>(
     lhses: &[Vec<MatcherLoc>],
     rhses: &[mbe::TokenTree],
 ) -> Box<dyn MacResult + 'cx> {
-    let sess = &cx.sess.parse_sess;
+    let psess = &cx.sess.psess;
     // Macros defined in the current crate have a real node id,
     // whereas macros from an external crate have a dummy id.
     let is_local = node_id != DUMMY_NODE_ID;
@@ -206,7 +206,7 @@ fn expand_macro<'cx>(
     }
 
     // Track nothing for the best performance.
-    let try_success_result = try_match_macro(sess, name, &arg, lhses, &mut NoopTracker);
+    let try_success_result = try_match_macro(psess, name, &arg, lhses, &mut NoopTracker);
 
     match try_success_result {
         Ok((i, named_matches)) => {
@@ -230,7 +230,7 @@ fn expand_macro<'cx>(
                 trace_macros_note(&mut cx.expansions, sp, msg);
             }
 
-            let p = Parser::new(sess, tts, None);
+            let p = Parser::new(psess, tts, None);
 
             if is_local {
                 cx.resolver.record_macro_rule_usage(node_id, i);
@@ -272,9 +272,9 @@ pub(super) enum CanRetry {
 /// Try expanding the macro. Returns the index of the successful arm and its named_matches if it was successful,
 /// and nothing if it failed. On failure, it's the callers job to use `track` accordingly to record all errors
 /// correctly.
-#[instrument(level = "debug", skip(sess, arg, lhses, track), fields(tracking = %T::description()))]
+#[instrument(level = "debug", skip(psess, arg, lhses, track), fields(tracking = %T::description()))]
 pub(super) fn try_match_macro<'matcher, T: Tracker<'matcher>>(
-    sess: &ParseSess,
+    psess: &ParseSess,
     name: Ident,
     arg: &TokenStream,
     lhses: &'matcher [Vec<MatcherLoc>],
@@ -299,7 +299,7 @@ pub(super) fn try_match_macro<'matcher, T: Tracker<'matcher>>(
     // hacky, but speeds up the `html5ever` benchmark significantly. (Issue
     // 68836 suggests a more comprehensive but more complex change to deal with
     // this situation.)
-    let parser = parser_from_cx(sess, arg.clone(), T::recovery());
+    let parser = parser_from_cx(psess, arg.clone(), T::recovery());
     // Try each arm's matchers.
     let mut tt_parser = TtParser::new(name);
     for (i, lhs) in lhses.iter().enumerate() {
@@ -309,7 +309,7 @@ pub(super) fn try_match_macro<'matcher, T: Tracker<'matcher>>(
         // This is used so that if a matcher is not `Success(..)`ful,
         // then the spans which became gated when parsing the unsuccessful matcher
         // are not recorded. On the first `Success(..)`ful matcher, the spans are merged.
-        let mut gated_spans_snapshot = mem::take(&mut *sess.gated_spans.spans.borrow_mut());
+        let mut gated_spans_snapshot = mem::take(&mut *psess.gated_spans.spans.borrow_mut());
 
         let result = tt_parser.parse_tt(&mut Cow::Borrowed(&parser), lhs, track);
 
@@ -320,7 +320,7 @@ pub(super) fn try_match_macro<'matcher, T: Tracker<'matcher>>(
                 debug!("Parsed arm successfully");
                 // The matcher was `Success(..)`ful.
                 // Merge the gated spans from parsing the matcher with the preexisting ones.
-                sess.gated_spans.merge(gated_spans_snapshot);
+                psess.gated_spans.merge(gated_spans_snapshot);
 
                 return Ok((i, named_matches));
             }
@@ -342,7 +342,7 @@ pub(super) fn try_match_macro<'matcher, T: Tracker<'matcher>>(
 
         // The matcher was not `Success(..)`ful.
         // Restore to the state before snapshotting and maybe try again.
-        mem::swap(&mut gated_spans_snapshot, &mut sess.gated_spans.spans.borrow_mut());
+        mem::swap(&mut gated_spans_snapshot, &mut psess.gated_spans.spans.borrow_mut());
     }
 
     Err(CanRetry::Yes)
@@ -376,7 +376,7 @@ pub fn compile_declarative_macro(
     };
     let dummy_syn_ext = |guar| (mk_syn_ext(Box::new(DummyExpander(guar))), Vec::new());
 
-    let dcx = &sess.parse_sess.dcx;
+    let dcx = &sess.psess.dcx;
     let lhs_nm = Ident::new(sym::lhs, def.span);
     let rhs_nm = Ident::new(sym::rhs, def.span);
     let tt_spec = Some(NonterminalKind::TT);
@@ -430,7 +430,7 @@ pub fn compile_declarative_macro(
 
     let create_parser = || {
         let body = macro_def.body.tokens.clone();
-        Parser::new(&sess.parse_sess, body, rustc_parse::MACRO_ARGUMENTS)
+        Parser::new(&sess.psess, body, rustc_parse::MACRO_ARGUMENTS)
     };
 
     let parser = create_parser();
@@ -533,7 +533,7 @@ pub fn compile_declarative_macro(
     }
 
     check_emission(macro_check::check_meta_variables(
-        &sess.parse_sess,
+        &sess.psess,
         def.id,
         def.span,
         &lhses,
@@ -1149,7 +1149,7 @@ fn check_matcher_core<'tt>(
                             name,
                             Some(NonterminalKind::PatParam { inferred: false }),
                         ));
-                        sess.parse_sess.buffer_lint_with_diagnostic(
+                        sess.psess.buffer_lint_with_diagnostic(
                             RUST_2021_INCOMPATIBLE_OR_PATTERNS,
                             span,
                             ast::CRATE_NODE_ID,
@@ -1182,7 +1182,7 @@ fn check_matcher_core<'tt>(
                             err.span_label(sp, format!("not allowed after `{kind}` fragments"));
 
                             if kind == NonterminalKind::PatWithOr
-                                && sess.parse_sess.edition.at_least_rust_2021()
+                                && sess.psess.edition.at_least_rust_2021()
                                 && next_token.is_token(&BinOp(token::BinOpToken::Or))
                             {
                                 let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl(
@@ -1406,10 +1406,10 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String {
 }
 
 pub(super) fn parser_from_cx(
-    sess: &ParseSess,
+    psess: &ParseSess,
     mut tts: TokenStream,
     recovery: Recovery,
 ) -> Parser<'_> {
     tts.desugar_doc_comments();
-    Parser::new(sess, tts, rustc_parse::MACRO_ARGUMENTS).recovery(recovery)
+    Parser::new(psess, tts, rustc_parse::MACRO_ARGUMENTS).recovery(recovery)
 }
diff --git a/compiler/rustc_expand/src/mbe/metavar_expr.rs b/compiler/rustc_expand/src/mbe/metavar_expr.rs
index 84f7dc4771a..81e1de5b095 100644
--- a/compiler/rustc_expand/src/mbe/metavar_expr.rs
+++ b/compiler/rustc_expand/src/mbe/metavar_expr.rs
@@ -27,30 +27,30 @@ pub(crate) enum MetaVarExpr {
 
 impl MetaVarExpr {
     /// Attempt to parse a meta-variable expression from a token stream.
-    pub(crate) fn parse<'sess>(
+    pub(crate) fn parse<'psess>(
         input: &TokenStream,
         outer_span: Span,
-        sess: &'sess ParseSess,
-    ) -> PResult<'sess, MetaVarExpr> {
+        psess: &'psess ParseSess,
+    ) -> PResult<'psess, MetaVarExpr> {
         let mut tts = input.trees();
-        let ident = parse_ident(&mut tts, sess, outer_span)?;
+        let ident = parse_ident(&mut tts, psess, outer_span)?;
         let Some(TokenTree::Delimited(.., Delimiter::Parenthesis, args)) = tts.next() else {
             let msg = "meta-variable expression parameter must be wrapped in parentheses";
-            return Err(sess.dcx.struct_span_err(ident.span, msg));
+            return Err(psess.dcx.struct_span_err(ident.span, msg));
         };
-        check_trailing_token(&mut tts, sess)?;
+        check_trailing_token(&mut tts, psess)?;
         let mut iter = args.trees();
         let rslt = match ident.as_str() {
-            "count" => parse_count(&mut iter, sess, ident.span)?,
+            "count" => parse_count(&mut iter, psess, ident.span)?,
             "ignore" => {
-                eat_dollar(&mut iter, sess, ident.span)?;
-                MetaVarExpr::Ignore(parse_ident(&mut iter, sess, ident.span)?)
+                eat_dollar(&mut iter, psess, ident.span)?;
+                MetaVarExpr::Ignore(parse_ident(&mut iter, psess, ident.span)?)
             }
-            "index" => MetaVarExpr::Index(parse_depth(&mut iter, sess, ident.span)?),
-            "length" => MetaVarExpr::Length(parse_depth(&mut iter, sess, ident.span)?),
+            "index" => MetaVarExpr::Index(parse_depth(&mut iter, psess, ident.span)?),
+            "length" => MetaVarExpr::Length(parse_depth(&mut iter, psess, ident.span)?),
             _ => {
                 let err_msg = "unrecognized meta-variable expression";
-                let mut err = sess.dcx.struct_span_err(ident.span, err_msg);
+                let mut err = psess.dcx.struct_span_err(ident.span, err_msg);
                 err.span_suggestion(
                     ident.span,
                     "supported expressions are count, ignore, index and length",
@@ -60,7 +60,7 @@ impl MetaVarExpr {
                 return Err(err);
             }
         };
-        check_trailing_token(&mut iter, sess)?;
+        check_trailing_token(&mut iter, psess)?;
         Ok(rslt)
     }
 
@@ -73,12 +73,12 @@ impl MetaVarExpr {
 }
 
 // Checks if there are any remaining tokens. For example, `${ignore(ident ... a b c ...)}`
-fn check_trailing_token<'sess>(
+fn check_trailing_token<'psess>(
     iter: &mut RefTokenTreeCursor<'_>,
-    sess: &'sess ParseSess,
-) -> PResult<'sess, ()> {
+    psess: &'psess ParseSess,
+) -> PResult<'psess, ()> {
     if let Some(tt) = iter.next() {
-        let mut diag = sess
+        let mut diag = psess
             .dcx
             .struct_span_err(tt.span(), format!("unexpected token: {}", pprust::tt_to_string(tt)));
         diag.span_note(tt.span(), "meta-variable expression must not have trailing tokens");
@@ -89,21 +89,21 @@ fn check_trailing_token<'sess>(
 }
 
 /// Parse a meta-variable `count` expression: `count(ident[, depth])`
-fn parse_count<'sess>(
+fn parse_count<'psess>(
     iter: &mut RefTokenTreeCursor<'_>,
-    sess: &'sess ParseSess,
+    psess: &'psess ParseSess,
     span: Span,
-) -> PResult<'sess, MetaVarExpr> {
-    eat_dollar(iter, sess, span)?;
-    let ident = parse_ident(iter, sess, span)?;
+) -> PResult<'psess, MetaVarExpr> {
+    eat_dollar(iter, psess, span)?;
+    let ident = parse_ident(iter, psess, span)?;
     let depth = if try_eat_comma(iter) {
         if iter.look_ahead(0).is_none() {
-            return Err(sess.dcx.struct_span_err(
+            return Err(psess.dcx.struct_span_err(
                 span,
                 "`count` followed by a comma must have an associated index indicating its depth",
             ));
         }
-        parse_depth(iter, sess, span)?
+        parse_depth(iter, psess, span)?
     } else {
         0
     };
@@ -111,14 +111,14 @@ fn parse_count<'sess>(
 }
 
 /// Parses the depth used by index(depth) and length(depth).
-fn parse_depth<'sess>(
+fn parse_depth<'psess>(
     iter: &mut RefTokenTreeCursor<'_>,
-    sess: &'sess ParseSess,
+    psess: &'psess ParseSess,
     span: Span,
-) -> PResult<'sess, usize> {
+) -> PResult<'psess, usize> {
     let Some(tt) = iter.next() else { return Ok(0) };
     let TokenTree::Token(token::Token { kind: token::TokenKind::Literal(lit), .. }, _) = tt else {
-        return Err(sess
+        return Err(psess
             .dcx
             .struct_span_err(span, "meta-variable expression depth must be a literal"));
     };
@@ -129,16 +129,16 @@ fn parse_depth<'sess>(
         Ok(n_usize)
     } else {
         let msg = "only unsuffixes integer literals are supported in meta-variable expressions";
-        Err(sess.dcx.struct_span_err(span, msg))
+        Err(psess.dcx.struct_span_err(span, msg))
     }
 }
 
 /// Parses an generic ident
-fn parse_ident<'sess>(
+fn parse_ident<'psess>(
     iter: &mut RefTokenTreeCursor<'_>,
-    sess: &'sess ParseSess,
+    psess: &'psess ParseSess,
     span: Span,
-) -> PResult<'sess, Ident> {
+) -> PResult<'psess, Ident> {
     if let Some(tt) = iter.next()
         && let TokenTree::Token(token, _) = tt
     {
@@ -147,7 +147,7 @@ fn parse_ident<'sess>(
         }
         let token_str = pprust::token_to_string(token);
         let mut err =
-            sess.dcx.struct_span_err(span, format!("expected identifier, found `{}`", &token_str));
+            psess.dcx.struct_span_err(span, format!("expected identifier, found `{}`", &token_str));
         err.span_suggestion(
             token.span,
             format!("try removing `{}`", &token_str),
@@ -156,7 +156,7 @@ fn parse_ident<'sess>(
         );
         return Err(err);
     }
-    Err(sess.dcx.struct_span_err(span, "expected identifier"))
+    Err(psess.dcx.struct_span_err(span, "expected identifier"))
 }
 
 /// Tries to move the iterator forward returning `true` if there is a comma. If not, then the
@@ -170,17 +170,17 @@ fn try_eat_comma(iter: &mut RefTokenTreeCursor<'_>) -> bool {
 }
 
 /// Expects that the next item is a dollar sign.
-fn eat_dollar<'sess>(
+fn eat_dollar<'psess>(
     iter: &mut RefTokenTreeCursor<'_>,
-    sess: &'sess ParseSess,
+    psess: &'psess ParseSess,
     span: Span,
-) -> PResult<'sess, ()> {
+) -> PResult<'psess, ()> {
     if let Some(TokenTree::Token(token::Token { kind: token::Dollar, .. }, _)) = iter.look_ahead(0)
     {
         let _ = iter.next();
         return Ok(());
     }
-    Err(sess.dcx.struct_span_err(
+    Err(psess.dcx.struct_span_err(
         span,
         "meta-variables within meta-variable expressions must be referenced using a dollar sign",
     ))
diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs
index ec1dd807d1a..5fd3716743b 100644
--- a/compiler/rustc_expand/src/mbe/quoted.rs
+++ b/compiler/rustc_expand/src/mbe/quoted.rs
@@ -175,8 +175,7 @@ fn parse_tree<'a>(
                                 // The delimiter is `{`. This indicates the beginning
                                 // of a meta-variable expression (e.g. `${count(ident)}`).
                                 // Try to parse the meta-variable expression.
-                                match MetaVarExpr::parse(tts, delim_span.entire(), &sess.parse_sess)
-                                {
+                                match MetaVarExpr::parse(tts, delim_span.entire(), &sess.psess) {
                                     Err(err) => {
                                         err.emit();
                                         // Returns early the same read `$` to avoid spanning
diff --git a/compiler/rustc_expand/src/module.rs b/compiler/rustc_expand/src/module.rs
index 1282cf2c03a..8a68b39e496 100644
--- a/compiler/rustc_expand/src/module.rs
+++ b/compiler/rustc_expand/src/module.rs
@@ -66,7 +66,7 @@ pub(crate) fn parse_external_mod(
         }
 
         // Actually parse the external file as a module.
-        let mut parser = new_parser_from_file(&sess.parse_sess, &mp.file_path, Some(span));
+        let mut parser = new_parser_from_file(&sess.psess, &mp.file_path, Some(span));
         let (inner_attrs, items, inner_span) =
             parser.parse_mod(&token::Eof).map_err(|err| ModError::ParserError(err))?;
         attrs.extend(inner_attrs);
@@ -157,7 +157,7 @@ fn mod_file_path<'a>(
         DirOwnership::Owned { relative } => relative,
         DirOwnership::UnownedViaBlock => None,
     };
-    let result = default_submod_path(&sess.parse_sess, ident, relative, dir_path);
+    let result = default_submod_path(&sess.psess, ident, relative, dir_path);
     match dir_ownership {
         DirOwnership::Owned { .. } => result,
         DirOwnership::UnownedViaBlock => Err(ModError::ModInBlock(match result {
@@ -185,11 +185,7 @@ fn mod_file_path_from_attr(
         // complexity). Usually bad forms are checked in AstValidator (via
         // `check_builtin_attribute`), but by the time that runs the macro
         // is expanded, and it doesn't give an error.
-        validate_attr::emit_fatal_malformed_builtin_attribute(
-            &sess.parse_sess,
-            first_path,
-            sym::path,
-        );
+        validate_attr::emit_fatal_malformed_builtin_attribute(&sess.psess, first_path, sym::path);
     };
 
     let path_str = path_sym.as_str();
@@ -207,7 +203,7 @@ fn mod_file_path_from_attr(
 /// Returns a path to a module.
 // Public for rustfmt usage.
 pub fn default_submod_path<'a>(
-    sess: &'a ParseSess,
+    psess: &'a ParseSess,
     ident: Ident,
     relative: Option<Ident>,
     dir_path: &Path,
@@ -229,8 +225,8 @@ pub fn default_submod_path<'a>(
         format!("{}{}{}mod.rs", relative_prefix, ident.name, path::MAIN_SEPARATOR);
     let default_path = dir_path.join(&default_path_str);
     let secondary_path = dir_path.join(&secondary_path_str);
-    let default_exists = sess.source_map().file_exists(&default_path);
-    let secondary_exists = sess.source_map().file_exists(&secondary_path);
+    let default_exists = psess.source_map().file_exists(&default_path);
+    let secondary_exists = psess.source_map().file_exists(&secondary_path);
 
     match (default_exists, secondary_exists) {
         (true, false) => Ok(ModulePathSuccess {
diff --git a/compiler/rustc_expand/src/parse/tests.rs b/compiler/rustc_expand/src/parse/tests.rs
index 5ffe8f3c73e..066afd7a41d 100644
--- a/compiler/rustc_expand/src/parse/tests.rs
+++ b/compiler/rustc_expand/src/parse/tests.rs
@@ -1,5 +1,5 @@
 use crate::tests::{
-    matches_codepattern, sess, string_to_stream, with_error_checking_parse,
+    matches_codepattern, psess, string_to_stream, with_error_checking_parse,
     with_expected_parse_error,
 };
 
@@ -26,9 +26,9 @@ use std::path::PathBuf;
 fn parse_item_from_source_str(
     name: FileName,
     source: String,
-    sess: &ParseSess,
+    psess: &ParseSess,
 ) -> PResult<'_, Option<P<ast::Item>>> {
-    new_parser_from_source_str(sess, name, source).parse_item(ForceCollect::No)
+    new_parser_from_source_str(psess, name, source).parse_item(ForceCollect::No)
 }
 
 // Produces a `rustc_span::span`.
@@ -38,12 +38,12 @@ fn sp(a: u32, b: u32) -> Span {
 
 /// Parses a string, return an expression.
 fn string_to_expr(source_str: String) -> P<ast::Expr> {
-    with_error_checking_parse(source_str, &sess(), |p| p.parse_expr())
+    with_error_checking_parse(source_str, &psess(), |p| p.parse_expr())
 }
 
 /// Parses a string, returns an item.
 fn string_to_item(source_str: String) -> Option<P<ast::Item>> {
-    with_error_checking_parse(source_str, &sess(), |p| p.parse_item(ForceCollect::No))
+    with_error_checking_parse(source_str, &psess(), |p| p.parse_item(ForceCollect::No))
 }
 
 #[test]
@@ -279,24 +279,24 @@ let mut fflags: c_int = wb();
 #[test]
 fn crlf_doc_comments() {
     create_default_session_globals_then(|| {
-        let sess = sess();
+        let psess = psess();
 
         let name_1 = FileName::Custom("crlf_source_1".to_string());
         let source = "/// doc comment\r\nfn foo() {}".to_string();
-        let item = parse_item_from_source_str(name_1, source, &sess).unwrap().unwrap();
+        let item = parse_item_from_source_str(name_1, source, &psess).unwrap().unwrap();
         let doc = item.attrs.iter().filter_map(|at| at.doc_str()).next().unwrap();
         assert_eq!(doc.as_str(), " doc comment");
 
         let name_2 = FileName::Custom("crlf_source_2".to_string());
         let source = "/// doc comment\r\n/// line 2\r\nfn foo() {}".to_string();
-        let item = parse_item_from_source_str(name_2, source, &sess).unwrap().unwrap();
+        let item = parse_item_from_source_str(name_2, source, &psess).unwrap().unwrap();
         let docs = item.attrs.iter().filter_map(|at| at.doc_str()).collect::<Vec<_>>();
         let b: &[_] = &[Symbol::intern(" doc comment"), Symbol::intern(" line 2")];
         assert_eq!(&docs[..], b);
 
         let name_3 = FileName::Custom("clrf_source_3".to_string());
         let source = "/** doc comment\r\n *  with CRLF */\r\nfn foo() {}".to_string();
-        let item = parse_item_from_source_str(name_3, source, &sess).unwrap().unwrap();
+        let item = parse_item_from_source_str(name_3, source, &psess).unwrap().unwrap();
         let doc = item.attrs.iter().filter_map(|at| at.doc_str()).next().unwrap();
         assert_eq!(doc.as_str(), " doc comment\n *  with CRLF ");
     });
@@ -307,24 +307,24 @@ fn ttdelim_span() {
     fn parse_expr_from_source_str(
         name: FileName,
         source: String,
-        sess: &ParseSess,
+        psess: &ParseSess,
     ) -> PResult<'_, P<ast::Expr>> {
-        new_parser_from_source_str(sess, name, source).parse_expr()
+        new_parser_from_source_str(psess, name, source).parse_expr()
     }
 
     create_default_session_globals_then(|| {
-        let sess = sess();
+        let psess = psess();
         let expr = parse_expr_from_source_str(
             PathBuf::from("foo").into(),
             "foo!( fn main() { body } )".to_string(),
-            &sess,
+            &psess,
         )
         .unwrap();
 
         let ast::ExprKind::MacCall(mac) = &expr.kind else { panic!("not a macro") };
         let span = mac.args.tokens.trees().last().unwrap().span();
 
-        match sess.source_map().span_to_snippet(span) {
+        match psess.source_map().span_to_snippet(span) {
             Ok(s) => assert_eq!(&s[..], "{ body }"),
             Err(_) => panic!("could not get snippet"),
         }
@@ -340,7 +340,7 @@ fn out_of_line_mod() {
         let item = parse_item_from_source_str(
             PathBuf::from("foo").into(),
             "mod foo { struct S; mod this_does_not_exist; }".to_owned(),
-            &sess(),
+            &psess(),
         )
         .unwrap()
         .unwrap();
diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs
index 23caf2f193a..4b5c148cb55 100644
--- a/compiler/rustc_expand/src/proc_macro.rs
+++ b/compiler/rustc_expand/src/proc_macro.rs
@@ -162,7 +162,7 @@ impl MultiItemModifier for DeriveProcMacro {
 
         let error_count_before = ecx.dcx().err_count();
         let mut parser =
-            rustc_parse::stream_to_parser(&ecx.sess.parse_sess, stream, Some("proc-macro derive"));
+            rustc_parse::stream_to_parser(&ecx.sess.psess, stream, Some("proc-macro derive"));
         let mut items = vec![];
 
         loop {
diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs
index 6fe0d611363..efe35c252d8 100644
--- a/compiler/rustc_expand/src/proc_macro_server.rs
+++ b/compiler/rustc_expand/src/proc_macro_server.rs
@@ -354,7 +354,7 @@ impl ToInternal<SmallVec<[tokenstream::TokenTree; 2]>>
                 )]
             }
             TokenTree::Ident(self::Ident { sym, is_raw, span }) => {
-                rustc.sess().symbol_gallery.insert(sym, span);
+                rustc.psess().symbol_gallery.insert(sym, span);
                 smallvec![tokenstream::TokenTree::token_alone(Ident(sym, is_raw.into()), span)]
             }
             TokenTree::Literal(self::Literal {
@@ -429,8 +429,8 @@ impl<'a, 'b> Rustc<'a, 'b> {
         }
     }
 
-    fn sess(&self) -> &ParseSess {
-        self.ecx.parse_sess()
+    fn psess(&self) -> &ParseSess {
+        self.ecx.psess()
     }
 }
 
@@ -448,19 +448,19 @@ impl server::FreeFunctions for Rustc<'_, '_> {
     }
 
     fn track_env_var(&mut self, var: &str, value: Option<&str>) {
-        self.sess()
+        self.psess()
             .env_depinfo
             .borrow_mut()
             .insert((Symbol::intern(var), value.map(Symbol::intern)));
     }
 
     fn track_path(&mut self, path: &str) {
-        self.sess().file_depinfo.borrow_mut().insert(Symbol::intern(path));
+        self.psess().file_depinfo.borrow_mut().insert(Symbol::intern(path));
     }
 
     fn literal_from_str(&mut self, s: &str) -> Result<Literal<Self::Span, Self::Symbol>, ()> {
         let name = FileName::proc_macro_source_code(s);
-        let mut parser = rustc_parse::new_parser_from_source_str(self.sess(), name, s.to_owned());
+        let mut parser = rustc_parse::new_parser_from_source_str(self.psess(), name, s.to_owned());
 
         let first_span = parser.token.span.data();
         let minus_present = parser.eat(&token::BinOp(token::Minus));
@@ -514,7 +514,7 @@ impl server::FreeFunctions for Rustc<'_, '_> {
     fn emit_diagnostic(&mut self, diagnostic: Diagnostic<Self::Span>) {
         let message = rustc_errors::DiagnosticMessage::from(diagnostic.message);
         let mut diag: Diag<'_, ()> =
-            Diag::new(&self.sess().dcx, diagnostic.level.to_internal(), message);
+            Diag::new(&self.psess().dcx, diagnostic.level.to_internal(), message);
         diag.span(MultiSpan::from_spans(diagnostic.spans));
         for child in diagnostic.children {
             diag.sub(child.level.to_internal(), child.message, MultiSpan::from_spans(child.spans));
@@ -532,7 +532,7 @@ impl server::TokenStream for Rustc<'_, '_> {
         parse_stream_from_source_str(
             FileName::proc_macro_source_code(src),
             src.to_string(),
-            self.sess(),
+            self.psess(),
             Some(self.call_site),
         )
     }
@@ -545,7 +545,7 @@ impl server::TokenStream for Rustc<'_, '_> {
         // Parse the expression from our tokenstream.
         let expr: PResult<'_, _> = try {
             let mut p = rustc_parse::stream_to_parser(
-                self.sess(),
+                self.psess(),
                 stream.clone(),
                 Some("proc_macro expand expr"),
             );
@@ -680,7 +680,7 @@ impl server::Span for Rustc<'_, '_> {
     }
 
     fn source_file(&mut self, span: Self::Span) -> Self::SourceFile {
-        self.sess().source_map().lookup_char_pos(span.lo()).file
+        self.psess().source_map().lookup_char_pos(span.lo()).file
     }
 
     fn parent(&mut self, span: Self::Span) -> Option<Self::Span> {
@@ -692,7 +692,7 @@ impl server::Span for Rustc<'_, '_> {
     }
 
     fn byte_range(&mut self, span: Self::Span) -> Range<usize> {
-        let source_map = self.sess().source_map();
+        let source_map = self.psess().source_map();
 
         let relative_start_pos = source_map.lookup_byte_offset(span.lo()).pos;
         let relative_end_pos = source_map.lookup_byte_offset(span.hi()).pos;
@@ -708,18 +708,18 @@ impl server::Span for Rustc<'_, '_> {
     }
 
     fn line(&mut self, span: Self::Span) -> usize {
-        let loc = self.sess().source_map().lookup_char_pos(span.lo());
+        let loc = self.psess().source_map().lookup_char_pos(span.lo());
         loc.line
     }
 
     fn column(&mut self, span: Self::Span) -> usize {
-        let loc = self.sess().source_map().lookup_char_pos(span.lo());
+        let loc = self.psess().source_map().lookup_char_pos(span.lo());
         loc.col.to_usize() + 1
     }
 
     fn join(&mut self, first: Self::Span, second: Self::Span) -> Option<Self::Span> {
-        let self_loc = self.sess().source_map().lookup_char_pos(first.lo());
-        let other_loc = self.sess().source_map().lookup_char_pos(second.lo());
+        let self_loc = self.psess().source_map().lookup_char_pos(first.lo());
+        let other_loc = self.psess().source_map().lookup_char_pos(second.lo());
 
         if self_loc.file.name != other_loc.file.name {
             return None;
@@ -769,7 +769,7 @@ impl server::Span for Rustc<'_, '_> {
     }
 
     fn source_text(&mut self, span: Self::Span) -> Option<String> {
-        self.sess().source_map().span_to_snippet(span).ok()
+        self.psess().source_map().span_to_snippet(span).ok()
     }
 
     /// Saves the provided span into the metadata of
@@ -797,7 +797,7 @@ impl server::Span for Rustc<'_, '_> {
     /// since we've loaded `my_proc_macro` from disk in order to execute it).
     /// In this way, we have obtained a span pointing into `my_proc_macro`
     fn save_span(&mut self, span: Self::Span) -> usize {
-        self.sess().save_proc_macro_span(span)
+        self.psess().save_proc_macro_span(span)
     }
 
     fn recover_proc_macro_span(&mut self, id: usize) -> Self::Span {
diff --git a/compiler/rustc_expand/src/tests.rs b/compiler/rustc_expand/src/tests.rs
index 7d19ca13c97..8c47b759453 100644
--- a/compiler/rustc_expand/src/tests.rs
+++ b/compiler/rustc_expand/src/tests.rs
@@ -18,13 +18,13 @@ use std::path::{Path, PathBuf};
 use std::str;
 use std::sync::{Arc, Mutex};
 
-pub(crate) fn sess() -> ParseSess {
+pub(crate) fn psess() -> ParseSess {
     ParseSess::new(vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE])
 }
 
 /// Map string to parser (via tts).
-fn string_to_parser(ps: &ParseSess, source_str: String) -> Parser<'_> {
-    new_parser_from_source_str(ps, PathBuf::from("bogofile").into(), source_str)
+fn string_to_parser(psess: &ParseSess, source_str: String) -> Parser<'_> {
+    new_parser_from_source_str(psess, PathBuf::from("bogofile").into(), source_str)
 }
 
 fn create_test_handler() -> (DiagCtxt, Lrc<SourceMap>, Arc<Mutex<Vec<u8>>>) {
@@ -44,13 +44,13 @@ fn create_test_handler() -> (DiagCtxt, Lrc<SourceMap>, Arc<Mutex<Vec<u8>>>) {
 /// Returns the result of parsing the given string via the given callback.
 ///
 /// If there are any errors, this will panic.
-pub(crate) fn with_error_checking_parse<'a, T, F>(s: String, ps: &'a ParseSess, f: F) -> T
+pub(crate) fn with_error_checking_parse<'a, T, F>(s: String, psess: &'a ParseSess, f: F) -> T
 where
     F: FnOnce(&mut Parser<'a>) -> PResult<'a, T>,
 {
-    let mut p = string_to_parser(&ps, s);
+    let mut p = string_to_parser(&psess, s);
     let x = f(&mut p).unwrap();
-    p.sess.dcx.abort_if_errors();
+    p.psess.dcx.abort_if_errors();
     x
 }
 
@@ -61,8 +61,8 @@ where
     F: for<'a> FnOnce(&mut Parser<'a>) -> PResult<'a, T>,
 {
     let (handler, source_map, output) = create_test_handler();
-    let ps = ParseSess::with_dcx(handler, source_map);
-    let mut p = string_to_parser(&ps, source_str.to_string());
+    let psess = ParseSess::with_dcx(handler, source_map);
+    let mut p = string_to_parser(&psess, source_str.to_string());
     let result = f(&mut p);
     assert!(result.is_ok());
 
@@ -76,18 +76,18 @@ where
 
 /// Maps a string to tts, using a made-up filename.
 pub(crate) fn string_to_stream(source_str: String) -> TokenStream {
-    let ps = sess();
+    let psess = psess();
     source_file_to_stream(
-        &ps,
-        ps.source_map().new_source_file(PathBuf::from("bogofile").into(), source_str),
+        &psess,
+        psess.source_map().new_source_file(PathBuf::from("bogofile").into(), source_str),
         None,
     )
 }
 
 /// Parses a string, returns a crate.
 pub(crate) fn string_to_crate(source_str: String) -> ast::Crate {
-    let ps = sess();
-    with_error_checking_parse(source_str, &ps, |p| p.parse_crate_mod())
+    let psess = psess();
+    with_error_checking_parse(source_str, &psess, |p| p.parse_crate_mod())
 }
 
 /// Does the given string match the pattern? whitespace in the first string