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`.
This commit is contained in:
@@ -85,7 +85,7 @@ impl<'a> Parser<'a> {
|
||||
// Always make an outer attribute - this allows us to recover from a misplaced
|
||||
// inner attribute.
|
||||
Some(attr::mk_doc_comment(
|
||||
&self.sess.attr_id_generator,
|
||||
&self.psess.attr_id_generator,
|
||||
comment_kind,
|
||||
ast::AttrStyle::Outer,
|
||||
data,
|
||||
@@ -135,7 +135,7 @@ impl<'a> Parser<'a> {
|
||||
this.error_on_forbidden_inner_attr(attr_sp, inner_parse_policy);
|
||||
}
|
||||
|
||||
Ok(attr::mk_attr_from_item(&self.sess.attr_id_generator, item, None, style, attr_sp))
|
||||
Ok(attr::mk_attr_from_item(&self.psess.attr_id_generator, item, None, style, attr_sp))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ impl<'a> Parser<'a> {
|
||||
if attr_style == ast::AttrStyle::Inner {
|
||||
self.bump();
|
||||
Some(attr::mk_doc_comment(
|
||||
&self.sess.attr_id_generator,
|
||||
&self.psess.attr_id_generator,
|
||||
comment_kind,
|
||||
attr_style,
|
||||
data,
|
||||
|
||||
@@ -40,8 +40,8 @@ impl AttrWrapper {
|
||||
AttrWrapper { attrs: AttrVec::new(), start_pos: usize::MAX }
|
||||
}
|
||||
|
||||
pub(crate) fn take_for_recovery(self, sess: &ParseSess) -> AttrVec {
|
||||
sess.dcx.span_delayed_bug(
|
||||
pub(crate) fn take_for_recovery(self, psess: &ParseSess) -> AttrVec {
|
||||
psess.dcx.span_delayed_bug(
|
||||
self.attrs.get(0).map(|attr| attr.span).unwrap_or(DUMMY_SP),
|
||||
"AttrVec is taken for recovery but no error is produced",
|
||||
);
|
||||
|
||||
@@ -242,7 +242,7 @@ impl<'a> DerefMut for SnapshotParser<'a> {
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
pub fn dcx(&self) -> &'a DiagCtxt {
|
||||
&self.sess.dcx
|
||||
&self.psess.dcx
|
||||
}
|
||||
|
||||
/// Replace `self` with `snapshot.parser`.
|
||||
@@ -257,7 +257,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
pub(super) fn span_to_snippet(&self, span: Span) -> Result<String, SpanSnippetError> {
|
||||
self.sess.source_map().span_to_snippet(span)
|
||||
self.psess.source_map().span_to_snippet(span)
|
||||
}
|
||||
|
||||
/// Emits an error with suggestions if an identifier was expected but not found.
|
||||
@@ -364,7 +364,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
if !self.look_ahead(1, |t| *t == token::Lt)
|
||||
&& let Ok(snippet) =
|
||||
self.sess.source_map().span_to_snippet(generic.span)
|
||||
self.psess.source_map().span_to_snippet(generic.span)
|
||||
{
|
||||
err.multipart_suggestion_verbose(
|
||||
format!("place the generic parameter name after the {ident_name} name"),
|
||||
@@ -489,7 +489,7 @@ impl<'a> Parser<'a> {
|
||||
expected.sort_by_cached_key(|x| x.to_string());
|
||||
expected.dedup();
|
||||
|
||||
let sm = self.sess.source_map();
|
||||
let sm = self.psess.source_map();
|
||||
|
||||
// Special-case "expected `;`" errors.
|
||||
if expected.contains(&TokenType::Token(token::Semi)) {
|
||||
@@ -822,7 +822,7 @@ impl<'a> Parser<'a> {
|
||||
// #[cfg(..)]
|
||||
// other_expr
|
||||
// So we suggest using `if cfg!(..) { expr } else if cfg!(..) { other_expr }`.
|
||||
let margin = self.sess.source_map().span_to_margin(next_expr.span).unwrap_or(0);
|
||||
let margin = self.psess.source_map().span_to_margin(next_expr.span).unwrap_or(0);
|
||||
let sugg = vec![
|
||||
(attr.span.with_hi(segment.span().hi()), "if cfg!".to_string()),
|
||||
(args_span.shrink_to_hi().with_hi(attr.span.hi()), " {".to_string()),
|
||||
@@ -850,7 +850,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
fn check_too_many_raw_str_terminators(&mut self, err: &mut Diag<'_>) -> bool {
|
||||
let sm = self.sess.source_map();
|
||||
let sm = self.psess.source_map();
|
||||
match (&self.prev_token.kind, &self.token.kind) {
|
||||
(
|
||||
TokenKind::Literal(Lit {
|
||||
@@ -935,7 +935,7 @@ impl<'a> Parser<'a> {
|
||||
// expand `before` so that we take care of module path such as:
|
||||
// `foo::Bar { ... } `
|
||||
// we expect to suggest `(foo::Bar { ... })` instead of `foo::(Bar { ... })`
|
||||
let sm = self.sess.source_map();
|
||||
let sm = self.psess.source_map();
|
||||
let before = maybe_struct_name.span.shrink_to_lo();
|
||||
if let Ok(extend_before) = sm.span_extend_prev_while(before, |t| {
|
||||
t.is_alphanumeric() || t == ':' || t == '_'
|
||||
@@ -1872,7 +1872,7 @@ impl<'a> Parser<'a> {
|
||||
);
|
||||
let mut err = self.dcx().struct_span_err(sp, msg);
|
||||
let label_exp = format!("expected `{token_str}`");
|
||||
let sm = self.sess.source_map();
|
||||
let sm = self.psess.source_map();
|
||||
if !sm.is_multiline(prev_sp.until(sp)) {
|
||||
// When the spans are in the same line, it means that the only content
|
||||
// between them is whitespace, point only at the found token.
|
||||
@@ -1893,7 +1893,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
pub(super) fn recover_colon_as_semi(&mut self) -> bool {
|
||||
let line_idx = |span: Span| {
|
||||
self.sess
|
||||
self.psess
|
||||
.source_map()
|
||||
.span_to_lines(span)
|
||||
.ok()
|
||||
@@ -1906,7 +1906,7 @@ impl<'a> Parser<'a> {
|
||||
{
|
||||
self.dcx().emit_err(ColonAsSemi {
|
||||
span: self.token.span,
|
||||
type_ascription: self.sess.unstable_features.is_nightly_build().then_some(()),
|
||||
type_ascription: self.psess.unstable_features.is_nightly_build().then_some(()),
|
||||
});
|
||||
self.bump();
|
||||
return true;
|
||||
@@ -2357,8 +2357,8 @@ impl<'a> Parser<'a> {
|
||||
),
|
||||
};
|
||||
let mut err = self.dcx().struct_span_err(span, msg);
|
||||
let sp = self.sess.source_map().start_point(self.token.span);
|
||||
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
|
||||
let sp = self.psess.source_map().start_point(self.token.span);
|
||||
if let Some(sp) = self.psess.ambiguous_block_expr_parse.borrow().get(&sp) {
|
||||
err.subdiagnostic(self.dcx(), ExprParenthesesNeeded::surrounding(*sp));
|
||||
}
|
||||
err.span_label(span, "expected expression");
|
||||
@@ -2539,7 +2539,7 @@ impl<'a> Parser<'a> {
|
||||
};
|
||||
|
||||
let ident = param.ident.to_string();
|
||||
let sugg = match (ty_generics, self.sess.source_map().span_to_snippet(param.span())) {
|
||||
let sugg = match (ty_generics, self.psess.source_map().span_to_snippet(param.span())) {
|
||||
(Some(Generics { params, span: impl_generics, .. }), Ok(snippet)) => {
|
||||
Some(match ¶ms[..] {
|
||||
[] => UnexpectedConstParamDeclarationSugg::AddParam {
|
||||
|
||||
@@ -403,8 +403,8 @@ impl<'a> Parser<'a> {
|
||||
// suggestions based on the assumption that double-refs are rarely intentional,
|
||||
// and closures are distinct enough that they don't get mixed up with their
|
||||
// return value.
|
||||
let sp = self.sess.source_map().start_point(self.token.span);
|
||||
self.sess.ambiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span);
|
||||
let sp = self.psess.source_map().start_point(self.token.span);
|
||||
self.psess.ambiguous_block_expr_parse.borrow_mut().insert(sp, lhs.span);
|
||||
false
|
||||
}
|
||||
(true, Some(op)) if !op.can_continue_expr_unambiguously() => false,
|
||||
@@ -608,7 +608,7 @@ impl<'a> Parser<'a> {
|
||||
};
|
||||
|
||||
// a block on the LHS might have been intended to be an expression instead
|
||||
if let Some(sp) = this.sess.ambiguous_block_expr_parse.borrow().get(&lo) {
|
||||
if let Some(sp) = this.psess.ambiguous_block_expr_parse.borrow().get(&lo) {
|
||||
err.add_parentheses = Some(ExprParenthesesNeeded::surrounding(*sp));
|
||||
} else {
|
||||
err.remove_plus = Some(lo);
|
||||
@@ -666,7 +666,7 @@ impl<'a> Parser<'a> {
|
||||
fn parse_expr_box(&mut self, box_kw: Span) -> PResult<'a, (Span, ExprKind)> {
|
||||
let (span, _) = self.parse_expr_prefix_common(box_kw)?;
|
||||
let inner_span = span.with_lo(box_kw.hi());
|
||||
let code = self.sess.source_map().span_to_snippet(inner_span).unwrap();
|
||||
let code = self.psess.source_map().span_to_snippet(inner_span).unwrap();
|
||||
let guar = self.dcx().emit_err(errors::BoxSyntaxRemoved { span: span, code: code.trim() });
|
||||
Ok((span, ExprKind::Err(guar)))
|
||||
}
|
||||
@@ -700,7 +700,7 @@ impl<'a> Parser<'a> {
|
||||
// Span the `not` plus trailing whitespace to avoid
|
||||
// trailing whitespace after the `!` in our suggestion
|
||||
sub: sub_diag(
|
||||
self.sess.source_map().span_until_non_whitespace(lo.to(negated_token.span)),
|
||||
self.psess.source_map().span_until_non_whitespace(lo.to(negated_token.span)),
|
||||
),
|
||||
});
|
||||
|
||||
@@ -915,7 +915,7 @@ impl<'a> Parser<'a> {
|
||||
let found_raw = self.eat_keyword(kw::Raw);
|
||||
assert!(found_raw);
|
||||
let mutability = self.parse_const_or_mut().unwrap();
|
||||
self.sess.gated_spans.gate(sym::raw_ref_op, lo.to(self.prev_token.span));
|
||||
self.psess.gated_spans.gate(sym::raw_ref_op, lo.to(self.prev_token.span));
|
||||
(ast::BorrowKind::Raw, mutability)
|
||||
} else {
|
||||
// `mut?`
|
||||
@@ -1013,7 +1013,7 @@ impl<'a> Parser<'a> {
|
||||
fn error_unexpected_after_dot(&self) {
|
||||
let actual = pprust::token_to_string(&self.token);
|
||||
let span = self.token.span;
|
||||
let sm = self.sess.source_map();
|
||||
let sm = self.psess.source_map();
|
||||
let (span, actual) = match (&self.token.kind, self.subparser_name) {
|
||||
(token::Eof, Some(_)) if let Ok(actual) = sm.span_to_snippet(sm.next_point(span)) => {
|
||||
(span.shrink_to_hi(), actual.into())
|
||||
@@ -1434,7 +1434,7 @@ impl<'a> Parser<'a> {
|
||||
this.parse_expr_closure().map_err(|mut err| {
|
||||
// If the input is something like `if a { 1 } else { 2 } | if a { 3 } else { 4 }`
|
||||
// then suggest parens around the lhs.
|
||||
if let Some(sp) = this.sess.ambiguous_block_expr_parse.borrow().get(&lo) {
|
||||
if let Some(sp) = this.psess.ambiguous_block_expr_parse.borrow().get(&lo) {
|
||||
err.subdiagnostic(this.dcx(), ExprParenthesesNeeded::surrounding(*sp));
|
||||
}
|
||||
err
|
||||
@@ -1634,7 +1634,7 @@ impl<'a> Parser<'a> {
|
||||
&& let Some(expr) = self.maybe_parse_struct_expr(&qself, &path)
|
||||
{
|
||||
if qself.is_some() {
|
||||
self.sess.gated_spans.gate(sym::more_qualified_paths, path.span);
|
||||
self.psess.gated_spans.gate(sym::more_qualified_paths, path.span);
|
||||
}
|
||||
return expr;
|
||||
} else {
|
||||
@@ -1821,7 +1821,7 @@ impl<'a> Parser<'a> {
|
||||
let kind = ExprKind::Yeet(self.parse_expr_opt()?);
|
||||
|
||||
let span = lo.to(self.prev_token.span);
|
||||
self.sess.gated_spans.gate(sym::yeet_expr, span);
|
||||
self.psess.gated_spans.gate(sym::yeet_expr, span);
|
||||
let expr = self.mk_expr(span, kind);
|
||||
self.maybe_recover_from_bad_qpath(expr)
|
||||
}
|
||||
@@ -1831,7 +1831,7 @@ impl<'a> Parser<'a> {
|
||||
let lo = self.prev_token.span;
|
||||
let kind = ExprKind::Become(self.parse_expr()?);
|
||||
let span = lo.to(self.prev_token.span);
|
||||
self.sess.gated_spans.gate(sym::explicit_tail_calls, span);
|
||||
self.psess.gated_spans.gate(sym::explicit_tail_calls, span);
|
||||
let expr = self.mk_expr(span, kind);
|
||||
self.maybe_recover_from_bad_qpath(expr)
|
||||
}
|
||||
@@ -1875,7 +1875,7 @@ impl<'a> Parser<'a> {
|
||||
| ExprKind::Block(_, None)
|
||||
)
|
||||
{
|
||||
self.sess.buffer_lint_with_diagnostic(
|
||||
self.psess.buffer_lint_with_diagnostic(
|
||||
BREAK_WITH_LABEL_AND_LOOP,
|
||||
lo.to(expr.span),
|
||||
ast::CRATE_NODE_ID,
|
||||
@@ -1926,7 +1926,7 @@ impl<'a> Parser<'a> {
|
||||
let lo = self.prev_token.span;
|
||||
let kind = ExprKind::Yield(self.parse_expr_opt()?);
|
||||
let span = lo.to(self.prev_token.span);
|
||||
self.sess.gated_spans.gate(sym::yield_expr, span);
|
||||
self.psess.gated_spans.gate(sym::yield_expr, span);
|
||||
let expr = self.mk_expr(span, kind);
|
||||
self.maybe_recover_from_bad_qpath(expr)
|
||||
}
|
||||
@@ -1955,7 +1955,7 @@ impl<'a> Parser<'a> {
|
||||
let err = self.dcx().create_err(errors::ExpectedBuiltinIdent { span: self.token.span });
|
||||
return Err(err);
|
||||
};
|
||||
self.sess.gated_spans.gate(sym::builtin_syntax, ident.span);
|
||||
self.psess.gated_spans.gate(sym::builtin_syntax, ident.span);
|
||||
self.bump();
|
||||
|
||||
self.expect(&TokenKind::OpenDelim(Delimiter::Parenthesis))?;
|
||||
@@ -2143,7 +2143,7 @@ impl<'a> Parser<'a> {
|
||||
Err(err) => {
|
||||
let span = token.uninterpolated_span();
|
||||
self.bump();
|
||||
let guar = report_lit_error(self.sess, err, lit, span);
|
||||
let guar = report_lit_error(self.psess, err, lit, span);
|
||||
// Pack possible quotes and prefixes from the original literal into
|
||||
// the error literal's symbol so they can be pretty-printed faithfully.
|
||||
let suffixless_lit = token::Lit::new(lit.kind, lit.symbol, None);
|
||||
@@ -2236,7 +2236,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
if self.token.kind == token::Comma {
|
||||
if !self.sess.source_map().is_multiline(prev_span.until(self.token.span)) {
|
||||
if !self.psess.source_map().is_multiline(prev_span.until(self.token.span)) {
|
||||
return Ok(());
|
||||
}
|
||||
let mut snapshot = self.create_snapshot_for_diagnostic();
|
||||
@@ -2312,7 +2312,7 @@ impl<'a> Parser<'a> {
|
||||
let lifetime_defs = self.parse_late_bound_lifetime_defs()?;
|
||||
let span = lo.to(self.prev_token.span);
|
||||
|
||||
self.sess.gated_spans.gate(sym::closure_lifetime_binder, span);
|
||||
self.psess.gated_spans.gate(sym::closure_lifetime_binder, span);
|
||||
|
||||
ClosureBinder::For { span, generic_params: lifetime_defs }
|
||||
} else {
|
||||
@@ -2354,12 +2354,12 @@ impl<'a> Parser<'a> {
|
||||
match coroutine_kind {
|
||||
Some(CoroutineKind::Async { span, .. }) => {
|
||||
// Feature-gate `async ||` closures.
|
||||
self.sess.gated_spans.gate(sym::async_closure, span);
|
||||
self.psess.gated_spans.gate(sym::async_closure, span);
|
||||
}
|
||||
Some(CoroutineKind::Gen { span, .. }) | Some(CoroutineKind::AsyncGen { span, .. }) => {
|
||||
// Feature-gate `gen ||` and `async gen ||` closures.
|
||||
// FIXME(gen_blocks): This perhaps should be a different gate.
|
||||
self.sess.gated_spans.gate(sym::gen_blocks, span);
|
||||
self.psess.gated_spans.gate(sym::gen_blocks, span);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
@@ -2502,7 +2502,7 @@ impl<'a> Parser<'a> {
|
||||
ExprKind::Block(_, None) => {
|
||||
let guar = this.dcx().emit_err(errors::IfExpressionMissingCondition {
|
||||
if_span: lo.with_neighbor(cond.span).shrink_to_hi(),
|
||||
block_span: self.sess.source_map().start_point(cond_span),
|
||||
block_span: self.psess.source_map().start_point(cond_span),
|
||||
});
|
||||
std::mem::replace(&mut cond, this.mk_expr_err(cond_span.shrink_to_hi(), guar))
|
||||
}
|
||||
@@ -2594,7 +2594,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
if let ExprKind::Let(_, _, _, None) = cond.kind {
|
||||
// Remove the last feature gating of a `let` expression since it's stable.
|
||||
self.sess.gated_spans.ungate_last(sym::let_chains, cond.span);
|
||||
self.psess.gated_spans.ungate_last(sym::let_chains, cond.span);
|
||||
}
|
||||
|
||||
Ok(cond)
|
||||
@@ -2690,7 +2690,7 @@ impl<'a> Parser<'a> {
|
||||
attrs: AttrWrapper,
|
||||
) {
|
||||
if !attrs.is_empty()
|
||||
&& let [x0 @ xn] | [x0, .., xn] = &*attrs.take_for_recovery(self.sess)
|
||||
&& let [x0 @ xn] | [x0, .., xn] = &*attrs.take_for_recovery(self.psess)
|
||||
{
|
||||
let attributes = x0.span.to(xn.span);
|
||||
let last = xn.span;
|
||||
@@ -2787,7 +2787,7 @@ impl<'a> Parser<'a> {
|
||||
self.token.uninterpolated_span().at_least_rust_2018() && self.eat_keyword(kw::Await);
|
||||
|
||||
if is_await {
|
||||
self.sess.gated_spans.gate(sym::async_for_loop, self.prev_token.span);
|
||||
self.psess.gated_spans.gate(sym::async_for_loop, self.prev_token.span);
|
||||
}
|
||||
|
||||
let kind = if is_await { ForLoopKind::ForAwait } else { ForLoopKind::For };
|
||||
@@ -3048,7 +3048,7 @@ impl<'a> Parser<'a> {
|
||||
|x| {
|
||||
// Don't gate twice
|
||||
if !pat.contains_never_pattern() {
|
||||
this.sess.gated_spans.gate(sym::never_patterns, pat.span);
|
||||
this.psess.gated_spans.gate(sym::never_patterns, pat.span);
|
||||
}
|
||||
x
|
||||
},
|
||||
@@ -3103,7 +3103,7 @@ impl<'a> Parser<'a> {
|
||||
this.expect_one_of(&[token::Comma], &[token::CloseDelim(Delimiter::Brace)])
|
||||
.map_err(|mut err| {
|
||||
if this.token == token::FatArrow {
|
||||
let sm = this.sess.source_map();
|
||||
let sm = this.psess.source_map();
|
||||
if let Ok(expr_lines) = sm.span_to_lines(expr_span)
|
||||
&& let Ok(arm_start_lines) = sm.span_to_lines(arm_start_span)
|
||||
&& arm_start_lines.lines[0].end_col
|
||||
@@ -3227,10 +3227,10 @@ impl<'a> Parser<'a> {
|
||||
if has_let_expr {
|
||||
if does_not_have_bin_op {
|
||||
// Remove the last feature gating of a `let` expression since it's stable.
|
||||
self.sess.gated_spans.ungate_last(sym::let_chains, cond.span);
|
||||
self.psess.gated_spans.ungate_last(sym::let_chains, cond.span);
|
||||
}
|
||||
let span = if_span.to(cond.span);
|
||||
self.sess.gated_spans.gate(sym::if_let_guard, span);
|
||||
self.psess.gated_spans.gate(sym::if_let_guard, span);
|
||||
}
|
||||
Ok(Some(cond))
|
||||
}
|
||||
@@ -3321,7 +3321,7 @@ impl<'a> Parser<'a> {
|
||||
Err(self.dcx().create_err(errors::CatchAfterTry { span: self.prev_token.span }))
|
||||
} else {
|
||||
let span = span_lo.to(body.span);
|
||||
self.sess.gated_spans.gate(sym::try_blocks, span);
|
||||
self.psess.gated_spans.gate(sym::try_blocks, span);
|
||||
Ok(self.mk_expr_with_attrs(span, ExprKind::TryBlock(body), attrs))
|
||||
}
|
||||
}
|
||||
@@ -3359,7 +3359,7 @@ impl<'a> Parser<'a> {
|
||||
// `async` blocks are stable
|
||||
}
|
||||
GenBlockKind::Gen | GenBlockKind::AsyncGen => {
|
||||
self.sess.gated_spans.gate(sym::gen_blocks, lo.to(self.prev_token.span));
|
||||
self.psess.gated_spans.gate(sym::gen_blocks, lo.to(self.prev_token.span));
|
||||
}
|
||||
}
|
||||
let capture_clause = self.parse_capture_clause()?;
|
||||
@@ -3876,7 +3876,7 @@ impl MutVisitor for CondChecker<'_> {
|
||||
comparison: self.comparison,
|
||||
}));
|
||||
} else {
|
||||
self.parser.sess.gated_spans.gate(sym::let_chains, span);
|
||||
self.parser.psess.gated_spans.gate(sym::let_chains, span);
|
||||
}
|
||||
}
|
||||
ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, _, _) => {
|
||||
|
||||
@@ -420,7 +420,7 @@ impl<'a> Parser<'a> {
|
||||
type_err.cancel();
|
||||
|
||||
let body_sp = pred_lo.to(snapshot.prev_token.span);
|
||||
let map = self.sess.source_map();
|
||||
let map = self.psess.source_map();
|
||||
|
||||
self.dcx().emit_err(WhereClauseBeforeTupleStructBody {
|
||||
span: where_sp,
|
||||
|
||||
@@ -563,7 +563,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
let constness = self.parse_constness(Case::Sensitive);
|
||||
if let Const::Yes(span) = constness {
|
||||
self.sess.gated_spans.gate(sym::const_trait_impl, span);
|
||||
self.psess.gated_spans.gate(sym::const_trait_impl, span);
|
||||
}
|
||||
|
||||
// Parse stray `impl async Trait`
|
||||
@@ -699,7 +699,7 @@ impl<'a> Parser<'a> {
|
||||
None
|
||||
};
|
||||
let span = span.to(self.prev_token.span);
|
||||
self.sess.gated_spans.gate(sym::fn_delegation, span);
|
||||
self.psess.gated_spans.gate(sym::fn_delegation, span);
|
||||
|
||||
let ident = path.segments.last().map(|seg| seg.ident).unwrap_or(Ident::empty());
|
||||
Ok((
|
||||
@@ -859,7 +859,7 @@ impl<'a> Parser<'a> {
|
||||
let unsafety = self.parse_unsafety(Case::Sensitive);
|
||||
// Parse optional `auto` prefix.
|
||||
let is_auto = if self.eat_keyword(kw::Auto) {
|
||||
self.sess.gated_spans.gate(sym::auto_traits, self.prev_token.span);
|
||||
self.psess.gated_spans.gate(sym::auto_traits, self.prev_token.span);
|
||||
IsAuto::Yes
|
||||
} else {
|
||||
IsAuto::No
|
||||
@@ -894,7 +894,7 @@ impl<'a> Parser<'a> {
|
||||
self.dcx().emit_err(errors::TraitAliasCannotBeUnsafe { span: whole_span });
|
||||
}
|
||||
|
||||
self.sess.gated_spans.gate(sym::trait_alias, whole_span);
|
||||
self.psess.gated_spans.gate(sym::trait_alias, whole_span);
|
||||
|
||||
Ok((ident, ItemKind::TraitAlias(generics, bounds)))
|
||||
} else {
|
||||
@@ -1209,7 +1209,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
fn error_bad_item_kind<T>(&self, span: Span, kind: &ItemKind, ctx: &'static str) -> Option<T> {
|
||||
// FIXME(#100717): needs variant for each `ItemKind` (instead of using `ItemKind::descr()`)
|
||||
let span = self.sess.source_map().guess_head_span(span);
|
||||
let span = self.psess.source_map().guess_head_span(span);
|
||||
let descr = kind.descr();
|
||||
self.dcx().emit_err(errors::BadItemKind { span, descr, ctx });
|
||||
None
|
||||
@@ -1332,7 +1332,7 @@ impl<'a> Parser<'a> {
|
||||
// Check the span for emptiness instead of the list of parameters in order to correctly
|
||||
// recognize and subsequently flag empty parameter lists (`<>`) as unstable.
|
||||
if !generics.span.is_empty() {
|
||||
self.sess.gated_spans.gate(sym::generic_const_items, generics.span);
|
||||
self.psess.gated_spans.gate(sym::generic_const_items, generics.span);
|
||||
}
|
||||
|
||||
// Parse the type of a constant item. That is, the `":" $ty` fragment.
|
||||
@@ -1366,7 +1366,7 @@ impl<'a> Parser<'a> {
|
||||
name: ident.span,
|
||||
body: expr.span,
|
||||
sugg: if !after_where_clause.has_where_token {
|
||||
self.sess.source_map().span_to_snippet(expr.span).ok().map(|body| {
|
||||
self.psess.source_map().span_to_snippet(expr.span).ok().map(|body| {
|
||||
errors::WhereClauseBeforeConstBodySugg {
|
||||
left: before_where_clause.span.shrink_to_lo(),
|
||||
snippet: body,
|
||||
@@ -1401,7 +1401,7 @@ impl<'a> Parser<'a> {
|
||||
};
|
||||
|
||||
if where_clause.has_where_token {
|
||||
self.sess.gated_spans.gate(sym::generic_const_items, where_clause.span);
|
||||
self.psess.gated_spans.gate(sym::generic_const_items, where_clause.span);
|
||||
}
|
||||
|
||||
generics.where_clause = where_clause;
|
||||
@@ -1898,7 +1898,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
fn expect_field_ty_separator(&mut self) -> PResult<'a, ()> {
|
||||
if let Err(err) = self.expect(&token::Colon) {
|
||||
let sm = self.sess.source_map();
|
||||
let sm = self.psess.source_map();
|
||||
let eq_typo = self.token.kind == token::Eq && self.look_ahead(1, |t| t.is_path_start());
|
||||
let semi_typo = self.token.kind == token::Semi
|
||||
&& self.look_ahead(1, |t| {
|
||||
@@ -1970,7 +1970,7 @@ impl<'a> Parser<'a> {
|
||||
fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> {
|
||||
let (ident, is_raw) = self.ident_or_err(true)?;
|
||||
if ident.name == kw::Underscore {
|
||||
self.sess.gated_spans.gate(sym::unnamed_fields, lo);
|
||||
self.psess.gated_spans.gate(sym::unnamed_fields, lo);
|
||||
} else if matches!(is_raw, IdentIsRaw::No) && ident.is_reserved() {
|
||||
let snapshot = self.create_snapshot_for_diagnostic();
|
||||
let err = if self.check_fn_front_matter(false, Case::Sensitive) {
|
||||
@@ -2080,7 +2080,7 @@ impl<'a> Parser<'a> {
|
||||
return self.unexpected();
|
||||
};
|
||||
|
||||
self.sess.gated_spans.gate(sym::decl_macro, lo.to(self.prev_token.span));
|
||||
self.psess.gated_spans.gate(sym::decl_macro, lo.to(self.prev_token.span));
|
||||
Ok((ident, ItemKind::MacroDef(ast::MacroDef { body, macro_rules: false })))
|
||||
}
|
||||
|
||||
@@ -2460,7 +2460,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
match coroutine_kind {
|
||||
Some(CoroutineKind::Gen { span, .. }) | Some(CoroutineKind::AsyncGen { span, .. }) => {
|
||||
self.sess.gated_spans.gate(sym::gen_blocks, span);
|
||||
self.psess.gated_spans.gate(sym::gen_blocks, span);
|
||||
}
|
||||
Some(CoroutineKind::Async { .. }) | None => {}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ pub enum Recovery {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Parser<'a> {
|
||||
pub sess: &'a ParseSess,
|
||||
pub psess: &'a ParseSess,
|
||||
/// The current token.
|
||||
pub token: Token,
|
||||
/// The spacing for the current token.
|
||||
@@ -414,12 +414,12 @@ pub(super) fn token_descr(token: &Token) -> String {
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
pub fn new(
|
||||
sess: &'a ParseSess,
|
||||
psess: &'a ParseSess,
|
||||
stream: TokenStream,
|
||||
subparser_name: Option<&'static str>,
|
||||
) -> Self {
|
||||
let mut parser = Parser {
|
||||
sess,
|
||||
psess,
|
||||
token: Token::dummy(),
|
||||
token_spacing: Spacing::Alone,
|
||||
prev_token: Token::dummy(),
|
||||
@@ -714,7 +714,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
match self.token.kind.break_two_token_op() {
|
||||
Some((first, second)) if first == expected => {
|
||||
let first_span = self.sess.source_map().start_point(self.token.span);
|
||||
let first_span = self.psess.source_map().start_point(self.token.span);
|
||||
let second_span = self.token.span.with_lo(first_span.hi());
|
||||
self.token = Token::new(first, first_span);
|
||||
// Keep track of this token - if we end token capturing now,
|
||||
@@ -1213,7 +1213,7 @@ impl<'a> Parser<'a> {
|
||||
fn parse_closure_constness(&mut self) -> Const {
|
||||
let constness = self.parse_constness_(Case::Sensitive, true);
|
||||
if let Const::Yes(span) = constness {
|
||||
self.sess.gated_spans.gate(sym::const_closures, span);
|
||||
self.psess.gated_spans.gate(sym::const_closures, span);
|
||||
}
|
||||
constness
|
||||
}
|
||||
@@ -1234,9 +1234,9 @@ impl<'a> Parser<'a> {
|
||||
/// Parses inline const expressions.
|
||||
fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, P<Expr>> {
|
||||
if pat {
|
||||
self.sess.gated_spans.gate(sym::inline_const_pat, span);
|
||||
self.psess.gated_spans.gate(sym::inline_const_pat, span);
|
||||
} else {
|
||||
self.sess.gated_spans.gate(sym::inline_const, span);
|
||||
self.psess.gated_spans.gate(sym::inline_const, span);
|
||||
}
|
||||
self.eat_keyword(kw::Const);
|
||||
let (attrs, blk) = self.parse_inner_attrs_and_block()?;
|
||||
@@ -1521,7 +1521,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
pub(crate) fn make_unclosed_delims_error(
|
||||
unmatched: UnmatchedDelim,
|
||||
sess: &ParseSess,
|
||||
psess: &ParseSess,
|
||||
) -> Option<Diag<'_>> {
|
||||
// `None` here means an `Eof` was found. We already emit those errors elsewhere, we add them to
|
||||
// `unmatched_delims` only for error recovery in the `Parser`.
|
||||
@@ -1530,7 +1530,7 @@ pub(crate) fn make_unclosed_delims_error(
|
||||
if let Some(sp) = unmatched.unclosed_span {
|
||||
spans.push(sp);
|
||||
};
|
||||
let err = sess.dcx.create_err(MismatchedClosingDelimiter {
|
||||
let err = psess.dcx.create_err(MismatchedClosingDelimiter {
|
||||
spans,
|
||||
delimiter: pprust::token_kind_to_string(&token::CloseDelim(found_delim)).to_string(),
|
||||
unmatched: unmatched.found_span,
|
||||
|
||||
@@ -470,7 +470,7 @@ impl<'a> Parser<'a> {
|
||||
self.parse_pat_range_to(form)? // `..=X`, `...X`, or `..X`.
|
||||
} else if self.eat(&token::Not) {
|
||||
// Parse `!`
|
||||
self.sess.gated_spans.gate(sym::never_patterns, self.prev_token.span);
|
||||
self.psess.gated_spans.gate(sym::never_patterns, self.prev_token.span);
|
||||
PatKind::Never
|
||||
} else if self.eat_keyword(kw::Underscore) {
|
||||
// Parse `_`
|
||||
@@ -843,8 +843,8 @@ impl<'a> Parser<'a> {
|
||||
let mut err = self.dcx().struct_span_err(self.token.span, msg);
|
||||
err.span_label(self.token.span, format!("expected {expected}"));
|
||||
|
||||
let sp = self.sess.source_map().start_point(self.token.span);
|
||||
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
|
||||
let sp = self.psess.source_map().start_point(self.token.span);
|
||||
if let Some(sp) = self.psess.ambiguous_block_expr_parse.borrow().get(&sp) {
|
||||
err.subdiagnostic(self.dcx(), ExprParenthesesNeeded::surrounding(*sp));
|
||||
}
|
||||
|
||||
@@ -1067,7 +1067,7 @@ impl<'a> Parser<'a> {
|
||||
fn parse_pat_struct(&mut self, qself: Option<P<QSelf>>, path: Path) -> PResult<'a, PatKind> {
|
||||
if qself.is_some() {
|
||||
// Feature gate the use of qualified paths in patterns
|
||||
self.sess.gated_spans.gate(sym::more_qualified_paths, path.span);
|
||||
self.psess.gated_spans.gate(sym::more_qualified_paths, path.span);
|
||||
}
|
||||
self.bump();
|
||||
let (fields, etc) = self.parse_pat_fields().unwrap_or_else(|mut e| {
|
||||
@@ -1096,7 +1096,7 @@ impl<'a> Parser<'a> {
|
||||
)
|
||||
})?;
|
||||
if qself.is_some() {
|
||||
self.sess.gated_spans.gate(sym::more_qualified_paths, path.span);
|
||||
self.psess.gated_spans.gate(sym::more_qualified_paths, path.span);
|
||||
}
|
||||
Ok(PatKind::TupleStruct(qself, path, fields))
|
||||
}
|
||||
@@ -1143,7 +1143,7 @@ impl<'a> Parser<'a> {
|
||||
Ok(PatKind::Ident(BindingAnnotation::NONE, Ident::new(kw::Box, box_span), sub))
|
||||
} else {
|
||||
let pat = self.parse_pat_with_range_pat(false, None, None)?;
|
||||
self.sess.gated_spans.gate(sym::box_patterns, box_span.to(self.prev_token.span));
|
||||
self.psess.gated_spans.gate(sym::box_patterns, box_span.to(self.prev_token.span));
|
||||
Ok(PatKind::Box(pat))
|
||||
}
|
||||
}
|
||||
@@ -1192,15 +1192,15 @@ impl<'a> Parser<'a> {
|
||||
.look_ahead(1, |t| if *t == token::Comma { Some(t.clone()) } else { None })
|
||||
{
|
||||
let nw_span = self
|
||||
.sess
|
||||
.psess
|
||||
.source_map()
|
||||
.span_extend_to_line(comma_tok.span)
|
||||
.trim_start(comma_tok.span.shrink_to_lo())
|
||||
.map(|s| self.sess.source_map().span_until_non_whitespace(s));
|
||||
.map(|s| self.psess.source_map().span_until_non_whitespace(s));
|
||||
first_etc_and_maybe_comma_span = nw_span.map(|s| etc_sp.to(s));
|
||||
} else {
|
||||
first_etc_and_maybe_comma_span =
|
||||
Some(self.sess.source_map().span_until_non_whitespace(etc_sp));
|
||||
Some(self.psess.source_map().span_until_non_whitespace(etc_sp));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1218,7 +1218,8 @@ impl<'a> Parser<'a> {
|
||||
let mut comma_sp = None;
|
||||
if self.token == token::Comma {
|
||||
// Issue #49257
|
||||
let nw_span = self.sess.source_map().span_until_non_whitespace(self.token.span);
|
||||
let nw_span =
|
||||
self.psess.source_map().span_until_non_whitespace(self.token.span);
|
||||
etc_sp = etc_sp.to(nw_span);
|
||||
err.span_label(
|
||||
etc_sp,
|
||||
|
||||
@@ -250,7 +250,7 @@ impl<'a> Parser<'a> {
|
||||
self.dcx().emit_err(PathSingleColon {
|
||||
span: self.prev_token.span,
|
||||
type_ascription: self
|
||||
.sess
|
||||
.psess
|
||||
.unstable_features
|
||||
.is_nightly_build()
|
||||
.then_some(()),
|
||||
@@ -322,7 +322,7 @@ impl<'a> Parser<'a> {
|
||||
err = self.dcx().create_err(PathSingleColon {
|
||||
span: self.token.span,
|
||||
type_ascription: self
|
||||
.sess
|
||||
.psess
|
||||
.unstable_features
|
||||
.is_nightly_build()
|
||||
.then_some(()),
|
||||
@@ -638,9 +638,9 @@ impl<'a> Parser<'a> {
|
||||
&& args.inputs.is_empty()
|
||||
&& matches!(args.output, ast::FnRetTy::Default(..))
|
||||
{
|
||||
self.sess.gated_spans.gate(sym::return_type_notation, span);
|
||||
self.psess.gated_spans.gate(sym::return_type_notation, span);
|
||||
} else {
|
||||
self.sess.gated_spans.gate(sym::associated_type_bounds, span);
|
||||
self.psess.gated_spans.gate(sym::associated_type_bounds, span);
|
||||
}
|
||||
}
|
||||
let constraint =
|
||||
@@ -675,7 +675,7 @@ impl<'a> Parser<'a> {
|
||||
let term = match arg {
|
||||
Some(GenericArg::Type(ty)) => ty.into(),
|
||||
Some(GenericArg::Const(c)) => {
|
||||
self.sess.gated_spans.gate(sym::associated_const_equality, span);
|
||||
self.psess.gated_spans.gate(sym::associated_const_equality, span);
|
||||
c.into()
|
||||
}
|
||||
Some(GenericArg::Lifetime(lt)) => {
|
||||
@@ -691,7 +691,7 @@ impl<'a> Parser<'a> {
|
||||
.struct_span_err(after_eq.to(before_next), "missing type to the right of `=`");
|
||||
if matches!(self.token.kind, token::Comma | token::Gt) {
|
||||
err.span_suggestion(
|
||||
self.sess.source_map().next_point(eq).to(before_next),
|
||||
self.psess.source_map().next_point(eq).to(before_next),
|
||||
"to constrain the associated type, add a type after `=`",
|
||||
" TheType",
|
||||
Applicability::HasPlaceholders,
|
||||
|
||||
@@ -230,7 +230,7 @@ impl<'a> Parser<'a> {
|
||||
/// Also error if the previous token was a doc comment.
|
||||
fn error_outer_attrs(&self, attrs: AttrWrapper) {
|
||||
if !attrs.is_empty()
|
||||
&& let attrs @ [.., last] = &*attrs.take_for_recovery(self.sess)
|
||||
&& let attrs @ [.., last] = &*attrs.take_for_recovery(self.psess)
|
||||
{
|
||||
if last.is_doc_comment() {
|
||||
self.dcx().emit_err(errors::DocCommentDoesNotDocumentAnything {
|
||||
@@ -494,7 +494,7 @@ impl<'a> Parser<'a> {
|
||||
// Do not suggest `if foo println!("") {;}` (as would be seen in test for #46836).
|
||||
Ok(Some(Stmt { kind: StmtKind::Empty, .. })) => {}
|
||||
Ok(Some(stmt)) => {
|
||||
let stmt_own_line = self.sess.source_map().is_line_before_span_empty(sp);
|
||||
let stmt_own_line = self.psess.source_map().is_line_before_span_empty(sp);
|
||||
let stmt_span = if stmt_own_line && self.eat(&token::Semi) {
|
||||
// Expand the span to include the semicolon.
|
||||
stmt.span.with_hi(self.prev_token.span.hi())
|
||||
@@ -613,7 +613,7 @@ impl<'a> Parser<'a> {
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
if self.sess.unstable_features.is_nightly_build() {
|
||||
if self.psess.unstable_features.is_nightly_build() {
|
||||
// FIXME(Nilstrieb): Remove this again after a few months.
|
||||
err.note("type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>");
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ impl<'a> Parser<'a> {
|
||||
let (fields, _recovered) =
|
||||
self.parse_record_struct_body(if is_union { "union" } else { "struct" }, lo, false)?;
|
||||
let span = lo.to(self.prev_token.span);
|
||||
self.sess.gated_spans.gate(sym::unnamed_fields, span);
|
||||
self.psess.gated_spans.gate(sym::unnamed_fields, span);
|
||||
let id = ast::DUMMY_NODE_ID;
|
||||
let kind =
|
||||
if is_union { TyKind::AnonUnion(id, fields) } else { TyKind::AnonStruct(id, fields) };
|
||||
@@ -694,7 +694,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
// parse dyn* types
|
||||
let syntax = if self.eat(&TokenKind::BinOp(token::Star)) {
|
||||
self.sess.gated_spans.gate(sym::dyn_star, lo.to(self.prev_token.span));
|
||||
self.psess.gated_spans.gate(sym::dyn_star, lo.to(self.prev_token.span));
|
||||
TraitObjectSyntax::DynStar
|
||||
} else {
|
||||
TraitObjectSyntax::Dyn
|
||||
@@ -874,10 +874,10 @@ impl<'a> Parser<'a> {
|
||||
let tilde = self.prev_token.span;
|
||||
self.expect_keyword(kw::Const)?;
|
||||
let span = tilde.to(self.prev_token.span);
|
||||
self.sess.gated_spans.gate(sym::const_trait_impl, span);
|
||||
self.psess.gated_spans.gate(sym::const_trait_impl, span);
|
||||
BoundConstness::Maybe(span)
|
||||
} else if self.eat_keyword(kw::Const) {
|
||||
self.sess.gated_spans.gate(sym::const_trait_impl, self.prev_token.span);
|
||||
self.psess.gated_spans.gate(sym::const_trait_impl, self.prev_token.span);
|
||||
BoundConstness::Always(self.prev_token.span)
|
||||
} else {
|
||||
BoundConstness::Never
|
||||
@@ -886,7 +886,7 @@ impl<'a> Parser<'a> {
|
||||
let asyncness = if self.token.uninterpolated_span().at_least_rust_2018()
|
||||
&& self.eat_keyword(kw::Async)
|
||||
{
|
||||
self.sess.gated_spans.gate(sym::async_closure, self.prev_token.span);
|
||||
self.psess.gated_spans.gate(sym::async_closure, self.prev_token.span);
|
||||
BoundAsyncness::Async(self.prev_token.span)
|
||||
} else if self.may_recover()
|
||||
&& self.token.uninterpolated_span().is_rust_2015()
|
||||
@@ -897,7 +897,7 @@ impl<'a> Parser<'a> {
|
||||
span: self.prev_token.span,
|
||||
help: HelpUseLatestEdition::new(),
|
||||
});
|
||||
self.sess.gated_spans.gate(sym::async_closure, self.prev_token.span);
|
||||
self.psess.gated_spans.gate(sym::async_closure, self.prev_token.span);
|
||||
BoundAsyncness::Async(self.prev_token.span)
|
||||
} else {
|
||||
BoundAsyncness::Normal
|
||||
@@ -906,7 +906,7 @@ impl<'a> Parser<'a> {
|
||||
let polarity = if self.eat(&token::Question) {
|
||||
BoundPolarity::Maybe(self.prev_token.span)
|
||||
} else if self.eat(&token::Not) {
|
||||
self.sess.gated_spans.gate(sym::negative_bounds, self.prev_token.span);
|
||||
self.psess.gated_spans.gate(sym::negative_bounds, self.prev_token.span);
|
||||
BoundPolarity::Negative(self.prev_token.span)
|
||||
} else {
|
||||
BoundPolarity::Positive
|
||||
|
||||
Reference in New Issue
Block a user