Skip to content

Commit

Permalink
Auto merge of #42336 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

- Successful merges: #42126, #42196, #42252, #42277, #42315, #42329, #42330
- Failed merges:
  • Loading branch information
bors committed May 31, 2017
2 parents fd7b44b + 7f286a8 commit e0cc22b
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 73 deletions.
38 changes: 37 additions & 1 deletion src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,40 @@ pub trait AsMut<T: ?Sized> {
/// - [`From<T>`][From]` for U` implies `Into<U> for T`
/// - [`into`] is reflexive, which means that `Into<T> for T` is implemented
///
/// # Implementing `Into`
///
/// There is one exception to implementing `Into`, and it's kind of esoteric.
/// If the destination type is not part of the current crate, and it uses a
/// generic variable, then you can't implement `From` directly. For example,
/// take this crate:
///
/// ```compile_fail
/// struct Wrapper<T>(Vec<T>);
/// impl<T> From<Wrapper<T>> for Vec<T> {
/// fn from(w: Wrapper<T>) -> Vec<T> {
/// w.0
/// }
/// }
/// ```
///
/// To fix this, you can implement `Into` directly:
///
/// ```
/// struct Wrapper<T>(Vec<T>);
/// impl<T> Into<Vec<T>> for Wrapper<T> {
/// fn into(self) -> Vec<T> {
/// self.0
/// }
/// }
/// ```
///
/// This won't always allow the conversion: for example, `try!` and `?`
/// always use `From`. However, in most cases, people use `Into` to do the
/// conversions, and this will allow that.
///
/// In almost all cases, you should try to implement `From`, then fall back
/// to `Into` if `From` can't be implemented.
///
/// # Examples
///
/// [`String`] implements `Into<Vec<u8>>`:
Expand Down Expand Up @@ -285,9 +319,11 @@ pub trait From<T>: Sized {
/// Library authors should not directly implement this trait, but should prefer
/// implementing the [`TryFrom`] trait, which offers greater flexibility and
/// provides an equivalent `TryInto` implementation for free, thanks to a
/// blanket implementation in the standard library.
/// blanket implementation in the standard library. For more information on this,
/// see the documentation for [`Into`].
///
/// [`TryFrom`]: trait.TryFrom.html
/// [`Into`]: trait.Into.html
#[unstable(feature = "try_from", issue = "33417")]
pub trait TryInto<T>: Sized {
/// The type returned in the event of a conversion error.
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ pub trait Iterator {
///
/// ```
/// // an infinite iterator has no upper bound
/// // and the maximum possible lower bound
/// let iter = 0..;
///
/// assert_eq!((0, None), iter.size_hint());
/// assert_eq!((usize::max_value(), None), iter.size_hint());
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
5 changes: 5 additions & 0 deletions src/libcore/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,11 @@ impl<A: Step> Iterator for ops::RangeFrom<A> where
mem::swap(&mut n, &mut self.start);
Some(n)
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(usize::MAX, None)
}
}

#[unstable(feature = "fused", issue = "35602")]
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/iter/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub trait FromIterator<A>: Sized {
///
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: trait.FromIterator.html
/// [module-level documentation]: index.html
///
/// # Examples
///
Expand Down Expand Up @@ -219,7 +219,7 @@ pub trait IntoIterator {
///
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: trait.IntoIterator.html
/// [module-level documentation]: index.html
///
/// # Examples
///
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub fn size_of_val<T: ?Sized>(val: &T) -> usize {

/// Returns the [ABI]-required minimum alignment of a type.
///
/// Every valid address of a value of the type `T` must be a multiple of this number.
/// Every reference to a value of the type `T` must be a multiple of this number.
///
/// This is the alignment used for struct fields. It may be smaller than the preferred alignment.
///
Expand All @@ -243,7 +243,7 @@ pub fn min_align_of<T>() -> usize {

/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to.
///
/// Every valid address of a value of the type `T` must be a multiple of this number.
/// Every reference to a value of the type `T` must be a multiple of this number.
///
/// [ABI]: https://en.wikipedia.org/wiki/Application_binary_interface
///
Expand All @@ -264,7 +264,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {

/// Returns the [ABI]-required minimum alignment of a type.
///
/// Every valid address of a value of the type `T` must be a multiple of this number.
/// Every reference to a value of the type `T` must be a multiple of this number.
///
/// This is the alignment used for struct fields. It may be smaller than the preferred alignment.
///
Expand All @@ -285,7 +285,7 @@ pub fn align_of<T>() -> usize {

/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to.
///
/// Every valid address of a value of the type `T` must be a multiple of this number.
/// Every reference to a value of the type `T` must be a multiple of this number.
///
/// [ABI]: https://en.wikipedia.org/wiki/Application_binary_interface
///
Expand Down
1 change: 1 addition & 0 deletions src/libcore/tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ fn test_iterator_size_hint() {
let v2 = &[10, 11, 12];
let vi = v.iter();

assert_eq!((0..).size_hint(), (usize::MAX, None));
assert_eq!(c.size_hint(), (usize::MAX, None));
assert_eq!(vi.clone().size_hint(), (10, Some(10)));

Expand Down
6 changes: 5 additions & 1 deletion src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
{
if let InferTables::InProgress(tables) = self.tables {
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
return tables.borrow().closure_kinds.get(&id).cloned();
return tables.borrow()
.closure_kinds
.get(&id)
.cloned()
.map(|(kind, _)| kind);
}
}

Expand Down
18 changes: 4 additions & 14 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
};

let unparsed_crate_types = matches.opt_strs("crate-type");
let (crate_types, emit_metadata) = parse_crate_types_from_list(unparsed_crate_types)
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
.unwrap_or_else(|e| early_error(error_format, &e[..]));

let mut lint_opts = vec![];
Expand Down Expand Up @@ -1402,9 +1402,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
}
}
};
if emit_metadata {
output_types.insert(OutputType::Metadata, None);
} else if output_types.is_empty() {
if output_types.is_empty() {
output_types.insert(OutputType::Exe, None);
}

Expand Down Expand Up @@ -1629,9 +1627,8 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
}

pub fn parse_crate_types_from_list(list_list: Vec<String>)
-> Result<(Vec<CrateType>, bool), String> {
-> Result<Vec<CrateType>, String> {
let mut crate_types: Vec<CrateType> = Vec::new();
let mut emit_metadata = false;
for unparsed_crate_type in &list_list {
for part in unparsed_crate_type.split(',') {
let new_part = match part {
Expand All @@ -1642,13 +1639,6 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>)
"cdylib" => CrateTypeCdylib,
"bin" => CrateTypeExecutable,
"proc-macro" => CrateTypeProcMacro,
// FIXME(#38640) remove this when Cargo is fixed.
"metadata" => {
early_warn(ErrorOutputType::default(), "--crate-type=metadata is deprecated, \
prefer --emit=metadata");
emit_metadata = true;
CrateTypeRlib
}
_ => {
return Err(format!("unknown crate type: `{}`",
part));
Expand All @@ -1660,7 +1650,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>)
}
}

return Ok((crate_types, emit_metadata));
Ok(crate_types)
}

pub mod nightly_options {
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use syntax::abi;
use syntax::ast::{self, Name, NodeId};
use syntax::attr;
use syntax::symbol::{Symbol, keywords};
use syntax_pos::Span;

use hir;

Expand Down Expand Up @@ -229,8 +230,9 @@ pub struct TypeckTables<'tcx> {
/// Records the type of each closure.
pub closure_tys: NodeMap<ty::PolyFnSig<'tcx>>,

/// Records the kind of each closure.
pub closure_kinds: NodeMap<ty::ClosureKind>,
/// Records the kind of each closure and the span and name of the variable
/// that caused the closure to be this kind.
pub closure_kinds: NodeMap<(ty::ClosureKind, Option<(Span, ast::Name)>)>,

/// For each fn, records the "liberated" types of its arguments
/// and return type. Liberated means that all bound regions
Expand Down
14 changes: 9 additions & 5 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ use rustc::middle::free_region::RegionRelations;
use rustc::ty::{self, TyCtxt};
use rustc::ty::maps::Providers;

use syntax_pos::DUMMY_SP;

use std::fmt;
use std::rc::Rc;
use std::hash::{Hash, Hasher};
Expand Down Expand Up @@ -587,9 +585,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
verb, msg, nl);
let need_note = match lp.ty.sty {
ty::TypeVariants::TyClosure(id, _) => {
if let Ok(ty::ClosureKind::FnOnce) =
ty::queries::closure_kind::try_get(self.tcx, DUMMY_SP, id) {
err.help("closure was moved because it only implements `FnOnce`");
let node_id = self.tcx.hir.as_local_node_id(id).unwrap();
if let Some(&(ty::ClosureKind::FnOnce, Some((span, name)))) =
self.tables.closure_kinds.get(&node_id)
{
err.span_note(span, &format!(
"closure cannot be invoked more than once because \
it moves the variable `{}` out of its environment",
name
));
false
} else {
true
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.tables.borrow_mut().closure_tys.insert(expr.id, sig);
match opt_kind {
Some(kind) => {
self.tables.borrow_mut().closure_kinds.insert(expr.id, kind);
self.tables.borrow_mut().closure_kinds.insert(expr.id, (kind, None));
}
None => {}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {

let closure_kinds = &self.tables.borrow().closure_kinds;
let closure_kind = match closure_kinds.get(&closure_id) {
Some(&k) => k,
Some(&(k, _)) => k,
None => {
return Err(MethodError::ClosureAmbiguity(trait_def_id));
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ fn closure_kind<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId)
-> ty::ClosureKind {
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
tcx.typeck_tables_of(def_id).closure_kinds[&node_id]
tcx.typeck_tables_of(def_id).closure_kinds[&node_id].0
}

fn adt_destructor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
Expand Down
Loading

0 comments on commit e0cc22b

Please sign in to comment.