Skip to content

Commit 47ae8de

Browse files
committed
Auto merge of #88750 - jackh726:rollup-w57i9fp, r=jackh726
Rollup of 9 pull requests Successful merges: - #86263 (Rustdoc: Report Layout of enum variants) - #88541 (Add regression test for #74400) - #88553 (Improve diagnostics for unary plus operators (#88276)) - #88594 (More symbolic doc aliases) - #88648 (Correct “copies” to “moves” in `<Option<T> as From<T>>::from` doc, and other copyediting) - #88691 (Add a regression test for #88649) - #88694 (Drop 1.56 stabilizations from 1.55 release notes) - #88712 (Fix docs for `uX::checked_next_multiple_of`) - #88726 (Fix typo in `const_generics` replaced with `adt_const_params` note) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c9db3e0 + 4cb751e commit 47ae8de

File tree

22 files changed

+260
-45
lines changed

22 files changed

+260
-45
lines changed

Diff for: RELEASES.md

+1-15
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ Language
1010

1111
Compiler
1212
--------
13-
- [Added tier 3\* support for `powerpc-unknown-freebsd`.][87370]
14-
- [Added tier 3 support for `powerpc64le-unknown-freebsd`.][83572]
13+
- [Added tier 3\* support for `powerpc64le-unknown-freebsd`.][83572]
1514

1615
\* Refer to Rust's [platform support page][platform-support-doc] for more
1716
information on Rust's tiered platform support.
@@ -24,17 +23,6 @@ Libraries
2423
no longer reject certain valid floating point values, and reduce
2524
the produced code size for non-stripped artifacts.
2625
- [`string::Drain` now implements `AsRef<str>` and `AsRef<[u8]>`.][86858]
27-
- [`collections::{BinaryHeap, BTreeSet, HashSet, LinkedList, VecDeque}` now
28-
implement `From<[T; N]>`.][84111]
29-
- [`collections::{BTreeMap, HashMap}` now implement `From<[(K, V); N]>`.][84111]
30-
This allows you to write the following;
31-
```rust
32-
let highscores = std::collections::HashMap::from([
33-
("Alice", 9000u32),
34-
("Bob", 7250),
35-
("Charlie", 5500),
36-
]);
37-
```
3826

3927
Stabilised APIs
4028
---------------
@@ -60,7 +48,6 @@ Stabilised APIs
6048
The following previously stable functions are now `const`.
6149

6250
- [`str::from_utf8_unchecked`]
63-
- [`mem::transmute`]
6451

6552

6653
Cargo
@@ -131,7 +118,6 @@ Compatibility Notes
131118
[`MaybeUninit::assume_init_ref`]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.assume_init_ref
132119
[`MaybeUninit::write`]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.write
133120
[`Seek::rewind`]: https://doc.rust-lang.org/stable/std/io/trait.Seek.html#method.rewind
134-
[`mem::transmute`]: https://doc.rust-lang.org/stable/std/mem/fn.transmute.html
135121
[`ops::ControlFlow`]: https://doc.rust-lang.org/stable/std/ops/enum.ControlFlow.html
136122
[`str::from_utf8_unchecked`]: https://doc.rust-lang.org/stable/std/str/fn.from_utf8_unchecked.html
137123
[`x86::_bittest`]: https://doc.rust-lang.org/stable/core/arch/x86/fn._bittest.html

Diff for: compiler/rustc_ast/src/token.rs

+7
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,13 @@ impl Token {
586586
self.is_non_raw_ident_where(|id| id.name.is_bool_lit())
587587
}
588588

589+
pub fn is_numeric_lit(&self) -> bool {
590+
matches!(
591+
self.kind,
592+
Literal(Lit { kind: LitKind::Integer, .. }) | Literal(Lit { kind: LitKind::Float, .. })
593+
)
594+
}
595+
589596
/// Returns `true` if the token is a non-raw identifier for which `pred` holds.
590597
pub fn is_non_raw_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool {
591598
match self.ident() {

Diff for: compiler/rustc_feature/src/removed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ declare_features! (
104104
(removed, quote, "1.33.0", Some(29601), None, None),
105105
/// Allows const generic types (e.g. `struct Foo<const N: usize>(...);`).
106106
(removed, const_generics, "1.34.0", Some(44580), None,
107-
Some("removed in favor of `#![feature(adt_const_params]` and `#![feature(generic_const_exprs)]`")),
107+
Some("removed in favor of `#![feature(adt_const_params)]` and `#![feature(generic_const_exprs)]`")),
108108
/// Allows `[x; N]` where `x` is a constant (RFC 2203).
109109
(removed, const_in_array_repeat_expressions, "1.37.0", Some(49147), None,
110110
Some("removed due to causing promotable bugs")),

Diff for: compiler/rustc_parse/src/parser/expr.rs

+20
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,26 @@ impl<'a> Parser<'a> {
516516
token::BinOp(token::And) | token::AndAnd => {
517517
make_it!(this, attrs, |this, _| this.parse_borrow_expr(lo))
518518
}
519+
token::BinOp(token::Plus) if this.look_ahead(1, |tok| tok.is_numeric_lit()) => {
520+
let mut err = this.struct_span_err(lo, "leading `+` is not supported");
521+
err.span_label(lo, "unexpected `+`");
522+
523+
// a block on the LHS might have been intended to be an expression instead
524+
if let Some(sp) = this.sess.ambiguous_block_expr_parse.borrow().get(&lo) {
525+
this.sess.expr_parentheses_needed(&mut err, *sp);
526+
} else {
527+
err.span_suggestion_verbose(
528+
lo,
529+
"try removing the `+`",
530+
"".to_string(),
531+
Applicability::MachineApplicable,
532+
);
533+
}
534+
err.emit();
535+
536+
this.bump();
537+
this.parse_prefix_expr(None)
538+
} // `+expr`
519539
token::Ident(..) if this.token.is_keyword(kw::Box) => {
520540
make_it!(this, attrs, |this, _| this.parse_box_expr(lo))
521541
}

Diff for: library/core/src/num/uint_macros.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,8 @@ macro_rules! uint_impl {
19241924
}
19251925

19261926
/// Calculates the smallest value greater than or equal to `self` that
1927-
/// is a multiple of `rhs`. If `rhs` is negative,
1927+
/// is a multiple of `rhs`. Returns `None` is `rhs` is zero or the
1928+
/// operation would result in overflow.
19281929
///
19291930
/// # Examples
19301931
///

Diff for: library/core/src/ops/bit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
/// ```
3131
#[lang = "not"]
3232
#[stable(feature = "rust1", since = "1.0.0")]
33+
#[doc(alias = "!")]
3334
pub trait Not {
3435
/// The resulting type after applying the `!` operator.
3536
#[stable(feature = "rust1", since = "1.0.0")]

Diff for: library/core/src/option.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ impl<T> Option<T> {
11731173
// Entry-like operations to insert a value and return a reference
11741174
/////////////////////////////////////////////////////////////////////////
11751175

1176-
/// Inserts `value` into the option then returns a mutable reference to it.
1176+
/// Inserts `value` into the option, then returns a mutable reference to it.
11771177
///
11781178
/// If the option already contains a value, the old value is dropped.
11791179
///
@@ -1397,7 +1397,7 @@ impl<T> Option<T> {
13971397
}
13981398

13991399
impl<T, U> Option<(T, U)> {
1400-
/// Unzips an option containing a tuple of two options
1400+
/// Unzips an option containing a tuple of two options.
14011401
///
14021402
/// If `self` is `Some((a, b))` this method returns `(Some(a), Some(b))`.
14031403
/// Otherwise, `(None, None)` is returned.
@@ -1500,7 +1500,7 @@ impl<T: Clone> Option<&mut T> {
15001500
}
15011501

15021502
impl<T: Default> Option<T> {
1503-
/// Returns the contained [`Some`] value or a default
1503+
/// Returns the contained [`Some`] value or a default.
15041504
///
15051505
/// Consumes the `self` argument then, if [`Some`], returns the contained
15061506
/// value, otherwise if [`None`], returns the [default value] for that
@@ -1561,7 +1561,7 @@ impl<T: DerefMut> Option<T> {
15611561
/// Converts from `Option<T>` (or `&mut Option<T>`) to `Option<&mut T::Target>`.
15621562
///
15631563
/// Leaves the original `Option` in-place, creating a new one containing a mutable reference to
1564-
/// the inner type's `Deref::Target` type.
1564+
/// the inner type's [`Deref::Target`] type.
15651565
///
15661566
/// # Examples
15671567
///
@@ -1701,7 +1701,7 @@ impl<'a, T> IntoIterator for &'a mut Option<T> {
17011701

17021702
#[stable(since = "1.12.0", feature = "option_from")]
17031703
impl<T> From<T> for Option<T> {
1704-
/// Copies `val` into a new `Some`.
1704+
/// Moves `val` into a new [`Some`].
17051705
///
17061706
/// # Examples
17071707
///
@@ -1942,8 +1942,8 @@ unsafe impl<A> TrustedLen for IntoIter<A> {}
19421942
impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
19431943
/// Takes each element in the [`Iterator`]: if it is [`None`][Option::None],
19441944
/// no further elements are taken, and the [`None`][Option::None] is
1945-
/// returned. Should no [`None`][Option::None] occur, a container with the
1946-
/// values of each [`Option`] is returned.
1945+
/// returned. Should no [`None`][Option::None] occur, a container of type
1946+
/// `V` containing the values of each [`Option`] is returned.
19471947
///
19481948
/// # Examples
19491949
///
@@ -2039,7 +2039,7 @@ impl<T> ops::FromResidual for Option<T> {
20392039
}
20402040

20412041
impl<T> Option<Option<T>> {
2042-
/// Converts from `Option<Option<T>>` to `Option<T>`
2042+
/// Converts from `Option<Option<T>>` to `Option<T>`.
20432043
///
20442044
/// # Examples
20452045
///

Diff for: library/std/src/keyword_docs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ mod break_keyword {}
119119

120120
#[doc(keyword = "const")]
121121
//
122-
/// Compile-time constants and compile-time evaluable functions.
122+
/// Compile-time constants, compile-time evaluable functions, and raw pointers.
123123
///
124124
/// ## Compile-time constants
125125
///

Diff for: library/std/src/primitive_docs.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,11 @@ mod prim_char {}
388388
#[stable(feature = "rust1", since = "1.0.0")]
389389
mod prim_unit {}
390390

391-
#[doc(alias = "ptr")]
392391
#[doc(primitive = "pointer")]
392+
#[doc(alias = "ptr")]
393+
#[doc(alias = "*")]
394+
#[doc(alias = "*const")]
395+
#[doc(alias = "*mut")]
393396
//
394397
/// Raw, unsafe pointers, `*const T`, and `*mut T`.
395398
///
@@ -502,10 +505,10 @@ mod prim_unit {}
502505
#[stable(feature = "rust1", since = "1.0.0")]
503506
mod prim_pointer {}
504507

508+
#[doc(primitive = "array")]
505509
#[doc(alias = "[]")]
506510
#[doc(alias = "[T;N]")] // unfortunately, rustdoc doesn't have fuzzy search for aliases
507511
#[doc(alias = "[T; N]")]
508-
#[doc(primitive = "array")]
509512
/// A fixed-size array, denoted `[T; N]`, for the element type, `T`, and the
510513
/// non-negative compile-time constant size, `N`.
511514
///

Diff for: src/librustdoc/html/render/print_item.rs

+46-11
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ use rustc_hir as hir;
88
use rustc_hir::def::CtorKind;
99
use rustc_hir::def_id::DefId;
1010
use rustc_middle::middle::stability;
11+
use rustc_middle::span_bug;
1112
use rustc_middle::ty::layout::LayoutError;
12-
use rustc_middle::ty::TyCtxt;
13+
use rustc_middle::ty::{Adt, TyCtxt};
1314
use rustc_span::hygiene::MacroKind;
1415
use rustc_span::symbol::{kw, sym, Symbol};
16+
use rustc_target::abi::{Layout, Primitive, TagEncoding, Variants};
1517

1618
use super::{
1719
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_strs, notable_traits_decl,
@@ -1621,6 +1623,15 @@ fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) {
16211623
}
16221624

16231625
fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
1626+
fn write_size_of_layout(w: &mut Buffer, layout: &Layout, tag_size: u64) {
1627+
if layout.abi.is_unsized() {
1628+
write!(w, "(unsized)");
1629+
} else {
1630+
let bytes = layout.size.bytes() - tag_size;
1631+
write!(w, "{size} byte{pl}", size = bytes, pl = if bytes == 1 { "" } else { "s" },);
1632+
}
1633+
}
1634+
16241635
if !cx.shared.show_type_layout {
16251636
return;
16261637
}
@@ -1642,16 +1653,40 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
16421653
<a href=\"https://doc.rust-lang.org/reference/type-layout.html\">“Type Layout”</a> \
16431654
chapter for details on type layout guarantees.</p></div>"
16441655
);
1645-
if ty_layout.layout.abi.is_unsized() {
1646-
writeln!(w, "<p><strong>Size:</strong> (unsized)</p>");
1647-
} else {
1648-
let bytes = ty_layout.layout.size.bytes();
1649-
writeln!(
1650-
w,
1651-
"<p><strong>Size:</strong> {size} byte{pl}</p>",
1652-
size = bytes,
1653-
pl = if bytes == 1 { "" } else { "s" },
1654-
);
1656+
w.write_str("<p><strong>Size:</strong> ");
1657+
write_size_of_layout(w, ty_layout.layout, 0);
1658+
writeln!(w, "</p>");
1659+
if let Variants::Multiple { variants, tag, tag_encoding, .. } =
1660+
&ty_layout.layout.variants
1661+
{
1662+
if !variants.is_empty() {
1663+
w.write_str(
1664+
"<p><strong>Size for each variant:</strong></p>\
1665+
<ul>",
1666+
);
1667+
1668+
let adt = if let Adt(adt, _) = ty_layout.ty.kind() {
1669+
adt
1670+
} else {
1671+
span_bug!(tcx.def_span(ty_def_id), "not an adt")
1672+
};
1673+
1674+
let tag_size = if let TagEncoding::Niche { .. } = tag_encoding {
1675+
0
1676+
} else if let Primitive::Int(i, _) = tag.value {
1677+
i.size().bytes()
1678+
} else {
1679+
span_bug!(tcx.def_span(ty_def_id), "tag is neither niche nor int")
1680+
};
1681+
1682+
for (index, layout) in variants.iter_enumerated() {
1683+
let ident = adt.variants[index].ident;
1684+
write!(w, "<li><code>{name}</code>: ", name = ident);
1685+
write_size_of_layout(w, layout, tag_size);
1686+
writeln!(w, "</li>");
1687+
}
1688+
w.write_str("</ul>");
1689+
}
16551690
}
16561691
}
16571692
// This kind of layout error can occur with valid code, e.g. if you try to

Diff for: src/test/rustdoc/type-layout.rs

+18
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,21 @@ pub struct Unsized([u8]);
5252

5353
// @!has type_layout/trait.MyTrait.html 'Size: '
5454
pub trait MyTrait {}
55+
56+
// @has type_layout/enum.Variants.html 'Size: '
57+
// @has - '2 bytes'
58+
// @has - '<code>A</code>: 0 bytes'
59+
// @has - '<code>B</code>: 1 byte'
60+
pub enum Variants {
61+
A,
62+
B(u8),
63+
}
64+
65+
// @has type_layout/enum.WithNiche.html 'Size: '
66+
// @has - //p '4 bytes'
67+
// @has - '<code>None</code>: 0 bytes'
68+
// @has - '<code>Some</code>: 4 bytes'
69+
pub enum WithNiche {
70+
None,
71+
Some(std::num::NonZeroU32),
72+
}

Diff for: src/test/ui/associated-types/issue-36499.stderr

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
error: expected expression, found `+`
1+
error: leading `+` is not supported
22
--> $DIR/issue-36499.rs:4:9
33
|
44
LL | 2 + +2;
5-
| ^ expected expression
5+
| ^ unexpected `+`
6+
|
7+
help: try removing the `+`
8+
|
9+
LL - 2 + +2;
10+
LL + 2 + 2;
11+
|
612

713
error: aborting due to previous error
814

Diff for: src/test/ui/consts/issue-88649.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
#![crate_type = "lib"]
3+
4+
enum Foo {
5+
Variant1(bool),
6+
Variant2(bool),
7+
}
8+
9+
const _: () = {
10+
let mut n = 0;
11+
while n < 2 {
12+
match Foo::Variant1(true) {
13+
Foo::Variant1(x) | Foo::Variant2(x) if x => {}
14+
_ => {}
15+
}
16+
n += 1;
17+
}
18+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0310]: the parameter type `T` may not live long enough
2+
--> $DIR/issue_74400.rs:12:5
3+
|
4+
LL | f(data, identity)
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
= help: consider adding an explicit lifetime bound `T: 'static`...
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/issue_74400.rs:12:5
11+
|
12+
LL | f(data, identity)
13+
| ^^^^^^^^^^^^^^^^^ one type is more general than the other
14+
|
15+
= note: expected type `for<'r> Fn<(&'r T,)>`
16+
found type `Fn<(&T,)>`
17+
18+
error: implementation of `FnOnce` is not general enough
19+
--> $DIR/issue_74400.rs:12:5
20+
|
21+
LL | f(data, identity)
22+
| ^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
23+
|
24+
= note: `fn(&'2 T) -> &'2 T {identity::<&'2 T>}` must implement `FnOnce<(&'1 T,)>`, for any lifetime `'1`...
25+
= note: ...but it actually implements `FnOnce<(&'2 T,)>`, for some specific lifetime `'2`
26+
27+
error: aborting due to 3 previous errors
28+
29+
Some errors have detailed explanations: E0308, E0310.
30+
For more information about an error, try `rustc --explain E0308`.

Diff for: src/test/ui/lifetimes/lifetime-errors/issue_74400.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! Regression test for #74400: Type mismatch in function arguments E0631, E0271 are falsely
2+
//! recognized as E0308 mismatched types.
3+
4+
use std::convert::identity;
5+
6+
fn main() {}
7+
8+
fn f<T, S>(data: &[T], key: impl Fn(&T) -> S) {
9+
}
10+
11+
fn g<T>(data: &[T]) {
12+
f(data, identity) //~ ERROR implementation of `FnOnce` is not general
13+
}

0 commit comments

Comments
 (0)