Skip to content

Commit 91c5be6

Browse files
committed
Auto merge of rust-lang#125423 - fmease:rollup-ne4l9y4, r=fmease
Rollup of 7 pull requests Successful merges: - rust-lang#125043 (reference type safety invariant docs: clarification) - rust-lang#125306 (Force the inner coroutine of an async closure to `move` if the outer closure is `move` and `FnOnce`) - rust-lang#125355 (Use Backtrace::force_capture instead of Backtrace::capture in rustc_log) - rust-lang#125382 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 7)) - rust-lang#125391 (Minor serialize/span tweaks) - rust-lang#125395 (Remove unnecessary `.md` from the documentation sidebar) - rust-lang#125399 (Stop using `to_hir_binop` in codegen) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 93e7cb8 + 412c46c commit 91c5be6

Some content is hidden

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

41 files changed

+253
-137
lines changed

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_codegen_ssa::mir::operand::OperandRef;
1414
use rustc_codegen_ssa::mir::place::PlaceRef;
1515
use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods};
1616
use rustc_hir as hir;
17+
use rustc_middle::mir::BinOp;
1718
use rustc_middle::span_bug;
1819
use rustc_middle::ty::layout::HasTyCtxt;
1920
use rustc_middle::ty::{self, Ty};
@@ -122,12 +123,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
122123
let in_ty = arg_tys[0];
123124

124125
let comparison = match name {
125-
sym::simd_eq => Some(hir::BinOpKind::Eq),
126-
sym::simd_ne => Some(hir::BinOpKind::Ne),
127-
sym::simd_lt => Some(hir::BinOpKind::Lt),
128-
sym::simd_le => Some(hir::BinOpKind::Le),
129-
sym::simd_gt => Some(hir::BinOpKind::Gt),
130-
sym::simd_ge => Some(hir::BinOpKind::Ge),
126+
sym::simd_eq => Some(BinOp::Eq),
127+
sym::simd_ne => Some(BinOp::Ne),
128+
sym::simd_lt => Some(BinOp::Lt),
129+
sym::simd_le => Some(BinOp::Le),
130+
sym::simd_gt => Some(BinOp::Gt),
131+
sym::simd_ge => Some(BinOp::Ge),
131132
_ => None,
132133
};
133134

compiler/rustc_codegen_llvm/src/intrinsic.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1414
use rustc_codegen_ssa::mir::place::PlaceRef;
1515
use rustc_codegen_ssa::traits::*;
1616
use rustc_hir as hir;
17+
use rustc_middle::mir::BinOp;
1718
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf};
1819
use rustc_middle::ty::{self, GenericArgsRef, Ty};
1920
use rustc_middle::{bug, span_bug};
@@ -1104,12 +1105,12 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
11041105
let in_ty = arg_tys[0];
11051106

11061107
let comparison = match name {
1107-
sym::simd_eq => Some(hir::BinOpKind::Eq),
1108-
sym::simd_ne => Some(hir::BinOpKind::Ne),
1109-
sym::simd_lt => Some(hir::BinOpKind::Lt),
1110-
sym::simd_le => Some(hir::BinOpKind::Le),
1111-
sym::simd_gt => Some(hir::BinOpKind::Gt),
1112-
sym::simd_ge => Some(hir::BinOpKind::Ge),
1108+
sym::simd_eq => Some(BinOp::Eq),
1109+
sym::simd_ne => Some(BinOp::Ne),
1110+
sym::simd_lt => Some(BinOp::Lt),
1111+
sym::simd_le => Some(BinOp::Le),
1112+
sym::simd_gt => Some(BinOp::Gt),
1113+
sym::simd_ge => Some(BinOp::Ge),
11131114
_ => None,
11141115
};
11151116

compiler/rustc_codegen_ssa/src/base.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
2020
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
2121
use rustc_data_structures::sync::par_map;
2222
use rustc_data_structures::unord::UnordMap;
23-
use rustc_hir as hir;
2423
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
2524
use rustc_hir::lang_items::LangItem;
2625
use rustc_metadata::EncodedMetadata;
@@ -30,6 +29,7 @@ use rustc_middle::middle::debugger_visualizer::{DebuggerVisualizerFile, Debugger
3029
use rustc_middle::middle::exported_symbols;
3130
use rustc_middle::middle::exported_symbols::SymbolExportKind;
3231
use rustc_middle::middle::lang_items;
32+
use rustc_middle::mir::BinOp;
3333
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
3434
use rustc_middle::query::Providers;
3535
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
@@ -46,32 +46,32 @@ use std::time::{Duration, Instant};
4646

4747
use itertools::Itertools;
4848

49-
pub fn bin_op_to_icmp_predicate(op: hir::BinOpKind, signed: bool) -> IntPredicate {
49+
pub fn bin_op_to_icmp_predicate(op: BinOp, signed: bool) -> IntPredicate {
5050
match op {
51-
hir::BinOpKind::Eq => IntPredicate::IntEQ,
52-
hir::BinOpKind::Ne => IntPredicate::IntNE,
53-
hir::BinOpKind::Lt => {
51+
BinOp::Eq => IntPredicate::IntEQ,
52+
BinOp::Ne => IntPredicate::IntNE,
53+
BinOp::Lt => {
5454
if signed {
5555
IntPredicate::IntSLT
5656
} else {
5757
IntPredicate::IntULT
5858
}
5959
}
60-
hir::BinOpKind::Le => {
60+
BinOp::Le => {
6161
if signed {
6262
IntPredicate::IntSLE
6363
} else {
6464
IntPredicate::IntULE
6565
}
6666
}
67-
hir::BinOpKind::Gt => {
67+
BinOp::Gt => {
6868
if signed {
6969
IntPredicate::IntSGT
7070
} else {
7171
IntPredicate::IntUGT
7272
}
7373
}
74-
hir::BinOpKind::Ge => {
74+
BinOp::Ge => {
7575
if signed {
7676
IntPredicate::IntSGE
7777
} else {
@@ -86,14 +86,14 @@ pub fn bin_op_to_icmp_predicate(op: hir::BinOpKind, signed: bool) -> IntPredicat
8686
}
8787
}
8888

89-
pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> RealPredicate {
89+
pub fn bin_op_to_fcmp_predicate(op: BinOp) -> RealPredicate {
9090
match op {
91-
hir::BinOpKind::Eq => RealPredicate::RealOEQ,
92-
hir::BinOpKind::Ne => RealPredicate::RealUNE,
93-
hir::BinOpKind::Lt => RealPredicate::RealOLT,
94-
hir::BinOpKind::Le => RealPredicate::RealOLE,
95-
hir::BinOpKind::Gt => RealPredicate::RealOGT,
96-
hir::BinOpKind::Ge => RealPredicate::RealOGE,
91+
BinOp::Eq => RealPredicate::RealOEQ,
92+
BinOp::Ne => RealPredicate::RealUNE,
93+
BinOp::Lt => RealPredicate::RealOLT,
94+
BinOp::Le => RealPredicate::RealOLE,
95+
BinOp::Gt => RealPredicate::RealOGT,
96+
BinOp::Ge => RealPredicate::RealOGE,
9797
op => {
9898
bug!(
9999
"comparison_op_to_fcmp_predicate: expected comparison operator, \
@@ -110,7 +110,7 @@ pub fn compare_simd_types<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
110110
rhs: Bx::Value,
111111
t: Ty<'tcx>,
112112
ret_ty: Bx::Type,
113-
op: hir::BinOpKind,
113+
op: BinOp,
114114
) -> Bx::Value {
115115
let signed = match t.kind() {
116116
ty::Float(_) => {

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::common::IntPredicate;
77
use crate::traits::*;
88
use crate::MemFlags;
99

10-
use rustc_hir as hir;
1110
use rustc_middle::mir;
1211
use rustc_middle::ty::cast::{CastTy, IntTy};
1312
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
@@ -896,9 +895,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
896895
| mir::BinOp::Le
897896
| mir::BinOp::Ge => {
898897
if is_float {
899-
bx.fcmp(base::bin_op_to_fcmp_predicate(op.to_hir_binop()), lhs, rhs)
898+
bx.fcmp(base::bin_op_to_fcmp_predicate(op), lhs, rhs)
900899
} else {
901-
bx.icmp(base::bin_op_to_icmp_predicate(op.to_hir_binop(), is_signed), lhs, rhs)
900+
bx.icmp(base::bin_op_to_icmp_predicate(op, is_signed), lhs, rhs)
902901
}
903902
}
904903
mir::BinOp::Cmp => {
@@ -912,16 +911,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
912911
// `PartialOrd`, so only use it in debug for now. Once LLVM can handle it
913912
// better (see <https://github.com/llvm/llvm-project/issues/73417>), it'll
914913
// be worth trying it in optimized builds as well.
915-
let is_gt = bx.icmp(pred(hir::BinOpKind::Gt), lhs, rhs);
914+
let is_gt = bx.icmp(pred(mir::BinOp::Gt), lhs, rhs);
916915
let gtext = bx.zext(is_gt, bx.type_i8());
917-
let is_lt = bx.icmp(pred(hir::BinOpKind::Lt), lhs, rhs);
916+
let is_lt = bx.icmp(pred(mir::BinOp::Lt), lhs, rhs);
918917
let ltext = bx.zext(is_lt, bx.type_i8());
919918
bx.unchecked_ssub(gtext, ltext)
920919
} else {
921920
// These operations are those expected by `tests/codegen/integer-cmp.rs`,
922921
// from <https://github.com/rust-lang/rust/pull/63767>.
923-
let is_lt = bx.icmp(pred(hir::BinOpKind::Lt), lhs, rhs);
924-
let is_ne = bx.icmp(pred(hir::BinOpKind::Ne), lhs, rhs);
922+
let is_lt = bx.icmp(pred(mir::BinOp::Lt), lhs, rhs);
923+
let is_ne = bx.icmp(pred(mir::BinOp::Ne), lhs, rhs);
925924
let ge = bx.select(
926925
is_ne,
927926
bx.cx().const_i8(Ordering::Greater as i8),

compiler/rustc_hir_typeck/src/upvar.rs

+58-31
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,60 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
204204
fake_reads: Default::default(),
205205
};
206206

207+
let _ = euv::ExprUseVisitor::new(
208+
&FnCtxt::new(self, self.tcx.param_env(closure_def_id), closure_def_id),
209+
&mut delegate,
210+
)
211+
.consume_body(body);
212+
213+
// There are several curious situations with coroutine-closures where
214+
// analysis is too aggressive with borrows when the coroutine-closure is
215+
// marked `move`. Specifically:
216+
//
217+
// 1. If the coroutine-closure was inferred to be `FnOnce` during signature
218+
// inference, then it's still possible that we try to borrow upvars from
219+
// the coroutine-closure because they are not used by the coroutine body
220+
// in a way that forces a move. See the test:
221+
// `async-await/async-closures/force-move-due-to-inferred-kind.rs`.
222+
//
223+
// 2. If the coroutine-closure is forced to be `FnOnce` due to the way it
224+
// uses its upvars, but not *all* upvars would force the closure to `FnOnce`.
225+
// See the test: `async-await/async-closures/force-move-due-to-actually-fnonce.rs`.
226+
//
227+
// This would lead to an impossible to satisfy situation, since `AsyncFnOnce`
228+
// coroutine bodies can't borrow from their parent closure. To fix this,
229+
// we force the inner coroutine to also be `move`. This only matters for
230+
// coroutine-closures that are `move` since otherwise they themselves will
231+
// be borrowing from the outer environment, so there's no self-borrows occuring.
232+
//
233+
// One *important* note is that we do a call to `process_collected_capture_information`
234+
// to eagerly test whether the coroutine would end up `FnOnce`, but we do this
235+
// *before* capturing all the closure args by-value below, since that would always
236+
// cause the analysis to return `FnOnce`.
237+
if let UpvarArgs::Coroutine(..) = args
238+
&& let hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure) =
239+
self.tcx.coroutine_kind(closure_def_id).expect("coroutine should have kind")
240+
&& let parent_hir_id =
241+
self.tcx.local_def_id_to_hir_id(self.tcx.local_parent(closure_def_id))
242+
&& let parent_ty = self.node_ty(parent_hir_id)
243+
&& let hir::CaptureBy::Value { move_kw } =
244+
self.tcx.hir_node(parent_hir_id).expect_closure().capture_clause
245+
{
246+
// (1.) Closure signature inference forced this closure to `FnOnce`.
247+
if let Some(ty::ClosureKind::FnOnce) = self.closure_kind(parent_ty) {
248+
capture_clause = hir::CaptureBy::Value { move_kw };
249+
}
250+
// (2.) The way that the closure uses its upvars means it's `FnOnce`.
251+
else if let (_, ty::ClosureKind::FnOnce, _) = self
252+
.process_collected_capture_information(
253+
capture_clause,
254+
&delegate.capture_information,
255+
)
256+
{
257+
capture_clause = hir::CaptureBy::Value { move_kw };
258+
}
259+
}
260+
207261
// As noted in `lower_coroutine_body_with_moved_arguments`, we default the capture mode
208262
// to `ByRef` for the `async {}` block internal to async fns/closure. This means
209263
// that we would *not* be moving all of the parameters into the async block by default.
@@ -253,34 +307,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
253307
}
254308
}
255309

256-
let _ = euv::ExprUseVisitor::new(
257-
&FnCtxt::new(self, self.tcx.param_env(closure_def_id), closure_def_id),
258-
&mut delegate,
259-
)
260-
.consume_body(body);
261-
262-
// If a coroutine is comes from a coroutine-closure that is `move`, but
263-
// the coroutine-closure was inferred to be `FnOnce` during signature
264-
// inference, then it's still possible that we try to borrow upvars from
265-
// the coroutine-closure because they are not used by the coroutine body
266-
// in a way that forces a move.
267-
//
268-
// This would lead to an impossible to satisfy situation, since `AsyncFnOnce`
269-
// coroutine bodies can't borrow from their parent closure. To fix this,
270-
// we force the inner coroutine to also be `move`. This only matters for
271-
// coroutine-closures that are `move` since otherwise they themselves will
272-
// be borrowing from the outer environment, so there's no self-borrows occuring.
273-
if let UpvarArgs::Coroutine(..) = args
274-
&& let hir::CoroutineKind::Desugared(_, hir::CoroutineSource::Closure) =
275-
self.tcx.coroutine_kind(closure_def_id).expect("coroutine should have kind")
276-
&& let parent_hir_id =
277-
self.tcx.local_def_id_to_hir_id(self.tcx.local_parent(closure_def_id))
278-
&& let parent_ty = self.node_ty(parent_hir_id)
279-
&& let Some(ty::ClosureKind::FnOnce) = self.closure_kind(parent_ty)
280-
{
281-
capture_clause = self.tcx.hir_node(parent_hir_id).expect_closure().capture_clause;
282-
}
283-
284310
debug!(
285311
"For closure={:?}, capture_information={:#?}",
286312
closure_def_id, delegate.capture_information
@@ -289,7 +315,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
289315
self.log_capture_analysis_first_pass(closure_def_id, &delegate.capture_information, span);
290316

291317
let (capture_information, closure_kind, origin) = self
292-
.process_collected_capture_information(capture_clause, delegate.capture_information);
318+
.process_collected_capture_information(capture_clause, &delegate.capture_information);
293319

294320
self.compute_min_captures(closure_def_id, capture_information, span);
295321

@@ -545,13 +571,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
545571
fn process_collected_capture_information(
546572
&self,
547573
capture_clause: hir::CaptureBy,
548-
capture_information: InferredCaptureInformation<'tcx>,
574+
capture_information: &InferredCaptureInformation<'tcx>,
549575
) -> (InferredCaptureInformation<'tcx>, ty::ClosureKind, Option<(Span, Place<'tcx>)>) {
550576
let mut closure_kind = ty::ClosureKind::LATTICE_BOTTOM;
551577
let mut origin: Option<(Span, Place<'tcx>)> = None;
552578

553579
let processed = capture_information
554-
.into_iter()
580+
.iter()
581+
.cloned()
555582
.map(|(place, mut capture_info)| {
556583
// Apply rules for safety before inferring closure kind
557584
let (place, capture_kind) =

compiler/rustc_log/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ where
159159
if !target.contains(&self.backtrace_target) {
160160
return Ok(());
161161
}
162-
let backtrace = std::backtrace::Backtrace::capture();
162+
// Use Backtrace::force_capture because we don't want to depend on the
163+
// RUST_BACKTRACE environment variable being set.
164+
let backtrace = std::backtrace::Backtrace::force_capture();
163165
writeln!(writer, "stack backtrace: \n{backtrace:?}")
164166
}
165167
}

compiler/rustc_macros/src/serialize.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn type_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
1313
quote! {}
1414
};
1515

16-
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_type_ir::codec::TyDecoder #bound });
16+
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_type_ir::codec::TyDecoder #bound });
1717
s.add_bounds(synstructure::AddBounds::Fields);
1818
s.underscore_const(true);
1919

@@ -34,7 +34,7 @@ pub fn meta_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
3434

3535
pub fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
3636
let decoder_ty = quote! { __D };
37-
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_span::SpanDecoder});
37+
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_span::SpanDecoder });
3838
s.add_bounds(synstructure::AddBounds::Generics);
3939
s.underscore_const(true);
4040

@@ -43,7 +43,7 @@ pub fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::Toke
4343

4444
pub fn decodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
4545
let decoder_ty = quote! { __D };
46-
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_serialize::Decoder});
46+
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_serialize::Decoder });
4747
s.add_bounds(synstructure::AddBounds::Generics);
4848
s.underscore_const(true);
4949

@@ -120,7 +120,7 @@ fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream {
120120
let __decoder = quote! { __decoder };
121121
// Use the span of the field for the method call, so
122122
// that backtraces will point to the field.
123-
quote_spanned! {field_span=> #decode_inner_method(#__decoder) }
123+
quote_spanned! { field_span=> #decode_inner_method(#__decoder) }
124124
}
125125

126126
pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
@@ -133,7 +133,7 @@ pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
133133
};
134134

135135
let encoder_ty = quote! { __E };
136-
s.add_impl_generic(parse_quote! {#encoder_ty: ::rustc_type_ir::codec::TyEncoder #bound });
136+
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_type_ir::codec::TyEncoder #bound });
137137
s.add_bounds(synstructure::AddBounds::Fields);
138138
s.underscore_const(true);
139139

@@ -142,7 +142,7 @@ pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
142142

143143
pub fn meta_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
144144
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
145-
s.add_impl_generic(parse_quote! {'tcx});
145+
s.add_impl_generic(parse_quote! { 'tcx });
146146
}
147147
s.add_impl_generic(parse_quote! { '__a });
148148
let encoder_ty = quote! { EncodeContext<'__a, 'tcx> };
@@ -154,7 +154,7 @@ pub fn meta_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2:
154154

155155
pub fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
156156
let encoder_ty = quote! { __E };
157-
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_span::SpanEncoder});
157+
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_span::SpanEncoder });
158158
s.add_bounds(synstructure::AddBounds::Generics);
159159
s.underscore_const(true);
160160

@@ -163,7 +163,7 @@ pub fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::Toke
163163

164164
pub fn encodable_generic_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
165165
let encoder_ty = quote! { __E };
166-
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_serialize::Encoder});
166+
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_serialize::Encoder });
167167
s.add_bounds(synstructure::AddBounds::Generics);
168168
s.underscore_const(true);
169169

compiler/rustc_middle/src/mir/tcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl BorrowKind {
295295
}
296296

297297
impl BinOp {
298-
pub fn to_hir_binop(self) -> hir::BinOpKind {
298+
pub(crate) fn to_hir_binop(self) -> hir::BinOpKind {
299299
match self {
300300
BinOp::Add => hir::BinOpKind::Add,
301301
BinOp::Sub => hir::BinOpKind::Sub,

0 commit comments

Comments
 (0)