Skip to content

Commit

Permalink
Auto merge of #36378 - GuillaumeGomez:rollup, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

- Successful merges: #35691, #36045, #36311, #36314, #36326, #36346
- Failed merges:
  • Loading branch information
bors authored Sep 10, 2016
2 parents a5f4cc5 + 2ded399 commit f8ba7cb
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/doc/nomicon/ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let mut data = vec![1, 2, 3];
let x = &data[0];
// OH NO! `push` causes the backing storage of `data` to be reallocated.
// Dangling pointer! User after free! Alas!
// Dangling pointer! Use after free! Alas!
// (this does not compile in Rust)
data.push(4);
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_trans/meth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ pub fn trans_object_shim<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
llfn
}

/// Creates a returns a dynamic vtable for the given type and vtable origin.
/// Creates a dynamic vtable for the given type and vtable origin.
/// This is used only for objects.
///
/// The vtables are cached instead of created on every call.
///
/// The `trait_ref` encodes the erased self type. Hence if we are
/// making an object `Foo<Trait>` from a value of type `Foo<T>`, then
/// `trait_ref` would map `T:Trait`.
Expand Down
38 changes: 30 additions & 8 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3159,14 +3159,36 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
tcx.sess.span_err(span, "union expressions should have exactly one field");
}
} else if check_completeness && !error_happened && !remaining_fields.is_empty() {
span_err!(tcx.sess, span, E0063,
"missing field{} {} in initializer of `{}`",
if remaining_fields.len() == 1 {""} else {"s"},
remaining_fields.keys()
.map(|n| format!("`{}`", n))
.collect::<Vec<_>>()
.join(", "),
adt_ty);
let len = remaining_fields.len();

let mut displayable_field_names = remaining_fields
.keys()
.map(|x| x.as_str())
.collect::<Vec<_>>();

displayable_field_names.sort();

let truncated_fields_error = if len <= 3 {
"".to_string()
} else {
format!(" and {} other field{}", (len - 3), if len - 3 == 1 {""} else {"s"})
};

let remaining_fields_names = displayable_field_names.iter().take(3)
.map(|n| format!("`{}`", n))
.collect::<Vec<_>>()
.join(", ");

struct_span_err!(tcx.sess, span, E0063,
"missing field{} {}{} in initializer of `{}`",
if remaining_fields.len() == 1 {""} else {"s"},
remaining_fields_names,
truncated_fields_error,
adt_ty)
.span_label(span, &format!("missing {}{}",
remaining_fields_names,
truncated_fields_error))
.emit();
}
}

Expand Down
18 changes: 15 additions & 3 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1560,13 +1560,22 @@ impl<'a> fmt::Display for Item<'a> {
} else {
write!(fmt, "Module ")?;
},
clean::FunctionItem(..) => write!(fmt, "Function ")?,
clean::FunctionItem(..) | clean::ForeignFunctionItem(..) =>
write!(fmt, "Function ")?,
clean::TraitItem(..) => write!(fmt, "Trait ")?,
clean::StructItem(..) => write!(fmt, "Struct ")?,
clean::UnionItem(..) => write!(fmt, "Union ")?,
clean::EnumItem(..) => write!(fmt, "Enum ")?,
clean::TypedefItem(..) => write!(fmt, "Type Definition ")?,
clean::MacroItem(..) => write!(fmt, "Macro ")?,
clean::PrimitiveItem(..) => write!(fmt, "Primitive Type ")?,
_ => {}
clean::StaticItem(..) | clean::ForeignStaticItem(..) =>
write!(fmt, "Static ")?,
clean::ConstantItem(..) => write!(fmt, "Constant ")?,
_ => {
// We don't generate pages for any other type.
unreachable!();
}
}
if !self.item.is_primitive() {
let cur = &self.cx.current;
Expand Down Expand Up @@ -1628,7 +1637,10 @@ impl<'a> fmt::Display for Item<'a> {
clean::StaticItem(ref i) | clean::ForeignStaticItem(ref i) =>
item_static(fmt, self.cx, self.item, i),
clean::ConstantItem(ref c) => item_constant(fmt, self.cx, self.item, c),
_ => Ok(())
_ => {
// We don't generate pages for any other type.
unreachable!();
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,9 +1169,9 @@ impl PathBuf {
/// let mut p = PathBuf::from("/test/test.rs");
///
/// p.pop();
/// assert_eq!(Path::new("/test"), p.as_path());
/// assert_eq!(Path::new("/test"), p);
/// p.pop();
/// assert_eq!(Path::new("/"), p.as_path());
/// assert_eq!(Path::new("/"), p);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pop(&mut self) -> bool {
Expand Down
12 changes: 12 additions & 0 deletions src/libstd/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ impl Instant {
/// This function may panic if the current time is earlier than this
/// instant, which is something that can happen if an `Instant` is
/// produced synthetically.
///
/// # Examples
///
/// ```no_run
/// use std::thread::sleep;
/// use std::time::{Duration, Instant};
///
/// let instant = Instant::now();
/// let three_secs = Duration::from_secs(3);
/// sleep(three_secs);
/// assert!(instant.elapsed() >= three_secs);
/// ```
#[stable(feature = "time2", since = "1.8.0")]
pub fn elapsed(&self) -> Duration {
Instant::now() - *self
Expand Down
42 changes: 39 additions & 3 deletions src/test/compile-fail/E0063.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,47 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

struct Foo {
// ignore-tidy-linelength

struct SingleFoo {
x: i32
}

struct PluralFoo {
x: i32,
y: i32,
z: i32
}

struct TruncatedFoo {
a: i32,
b: i32,
x: i32,
y: i32
y: i32,
z: i32
}

struct TruncatedPluralFoo {
a: i32,
b: i32,
c: i32,
x: i32,
y: i32,
z: i32
}


fn main() {
let x = Foo { x: 0 }; //~ ERROR E0063
let w = SingleFoo { };
//~^ ERROR missing field `x` in initializer of `SingleFoo`
//~| NOTE missing `x`
let x = PluralFoo {x: 1};
//~^ ERROR missing fields `y`, `z` in initializer of `PluralFoo`
//~| NOTE missing `y`, `z`
let y = TruncatedFoo{x:1};
//~^ missing fields `a`, `b`, `y` and 1 other field in initializer of `TruncatedFoo`
//~| NOTE `a`, `b`, `y` and 1 other field
let z = TruncatedPluralFoo{x:1};
//~^ ERROR missing fields `a`, `b`, `c` and 2 other fields in initializer of `TruncatedPluralFoo`
//~| NOTE missing `a`, `b`, `c` and 2 other fields
}
59 changes: 59 additions & 0 deletions src/test/rustdoc/titles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2016 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.

#![crate_name = "foo"]

// @matches 'foo/index.html' '//h1' 'Crate foo'

// @matches 'foo/foo_mod/index.html' '//h1' 'Module foo::foo_mod'
pub mod foo_mod {
pub struct __Thing {}
}

extern {
// @matches 'foo/fn.foo_ffn.html' '//h1' 'Function foo::foo_ffn'
pub fn foo_ffn();
}

// @matches 'foo/fn.foo_fn.html' '//h1' 'Function foo::foo_fn'
pub fn foo_fn() {}

// @matches 'foo/trait.FooTrait.html' '//h1' 'Trait foo::FooTrait'
pub trait FooTrait {}

// @matches 'foo/struct.FooStruct.html' '//h1' 'Struct foo::FooStruct'
pub struct FooStruct;

// @matches 'foo/enum.FooEnum.html' '//h1' 'Enum foo::FooEnum'
pub enum FooEnum {}

// @matches 'foo/type.FooType.html' '//h1' 'Type Definition foo::FooType'
pub type FooType = FooStruct;

// @matches 'foo/macro.foo_macro.html' '//h1' 'Macro foo::foo_macro'
#[macro_export]
macro_rules! foo_macro {
() => ();
}

// @matches 'foo/primitive.bool.html' '//h1' 'Primitive Type bool'
#[doc(primitive = "bool")]
mod bool {}

// @matches 'foo/static.FOO_STATIC.html' '//h1' 'Static foo::FOO_STATIC'
pub static FOO_STATIC: FooStruct = FooStruct;

extern {
// @matches 'foo/static.FOO_FSTATIC.html' '//h1' 'Static foo::FOO_FSTATIC'
pub static FOO_FSTATIC: FooStruct;
}

// @matches 'foo/constant.FOO_CONSTANT.html' '//h1' 'Constant foo::FOO_CONSTANT'
pub const FOO_CONSTANT: FooStruct = FooStruct;

0 comments on commit f8ba7cb

Please sign in to comment.