Skip to content

Commit 7a20864

Browse files
authored
Auto merge of #37382 - jonathandturner:rollup, r=jonathandturner
Rollup of 7 pull requests - Successful merges: #37228, #37304, #37324, #37328, #37336, #37349, #37372 - Failed merges:
2 parents 3caf63c + e948cf1 commit 7a20864

24 files changed

+552
-597
lines changed

src/doc/book/deref-coercions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ foo(&counted);
6969
All we’ve done is wrap our `String` in an `Rc<T>`. But we can now pass the
7070
`Rc<String>` around anywhere we’d have a `String`. The signature of `foo`
7171
didn’t change, but works just as well with either type. This example has two
72-
conversions: `Rc<String>` to `String` and then `String` to `&str`. Rust will do
72+
conversions: `&Rc<String>` to `&String` and then `&String` to `&str`. Rust will do
7373
this as many times as possible until the types match.
7474

7575
Another very common implementation provided by the standard library is:

src/librustc/traits/error_reporting.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
445445
let mut err = struct_span_err!(self.tcx.sess, span, E0277,
446446
"the trait bound `{}` is not satisfied",
447447
trait_ref.to_predicate());
448-
err.span_label(span, &format!("trait `{}` not satisfied",
449-
trait_ref.to_predicate()));
448+
err.span_label(span, &format!("the trait `{}` is not implemented \
449+
for `{}`",
450+
trait_ref,
451+
trait_ref.self_ty()));
450452

451453
// Try to report a help message
452454

src/librustc/ty/util.rs

+32-25
Original file line numberDiff line numberDiff line change
@@ -392,27 +392,30 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
392392
}
393393
}
394394

395-
// When hashing a type this ends up affecting properties like symbol names. We
396-
// want these symbol names to be calculated independent of other factors like
397-
// what architecture you're compiling *from*.
398-
//
399-
// The hashing just uses the standard `Hash` trait, but the implementations of
400-
// `Hash` for the `usize` and `isize` types are *not* architecture independent
401-
// (e.g. they has 4 or 8 bytes). As a result we want to avoid `usize` and
402-
// `isize` completely when hashing. To ensure that these don't leak in we use a
403-
// custom hasher implementation here which inflates the size of these to a `u64`
404-
// and `i64`.
405-
struct WidenUsizeHasher<H> {
395+
/// When hashing a type this ends up affecting properties like symbol names. We
396+
/// want these symbol names to be calculated independent of other factors like
397+
/// what architecture you're compiling *from*.
398+
///
399+
/// The hashing just uses the standard `Hash` trait, but the implementations of
400+
/// `Hash` for the `usize` and `isize` types are *not* architecture independent
401+
/// (e.g. they has 4 or 8 bytes). As a result we want to avoid `usize` and
402+
/// `isize` completely when hashing. To ensure that these don't leak in we use a
403+
/// custom hasher implementation here which inflates the size of these to a `u64`
404+
/// and `i64`.
405+
///
406+
/// The same goes for endianess: We always convert multi-byte integers to little
407+
/// endian before hashing.
408+
pub struct ArchIndependentHasher<H> {
406409
inner: H,
407410
}
408411

409-
impl<H> WidenUsizeHasher<H> {
410-
fn new(inner: H) -> WidenUsizeHasher<H> {
411-
WidenUsizeHasher { inner: inner }
412+
impl<H> ArchIndependentHasher<H> {
413+
pub fn new(inner: H) -> ArchIndependentHasher<H> {
414+
ArchIndependentHasher { inner: inner }
412415
}
413416
}
414417

415-
impl<H: Hasher> Hasher for WidenUsizeHasher<H> {
418+
impl<H: Hasher> Hasher for ArchIndependentHasher<H> {
416419
fn write(&mut self, bytes: &[u8]) {
417420
self.inner.write(bytes)
418421
}
@@ -425,44 +428,44 @@ impl<H: Hasher> Hasher for WidenUsizeHasher<H> {
425428
self.inner.write_u8(i)
426429
}
427430
fn write_u16(&mut self, i: u16) {
428-
self.inner.write_u16(i)
431+
self.inner.write_u16(i.to_le())
429432
}
430433
fn write_u32(&mut self, i: u32) {
431-
self.inner.write_u32(i)
434+
self.inner.write_u32(i.to_le())
432435
}
433436
fn write_u64(&mut self, i: u64) {
434-
self.inner.write_u64(i)
437+
self.inner.write_u64(i.to_le())
435438
}
436439
fn write_usize(&mut self, i: usize) {
437-
self.inner.write_u64(i as u64)
440+
self.inner.write_u64((i as u64).to_le())
438441
}
439442
fn write_i8(&mut self, i: i8) {
440443
self.inner.write_i8(i)
441444
}
442445
fn write_i16(&mut self, i: i16) {
443-
self.inner.write_i16(i)
446+
self.inner.write_i16(i.to_le())
444447
}
445448
fn write_i32(&mut self, i: i32) {
446-
self.inner.write_i32(i)
449+
self.inner.write_i32(i.to_le())
447450
}
448451
fn write_i64(&mut self, i: i64) {
449-
self.inner.write_i64(i)
452+
self.inner.write_i64(i.to_le())
450453
}
451454
fn write_isize(&mut self, i: isize) {
452-
self.inner.write_i64(i as i64)
455+
self.inner.write_i64((i as i64).to_le())
453456
}
454457
}
455458

456459
pub struct TypeIdHasher<'a, 'gcx: 'a+'tcx, 'tcx: 'a, H> {
457460
tcx: TyCtxt<'a, 'gcx, 'tcx>,
458-
state: WidenUsizeHasher<H>,
461+
state: ArchIndependentHasher<H>,
459462
}
460463

461464
impl<'a, 'gcx, 'tcx, H: Hasher> TypeIdHasher<'a, 'gcx, 'tcx, H> {
462465
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, state: H) -> Self {
463466
TypeIdHasher {
464467
tcx: tcx,
465-
state: WidenUsizeHasher::new(state),
468+
state: ArchIndependentHasher::new(state),
466469
}
467470
}
468471

@@ -493,6 +496,10 @@ impl<'a, 'gcx, 'tcx, H: Hasher> TypeIdHasher<'a, 'gcx, 'tcx, H> {
493496
pub fn def_path(&mut self, def_path: &ast_map::DefPath) {
494497
def_path.deterministic_hash_to(self.tcx, &mut self.state);
495498
}
499+
500+
pub fn into_inner(self) -> H {
501+
self.state.inner
502+
}
496503
}
497504

498505
impl<'a, 'gcx, 'tcx, H: Hasher> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tcx, H> {

src/librustc_metadata/astencode.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_serialize::Encodable;
3030
pub struct Ast<'tcx> {
3131
id_range: IdRange,
3232
item: Lazy<InlinedItem>,
33-
side_tables: LazySeq<(ast::NodeId, TableEntry<'tcx>)>
33+
side_tables: LazySeq<(ast::NodeId, TableEntry<'tcx>)>,
3434
}
3535

3636
#[derive(RustcEncodable, RustcDecodable)]
@@ -39,7 +39,7 @@ enum TableEntry<'tcx> {
3939
NodeType(Ty<'tcx>),
4040
ItemSubsts(ty::ItemSubsts<'tcx>),
4141
Adjustment(ty::adjustment::AutoAdjustment<'tcx>),
42-
ConstQualif(ConstQualif)
42+
ConstQualif(ConstQualif),
4343
}
4444

4545
impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
@@ -48,7 +48,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
4848
match ii {
4949
InlinedItemRef::Item(_, i) => id_visitor.visit_item(i),
5050
InlinedItemRef::TraitItem(_, ti) => id_visitor.visit_trait_item(ti),
51-
InlinedItemRef::ImplItem(_, ii) => id_visitor.visit_impl_item(ii)
51+
InlinedItemRef::ImplItem(_, ii) => id_visitor.visit_impl_item(ii),
5252
}
5353

5454
let ii_pos = self.position();
@@ -58,27 +58,27 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
5858
let tables_count = {
5959
let mut visitor = SideTableEncodingIdVisitor {
6060
ecx: self,
61-
count: 0
61+
count: 0,
6262
};
6363
match ii {
6464
InlinedItemRef::Item(_, i) => visitor.visit_item(i),
6565
InlinedItemRef::TraitItem(_, ti) => visitor.visit_trait_item(ti),
66-
InlinedItemRef::ImplItem(_, ii) => visitor.visit_impl_item(ii)
66+
InlinedItemRef::ImplItem(_, ii) => visitor.visit_impl_item(ii),
6767
}
6868
visitor.count
6969
};
7070

7171
self.lazy(&Ast {
7272
id_range: id_visitor.result(),
7373
item: Lazy::with_position(ii_pos),
74-
side_tables: LazySeq::with_position_and_length(tables_pos, tables_count)
74+
side_tables: LazySeq::with_position_and_length(tables_pos, tables_count),
7575
})
7676
}
7777
}
7878

79-
struct SideTableEncodingIdVisitor<'a, 'b:'a, 'tcx:'b> {
79+
struct SideTableEncodingIdVisitor<'a, 'b: 'a, 'tcx: 'b> {
8080
ecx: &'a mut EncodeContext<'b, 'tcx>,
81-
count: usize
81+
count: usize,
8282
}
8383

8484
impl<'a, 'b, 'tcx, 'v> Visitor<'v> for SideTableEncodingIdVisitor<'a, 'b, 'tcx> {
@@ -114,10 +114,11 @@ pub fn decode_inlined_item<'a, 'tcx>(cdata: &CrateMetadata,
114114

115115
let cnt = ast.id_range.max.as_usize() - ast.id_range.min.as_usize();
116116
let start = tcx.sess.reserve_node_ids(cnt);
117-
let id_ranges = [ast.id_range, IdRange {
118-
min: start,
119-
max: ast::NodeId::new(start.as_usize() + cnt)
120-
}];
117+
let id_ranges = [ast.id_range,
118+
IdRange {
119+
min: start,
120+
max: ast::NodeId::new(start.as_usize() + cnt),
121+
}];
121122

122123
let ii = ast.item.decode((cdata, tcx, id_ranges));
123124
let ii = ast_map::map_decoded_item(&tcx.map,
@@ -129,7 +130,7 @@ pub fn decode_inlined_item<'a, 'tcx>(cdata: &CrateMetadata,
129130
let item_node_id = match ii {
130131
&InlinedItem::Item(_, ref i) => i.id,
131132
&InlinedItem::TraitItem(_, ref ti) => ti.id,
132-
&InlinedItem::ImplItem(_, ref ii) => ii.id
133+
&InlinedItem::ImplItem(_, ref ii) => ii.id,
133134
};
134135
let inlined_did = tcx.map.local_def_id(item_node_id);
135136
tcx.register_item_type(inlined_did, tcx.lookup_item_type(orig_did));

src/librustc_metadata/cstore.rs

+46-38
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct ImportedFileMap {
5454
/// The end of this FileMap within the codemap of its original crate
5555
pub original_end_pos: syntax_pos::BytePos,
5656
/// The imported FileMap's representation within the local codemap
57-
pub translated_filemap: Rc<syntax_pos::FileMap>
57+
pub translated_filemap: Rc<syntax_pos::FileMap>,
5858
}
5959

6060
pub struct CrateMetadata {
@@ -141,21 +141,23 @@ impl CStore {
141141
self.metas.borrow_mut().insert(cnum, data);
142142
}
143143

144-
pub fn iter_crate_data<I>(&self, mut i: I) where
145-
I: FnMut(CrateNum, &Rc<CrateMetadata>),
144+
pub fn iter_crate_data<I>(&self, mut i: I)
145+
where I: FnMut(CrateNum, &Rc<CrateMetadata>)
146146
{
147147
for (&k, v) in self.metas.borrow().iter() {
148148
i(k, v);
149149
}
150150
}
151151

152152
/// Like `iter_crate_data`, but passes source paths (if available) as well.
153-
pub fn iter_crate_data_origins<I>(&self, mut i: I) where
154-
I: FnMut(CrateNum, &CrateMetadata, Option<CrateSource>),
153+
pub fn iter_crate_data_origins<I>(&self, mut i: I)
154+
where I: FnMut(CrateNum, &CrateMetadata, Option<CrateSource>)
155155
{
156156
for (&k, v) in self.metas.borrow().iter() {
157157
let origin = self.opt_used_crate_source(k);
158-
origin.as_ref().map(|cs| { assert!(k == cs.cnum); });
158+
origin.as_ref().map(|cs| {
159+
assert!(k == cs.cnum);
160+
});
159161
i(k, &v, origin);
160162
}
161163
}
@@ -167,10 +169,12 @@ impl CStore {
167169
}
168170
}
169171

170-
pub fn opt_used_crate_source(&self, cnum: CrateNum)
171-
-> Option<CrateSource> {
172-
self.used_crate_sources.borrow_mut()
173-
.iter().find(|source| source.cnum == cnum).cloned()
172+
pub fn opt_used_crate_source(&self, cnum: CrateNum) -> Option<CrateSource> {
173+
self.used_crate_sources
174+
.borrow_mut()
175+
.iter()
176+
.find(|source| source.cnum == cnum)
177+
.cloned()
174178
}
175179

176180
pub fn reset(&self) {
@@ -182,19 +186,17 @@ impl CStore {
182186
self.statically_included_foreign_items.borrow_mut().clear();
183187
}
184188

185-
pub fn crate_dependencies_in_rpo(&self, krate: CrateNum) -> Vec<CrateNum>
186-
{
189+
pub fn crate_dependencies_in_rpo(&self, krate: CrateNum) -> Vec<CrateNum> {
187190
let mut ordering = Vec::new();
188191
self.push_dependencies_in_postorder(&mut ordering, krate);
189192
ordering.reverse();
190193
ordering
191194
}
192195

193-
pub fn push_dependencies_in_postorder(&self,
194-
ordering: &mut Vec<CrateNum>,
195-
krate: CrateNum)
196-
{
197-
if ordering.contains(&krate) { return }
196+
pub fn push_dependencies_in_postorder(&self, ordering: &mut Vec<CrateNum>, krate: CrateNum) {
197+
if ordering.contains(&krate) {
198+
return;
199+
}
198200

199201
let data = self.get_crate_data(krate);
200202
for &dep in data.cnum_map.borrow().iter() {
@@ -215,20 +217,25 @@ impl CStore {
215217
// In order to get this left-to-right dependency ordering, we perform a
216218
// topological sort of all crates putting the leaves at the right-most
217219
// positions.
218-
pub fn do_get_used_crates(&self, prefer: LinkagePreference)
220+
pub fn do_get_used_crates(&self,
221+
prefer: LinkagePreference)
219222
-> Vec<(CrateNum, Option<PathBuf>)> {
220223
let mut ordering = Vec::new();
221224
for (&num, _) in self.metas.borrow().iter() {
222225
self.push_dependencies_in_postorder(&mut ordering, num);
223226
}
224227
info!("topological ordering: {:?}", ordering);
225228
ordering.reverse();
226-
let mut libs = self.used_crate_sources.borrow()
229+
let mut libs = self.used_crate_sources
230+
.borrow()
227231
.iter()
228-
.map(|src| (src.cnum, match prefer {
229-
LinkagePreference::RequireDynamic => src.dylib.clone().map(|p| p.0),
230-
LinkagePreference::RequireStatic => src.rlib.clone().map(|p| p.0),
231-
}))
232+
.map(|src| {
233+
(src.cnum,
234+
match prefer {
235+
LinkagePreference::RequireDynamic => src.dylib.clone().map(|p| p.0),
236+
LinkagePreference::RequireStatic => src.rlib.clone().map(|p| p.0),
237+
})
238+
})
232239
.collect::<Vec<_>>();
233240
libs.sort_by(|&(a, _), &(b, _)| {
234241
let a = ordering.iter().position(|x| *x == a);
@@ -243,9 +250,7 @@ impl CStore {
243250
self.used_libraries.borrow_mut().push((lib, kind));
244251
}
245252

246-
pub fn get_used_libraries<'a>(&'a self)
247-
-> &'a RefCell<Vec<(String,
248-
NativeLibraryKind)>> {
253+
pub fn get_used_libraries<'a>(&'a self) -> &'a RefCell<Vec<(String, NativeLibraryKind)>> {
249254
&self.used_libraries
250255
}
251256

@@ -255,13 +260,11 @@ impl CStore {
255260
}
256261
}
257262

258-
pub fn get_used_link_args<'a>(&'a self) -> &'a RefCell<Vec<String> > {
263+
pub fn get_used_link_args<'a>(&'a self) -> &'a RefCell<Vec<String>> {
259264
&self.used_link_args
260265
}
261266

262-
pub fn add_extern_mod_stmt_cnum(&self,
263-
emod_id: ast::NodeId,
264-
cnum: CrateNum) {
267+
pub fn add_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId, cnum: CrateNum) {
265268
self.extern_mod_crate_map.borrow_mut().insert(emod_id, cnum);
266269
}
267270

@@ -273,8 +276,7 @@ impl CStore {
273276
self.statically_included_foreign_items.borrow().contains(&id)
274277
}
275278

276-
pub fn do_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>
277-
{
279+
pub fn do_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> {
278280
self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
279281
}
280282

@@ -288,14 +290,20 @@ impl CStore {
288290
}
289291

290292
impl CrateMetadata {
291-
pub fn name(&self) -> &str { &self.root.name }
292-
pub fn hash(&self) -> Svh { self.root.hash }
293-
pub fn disambiguator(&self) -> &str { &self.root.disambiguator }
293+
pub fn name(&self) -> &str {
294+
&self.root.name
295+
}
296+
pub fn hash(&self) -> Svh {
297+
self.root.hash
298+
}
299+
pub fn disambiguator(&self) -> &str {
300+
&self.root.disambiguator
301+
}
294302

295303
pub fn is_staged_api(&self) -> bool {
296-
self.get_item_attrs(CRATE_DEF_INDEX).iter().any(|attr| {
297-
attr.name() == "stable" || attr.name() == "unstable"
298-
})
304+
self.get_item_attrs(CRATE_DEF_INDEX)
305+
.iter()
306+
.any(|attr| attr.name() == "stable" || attr.name() == "unstable")
299307
}
300308

301309
pub fn is_allocator(&self) -> bool {

0 commit comments

Comments
 (0)