Skip to content

Commit 394c406

Browse files
committed
Auto merge of rust-lang#130269 - Zalathar:rollup-coxzt2t, r=Zalathar
Rollup of 8 pull requests Successful merges: - rust-lang#125060 (Expand documentation of PathBuf, discussing lack of sanitization) - rust-lang#129367 (Fix default/minimum deployment target for Aarch64 simulator targets) - rust-lang#130156 (Add test for S_OBJNAME & update test for LF_BUILDINFO cl and cmd) - rust-lang#130160 (Fix `slice::first_mut` docs) - rust-lang#130235 (Simplify some nested `if` statements) - rust-lang#130250 (Fix `clippy::useless_conversion`) - rust-lang#130252 (Properly report error on `const gen fn`) - rust-lang#130256 (Re-run coverage tests if `coverage-dump` was modified) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f753bc7 + 458a57a commit 394c406

File tree

90 files changed

+740
-761
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+740
-761
lines changed

compiler/rustc_ast/src/ast.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -2602,12 +2602,12 @@ impl CoroutineKind {
26022602
}
26032603
}
26042604

2605-
pub fn is_async(self) -> bool {
2606-
matches!(self, CoroutineKind::Async { .. })
2607-
}
2608-
2609-
pub fn is_gen(self) -> bool {
2610-
matches!(self, CoroutineKind::Gen { .. })
2605+
pub fn as_str(self) -> &'static str {
2606+
match self {
2607+
CoroutineKind::Async { .. } => "async",
2608+
CoroutineKind::Gen { .. } => "gen",
2609+
CoroutineKind::AsyncGen { .. } => "async gen",
2610+
}
26112611
}
26122612

26132613
pub fn closure_id(self) -> NodeId {
@@ -3486,7 +3486,7 @@ impl From<ForeignItemKind> for ItemKind {
34863486
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
34873487
match foreign_item_kind {
34883488
ForeignItemKind::Static(box static_foreign_item) => {
3489-
ItemKind::Static(Box::new(static_foreign_item.into()))
3489+
ItemKind::Static(Box::new(static_foreign_item))
34903490
}
34913491
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
34923492
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
@@ -3500,9 +3500,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
35003500

35013501
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
35023502
Ok(match item_kind {
3503-
ItemKind::Static(box static_item) => {
3504-
ForeignItemKind::Static(Box::new(static_item.into()))
3505-
}
3503+
ItemKind::Static(box static_item) => ForeignItemKind::Static(Box::new(static_item)),
35063504
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),
35073505
ItemKind::TyAlias(ty_alias_kind) => ForeignItemKind::TyAlias(ty_alias_kind),
35083506
ItemKind::MacCall(a) => ForeignItemKind::MacCall(a),

compiler/rustc_ast/src/entry.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,16 @@ pub fn entry_point_type(
4545
EntryPointType::Start
4646
} else if attr::contains_name(attrs, sym::rustc_main) {
4747
EntryPointType::RustcMainAttr
48-
} else {
49-
if let Some(name) = name
50-
&& name == sym::main
51-
{
52-
if at_root {
53-
// This is a top-level function so it can be `main`.
54-
EntryPointType::MainNamed
55-
} else {
56-
EntryPointType::OtherMain
57-
}
48+
} else if let Some(name) = name
49+
&& name == sym::main
50+
{
51+
if at_root {
52+
// This is a top-level function so it can be `main`.
53+
EntryPointType::MainNamed
5854
} else {
59-
EntryPointType::None
55+
EntryPointType::OtherMain
6056
}
57+
} else {
58+
EntryPointType::None
6159
}
6260
}

compiler/rustc_ast_lowering/src/index.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,24 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
7878

7979
// Make sure that the DepNode of some node coincides with the HirId
8080
// owner of that node.
81-
if cfg!(debug_assertions) {
82-
if hir_id.owner != self.owner {
83-
span_bug!(
84-
span,
85-
"inconsistent HirId at `{:?}` for `{:?}`: \
81+
if cfg!(debug_assertions) && hir_id.owner != self.owner {
82+
span_bug!(
83+
span,
84+
"inconsistent HirId at `{:?}` for `{:?}`: \
8685
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
87-
self.tcx.sess.source_map().span_to_diagnostic_string(span),
88-
node,
89-
self.tcx
90-
.definitions_untracked()
91-
.def_path(self.owner.def_id)
92-
.to_string_no_crate_verbose(),
93-
self.owner,
94-
self.tcx
95-
.definitions_untracked()
96-
.def_path(hir_id.owner.def_id)
97-
.to_string_no_crate_verbose(),
98-
hir_id.owner,
99-
)
100-
}
86+
self.tcx.sess.source_map().span_to_diagnostic_string(span),
87+
node,
88+
self.tcx
89+
.definitions_untracked()
90+
.def_path(self.owner.def_id)
91+
.to_string_no_crate_verbose(),
92+
self.owner,
93+
self.tcx
94+
.definitions_untracked()
95+
.def_path(hir_id.owner.def_id)
96+
.to_string_no_crate_verbose(),
97+
hir_id.owner,
98+
)
10199
}
102100

103101
self.nodes[hir_id.local_id] = ParentedNode { parent: self.parent_node, node };

compiler/rustc_ast_lowering/src/item.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -628,13 +628,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
628628
.map_or(Const::No, |attr| Const::Yes(attr.span)),
629629
_ => Const::No,
630630
}
631+
} else if self.tcx.is_const_trait(def_id) {
632+
// FIXME(effects) span
633+
Const::Yes(self.tcx.def_ident_span(def_id).unwrap())
631634
} else {
632-
if self.tcx.is_const_trait(def_id) {
633-
// FIXME(effects) span
634-
Const::Yes(self.tcx.def_ident_span(def_id).unwrap())
635-
} else {
636-
Const::No
637-
}
635+
Const::No
638636
}
639637
} else {
640638
Const::No

compiler/rustc_ast_passes/messages.ftl

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ ast_passes_body_in_extern = incorrect `{$kind}` inside `extern` block
4040
4141
ast_passes_bound_in_context = bounds on `type`s in {$ctx} have no effect
4242
43-
ast_passes_const_and_async = functions cannot be both `const` and `async`
44-
.const = `const` because of this
45-
.async = `async` because of this
46-
.label = {""}
47-
4843
ast_passes_const_and_c_variadic = functions cannot be both `const` and C-variadic
4944
.const = `const` because of this
5045
.variadic = C-variadic because of this
5146
47+
ast_passes_const_and_coroutine = functions cannot be both `const` and `{$coroutine_kind}`
48+
.const = `const` because of this
49+
.coroutine = `{$coroutine_kind}` because of this
50+
.label = {""}
51+
5252
ast_passes_const_bound_trait_object = const trait bounds are not allowed in trait object types
5353
5454
ast_passes_const_without_body =

compiler/rustc_ast_passes/src/ast_validation.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,13 @@ impl<'a> AstValidator<'a> {
447447
fn check_item_safety(&self, span: Span, safety: Safety) {
448448
match self.extern_mod_safety {
449449
Some(extern_safety) => {
450-
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_)) {
451-
if extern_safety == Safety::Default {
452-
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
453-
item_span: span,
454-
block: Some(self.current_extern_span().shrink_to_lo()),
455-
});
456-
}
450+
if matches!(safety, Safety::Unsafe(_) | Safety::Safe(_))
451+
&& extern_safety == Safety::Default
452+
{
453+
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
454+
item_span: span,
455+
block: Some(self.current_extern_span().shrink_to_lo()),
456+
});
457457
}
458458
}
459459
None => {
@@ -1418,21 +1418,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14181418

14191419
// Functions cannot both be `const async` or `const gen`
14201420
if let Some(&FnHeader {
1421-
constness: Const::Yes(cspan),
1421+
constness: Const::Yes(const_span),
14221422
coroutine_kind: Some(coroutine_kind),
14231423
..
14241424
}) = fk.header()
14251425
{
1426-
let aspan = match coroutine_kind {
1427-
CoroutineKind::Async { span: aspan, .. }
1428-
| CoroutineKind::Gen { span: aspan, .. }
1429-
| CoroutineKind::AsyncGen { span: aspan, .. } => aspan,
1430-
};
1431-
// FIXME(gen_blocks): Report a different error for `const gen`
1432-
self.dcx().emit_err(errors::ConstAndAsync {
1433-
spans: vec![cspan, aspan],
1434-
cspan,
1435-
aspan,
1426+
self.dcx().emit_err(errors::ConstAndCoroutine {
1427+
spans: vec![coroutine_kind.span(), const_span],
1428+
const_span,
1429+
coroutine_span: coroutine_kind.span(),
1430+
coroutine_kind: coroutine_kind.as_str(),
14361431
span,
14371432
});
14381433
}

compiler/rustc_ast_passes/src/errors.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -657,16 +657,17 @@ pub(crate) enum TildeConstReason {
657657
}
658658

659659
#[derive(Diagnostic)]
660-
#[diag(ast_passes_const_and_async)]
661-
pub(crate) struct ConstAndAsync {
660+
#[diag(ast_passes_const_and_coroutine)]
661+
pub(crate) struct ConstAndCoroutine {
662662
#[primary_span]
663663
pub spans: Vec<Span>,
664664
#[label(ast_passes_const)]
665-
pub cspan: Span,
666-
#[label(ast_passes_async)]
667-
pub aspan: Span,
665+
pub const_span: Span,
666+
#[label(ast_passes_coroutine)]
667+
pub coroutine_span: Span,
668668
#[label]
669669
pub span: Span,
670+
pub coroutine_kind: &'static str,
670671
}
671672

672673
#[derive(Diagnostic)]

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+22-25
Original file line numberDiff line numberDiff line change
@@ -2574,33 +2574,31 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
25742574
}
25752575
impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> {
25762576
fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
2577-
if e.span.contains(self.capture_span) {
2578-
if let hir::ExprKind::Closure(&hir::Closure {
2577+
if e.span.contains(self.capture_span)
2578+
&& let hir::ExprKind::Closure(&hir::Closure {
25792579
kind: hir::ClosureKind::Closure,
25802580
body,
25812581
fn_arg_span,
25822582
fn_decl: hir::FnDecl { inputs, .. },
25832583
..
25842584
}) = e.kind
2585-
&& let hir::Node::Expr(body) = self.tcx.hir_node(body.hir_id)
2586-
{
2587-
self.suggest_arg = "this: &Self".to_string();
2588-
if inputs.len() > 0 {
2589-
self.suggest_arg.push_str(", ");
2590-
}
2591-
self.in_closure = true;
2592-
self.closure_arg_span = fn_arg_span;
2593-
self.visit_expr(body);
2594-
self.in_closure = false;
2585+
&& let hir::Node::Expr(body) = self.tcx.hir_node(body.hir_id)
2586+
{
2587+
self.suggest_arg = "this: &Self".to_string();
2588+
if inputs.len() > 0 {
2589+
self.suggest_arg.push_str(", ");
25952590
}
2591+
self.in_closure = true;
2592+
self.closure_arg_span = fn_arg_span;
2593+
self.visit_expr(body);
2594+
self.in_closure = false;
25962595
}
2597-
if let hir::Expr { kind: hir::ExprKind::Path(path), .. } = e {
2598-
if let hir::QPath::Resolved(_, hir::Path { segments: [seg], .. }) = path
2599-
&& seg.ident.name == kw::SelfLower
2600-
&& self.in_closure
2601-
{
2602-
self.closure_change_spans.push(e.span);
2603-
}
2596+
if let hir::Expr { kind: hir::ExprKind::Path(path), .. } = e
2597+
&& let hir::QPath::Resolved(_, hir::Path { segments: [seg], .. }) = path
2598+
&& seg.ident.name == kw::SelfLower
2599+
&& self.in_closure
2600+
{
2601+
self.closure_change_spans.push(e.span);
26042602
}
26052603
hir::intravisit::walk_expr(self, e);
26062604
}
@@ -2609,20 +2607,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
26092607
if let hir::Pat { kind: hir::PatKind::Binding(_, hir_id, _ident, _), .. } =
26102608
local.pat
26112609
&& let Some(init) = local.init
2612-
{
2613-
if let hir::Expr {
2610+
&& let hir::Expr {
26142611
kind:
26152612
hir::ExprKind::Closure(&hir::Closure {
26162613
kind: hir::ClosureKind::Closure,
26172614
..
26182615
}),
26192616
..
26202617
} = init
2621-
&& init.span.contains(self.capture_span)
2622-
{
2623-
self.closure_local_id = Some(*hir_id);
2624-
}
2618+
&& init.span.contains(self.capture_span)
2619+
{
2620+
self.closure_local_id = Some(*hir_id);
26252621
}
2622+
26262623
hir::intravisit::walk_local(self, local);
26272624
}
26282625

compiler/rustc_borrowck/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2069,12 +2069,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
20692069
// no move out from an earlier location) then this is an attempt at initialization
20702070
// of the union - we should error in that case.
20712071
let tcx = this.infcx.tcx;
2072-
if base.ty(this.body(), tcx).ty.is_union() {
2073-
if this.move_data.path_map[mpi].iter().any(|moi| {
2072+
if base.ty(this.body(), tcx).ty.is_union()
2073+
&& this.move_data.path_map[mpi].iter().any(|moi| {
20742074
this.move_data.moves[*moi].source.is_predecessor_of(location, this.body)
2075-
}) {
2076-
return;
2077-
}
2075+
})
2076+
{
2077+
return;
20782078
}
20792079

20802080
this.report_use_of_moved_or_uninitialized(

compiler/rustc_borrowck/src/region_infer/values.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ impl LivenessValues {
118118
debug!("LivenessValues::add_location(region={:?}, location={:?})", region, location);
119119
if let Some(points) = &mut self.points {
120120
points.insert(region, point);
121-
} else {
122-
if self.elements.point_in_range(point) {
123-
self.live_regions.as_mut().unwrap().insert(region);
124-
}
121+
} else if self.elements.point_in_range(point) {
122+
self.live_regions.as_mut().unwrap().insert(region);
125123
}
126124

127125
// When available, record the loans flowing into this region as live at the given point.
@@ -137,10 +135,8 @@ impl LivenessValues {
137135
debug!("LivenessValues::add_points(region={:?}, points={:?})", region, points);
138136
if let Some(this) = &mut self.points {
139137
this.union_row(region, points);
140-
} else {
141-
if points.iter().any(|point| self.elements.point_in_range(point)) {
142-
self.live_regions.as_mut().unwrap().insert(region);
143-
}
138+
} else if points.iter().any(|point| self.elements.point_in_range(point)) {
139+
self.live_regions.as_mut().unwrap().insert(region);
144140
}
145141

146142
// When available, record the loans flowing into this region as live at the given points.

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,11 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
353353
let location = self.cx.elements.to_location(drop_point);
354354
debug_assert_eq!(self.cx.body.terminator_loc(location.block), location,);
355355

356-
if self.cx.initialized_at_terminator(location.block, mpi) {
357-
if self.drop_live_at.insert(drop_point) {
358-
self.drop_locations.push(location);
359-
self.stack.push(drop_point);
360-
}
356+
if self.cx.initialized_at_terminator(location.block, mpi)
357+
&& self.drop_live_at.insert(drop_point)
358+
{
359+
self.drop_locations.push(location);
360+
self.stack.push(drop_point);
361361
}
362362
}
363363

compiler/rustc_builtin_macros/src/asm.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,11 @@ pub fn parse_asm_args<'a>(
235235
continue;
236236
}
237237
args.named_args.insert(name, slot);
238-
} else {
239-
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
240-
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
241-
let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect();
238+
} else if !args.named_args.is_empty() || !args.reg_args.is_empty() {
239+
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
240+
let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect();
242241

243-
dcx.emit_err(errors::AsmPositionalAfter { span, named, explicit });
244-
}
242+
dcx.emit_err(errors::AsmPositionalAfter { span, named, explicit });
245243
}
246244
}
247245

compiler/rustc_codegen_llvm/src/back/lto.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ fn prepare_lto(
9292
dcx.emit_err(LtoDylib);
9393
return Err(FatalError);
9494
}
95-
} else if *crate_type == CrateType::ProcMacro {
96-
if !cgcx.opts.unstable_opts.dylib_lto {
97-
dcx.emit_err(LtoProcMacro);
98-
return Err(FatalError);
99-
}
95+
} else if *crate_type == CrateType::ProcMacro && !cgcx.opts.unstable_opts.dylib_lto {
96+
dcx.emit_err(LtoProcMacro);
97+
return Err(FatalError);
10098
}
10199
}
102100

0 commit comments

Comments
 (0)