Skip to content

Commit

Permalink
Auto merge of rust-lang#126710 - jieyouxu:rollup-3hmke71, r=jieyouxu
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - rust-lang#124807 (Migrate `run-make/rustdoc-io-error` to `rmake.rs`)
 - rust-lang#126095 (Migrate `link-args-order`, `ls-metadata` and `lto-readonly-lib` `run-make` tests to `rmake`)
 - rust-lang#126308 (Ban `ArrayToPointer` and `MutToConstPointer` from runtime MIR)
 - rust-lang#126620 (Actually taint InferCtxt when a fulfillment error is emitted)
 - rust-lang#126629 (Migrate `run-make/compressed-debuginfo` to `rmake.rs`)
 - rust-lang#126644 (Rewrite `extern-flag-rename-transitive`. `debugger-visualizer-dep-info`, `metadata-flag-frobs-symbols`, `extern-overrides-distribution` and `forced-unwind-terminate-pof` `run-make` tests to rmake)
 - rust-lang#126650 (Rename a bunch of things in the new solver and `rustc_type_ir`)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jun 19, 2024
2 parents d8a38b0 + 5d6bebd commit f2b449c
Show file tree
Hide file tree
Showing 145 changed files with 1,435 additions and 970 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
tcx: TyCtxt<'tcx>,
}
impl<'tcx> ty::TypeFolder<TyCtxt<'tcx>> for OpaqueFolder<'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
Expand Down
21 changes: 11 additions & 10 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,21 +677,22 @@ fn codegen_stmt<'tcx>(
CastKind::PointerCoercion(PointerCoercion::UnsafeFnPointer),
ref operand,
to_ty,
)
| Rvalue::Cast(
CastKind::PointerCoercion(PointerCoercion::MutToConstPointer),
ref operand,
to_ty,
)
| Rvalue::Cast(
CastKind::PointerCoercion(PointerCoercion::ArrayToPointer),
ref operand,
to_ty,
) => {
let to_layout = fx.layout_of(fx.monomorphize(to_ty));
let operand = codegen_operand(fx, operand);
lval.write_cvalue(fx, operand.cast_pointer_to(to_layout));
}
Rvalue::Cast(
CastKind::PointerCoercion(
PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer,
),
..,
) => {
bug!(
"{:?} is for borrowck, and should never appear in codegen",
to_place_and_rval.1
);
}
Rvalue::Cast(
CastKind::IntToInt
| CastKind::FloatToFloat
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
base::unsize_ptr(bx, lldata, operand.layout.ty, cast.ty, llextra);
OperandValue::Pair(lldata, llextra)
}
mir::CastKind::PointerCoercion(PointerCoercion::MutToConstPointer)
| mir::CastKind::PtrToPtr
mir::CastKind::PointerCoercion(
PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer,
) => {
bug!("{kind:?} is for borrowck, and should never appear in codegen");
}
mir::CastKind::PtrToPtr
if bx.cx().is_backend_scalar_pair(operand.layout) =>
{
if let OperandValue::Pair(data_ptr, meta) = operand.val {
Expand All @@ -477,9 +481,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
base::cast_to_dyn_star(bx, lldata, operand.layout, cast.ty, llextra);
OperandValue::Pair(lldata, llextra)
}
mir::CastKind::PointerCoercion(
PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer,
)
| mir::CastKind::IntToInt
| mir::CastKind::FloatToInt
| mir::CastKind::FloatToFloat
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_const_eval/src/interpret/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
CastKind::PointerCoercion(
PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer,
) => {
// These are NOPs, but can be wide pointers.
let v = self.read_immediate(src)?;
self.write_immediate(*v, dest)?;
bug!("{cast_kind:?} casts are for borrowck only, not runtime MIR");
}

CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer) => {
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ struct RemapLateBound<'a, 'tcx> {
}

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}

Expand Down Expand Up @@ -790,13 +790,13 @@ impl<'tcx, E> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx, E
where
E: 'tcx,
{
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.ocx.infcx.tcx
}

fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
if let ty::Alias(ty::Projection, proj) = ty.kind()
&& self.interner().is_impl_trait_in_trait(proj.def_id)
&& self.cx().is_impl_trait_in_trait(proj.def_id)
{
if let Some((ty, _)) = self.types.get(&proj.def_id) {
return *ty;
Expand All @@ -810,9 +810,9 @@ where
self.types.insert(proj.def_id, (infer_ty, proj.args));
// Recurse into bounds
for (pred, pred_span) in self
.interner()
.cx()
.explicit_item_bounds(proj.def_id)
.iter_instantiated_copied(self.interner(), proj.args)
.iter_instantiated_copied(self.cx(), proj.args)
{
let pred = pred.fold_with(self);
let pred = self.ocx.normalize(
Expand All @@ -822,7 +822,7 @@ where
);

self.ocx.register_obligation(traits::Obligation::new(
self.interner(),
self.cx(),
ObligationCause::new(
self.span,
self.body_id,
Expand Down Expand Up @@ -853,7 +853,7 @@ struct RemapHiddenTyRegions<'tcx> {
impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
type Error = ErrorGuaranteed;

fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}

Expand Down Expand Up @@ -2072,7 +2072,7 @@ struct ReplaceTy<'tcx> {
}

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceTy<'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ struct Anonymize<'tcx> {
}

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Anonymize<'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}

Expand Down
11 changes: 1 addition & 10 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,7 @@ where

let errors = wfcx.select_all_or_error();
if !errors.is_empty() {
let err = infcx.err_ctxt().report_fulfillment_errors(errors);
if tcx.dcx().has_errors().is_some() {
return Err(err);
} else {
// HACK(oli-obk): tests/ui/specialization/min_specialization/specialize_on_type_error.rs
// causes an delayed bug during normalization, without reporting an error, so we need
// to act as if no error happened, in order to let our callers continue and report an
// error later in check_impl_items_against_trait.
return Ok(());
}
return Err(infcx.err_ctxt().report_fulfillment_errors(errors));
}

debug!(?assumed_wf_types);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ struct TyVarReplacer<'cx, 'tcx> {
}

impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for TyVarReplacer<'cx, 'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.infcx.tcx
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/item_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct AssocTyToOpaque<'tcx> {
}

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTyToOpaque<'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
}

fn report_error(&self, p: impl Into<ty::GenericArg<'tcx>>) -> ErrorGuaranteed {
if let Some(guar) = self.fcx.dcx().has_errors() {
if let Some(guar) = self.fcx.tainted_by_errors() {
guar
} else {
self.fcx
Expand Down Expand Up @@ -847,7 +847,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
}

impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.fcx.tcx
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ struct Canonicalizer<'cx, 'tcx> {
}

impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}

Expand Down Expand Up @@ -773,7 +773,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
) -> ty::Region<'tcx> {
let var = self.canonical_var(info, r.into());
let br = ty::BoundRegion { var, kind: ty::BrAnon };
ty::Region::new_bound(self.interner(), self.binder_index, br)
ty::Region::new_bound(self.cx(), self.binder_index, br)
}

/// Given a type variable `ty_var` of the given kind, first check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ struct ClosureEraser<'tcx> {
}

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ClosureEraser<'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
}

impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.infcx.tcx
}

Expand All @@ -117,7 +117,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
| ty::RePlaceholder(..)
| ty::ReStatic
| ty::ReError(_)
| ty::ReErased => self.interner().lifetimes.re_erased,
| ty::ReErased => self.cx().lifetimes.re_erased,
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ struct InferenceLiteralEraser<'tcx> {
}

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for InferenceLiteralEraser<'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}

Expand Down Expand Up @@ -1859,7 +1859,7 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>(
}

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceParamAndInferWithPlaceholder<'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.tcx
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_infer/src/infer/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<'a, 'tcx> OpportunisticVarResolver<'a, 'tcx> {
}

impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for OpportunisticVarResolver<'a, 'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.infcx.tcx
}

Expand Down Expand Up @@ -66,7 +66,7 @@ impl<'a, 'tcx> OpportunisticRegionResolver<'a, 'tcx> {
}

impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for OpportunisticRegionResolver<'a, 'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.infcx.tcx
}

Expand All @@ -85,7 +85,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for OpportunisticRegionResolver<'a, 'tcx
.inner
.borrow_mut()
.unwrap_region_constraints()
.opportunistic_resolve_var(TypeFolder::interner(self), vid),
.opportunistic_resolve_var(TypeFolder::cx(self), vid),
_ => r,
}
}
Expand Down Expand Up @@ -121,7 +121,7 @@ struct FullTypeResolver<'a, 'tcx> {
impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
type Error = FixupError;

fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.infcx.tcx
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/snapshot/fudge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub struct InferenceFudger<'a, 'tcx> {
}

impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for InferenceFudger<'a, 'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.infcx.tcx
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ struct ReplaceLocalTypesWithInfer<'a, 'tcx, F: FnMut(DefId) -> bool> {
impl<'a, 'tcx, F: FnMut(DefId) -> bool> TypeFolder<TyCtxt<'tcx>>
for ReplaceLocalTypesWithInfer<'a, 'tcx, F>
{
fn interner(&self) -> TyCtxt<'tcx> {
fn cx(&self) -> TyCtxt<'tcx> {
self.infcx.tcx
}

Expand Down
13 changes: 11 additions & 2 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ pub enum AnalysisPhase {
/// * [`StatementKind::AscribeUserType`]
/// * [`StatementKind::Coverage`] with [`CoverageKind::BlockMarker`] or [`CoverageKind::SpanMarker`]
/// * [`Rvalue::Ref`] with `BorrowKind::Fake`
/// * [`CastKind::PointerCoercion`] with any of the following:
/// * [`PointerCoercion::ArrayToPointer`]
/// * [`PointerCoercion::MutToConstPointer`]
///
/// Furthermore, `Deref` projections must be the first projection within any place (if they
/// appear at all)
Expand Down Expand Up @@ -1284,8 +1287,7 @@ pub enum Rvalue<'tcx> {
///
/// This allows for casts from/to a variety of types.
///
/// **FIXME**: Document exactly which `CastKind`s allow which types of casts. Figure out why
/// `ArrayToPointer` and `MutToConstPointer` are special.
/// **FIXME**: Document exactly which `CastKind`s allow which types of casts.
Cast(CastKind, Operand<'tcx>, Ty<'tcx>),

/// * `Offset` has the same semantics as [`offset`](pointer::offset), except that the second
Expand Down Expand Up @@ -1365,6 +1367,13 @@ pub enum CastKind {
PointerWithExposedProvenance,
/// Pointer related casts that are done by coercions. Note that reference-to-raw-ptr casts are
/// translated into `&raw mut/const *r`, i.e., they are not actually casts.
///
/// The following are allowed in [`AnalysisPhase::Initial`] as they're needed for borrowck,
/// but after that are forbidden (including in all phases of runtime MIR):
/// * [`PointerCoercion::ArrayToPointer`]
/// * [`PointerCoercion::MutToConstPointer`]
///
/// Both are runtime nops, so should be [`CastKind::PtrToPtr`] instead in runtime MIR.
PointerCoercion(PointerCoercion),
/// Cast into a dyn* object.
DynStar,
Expand Down
Loading

0 comments on commit f2b449c

Please sign in to comment.