Skip to content

Commit ca37a45

Browse files
committed
Auto merge of rust-lang#100048 - matthiaskrgr:rollup-agimvm6, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#99156 (`codegen_fulfill_obligation` expect erased regions) - rust-lang#99293 (only run --all-targets in stage0 for Std) - rust-lang#99779 (Fix item info pos and height) - rust-lang#99994 (Remove `guess_head_span`) - rust-lang#100011 (Use Parser's `restrictions` instead of `let_expr_allowed`) - rust-lang#100017 (kmc-solid: Update `Socket::connect_timeout` to be in line with rust-lang#78802) - rust-lang#100037 (Update rustc man page to match `rustc --help`) - rust-lang#100042 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9538d2d + 6ab19fd commit ca37a45

File tree

20 files changed

+418
-324
lines changed

20 files changed

+418
-324
lines changed

compiler/rustc_infer/src/infer/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub use self::ValuePairs::*;
88
use self::opaque_types::OpaqueTypeStorage;
99
pub(crate) use self::undo_log::{InferCtxtUndoLogs, Snapshot, UndoLog};
1010

11-
use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine};
11+
use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine, TraitEngineExt};
1212

1313
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1414
use rustc_data_structures::sync::Lrc;
@@ -645,9 +645,7 @@ impl<'tcx, T> InferOk<'tcx, T> {
645645
fulfill_cx: &mut dyn TraitEngine<'tcx>,
646646
) -> T {
647647
let InferOk { value, obligations } = self;
648-
for obligation in obligations {
649-
fulfill_cx.register_predicate_obligation(infcx, obligation);
650-
}
648+
fulfill_cx.register_predicate_obligations(infcx, obligations);
651649
value
652650
}
653651
}

compiler/rustc_parse/src/parser/expr.rs

+17-39
Original file line numberDiff line numberDiff line change
@@ -1391,8 +1391,6 @@ impl<'a> Parser<'a> {
13911391
} else if self.is_do_yeet() {
13921392
self.parse_yeet_expr(attrs)
13931393
} else if self.check_keyword(kw::Let) {
1394-
self.manage_let_chains_context();
1395-
self.bump();
13961394
self.parse_let_expr(attrs)
13971395
} else if self.eat_keyword(kw::Underscore) {
13981396
Ok(self.mk_expr(self.prev_token.span, ExprKind::Underscore, attrs))
@@ -2342,32 +2340,24 @@ impl<'a> Parser<'a> {
23422340

23432341
/// Parses the condition of a `if` or `while` expression.
23442342
fn parse_cond_expr(&mut self) -> PResult<'a, P<Expr>> {
2345-
self.with_let_management(true, |local_self| {
2346-
local_self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)
2347-
})
2343+
self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL | Restrictions::ALLOW_LET, None)
23482344
}
23492345

2350-
// Checks if `let` is in an invalid position like `let x = let y = 1;` or
2351-
// if the current `let` is in a let_chains context but nested in another
2352-
// expression like `if let Some(_) = _opt && [1, 2, 3][let _ = ()] = 1`.
2353-
//
2354-
// This method expects that the current token is `let`.
2355-
fn manage_let_chains_context(&mut self) {
2356-
debug_assert!(matches!(self.token.kind, TokenKind::Ident(kw::Let, _)));
2357-
let is_in_a_let_chains_context_but_nested_in_other_expr = self.let_expr_allowed
2358-
&& !matches!(
2359-
self.prev_token.kind,
2360-
TokenKind::AndAnd | TokenKind::Ident(kw::If, _) | TokenKind::Ident(kw::While, _)
2361-
);
2362-
if !self.let_expr_allowed || is_in_a_let_chains_context_but_nested_in_other_expr {
2346+
/// Parses a `let $pat = $expr` pseudo-expression.
2347+
fn parse_let_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
2348+
// This is a *approximate* heuristic that detects if `let` chains are
2349+
// being parsed in the right position. It's approximate because it
2350+
// doesn't deny all invalid `let` expressions, just completely wrong usages.
2351+
let not_in_chain = !matches!(
2352+
self.prev_token.kind,
2353+
TokenKind::AndAnd | TokenKind::Ident(kw::If, _) | TokenKind::Ident(kw::While, _)
2354+
);
2355+
if !self.restrictions.contains(Restrictions::ALLOW_LET) || not_in_chain {
23632356
self.struct_span_err(self.token.span, "expected expression, found `let` statement")
23642357
.emit();
23652358
}
2366-
}
23672359

2368-
/// Parses a `let $pat = $expr` pseudo-expression.
2369-
/// The `let` token has already been eaten.
2370-
fn parse_let_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
2360+
self.bump(); // Eat `let` token
23712361
let lo = self.prev_token.span;
23722362
let pat = self.parse_pat_allow_top_alt(
23732363
None,
@@ -2687,7 +2677,9 @@ impl<'a> Parser<'a> {
26872677
// `&&` tokens.
26882678
fn check_let_expr(expr: &Expr) -> bool {
26892679
match expr.kind {
2690-
ExprKind::Binary(_, ref lhs, ref rhs) => check_let_expr(lhs) || check_let_expr(rhs),
2680+
ExprKind::Binary(BinOp { node: BinOpKind::And, .. }, ref lhs, ref rhs) => {
2681+
check_let_expr(lhs) || check_let_expr(rhs)
2682+
}
26912683
ExprKind::Let(..) => true,
26922684
_ => false,
26932685
}
@@ -2703,9 +2695,8 @@ impl<'a> Parser<'a> {
27032695
)?;
27042696
let guard = if this.eat_keyword(kw::If) {
27052697
let if_span = this.prev_token.span;
2706-
let cond = this.with_let_management(true, |local_this| local_this.parse_expr())?;
2707-
let has_let_expr = check_let_expr(&cond);
2708-
if has_let_expr {
2698+
let cond = this.parse_expr_res(Restrictions::ALLOW_LET, None)?;
2699+
if check_let_expr(&cond) {
27092700
let span = if_span.to(cond.span);
27102701
this.sess.gated_spans.gate(sym::if_let_guard, span);
27112702
}
@@ -3279,17 +3270,4 @@ impl<'a> Parser<'a> {
32793270
Ok((res, trailing))
32803271
})
32813272
}
3282-
3283-
// Calls `f` with the internal `let_expr_allowed` set to `let_expr_allowed` and then
3284-
// sets the internal `let_expr_allowed` back to its original value.
3285-
fn with_let_management<T>(
3286-
&mut self,
3287-
let_expr_allowed: bool,
3288-
f: impl FnOnce(&mut Self) -> T,
3289-
) -> T {
3290-
let last_let_expr_allowed = mem::replace(&mut self.let_expr_allowed, let_expr_allowed);
3291-
let rslt = f(self);
3292-
self.let_expr_allowed = last_let_expr_allowed;
3293-
rslt
3294-
}
32953273
}

compiler/rustc_parse/src/parser/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ bitflags::bitflags! {
4747
const STMT_EXPR = 1 << 0;
4848
const NO_STRUCT_LITERAL = 1 << 1;
4949
const CONST_EXPR = 1 << 2;
50+
const ALLOW_LET = 1 << 3;
5051
}
5152
}
5253

@@ -147,15 +148,12 @@ pub struct Parser<'a> {
147148
/// This allows us to recover when the user forget to add braces around
148149
/// multiple statements in the closure body.
149150
pub current_closure: Option<ClosureSpans>,
150-
/// Used to track where `let`s are allowed. For example, `if true && let 1 = 1` is valid
151-
/// but `[1, 2, 3][let _ = ()]` is not.
152-
let_expr_allowed: bool,
153151
}
154152

155153
// This type is used a lot, e.g. it's cloned when matching many declarative macro rules. Make sure
156154
// it doesn't unintentionally get bigger.
157155
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
158-
rustc_data_structures::static_assert_size!(Parser<'_>, 336);
156+
rustc_data_structures::static_assert_size!(Parser<'_>, 328);
159157

160158
/// Stores span information about a closure.
161159
#[derive(Clone)]
@@ -462,7 +460,6 @@ impl<'a> Parser<'a> {
462460
inner_attr_ranges: Default::default(),
463461
},
464462
current_closure: None,
465-
let_expr_allowed: false,
466463
};
467464

468465
// Make parser point to the first token.

compiler/rustc_trait_selection/src/traits/codegen.rs

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ pub fn codegen_fulfill_obligation<'tcx>(
2323
tcx: TyCtxt<'tcx>,
2424
(param_env, trait_ref): (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>),
2525
) -> Result<&'tcx ImplSource<'tcx, ()>, CodegenObligationError> {
26-
// Remove any references to regions; this helps improve caching.
27-
let trait_ref = tcx.erase_regions(trait_ref);
2826
// We expect the input to be fully normalized.
2927
debug_assert_eq!(trait_ref, tcx.normalize_erasing_regions(param_env, trait_ref));
3028

compiler/rustc_typeck/src/check/_match.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
356356
// 6 | | };
357357
// | |_____^ expected integer, found `()`
358358
// ```
359-
if block.expr.is_none() && block.stmts.is_empty() && outer_span.is_some() {
360-
let sp = if let Some(cs) = cond_span.find_ancestor_inside(span) {
361-
span.with_hi(cs.hi())
362-
} else {
363-
span
364-
};
365-
outer_span = Some(sp);
359+
if block.expr.is_none() && block.stmts.is_empty()
360+
&& let Some(outer_span) = &mut outer_span
361+
&& let Some(cond_span) = cond_span.find_ancestor_inside(*outer_span)
362+
{
363+
*outer_span = outer_span.with_hi(cond_span.hi())
366364
}
367365

368366
(self.find_block_span(block), block.hir_id)

library/std/src/sys/solid/net.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ impl Socket {
230230
pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
231231
self.set_nonblocking(true)?;
232232
let r = unsafe {
233-
let (addrp, len) = addr.into_inner();
234-
cvt(netc::connect(self.0.raw(), addrp, len))
233+
let (addr, len) = addr.into_inner();
234+
cvt(netc::connect(self.0.raw(), addr.as_ptr(), len))
235235
};
236236
self.set_nonblocking(false)?;
237237

src/bootstrap/check.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,13 @@ impl Step for Std {
140140
cargo_subcommand(builder.kind),
141141
);
142142

143-
cargo.arg("--all-targets");
143+
// If we're not in stage 0, tests and examples will fail to compile
144+
// from `core` definitions being loaded from two different `libcore`
145+
// .rmeta and .rlib files.
146+
if compiler.stage == 0 {
147+
cargo.arg("--all-targets");
148+
}
149+
144150
std_cargo(builder, target, compiler.stage, &mut cargo);
145151

146152
// Explicitly pass -p for all dependencies krates -- this will force cargo

src/doc/man/rustc.1

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ The optional \fIKIND\fR can be one of \fIstatic\fR, \fIdylib\fR, or
4444
\fIframework\fR.
4545
If omitted, \fIdylib\fR is assumed.
4646
.TP
47-
\fB\-\-crate\-type\fR [bin|lib|rlib|dylib|cdylib|staticlib]
47+
\fB\-\-crate\-type\fR [bin|lib|rlib|dylib|cdylib|staticlib|proc\-macro]
4848
Comma separated list of types of crates for the compiler to emit.
4949
.TP
5050
\fB\-\-crate\-name\fR \fINAME\fR
5151
Specify the name of the crate being built.
5252
.TP
53-
\fB\-\-emit\fR [asm|llvm\-bc|llvm\-ir|obj|link|dep\-info|mir][=\fIPATH\fR]
53+
\fB\-\-emit\fR [asm|llvm\-bc|llvm\-ir|obj|metadata|link|dep\-info|mir][=\fIPATH\fR]
5454
Configure the output that \fBrustc\fR will produce. Each emission may also have
5555
an optional explicit output \fIPATH\fR specified for that particular emission
5656
kind. This path takes precedence over the \fB-o\fR option.
5757
.TP
58-
\fB\-\-print\fR [crate\-name|\:file\-names|\:sysroot|\:cfg|\:target\-list|\:target\-cpus|\:target\-features|\:relocation\-models|\:code\-models|\:tls\-models|\:target\-spec\-json|\:native\-static\-libs]
58+
\fB\-\-print\fR [crate\-name|\:file\-names|\:sysroot|\:target\-libdir|\:cfg|\:target\-list|\:target\-cpus|\:target\-features|\:relocation\-models|\:code\-models|\:tls\-models|\:target\-spec\-json|\:native\-static\-libs|\:stack\-protector\-strategies|\:link\-args]
5959
Comma separated list of compiler information to print on stdout.
6060
.TP
6161
\fB\-g\fR

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,14 @@ table,
11111111
}
11121112

11131113
.item-info .stab {
1114-
display: inline-block;
1114+
width: fit-content;
1115+
/* This min-height is needed to unify the height of the stab elements because some of them
1116+
have emojis.
1117+
*/
1118+
min-height: 36px;
1119+
display: flex;
1120+
align-items: center;
1121+
white-space: pre-wrap;
11151122
}
11161123
.stab {
11171124
padding: 3px;
@@ -1121,6 +1128,7 @@ table,
11211128
}
11221129
.stab p {
11231130
display: inline;
1131+
margin: 0;
11241132
}
11251133

11261134
.stab .emoji {

src/test/rustdoc-gui/item-info-width.goml

-8
This file was deleted.

src/test/rustdoc-gui/item-info.goml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// This test ensures a few things for item info elements.
2+
goto: file://|DOC_PATH|/lib2/struct.Foo.html
3+
// Ensuring that the item information don't take 100% of the width if unnecessary.
4+
// We set a fixed size so there is no chance of "random" resize.
5+
size: (1100, 800)
6+
// We check that ".item-info" is bigger than its content.
7+
assert-css: (".item-info", {"width": "790px"})
8+
assert-css: (".item-info .stab", {"width": "289px"})
9+
assert-position: (".item-info .stab", {"x": 295})
10+
11+
// Now we ensure that they're not rendered on the same line.
12+
goto: file://|DOC_PATH|/lib2/trait.Trait.html
13+
// We first ensure that there are two item info on the trait.
14+
assert-count: ("#main-content > .item-info .stab", 2)
15+
// They should not have the same `y` position!
16+
compare-elements-position-false: (
17+
"#main-content > .item-info .stab:nth-of-type(1)",
18+
"#main-content > .item-info .stab:nth-of-type(2)",
19+
("y"),
20+
)
21+
// But they should have the same `x` position.
22+
compare-elements-position: (
23+
"#main-content > .item-info .stab:nth-of-type(1)",
24+
"#main-content > .item-info .stab:nth-of-type(2)",
25+
("x"),
26+
)
27+
// They are supposed to have the same height too.
28+
compare-elements-css: (
29+
"#main-content > .item-info .stab:nth-of-type(1)",
30+
"#main-content > .item-info .stab:nth-of-type(2)",
31+
["height"],
32+
)

src/test/rustdoc-gui/src/lib2/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ impl Foo {
3030
pub fn a_method(&self) {}
3131
}
3232

33+
#[doc(cfg(feature = "foo-method"))]
34+
#[deprecated = "Whatever [`Foo::a_method`](#method.a_method)"]
3335
pub trait Trait {
3436
type X;
3537
const Y: u32;
3638

39+
#[deprecated = "Whatever [`Foo`](#tadam)"]
3740
fn foo() {}
3841
}
3942

src/test/ui/rfc-2294-if-let-guard/feature-gate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ fn _if_let_guard() {
3232
() if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
3333
//~^ ERROR `if let` guards are experimental
3434
//~| ERROR expected expression, found `let` statement
35+
//~| ERROR expected expression, found `let` statement
36+
//~| ERROR expected expression, found `let` statement
3537

3638
() if let Range { start: _, end: _ } = (true..true) && false => {}
3739
//~^ ERROR `if let` guards are experimental

src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr

+18-6
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,31 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
4141
| ^^^
4242

4343
error: expected expression, found `let` statement
44-
--> $DIR/feature-gate.rs:52:16
44+
--> $DIR/feature-gate.rs:32:55
45+
|
46+
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
47+
| ^^^
48+
49+
error: expected expression, found `let` statement
50+
--> $DIR/feature-gate.rs:32:68
51+
|
52+
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
53+
| ^^^
54+
55+
error: expected expression, found `let` statement
56+
--> $DIR/feature-gate.rs:54:16
4557
|
4658
LL | use_expr!((let 0 = 1 && 0 == 0));
4759
| ^^^
4860

4961
error: expected expression, found `let` statement
50-
--> $DIR/feature-gate.rs:54:16
62+
--> $DIR/feature-gate.rs:56:16
5163
|
5264
LL | use_expr!((let 0 = 1));
5365
| ^^^
5466

5567
error: no rules expected the token `let`
56-
--> $DIR/feature-gate.rs:62:15
68+
--> $DIR/feature-gate.rs:64:15
5769
|
5870
LL | macro_rules! use_expr {
5971
| --------------------- when calling this macro
@@ -102,7 +114,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
102114
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
103115

104116
error[E0658]: `if let` guards are experimental
105-
--> $DIR/feature-gate.rs:36:12
117+
--> $DIR/feature-gate.rs:38:12
106118
|
107119
LL | () if let Range { start: _, end: _ } = (true..true) && false => {}
108120
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -112,7 +124,7 @@ LL | () if let Range { start: _, end: _ } = (true..true) && false => {}
112124
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
113125

114126
error[E0658]: `if let` guards are experimental
115-
--> $DIR/feature-gate.rs:58:12
127+
--> $DIR/feature-gate.rs:60:12
116128
|
117129
LL | () if let 0 = 1 => {}
118130
| ^^^^^^^^^^^^
@@ -121,6 +133,6 @@ LL | () if let 0 = 1 => {}
121133
= help: add `#![feature(if_let_guard)]` to the crate attributes to enable
122134
= help: you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`
123135

124-
error: aborting due to 16 previous errors
136+
error: aborting due to 18 previous errors
125137

126138
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)