Skip to content

Commit

Permalink
Auto merge of rust-lang#127788 - tgross35:rollup-kdqqz56, r=tgross35
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - rust-lang#120990 (Suggest a borrow when using dbg)
 - rust-lang#127047 (fix least significant digits of f128 associated constants)
 - rust-lang#127680 (Bootstrap command refactoring: port remaining commands with access to `Build` (step 6))
 - rust-lang#127770 (Update books)
 - rust-lang#127780 (Make sure trait def ids match before zipping args in `note_function_argument_obligation`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jul 16, 2024
2 parents 5c84886 + 36c2f58 commit 9d6d563
Show file tree
Hide file tree
Showing 26 changed files with 506 additions and 218 deletions.
65 changes: 63 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![allow(rustc::untranslatable_diagnostic)]

use either::Either;
use hir::ClosureKind;
use hir::{ClosureKind, Path};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag, MultiSpan};
Expand All @@ -16,6 +16,7 @@ use rustc_hir::{CoroutineKind, CoroutineSource, LangItem};
use rustc_middle::bug;
use rustc_middle::hir::nested_filter::OnlyBodies;
use rustc_middle::mir::tcx::PlaceTy;
use rustc_middle::mir::VarDebugInfoContents;
use rustc_middle::mir::{
self, AggregateKind, BindingForm, BorrowKind, CallSource, ClearCrossCrate, ConstraintCategory,
FakeBorrowKind, FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, MutBorrowKind,
Expand Down Expand Up @@ -546,7 +547,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
self.suggest_cloning(err, ty, expr, None, Some(move_spans));
}
}
if let Some(pat) = finder.pat {

self.suggest_ref_for_dbg_args(expr, place, move_span, err);

// it's useless to suggest inserting `ref` when the span don't comes from local code
if let Some(pat) = finder.pat
&& !move_span.is_dummy()
&& !self.infcx.tcx.sess.source_map().is_imported(move_span)
{
*in_pattern = true;
let mut sugg = vec![(pat.span.shrink_to_lo(), "ref ".to_string())];
if let Some(pat) = finder.parent_pat {
Expand All @@ -561,6 +569,59 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
}
}

// for dbg!(x) which may take ownership, suggest dbg!(&x) instead
// but here we actually do not check whether the macro name is `dbg!`
// so that we may extend the scope a bit larger to cover more cases
fn suggest_ref_for_dbg_args(
&self,
body: &hir::Expr<'_>,
place: &Place<'tcx>,
move_span: Span,
err: &mut Diag<'infcx>,
) {
let var_info = self.body.var_debug_info.iter().find(|info| match info.value {
VarDebugInfoContents::Place(ref p) => p == place,
_ => false,
});
let arg_name = if let Some(var_info) = var_info {
var_info.name
} else {
return;
};
struct MatchArgFinder {
expr_span: Span,
match_arg_span: Option<Span>,
arg_name: Symbol,
}
impl Visitor<'_> for MatchArgFinder {
fn visit_expr(&mut self, e: &hir::Expr<'_>) {
// dbg! is expanded into a match pattern, we need to find the right argument span
if let hir::ExprKind::Match(expr, ..) = &e.kind
&& let hir::ExprKind::Path(hir::QPath::Resolved(
_,
path @ Path { segments: [seg], .. },
)) = &expr.kind
&& seg.ident.name == self.arg_name
&& self.expr_span.source_callsite().contains(expr.span)
{
self.match_arg_span = Some(path.span);
}
hir::intravisit::walk_expr(self, e);
}
}

let mut finder = MatchArgFinder { expr_span: move_span, match_arg_span: None, arg_name };
finder.visit_expr(body);
if let Some(macro_arg_span) = finder.match_arg_span {
err.span_suggestion_verbose(
macro_arg_span.shrink_to_lo(),
"consider borrowing instead of transferring ownership",
"&",
Applicability::MachineApplicable,
);
}
}

fn report_use_of_uninitialized(
&self,
mpi: MovePathIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3810,6 +3810,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
{
if let Some(where_pred) = where_pred.as_trait_clause()
&& let Some(failed_pred) = failed_pred.as_trait_clause()
&& where_pred.def_id() == failed_pred.def_id()
{
self.enter_forall(where_pred, |where_pred| {
let failed_pred = self.instantiate_binder_with_fresh_vars(
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ impl f128 {
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
/// [`MANTISSA_DIGITS`]: f128::MANTISSA_DIGITS
#[unstable(feature = "f128", issue = "116909")]
pub const EPSILON: f128 = 1.92592994438723585305597794258492731e-34_f128;
pub const EPSILON: f128 = 1.92592994438723585305597794258492732e-34_f128;

/// Smallest finite `f128` value.
///
/// Equal to &minus;[`MAX`].
///
/// [`MAX`]: f128::MAX
#[unstable(feature = "f128", issue = "116909")]
pub const MIN: f128 = -1.18973149535723176508575932662800701e+4932_f128;
pub const MIN: f128 = -1.18973149535723176508575932662800702e+4932_f128;
/// Smallest positive normal `f128` value.
///
/// Equal to 2<sup>[`MIN_EXP`]&nbsp;&minus;&nbsp;1</sup>.
Expand All @@ -194,7 +194,7 @@ impl f128 {
/// [`MANTISSA_DIGITS`]: f128::MANTISSA_DIGITS
/// [`MAX_EXP`]: f128::MAX_EXP
#[unstable(feature = "f128", issue = "116909")]
pub const MAX: f128 = 1.18973149535723176508575932662800701e+4932_f128;
pub const MAX: f128 = 1.18973149535723176508575932662800702e+4932_f128;

/// One greater than the minimum possible normal power of 2 exponent.
///
Expand Down
26 changes: 9 additions & 17 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::fs;
use std::io::prelude::*;
use std::io::BufReader;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::process::Stdio;
use std::str;

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

target_deps.push(dst);
Expand All @@ -707,25 +707,17 @@ fn copy_sanitizers(
target_deps
}

fn apple_darwin_update_library_name(library_path: &Path, new_name: &str) {
let status = Command::new("install_name_tool")
.arg("-id")
.arg(new_name)
.arg(library_path)
.status()
.expect("failed to execute `install_name_tool`");
assert!(status.success());
fn apple_darwin_update_library_name(builder: &Builder<'_>, library_path: &Path, new_name: &str) {
command("install_name_tool").arg("-id").arg(new_name).arg(library_path).run(builder);
}

fn apple_darwin_sign_file(file_path: &Path) {
let status = Command::new("codesign")
fn apple_darwin_sign_file(builder: &Builder<'_>, file_path: &Path) {
command("codesign")
.arg("-f") // Force to rewrite the existing signature
.arg("-s")
.arg("-")
.arg(file_path)
.status()
.expect("failed to execute `codesign`");
assert!(status.success());
.run(builder);
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -1171,7 +1163,7 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
if builder.config.llvm_profile_generate && target.is_msvc() {
if let Some(ref clang_cl_path) = builder.config.llvm_clang_cl {
// Add clang's runtime library directory to the search path
let clang_rt_dir = get_clang_cl_resource_dir(clang_cl_path);
let clang_rt_dir = get_clang_cl_resource_dir(builder, clang_cl_path);
llvm_linker_flags.push_str(&format!("-L{}", clang_rt_dir.display()));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub fn prebuilt_llvm_config(builder: &Builder<'_>, target: TargetSelection) -> L
static STAMP_HASH_MEMO: OnceLock<String> = OnceLock::new();
let smart_stamp_hash = STAMP_HASH_MEMO.get_or_init(|| {
generate_smart_stamp_hash(
builder,
&builder.config.src.join("src/llvm-project"),
builder.in_tree_llvm_info.sha().unwrap_or_default(),
)
Expand Down Expand Up @@ -912,7 +913,7 @@ impl Step for Lld {
if let Some(clang_cl_path) = builder.config.llvm_clang_cl.as_ref() {
// Find clang's runtime library directory and push that as a search path to the
// cmake linker flags.
let clang_rt_dir = get_clang_cl_resource_dir(clang_cl_path);
let clang_rt_dir = get_clang_cl_resource_dir(builder, clang_cl_path);
ldflags.push_all(format!("/libpath:{}", clang_rt_dir.display()));
}
}
Expand Down
60 changes: 28 additions & 32 deletions src/bootstrap/src/core/build_steps/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::t;
use crate::utils::change_tracker::CONFIG_CHANGE_HISTORY;
use crate::utils::exec::command;
use crate::utils::helpers::{self, hex_encode};
use crate::Config;
use sha2::Digest;
Expand All @@ -16,7 +17,6 @@ use std::fmt::Write as _;
use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf, MAIN_SEPARATOR_STR};
use std::process::Command;
use std::str::FromStr;
use std::{fmt, fs, io};

Expand Down Expand Up @@ -266,20 +266,16 @@ impl Step for Link {
}
let stage_path =
["build", config.build.rustc_target_arg(), "stage1"].join(MAIN_SEPARATOR_STR);
if !rustup_installed() {
if !rustup_installed(builder) {
eprintln!("`rustup` is not installed; cannot link `stage1` toolchain");
} else if stage_dir_exists(&stage_path[..]) && !config.dry_run() {
attempt_toolchain_link(&stage_path[..]);
attempt_toolchain_link(builder, &stage_path[..]);
}
}
}

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

fn stage_dir_exists(stage_path: &str) -> bool {
Expand All @@ -289,8 +285,8 @@ fn stage_dir_exists(stage_path: &str) -> bool {
}
}

fn attempt_toolchain_link(stage_path: &str) {
if toolchain_is_linked() {
fn attempt_toolchain_link(builder: &Builder<'_>, stage_path: &str) {
if toolchain_is_linked(builder) {
return;
}

Expand All @@ -301,7 +297,7 @@ fn attempt_toolchain_link(stage_path: &str) {
return;
}

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

fn toolchain_is_linked() -> bool {
match Command::new("rustup")
fn toolchain_is_linked(builder: &Builder<'_>) -> bool {
match command("rustup")
.capture_stdout()
.allow_failure()
.args(["toolchain", "list"])
.stdout(std::process::Stdio::piped())
.output()
.run(builder)
.stdout_if_ok()
{
Ok(toolchain_list) => {
if !String::from_utf8_lossy(&toolchain_list.stdout).contains("stage1") {
Some(toolchain_list) => {
if !toolchain_list.contains("stage1") {
return false;
}
// The toolchain has already been linked.
println!(
"`stage1` toolchain already linked; not attempting to link `stage1` toolchain"
);
}
Err(_) => {
None => {
// In this case, we don't know if the `stage1` toolchain has been linked;
// but `rustup` failed, so let's not go any further.
println!(
Expand All @@ -341,12 +339,12 @@ fn toolchain_is_linked() -> bool {
true
}

fn try_link_toolchain(stage_path: &str) -> bool {
Command::new("rustup")
.stdout(std::process::Stdio::null())
fn try_link_toolchain(builder: &Builder<'_>, stage_path: &str) -> bool {
command("rustup")
.capture_stdout()
.args(["toolchain", "link", "stage1", stage_path])
.output()
.map_or(false, |output| output.status.success())
.run(builder)
.is_success()
}

fn ensure_stage1_toolchain_placeholder_exists(stage_path: &str) -> bool {
Expand Down Expand Up @@ -476,20 +474,18 @@ impl Step for Hook {
if config.dry_run() {
return;
}
t!(install_git_hook_maybe(config));
t!(install_git_hook_maybe(builder, config));
}
}

// install a git hook to automatically run tidy, if they want
fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
fn install_git_hook_maybe(builder: &Builder<'_>, config: &Config) -> io::Result<()> {
let git = helpers::git(Some(&config.src))
.capture()
.args(["rev-parse", "--git-common-dir"])
.as_command_mut()
.output()
.map(|output| {
assert!(output.status.success(), "failed to run `git`");
PathBuf::from(t!(String::from_utf8(output.stdout)).trim())
})?;
.run(builder)
.stdout();
let git = PathBuf::from(git.trim());
let hooks_dir = git.join("hooks");
let dst = hooks_dir.join("pre-push");
if dst.exists() {
Expand Down
18 changes: 6 additions & 12 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::ffi::OsString;
use std::fs;
use std::iter;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

use clap_complete::shells;

Expand Down Expand Up @@ -169,12 +168,8 @@ You can skip linkcheck with --skip src/tools/linkchecker"
}
}

fn check_if_tidy_is_installed() -> bool {
Command::new("tidy")
.arg("--version")
.stdout(Stdio::null())
.status()
.map_or(false, |status| status.success())
fn check_if_tidy_is_installed(builder: &Builder<'_>) -> bool {
command("tidy").capture_stdout().allow_failure().arg("--version").run(builder).is_success()
}

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

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let builder = run.builder;
let run = run.path("src/tools/html-checker");
run.lazy_default_condition(Box::new(check_if_tidy_is_installed))
run.lazy_default_condition(Box::new(|| check_if_tidy_is_installed(builder)))
}

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

fn run(self, builder: &Builder<'_>) {
if !check_if_tidy_is_installed() {
if !check_if_tidy_is_installed(builder) {
eprintln!("not running HTML-check tool because `tidy` is missing");
eprintln!(
"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."
Expand Down Expand Up @@ -2099,9 +2095,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
let git_config = builder.config.git_config();
cmd.arg("--git-repository").arg(git_config.git_repository);
cmd.arg("--nightly-branch").arg(git_config.nightly_branch);

// FIXME: Move CiEnv back to bootstrap, it is only used here anyway
builder.ci_env.force_coloring_in_ci(cmd.as_command_mut());
cmd.force_coloring_in_ci(builder.ci_env);

#[cfg(feature = "build-metrics")]
builder.metrics.begin_test_suite(
Expand Down
Loading

0 comments on commit 9d6d563

Please sign in to comment.