Skip to content

Commit 9d6d563

Browse files
committed
Auto merge of #127788 - tgross35:rollup-kdqqz56, r=tgross35
Rollup of 5 pull requests Successful merges: - #120990 (Suggest a borrow when using dbg) - #127047 (fix least significant digits of f128 associated constants) - #127680 (Bootstrap command refactoring: port remaining commands with access to `Build` (step 6)) - #127770 (Update books) - #127780 (Make sure trait def ids match before zipping args in `note_function_argument_obligation`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5c84886 + 36c2f58 commit 9d6d563

File tree

26 files changed

+506
-218
lines changed

26 files changed

+506
-218
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+63-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![allow(rustc::untranslatable_diagnostic)]
55

66
use either::Either;
7-
use hir::ClosureKind;
7+
use hir::{ClosureKind, Path};
88
use rustc_data_structures::captures::Captures;
99
use rustc_data_structures::fx::FxIndexSet;
1010
use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag, MultiSpan};
@@ -16,6 +16,7 @@ use rustc_hir::{CoroutineKind, CoroutineSource, LangItem};
1616
use rustc_middle::bug;
1717
use rustc_middle::hir::nested_filter::OnlyBodies;
1818
use rustc_middle::mir::tcx::PlaceTy;
19+
use rustc_middle::mir::VarDebugInfoContents;
1920
use rustc_middle::mir::{
2021
self, AggregateKind, BindingForm, BorrowKind, CallSource, ClearCrossCrate, ConstraintCategory,
2122
FakeBorrowKind, FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, MutBorrowKind,
@@ -546,7 +547,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
546547
self.suggest_cloning(err, ty, expr, None, Some(move_spans));
547548
}
548549
}
549-
if let Some(pat) = finder.pat {
550+
551+
self.suggest_ref_for_dbg_args(expr, place, move_span, err);
552+
553+
// it's useless to suggest inserting `ref` when the span don't comes from local code
554+
if let Some(pat) = finder.pat
555+
&& !move_span.is_dummy()
556+
&& !self.infcx.tcx.sess.source_map().is_imported(move_span)
557+
{
550558
*in_pattern = true;
551559
let mut sugg = vec![(pat.span.shrink_to_lo(), "ref ".to_string())];
552560
if let Some(pat) = finder.parent_pat {
@@ -561,6 +569,59 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
561569
}
562570
}
563571

572+
// for dbg!(x) which may take ownership, suggest dbg!(&x) instead
573+
// but here we actually do not check whether the macro name is `dbg!`
574+
// so that we may extend the scope a bit larger to cover more cases
575+
fn suggest_ref_for_dbg_args(
576+
&self,
577+
body: &hir::Expr<'_>,
578+
place: &Place<'tcx>,
579+
move_span: Span,
580+
err: &mut Diag<'infcx>,
581+
) {
582+
let var_info = self.body.var_debug_info.iter().find(|info| match info.value {
583+
VarDebugInfoContents::Place(ref p) => p == place,
584+
_ => false,
585+
});
586+
let arg_name = if let Some(var_info) = var_info {
587+
var_info.name
588+
} else {
589+
return;
590+
};
591+
struct MatchArgFinder {
592+
expr_span: Span,
593+
match_arg_span: Option<Span>,
594+
arg_name: Symbol,
595+
}
596+
impl Visitor<'_> for MatchArgFinder {
597+
fn visit_expr(&mut self, e: &hir::Expr<'_>) {
598+
// dbg! is expanded into a match pattern, we need to find the right argument span
599+
if let hir::ExprKind::Match(expr, ..) = &e.kind
600+
&& let hir::ExprKind::Path(hir::QPath::Resolved(
601+
_,
602+
path @ Path { segments: [seg], .. },
603+
)) = &expr.kind
604+
&& seg.ident.name == self.arg_name
605+
&& self.expr_span.source_callsite().contains(expr.span)
606+
{
607+
self.match_arg_span = Some(path.span);
608+
}
609+
hir::intravisit::walk_expr(self, e);
610+
}
611+
}
612+
613+
let mut finder = MatchArgFinder { expr_span: move_span, match_arg_span: None, arg_name };
614+
finder.visit_expr(body);
615+
if let Some(macro_arg_span) = finder.match_arg_span {
616+
err.span_suggestion_verbose(
617+
macro_arg_span.shrink_to_lo(),
618+
"consider borrowing instead of transferring ownership",
619+
"&",
620+
Applicability::MachineApplicable,
621+
);
622+
}
623+
}
624+
564625
fn report_use_of_uninitialized(
565626
&self,
566627
mpi: MovePathIndex,

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3810,6 +3810,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
38103810
{
38113811
if let Some(where_pred) = where_pred.as_trait_clause()
38123812
&& let Some(failed_pred) = failed_pred.as_trait_clause()
3813+
&& where_pred.def_id() == failed_pred.def_id()
38133814
{
38143815
self.enter_forall(where_pred, |where_pred| {
38153816
let failed_pred = self.instantiate_binder_with_fresh_vars(

library/core/src/num/f128.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ impl f128 {
170170
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
171171
/// [`MANTISSA_DIGITS`]: f128::MANTISSA_DIGITS
172172
#[unstable(feature = "f128", issue = "116909")]
173-
pub const EPSILON: f128 = 1.92592994438723585305597794258492731e-34_f128;
173+
pub const EPSILON: f128 = 1.92592994438723585305597794258492732e-34_f128;
174174

175175
/// Smallest finite `f128` value.
176176
///
177177
/// Equal to &minus;[`MAX`].
178178
///
179179
/// [`MAX`]: f128::MAX
180180
#[unstable(feature = "f128", issue = "116909")]
181-
pub const MIN: f128 = -1.18973149535723176508575932662800701e+4932_f128;
181+
pub const MIN: f128 = -1.18973149535723176508575932662800702e+4932_f128;
182182
/// Smallest positive normal `f128` value.
183183
///
184184
/// Equal to 2<sup>[`MIN_EXP`]&nbsp;&minus;&nbsp;1</sup>.
@@ -194,7 +194,7 @@ impl f128 {
194194
/// [`MANTISSA_DIGITS`]: f128::MANTISSA_DIGITS
195195
/// [`MAX_EXP`]: f128::MAX_EXP
196196
#[unstable(feature = "f128", issue = "116909")]
197-
pub const MAX: f128 = 1.18973149535723176508575932662800701e+4932_f128;
197+
pub const MAX: f128 = 1.18973149535723176508575932662800702e+4932_f128;
198198

199199
/// One greater than the minimum possible normal power of 2 exponent.
200200
///

src/bootstrap/src/core/build_steps/compile.rs

+9-17
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::fs;
1414
use std::io::prelude::*;
1515
use std::io::BufReader;
1616
use std::path::{Path, PathBuf};
17-
use std::process::{Command, Stdio};
17+
use std::process::Stdio;
1818
use std::str;
1919

2020
use serde_derive::Deserialize;
@@ -695,10 +695,10 @@ fn copy_sanitizers(
695695
|| target == "x86_64-apple-ios"
696696
{
697697
// Update the library’s install name to reflect that it has been renamed.
698-
apple_darwin_update_library_name(&dst, &format!("@rpath/{}", &runtime.name));
698+
apple_darwin_update_library_name(builder, &dst, &format!("@rpath/{}", &runtime.name));
699699
// Upon renaming the install name, the code signature of the file will invalidate,
700700
// so we will sign it again.
701-
apple_darwin_sign_file(&dst);
701+
apple_darwin_sign_file(builder, &dst);
702702
}
703703

704704
target_deps.push(dst);
@@ -707,25 +707,17 @@ fn copy_sanitizers(
707707
target_deps
708708
}
709709

710-
fn apple_darwin_update_library_name(library_path: &Path, new_name: &str) {
711-
let status = Command::new("install_name_tool")
712-
.arg("-id")
713-
.arg(new_name)
714-
.arg(library_path)
715-
.status()
716-
.expect("failed to execute `install_name_tool`");
717-
assert!(status.success());
710+
fn apple_darwin_update_library_name(builder: &Builder<'_>, library_path: &Path, new_name: &str) {
711+
command("install_name_tool").arg("-id").arg(new_name).arg(library_path).run(builder);
718712
}
719713

720-
fn apple_darwin_sign_file(file_path: &Path) {
721-
let status = Command::new("codesign")
714+
fn apple_darwin_sign_file(builder: &Builder<'_>, file_path: &Path) {
715+
command("codesign")
722716
.arg("-f") // Force to rewrite the existing signature
723717
.arg("-s")
724718
.arg("-")
725719
.arg(file_path)
726-
.status()
727-
.expect("failed to execute `codesign`");
728-
assert!(status.success());
720+
.run(builder);
729721
}
730722

731723
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1171,7 +1163,7 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
11711163
if builder.config.llvm_profile_generate && target.is_msvc() {
11721164
if let Some(ref clang_cl_path) = builder.config.llvm_clang_cl {
11731165
// Add clang's runtime library directory to the search path
1174-
let clang_rt_dir = get_clang_cl_resource_dir(clang_cl_path);
1166+
let clang_rt_dir = get_clang_cl_resource_dir(builder, clang_cl_path);
11751167
llvm_linker_flags.push_str(&format!("-L{}", clang_rt_dir.display()));
11761168
}
11771169
}

src/bootstrap/src/core/build_steps/llvm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ pub fn prebuilt_llvm_config(builder: &Builder<'_>, target: TargetSelection) -> L
125125
static STAMP_HASH_MEMO: OnceLock<String> = OnceLock::new();
126126
let smart_stamp_hash = STAMP_HASH_MEMO.get_or_init(|| {
127127
generate_smart_stamp_hash(
128+
builder,
128129
&builder.config.src.join("src/llvm-project"),
129130
builder.in_tree_llvm_info.sha().unwrap_or_default(),
130131
)
@@ -912,7 +913,7 @@ impl Step for Lld {
912913
if let Some(clang_cl_path) = builder.config.llvm_clang_cl.as_ref() {
913914
// Find clang's runtime library directory and push that as a search path to the
914915
// cmake linker flags.
915-
let clang_rt_dir = get_clang_cl_resource_dir(clang_cl_path);
916+
let clang_rt_dir = get_clang_cl_resource_dir(builder, clang_cl_path);
916917
ldflags.push_all(format!("/libpath:{}", clang_rt_dir.display()));
917918
}
918919
}

src/bootstrap/src/core/build_steps/setup.rs

+28-32
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
99
use crate::t;
1010
use crate::utils::change_tracker::CONFIG_CHANGE_HISTORY;
11+
use crate::utils::exec::command;
1112
use crate::utils::helpers::{self, hex_encode};
1213
use crate::Config;
1314
use sha2::Digest;
@@ -16,7 +17,6 @@ use std::fmt::Write as _;
1617
use std::fs::File;
1718
use std::io::Write;
1819
use std::path::{Path, PathBuf, MAIN_SEPARATOR_STR};
19-
use std::process::Command;
2020
use std::str::FromStr;
2121
use std::{fmt, fs, io};
2222

@@ -266,20 +266,16 @@ impl Step for Link {
266266
}
267267
let stage_path =
268268
["build", config.build.rustc_target_arg(), "stage1"].join(MAIN_SEPARATOR_STR);
269-
if !rustup_installed() {
269+
if !rustup_installed(builder) {
270270
eprintln!("`rustup` is not installed; cannot link `stage1` toolchain");
271271
} else if stage_dir_exists(&stage_path[..]) && !config.dry_run() {
272-
attempt_toolchain_link(&stage_path[..]);
272+
attempt_toolchain_link(builder, &stage_path[..]);
273273
}
274274
}
275275
}
276276

277-
fn rustup_installed() -> bool {
278-
Command::new("rustup")
279-
.arg("--version")
280-
.stdout(std::process::Stdio::null())
281-
.output()
282-
.map_or(false, |output| output.status.success())
277+
fn rustup_installed(builder: &Builder<'_>) -> bool {
278+
command("rustup").capture_stdout().arg("--version").run(builder).is_success()
283279
}
284280

285281
fn stage_dir_exists(stage_path: &str) -> bool {
@@ -289,8 +285,8 @@ fn stage_dir_exists(stage_path: &str) -> bool {
289285
}
290286
}
291287

292-
fn attempt_toolchain_link(stage_path: &str) {
293-
if toolchain_is_linked() {
288+
fn attempt_toolchain_link(builder: &Builder<'_>, stage_path: &str) {
289+
if toolchain_is_linked(builder) {
294290
return;
295291
}
296292

@@ -301,7 +297,7 @@ fn attempt_toolchain_link(stage_path: &str) {
301297
return;
302298
}
303299

304-
if try_link_toolchain(stage_path) {
300+
if try_link_toolchain(builder, stage_path) {
305301
println!(
306302
"Added `stage1` rustup toolchain; try `cargo +stage1 build` on a separate rust project to run a newly-built toolchain"
307303
);
@@ -315,22 +311,24 @@ fn attempt_toolchain_link(stage_path: &str) {
315311
}
316312
}
317313

318-
fn toolchain_is_linked() -> bool {
319-
match Command::new("rustup")
314+
fn toolchain_is_linked(builder: &Builder<'_>) -> bool {
315+
match command("rustup")
316+
.capture_stdout()
317+
.allow_failure()
320318
.args(["toolchain", "list"])
321-
.stdout(std::process::Stdio::piped())
322-
.output()
319+
.run(builder)
320+
.stdout_if_ok()
323321
{
324-
Ok(toolchain_list) => {
325-
if !String::from_utf8_lossy(&toolchain_list.stdout).contains("stage1") {
322+
Some(toolchain_list) => {
323+
if !toolchain_list.contains("stage1") {
326324
return false;
327325
}
328326
// The toolchain has already been linked.
329327
println!(
330328
"`stage1` toolchain already linked; not attempting to link `stage1` toolchain"
331329
);
332330
}
333-
Err(_) => {
331+
None => {
334332
// In this case, we don't know if the `stage1` toolchain has been linked;
335333
// but `rustup` failed, so let's not go any further.
336334
println!(
@@ -341,12 +339,12 @@ fn toolchain_is_linked() -> bool {
341339
true
342340
}
343341

344-
fn try_link_toolchain(stage_path: &str) -> bool {
345-
Command::new("rustup")
346-
.stdout(std::process::Stdio::null())
342+
fn try_link_toolchain(builder: &Builder<'_>, stage_path: &str) -> bool {
343+
command("rustup")
344+
.capture_stdout()
347345
.args(["toolchain", "link", "stage1", stage_path])
348-
.output()
349-
.map_or(false, |output| output.status.success())
346+
.run(builder)
347+
.is_success()
350348
}
351349

352350
fn ensure_stage1_toolchain_placeholder_exists(stage_path: &str) -> bool {
@@ -476,20 +474,18 @@ impl Step for Hook {
476474
if config.dry_run() {
477475
return;
478476
}
479-
t!(install_git_hook_maybe(config));
477+
t!(install_git_hook_maybe(builder, config));
480478
}
481479
}
482480

483481
// install a git hook to automatically run tidy, if they want
484-
fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
482+
fn install_git_hook_maybe(builder: &Builder<'_>, config: &Config) -> io::Result<()> {
485483
let git = helpers::git(Some(&config.src))
484+
.capture()
486485
.args(["rev-parse", "--git-common-dir"])
487-
.as_command_mut()
488-
.output()
489-
.map(|output| {
490-
assert!(output.status.success(), "failed to run `git`");
491-
PathBuf::from(t!(String::from_utf8(output.stdout)).trim())
492-
})?;
486+
.run(builder)
487+
.stdout();
488+
let git = PathBuf::from(git.trim());
493489
let hooks_dir = git.join("hooks");
494490
let dst = hooks_dir.join("pre-push");
495491
if dst.exists() {

src/bootstrap/src/core/build_steps/test.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::ffi::OsString;
99
use std::fs;
1010
use std::iter;
1111
use std::path::{Path, PathBuf};
12-
use std::process::{Command, Stdio};
1312

1413
use clap_complete::shells;
1514

@@ -169,12 +168,8 @@ You can skip linkcheck with --skip src/tools/linkchecker"
169168
}
170169
}
171170

172-
fn check_if_tidy_is_installed() -> bool {
173-
Command::new("tidy")
174-
.arg("--version")
175-
.stdout(Stdio::null())
176-
.status()
177-
.map_or(false, |status| status.success())
171+
fn check_if_tidy_is_installed(builder: &Builder<'_>) -> bool {
172+
command("tidy").capture_stdout().allow_failure().arg("--version").run(builder).is_success()
178173
}
179174

180175
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -188,16 +183,17 @@ impl Step for HtmlCheck {
188183
const ONLY_HOSTS: bool = true;
189184

190185
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
186+
let builder = run.builder;
191187
let run = run.path("src/tools/html-checker");
192-
run.lazy_default_condition(Box::new(check_if_tidy_is_installed))
188+
run.lazy_default_condition(Box::new(|| check_if_tidy_is_installed(builder)))
193189
}
194190

195191
fn make_run(run: RunConfig<'_>) {
196192
run.builder.ensure(HtmlCheck { target: run.target });
197193
}
198194

199195
fn run(self, builder: &Builder<'_>) {
200-
if !check_if_tidy_is_installed() {
196+
if !check_if_tidy_is_installed(builder) {
201197
eprintln!("not running HTML-check tool because `tidy` is missing");
202198
eprintln!(
203199
"You need the HTML tidy tool https://www.html-tidy.org/, this tool is *not* part of the rust project and needs to be installed separately, for example via your package manager."
@@ -2099,9 +2095,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
20992095
let git_config = builder.config.git_config();
21002096
cmd.arg("--git-repository").arg(git_config.git_repository);
21012097
cmd.arg("--nightly-branch").arg(git_config.nightly_branch);
2102-
2103-
// FIXME: Move CiEnv back to bootstrap, it is only used here anyway
2104-
builder.ci_env.force_coloring_in_ci(cmd.as_command_mut());
2098+
cmd.force_coloring_in_ci(builder.ci_env);
21052099

21062100
#[cfg(feature = "build-metrics")]
21072101
builder.metrics.begin_test_suite(

0 commit comments

Comments
 (0)