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 7 pull requests #86399

Merged
merged 26 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3803c09
Rename IoSlice(Mut)::advance to advance_slice
Thomasdezeeuw May 29, 2021
49e25b5
Add IoSlice(Mut)::advance
Thomasdezeeuw May 29, 2021
fd14c52
Rename IoSlice(Mut)::advance_slice to advance_slices
Thomasdezeeuw Jun 5, 2021
2727c3b
Document Arc::from
fee1-dead May 25, 2021
4fe4ff9
Use better error message for hard errors in CTFE
syvb Jun 15, 2021
c8a8a23
Do not emit invalid suggestions on multiple mutable borrow errors
JohnTitor Jun 16, 2021
d828ead
Remove invalid suggestions for assoc consts on placeholder type error
JohnTitor Jun 16, 2021
fb06d9e
Move some typeck-related tests to the typeck dir
JohnTitor Jun 16, 2021
044b362
Move some hard error logic to InterpError
syvb Jun 16, 2021
cb2f8d9
Make `sum()` and `product()` hyperlinks refer to `Iterator` methods.
kpreid Jun 17, 2021
ce64729
Remove methods under Implementors on trait pages
jsha Jun 3, 2021
bff4f07
Use render_impl_summary when rendering traits.
jsha Jun 8, 2021
910c7fa
Add doc(hidden) to all __iterator_get_unchecked
jsha Jun 12, 2021
593d6d1
Make portability part of the summary.
jsha Jun 8, 2021
5de1391
Factor out render_rightside
jsha Jun 12, 2021
c4fa6d5
Move anchor earlier in the DOM for easier layout
jsha Jun 17, 2021
2ac5c17
Fix target highlighting in rustdoc.
jsha Jun 17, 2021
bf81e13
Restore details for Impls on Foreign Types
jsha Jun 16, 2021
5e7a8c6
Fix typos in code examples.
m-ou-se Jun 17, 2021
36b9a6e
Rollup merge of #85663 - fee1-dead:document-arc-from, r=m-ou-se
JohnTitor Jun 17, 2021
31ee680
Rollup merge of #85802 - Thomasdezeeuw:ioslice-advance, r=m-ou-se
JohnTitor Jun 17, 2021
9521da7
Rollup merge of #85970 - jsha:remove-methods-implementors, r=Guillaum…
JohnTitor Jun 17, 2021
c062f3d
Rollup merge of #86340 - Smittyvb:ctfe-hard-error-message, r=RalfJung
JohnTitor Jun 17, 2021
afe70ee
Rollup merge of #86343 - JohnTitor:issue-85581, r=estebank
JohnTitor Jun 17, 2021
aff7994
Rollup merge of #86355 - JohnTitor:issue-82158, r=estebank
JohnTitor Jun 17, 2021
65d412b
Rollup merge of #86389 - kpreid:sum, r=scottmcm
JohnTitor Jun 17, 2021
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
10 changes: 10 additions & 0 deletions compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,4 +518,14 @@ impl InterpError<'_> {
_ => false,
}
}

/// Should this error be reported as a hard error, preventing compilation, or a soft error,
/// causing a deny-by-default lint?
pub fn is_hard_err(&self) -> bool {
use InterpError::*;
match *self {
MachineStop(ref err) => err.is_hard_err(),
_ => false,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
Some(borrow_span),
None,
);
err.buffer(&mut self.errors_buffer);
}
Expand Down Expand Up @@ -498,6 +499,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
None,
None,
);
err
}
Expand Down Expand Up @@ -718,6 +720,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
first_borrow_desc,
None,
Some((issued_span, span)),
);

err
Expand Down Expand Up @@ -1076,6 +1079,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
None,
None,
);
}
} else {
Expand All @@ -1093,6 +1097,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
None,
None,
);
}

Expand Down Expand Up @@ -1158,6 +1163,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
None,
None,
);

err.buffer(&mut self.errors_buffer);
Expand Down Expand Up @@ -1236,6 +1242,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
None,
None,
);

let within = if borrow_spans.for_generator() { " by generator" } else { "" };
Expand Down Expand Up @@ -1614,6 +1621,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&mut err,
"",
None,
None,
);

self.explain_deref_coercion(loan, &mut err);
Expand Down
26 changes: 18 additions & 8 deletions compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl BorrowExplanation {
err: &mut DiagnosticBuilder<'_>,
borrow_desc: &str,
borrow_span: Option<Span>,
multiple_borrow_span: Option<(Span, Span)>,
) {
match *self {
BorrowExplanation::UsedLater(later_use_kind, var_or_use_span, path_span) => {
Expand Down Expand Up @@ -192,14 +193,23 @@ impl BorrowExplanation {

if let Some(info) = &local_decl.is_block_tail {
if info.tail_result_is_ignored {
err.span_suggestion_verbose(
info.span.shrink_to_hi(),
"consider adding semicolon after the expression so its \
temporaries are dropped sooner, before the local variables \
declared by the block are dropped",
";".to_string(),
Applicability::MaybeIncorrect,
);
// #85581: If the first mutable borrow's scope contains
// the second borrow, this suggestion isn't helpful.
if !multiple_borrow_span
.map(|(old, new)| {
old.to(info.span.shrink_to_hi()).contains(new)
})
.unwrap_or(false)
{
err.span_suggestion_verbose(
info.span.shrink_to_hi(),
"consider adding semicolon after the expression so its \
temporaries are dropped sooner, before the local variables \
declared by the block are dropped",
";".to_string(),
Applicability::MaybeIncorrect,
);
}
} else {
err.note(
"the temporary is part of an expression at the end of a \
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_mir/src/const_eval/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl<'tcx> ConstEvalErr<'tcx> {
tcx: TyCtxtAt<'tcx>,
message: &str,
emit: impl FnOnce(DiagnosticBuilder<'_>),
mut lint_root: Option<hir::HirId>,
lint_root: Option<hir::HirId>,
) -> ErrorHandled {
let finish = |mut err: DiagnosticBuilder<'_>, span_msg: Option<String>| {
trace!("reporting const eval failure at {:?}", self.span);
Expand Down Expand Up @@ -194,12 +194,6 @@ impl<'tcx> ConstEvalErr<'tcx> {
_ => {}
};

// If we have a 'hard error', then set `lint_root` to `None` so that we don't
// emit a lint.
if matches!(&self.error, InterpError::MachineStop(err) if err.is_hard_err()) {
lint_root = None;
}

let err_msg = self.error.to_string();

// Regular case - emit a lint.
Expand Down
27 changes: 15 additions & 12 deletions compiler/rustc_mir/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,22 +312,17 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
let err = ConstEvalErr::new(&ecx, error, None);
// Some CTFE errors raise just a lint, not a hard error; see
// <https://github.com/rust-lang/rust/issues/71800>.
let emit_as_lint = if let Some(def) = def.as_local() {
let is_hard_err = if let Some(def) = def.as_local() {
// (Associated) consts only emit a lint, since they might be unused.
matches!(tcx.def_kind(def.did.to_def_id()), DefKind::Const | DefKind::AssocConst)
!matches!(tcx.def_kind(def.did.to_def_id()), DefKind::Const | DefKind::AssocConst)
// check if the inner InterpError is hard
|| err.error.is_hard_err()
} else {
// use of broken constant from other crate: always an error
false
true
};
if emit_as_lint {
let hir_id = tcx.hir().local_def_id_to_hir_id(def.as_local().unwrap().did);
Err(err.report_as_lint(
tcx.at(tcx.def_span(def.did)),
"any use of this value will cause an error",
hir_id,
Some(err.span),
))
} else {

if is_hard_err {
let msg = if is_static {
Cow::from("could not evaluate static initializer")
} else {
Expand All @@ -345,6 +340,14 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
};

Err(err.report_as_error(ecx.tcx.at(ecx.cur_span()), &msg))
} else {
let hir_id = tcx.hir().local_def_id_to_hir_id(def.as_local().unwrap().did);
Err(err.report_as_lint(
tcx.at(tcx.def_span(def.did)),
"any use of this value will cause an error",
hir_id,
Some(err.span),
))
}
}
Ok(mplace) => {
Expand Down
26 changes: 16 additions & 10 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ crate fn placeholder_type_error(
// Suggest, but only if it is not a function in const or static
if suggest {
let mut is_fn = false;
let mut is_const = false;
let mut is_static = false;
let mut is_const_or_static = false;

if let Some(hir_ty) = hir_ty {
if let hir::TyKind::BareFn(_) = hir_ty.kind {
Expand All @@ -190,19 +189,26 @@ crate fn placeholder_type_error(
let parent_id = tcx.hir().get_parent_node(hir_ty.hir_id);
let parent_node = tcx.hir().get(parent_id);

if let hir::Node::Item(item) = parent_node {
if let hir::ItemKind::Const(_, _) = item.kind {
is_const = true;
} else if let hir::ItemKind::Static(_, _, _) = item.kind {
is_static = true;
}
}
is_const_or_static = match parent_node {
Node::Item(&hir::Item {
kind: hir::ItemKind::Const(..) | hir::ItemKind::Static(..),
..
})
| Node::TraitItem(&hir::TraitItem {
kind: hir::TraitItemKind::Const(..),
..
})
| Node::ImplItem(&hir::ImplItem {
kind: hir::ImplItemKind::Const(..), ..
}) => true,
_ => false,
};
}
}

// if function is wrapped around a const or static,
// then don't show the suggestion
if !(is_fn && (is_const || is_static)) {
if !(is_fn && is_const_or_static) {
err.multipart_suggestion(
"use type parameters instead",
sugg,
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/collections/vec_deque/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl<T> Iterator for IntoIter<T> {
}

#[inline]
#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
where
Self: TrustedRandomAccess,
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/collections/vec_deque/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl<'a, T> Iterator for Iter<'a, T> {
}

#[inline]
#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
where
Self: TrustedRandomAccess,
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/collections/vec_deque/iter_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
}

#[inline]
#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
where
Self: TrustedRandomAccess,
Expand Down
14 changes: 14 additions & 0 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2300,6 +2300,20 @@ impl<T: ?Sized + Hash> Hash for Arc<T> {

#[stable(feature = "from_for_ptrs", since = "1.6.0")]
impl<T> From<T> for Arc<T> {
/// Converts a `T` into an `Arc<T>`
///
/// The conversion moves the value into a
/// newly allocated `Arc`. It is equivalent to
/// calling `Arc::new(t)`.
///
/// # Example
/// ```rust
/// # use std::sync::Arc;
/// let x = 5;
/// let arc = Arc::new(5);
///
/// assert_eq!(Arc::from(x), arc);
/// ```
fn from(t: T) -> Self {
Arc::new(t)
}
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/vec/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
self.len()
}

#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> Self::Item
where
Self: TrustedRandomAccess,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/array/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> {
}

#[inline]
#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
where
Self: TrustedRandomAccess,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/adapters/cloned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ where
self.it.map(T::clone).fold(init, f)
}

#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> T
where
Self: TrustedRandomAccess,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/adapters/copied.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ where
self.it.count()
}

#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> T
where
Self: TrustedRandomAccess,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/adapters/enumerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ where
}

#[rustc_inherit_overflow_checks]
#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item
where
Self: TrustedRandomAccess,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/adapters/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ where
}

#[inline]
#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
where
Self: TrustedRandomAccess,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/adapters/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ where
self.iter.fold(init, map_fold(self.f, g))
}

#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> B
where
Self: TrustedRandomAccess,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/adapters/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ where
}

#[inline]
#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
where
Self: TrustedRandomAccess,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ impl<A: Step> Iterator for ops::Range<A> {
}

#[inline]
#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
where
Self: TrustedRandomAccess,
Expand Down
18 changes: 8 additions & 10 deletions library/core/src/iter/traits/accum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ use crate::num::Wrapping;

/// Trait to represent types that can be created by summing up an iterator.
///
/// This trait is used to implement the [`sum()`] method on iterators. Types which
/// implement the trait can be generated by the [`sum()`] method. Like
/// [`FromIterator`] this trait should rarely be called directly and instead
/// interacted with through [`Iterator::sum()`].
/// This trait is used to implement [`Iterator::sum()`]. Types which implement
/// this trait can be generated by using the [`sum()`] method on an iterator.
/// Like [`FromIterator`], this trait should rarely be called directly.
///
/// [`sum()`]: Sum::sum
/// [`sum()`]: Iterator::sum
/// [`FromIterator`]: iter::FromIterator
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
pub trait Sum<A = Self>: Sized {
Expand All @@ -21,12 +20,11 @@ pub trait Sum<A = Self>: Sized {
/// Trait to represent types that can be created by multiplying elements of an
/// iterator.
///
/// This trait is used to implement the [`product()`] method on iterators. Types
/// which implement the trait can be generated by the [`product()`] method. Like
/// [`FromIterator`] this trait should rarely be called directly and instead
/// interacted with through [`Iterator::product()`].
/// This trait is used to implement [`Iterator::product()`]. Types which implement
/// this trait can be generated by using the [`product()`] method on an iterator.
/// Like [`FromIterator`], this trait should rarely be called directly.
///
/// [`product()`]: Product::product
/// [`product()`]: Iterator::product
/// [`FromIterator`]: iter::FromIterator
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
pub trait Product<A = Self>: Sized {
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/slice/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,7 @@ impl<'a, T, const N: usize> Iterator for ArrayChunks<'a, T, N> {
self.iter.last()
}

#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> &'a [T; N] {
// SAFETY: The safety guarantees of `__iterator_get_unchecked` are
// transferred to the caller.
Expand Down Expand Up @@ -2260,6 +2261,7 @@ impl<'a, T, const N: usize> Iterator for ArrayChunksMut<'a, T, N> {
self.iter.last()
}

#[doc(hidden)]
unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> &'a mut [T; N] {
// SAFETY: The safety guarantees of `__iterator_get_unchecked` are transferred to
// the caller.
Expand Down
Loading