Skip to content

Commit c0b7112

Browse files
committed
Auto merge of #40216 - frewsxcv:rollup, r=frewsxcv
Rollup of 7 pull requests - Successful merges: #39832, #40104, #40110, #40117, #40129, #40139, #40166 - Failed merges:
2 parents 5907ed6 + ba39e5d commit c0b7112

File tree

35 files changed

+411
-144
lines changed

35 files changed

+411
-144
lines changed

src/libcollections/fmt.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ use string;
524524
pub fn format(args: Arguments) -> string::String {
525525
let capacity = args.estimated_capacity();
526526
let mut output = string::String::with_capacity(capacity);
527-
let _ = output.write_fmt(args);
527+
output.write_fmt(args)
528+
.expect("a formatting trait implementation returned an error");
528529
output
529530
}

src/libcollections/macros.rs

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ macro_rules! vec {
7272
///
7373
/// [fmt]: ../std/fmt/index.html
7474
///
75+
/// # Panics
76+
///
77+
/// `format!` panics if a formatting trait implementation returns an error.
78+
/// This indicates an incorrect implementation
79+
/// since `fmt::Write for String` never returns an error itself.
80+
///
7581
/// # Examples
7682
///
7783
/// ```

src/libcollections/string.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1900,13 +1900,20 @@ pub trait ToString {
19001900
fn to_string(&self) -> String;
19011901
}
19021902

1903+
/// # Panics
1904+
///
1905+
/// In this implementation, the `to_string` method panics
1906+
/// if the `Display` implementation returns an error.
1907+
/// This indicates an incorrect `Display` implementation
1908+
/// since `fmt::Write for String` never returns an error itself.
19031909
#[stable(feature = "rust1", since = "1.0.0")]
19041910
impl<T: fmt::Display + ?Sized> ToString for T {
19051911
#[inline]
19061912
default fn to_string(&self) -> String {
19071913
use core::fmt::Write;
19081914
let mut buf = String::new();
1909-
let _ = buf.write_fmt(format_args!("{}", self));
1915+
buf.write_fmt(format_args!("{}", self))
1916+
.expect("a Display implementation return an error unexpectedly");
19101917
buf.shrink_to_fit();
19111918
buf
19121919
}

src/libproc_macro/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ pub mod __internal {
125125
fn register_attr_proc_macro(&mut self,
126126
name: &str,
127127
expand: fn(TokenStream, TokenStream) -> TokenStream);
128+
129+
fn register_bang_proc_macro(&mut self,
130+
name: &str,
131+
expand: fn(TokenStream) -> TokenStream);
128132
}
129133

130134
// Emulate scoped_thread_local!() here essentially

src/librustc/mir/mod.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ pub enum Rvalue<'tcx> {
983983
Use(Operand<'tcx>),
984984

985985
/// [x; 32]
986-
Repeat(Operand<'tcx>, TypedConstVal<'tcx>),
986+
Repeat(Operand<'tcx>, ConstUsize),
987987

988988
/// &x or &mut x
989989
Ref(&'tcx Region, BorrowKind, Lvalue<'tcx>),
@@ -1038,7 +1038,8 @@ pub enum CastKind {
10381038

10391039
#[derive(Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
10401040
pub enum AggregateKind<'tcx> {
1041-
Array,
1041+
/// The type is of the element
1042+
Array(Ty<'tcx>),
10421043
Tuple,
10431044
/// The second field is variant number (discriminant), it's equal to 0
10441045
/// for struct and union expressions. The fourth field is active field
@@ -1135,7 +1136,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
11351136
}
11361137

11371138
match *kind {
1138-
AggregateKind::Array => write!(fmt, "{:?}", lvs),
1139+
AggregateKind::Array(_) => write!(fmt, "{:?}", lvs),
11391140

11401141
AggregateKind::Tuple => {
11411142
match lvs.len() {
@@ -1202,19 +1203,6 @@ pub struct Constant<'tcx> {
12021203
pub literal: Literal<'tcx>,
12031204
}
12041205

1205-
#[derive(Clone, RustcEncodable, RustcDecodable)]
1206-
pub struct TypedConstVal<'tcx> {
1207-
pub ty: Ty<'tcx>,
1208-
pub span: Span,
1209-
pub value: ConstUsize,
1210-
}
1211-
1212-
impl<'tcx> Debug for TypedConstVal<'tcx> {
1213-
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
1214-
write!(fmt, "const {}", ConstInt::Usize(self.value))
1215-
}
1216-
}
1217-
12181206
newtype_index!(Promoted, "promoted");
12191207

12201208
#[derive(Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]

src/librustc/mir/tcx.rs

+19-25
Original file line numberDiff line numberDiff line change
@@ -134,76 +134,70 @@ impl<'tcx> Lvalue<'tcx> {
134134
}
135135

136136
impl<'tcx> Rvalue<'tcx> {
137-
pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Ty<'tcx>>
137+
pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx>
138138
{
139139
match *self {
140-
Rvalue::Use(ref operand) => Some(operand.ty(mir, tcx)),
140+
Rvalue::Use(ref operand) => operand.ty(mir, tcx),
141141
Rvalue::Repeat(ref operand, ref count) => {
142142
let op_ty = operand.ty(mir, tcx);
143-
let count = count.value.as_u64(tcx.sess.target.uint_type);
143+
let count = count.as_u64(tcx.sess.target.uint_type);
144144
assert_eq!(count as usize as u64, count);
145-
Some(tcx.mk_array(op_ty, count as usize))
145+
tcx.mk_array(op_ty, count as usize)
146146
}
147147
Rvalue::Ref(reg, bk, ref lv) => {
148148
let lv_ty = lv.ty(mir, tcx).to_ty(tcx);
149-
Some(tcx.mk_ref(reg,
149+
tcx.mk_ref(reg,
150150
ty::TypeAndMut {
151151
ty: lv_ty,
152152
mutbl: bk.to_mutbl_lossy()
153153
}
154-
))
154+
)
155155
}
156-
Rvalue::Len(..) => Some(tcx.types.usize),
157-
Rvalue::Cast(.., ty) => Some(ty),
156+
Rvalue::Len(..) => tcx.types.usize,
157+
Rvalue::Cast(.., ty) => ty,
158158
Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
159159
let lhs_ty = lhs.ty(mir, tcx);
160160
let rhs_ty = rhs.ty(mir, tcx);
161-
Some(op.ty(tcx, lhs_ty, rhs_ty))
161+
op.ty(tcx, lhs_ty, rhs_ty)
162162
}
163163
Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
164164
let lhs_ty = lhs.ty(mir, tcx);
165165
let rhs_ty = rhs.ty(mir, tcx);
166166
let ty = op.ty(tcx, lhs_ty, rhs_ty);
167-
let ty = tcx.intern_tup(&[ty, tcx.types.bool], false);
168-
Some(ty)
167+
tcx.intern_tup(&[ty, tcx.types.bool], false)
169168
}
170169
Rvalue::UnaryOp(_, ref operand) => {
171-
Some(operand.ty(mir, tcx))
170+
operand.ty(mir, tcx)
172171
}
173172
Rvalue::Discriminant(ref lval) => {
174173
let ty = lval.ty(mir, tcx).to_ty(tcx);
175174
if let ty::TyAdt(adt_def, _) = ty.sty {
176-
Some(adt_def.repr.discr_type().to_ty(tcx))
175+
adt_def.repr.discr_type().to_ty(tcx)
177176
} else {
178177
// Undefined behaviour, bug for now; may want to return something for
179178
// the `discriminant` intrinsic later.
180179
bug!("Rvalue::Discriminant on Lvalue of type {:?}", ty);
181180
}
182181
}
183182
Rvalue::Box(t) => {
184-
Some(tcx.mk_box(t))
183+
tcx.mk_box(t)
185184
}
186185
Rvalue::Aggregate(ref ak, ref ops) => {
187186
match *ak {
188-
AggregateKind::Array => {
189-
if let Some(operand) = ops.get(0) {
190-
let ty = operand.ty(mir, tcx);
191-
Some(tcx.mk_array(ty, ops.len()))
192-
} else {
193-
None
194-
}
187+
AggregateKind::Array(ty) => {
188+
tcx.mk_array(ty, ops.len())
195189
}
196190
AggregateKind::Tuple => {
197-
Some(tcx.mk_tup(
191+
tcx.mk_tup(
198192
ops.iter().map(|op| op.ty(mir, tcx)),
199193
false
200-
))
194+
)
201195
}
202196
AggregateKind::Adt(def, _, substs, _) => {
203-
Some(tcx.item_type(def.did).subst(tcx, substs))
197+
tcx.item_type(def.did).subst(tcx, substs)
204198
}
205199
AggregateKind::Closure(did, substs) => {
206-
Some(tcx.mk_closure_from_closure_substs(did, substs))
200+
tcx.mk_closure_from_closure_substs(did, substs)
207201
}
208202
}
209203
}

src/librustc/mir/visit.rs

+4-23
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,6 @@ macro_rules! make_mir_visitor {
235235
self.super_const_usize(const_usize);
236236
}
237237

238-
fn visit_typed_const_val(&mut self,
239-
val: & $($mutability)* TypedConstVal<'tcx>,
240-
location: Location) {
241-
self.super_typed_const_val(val, location);
242-
}
243-
244238
fn visit_local_decl(&mut self,
245239
local_decl: & $($mutability)* LocalDecl<'tcx>) {
246240
self.super_local_decl(local_decl);
@@ -467,9 +461,9 @@ macro_rules! make_mir_visitor {
467461
}
468462

469463
Rvalue::Repeat(ref $($mutability)* value,
470-
ref $($mutability)* typed_const_val) => {
464+
ref $($mutability)* length) => {
471465
self.visit_operand(value, location);
472-
self.visit_typed_const_val(typed_const_val, location);
466+
self.visit_const_usize(length, location);
473467
}
474468

475469
Rvalue::Ref(r, bk, ref $($mutability)* path) => {
@@ -515,7 +509,8 @@ macro_rules! make_mir_visitor {
515509
Rvalue::Aggregate(ref $($mutability)* kind,
516510
ref $($mutability)* operands) => {
517511
match *kind {
518-
AggregateKind::Array => {
512+
AggregateKind::Array(ref $($mutability)* ty) => {
513+
self.visit_ty(ty);
519514
}
520515
AggregateKind::Tuple => {
521516
}
@@ -647,20 +642,6 @@ macro_rules! make_mir_visitor {
647642
self.visit_literal(literal, location);
648643
}
649644

650-
fn super_typed_const_val(&mut self,
651-
constant: & $($mutability)* TypedConstVal<'tcx>,
652-
location: Location) {
653-
let TypedConstVal {
654-
ref $($mutability)* span,
655-
ref $($mutability)* ty,
656-
ref $($mutability)* value,
657-
} = *constant;
658-
659-
self.visit_span(span);
660-
self.visit_ty(ty);
661-
self.visit_const_usize(value, location);
662-
}
663-
664645
fn super_literal(&mut self,
665646
literal: & $($mutability)* Literal<'tcx>,
666647
location: Location) {

src/librustc_llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub enum CallConv {
5353
X86_64_SysV = 78,
5454
X86_64_Win64 = 79,
5555
X86_VectorCall = 80,
56+
X86_Intr = 83,
5657
}
5758

5859
/// LLVMRustLinkage

src/librustc_metadata/creader.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ impl<'a> CrateLoader<'a> {
586586
use proc_macro::__internal::Registry;
587587
use rustc_back::dynamic_lib::DynamicLibrary;
588588
use syntax_ext::deriving::custom::ProcMacroDerive;
589-
use syntax_ext::proc_macro_impl::AttrProcMacro;
589+
use syntax_ext::proc_macro_impl::{AttrProcMacro, BangProcMacro};
590590

591591
let path = match dylib {
592592
Some(dylib) => dylib,
@@ -630,6 +630,15 @@ impl<'a> CrateLoader<'a> {
630630
);
631631
self.0.push((Symbol::intern(name), Rc::new(expand)));
632632
}
633+
634+
fn register_bang_proc_macro(&mut self,
635+
name: &str,
636+
expand: fn(TokenStream) -> TokenStream) {
637+
let expand = SyntaxExtension::ProcMacro(
638+
Box::new(BangProcMacro { inner: expand })
639+
);
640+
self.0.push((Symbol::intern(name), Rc::new(expand)));
641+
}
633642
}
634643

635644
let mut my_registrar = MyRegistrar(Vec::new());

src/librustc_mir/build/expr/as_rvalue.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
148148
// to the same MIR as `let x = ();`.
149149

150150
// first process the set of fields
151+
let el_ty = expr.ty.sequence_element_type(this.hir.tcx());
151152
let fields: Vec<_> =
152153
fields.into_iter()
153154
.map(|f| unpack!(block = this.as_operand(block, f)))
154155
.collect();
155156

156-
block.and(Rvalue::Aggregate(AggregateKind::Array, fields))
157+
block.and(Rvalue::Aggregate(AggregateKind::Array(el_ty), fields))
157158
}
158159
ExprKind::Tuple { fields } => { // see (*) above
159160
// first process the set of fields

src/librustc_mir/hair/cx/expr.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
602602

603603
ExprKind::Repeat {
604604
value: v.to_ref(),
605-
count: TypedConstVal {
606-
ty: cx.tcx.types.usize,
607-
span: c.span,
608-
value: count
609-
}
605+
count: count,
610606
}
611607
}
612608
hir::ExprRet(ref v) => ExprKind::Return { value: v.to_ref() },

src/librustc_mir/hair/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
//! unit-tested and separated from the Rust source and compiler data
1515
//! structures.
1616
17-
use rustc::mir::{BinOp, BorrowKind, Field, Literal, UnOp, TypedConstVal};
17+
use rustc_const_math::ConstUsize;
18+
use rustc::mir::{BinOp, BorrowKind, Field, Literal, UnOp};
1819
use rustc::hir::def_id::DefId;
1920
use rustc::middle::region::CodeExtent;
2021
use rustc::ty::subst::Substs;
@@ -219,7 +220,7 @@ pub enum ExprKind<'tcx> {
219220
},
220221
Repeat {
221222
value: ExprRef<'tcx>,
222-
count: TypedConstVal<'tcx>,
223+
count: ConstUsize,
223224
},
224225
Array {
225226
fields: Vec<ExprRef<'tcx>>,

src/librustc_mir/transform/qualify_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
752752
}
753753

754754
if Some(def.did) == self.tcx.lang_items.unsafe_cell_type() {
755-
let ty = rvalue.ty(self.mir, self.tcx).unwrap();
755+
let ty = rvalue.ty(self.mir, self.tcx);
756756
self.add_type(ty);
757757
assert!(self.qualif.intersects(Qualif::MUTABLE_INTERIOR));
758758
// Even if the value inside may not need dropping,

src/librustc_mir/transform/type_check.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
8383

8484
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
8585
self.super_rvalue(rvalue, location);
86-
if let Some(ty) = rvalue.ty(self.mir, self.tcx()) {
87-
self.sanitize_type(rvalue, ty);
88-
}
86+
let rval_ty = rvalue.ty(self.mir, self.tcx());
87+
self.sanitize_type(rvalue, rval_ty);
8988
}
9089

9190
fn visit_mir(&mut self, mir: &Mir<'tcx>) {
@@ -356,14 +355,10 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
356355
StatementKind::Assign(ref lv, ref rv) => {
357356
let lv_ty = lv.ty(mir, tcx).to_ty(tcx);
358357
let rv_ty = rv.ty(mir, tcx);
359-
if let Some(rv_ty) = rv_ty {
360-
if let Err(terr) = self.sub_types(rv_ty, lv_ty) {
361-
span_mirbug!(self, stmt, "bad assignment ({:?} = {:?}): {:?}",
362-
lv_ty, rv_ty, terr);
363-
}
358+
if let Err(terr) = self.sub_types(rv_ty, lv_ty) {
359+
span_mirbug!(self, stmt, "bad assignment ({:?} = {:?}): {:?}",
360+
lv_ty, rv_ty, terr);
364361
}
365-
// FIXME: rvalue with undeterminable type - e.g. AggregateKind::Array branch that
366-
// returns `None`.
367362
}
368363
StatementKind::SetDiscriminant{ ref lvalue, variant_index } => {
369364
let lvalue_type = lvalue.ty(mir, tcx).to_ty(tcx);

0 commit comments

Comments
 (0)