Skip to content

Commit f6fe99c

Browse files
committed
Auto merge of rust-lang#70734 - Dylan-DPC:rollup-xmncatq, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#70696 (Extend rust-lang#69020 test to include reversed operand order.) - rust-lang#70706 (Minor cleanup in rustdoc --check-theme) - rust-lang#70725 (Avoid `.unwrap()`s on `.span_to_snippet(...)`s) - rust-lang#70728 (Minor doc improvements on `AllocRef`) - rust-lang#70730 (Fix link in task::Wake docs) - rust-lang#70731 (Minor follow-up after renaming librustc(_middle)) Failed merges: r? @ghost
2 parents 34f7f55 + 04824f3 commit f6fe99c

31 files changed

+356
-220
lines changed

src/liballoc/task.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ use crate::sync::Arc;
1212
/// to the tasks that are executed on that executor.
1313
///
1414
/// This trait is a memory-safe and ergonomic alternative to constructing a
15-
/// [`RawWaker`]. It supports the common executor design in which the data
16-
/// used to wake up a task is stored in an [`Arc`]. Some executors (especially
15+
/// [`RawWaker`]. It supports the common executor design in which the data used
16+
/// to wake up a task is stored in an [`Arc`][arc]. Some executors (especially
1717
/// those for embedded systems) cannot use this API, which is why [`RawWaker`]
1818
/// exists as an alternative for those systems.
19+
///
20+
/// [arc]: ../../std/sync/struct.Arc.html
1921
#[unstable(feature = "wake_trait", issue = "69912")]
2022
pub trait Wake {
2123
/// Wake this task.

src/libcore/alloc/mod.rs

+22-19
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub enum ReallocPlacement {
119119
///
120120
/// Unlike [`GlobalAlloc`][], zero-sized allocations are allowed in `AllocRef`. If an underlying
121121
/// allocator does not support this (like jemalloc) or return a null pointer (such as
122-
/// `libc::malloc`), this case must be caught.
122+
/// `libc::malloc`), this must be caught by the implementation.
123123
///
124124
/// ### Currently allocated memory
125125
///
@@ -157,18 +157,20 @@ pub enum ReallocPlacement {
157157
/// # Safety
158158
///
159159
/// * Memory blocks returned from an allocator must point to valid memory and retain their validity
160-
/// until the instance and all of its clones are dropped, and
160+
/// until the instance and all of its clones are dropped,
161161
///
162162
/// * cloning or moving the allocator must not invalidate memory blocks returned from this
163-
/// allocator. A cloned allocator must behave like the same allocator.
163+
/// allocator. A cloned allocator must behave like the same allocator, and
164164
///
165165
/// * any pointer to a memory block which is [*currently allocated*] may be passed to any other
166166
/// method of the allocator.
167167
///
168168
/// [*currently allocated*]: #currently-allocated-memory
169169
#[unstable(feature = "allocator_api", issue = "32838")]
170170
pub unsafe trait AllocRef {
171-
/// On success, returns a memory block meeting the size and alignment guarantees of `layout`.
171+
/// Attempts to allocate a block of memory.
172+
///
173+
/// On success, returns a [`MemoryBlock`][] meeting the size and alignment guarantees of `layout`.
172174
///
173175
/// The returned block may have a larger size than specified by `layout.size()` and is
174176
/// initialized as specified by [`init`], all the way up to the returned size of the block.
@@ -190,26 +192,26 @@ pub unsafe trait AllocRef {
190192
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
191193
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocErr>;
192194

193-
/// Deallocates the memory denoted by `memory`.
195+
/// Deallocates the memory referenced by `ptr`.
194196
///
195197
/// # Safety
196198
///
197-
/// * `ptr` must be [*currently allocated*] via this allocator, and
198-
/// * `layout` must [*fit*] the `ptr`.
199+
/// * `ptr` must denote a block of memory [*currently allocated*] via this allocator, and
200+
/// * `layout` must [*fit*] that block of memory.
199201
///
200202
/// [*currently allocated*]: #currently-allocated-memory
201203
/// [*fit*]: #memory-fitting
202204
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout);
203205

204206
/// Attempts to extend the memory block.
205207
///
206-
/// Returns a new memory block containing a pointer and the actual size of the allocated
207-
/// block. The pointer is suitable for holding data described by a new layout with `layout`’s
208+
/// Returns a new [`MemoryBlock`][] containing a pointer and the actual size of the allocated
209+
/// memory. The pointer is suitable for holding data described by a new layout with `layout`’s
208210
/// alignment and a size given by `new_size`. To accomplish this, the allocator may extend the
209211
/// allocation referenced by `ptr` to fit the new layout. If the [`placement`] is
210212
/// [`InPlace`], the returned pointer is guaranteed to be the same as the passed `ptr`.
211213
///
212-
/// If `ReallocPlacement::MayMove` is used then ownership of the memory block referenced by `ptr`
214+
/// If [`MayMove`] is used then ownership of the memory block referenced by `ptr`
213215
/// is transferred to this allocator. The memory may or may not be freed, and should be
214216
/// considered unusable (unless of course it is transferred back to the caller again via the
215217
/// return value of this method).
@@ -227,17 +229,18 @@ pub unsafe trait AllocRef {
227229
/// the size of the `MemoryBlock` returned by the `grow` call.
228230
///
229231
/// [`InPlace`]: ReallocPlacement::InPlace
232+
/// [`MayMove`]: ReallocPlacement::MayMove
230233
/// [`placement`]: ReallocPlacement
231234
/// [`init`]: AllocInit
232235
///
233236
/// # Safety
234237
///
235-
/// * `ptr` must be [*currently allocated*] via this allocator,
236-
/// * `layout` must [*fit*] the `ptr`. (The `new_size` argument need not fit it.)
238+
/// * `ptr` must denote a block of memory [*currently allocated*] via this allocator,
239+
/// * `layout` must [*fit*] that block of memory (The `new_size` argument need not fit it.),
237240
// We can't require that `new_size` is strictly greater than `memory.size` because of ZSTs.
238241
// An alternative would be
239242
// * `new_size must be strictly greater than `memory.size` or both are zero
240-
/// * `new_size` must be greater than or equal to `layout.size()`
243+
/// * `new_size` must be greater than or equal to `layout.size()`, and
241244
/// * `new_size`, when rounded up to the nearest multiple of `layout.align()`, must not overflow
242245
/// (i.e., the rounded value must be less than or equal to `usize::MAX`).
243246
///
@@ -289,8 +292,8 @@ pub unsafe trait AllocRef {
289292

290293
/// Attempts to shrink the memory block.
291294
///
292-
/// Returns a new memory block containing a pointer and the actual size of the allocated
293-
/// block. The pointer is suitable for holding data described by a new layout with `layout`’s
295+
/// Returns a new [`MemoryBlock`][] containing a pointer and the actual size of the allocated
296+
/// memory. The pointer is suitable for holding data described by a new layout with `layout`’s
294297
/// alignment and a size given by `new_size`. To accomplish this, the allocator may shrink the
295298
/// allocation referenced by `ptr` to fit the new layout. If the [`placement`] is
296299
/// [`InPlace`], the returned pointer is guaranteed to be the same as the passed `ptr`.
@@ -310,20 +313,20 @@ pub unsafe trait AllocRef {
310313
///
311314
/// # Safety
312315
///
313-
/// * `ptr` must be [*currently allocated*] via this allocator,
314-
/// * `layout` must [*fit*] the `ptr`. (The `new_size` argument need not fit it.)
316+
/// * `ptr` must denote a block of memory [*currently allocated*] via this allocator,
317+
/// * `layout` must [*fit*] that block of memory (The `new_size` argument need not fit it.), and
315318
// We can't require that `new_size` is strictly smaller than `memory.size` because of ZSTs.
316319
// An alternative would be
317320
// * `new_size must be strictly smaller than `memory.size` or both are zero
318-
/// * `new_size` must be smaller than or equal to `layout.size()`
321+
/// * `new_size` must be smaller than or equal to `layout.size()`.
319322
///
320323
/// [*currently allocated*]: #currently-allocated-memory
321324
/// [*fit*]: #memory-fitting
322325
///
323326
/// # Errors
324327
///
325328
/// Returns `Err` if the new layout does not meet the allocator's size and alignment
326-
/// constraints of the allocator, or if growing otherwise fails.
329+
/// constraints of the allocator, or if shrinking otherwise fails.
327330
///
328331
/// Implementations are encouraged to return `Err` on memory exhaustion rather than panicking or
329332
/// aborting, but this is not a strict requirement. (Specifically: it is *legal* to implement

src/libcore/clone.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ pub struct AssertParamIsCopy<T: Copy + ?Sized> {
169169
/// Implementations of `Clone` for primitive types.
170170
///
171171
/// Implementations that cannot be described in Rust
172-
/// are implemented in `SelectionContext::copy_clone_conditions()` in librustc_middle.
172+
/// are implemented in `traits::SelectionContext::copy_clone_conditions()`
173+
/// in `rustc_trait_selection`.
173174
mod impls {
174175

175176
use super::Clone;

src/libcore/marker.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,8 @@ impl<T: ?Sized> Unpin for *mut T {}
759759
/// Implementations of `Copy` for primitive types.
760760
///
761761
/// Implementations that cannot be described in Rust
762-
/// are implemented in `SelectionContext::copy_clone_conditions()` in librustc_middle.
762+
/// are implemented in `traits::SelectionContext::copy_clone_conditions()`
763+
/// in `rustc_trait_selection`.
763764
mod copy_impls {
764765

765766
use super::Copy;

src/libcore/raw.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
//! They can be used as targets of transmutes in unsafe code for manipulating
77
//! the raw representations directly.
88
//!
9-
//! Their definition should always match the ABI defined in `rustc_target::abi`.
9+
//! Their definition should always match the ABI defined in
10+
//! `rustc_middle::ty::layout`.
1011
1112
/// The representation of a trait object like `&SomeTrait`.
1213
///

src/librustc_infer/infer/lexical_region_resolve/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! This module provides linkage between libgraphviz traits and
2-
//! `rustc_middle::middle::typeck::infer::region_constraints`, generating a
2+
//! `rustc_trait_selection::infer::region_constraints`, generating a
33
//! rendering of the graph represented by the list of `Constraint`
44
//! instances (which make up the edges of the graph), as well as the
55
//! origin for each constraint (which are attached to the labels on

src/librustc_mir/borrow_check/region_infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pub(crate) enum Cause {
202202
///
203203
/// For more information about this translation, see
204204
/// `InferCtxt::process_registered_region_obligations` and
205-
/// `InferCtxt::type_must_outlive` in `rustc_middle::infer::outlives`.
205+
/// `InferCtxt::type_must_outlive` in `rustc_infer::infer::InferCtxt`.
206206
#[derive(Clone, Debug)]
207207
pub struct TypeTest<'tcx> {
208208
/// The type `T` that must outlive the region.

src/librustc_mir/borrow_check/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10531053
/// regions which are extracted and stored as having occurred at
10541054
/// `locations`.
10551055
///
1056-
/// **Any `rustc_middle::infer` operations that might generate region
1056+
/// **Any `rustc_infer::infer` operations that might generate region
10571057
/// constraints should occur within this method so that those
10581058
/// constraints can be properly localized!**
10591059
fn fully_perform_op<R>(

src/librustc_parse/parser/stmt.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ impl<'a> Parser<'a> {
165165
// Rewind to before attempting to parse the type and continue parsing.
166166
let parser_snapshot_after_type = self.clone();
167167
mem::replace(self, parser_snapshot_before_type);
168-
169-
let snippet = self.span_to_snippet(pat.span).unwrap();
170-
err.span_label(pat.span, format!("while parsing the type for `{}`", snippet));
168+
if let Ok(snip) = self.span_to_snippet(pat.span) {
169+
err.span_label(pat.span, format!("while parsing the type for `{}`", snip));
170+
}
171171
(Some((parser_snapshot_after_type, colon_sp, err)), None)
172172
}
173173
}

src/librustc_passes/region.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub struct Context {
2727
/// of the innermost fn body. Each fn forms its own disjoint tree
2828
/// in the region hierarchy. These fn bodies are themselves
2929
/// arranged into a tree. See the "Modeling closures" section of
30-
/// the README in `infer::region_constraints` for more
31-
/// details.
30+
/// the README in `rustc_trait_selection::infer::region_constraints`
31+
/// for more details.
3232
root_id: Option<hir::ItemLocalId>,
3333

3434
/// The scope that contains any new variables declared, plus its depth in

src/librustc_passes/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
438438
// If the `-Z force-unstable-if-unmarked` flag is passed then we provide
439439
// a parent stability annotation which indicates that this is private
440440
// with the `rustc_private` feature. This is intended for use when
441-
// compiling librustc_middle crates themselves so we can leverage crates.io
441+
// compiling `librustc_*` crates themselves so we can leverage crates.io
442442
// while maintaining the invariant that all sysroot crates are unstable
443443
// by default and are unable to be used.
444444
if tcx.sess.opts.debugging_opts.force_unstable_if_unmarked {

src/librustc_session/filesearch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
143143
// FIXME: This is a quick hack to make the rustc binary able to locate
144144
// Rust libraries in Linux environments where libraries might be installed
145145
// to lib64/lib32. This would be more foolproof by basing the sysroot off
146-
// of the directory where librustc_middle is located, rather than where the rustc
147-
// binary is.
146+
// of the directory where `librustc_driver` is located, rather than
147+
// where the rustc binary is.
148148
// If --libdir is set during configuration to the value other than
149149
// "lib" (i.e., non-default), this value is used (see issue #16552).
150150

src/librustc_session/lint.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub enum BuiltinLintDiagnostics {
195195
}
196196

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

210-
/// A lint Id that can be passed to `rustc_session::lint::Lint::from_parser_lint_id`.
210+
/// A lint Id that can be passed to
211+
/// `rustc_lint::early::EarlyContextAndPass::check_id`.
211212
pub lint_id: LintId,
212213

213214
/// Customization of the `DiagnosticBuilder<'_>` for the lint.

src/librustc_trait_selection/traits/error_reporting/mod.rs

+24-33
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub trait InferCtxtExt<'tcx> {
6565
/// returns a span and `ArgKind` information that describes the
6666
/// arguments it expects. This can be supplied to
6767
/// `report_arg_count_mismatch`.
68-
fn get_fn_like_arguments(&self, node: Node<'_>) -> (Span, Vec<ArgKind>);
68+
fn get_fn_like_arguments(&self, node: Node<'_>) -> Option<(Span, Vec<ArgKind>)>;
6969

7070
/// Reports an error when the number of arguments needed by a
7171
/// trait match doesn't match the number that the expression
@@ -611,10 +611,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
611611
)
612612
} else {
613613
let (closure_span, found) = found_did
614-
.and_then(|did| self.tcx.hir().get_if_local(did))
615-
.map(|node| {
616-
let (found_span, found) = self.get_fn_like_arguments(node);
617-
(Some(found_span), found)
614+
.and_then(|did| {
615+
let node = self.tcx.hir().get_if_local(did)?;
616+
let (found_span, found) = self.get_fn_like_arguments(node)?;
617+
Some((Some(found_span), found))
618618
})
619619
.unwrap_or((found_span, found));
620620

@@ -672,43 +672,38 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
672672
/// returns a span and `ArgKind` information that describes the
673673
/// arguments it expects. This can be supplied to
674674
/// `report_arg_count_mismatch`.
675-
fn get_fn_like_arguments(&self, node: Node<'_>) -> (Span, Vec<ArgKind>) {
676-
match node {
675+
fn get_fn_like_arguments(&self, node: Node<'_>) -> Option<(Span, Vec<ArgKind>)> {
676+
let sm = self.tcx.sess.source_map();
677+
let hir = self.tcx.hir();
678+
Some(match node {
677679
Node::Expr(&hir::Expr {
678680
kind: hir::ExprKind::Closure(_, ref _decl, id, span, _),
679681
..
680682
}) => (
681-
self.tcx.sess.source_map().guess_head_span(span),
682-
self.tcx
683-
.hir()
684-
.body(id)
683+
sm.guess_head_span(span),
684+
hir.body(id)
685685
.params
686686
.iter()
687687
.map(|arg| {
688688
if let hir::Pat { kind: hir::PatKind::Tuple(ref args, _), span, .. } =
689689
*arg.pat
690690
{
691-
ArgKind::Tuple(
691+
Some(ArgKind::Tuple(
692692
Some(span),
693693
args.iter()
694694
.map(|pat| {
695-
let snippet = self
696-
.tcx
697-
.sess
698-
.source_map()
699-
.span_to_snippet(pat.span)
700-
.unwrap();
701-
(snippet, "_".to_owned())
695+
sm.span_to_snippet(pat.span)
696+
.ok()
697+
.map(|snippet| (snippet, "_".to_owned()))
702698
})
703-
.collect::<Vec<_>>(),
704-
)
699+
.collect::<Option<Vec<_>>>()?,
700+
))
705701
} else {
706-
let name =
707-
self.tcx.sess.source_map().span_to_snippet(arg.pat.span).unwrap();
708-
ArgKind::Arg(name, "_".to_owned())
702+
let name = sm.span_to_snippet(arg.pat.span).ok()?;
703+
Some(ArgKind::Arg(name, "_".to_owned()))
709704
}
710705
})
711-
.collect::<Vec<ArgKind>>(),
706+
.collect::<Option<Vec<ArgKind>>>()?,
712707
),
713708
Node::Item(&hir::Item { span, kind: hir::ItemKind::Fn(ref sig, ..), .. })
714709
| Node::ImplItem(&hir::ImplItem {
@@ -721,7 +716,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
721716
kind: hir::TraitItemKind::Fn(ref sig, _),
722717
..
723718
}) => (
724-
self.tcx.sess.source_map().guess_head_span(span),
719+
sm.guess_head_span(span),
725720
sig.decl
726721
.inputs
727722
.iter()
@@ -735,16 +730,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
735730
.collect::<Vec<ArgKind>>(),
736731
),
737732
Node::Ctor(ref variant_data) => {
738-
let span = variant_data
739-
.ctor_hir_id()
740-
.map(|hir_id| self.tcx.hir().span(hir_id))
741-
.unwrap_or(DUMMY_SP);
742-
let span = self.tcx.sess.source_map().guess_head_span(span);
743-
733+
let span = variant_data.ctor_hir_id().map(|id| hir.span(id)).unwrap_or(DUMMY_SP);
734+
let span = sm.guess_head_span(span);
744735
(span, vec![ArgKind::empty(); variant_data.fields().len()])
745736
}
746737
_ => panic!("non-FnLike node found: {:?}", node),
747-
}
738+
})
748739
}
749740

750741
/// Reports an error when the number of arguments needed by a

0 commit comments

Comments
 (0)