Skip to content

Rollup of 8 pull requests #40886

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

Closed
wants to merge 69 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
67867c6
Update docs for std::str
tigleym Mar 20, 2017
6365272
Move str docs to proper place in file.
tigleym Mar 20, 2017
f628117
Fix Rust linting error
tigleym Mar 21, 2017
dae66e0
Specialize Vec::from_iter for vec::IntoIter
sfackler Mar 18, 2017
8a91e4d
Document Cursor::new position is 0
stepancheg Mar 24, 2017
b442b5e
refactor if so that the "then type" is an expression
nikomatsakis Mar 9, 2017
0dcf7c4
update comment
nikomatsakis Mar 9, 2017
0960d7f
refactor the `targeted_by_break` field
nikomatsakis Mar 22, 2017
21b2cdf
change the strategy for diverging types
nikomatsakis Mar 3, 2017
64643c5
add some debug logs to type_variable.rs
nikomatsakis Mar 17, 2017
b51c6c0
add a `TypeVariableOrigin` we'll use later (`DerivingFn`)
nikomatsakis Mar 17, 2017
339c20e
add an `ObligationCauseCode` we'll use later (`ReturnNoExpression`)
nikomatsakis Mar 17, 2017
6b64b86
introduce (but do not yet use) a `CoerceMany` API
nikomatsakis Mar 17, 2017
0e29ef5
port the match code to use `CoerceMany`
nikomatsakis Mar 17, 2017
e5b6646
port if-then-else to use `CoerceMany`
nikomatsakis Mar 17, 2017
4544296
port `return` expressions to use `CoerceMany`
nikomatsakis Mar 17, 2017
bdb5400
document the diverges flag etc
nikomatsakis Mar 17, 2017
9e24b91
do not eagerly convert `!` to a diverging variable
nikomatsakis Mar 17, 2017
a167839
rework how we handle the type of loops
nikomatsakis Mar 17, 2017
3816675
rewrite `ExprArray` processing to use `CoerceMany`
nikomatsakis Mar 17, 2017
79ce589
whitespace changes, debug message
nikomatsakis Mar 17, 2017
2b1faea
make `try_find_coercion_lub` private; we always use `CoerceMany`
nikomatsakis Mar 17, 2017
f38abfc
more detailed tests around diverging type variables
nikomatsakis Mar 17, 2017
410e4bb
we now get an extra unreachable code warning in this test
nikomatsakis Mar 17, 2017
692156f
add regression test for #39808
nikomatsakis Mar 18, 2017
25903b6
pacify the mercilous tidy
nikomatsakis Mar 21, 2017
169facf
added missing links in std::net TCP docs
chordowl Mar 25, 2017
76d08ed
Update std::net:Incoming's docs to use standard iterator boilerplate
chordowl Mar 26, 2017
0df7398
std::net docs: changed occurences of "RFC" to say "IETF RFC"
chordowl Mar 25, 2017
df5830a
Added links throughout std::net::ToSocketAddrs' documentation
chordowl Mar 25, 2017
0d5baba
Added links to std::net::AddrParseError's documentation
chordowl Mar 25, 2017
347b709
Expanded and added links to std::net::{IpAddr,Ipv4Addr,Ipv6Addr} docs
chordowl Mar 26, 2017
be713fa
Removed link in std::net::ToSocketAddr's summary sentence
chordowl Mar 26, 2017
6f0c742
Expanded and added links to std::net::{SocketAddr,SocketAddrV4,Socket…
chordowl Mar 26, 2017
1a9c8ba
Added examples to std::net::{SocketAddr, SocketAddrV4, SocketAddrV6} …
chordowl Mar 26, 2017
ad816f8
Added links to std::net::Shutdown docs and made them more consistent
chordowl Mar 26, 2017
597bcec
Expanded top-level docs for std::net{TcpListener,TcpStream,UdpSocket}
chordowl Mar 26, 2017
577677d
Expanded std::net module docs
chordowl Mar 26, 2017
c2601fd
fix trailing whitespace
chordowl Mar 26, 2017
62036e3
save-analysis: only index path references once
nrc Mar 8, 2017
28173d3
save-analysis: index extern blocks
nrc Mar 8, 2017
b8cbc5d
Addressed requested changes for PR #40838
chordowl Mar 27, 2017
ff0a976
cherry-pick over the tests I wrote for the reachability code
nikomatsakis Mar 21, 2017
ceba72a
avoid allocating a vector when the coercion sites are known upfront
nikomatsakis Mar 21, 2017
f734cee
coercion now depends on whether the expression diverges
nikomatsakis Mar 24, 2017
dbbe7fc
fix handling of blocks with `CoerceMany`
nikomatsakis Mar 24, 2017
1f97c39
rename `only_has_type_or_fresh_var` to `coercion_target_type`
nikomatsakis Mar 24, 2017
84002a5
remove `Clone` from `FnCtxt`
nikomatsakis Mar 22, 2017
c543467
have coercion supply back the target type
nikomatsakis Mar 23, 2017
c85d568
add test illustrating current "coerce to `!`" behavior
nikomatsakis Mar 24, 2017
2892a1e
fix `X as !` behavior
nikomatsakis Mar 24, 2017
f5179b6
document `diverges` more correctly
nikomatsakis Mar 24, 2017
0d2ca4f
kill the graphviz-flowgraph tests
nikomatsakis Mar 24, 2017
faf8b42
update UI test
nikomatsakis Mar 25, 2017
4885f9e
fix error message for issue-10176.rs
nikomatsakis Mar 26, 2017
434e601
Update various book modules
steveklabnik Mar 27, 2017
da74e86
Review request changes
tigleym Mar 27, 2017
93a0f54
remove comments that were tripping up pretty printer
nikomatsakis Mar 27, 2017
8f6b68c
rebased
nrc Mar 15, 2017
1fea035
Rustdoc: memoize `pub use`-reexported macros so they don't appear twi…
abonander Mar 24, 2017
d8fc5b8
Rustdoc: test proper representation for `pub use` macros
abonander Mar 28, 2017
a2af5ff
Rollup merge of #40224 - nikomatsakis:issue-39808, r=eddyb
frewsxcv Mar 29, 2017
5cf960d
Rollup merge of #40348 - nrc:save-extern-fn, r=eddyb
frewsxcv Mar 29, 2017
f79c794
Rollup merge of #40682 - TigleyM:str_doc, r=steveklabnik
frewsxcv Mar 29, 2017
bec0ac7
Rollup merge of #40731 - sfackler:vec-from-iter-spec, r=aturon
frewsxcv Mar 29, 2017
cada36b
Rollup merge of #40783 - stepancheg:cursor-new-0, r=aturon
frewsxcv Mar 29, 2017
873edbf
Rollup merge of #40814 - abonander:issue_39436, r=jseyfried
frewsxcv Mar 29, 2017
778b704
Rollup merge of #40838 - lukaramu:std-net-docs, r=GuillaumeGomez
frewsxcv Mar 29, 2017
b75dd8e
Rollup merge of #40864 - steveklabnik:update-submodules, r=nrc
frewsxcv Mar 29, 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
2 changes: 1 addition & 1 deletion src/doc/nomicon
2 changes: 1 addition & 1 deletion src/doc/reference
21 changes: 20 additions & 1 deletion src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,28 @@

//! Unicode string slices.
//!
//! The `&str` type is one of the two main string types, the other being `String`.
//! Unlike its `String` counterpart, its contents are borrowed.
//!
//! # Basic Usage
//!
//! A basic string declaration of `&str` type:
//!
//! ```
//! let hello_world = "Hello, World!";
//! ```
//!
//! Here we have declared a string literal, also known as a string slice.
//! String literals have a static lifetime, which means the string `hello_world`
//! is guaranteed to be valid for the duration of the entire program.
//! We can explicitly specify `hello_world`'s lifetime as well:
//!
//! ```
//! let hello_world: &'static str = "Hello, world!";
//! ```
//!
//! *[See also the `str` primitive type](../../std/primitive.str.html).*


#![stable(feature = "rust1", since = "1.0.0")]

// Many of the usings in this module are only used in the test configuration.
Expand Down
29 changes: 25 additions & 4 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ impl<T> ops::DerefMut for Vec<T> {
impl<T> FromIterator<T> for Vec<T> {
#[inline]
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Vec<T> {
<Self as SpecExtend<_, _>>::from_iter(iter.into_iter())
<Self as SpecExtend<T, I::IntoIter>>::from_iter(iter.into_iter())
}
}

Expand Down Expand Up @@ -1631,7 +1631,7 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
impl<T> Extend<T> for Vec<T> {
#[inline]
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
self.spec_extend(iter.into_iter())
<Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter())
}
}

Expand Down Expand Up @@ -1662,7 +1662,7 @@ impl<T, I> SpecExtend<T, I> for Vec<T>
vector
}
};
vector.spec_extend(iterator);
<Vec<T> as SpecExtend<T, I>>::spec_extend(&mut vector, iterator);
vector
}

Expand All @@ -1674,7 +1674,7 @@ impl<T, I> SpecExtend<T, I> for Vec<T>
impl<T, I> SpecExtend<T, I> for Vec<T>
where I: TrustedLen<Item=T>,
{
fn from_iter(iterator: I) -> Self {
default fn from_iter(iterator: I) -> Self {
let mut vector = Vec::new();
vector.spec_extend(iterator);
vector
Expand Down Expand Up @@ -1706,6 +1706,27 @@ impl<T, I> SpecExtend<T, I> for Vec<T>
}
}

impl<T> SpecExtend<T, IntoIter<T>> for Vec<T> {
fn from_iter(iterator: IntoIter<T>) -> Self {
// A common case is passing a vector into a function which immediately
// re-collects into a vector. We can short circuit this if the IntoIter
// has not been advanced at all.
if *iterator.buf == iterator.ptr as *mut T {
unsafe {
let vec = Vec::from_raw_parts(*iterator.buf as *mut T,
iterator.len(),
iterator.cap);
mem::forget(iterator);
vec
}
} else {
let mut vector = Vec::new();
vector.spec_extend(iterator);
vector
}
}
}

impl<'a, T: 'a, I> SpecExtend<&'a T, I> for Vec<T>
where I: Iterator<Item=&'a T>,
T: Clone,
Expand Down
16 changes: 16 additions & 0 deletions src/libcollectionstest/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,19 @@ fn test_placement_panic() {
let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| { vec.place_back() <- mkpanic(); }));
assert_eq!(vec.len(), 3);
}

#[test]
fn from_into_inner() {
let vec = vec![1, 2, 3];
let ptr = vec.as_ptr();
let vec = vec.into_iter().collect::<Vec<_>>();
assert_eq!(vec, [1, 2, 3]);
assert_eq!(vec.as_ptr(), ptr);

let ptr = &vec[1] as *const _;
let mut it = vec.into_iter();
it.next().unwrap();
let vec = it.collect::<Vec<_>>();
assert_eq!(vec, [2, 3]);
assert!(ptr != vec.as_ptr());
}
8 changes: 4 additions & 4 deletions src/librustc/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
fn block(&mut self, blk: &hir::Block, pred: CFGIndex) -> CFGIndex {
if let Some(break_to_expr_id) = blk.break_to_expr_id {
if blk.targeted_by_break {
let expr_exit = self.add_ast_node(blk.id, &[]);

self.breakable_block_scopes.push(BlockScope {
block_expr_id: break_to_expr_id,
block_expr_id: blk.id,
break_index: expr_exit,
});

Expand Down Expand Up @@ -195,7 +195,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
// [..expr..]
//
let cond_exit = self.expr(&cond, pred); // 1
let then_exit = self.block(&then, cond_exit); // 2
let then_exit = self.expr(&then, cond_exit); // 2
self.add_ast_node(expr.id, &[cond_exit, then_exit]) // 3,4
}

Expand All @@ -215,7 +215,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
// [..expr..]
//
let cond_exit = self.expr(&cond, pred); // 1
let then_exit = self.block(&then, cond_exit); // 2
let then_exit = self.expr(&then, cond_exit); // 2
let else_exit = self.expr(&otherwise, cond_exit); // 3
self.add_ast_node(expr.id, &[then_exit, else_exit]) // 4, 5
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
}
ExprIf(ref head_expression, ref if_block, ref optional_else) => {
visitor.visit_expr(head_expression);
visitor.visit_block(if_block);
visitor.visit_expr(if_block);
walk_list!(visitor, visit_expr, optional_else);
}
ExprWhile(ref subexpression, ref block, ref opt_sp_name) => {
Expand Down
39 changes: 21 additions & 18 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ impl<'a> LoweringContext<'a> {
bounds.iter().map(|bound| self.lower_ty_param_bound(bound)).collect()
}

fn lower_block(&mut self, b: &Block, break_to: Option<NodeId>) -> P<hir::Block> {
fn lower_block(&mut self, b: &Block, targeted_by_break: bool) -> P<hir::Block> {
let mut expr = None;

let mut stmts = vec![];
Expand All @@ -1169,7 +1169,7 @@ impl<'a> LoweringContext<'a> {
expr: expr,
rules: self.lower_block_check_mode(&b.rules),
span: b.span,
break_to_expr_id: break_to,
targeted_by_break: targeted_by_break,
})
}

Expand Down Expand Up @@ -1264,7 +1264,7 @@ impl<'a> LoweringContext<'a> {
}
ItemKind::Fn(ref decl, unsafety, constness, abi, ref generics, ref body) => {
self.with_new_scopes(|this| {
let body = this.lower_block(body, None);
let body = this.lower_block(body, false);
let body = this.expr_block(body, ThinVec::new());
let body_id = this.record_body(body, Some(decl));
hir::ItemFn(this.lower_fn_decl(decl),
Expand Down Expand Up @@ -1358,7 +1358,7 @@ impl<'a> LoweringContext<'a> {
hir::TraitMethod::Required(names))
}
TraitItemKind::Method(ref sig, Some(ref body)) => {
let body = this.lower_block(body, None);
let body = this.lower_block(body, false);
let expr = this.expr_block(body, ThinVec::new());
let body_id = this.record_body(expr, Some(&sig.decl));
hir::TraitItemKind::Method(this.lower_method_sig(sig),
Expand Down Expand Up @@ -1414,7 +1414,7 @@ impl<'a> LoweringContext<'a> {
hir::ImplItemKind::Const(this.lower_ty(ty), body_id)
}
ImplItemKind::Method(ref sig, ref body) => {
let body = this.lower_block(body, None);
let body = this.lower_block(body, false);
let expr = this.expr_block(body, ThinVec::new());
let body_id = this.record_body(expr, Some(&sig.decl));
hir::ImplItemKind::Method(this.lower_method_sig(sig), body_id)
Expand Down Expand Up @@ -1838,32 +1838,35 @@ impl<'a> LoweringContext<'a> {
id: id,
rules: hir::DefaultBlock,
span: span,
break_to_expr_id: None,
targeted_by_break: false,
});
P(self.expr_block(blk, ThinVec::new()))
}
_ => P(self.lower_expr(els)),
}
});

hir::ExprIf(P(self.lower_expr(cond)), self.lower_block(blk, None), else_opt)
let then_blk = self.lower_block(blk, false);
let then_expr = self.expr_block(then_blk, ThinVec::new());

hir::ExprIf(P(self.lower_expr(cond)), P(then_expr), else_opt)
}
ExprKind::While(ref cond, ref body, opt_ident) => {
self.with_loop_scope(e.id, |this|
hir::ExprWhile(
this.with_loop_condition_scope(|this| P(this.lower_expr(cond))),
this.lower_block(body, None),
this.lower_block(body, false),
this.lower_opt_sp_ident(opt_ident)))
}
ExprKind::Loop(ref body, opt_ident) => {
self.with_loop_scope(e.id, |this|
hir::ExprLoop(this.lower_block(body, None),
hir::ExprLoop(this.lower_block(body, false),
this.lower_opt_sp_ident(opt_ident),
hir::LoopSource::Loop))
}
ExprKind::Catch(ref body) => {
self.with_catch_scope(e.id, |this|
hir::ExprBlock(this.lower_block(body, Some(e.id))))
self.with_catch_scope(body.id, |this|
hir::ExprBlock(this.lower_block(body, true)))
}
ExprKind::Match(ref expr, ref arms) => {
hir::ExprMatch(P(self.lower_expr(expr)),
Expand All @@ -1881,7 +1884,7 @@ impl<'a> LoweringContext<'a> {
})
})
}
ExprKind::Block(ref blk) => hir::ExprBlock(self.lower_block(blk, None)),
ExprKind::Block(ref blk) => hir::ExprBlock(self.lower_block(blk, false)),
ExprKind::Assign(ref el, ref er) => {
hir::ExprAssign(P(self.lower_expr(el)), P(self.lower_expr(er)))
}
Expand Down Expand Up @@ -2027,7 +2030,7 @@ impl<'a> LoweringContext<'a> {

// `<pat> => <body>`
{
let body = self.lower_block(body, None);
let body = self.lower_block(body, false);
let body_expr = P(self.expr_block(body, ThinVec::new()));
let pat = self.lower_pat(pat);
arms.push(self.arm(hir_vec![pat], body_expr));
Expand Down Expand Up @@ -2099,7 +2102,7 @@ impl<'a> LoweringContext<'a> {
let (guard, body) = if let ExprKind::If(ref cond,
ref then,
_) = else_expr.node {
let then = self.lower_block(then, None);
let then = self.lower_block(then, false);
(Some(cond),
self.expr_block(then, ThinVec::new()))
} else {
Expand Down Expand Up @@ -2149,7 +2152,7 @@ impl<'a> LoweringContext<'a> {
// Note that the block AND the condition are evaluated in the loop scope.
// This is done to allow `break` from inside the condition of the loop.
let (body, break_expr, sub_expr) = self.with_loop_scope(e.id, |this| (
this.lower_block(body, None),
this.lower_block(body, false),
this.expr_break(e.span, ThinVec::new()),
this.with_loop_condition_scope(|this| P(this.lower_expr(sub_expr))),
));
Expand Down Expand Up @@ -2210,7 +2213,7 @@ impl<'a> LoweringContext<'a> {
// `::std::option::Option::Some(<pat>) => <body>`
let pat_arm = {
let body_block = self.with_loop_scope(e.id,
|this| this.lower_block(body, None));
|this| this.lower_block(body, false));
let body_expr = P(self.expr_block(body_block, ThinVec::new()));
let pat = self.lower_pat(pat);
let some_pat = self.pat_some(e.span, pat);
Expand Down Expand Up @@ -2642,7 +2645,7 @@ impl<'a> LoweringContext<'a> {
id: self.next_id(),
rules: hir::DefaultBlock,
span: span,
break_to_expr_id: None,
targeted_by_break: false,
}
}

Expand Down Expand Up @@ -2750,7 +2753,7 @@ impl<'a> LoweringContext<'a> {
id: id,
stmts: stmts,
expr: Some(expr),
break_to_expr_id: None,
targeted_by_break: false,
});
self.expr_block(block, attrs)
}
Expand Down
12 changes: 7 additions & 5 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,11 @@ pub struct Block {
/// Distinguishes between `unsafe { ... }` and `{ ... }`
pub rules: BlockCheckMode,
pub span: Span,
/// The id of the expression that `break` breaks to if the block can be broken out of.
/// Currently only `Some(_)` for `catch {}` blocks
pub break_to_expr_id: Option<NodeId>,
/// If true, then there may exist `break 'a` values that aim to
/// break out of this block early. As of this writing, this is not
/// currently permitted in Rust itself, but it is generated as
/// part of `catch` statements.
pub targeted_by_break: bool,
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
Expand Down Expand Up @@ -992,8 +994,8 @@ pub enum Expr_ {
ExprType(P<Expr>, P<Ty>),
/// An `if` block, with an optional else block
///
/// `if expr { block } else { expr }`
ExprIf(P<Expr>, P<Block>, Option<P<Expr>>),
/// `if expr { expr } else { expr }`
ExprIf(P<Expr>, P<Expr>, Option<P<Expr>>),
/// A while loop, with an optional label
///
/// `'label: while expr { block }`
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ impl<'a> State<'a> {
word(&mut self.s, " else if ")?;
self.print_expr(&i)?;
space(&mut self.s)?;
self.print_block(&then)?;
self.print_expr(&then)?;
self.print_else(e.as_ref().map(|e| &**e))
}
// "final else"
Expand All @@ -1058,13 +1058,13 @@ impl<'a> State<'a> {

pub fn print_if(&mut self,
test: &hir::Expr,
blk: &hir::Block,
blk: &hir::Expr,
elseopt: Option<&hir::Expr>)
-> io::Result<()> {
self.head("if")?;
self.print_expr(test)?;
space(&mut self.s)?;
self.print_block(blk)?;
self.print_expr(blk)?;
self.print_else(elseopt)
}

Expand Down
5 changes: 4 additions & 1 deletion src/librustc/infer/type_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct TypeVariableTable<'tcx> {
}

/// Reasons to create a type inference variable
#[derive(Debug)]
pub enum TypeVariableOrigin {
MiscVariable(Span),
NormalizeProjectionType(Span),
Expand All @@ -41,6 +42,7 @@ pub enum TypeVariableOrigin {
AdjustmentType(Span),
DivergingStmt(Span),
DivergingBlockExpr(Span),
DivergingFn(Span),
LatticeVariable(Span),
}

Expand Down Expand Up @@ -196,14 +198,15 @@ impl<'tcx> TypeVariableTable<'tcx> {
diverging: bool,
origin: TypeVariableOrigin,
default: Option<Default<'tcx>>,) -> ty::TyVid {
debug!("new_var(diverging={:?}, origin={:?})", diverging, origin);
self.eq_relations.new_key(());
let index = self.values.push(TypeVariableData {
value: Bounded { relations: vec![], default: default },
origin: origin,
diverging: diverging
});
let v = ty::TyVid { index: index as u32 };
debug!("new_var() -> {:?}", v);
debug!("new_var: diverging={:?} index={:?}", diverging, v);
v
}

Expand Down
Loading