mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
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.
This commit is contained in:
commit
cc009bc536
@ -41,6 +41,7 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
|
|||||||
use rustc_middle::ty::error::TypeError::FieldMisMatch;
|
use rustc_middle::ty::error::TypeError::FieldMisMatch;
|
||||||
use rustc_middle::ty::subst::SubstsRef;
|
use rustc_middle::ty::subst::SubstsRef;
|
||||||
use rustc_middle::ty::{self, AdtKind, Ty, TypeVisitable};
|
use rustc_middle::ty::{self, AdtKind, Ty, TypeVisitable};
|
||||||
|
use rustc_session::errors::ExprParenthesesNeeded;
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_span::hygiene::DesugaringKind;
|
use rustc_span::hygiene::DesugaringKind;
|
||||||
use rustc_span::lev_distance::find_best_match_for_name;
|
use rustc_span::lev_distance::find_best_match_for_name;
|
||||||
@ -394,7 +395,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
if let Some(sp) =
|
if let Some(sp) =
|
||||||
tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp)
|
tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp)
|
||||||
{
|
{
|
||||||
tcx.sess.parse_sess.expr_parentheses_needed(&mut err, *sp);
|
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
|
||||||
}
|
}
|
||||||
err.emit();
|
err.emit();
|
||||||
oprnd_t = tcx.ty_error();
|
oprnd_t = tcx.ty_error();
|
||||||
|
@ -15,6 +15,7 @@ use rustc_infer::infer::{self, TyCtxtInferExt};
|
|||||||
use rustc_infer::traits::{self, StatementAsExpression};
|
use rustc_infer::traits::{self, StatementAsExpression};
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_middle::ty::{self, Binder, IsSuggestable, ToPredicate, Ty};
|
use rustc_middle::ty::{self, Binder, IsSuggestable, ToPredicate, Ty};
|
||||||
|
use rustc_session::errors::ExprParenthesesNeeded;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_trait_selection::infer::InferCtxtExt;
|
use rustc_trait_selection::infer::InferCtxtExt;
|
||||||
@ -895,7 +896,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let sp = self.tcx.sess.source_map().start_point(expr.span);
|
let sp = self.tcx.sess.source_map().start_point(expr.span);
|
||||||
if let Some(sp) = self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) {
|
if let Some(sp) = self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) {
|
||||||
// `{ 42 } &&x` (#61475) or `{ 42 } && if x { 1 } else { 0 }`
|
// `{ 42 } &&x` (#61475) or `{ 42 } && if x { 1 } else { 0 }`
|
||||||
self.tcx.sess.parse_sess.expr_parentheses_needed(err, *sp);
|
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ use rustc_middle::ty::adjustment::{
|
|||||||
};
|
};
|
||||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||||
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitable};
|
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeVisitable};
|
||||||
|
use rustc_session::errors::ExprParenthesesNeeded;
|
||||||
use rustc_span::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
use rustc_span::symbol::{sym, Ident};
|
use rustc_span::symbol::{sym, Ident};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
@ -677,7 +678,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// If the previous expression was a block expression, suggest parentheses
|
// If the previous expression was a block expression, suggest parentheses
|
||||||
// (turning this into a binary subtraction operation instead.)
|
// (turning this into a binary subtraction operation instead.)
|
||||||
// for example, `{2} - 2` -> `({2}) - 2` (see src\test\ui\parser\expr-as-stmt.rs)
|
// for example, `{2} - 2` -> `({2}) - 2` (see src\test\ui\parser\expr-as-stmt.rs)
|
||||||
self.tcx.sess.parse_sess.expr_parentheses_needed(&mut err, *sp);
|
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
|
||||||
} else {
|
} else {
|
||||||
match actual.kind() {
|
match actual.kind() {
|
||||||
Uint(_) if op == hir::UnOp::Neg => {
|
Uint(_) if op == hir::UnOp::Neg => {
|
||||||
|
@ -33,6 +33,7 @@ use rustc_errors::{
|
|||||||
fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
|
fluent, Applicability, DiagnosticBuilder, DiagnosticMessage, Handler, MultiSpan, PResult,
|
||||||
};
|
};
|
||||||
use rustc_errors::{pluralize, Diagnostic, ErrorGuaranteed, IntoDiagnostic};
|
use rustc_errors::{pluralize, Diagnostic, ErrorGuaranteed, IntoDiagnostic};
|
||||||
|
use rustc_session::errors::ExprParenthesesNeeded;
|
||||||
use rustc_span::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
use rustc_span::symbol::{kw, sym, Ident};
|
use rustc_span::symbol::{kw, sym, Ident};
|
||||||
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
|
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
|
||||||
@ -2049,7 +2050,7 @@ impl<'a> Parser<'a> {
|
|||||||
let mut err = self.struct_span_err(span, &msg);
|
let mut err = self.struct_span_err(span, &msg);
|
||||||
let sp = self.sess.source_map().start_point(self.token.span);
|
let sp = self.sess.source_map().start_point(self.token.span);
|
||||||
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
|
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
|
||||||
self.sess.expr_parentheses_needed(&mut err, *sp);
|
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
|
||||||
}
|
}
|
||||||
err.span_label(span, "expected expression");
|
err.span_label(span, "expected expression");
|
||||||
err
|
err
|
||||||
|
@ -1310,7 +1310,7 @@ impl<'a> Parser<'a> {
|
|||||||
// If the input is something like `if a { 1 } else { 2 } | if a { 3 } else { 4 }`
|
// If the input is something like `if a { 1 } else { 2 } | if a { 3 } else { 4 }`
|
||||||
// then suggest parens around the lhs.
|
// then suggest parens around the lhs.
|
||||||
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&lo) {
|
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&lo) {
|
||||||
self.sess.expr_parentheses_needed(&mut err, *sp);
|
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
|
||||||
}
|
}
|
||||||
err
|
err
|
||||||
})
|
})
|
||||||
|
@ -10,6 +10,7 @@ use rustc_ast::{
|
|||||||
};
|
};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, PResult};
|
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, PResult};
|
||||||
|
use rustc_session::errors::ExprParenthesesNeeded;
|
||||||
use rustc_span::source_map::{respan, Span, Spanned};
|
use rustc_span::source_map::{respan, Span, Spanned};
|
||||||
use rustc_span::symbol::{kw, sym, Ident};
|
use rustc_span::symbol::{kw, sym, Ident};
|
||||||
|
|
||||||
@ -693,7 +694,7 @@ impl<'a> Parser<'a> {
|
|||||||
|
|
||||||
let sp = self.sess.source_map().start_point(self.token.span);
|
let sp = self.sess.source_map().start_point(self.token.span);
|
||||||
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
|
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
|
||||||
self.sess.expr_parentheses_needed(&mut err, *sp);
|
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(err)
|
Err(err)
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
//! It also serves as an input to the parser itself.
|
//! It also serves as an input to the parser itself.
|
||||||
|
|
||||||
use crate::config::CheckCfg;
|
use crate::config::CheckCfg;
|
||||||
use crate::errors::{
|
use crate::errors::{FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError};
|
||||||
ExprParenthesesNeeded, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError,
|
|
||||||
};
|
|
||||||
use crate::lint::{
|
use crate::lint::{
|
||||||
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
|
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
|
||||||
};
|
};
|
||||||
@ -13,8 +11,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
|
|||||||
use rustc_data_structures::sync::{Lock, Lrc};
|
use rustc_data_structures::sync::{Lock, Lrc};
|
||||||
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
|
use rustc_errors::{emitter::SilentEmitter, ColorConfig, Handler};
|
||||||
use rustc_errors::{
|
use rustc_errors::{
|
||||||
fallback_fluent_bundle, AddToDiagnostic, Diagnostic, DiagnosticBuilder, DiagnosticId,
|
fallback_fluent_bundle, Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage,
|
||||||
DiagnosticMessage, EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, MultiSpan, StashKey,
|
EmissionGuarantee, ErrorGuaranteed, IntoDiagnostic, MultiSpan, StashKey,
|
||||||
};
|
};
|
||||||
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
|
use rustc_feature::{find_feature_issue, GateIssue, UnstableFeatures};
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
@ -324,12 +322,6 @@ impl ParseSess {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extend an error with a suggestion to wrap an expression with parentheses to allow the
|
|
||||||
/// parser to continue parsing the following operation as part of the same expression.
|
|
||||||
pub fn expr_parentheses_needed(&self, err: &mut Diagnostic, span: Span) {
|
|
||||||
ExprParenthesesNeeded::surrounding(span).add_to_diagnostic(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn save_proc_macro_span(&self, span: Span) -> usize {
|
pub fn save_proc_macro_span(&self, span: Span) -> usize {
|
||||||
let mut spans = self.proc_macro_quoted_spans.lock();
|
let mut spans = self.proc_macro_quoted_spans.lock();
|
||||||
spans.push(span);
|
spans.push(span);
|
||||||
|
Loading…
Reference in New Issue
Block a user