fatal error instead of ICE for impossible range during HIR lowering

End-less ranges (`a...`) don't parse but bad syntax extensions could
conceivably produce them. Unbounded ranges (`...`) do parse and are
caught here.

The other panics in HIR lowering are all for unexpanded macros, which
cannot be constructed by bad syntax extensions.
This commit is contained in:
Alex Burka 2016-03-15 13:03:42 -04:00
parent cd80c1bb55
commit 9799cacba3
4 changed files with 20 additions and 3 deletions

View file

@ -336,6 +336,10 @@ impl NodeIdAssigner for Session {
fn peek_node_id(&self) -> NodeId {
self.next_node_id.get().checked_add(1).unwrap()
}
fn diagnostic(&self) -> &errors::Handler {
self.diagnostic()
}
}
fn split_msg_into_multilines(msg: &str) -> Option<String> {

View file

@ -68,6 +68,7 @@ use std::collections::HashMap;
use std::iter;
use syntax::ast::*;
use syntax::attr::{ThinAttributes, ThinAttributesExt};
use syntax::errors::Handler;
use syntax::ext::mtwt;
use syntax::ptr::P;
use syntax::codemap::{respan, Spanned, Span};
@ -140,6 +141,11 @@ impl<'a, 'hir> LoweringContext<'a> {
result
}
}
// panics if this LoweringContext's NodeIdAssigner is not a Session
fn diagnostic(&self) -> &Handler {
self.id_assigner.diagnostic()
}
}
// Utility fn for setting and unsetting the cached id.
@ -1289,7 +1295,8 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
make_struct(lctx, e, &["RangeInclusive", "NonEmpty"],
&[("start", e1), ("end", e2)]),
_ => panic!("impossible range in AST"),
_ => panic!(lctx.diagnostic().span_fatal(e.span,
"inclusive range with no end"))
}
});
}

View file

@ -19,6 +19,7 @@ pub use self::PathParameters::*;
use attr::ThinAttributes;
use codemap::{Span, Spanned, DUMMY_SP, ExpnId};
use abi::Abi;
use errors;
use ext::base;
use ext::tt::macro_parser;
use parse::token::InternedString;
@ -344,6 +345,10 @@ pub const DUMMY_NODE_ID: NodeId = !0;
pub trait NodeIdAssigner {
fn next_node_id(&self) -> NodeId;
fn peek_node_id(&self) -> NodeId;
fn diagnostic(&self) -> &errors::Handler {
panic!("this ID assigner cannot emit diagnostics")
}
}
/// The AST represents all type param bounds as types.

View file

@ -13,6 +13,7 @@
#![feature(inclusive_range_syntax, inclusive_range)]
pub fn main() {
for _ in 1... {}
} //~ ERROR expected one of
for _ in 1... {} //~ERROR inclusive range with no end
//~^HELP 28237
}