Skip to content
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

Rollup of 10 pull requests #137130

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6ec3cf9
Load all builtin targets at once instead of one by one
Urgau Feb 15, 2025
17071ff
Rework name_regions to not rely on reverse scc graph for non-member-c…
compiler-errors Feb 15, 2025
7e35729
Don't project into `NonNull` when dropping a `Box`
scottmcm Feb 16, 2025
6bdf340
add docs to cc-detect
Shourya742 Feb 14, 2025
f6c911a
add unit test for cc-detect
Shourya742 Feb 14, 2025
f396a31
Add an example for std::error::Error
ChrisDenton Feb 16, 2025
8ae3ca9
Fix test that relies on error language
ChrisDenton Feb 16, 2025
56f8f48
fix broken `x {doc, build} core`
onur-ozkan Feb 16, 2025
75195b5
Optimize `Seek::stream_len` impl for `File`
tbu- May 13, 2024
a529985
Clarify description of `Seek::stream_len`
tbu- Jan 9, 2025
95a5ecc
Enable relative-path-include-bytes on Windows
ChrisDenton Feb 16, 2025
b621a48
bootstrap: add more tracing to compiler/std/llvm flows
jieyouxu Feb 15, 2025
7b11816
bootstrap: take `target` by value in `is_builder_target`
jieyouxu Feb 15, 2025
05ba1a4
rustc-dev-guide: document `COMPILER` and `COMPILER_FOR` tracing targets
jieyouxu Feb 15, 2025
6027f28
Rollup merge of #125087 - tbu-:pr_file_stream_len, r=joshtriplett
GuillaumeGomez Feb 16, 2025
a4964fc
Rollup merge of #137012 - Shourya742:2025-02-14-doc-and-unit-test-cc-…
GuillaumeGomez Feb 16, 2025
54fa2f8
Rollup merge of #137072 - Urgau:check-cfg-load-builtins-at-once, r=No…
GuillaumeGomez Feb 16, 2025
51c6826
Rollup merge of #137080 - jieyouxu:more-tracing, r=onur-ozkan
GuillaumeGomez Feb 16, 2025
98aeba2
Rollup merge of #137102 - compiler-errors:name_regions2, r=oli-obk
GuillaumeGomez Feb 16, 2025
2a26fa3
Rollup merge of #137112 - scottmcm:box-drop-no-nonnull-project, r=oli…
GuillaumeGomez Feb 16, 2025
e4e82b4
Rollup merge of #137114 - ChrisDenton:error, r=Noratrieb
GuillaumeGomez Feb 16, 2025
0c3dcae
Rollup merge of #137117 - ChrisDenton:error-lang, r=fmease,Noratrieb
GuillaumeGomez Feb 16, 2025
0a867e6
Rollup merge of #137119 - onur-ozkan:fix-broken-core, r=jieyouxu
GuillaumeGomez Feb 16, 2025
d575236
Rollup merge of #137120 - ChrisDenton:its-all-relative, r=GuillaumeGomez
GuillaumeGomez Feb 16, 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
30 changes: 24 additions & 6 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use rustc_infer::infer::{NllRegionVariableOrigin, RelateParamBound};
use rustc_middle::bug;
use rustc_middle::hir::place::PlaceBase;
use rustc_middle::mir::{AnnotationSource, ConstraintCategory, ReturnConstraint};
use rustc_middle::ty::{self, GenericArgs, Region, RegionVid, Ty, TyCtxt, TypeVisitor};
use rustc_middle::ty::fold::fold_regions;
use rustc_middle::ty::{
self, GenericArgs, Region, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitor,
};
use rustc_span::{Ident, Span, kw};
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
use rustc_trait_selection::error_reporting::infer::nice_region_error::{
Expand Down Expand Up @@ -183,6 +186,17 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
}
}

/// Map the regions in the type to named regions, where possible.
fn name_regions<T>(&self, tcx: TyCtxt<'tcx>, ty: T) -> T
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
fold_regions(tcx, ty, |region, _| match *region {
ty::ReVar(vid) => self.to_error_region(vid).unwrap_or(region),
_ => region,
})
}

/// Returns `true` if a closure is inferred to be an `FnMut` closure.
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
if let Some(ty::ReLateParam(late_param)) = self.to_error_region(fr).as_deref()
Expand Down Expand Up @@ -314,7 +328,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let type_test_span = type_test.span;

if let Some(lower_bound_region) = lower_bound_region {
let generic_ty = self.regioncx.name_regions(
let generic_ty = self.name_regions(
self.infcx.tcx,
type_test.generic_kind.to_ty(self.infcx.tcx),
);
Expand All @@ -323,7 +337,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
self.body.source.def_id().expect_local(),
type_test_span,
Some(origin),
self.regioncx.name_regions(self.infcx.tcx, type_test.generic_kind),
self.name_regions(self.infcx.tcx, type_test.generic_kind),
lower_bound_region,
));
} else {
Expand Down Expand Up @@ -354,9 +368,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
}

RegionErrorKind::UnexpectedHiddenRegion { span, hidden_ty, key, member_region } => {
let named_ty = self.regioncx.name_regions(self.infcx.tcx, hidden_ty);
let named_key = self.regioncx.name_regions(self.infcx.tcx, key);
let named_region = self.regioncx.name_regions(self.infcx.tcx, member_region);
let named_ty =
self.regioncx.name_regions_for_member_constraint(self.infcx.tcx, hidden_ty);
let named_key =
self.regioncx.name_regions_for_member_constraint(self.infcx.tcx, key);
let named_region = self
.regioncx
.name_regions_for_member_constraint(self.infcx.tcx, member_region);
let diag = unexpected_hidden_region_diagnostic(
self.infcx,
self.mir_def_id(),
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// that the regions produced are in fact equal to the named region they are
/// replaced with. This is fine because this function is only to improve the
/// region names in error messages.
pub(crate) fn name_regions<T>(&self, tcx: TyCtxt<'tcx>, ty: T) -> T
///
/// This differs from `MirBorrowckCtxt::name_regions` since it is particularly
/// lax with mapping region vids that are *shorter* than a universal region to
/// that universal region. This is useful for member region constraints since
/// we want to suggest a universal region name to capture even if it's technically
/// not equal to the error region.
pub(crate) fn name_regions_for_member_constraint<T>(&self, tcx: TyCtxt<'tcx>, ty: T) -> T
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_middle/src/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ impl<'tcx> PlaceTy<'tcx> {
}
}

pub fn multi_projection_ty(
self,
tcx: TyCtxt<'tcx>,
elems: &[PlaceElem<'tcx>],
) -> PlaceTy<'tcx> {
elems.iter().fold(self, |place_ty, &elem| place_ty.projection_ty(tcx, elem))
}

/// Convenience wrapper around `projection_ty_core` for
/// `PlaceElem`, where we can just use the `Ty` that is already
/// stored inline on field projection elems.
Expand Down Expand Up @@ -167,11 +175,7 @@ impl<'tcx> Place<'tcx> {
where
D: HasLocalDecls<'tcx>,
{
projection
.iter()
.fold(PlaceTy::from_ty(local_decls.local_decls()[local].ty), |place_ty, &elem| {
place_ty.projection_ty(tcx, elem)
})
PlaceTy::from_ty(local_decls.local_decls()[local].ty).multi_projection_ty(tcx, projection)
}

pub fn ty<D: ?Sized>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>
Expand Down
30 changes: 26 additions & 4 deletions compiler/rustc_mir_transform/src/elaborate_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub(crate) trait DropElaborator<'a, 'tcx>: fmt::Debug {

// Accessors

fn patch_ref(&self) -> &MirPatch<'tcx>;
fn patch(&mut self) -> &mut MirPatch<'tcx>;
fn body(&self) -> &'a Body<'tcx>;
fn tcx(&self) -> TyCtxt<'tcx>;
Expand Down Expand Up @@ -180,7 +181,14 @@ where
{
#[instrument(level = "trace", skip(self), ret)]
fn place_ty(&self, place: Place<'tcx>) -> Ty<'tcx> {
place.ty(self.elaborator.body(), self.tcx()).ty
if place.local < self.elaborator.body().local_decls.next_index() {
place.ty(self.elaborator.body(), self.tcx()).ty
} else {
// We don't have a slice with all the locals, since some are in the patch.
tcx::PlaceTy::from_ty(self.elaborator.patch_ref().local_ty(place.local))
.multi_projection_ty(self.elaborator.tcx(), place.projection)
.ty
}
}

fn tcx(&self) -> TyCtxt<'tcx> {
Expand Down Expand Up @@ -410,12 +418,26 @@ where

let unique_place = self.tcx().mk_place_field(self.place, FieldIdx::ZERO, unique_ty);
let nonnull_place = self.tcx().mk_place_field(unique_place, FieldIdx::ZERO, nonnull_ty);
let ptr_place = self.tcx().mk_place_field(nonnull_place, FieldIdx::ZERO, ptr_ty);
let interior = self.tcx().mk_place_deref(ptr_place);

let ptr_local = self.new_temp(ptr_ty);

let interior = self.tcx().mk_place_deref(Place::from(ptr_local));
let interior_path = self.elaborator.deref_subpath(self.path);

self.drop_subpath(interior, interior_path, succ, unwind)
let do_drop_bb = self.drop_subpath(interior, interior_path, succ, unwind);

let setup_bbd = BasicBlockData {
statements: vec![self.assign(
Place::from(ptr_local),
Rvalue::Cast(CastKind::Transmute, Operand::Copy(nonnull_place), ptr_ty),
)],
terminator: Some(Terminator {
kind: TerminatorKind::Goto { target: do_drop_bb },
source_info: self.source_info,
}),
is_cleanup: unwind.is_cleanup(),
};
self.elaborator.patch().new_block(setup_bbd)
}

#[instrument(level = "debug", ret)]
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_mir_transform/src/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ impl InitializationData<'_, '_> {
impl<'a, 'tcx> DropElaborator<'a, 'tcx> for ElaborateDropsCtxt<'a, 'tcx> {
type Path = MovePathIndex;

fn patch_ref(&self) -> &MirPatch<'tcx> {
&self.patch
}

fn patch(&mut self) -> &mut MirPatch<'tcx> {
&mut self.patch
}
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_mir_transform/src/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ impl<'tcx> MirPatch<'tcx> {
Local::new(index)
}

/// Returns the type of a local that's newly-added in the patch.
pub(crate) fn local_ty(&self, local: Local) -> Ty<'tcx> {
let local = local.as_usize();
assert!(local < self.next_local);
let new_local_idx = self.new_locals.len() - (self.next_local - local);
self.new_locals[new_local_idx].ty
}

pub(crate) fn new_block(&mut self, data: BasicBlockData<'tcx>) -> BasicBlock {
let block = BasicBlock::new(self.patch_map.len());
debug!("MirPatch: new_block: {:?}: {:?}", block, data);
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_mir_transform/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ impl fmt::Debug for DropShimElaborator<'_, '_> {
impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> {
type Path = ();

fn patch_ref(&self) -> &MirPatch<'tcx> {
&self.patch
}
fn patch(&mut self) -> &mut MirPatch<'tcx> {
&mut self.patch
}
Expand Down
8 changes: 2 additions & 6 deletions compiler/rustc_session/src/config/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_lint_defs::BuiltinLintDiag;
use rustc_lint_defs::builtin::EXPLICIT_BUILTIN_CFGS_IN_FLAGS;
use rustc_span::{Symbol, sym};
use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, TARGETS, Target, TargetTuple};
use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, Target};

use crate::Session;
use crate::config::{CrateType, FmtDebug};
Expand Down Expand Up @@ -432,11 +432,7 @@ impl CheckCfg {
panic!("unable to get all the check-cfg values buckets");
};

for target in TARGETS
.iter()
.map(|target| Target::expect_builtin(&TargetTuple::from_tuple(target)))
.chain(iter::once(current_target.clone()))
{
for target in Target::builtins().chain(iter::once(current_target.clone())) {
values_target_abi.insert(Symbol::intern(&target.options.abi));
values_target_arch.insert(Symbol::intern(&target.arch));
values_target_endian.insert(Symbol::intern(target.options.endian.as_str()));
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,14 @@ macro_rules! supported_targets {
Some(t)
}

fn load_all_builtins() -> impl Iterator<Item = Target> {
[
$( targets::$module::target, )+
]
.into_iter()
.map(|f| f())
}

#[cfg(test)]
mod tests {
// Cannot put this into a separate file without duplication, make an exception.
Expand Down Expand Up @@ -3360,6 +3368,11 @@ impl Target {
}
}

/// Load all built-in targets
pub fn builtins() -> impl Iterator<Item = Target> {
load_all_builtins()
}

/// Search for a JSON file specifying the given target tuple.
///
/// If none is found in `$RUST_TARGET_PATH`, look for a file called `target.json` inside the
Expand Down
24 changes: 24 additions & 0 deletions library/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ use crate::fmt::{self, Debug, Display, Formatter};
/// accessing that error via [`Error::source()`]. This makes it possible for the
/// high-level module to provide its own errors while also revealing some of the
/// implementation for debugging.
///
/// # Example
///
/// Implementing the `Error` trait only requires that `Debug` and `Display` are implemented too.
///
/// ```
/// use std::error::Error;
/// use std::fmt;
/// use std::path::PathBuf;
///
/// #[derive(Debug)]
/// struct ReadConfigError {
/// path: PathBuf
/// }
///
/// impl fmt::Display for ReadConfigError {
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// let path = self.path.display();
/// write!(f, "unable to read configuration at {path}")
/// }
/// }
///
/// impl Error for ReadConfigError {}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Error")]
#[rustc_has_incoherent_inherent_impls]
Expand Down
35 changes: 35 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,9 +1226,38 @@ impl Write for &File {
}
#[stable(feature = "rust1", since = "1.0.0")]
impl Seek for &File {
/// Seek to an offset, in bytes in a file.
///
/// See [`Seek::seek`] docs for more info.
///
/// # Platform-specific behavior
///
/// This function currently corresponds to the `lseek64` function on Unix
/// and the `SetFilePointerEx` function on Windows. Note that this [may
/// change in the future][changes].
///
/// [changes]: io#platform-specific-behavior
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
self.inner.seek(pos)
}

/// Returns the length of this file (in bytes).
///
/// See [`Seek::stream_len`] docs for more info.
///
/// # Platform-specific behavior
///
/// This function currently corresponds to the `statx` function on Linux
/// (with fallbacks) and the `GetFileSizeEx` function on Windows. Note that
/// this [may change in the future][changes].
///
/// [changes]: io#platform-specific-behavior
fn stream_len(&mut self) -> io::Result<u64> {
if let Some(result) = self.inner.size() {
return result;
}
io::stream_len_default(self)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -1275,6 +1304,9 @@ impl Seek for File {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
(&*self).seek(pos)
}
fn stream_len(&mut self) -> io::Result<u64> {
(&*self).stream_len()
}
}

#[stable(feature = "io_traits_arc", since = "1.73.0")]
Expand Down Expand Up @@ -1321,6 +1353,9 @@ impl Seek for Arc<File> {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
(&**self).seek(pos)
}
fn stream_len(&mut self) -> io::Result<u64> {
(&**self).stream_len()
}
}

impl OpenOptions {
Expand Down
26 changes: 15 additions & 11 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,7 @@ pub trait Seek {

/// Returns the length of this stream (in bytes).
///
/// This method is implemented using up to three seek operations. If this
/// The default implementation uses up to three seek operations. If this
/// method returns successfully, the seek position is unchanged (i.e. the
/// position before calling this method is the same as afterwards).
/// However, if this method returns an error, the seek position is
Expand Down Expand Up @@ -2051,16 +2051,7 @@ pub trait Seek {
/// ```
#[unstable(feature = "seek_stream_len", issue = "59359")]
fn stream_len(&mut self) -> Result<u64> {
let old_pos = self.stream_position()?;
let len = self.seek(SeekFrom::End(0))?;

// Avoid seeking a third time when we were already at the end of the
// stream. The branch is usually way cheaper than a seek operation.
if old_pos != len {
self.seek(SeekFrom::Start(old_pos))?;
}

Ok(len)
stream_len_default(self)
}

/// Returns the current seek position from the start of the stream.
Expand Down Expand Up @@ -2121,6 +2112,19 @@ pub trait Seek {
}
}

pub(crate) fn stream_len_default<T: Seek + ?Sized>(self_: &mut T) -> Result<u64> {
let old_pos = self_.stream_position()?;
let len = self_.seek(SeekFrom::End(0))?;

// Avoid seeking a third time when we were already at the end of the
// stream. The branch is usually way cheaper than a seek operation.
if old_pos != len {
self_.seek(SeekFrom::Start(old_pos))?;
}

Ok(len)
}

/// Enumeration of possible methods to seek within an I/O object.
///
/// It is used by the [`Seek`] trait.
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/pal/hermit/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ impl File {
Err(Error::from_raw_os_error(22))
}

pub fn size(&self) -> Option<io::Result<u64>> {
None
}

pub fn duplicate(&self) -> io::Result<File> {
Err(Error::from_raw_os_error(22))
}
Expand Down
Loading
Loading