Skip to content

Commit

Permalink
Auto merge of rust-lang#88750 - jackh726:rollup-w57i9fp, r=jackh726
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - rust-lang#86263 (Rustdoc: Report Layout of enum variants)
 - rust-lang#88541 (Add regression test for rust-lang#74400)
 - rust-lang#88553 (Improve diagnostics for unary plus operators (rust-lang#88276))
 - rust-lang#88594 (More symbolic doc aliases)
 - rust-lang#88648 (Correct “copies” to “moves” in `<Option<T> as From<T>>::from` doc, and other copyediting)
 - rust-lang#88691 (Add a regression test for rust-lang#88649)
 - rust-lang#88694 (Drop 1.56 stabilizations from 1.55 release notes)
 - rust-lang#88712 (Fix docs for `uX::checked_next_multiple_of`)
 - rust-lang#88726 (Fix typo in `const_generics` replaced with `adt_const_params` note)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Sep 8, 2021
2 parents c9db3e0 + 4cb751e commit 47ae8de
Show file tree
Hide file tree
Showing 22 changed files with 260 additions and 45 deletions.
16 changes: 1 addition & 15 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Language

Compiler
--------
- [Added tier 3\* support for `powerpc-unknown-freebsd`.][87370]
- [Added tier 3 support for `powerpc64le-unknown-freebsd`.][83572]
- [Added tier 3\* support for `powerpc64le-unknown-freebsd`.][83572]

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

Stabilised APIs
---------------
Expand All @@ -60,7 +48,6 @@ Stabilised APIs
The following previously stable functions are now `const`.

- [`str::from_utf8_unchecked`]
- [`mem::transmute`]


Cargo
Expand Down Expand Up @@ -131,7 +118,6 @@ Compatibility Notes
[`MaybeUninit::assume_init_ref`]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.assume_init_ref
[`MaybeUninit::write`]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.write
[`Seek::rewind`]: https://doc.rust-lang.org/stable/std/io/trait.Seek.html#method.rewind
[`mem::transmute`]: https://doc.rust-lang.org/stable/std/mem/fn.transmute.html
[`ops::ControlFlow`]: https://doc.rust-lang.org/stable/std/ops/enum.ControlFlow.html
[`str::from_utf8_unchecked`]: https://doc.rust-lang.org/stable/std/str/fn.from_utf8_unchecked.html
[`x86::_bittest`]: https://doc.rust-lang.org/stable/core/arch/x86/fn._bittest.html
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,13 @@ impl Token {
self.is_non_raw_ident_where(|id| id.name.is_bool_lit())
}

pub fn is_numeric_lit(&self) -> bool {
matches!(
self.kind,
Literal(Lit { kind: LitKind::Integer, .. }) | Literal(Lit { kind: LitKind::Float, .. })
)
}

/// Returns `true` if the token is a non-raw identifier for which `pred` holds.
pub fn is_non_raw_ident_where(&self, pred: impl FnOnce(Ident) -> bool) -> bool {
match self.ident() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ declare_features! (
(removed, quote, "1.33.0", Some(29601), None, None),
/// Allows const generic types (e.g. `struct Foo<const N: usize>(...);`).
(removed, const_generics, "1.34.0", Some(44580), None,
Some("removed in favor of `#![feature(adt_const_params]` and `#![feature(generic_const_exprs)]`")),
Some("removed in favor of `#![feature(adt_const_params)]` and `#![feature(generic_const_exprs)]`")),
/// Allows `[x; N]` where `x` is a constant (RFC 2203).
(removed, const_in_array_repeat_expressions, "1.37.0", Some(49147), None,
Some("removed due to causing promotable bugs")),
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,26 @@ impl<'a> Parser<'a> {
token::BinOp(token::And) | token::AndAnd => {
make_it!(this, attrs, |this, _| this.parse_borrow_expr(lo))
}
token::BinOp(token::Plus) if this.look_ahead(1, |tok| tok.is_numeric_lit()) => {
let mut err = this.struct_span_err(lo, "leading `+` is not supported");
err.span_label(lo, "unexpected `+`");

// a block on the LHS might have been intended to be an expression instead
if let Some(sp) = this.sess.ambiguous_block_expr_parse.borrow().get(&lo) {
this.sess.expr_parentheses_needed(&mut err, *sp);
} else {
err.span_suggestion_verbose(
lo,
"try removing the `+`",
"".to_string(),
Applicability::MachineApplicable,
);
}
err.emit();

this.bump();
this.parse_prefix_expr(None)
} // `+expr`
token::Ident(..) if this.token.is_keyword(kw::Box) => {
make_it!(this, attrs, |this, _| this.parse_box_expr(lo))
}
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,8 @@ macro_rules! uint_impl {
}

/// Calculates the smallest value greater than or equal to `self` that
/// is a multiple of `rhs`. If `rhs` is negative,
/// is a multiple of `rhs`. Returns `None` is `rhs` is zero or the
/// operation would result in overflow.
///
/// # Examples
///
Expand Down
1 change: 1 addition & 0 deletions library/core/src/ops/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
/// ```
#[lang = "not"]
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(alias = "!")]
pub trait Not {
/// The resulting type after applying the `!` operator.
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
16 changes: 8 additions & 8 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ impl<T> Option<T> {
// Entry-like operations to insert a value and return a reference
/////////////////////////////////////////////////////////////////////////

/// Inserts `value` into the option then returns a mutable reference to it.
/// Inserts `value` into the option, then returns a mutable reference to it.
///
/// If the option already contains a value, the old value is dropped.
///
Expand Down Expand Up @@ -1397,7 +1397,7 @@ impl<T> Option<T> {
}

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

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

#[stable(since = "1.12.0", feature = "option_from")]
impl<T> From<T> for Option<T> {
/// Copies `val` into a new `Some`.
/// Moves `val` into a new [`Some`].
///
/// # Examples
///
Expand Down Expand Up @@ -1942,8 +1942,8 @@ unsafe impl<A> TrustedLen for IntoIter<A> {}
impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
/// Takes each element in the [`Iterator`]: if it is [`None`][Option::None],
/// no further elements are taken, and the [`None`][Option::None] is
/// returned. Should no [`None`][Option::None] occur, a container with the
/// values of each [`Option`] is returned.
/// returned. Should no [`None`][Option::None] occur, a container of type
/// `V` containing the values of each [`Option`] is returned.
///
/// # Examples
///
Expand Down Expand Up @@ -2039,7 +2039,7 @@ impl<T> ops::FromResidual for Option<T> {
}

impl<T> Option<Option<T>> {
/// Converts from `Option<Option<T>>` to `Option<T>`
/// Converts from `Option<Option<T>>` to `Option<T>`.
///
/// # Examples
///
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ mod break_keyword {}

#[doc(keyword = "const")]
//
/// Compile-time constants and compile-time evaluable functions.
/// Compile-time constants, compile-time evaluable functions, and raw pointers.
///
/// ## Compile-time constants
///
Expand Down
7 changes: 5 additions & 2 deletions library/std/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,11 @@ mod prim_char {}
#[stable(feature = "rust1", since = "1.0.0")]
mod prim_unit {}

#[doc(alias = "ptr")]
#[doc(primitive = "pointer")]
#[doc(alias = "ptr")]
#[doc(alias = "*")]
#[doc(alias = "*const")]
#[doc(alias = "*mut")]
//
/// Raw, unsafe pointers, `*const T`, and `*mut T`.
///
Expand Down Expand Up @@ -502,10 +505,10 @@ mod prim_unit {}
#[stable(feature = "rust1", since = "1.0.0")]
mod prim_pointer {}

#[doc(primitive = "array")]
#[doc(alias = "[]")]
#[doc(alias = "[T;N]")] // unfortunately, rustdoc doesn't have fuzzy search for aliases
#[doc(alias = "[T; N]")]
#[doc(primitive = "array")]
/// A fixed-size array, denoted `[T; N]`, for the element type, `T`, and the
/// non-negative compile-time constant size, `N`.
///
Expand Down
57 changes: 46 additions & 11 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ use rustc_hir as hir;
use rustc_hir::def::CtorKind;
use rustc_hir::def_id::DefId;
use rustc_middle::middle::stability;
use rustc_middle::span_bug;
use rustc_middle::ty::layout::LayoutError;
use rustc_middle::ty::TyCtxt;
use rustc_middle::ty::{Adt, TyCtxt};
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_target::abi::{Layout, Primitive, TagEncoding, Variants};

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

fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
fn write_size_of_layout(w: &mut Buffer, layout: &Layout, tag_size: u64) {
if layout.abi.is_unsized() {
write!(w, "(unsized)");
} else {
let bytes = layout.size.bytes() - tag_size;
write!(w, "{size} byte{pl}", size = bytes, pl = if bytes == 1 { "" } else { "s" },);
}
}

if !cx.shared.show_type_layout {
return;
}
Expand All @@ -1642,16 +1653,40 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
<a href=\"https://doc.rust-lang.org/reference/type-layout.html\">“Type Layout”</a> \
chapter for details on type layout guarantees.</p></div>"
);
if ty_layout.layout.abi.is_unsized() {
writeln!(w, "<p><strong>Size:</strong> (unsized)</p>");
} else {
let bytes = ty_layout.layout.size.bytes();
writeln!(
w,
"<p><strong>Size:</strong> {size} byte{pl}</p>",
size = bytes,
pl = if bytes == 1 { "" } else { "s" },
);
w.write_str("<p><strong>Size:</strong> ");
write_size_of_layout(w, ty_layout.layout, 0);
writeln!(w, "</p>");
if let Variants::Multiple { variants, tag, tag_encoding, .. } =
&ty_layout.layout.variants
{
if !variants.is_empty() {
w.write_str(
"<p><strong>Size for each variant:</strong></p>\
<ul>",
);

let adt = if let Adt(adt, _) = ty_layout.ty.kind() {
adt
} else {
span_bug!(tcx.def_span(ty_def_id), "not an adt")
};

let tag_size = if let TagEncoding::Niche { .. } = tag_encoding {
0
} else if let Primitive::Int(i, _) = tag.value {
i.size().bytes()
} else {
span_bug!(tcx.def_span(ty_def_id), "tag is neither niche nor int")
};

for (index, layout) in variants.iter_enumerated() {
let ident = adt.variants[index].ident;
write!(w, "<li><code>{name}</code>: ", name = ident);
write_size_of_layout(w, layout, tag_size);
writeln!(w, "</li>");
}
w.write_str("</ul>");
}
}
}
// This kind of layout error can occur with valid code, e.g. if you try to
Expand Down
18 changes: 18 additions & 0 deletions src/test/rustdoc/type-layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,21 @@ pub struct Unsized([u8]);

// @!has type_layout/trait.MyTrait.html 'Size: '
pub trait MyTrait {}

// @has type_layout/enum.Variants.html 'Size: '
// @has - '2 bytes'
// @has - '<code>A</code>: 0 bytes'
// @has - '<code>B</code>: 1 byte'
pub enum Variants {
A,
B(u8),
}

// @has type_layout/enum.WithNiche.html 'Size: '
// @has - //p '4 bytes'
// @has - '<code>None</code>: 0 bytes'
// @has - '<code>Some</code>: 4 bytes'
pub enum WithNiche {
None,
Some(std::num::NonZeroU32),
}
10 changes: 8 additions & 2 deletions src/test/ui/associated-types/issue-36499.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
error: expected expression, found `+`
error: leading `+` is not supported
--> $DIR/issue-36499.rs:4:9
|
LL | 2 + +2;
| ^ expected expression
| ^ unexpected `+`
|
help: try removing the `+`
|
LL - 2 + +2;
LL + 2 + 2;
|

error: aborting due to previous error

18 changes: 18 additions & 0 deletions src/test/ui/consts/issue-88649.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// check-pass
#![crate_type = "lib"]

enum Foo {
Variant1(bool),
Variant2(bool),
}

const _: () = {
let mut n = 0;
while n < 2 {
match Foo::Variant1(true) {
Foo::Variant1(x) | Foo::Variant2(x) if x => {}
_ => {}
}
n += 1;
}
};
30 changes: 30 additions & 0 deletions src/test/ui/lifetimes/lifetime-errors/issue_74400.nll.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
error[E0310]: the parameter type `T` may not live long enough
--> $DIR/issue_74400.rs:12:5
|
LL | f(data, identity)
| ^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `T: 'static`...

error[E0308]: mismatched types
--> $DIR/issue_74400.rs:12:5
|
LL | f(data, identity)
| ^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected type `for<'r> Fn<(&'r T,)>`
found type `Fn<(&T,)>`

error: implementation of `FnOnce` is not general enough
--> $DIR/issue_74400.rs:12:5
|
LL | f(data, identity)
| ^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
= note: `fn(&'2 T) -> &'2 T {identity::<&'2 T>}` must implement `FnOnce<(&'1 T,)>`, for any lifetime `'1`...
= note: ...but it actually implements `FnOnce<(&'2 T,)>`, for some specific lifetime `'2`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0308, E0310.
For more information about an error, try `rustc --explain E0308`.
13 changes: 13 additions & 0 deletions src/test/ui/lifetimes/lifetime-errors/issue_74400.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Regression test for #74400: Type mismatch in function arguments E0631, E0271 are falsely
//! recognized as E0308 mismatched types.
use std::convert::identity;

fn main() {}

fn f<T, S>(data: &[T], key: impl Fn(&T) -> S) {
}

fn g<T>(data: &[T]) {
f(data, identity) //~ ERROR implementation of `FnOnce` is not general
}
Loading

0 comments on commit 47ae8de

Please sign in to comment.