Skip to content

Commit 806a553

Browse files
committed
Auto merge of #34004 - Manishearth:rollup, r=Manishearth
Rollup of 11 pull requests - Successful merges: #33385, #33606, #33841, #33892, #33896, #33915, #33921, #33967, #33970, #33973, #33977 - Failed merges:
2 parents 433d70c + 42e593a commit 806a553

31 files changed

+354
-81
lines changed

src/doc/footer.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<footer><p>
2-
Copyright &copy; 2011-2015 The Rust Project Developers. Licensed under the
2+
Copyright &copy; 2011 The Rust Project Developers. Licensed under the
33
<a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>
44
or the <a href="https://opensource.org/licenses/MIT">MIT license</a>, at your option.
55
</p><p>

src/libcollections/fmt.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Utilities for formatting and printing strings
11+
//! Utilities for formatting and printing `String`s
1212
//!
1313
//! This module contains the runtime support for the `format!` syntax extension.
1414
//! This macro is implemented in the compiler to emit calls to this module in
15-
//! order to format arguments at runtime into strings and streams.
15+
//! order to format arguments at runtime into strings.
1616
//!
1717
//! # Usage
1818
//!
1919
//! The `format!` macro is intended to be familiar to those coming from C's
20-
//! printf/fprintf functions or Python's `str.format` function. In its current
21-
//! revision, the `format!` macro returns a `String` type which is the result of
22-
//! the formatting. In the future it will also be able to pass in a stream to
23-
//! format arguments directly while performing minimal allocations.
20+
//! printf/fprintf functions or Python's `str.format` function.
2421
//!
2522
//! Some examples of the `format!` extension are:
2623
//!

src/libcore/slice.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,9 @@ impl<A> SlicePartialEq<A> for [A]
18301830
if self.len() != other.len() {
18311831
return false;
18321832
}
1833+
if self.as_ptr() == other.as_ptr() {
1834+
return true;
1835+
}
18331836
unsafe {
18341837
let size = mem::size_of_val(self);
18351838
memcmp(self.as_ptr() as *const u8,

src/libcore/str/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ fn unwrap_or_0(opt: Option<&u8>) -> u8 {
354354
/// UTF-8-like encoding).
355355
#[unstable(feature = "str_internals", issue = "0")]
356356
#[inline]
357-
pub fn next_code_point(bytes: &mut slice::Iter<u8>) -> Option<u32> {
357+
pub fn next_code_point<'a, I: Iterator<Item = &'a u8>>(bytes: &mut I) -> Option<u32> {
358358
// Decode UTF-8
359359
let x = match bytes.next() {
360360
None => return None,
@@ -388,7 +388,8 @@ pub fn next_code_point(bytes: &mut slice::Iter<u8>) -> Option<u32> {
388388
/// Reads the last code point out of a byte iterator (assuming a
389389
/// UTF-8-like encoding).
390390
#[inline]
391-
fn next_code_point_reverse(bytes: &mut slice::Iter<u8>) -> Option<u32> {
391+
fn next_code_point_reverse<'a,
392+
I: DoubleEndedIterator<Item = &'a u8>>(bytes: &mut I) -> Option<u32> {
392393
// Decode UTF-8
393394
let w = match bytes.next_back() {
394395
None => return None,

src/librustc/middle/stability.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use syntax::parse::token::InternedString;
2626
use syntax::codemap::{Span, DUMMY_SP};
2727
use syntax::ast;
2828
use syntax::ast::{NodeId, Attribute};
29-
use syntax::feature_gate::{GateIssue, emit_feature_err};
29+
use syntax::feature_gate::{GateIssue, emit_feature_err, find_lang_feature_accepted_version};
3030
use syntax::attr::{self, Stability, Deprecation, AttrMetaMethods};
3131
use util::nodemap::{DefIdMap, FnvHashSet, FnvHashMap};
3232

@@ -37,6 +37,7 @@ use hir::pat_util::EnumerateAndAdjustIterator;
3737

3838
use std::mem::replace;
3939
use std::cmp::Ordering;
40+
use std::ops::Deref;
4041

4142
#[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Copy, Debug, Eq, Hash)]
4243
pub enum StabilityLevel {
@@ -322,7 +323,7 @@ impl<'a, 'tcx> Index<'tcx> {
322323
/// features and possibly prints errors. Returns a list of all
323324
/// features used.
324325
pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
325-
-> FnvHashMap<InternedString, StabilityLevel> {
326+
-> FnvHashMap<InternedString, attr::StabilityLevel> {
326327
let _task = tcx.dep_graph.in_task(DepNode::StabilityCheck);
327328
let ref active_lib_features = tcx.sess.features.borrow().declared_lib_features;
328329

@@ -343,7 +344,7 @@ pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
343344
struct Checker<'a, 'tcx: 'a> {
344345
tcx: TyCtxt<'a, 'tcx, 'tcx>,
345346
active_features: FnvHashSet<InternedString>,
346-
used_features: FnvHashMap<InternedString, StabilityLevel>,
347+
used_features: FnvHashMap<InternedString, attr::StabilityLevel>,
347348
// Within a block where feature gate checking can be skipped.
348349
in_skip_block: u32,
349350
}
@@ -367,7 +368,8 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
367368

368369
match *stab {
369370
Some(&Stability { level: attr::Unstable {ref reason, issue}, ref feature, .. }) => {
370-
self.used_features.insert(feature.clone(), Unstable);
371+
self.used_features.insert(feature.clone(),
372+
attr::Unstable { reason: reason.clone(), issue: issue });
371373

372374
if !self.active_features.contains(feature) {
373375
let msg = match *reason {
@@ -380,7 +382,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
380382
}
381383
}
382384
Some(&Stability { ref level, ref feature, .. }) => {
383-
self.used_features.insert(feature.clone(), StabilityLevel::from_attr_level(level));
385+
self.used_features.insert(feature.clone(), level.clone());
384386

385387
// Stable APIs are always ok to call and deprecated APIs are
386388
// handled by a lint.
@@ -716,28 +718,32 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
716718
/// libraries, identify activated features that don't exist and error about them.
717719
pub fn check_unused_or_stable_features(sess: &Session,
718720
lib_features_used: &FnvHashMap<InternedString,
719-
StabilityLevel>) {
721+
attr::StabilityLevel>) {
720722
let ref declared_lib_features = sess.features.borrow().declared_lib_features;
721723
let mut remaining_lib_features: FnvHashMap<InternedString, Span>
722724
= declared_lib_features.clone().into_iter().collect();
723725

724-
let stable_msg = "this feature is stable. attribute no longer needed";
726+
fn format_stable_since_msg(version: &str) -> String {
727+
format!("this feature has been stable since {}. Attribute no longer needed", version)
728+
}
725729

726-
for &span in &sess.features.borrow().declared_stable_lang_features {
730+
for &(ref stable_lang_feature, span) in &sess.features.borrow().declared_stable_lang_features {
731+
let version = find_lang_feature_accepted_version(stable_lang_feature.deref())
732+
.expect("unexpectedly couldn't find version feature was stabilized");
727733
sess.add_lint(lint::builtin::STABLE_FEATURES,
728734
ast::CRATE_NODE_ID,
729735
span,
730-
stable_msg.to_string());
736+
format_stable_since_msg(version));
731737
}
732738

733739
for (used_lib_feature, level) in lib_features_used {
734740
match remaining_lib_features.remove(used_lib_feature) {
735741
Some(span) => {
736-
if *level == Stable {
742+
if let &attr::StabilityLevel::Stable { since: ref version } = level {
737743
sess.add_lint(lint::builtin::STABLE_FEATURES,
738744
ast::CRATE_NODE_ID,
739745
span,
740-
stable_msg.to_string());
746+
format_stable_since_msg(version.deref()));
741747
}
742748
}
743749
None => ( /* used but undeclared, handled during the previous ast visit */ )

src/librustc/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
665665
/// reference to the context, to allow formatting values that need it.
666666
pub fn create_and_enter<F, R>(s: &'tcx Session,
667667
arenas: &'tcx CtxtArenas<'tcx>,
668-
def_map: RefCell<DefMap>,
668+
def_map: DefMap,
669669
named_region_map: resolve_lifetime::NamedRegionMap,
670670
map: ast_map::Map<'tcx>,
671671
freevars: FreevarMap,
@@ -693,7 +693,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
693693
item_variance_map: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
694694
variance_computed: Cell::new(false),
695695
sess: s,
696-
def_map: def_map,
696+
def_map: RefCell::new(def_map),
697697
tables: RefCell::new(Tables::empty()),
698698
impl_trait_refs: RefCell::new(DepTrackingMap::new(dep_graph.clone())),
699699
trait_defs: RefCell::new(DepTrackingMap::new(dep_graph.clone())),

src/librustc_driver/driver.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ use super::Compilation;
4444

4545
use serialize::json;
4646

47-
use std::cell::RefCell;
4847
use std::collections::HashMap;
4948
use std::env;
5049
use std::ffi::{OsString, OsStr};
@@ -893,7 +892,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
893892
let trait_map = resolutions.trait_map;
894893
TyCtxt::create_and_enter(sess,
895894
arenas,
896-
RefCell::new(resolutions.def_map),
895+
resolutions.def_map,
897896
named_region_map,
898897
hir_map,
899898
resolutions.freevars,

src/librustc_driver/test.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use rustc_metadata::cstore::CStore;
2929
use rustc_metadata::creader::read_local_crates;
3030
use rustc::hir::map as hir_map;
3131
use rustc::session::{self, config};
32-
use std::cell::RefCell;
3332
use std::rc::Rc;
3433
use syntax::ast;
3534
use syntax::abi::Abi;
@@ -140,7 +139,7 @@ fn test_env<F>(source_string: &str,
140139
let index = stability::Index::new(&ast_map);
141140
TyCtxt::create_and_enter(&sess,
142141
&arenas,
143-
RefCell::new(resolutions.def_map),
142+
resolutions.def_map,
144143
named_region_map.unwrap(),
145144
ast_map,
146145
resolutions.freevars,

src/librustc_mir/transform/type_check.rs

+24-25
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
118118
self.cx.infcx.tcx
119119
}
120120

121-
fn infcx(&self) -> &'a InferCtxt<'a, 'gcx, 'tcx> {
122-
self.cx.infcx
123-
}
124-
125121
fn sanitize_type(&mut self, parent: &fmt::Debug, ty: Ty<'tcx>) -> Ty<'tcx> {
126122
if ty.needs_infer() || ty.has_escaping_regions() || ty.references_error() {
127123
span_mirbug_and_err!(self, parent, "bad type {:?}", ty)
@@ -292,30 +288,11 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
292288
};
293289

294290
if let Some(field) = variant.fields.get(field.index()) {
295-
Ok(self.normalize(field.ty(tcx, substs)))
291+
Ok(self.cx.normalize(&field.ty(tcx, substs)))
296292
} else {
297293
Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
298294
}
299295
}
300-
301-
fn normalize(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
302-
let infcx = self.infcx();
303-
let mut selcx = traits::SelectionContext::new(infcx);
304-
let cause = traits::ObligationCause::misc(self.last_span, 0);
305-
let traits::Normalized { value: ty, obligations } =
306-
traits::normalize(&mut selcx, cause, &ty);
307-
308-
debug!("normalize: ty={:?} obligations={:?}",
309-
ty,
310-
obligations);
311-
312-
let mut fulfill_cx = &mut self.cx.fulfillment_cx;
313-
for obligation in obligations {
314-
fulfill_cx.register_predicate_obligation(infcx, obligation);
315-
}
316-
317-
ty
318-
}
319296
}
320297

321298
pub struct TypeChecker<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
@@ -373,7 +350,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
373350
}
374351
}
375352

376-
fn check_terminator(&self,
353+
fn check_terminator(&mut self,
377354
mir: &Mir<'tcx>,
378355
term: &Terminator<'tcx>) {
379356
debug!("check_terminator: {:?}", term);
@@ -431,6 +408,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
431408
}
432409
};
433410
let sig = tcx.erase_late_bound_regions(&func_ty.sig);
411+
let sig = self.normalize(&sig);
434412
self.check_call_dest(mir, term, &sig, destination);
435413

436414
if self.is_box_free(func) {
@@ -558,6 +536,27 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
558536
}
559537
}
560538

539+
540+
fn normalize<T>(&mut self, value: &T) -> T
541+
where T: fmt::Debug + TypeFoldable<'tcx>
542+
{
543+
let mut selcx = traits::SelectionContext::new(self.infcx);
544+
let cause = traits::ObligationCause::misc(self.last_span, 0);
545+
let traits::Normalized { value, obligations } =
546+
traits::normalize(&mut selcx, cause, value);
547+
548+
debug!("normalize: value={:?} obligations={:?}",
549+
value,
550+
obligations);
551+
552+
let mut fulfill_cx = &mut self.fulfillment_cx;
553+
for obligation in obligations {
554+
fulfill_cx.register_predicate_obligation(self.infcx, obligation);
555+
}
556+
557+
value
558+
}
559+
561560
fn verify_obligations(&mut self, mir: &Mir<'tcx>) {
562561
self.last_span = mir.span;
563562
if let Err(e) = self.fulfillment_cx.select_all_or_error(self.infcx) {

src/librustc_resolve/lib.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -2422,13 +2422,16 @@ impl<'a> Resolver<'a> {
24222422
}
24232423
}
24242424
}
2425-
} else if let Err(false) = self.resolve_path(pat_id, &path, 0, ValueNS) {
2426-
resolve_error(
2427-
self,
2428-
path.span,
2429-
ResolutionError::UnresolvedEnumVariantStructOrConst(
2430-
&path.segments.last().unwrap().identifier.name.as_str())
2431-
);
2425+
} else {
2426+
if let Err(false) = self.resolve_path(pat_id, &path, 0, ValueNS) {
2427+
// No error has been reported, so we need to do this ourselves.
2428+
resolve_error(
2429+
self,
2430+
path.span,
2431+
ResolutionError::UnresolvedEnumVariantStructOrConst(
2432+
&path.segments.last().unwrap().identifier.name.as_str())
2433+
);
2434+
}
24322435
self.record_def(pattern.id, err_path_resolution());
24332436
}
24342437
visit::walk_path(self, path);

src/libstd/io/cursor.rs

+2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ impl<T> BufRead for Cursor<T> where T: AsRef<[u8]> {
230230

231231
#[stable(feature = "rust1", since = "1.0.0")]
232232
impl<'a> Write for Cursor<&'a mut [u8]> {
233+
#[inline]
233234
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
234235
let pos = cmp::min(self.pos, self.inner.len() as u64);
235236
let amt = (&mut self.inner[(pos as usize)..]).write(data)?;
@@ -269,6 +270,7 @@ impl Write for Cursor<Vec<u8>> {
269270

270271
#[stable(feature = "cursor_box_slice", since = "1.5.0")]
271272
impl Write for Cursor<Box<[u8]>> {
273+
#[inline]
272274
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
273275
let pos = cmp::min(self.pos, self.inner.len() as u64);
274276
let amt = (&mut self.inner[(pos as usize)..]).write(buf)?;

src/libsyntax/ext/tt/macro_rules.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
179179
for (i, lhs) in lhses.iter().enumerate() { // try each arm's matchers
180180
let lhs_tt = match *lhs {
181181
TokenTree::Delimited(_, ref delim) => &delim.tts[..],
182-
_ => cx.span_fatal(sp, "malformed macro lhs")
182+
_ => cx.span_bug(sp, "malformed macro lhs")
183183
};
184184

185185
match TokenTree::parse(cx, lhs_tt, arg) {
186186
Success(named_matches) => {
187187
let rhs = match rhses[i] {
188188
// ignore delimiters
189189
TokenTree::Delimited(_, ref delimed) => delimed.tts.clone(),
190-
_ => cx.span_fatal(sp, "malformed macro rhs"),
190+
_ => cx.span_bug(sp, "malformed macro rhs"),
191191
};
192192
// rhs has holes ( `$id` and `$(...)` that need filled)
193193
let trncbr = new_tt_reader(&cx.parse_sess().span_diagnostic,
@@ -326,19 +326,14 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
326326
NormalTT(exp, Some(def.span), def.allow_internal_unstable)
327327
}
328328

329-
// why is this here? because of https://github.com/rust-lang/rust/issues/27774
330-
fn ref_slice<A>(s: &A) -> &[A] { use std::slice::from_raw_parts; unsafe { from_raw_parts(s, 1) } }
331-
332329
fn check_lhs_nt_follows(cx: &mut ExtCtxt, lhs: &TokenTree) -> bool {
333330
// lhs is going to be like TokenTree::Delimited(...), where the
334331
// entire lhs is those tts. Or, it can be a "bare sequence", not wrapped in parens.
335332
match lhs {
336333
&TokenTree::Delimited(_, ref tts) => check_matcher(cx, &tts.tts),
337-
tt @ &TokenTree::Sequence(..) => check_matcher(cx, ref_slice(tt)),
338334
_ => {
339-
cx.span_err(lhs.get_span(),
340-
"invalid macro matcher; matchers must be contained \
341-
in balanced delimiters or a repetition indicator");
335+
cx.span_err(lhs.get_span(), "invalid macro matcher; matchers must \
336+
be contained in balanced delimiters");
342337
false
343338
}
344339
}

0 commit comments

Comments
 (0)