Skip to content

Commit 90b6588

Browse files
committed
Auto merge of #148462 - Zalathar:rollup-6gckwu6, r=Zalathar
Rollup of 8 pull requests Successful merges: - #133149 (Provide more context on `Fn` closure modifying binding) - #145915 (Stabilize `fmt::from_fn`) - #145974 (Stabilize -Zno-jump-tables into -Cjump-tables=bool) - #146057 (feat: add `from_fn_ptr` to `Waker` and `LocalWaker`) - #146301 (library: std: sys: net: uefi: tcp: Implement write_vectored) - #148437 (Regression test for undefined `__chkstk` on `aarch64-unknown-uefi`) - #148448 (Update books) - #148451 (tidy: Fix false positives with absolute repo paths in `pal.rs` `check()`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5f9dd05 + 0bded52 commit 90b6588

File tree

36 files changed

+320
-83
lines changed

36 files changed

+320
-83
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
150150
}
151151
}
152152
}
153-
PlaceRef { local: _, projection: [proj_base @ .., ProjectionElem::Deref] } => {
154-
if the_place_err.local == ty::CAPTURE_STRUCT_LOCAL
153+
PlaceRef { local, projection: [proj_base @ .., ProjectionElem::Deref] } => {
154+
if local == ty::CAPTURE_STRUCT_LOCAL
155155
&& proj_base.is_empty()
156156
&& !self.upvars.is_empty()
157157
{
@@ -165,10 +165,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
165165
", as `Fn` closures cannot mutate their captured variables".to_string()
166166
}
167167
} else {
168-
let source = self.borrowed_content_source(PlaceRef {
169-
local: the_place_err.local,
170-
projection: proj_base,
171-
});
168+
let source =
169+
self.borrowed_content_source(PlaceRef { local, projection: proj_base });
172170
let pointer_type = source.describe_for_immutable_place(self.infcx.tcx);
173171
opt_source = Some(source);
174172
if let Some(desc) = self.describe_place(access_place.as_ref()) {
@@ -540,6 +538,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
540538
PlaceRef { local, projection: [ProjectionElem::Deref] }
541539
if local == ty::CAPTURE_STRUCT_LOCAL && !self.upvars.is_empty() =>
542540
{
541+
self.point_at_binding_outside_closure(&mut err, local, access_place);
543542
self.expected_fn_found_fn_mut_call(&mut err, span, act);
544543
}
545544

@@ -958,6 +957,50 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
958957
}
959958
}
960959

960+
/// When modifying a binding from inside of an `Fn` closure, point at the binding definition.
961+
fn point_at_binding_outside_closure(
962+
&self,
963+
err: &mut Diag<'_>,
964+
local: Local,
965+
access_place: Place<'tcx>,
966+
) {
967+
let place = access_place.as_ref();
968+
for (index, elem) in place.projection.into_iter().enumerate() {
969+
if let ProjectionElem::Deref = elem {
970+
if index == 0 {
971+
if self.body.local_decls[local].is_ref_for_guard() {
972+
continue;
973+
}
974+
if let LocalInfo::StaticRef { .. } = *self.body.local_decls[local].local_info()
975+
{
976+
continue;
977+
}
978+
}
979+
if let Some(field) = self.is_upvar_field_projection(PlaceRef {
980+
local,
981+
projection: place.projection.split_at(index + 1).0,
982+
}) {
983+
let var_index = field.index();
984+
let upvar = self.upvars[var_index];
985+
if let Some(hir_id) = upvar.info.capture_kind_expr_id {
986+
let node = self.infcx.tcx.hir_node(hir_id);
987+
if let hir::Node::Expr(expr) = node
988+
&& let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind
989+
&& let hir::def::Res::Local(hir_id) = path.res
990+
&& let hir::Node::Pat(pat) = self.infcx.tcx.hir_node(hir_id)
991+
{
992+
let name = upvar.to_string(self.infcx.tcx);
993+
err.span_label(
994+
pat.span,
995+
format!("`{name}` declared here, outside the closure"),
996+
);
997+
break;
998+
}
999+
}
1000+
}
1001+
}
1002+
}
1003+
}
9611004
/// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
9621005
fn expected_fn_found_fn_mut_call(&self, err: &mut Diag<'_>, sp: Span, act: &str) {
9631006
err.span_label(sp, format!("cannot {act}"));
@@ -970,6 +1013,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
9701013
let def_id = tcx.hir_enclosing_body_owner(fn_call_id);
9711014
let mut look_at_return = true;
9721015

1016+
err.span_label(closure_span, "in this closure");
9731017
// If the HIR node is a function or method call, get the DefId
9741018
// of the callee function or method, the span, and args of the call expr
9751019
let get_call_details = || {
@@ -1040,7 +1084,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
10401084
if let Some(span) = arg {
10411085
err.span_label(span, "change this to accept `FnMut` instead of `Fn`");
10421086
err.span_label(call_span, "expects `Fn` instead of `FnMut`");
1043-
err.span_label(closure_span, "in this closure");
10441087
look_at_return = false;
10451088
}
10461089
}
@@ -1067,7 +1110,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
10671110
sig.decl.output.span(),
10681111
"change this to return `FnMut` instead of `Fn`",
10691112
);
1070-
err.span_label(closure_span, "in this closure");
10711113
}
10721114
_ => {}
10731115
}

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ fn instrument_function_attr<'ll>(
229229
}
230230

231231
fn nojumptables_attr<'ll>(cx: &SimpleCx<'ll>, sess: &Session) -> Option<&'ll Attribute> {
232-
if !sess.opts.unstable_opts.no_jump_tables {
232+
if sess.opts.cg.jump_tables {
233233
return None;
234234
}
235235

compiler/rustc_hir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
44
55
// tidy-alphabetical-start
6+
#![cfg_attr(bootstrap, feature(debug_closure_helpers))]
67
#![feature(associated_type_defaults)]
78
#![feature(closure_track_caller)]
8-
#![feature(debug_closure_helpers)]
99
#![feature(exhaustive_patterns)]
1010
#![feature(never_type)]
1111
#![feature(variant_count)]

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ This API is completely unstable and subject to change.
5959
#![allow(internal_features)]
6060
#![allow(rustc::diagnostic_outside_of_impl)]
6161
#![allow(rustc::untranslatable_diagnostic)]
62+
#![cfg_attr(bootstrap, feature(debug_closure_helpers))]
6263
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
6364
#![doc(rust_logo)]
6465
#![feature(assert_matches)]
65-
#![feature(debug_closure_helpers)]
6666
#![feature(gen_blocks)]
6767
#![feature(if_let_guard)]
6868
#![feature(iter_intersperse)]

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ fn test_codegen_options_tracking_hash() {
620620
tracked!(force_frame_pointers, FramePointer::Always);
621621
tracked!(force_unwind_tables, Some(true));
622622
tracked!(instrument_coverage, InstrumentCoverage::Yes);
623+
tracked!(jump_tables, false);
623624
tracked!(link_dead_code, Some(true));
624625
tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
625626
tracked!(llvm_args, vec![String::from("1"), String::from("2")]);
@@ -831,7 +832,6 @@ fn test_unstable_options_tracking_hash() {
831832
tracked!(mutable_noalias, false);
832833
tracked!(next_solver, NextSolverConfig { coherence: true, globally: true });
833834
tracked!(no_generate_arange_section, true);
834-
tracked!(no_jump_tables, true);
835835
tracked!(no_link, true);
836836
tracked!(no_profiler_runtime, true);
837837
tracked!(no_trait_vptr, true);

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,8 @@ options! {
20932093
"instrument the generated code to support LLVM source-based code coverage reports \
20942094
(note, the compiler build config must include `profiler = true`); \
20952095
implies `-C symbol-mangling-version=v0`"),
2096+
jump_tables: bool = (true, parse_bool, [TRACKED],
2097+
"allow jump table and lookup table generation from switch case lowering (default: yes)"),
20962098
link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED],
20972099
"a single extra argument to append to the linker invocation (can be used several times)"),
20982100
link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
@@ -2475,8 +2477,6 @@ options! {
24752477
"omit DWARF address ranges that give faster lookups"),
24762478
no_implied_bounds_compat: bool = (false, parse_bool, [TRACKED],
24772479
"disable the compatibility version of the `implied_bounds_ty` query"),
2478-
no_jump_tables: bool = (false, parse_no_value, [TRACKED],
2479-
"disable the jump tables and lookup tables that can be generated from a switch case lowering"),
24802480
no_leak_check: bool = (false, parse_no_value, [UNTRACKED],
24812481
"disable the 'leak check' for subtyping; unsound, but useful for tests"),
24822482
no_link: bool = (false, parse_no_value, [TRACKED],

compiler/rustc_target/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
1010
// tidy-alphabetical-start
1111
#![allow(internal_features)]
12+
#![cfg_attr(bootstrap, feature(debug_closure_helpers))]
1213
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1314
#![doc(rust_logo)]
14-
#![feature(debug_closure_helpers)]
1515
#![feature(iter_intersperse)]
1616
#![feature(rustdoc_internals)]
1717
// tidy-alphabetical-end

library/alloc/src/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ pub use core::fmt::{DebugAsHex, FormattingOptions, Sign};
602602
pub use core::fmt::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};
603603
#[stable(feature = "rust1", since = "1.0.0")]
604604
pub use core::fmt::{Formatter, Result, Write};
605-
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
605+
#[stable(feature = "fmt_from_fn", since = "CURRENT_RUSTC_VERSION")]
606606
pub use core::fmt::{FromFn, from_fn};
607607
#[stable(feature = "rust1", since = "1.0.0")]
608608
pub use core::fmt::{LowerExp, UpperExp};

library/core/src/fmt/builders.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,13 +1210,12 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
12101210
}
12111211
}
12121212

1213-
/// Creates a type whose [`fmt::Debug`] and [`fmt::Display`] impls are provided with the function
1214-
/// `f`.
1213+
/// Creates a type whose [`fmt::Debug`] and [`fmt::Display`] impls are
1214+
/// forwarded to the provided closure.
12151215
///
12161216
/// # Examples
12171217
///
12181218
/// ```
1219-
/// #![feature(debug_closure_helpers)]
12201219
/// use std::fmt;
12211220
///
12221221
/// let value = 'a';
@@ -1227,21 +1226,19 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
12271226
/// assert_eq!(format!("{}", wrapped), "'a'");
12281227
/// assert_eq!(format!("{:?}", wrapped), "'a'");
12291228
/// ```
1230-
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
1229+
#[stable(feature = "fmt_from_fn", since = "CURRENT_RUSTC_VERSION")]
12311230
#[must_use = "returns a type implementing Debug and Display, which do not have any effects unless they are used"]
12321231
pub fn from_fn<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result>(f: F) -> FromFn<F> {
12331232
FromFn(f)
12341233
}
12351234

1236-
/// Implements [`fmt::Debug`] and [`fmt::Display`] using a function.
1235+
/// Implements [`fmt::Debug`] and [`fmt::Display`] via the provided closure.
12371236
///
12381237
/// Created with [`from_fn`].
1239-
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
1240-
pub struct FromFn<F>(F)
1241-
where
1242-
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result;
1238+
#[stable(feature = "fmt_from_fn", since = "CURRENT_RUSTC_VERSION")]
1239+
pub struct FromFn<F>(F);
12431240

1244-
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
1241+
#[stable(feature = "fmt_from_fn", since = "CURRENT_RUSTC_VERSION")]
12451242
impl<F> fmt::Debug for FromFn<F>
12461243
where
12471244
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,
@@ -1251,7 +1248,7 @@ where
12511248
}
12521249
}
12531250

1254-
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
1251+
#[stable(feature = "fmt_from_fn", since = "CURRENT_RUSTC_VERSION")]
12551252
impl<F> fmt::Display for FromFn<F>
12561253
where
12571254
F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result,

library/core/src/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub use num_buffer::{NumBuffer, NumBufferTrait};
3939

4040
#[stable(feature = "debug_builders", since = "1.2.0")]
4141
pub use self::builders::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};
42-
#[unstable(feature = "debug_closure_helpers", issue = "117729")]
42+
#[stable(feature = "fmt_from_fn", since = "CURRENT_RUSTC_VERSION")]
4343
pub use self::builders::{FromFn, from_fn};
4444

4545
/// The type returned by formatter methods.

0 commit comments

Comments
 (0)