Skip to content

Commit

Permalink
Auto merge of rust-lang#100048 - matthiaskrgr:rollup-agimvm6, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed Aug 2, 2022
2 parents 9538d2d + 6ab19fd commit ca37a45
Show file tree
Hide file tree
Showing 20 changed files with 418 additions and 324 deletions.
6 changes: 2 additions & 4 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use self::ValuePairs::*;
use self::opaque_types::OpaqueTypeStorage;
pub(crate) use self::undo_log::{InferCtxtUndoLogs, Snapshot, UndoLog};

use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine};
use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine, TraitEngineExt};

use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc;
Expand Down Expand Up @@ -645,9 +645,7 @@ impl<'tcx, T> InferOk<'tcx, T> {
fulfill_cx: &mut dyn TraitEngine<'tcx>,
) -> T {
let InferOk { value, obligations } = self;
for obligation in obligations {
fulfill_cx.register_predicate_obligation(infcx, obligation);
}
fulfill_cx.register_predicate_obligations(infcx, obligations);
value
}
}
Expand Down
56 changes: 17 additions & 39 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,8 +1391,6 @@ impl<'a> Parser<'a> {
} else if self.is_do_yeet() {
self.parse_yeet_expr(attrs)
} else if self.check_keyword(kw::Let) {
self.manage_let_chains_context();
self.bump();
self.parse_let_expr(attrs)
} else if self.eat_keyword(kw::Underscore) {
Ok(self.mk_expr(self.prev_token.span, ExprKind::Underscore, attrs))
Expand Down Expand Up @@ -2342,32 +2340,24 @@ impl<'a> Parser<'a> {

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

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

/// Parses a `let $pat = $expr` pseudo-expression.
/// The `let` token has already been eaten.
fn parse_let_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
self.bump(); // Eat `let` token
let lo = self.prev_token.span;
let pat = self.parse_pat_allow_top_alt(
None,
Expand Down Expand Up @@ -2687,7 +2677,9 @@ impl<'a> Parser<'a> {
// `&&` tokens.
fn check_let_expr(expr: &Expr) -> bool {
match expr.kind {
ExprKind::Binary(_, ref lhs, ref rhs) => check_let_expr(lhs) || check_let_expr(rhs),
ExprKind::Binary(BinOp { node: BinOpKind::And, .. }, ref lhs, ref rhs) => {
check_let_expr(lhs) || check_let_expr(rhs)
}
ExprKind::Let(..) => true,
_ => false,
}
Expand All @@ -2703,9 +2695,8 @@ impl<'a> Parser<'a> {
)?;
let guard = if this.eat_keyword(kw::If) {
let if_span = this.prev_token.span;
let cond = this.with_let_management(true, |local_this| local_this.parse_expr())?;
let has_let_expr = check_let_expr(&cond);
if has_let_expr {
let cond = this.parse_expr_res(Restrictions::ALLOW_LET, None)?;
if check_let_expr(&cond) {
let span = if_span.to(cond.span);
this.sess.gated_spans.gate(sym::if_let_guard, span);
}
Expand Down Expand Up @@ -3279,17 +3270,4 @@ impl<'a> Parser<'a> {
Ok((res, trailing))
})
}

// Calls `f` with the internal `let_expr_allowed` set to `let_expr_allowed` and then
// sets the internal `let_expr_allowed` back to its original value.
fn with_let_management<T>(
&mut self,
let_expr_allowed: bool,
f: impl FnOnce(&mut Self) -> T,
) -> T {
let last_let_expr_allowed = mem::replace(&mut self.let_expr_allowed, let_expr_allowed);
let rslt = f(self);
self.let_expr_allowed = last_let_expr_allowed;
rslt
}
}
7 changes: 2 additions & 5 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ bitflags::bitflags! {
const STMT_EXPR = 1 << 0;
const NO_STRUCT_LITERAL = 1 << 1;
const CONST_EXPR = 1 << 2;
const ALLOW_LET = 1 << 3;
}
}

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

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

/// Stores span information about a closure.
#[derive(Clone)]
Expand Down Expand Up @@ -462,7 +460,6 @@ impl<'a> Parser<'a> {
inner_attr_ranges: Default::default(),
},
current_closure: None,
let_expr_allowed: false,
};

// Make parser point to the first token.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_trait_selection/src/traits/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ pub fn codegen_fulfill_obligation<'tcx>(
tcx: TyCtxt<'tcx>,
(param_env, trait_ref): (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>),
) -> Result<&'tcx ImplSource<'tcx, ()>, CodegenObligationError> {
// Remove any references to regions; this helps improve caching.
let trait_ref = tcx.erase_regions(trait_ref);
// We expect the input to be fully normalized.
debug_assert_eq!(trait_ref, tcx.normalize_erasing_regions(param_env, trait_ref));

Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_typeck/src/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// 6 | | };
// | |_____^ expected integer, found `()`
// ```
if block.expr.is_none() && block.stmts.is_empty() && outer_span.is_some() {
let sp = if let Some(cs) = cond_span.find_ancestor_inside(span) {
span.with_hi(cs.hi())
} else {
span
};
outer_span = Some(sp);
if block.expr.is_none() && block.stmts.is_empty()
&& let Some(outer_span) = &mut outer_span
&& let Some(cond_span) = cond_span.find_ancestor_inside(*outer_span)
{
*outer_span = outer_span.with_hi(cond_span.hi())
}

(self.find_block_span(block), block.hir_id)
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/solid/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ impl Socket {
pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
self.set_nonblocking(true)?;
let r = unsafe {
let (addrp, len) = addr.into_inner();
cvt(netc::connect(self.0.raw(), addrp, len))
let (addr, len) = addr.into_inner();
cvt(netc::connect(self.0.raw(), addr.as_ptr(), len))
};
self.set_nonblocking(false)?;

Expand Down
8 changes: 7 additions & 1 deletion src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ impl Step for Std {
cargo_subcommand(builder.kind),
);

cargo.arg("--all-targets");
// If we're not in stage 0, tests and examples will fail to compile
// from `core` definitions being loaded from two different `libcore`
// .rmeta and .rlib files.
if compiler.stage == 0 {
cargo.arg("--all-targets");
}

std_cargo(builder, target, compiler.stage, &mut cargo);

// Explicitly pass -p for all dependencies krates -- this will force cargo
Expand Down
2 changes: 1 addition & 1 deletion src/doc/embedded-book
6 changes: 3 additions & 3 deletions src/doc/man/rustc.1
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ The optional \fIKIND\fR can be one of \fIstatic\fR, \fIdylib\fR, or
\fIframework\fR.
If omitted, \fIdylib\fR is assumed.
.TP
\fB\-\-crate\-type\fR [bin|lib|rlib|dylib|cdylib|staticlib]
\fB\-\-crate\-type\fR [bin|lib|rlib|dylib|cdylib|staticlib|proc\-macro]
Comma separated list of types of crates for the compiler to emit.
.TP
\fB\-\-crate\-name\fR \fINAME\fR
Specify the name of the crate being built.
.TP
\fB\-\-emit\fR [asm|llvm\-bc|llvm\-ir|obj|link|dep\-info|mir][=\fIPATH\fR]
\fB\-\-emit\fR [asm|llvm\-bc|llvm\-ir|obj|metadata|link|dep\-info|mir][=\fIPATH\fR]
Configure the output that \fBrustc\fR will produce. Each emission may also have
an optional explicit output \fIPATH\fR specified for that particular emission
kind. This path takes precedence over the \fB-o\fR option.
.TP
\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]
\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]
Comma separated list of compiler information to print on stdout.
.TP
\fB\-g\fR
Expand Down
10 changes: 9 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,14 @@ table,
}

.item-info .stab {
display: inline-block;
width: fit-content;
/* This min-height is needed to unify the height of the stab elements because some of them
have emojis.
*/
min-height: 36px;
display: flex;
align-items: center;
white-space: pre-wrap;
}
.stab {
padding: 3px;
Expand All @@ -1121,6 +1128,7 @@ table,
}
.stab p {
display: inline;
margin: 0;
}

.stab .emoji {
Expand Down
8 changes: 0 additions & 8 deletions src/test/rustdoc-gui/item-info-width.goml

This file was deleted.

32 changes: 32 additions & 0 deletions src/test/rustdoc-gui/item-info.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This test ensures a few things for item info elements.
goto: file://|DOC_PATH|/lib2/struct.Foo.html
// Ensuring that the item information don't take 100% of the width if unnecessary.
// We set a fixed size so there is no chance of "random" resize.
size: (1100, 800)
// We check that ".item-info" is bigger than its content.
assert-css: (".item-info", {"width": "790px"})
assert-css: (".item-info .stab", {"width": "289px"})
assert-position: (".item-info .stab", {"x": 295})

// Now we ensure that they're not rendered on the same line.
goto: file://|DOC_PATH|/lib2/trait.Trait.html
// We first ensure that there are two item info on the trait.
assert-count: ("#main-content > .item-info .stab", 2)
// They should not have the same `y` position!
compare-elements-position-false: (
"#main-content > .item-info .stab:nth-of-type(1)",
"#main-content > .item-info .stab:nth-of-type(2)",
("y"),
)
// But they should have the same `x` position.
compare-elements-position: (
"#main-content > .item-info .stab:nth-of-type(1)",
"#main-content > .item-info .stab:nth-of-type(2)",
("x"),
)
// They are supposed to have the same height too.
compare-elements-css: (
"#main-content > .item-info .stab:nth-of-type(1)",
"#main-content > .item-info .stab:nth-of-type(2)",
["height"],
)
3 changes: 3 additions & 0 deletions src/test/rustdoc-gui/src/lib2/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ impl Foo {
pub fn a_method(&self) {}
}

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

#[deprecated = "Whatever [`Foo`](#tadam)"]
fn foo() {}
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/rfc-2294-if-let-guard/feature-gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ fn _if_let_guard() {
() if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
//~^ ERROR `if let` guards are experimental
//~| ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement
//~| ERROR expected expression, found `let` statement

() if let Range { start: _, end: _ } = (true..true) && false => {}
//~^ ERROR `if let` guards are experimental
Expand Down
24 changes: 18 additions & 6 deletions src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,31 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
| ^^^

error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:52:16
--> $DIR/feature-gate.rs:32:55
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^

error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:32:68
|
LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) => {}
| ^^^

error: expected expression, found `let` statement
--> $DIR/feature-gate.rs:54:16
|
LL | use_expr!((let 0 = 1 && 0 == 0));
| ^^^

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

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

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

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

error: aborting due to 16 previous errors
error: aborting due to 18 previous errors

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

0 comments on commit ca37a45

Please sign in to comment.