Skip to content

Commit c8a5acd

Browse files
authored
Rollup merge of rust-lang#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 c531545 + e1cd185 commit c8a5acd

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
@@ -64,6 +64,12 @@ use std::mem;
6464
use std::ops::{Bound, Deref};
6565
use std::sync::Arc;
6666

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

6975
pub struct CtxtInterners<'tcx> {
@@ -1170,18 +1176,15 @@ impl<'tcx> TyCtxt<'tcx> {
11701176
#[track_caller]
11711177
pub fn ty_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Ty<'tcx> {
11721178
self.sess.delay_span_bug(span, msg);
1173-
self.mk_ty(Error(super::sty::DelaySpanBugEmitted(())))
1179+
self.mk_ty(Error(DelaySpanBugEmitted(())))
11741180
}
11751181

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

11871190
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)