Skip to content

Commit 9eb69ab

Browse files
committed
Auto merge of #23337 - Manishearth:rollup, r=Manishearth
r? @Manishearth
2 parents ee76963 + 40b6464 commit 9eb69ab

File tree

29 files changed

+417
-47
lines changed

29 files changed

+417
-47
lines changed

mk/llvm.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ $$(LLVM_STAMP_$(1)): $(S)src/rustllvm/llvm-auto-clean-trigger
4444
touch -r $$@.start_time $$@ && rm $$@.start_time
4545

4646
ifeq ($$(CFG_ENABLE_LLVM_STATIC_STDCPP),1)
47-
LLVM_STDCPP_LOCATION_$(1) = $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
48-
-print-file-name=libstdc++.a)
47+
LLVM_STDCPP_RUSTFLAGS_$(1) = -L "$$(dir $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
48+
-print-file-name=libstdc++.a))"
4949
else
50-
LLVM_STDCPP_LOCATION_$(1) =
50+
LLVM_STDCPP_RUSTFLAGS_$(1) =
5151
endif
5252

5353

mk/main.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)
3030
CFG_DISABLE_UNSTABLE_FEATURES=1
3131
endif
3232
ifeq ($(CFG_RELEASE_CHANNEL),beta)
33-
CFG_RELEASE=$(CFG_RELEASE_NUM)-beta(CFG_PRERELEASE_VERSION)
34-
CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-beta(CFG_PRERELEASE_VERSION)
33+
CFG_RELEASE=$(CFG_RELEASE_NUM)-beta$(CFG_PRERELEASE_VERSION)
34+
CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-beta$(CFG_PRERELEASE_VERSION)
3535
CFG_DISABLE_UNSTABLE_FEATURES=1
3636
endif
3737
ifeq ($(CFG_RELEASE_CHANNEL),nightly)

mk/target.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
8585
$$(RUST_LIB_FLAGS_ST$(1)) \
8686
-L "$$(RT_OUTPUT_DIR_$(2))" \
8787
-L "$$(LLVM_LIBDIR_$(2))" \
88-
-L "$$(dir $$(LLVM_STDCPP_LOCATION_$(2)))" \
88+
$$(LLVM_STDCPP_RUSTFLAGS_$(2)) \
8989
$$(RUSTFLAGS_$(4)) \
9090
--out-dir $$(@D) \
9191
-C extra-filename=-$$(CFG_FILENAME_EXTRA) \

src/doc/trpl/hello-cargo.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ Hello, world!
8585
Bam! We build our project with `cargo build`, and run it with
8686
`./target/debug/hello_world`. This hasn't bought us a whole lot over our simple use
8787
of `rustc`, but think about the future: when our project has more than one
88-
file, we would need to call `rustc` more than once, and pass it a bunch of options to
88+
file, we would need to call `rustc` more than once and pass it a bunch of options to
8989
tell it to build everything together. With Cargo, as our project grows, we can
90-
just `cargo build` and it'll work the right way. When you're project is finally ready for release, you can use `cargo build --release` to compile your crates with optimizations.
90+
just `cargo build`, and it'll work the right way. When your project is finally
91+
ready for release, you can use `cargo build --release` to compile your crates with
92+
optimizations.
9193

9294
You'll also notice that Cargo has created a new file: `Cargo.lock`.
9395

src/etc/gdb_rust_pretty_printing.py

+88-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ def rust_pretty_printer_lookup_function(val):
2727
if type_code == gdb.TYPE_CODE_STRUCT:
2828
struct_kind = classify_struct(val.type)
2929

30+
if struct_kind == STRUCT_KIND_SLICE:
31+
return RustSlicePrinter(val)
32+
3033
if struct_kind == STRUCT_KIND_STR_SLICE:
3134
return RustStringSlicePrinter(val)
3235

36+
if struct_kind == STRUCT_KIND_STD_VEC:
37+
return RustStdVecPrinter(val)
38+
39+
if struct_kind == STRUCT_KIND_STD_STRING:
40+
return RustStdStringPrinter(val)
41+
3342
if struct_kind == STRUCT_KIND_TUPLE:
3443
return RustTuplePrinter(val)
3544

@@ -172,6 +181,28 @@ def children(self):
172181
def display_hint(self):
173182
return "array"
174183

184+
class RustSlicePrinter:
185+
def __init__(self, val):
186+
self.val = val
187+
188+
def display_hint(self):
189+
return "array"
190+
191+
def to_string(self):
192+
length = int(self.val["length"])
193+
return self.val.type.tag + ("(len: %i)" % length)
194+
195+
def children(self):
196+
cs = []
197+
length = int(self.val["length"])
198+
data_ptr = self.val["data_ptr"]
199+
assert data_ptr.type.code == gdb.TYPE_CODE_PTR
200+
pointee_type = data_ptr.type.target()
201+
202+
for index in range(0, length):
203+
cs.append((str(index), (data_ptr + index).dereference()))
204+
205+
return cs
175206

176207
class RustStringSlicePrinter:
177208
def __init__(self, val):
@@ -181,6 +212,35 @@ def to_string(self):
181212
slice_byte_len = self.val["length"]
182213
return '"%s"' % self.val["data_ptr"].string(encoding="utf-8", length=slice_byte_len)
183214

215+
class RustStdVecPrinter:
216+
def __init__(self, val):
217+
self.val = val
218+
219+
def display_hint(self):
220+
return "array"
221+
222+
def to_string(self):
223+
length = int(self.val["len"])
224+
cap = int(self.val["cap"])
225+
return self.val.type.tag + ("(len: %i, cap: %i)" % (length, cap))
226+
227+
def children(self):
228+
cs = []
229+
(length, data_ptr) = extract_length_and_data_ptr_from_std_vec(self.val)
230+
pointee_type = data_ptr.type.target()
231+
232+
for index in range(0, length):
233+
cs.append((str(index), (data_ptr + index).dereference()))
234+
return cs
235+
236+
class RustStdStringPrinter:
237+
def __init__(self, val):
238+
self.val = val
239+
240+
def to_string(self):
241+
(length, data_ptr) = extract_length_and_data_ptr_from_std_vec(self.val["vec"])
242+
return '"%s"' % data_ptr.string(encoding="utf-8", length=length)
243+
184244

185245
class RustCStyleEnumPrinter:
186246
def __init__(self, val):
@@ -204,19 +264,38 @@ def to_string(self):
204264
STRUCT_KIND_TUPLE_VARIANT = 3
205265
STRUCT_KIND_STRUCT_VARIANT = 4
206266
STRUCT_KIND_CSTYLE_VARIANT = 5
207-
STRUCT_KIND_STR_SLICE = 6
267+
STRUCT_KIND_SLICE = 6
268+
STRUCT_KIND_STR_SLICE = 7
269+
STRUCT_KIND_STD_VEC = 8
270+
STRUCT_KIND_STD_STRING = 9
208271

209272

210273
def classify_struct(type):
274+
# print("\nclassify_struct: tag=%s\n" % type.tag)
211275
if type.tag == "&str":
212276
return STRUCT_KIND_STR_SLICE
213277

278+
if type.tag.startswith("&[") and type.tag.endswith("]"):
279+
return STRUCT_KIND_SLICE
280+
214281
fields = list(type.fields())
215282
field_count = len(fields)
216283

217284
if field_count == 0:
218285
return STRUCT_KIND_REGULAR_STRUCT
219286

287+
if (field_count == 3 and
288+
fields[0].name == "ptr" and
289+
fields[1].name == "len" and
290+
fields[2].name == "cap" and
291+
type.tag.startswith("Vec<")):
292+
return STRUCT_KIND_STD_VEC
293+
294+
if (field_count == 1 and
295+
fields[0].name == "vec" and
296+
type.tag == "String"):
297+
return STRUCT_KIND_STD_STRING
298+
220299
if fields[0].name == "RUST$ENUM$DISR":
221300
if field_count == 1:
222301
return STRUCT_KIND_CSTYLE_VARIANT
@@ -254,3 +333,11 @@ def get_field_at_index(val, index):
254333
return field
255334
i += 1
256335
return None
336+
337+
def extract_length_and_data_ptr_from_std_vec(vec_val):
338+
length = int(vec_val["len"])
339+
vec_ptr_val = vec_val["ptr"]
340+
unique_ptr_val = vec_ptr_val[first_field(vec_ptr_val)]
341+
data_ptr = unique_ptr_val[first_field(unique_ptr_val)]
342+
assert data_ptr.type.code == gdb.TYPE_CODE_PTR
343+
return (length, data_ptr)

src/liballoc/heap.rs

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ mod imp {
198198
extern {}
199199

200200
extern {
201+
#[allocator]
201202
fn je_mallocx(size: size_t, flags: c_int) -> *mut c_void;
202203
fn je_rallocx(ptr: *mut c_void, size: size_t, flags: c_int) -> *mut c_void;
203204
fn je_xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t;

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969

7070
#![feature(no_std)]
7171
#![no_std]
72+
#![feature(allocator)]
7273
#![feature(lang_items, unsafe_destructor)]
7374
#![feature(box_syntax)]
7475
#![feature(optin_builtin_traits)]

src/libcore/hash/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ mod sip;
7070
/// A hashable type.
7171
///
7272
/// The `H` type parameter is an abstract hash state that is used by the `Hash`
73-
/// to compute the hash. Specific implementations of this trait may specialize
74-
/// for particular instances of `H` in order to be able to optimize the hashing
75-
/// behavior.
73+
/// to compute the hash.
7674
#[stable(feature = "rust1", since = "1.0.0")]
7775
pub trait Hash {
7876
/// Feeds this value into the state given, updating the hasher as necessary.

src/libcore/ptr.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,34 @@
3333
//! let my_speed_ptr: *mut i32 = &mut my_speed;
3434
//! ```
3535
//!
36+
//! To get a pointer to a boxed value, dereference the box:
37+
//!
38+
//! ```
39+
//! let my_num: Box<i32> = Box::new(10);
40+
//! let my_num_ptr: *const i32 = &*my_num;
41+
//! let mut my_speed: Box<i32> = Box::new(88);
42+
//! let my_speed_ptr: *mut i32 = &mut *my_speed;
43+
//! ```
44+
//!
3645
//! This does not take ownership of the original allocation
3746
//! and requires no resource management later,
3847
//! but you must not use the pointer after its lifetime.
3948
//!
40-
//! ## 2. Transmute an owned box (`Box<T>`).
49+
//! ## 2. Consume a box (`Box<T>`).
4150
//!
42-
//! The `transmute` function takes, by value, whatever it's given
43-
//! and returns it as whatever type is requested, as long as the
44-
//! types are the same size. Because `Box<T>` and `*mut T` have the same
45-
//! representation they can be trivially,
46-
//! though unsafely, transformed from one type to the other.
51+
//! The `into_raw` function consumes a box and returns
52+
//! the raw pointer. It doesn't destroy `T` or deallocate any memory.
4753
//!
4854
//! ```
49-
//! use std::mem;
55+
//! use std::boxed;
5056
//!
5157
//! unsafe {
52-
//! let my_num: Box<i32> = Box::new(10);
53-
//! let my_num: *const i32 = mem::transmute(my_num);
5458
//! let my_speed: Box<i32> = Box::new(88);
55-
//! let my_speed: *mut i32 = mem::transmute(my_speed);
59+
//! let my_speed: *mut i32 = boxed::into_raw(my_speed);
5660
//!
5761
//! // By taking ownership of the original `Box<T>` though
58-
//! // we are obligated to transmute it back later to be destroyed.
59-
//! drop(mem::transmute::<_, Box<i32>>(my_speed));
60-
//! drop(mem::transmute::<_, Box<i32>>(my_num));
62+
//! // we are obligated to put it together later to be destroyed.
63+
//! drop(Box::from_raw(my_speed));
6164
//! }
6265
//! ```
6366
//!

src/librustc/metadata/csearch.rs

+5
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,8 @@ pub fn is_defaulted_trait(cstore: &cstore::CStore, trait_def_id: ast::DefId) ->
411411
let cdata = cstore.get_crate_data(trait_def_id.krate);
412412
decoder::is_defaulted_trait(&*cdata, trait_def_id.node)
413413
}
414+
415+
pub fn is_default_impl(cstore: &cstore::CStore, impl_did: ast::DefId) -> bool {
416+
let cdata = cstore.get_crate_data(impl_did.krate);
417+
decoder::is_default_impl(&*cdata, impl_did.node)
418+
}

src/librustc/metadata/decoder.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1537,13 +1537,18 @@ pub fn is_associated_type(cdata: Cmd, id: ast::NodeId) -> bool {
15371537
}
15381538
}
15391539

1540-
pub fn is_defaulted_trait<'tcx>(cdata: Cmd, trait_id: ast::NodeId) -> bool {
1540+
pub fn is_defaulted_trait(cdata: Cmd, trait_id: ast::NodeId) -> bool {
15411541
let trait_doc = lookup_item(trait_id, cdata.data());
15421542
assert!(item_family(trait_doc) == Family::Trait);
15431543
let defaulted_doc = reader::get_doc(trait_doc, tag_defaulted_trait);
15441544
reader::doc_as_u8(defaulted_doc) != 0
15451545
}
15461546

1547+
pub fn is_default_impl(cdata: Cmd, impl_id: ast::NodeId) -> bool {
1548+
let impl_doc = lookup_item(impl_id, cdata.data());
1549+
item_family(impl_doc) == Family::DefaultImpl
1550+
}
1551+
15471552
pub fn get_imported_filemaps(metadata: &[u8]) -> Vec<codemap::FileMap> {
15481553
let crate_doc = rbml::Doc::new(metadata);
15491554
let cm_doc = reader::get_doc(crate_doc, tag_codemap);

src/librustc/middle/dead.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct MarkSymbolVisitor<'a, 'tcx: 'a> {
4747
struct_has_extern_repr: bool,
4848
ignore_non_const_paths: bool,
4949
inherited_pub_visibility: bool,
50+
ignore_variant_stack: Vec<ast::NodeId>,
5051
}
5152

5253
impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
@@ -59,6 +60,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
5960
struct_has_extern_repr: false,
6061
ignore_non_const_paths: false,
6162
inherited_pub_visibility: false,
63+
ignore_variant_stack: vec![],
6264
}
6365
}
6466

@@ -79,7 +81,9 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
7981
def::DefPrimTy(_) => (),
8082
def::DefVariant(enum_id, variant_id, _) => {
8183
self.check_def_id(enum_id);
82-
self.check_def_id(variant_id);
84+
if !self.ignore_variant_stack.contains(&variant_id.node) {
85+
self.check_def_id(variant_id);
86+
}
8387
}
8488
_ => {
8589
self.check_def_id(def.def_id());
@@ -278,6 +282,23 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
278282
visit::walk_expr(self, expr);
279283
}
280284

285+
fn visit_arm(&mut self, arm: &ast::Arm) {
286+
if arm.pats.len() == 1 {
287+
let pat = &*arm.pats[0];
288+
let variants = pat_util::necessary_variants(&self.tcx.def_map, pat);
289+
290+
// Inside the body, ignore constructions of variants
291+
// necessary for the pattern to match. Those construction sites
292+
// can't be reached unless the variant is constructed elsewhere.
293+
let len = self.ignore_variant_stack.len();
294+
self.ignore_variant_stack.push_all(&*variants);
295+
visit::walk_arm(self, arm);
296+
self.ignore_variant_stack.truncate(len);
297+
} else {
298+
visit::walk_arm(self, arm);
299+
}
300+
}
301+
281302
fn visit_pat(&mut self, pat: &ast::Pat) {
282303
let def_map = &self.tcx.def_map;
283304
match pat.node {
@@ -397,6 +418,11 @@ fn create_and_seed_worklist(tcx: &ty::ctxt,
397418
worklist.push(*id);
398419
}
399420
for id in reachable_symbols {
421+
// Reachable variants can be dead, because we warn about
422+
// variants never constructed, not variants never used.
423+
if let Some(ast_map::NodeVariant(..)) = tcx.map.find(*id) {
424+
continue;
425+
}
400426
worklist.push(*id);
401427
}
402428

src/librustc/middle/pat_util.rs

+24
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,27 @@ pub fn def_to_path(tcx: &ty::ctxt, id: ast::DefId) -> ast::Path {
155155
span: DUMMY_SP,
156156
})
157157
}
158+
159+
/// Return variants that are necessary to exist for the pattern to match.
160+
pub fn necessary_variants(dm: &DefMap, pat: &ast::Pat) -> Vec<ast::NodeId> {
161+
let mut variants = vec![];
162+
walk_pat(pat, |p| {
163+
match p.node {
164+
ast::PatEnum(_, _) |
165+
ast::PatIdent(_, _, None) |
166+
ast::PatStruct(..) => {
167+
match dm.borrow().get(&p.id) {
168+
Some(&PathResolution {base_def: DefVariant(_, id, _), ..}) => {
169+
variants.push(id.node);
170+
}
171+
_ => ()
172+
}
173+
}
174+
_ => ()
175+
}
176+
true
177+
});
178+
variants.sort();
179+
variants.dedup();
180+
variants
181+
}

0 commit comments

Comments
 (0)