Skip to content

Commit 3d845e1

Browse files
committed
Auto merge of #58361 - GuillaumeGomez:rollup, r=GuillaumeGomez
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
2 parents 0b7af26 + d792cef commit 3d845e1

File tree

25 files changed

+306
-102
lines changed

25 files changed

+306
-102
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# This file is automatically @generated by Cargo.
2+
# It is not intended for manual editing.
13
[[package]]
24
name = "adler32"
35
version = "1.0.3"

src/doc/rustdoc/src/unstable-features.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
# Unstable features
22

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

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

429428
This flag allows you to keep doctest executables around after they're compiled or run.
430429
Usually, rustdoc will immediately discard a compiled doctest after it's been tested, but
431-
with this option, you can keep those binaries around for farther testing.
430+
with this option, you can keep those binaries around for farther testing.

src/libcore/convert.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
//! [`TryFrom<T>`][`TryFrom`] rather than [`Into<U>`][`Into`] or [`TryInto<U>`][`TryInto`],
1818
//! as [`From`] and [`TryFrom`] provide greater flexibility and offer
1919
//! equivalent [`Into`] or [`TryInto`] implementations for free, thanks to a
20-
//! blanket implementation in the standard library.
20+
//! blanket implementation in the standard library. However, there are some cases
21+
//! where this is not possible, such as creating conversions into a type defined
22+
//! outside your library, so implementing [`Into`] instead of [`From`] is
23+
//! sometimes necessary.
2124
//!
2225
//! # Generic Implementations
2326
//!

src/libcore/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
//! often generated by LLVM. Additionally, this library can make explicit
2525
//! calls to these functions. Their signatures are the same as found in C.
2626
//! These functions are often provided by the system libc, but can also be
27-
//! provided by the [rlibc crate](https://crates.io/crates/rlibc).
27+
//! provided by the [compiler-builtins crate](https://crates.io/crates/compiler_builtins).
2828
//!
2929
//! * `rust_begin_panic` - This function takes four arguments, a
3030
//! `fmt::Arguments`, a `&'static str`, and two `u32`'s. These four arguments

src/libcore/ops/function.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
label="expected an `Fn<{Args}>` closure, found `{Self}`",
6363
)]
6464
#[fundamental] // so that regex can rely that `&str: !FnMut`
65-
#[must_use]
65+
#[must_use = "closures are lazy and do nothing unless called"]
6666
pub trait Fn<Args> : FnMut<Args> {
6767
/// Performs the call operation.
6868
#[unstable(feature = "fn_traits", issue = "29625")]
@@ -141,7 +141,7 @@ pub trait Fn<Args> : FnMut<Args> {
141141
label="expected an `FnMut<{Args}>` closure, found `{Self}`",
142142
)]
143143
#[fundamental] // so that regex can rely that `&str: !FnMut`
144-
#[must_use]
144+
#[must_use = "closures are lazy and do nothing unless called"]
145145
pub trait FnMut<Args> : FnOnce<Args> {
146146
/// Performs the call operation.
147147
#[unstable(feature = "fn_traits", issue = "29625")]
@@ -220,7 +220,7 @@ pub trait FnMut<Args> : FnOnce<Args> {
220220
label="expected an `FnOnce<{Args}>` closure, found `{Self}`",
221221
)]
222222
#[fundamental] // so that regex can rely that `&str: !FnMut`
223-
#[must_use]
223+
#[must_use = "closures are lazy and do nothing unless called"]
224224
pub trait FnOnce<Args> {
225225
/// The returned type after the call operator is used.
226226
#[stable(feature = "fn_once_output", since = "1.12.0")]

src/librustc/mir/interpret/mod.rs

+23-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub use self::pointer::{Pointer, PointerArithmetic};
2727
use std::fmt;
2828
use crate::mir;
2929
use crate::hir::def_id::DefId;
30-
use crate::ty::{self, TyCtxt, Instance};
30+
use crate::ty::{self, TyCtxt, Instance, subst::UnpackedKind};
3131
use crate::ty::layout::{self, Size};
3232
use std::io;
3333
use crate::rustc_serialize::{Encoder, Decodable, Encodable};
@@ -318,14 +318,29 @@ impl<'tcx> AllocMap<'tcx> {
318318
id
319319
}
320320

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

331346
/// Returns `None` in case the `AllocId` is dangling. An `EvalContext` can still have a

src/librustc_codegen_llvm/back/rpath.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ fn get_rpath_relative_to_output(config: &mut RPathConfig, lib: &Path) -> String
101101

102102
let cwd = env::current_dir().unwrap();
103103
let mut lib = fs::canonicalize(&cwd.join(lib)).unwrap_or_else(|_| cwd.join(lib));
104-
lib.pop();
104+
lib.pop(); // strip filename
105105
let mut output = cwd.join(&config.out_filename);
106-
output.pop();
106+
output.pop(); // strip filename
107107
let output = fs::canonicalize(&output).unwrap_or(output);
108108
let relative = path_relative_from(&lib, &output).unwrap_or_else(||
109109
panic!("couldn't create relative path from {:?} to {:?}", output, lib));

src/librustc_driver/lib.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,15 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
838838
early_error(sopts.error_format, "no input filename given");
839839
}
840840
1 => panic!("make_input should have provided valid inputs"),
841-
_ => early_error(sopts.error_format, "multiple input filenames provided"),
841+
_ =>
842+
early_error(
843+
sopts.error_format,
844+
&format!(
845+
"multiple input filenames provided (first two filenames are `{}` and `{}`)",
846+
matches.free[0],
847+
matches.free[1],
848+
),
849+
)
842850
}
843851
}
844852

src/librustc_mir/interpret/place.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,8 @@ where
823823
let src = match self.try_read_immediate(src)? {
824824
Ok(src_val) => {
825825
// Yay, we got a value that we can write directly.
826+
// FIXME: Add a check to make sure that if `src` is indirect,
827+
// it does not overlap with `dest`.
826828
return self.write_immediate_no_validate(src_val, dest);
827829
}
828830
Err(mplace) => mplace,
@@ -836,7 +838,8 @@ where
836838
self.memory.copy(
837839
src_ptr, src_align,
838840
dest_ptr, dest_align,
839-
dest.layout.size, false
841+
dest.layout.size,
842+
/*nonoverlapping*/ true,
840843
)?;
841844

842845
Ok(())

src/librustc_mir/interpret/visitor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
125125
}
126126

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

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

137137
// Recursive actions, ready to be overloaded.
138138
/// Visit the given value, dispatching as appropriate to more specialized visitors.

src/librustdoc/clean/mod.rs

+71-4
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ pub enum ItemEnum {
517517
StaticItem(Static),
518518
ConstantItem(Constant),
519519
TraitItem(Trait),
520+
TraitAliasItem(TraitAlias),
520521
ImplItem(Impl),
521522
/// A method signature only. Used for required methods in traits (ie,
522523
/// non-default-methods).
@@ -554,6 +555,7 @@ impl ItemEnum {
554555
ItemEnum::TyMethodItem(ref i) => &i.generics,
555556
ItemEnum::MethodItem(ref i) => &i.generics,
556557
ItemEnum::ForeignFunctionItem(ref f) => &f.generics,
558+
ItemEnum::TraitAliasItem(ref ta) => &ta.generics,
557559
_ => return None,
558560
})
559561
}
@@ -603,6 +605,7 @@ impl Clean<Item> for doctree::Module {
603605
items.extend(self.impls.iter().flat_map(|x| x.clean(cx)));
604606
items.extend(self.macros.iter().map(|x| x.clean(cx)));
605607
items.extend(self.proc_macros.iter().map(|x| x.clean(cx)));
608+
items.extend(self.trait_aliases.iter().map(|x| x.clean(cx)));
606609

607610
// determine if we should display the inner contents or
608611
// the outer `mod` item for the source code.
@@ -1724,6 +1727,30 @@ impl FnDecl {
17241727
pub fn self_type(&self) -> Option<SelfTy> {
17251728
self.inputs.values.get(0).and_then(|v| v.to_self())
17261729
}
1730+
1731+
/// Returns the sugared return type for an async function.
1732+
///
1733+
/// For example, if the return type is `impl std::future::Future<Output = i32>`, this function
1734+
/// will return `i32`.
1735+
///
1736+
/// # Panics
1737+
///
1738+
/// This function will panic if the return type does not match the expected sugaring for async
1739+
/// functions.
1740+
pub fn sugared_async_return_type(&self) -> FunctionRetTy {
1741+
match &self.output {
1742+
FunctionRetTy::Return(Type::ImplTrait(bounds)) => {
1743+
match &bounds[0] {
1744+
GenericBound::TraitBound(PolyTrait { trait_, .. }, ..) => {
1745+
let bindings = trait_.bindings().unwrap();
1746+
FunctionRetTy::Return(bindings[0].ty.clone())
1747+
}
1748+
_ => panic!("unexpected desugaring of async function"),
1749+
}
1750+
}
1751+
_ => panic!("unexpected desugaring of async function"),
1752+
}
1753+
}
17271754
}
17281755

17291756
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
@@ -1885,13 +1912,38 @@ impl Clean<Item> for doctree::Trait {
18851912
items: self.items.clean(cx),
18861913
generics: self.generics.clean(cx),
18871914
bounds: self.bounds.clean(cx),
1888-
is_spotlight: is_spotlight,
1915+
is_spotlight,
18891916
is_auto: self.is_auto.clean(cx),
18901917
}),
18911918
}
18921919
}
18931920
}
18941921

1922+
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
1923+
pub struct TraitAlias {
1924+
pub generics: Generics,
1925+
pub bounds: Vec<GenericBound>,
1926+
}
1927+
1928+
impl Clean<Item> for doctree::TraitAlias {
1929+
fn clean(&self, cx: &DocContext) -> Item {
1930+
let attrs = self.attrs.clean(cx);
1931+
Item {
1932+
name: Some(self.name.clean(cx)),
1933+
attrs,
1934+
source: self.whence.clean(cx),
1935+
def_id: cx.tcx.hir().local_def_id(self.id),
1936+
visibility: self.vis.clean(cx),
1937+
stability: self.stab.clean(cx),
1938+
deprecation: self.depr.clean(cx),
1939+
inner: TraitAliasItem(TraitAlias {
1940+
generics: self.generics.clean(cx),
1941+
bounds: self.bounds.clean(cx),
1942+
}),
1943+
}
1944+
}
1945+
}
1946+
18951947
impl Clean<bool> for hir::IsAuto {
18961948
fn clean(&self, _: &DocContext) -> bool {
18971949
match *self {
@@ -2223,6 +2275,7 @@ pub enum TypeKind {
22232275
Macro,
22242276
Attr,
22252277
Derive,
2278+
TraitAlias,
22262279
}
22272280

22282281
pub trait GetDefId {
@@ -2282,6 +2335,21 @@ impl Type {
22822335
_ => None,
22832336
}
22842337
}
2338+
2339+
pub fn bindings(&self) -> Option<&[TypeBinding]> {
2340+
match *self {
2341+
ResolvedPath { ref path, .. } => {
2342+
path.segments.last().and_then(|seg| {
2343+
if let GenericArgs::AngleBracketed { ref bindings, .. } = seg.args {
2344+
Some(&**bindings)
2345+
} else {
2346+
None
2347+
}
2348+
})
2349+
}
2350+
_ => None
2351+
}
2352+
}
22852353
}
22862354

22872355
impl GetDefId for Type {
@@ -3819,10 +3887,9 @@ pub fn register_def(cx: &DocContext, def: Def) -> DefId {
38193887
MacroKind::Derive => (i, TypeKind::Derive),
38203888
MacroKind::ProcMacroStub => unreachable!(),
38213889
},
3890+
Def::TraitAlias(i) => (i, TypeKind::TraitAlias),
38223891
Def::SelfTy(Some(def_id), _) => (def_id, TypeKind::Trait),
3823-
Def::SelfTy(_, Some(impl_def_id)) => {
3824-
return impl_def_id
3825-
}
3892+
Def::SelfTy(_, Some(impl_def_id)) => return impl_def_id,
38263893
_ => return def.def_id()
38273894
};
38283895
if did.is_local() { return did }

src/librustdoc/doctree.rs

+29-15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub struct Module {
3838
pub foreigns: Vec<hir::ForeignMod>,
3939
pub macros: Vec<Macro>,
4040
pub proc_macros: Vec<ProcMacro>,
41+
pub trait_aliases: Vec<TraitAlias>,
4142
pub is_crate: bool,
4243
}
4344

@@ -53,21 +54,22 @@ impl Module {
5354
where_inner: syntax_pos::DUMMY_SP,
5455
attrs : hir::HirVec::new(),
5556
extern_crates: Vec::new(),
56-
imports : Vec::new(),
57-
structs : Vec::new(),
58-
unions : Vec::new(),
59-
enums : Vec::new(),
60-
fns : Vec::new(),
61-
mods : Vec::new(),
62-
typedefs : Vec::new(),
63-
existentials: Vec::new(),
64-
statics : Vec::new(),
65-
constants : Vec::new(),
66-
traits : Vec::new(),
67-
impls : Vec::new(),
68-
foreigns : Vec::new(),
69-
macros : Vec::new(),
70-
proc_macros: Vec::new(),
57+
imports : Vec::new(),
58+
structs : Vec::new(),
59+
unions : Vec::new(),
60+
enums : Vec::new(),
61+
fns : Vec::new(),
62+
mods : Vec::new(),
63+
typedefs : Vec::new(),
64+
existentials: Vec::new(),
65+
statics : Vec::new(),
66+
constants : Vec::new(),
67+
traits : Vec::new(),
68+
impls : Vec::new(),
69+
foreigns : Vec::new(),
70+
macros : Vec::new(),
71+
proc_macros: Vec::new(),
72+
trait_aliases: Vec::new(),
7173
is_crate : false,
7274
}
7375
}
@@ -208,6 +210,18 @@ pub struct Trait {
208210
pub depr: Option<attr::Deprecation>,
209211
}
210212

213+
pub struct TraitAlias {
214+
pub name: Name,
215+
pub generics: hir::Generics,
216+
pub bounds: hir::HirVec<hir::GenericBound>,
217+
pub attrs: hir::HirVec<ast::Attribute>,
218+
pub id: ast::NodeId,
219+
pub whence: Span,
220+
pub vis: hir::Visibility,
221+
pub stab: Option<attr::Stability>,
222+
pub depr: Option<attr::Deprecation>,
223+
}
224+
211225
#[derive(Debug)]
212226
pub struct Impl {
213227
pub unsafety: hir::Unsafety,

0 commit comments

Comments
 (0)