Skip to content

Commit 8cc75b5

Browse files
committed
Auto merge of rust-lang#111311 - JohnTitor:rollup-vfpjm0d, r=JohnTitor
Rollup of 7 pull requests Successful merges: - rust-lang#105583 (Operand::extract_field: only cast llval if it's a pointer and replace bitcast w/ pointercast.) - rust-lang#110094 (clean up `transmute`s in `core`) - rust-lang#111150 (added TraitAlias to check_item() for missing_docs) - rust-lang#111293 (rustc --explain E0726 - grammar fixing (it's => its + add a `the` where it felt right to do so)) - rust-lang#111300 (Emit while_true lint spanning the entire loop condition) - rust-lang#111301 (Remove calls to `mem::forget` and `mem::replace` in `Option::get_or_insert_with`.) - rust-lang#111303 (update Rust Unstable Book docs for `--extern force`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 70a779c + 8372eae commit 8cc75b5

File tree

10 files changed

+113
-74
lines changed

10 files changed

+113
-74
lines changed

compiler/rustc_codegen_ssa/src/mir/operand.rs

+33-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::place::PlaceRef;
22
use super::{FunctionCx, LocalRef};
33

44
use crate::base;
5+
use crate::common::TypeKind;
56
use crate::glue;
67
use crate::traits::*;
78
use crate::MemFlags;
@@ -236,19 +237,47 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
236237
};
237238

238239
match (&mut val, field.abi) {
239-
(OperandValue::Immediate(llval), _) => {
240+
(
241+
OperandValue::Immediate(llval),
242+
Abi::Scalar(_) | Abi::ScalarPair(..) | Abi::Vector { .. },
243+
) => {
240244
// Bools in union fields needs to be truncated.
241245
*llval = bx.to_immediate(*llval, field);
242246
// HACK(eddyb) have to bitcast pointers until LLVM removes pointee types.
243-
*llval = bx.bitcast(*llval, bx.cx().immediate_backend_type(field));
247+
let ty = bx.cx().immediate_backend_type(field);
248+
if bx.type_kind(ty) == TypeKind::Pointer {
249+
*llval = bx.pointercast(*llval, ty);
250+
}
244251
}
245252
(OperandValue::Pair(a, b), Abi::ScalarPair(a_abi, b_abi)) => {
246253
// Bools in union fields needs to be truncated.
247254
*a = bx.to_immediate_scalar(*a, a_abi);
248255
*b = bx.to_immediate_scalar(*b, b_abi);
249256
// HACK(eddyb) have to bitcast pointers until LLVM removes pointee types.
250-
*a = bx.bitcast(*a, bx.cx().scalar_pair_element_backend_type(field, 0, true));
251-
*b = bx.bitcast(*b, bx.cx().scalar_pair_element_backend_type(field, 1, true));
257+
let a_ty = bx.cx().scalar_pair_element_backend_type(field, 0, true);
258+
let b_ty = bx.cx().scalar_pair_element_backend_type(field, 1, true);
259+
if bx.type_kind(a_ty) == TypeKind::Pointer {
260+
*a = bx.pointercast(*a, a_ty);
261+
}
262+
if bx.type_kind(b_ty) == TypeKind::Pointer {
263+
*b = bx.pointercast(*b, b_ty);
264+
}
265+
}
266+
// Newtype vector of array, e.g. #[repr(simd)] struct S([i32; 4]);
267+
(OperandValue::Immediate(llval), Abi::Aggregate { sized: true }) => {
268+
assert!(matches!(self.layout.abi, Abi::Vector { .. }));
269+
270+
let llty = bx.cx().backend_type(self.layout);
271+
let llfield_ty = bx.cx().backend_type(field);
272+
273+
// Can't bitcast an aggregate, so round trip through memory.
274+
let lltemp = bx.alloca(llfield_ty, field.align.abi);
275+
let llptr = bx.pointercast(lltemp, bx.cx().type_ptr_to(llty));
276+
bx.store(*llval, llptr, field.align.abi);
277+
*llval = bx.load(llfield_ty, lltemp, field.align.abi);
278+
}
279+
(OperandValue::Immediate(_), Abi::Uninhabited | Abi::Aggregate { sized: false }) => {
280+
bug!()
252281
}
253282
(OperandValue::Pair(..), _) => bug!(),
254283
(OperandValue::Ref(..), _) => bug!(),

compiler/rustc_error_codes/src/error_codes/E0726.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ block_on(future);
2525

2626
Specify desired lifetime of parameter `content` or indicate the anonymous
2727
lifetime like `content: Content<'_>`. The anonymous lifetime tells the Rust
28-
compiler that `content` is only needed until create function is done with
29-
it's execution.
28+
compiler that `content` is only needed until the `create` function is done with
29+
its execution.
3030

3131
The `implicit elision` meaning the omission of suggested lifetime that is
3232
`pub async fn create<'a>(content: Content<'a>) {}` is not allowed here as

compiler/rustc_lint/src/builtin.rs

+6-26
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ impl EarlyLintPass for WhileTrue {
117117
#[inline]
118118
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
119119
if let ast::ExprKind::While(cond, _, label) = &e.kind
120-
&& let cond = pierce_parens(cond)
121-
&& let ast::ExprKind::Lit(token_lit) = cond.kind
120+
&& let ast::ExprKind::Lit(token_lit) = pierce_parens(cond).kind
122121
&& let token::Lit { kind: token::Bool, symbol: kw::True, .. } = token_lit
123122
&& !cond.span.from_expansion()
124123
{
@@ -547,32 +546,13 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
547546
}
548547

549548
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
550-
match it.kind {
551-
hir::ItemKind::Trait(..) => {
552-
// Issue #11592: traits are always considered exported, even when private.
553-
if cx.tcx.visibility(it.owner_id)
554-
== ty::Visibility::Restricted(
555-
cx.tcx.parent_module_from_def_id(it.owner_id.def_id).to_def_id(),
556-
)
557-
{
558-
return;
559-
}
560-
}
561-
hir::ItemKind::TyAlias(..)
562-
| hir::ItemKind::Fn(..)
563-
| hir::ItemKind::Macro(..)
564-
| hir::ItemKind::Mod(..)
565-
| hir::ItemKind::Enum(..)
566-
| hir::ItemKind::Struct(..)
567-
| hir::ItemKind::Union(..)
568-
| hir::ItemKind::Const(..)
569-
| hir::ItemKind::Static(..) => {}
570-
571-
_ => return,
572-
};
549+
// Previously the Impl and Use types have been excluded from missing docs,
550+
// so we will continue to exclude them for compatibility
551+
if let hir::ItemKind::Impl(..) | hir::ItemKind::Use(..) = it.kind {
552+
return;
553+
}
573554

574555
let (article, desc) = cx.tcx.article_and_description(it.owner_id.to_def_id());
575-
576556
self.check_missing_docs_attrs(cx, it.owner_id.def_id, article, desc);
577557
}
578558

library/core/src/mem/maybe_uninit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ impl<T, const N: usize> MaybeUninit<[T; N]> {
12871287
#[inline]
12881288
pub const fn transpose(self) -> [MaybeUninit<T>; N] {
12891289
// SAFETY: T and MaybeUninit<T> have the same layout
1290-
unsafe { super::transmute_copy(&ManuallyDrop::new(self)) }
1290+
unsafe { intrinsics::transmute_unchecked(self) }
12911291
}
12921292
}
12931293

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

library/core/src/option.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1641,10 +1641,8 @@ impl<T> Option<T> {
16411641
where
16421642
F: FnOnce() -> T,
16431643
{
1644-
if let None = *self {
1645-
// the compiler isn't smart enough to know that we are not dropping a `T`
1646-
// here and wants us to ensure `T` can be dropped at compile time.
1647-
mem::forget(mem::replace(self, Some(f())))
1644+
if let None = self {
1645+
*self = Some(f());
16481646
}
16491647

16501648
// SAFETY: a `None` variant for `self` would have been replaced by a `Some`

library/core/src/tuple.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// See src/libstd/primitive_docs.rs for documentation.
22

33
use crate::cmp::Ordering::{self, *};
4-
use crate::mem::transmute;
54

65
// Recursive macro for implementing n-ary tuple functions and operations
76
//
@@ -142,16 +141,13 @@ macro_rules! maybe_tuple_doc {
142141
#[inline]
143142
const fn ordering_is_some(c: Option<Ordering>, x: Ordering) -> bool {
144143
// FIXME: Just use `==` once that's const-stable on `Option`s.
145-
// This isn't using `match` because that optimizes worse due to
146-
// making a two-step check (`Some` *then* the inner value).
147-
148-
// SAFETY: There's no public guarantee for `Option<Ordering>`,
149-
// but we're core so we know that it's definitely a byte.
150-
unsafe {
151-
let c: i8 = transmute(c);
152-
let x: i8 = transmute(Some(x));
153-
c == x
154-
}
144+
// This is mapping `None` to 2 and then doing the comparison afterwards
145+
// because it optimizes better (`None::<Ordering>` is represented as 2).
146+
x as i8
147+
== match c {
148+
Some(c) => c as i8,
149+
None => 2,
150+
}
155151
}
156152

157153
// Constructs an expression that performs a lexical ordering using method `$rel`.

src/doc/unstable-book/src/compiler-flags/extern-options.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Tracking issue for `noprelude`: [#98398](https://github.com/rust-lang/rust/issues/98398)
55
* Tracking issue for `priv`: [#98399](https://github.com/rust-lang/rust/issues/98399)
66
* Tracking issue for `nounused`: [#98400](https://github.com/rust-lang/rust/issues/98400)
7+
* Tracking issue for `force`: [#111302](https://github.com/rust-lang/rust/issues/111302)
78

89
The behavior of the `--extern` flag can be modified with `noprelude`, `priv` or `nounused` options.
910

@@ -25,3 +26,4 @@ To use multiple options, separate them with a comma:
2526
This is used by the [build-std project](https://github.com/rust-lang/wg-cargo-std-aware/) to simulate compatibility with sysroot-only crates.
2627
* `priv`: Mark the crate as a private dependency for the [`exported_private_dependencies`](../../rustc/lints/listing/warn-by-default.html#exported-private-dependencies) lint.
2728
* `nounused`: Suppress [`unused-crate-dependencies`](../../rustc/lints/listing/allowed-by-default.html#unused-crate-dependencies) warnings for the crate.
29+
* `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.

tests/ui/lint/lint-missing-doc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![deny(missing_docs)]
44
#![allow(dead_code)]
55
#![feature(associated_type_defaults, extern_types)]
6+
#![feature(trait_alias)]
67

78
//! Some garbage docs for the crate here
89
#![doc="More garbage"]
@@ -202,4 +203,6 @@ extern "C" {
202203
//~^ ERROR: missing documentation for a foreign type
203204
}
204205

206+
pub trait T = Sync; //~ ERROR: missing documentation for a trait alias
207+
205208
fn main() {}

tests/ui/lint/lint-missing-doc.stderr

+31-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: missing documentation for a type alias
2-
--> $DIR/lint-missing-doc.rs:11:1
2+
--> $DIR/lint-missing-doc.rs:12:1
33
|
44
LL | pub type PubTypedef = String;
55
| ^^^^^^^^^^^^^^^^^^^
@@ -11,142 +11,148 @@ LL | #![deny(missing_docs)]
1111
| ^^^^^^^^^^^^
1212

1313
error: missing documentation for a struct
14-
--> $DIR/lint-missing-doc.rs:18:1
14+
--> $DIR/lint-missing-doc.rs:19:1
1515
|
1616
LL | pub struct PubFoo {
1717
| ^^^^^^^^^^^^^^^^^
1818

1919
error: missing documentation for a struct field
20-
--> $DIR/lint-missing-doc.rs:19:5
20+
--> $DIR/lint-missing-doc.rs:20:5
2121
|
2222
LL | pub a: isize,
2323
| ^^^^^^^^^^^^
2424

2525
error: missing documentation for a module
26-
--> $DIR/lint-missing-doc.rs:30:1
26+
--> $DIR/lint-missing-doc.rs:31:1
2727
|
2828
LL | pub mod pub_module_no_dox {}
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3030

3131
error: missing documentation for a function
32-
--> $DIR/lint-missing-doc.rs:34:1
32+
--> $DIR/lint-missing-doc.rs:35:1
3333
|
3434
LL | pub fn foo2() {}
3535
| ^^^^^^^^^^^^^
3636

3737
error: missing documentation for a trait
38-
--> $DIR/lint-missing-doc.rs:52:1
38+
--> $DIR/lint-missing-doc.rs:53:1
3939
|
4040
LL | pub trait C {
4141
| ^^^^^^^^^^^
4242

4343
error: missing documentation for a method
44-
--> $DIR/lint-missing-doc.rs:53:5
44+
--> $DIR/lint-missing-doc.rs:54:5
4545
|
4646
LL | fn foo(&self);
4747
| ^^^^^^^^^^^^^^
4848

4949
error: missing documentation for a method
50-
--> $DIR/lint-missing-doc.rs:54:5
50+
--> $DIR/lint-missing-doc.rs:55:5
5151
|
5252
LL | fn foo_with_impl(&self) {}
5353
| ^^^^^^^^^^^^^^^^^^^^^^^
5454

5555
error: missing documentation for an associated function
56-
--> $DIR/lint-missing-doc.rs:55:5
56+
--> $DIR/lint-missing-doc.rs:56:5
5757
|
5858
LL | fn foo_no_self();
5959
| ^^^^^^^^^^^^^^^^^
6060

6161
error: missing documentation for an associated function
62-
--> $DIR/lint-missing-doc.rs:56:5
62+
--> $DIR/lint-missing-doc.rs:57:5
6363
|
6464
LL | fn foo_no_self_with_impl() {}
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6666

6767
error: missing documentation for an associated type
68-
--> $DIR/lint-missing-doc.rs:66:5
68+
--> $DIR/lint-missing-doc.rs:67:5
6969
|
7070
LL | type AssociatedType;
7171
| ^^^^^^^^^^^^^^^^^^^
7272

7373
error: missing documentation for an associated type
74-
--> $DIR/lint-missing-doc.rs:67:5
74+
--> $DIR/lint-missing-doc.rs:68:5
7575
|
7676
LL | type AssociatedTypeDef = Self;
7777
| ^^^^^^^^^^^^^^^^^^^^^^
7878

7979
error: missing documentation for an associated function
80-
--> $DIR/lint-missing-doc.rs:83:5
80+
--> $DIR/lint-missing-doc.rs:84:5
8181
|
8282
LL | pub fn foo() {}
8383
| ^^^^^^^^^^^^
8484

8585
error: missing documentation for an enum
86-
--> $DIR/lint-missing-doc.rs:120:1
86+
--> $DIR/lint-missing-doc.rs:121:1
8787
|
8888
LL | pub enum PubBaz {
8989
| ^^^^^^^^^^^^^^^
9090

9191
error: missing documentation for a variant
92-
--> $DIR/lint-missing-doc.rs:121:5
92+
--> $DIR/lint-missing-doc.rs:122:5
9393
|
9494
LL | PubBazA {
9595
| ^^^^^^^
9696

9797
error: missing documentation for a struct field
98-
--> $DIR/lint-missing-doc.rs:122:9
98+
--> $DIR/lint-missing-doc.rs:123:9
9999
|
100100
LL | a: isize,
101101
| ^^^^^^^^
102102

103103
error: missing documentation for a constant
104-
--> $DIR/lint-missing-doc.rs:153:1
104+
--> $DIR/lint-missing-doc.rs:154:1
105105
|
106106
LL | pub const FOO4: u32 = 0;
107107
| ^^^^^^^^^^^^^^^^^^^
108108

109109
error: missing documentation for a static
110-
--> $DIR/lint-missing-doc.rs:163:1
110+
--> $DIR/lint-missing-doc.rs:164:1
111111
|
112112
LL | pub static BAR4: u32 = 0;
113113
| ^^^^^^^^^^^^^^^^^^^^
114114

115115
error: missing documentation for a function
116-
--> $DIR/lint-missing-doc.rs:169:5
116+
--> $DIR/lint-missing-doc.rs:170:5
117117
|
118118
LL | pub fn undocumented1() {}
119119
| ^^^^^^^^^^^^^^^^^^^^^^
120120

121121
error: missing documentation for a function
122-
--> $DIR/lint-missing-doc.rs:170:5
122+
--> $DIR/lint-missing-doc.rs:171:5
123123
|
124124
LL | pub fn undocumented2() {}
125125
| ^^^^^^^^^^^^^^^^^^^^^^
126126

127127
error: missing documentation for a function
128-
--> $DIR/lint-missing-doc.rs:176:9
128+
--> $DIR/lint-missing-doc.rs:177:9
129129
|
130130
LL | pub fn also_undocumented1() {}
131131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
132132

133133
error: missing documentation for a function
134-
--> $DIR/lint-missing-doc.rs:191:5
134+
--> $DIR/lint-missing-doc.rs:192:5
135135
|
136136
LL | pub fn extern_fn_undocumented(f: f32) -> f32;
137137
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
138138

139139
error: missing documentation for a static
140-
--> $DIR/lint-missing-doc.rs:196:5
140+
--> $DIR/lint-missing-doc.rs:197:5
141141
|
142142
LL | pub static EXTERN_STATIC_UNDOCUMENTED: u8;
143143
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144144

145145
error: missing documentation for a foreign type
146-
--> $DIR/lint-missing-doc.rs:201:5
146+
--> $DIR/lint-missing-doc.rs:202:5
147147
|
148148
LL | pub type ExternTyUndocumented;
149149
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
150150

151-
error: aborting due to 24 previous errors
151+
error: missing documentation for a trait alias
152+
--> $DIR/lint-missing-doc.rs:206:1
153+
|
154+
LL | pub trait T = Sync;
155+
| ^^^^^^^^^^^
156+
157+
error: aborting due to 25 previous errors
152158

0 commit comments

Comments
 (0)