Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #70734

Merged
merged 17 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/liballoc/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ use crate::sync::Arc;
/// to the tasks that are executed on that executor.
///
/// This trait is a memory-safe and ergonomic alternative to constructing a
/// [`RawWaker`]. It supports the common executor design in which the data
/// used to wake up a task is stored in an [`Arc`]. Some executors (especially
/// [`RawWaker`]. It supports the common executor design in which the data used
/// to wake up a task is stored in an [`Arc`][arc]. Some executors (especially
/// those for embedded systems) cannot use this API, which is why [`RawWaker`]
/// exists as an alternative for those systems.
///
/// [arc]: ../../std/sync/struct.Arc.html
#[unstable(feature = "wake_trait", issue = "69912")]
pub trait Wake {
/// Wake this task.
Expand Down
41 changes: 22 additions & 19 deletions src/libcore/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub enum ReallocPlacement {
///
/// Unlike [`GlobalAlloc`][], zero-sized allocations are allowed in `AllocRef`. If an underlying
/// allocator does not support this (like jemalloc) or return a null pointer (such as
/// `libc::malloc`), this case must be caught.
/// `libc::malloc`), this must be caught by the implementation.
///
/// ### Currently allocated memory
///
Expand Down Expand Up @@ -157,18 +157,20 @@ pub enum ReallocPlacement {
/// # Safety
///
/// * Memory blocks returned from an allocator must point to valid memory and retain their validity
/// until the instance and all of its clones are dropped, and
/// until the instance and all of its clones are dropped,
///
/// * cloning or moving the allocator must not invalidate memory blocks returned from this
/// allocator. A cloned allocator must behave like the same allocator.
/// allocator. A cloned allocator must behave like the same allocator, and
///
/// * any pointer to a memory block which is [*currently allocated*] may be passed to any other
/// method of the allocator.
///
/// [*currently allocated*]: #currently-allocated-memory
#[unstable(feature = "allocator_api", issue = "32838")]
pub unsafe trait AllocRef {
/// On success, returns a memory block meeting the size and alignment guarantees of `layout`.
/// Attempts to allocate a block of memory.
///
/// On success, returns a [`MemoryBlock`][] meeting the size and alignment guarantees of `layout`.
///
/// The returned block may have a larger size than specified by `layout.size()` and is
/// initialized as specified by [`init`], all the way up to the returned size of the block.
Expand All @@ -190,26 +192,26 @@ pub unsafe trait AllocRef {
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocErr>;

/// Deallocates the memory denoted by `memory`.
/// Deallocates the memory referenced by `ptr`.
///
/// # Safety
///
/// * `ptr` must be [*currently allocated*] via this allocator, and
/// * `layout` must [*fit*] the `ptr`.
/// * `ptr` must denote a block of memory [*currently allocated*] via this allocator, and
/// * `layout` must [*fit*] that block of memory.
///
/// [*currently allocated*]: #currently-allocated-memory
/// [*fit*]: #memory-fitting
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout);

/// Attempts to extend the memory block.
///
/// Returns a new memory block containing a pointer and the actual size of the allocated
/// block. The pointer is suitable for holding data described by a new layout with `layout`’s
/// Returns a new [`MemoryBlock`][] containing a pointer and the actual size of the allocated
/// memory. The pointer is suitable for holding data described by a new layout with `layout`’s
/// alignment and a size given by `new_size`. To accomplish this, the allocator may extend the
/// allocation referenced by `ptr` to fit the new layout. If the [`placement`] is
/// [`InPlace`], the returned pointer is guaranteed to be the same as the passed `ptr`.
///
/// If `ReallocPlacement::MayMove` is used then ownership of the memory block referenced by `ptr`
/// If [`MayMove`] is used then ownership of the memory block referenced by `ptr`
/// is transferred to this allocator. The memory may or may not be freed, and should be
/// considered unusable (unless of course it is transferred back to the caller again via the
/// return value of this method).
Expand All @@ -227,17 +229,18 @@ pub unsafe trait AllocRef {
/// the size of the `MemoryBlock` returned by the `grow` call.
///
/// [`InPlace`]: ReallocPlacement::InPlace
/// [`MayMove`]: ReallocPlacement::MayMove
/// [`placement`]: ReallocPlacement
/// [`init`]: AllocInit
///
/// # Safety
///
/// * `ptr` must be [*currently allocated*] via this allocator,
/// * `layout` must [*fit*] the `ptr`. (The `new_size` argument need not fit it.)
/// * `ptr` must denote a block of memory [*currently allocated*] via this allocator,
/// * `layout` must [*fit*] that block of memory (The `new_size` argument need not fit it.),
// We can't require that `new_size` is strictly greater than `memory.size` because of ZSTs.
// An alternative would be
// * `new_size must be strictly greater than `memory.size` or both are zero
/// * `new_size` must be greater than or equal to `layout.size()`
/// * `new_size` must be greater than or equal to `layout.size()`, and
/// * `new_size`, when rounded up to the nearest multiple of `layout.align()`, must not overflow
/// (i.e., the rounded value must be less than or equal to `usize::MAX`).
///
Expand Down Expand Up @@ -289,8 +292,8 @@ pub unsafe trait AllocRef {

/// Attempts to shrink the memory block.
///
/// Returns a new memory block containing a pointer and the actual size of the allocated
/// block. The pointer is suitable for holding data described by a new layout with `layout`’s
/// Returns a new [`MemoryBlock`][] containing a pointer and the actual size of the allocated
/// memory. The pointer is suitable for holding data described by a new layout with `layout`’s
/// alignment and a size given by `new_size`. To accomplish this, the allocator may shrink the
/// allocation referenced by `ptr` to fit the new layout. If the [`placement`] is
/// [`InPlace`], the returned pointer is guaranteed to be the same as the passed `ptr`.
Expand All @@ -310,20 +313,20 @@ pub unsafe trait AllocRef {
///
/// # Safety
///
/// * `ptr` must be [*currently allocated*] via this allocator,
/// * `layout` must [*fit*] the `ptr`. (The `new_size` argument need not fit it.)
/// * `ptr` must denote a block of memory [*currently allocated*] via this allocator,
/// * `layout` must [*fit*] that block of memory (The `new_size` argument need not fit it.), and
// We can't require that `new_size` is strictly smaller than `memory.size` because of ZSTs.
// An alternative would be
// * `new_size must be strictly smaller than `memory.size` or both are zero
/// * `new_size` must be smaller than or equal to `layout.size()`
/// * `new_size` must be smaller than or equal to `layout.size()`.
///
/// [*currently allocated*]: #currently-allocated-memory
/// [*fit*]: #memory-fitting
///
/// # Errors
///
/// Returns `Err` if the new layout does not meet the allocator's size and alignment
/// constraints of the allocator, or if growing otherwise fails.
/// constraints of the allocator, or if shrinking otherwise fails.
///
/// Implementations are encouraged to return `Err` on memory exhaustion rather than panicking or
/// aborting, but this is not a strict requirement. (Specifically: it is *legal* to implement
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ pub struct AssertParamIsCopy<T: Copy + ?Sized> {
/// Implementations of `Clone` for primitive types.
///
/// Implementations that cannot be described in Rust
/// are implemented in `SelectionContext::copy_clone_conditions()` in librustc_middle.
/// are implemented in `traits::SelectionContext::copy_clone_conditions()`
/// in `rustc_trait_selection`.
mod impls {

use super::Clone;
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,8 @@ impl<T: ?Sized> Unpin for *mut T {}
/// Implementations of `Copy` for primitive types.
///
/// Implementations that cannot be described in Rust
/// are implemented in `SelectionContext::copy_clone_conditions()` in librustc_middle.
/// are implemented in `traits::SelectionContext::copy_clone_conditions()`
/// in `rustc_trait_selection`.
mod copy_impls {

use super::Copy;
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
//! They can be used as targets of transmutes in unsafe code for manipulating
//! the raw representations directly.
//!
//! Their definition should always match the ABI defined in `rustc_target::abi`.
//! Their definition should always match the ABI defined in
//! `rustc_middle::ty::layout`.

/// The representation of a trait object like `&SomeTrait`.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This module provides linkage between libgraphviz traits and
//! `rustc_middle::middle::typeck::infer::region_constraints`, generating a
//! `rustc_trait_selection::infer::region_constraints`, generating a
//! rendering of the graph represented by the list of `Constraint`
//! instances (which make up the edges of the graph), as well as the
//! origin for each constraint (which are attached to the labels on
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub(crate) enum Cause {
///
/// For more information about this translation, see
/// `InferCtxt::process_registered_region_obligations` and
/// `InferCtxt::type_must_outlive` in `rustc_middle::infer::outlives`.
/// `InferCtxt::type_must_outlive` in `rustc_infer::infer::InferCtxt`.
#[derive(Clone, Debug)]
pub struct TypeTest<'tcx> {
/// The type `T` that must outlive the region.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
/// regions which are extracted and stored as having occurred at
/// `locations`.
///
/// **Any `rustc_middle::infer` operations that might generate region
/// **Any `rustc_infer::infer` operations that might generate region
/// constraints should occur within this method so that those
/// constraints can be properly localized!**
fn fully_perform_op<R>(
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_parse/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ impl<'a> Parser<'a> {
// Rewind to before attempting to parse the type and continue parsing.
let parser_snapshot_after_type = self.clone();
mem::replace(self, parser_snapshot_before_type);

let snippet = self.span_to_snippet(pat.span).unwrap();
err.span_label(pat.span, format!("while parsing the type for `{}`", snippet));
if let Ok(snip) = self.span_to_snippet(pat.span) {
err.span_label(pat.span, format!("while parsing the type for `{}`", snip));
}
(Some((parser_snapshot_after_type, colon_sp, err)), None)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ pub struct Context {
/// of the innermost fn body. Each fn forms its own disjoint tree
/// in the region hierarchy. These fn bodies are themselves
/// arranged into a tree. See the "Modeling closures" section of
/// the README in `infer::region_constraints` for more
/// details.
/// the README in `rustc_trait_selection::infer::region_constraints`
/// for more details.
root_id: Option<hir::ItemLocalId>,

/// The scope that contains any new variables declared, plus its depth in
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
// If the `-Z force-unstable-if-unmarked` flag is passed then we provide
// a parent stability annotation which indicates that this is private
// with the `rustc_private` feature. This is intended for use when
// compiling librustc_middle crates themselves so we can leverage crates.io
// compiling `librustc_*` crates themselves so we can leverage crates.io
// while maintaining the invariant that all sysroot crates are unstable
// by default and are unable to be used.
if tcx.sess.opts.debugging_opts.force_unstable_if_unmarked {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_session/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
// FIXME: This is a quick hack to make the rustc binary able to locate
// Rust libraries in Linux environments where libraries might be installed
// to lib64/lib32. This would be more foolproof by basing the sysroot off
// of the directory where librustc_middle is located, rather than where the rustc
// binary is.
// of the directory where `librustc_driver` is located, rather than
// where the rustc binary is.
// If --libdir is set during configuration to the value other than
// "lib" (i.e., non-default), this value is used (see issue #16552).

Expand Down
5 changes: 3 additions & 2 deletions src/librustc_session/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub enum BuiltinLintDiagnostics {
}

/// Lints that are buffered up early on in the `Session` before the
/// `LintLevels` is calculated. These are later passed to `librustc_middle`.
/// `LintLevels` is calculated.
#[derive(PartialEq)]
pub struct BufferedEarlyLint {
/// The span of code that we are linting on.
Expand All @@ -207,7 +207,8 @@ pub struct BufferedEarlyLint {
/// The `NodeId` of the AST node that generated the lint.
pub node_id: NodeId,

/// A lint Id that can be passed to `rustc_session::lint::Lint::from_parser_lint_id`.
/// A lint Id that can be passed to
/// `rustc_lint::early::EarlyContextAndPass::check_id`.
pub lint_id: LintId,

/// Customization of the `DiagnosticBuilder<'_>` for the lint.
Expand Down
57 changes: 24 additions & 33 deletions src/librustc_trait_selection/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub trait InferCtxtExt<'tcx> {
/// returns a span and `ArgKind` information that describes the
/// arguments it expects. This can be supplied to
/// `report_arg_count_mismatch`.
fn get_fn_like_arguments(&self, node: Node<'_>) -> (Span, Vec<ArgKind>);
fn get_fn_like_arguments(&self, node: Node<'_>) -> Option<(Span, Vec<ArgKind>)>;

/// Reports an error when the number of arguments needed by a
/// trait match doesn't match the number that the expression
Expand Down Expand Up @@ -611,10 +611,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
)
} else {
let (closure_span, found) = found_did
.and_then(|did| self.tcx.hir().get_if_local(did))
.map(|node| {
let (found_span, found) = self.get_fn_like_arguments(node);
(Some(found_span), found)
.and_then(|did| {
let node = self.tcx.hir().get_if_local(did)?;
let (found_span, found) = self.get_fn_like_arguments(node)?;
Some((Some(found_span), found))
})
.unwrap_or((found_span, found));

Expand Down Expand Up @@ -672,43 +672,38 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
/// returns a span and `ArgKind` information that describes the
/// arguments it expects. This can be supplied to
/// `report_arg_count_mismatch`.
fn get_fn_like_arguments(&self, node: Node<'_>) -> (Span, Vec<ArgKind>) {
match node {
fn get_fn_like_arguments(&self, node: Node<'_>) -> Option<(Span, Vec<ArgKind>)> {
let sm = self.tcx.sess.source_map();
let hir = self.tcx.hir();
Some(match node {
Node::Expr(&hir::Expr {
kind: hir::ExprKind::Closure(_, ref _decl, id, span, _),
..
}) => (
self.tcx.sess.source_map().guess_head_span(span),
self.tcx
.hir()
.body(id)
sm.guess_head_span(span),
hir.body(id)
.params
.iter()
.map(|arg| {
if let hir::Pat { kind: hir::PatKind::Tuple(ref args, _), span, .. } =
*arg.pat
{
ArgKind::Tuple(
Some(ArgKind::Tuple(
Some(span),
args.iter()
.map(|pat| {
let snippet = self
.tcx
.sess
.source_map()
.span_to_snippet(pat.span)
.unwrap();
(snippet, "_".to_owned())
sm.span_to_snippet(pat.span)
.ok()
.map(|snippet| (snippet, "_".to_owned()))
})
.collect::<Vec<_>>(),
)
.collect::<Option<Vec<_>>>()?,
))
} else {
let name =
self.tcx.sess.source_map().span_to_snippet(arg.pat.span).unwrap();
ArgKind::Arg(name, "_".to_owned())
let name = sm.span_to_snippet(arg.pat.span).ok()?;
Some(ArgKind::Arg(name, "_".to_owned()))
}
})
.collect::<Vec<ArgKind>>(),
.collect::<Option<Vec<ArgKind>>>()?,
),
Node::Item(&hir::Item { span, kind: hir::ItemKind::Fn(ref sig, ..), .. })
| Node::ImplItem(&hir::ImplItem {
Expand All @@ -721,7 +716,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
kind: hir::TraitItemKind::Fn(ref sig, _),
..
}) => (
self.tcx.sess.source_map().guess_head_span(span),
sm.guess_head_span(span),
sig.decl
.inputs
.iter()
Expand All @@ -735,16 +730,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
.collect::<Vec<ArgKind>>(),
),
Node::Ctor(ref variant_data) => {
let span = variant_data
.ctor_hir_id()
.map(|hir_id| self.tcx.hir().span(hir_id))
.unwrap_or(DUMMY_SP);
let span = self.tcx.sess.source_map().guess_head_span(span);

let span = variant_data.ctor_hir_id().map(|id| hir.span(id)).unwrap_or(DUMMY_SP);
let span = sm.guess_head_span(span);
(span, vec![ArgKind::empty(); variant_data.fields().len()])
}
_ => panic!("non-FnLike node found: {:?}", node),
}
})
}

/// Reports an error when the number of arguments needed by a
Expand Down
Loading