Skip to content

Rollup of 9 pull requests #45956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ef76ebf
Allow absolute if either contains root or a scheme
jackpot51 Oct 25, 2017
fb2a5d5
Remove deprecated message
kornelski Nov 7, 2017
2f68b87
Add futex timeout
jackpot51 Nov 7, 2017
6a9fa50
Fix test case header parsing code in presence of multiple revisions.
michaelwoerister Nov 10, 2017
ec15924
compiletest: Fix a couple of test re-run issues
ollie27 Nov 10, 2017
abff092
Refactor Option::filter method
shanavas786 Nov 11, 2017
d3e9881
MIR-borrowck: fix diagnostics for closures
sinkuu Nov 11, 2017
f99142b
Fix comments
sinkuu Nov 13, 2017
5cc488d
deduplicate projection error (E0271) messages
zackmdavis Nov 13, 2017
b8891ee
Fix style in interner test
udoprog Nov 13, 2017
e3ca816
Rollup merge of #45828 - pornel:printoption, r=nrc
kennytm Nov 13, 2017
563af5d
Rollup merge of #45892 - redox-os:is_absolute_fix, r=alexcrichton
kennytm Nov 13, 2017
331862e
Rollup merge of #45893 - redox-os:futex_timeout, r=alexcrichton
kennytm Nov 13, 2017
e349b18
Rollup merge of #45914 - michaelwoerister:fix-test-header-parsing, r=…
kennytm Nov 13, 2017
5d9b63c
Rollup merge of #45917 - ollie27:compiletest_stamp, r=alexcrichton
kennytm Nov 13, 2017
574dff9
Rollup merge of #45927 - sinkuu:mir-borrowck-closure, r=estebank
kennytm Nov 13, 2017
3604737
Rollup merge of #45933 - shanavas786:refactor-filter, r=alexcrichton
kennytm Nov 13, 2017
8c9d500
Rollup merge of #45952 - zackmdavis:singular_projection, r=estebank
kennytm Nov 13, 2017
48d2627
Rollup merge of #45954 - udoprog:fix-style, r=kennytm
kennytm Nov 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,16 +634,12 @@ impl<T> Option<T> {
#[inline]
#[unstable(feature = "option_filter", issue = "45860")]
pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self {
match self {
Some(x) => {
if predicate(&x) {
Some(x)
} else {
None
}
if let Some(x) = self {
if predicate(&x) {
return Some(x)
}
None => None,
}
None
}

/// Returns the option if it contains a value, otherwise returns `optb`.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ impl ForeignItem_ {
}

/// A free variable referred to in a function.
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable)]
pub struct Freevar {
/// The variable being accessed free.
pub def: Def,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ impl<'tcx> Mir<'tcx> {
let block = &self[location.block];
let stmts = &block.statements;
let idx = location.statement_index;
if location.statement_index < stmts.len() {
if idx < stmts.len() {
&stmts[idx].source_info
} else {
assert!(location.statement_index == stmts.len());
assert!(idx == stmts.len());
&block.terminator().source_info
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ enum DiagnosticBuilderMethod {
// add more variants as needed to support one-time diagnostics
}

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

impl Session {
Expand Down
21 changes: 14 additions & 7 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use middle::const_val;
use rustc::lint::builtin::EXTRA_REQUIREMENT_IN_IMPL;
use std::fmt;
use syntax::ast;
use session::DiagnosticMessageId;
use ty::{self, AdtKind, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
use ty::error::ExpectedFound;
use ty::fast_reject;
Expand Down Expand Up @@ -219,13 +220,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}
}

let mut diag = struct_span_err!(
self.tcx.sess, obligation.cause.span, E0271,
"type mismatch resolving `{}`", predicate
);
self.note_type_err(&mut diag, &obligation.cause, None, values, err);
self.note_obligation_cause(&mut diag, obligation);
diag.emit();
let msg = format!("type mismatch resolving `{}`", predicate);
let error_id = (DiagnosticMessageId::ErrorId(271),
Some(obligation.cause.span), msg.clone());
let fresh = self.tcx.sess.one_time_diagnostics.borrow_mut().insert(error_id);
if fresh {
let mut diag = struct_span_err!(
self.tcx.sess, obligation.cause.span, E0271,
"type mismatch resolving `{}`", predicate
);
self.note_type_err(&mut diag, &obligation.cause, None, values, err);
self.note_obligation_cause(&mut diag, obligation);
diag.emit();
}
});
}

Expand Down
98 changes: 92 additions & 6 deletions src/librustc_mir/borrow_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,72 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
err.emit();
}

/// Finds the span of arguments of a closure (within `maybe_closure_span`) and its usage of
/// the local assigned at `location`.
/// This is done by searching in statements succeeding `location`
/// and originating from `maybe_closure_span`.
fn find_closure_span(
&self,
maybe_closure_span: Span,
location: Location,
) -> Option<(Span, Span)> {
use rustc::hir::ExprClosure;
use rustc::mir::AggregateKind;

let local = if let StatementKind::Assign(Lvalue::Local(local), _) =
self.mir[location.block].statements[location.statement_index].kind
{
local
} else {
return None;
};

for stmt in &self.mir[location.block].statements[location.statement_index + 1..] {
if maybe_closure_span != stmt.source_info.span {
break;
}

if let StatementKind::Assign(_, Rvalue::Aggregate(ref kind, ref lvs)) = stmt.kind {
if let AggregateKind::Closure(def_id, _) = **kind {
debug!("find_closure_span: found closure {:?}", lvs);

return if let Some(node_id) = self.tcx.hir.as_local_node_id(def_id) {
let args_span = if let ExprClosure(_, _, _, span, _) =
self.tcx.hir.expect_expr(node_id).node
{
span
} else {
return None;
};

self.tcx
.with_freevars(node_id, |freevars| {
for (v, lv) in freevars.iter().zip(lvs) {
if let Operand::Consume(Lvalue::Local(l)) = *lv {
if local == l {
debug!(
"find_closure_span: found captured local {:?}",
l
);
return Some(v.span);
}
}
}
None
})
.map(|var_span| (args_span, var_span))
} else {
None
};
}
}
}

None
}

fn report_conflicting_borrow(&mut self,
_context: Context,
context: Context,
common_prefix: &Lvalue,
(lvalue, span): (&Lvalue, Span),
gen_borrow_kind: BorrowKind,
Expand All @@ -1183,38 +1247,60 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>

let issued_span = self.retrieve_borrow_span(issued_borrow);

let new_closure_span = self.find_closure_span(span, context.loc);
let span = new_closure_span.map(|(args, _)| args).unwrap_or(span);
let old_closure_span = self.find_closure_span(issued_span, issued_borrow.location);
let issued_span = old_closure_span.map(|(args, _)| args).unwrap_or(issued_span);

let desc_lvalue = self.describe_lvalue(lvalue);

// FIXME: supply non-"" `opt_via` when appropriate
let mut err = match (gen_borrow_kind, "immutable", "mutable",
issued_borrow.kind, "immutable", "mutable") {
(BorrowKind::Shared, lft, _, BorrowKind::Mut, _, rgt) |
(BorrowKind::Mut, _, lft, BorrowKind::Shared, rgt, _) =>
self.tcx.cannot_reborrow_already_borrowed(
span, &self.describe_lvalue(lvalue), "", lft, issued_span,
span, &desc_lvalue, "", lft, issued_span,
"it", rgt, "", end_issued_loan_span, Origin::Mir),

(BorrowKind::Mut, _, _, BorrowKind::Mut, _, _) =>
self.tcx.cannot_mutably_borrow_multiply(
span, &self.describe_lvalue(lvalue), "", issued_span,
span, &desc_lvalue, "", issued_span,
"", end_issued_loan_span, Origin::Mir),

(BorrowKind::Unique, _, _, BorrowKind::Unique, _, _) =>
self.tcx.cannot_uniquely_borrow_by_two_closures(
span, &self.describe_lvalue(lvalue), issued_span,
span, &desc_lvalue, issued_span,
end_issued_loan_span, Origin::Mir),

(BorrowKind::Unique, _, _, _, _, _) =>
self.tcx.cannot_uniquely_borrow_by_one_closure(
span, &self.describe_lvalue(lvalue), "",
span, &desc_lvalue, "",
issued_span, "it", "", end_issued_loan_span, Origin::Mir),

(_, _, _, BorrowKind::Unique, _, _) =>
self.tcx.cannot_reborrow_already_uniquely_borrowed(
span, &self.describe_lvalue(lvalue), "it", "",
span, &desc_lvalue, "it", "",
issued_span, "", end_issued_loan_span, Origin::Mir),

(BorrowKind::Shared, _, _, BorrowKind::Shared, _, _) =>
unreachable!(),
};

if let Some((_, var_span)) = old_closure_span {
err.span_label(
var_span,
format!("previous borrow occurs due to use of `{}` in closure", desc_lvalue),
);
}

if let Some((_, var_span)) = new_closure_span {
err.span_label(
var_span,
format!("borrow occurs due to use of `{}` in closure", desc_lvalue),
);
}

err.emit();
}

Expand Down
21 changes: 0 additions & 21 deletions src/librustc_trans/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,31 +503,10 @@ fn link_staticlib(sess: &Session,
if !all_native_libs.is_empty() {
if sess.opts.prints.contains(&PrintRequest::NativeStaticLibs) {
print_native_static_libs(sess, &all_native_libs);
} else {
// Fallback for backwards compatibility only
print_native_static_libs_legacy(sess, &all_native_libs);
}
}
}

fn print_native_static_libs_legacy(sess: &Session, all_native_libs: &[NativeLibrary]) {
sess.note_without_error("link against the following native artifacts when linking against \
this static library");
sess.note_without_error("This list will not be printed by default. \
Please add --print=native-static-libs if you need this information");

for lib in all_native_libs.iter().filter(|l| relevant_lib(sess, l)) {
let name = match lib.kind {
NativeLibraryKind::NativeStaticNobundle |
NativeLibraryKind::NativeUnknown => "library",
NativeLibraryKind::NativeFramework => "framework",
// These are included, no need to print them
NativeLibraryKind::NativeStatic => continue,
};
sess.note_without_error(&format!("{}: {}", name, lib.name));
}
}

fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLibrary]) {
let lib_args: Vec<_> = all_native_libs.iter()
.filter(|l| relevant_lib(sess, l))
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,11 +1690,11 @@ impl Path {
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(deprecated)]
pub fn is_absolute(&self) -> bool {
if !cfg!(target_os = "redox") {
self.has_root() && (cfg!(unix) || self.prefix().is_some())
} else {
if cfg!(target_os = "redox") {
// FIXME: Allow Redox prefixes
has_redox_scheme(self.as_u8_slice())
self.has_root() || has_redox_scheme(self.as_u8_slice())
} else {
self.has_root() && (cfg!(unix) || self.prefix().is_some())
}
}

Expand Down
57 changes: 37 additions & 20 deletions src/libstd/sys/redox/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
// except according to those terms.

use cell::UnsafeCell;
use intrinsics::{atomic_cxchg, atomic_xadd, atomic_xchg};
use intrinsics::{atomic_cxchg, atomic_load, atomic_xadd, atomic_xchg};
use ptr;
use time::Duration;

use sys::mutex::{mutex_unlock, Mutex};
use sys::syscall::{futex, FUTEX_WAIT, FUTEX_WAKE, FUTEX_REQUEUE};
use sys::syscall::{futex, TimeSpec, FUTEX_WAIT, FUTEX_WAKE, FUTEX_REQUEUE};

pub struct Condvar {
lock: UnsafeCell<*mut i32>,
Expand Down Expand Up @@ -63,33 +63,50 @@ impl Condvar {
}

#[inline]
pub fn wait(&self, mutex: &Mutex) {
unsafe {
let lock = self.lock.get();
let seq = self.seq.get();

if *lock != mutex.lock.get() {
if *lock != ptr::null_mut() {
panic!("Condvar used with more than one Mutex");
}
unsafe fn wait_inner(&self, mutex: &Mutex, timeout_ptr: *const TimeSpec) -> bool {
let lock = self.lock.get();
let seq = self.seq.get();

atomic_cxchg(lock as *mut usize, 0, mutex.lock.get() as usize);
if *lock != mutex.lock.get() {
if *lock != ptr::null_mut() {
panic!("Condvar used with more than one Mutex");
}

mutex_unlock(*lock);
atomic_cxchg(lock as *mut usize, 0, mutex.lock.get() as usize);
}

let _ = futex(seq, FUTEX_WAIT, *seq, 0, ptr::null_mut());
mutex_unlock(*lock);

while atomic_xchg(*lock, 2) != 0 {
let _ = futex(*lock, FUTEX_WAIT, 2, 0, ptr::null_mut());
}
let seq_before = atomic_load(seq);

let _ = futex(seq, FUTEX_WAIT, seq_before, timeout_ptr as usize, ptr::null_mut());

let seq_after = atomic_load(seq);

while atomic_xchg(*lock, 2) != 0 {
let _ = futex(*lock, FUTEX_WAIT, 2, 0, ptr::null_mut());
}

seq_before != seq_after
}

#[inline]
pub fn wait(&self, mutex: &Mutex) {
unsafe {
assert!(self.wait_inner(mutex, ptr::null()));
}
}

#[inline]
pub fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool {
::sys_common::util::dumb_print(format_args!("condvar wait_timeout\n"));
unimplemented!();
pub fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
unsafe {
let timeout = TimeSpec {
tv_sec: dur.as_secs() as i64,
tv_nsec: dur.subsec_nanos() as i32
};

self.wait_inner(mutex, &timeout as *const TimeSpec)
}
}

#[inline]
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/sys/redox/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> {
}

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

pub fn stat(p: &Path) -> io::Result<FileAttr> {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ mod tests {
// first one is zero:
assert_eq!(i.intern("dog"), Symbol(0));
// re-use gets the same entry:
assert_eq!(i.intern ("dog"), Symbol(0));
assert_eq!(i.intern("dog"), Symbol(0));
// different string gets a different #:
assert_eq!(i.intern("cat"), Symbol(1));
assert_eq!(i.intern("cat"), Symbol(1));
Expand Down
Loading