Skip to content

Commit

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

- Successful merges: #41937, #41957, #42017, #42039, #42046
- Failed merges:
  • Loading branch information
bors committed May 17, 2017
2 parents 86319e4 + c3d22eb commit d8215fc
Show file tree
Hide file tree
Showing 41 changed files with 617 additions and 547 deletions.
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 62 files
+2 −0 .gitattributes
+11 −8 CONTRIBUTING.md
+1 −2 first-edition/src/bibliography.md
+2 −2 first-edition/src/guessing-game.md
+1 −1 first-edition/src/mutability.md
+1 −1 first-edition/src/references-and-borrowing.md
+1 −1 first-edition/src/structs.md
+1 −1 first-edition/src/syntax-index.md
+1 −1 first-edition/src/the-stack-and-the-heap.md
+24 −0 second-edition/dictionary.txt
+1 −1 second-edition/nostarch/chapter03.md
+352 −253 second-edition/nostarch/chapter05.md
+ second-edition/nostarch/odt/chapter05.docx
+ second-edition/nostarch/odt/chapter05.odt
+11 −3 second-edition/src/SUMMARY.md
+1 −1 second-edition/src/ch01-02-hello-world.md
+1 −1 second-edition/src/ch03-02-data-types.md
+2 −2 second-edition/src/ch03-03-how-functions-work.md
+3 −3 second-edition/src/ch03-05-control-flow.md
+2 −2 second-edition/src/ch04-01-what-is-ownership.md
+10 −7 second-edition/src/ch04-03-slices.md
+11 −393 second-edition/src/ch05-00-structs.md
+267 −0 second-edition/src/ch05-01-defining-structs.md
+0 −253 second-edition/src/ch05-01-method-syntax.md
+262 −0 second-edition/src/ch05-02-example-structs.md
+243 −0 second-edition/src/ch05-03-method-syntax.md
+1 −1 second-edition/src/ch06-01-defining-an-enum.md
+1 −1 second-edition/src/ch07-01-mod-and-the-filesystem.md
+0 −1 second-edition/src/ch07-02-controlling-visibility-with-pub.md
+0 −6 second-edition/src/ch07-03-importing-names-with-use.md
+1 −1 second-edition/src/ch08-02-strings.md
+2 −2 second-edition/src/ch08-03-hash-maps.md
+3 −3 second-edition/src/ch09-01-unrecoverable-errors-with-panic.md
+5 −5 second-edition/src/ch09-03-to-panic-or-not-to-panic.md
+4 −4 second-edition/src/ch10-00-generics.md
+1 −1 second-edition/src/ch10-03-lifetime-syntax.md
+6 −6 second-edition/src/ch11-01-writing-tests.md
+4 −4 second-edition/src/ch11-02-running-tests.md
+2 −2 second-edition/src/ch11-03-test-organization.md
+1 −1 second-edition/src/ch12-01-accepting-command-line-arguments.md
+1 −1 second-edition/src/ch12-02-reading-a-file.md
+7 −11 second-edition/src/ch12-03-improving-error-handling-and-modularity.md
+4 −4 second-edition/src/ch12-04-testing-the-librarys-functionality.md
+3 −3 second-edition/src/ch12-05-working-with-environment-variables.md
+7 −8 second-edition/src/ch13-02-iterators.md
+2 −4 second-edition/src/ch13-03-improving-our-io-project.md
+2 −2 second-edition/src/ch14-01-release-profiles.md
+1 −1 second-edition/src/ch14-02-publishing-to-crates-io.md
+4 −4 second-edition/src/ch14-03-cargo-workspaces.md
+4 −6 second-edition/src/ch15-01-box.md
+3 −1 second-edition/src/ch18-02-refutability.md
+1 −1 second-edition/src/ch18-03-pattern-syntax.md
+11 −13 second-edition/src/ch19-02-advanced-lifetimes.md
+30 −2 second-edition/src/ch20-00-final-project-a-web-server.md
+589 −0 second-edition/src/ch20-01-single-threaded.md
+113 −0 second-edition/src/ch20-02-slow-requests.md
+284 −0 second-edition/src/ch20-03-designing-the-interface.md
+248 −0 second-edition/src/ch20-04-storing-threads.md
+516 −0 second-edition/src/ch20-05-sending-requests-via-channels.md
+589 −0 second-edition/src/ch20-06-graceful-shutdown-and-cleanup.md
+ second-edition/src/img/hello.png
+7 −2 second-edition/theme/index.hbs
2 changes: 1 addition & 1 deletion src/doc/reference
19 changes: 19 additions & 0 deletions src/librustc/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ use super::sub::Sub;
use super::InferCtxt;
use super::{MiscVariable, TypeTrace};

use hir::def_id::DefId;
use ty::{IntType, UintType};
use ty::{self, Ty, TyCtxt};
use ty::error::TypeError;
use ty::relate::{self, Relate, RelateResult, TypeRelation};
use ty::subst::Substs;
use traits::{Obligation, PredicateObligations};

use syntax::ast;
Expand Down Expand Up @@ -336,6 +338,23 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
Ok(ty::Binder(self.relate(a.skip_binder(), b.skip_binder())?))
}

fn relate_item_substs(&mut self,
item_def_id: DefId,
a_subst: &'tcx Substs<'tcx>,
b_subst: &'tcx Substs<'tcx>)
-> RelateResult<'tcx, &'tcx Substs<'tcx>>
{
if self.ambient_variance == ty::Variance::Invariant {
// Avoid fetching the variance if we are in an invariant
// context; no need, and it can induce dependency cycles
// (e.g. #41849).
relate::relate_substs(self, None, a_subst, b_subst)
} else {
let opt_variances = self.tcx().variances_of(item_def_id);
relate::relate_substs(self, Some(&opt_variances), a_subst, b_subst)
}
}

fn relate_with_variance<T: Relate<'tcx>>(&mut self,
variance: ty::Variance,
a: &T,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ macro_rules! define_map_struct {
output: $output:tt) => {
define_map_struct! {
tcx: $tcx,
ready: ([pub] $attrs $name),
ready: ([] $attrs $name),
input: ($($input)*),
output: $output
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_mir/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ fn write_mir_sig(tcx: TyCtxt, src: MirSource, mir: &Mir, w: &mut Write)
MirSource::Promoted(_, i) => write!(w, "{:?} in", i)?
}

write!(w, " {}", tcx.node_path_str(src.item_id()))?;
item_path::with_forced_impl_filename_line(|| { // see notes on #41697 elsewhere
write!(w, " {}", tcx.node_path_str(src.item_id()))
})?;

if let MirSource::Fn(_) = src {
write!(w, "(")?;
Expand Down
51 changes: 49 additions & 2 deletions src/librustc_typeck/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,45 @@ pub fn coerce_unsized_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
return err_info;
}

// Here we are considering a case of converting
// `S<P0...Pn>` to S<Q0...Qn>`. As an example, let's imagine a struct `Foo<T, U>`,
// which acts like a pointer to `U`, but carries along some extra data of type `T`:
//
// struct Foo<T, U> {
// extra: T,
// ptr: *mut U,
// }
//
// We might have an impl that allows (e.g.) `Foo<T, [i32; 3]>` to be unsized
// to `Foo<T, [i32]>`. That impl would look like:
//
// impl<T, U: Unsize<V>, V> CoerceUnsized<Foo<T, V>> for Foo<T, U> {}
//
// Here `U = [i32; 3]` and `V = [i32]`. At runtime,
// when this coercion occurs, we would be changing the
// field `ptr` from a thin pointer of type `*mut [i32;
// 3]` to a fat pointer of type `*mut [i32]` (with
// extra data `3`). **The purpose of this check is to
// make sure that we know how to do this conversion.**
//
// To check if this impl is legal, we would walk down
// the fields of `Foo` and consider their types with
// both substitutes. We are looking to find that
// exactly one (non-phantom) field has changed its
// type, which we will expect to be the pointer that
// is becoming fat (we could probably generalize this
// to mutiple thin pointers of the same type becoming
// fat, but we don't). In this case:
//
// - `extra` has type `T` before and type `T` after
// - `ptr` has type `*mut U` before and type `*mut V` after
//
// Since just one field changed, we would then check
// that `*mut U: CoerceUnsized<*mut V>` is implemented
// (in other words, that we know how to do this
// conversion). This will work out because `U:
// Unsize<V>`, and we have a builtin rule that `*mut
// U` can be coerced to `*mut V` if `U: Unsize<V>`.
let fields = &def_a.struct_variant().fields;
let diff_fields = fields.iter()
.enumerate()
Expand All @@ -260,8 +299,16 @@ pub fn coerce_unsized_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
return None;
}

// Ignore fields that aren't significantly changed
if let Ok(ok) = infcx.sub_types(false, &cause, b, a) {
// Ignore fields that aren't changed; it may
// be that we could get away with subtyping or
// something more accepting, but we use
// equality because we want to be able to
// perform this check without computing
// variance where possible. (This is because
// we may have to evaluate constraint
// expressions in the course of execution.)
// See e.g. #41936.
if let Ok(ok) = infcx.eq_types(false, &cause, b, a) {
if ok.obligations.is_empty() {
return None;
}
Expand Down
18 changes: 9 additions & 9 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ impl Stmt {
StmtKind::Mac(mac) => StmtKind::Mac(mac.map(|(mac, _style, attrs)| {
(mac, MacStmtStyle::Semicolon, attrs)
})),
node @ _ => node,
node => node,
};
self
}
Expand Down Expand Up @@ -1076,16 +1076,16 @@ impl LitKind {
pub fn is_unsuffixed(&self) -> bool {
match *self {
// unsuffixed variants
LitKind::Str(..) => true,
LitKind::ByteStr(..) => true,
LitKind::Byte(..) => true,
LitKind::Char(..) => true,
LitKind::Int(_, LitIntType::Unsuffixed) => true,
LitKind::FloatUnsuffixed(..) => true,
LitKind::Str(..) |
LitKind::ByteStr(..) |
LitKind::Byte(..) |
LitKind::Char(..) |
LitKind::Int(_, LitIntType::Unsuffixed) |
LitKind::FloatUnsuffixed(..) |
LitKind::Bool(..) => true,
// suffixed variants
LitKind::Int(_, LitIntType::Signed(..)) => false,
LitKind::Int(_, LitIntType::Unsigned(..)) => false,
LitKind::Int(_, LitIntType::Signed(..)) |
LitKind::Int(_, LitIntType::Unsigned(..)) |
LitKind::Float(..) => false,
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/libsyntax/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ impl NestedMetaItem {
/// Returns the MetaItem if self is a NestedMetaItemKind::MetaItem.
pub fn meta_item(&self) -> Option<&MetaItem> {
match self.node {
NestedMetaItemKind::MetaItem(ref item) => Some(&item),
NestedMetaItemKind::MetaItem(ref item) => Some(item),
_ => None
}
}

/// Returns the Lit if self is a NestedMetaItemKind::Literal.
pub fn literal(&self) -> Option<&Lit> {
match self.node {
NestedMetaItemKind::Literal(ref lit) => Some(&lit),
NestedMetaItemKind::Literal(ref lit) => Some(lit),
_ => None
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ impl MetaItem {
match self.node {
MetaItemKind::NameValue(ref v) => {
match v.node {
LitKind::Str(ref s, _) => Some((*s).clone()),
LitKind::Str(ref s, _) => Some(*s),
_ => None,
}
},
Expand Down Expand Up @@ -1217,9 +1217,10 @@ impl LitKind {
Token::Literal(token::Lit::Float(symbol), Some(Symbol::intern(ty.ty_to_string())))
}
LitKind::FloatUnsuffixed(symbol) => Token::Literal(token::Lit::Float(symbol), None),
LitKind::Bool(value) => Token::Ident(Ident::with_empty_ctxt(Symbol::intern(match value {
true => "true",
false => "false",
LitKind::Bool(value) => Token::Ident(Ident::with_empty_ctxt(Symbol::intern(if value {
"true"
} else {
"false"
}))),
}
}
Expand Down Expand Up @@ -1261,7 +1262,7 @@ impl<T: HasAttrs> HasAttrs for Spanned<T> {

impl HasAttrs for Vec<Attribute> {
fn attrs(&self) -> &[Attribute] {
&self
self
}
fn map_attrs<F: FnOnce(Vec<Attribute>) -> Vec<Attribute>>(self, f: F) -> Self {
f(self)
Expand All @@ -1270,7 +1271,7 @@ impl HasAttrs for Vec<Attribute> {

impl HasAttrs for ThinVec<Attribute> {
fn attrs(&self) -> &[Attribute] {
&self
self
}
fn map_attrs<F: FnOnce(Vec<Attribute>) -> Vec<Attribute>>(self, f: F) -> Self {
f(self.into()).into()
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ impl CodeMap {
match self.span_to_snippet(sp) {
Ok(snippet) => {
let snippet = snippet.split(c).nth(0).unwrap_or("").trim_right();
if snippet.len() > 0 && !snippet.contains('\n') {
if !snippet.is_empty() && !snippet.contains('\n') {
Span { hi: BytePos(sp.lo.0 + snippet.len() as u32), ..sp }
} else {
sp
Expand All @@ -502,7 +502,7 @@ impl CodeMap {
pub fn get_filemap(&self, filename: &str) -> Option<Rc<FileMap>> {
for fm in self.files.borrow().iter() {
if filename == fm.name {
(self.dep_tracking_callback.borrow())(&fm);
(self.dep_tracking_callback.borrow())(fm);
return Some(fm.clone());
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'a> StripUnconfigured<'a> {
return false;
}

let mis = if !is_cfg(&attr) {
let mis = if !is_cfg(attr) {
return true;
} else if let Some(mis) = attr.meta_item_list() {
mis
Expand All @@ -150,7 +150,7 @@ impl<'a> StripUnconfigured<'a> {
// flag the offending attributes
for attr in attrs.iter() {
if !self.features.map(|features| features.stmt_expr_attributes).unwrap_or(true) {
let mut err = feature_err(&self.sess,
let mut err = feature_err(self.sess,
"stmt_expr_attributes",
attr.span,
GateIssue::Language,
Expand Down Expand Up @@ -258,7 +258,7 @@ impl<'a> StripUnconfigured<'a> {
pub fn configure_struct_expr_field(&mut self, field: ast::Field) -> Option<ast::Field> {
if !self.features.map(|features| features.struct_field_attributes).unwrap_or(true) {
if !field.attrs.is_empty() {
let mut err = feature_err(&self.sess,
let mut err = feature_err(self.sess,
"struct_field_attributes",
field.span,
GateIssue::Language,
Expand Down Expand Up @@ -290,7 +290,7 @@ impl<'a> StripUnconfigured<'a> {
for attr in attrs.iter() {
if !self.features.map(|features| features.struct_field_attributes).unwrap_or(true) {
let mut err = feature_err(
&self.sess,
self.sess,
"struct_field_attributes",
attr.span,
GateIssue::Language,
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/diagnostics/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,

// URLs can be unavoidably longer than the line limit, so we allow them.
// Allowed format is: `[name]: https://www.rust-lang.org/`
let is_url = |l: &str| l.starts_with('[') && l.contains("]:") && l.contains("http");
let is_url = |l: &str| l.starts_with("[") && l.contains("]:") && l.contains("http");

if msg.lines().any(|line| line.len() > MAX_DESCRIPTION_WIDTH && !is_url(line)) {
ecx.span_err(span, &format!(
Expand Down Expand Up @@ -177,7 +177,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
if let Err(e) = output_metadata(ecx,
&target_triple,
&crate_name.name.as_str(),
&diagnostics) {
diagnostics) {
ecx.span_bug(span, &format!(
"error writing metadata for triple `{}` and crate `{}`, error: {}, \
cause: {:?}",
Expand Down Expand Up @@ -227,7 +227,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,

MacEager::items(SmallVector::many(vec![
P(ast::Item {
ident: name.clone(),
ident: *name,
attrs: Vec::new(),
id: ast::DUMMY_NODE_ID,
node: ast::ItemKind::Const(
Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ pub struct ExpansionData {
}

/// One of these is made during expansion and incrementally updated as we go;
/// when a macro expansion occurs, the resulting nodes have the backtrace()
/// -> expn_info of their expansion context stored into their span.
/// when a macro expansion occurs, the resulting nodes have the `backtrace()
/// -> expn_info` of their expansion context stored into their span.
pub struct ExtCtxt<'a> {
pub parse_sess: &'a parse::ParseSess,
pub ecfg: expand::ExpansionConfig<'a>,
Expand Down Expand Up @@ -711,7 +711,7 @@ impl<'a> ExtCtxt<'a> {
}
ctxt = info.call_site.ctxt;
last_macro = Some(info.call_site);
return Some(());
Some(())
}).is_none() {
break
}
Expand Down Expand Up @@ -772,9 +772,9 @@ impl<'a> ExtCtxt<'a> {
}
pub fn trace_macros_diag(&self) {
for (sp, notes) in self.expansions.iter() {
let mut db = self.parse_sess.span_diagnostic.span_note_diag(*sp, &"trace_macro");
let mut db = self.parse_sess.span_diagnostic.span_note_diag(*sp, "trace_macro");
for note in notes {
db.note(&note);
db.note(note);
}
db.emit();
}
Expand All @@ -797,7 +797,7 @@ impl<'a> ExtCtxt<'a> {
v.push(self.ident_of(s));
}
v.extend(components.iter().map(|s| self.ident_of(s)));
return v
v
}
pub fn name_of(&self, st: &str) -> ast::Name {
Symbol::intern(st)
Expand Down
Loading

0 comments on commit d8215fc

Please sign in to comment.