Skip to content

Commit 4d3ce2e

Browse files
committed
Auto merge of #86399 - JohnTitor:rollup-qlm2dvz, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #85663 (Document Arc::from) - #85802 (Rename IoSlice(Mut)::advance to advance_slice and add IoSlice(Mut)::advance) - #85970 (Remove methods under Implementors on trait pages) - #86340 (Use better error message for hard errors in CTFE) - #86343 (Do not emit invalid suggestions on multiple mutable borrow errors) - #86355 (Remove invalid suggestions for assoc consts on placeholder type error) - #86389 (Make `sum()` and `product()` documentation hyperlinks refer to `Iterator` methods.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0ef2b4a + 65d412b commit 4d3ce2e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+406
-318
lines changed

compiler/rustc_middle/src/mir/interpret/error.rs

+10
Original file line numberDiff line numberDiff line change
@@ -518,4 +518,14 @@ impl InterpError<'_> {
518518
_ => false,
519519
}
520520
}
521+
522+
/// Should this error be reported as a hard error, preventing compilation, or a soft error,
523+
/// causing a deny-by-default lint?
524+
pub fn is_hard_err(&self) -> bool {
525+
use InterpError::*;
526+
match *self {
527+
MachineStop(ref err) => err.is_hard_err(),
528+
_ => false,
529+
}
530+
}
521531
}

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
453453
&mut err,
454454
"",
455455
Some(borrow_span),
456+
None,
456457
);
457458
err.buffer(&mut self.errors_buffer);
458459
}
@@ -498,6 +499,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
498499
&mut err,
499500
"",
500501
None,
502+
None,
501503
);
502504
err
503505
}
@@ -718,6 +720,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
718720
&mut err,
719721
first_borrow_desc,
720722
None,
723+
Some((issued_span, span)),
721724
);
722725

723726
err
@@ -1076,6 +1079,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10761079
&mut err,
10771080
"",
10781081
None,
1082+
None,
10791083
);
10801084
}
10811085
} else {
@@ -1093,6 +1097,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10931097
&mut err,
10941098
"",
10951099
None,
1100+
None,
10961101
);
10971102
}
10981103

@@ -1158,6 +1163,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11581163
&mut err,
11591164
"",
11601165
None,
1166+
None,
11611167
);
11621168

11631169
err.buffer(&mut self.errors_buffer);
@@ -1236,6 +1242,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12361242
&mut err,
12371243
"",
12381244
None,
1245+
None,
12391246
);
12401247

12411248
let within = if borrow_spans.for_generator() { " by generator" } else { "" };
@@ -1614,6 +1621,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16141621
&mut err,
16151622
"",
16161623
None,
1624+
None,
16171625
);
16181626

16191627
self.explain_deref_coercion(loan, &mut err);

compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl BorrowExplanation {
6666
err: &mut DiagnosticBuilder<'_>,
6767
borrow_desc: &str,
6868
borrow_span: Option<Span>,
69+
multiple_borrow_span: Option<(Span, Span)>,
6970
) {
7071
match *self {
7172
BorrowExplanation::UsedLater(later_use_kind, var_or_use_span, path_span) => {
@@ -192,14 +193,23 @@ impl BorrowExplanation {
192193

193194
if let Some(info) = &local_decl.is_block_tail {
194195
if info.tail_result_is_ignored {
195-
err.span_suggestion_verbose(
196-
info.span.shrink_to_hi(),
197-
"consider adding semicolon after the expression so its \
198-
temporaries are dropped sooner, before the local variables \
199-
declared by the block are dropped",
200-
";".to_string(),
201-
Applicability::MaybeIncorrect,
202-
);
196+
// #85581: If the first mutable borrow's scope contains
197+
// the second borrow, this suggestion isn't helpful.
198+
if !multiple_borrow_span
199+
.map(|(old, new)| {
200+
old.to(info.span.shrink_to_hi()).contains(new)
201+
})
202+
.unwrap_or(false)
203+
{
204+
err.span_suggestion_verbose(
205+
info.span.shrink_to_hi(),
206+
"consider adding semicolon after the expression so its \
207+
temporaries are dropped sooner, before the local variables \
208+
declared by the block are dropped",
209+
";".to_string(),
210+
Applicability::MaybeIncorrect,
211+
);
212+
}
203213
} else {
204214
err.note(
205215
"the temporary is part of an expression at the end of a \

compiler/rustc_mir/src/const_eval/error.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'tcx> ConstEvalErr<'tcx> {
157157
tcx: TyCtxtAt<'tcx>,
158158
message: &str,
159159
emit: impl FnOnce(DiagnosticBuilder<'_>),
160-
mut lint_root: Option<hir::HirId>,
160+
lint_root: Option<hir::HirId>,
161161
) -> ErrorHandled {
162162
let finish = |mut err: DiagnosticBuilder<'_>, span_msg: Option<String>| {
163163
trace!("reporting const eval failure at {:?}", self.span);
@@ -194,12 +194,6 @@ impl<'tcx> ConstEvalErr<'tcx> {
194194
_ => {}
195195
};
196196

197-
// If we have a 'hard error', then set `lint_root` to `None` so that we don't
198-
// emit a lint.
199-
if matches!(&self.error, InterpError::MachineStop(err) if err.is_hard_err()) {
200-
lint_root = None;
201-
}
202-
203197
let err_msg = self.error.to_string();
204198

205199
// Regular case - emit a lint.

compiler/rustc_mir/src/const_eval/eval_queries.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -312,22 +312,17 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
312312
let err = ConstEvalErr::new(&ecx, error, None);
313313
// Some CTFE errors raise just a lint, not a hard error; see
314314
// <https://github.com/rust-lang/rust/issues/71800>.
315-
let emit_as_lint = if let Some(def) = def.as_local() {
315+
let is_hard_err = if let Some(def) = def.as_local() {
316316
// (Associated) consts only emit a lint, since they might be unused.
317-
matches!(tcx.def_kind(def.did.to_def_id()), DefKind::Const | DefKind::AssocConst)
317+
!matches!(tcx.def_kind(def.did.to_def_id()), DefKind::Const | DefKind::AssocConst)
318+
// check if the inner InterpError is hard
319+
|| err.error.is_hard_err()
318320
} else {
319321
// use of broken constant from other crate: always an error
320-
false
322+
true
321323
};
322-
if emit_as_lint {
323-
let hir_id = tcx.hir().local_def_id_to_hir_id(def.as_local().unwrap().did);
324-
Err(err.report_as_lint(
325-
tcx.at(tcx.def_span(def.did)),
326-
"any use of this value will cause an error",
327-
hir_id,
328-
Some(err.span),
329-
))
330-
} else {
324+
325+
if is_hard_err {
331326
let msg = if is_static {
332327
Cow::from("could not evaluate static initializer")
333328
} else {
@@ -345,6 +340,14 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
345340
};
346341

347342
Err(err.report_as_error(ecx.tcx.at(ecx.cur_span()), &msg))
343+
} else {
344+
let hir_id = tcx.hir().local_def_id_to_hir_id(def.as_local().unwrap().did);
345+
Err(err.report_as_lint(
346+
tcx.at(tcx.def_span(def.did)),
347+
"any use of this value will cause an error",
348+
hir_id,
349+
Some(err.span),
350+
))
348351
}
349352
}
350353
Ok(mplace) => {

compiler/rustc_typeck/src/collect.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ crate fn placeholder_type_error(
179179
// Suggest, but only if it is not a function in const or static
180180
if suggest {
181181
let mut is_fn = false;
182-
let mut is_const = false;
183-
let mut is_static = false;
182+
let mut is_const_or_static = false;
184183

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

193-
if let hir::Node::Item(item) = parent_node {
194-
if let hir::ItemKind::Const(_, _) = item.kind {
195-
is_const = true;
196-
} else if let hir::ItemKind::Static(_, _, _) = item.kind {
197-
is_static = true;
198-
}
199-
}
192+
is_const_or_static = match parent_node {
193+
Node::Item(&hir::Item {
194+
kind: hir::ItemKind::Const(..) | hir::ItemKind::Static(..),
195+
..
196+
})
197+
| Node::TraitItem(&hir::TraitItem {
198+
kind: hir::TraitItemKind::Const(..),
199+
..
200+
})
201+
| Node::ImplItem(&hir::ImplItem {
202+
kind: hir::ImplItemKind::Const(..), ..
203+
}) => true,
204+
_ => false,
205+
};
200206
}
201207
}
202208

203209
// if function is wrapped around a const or static,
204210
// then don't show the suggestion
205-
if !(is_fn && (is_const || is_static)) {
211+
if !(is_fn && is_const_or_static) {
206212
err.multipart_suggestion(
207213
"use type parameters instead",
208214
sugg,

library/alloc/src/collections/vec_deque/into_iter.rs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl<T> Iterator for IntoIter<T> {
3838
}
3939

4040
#[inline]
41+
#[doc(hidden)]
4142
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
4243
where
4344
Self: TrustedRandomAccess,

library/alloc/src/collections/vec_deque/iter.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl<'a, T> Iterator for Iter<'a, T> {
103103
}
104104

105105
#[inline]
106+
#[doc(hidden)]
106107
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
107108
where
108109
Self: TrustedRandomAccess,

library/alloc/src/collections/vec_deque/iter_mut.rs

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
8989
}
9090

9191
#[inline]
92+
#[doc(hidden)]
9293
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
9394
where
9495
Self: TrustedRandomAccess,

library/alloc/src/sync.rs

+14
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,20 @@ impl<T: ?Sized + Hash> Hash for Arc<T> {
23002300

23012301
#[stable(feature = "from_for_ptrs", since = "1.6.0")]
23022302
impl<T> From<T> for Arc<T> {
2303+
/// Converts a `T` into an `Arc<T>`
2304+
///
2305+
/// The conversion moves the value into a
2306+
/// newly allocated `Arc`. It is equivalent to
2307+
/// calling `Arc::new(t)`.
2308+
///
2309+
/// # Example
2310+
/// ```rust
2311+
/// # use std::sync::Arc;
2312+
/// let x = 5;
2313+
/// let arc = Arc::new(5);
2314+
///
2315+
/// assert_eq!(Arc::from(x), arc);
2316+
/// ```
23032317
fn from(t: T) -> Self {
23042318
Arc::new(t)
23052319
}

library/alloc/src/vec/into_iter.rs

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
163163
self.len()
164164
}
165165

166+
#[doc(hidden)]
166167
unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> Self::Item
167168
where
168169
Self: TrustedRandomAccess,

library/core/src/array/iter.rs

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> {
132132
}
133133

134134
#[inline]
135+
#[doc(hidden)]
135136
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
136137
where
137138
Self: TrustedRandomAccess,

library/core/src/iter/adapters/cloned.rs

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ where
5858
self.it.map(T::clone).fold(init, f)
5959
}
6060

61+
#[doc(hidden)]
6162
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> T
6263
where
6364
Self: TrustedRandomAccess,

library/core/src/iter/adapters/copied.rs

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ where
7474
self.it.count()
7575
}
7676

77+
#[doc(hidden)]
7778
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> T
7879
where
7980
Self: TrustedRandomAccess,

library/core/src/iter/adapters/enumerate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ where
111111
}
112112

113113
#[rustc_inherit_overflow_checks]
114+
#[doc(hidden)]
114115
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item
115116
where
116117
Self: TrustedRandomAccess,

library/core/src/iter/adapters/fuse.rs

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ where
114114
}
115115

116116
#[inline]
117+
#[doc(hidden)]
117118
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
118119
where
119120
Self: TrustedRandomAccess,

library/core/src/iter/adapters/map.rs

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ where
122122
self.iter.fold(init, map_fold(self.f, g))
123123
}
124124

125+
#[doc(hidden)]
125126
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> B
126127
where
127128
Self: TrustedRandomAccess,

library/core/src/iter/adapters/zip.rs

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ where
8888
}
8989

9090
#[inline]
91+
#[doc(hidden)]
9192
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
9293
where
9394
Self: TrustedRandomAccess,

library/core/src/iter/range.rs

+1
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ impl<A: Step> Iterator for ops::Range<A> {
667667
}
668668

669669
#[inline]
670+
#[doc(hidden)]
670671
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
671672
where
672673
Self: TrustedRandomAccess,

library/core/src/iter/traits/accum.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ use crate::num::Wrapping;
33

44
/// Trait to represent types that can be created by summing up an iterator.
55
///
6-
/// This trait is used to implement the [`sum()`] method on iterators. Types which
7-
/// implement the trait can be generated by the [`sum()`] method. Like
8-
/// [`FromIterator`] this trait should rarely be called directly and instead
9-
/// interacted with through [`Iterator::sum()`].
6+
/// This trait is used to implement [`Iterator::sum()`]. Types which implement
7+
/// this trait can be generated by using the [`sum()`] method on an iterator.
8+
/// Like [`FromIterator`], this trait should rarely be called directly.
109
///
11-
/// [`sum()`]: Sum::sum
10+
/// [`sum()`]: Iterator::sum
1211
/// [`FromIterator`]: iter::FromIterator
1312
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
1413
pub trait Sum<A = Self>: Sized {
@@ -21,12 +20,11 @@ pub trait Sum<A = Self>: Sized {
2120
/// Trait to represent types that can be created by multiplying elements of an
2221
/// iterator.
2322
///
24-
/// This trait is used to implement the [`product()`] method on iterators. Types
25-
/// which implement the trait can be generated by the [`product()`] method. Like
26-
/// [`FromIterator`] this trait should rarely be called directly and instead
27-
/// interacted with through [`Iterator::product()`].
23+
/// This trait is used to implement [`Iterator::product()`]. Types which implement
24+
/// this trait can be generated by using the [`product()`] method on an iterator.
25+
/// Like [`FromIterator`], this trait should rarely be called directly.
2826
///
29-
/// [`product()`]: Product::product
27+
/// [`product()`]: Iterator::product
3028
/// [`FromIterator`]: iter::FromIterator
3129
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
3230
pub trait Product<A = Self>: Sized {

library/core/src/slice/iter.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2148,6 +2148,7 @@ impl<'a, T, const N: usize> Iterator for ArrayChunks<'a, T, N> {
21482148
self.iter.last()
21492149
}
21502150

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

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

0 commit comments

Comments
 (0)