Skip to content

Commit a9985cf

Browse files
committed
Auto merge of #107584 - matthiaskrgr:rollup-vav4ljz, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #107201 (Remove confusing 'while checking' note from opaque future type mismatches) - #107312 (Add Style Guide rules for let-else statements) - #107488 (Fix syntax in `-Zunpretty-expanded` output for derived `PartialEq`.) - #107531 (Inline CSS background images directly into the CSS) - #107576 (Add proc-macro boilerplate to crt-static test) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 821b2a8 + 643fc97 commit a9985cf

28 files changed

+155
-254
lines changed

compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,30 @@ pub fn expand_deriving_partial_eq(
2929
cx.span_bug(field.span, "not exactly 2 arguments in `derive(PartialEq)`");
3030
};
3131

32-
// We received `&T` arguments. Convert them to `T` by
33-
// stripping `&` or adding `*`. This isn't necessary for
34-
// type checking, but it results in much better error
35-
// messages if something goes wrong.
32+
// We received arguments of type `&T`. Convert them to type `T` by stripping
33+
// any leading `&` or adding `*`. This isn't necessary for type checking, but
34+
// it results in better error messages if something goes wrong.
35+
//
36+
// Note: for arguments that look like `&{ x }`, which occur with packed
37+
// structs, this would cause expressions like `{ self.x } == { other.x }`,
38+
// which isn't valid Rust syntax. This wouldn't break compilation because these
39+
// AST nodes are constructed within the compiler. But it would mean that code
40+
// printed by `-Zunpretty=expanded` (or `cargo expand`) would have invalid
41+
// syntax, which would be suboptimal. So we wrap these in parens, giving
42+
// `({ self.x }) == ({ other.x })`, which is valid syntax.
3643
let convert = |expr: &P<Expr>| {
3744
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) =
3845
&expr.kind
3946
{
40-
inner.clone()
47+
if let ExprKind::Block(..) = &inner.kind {
48+
// `&{ x }` form: remove the `&`, add parens.
49+
cx.expr_paren(field.span, inner.clone())
50+
} else {
51+
// `&x` form: remove the `&`.
52+
inner.clone()
53+
}
4154
} else {
55+
// No leading `&`: add a leading `*`.
4256
cx.expr_deref(field.span, expr.clone())
4357
}
4458
};

compiler/rustc_expand/src/build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ impl<'a> ExtCtxt<'a> {
272272
self.expr(sp, ast::ExprKind::AddrOf(ast::BorrowKind::Ref, ast::Mutability::Not, e))
273273
}
274274

275+
pub fn expr_paren(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {
276+
self.expr(sp, ast::ExprKind::Paren(e))
277+
}
278+
275279
pub fn expr_call(
276280
&self,
277281
span: Span,

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+16-46
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use crate::traits::{
6060

6161
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
6262
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed, IntoDiagnosticArg};
63-
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString, MultiSpan};
63+
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
6464
use rustc_hir as hir;
6565
use rustc_hir::def::DefKind;
6666
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -1470,51 +1470,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14701470
for (key, values) in types.iter() {
14711471
let count = values.len();
14721472
let kind = key.descr();
1473-
let mut returned_async_output_error = false;
14741473
for &sp in values {
1475-
if sp.is_desugaring(DesugaringKind::Async) && !returned_async_output_error {
1476-
if [sp] != err.span.primary_spans() {
1477-
let mut span: MultiSpan = sp.into();
1478-
span.push_span_label(
1479-
sp,
1480-
format!(
1481-
"checked the `Output` of this `async fn`, {}{} {}{}",
1482-
if count > 1 { "one of the " } else { "" },
1483-
target,
1484-
kind,
1485-
pluralize!(count),
1486-
),
1487-
);
1488-
err.span_note(
1489-
span,
1490-
"while checking the return type of the `async fn`",
1491-
);
1492-
} else {
1493-
err.span_label(
1494-
sp,
1495-
format!(
1496-
"checked the `Output` of this `async fn`, {}{} {}{}",
1497-
if count > 1 { "one of the " } else { "" },
1498-
target,
1499-
kind,
1500-
pluralize!(count),
1501-
),
1502-
);
1503-
err.note("while checking the return type of the `async fn`");
1504-
}
1505-
returned_async_output_error = true;
1506-
} else {
1507-
err.span_label(
1508-
sp,
1509-
format!(
1510-
"{}{} {}{}",
1511-
if count == 1 { "the " } else { "one of the " },
1512-
target,
1513-
kind,
1514-
pluralize!(count),
1515-
),
1516-
);
1517-
}
1474+
err.span_label(
1475+
sp,
1476+
format!(
1477+
"{}{} {}{}",
1478+
if count == 1 { "the " } else { "one of the " },
1479+
target,
1480+
kind,
1481+
pluralize!(count),
1482+
),
1483+
);
15181484
}
15191485
}
15201486
}
@@ -1537,7 +1503,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
15371503
// |
15381504
// = note: expected unit type `()`
15391505
// found closure `[closure@$DIR/issue-20862.rs:2:5: 2:14 x:_]`
1540-
if !self.ignore_span.overlaps(span) {
1506+
//
1507+
// Also ignore opaque `Future`s that come from async fns.
1508+
if !self.ignore_span.overlaps(span)
1509+
&& !span.is_desugaring(DesugaringKind::Async)
1510+
{
15411511
self.types.entry(kind).or_default().insert(span);
15421512
}
15431513
}

src/doc/style-guide/src/statements.md

+78
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,84 @@ let Foo {
9999
);
100100
```
101101

102+
#### else blocks (let-else statements)
103+
104+
If a let statement contains an `else` component, also known as a let-else statement,
105+
then the `else` component should be formatted according to the same rules as the `else` block
106+
in [control flow expressions (i.e. if-else, and if-let-else expressions)](./expressions.md#control-flow-expressions).
107+
Apply the same formatting rules to the components preceding
108+
the `else` block (i.e. the `let pattern: Type = initializer_expr ...` portion)
109+
as described [above](#let-statements)
110+
111+
Similarly to if-else expressions, if the initializer
112+
expression is multi-lined, then the `else` keyword and opening brace of the block (i.e. `else {`)
113+
should be put on the same line as the end of the initializer
114+
expression with a preceding space if all the following are true:
115+
116+
* The initializer expression ends with one or more closing
117+
parentheses, square brackets, and/or braces
118+
* There is nothing else on that line
119+
* That line is not indented beyond the indent of the first line containing the `let` keyword
120+
121+
For example:
122+
123+
```rust
124+
let Some(x) = y.foo(
125+
"abc",
126+
fairly_long_identifier,
127+
"def",
128+
"123456",
129+
"string",
130+
"cheese",
131+
) else {
132+
bar()
133+
}
134+
```
135+
136+
Otherwise, the `else` keyword and opening brace should be placed on the next line after the end of the initializer expression, and should not be indented (the `else` keyword should be aligned with the `let` keyword).
137+
138+
For example:
139+
140+
```rust
141+
let Some(x) = abcdef()
142+
.foo(
143+
"abc",
144+
some_really_really_really_long_ident,
145+
"ident",
146+
"123456",
147+
)
148+
.bar()
149+
.baz()
150+
.qux("fffffffffffffffff")
151+
else {
152+
foo_bar()
153+
}
154+
```
155+
156+
##### Single line let-else statements
157+
158+
The entire let-else statement may be formatted on a single line if all the following are true:
159+
160+
* the entire statement is *short*
161+
* the `else` block contains a single-line expression and no statements
162+
* the `else` block contains no comments
163+
* the let statement components preceding the `else` block can be formatted on a single line
164+
165+
```rust
166+
let Some(1) = opt else { return };
167+
168+
let Some(1) = opt else {
169+
return;
170+
};
171+
172+
let Some(1) = opt else {
173+
// nope
174+
return
175+
};
176+
```
177+
178+
Formatters may allow users to configure the value of the threshold
179+
used to determine whether a let-else statement is *short*.
102180

103181
### Macros in statement position
104182

src/librustdoc/html/static/css/rustdoc.css

+13-4
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,11 @@ so that we can apply CSS-filters to change the arrow color in themes */
814814
background-repeat: no-repeat;
815815
background-size: 20px;
816816
background-position: calc(100% - 2px) 56%;
817-
/* image is black color */
818-
background-image: url("down-arrow-927217e04c7463ac.svg");
817+
/* down arrow (image is black color) */
818+
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" \
819+
width="128" height="128" viewBox="-30 -20 176 176"><path d="M111,40.5L64,87.499L17,40.5" \
820+
fill="none" stroke="black" strike-linecap="square" stroke-miterlimit="10" stroke-width="12"/> \
821+
</svg>');
819822
/* changes the arrow image color */
820823
filter: var(--crate-search-div-filter);
821824
}
@@ -1444,7 +1447,10 @@ details.toggle > summary.hideme > span {
14441447
}
14451448

14461449
details.toggle > summary::before {
1447-
background: url("toggle-plus-1092eb4930d581b0.svg") no-repeat top left;
1450+
/* toggle plus */
1451+
background: url('data:image/svg+xml,<svg width="17" height="17" \
1452+
shape-rendering="crispEdges" stroke="black" fill="none" xmlns="http://www.w3.org/2000/svg"><path \
1453+
d="M5 2.5H2.5v12H5m7-12h2.5v12H12M5 8.5h7M8.5 12V8.625v0V5"/></svg>') no-repeat top left;
14481454
content: "";
14491455
cursor: pointer;
14501456
width: 16px;
@@ -1522,7 +1528,10 @@ details.toggle[open] > summary.hideme > span {
15221528
}
15231529

15241530
details.toggle[open] > summary::before {
1525-
background: url("toggle-minus-31bbd6e4c77f5c96.svg") no-repeat top left;
1531+
/* toggle minus */
1532+
background: url('data:image/svg+xml,<svg width="17" height="17" \
1533+
shape-rendering="crispEdges" stroke="black" fill="none" xmlns="http://www.w3.org/2000/svg"><path \
1534+
d="M5 2.5H2.5v12H5m7-12h2.5v12H12M5 8.5h7"/></svg>') no-repeat top left;
15261535
}
15271536

15281537
details.toggle[open] > summary::after {

src/librustdoc/html/static/images/down-arrow.svg

-1
This file was deleted.

src/librustdoc/html/static/images/toggle-minus.svg

-1
This file was deleted.

src/librustdoc/html/static/images/toggle-plus.svg

-1
This file was deleted.

src/librustdoc/html/static_files.rs

-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ static_files! {
102102
scrape_examples_js => "static/js/scrape-examples.js",
103103
wheel_svg => "static/images/wheel.svg",
104104
clipboard_svg => "static/images/clipboard.svg",
105-
down_arrow_svg => "static/images/down-arrow.svg",
106-
toggle_minus_png => "static/images/toggle-minus.svg",
107-
toggle_plus_png => "static/images/toggle-plus.svg",
108105
copyright => "static/COPYRIGHT.txt",
109106
license_apache => "static/LICENSE-APACHE.txt",
110107
license_mit => "static/LICENSE-MIT.txt",

tests/ui/async-await/dont-suggest-missing-await.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ LL | take_u32(x)
66
| |
77
| arguments to this function are incorrect
88
|
9-
note: while checking the return type of the `async fn`
10-
--> $DIR/dont-suggest-missing-await.rs:7:24
11-
|
12-
LL | async fn make_u32() -> u32 {
13-
| ^^^ checked the `Output` of this `async fn`, found opaque type
149
= note: expected type `u32`
1510
found opaque type `impl Future<Output = u32>`
1611
note: function defined here

tests/ui/async-await/generator-desc.stderr

-10
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ LL | fun(one(), two());
2121
| |
2222
| arguments to this function are incorrect
2323
|
24-
note: while checking the return type of the `async fn`
25-
--> $DIR/generator-desc.rs:5:16
26-
|
27-
LL | async fn one() {}
28-
| ^ checked the `Output` of this `async fn`, expected opaque type
29-
note: while checking the return type of the `async fn`
30-
--> $DIR/generator-desc.rs:6:16
31-
|
32-
LL | async fn two() {}
33-
| ^ checked the `Output` of this `async fn`, found opaque type
3424
= note: expected opaque type `impl Future<Output = ()>` (opaque type at <$DIR/generator-desc.rs:5:16>)
3525
found opaque type `impl Future<Output = ()>` (opaque type at <$DIR/generator-desc.rs:6:16>)
3626
= help: consider `await`ing on both `Future`s

tests/ui/async-await/issue-61076.rs

-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ async fn struct_() -> Struct {
5454
}
5555

5656
async fn tuple() -> Tuple {
57-
//~^ NOTE checked the `Output` of this `async fn`, expected opaque type
58-
//~| NOTE while checking the return type of the `async fn`
59-
//~| NOTE in this expansion of desugaring of `async` block or function
6057
Tuple(1i32)
6158
}
6259

tests/ui/async-await/issue-61076.stderr

+5-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | foo().await?;
1111
| ++++++
1212

1313
error[E0277]: the `?` operator can only be applied to values that implement `Try`
14-
--> $DIR/issue-61076.rs:65:5
14+
--> $DIR/issue-61076.rs:62:5
1515
|
1616
LL | t?;
1717
| ^^ the `?` operator cannot be applied to type `T`
@@ -23,7 +23,7 @@ LL | t.await?;
2323
| ++++++
2424

2525
error[E0609]: no field `0` on type `impl Future<Output = Tuple>`
26-
--> $DIR/issue-61076.rs:74:26
26+
--> $DIR/issue-61076.rs:71:26
2727
|
2828
LL | let _: i32 = tuple().0;
2929
| ^ field not available in `impl Future`, but it is available in its `Output`
@@ -34,7 +34,7 @@ LL | let _: i32 = tuple().await.0;
3434
| ++++++
3535

3636
error[E0609]: no field `a` on type `impl Future<Output = Struct>`
37-
--> $DIR/issue-61076.rs:78:28
37+
--> $DIR/issue-61076.rs:75:28
3838
|
3939
LL | let _: i32 = struct_().a;
4040
| ^ field not available in `impl Future`, but it is available in its `Output`
@@ -45,7 +45,7 @@ LL | let _: i32 = struct_().await.a;
4545
| ++++++
4646

4747
error[E0599]: no method named `method` found for opaque type `impl Future<Output = Struct>` in the current scope
48-
--> $DIR/issue-61076.rs:82:15
48+
--> $DIR/issue-61076.rs:79:15
4949
|
5050
LL | struct_().method();
5151
| ^^^^^^ method not found in `impl Future<Output = Struct>`
@@ -56,19 +56,14 @@ LL | struct_().await.method();
5656
| ++++++
5757

5858
error[E0308]: mismatched types
59-
--> $DIR/issue-61076.rs:91:9
59+
--> $DIR/issue-61076.rs:88:9
6060
|
6161
LL | match tuple() {
6262
| ------- this expression has type `impl Future<Output = Tuple>`
6363
LL |
6464
LL | Tuple(_) => {}
6565
| ^^^^^^^^ expected opaque type, found `Tuple`
6666
|
67-
note: while checking the return type of the `async fn`
68-
--> $DIR/issue-61076.rs:56:21
69-
|
70-
LL | async fn tuple() -> Tuple {
71-
| ^^^^^ checked the `Output` of this `async fn`, expected opaque type
7267
= note: expected opaque type `impl Future<Output = Tuple>`
7368
found struct `Tuple`
7469
help: consider `await`ing on the `Future`

0 commit comments

Comments
 (0)