Skip to content

Commit d2f1c52

Browse files
committed
Remove use error recovery code
1 parent f5cdcf3 commit d2f1c52

File tree

3 files changed

+6
-64
lines changed

3 files changed

+6
-64
lines changed

compiler/rustc_parse/src/errors.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,6 @@ pub(crate) struct IncorrectAwait {
141141
pub suggestion: AwaitSuggestion,
142142
}
143143

144-
#[derive(Subdiagnostic)]
145-
#[multipart_suggestion(
146-
parse_incorrect_use_of_use_postfix_suggestion,
147-
applicability = "machine-applicable"
148-
)]
149-
pub(crate) struct UseSuggestion {
150-
#[suggestion_part(code = "")]
151-
pub removal: Span,
152-
#[suggestion_part(code = ".use{question_mark}")]
153-
pub dot_use: Span,
154-
pub question_mark: &'static str,
155-
}
156-
157-
#[derive(Diagnostic)]
158-
#[diag(parse_incorrect_use_of_use)]
159-
pub(crate) struct IncorrectUse {
160-
#[primary_span]
161-
pub span: Span,
162-
#[subdiagnostic]
163-
pub suggestion: UseSuggestion,
164-
}
165-
166144
#[derive(Diagnostic)]
167145
#[diag(parse_in_in_typo)]
168146
pub(crate) struct InInTypo {

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ use crate::errors::{
4040
DoubleColonInBound, ExpectedIdentifier, ExpectedSemi, ExpectedSemiSugg,
4141
GenericParamsWithoutAngleBrackets, GenericParamsWithoutAngleBracketsSugg,
4242
HelpIdentifierStartsWithNumber, HelpUseLatestEdition, InInTypo, IncorrectAwait,
43-
IncorrectSemicolon, IncorrectUse, IncorrectUseOfAwait, IncorrectUseOfUse,
44-
PatternMethodParamWithoutBody, QuestionMarkInType, QuestionMarkInTypeSugg, SelfParamNotFirst,
45-
StructLiteralBodyWithoutPath, StructLiteralBodyWithoutPathSugg, StructLiteralNeedingParens,
46-
StructLiteralNeedingParensSugg, SuggAddMissingLetStmt, SuggEscapeIdentifier, SuggRemoveComma,
47-
TernaryOperator, UnexpectedConstInGenericParam, UnexpectedConstParamDeclaration,
48-
UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets, UseEqInstead, UseSuggestion,
49-
WrapType,
43+
IncorrectSemicolon, IncorrectUseOfAwait, IncorrectUseOfUse, PatternMethodParamWithoutBody,
44+
QuestionMarkInType, QuestionMarkInTypeSugg, SelfParamNotFirst, StructLiteralBodyWithoutPath,
45+
StructLiteralBodyWithoutPathSugg, StructLiteralNeedingParens, StructLiteralNeedingParensSugg,
46+
SuggAddMissingLetStmt, SuggEscapeIdentifier, SuggRemoveComma, TernaryOperator,
47+
UnexpectedConstInGenericParam, UnexpectedConstParamDeclaration,
48+
UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets, UseEqInstead, WrapType,
5049
};
5150
use crate::parser::attr::InnerAttrPolicy;
5251
use crate::{exp, fluent_generated as fluent};
@@ -1968,20 +1967,6 @@ impl<'a> Parser<'a> {
19681967
self.maybe_recover_from_bad_qpath(expr)
19691968
}
19701969

1971-
/// Consumes alternative use syntaxes like `use!(<expr>)`, `use <expr>`,
1972-
/// `use? <expr>`, `use(<expr>)`, and `use { <expr> }`.
1973-
pub(super) fn recover_incorrect_use_syntax(&mut self, use_sp: Span) -> PResult<'a, P<Expr>> {
1974-
let (hi, expr, is_question) = if self.token == token::Not {
1975-
// Handle `use!(<expr>)`.
1976-
self.recover_macro()?
1977-
} else {
1978-
self.recover_prefix(use_sp, "use")?
1979-
};
1980-
let (sp, guar) = self.error_on_incorrect_use(use_sp, hi, &expr, is_question);
1981-
let expr = self.mk_expr_err(use_sp.to(sp), guar);
1982-
self.maybe_recover_from_bad_qpath(expr)
1983-
}
1984-
19851970
fn recover_macro(&mut self) -> PResult<'a, (Span, P<Expr>, bool)> {
19861971
self.expect(exp!(Not))?;
19871972
self.expect(exp!(OpenParen))?;
@@ -2033,25 +2018,6 @@ impl<'a> Parser<'a> {
20332018
(span, guar)
20342019
}
20352020

2036-
fn error_on_incorrect_use(
2037-
&self,
2038-
lo: Span,
2039-
hi: Span,
2040-
expr: &Expr,
2041-
is_question: bool,
2042-
) -> (Span, ErrorGuaranteed) {
2043-
let span = lo.to(hi);
2044-
let guar = self.dcx().emit_err(IncorrectUse {
2045-
span,
2046-
suggestion: UseSuggestion {
2047-
removal: lo.until(expr.span),
2048-
dot_use: expr.span.shrink_to_hi(),
2049-
question_mark: if is_question { "?" } else { "" },
2050-
},
2051-
});
2052-
(span, guar)
2053-
}
2054-
20552021
/// If encountering `future.await()`, consumes and emits an error.
20562022
pub(super) fn recover_from_await_method_call(&mut self) {
20572023
if self.token == token::OpenDelim(Delimiter::Parenthesis)

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,8 +1500,6 @@ impl<'a> Parser<'a> {
15001500
this.parse_expr_let(restrictions)
15011501
} else if this.eat_keyword(exp!(Underscore)) {
15021502
Ok(this.mk_expr(this.prev_token.span, ExprKind::Underscore))
1503-
} else if this.eat_keyword_noexpect(kw::Use) {
1504-
this.recover_incorrect_use_syntax(lo)
15051503
} else if this.token.uninterpolated_span().at_least_rust_2018() {
15061504
// `Span::at_least_rust_2018()` is somewhat expensive; don't get it repeatedly.
15071505
if this.token.uninterpolated_span().at_least_rust_2024()

0 commit comments

Comments
 (0)