Skip to content

Rollup of 6 pull requests #143676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fab9c64
Add triagebot stdarch mention ping
Kobzol Jul 8, 2025
66bc234
tidy: refactor --extra-checks parsing
lolbinarycat Jul 3, 2025
9eb1805
tidy: factor out change detection logic and make it more robust
lolbinarycat Jul 3, 2025
4a6f697
tidy: update files_modified to take CiInfo
lolbinarycat Jul 3, 2025
64456e0
tidy: add `auto:` prefix to --extra-checks syntax
lolbinarycat Jul 3, 2025
6b349a4
tidy: warn when --extra-checks is passed an invalid lang:kind combo
lolbinarycat Jul 3, 2025
9aafc98
tidy: assume all files are modified in CI
lolbinarycat Jul 8, 2025
1f80fd0
bootstrap: add change tracker entry for new --extra-checks=auto: feature
lolbinarycat Jul 8, 2025
87e7539
Disable docs for `compiler-builtins` and `sysroot`
cuviper Jul 8, 2025
3c7bf9f
Expose nested bodies in rustc_borrowck::consumers
nilehmann Jul 9, 2025
6637335
Fix VxWorks build errors
biabbas Jul 9, 2025
6fe2ad8
use `--dynamic-list` for exporting executable symbols
usamoi Jul 4, 2025
0e676f4
Rollup merge of #143398 - lolbinarycat:tidy-extra-checks-auto, r=Kobzol
Kobzol Jul 9, 2025
c1bb3b8
Rollup merge of #143446 - usamoi:export-executable-symbols, r=bjorn3,…
Kobzol Jul 9, 2025
667289c
Rollup merge of #143644 - Kobzol:stdarch-mention, r=Amanieu
Kobzol Jul 9, 2025
9e1872a
Rollup merge of #143660 - cuviper:lib-doc-false, r=tgross35
Kobzol Jul 9, 2025
93ab533
Rollup merge of #143666 - nilehmann:nested_bodies_in_consumers, r=lcnr
Kobzol Jul 9, 2025
5b59dbd
Rollup merge of #143668 - biabbas:vxworks, r=Noratrieb
Kobzol Jul 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 57 additions & 24 deletions compiler/rustc_borrowck/src/consumers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! This file provides API for compiler consumers.
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::LocalDefId;
use rustc_index::IndexVec;
use rustc_middle::bug;
use rustc_middle::mir::{Body, Promoted};
use rustc_middle::ty::TyCtxt;

Expand All @@ -17,7 +19,39 @@ pub use super::polonius::legacy::{
pub use super::region_infer::RegionInferenceContext;
use crate::{BorrowCheckRootCtxt, do_mir_borrowck};

/// Options determining the output behavior of [`get_body_with_borrowck_facts`].
/// Struct used during mir borrowck to collect bodies with facts for a typeck root and all
/// its nested bodies.
pub(crate) struct BorrowckConsumer<'tcx> {
options: ConsumerOptions,
bodies: FxHashMap<LocalDefId, BodyWithBorrowckFacts<'tcx>>,
}

impl<'tcx> BorrowckConsumer<'tcx> {
pub(crate) fn new(options: ConsumerOptions) -> Self {
Self { options, bodies: Default::default() }
}

pub(crate) fn insert_body(&mut self, def_id: LocalDefId, body: BodyWithBorrowckFacts<'tcx>) {
if self.bodies.insert(def_id, body).is_some() {
bug!("unexpected previous body for {def_id:?}");
}
}

/// Should the Polonius input facts be computed?
pub(crate) fn polonius_input(&self) -> bool {
matches!(
self.options,
ConsumerOptions::PoloniusInputFacts | ConsumerOptions::PoloniusOutputFacts
)
}

/// Should we run Polonius and collect the output facts?
pub(crate) fn polonius_output(&self) -> bool {
matches!(self.options, ConsumerOptions::PoloniusOutputFacts)
}
}

/// Options determining the output behavior of [`get_bodies_with_borrowck_facts`].
///
/// If executing under `-Z polonius` the choice here has no effect, and everything as if
/// [`PoloniusOutputFacts`](ConsumerOptions::PoloniusOutputFacts) had been selected
Expand All @@ -43,17 +77,6 @@ pub enum ConsumerOptions {
PoloniusOutputFacts,
}

impl ConsumerOptions {
/// Should the Polonius input facts be computed?
pub(crate) fn polonius_input(&self) -> bool {
matches!(self, Self::PoloniusInputFacts | Self::PoloniusOutputFacts)
}
/// Should we run Polonius and collect the output facts?
pub(crate) fn polonius_output(&self) -> bool {
matches!(self, Self::PoloniusOutputFacts)
}
}

/// A `Body` with information computed by the borrow checker. This struct is
/// intended to be consumed by compiler consumers.
///
Expand Down Expand Up @@ -82,25 +105,35 @@ pub struct BodyWithBorrowckFacts<'tcx> {
pub output_facts: Option<Box<PoloniusOutput>>,
}

/// This function computes borrowck facts for the given body. The [`ConsumerOptions`]
/// determine which facts are returned. This function makes a copy of the body because
/// it needs to regenerate the region identifiers. It should never be invoked during a
/// typical compilation session due to the unnecessary overhead of returning
/// [`BodyWithBorrowckFacts`].
/// This function computes borrowck facts for the given def id and all its nested bodies.
/// It must be called with a typeck root which will then borrowck all nested bodies as well.
/// The [`ConsumerOptions`] determine which facts are returned. This function makes a copy
/// of the bodies because it needs to regenerate the region identifiers. It should never be
/// invoked during a typical compilation session due to the unnecessary overhead of
/// returning [`BodyWithBorrowckFacts`].
///
/// Note:
/// * This function will panic if the required body was already stolen. This
/// * This function will panic if the required bodies were already stolen. This
/// can, for example, happen when requesting a body of a `const` function
/// because they are evaluated during typechecking. The panic can be avoided
/// by overriding the `mir_borrowck` query. You can find a complete example
/// that shows how to do this at `tests/run-make/obtain-borrowck/`.
/// that shows how to do this at `tests/ui-fulldeps/obtain-borrowck.rs`.
///
/// * Polonius is highly unstable, so expect regular changes in its signature or other details.
pub fn get_body_with_borrowck_facts(
pub fn get_bodies_with_borrowck_facts(
tcx: TyCtxt<'_>,
def_id: LocalDefId,
root_def_id: LocalDefId,
options: ConsumerOptions,
) -> BodyWithBorrowckFacts<'_> {
let mut root_cx = BorrowCheckRootCtxt::new(tcx, def_id);
*do_mir_borrowck(&mut root_cx, def_id, Some(options)).1.unwrap()
) -> FxHashMap<LocalDefId, BodyWithBorrowckFacts<'_>> {
let mut root_cx =
BorrowCheckRootCtxt::new(tcx, root_def_id, Some(BorrowckConsumer::new(options)));

// See comment in `rustc_borrowck::mir_borrowck`
let nested_bodies = tcx.nested_bodies_within(root_def_id);
for def_id in nested_bodies {
root_cx.get_or_insert_nested(def_id);
}

do_mir_borrowck(&mut root_cx, root_def_id);
root_cx.consumer.unwrap().bodies
}
43 changes: 19 additions & 24 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use smallvec::SmallVec;
use tracing::{debug, instrument};

use crate::borrow_set::{BorrowData, BorrowSet};
use crate::consumers::{BodyWithBorrowckFacts, ConsumerOptions};
use crate::consumers::BodyWithBorrowckFacts;
use crate::dataflow::{BorrowIndex, Borrowck, BorrowckDomain, Borrows};
use crate::diagnostics::{
AccessKind, BorrowckDiagnosticsBuffer, IllegalMoveOriginKind, MoveError, RegionName,
Expand Down Expand Up @@ -124,7 +124,7 @@ fn mir_borrowck(
let opaque_types = ConcreteOpaqueTypes(Default::default());
Ok(tcx.arena.alloc(opaque_types))
} else {
let mut root_cx = BorrowCheckRootCtxt::new(tcx, def);
let mut root_cx = BorrowCheckRootCtxt::new(tcx, def, None);
// We need to manually borrowck all nested bodies from the HIR as
// we do not generate MIR for dead code. Not doing so causes us to
// never check closures in dead code.
Expand All @@ -134,7 +134,7 @@ fn mir_borrowck(
}

let PropagatedBorrowCheckResults { closure_requirements, used_mut_upvars } =
do_mir_borrowck(&mut root_cx, def, None).0;
do_mir_borrowck(&mut root_cx, def);
debug_assert!(closure_requirements.is_none());
debug_assert!(used_mut_upvars.is_empty());
root_cx.finalize()
Expand Down Expand Up @@ -289,17 +289,12 @@ impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {

/// Perform the actual borrow checking.
///
/// Use `consumer_options: None` for the default behavior of returning
/// [`PropagatedBorrowCheckResults`] only. Otherwise, return [`BodyWithBorrowckFacts`]
/// according to the given [`ConsumerOptions`].
///
/// For nested bodies this should only be called through `root_cx.get_or_insert_nested`.
#[instrument(skip(root_cx), level = "debug")]
fn do_mir_borrowck<'tcx>(
root_cx: &mut BorrowCheckRootCtxt<'tcx>,
def: LocalDefId,
consumer_options: Option<ConsumerOptions>,
) -> (PropagatedBorrowCheckResults<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
) -> PropagatedBorrowCheckResults<'tcx> {
let tcx = root_cx.tcx;
let infcx = BorrowckInferCtxt::new(tcx, def);
let (input_body, promoted) = tcx.mir_promoted(def);
Expand Down Expand Up @@ -343,7 +338,6 @@ fn do_mir_borrowck<'tcx>(
&location_table,
&move_data,
&borrow_set,
consumer_options,
);

// Dump MIR results into a file, if that is enabled. This lets us
Expand Down Expand Up @@ -483,23 +477,24 @@ fn do_mir_borrowck<'tcx>(
used_mut_upvars: mbcx.used_mut_upvars,
};

let body_with_facts = if consumer_options.is_some() {
Some(Box::new(BodyWithBorrowckFacts {
body: body_owned,
promoted,
borrow_set,
region_inference_context: regioncx,
location_table: polonius_input.as_ref().map(|_| location_table),
input_facts: polonius_input,
output_facts: polonius_output,
}))
} else {
None
};
if let Some(consumer) = &mut root_cx.consumer {
consumer.insert_body(
def,
BodyWithBorrowckFacts {
body: body_owned,
promoted,
borrow_set,
region_inference_context: regioncx,
location_table: polonius_input.as_ref().map(|_| location_table),
input_facts: polonius_input,
output_facts: polonius_output,
},
);
}

debug!("do_mir_borrowck: result = {:#?}", result);

(result, body_with_facts)
result
}

fn get_flow_results<'a, 'tcx>(
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use rustc_span::sym;
use tracing::{debug, instrument};

use crate::borrow_set::BorrowSet;
use crate::consumers::ConsumerOptions;
use crate::diagnostics::RegionErrors;
use crate::handle_placeholders::compute_sccs_applying_placeholder_outlives_constraints;
use crate::polonius::PoloniusDiagnosticsContext;
Expand Down Expand Up @@ -83,12 +82,11 @@ pub(crate) fn compute_regions<'tcx>(
location_table: &PoloniusLocationTable,
move_data: &MoveData<'tcx>,
borrow_set: &BorrowSet<'tcx>,
consumer_options: Option<ConsumerOptions>,
) -> NllOutput<'tcx> {
let is_polonius_legacy_enabled = infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled();
let polonius_input = consumer_options.map(|c| c.polonius_input()).unwrap_or_default()
let polonius_input = root_cx.consumer.as_ref().map_or(false, |c| c.polonius_input())
|| is_polonius_legacy_enabled;
let polonius_output = consumer_options.map(|c| c.polonius_output()).unwrap_or_default()
let polonius_output = root_cx.consumer.as_ref().map_or(false, |c| c.polonius_output())
|| is_polonius_legacy_enabled;
let mut polonius_facts =
(polonius_input || PoloniusFacts::enabled(infcx.tcx)).then_some(PoloniusFacts::default());
Expand Down
13 changes: 11 additions & 2 deletions compiler/rustc_borrowck/src/root_cx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use rustc_middle::ty::{OpaqueHiddenType, Ty, TyCtxt, TypeVisitableExt};
use rustc_span::ErrorGuaranteed;
use smallvec::SmallVec;

use crate::consumers::BorrowckConsumer;
use crate::{ClosureRegionRequirements, ConcreteOpaqueTypes, PropagatedBorrowCheckResults};

/// The shared context used by both the root as well as all its nested
Expand All @@ -16,16 +17,24 @@ pub(super) struct BorrowCheckRootCtxt<'tcx> {
concrete_opaque_types: ConcreteOpaqueTypes<'tcx>,
nested_bodies: FxHashMap<LocalDefId, PropagatedBorrowCheckResults<'tcx>>,
tainted_by_errors: Option<ErrorGuaranteed>,
/// This should be `None` during normal compilation. See [`crate::consumers`] for more
/// information on how this is used.
pub(crate) consumer: Option<BorrowckConsumer<'tcx>>,
}

impl<'tcx> BorrowCheckRootCtxt<'tcx> {
pub(super) fn new(tcx: TyCtxt<'tcx>, root_def_id: LocalDefId) -> BorrowCheckRootCtxt<'tcx> {
pub(super) fn new(
tcx: TyCtxt<'tcx>,
root_def_id: LocalDefId,
consumer: Option<BorrowckConsumer<'tcx>>,
) -> BorrowCheckRootCtxt<'tcx> {
BorrowCheckRootCtxt {
tcx,
root_def_id,
concrete_opaque_types: Default::default(),
nested_bodies: Default::default(),
tainted_by_errors: None,
consumer,
}
}

Expand Down Expand Up @@ -71,7 +80,7 @@ impl<'tcx> BorrowCheckRootCtxt<'tcx> {
self.root_def_id.to_def_id()
);
if !self.nested_bodies.contains_key(&def_id) {
let result = super::do_mir_borrowck(self, def_id, None).0;
let result = super::do_mir_borrowck(self, def_id);
if let Some(prev) = self.nested_bodies.insert(def_id, result) {
bug!("unexpected previous nested body: {prev:?}");
}
Expand Down
41 changes: 25 additions & 16 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,7 @@ impl<'a> Linker for GccLinker<'a> {
return;
}

let is_windows = self.sess.target.is_like_windows;
let path = tmpdir.join(if is_windows { "list.def" } else { "list" });

let path = tmpdir.join(if self.sess.target.is_like_windows { "list.def" } else { "list" });
debug!("EXPORTED SYMBOLS:");

if self.sess.target.is_like_darwin {
Expand All @@ -817,7 +815,8 @@ impl<'a> Linker for GccLinker<'a> {
if let Err(error) = res {
self.sess.dcx().emit_fatal(errors::LibDefWriteFailure { error });
}
} else if is_windows {
self.link_arg("-exported_symbols_list").link_arg(path);
} else if self.sess.target.is_like_windows {
let res: io::Result<()> = try {
let mut f = File::create_buffered(&path)?;

Expand All @@ -835,6 +834,21 @@ impl<'a> Linker for GccLinker<'a> {
if let Err(error) = res {
self.sess.dcx().emit_fatal(errors::LibDefWriteFailure { error });
}
self.link_arg(path);
} else if crate_type == CrateType::Executable && !self.sess.target.is_like_solaris {
let res: io::Result<()> = try {
let mut f = File::create_buffered(&path)?;
writeln!(f, "{{")?;
for (sym, _) in symbols {
debug!(sym);
writeln!(f, " {sym};")?;
}
writeln!(f, "}};")?;
};
if let Err(error) = res {
self.sess.dcx().emit_fatal(errors::VersionScriptWriteFailure { error });
}
self.link_arg("--dynamic-list").link_arg(path);
} else {
// Write an LD version script
let res: io::Result<()> = try {
Expand All @@ -852,18 +866,13 @@ impl<'a> Linker for GccLinker<'a> {
if let Err(error) = res {
self.sess.dcx().emit_fatal(errors::VersionScriptWriteFailure { error });
}
}

if self.sess.target.is_like_darwin {
self.link_arg("-exported_symbols_list").link_arg(path);
} else if self.sess.target.is_like_solaris {
self.link_arg("-M").link_arg(path);
} else if is_windows {
self.link_arg(path);
} else {
let mut arg = OsString::from("--version-script=");
arg.push(path);
self.link_arg(arg).link_arg("--no-undefined-version");
if self.sess.target.is_like_solaris {
self.link_arg("-M").link_arg(path);
} else {
let mut arg = OsString::from("--version-script=");
arg.push(path);
self.link_arg(arg).link_arg("--no-undefined-version");
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions library/compiler-builtins/compiler-builtins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ links = "compiler-rt"
bench = false
doctest = false
test = false
# make sure this crate isn't included in public standard library docs
doc = false

[dependencies]
core = { path = "../../core", optional = true }
Expand Down
1 change: 0 additions & 1 deletion library/std/src/sys/fs/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,6 @@ impl File {
target_os = "redox",
target_os = "espidf",
target_os = "horizon",
target_os = "vxworks",
target_os = "nuttx",
)))]
let to_timespec = |time: Option<SystemTime>| match time {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl Thread {

#[cfg(target_os = "vxworks")]
pub fn set_name(name: &CStr) {
let mut name = truncate_cstr::<{ libc::VX_TASK_RENAME_LENGTH - 1 }>(name);
let mut name = truncate_cstr::<{ (libc::VX_TASK_RENAME_LENGTH - 1) as usize }>(name);
let res = unsafe { libc::taskNameSet(libc::taskIdSelf(), name.as_mut_ptr()) };
debug_assert_eq!(res, libc::OK);
}
Expand Down
4 changes: 4 additions & 0 deletions library/sysroot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ name = "sysroot"
version = "0.0.0"
edition = "2024"

[lib]
# make sure this crate isn't included in public standard library docs
doc = false

# this is a dummy crate to ensure that all required crates appear in the sysroot
[dependencies]
proc_macro = { path = "../proc_macro", public = true }
Expand Down
4 changes: 0 additions & 4 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,10 +739,6 @@ fn doc_std(
}

for krate in requested_crates {
if krate == "sysroot" {
// The sysroot crate is an implementation detail, don't include it in public docs.
continue;
}
cargo.arg("-p").arg(krate);
}

Expand Down
Loading
Loading