Skip to content

Commit ffb4210

Browse files
committed
Swathes of errors solved
1 parent 3ae36a8 commit ffb4210

File tree

22 files changed

+81
-32
lines changed

22 files changed

+81
-32
lines changed

compiler/rustc_middle/src/middle/deduced_param_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_macros::{Decodable, Encodable, HashStable};
22

3+
use crate::ty::util::TyUtil;
34
use crate::ty::{Ty, TyCtxt, TypingEnv};
45

56
/// Summarizes how a parameter (a return place or an argument) is used inside a MIR body.

compiler/rustc_middle/src/mir/interpret/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub use self::value::Scalar;
4545
use crate::mir;
4646
use crate::ty::codec::{TyDecoder, TyEncoder};
4747
use crate::ty::print::with_no_trimmed_paths;
48+
use crate::ty::util::TyUtil;
4849
use crate::ty::{self, Instance, Ty, TyCtxt};
4950

5051
/// Uniquely identifies one of the following:

compiler/rustc_middle/src/query/keys.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_data_structures::stable_hasher::HashStable;
99
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId};
1010
use rustc_hir::hir_id::OwnerId;
1111
use rustc_span::{DUMMY_SP, Ident, LocalExpnId, Span, Symbol};
12-
use rustc_type_ir::inherent::IntoKind;
1312

1413
use crate::dep_graph::DepNodeIndex;
1514
use crate::ich::StableHashingContext;
@@ -270,7 +269,7 @@ impl<'tcx> QueryKey for Ty<'tcx> {
270269
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> {
271270
match self.kind() {
272271
ty::Adt(adt, _) => Some(adt.did()),
273-
ty::Coroutine(def_id, ..) => Some(def_id),
272+
ty::Coroutine(def_id, ..) => Some(*def_id),
274273
_ => None,
275274
}
276275
}

compiler/rustc_middle/src/query/on_disk_cache.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_span::{
2121
BlobDecoder, BytePos, ByteSymbol, CachingSourceMapView, ExpnData, ExpnHash, RelativeBytePos,
2222
SourceFile, Span, SpanDecoder, SpanEncoder, Spanned, StableSourceFileId, Symbol,
2323
};
24+
use rustc_type_ir::{TyDecoder, TyEncoder};
2425

2526
use crate::dep_graph::{DepNodeIndex, QuerySideEffect, SerializedDepNodeIndex};
2627
use crate::mir::interpret::{AllocDecodingSession, AllocDecodingState};

compiler/rustc_middle/src/thir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use crate::mir::{self, AssignOp, BinOp, BorrowKind, FakeReadCause, UnOp};
3131
use crate::thir::visit::for_each_immediate_subpat;
3232
use crate::ty::adjustment::PointerCoercion;
3333
use crate::ty::layout::IntegerExt;
34+
use crate::ty::util::TyUtil;
3435
use crate::ty::{
3536
self, AdtDef, CanonicalUserType, CanonicalUserTypeAnnotation, FnSig, GenericArgsRef, Ty,
3637
TyCtxt, UpvarArgs,

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ impl<'tcx> AdtDef<'tcx> {
207207
self.0.0.repr
208208
}
209209

210+
/// Asserts this is a struct or union and returns its unique variant.
211+
pub fn non_enum_variant(self) -> &'tcx VariantDef {
212+
assert!(self.is_struct() || self.is_union());
213+
self.variant(FIRST_VARIANT)
214+
}
215+
210216
pub fn field_representing_type_info(
211217
self,
212218
tcx: TyCtxt<'tcx>,
@@ -336,8 +342,7 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
336342

337343
/// Asserts this is a struct or union and returns its unique variant.
338344
fn non_enum_variant(self) -> &'tcx VariantDef {
339-
assert!(self.is_struct() || self.is_union());
340-
self.variant(FIRST_VARIANT)
345+
self.non_enum_variant()
341346
}
342347

343348
fn repr_is_simd(self) -> bool {

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_macros::HashStable;
66
use rustc_type_ir::walk::TypeWalker;
77
use rustc_type_ir::{self as ir, TypeFlags, WithCachedTypeInfo};
88

9+
use crate::mir::ConstValue;
910
use crate::mir::interpret::Scalar;
1011
use crate::ty::{self, Ty, TyCtxt};
1112

@@ -215,7 +216,7 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
215216
}
216217

217218
fn try_to_target_usize(&self, tcx: TyCtxt<'tcx>) -> Option<u64> {
218-
Some(self.try_to_scalar_int()?.to_target_usize(tcx))
219+
self.try_to_value()?.try_to_target_usize(tcx)
219220
}
220221

221222
#[inline]

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,9 @@ impl<'tcx> TyCtxt<'tcx> {
22982298
GenericParamDefKind::Lifetime => {
22992299
ty::Region::new_early_param(self, param.to_early_bound_region_data()).into()
23002300
}
2301-
GenericParamDefKind::Type { .. } => Ty::new_param(self, param.index, param.name).into(),
2301+
GenericParamDefKind::Type { .. } => {
2302+
Ty::new_param(self, ty::ParamTy::new(param.index, param.name)).into()
2303+
}
23022304
GenericParamDefKind::Const { .. } => {
23032305
ty::Const::new_param(self, ParamConst { index: param.index, name: param.name })
23042306
.into()

compiler/rustc_middle/src/ty/context/impl_interner.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
312312
}
313313
}
314314

315-
/// Given the `DefId`, returns the `DefId` of the innermost item that
316-
/// has its own type-checking context or "inference environment".
317-
///
318-
/// For example, a closure has its own `DefId`, but it is type-checked
319-
/// with the containing item. Therefore, when we fetch the `typeck` of the closure,
320-
/// for example, we really wind up fetching the `typeck` of the enclosing fn item.
321315
fn typeck_root_def_id(self, def_id: DefId) -> DefId {
322-
let mut def_id = def_id;
323-
while self.is_typeck_child(def_id) {
324-
def_id = self.parent(def_id);
325-
}
326-
def_id
316+
self.typeck_root_def_id(def_id)
327317
}
328318

329319
fn debug_assert_new_dynamic_compatible(
@@ -909,11 +899,11 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
909899
}
910900

911901
fn get_anon_bound_ty(self, id: usize) -> Option<Vec<Ty<'tcx>>> {
912-
self.types.anon_bound_tys.get(id).copied()
902+
self.types.anon_bound_tys.get(id).cloned()
913903
}
914904

915905
fn get_anon_canonical_bound_ty(self, id: usize) -> Option<Ty<'tcx>> {
916-
self.types.anon_canonical_bound_tys.get(id.as_usize()).copied()
906+
self.types.anon_canonical_bound_tys.get(id).copied()
917907
}
918908

919909
fn get_generic_args_for_item(
@@ -1047,6 +1037,19 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
10471037
let context_ty = Ty::new_adt(self, context_adt_ref, context_args);
10481038
Ty::new_mut_ref(self, self.lifetimes.re_erased, context_ty)
10491039
}
1040+
1041+
fn new_fn_def(
1042+
self,
1043+
def_id: DefId,
1044+
args: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
1045+
) -> Ty<'tcx> {
1046+
debug_assert_matches!(
1047+
self.def_kind(def_id),
1048+
DefKind::AssocFn | DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn)
1049+
);
1050+
let args = self.check_and_mk_args(def_id, args);
1051+
Ty::new(self, ty::FnDef(def_id, args))
1052+
}
10501053
}
10511054

10521055
/// Defines trivial conversion functions between the main [`LangItem`] enum,

compiler/rustc_middle/src/ty/diagnostics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_hir::{self as hir, AmbigArg, LangItem, PredicateOrigin, WherePredicate
1313
use rustc_span::{BytePos, Span};
1414
use rustc_type_ir::TyKind::*;
1515

16+
use crate::ty::util::TyUtil;
1617
use crate::ty::{
1718
self, AliasTy, Const, ConstKind, FallibleTypeFolder, InferConst, InferTy, Instance, Opaque,
1819
PolyTraitPredicate, Projection, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable,

0 commit comments

Comments
 (0)