Skip to content

Commit eb10acd

Browse files
committed
Auto merge of rust-lang#122012 - matthiaskrgr:rollup-bzqjj2n, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#121213 (Add an example to demonstrate how Rc::into_inner works) - rust-lang#121262 (Add vector time complexity) - rust-lang#121287 (Clarify/add `must_use` message for Rc/Arc/Weak::into_raw.) - rust-lang#121664 (Adjust error `yield`/`await` lowering) - rust-lang#121826 (Use root obligation on E0277 for some cases) - rust-lang#121838 (Use the correct logic for nested impl trait in assoc types) - rust-lang#121913 (Don't panic when waiting on poisoned queries) - rust-lang#121987 (pattern analysis: abort on arity mismatch) - rust-lang#121993 (Avoid using unnecessary queries when printing the query stack in panics) - rust-lang#121997 (interpret/cast: make more matches on FloatTy properly exhaustive) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6d82806 + 74b6933 commit eb10acd

File tree

7 files changed

+90
-37
lines changed

7 files changed

+90
-37
lines changed

alloc/src/rc.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,21 @@ impl<T, A: Allocator> Rc<T, A> {
944944
/// is in fact equivalent to <code>[Rc::try_unwrap]\(this).[ok][Result::ok]()</code>.
945945
/// (Note that the same kind of equivalence does **not** hold true for
946946
/// [`Arc`](crate::sync::Arc), due to race conditions that do not apply to `Rc`!)
947+
///
948+
/// # Examples
949+
///
950+
/// ```
951+
/// use std::rc::Rc;
952+
///
953+
/// let x = Rc::new(3);
954+
/// assert_eq!(Rc::into_inner(x), Some(3));
955+
///
956+
/// let x = Rc::new(4);
957+
/// let y = Rc::clone(&x);
958+
///
959+
/// assert_eq!(Rc::into_inner(y), None);
960+
/// assert_eq!(Rc::into_inner(x), Some(4));
961+
/// ```
947962
#[inline]
948963
#[stable(feature = "rc_into_inner", since = "1.70.0")]
949964
pub fn into_inner(this: Self) -> Option<T> {
@@ -1329,6 +1344,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
13291344
/// let x_ptr = Rc::into_raw(x);
13301345
/// assert_eq!(unsafe { &*x_ptr }, "hello");
13311346
/// ```
1347+
#[must_use = "losing the pointer will leak memory"]
13321348
#[stable(feature = "rc_raw", since = "1.17.0")]
13331349
#[rustc_never_returns_null_ptr]
13341350
pub fn into_raw(this: Self) -> *const T {
@@ -2970,7 +2986,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
29702986
///
29712987
/// [`from_raw`]: Weak::from_raw
29722988
/// [`as_ptr`]: Weak::as_ptr
2973-
#[must_use = "`self` will be dropped if the result is not used"]
2989+
#[must_use = "losing the pointer will leak memory"]
29742990
#[stable(feature = "weak_into_raw", since = "1.45.0")]
29752991
pub fn into_raw(self) -> *const T {
29762992
let result = self.as_ptr();

alloc/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
27192719
///
27202720
/// [`from_raw`]: Weak::from_raw
27212721
/// [`as_ptr`]: Weak::as_ptr
2722-
#[must_use = "`self` will be dropped if the result is not used"]
2722+
#[must_use = "losing the pointer will leak memory"]
27232723
#[stable(feature = "weak_into_raw", since = "1.45.0")]
27242724
pub fn into_raw(self) -> *const T {
27252725
let result = self.as_ptr();

alloc/src/vec/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,12 @@ impl<T, A: Allocator> Vec<T, A> {
14901490
/// vec.insert(4, 5);
14911491
/// assert_eq!(vec, [1, 4, 2, 3, 5]);
14921492
/// ```
1493+
///
1494+
/// # Time complexity
1495+
///
1496+
/// Takes *O*([`Vec::len`]) time. All items after the insertion index must be
1497+
/// shifted to the right. In the worst case, all elements are shifted when
1498+
/// the insertion index is 0.
14931499
#[cfg(not(no_global_oom_handling))]
14941500
#[stable(feature = "rust1", since = "1.0.0")]
14951501
pub fn insert(&mut self, index: usize, element: T) {
@@ -1913,6 +1919,13 @@ impl<T, A: Allocator> Vec<T, A> {
19131919
/// vec.push(3);
19141920
/// assert_eq!(vec, [1, 2, 3]);
19151921
/// ```
1922+
///
1923+
/// # Time complexity
1924+
///
1925+
/// Takes amortized *O*(1) time. If the vector's length would exceed its
1926+
/// capacity after the push, *O*(*capacity*) time is taken to copy the
1927+
/// vector's elements to a larger allocation. This expensive operation is
1928+
/// offset by the *capacity* *O*(1) insertions it allows.
19161929
#[cfg(not(no_global_oom_handling))]
19171930
#[inline]
19181931
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1961,6 +1974,10 @@ impl<T, A: Allocator> Vec<T, A> {
19611974
/// }
19621975
/// assert_eq!(from_iter_fallible(0..100), Ok(Vec::from_iter(0..100)));
19631976
/// ```
1977+
///
1978+
/// # Time complexity
1979+
///
1980+
/// Takes *O*(1) time.
19641981
#[inline]
19651982
#[unstable(feature = "vec_push_within_capacity", issue = "100486")]
19661983
pub fn push_within_capacity(&mut self, value: T) -> Result<(), T> {
@@ -1990,6 +2007,10 @@ impl<T, A: Allocator> Vec<T, A> {
19902007
/// assert_eq!(vec.pop(), Some(3));
19912008
/// assert_eq!(vec, [1, 2]);
19922009
/// ```
2010+
///
2011+
/// # Time complexity
2012+
///
2013+
/// Takes *O*(1) time.
19932014
#[inline]
19942015
#[stable(feature = "rust1", since = "1.0.0")]
19952016
pub fn pop(&mut self) -> Option<T> {

core/src/future/future.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ use crate::task::{Context, Poll};
3030
#[lang = "future_trait"]
3131
#[diagnostic::on_unimplemented(
3232
label = "`{Self}` is not a future",
33-
message = "`{Self}` is not a future",
34-
note = "{Self} must be a future or must implement `IntoFuture` to be awaited"
33+
message = "`{Self}` is not a future"
3534
)]
3635
pub trait Future {
3736
/// The type of value produced on completion.

core/src/future/into_future.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ use crate::future::Future;
100100
/// ```
101101
#[stable(feature = "into_future", since = "1.64.0")]
102102
#[rustc_diagnostic_item = "IntoFuture"]
103+
#[diagnostic::on_unimplemented(
104+
label = "`{Self}` is not a future",
105+
message = "`{Self}` is not a future",
106+
note = "{Self} must be a future or must implement `IntoFuture` to be awaited"
107+
)]
103108
pub trait IntoFuture {
104109
/// The output that the future will produce on completion.
105110
#[stable(feature = "into_future", since = "1.64.0")]

core/src/iter/traits/collect.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,49 @@ pub trait FromIterator<A>: Sized {
236236
/// ```
237237
#[rustc_diagnostic_item = "IntoIterator"]
238238
#[rustc_skip_array_during_method_dispatch]
239+
#[rustc_on_unimplemented(
240+
on(
241+
_Self = "core::ops::range::RangeTo<Idx>",
242+
label = "if you meant to iterate until a value, add a starting value",
243+
note = "`..end` is a `RangeTo`, which cannot be iterated on; you might have meant to have a \
244+
bounded `Range`: `0..end`"
245+
),
246+
on(
247+
_Self = "core::ops::range::RangeToInclusive<Idx>",
248+
label = "if you meant to iterate until a value (including it), add a starting value",
249+
note = "`..=end` is a `RangeToInclusive`, which cannot be iterated on; you might have meant \
250+
to have a bounded `RangeInclusive`: `0..=end`"
251+
),
252+
on(
253+
_Self = "[]",
254+
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
255+
),
256+
on(_Self = "&[]", label = "`{Self}` is not an iterator; try calling `.iter()`"),
257+
on(
258+
_Self = "alloc::vec::Vec<T, A>",
259+
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
260+
),
261+
on(
262+
_Self = "&str",
263+
label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"
264+
),
265+
on(
266+
_Self = "alloc::string::String",
267+
label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"
268+
),
269+
on(
270+
_Self = "{integral}",
271+
note = "if you want to iterate between `start` until a value `end`, use the exclusive range \
272+
syntax `start..end` or the inclusive range syntax `start..=end`"
273+
),
274+
on(
275+
_Self = "{float}",
276+
note = "if you want to iterate between `start` until a value `end`, use the exclusive range \
277+
syntax `start..end` or the inclusive range syntax `start..=end`"
278+
),
279+
label = "`{Self}` is not an iterator",
280+
message = "`{Self}` is not an iterator"
281+
)]
239282
#[stable(feature = "rust1", since = "1.0.0")]
240283
pub trait IntoIterator {
241284
/// The type of the elements being iterated over.

core/src/iter/traits/iterator.rs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,11 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
2828
#[rustc_on_unimplemented(
2929
on(
3030
_Self = "core::ops::range::RangeTo<Idx>",
31-
label = "if you meant to iterate until a value, add a starting value",
32-
note = "`..end` is a `RangeTo`, which cannot be iterated on; you might have meant to have a \
33-
bounded `Range`: `0..end`"
31+
note = "you might have meant to use a bounded `Range`"
3432
),
3533
on(
3634
_Self = "core::ops::range::RangeToInclusive<Idx>",
37-
label = "if you meant to iterate until a value (including it), add a starting value",
38-
note = "`..=end` is a `RangeToInclusive`, which cannot be iterated on; you might have meant \
39-
to have a bounded `RangeInclusive`: `0..=end`"
40-
),
41-
on(
42-
_Self = "[]",
43-
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
44-
),
45-
on(_Self = "&[]", label = "`{Self}` is not an iterator; try calling `.iter()`"),
46-
on(
47-
_Self = "alloc::vec::Vec<T, A>",
48-
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
49-
),
50-
on(
51-
_Self = "&str",
52-
label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"
53-
),
54-
on(
55-
_Self = "alloc::string::String",
56-
label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"
57-
),
58-
on(
59-
_Self = "{integral}",
60-
note = "if you want to iterate between `start` until a value `end`, use the exclusive range \
61-
syntax `start..end` or the inclusive range syntax `start..=end`"
62-
),
63-
on(
64-
_Self = "{float}",
65-
note = "if you want to iterate between `start` until a value `end`, use the exclusive range \
66-
syntax `start..end` or the inclusive range syntax `start..=end`"
35+
note = "you might have meant to use a bounded `RangeInclusive`"
6736
),
6837
label = "`{Self}` is not an iterator",
6938
message = "`{Self}` is not an iterator"

0 commit comments

Comments
 (0)