Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f6fe99c

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

File tree

31 files changed

+356
-220
lines changed

31 files changed

+356
-220
lines changed
 

‎src/liballoc/task.rs

Lines changed: 4 additions & 2 deletions
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

Lines changed: 22 additions & 19 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 24 additions & 33 deletions
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

‎src/librustc_trait_selection/traits/error_reporting/suggestions.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -732,12 +732,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
732732
true
733733
};
734734

735+
let sm = self.tcx.sess.source_map();
735736
let (snippet, last_ty) =
736737
if let (true, hir::TyKind::TraitObject(..), Ok(snippet), true, Some(last_ty)) = (
737738
// Verify that we're dealing with a return `dyn Trait`
738739
ret_ty.span.overlaps(span),
739740
&ret_ty.kind,
740-
self.tcx.sess.source_map().span_to_snippet(ret_ty.span),
741+
sm.span_to_snippet(ret_ty.span),
741742
// If any of the return types does not conform to the trait, then we can't
742743
// suggest `impl Trait` nor trait objects, it is a type mismatch error.
743744
all_returns_conform_to_trait,
@@ -775,26 +776,23 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
775776
if is_object_safe {
776777
// Suggest `-> Box<dyn Trait>` and `Box::new(returned_value)`.
777778
// Get all the return values and collect their span and suggestion.
778-
let mut suggestions = visitor
779+
if let Some(mut suggestions) = visitor
779780
.returns
780781
.iter()
781782
.map(|expr| {
782-
(
783-
expr.span,
784-
format!(
785-
"Box::new({})",
786-
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap()
787-
),
788-
)
783+
let snip = sm.span_to_snippet(expr.span).ok()?;
784+
Some((expr.span, format!("Box::new({})", snip)))
789785
})
790-
.collect::<Vec<_>>();
791-
// Add the suggestion for the return type.
792-
suggestions.push((ret_ty.span, format!("Box<dyn {}>", trait_obj)));
793-
err.multipart_suggestion(
794-
"return a boxed trait object instead",
795-
suggestions,
796-
Applicability::MaybeIncorrect,
797-
);
786+
.collect::<Option<Vec<_>>>()
787+
{
788+
// Add the suggestion for the return type.
789+
suggestions.push((ret_ty.span, format!("Box<dyn {}>", trait_obj)));
790+
err.multipart_suggestion(
791+
"return a boxed trait object instead",
792+
suggestions,
793+
Applicability::MaybeIncorrect,
794+
);
795+
}
798796
} else {
799797
// This is currently not possible to trigger because E0038 takes precedence, but
800798
// leave it in for completeness in case anything changes in an earlier stage.

‎src/librustc_trait_selection/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
10101010
// type.
10111011
//
10121012
// NOTE: This should be kept in sync with the similar code in
1013-
// `rustc_middle::ty::instance::resolve_associated_item()`.
1013+
// `rustc_ty::instance::resolve_associated_item()`.
10141014
let node_item =
10151015
assoc_ty_def(selcx, impl_data.impl_def_id, obligation.predicate.item_def_id)
10161016
.map_err(|ErrorReported| ())?;

‎src/librustc_traits/implied_outlives_bounds.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Provider for the `implied_outlives_bounds` query.
2-
//! Do not call this query directory. See [`rustc_middle::traits::query::implied_outlives_bounds`].
2+
//! Do not call this query directory. See
3+
//! [`rustc_trait_selection::traits::query::type_op::implied_outlives_bounds`].
34
45
use rustc_hir as hir;
56
use rustc_infer::infer::canonical::{self, Canonical};

‎src/librustc_ty/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn resolve_associated_item<'tcx>(
118118
// Since this is a trait item, we need to see if the item is either a trait default item
119119
// or a specialization because we can't resolve those unless we can `Reveal::All`.
120120
// NOTE: This should be kept in sync with the similar code in
121-
// `rustc_middle::traits::project::assemble_candidates_from_impls()`.
121+
// `rustc_trait_selection::traits::project::assemble_candidates_from_impls()`.
122122
let eligible = if leaf_def.is_final() {
123123
// Non-specializable items are always projectable.
124124
true

‎src/librustc_typeck/check/closure.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,18 +432,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
432432
body: &hir::Body<'_>,
433433
expected_sig: ExpectedSig<'tcx>,
434434
) -> ClosureSignatures<'tcx> {
435-
let expr_map_node = self.tcx.hir().get_if_local(expr_def_id).unwrap();
435+
let hir = self.tcx.hir();
436+
let expr_map_node = hir.get_if_local(expr_def_id).unwrap();
436437
let expected_args: Vec<_> = expected_sig
437438
.sig
438439
.inputs()
439440
.iter()
440441
.map(|ty| ArgKind::from_expected_ty(ty, None))
441442
.collect();
442-
let (closure_span, found_args) = self.get_fn_like_arguments(expr_map_node);
443-
let expected_span = expected_sig.cause_span.unwrap_or(closure_span);
443+
let (closure_span, found_args) = match self.get_fn_like_arguments(expr_map_node) {
444+
Some((sp, args)) => (Some(sp), args),
445+
None => (None, Vec::new()),
446+
};
447+
let expected_span =
448+
expected_sig.cause_span.unwrap_or_else(|| hir.span_if_local(expr_def_id).unwrap());
444449
self.report_arg_count_mismatch(
445450
expected_span,
446-
Some(closure_span),
451+
closure_span,
447452
expected_args,
448453
found_args,
449454
true,

‎src/librustc_typeck/check/op.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
481481
}
482482

483483
/// If one of the types is an uncalled function and calling it would yield the other type,
484-
/// suggest calling the function. Returns whether a suggestion was given.
484+
/// suggest calling the function. Returns `true` if suggestion would apply (even if not given).
485485
fn add_type_neq_err_label(
486486
&self,
487487
err: &mut rustc_errors::DiagnosticBuilder<'_>,
@@ -514,24 +514,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
514514
.lookup_op_method(fn_sig.output(), &[other_ty], Op::Binary(op, is_assign))
515515
.is_ok()
516516
{
517-
let (variable_snippet, applicability) = if !fn_sig.inputs().is_empty() {
518-
(
519-
format!("{}( /* arguments */ )", source_map.span_to_snippet(span).unwrap()),
520-
Applicability::HasPlaceholders,
521-
)
522-
} else {
523-
(
524-
format!("{}()", source_map.span_to_snippet(span).unwrap()),
525-
Applicability::MaybeIncorrect,
526-
)
527-
};
517+
if let Ok(snippet) = source_map.span_to_snippet(span) {
518+
let (variable_snippet, applicability) = if !fn_sig.inputs().is_empty() {
519+
(format!("{}( /* arguments */ )", snippet), Applicability::HasPlaceholders)
520+
} else {
521+
(format!("{}()", snippet), Applicability::MaybeIncorrect)
522+
};
528523

529-
err.span_suggestion(
530-
span,
531-
"you might have forgotten to call this function",
532-
variable_snippet,
533-
applicability,
534-
);
524+
err.span_suggestion(
525+
span,
526+
"you might have forgotten to call this function",
527+
variable_snippet,
528+
applicability,
529+
);
530+
}
535531
return true;
536532
}
537533
}

‎src/librustdoc/theme.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ use rustc_errors::Handler;
88
#[cfg(test)]
99
mod tests;
1010

11-
macro_rules! try_something {
12-
($e:expr, $diag:expr, $out:expr) => {{
13-
match $e {
14-
Ok(c) => c,
15-
Err(e) => {
16-
$diag.struct_err(&e.to_string()).emit();
17-
return $out;
18-
}
19-
}
20-
}};
21-
}
22-
2311
#[derive(Debug, Clone, Eq)]
2412
pub struct CssPath {
2513
pub name: String,
@@ -265,7 +253,13 @@ pub fn test_theme_against<P: AsRef<Path>>(
265253
against: &CssPath,
266254
diag: &Handler,
267255
) -> (bool, Vec<String>) {
268-
let data = try_something!(fs::read(f), diag, (false, vec![]));
256+
let data = match fs::read(f) {
257+
Ok(c) => c,
258+
Err(e) => {
259+
diag.struct_err(&e.to_string()).emit();
260+
return (false, vec![]);
261+
}
262+
};
269263

270264
let paths = load_css_paths(&data);
271265
let mut ret = vec![];

‎src/libstd/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,10 @@ pub fn rust_oom(layout: Layout) -> ! {
289289
pub mod __default_lib_allocator {
290290
use super::{GlobalAlloc, Layout, System};
291291
// These magic symbol names are used as a fallback for implementing the
292-
// `__rust_alloc` etc symbols (see `src/liballoc/alloc.rs) when there is
292+
// `__rust_alloc` etc symbols (see `src/liballoc/alloc.rs`) when there is
293293
// no `#[global_allocator]` attribute.
294294

295-
// for symbol names src/librustc_middle/middle/allocator.rs
295+
// for symbol names src/librustc_ast/expand/allocator.rs
296296
// for signatures src/librustc_allocator/lib.rs
297297

298298
// linkage directives are provided as part of the current compiler allocator
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error: this arithmetic operation will overflow
2+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
3+
|
4+
LL | const NEG: i32 = -i32::MIN + T::NEG;
5+
| ^^^^^^^^^ attempt to negate with overflow
6+
|
7+
= note: `#[deny(arithmetic_overflow)]` on by default
8+
9+
error: this arithmetic operation will overflow
10+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
11+
|
12+
LL | const NEG_REV: i32 = T::NEG + (-i32::MIN);
13+
| ^^^^^^^^^^^ attempt to negate with overflow
14+
15+
error: this arithmetic operation will overflow
16+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
17+
|
18+
LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
19+
| ^^^^^^^^^^^^ attempt to add with overflow
20+
21+
error: this arithmetic operation will overflow
22+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
23+
|
24+
LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1);
25+
| ^^^^^^^^^^^^ attempt to add with overflow
26+
27+
error: this operation will panic at runtime
28+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
29+
|
30+
LL | const DIV: i32 = (1/0) + T::DIV;
31+
| ^^^^^ attempt to divide by zero
32+
|
33+
= note: `#[deny(unconditional_panic)]` on by default
34+
35+
error: this operation will panic at runtime
36+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
37+
|
38+
LL | const DIV_REV: i32 = T::DIV + (1/0);
39+
| ^^^^^ attempt to divide by zero
40+
41+
error: this operation will panic at runtime
42+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
43+
|
44+
LL | const OOB: i32 = [1][1] + T::OOB;
45+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
46+
47+
error: this operation will panic at runtime
48+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
49+
|
50+
LL | const OOB_REV: i32 = T::OOB + [1][1];
51+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
52+
53+
error: aborting due to 8 previous errors
54+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error: this arithmetic operation will overflow
2+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
3+
|
4+
LL | const NEG: i32 = -i32::MIN + T::NEG;
5+
| ^^^^^^^^^ attempt to negate with overflow
6+
|
7+
= note: `#[deny(arithmetic_overflow)]` on by default
8+
9+
error: this arithmetic operation will overflow
10+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
11+
|
12+
LL | const NEG_REV: i32 = T::NEG + (-i32::MIN);
13+
| ^^^^^^^^^^^ attempt to negate with overflow
14+
15+
error: this arithmetic operation will overflow
16+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
17+
|
18+
LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
19+
| ^^^^^^^^^^^^ attempt to add with overflow
20+
21+
error: this arithmetic operation will overflow
22+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
23+
|
24+
LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1);
25+
| ^^^^^^^^^^^^ attempt to add with overflow
26+
27+
error: this operation will panic at runtime
28+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
29+
|
30+
LL | const DIV: i32 = (1/0) + T::DIV;
31+
| ^^^^^ attempt to divide by zero
32+
|
33+
= note: `#[deny(unconditional_panic)]` on by default
34+
35+
error: this operation will panic at runtime
36+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
37+
|
38+
LL | const DIV_REV: i32 = T::DIV + (1/0);
39+
| ^^^^^ attempt to divide by zero
40+
41+
error: this operation will panic at runtime
42+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
43+
|
44+
LL | const OOB: i32 = [1][1] + T::OOB;
45+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
46+
47+
error: this operation will panic at runtime
48+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
49+
|
50+
LL | const OOB_REV: i32 = T::OOB + [1][1];
51+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
52+
53+
error: aborting due to 8 previous errors
54+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error: this arithmetic operation will overflow
2+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:29:22
3+
|
4+
LL | const NEG: i32 = -i32::MIN + T::NEG;
5+
| ^^^^^^^^^ attempt to negate with overflow
6+
|
7+
= note: `#[deny(arithmetic_overflow)]` on by default
8+
9+
error: this arithmetic operation will overflow
10+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:31:35
11+
|
12+
LL | const NEG_REV: i32 = T::NEG + (-i32::MIN);
13+
| ^^^^^^^^^^^ attempt to negate with overflow
14+
15+
error: this arithmetic operation will overflow
16+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:34:22
17+
|
18+
LL | const ADD: i32 = (i32::MAX+1) + T::ADD;
19+
| ^^^^^^^^^^^^ attempt to add with overflow
20+
21+
error: this arithmetic operation will overflow
22+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:36:36
23+
|
24+
LL | const ADD_REV: i32 = T::ADD + (i32::MAX+1);
25+
| ^^^^^^^^^^^^ attempt to add with overflow
26+
27+
error: this operation will panic at runtime
28+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:39:22
29+
|
30+
LL | const DIV: i32 = (1/0) + T::DIV;
31+
| ^^^^^ attempt to divide by zero
32+
|
33+
= note: `#[deny(unconditional_panic)]` on by default
34+
35+
error: this operation will panic at runtime
36+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:41:35
37+
|
38+
LL | const DIV_REV: i32 = T::DIV + (1/0);
39+
| ^^^^^ attempt to divide by zero
40+
41+
error: this operation will panic at runtime
42+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:44:22
43+
|
44+
LL | const OOB: i32 = [1][1] + T::OOB;
45+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
46+
47+
error: this operation will panic at runtime
48+
--> $DIR/issue-69020-assoc-const-arith-overflow.rs:46:35
49+
|
50+
LL | const OOB_REV: i32 = T::OOB + [1][1];
51+
| ^^^^^^ index out of bounds: the len is 1 but the index is 1
52+
53+
error: aborting due to 8 previous errors
54+

‎src/test/ui/consts/issue-69020.rs renamed to ‎src/test/ui/associated-const/issue-69020-assoc-const-arith-overflow.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,40 @@ use std::i32;
99

1010
pub trait Foo {
1111
const NEG: i32;
12+
const NEG_REV: i32;
13+
1214
const ADD: i32;
15+
const ADD_REV: i32;
16+
1317
const DIV: i32;
18+
const DIV_REV: i32;
19+
1420
const OOB: i32;
21+
const OOB_REV: i32;
1522
}
1623

17-
// These constants cannot be evaluated already (they depend on `T::N`), so
18-
// they can just be linted like normal run-time code. But codegen works
19-
// a bit different in const context, so this test makes sure that we still catch overflow.
24+
// These constants cannot be evaluated already (they depend on `T::N`), so they can just be linted
25+
// like normal run-time code. But codegen works a bit different in const context, so this test
26+
// makes sure that we still catch overflow. Also make sure we emit the same lints if we reverse the
27+
// operands (so that the generic operand comes first).
2028
impl<T: Foo> Foo for Vec<T> {
2129
const NEG: i32 = -i32::MIN + T::NEG;
2230
//~^ ERROR arithmetic operation will overflow
31+
const NEG_REV: i32 = T::NEG + (-i32::MIN);
32+
//~^ ERROR arithmetic operation will overflow
33+
2334
const ADD: i32 = (i32::MAX+1) + T::ADD;
2435
//~^ ERROR arithmetic operation will overflow
36+
const ADD_REV: i32 = T::ADD + (i32::MAX+1);
37+
//~^ ERROR arithmetic operation will overflow
38+
2539
const DIV: i32 = (1/0) + T::DIV;
2640
//~^ ERROR operation will panic
41+
const DIV_REV: i32 = T::DIV + (1/0);
42+
//~^ ERROR operation will panic
43+
2744
const OOB: i32 = [1][1] + T::OOB;
2845
//~^ ERROR operation will panic
46+
const OOB_REV: i32 = T::OOB + [1][1];
47+
//~^ ERROR operation will panic
2948
}

‎src/test/ui/consts/issue-69020.noopt.stderr

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎src/test/ui/consts/issue-69020.opt.stderr

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎src/test/ui/consts/issue-69020.opt_with_overflow_checks.stderr

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn a() -> i32 {
2+
3
3+
}
4+
5+
pub fn main() {
6+
assert_eq!(a, 0);
7+
//~^ ERROR binary operation `==` cannot
8+
//~| ERROR mismatched types
9+
//~| ERROR doesn't implement
10+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
error[E0369]: binary operation `==` cannot be applied to type `fn() -> i32 {a}`
2+
--> $DIR/issue-70724-add_type_neq_err_label-unwrap.rs:6:5
3+
|
4+
LL | assert_eq!(a, 0);
5+
| ^^^^^^^^^^^^^^^^^
6+
| |
7+
| fn() -> i32 {a}
8+
| {integer}
9+
| help: you might have forgotten to call this function: `*left_val()`
10+
|
11+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
12+
13+
error[E0308]: mismatched types
14+
--> $DIR/issue-70724-add_type_neq_err_label-unwrap.rs:6:5
15+
|
16+
LL | assert_eq!(a, 0);
17+
| ^^^^^^^^^^^^^^^^^ expected fn item, found integer
18+
|
19+
= note: expected fn item `fn() -> i32 {a}`
20+
found type `i32`
21+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
22+
23+
error[E0277]: `fn() -> i32 {a}` doesn't implement `std::fmt::Debug`
24+
--> $DIR/issue-70724-add_type_neq_err_label-unwrap.rs:6:5
25+
|
26+
LL | fn a() -> i32 {
27+
| - consider calling this function
28+
...
29+
LL | assert_eq!(a, 0);
30+
| ^^^^^^^^^^^^^^^^^ `fn() -> i32 {a}` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
31+
|
32+
= help: the trait `std::fmt::Debug` is not implemented for `fn() -> i32 {a}`
33+
= help: use parentheses to call the function: `a()`
34+
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&fn() -> i32 {a}`
35+
= note: required by `std::fmt::Debug::fmt`
36+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
37+
38+
error: aborting due to 3 previous errors
39+
40+
Some errors have detailed explanations: E0277, E0308, E0369.
41+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)
Please sign in to comment.