Skip to content

Commit 54c7434

Browse files
authored
Rollup merge of #74399 - mark-i-m:ty-err-4, r=eddyb
Move DelaySpanBugEmitted to ty::context This makes it even hard to abuse. r? @eddyb cc @LeSeulArtichaut as this will probably conflict with your PR :/
2 parents 3ef2244 + e1cd185 commit 54c7434

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

src/librustc_middle/ty/consts/kind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub enum ConstKind<'tcx> {
3434

3535
/// A placeholder for a const which could not be computed; this is
3636
/// propagated to avoid useless error messages.
37-
Error(ty::sty::DelaySpanBugEmitted),
37+
Error(ty::DelaySpanBugEmitted),
3838
}
3939

4040
#[cfg(target_arch = "x86_64")]

src/librustc_middle/ty/context.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ use std::mem;
6565
use std::ops::{Bound, Deref};
6666
use std::sync::Arc;
6767

68+
/// A type that is not publicly constructable. This prevents people from making `TyKind::Error`
69+
/// except through `tcx.err*()`, which are in this module.
70+
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
71+
#[derive(TyEncodable, TyDecodable, HashStable)]
72+
pub struct DelaySpanBugEmitted(());
73+
6874
type InternedSet<'tcx, T> = ShardedHashMap<Interned<'tcx, T>, ()>;
6975

7076
pub struct CtxtInterners<'tcx> {
@@ -1171,18 +1177,15 @@ impl<'tcx> TyCtxt<'tcx> {
11711177
#[track_caller]
11721178
pub fn ty_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Ty<'tcx> {
11731179
self.sess.delay_span_bug(span, msg);
1174-
self.mk_ty(Error(super::sty::DelaySpanBugEmitted(())))
1180+
self.mk_ty(Error(DelaySpanBugEmitted(())))
11751181
}
11761182

11771183
/// Like `err` but for constants.
11781184
#[track_caller]
11791185
pub fn const_error(self, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
11801186
self.sess
11811187
.delay_span_bug(DUMMY_SP, "ty::ConstKind::Error constructed but no error reported.");
1182-
self.mk_const(ty::Const {
1183-
val: ty::ConstKind::Error(super::sty::DelaySpanBugEmitted(())),
1184-
ty,
1185-
})
1188+
self.mk_const(ty::Const { val: ty::ConstKind::Error(DelaySpanBugEmitted(())), ty })
11861189
}
11871190

11881191
pub fn consider_optimizing<T: Fn() -> String>(&self, msg: T) -> bool {

src/librustc_middle/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ pub use self::binding::BindingMode::*;
7373

7474
pub use self::context::{tls, FreeRegionInfo, TyCtxt};
7575
pub use self::context::{
76-
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, ResolvedOpaqueTy,
77-
UserType, UserTypeAnnotationIndex,
76+
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations,
77+
DelaySpanBugEmitted, ResolvedOpaqueTy, UserType, UserTypeAnnotationIndex,
7878
};
7979
pub use self::context::{
8080
CtxtInterners, GeneratorInteriorTypeCause, GlobalCtxt, Lift, TypeckResults,

src/librustc_middle/ty/sty.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
1010
use crate::ty::{
1111
self, AdtDef, DefIdTree, Discr, Ty, TyCtxt, TypeFlags, TypeFoldable, WithConstness,
1212
};
13-
use crate::ty::{List, ParamEnv, TyS};
13+
use crate::ty::{DelaySpanBugEmitted, List, ParamEnv, TyS};
1414
use polonius_engine::Atom;
1515
use rustc_ast::ast;
1616
use rustc_data_structures::captures::Captures;
@@ -212,12 +212,6 @@ impl TyKind<'tcx> {
212212
}
213213
}
214214

215-
/// A type that is not publicly constructable. This prevents people from making `TyKind::Error`
216-
/// except through `tcx.err*()`.
217-
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
218-
#[derive(TyEncodable, TyDecodable, HashStable)]
219-
pub struct DelaySpanBugEmitted(pub(super) ());
220-
221215
// `TyKind` is used a lot. Make sure it doesn't unintentionally get bigger.
222216
#[cfg(target_arch = "x86_64")]
223217
static_assert_size!(TyKind<'_>, 24);

0 commit comments

Comments
 (0)