Skip to content

Commit e312c8a

Browse files
committed
Auto merge of #45956 - kennytm:rollup, r=kennytm
Rollup of 9 pull requests - Successful merges: #45828, #45892, #45893, #45914, #45917, #45927, #45933, #45952, #45954 - Failed merges:
2 parents c8c1424 + 48d2627 commit e312c8a

File tree

18 files changed

+420
-84
lines changed

18 files changed

+420
-84
lines changed

src/libcore/option.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -634,16 +634,12 @@ impl<T> Option<T> {
634634
#[inline]
635635
#[unstable(feature = "option_filter", issue = "45860")]
636636
pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self {
637-
match self {
638-
Some(x) => {
639-
if predicate(&x) {
640-
Some(x)
641-
} else {
642-
None
643-
}
637+
if let Some(x) = self {
638+
if predicate(&x) {
639+
return Some(x)
644640
}
645-
None => None,
646641
}
642+
None
647643
}
648644

649645
/// Returns the option if it contains a value, otherwise returns `optb`.

src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ impl ForeignItem_ {
19491949
}
19501950

19511951
/// A free variable referred to in a function.
1952-
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
1952+
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable)]
19531953
pub struct Freevar {
19541954
/// The variable being accessed free.
19551955
pub def: Def,

src/librustc/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ impl<'tcx> Mir<'tcx> {
267267
let block = &self[location.block];
268268
let stmts = &block.statements;
269269
let idx = location.statement_index;
270-
if location.statement_index < stmts.len() {
270+
if idx < stmts.len() {
271271
&stmts[idx].source_info
272272
} else {
273-
assert!(location.statement_index == stmts.len());
273+
assert!(idx == stmts.len());
274274
&block.terminator().source_info
275275
}
276276
}

src/librustc/session/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,13 @@ enum DiagnosticBuilderMethod {
164164
// add more variants as needed to support one-time diagnostics
165165
}
166166

167-
/// Diagnostic message id - used in order to avoid emitting the same message more than once
167+
/// Diagnostic message ID—used by `Session.one_time_diagnostics` to avoid
168+
/// emitting the same message more than once
168169
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
169170
pub enum DiagnosticMessageId {
171+
ErrorId(u16), // EXXXX error code as integer
170172
LintId(lint::LintId),
171-
StabilityId(u32)
173+
StabilityId(u32) // issue number
172174
}
173175

174176
impl Session {

src/librustc/traits/error_reporting.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use middle::const_val;
3636
use rustc::lint::builtin::EXTRA_REQUIREMENT_IN_IMPL;
3737
use std::fmt;
3838
use syntax::ast;
39+
use session::DiagnosticMessageId;
3940
use ty::{self, AdtKind, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
4041
use ty::error::ExpectedFound;
4142
use ty::fast_reject;
@@ -219,13 +220,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
219220
}
220221
}
221222

222-
let mut diag = struct_span_err!(
223-
self.tcx.sess, obligation.cause.span, E0271,
224-
"type mismatch resolving `{}`", predicate
225-
);
226-
self.note_type_err(&mut diag, &obligation.cause, None, values, err);
227-
self.note_obligation_cause(&mut diag, obligation);
228-
diag.emit();
223+
let msg = format!("type mismatch resolving `{}`", predicate);
224+
let error_id = (DiagnosticMessageId::ErrorId(271),
225+
Some(obligation.cause.span), msg.clone());
226+
let fresh = self.tcx.sess.one_time_diagnostics.borrow_mut().insert(error_id);
227+
if fresh {
228+
let mut diag = struct_span_err!(
229+
self.tcx.sess, obligation.cause.span, E0271,
230+
"type mismatch resolving `{}`", predicate
231+
);
232+
self.note_type_err(&mut diag, &obligation.cause, None, values, err);
233+
self.note_obligation_cause(&mut diag, obligation);
234+
diag.emit();
235+
}
229236
});
230237
}
231238

src/librustc_mir/borrow_check.rs

+92-6
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,72 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
11691169
err.emit();
11701170
}
11711171

1172+
/// Finds the span of arguments of a closure (within `maybe_closure_span`) and its usage of
1173+
/// the local assigned at `location`.
1174+
/// This is done by searching in statements succeeding `location`
1175+
/// and originating from `maybe_closure_span`.
1176+
fn find_closure_span(
1177+
&self,
1178+
maybe_closure_span: Span,
1179+
location: Location,
1180+
) -> Option<(Span, Span)> {
1181+
use rustc::hir::ExprClosure;
1182+
use rustc::mir::AggregateKind;
1183+
1184+
let local = if let StatementKind::Assign(Lvalue::Local(local), _) =
1185+
self.mir[location.block].statements[location.statement_index].kind
1186+
{
1187+
local
1188+
} else {
1189+
return None;
1190+
};
1191+
1192+
for stmt in &self.mir[location.block].statements[location.statement_index + 1..] {
1193+
if maybe_closure_span != stmt.source_info.span {
1194+
break;
1195+
}
1196+
1197+
if let StatementKind::Assign(_, Rvalue::Aggregate(ref kind, ref lvs)) = stmt.kind {
1198+
if let AggregateKind::Closure(def_id, _) = **kind {
1199+
debug!("find_closure_span: found closure {:?}", lvs);
1200+
1201+
return if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
1202+
let args_span = if let ExprClosure(_, _, _, span, _) =
1203+
self.tcx.hir.expect_expr(node_id).node
1204+
{
1205+
span
1206+
} else {
1207+
return None;
1208+
};
1209+
1210+
self.tcx
1211+
.with_freevars(node_id, |freevars| {
1212+
for (v, lv) in freevars.iter().zip(lvs) {
1213+
if let Operand::Consume(Lvalue::Local(l)) = *lv {
1214+
if local == l {
1215+
debug!(
1216+
"find_closure_span: found captured local {:?}",
1217+
l
1218+
);
1219+
return Some(v.span);
1220+
}
1221+
}
1222+
}
1223+
None
1224+
})
1225+
.map(|var_span| (args_span, var_span))
1226+
} else {
1227+
None
1228+
};
1229+
}
1230+
}
1231+
}
1232+
1233+
None
1234+
}
1235+
11721236
fn report_conflicting_borrow(&mut self,
1173-
_context: Context,
1237+
context: Context,
11741238
common_prefix: &Lvalue,
11751239
(lvalue, span): (&Lvalue, Span),
11761240
gen_borrow_kind: BorrowKind,
@@ -1183,38 +1247,60 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
11831247

11841248
let issued_span = self.retrieve_borrow_span(issued_borrow);
11851249

1250+
let new_closure_span = self.find_closure_span(span, context.loc);
1251+
let span = new_closure_span.map(|(args, _)| args).unwrap_or(span);
1252+
let old_closure_span = self.find_closure_span(issued_span, issued_borrow.location);
1253+
let issued_span = old_closure_span.map(|(args, _)| args).unwrap_or(issued_span);
1254+
1255+
let desc_lvalue = self.describe_lvalue(lvalue);
1256+
11861257
// FIXME: supply non-"" `opt_via` when appropriate
11871258
let mut err = match (gen_borrow_kind, "immutable", "mutable",
11881259
issued_borrow.kind, "immutable", "mutable") {
11891260
(BorrowKind::Shared, lft, _, BorrowKind::Mut, _, rgt) |
11901261
(BorrowKind::Mut, _, lft, BorrowKind::Shared, rgt, _) =>
11911262
self.tcx.cannot_reborrow_already_borrowed(
1192-
span, &self.describe_lvalue(lvalue), "", lft, issued_span,
1263+
span, &desc_lvalue, "", lft, issued_span,
11931264
"it", rgt, "", end_issued_loan_span, Origin::Mir),
11941265

11951266
(BorrowKind::Mut, _, _, BorrowKind::Mut, _, _) =>
11961267
self.tcx.cannot_mutably_borrow_multiply(
1197-
span, &self.describe_lvalue(lvalue), "", issued_span,
1268+
span, &desc_lvalue, "", issued_span,
11981269
"", end_issued_loan_span, Origin::Mir),
11991270

12001271
(BorrowKind::Unique, _, _, BorrowKind::Unique, _, _) =>
12011272
self.tcx.cannot_uniquely_borrow_by_two_closures(
1202-
span, &self.describe_lvalue(lvalue), issued_span,
1273+
span, &desc_lvalue, issued_span,
12031274
end_issued_loan_span, Origin::Mir),
12041275

12051276
(BorrowKind::Unique, _, _, _, _, _) =>
12061277
self.tcx.cannot_uniquely_borrow_by_one_closure(
1207-
span, &self.describe_lvalue(lvalue), "",
1278+
span, &desc_lvalue, "",
12081279
issued_span, "it", "", end_issued_loan_span, Origin::Mir),
12091280

12101281
(_, _, _, BorrowKind::Unique, _, _) =>
12111282
self.tcx.cannot_reborrow_already_uniquely_borrowed(
1212-
span, &self.describe_lvalue(lvalue), "it", "",
1283+
span, &desc_lvalue, "it", "",
12131284
issued_span, "", end_issued_loan_span, Origin::Mir),
12141285

12151286
(BorrowKind::Shared, _, _, BorrowKind::Shared, _, _) =>
12161287
unreachable!(),
12171288
};
1289+
1290+
if let Some((_, var_span)) = old_closure_span {
1291+
err.span_label(
1292+
var_span,
1293+
format!("previous borrow occurs due to use of `{}` in closure", desc_lvalue),
1294+
);
1295+
}
1296+
1297+
if let Some((_, var_span)) = new_closure_span {
1298+
err.span_label(
1299+
var_span,
1300+
format!("borrow occurs due to use of `{}` in closure", desc_lvalue),
1301+
);
1302+
}
1303+
12181304
err.emit();
12191305
}
12201306

src/librustc_trans/back/link.rs

-21
Original file line numberDiff line numberDiff line change
@@ -503,31 +503,10 @@ fn link_staticlib(sess: &Session,
503503
if !all_native_libs.is_empty() {
504504
if sess.opts.prints.contains(&PrintRequest::NativeStaticLibs) {
505505
print_native_static_libs(sess, &all_native_libs);
506-
} else {
507-
// Fallback for backwards compatibility only
508-
print_native_static_libs_legacy(sess, &all_native_libs);
509506
}
510507
}
511508
}
512509

513-
fn print_native_static_libs_legacy(sess: &Session, all_native_libs: &[NativeLibrary]) {
514-
sess.note_without_error("link against the following native artifacts when linking against \
515-
this static library");
516-
sess.note_without_error("This list will not be printed by default. \
517-
Please add --print=native-static-libs if you need this information");
518-
519-
for lib in all_native_libs.iter().filter(|l| relevant_lib(sess, l)) {
520-
let name = match lib.kind {
521-
NativeLibraryKind::NativeStaticNobundle |
522-
NativeLibraryKind::NativeUnknown => "library",
523-
NativeLibraryKind::NativeFramework => "framework",
524-
// These are included, no need to print them
525-
NativeLibraryKind::NativeStatic => continue,
526-
};
527-
sess.note_without_error(&format!("{}: {}", name, lib.name));
528-
}
529-
}
530-
531510
fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLibrary]) {
532511
let lib_args: Vec<_> = all_native_libs.iter()
533512
.filter(|l| relevant_lib(sess, l))

src/libstd/path.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1690,11 +1690,11 @@ impl Path {
16901690
#[stable(feature = "rust1", since = "1.0.0")]
16911691
#[allow(deprecated)]
16921692
pub fn is_absolute(&self) -> bool {
1693-
if !cfg!(target_os = "redox") {
1694-
self.has_root() && (cfg!(unix) || self.prefix().is_some())
1695-
} else {
1693+
if cfg!(target_os = "redox") {
16961694
// FIXME: Allow Redox prefixes
1697-
has_redox_scheme(self.as_u8_slice())
1695+
self.has_root() || has_redox_scheme(self.as_u8_slice())
1696+
} else {
1697+
self.has_root() && (cfg!(unix) || self.prefix().is_some())
16981698
}
16991699
}
17001700

src/libstd/sys/redox/condvar.rs

+37-20
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
// except according to those terms.
1010

1111
use cell::UnsafeCell;
12-
use intrinsics::{atomic_cxchg, atomic_xadd, atomic_xchg};
12+
use intrinsics::{atomic_cxchg, atomic_load, atomic_xadd, atomic_xchg};
1313
use ptr;
1414
use time::Duration;
1515

1616
use sys::mutex::{mutex_unlock, Mutex};
17-
use sys::syscall::{futex, FUTEX_WAIT, FUTEX_WAKE, FUTEX_REQUEUE};
17+
use sys::syscall::{futex, TimeSpec, FUTEX_WAIT, FUTEX_WAKE, FUTEX_REQUEUE};
1818

1919
pub struct Condvar {
2020
lock: UnsafeCell<*mut i32>,
@@ -63,33 +63,50 @@ impl Condvar {
6363
}
6464

6565
#[inline]
66-
pub fn wait(&self, mutex: &Mutex) {
67-
unsafe {
68-
let lock = self.lock.get();
69-
let seq = self.seq.get();
70-
71-
if *lock != mutex.lock.get() {
72-
if *lock != ptr::null_mut() {
73-
panic!("Condvar used with more than one Mutex");
74-
}
66+
unsafe fn wait_inner(&self, mutex: &Mutex, timeout_ptr: *const TimeSpec) -> bool {
67+
let lock = self.lock.get();
68+
let seq = self.seq.get();
7569

76-
atomic_cxchg(lock as *mut usize, 0, mutex.lock.get() as usize);
70+
if *lock != mutex.lock.get() {
71+
if *lock != ptr::null_mut() {
72+
panic!("Condvar used with more than one Mutex");
7773
}
7874

79-
mutex_unlock(*lock);
75+
atomic_cxchg(lock as *mut usize, 0, mutex.lock.get() as usize);
76+
}
8077

81-
let _ = futex(seq, FUTEX_WAIT, *seq, 0, ptr::null_mut());
78+
mutex_unlock(*lock);
8279

83-
while atomic_xchg(*lock, 2) != 0 {
84-
let _ = futex(*lock, FUTEX_WAIT, 2, 0, ptr::null_mut());
85-
}
80+
let seq_before = atomic_load(seq);
81+
82+
let _ = futex(seq, FUTEX_WAIT, seq_before, timeout_ptr as usize, ptr::null_mut());
83+
84+
let seq_after = atomic_load(seq);
85+
86+
while atomic_xchg(*lock, 2) != 0 {
87+
let _ = futex(*lock, FUTEX_WAIT, 2, 0, ptr::null_mut());
88+
}
89+
90+
seq_before != seq_after
91+
}
92+
93+
#[inline]
94+
pub fn wait(&self, mutex: &Mutex) {
95+
unsafe {
96+
assert!(self.wait_inner(mutex, ptr::null()));
8697
}
8798
}
8899

89100
#[inline]
90-
pub fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool {
91-
::sys_common::util::dumb_print(format_args!("condvar wait_timeout\n"));
92-
unimplemented!();
101+
pub fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
102+
unsafe {
103+
let timeout = TimeSpec {
104+
tv_sec: dur.as_secs() as i64,
105+
tv_nsec: dur.subsec_nanos() as i32
106+
};
107+
108+
self.wait_inner(mutex, &timeout as *const TimeSpec)
109+
}
93110
}
94111

95112
#[inline]

src/libstd/sys/redox/fs.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> {
437437
}
438438

439439
pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> {
440-
::sys_common::util::dumb_print(format_args!("Link\n"));
441-
unimplemented!();
440+
Err(Error::from_raw_os_error(syscall::ENOSYS))
442441
}
443442

444443
pub fn stat(p: &Path) -> io::Result<FileAttr> {

src/libsyntax_pos/symbol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ mod tests {
416416
// first one is zero:
417417
assert_eq!(i.intern("dog"), Symbol(0));
418418
// re-use gets the same entry:
419-
assert_eq!(i.intern ("dog"), Symbol(0));
419+
assert_eq!(i.intern("dog"), Symbol(0));
420420
// different string gets a different #:
421421
assert_eq!(i.intern("cat"), Symbol(1));
422422
assert_eq!(i.intern("cat"), Symbol(1));

0 commit comments

Comments
 (0)