Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #103083

Merged
merged 22 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
99182dd
std: use semaphore for thread parking on Apple platforms
joboet Oct 6, 2022
0ad4dd4
std: add thread parking tests
joboet Oct 6, 2022
b4c8a7b
std: remove unused linker attribute
joboet Oct 8, 2022
c320ab9
std: do not use dispatch semaphore under miri (yet)
joboet Oct 8, 2022
ad8b242
Let chains should still drop temporaries
nathanwhit Oct 12, 2022
e8a6e60
resolve: Add some asserts for unexpected lifetime rib combinations
petrochenkov Oct 9, 2022
e94ec30
resolve: Remove redundant item lifetime ribs
petrochenkov Oct 10, 2022
f634106
resolve: Regroup lifetime rib kinds to account for their purpose
petrochenkov Oct 10, 2022
709a08a
Lower condition directly from AST to HIR
nathanwhit Oct 14, 2022
4e1c09d
Validate MIR in the `drop_order` test
nathanwhit Oct 14, 2022
b841848
check if the self type is `ty::Float` before getting second substs
TaKO8Ki Oct 13, 2022
5378677
normalize stderr
TaKO8Ki Oct 13, 2022
40bb4b7
Update cargo
weihanglo Oct 14, 2022
f528414
Add missing checks for `doc(cfg_hide(...))` attribute
GuillaumeGomez Oct 12, 2022
6f0c247
Add UI test for invalid `doc(cfg_hide(...))` attributes
GuillaumeGomez Oct 12, 2022
062ea9c
remove no_core feature
TaKO8Ki Oct 14, 2022
cbe5e7b
Rollup merge of #102773 - joboet:apple_parker, r=thomcc
Dylan-DPC Oct 15, 2022
39ff2a6
Rollup merge of #102884 - petrochenkov:liferib, r=cjgillot
Dylan-DPC Oct 15, 2022
59e0af6
Rollup merge of #102954 - GuillaumeGomez:cfg-hide-attr-checks, r=Mani…
Dylan-DPC Oct 15, 2022
b79ad57
Rollup merge of #102998 - nathanwhit:let-chains-drop-order, r=eholk
Dylan-DPC Oct 15, 2022
65dca11
Rollup merge of #103003 - TaKO8Ki:fix-102989, r=compiler-errors
Dylan-DPC Oct 15, 2022
ac23c9f
Rollup merge of #103041 - weihanglo:update-cargo, r=ehuss
Dylan-DPC Oct 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ dependencies = [
"cargo-test-macro",
"cargo-test-support",
"cargo-util",
"clap 4.0.9",
"clap 4.0.15",
"crates-io",
"curl",
"curl-sys",
Expand Down Expand Up @@ -439,7 +439,7 @@ dependencies = [

[[package]]
name = "cargo-util"
version = "0.2.1"
version = "0.2.2"
dependencies = [
"anyhow",
"core-foundation",
Expand Down Expand Up @@ -602,9 +602,9 @@ dependencies = [

[[package]]
name = "clap"
version = "4.0.9"
version = "4.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30607dd93c420c6f1f80b544be522a0238a7db35e6a12968d28910983fee0df0"
checksum = "6bf8832993da70a4c6d13c581f4463c2bdda27b9bf1c5498dc4365543abe6d6f"
dependencies = [
"atty",
"bitflags",
Expand Down
65 changes: 45 additions & 20 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,32 +387,58 @@ impl<'hir> LoweringContext<'_, 'hir> {
then: &Block,
else_opt: Option<&Expr>,
) -> hir::ExprKind<'hir> {
let lowered_cond = self.lower_expr(cond);
let new_cond = self.manage_let_cond(lowered_cond);
let lowered_cond = self.lower_cond(cond);
let then_expr = self.lower_block_expr(then);
if let Some(rslt) = else_opt {
hir::ExprKind::If(new_cond, self.arena.alloc(then_expr), Some(self.lower_expr(rslt)))
hir::ExprKind::If(
lowered_cond,
self.arena.alloc(then_expr),
Some(self.lower_expr(rslt)),
)
} else {
hir::ExprKind::If(new_cond, self.arena.alloc(then_expr), None)
hir::ExprKind::If(lowered_cond, self.arena.alloc(then_expr), None)
}
}

// If `cond` kind is `let`, returns `let`. Otherwise, wraps and returns `cond`
// in a temporary block.
fn manage_let_cond(&mut self, cond: &'hir hir::Expr<'hir>) -> &'hir hir::Expr<'hir> {
fn has_let_expr<'hir>(expr: &'hir hir::Expr<'hir>) -> bool {
match expr.kind {
hir::ExprKind::Binary(_, lhs, rhs) => has_let_expr(lhs) || has_let_expr(rhs),
hir::ExprKind::Let(..) => true,
// Lowers a condition (i.e. `cond` in `if cond` or `while cond`), wrapping it in a terminating scope
// so that temporaries created in the condition don't live beyond it.
fn lower_cond(&mut self, cond: &Expr) -> &'hir hir::Expr<'hir> {
fn has_let_expr(expr: &Expr) -> bool {
match &expr.kind {
ExprKind::Binary(_, lhs, rhs) => has_let_expr(lhs) || has_let_expr(rhs),
ExprKind::Let(..) => true,
_ => false,
}
}
if has_let_expr(cond) {
cond
} else {
let reason = DesugaringKind::CondTemporary;
let span_block = self.mark_span_with_reason(reason, cond.span, None);
self.expr_drop_temps(span_block, cond, AttrVec::new())

// We have to take special care for `let` exprs in the condition, e.g. in
// `if let pat = val` or `if foo && let pat = val`, as we _do_ want `val` to live beyond the
// condition in this case.
//
// In order to mantain the drop behavior for the non `let` parts of the condition,
// we still wrap them in terminating scopes, e.g. `if foo && let pat = val` essentially
// gets transformed into `if { let _t = foo; _t } && let pat = val`
match &cond.kind {
ExprKind::Binary(op @ Spanned { node: ast::BinOpKind::And, .. }, lhs, rhs)
if has_let_expr(cond) =>
{
let op = self.lower_binop(*op);
let lhs = self.lower_cond(lhs);
let rhs = self.lower_cond(rhs);

self.arena.alloc(self.expr(
cond.span,
hir::ExprKind::Binary(op, lhs, rhs),
AttrVec::new(),
))
}
ExprKind::Let(..) => self.lower_expr(cond),
_ => {
let cond = self.lower_expr(cond);
let reason = DesugaringKind::CondTemporary;
let span_block = self.mark_span_with_reason(reason, cond.span, None);
self.expr_drop_temps(span_block, cond, AttrVec::new())
}
}
}

Expand All @@ -439,14 +465,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
body: &Block,
opt_label: Option<Label>,
) -> hir::ExprKind<'hir> {
let lowered_cond = self.with_loop_condition_scope(|t| t.lower_expr(cond));
let new_cond = self.manage_let_cond(lowered_cond);
let lowered_cond = self.with_loop_condition_scope(|t| t.lower_cond(cond));
let then = self.lower_block_expr(body);
let expr_break = self.expr_break(span, AttrVec::new());
let stmt_break = self.stmt_expr(span, expr_break);
let else_blk = self.block_all(span, arena_vec![self; stmt_break], None);
let else_expr = self.arena.alloc(self.expr_block(else_blk, AttrVec::new()));
let if_kind = hir::ExprKind::If(new_cond, self.arena.alloc(then), Some(else_expr));
let if_kind = hir::ExprKind::If(lowered_cond, self.arena.alloc(then), Some(else_expr));
let if_expr = self.expr(span, if_kind, AttrVec::new());
let block = self.block_expr(self.arena.alloc(if_expr));
let span = self.lower_span(span.with_hi(cond.span.hi()));
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/passes.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ passes_doc_test_takes_list =
passes_doc_primitive =
`doc(primitive)` should never have been stable

passes_doc_cfg_hide_takes_list =
`#[doc(cfg_hide(...)]` takes a list of attributes

passes_doc_test_unknown_any =
unknown `doc` attribute `{$path}`

Expand Down
23 changes: 23 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,22 @@ impl CheckAttrVisitor<'_> {
is_valid
}

/// Check that the `#![doc(cfg_hide(...))]` attribute only contains a list of attributes.
/// Returns `true` if valid.
fn check_doc_cfg_hide(&self, meta: &NestedMetaItem, hir_id: HirId) -> bool {
if meta.meta_item_list().is_some() {
true
} else {
self.tcx.emit_spanned_lint(
INVALID_DOC_ATTRIBUTES,
hir_id,
meta.span(),
errors::DocCfgHideTakesList,
);
false
}
}

/// Runs various checks on `#[doc]` attributes. Returns `true` if valid.
///
/// `specified_inline` should be initialized to `None` and kept for the scope
Expand Down Expand Up @@ -987,6 +1003,13 @@ impl CheckAttrVisitor<'_> {
is_valid = false;
}

sym::cfg_hide
if !self.check_attr_crate_level(attr, meta, hir_id)
|| !self.check_doc_cfg_hide(meta, hir_id) =>
{
is_valid = false;
}

sym::inline | sym::no_inline
if !self.check_doc_inline(
attr,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ pub struct DocTestUnknown {
#[diag(passes::doc_test_takes_list)]
pub struct DocTestTakesList;

#[derive(LintDiagnostic)]
#[diag(passes::doc_cfg_hide_takes_list)]
pub struct DocCfgHideTakesList;

#[derive(LintDiagnostic)]
#[diag(passes::doc_primitive)]
pub struct DocPrimitive;
Expand Down
Loading