Skip to content

Commit 1e5ec0a

Browse files
Lift TraitRef into rustc_type_ir
1 parent 5e606c0 commit 1e5ec0a

File tree

51 files changed

+445
-241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+445
-241
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_middle::mir::{
2222
Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator,
2323
TerminatorKind, VarBindingForm,
2424
};
25+
use rustc_middle::ty::print::PrintTraitRefExt as _;
2526
use rustc_middle::ty::{
2627
self, suggest_constraining_type_params, PredicateKind, ToPredicate, Ty, TyCtxt,
2728
TypeSuperVisitable, TypeVisitor,

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,11 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
532532

533533
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
534534
let tcx = self.tcx();
535-
let trait_ref =
536-
ty::TraitRef::from_lang_item(tcx, LangItem::Copy, self.last_span, [place_ty.ty]);
535+
let trait_ref = ty::TraitRef::new(
536+
tcx,
537+
tcx.require_lang_item(LangItem::Copy, Some(self.last_span)),
538+
[place_ty.ty],
539+
);
537540

538541
// To have a `Copy` operand, the type `T` of the
539542
// value must be `Copy`. Note that we prove that `T: Copy`,
@@ -1273,10 +1276,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12731276

12741277
self.check_rvalue(body, rv, location);
12751278
if !self.unsized_feature_enabled() {
1276-
let trait_ref = ty::TraitRef::from_lang_item(
1279+
let trait_ref = ty::TraitRef::new(
12771280
tcx,
1278-
LangItem::Sized,
1279-
self.last_span,
1281+
tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
12801282
[place_ty],
12811283
);
12821284
self.prove_trait_ref(
@@ -1925,8 +1927,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19251927
Operand::Move(place) => {
19261928
// Make sure that repeated elements implement `Copy`.
19271929
let ty = place.ty(body, tcx).ty;
1928-
let trait_ref =
1929-
ty::TraitRef::from_lang_item(tcx, LangItem::Copy, span, [ty]);
1930+
let trait_ref = ty::TraitRef::new(
1931+
tcx,
1932+
tcx.require_lang_item(LangItem::Copy, Some(span)),
1933+
[ty],
1934+
);
19301935

19311936
self.prove_trait_ref(
19321937
trait_ref,
@@ -1939,7 +1944,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19391944
}
19401945

19411946
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
1942-
let trait_ref = ty::TraitRef::from_lang_item(tcx, LangItem::Sized, span, [ty]);
1947+
let trait_ref = ty::TraitRef::new(
1948+
tcx,
1949+
tcx.require_lang_item(LangItem::Sized, Some(span)),
1950+
[ty],
1951+
);
19431952

19441953
self.prove_trait_ref(
19451954
trait_ref,
@@ -1952,7 +1961,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19521961
Rvalue::ShallowInitBox(operand, ty) => {
19531962
self.check_operand(operand, location);
19541963

1955-
let trait_ref = ty::TraitRef::from_lang_item(tcx, LangItem::Sized, span, [*ty]);
1964+
let trait_ref = ty::TraitRef::new(
1965+
tcx,
1966+
tcx.require_lang_item(LangItem::Sized, Some(span)),
1967+
[*ty],
1968+
);
19561969

19571970
self.prove_trait_ref(
19581971
trait_ref,
@@ -2050,10 +2063,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20502063

20512064
CastKind::PointerCoercion(PointerCoercion::Unsize) => {
20522065
let &ty = ty;
2053-
let trait_ref = ty::TraitRef::from_lang_item(
2066+
let trait_ref = ty::TraitRef::new(
20542067
tcx,
2055-
LangItem::CoerceUnsized,
2056-
span,
2068+
tcx.require_lang_item(LangItem::CoerceUnsized, Some(span)),
20572069
[op.ty(body, tcx), ty],
20582070
);
20592071

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::def_id::DefId;
88
use rustc_infer::infer::TyCtxtInferExt;
99
use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
1010
use rustc_middle::mir::{self, CallSource};
11-
use rustc_middle::ty::print::with_no_trimmed_paths;
11+
use rustc_middle::ty::print::{with_no_trimmed_paths, PrintTraitRefExt as _};
1212
use rustc_middle::ty::{
1313
self, suggest_constraining_type_param, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef,
1414
Param, TraitRef, Ty,

compiler/rustc_errors/src/diagnostic_impls.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ into_diag_arg_using_display!(
9494
ErrCode,
9595
);
9696

97+
impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::TraitRef<I> {
98+
fn into_diag_arg(self) -> DiagArgValue {
99+
self.to_string().into_diag_arg()
100+
}
101+
}
102+
97103
into_diag_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize);
98104

99105
impl IntoDiagArg for bool {

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_infer::infer::TyCtxtInferExt;
1414
use rustc_infer::infer::{self, RegionResolutionError};
1515
use rustc_infer::traits::Obligation;
1616
use rustc_middle::ty::adjustment::CoerceUnsizedInfo;
17+
use rustc_middle::ty::print::PrintTraitRefExt as _;
1718
use rustc_middle::ty::{self, suggest_constraining_type_params, Ty, TyCtxt, TypeVisitableExt};
1819
use rustc_span::{Span, DUMMY_SP};
1920
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;

compiler/rustc_hir_analysis/src/coherence/unsafety.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
use rustc_errors::{codes::*, struct_span_code_err};
55
use rustc_hir::Unsafety;
6+
use rustc_middle::ty::print::PrintTraitRefExt as _;
67
use rustc_middle::ty::{ImplPolarity::*, ImplTraitHeader, TraitDef, TyCtxt};
78
use rustc_span::def_id::LocalDefId;
89
use rustc_span::ErrorGuaranteed;

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_errors::{codes::*, struct_span_code_err};
55
use rustc_hir as hir;
66
use rustc_hir::def::{DefKind, Res};
77
use rustc_hir::def_id::{DefId, LocalDefId};
8+
use rustc_middle::ty::print::PrintTraitRefExt as _;
89
use rustc_middle::ty::{self as ty, IsSuggestable, Ty, TyCtxt};
910
use rustc_span::symbol::Ident;
1011
use rustc_span::{ErrorGuaranteed, Span, Symbol};

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_hir::def::{DefKind, Res};
1717
use rustc_hir::def_id::{DefId, LocalDefId};
1818
use rustc_infer::traits::FulfillmentError;
1919
use rustc_middle::query::Key;
20+
use rustc_middle::ty::print::PrintTraitRefExt as _;
2021
use rustc_middle::ty::GenericParamDefKind;
2122
use rustc_middle::ty::{self, suggest_constraining_type_param};
2223
use rustc_middle::ty::{AdtDef, Ty, TyCtxt, TypeVisitableExt};

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
758758
self.tcx,
759759
self.cause.clone(),
760760
self.param_env,
761-
ty::TraitRef::from_lang_item(
761+
ty::TraitRef::new(
762762
self.tcx,
763-
hir::LangItem::PointerLike,
764-
self.cause.span,
763+
self.tcx.require_lang_item(hir::LangItem::PointerLike, Some(self.cause.span)),
765764
[a],
766765
),
767766
));

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ use rustc_hir::{ExprKind, Node, QPath};
2525
use rustc_infer::infer::{self, RegionVariableOrigin};
2626
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
2727
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
28-
use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths};
28+
use rustc_middle::ty::print::{
29+
with_crate_prefix, with_forced_trimmed_paths, PrintTraitRefExt as _,
30+
};
2931
use rustc_middle::ty::IsSuggestable;
3032
use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt, TypeVisitableExt};
3133
use rustc_span::def_id::DefIdSet;

0 commit comments

Comments
 (0)