Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_gcc/src/intrinsic/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(

match *in_elem.kind() {
ty::RawPtr(p_ty, _) => {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, &ObligationCause::dummy(), |ty| {
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
});
require!(
Expand All @@ -552,7 +552,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
}
match *out_elem.kind() {
ty::RawPtr(p_ty, _) => {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, &ObligationCause::dummy(), |ty| {
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
});
require!(
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_hir::find_attr;
use rustc_middle::mir::BinOp;
use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, LayoutOf};
use rustc_middle::ty::offload_meta::OffloadMetadata;
use rustc_middle::ty::{self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv};
Expand Down Expand Up @@ -2561,7 +2562,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(

match in_elem.kind() {
ty::RawPtr(p_ty, _) => {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, &ObligationCause::dummy(), |ty| {
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
});
require!(
Expand All @@ -2575,7 +2576,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
}
match out_elem.kind() {
ty::RawPtr(p_ty, _) => {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, &ObligationCause::dummy(), |ty| {
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
});
require!(
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_data_structures::assert_matches;
use rustc_errors::msg;
use rustc_hir::def_id::DefId;
use rustc_hir::find_attr;
use rustc_infer::traits::ObligationCause;
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
use rustc_middle::ty::{self, AdtDef, Instance, Ty, VariantDef};
use rustc_middle::{bug, mir, span_bug};
Expand Down Expand Up @@ -221,7 +222,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// to fields, which can yield non-normalized types. So we need to provide a
// normalization function.
let normalize = |ty| self.tcx.normalize_erasing_regions(self.typing_env, ty);
ty.ptr_metadata_ty(*self.tcx, normalize)
ty.ptr_metadata_ty(*self.tcx, &ObligationCause::dummy(), normalize)
};
return interp_ok(meta_ty(caller) == meta_ty(callee));
}
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,9 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
if !remapped_types.contains_key(assoc_item) {
remapped_types.insert(
*assoc_item,
ty::EarlyBinder::bind(Ty::new_error_with_message(
tcx,
return_span,
"missing synthetic item for RPITIT",
)),
ty::EarlyBinder::bind(
tcx.new_error_with_message(return_span, "missing synthetic item for RPITIT"),
),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub(crate) fn check_intrinsic_type(
{
Ty::new_param(tcx, n, name)
} else {
Ty::new_error_with_message(tcx, span, "expected param")
tcx.new_error_with_message(span, "expected param")
}
};

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
if !self.tcx.dcx().has_stashed_diagnostic(span, StashKey::ItemNoType) {
self.report_placeholder_type_error(vec![span], vec![]);
}
Ty::new_error_with_message(self.tcx(), span, "bad placeholder type")
self.tcx().new_error_with_message(span, "bad placeholder type")
}

fn ct_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> {
Expand Down Expand Up @@ -539,7 +539,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
self.lowerer().suggest_trait_fn_ty_for_impl_fn_infer(hir_id, Some(i))
{
infer_replacements.push((a.span, suggested_ty.to_string()));
return Ty::new_error_with_message(tcx, a.span, suggested_ty.to_string());
return tcx.new_error_with_message(a.span, suggested_ty.to_string());
}

self.lowerer().lower_ty(a)
Expand All @@ -553,7 +553,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
self.lowerer().suggest_trait_fn_ty_for_impl_fn_infer(hir_id, None)
{
infer_replacements.push((output.span, suggested_ty.to_string()));
Ty::new_error_with_message(tcx, output.span, suggested_ty.to_string())
tcx.new_error_with_message(output.span, suggested_ty.to_string())
} else {
self.lower_ty(output)
}
Expand Down
12 changes: 4 additions & 8 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
return map[&trait_item_def_id];
}
Err(_) => {
return ty::EarlyBinder::bind(Ty::new_error_with_message(
tcx,
return ty::EarlyBinder::bind(tcx.new_error_with_message(
DUMMY_SP,
"Could not collect return position impl trait in trait tys",
));
Expand Down Expand Up @@ -366,8 +365,7 @@ fn anon_const_type_of<'tcx>(icx: &ItemCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx
tcx.type_of(field_def_id).instantiate_identity()
}

_ => Ty::new_error_with_message(
tcx,
_ => tcx.new_error_with_message(
span,
format!("unexpected anon const parent in type_of(): {parent_node:?}"),
),
Expand Down Expand Up @@ -402,8 +400,7 @@ fn const_arg_anon_type_of<'tcx>(icx: &ItemCtxt<'tcx>, arg_hir_id: HirId, span: S

// This is not a `bug!` as const arguments in path segments that did not resolve to anything
// will result in `type_of` never being fed.
_ => Ty::new_error_with_message(
tcx,
_ => tcx.new_error_with_message(
span,
"`type_of` called on const argument's anon const before the const argument was lowered",
),
Expand All @@ -427,8 +424,7 @@ fn infer_placeholder_type<'tcx>(
if let Some(trait_item_def_id) = tcx.trait_item_of(def_id.to_def_id()) {
tcx.type_of(trait_item_def_id).instantiate_identity()
} else {
Ty::new_error_with_message(
tcx,
tcx.new_error_with_message(
ty_span,
"constant with `type const` requires an explicit type",
)
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let item_def_id = match path.res {
Res::Def(DefKind::AssocFn, item_def_id) => item_def_id,
Res::Err => {
return Ty::new_error_with_message(
tcx,
hir_ty.span,
"failed to resolve RTN",
);
return tcx.new_error_with_message(hir_ty.span, "failed to resolve RTN");
}
_ => bug!("only expected method resolution for fully qualified RTN"),
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
self.lowerer.ty_infer(Some(param), self.span).into()
} else {
// We've already errored above about the mismatch.
Ty::new_misc_error(tcx).into()
tcx.new_misc_error().into()
}
}
GenericParamDefKind::Const { has_default, .. } => {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
})?
}
ty::Alias(ty::Projection, _) => {
return Some(Ty::new_error_with_message(
self.tcx,
return Some(self.tcx.new_error_with_message(
closure_span,
"this projection should have been projected to an opaque type",
));
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(ctxt) => ctxt.coerce.as_ref().map(|coerce| coerce.expected_ty()),
None => {
// Avoid ICE when `break` is inside a closure (#65383).
return Ty::new_error_with_message(
tcx,
return tcx.new_error_with_message(
expr.span,
"break was outside loop, but no error was emitted",
);
Expand Down Expand Up @@ -762,8 +761,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut enclosing_breakables = self.enclosing_breakables.borrow_mut();
let Some(ctxt) = enclosing_breakables.opt_find_breakable(target_id) else {
// Avoid ICE when `break` is inside a closure (#65383).
return Ty::new_error_with_message(
tcx,
return tcx.new_error_with_message(
expr.span,
"break was outside loop, but no error was emitted",
);
Expand Down Expand Up @@ -823,8 +821,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// this can only happen if the `break` was not
// inside a loop at all, which is caught by the
// loop-checking pass.
let err = Ty::new_error_with_message(
self.tcx,
let err = self.tcx.new_error_with_message(
expr.span,
"break was outside loop, but no error was emitted",
);
Expand Down Expand Up @@ -871,7 +868,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
} else {
// There was an error; make type-check fail.
Ty::new_misc_error(self.tcx)
self.tcx.new_misc_error()
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2959,7 +2959,7 @@ impl<'a, 'b, 'tcx> ArgsCtxt<'a, 'b, 'tcx> {
.typeck_results
.borrow()
.expr_ty_adjusted_opt(expr)
.unwrap_or_else(|| Ty::new_misc_error(self.call_ctxt.fn_ctxt.tcx));
.unwrap_or_else(|| self.call_ctxt.fn_ctxt.tcx.new_misc_error());
(
self.call_ctxt.fn_ctxt.resolve_vars_if_possible(ty),
self.normalize_span(expr.span),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/inline_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
let ty = self.fcx.typeck_results.borrow().expr_ty_adjusted(expr);
let ty = self.fcx.try_structurally_resolve_type(expr.span, ty);
if ty.has_non_region_infer() {
Ty::new_misc_error(self.tcx())
self.tcx().new_misc_error()
} else {
self.tcx().erase_and_anonymize_regions(ty)
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_typeck/src/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ fn check_transmute<'tcx>(
if let Ok(ty) = tcx.try_normalize_erasing_regions(typing_env, ty) {
ty
} else {
Ty::new_error_with_message(
tcx,
tcx.new_error_with_message(
span(),
format!("tried to normalize non-wf type {ty:#?} in check_transmute"),
)
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// time writing the results into the various typeck results.
let mut autoderef = self.autoderef(self.call_expr.span, unadjusted_self_ty);
let Some((mut target, n)) = autoderef.nth(pick.autoderefs) else {
return Ty::new_error_with_message(
self.tcx,
DUMMY_SP,
format!("failed autoderef {}", pick.autoderefs),
);
return self
.tcx
.new_error_with_message(DUMMY_SP, format!("failed autoderef {}", pick.autoderefs));
};
assert_eq!(n, pick.autoderefs);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.typeck_results
.borrow()
.expr_ty_adjusted_opt(rcvr_expr)
.unwrap_or(Ty::new_misc_error(self.tcx)),
.unwrap_or(self.new_misc_error()),
);

let Ok(candidates) = self.probe_for_name_many(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
// error types are considered "builtin"
Err(_) if lhs_ty.references_error() || rhs_ty.references_error() => {
Ty::new_misc_error(self.tcx)
self.tcx.new_misc_error()
}
Err(errors) => {
let (_, trait_def_id) = lang_item_for_binop(self.tcx, op);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
demand_eqtype(&mut rhs, lhs);

if let (Some((true, ..)), _) | (_, Some((true, ..))) = (lhs, rhs) {
return Ty::new_misc_error(self.tcx);
return self.tcx.new_misc_error();
}

// Find the unified type and check if it's of numeric or char type again.
Expand Down Expand Up @@ -2053,7 +2053,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
})
.unwrap_or_else(|| {
inexistent_fields.push(field);
Ty::new_misc_error(tcx)
tcx.new_misc_error()
})
}
};
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_lint/src/gpukernel_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::iter;

use rustc_abi::ExternAbi;
use rustc_hir::{self as hir, find_attr};
use rustc_infer::traits::ObligationCause;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable};
use rustc_session::{declare_lint, declare_lint_pass};
use rustc_span::Span;
Expand Down Expand Up @@ -109,7 +110,10 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for CheckGpuKernelTypes<'tcx> {
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) => {}
// Thin pointers are allowed but fat pointers with metadata are not
ty::RawPtr(_, _) => {
if !ty.pointee_metadata_ty_or_projection(self.tcx).is_unit() {
if !ty
.pointee_metadata_ty_or_projection(&ObligationCause::dummy(), self.tcx)
.is_unit()
{
self.has_invalid = true;
}
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ impl<'a> BlobDecodeContext<'a> {
}

impl<'a, 'tcx> TyDecoder<'tcx> for MetadataDecodeContext<'a, 'tcx> {
type Interner = TyCtxt<'tcx>;

const CLEAR_CROSS_CRATE: bool = true;

#[inline]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for [u8] {
}

impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
type Interner = TyCtxt<'tcx>;

const CLEAR_CROSS_CRATE: bool = true;

fn position(&self) -> usize {
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_middle/src/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_hir::def_id::DefId;
use rustc_span::Span;
use rustc_target::spec::PanicStrategy;

use crate::ty::{self, TyCtxt};
use crate::ty::{self, AdtDef, TyCtxt};

impl<'tcx> TyCtxt<'tcx> {
/// Returns the `DefId` for a given `LangItem`.
Expand All @@ -27,6 +27,10 @@ impl<'tcx> TyCtxt<'tcx> {
self.lang_items().get(lang_item) == Some(def_id)
}

pub fn is_c_void(self, adt: ty::AdtDef<'tcx>) -> bool {
self.is_lang_item(adt.did(), LangItem::CVoid)
}

pub fn as_lang_item(self, def_id: DefId) -> Option<LangItem> {
self.lang_items().from_def_id(def_id)
}
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/mir/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ impl ConstValue {
self.try_to_scalar_int()?.try_into().ok()
}

pub fn try_to_target_usize(&self, tcx: TyCtxt<'_>) -> Option<u64> {
Some(self.try_to_scalar_int()?.to_target_usize(tcx))
}

pub fn try_to_bits_for_ty<'tcx>(
&self,
tcx: TyCtxt<'tcx>,
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/mir/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tracing::{debug, instrument};

use super::interpret::GlobalAlloc;
use super::*;
use crate::traits::ObligationCause;
use crate::ty::CoroutineArgsExt;

///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -870,7 +871,9 @@ impl<'tcx> UnOp {
pub fn ty(&self, tcx: TyCtxt<'tcx>, arg_ty: Ty<'tcx>) -> Ty<'tcx> {
match self {
UnOp::Not | UnOp::Neg => arg_ty,
UnOp::PtrMetadata => arg_ty.pointee_metadata_ty_or_projection(tcx),
UnOp::PtrMetadata => {
arg_ty.pointee_metadata_ty_or_projection(&ObligationCause::dummy(), tcx)
}
}
}
}
Expand Down
Loading
Loading