Auto merge of #111311 - JohnTitor:rollup-vfpjm0d, r=JohnTitor

Rollup of 7 pull requests

Successful merges:

 - #105583 (Operand::extract_field: only cast llval if it's a pointer and replace bitcast w/ pointercast.)
 - #110094 (clean up `transmute`s in `core`)
 - #111150 (added TraitAlias to check_item() for missing_docs)
 - #111293 (rustc --explain E0726 - grammar fixing (it's => its + add a `the` where it felt right to do so))
 - #111300 (Emit while_true lint spanning the entire loop condition)
 - #111301 (Remove calls to `mem::forget` and `mem::replace` in `Option::get_or_insert_with`.)
 - #111303 (update Rust Unstable Book docs for `--extern force`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2023-05-07 05:20:29 +00:00
commit 8cc75b56a6
10 changed files with 113 additions and 74 deletions

View File

@ -2,6 +2,7 @@ use super::place::PlaceRef;
use super::{FunctionCx, LocalRef}; use super::{FunctionCx, LocalRef};
use crate::base; use crate::base;
use crate::common::TypeKind;
use crate::glue; use crate::glue;
use crate::traits::*; use crate::traits::*;
use crate::MemFlags; use crate::MemFlags;
@ -236,19 +237,47 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
}; };
match (&mut val, field.abi) { match (&mut val, field.abi) {
(OperandValue::Immediate(llval), _) => { (
OperandValue::Immediate(llval),
Abi::Scalar(_) | Abi::ScalarPair(..) | Abi::Vector { .. },
) => {
// Bools in union fields needs to be truncated. // Bools in union fields needs to be truncated.
*llval = bx.to_immediate(*llval, field); *llval = bx.to_immediate(*llval, field);
// HACK(eddyb) have to bitcast pointers until LLVM removes pointee types. // HACK(eddyb) have to bitcast pointers until LLVM removes pointee types.
*llval = bx.bitcast(*llval, bx.cx().immediate_backend_type(field)); let ty = bx.cx().immediate_backend_type(field);
if bx.type_kind(ty) == TypeKind::Pointer {
*llval = bx.pointercast(*llval, ty);
}
} }
(OperandValue::Pair(a, b), Abi::ScalarPair(a_abi, b_abi)) => { (OperandValue::Pair(a, b), Abi::ScalarPair(a_abi, b_abi)) => {
// Bools in union fields needs to be truncated. // Bools in union fields needs to be truncated.
*a = bx.to_immediate_scalar(*a, a_abi); *a = bx.to_immediate_scalar(*a, a_abi);
*b = bx.to_immediate_scalar(*b, b_abi); *b = bx.to_immediate_scalar(*b, b_abi);
// HACK(eddyb) have to bitcast pointers until LLVM removes pointee types. // HACK(eddyb) have to bitcast pointers until LLVM removes pointee types.
*a = bx.bitcast(*a, bx.cx().scalar_pair_element_backend_type(field, 0, true)); let a_ty = bx.cx().scalar_pair_element_backend_type(field, 0, true);
*b = bx.bitcast(*b, bx.cx().scalar_pair_element_backend_type(field, 1, true)); let b_ty = bx.cx().scalar_pair_element_backend_type(field, 1, true);
if bx.type_kind(a_ty) == TypeKind::Pointer {
*a = bx.pointercast(*a, a_ty);
}
if bx.type_kind(b_ty) == TypeKind::Pointer {
*b = bx.pointercast(*b, b_ty);
}
}
// Newtype vector of array, e.g. #[repr(simd)] struct S([i32; 4]);
(OperandValue::Immediate(llval), Abi::Aggregate { sized: true }) => {
assert!(matches!(self.layout.abi, Abi::Vector { .. }));
let llty = bx.cx().backend_type(self.layout);
let llfield_ty = bx.cx().backend_type(field);
// Can't bitcast an aggregate, so round trip through memory.
let lltemp = bx.alloca(llfield_ty, field.align.abi);
let llptr = bx.pointercast(lltemp, bx.cx().type_ptr_to(llty));
bx.store(*llval, llptr, field.align.abi);
*llval = bx.load(llfield_ty, lltemp, field.align.abi);
}
(OperandValue::Immediate(_), Abi::Uninhabited | Abi::Aggregate { sized: false }) => {
bug!()
} }
(OperandValue::Pair(..), _) => bug!(), (OperandValue::Pair(..), _) => bug!(),
(OperandValue::Ref(..), _) => bug!(), (OperandValue::Ref(..), _) => bug!(),

View File

@ -25,8 +25,8 @@ block_on(future);
Specify desired lifetime of parameter `content` or indicate the anonymous Specify desired lifetime of parameter `content` or indicate the anonymous
lifetime like `content: Content<'_>`. The anonymous lifetime tells the Rust lifetime like `content: Content<'_>`. The anonymous lifetime tells the Rust
compiler that `content` is only needed until create function is done with compiler that `content` is only needed until the `create` function is done with
it's execution. its execution.
The `implicit elision` meaning the omission of suggested lifetime that is The `implicit elision` meaning the omission of suggested lifetime that is
`pub async fn create<'a>(content: Content<'a>) {}` is not allowed here as `pub async fn create<'a>(content: Content<'a>) {}` is not allowed here as

View File

@ -117,8 +117,7 @@ impl EarlyLintPass for WhileTrue {
#[inline] #[inline]
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) { fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
if let ast::ExprKind::While(cond, _, label) = &e.kind if let ast::ExprKind::While(cond, _, label) = &e.kind
&& let cond = pierce_parens(cond) && let ast::ExprKind::Lit(token_lit) = pierce_parens(cond).kind
&& let ast::ExprKind::Lit(token_lit) = cond.kind
&& let token::Lit { kind: token::Bool, symbol: kw::True, .. } = token_lit && let token::Lit { kind: token::Bool, symbol: kw::True, .. } = token_lit
&& !cond.span.from_expansion() && !cond.span.from_expansion()
{ {
@ -547,32 +546,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
} }
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) { fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
match it.kind { // Previously the Impl and Use types have been excluded from missing docs,
hir::ItemKind::Trait(..) => { // so we will continue to exclude them for compatibility
// Issue #11592: traits are always considered exported, even when private. if let hir::ItemKind::Impl(..) | hir::ItemKind::Use(..) = it.kind {
if cx.tcx.visibility(it.owner_id)
== ty::Visibility::Restricted(
cx.tcx.parent_module_from_def_id(it.owner_id.def_id).to_def_id(),
)
{
return; return;
} }
}
hir::ItemKind::TyAlias(..)
| hir::ItemKind::Fn(..)
| hir::ItemKind::Macro(..)
| hir::ItemKind::Mod(..)
| hir::ItemKind::Enum(..)
| hir::ItemKind::Struct(..)
| hir::ItemKind::Union(..)
| hir::ItemKind::Const(..)
| hir::ItemKind::Static(..) => {}
_ => return,
};
let (article, desc) = cx.tcx.article_and_description(it.owner_id.to_def_id()); let (article, desc) = cx.tcx.article_and_description(it.owner_id.to_def_id());
self.check_missing_docs_attrs(cx, it.owner_id.def_id, article, desc); self.check_missing_docs_attrs(cx, it.owner_id.def_id, article, desc);
} }

View File

@ -1287,7 +1287,7 @@ impl<T, const N: usize> MaybeUninit<[T; N]> {
#[inline] #[inline]
pub const fn transpose(self) -> [MaybeUninit<T>; N] { pub const fn transpose(self) -> [MaybeUninit<T>; N] {
// SAFETY: T and MaybeUninit<T> have the same layout // SAFETY: T and MaybeUninit<T> have the same layout
unsafe { super::transmute_copy(&ManuallyDrop::new(self)) } unsafe { intrinsics::transmute_unchecked(self) }
} }
} }
@ -1307,6 +1307,6 @@ impl<T, const N: usize> [MaybeUninit<T>; N] {
#[inline] #[inline]
pub const fn transpose(self) -> MaybeUninit<[T; N]> { pub const fn transpose(self) -> MaybeUninit<[T; N]> {
// SAFETY: T and MaybeUninit<T> have the same layout // SAFETY: T and MaybeUninit<T> have the same layout
unsafe { super::transmute_copy(&ManuallyDrop::new(self)) } unsafe { intrinsics::transmute_unchecked(self) }
} }
} }

View File

@ -1641,10 +1641,8 @@ impl<T> Option<T> {
where where
F: FnOnce() -> T, F: FnOnce() -> T,
{ {
if let None = *self { if let None = self {
// the compiler isn't smart enough to know that we are not dropping a `T` *self = Some(f());
// here and wants us to ensure `T` can be dropped at compile time.
mem::forget(mem::replace(self, Some(f())))
} }
// SAFETY: a `None` variant for `self` would have been replaced by a `Some` // SAFETY: a `None` variant for `self` would have been replaced by a `Some`

View File

@ -1,7 +1,6 @@
// See src/libstd/primitive_docs.rs for documentation. // See src/libstd/primitive_docs.rs for documentation.
use crate::cmp::Ordering::{self, *}; use crate::cmp::Ordering::{self, *};
use crate::mem::transmute;
// Recursive macro for implementing n-ary tuple functions and operations // Recursive macro for implementing n-ary tuple functions and operations
// //
@ -142,15 +141,12 @@ macro_rules! maybe_tuple_doc {
#[inline] #[inline]
const fn ordering_is_some(c: Option<Ordering>, x: Ordering) -> bool { const fn ordering_is_some(c: Option<Ordering>, x: Ordering) -> bool {
// FIXME: Just use `==` once that's const-stable on `Option`s. // FIXME: Just use `==` once that's const-stable on `Option`s.
// This isn't using `match` because that optimizes worse due to // This is mapping `None` to 2 and then doing the comparison afterwards
// making a two-step check (`Some` *then* the inner value). // because it optimizes better (`None::<Ordering>` is represented as 2).
x as i8
// SAFETY: There's no public guarantee for `Option<Ordering>`, == match c {
// but we're core so we know that it's definitely a byte. Some(c) => c as i8,
unsafe { None => 2,
let c: i8 = transmute(c);
let x: i8 = transmute(Some(x));
c == x
} }
} }

View File

@ -4,6 +4,7 @@
* Tracking issue for `noprelude`: [#98398](https://github.com/rust-lang/rust/issues/98398) * Tracking issue for `noprelude`: [#98398](https://github.com/rust-lang/rust/issues/98398)
* Tracking issue for `priv`: [#98399](https://github.com/rust-lang/rust/issues/98399) * Tracking issue for `priv`: [#98399](https://github.com/rust-lang/rust/issues/98399)
* Tracking issue for `nounused`: [#98400](https://github.com/rust-lang/rust/issues/98400) * Tracking issue for `nounused`: [#98400](https://github.com/rust-lang/rust/issues/98400)
* Tracking issue for `force`: [#111302](https://github.com/rust-lang/rust/issues/111302)
The behavior of the `--extern` flag can be modified with `noprelude`, `priv` or `nounused` options. The behavior of the `--extern` flag can be modified with `noprelude`, `priv` or `nounused` options.
@ -25,3 +26,4 @@ To use multiple options, separate them with a comma:
This is used by the [build-std project](https://github.com/rust-lang/wg-cargo-std-aware/) to simulate compatibility with sysroot-only crates. This is used by the [build-std project](https://github.com/rust-lang/wg-cargo-std-aware/) to simulate compatibility with sysroot-only crates.
* `priv`: Mark the crate as a private dependency for the [`exported_private_dependencies`](../../rustc/lints/listing/warn-by-default.html#exported-private-dependencies) lint. * `priv`: Mark the crate as a private dependency for the [`exported_private_dependencies`](../../rustc/lints/listing/warn-by-default.html#exported-private-dependencies) lint.
* `nounused`: Suppress [`unused-crate-dependencies`](../../rustc/lints/listing/allowed-by-default.html#unused-crate-dependencies) warnings for the crate. * `nounused`: Suppress [`unused-crate-dependencies`](../../rustc/lints/listing/allowed-by-default.html#unused-crate-dependencies) warnings for the crate.
* `force`: Resolve the crate as if it is used, even if it is not used. This can be used to satisfy compilation session requirements like the presence of an allocator or panic handler.

View File

@ -3,6 +3,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
#![allow(dead_code)] #![allow(dead_code)]
#![feature(associated_type_defaults, extern_types)] #![feature(associated_type_defaults, extern_types)]
#![feature(trait_alias)]
//! Some garbage docs for the crate here //! Some garbage docs for the crate here
#![doc="More garbage"] #![doc="More garbage"]
@ -202,4 +203,6 @@ extern "C" {
//~^ ERROR: missing documentation for a foreign type //~^ ERROR: missing documentation for a foreign type
} }
pub trait T = Sync; //~ ERROR: missing documentation for a trait alias
fn main() {} fn main() {}

View File

@ -1,5 +1,5 @@
error: missing documentation for a type alias error: missing documentation for a type alias
--> $DIR/lint-missing-doc.rs:11:1 --> $DIR/lint-missing-doc.rs:12:1
| |
LL | pub type PubTypedef = String; LL | pub type PubTypedef = String;
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
@ -11,142 +11,148 @@ LL | #![deny(missing_docs)]
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: missing documentation for a struct error: missing documentation for a struct
--> $DIR/lint-missing-doc.rs:18:1 --> $DIR/lint-missing-doc.rs:19:1
| |
LL | pub struct PubFoo { LL | pub struct PubFoo {
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
error: missing documentation for a struct field error: missing documentation for a struct field
--> $DIR/lint-missing-doc.rs:19:5 --> $DIR/lint-missing-doc.rs:20:5
| |
LL | pub a: isize, LL | pub a: isize,
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: missing documentation for a module error: missing documentation for a module
--> $DIR/lint-missing-doc.rs:30:1 --> $DIR/lint-missing-doc.rs:31:1
| |
LL | pub mod pub_module_no_dox {} LL | pub mod pub_module_no_dox {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function error: missing documentation for a function
--> $DIR/lint-missing-doc.rs:34:1 --> $DIR/lint-missing-doc.rs:35:1
| |
LL | pub fn foo2() {} LL | pub fn foo2() {}
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: missing documentation for a trait error: missing documentation for a trait
--> $DIR/lint-missing-doc.rs:52:1 --> $DIR/lint-missing-doc.rs:53:1
| |
LL | pub trait C { LL | pub trait C {
| ^^^^^^^^^^^ | ^^^^^^^^^^^
error: missing documentation for a method error: missing documentation for a method
--> $DIR/lint-missing-doc.rs:53:5 --> $DIR/lint-missing-doc.rs:54:5
| |
LL | fn foo(&self); LL | fn foo(&self);
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
error: missing documentation for a method error: missing documentation for a method
--> $DIR/lint-missing-doc.rs:54:5 --> $DIR/lint-missing-doc.rs:55:5
| |
LL | fn foo_with_impl(&self) {} LL | fn foo_with_impl(&self) {}
| ^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for an associated function error: missing documentation for an associated function
--> $DIR/lint-missing-doc.rs:55:5 --> $DIR/lint-missing-doc.rs:56:5
| |
LL | fn foo_no_self(); LL | fn foo_no_self();
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
error: missing documentation for an associated function error: missing documentation for an associated function
--> $DIR/lint-missing-doc.rs:56:5 --> $DIR/lint-missing-doc.rs:57:5
| |
LL | fn foo_no_self_with_impl() {} LL | fn foo_no_self_with_impl() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for an associated type error: missing documentation for an associated type
--> $DIR/lint-missing-doc.rs:66:5 --> $DIR/lint-missing-doc.rs:67:5
| |
LL | type AssociatedType; LL | type AssociatedType;
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
error: missing documentation for an associated type error: missing documentation for an associated type
--> $DIR/lint-missing-doc.rs:67:5 --> $DIR/lint-missing-doc.rs:68:5
| |
LL | type AssociatedTypeDef = Self; LL | type AssociatedTypeDef = Self;
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for an associated function error: missing documentation for an associated function
--> $DIR/lint-missing-doc.rs:83:5 --> $DIR/lint-missing-doc.rs:84:5
| |
LL | pub fn foo() {} LL | pub fn foo() {}
| ^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: missing documentation for an enum error: missing documentation for an enum
--> $DIR/lint-missing-doc.rs:120:1 --> $DIR/lint-missing-doc.rs:121:1
| |
LL | pub enum PubBaz { LL | pub enum PubBaz {
| ^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^
error: missing documentation for a variant error: missing documentation for a variant
--> $DIR/lint-missing-doc.rs:121:5 --> $DIR/lint-missing-doc.rs:122:5
| |
LL | PubBazA { LL | PubBazA {
| ^^^^^^^ | ^^^^^^^
error: missing documentation for a struct field error: missing documentation for a struct field
--> $DIR/lint-missing-doc.rs:122:9 --> $DIR/lint-missing-doc.rs:123:9
| |
LL | a: isize, LL | a: isize,
| ^^^^^^^^ | ^^^^^^^^
error: missing documentation for a constant error: missing documentation for a constant
--> $DIR/lint-missing-doc.rs:153:1 --> $DIR/lint-missing-doc.rs:154:1
| |
LL | pub const FOO4: u32 = 0; LL | pub const FOO4: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
error: missing documentation for a static error: missing documentation for a static
--> $DIR/lint-missing-doc.rs:163:1 --> $DIR/lint-missing-doc.rs:164:1
| |
LL | pub static BAR4: u32 = 0; LL | pub static BAR4: u32 = 0;
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function error: missing documentation for a function
--> $DIR/lint-missing-doc.rs:169:5 --> $DIR/lint-missing-doc.rs:170:5
| |
LL | pub fn undocumented1() {} LL | pub fn undocumented1() {}
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function error: missing documentation for a function
--> $DIR/lint-missing-doc.rs:170:5 --> $DIR/lint-missing-doc.rs:171:5
| |
LL | pub fn undocumented2() {} LL | pub fn undocumented2() {}
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function error: missing documentation for a function
--> $DIR/lint-missing-doc.rs:176:9 --> $DIR/lint-missing-doc.rs:177:9
| |
LL | pub fn also_undocumented1() {} LL | pub fn also_undocumented1() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a function error: missing documentation for a function
--> $DIR/lint-missing-doc.rs:191:5 --> $DIR/lint-missing-doc.rs:192:5
| |
LL | pub fn extern_fn_undocumented(f: f32) -> f32; LL | pub fn extern_fn_undocumented(f: f32) -> f32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a static error: missing documentation for a static
--> $DIR/lint-missing-doc.rs:196:5 --> $DIR/lint-missing-doc.rs:197:5
| |
LL | pub static EXTERN_STATIC_UNDOCUMENTED: u8; LL | pub static EXTERN_STATIC_UNDOCUMENTED: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: missing documentation for a foreign type error: missing documentation for a foreign type
--> $DIR/lint-missing-doc.rs:201:5 --> $DIR/lint-missing-doc.rs:202:5
| |
LL | pub type ExternTyUndocumented; LL | pub type ExternTyUndocumented;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 24 previous errors error: missing documentation for a trait alias
--> $DIR/lint-missing-doc.rs:206:1
|
LL | pub trait T = Sync;
| ^^^^^^^^^^^
error: aborting due to 25 previous errors

View File

@ -0,0 +1,25 @@
// run-pass
// compile-flags: -O -Zverify-llvm-ir
#![feature(repr_simd)]
#![feature(platform_intrinsics)]
#[allow(non_camel_case_types)]
#[derive(Clone, Copy)]
#[repr(simd)]
struct i32x4([i32; 4]);
extern "platform-intrinsic" {
pub(crate) fn simd_add<T>(x: T, y: T) -> T;
}
#[inline(always)]
fn to_array(a: i32x4) -> [i32; 4] {
a.0
}
fn main() {
let a = i32x4([1, 2, 3, 4]);
let b = unsafe { simd_add(a, a) };
assert_eq!(to_array(b), [2, 4, 6, 8]);
}