Skip to content

Commit c93ef33

Browse files
committed
Auto merge of rust-lang#103083 - Dylan-DPC:rollup-97cvwdv, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#102773 (Use semaphores for thread parking on Apple platforms) - rust-lang#102884 (resolve: Some cleanup, asserts and tests for lifetime ribs) - rust-lang#102954 (Add missing checks for `doc(cfg_hide(...))`) - rust-lang#102998 (Drop temporaries created in a condition, even if it's a let chain) - rust-lang#103003 (Fix `suggest_floating_point_literal` ICE) - rust-lang#103041 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b15e2c1 + ac23c9f commit c93ef33

File tree

18 files changed

+610
-104
lines changed

18 files changed

+610
-104
lines changed

Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ dependencies = [
297297
"cargo-test-macro",
298298
"cargo-test-support",
299299
"cargo-util",
300-
"clap 4.0.9",
300+
"clap 4.0.15",
301301
"crates-io",
302302
"curl",
303303
"curl-sys",
@@ -439,7 +439,7 @@ dependencies = [
439439

440440
[[package]]
441441
name = "cargo-util"
442-
version = "0.2.1"
442+
version = "0.2.2"
443443
dependencies = [
444444
"anyhow",
445445
"core-foundation",
@@ -602,9 +602,9 @@ dependencies = [
602602

603603
[[package]]
604604
name = "clap"
605-
version = "4.0.9"
605+
version = "4.0.15"
606606
source = "registry+https://github.com/rust-lang/crates.io-index"
607-
checksum = "30607dd93c420c6f1f80b544be522a0238a7db35e6a12968d28910983fee0df0"
607+
checksum = "6bf8832993da70a4c6d13c581f4463c2bdda27b9bf1c5498dc4365543abe6d6f"
608608
dependencies = [
609609
"atty",
610610
"bitflags",

compiler/rustc_ast_lowering/src/expr.rs

+45-20
Original file line numberDiff line numberDiff line change
@@ -387,32 +387,58 @@ impl<'hir> LoweringContext<'_, 'hir> {
387387
then: &Block,
388388
else_opt: Option<&Expr>,
389389
) -> hir::ExprKind<'hir> {
390-
let lowered_cond = self.lower_expr(cond);
391-
let new_cond = self.manage_let_cond(lowered_cond);
390+
let lowered_cond = self.lower_cond(cond);
392391
let then_expr = self.lower_block_expr(then);
393392
if let Some(rslt) = else_opt {
394-
hir::ExprKind::If(new_cond, self.arena.alloc(then_expr), Some(self.lower_expr(rslt)))
393+
hir::ExprKind::If(
394+
lowered_cond,
395+
self.arena.alloc(then_expr),
396+
Some(self.lower_expr(rslt)),
397+
)
395398
} else {
396-
hir::ExprKind::If(new_cond, self.arena.alloc(then_expr), None)
399+
hir::ExprKind::If(lowered_cond, self.arena.alloc(then_expr), None)
397400
}
398401
}
399402

400-
// If `cond` kind is `let`, returns `let`. Otherwise, wraps and returns `cond`
401-
// in a temporary block.
402-
fn manage_let_cond(&mut self, cond: &'hir hir::Expr<'hir>) -> &'hir hir::Expr<'hir> {
403-
fn has_let_expr<'hir>(expr: &'hir hir::Expr<'hir>) -> bool {
404-
match expr.kind {
405-
hir::ExprKind::Binary(_, lhs, rhs) => has_let_expr(lhs) || has_let_expr(rhs),
406-
hir::ExprKind::Let(..) => true,
403+
// Lowers a condition (i.e. `cond` in `if cond` or `while cond`), wrapping it in a terminating scope
404+
// so that temporaries created in the condition don't live beyond it.
405+
fn lower_cond(&mut self, cond: &Expr) -> &'hir hir::Expr<'hir> {
406+
fn has_let_expr(expr: &Expr) -> bool {
407+
match &expr.kind {
408+
ExprKind::Binary(_, lhs, rhs) => has_let_expr(lhs) || has_let_expr(rhs),
409+
ExprKind::Let(..) => true,
407410
_ => false,
408411
}
409412
}
410-
if has_let_expr(cond) {
411-
cond
412-
} else {
413-
let reason = DesugaringKind::CondTemporary;
414-
let span_block = self.mark_span_with_reason(reason, cond.span, None);
415-
self.expr_drop_temps(span_block, cond, AttrVec::new())
413+
414+
// We have to take special care for `let` exprs in the condition, e.g. in
415+
// `if let pat = val` or `if foo && let pat = val`, as we _do_ want `val` to live beyond the
416+
// condition in this case.
417+
//
418+
// In order to mantain the drop behavior for the non `let` parts of the condition,
419+
// we still wrap them in terminating scopes, e.g. `if foo && let pat = val` essentially
420+
// gets transformed into `if { let _t = foo; _t } && let pat = val`
421+
match &cond.kind {
422+
ExprKind::Binary(op @ Spanned { node: ast::BinOpKind::And, .. }, lhs, rhs)
423+
if has_let_expr(cond) =>
424+
{
425+
let op = self.lower_binop(*op);
426+
let lhs = self.lower_cond(lhs);
427+
let rhs = self.lower_cond(rhs);
428+
429+
self.arena.alloc(self.expr(
430+
cond.span,
431+
hir::ExprKind::Binary(op, lhs, rhs),
432+
AttrVec::new(),
433+
))
434+
}
435+
ExprKind::Let(..) => self.lower_expr(cond),
436+
_ => {
437+
let cond = self.lower_expr(cond);
438+
let reason = DesugaringKind::CondTemporary;
439+
let span_block = self.mark_span_with_reason(reason, cond.span, None);
440+
self.expr_drop_temps(span_block, cond, AttrVec::new())
441+
}
416442
}
417443
}
418444

@@ -439,14 +465,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
439465
body: &Block,
440466
opt_label: Option<Label>,
441467
) -> hir::ExprKind<'hir> {
442-
let lowered_cond = self.with_loop_condition_scope(|t| t.lower_expr(cond));
443-
let new_cond = self.manage_let_cond(lowered_cond);
468+
let lowered_cond = self.with_loop_condition_scope(|t| t.lower_cond(cond));
444469
let then = self.lower_block_expr(body);
445470
let expr_break = self.expr_break(span, AttrVec::new());
446471
let stmt_break = self.stmt_expr(span, expr_break);
447472
let else_blk = self.block_all(span, arena_vec![self; stmt_break], None);
448473
let else_expr = self.arena.alloc(self.expr_block(else_blk, AttrVec::new()));
449-
let if_kind = hir::ExprKind::If(new_cond, self.arena.alloc(then), Some(else_expr));
474+
let if_kind = hir::ExprKind::If(lowered_cond, self.arena.alloc(then), Some(else_expr));
450475
let if_expr = self.expr(span, if_kind, AttrVec::new());
451476
let block = self.block_expr(self.arena.alloc(if_expr));
452477
let span = self.lower_span(span.with_hi(cond.span.hi()));

compiler/rustc_error_messages/locales/en-US/passes.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ passes_doc_test_takes_list =
145145
passes_doc_primitive =
146146
`doc(primitive)` should never have been stable
147147
148+
passes_doc_cfg_hide_takes_list =
149+
`#[doc(cfg_hide(...)]` takes a list of attributes
150+
148151
passes_doc_test_unknown_any =
149152
unknown `doc` attribute `{$path}`
150153

compiler/rustc_passes/src/check_attr.rs

+23
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,22 @@ impl CheckAttrVisitor<'_> {
934934
is_valid
935935
}
936936

937+
/// Check that the `#![doc(cfg_hide(...))]` attribute only contains a list of attributes.
938+
/// Returns `true` if valid.
939+
fn check_doc_cfg_hide(&self, meta: &NestedMetaItem, hir_id: HirId) -> bool {
940+
if meta.meta_item_list().is_some() {
941+
true
942+
} else {
943+
self.tcx.emit_spanned_lint(
944+
INVALID_DOC_ATTRIBUTES,
945+
hir_id,
946+
meta.span(),
947+
errors::DocCfgHideTakesList,
948+
);
949+
false
950+
}
951+
}
952+
937953
/// Runs various checks on `#[doc]` attributes. Returns `true` if valid.
938954
///
939955
/// `specified_inline` should be initialized to `None` and kept for the scope
@@ -987,6 +1003,13 @@ impl CheckAttrVisitor<'_> {
9871003
is_valid = false;
9881004
}
9891005

1006+
sym::cfg_hide
1007+
if !self.check_attr_crate_level(attr, meta, hir_id)
1008+
|| !self.check_doc_cfg_hide(meta, hir_id) =>
1009+
{
1010+
is_valid = false;
1011+
}
1012+
9901013
sym::inline | sym::no_inline
9911014
if !self.check_doc_inline(
9921015
attr,

compiler/rustc_passes/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ pub struct DocTestUnknown {
271271
#[diag(passes::doc_test_takes_list)]
272272
pub struct DocTestTakesList;
273273

274+
#[derive(LintDiagnostic)]
275+
#[diag(passes::doc_cfg_hide_takes_list)]
276+
pub struct DocCfgHideTakesList;
277+
274278
#[derive(LintDiagnostic)]
275279
#[diag(passes::doc_primitive)]
276280
pub struct DocPrimitive;

0 commit comments

Comments
 (0)