Skip to content

Commit c2b56fb

Browse files
authored
Auto merge of #34552 - Manishearth:rollup, r=Manishearth
Rollup of 11 pull requests - Successful merges: #34355, #34446, #34459, #34460, #34467, #34495, #34497, #34499, #34513, #34536, #34542 - Failed merges:
2 parents 5dd1001 + 8e2598c commit c2b56fb

File tree

30 files changed

+620
-445
lines changed

30 files changed

+620
-445
lines changed

src/librustc/hir/lowering.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use session::Session;
5050
use std::collections::BTreeMap;
5151
use std::iter;
5252
use syntax::ast::*;
53+
use syntax::errors;
5354
use syntax::ptr::P;
5455
use syntax::codemap::{respan, Spanned};
5556
use syntax::parse::token;
@@ -60,7 +61,7 @@ use syntax_pos::Span;
6061
pub struct LoweringContext<'a> {
6162
crate_root: Option<&'static str>,
6263
// Use to assign ids to hir nodes that do not directly correspond to an ast node
63-
id_assigner: &'a NodeIdAssigner,
64+
sess: Option<&'a Session>,
6465
// As we walk the AST we must keep track of the current 'parent' def id (in
6566
// the form of a DefIndex) so that if we create a new node which introduces
6667
// a definition, then we can properly create the def id.
@@ -99,7 +100,6 @@ impl Resolver for DummyResolver {
99100

100101
pub fn lower_crate(sess: &Session,
101102
krate: &Crate,
102-
id_assigner: &NodeIdAssigner,
103103
resolver: &mut Resolver)
104104
-> hir::Crate {
105105
// We're constructing the HIR here; we don't care what we will
@@ -115,17 +115,17 @@ pub fn lower_crate(sess: &Session,
115115
} else {
116116
Some("std")
117117
},
118-
id_assigner: id_assigner,
118+
sess: Some(sess),
119119
parent_def: None,
120120
resolver: resolver,
121121
}.lower_crate(krate)
122122
}
123123

124124
impl<'a> LoweringContext<'a> {
125-
pub fn testing_context(id_assigner: &'a NodeIdAssigner, resolver: &'a mut Resolver) -> Self {
125+
pub fn testing_context(resolver: &'a mut Resolver) -> Self {
126126
LoweringContext {
127127
crate_root: None,
128-
id_assigner: id_assigner,
128+
sess: None,
129129
parent_def: None,
130130
resolver: resolver,
131131
}
@@ -161,7 +161,12 @@ impl<'a> LoweringContext<'a> {
161161
}
162162

163163
fn next_id(&self) -> NodeId {
164-
self.id_assigner.next_node_id()
164+
self.sess.map(Session::next_node_id).unwrap_or(0)
165+
}
166+
167+
fn diagnostic(&self) -> &errors::Handler {
168+
self.sess.map(Session::diagnostic)
169+
.unwrap_or_else(|| panic!("this lowerer cannot emit diagnostics"))
165170
}
166171

167172
fn str_to_ident(&self, s: &'static str) -> Name {
@@ -786,7 +791,7 @@ impl<'a> LoweringContext<'a> {
786791
if let Some(SelfKind::Explicit(..)) = sig.decl.get_self().map(|eself| eself.node) {
787792
match hir_sig.decl.get_self().map(|eself| eself.node) {
788793
Some(hir::SelfKind::Value(..)) | Some(hir::SelfKind::Region(..)) => {
789-
self.id_assigner.diagnostic().span_err(sig.decl.inputs[0].ty.span,
794+
self.diagnostic().span_err(sig.decl.inputs[0].ty.span,
790795
"the type placeholder `_` is not allowed within types on item signatures");
791796
}
792797
_ => {}
@@ -1212,7 +1217,7 @@ impl<'a> LoweringContext<'a> {
12121217
make_struct(self, e, &["RangeInclusive", "NonEmpty"],
12131218
&[("start", e1), ("end", e2)]),
12141219

1215-
_ => panic!(self.id_assigner.diagnostic()
1220+
_ => panic!(self.diagnostic()
12161221
.span_fatal(e.span, "inclusive range with no end")),
12171222
};
12181223
}

src/librustc/hir/map/def_collector.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ pub struct DefCollector<'ast> {
2525
// If we are walking HIR (c.f., AST), we need to keep a reference to the
2626
// crate.
2727
hir_crate: Option<&'ast hir::Crate>,
28-
pub definitions: Definitions,
28+
definitions: &'ast mut Definitions,
2929
parent_def: Option<DefIndex>,
3030
}
3131

3232
impl<'ast> DefCollector<'ast> {
33-
pub fn root() -> DefCollector<'ast> {
33+
pub fn root(definitions: &'ast mut Definitions) -> DefCollector<'ast> {
3434
let mut collector = DefCollector {
3535
hir_crate: None,
36-
definitions: Definitions::new(),
36+
definitions: definitions,
3737
parent_def: None,
3838
};
3939
let root = collector.create_def_with_parent(None, CRATE_NODE_ID, DefPathData::CrateRoot);
@@ -48,7 +48,7 @@ impl<'ast> DefCollector<'ast> {
4848
pub fn extend(parent_node: NodeId,
4949
parent_def_path: DefPath,
5050
parent_def_id: DefId,
51-
definitions: Definitions)
51+
definitions: &'ast mut Definitions)
5252
-> DefCollector<'ast> {
5353
let mut collector = DefCollector {
5454
hir_crate: None,

src/librustc/hir/map/definitions.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
use middle::cstore::LOCAL_CRATE;
1212
use hir::def_id::{DefId, DefIndex};
13+
use hir::map::def_collector::DefCollector;
1314
use rustc_data_structures::fnv::FnvHashMap;
14-
use syntax::ast;
15+
use syntax::{ast, visit};
1516
use syntax::parse::token::InternedString;
1617
use util::nodemap::NodeMap;
1718

@@ -189,6 +190,11 @@ impl Definitions {
189190
}
190191
}
191192

193+
pub fn collect(&mut self, krate: &ast::Crate) {
194+
let mut def_collector = DefCollector::root(self);
195+
visit::walk_crate(&mut def_collector, krate);
196+
}
197+
192198
/// Get the number of definitions.
193199
pub fn len(&self) -> usize {
194200
self.data.len()

src/librustc/hir/map/mod.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndex};
2424
use syntax::abi::Abi;
2525
use syntax::ast::{self, Name, NodeId, DUMMY_NODE_ID, };
2626
use syntax::codemap::Spanned;
27-
use syntax::visit;
2827
use syntax_pos::Span;
2928

3029
use hir::*;
@@ -780,12 +779,6 @@ impl<F: FoldOps> Folder for IdAndSpanUpdater<F> {
780779
}
781780
}
782781

783-
pub fn collect_definitions<'ast>(krate: &'ast ast::Crate) -> Definitions {
784-
let mut def_collector = DefCollector::root();
785-
visit::walk_crate(&mut def_collector, krate);
786-
def_collector.definitions
787-
}
788-
789782
pub fn map_crate<'ast>(forest: &'ast mut Forest,
790783
definitions: Definitions)
791784
-> Map<'ast> {
@@ -842,13 +835,12 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
842835
let ii = map.forest.inlined_items.alloc(ii);
843836
let ii_parent_id = fld.new_id(DUMMY_NODE_ID);
844837

845-
let defs = mem::replace(&mut *map.definitions.borrow_mut(), Definitions::new());
838+
let defs = &mut *map.definitions.borrow_mut();
846839
let mut def_collector = DefCollector::extend(ii_parent_id,
847840
parent_def_path.clone(),
848841
parent_def_id,
849842
defs);
850843
def_collector.walk_item(ii, map.krate());
851-
*map.definitions.borrow_mut() = def_collector.definitions;
852844

853845
let mut collector = NodeCollector::extend(map.krate(),
854846
ii,

src/librustc/session/mod.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use ty::tls;
2020
use util::nodemap::{NodeMap, FnvHashMap};
2121
use mir::transform as mir_pass;
2222

23-
use syntax::ast::{NodeId, NodeIdAssigner, Name};
23+
use syntax::ast::{NodeId, Name};
2424
use errors::{self, DiagnosticBuilder};
2525
use errors::emitter::{Emitter, BasicEmitter, EmitterWriter};
2626
use syntax::json::JsonEmitter;
@@ -272,6 +272,9 @@ impl Session {
272272

273273
id
274274
}
275+
pub fn next_node_id(&self) -> NodeId {
276+
self.reserve_node_ids(1)
277+
}
275278
pub fn diagnostic<'a>(&'a self) -> &'a errors::Handler {
276279
&self.parse_sess.span_diagnostic
277280
}
@@ -345,20 +348,6 @@ impl Session {
345348
}
346349
}
347350

348-
impl NodeIdAssigner for Session {
349-
fn next_node_id(&self) -> NodeId {
350-
self.reserve_node_ids(1)
351-
}
352-
353-
fn peek_node_id(&self) -> NodeId {
354-
self.next_node_id.get().checked_add(1).unwrap()
355-
}
356-
357-
fn diagnostic(&self) -> &errors::Handler {
358-
self.diagnostic()
359-
}
360-
}
361-
362351
fn split_msg_into_multilines(msg: &str) -> Option<String> {
363352
// Conditions for enabling multi-line errors:
364353
if !msg.contains("mismatched types") &&

src/librustc_const_eval/eval.rs

+41-48
Original file line numberDiff line numberDiff line change
@@ -543,54 +543,47 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
543543
let result = match e.node {
544544
hir::ExprUnary(hir::UnNeg, ref inner) => {
545545
// unary neg literals already got their sign during creation
546-
match inner.node {
547-
hir::ExprLit(ref lit) => {
548-
use syntax::ast::*;
549-
use syntax::ast::LitIntType::*;
550-
const I8_OVERFLOW: u64 = ::std::i8::MAX as u64 + 1;
551-
const I16_OVERFLOW: u64 = ::std::i16::MAX as u64 + 1;
552-
const I32_OVERFLOW: u64 = ::std::i32::MAX as u64 + 1;
553-
const I64_OVERFLOW: u64 = ::std::i64::MAX as u64 + 1;
554-
match (&lit.node, ety.map(|t| &t.sty)) {
555-
(&LitKind::Int(I8_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I8))) |
556-
(&LitKind::Int(I8_OVERFLOW, Signed(IntTy::I8)), _) => {
557-
return Ok(Integral(I8(::std::i8::MIN)))
558-
},
559-
(&LitKind::Int(I16_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I16))) |
560-
(&LitKind::Int(I16_OVERFLOW, Signed(IntTy::I16)), _) => {
561-
return Ok(Integral(I16(::std::i16::MIN)))
562-
},
563-
(&LitKind::Int(I32_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I32))) |
564-
(&LitKind::Int(I32_OVERFLOW, Signed(IntTy::I32)), _) => {
565-
return Ok(Integral(I32(::std::i32::MIN)))
566-
},
567-
(&LitKind::Int(I64_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I64))) |
568-
(&LitKind::Int(I64_OVERFLOW, Signed(IntTy::I64)), _) => {
569-
return Ok(Integral(I64(::std::i64::MIN)))
570-
},
571-
(&LitKind::Int(n, Unsuffixed), Some(&ty::TyInt(IntTy::Is))) |
572-
(&LitKind::Int(n, Signed(IntTy::Is)), _) => {
573-
match tcx.sess.target.int_type {
574-
IntTy::I16 => if n == I16_OVERFLOW {
575-
return Ok(Integral(Isize(Is16(::std::i16::MIN))));
576-
},
577-
IntTy::I32 => if n == I32_OVERFLOW {
578-
return Ok(Integral(Isize(Is32(::std::i32::MIN))));
579-
},
580-
IntTy::I64 => if n == I64_OVERFLOW {
581-
return Ok(Integral(Isize(Is64(::std::i64::MIN))));
582-
},
583-
_ => bug!(),
584-
}
585-
},
586-
_ => {},
587-
}
588-
},
589-
hir::ExprUnary(hir::UnNeg, ref inner) => {
590-
// skip `--$expr`
591-
return eval_const_expr_partial(tcx, inner, ty_hint, fn_args);
592-
},
593-
_ => {},
546+
if let hir::ExprLit(ref lit) = inner.node {
547+
use syntax::ast::*;
548+
use syntax::ast::LitIntType::*;
549+
const I8_OVERFLOW: u64 = ::std::i8::MAX as u64 + 1;
550+
const I16_OVERFLOW: u64 = ::std::i16::MAX as u64 + 1;
551+
const I32_OVERFLOW: u64 = ::std::i32::MAX as u64 + 1;
552+
const I64_OVERFLOW: u64 = ::std::i64::MAX as u64 + 1;
553+
match (&lit.node, ety.map(|t| &t.sty)) {
554+
(&LitKind::Int(I8_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I8))) |
555+
(&LitKind::Int(I8_OVERFLOW, Signed(IntTy::I8)), _) => {
556+
return Ok(Integral(I8(::std::i8::MIN)))
557+
},
558+
(&LitKind::Int(I16_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I16))) |
559+
(&LitKind::Int(I16_OVERFLOW, Signed(IntTy::I16)), _) => {
560+
return Ok(Integral(I16(::std::i16::MIN)))
561+
},
562+
(&LitKind::Int(I32_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I32))) |
563+
(&LitKind::Int(I32_OVERFLOW, Signed(IntTy::I32)), _) => {
564+
return Ok(Integral(I32(::std::i32::MIN)))
565+
},
566+
(&LitKind::Int(I64_OVERFLOW, Unsuffixed), Some(&ty::TyInt(IntTy::I64))) |
567+
(&LitKind::Int(I64_OVERFLOW, Signed(IntTy::I64)), _) => {
568+
return Ok(Integral(I64(::std::i64::MIN)))
569+
},
570+
(&LitKind::Int(n, Unsuffixed), Some(&ty::TyInt(IntTy::Is))) |
571+
(&LitKind::Int(n, Signed(IntTy::Is)), _) => {
572+
match tcx.sess.target.int_type {
573+
IntTy::I16 => if n == I16_OVERFLOW {
574+
return Ok(Integral(Isize(Is16(::std::i16::MIN))));
575+
},
576+
IntTy::I32 => if n == I32_OVERFLOW {
577+
return Ok(Integral(Isize(Is32(::std::i32::MIN))));
578+
},
579+
IntTy::I64 => if n == I64_OVERFLOW {
580+
return Ok(Integral(Isize(Is64(::std::i64::MIN))));
581+
},
582+
_ => bug!(),
583+
}
584+
},
585+
_ => {},
586+
}
594587
}
595588
match eval_const_expr_partial(tcx, &inner, ty_hint, fn_args)? {
596589
Float(f) => Float(-f),

0 commit comments

Comments
 (0)