Skip to content

Commit

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

Successful merges:

 - #57259 (Update reference of rlibc crate to compiler-builtins crate)
 - #57740 (Use `to_ne_bytes` for converting IPv4Addr to octets)
 - #57926 (Tiny expansion to docs for `core::convert`.)
 - #58157 (Add Cargo.lock automatically adding message)
 - #58203 (rustdoc: display sugared return types for async functions)
 - #58243 (Add trait alias support in rustdoc)
 - #58262 (Add #[must_use] message to Fn* traits)
 - #58295 (std::sys::unix::stdio: explain why we do into_raw)
 - #58297 (Cleanup JS a bit)
 - #58317 (Some writing improvement, conciseness of intro)
 - #58324 (miri: give non-generic functions a stable address)
 - #58332 (operand-to-place copies should never be overlapping)
 - #58345 (When there are multiple filenames, print what got interpreted as filenames)
 - #58346 (rpath computation: explain why we pop())
 - #58350 (Fix failing tidy (line endings on Windows))
 - #58352 (miri value visitor: use `?` in macro)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Feb 10, 2019
2 parents 0b7af26 + d792cef commit 3d845e1
Show file tree
Hide file tree
Showing 25 changed files with 306 additions and 102 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "adler32"
version = "1.0.3"
Expand Down
2 changes: 1 addition & 1 deletion src/doc/embedded-book
7 changes: 3 additions & 4 deletions src/doc/rustdoc/src/unstable-features.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Unstable features

Rustdoc is under active development, and like the Rust compiler, some features are only available
on the nightly releases. Some of these are new and need some more testing before they're able to get
released to the world at large, and some of them are tied to features in the Rust compiler that are
themselves unstable. Several features here require a matching `#![feature(...)]` attribute to
on nightly releases. Some of these features are new and need some more testing before they're able to be
released to the world at large, and some of them are tied to features in the Rust compiler that are unstable. Several features here require a matching `#![feature(...)]` attribute to
enable, and thus are more fully documented in the [Unstable Book]. Those sections will link over
there as necessary.

Expand Down Expand Up @@ -428,4 +427,4 @@ $ rustdoc src/lib.rs --test -Z unstable-options --persist-doctests target/rustdo

This flag allows you to keep doctest executables around after they're compiled or run.
Usually, rustdoc will immediately discard a compiled doctest after it's been tested, but
with this option, you can keep those binaries around for farther testing.
with this option, you can keep those binaries around for farther testing.
5 changes: 4 additions & 1 deletion src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
//! [`TryFrom<T>`][`TryFrom`] rather than [`Into<U>`][`Into`] or [`TryInto<U>`][`TryInto`],
//! as [`From`] and [`TryFrom`] provide greater flexibility and offer
//! equivalent [`Into`] or [`TryInto`] implementations for free, thanks to a
//! blanket implementation in the standard library.
//! blanket implementation in the standard library. However, there are some cases
//! where this is not possible, such as creating conversions into a type defined
//! outside your library, so implementing [`Into`] instead of [`From`] is
//! sometimes necessary.
//!
//! # Generic Implementations
//!
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! often generated by LLVM. Additionally, this library can make explicit
//! calls to these functions. Their signatures are the same as found in C.
//! These functions are often provided by the system libc, but can also be
//! provided by the [rlibc crate](https://crates.io/crates/rlibc).
//! provided by the [compiler-builtins crate](https://crates.io/crates/compiler_builtins).
//!
//! * `rust_begin_panic` - This function takes four arguments, a
//! `fmt::Arguments`, a `&'static str`, and two `u32`'s. These four arguments
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/ops/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
label="expected an `Fn<{Args}>` closure, found `{Self}`",
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use]
#[must_use = "closures are lazy and do nothing unless called"]
pub trait Fn<Args> : FnMut<Args> {
/// Performs the call operation.
#[unstable(feature = "fn_traits", issue = "29625")]
Expand Down Expand Up @@ -141,7 +141,7 @@ pub trait Fn<Args> : FnMut<Args> {
label="expected an `FnMut<{Args}>` closure, found `{Self}`",
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use]
#[must_use = "closures are lazy and do nothing unless called"]
pub trait FnMut<Args> : FnOnce<Args> {
/// Performs the call operation.
#[unstable(feature = "fn_traits", issue = "29625")]
Expand Down Expand Up @@ -220,7 +220,7 @@ pub trait FnMut<Args> : FnOnce<Args> {
label="expected an `FnOnce<{Args}>` closure, found `{Self}`",
)]
#[fundamental] // so that regex can rely that `&str: !FnMut`
#[must_use]
#[must_use = "closures are lazy and do nothing unless called"]
pub trait FnOnce<Args> {
/// The returned type after the call operator is used.
#[stable(feature = "fn_once_output", since = "1.12.0")]
Expand Down
31 changes: 23 additions & 8 deletions src/librustc/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use self::pointer::{Pointer, PointerArithmetic};
use std::fmt;
use crate::mir;
use crate::hir::def_id::DefId;
use crate::ty::{self, TyCtxt, Instance};
use crate::ty::{self, TyCtxt, Instance, subst::UnpackedKind};
use crate::ty::layout::{self, Size};
use std::io;
use crate::rustc_serialize::{Encoder, Decodable, Encodable};
Expand Down Expand Up @@ -318,14 +318,29 @@ impl<'tcx> AllocMap<'tcx> {
id
}

/// Functions cannot be identified by pointers, as asm-equal functions can get deduplicated
/// by the linker and functions can be duplicated across crates.
/// We thus generate a new `AllocId` for every mention of a function. This means that
/// `main as fn() == main as fn()` is false, while `let x = main as fn(); x == x` is true.
pub fn create_fn_alloc(&mut self, instance: Instance<'tcx>) -> AllocId {
let id = self.reserve();
self.id_to_kind.insert(id, AllocKind::Function(instance));
id
// Functions cannot be identified by pointers, as asm-equal functions can get deduplicated
// by the linker (we set the "unnamed_addr" attribute for LLVM) and functions can be
// duplicated across crates.
// We thus generate a new `AllocId` for every mention of a function. This means that
// `main as fn() == main as fn()` is false, while `let x = main as fn(); x == x` is true.
// However, formatting code relies on function identity (see #58320), so we only do
// this for generic functions. Lifetime parameters are ignored.
let is_generic = instance.substs.into_iter().any(|kind| {
match kind.unpack() {
UnpackedKind::Lifetime(_) => false,
_ => true,
}
});
if is_generic {
// Get a fresh ID
let id = self.reserve();
self.id_to_kind.insert(id, AllocKind::Function(instance));
id
} else {
// Deduplicate
self.intern(AllocKind::Function(instance))
}
}

/// Returns `None` in case the `AllocId` is dangling. An `EvalContext` can still have a
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig, lib: &Path) -> String

let cwd = env::current_dir().unwrap();
let mut lib = fs::canonicalize(&cwd.join(lib)).unwrap_or_else(|_| cwd.join(lib));
lib.pop();
lib.pop(); // strip filename
let mut output = cwd.join(&config.out_filename);
output.pop();
output.pop(); // strip filename
let output = fs::canonicalize(&output).unwrap_or(output);
let relative = path_relative_from(&lib, &output).unwrap_or_else(||
panic!("couldn't create relative path from {:?} to {:?}", output, lib));
Expand Down
10 changes: 9 additions & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,15 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
early_error(sopts.error_format, "no input filename given");
}
1 => panic!("make_input should have provided valid inputs"),
_ => early_error(sopts.error_format, "multiple input filenames provided"),
_ =>
early_error(
sopts.error_format,
&format!(
"multiple input filenames provided (first two filenames are `{}` and `{}`)",
matches.free[0],
matches.free[1],
),
)
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/librustc_mir/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,8 @@ where
let src = match self.try_read_immediate(src)? {
Ok(src_val) => {
// Yay, we got a value that we can write directly.
// FIXME: Add a check to make sure that if `src` is indirect,
// it does not overlap with `dest`.
return self.write_immediate_no_validate(src_val, dest);
}
Err(mplace) => mplace,
Expand All @@ -836,7 +838,8 @@ where
self.memory.copy(
src_ptr, src_align,
dest_ptr, dest_align,
dest.layout.size, false
dest.layout.size,
/*nonoverlapping*/ true,
)?;

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/interpret/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
}

macro_rules! make_value_visitor {
($visitor_trait_name:ident, $($mutability:ident)*) => {
($visitor_trait_name:ident, $($mutability:ident)?) => {
// How to traverse a value and what to do when we are at the leaves.
pub trait $visitor_trait_name<'a, 'mir, 'tcx: 'mir+'a, M: Machine<'a, 'mir, 'tcx>>: Sized {
type V: Value<'a, 'mir, 'tcx, M>;

/// The visitor must have an `EvalContext` in it.
fn ecx(&$($mutability)* self)
-> &$($mutability)* EvalContext<'a, 'mir, 'tcx, M>;
fn ecx(&$($mutability)? self)
-> &$($mutability)? EvalContext<'a, 'mir, 'tcx, M>;

// Recursive actions, ready to be overloaded.
/// Visit the given value, dispatching as appropriate to more specialized visitors.
Expand Down
75 changes: 71 additions & 4 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ pub enum ItemEnum {
StaticItem(Static),
ConstantItem(Constant),
TraitItem(Trait),
TraitAliasItem(TraitAlias),
ImplItem(Impl),
/// A method signature only. Used for required methods in traits (ie,
/// non-default-methods).
Expand Down Expand Up @@ -554,6 +555,7 @@ impl ItemEnum {
ItemEnum::TyMethodItem(ref i) => &i.generics,
ItemEnum::MethodItem(ref i) => &i.generics,
ItemEnum::ForeignFunctionItem(ref f) => &f.generics,
ItemEnum::TraitAliasItem(ref ta) => &ta.generics,
_ => return None,
})
}
Expand Down Expand Up @@ -603,6 +605,7 @@ impl Clean<Item> for doctree::Module {
items.extend(self.impls.iter().flat_map(|x| x.clean(cx)));
items.extend(self.macros.iter().map(|x| x.clean(cx)));
items.extend(self.proc_macros.iter().map(|x| x.clean(cx)));
items.extend(self.trait_aliases.iter().map(|x| x.clean(cx)));

// determine if we should display the inner contents or
// the outer `mod` item for the source code.
Expand Down Expand Up @@ -1724,6 +1727,30 @@ impl FnDecl {
pub fn self_type(&self) -> Option<SelfTy> {
self.inputs.values.get(0).and_then(|v| v.to_self())
}

/// Returns the sugared return type for an async function.
///
/// For example, if the return type is `impl std::future::Future<Output = i32>`, this function
/// will return `i32`.
///
/// # Panics
///
/// This function will panic if the return type does not match the expected sugaring for async
/// functions.
pub fn sugared_async_return_type(&self) -> FunctionRetTy {
match &self.output {
FunctionRetTy::Return(Type::ImplTrait(bounds)) => {
match &bounds[0] {
GenericBound::TraitBound(PolyTrait { trait_, .. }, ..) => {
let bindings = trait_.bindings().unwrap();
FunctionRetTy::Return(bindings[0].ty.clone())
}
_ => panic!("unexpected desugaring of async function"),
}
}
_ => panic!("unexpected desugaring of async function"),
}
}
}

#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
Expand Down Expand Up @@ -1885,13 +1912,38 @@ impl Clean<Item> for doctree::Trait {
items: self.items.clean(cx),
generics: self.generics.clean(cx),
bounds: self.bounds.clean(cx),
is_spotlight: is_spotlight,
is_spotlight,
is_auto: self.is_auto.clean(cx),
}),
}
}
}

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct TraitAlias {
pub generics: Generics,
pub bounds: Vec<GenericBound>,
}

impl Clean<Item> for doctree::TraitAlias {
fn clean(&self, cx: &DocContext) -> Item {
let attrs = self.attrs.clean(cx);
Item {
name: Some(self.name.clean(cx)),
attrs,
source: self.whence.clean(cx),
def_id: cx.tcx.hir().local_def_id(self.id),
visibility: self.vis.clean(cx),
stability: self.stab.clean(cx),
deprecation: self.depr.clean(cx),
inner: TraitAliasItem(TraitAlias {
generics: self.generics.clean(cx),
bounds: self.bounds.clean(cx),
}),
}
}
}

impl Clean<bool> for hir::IsAuto {
fn clean(&self, _: &DocContext) -> bool {
match *self {
Expand Down Expand Up @@ -2223,6 +2275,7 @@ pub enum TypeKind {
Macro,
Attr,
Derive,
TraitAlias,
}

pub trait GetDefId {
Expand Down Expand Up @@ -2282,6 +2335,21 @@ impl Type {
_ => None,
}
}

pub fn bindings(&self) -> Option<&[TypeBinding]> {
match *self {
ResolvedPath { ref path, .. } => {
path.segments.last().and_then(|seg| {
if let GenericArgs::AngleBracketed { ref bindings, .. } = seg.args {
Some(&**bindings)
} else {
None
}
})
}
_ => None
}
}
}

impl GetDefId for Type {
Expand Down Expand Up @@ -3819,10 +3887,9 @@ pub fn register_def(cx: &DocContext, def: Def) -> DefId {
MacroKind::Derive => (i, TypeKind::Derive),
MacroKind::ProcMacroStub => unreachable!(),
},
Def::TraitAlias(i) => (i, TypeKind::TraitAlias),
Def::SelfTy(Some(def_id), _) => (def_id, TypeKind::Trait),
Def::SelfTy(_, Some(impl_def_id)) => {
return impl_def_id
}
Def::SelfTy(_, Some(impl_def_id)) => return impl_def_id,
_ => return def.def_id()
};
if did.is_local() { return did }
Expand Down
44 changes: 29 additions & 15 deletions src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct Module {
pub foreigns: Vec<hir::ForeignMod>,
pub macros: Vec<Macro>,
pub proc_macros: Vec<ProcMacro>,
pub trait_aliases: Vec<TraitAlias>,
pub is_crate: bool,
}

Expand All @@ -53,21 +54,22 @@ impl Module {
where_inner: syntax_pos::DUMMY_SP,
attrs : hir::HirVec::new(),
extern_crates: Vec::new(),
imports : Vec::new(),
structs : Vec::new(),
unions : Vec::new(),
enums : Vec::new(),
fns : Vec::new(),
mods : Vec::new(),
typedefs : Vec::new(),
existentials: Vec::new(),
statics : Vec::new(),
constants : Vec::new(),
traits : Vec::new(),
impls : Vec::new(),
foreigns : Vec::new(),
macros : Vec::new(),
proc_macros: Vec::new(),
imports : Vec::new(),
structs : Vec::new(),
unions : Vec::new(),
enums : Vec::new(),
fns : Vec::new(),
mods : Vec::new(),
typedefs : Vec::new(),
existentials: Vec::new(),
statics : Vec::new(),
constants : Vec::new(),
traits : Vec::new(),
impls : Vec::new(),
foreigns : Vec::new(),
macros : Vec::new(),
proc_macros: Vec::new(),
trait_aliases: Vec::new(),
is_crate : false,
}
}
Expand Down Expand Up @@ -208,6 +210,18 @@ pub struct Trait {
pub depr: Option<attr::Deprecation>,
}

pub struct TraitAlias {
pub name: Name,
pub generics: hir::Generics,
pub bounds: hir::HirVec<hir::GenericBound>,
pub attrs: hir::HirVec<ast::Attribute>,
pub id: ast::NodeId,
pub whence: Span,
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
pub depr: Option<attr::Deprecation>,
}

#[derive(Debug)]
pub struct Impl {
pub unsafety: hir::Unsafety,
Expand Down
Loading

0 comments on commit 3d845e1

Please sign in to comment.