Skip to content

Commit cc009bc

Browse files
authored
Rollup merge of #102500 - compiler-errors:parse-sess-cleanup, r=cjgillot
Remove `expr_parentheses_needed` from `ParseSess` Not sure why this method needed to exist on `ParseSess`, but we can achieve the same behavior by just inlining it everywhere.
2 parents 21fc218 + 85a726e commit cc009bc

File tree

7 files changed

+14
-17
lines changed

7 files changed

+14
-17
lines changed

compiler/rustc_hir_analysis/src/check/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
4141
use rustc_middle::ty::error::TypeError::FieldMisMatch;
4242
use rustc_middle::ty::subst::SubstsRef;
4343
use rustc_middle::ty::{self, AdtKind, Ty, TypeVisitable};
44+
use rustc_session::errors::ExprParenthesesNeeded;
4445
use rustc_session::parse::feature_err;
4546
use rustc_span::hygiene::DesugaringKind;
4647
use rustc_span::lev_distance::find_best_match_for_name;
@@ -394,7 +395,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
394395
if let Some(sp) =
395396
tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp)
396397
{
397-
tcx.sess.parse_sess.expr_parentheses_needed(&mut err, *sp);
398+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
398399
}
399400
err.emit();
400401
oprnd_t = tcx.ty_error();

compiler/rustc_hir_analysis/src/check/fn_ctxt/suggestions.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_infer::infer::{self, TyCtxtInferExt};
1515
use rustc_infer::traits::{self, StatementAsExpression};
1616
use rustc_middle::lint::in_external_macro;
1717
use rustc_middle::ty::{self, Binder, IsSuggestable, ToPredicate, Ty};
18+
use rustc_session::errors::ExprParenthesesNeeded;
1819
use rustc_span::symbol::sym;
1920
use rustc_span::Span;
2021
use rustc_trait_selection::infer::InferCtxtExt;
@@ -895,7 +896,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
895896
let sp = self.tcx.sess.source_map().start_point(expr.span);
896897
if let Some(sp) = self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) {
897898
// `{ 42 } &&x` (#61475) or `{ 42 } && if x { 1 } else { 0 }`
898-
self.tcx.sess.parse_sess.expr_parentheses_needed(err, *sp);
899+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
899900
}
900901
}
901902

compiler/rustc_hir_analysis/src/check/op.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_middle::ty::adjustment::{
1313
};
1414
use rustc_middle::ty::print::with_no_trimmed_paths;
1515
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitable};
16+
use rustc_session::errors::ExprParenthesesNeeded;
1617
use rustc_span::source_map::Spanned;
1718
use rustc_span::symbol::{sym, Ident};
1819
use rustc_span::Span;
@@ -677,7 +678,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
677678
// If the previous expression was a block expression, suggest parentheses
678679
// (turning this into a binary subtraction operation instead.)
679680
// for example, `{2} - 2` -> `({2}) - 2` (see src\test\ui\parser\expr-as-stmt.rs)
680-
self.tcx.sess.parse_sess.expr_parentheses_needed(&mut err, *sp);
681+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
681682
} else {
682683
match actual.kind() {
683684
Uint(_) if op == hir::UnOp::Neg => {

compiler/rustc_parse/src/parser/diagnostics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use rustc_errors::{
3333
fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
3434
};
3535
use rustc_errors::{pluralize, Diagnostic, ErrorGuaranteed, IntoDiagnostic};
36+
use rustc_session::errors::ExprParenthesesNeeded;
3637
use rustc_span::source_map::Spanned;
3738
use rustc_span::symbol::{kw, sym, Ident};
3839
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
@@ -2049,7 +2050,7 @@ impl<'a> Parser<'a> {
20492050
let mut err = self.struct_span_err(span, &msg);
20502051
let sp = self.sess.source_map().start_point(self.token.span);
20512052
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
2052-
self.sess.expr_parentheses_needed(&mut err, *sp);
2053+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
20532054
}
20542055
err.span_label(span, "expected expression");
20552056
err

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ impl<'a> Parser<'a> {
13101310
// If the input is something like `if a { 1 } else { 2 } | if a { 3 } else { 4 }`
13111311
// then suggest parens around the lhs.
13121312
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&lo) {
1313-
self.sess.expr_parentheses_needed(&mut err, *sp);
1313+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
13141314
}
13151315
err
13161316
})

compiler/rustc_parse/src/parser/pat.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_ast::{
1010
};
1111
use rustc_ast_pretty::pprust;
1212
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, PResult};
13+
use rustc_session::errors::ExprParenthesesNeeded;
1314
use rustc_span::source_map::{respan, Span, Spanned};
1415
use rustc_span::symbol::{kw, sym, Ident};
1516

@@ -693,7 +694,7 @@ impl<'a> Parser<'a> {
693694

694695
let sp = self.sess.source_map().start_point(self.token.span);
695696
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
696-
self.sess.expr_parentheses_needed(&mut err, *sp);
697+
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
697698
}
698699

699700
Err(err)

compiler/rustc_session/src/parse.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
//! It also serves as an input to the parser itself.
33
44
use crate::config::CheckCfg;
5-
use crate::errors::{
6-
ExprParenthesesNeeded, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError,
7-
};
5+
use crate::errors::{FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError};
86
use crate::lint::{
97
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
108
};
@@ -13,8 +11,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
1311
use rustc_data_structures::sync::{Lock, Lrc};
1412
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
1513
use rustc_errors::{
16-
fallback_fluent_bundle, AddToDiagnostic, Diagnostic, DiagnosticBuilder, DiagnosticId,
17-
DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, MultiSpan, StashKey,
14+
fallback_fluent_bundle, Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
15+
EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, MultiSpan, StashKey,
1816
};
1917
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
2018
use rustc_span::edition::Edition;
@@ -324,12 +322,6 @@ impl ParseSess {
324322
});
325323
}
326324

327-
/// Extend an error with a suggestion to wrap an expression with parentheses to allow the
328-
/// parser to continue parsing the following operation as part of the same expression.
329-
pub fn expr_parentheses_needed(&self, err: &mut Diagnostic, span: Span) {
330-
ExprParenthesesNeeded::surrounding(span).add_to_diagnostic(err);
331-
}
332-
333325
pub fn save_proc_macro_span(&self, span: Span) -> usize {
334326
let mut spans = self.proc_macro_quoted_spans.lock();
335327
spans.push(span);

0 commit comments

Comments
 (0)