Skip to content
Merged
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
@@ -451,7 +451,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
// So peel off one-level, turning the &T into T.
match base_ty.builtin_deref(false, ty::NoPreference) {
Some(t) => t.ty,
None => { return Err(()); }
None => {
debug!("By-ref binding of non-derefable type {:?}", base_ty);
return Err(());
}
}
}
_ => base_ty,
@@ -1039,6 +1042,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
match base_cmt.ty.builtin_index() {
Some(ty) => (ty, ElementKind::VecElement),
None => {
debug!("Explicit index of non-indexable type {:?}", base_cmt);
return Err(());
}
}
@@ -1154,7 +1158,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
PatKind::TupleStruct(hir::QPath::Resolved(_, ref path), ..) |
PatKind::Struct(hir::QPath::Resolved(_, ref path), ..) => {
match path.def {
Def::Err => return Err(()),
Def::Err => {
debug!("access to unresolvable pattern {:?}", pat);
return Err(())
}
Def::Variant(variant_did) |
Def::VariantCtor(variant_did, ..) => {
// univariant enums do not need downcasts
7 changes: 5 additions & 2 deletions src/librustc_borrowck/borrowck/gather_loans/move_error.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
use borrowck::BorrowckCtxt;
use rustc::middle::mem_categorization as mc;
use rustc::middle::mem_categorization::Categorization;
use rustc::middle::mem_categorization::NoteClosureEnv;
use rustc::middle::mem_categorization::InteriorOffsetKind as Kind;
use rustc::ty;
use syntax::ast;
@@ -71,10 +72,12 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
let mut err = report_cannot_move_out_of(bccx, error.move_from.clone());
let mut is_first_note = true;
for move_to in &error.move_to_places {
err = note_move_destination(err, move_to.span,
move_to.name, is_first_note);
err = note_move_destination(err, move_to.span, move_to.name, is_first_note);
is_first_note = false;
}
if let NoteClosureEnv(upvar_id) = error.move_from.note {
err.span_label(bccx.tcx.hir.span(upvar_id.var_id), &"captured outer variable");
}
err.emit();
}
}
3 changes: 3 additions & 0 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
@@ -375,6 +375,9 @@ impl Handler {
panic!(ExplicitBug);
}
pub fn delay_span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
if self.treat_err_as_bug {
self.span_bug(sp, msg);
}
let mut delayed = self.delayed_span_bug.borrow_mut();
*delayed = Some((sp.into(), msg.to_string()));
}
11 changes: 11 additions & 0 deletions src/librustc_typeck/check/method/confirm.rs
Original file line number Diff line number Diff line change
@@ -516,6 +516,8 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
};

let index_expr_ty = self.node_ty(index_expr.id);
let adjusted_base_ty = self.resolve_type_vars_if_possible(&adjusted_base_ty);
let index_expr_ty = self.resolve_type_vars_if_possible(&index_expr_ty);

let result = self.try_index_step(ty::MethodCall::expr(expr.id),
expr,
@@ -531,6 +533,15 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {

let expr_ty = self.node_ty(expr.id);
self.demand_suptype(expr.span, expr_ty, return_ty);
} else {
// We could not perform a mutable index. Re-apply the
// immutable index adjustments - borrowck will detect
// this as an error.
if let Some(adjustment) = adjustment {
self.apply_adjustment(expr.id, adjustment);
}
self.tcx.sess.delay_span_bug(
expr.span, "convert_lvalue_derefs_to_mutable failed");
}
}
hir::ExprUnary(hir::UnDeref, ref base_expr) => {
17 changes: 8 additions & 9 deletions src/libstd/net/tcp.rs
Original file line number Diff line number Diff line change
@@ -72,24 +72,23 @@ pub struct TcpStream(net_imp::TcpStream);
///
/// # Examples
///
/// ```no_run
/// ```
/// # use std::io;
/// use std::net::{TcpListener, TcpStream};
///
/// let listener = TcpListener::bind("127.0.0.1:80").unwrap();
///
/// fn handle_client(stream: TcpStream) {
/// // ...
/// }
///
/// # fn process() -> io::Result<()> {
/// let listener = TcpListener::bind("127.0.0.1:80").unwrap();
///
/// // accept connections and process them serially
/// for stream in listener.incoming() {
/// match stream {
/// Ok(stream) => {
/// handle_client(stream);
/// }
/// Err(e) => { /* connection failed */ }
/// }
/// handle_client(stream?);
/// }
/// # Ok(())
/// # }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub struct TcpListener(net_imp::TcpListener);
283 changes: 254 additions & 29 deletions src/libstd/sync/mpsc/mod.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/llvm
2 changes: 1 addition & 1 deletion src/rustllvm/llvm-rebuild-trigger
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# If this file is modified, then llvm will be (optionally) cleaned and then rebuilt.
# The actual contents of this file do not matter, but to trigger a change on the
# build bots then the contents should be changed so git updates the mtime.
2017-04-25
2017-04-26
26 changes: 26 additions & 0 deletions src/test/run-pass/issue-41498.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// regression test for issue #41498.

struct S;
impl S {
fn mutate(&mut self) {}
}

fn call_and_ref<T, F: FnOnce() -> T>(x: &mut Option<T>, f: F) -> &mut T {
*x = Some(f());
x.as_mut().unwrap()
}

fn main() {
let mut n = None;
call_and_ref(&mut n, || [S])[0].mutate();
}
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
// check that borrowck looks inside consts/statics

static FN : &'static (Fn() -> (Box<Fn()->Box<i32>>) + Sync) = &|| {
let x = Box::new(0);
let x = Box::new(0); //~ NOTE moved
Box::new(|| x) //~ ERROR cannot move out of captured outer variable
};

10 changes: 10 additions & 0 deletions src/test/ui/borrowck/borrowck-in-static.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error[E0507]: cannot move out of captured outer variable in an `Fn` closure
--> $DIR/borrowck-in-static.rs:15:17
|
14 | let x = Box::new(0); //~ NOTE moved
| - captured outer variable
15 | Box::new(|| x) //~ ERROR cannot move out of captured outer variable
| ^ cannot move out of captured outer variable in an `Fn` closure

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ fn call<F>(f: F) where F : Fn() {
}

fn main() {
let y = vec![format!("World")];
let y = vec![format!("World")]; //~ NOTE moved
call(|| {
y.into_iter();
//~^ ERROR cannot move out of captured outer variable in an `Fn` closure
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0507]: cannot move out of captured outer variable in an `Fn` closure
--> $DIR/unboxed-closures-move-upvar-from-non-once-ref-closure.rs:21:9
|
19 | let y = vec![format!("World")]; //~ NOTE moved
| - captured outer variable
20 | call(|| {
21 | y.into_iter();
| ^ cannot move out of captured outer variable in an `Fn` closure

error: aborting due to previous error

17 changes: 15 additions & 2 deletions src/test/ui/span/borrowck-call-is-borrow-issue-12224.rs
Original file line number Diff line number Diff line change
@@ -21,8 +21,11 @@ struct Test<'a> {
fn call<F>(mut f: F) where F: FnMut(Fn) {
f(Box::new(|| {
//~^ ERROR: cannot borrow `f` as mutable more than once
//~| NOTE first mutable borrow occurs here
//~| NOTE second mutable borrow occurs here
f((Box::new(|| {})))
}));
//~^ NOTE first borrow ends here
}

fn test1() {
@@ -32,15 +35,21 @@ fn test1() {
}

fn test2<F>(f: &F) where F: FnMut() {
(*f)(); //~ ERROR: cannot borrow immutable borrowed content `*f` as mutable
//~^ NOTE use `&mut F` here to make mutable
(*f)();
//~^ ERROR cannot borrow immutable borrowed content `*f` as mutable
//~| NOTE cannot borrow as mutable
}

fn test3<F>(f: &mut F) where F: FnMut() {
(*f)();
}

fn test4(f: &Test) {
f.f.call_mut(()) //~ ERROR: cannot borrow immutable `Box` content `*f.f` as mutable
//~^ NOTE use `&mut Test` here to make mutable
f.f.call_mut(())
//~^ ERROR: cannot borrow immutable `Box` content `*f.f` as mutable
//~| NOTE cannot borrow as mutable
}

fn test5(f: &mut Test) {
@@ -57,10 +66,14 @@ fn test6() {
fn test7() {
fn foo<F>(_: F) where F: FnMut(Box<FnMut(isize)>, isize) {}
let mut f = |g: Box<FnMut(isize)>, b: isize| {};
//~^ NOTE moved
f(Box::new(|a| {
//~^ NOTE borrow of `f` occurs here
foo(f);
//~^ ERROR cannot move `f` into closure because it is borrowed
//~| ERROR cannot move out of captured outer variable in an `FnMut` closure
//~| NOTE move into closure occurs here
//~| NOTE cannot move out of captured outer variable in an `FnMut` closure
}), 3);
}

34 changes: 20 additions & 14 deletions src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr
Original file line number Diff line number Diff line change
@@ -5,40 +5,46 @@ error[E0499]: cannot borrow `f` as mutable more than once at a time
| - ^^ second mutable borrow occurs here
| |
| first mutable borrow occurs here
23 | //~^ ERROR: cannot borrow `f` as mutable more than once
24 | f((Box::new(|| {})))
...
26 | f((Box::new(|| {})))
| - borrow occurs due to use of `f` in closure
25 | }));
27 | }));
| - first borrow ends here

error: cannot borrow immutable borrowed content `*f` as mutable
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:35:5
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:39:5
|
34 | fn test2<F>(f: &F) where F: FnMut() {
37 | fn test2<F>(f: &F) where F: FnMut() {
| -- use `&mut F` here to make mutable
35 | (*f)(); //~ ERROR: cannot borrow immutable borrowed content `*f` as mutable
38 | //~^ NOTE use `&mut F` here to make mutable
39 | (*f)();
| ^^^^ cannot borrow as mutable

error: cannot borrow immutable `Box` content `*f.f` as mutable
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:43:5
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:50:5
|
42 | fn test4(f: &Test) {
48 | fn test4(f: &Test) {
| ----- use `&mut Test` here to make mutable
43 | f.f.call_mut(()) //~ ERROR: cannot borrow immutable `Box` content `*f.f` as mutable
49 | //~^ NOTE use `&mut Test` here to make mutable
50 | f.f.call_mut(())
| ^^^ cannot borrow as mutable

error[E0504]: cannot move `f` into closure because it is borrowed
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:61:13
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:72:13
|
60 | f(Box::new(|a| {
70 | f(Box::new(|a| {
| - borrow of `f` occurs here
61 | foo(f);
71 | //~^ NOTE borrow of `f` occurs here
72 | foo(f);
| ^ move into closure occurs here

error[E0507]: cannot move out of captured outer variable in an `FnMut` closure
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:61:13
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:72:13
|
61 | foo(f);
68 | let mut f = |g: Box<FnMut(isize)>, b: isize| {};
| ----- captured outer variable
...
72 | foo(f);
| ^ cannot move out of captured outer variable in an `FnMut` closure

error: aborting due to 5 previous errors
2 changes: 1 addition & 1 deletion src/tools/rustbook/Cargo.toml
Original file line number Diff line number Diff line change
@@ -8,5 +8,5 @@ license = "MIT/Apache-2.0"
clap = "2.19.3"

[dependencies.mdbook]
version = "0.0.19"
version = "0.0.21"
default-features = false
19 changes: 15 additions & 4 deletions src/tools/rustbook/src/main.rs
Original file line number Diff line number Diff line change
@@ -53,8 +53,7 @@ fn main() {

// Build command implementation
fn build(args: &ArgMatches) -> Result<(), Box<Error>> {
let book_dir = get_book_dir(args);
let book = MDBook::new(&book_dir).read_config();
let book = build_mdbook_struct(args);

let mut book = match args.value_of("dest-dir") {
Some(dest_dir) => book.set_dest(Path::new(dest_dir)),
@@ -67,14 +66,26 @@ fn build(args: &ArgMatches) -> Result<(), Box<Error>> {
}

fn test(args: &ArgMatches) -> Result<(), Box<Error>> {
let book_dir = get_book_dir(args);
let mut book = MDBook::new(&book_dir).read_config();
let mut book = build_mdbook_struct(args);

try!(book.test());

Ok(())
}

fn build_mdbook_struct(args: &ArgMatches) -> mdbook::MDBook {
let book_dir = get_book_dir(args);
let mut book = MDBook::new(&book_dir).read_config();

// By default mdbook will attempt to create non-existent files referenced
// from SUMMARY.md files. This is problematic on CI where we mount the
// source directory as readonly. To avoid any issues, we'll disabled
// mdbook's implicit file creation feature.
book.create_missing = false;

book
}

fn get_book_dir(args: &ArgMatches) -> PathBuf {
if let Some(dir) = args.value_of("dir") {
// Check if path is relative from current dir, or absolute...