Skip to content

Commit

Permalink
Rollup merge of rust-lang#101049 - JeanCASPAR:remove-span_fatal-from-…
Browse files Browse the repository at this point in the history
…ast_lowering, r=davidtwco

Remove span fatal from ast lowering

Now the crate `rustc_ast_lowering` is fully migrated to `SessionDiagnostic`.

r? `@davidtwco`
  • Loading branch information
matthiaskrgr authored Aug 31, 2022
2 parents 78e1294 + 79d4f09 commit eda68d7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,10 @@ pub struct ArbitraryExpressionInPattern {
#[primary_span]
pub span: Span,
}

#[derive(SessionDiagnostic, Clone, Copy)]
#[diag(ast_lowering::inclusive_range_with_no_end)]
pub struct InclusiveRangeWithNoEnd {
#[primary_span]
pub span: Span,
}
12 changes: 9 additions & 3 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::errors::{
AsyncGeneratorsNotSupported, AsyncNonMoveClosureNotSupported, AwaitOnlyInAsyncFnAndBlocks,
BaseExpressionDoubleDot, ClosureCannotBeStatic, FunctionalRecordUpdateDestructuringAssignemnt,
GeneratorTooManyParameters, NotSupportedForLifetimeBinderAsyncClosure, RustcBoxAttributeError,
UnderscoreExprLhsAssign,
GeneratorTooManyParameters, InclusiveRangeWithNoEnd, NotSupportedForLifetimeBinderAsyncClosure,
RustcBoxAttributeError, UnderscoreExprLhsAssign,
};
use super::ResolverAstLoweringExt;
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
Expand Down Expand Up @@ -1264,7 +1264,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
(Some(..), Some(..), HalfOpen) => hir::LangItem::Range,
(None, Some(..), Closed) => hir::LangItem::RangeToInclusive,
(Some(..), Some(..), Closed) => unreachable!(),
(_, None, Closed) => self.diagnostic().span_fatal(span, "inclusive range with no end"),
(start, None, Closed) => {
self.tcx.sess.emit_err(InclusiveRangeWithNoEnd { span });
match start {
Some(..) => hir::LangItem::RangeFrom,
None => hir::LangItem::RangeFull,
}
}
};

let fields = self.arena.alloc_from_iter(
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#![feature(never_type)]
#![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]

#[macro_use]
extern crate tracing;
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/ast_lowering.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,5 @@ ast_lowering_not_supported_for_lifetime_binder_async_closure =
ast_lowering_arbitrary_expression_in_pattern =
arbitrary expressions aren't allowed in patterns
ast_lowering_inclusive_range_with_no_end = inclusive range with no end

0 comments on commit eda68d7

Please sign in to comment.