Skip to content

Commit 5b838c5

Browse files
committed
Auto merge of rust-lang#30555 - Manishearth:rollup, r=Manishearth
- Successful merges: rust-lang#30485, rust-lang#30490, rust-lang#30513, rust-lang#30518, rust-lang#30528, rust-lang#30545, rust-lang#30551, rust-lang#30552 - Failed merges:
2 parents 711f11e + 04fe94a commit 5b838c5

21 files changed

+487
-108
lines changed

src/doc/book/syntax-index.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
* `!` (`ident!(…)`, `ident!{…}`, `ident![…]`): denotes macro expansion. See [Macros].
4343
* `!` (`!expr`): bitwise or logical complement. Overloadable (`Not`).
44+
* `!=` (`var != expr`): nonequality comparison. Overloadable (`PartialEq`).
4445
* `%` (`expr % expr`): arithmetic remainder. Overloadable (`Rem`).
4546
* `%=` (`var %= expr`): arithmetic remainder & assignment.
4647
* `&` (`expr & expr`): bitwise and. Overloadable (`BitAnd`).
@@ -75,13 +76,13 @@
7576
* `;` (`[…; len]`): part of fixed-size array syntax. See [Primitive Types (Arrays)].
7677
* `<<` (`expr << expr`): left-shift. Overloadable (`Shl`).
7778
* `<<=` (`var <<= expr`): left-shift & assignment.
78-
* `<` (`expr < expr`): less-than comparison. Overloadable (`Cmp`, `PartialCmp`).
79-
* `<=` (`var <= expr`): less-than or equal-to comparison. Overloadable (`Cmp`, `PartialCmp`).
79+
* `<` (`expr < expr`): less-than comparison. Overloadable (`PartialOrd`).
80+
* `<=` (`var <= expr`): less-than or equal-to comparison. Overloadable (`PartialOrd`).
8081
* `=` (`var = expr`, `ident = type`): assignment/equivalence. See [Variable Bindings], [`type` Aliases], generic parameter defaults.
81-
* `==` (`var == expr`): comparison. Overloadable (`Eq`, `PartialEq`).
82+
* `==` (`var == expr`): equality comparison. Overloadable (`PartialEq`).
8283
* `=>` (`pat => expr`): part of match arm syntax. See [Match].
83-
* `>` (`expr > expr`): greater-than comparison. Overloadable (`Cmp`, `PartialCmp`).
84-
* `>=` (`var >= expr`): greater-than or equal-to comparison. Overloadable (`Cmp`, `PartialCmp`).
84+
* `>` (`expr > expr`): greater-than comparison. Overloadable (`PartialOrd`).
85+
* `>=` (`var >= expr`): greater-than or equal-to comparison. Overloadable (`PartialOrd`).
8586
* `>>` (`expr >> expr`): right-shift. Overloadable (`Shr`).
8687
* `>>=` (`var >>= expr`): right-shift & assignment.
8788
* `@` (`ident @ pat`): pattern binding. See [Patterns (Bindings)].

src/grammar/parser-lalr.y

+2-2
Original file line numberDiff line numberDiff line change
@@ -1822,8 +1822,8 @@ unpaired_token
18221822
| LIT_FLOAT { $$ = mk_atom(yytext); }
18231823
| LIT_STR { $$ = mk_atom(yytext); }
18241824
| LIT_STR_RAW { $$ = mk_atom(yytext); }
1825-
| LIT_BYTE_STR { $$ = mk_atom(yytext); }
1826-
| LIT_BYTE_STR_RAW { $$ = mk_atom(yytext); }
1825+
| LIT_BYTE_STR { $$ = mk_atom(yytext); }
1826+
| LIT_BYTE_STR_RAW { $$ = mk_atom(yytext); }
18271827
| IDENT { $$ = mk_atom(yytext); }
18281828
| UNDERSCORE { $$ = mk_atom(yytext); }
18291829
| LIFETIME { $$ = mk_atom(yytext); }

src/librustc/front/map/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,10 @@ pub fn map_crate<'ast>(forest: &'ast mut Forest) -> Map<'ast> {
839839
}
840840

841841
/// Used for items loaded from external crate that are being inlined into this
842-
/// crate. The `path` should be the path to the item but should not include
843-
/// the item itself.
842+
/// crate.
844843
pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
845-
path: Vec<PathElem>,
846-
def_path: DefPath,
844+
parent_path: Vec<PathElem>,
845+
parent_def_path: DefPath,
847846
ii: InlinedItem,
848847
fold_ops: F)
849848
-> &'ast InlinedItem {
@@ -862,7 +861,7 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
862861
};
863862

864863
let ii_parent = map.forest.inlined_items.alloc(InlinedParent {
865-
path: path,
864+
path: parent_path,
866865
ii: ii
867866
});
868867

@@ -872,7 +871,7 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
872871
map.krate(),
873872
ii_parent,
874873
ii_parent_id,
875-
def_path,
874+
parent_def_path,
876875
mem::replace(&mut *map.map.borrow_mut(), vec![]),
877876
mem::replace(&mut *map.definitions.borrow_mut(), Definitions::new()));
878877
ii_parent.ii.visit(&mut collector);

src/librustc/mir/repr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,9 @@ pub struct Constant<'tcx> {
701701
#[derive(Clone, Copy, Debug, PartialEq, RustcEncodable, RustcDecodable)]
702702
pub enum ItemKind {
703703
Constant,
704+
/// This is any sort of callable (usually those that have a type of `fn(…) -> …`). This
705+
/// includes functions, constructors, but not methods which have their own ItemKind.
704706
Function,
705-
Struct,
706-
Variant,
707707
Method,
708708
}
709709

src/librustc_metadata/astencode.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,20 @@ impl<'a, 'b, 'c, 'tcx> ast_map::FoldOps for &'a DecodeContext<'b, 'c, 'tcx> {
124124
/// ast-map.
125125
pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
126126
tcx: &ty::ctxt<'tcx>,
127-
path: Vec<ast_map::PathElem>,
128-
def_path: ast_map::DefPath,
127+
parent_path: Vec<ast_map::PathElem>,
128+
parent_def_path: ast_map::DefPath,
129129
par_doc: rbml::Doc,
130130
orig_did: DefId)
131131
-> Result<&'tcx InlinedItem, (Vec<ast_map::PathElem>,
132132
ast_map::DefPath)> {
133133
match par_doc.opt_child(c::tag_ast) {
134-
None => Err((path, def_path)),
134+
None => Err((parent_path, parent_def_path)),
135135
Some(ast_doc) => {
136136
let mut path_as_str = None;
137137
debug!("> Decoding inlined fn: {:?}::?",
138138
{
139139
// Do an Option dance to use the path after it is moved below.
140-
let s = ast_map::path_to_string(path.iter().cloned());
140+
let s = ast_map::path_to_string(parent_path.iter().cloned());
141141
path_as_str = Some(s);
142142
path_as_str.as_ref().map(|x| &x[..])
143143
});
@@ -152,8 +152,11 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
152152
last_filemap_index: Cell::new(0)
153153
};
154154
let raw_ii = decode_ast(ast_doc);
155-
let ii = ast_map::map_decoded_item(&dcx.tcx.map, path, def_path, raw_ii, dcx);
156-
155+
let ii = ast_map::map_decoded_item(&dcx.tcx.map,
156+
parent_path,
157+
parent_def_path,
158+
raw_ii,
159+
dcx);
157160
let name = match *ii {
158161
InlinedItem::Item(ref i) => i.name,
159162
InlinedItem::Foreign(ref i) => i.name,

src/librustc_metadata/decoder.rs

+36-11
Original file line numberDiff line numberDiff line change
@@ -763,29 +763,54 @@ pub fn get_item_name(intr: &IdentInterner, cdata: Cmd, id: DefIndex) -> ast::Nam
763763
pub type DecodeInlinedItem<'a> =
764764
Box<for<'tcx> FnMut(Cmd,
765765
&ty::ctxt<'tcx>,
766-
Vec<hir_map::PathElem>,
767-
hir_map::DefPath,
766+
Vec<hir_map::PathElem>, // parent_path
767+
hir_map::DefPath, // parent_def_path
768768
rbml::Doc,
769769
DefId)
770770
-> Result<&'tcx InlinedItem, (Vec<hir_map::PathElem>,
771771
hir_map::DefPath)> + 'a>;
772772

773-
pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &ty::ctxt<'tcx>, id: DefIndex,
773+
pub fn maybe_get_item_ast<'tcx>(cdata: Cmd,
774+
tcx: &ty::ctxt<'tcx>,
775+
id: DefIndex,
774776
mut decode_inlined_item: DecodeInlinedItem)
775777
-> FoundAst<'tcx> {
776778
debug!("Looking up item: {:?}", id);
777779
let item_doc = cdata.lookup_item(id);
778780
let item_did = item_def_id(item_doc, cdata);
779-
let path = item_path(item_doc).split_last().unwrap().1.to_vec();
780-
let def_path = def_path(cdata, id);
781-
match decode_inlined_item(cdata, tcx, path, def_path, item_doc, item_did) {
781+
let parent_path = {
782+
let mut path = item_path(item_doc);
783+
path.pop();
784+
path
785+
};
786+
let parent_def_path = {
787+
let mut def_path = def_path(cdata, id);
788+
def_path.pop();
789+
def_path
790+
};
791+
match decode_inlined_item(cdata,
792+
tcx,
793+
parent_path,
794+
parent_def_path,
795+
item_doc,
796+
item_did) {
782797
Ok(ii) => FoundAst::Found(ii),
783-
Err((path, def_path)) => {
798+
Err((mut parent_path, mut parent_def_path)) => {
784799
match item_parent_item(cdata, item_doc) {
785-
Some(did) => {
786-
let parent_item = cdata.lookup_item(did.index);
787-
match decode_inlined_item(cdata, tcx, path, def_path, parent_item, did) {
788-
Ok(ii) => FoundAst::FoundParent(did, ii),
800+
Some(parent_did) => {
801+
// Remove the last element from the paths, since we are now
802+
// trying to inline the parent.
803+
parent_path.pop();
804+
parent_def_path.pop();
805+
806+
let parent_item = cdata.lookup_item(parent_did.index);
807+
match decode_inlined_item(cdata,
808+
tcx,
809+
parent_path,
810+
parent_def_path,
811+
parent_item,
812+
parent_did) {
813+
Ok(ii) => FoundAst::FoundParent(parent_did, ii),
789814
Err(_) => FoundAst::NotFound
790815
}
791816
}

src/librustc_mir/hair/cx/expr.rs

+29-29
Original file line numberDiff line numberDiff line change
@@ -519,51 +519,51 @@ fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr)
519519
let substs = cx.tcx.mk_substs(cx.tcx.node_id_item_substs(expr.id).substs);
520520
// Otherwise there may be def_map borrow conflicts
521521
let def = cx.tcx.def_map.borrow()[&expr.id].full_def();
522-
match def {
523-
def::DefVariant(_, def_id, false) |
524-
def::DefStruct(def_id) |
525-
def::DefFn(def_id, _) |
526-
def::DefMethod(def_id) => {
527-
let kind = match def {
528-
def::DefVariant(..) => ItemKind::Variant,
529-
def::DefStruct(..) => ItemKind::Struct,
530-
def::DefFn(..) => ItemKind::Function,
531-
def::DefMethod(..) => ItemKind::Method,
532-
_ => panic!()
533-
};
534-
ExprKind::Literal {
535-
literal: Literal::Item { def_id: def_id, kind: kind, substs: substs }
522+
let (def_id, kind) = match def {
523+
// A variant constructor.
524+
def::DefVariant(_, def_id, false) => (def_id, ItemKind::Function),
525+
// A regular function.
526+
def::DefFn(def_id, _) => (def_id, ItemKind::Function),
527+
def::DefMethod(def_id) => (def_id, ItemKind::Method),
528+
def::DefStruct(def_id) => {
529+
match cx.tcx.node_id_to_type(expr.id).sty {
530+
// A tuple-struct constructor.
531+
ty::TyBareFn(..) => (def_id, ItemKind::Function),
532+
// This is a special case: a unit struct which is used as a value. We return a
533+
// completely different ExprKind here to account for this special case.
534+
ty::TyStruct(adt_def, substs) => return ExprKind::Adt {
535+
adt_def: adt_def,
536+
variant_index: 0,
537+
substs: substs,
538+
fields: vec![],
539+
base: None
540+
},
541+
ref sty => panic!("unexpected sty: {:?}", sty)
536542
}
537543
},
538544
def::DefConst(def_id) |
539545
def::DefAssociatedConst(def_id) => {
540546
if let Some(v) = cx.try_const_eval_literal(expr) {
541-
ExprKind::Literal { literal: v }
547+
return ExprKind::Literal { literal: v };
542548
} else {
543-
ExprKind::Literal {
544-
literal: Literal::Item {
545-
def_id: def_id,
546-
kind: ItemKind::Constant,
547-
substs: substs
548-
}
549-
}
549+
(def_id, ItemKind::Constant)
550550
}
551551
}
552552

553-
554-
def::DefStatic(node_id, _) =>
555-
ExprKind::StaticRef {
556-
id: node_id,
557-
},
553+
def::DefStatic(node_id, _) => return ExprKind::StaticRef {
554+
id: node_id,
555+
},
558556

559557
def @ def::DefLocal(..) |
560-
def @ def::DefUpvar(..) =>
561-
convert_var(cx, expr, def),
558+
def @ def::DefUpvar(..) => return convert_var(cx, expr, def),
562559

563560
def =>
564561
cx.tcx.sess.span_bug(
565562
expr.span,
566563
&format!("def `{:?}` not yet implemented", def)),
564+
};
565+
ExprKind::Literal {
566+
literal: Literal::Item { def_id: def_id, kind: kind, substs: substs }
567567
}
568568
}
569569

src/librustc_trans/trans/mir/did.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
3939
did: DefId)
4040
-> OperandRef<'tcx> {
4141
match kind {
42-
ItemKind::Function |
43-
ItemKind::Struct |
44-
ItemKind::Variant => self.trans_fn_ref(bcx, ty, substs, did),
42+
ItemKind::Function => self.trans_fn_ref(bcx, ty, substs, did),
4543
ItemKind::Method => match bcx.tcx().impl_or_trait_item(did).container() {
4644
ty::ImplContainer(_) => self.trans_fn_ref(bcx, ty, substs, did),
4745
ty::TraitContainer(tdid) => self.trans_static_method(bcx, ty, did, tdid, substs)

src/librustc_trans/trans/mir/rvalue.rs

+31-18
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,30 @@ use trans::common::{self, Block, Result};
1919
use trans::debuginfo::DebugLoc;
2020
use trans::declare;
2121
use trans::expr;
22+
use trans::adt;
2223
use trans::machine;
2324
use trans::type_::Type;
2425
use trans::type_of;
2526
use trans::tvec;
2627

2728
use super::MirContext;
2829
use super::operand::{OperandRef, OperandValue};
30+
use super::lvalue::LvalueRef;
2931

3032
impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
3133
pub fn trans_rvalue(&mut self,
3234
bcx: Block<'bcx, 'tcx>,
33-
lldest: ValueRef,
35+
dest: LvalueRef<'tcx>,
3436
rvalue: &mir::Rvalue<'tcx>)
3537
-> Block<'bcx, 'tcx>
3638
{
37-
debug!("trans_rvalue(lldest={}, rvalue={:?})",
38-
bcx.val_to_string(lldest),
39+
debug!("trans_rvalue(dest.llval={}, rvalue={:?})",
40+
bcx.val_to_string(dest.llval),
3941
rvalue);
4042

4143
match *rvalue {
4244
mir::Rvalue::Use(ref operand) => {
43-
self.trans_operand_into(bcx, lldest, operand);
45+
self.trans_operand_into(bcx, dest.llval, operand);
4446
bcx
4547
}
4648

@@ -49,7 +51,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
4951
// into-coerce of a thin pointer to a fat pointer - just
5052
// use the operand path.
5153
let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue);
52-
self.store_operand(bcx, lldest, temp);
54+
self.store_operand(bcx, dest.llval, temp);
5355
return bcx;
5456
}
5557

@@ -72,12 +74,12 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
7274
base::store_ty(bcx, llval, lltemp, operand.ty);
7375
base::coerce_unsized_into(bcx,
7476
lltemp, operand.ty,
75-
lldest, cast_ty);
77+
dest.llval, cast_ty);
7678
}
7779
OperandValue::Ref(llref) => {
7880
base::coerce_unsized_into(bcx,
7981
llref, operand.ty,
80-
lldest, cast_ty);
82+
dest.llval, cast_ty);
8183
}
8284
}
8385
bcx
@@ -86,20 +88,31 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
8688
mir::Rvalue::Repeat(ref elem, ref count) => {
8789
let elem = self.trans_operand(bcx, elem);
8890
let size = self.trans_constant(bcx, count).immediate();
89-
let base = expr::get_dataptr(bcx, lldest);
91+
let base = expr::get_dataptr(bcx, dest.llval);
9092
tvec::iter_vec_raw(bcx, base, elem.ty, size, |bcx, llslot, _| {
9193
self.store_operand(bcx, llslot, elem);
9294
bcx
9395
})
9496
}
9597

96-
mir::Rvalue::Aggregate(_, ref operands) => {
97-
for (i, operand) in operands.iter().enumerate() {
98-
// Note: perhaps this should be StructGep, but
99-
// note that in some cases the values here will
100-
// not be structs but arrays.
101-
let lldest_i = build::GEPi(bcx, lldest, &[0, i]);
102-
self.trans_operand_into(bcx, lldest_i, operand);
98+
mir::Rvalue::Aggregate(ref kind, ref operands) => {
99+
match *kind {
100+
// Unit struct, which is translated very differently compared to any other
101+
// aggregate
102+
mir::AggregateKind::Adt(adt_def, 0, _)
103+
if adt_def.struct_variant().kind() == ty::VariantKind::Unit => {
104+
let repr = adt::represent_type(bcx.ccx(), dest.ty.to_ty(bcx.tcx()));
105+
adt::trans_set_discr(bcx, &*repr, dest.llval, 0);
106+
},
107+
_ => {
108+
for (i, operand) in operands.iter().enumerate() {
109+
// Note: perhaps this should be StructGep, but
110+
// note that in some cases the values here will
111+
// not be structs but arrays.
112+
let lldest_i = build::GEPi(bcx, dest.llval, &[0, i]);
113+
self.trans_operand_into(bcx, lldest_i, operand);
114+
}
115+
}
103116
}
104117
bcx
105118
}
@@ -113,9 +126,9 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
113126
let llbase1 = build::GEPi(bcx, llbase, &[from_start]);
114127
let adj = common::C_uint(ccx, from_start + from_end);
115128
let lllen1 = build::Sub(bcx, lllen, adj, DebugLoc::None);
116-
let lladdrdest = expr::get_dataptr(bcx, lldest);
129+
let lladdrdest = expr::get_dataptr(bcx, dest.llval);
117130
build::Store(bcx, llbase1, lladdrdest);
118-
let llmetadest = expr::get_meta(bcx, lldest);
131+
let llmetadest = expr::get_meta(bcx, dest.llval);
119132
build::Store(bcx, lllen1, llmetadest);
120133
bcx
121134
}
@@ -127,7 +140,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
127140
_ => {
128141
assert!(rvalue_creates_operand(rvalue));
129142
let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue);
130-
self.store_operand(bcx, lldest, temp);
143+
self.store_operand(bcx, dest.llval, temp);
131144
bcx
132145
}
133146
}

0 commit comments

Comments
 (0)