Skip to content

Commit d35d972

Browse files
committed
Auto merge of rust-lang#97574 - Dylan-DPC:rollup-jq850l6, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#97089 (Improve settings theme display) - rust-lang#97229 (Document the current aliasing rules for `Box<T>`.) - rust-lang#97371 (Suggest adding a semicolon to a closure without block) - rust-lang#97455 (Stabilize `toowned_clone_into`) - rust-lang#97565 (Add doc alias `memset` to `write_bytes`) - rust-lang#97569 (Remove `memset` alias from `fill_with`.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 989b806 + efd2519 commit d35d972

File tree

16 files changed

+266
-73
lines changed

16 files changed

+266
-73
lines changed

compiler/rustc_typeck/src/check/coercion.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15001500
coercion_error.clone(),
15011501
fcx,
15021502
parent_id,
1503-
expression.map(|expr| (expr, blk_id)),
1503+
expression,
1504+
Some(blk_id),
15041505
);
15051506
if !fcx.tcx.features().unsized_locals {
15061507
unsized_return = self.is_return_ty_unsized(fcx, blk_id);
@@ -1514,6 +1515,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15141515
coercion_error.clone(),
15151516
fcx,
15161517
id,
1518+
expression,
15171519
None,
15181520
);
15191521
if !fcx.tcx.features().unsized_locals {
@@ -1564,21 +1566,28 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15641566
ty_err: TypeError<'tcx>,
15651567
fcx: &FnCtxt<'a, 'tcx>,
15661568
id: hir::HirId,
1567-
expression: Option<(&'tcx hir::Expr<'tcx>, hir::HirId)>,
1569+
expression: Option<&'tcx hir::Expr<'tcx>>,
1570+
blk_id: Option<hir::HirId>,
15681571
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
15691572
let mut err = fcx.report_mismatched_types(cause, expected, found, ty_err);
15701573

15711574
let mut pointing_at_return_type = false;
15721575
let mut fn_output = None;
15731576

1577+
let parent_id = fcx.tcx.hir().get_parent_node(id);
1578+
let parent = fcx.tcx.hir().get(parent_id);
1579+
if let Some(expr) = expression
1580+
&& let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(_, _, body_id, ..), .. }) = parent
1581+
&& !matches!(fcx.tcx.hir().get(body_id.hir_id), hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Block(..), .. }))
1582+
{
1583+
fcx.suggest_missing_semicolon(&mut err, expr, expected, true);
1584+
}
15741585
// Verify that this is a tail expression of a function, otherwise the
15751586
// label pointing out the cause for the type coercion will be wrong
15761587
// as prior return coercions would not be relevant (#57664).
1577-
let parent_id = fcx.tcx.hir().get_parent_node(id);
1578-
let fn_decl = if let Some((expr, blk_id)) = expression {
1588+
let fn_decl = if let (Some(expr), Some(blk_id)) = (expression, blk_id) {
15791589
pointing_at_return_type =
15801590
fcx.suggest_mismatched_types_on_tail(&mut err, expr, expected, found, blk_id);
1581-
let parent = fcx.tcx.hir().get(parent_id);
15821591
if let (Some(cond_expr), true, false) = (
15831592
fcx.tcx.hir().get_if_cause(expr.hir_id),
15841593
expected.is_unit(),
@@ -1607,7 +1616,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16071616
};
16081617

16091618
if let Some((fn_decl, can_suggest)) = fn_decl {
1610-
if expression.is_none() {
1619+
if blk_id.is_none() {
16111620
pointing_at_return_type |= fcx.suggest_missing_return_type(
16121621
&mut err,
16131622
&fn_decl,
@@ -1625,8 +1634,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
16251634
let parent_id = fcx.tcx.hir().get_parent_item(id);
16261635
let parent_item = fcx.tcx.hir().get_by_def_id(parent_id);
16271636

1628-
if let (Some((expr, _)), Some((fn_decl, _, _))) =
1629-
(expression, fcx.get_node_fn_decl(parent_item))
1637+
if let (Some(expr), Some(_), Some((fn_decl, _, _))) =
1638+
(expression, blk_id, fcx.get_node_fn_decl(parent_item))
16301639
{
16311640
fcx.suggest_missing_break_or_return_expr(
16321641
&mut err,

compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

+28-14
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4646
blk_id: hir::HirId,
4747
) -> bool {
4848
let expr = expr.peel_drop_temps();
49-
// If the expression is from an external macro, then do not suggest
50-
// adding a semicolon, because there's nowhere to put it.
51-
// See issue #81943.
52-
if expr.can_have_side_effects() && !in_external_macro(self.tcx.sess, expr.span) {
53-
self.suggest_missing_semicolon(err, expr, expected);
54-
}
49+
self.suggest_missing_semicolon(err, expr, expected, false);
5550
let mut pointing_at_return_type = false;
5651
if let Some((fn_decl, can_suggest)) = self.get_fn_decl(blk_id) {
5752
let fn_id = self.tcx.hir().get_return_block(blk_id).unwrap();
@@ -473,11 +468,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
473468
/// This routine checks if the return expression in a block would make sense on its own as a
474469
/// statement and the return type has been left as default or has been specified as `()`. If so,
475470
/// it suggests adding a semicolon.
476-
fn suggest_missing_semicolon(
471+
///
472+
/// If the expression is the expression of a closure without block (`|| expr`), a
473+
/// block is needed to be added too (`|| { expr; }`). This is denoted by `needs_block`.
474+
pub fn suggest_missing_semicolon(
477475
&self,
478476
err: &mut Diagnostic,
479477
expression: &'tcx hir::Expr<'tcx>,
480478
expected: Ty<'tcx>,
479+
needs_block: bool,
481480
) {
482481
if expected.is_unit() {
483482
// `BlockTailExpression` only relevant if the tail expr would be
@@ -489,14 +488,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
489488
| ExprKind::If(..)
490489
| ExprKind::Match(..)
491490
| ExprKind::Block(..)
492-
if expression.can_have_side_effects() =>
491+
if expression.can_have_side_effects()
492+
// If the expression is from an external macro, then do not suggest
493+
// adding a semicolon, because there's nowhere to put it.
494+
// See issue #81943.
495+
&& !in_external_macro(self.tcx.sess, expression.span) =>
493496
{
494-
err.span_suggestion(
495-
expression.span.shrink_to_hi(),
496-
"consider using a semicolon here",
497-
";".to_string(),
498-
Applicability::MachineApplicable,
499-
);
497+
if needs_block {
498+
err.multipart_suggestion(
499+
"consider using a semicolon here",
500+
vec![
501+
(expression.span.shrink_to_lo(), "{ ".to_owned()),
502+
(expression.span.shrink_to_hi(), "; }".to_owned()),
503+
],
504+
Applicability::MachineApplicable,
505+
);
506+
} else {
507+
err.span_suggestion(
508+
expression.span.shrink_to_hi(),
509+
"consider using a semicolon here",
510+
";".to_string(),
511+
Applicability::MachineApplicable,
512+
);
513+
}
500514
}
501515
_ => (),
502516
}

library/alloc/src/borrow.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ pub trait ToOwned {
6767
/// Basic usage:
6868
///
6969
/// ```
70-
/// # #![feature(toowned_clone_into)]
7170
/// let mut s: String = String::new();
7271
/// "hello".clone_into(&mut s);
7372
///
7473
/// let mut v: Vec<i32> = Vec::new();
7574
/// [1, 2][..].clone_into(&mut v);
7675
/// ```
77-
#[unstable(feature = "toowned_clone_into", reason = "recently added", issue = "41263")]
76+
#[stable(feature = "toowned_clone_into", since = "1.63.0")]
7877
fn clone_into(&self, target: &mut Self::Owned) {
7978
*target = self.to_owned();
8079
}

library/alloc/src/boxed.rs

+14
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,21 @@
122122
//! definition is just using `T*` can lead to undefined behavior, as
123123
//! described in [rust-lang/unsafe-code-guidelines#198][ucg#198].
124124
//!
125+
//! # Considerations for unsafe code
126+
//!
127+
//! **Warning: This section is not normative and is subject to change, possibly
128+
//! being relaxed in the future! It is a simplified summary of the rules
129+
//! currently implemented in the compiler.**
130+
//!
131+
//! The aliasing rules for `Box<T>` are the same as for `&mut T`. `Box<T>`
132+
//! asserts uniqueness over its content. Using raw pointers derived from a box
133+
//! after that box has been mutated through, moved or borrowed as `&mut T`
134+
//! is not allowed. For more guidance on working with box from unsafe code, see
135+
//! [rust-lang/unsafe-code-guidelines#326][ucg#326].
136+
//!
137+
//!
125138
//! [ucg#198]: https://github.com/rust-lang/unsafe-code-guidelines/issues/198
139+
//! [ucg#326]: https://github.com/rust-lang/unsafe-code-guidelines/issues/326
126140
//! [dereferencing]: core::ops::Deref
127141
//! [`Box::<T>::from_raw(value)`]: Box::from_raw
128142
//! [`Global`]: crate::alloc::Global

library/core/src/intrinsics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,7 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
22872287
/// // Now the box is fine
22882288
/// assert_eq!(*v, 42);
22892289
/// ```
2290+
#[doc(alias = "memset")]
22902291
#[stable(feature = "rust1", since = "1.0.0")]
22912292
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
22922293
#[inline]

library/core/src/ptr/mut_ptr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,7 @@ impl<T: ?Sized> *mut T {
14121412
/// See [`ptr::write_bytes`] for safety concerns and examples.
14131413
///
14141414
/// [`ptr::write_bytes`]: crate::ptr::write_bytes()
1415+
#[doc(alias = "memset")]
14151416
#[stable(feature = "pointer_methods", since = "1.26.0")]
14161417
#[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
14171418
#[inline(always)]

library/core/src/slice/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3083,7 +3083,6 @@ impl<T> [T] {
30833083
/// buf.fill_with(Default::default);
30843084
/// assert_eq!(buf, vec![0; 10]);
30853085
/// ```
3086-
#[doc(alias = "memset")]
30873086
#[stable(feature = "slice_fill_with", since = "1.51.0")]
30883087
pub fn fill_with<F>(&mut self, mut f: F)
30893088
where

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@
299299
#![feature(map_try_insert)]
300300
#![feature(new_uninit)]
301301
#![feature(thin_box)]
302-
#![feature(toowned_clone_into)]
303302
#![feature(try_reserve_kind)]
304303
#![feature(vec_into_raw_parts)]
305304
#![feature(slice_concat_trait)]

src/librustdoc/html/static/css/settings.css

+20-33
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,40 @@
33
position: relative;
44
}
55

6-
.setting-line > div {
7-
display: inline-block;
8-
vertical-align: top;
9-
font-size: 17px;
10-
padding-top: 2px;
11-
}
12-
13-
.setting-line > .title {
14-
font-size: 19px;
15-
width: 100%;
16-
max-width: none;
17-
border-bottom: 1px solid;
18-
}
19-
20-
.setting-line .radio-line,
216
.setting-line .choices {
227
display: flex;
238
flex-wrap: wrap;
249
}
2510

26-
.setting-line .radio-line .setting-name {
27-
flex-grow: 1;
28-
margin-top: auto;
29-
margin-bottom: auto;
30-
}
31-
3211
.setting-line .radio-line input {
3312
margin-right: 0.3em;
13+
height: 1.2rem;
14+
width: 1.2rem;
15+
border: 1px solid;
16+
outline: none;
17+
-webkit-appearance: none;
18+
cursor: pointer;
19+
border-radius: 50%;
20+
}
21+
.setting-line .radio-line input + span {
22+
padding-bottom: 1px;
23+
}
24+
25+
.radio-line .setting-name {
26+
width: 100%;
3427
}
3528

3629
.radio-line .choice {
37-
border-radius: 0.1em;
38-
border: 1px solid;
39-
margin-left: 0.5em;
4030
margin-top: 0.1em;
4131
margin-bottom: 0.1em;
4232
min-width: 3.8em;
4333
padding: 0.3em;
34+
display: flex;
35+
align-items: center;
36+
cursor: pointer;
37+
}
38+
.radio-line .choice + .choice {
39+
margin-left: 0.5em;
4440
}
4541

4642
.toggle {
@@ -77,18 +73,9 @@
7773
width: 19px;
7874
left: 4px;
7975
bottom: 4px;
80-
background-color: white;
8176
transition: .3s;
8277
}
8378

84-
input:checked + .slider {
85-
background-color: #2196F3;
86-
}
87-
88-
input:focus + .slider {
89-
box-shadow: 0 0 0 2px #0a84ff, 0 0 0 6px rgba(10, 132, 255, 0.3);
90-
}
91-
9279
input:checked + .slider:before {
9380
transform: translateX(19px);
9481
}

src/librustdoc/html/static/css/themes/ayu.css

+32-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,38 @@ body, #settings-menu #settings, #settings-menu #settings::before {
1010
color: #c5c5c5;
1111
}
1212

13+
.setting-line .radio-line input {
14+
border-color: #c5c5c5;
15+
}
16+
.setting-line .radio-line input:checked {
17+
box-shadow: inset 0 0 0 3px #0f1419;
18+
background-color: #ffb454;
19+
}
20+
.setting-line .radio-line input:focus {
21+
box-shadow: 0 0 1px 1px #ffb454;
22+
}
23+
/* In here we combine both `:focus` and `:checked` properties. */
24+
.setting-line .radio-line input:checked:focus {
25+
box-shadow: inset 0 0 0 3px 0f1419,
26+
0 0 2px 2px #ffb454;
27+
}
28+
.setting-line .radio-line input:hover {
29+
border-color: #ffb454 !important;
30+
}
31+
32+
.slider {
33+
background-color: #ccc;
34+
}
35+
.slider:before {
36+
background-color: white;
37+
}
38+
input:checked + .slider {
39+
background-color: #ffb454;
40+
}
41+
input:focus + .slider {
42+
box-shadow: 0 0 0 2px #0a84ff, 0 0 0 6px rgba(10, 132, 255, 0.3);
43+
}
44+
1345
h1, h2, h3, h4 {
1446
color: white;
1547
}
@@ -601,13 +633,6 @@ div.files > .selected {
601633
background-color: #14191f;
602634
color: #ffb44c;
603635
}
604-
.setting-line > .title {
605-
border-bottom-color: #5c6773;
606-
}
607-
input:checked + .slider {
608-
background-color: #ffb454 !important;
609-
}
610-
611636

612637
.scraped-example-list .scrape-help {
613638
border-color: #aaa;

src/librustdoc/html/static/css/themes/dark.css

+32-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,38 @@ body, #settings-menu #settings, #settings-menu #settings::before {
33
color: #ddd;
44
}
55

6+
.setting-line .radio-line input {
7+
border-color: #ddd;
8+
}
9+
.setting-line .radio-line input:checked {
10+
box-shadow: inset 0 0 0 3px #353535;
11+
background-color: #2196f3;
12+
}
13+
.setting-line .radio-line input:focus {
14+
box-shadow: 0 0 1px 1px #2196f3;
15+
}
16+
/* In here we combine both `:focus` and `:checked` properties. */
17+
.setting-line .radio-line input:checked:focus {
18+
box-shadow: inset 0 0 0 3px #353535,
19+
0 0 2px 2px #2196f3;
20+
}
21+
.setting-line .radio-line input:hover {
22+
border-color: #2196f3 !important;
23+
}
24+
25+
.slider {
26+
background-color: #ccc;
27+
}
28+
.slider:before {
29+
background-color: white;
30+
}
31+
input:checked + .slider {
32+
background-color: #2196F3;
33+
}
34+
input:focus + .slider {
35+
box-shadow: 0 0 0 2px #0a84ff, 0 0 0 6px rgba(10, 132, 255, 0.3);
36+
}
37+
638
h1, h2, h3, h4 {
739
color: #ddd;
840
}
@@ -472,9 +504,6 @@ div.files > a:hover, div.name:hover {
472504
div.files > .selected {
473505
background-color: #333;
474506
}
475-
.setting-line > .title {
476-
border-bottom-color: #ddd;
477-
}
478507

479508
.scraped-example-list .scrape-help {
480509
border-color: #aaa;

0 commit comments

Comments
 (0)