@@ -57,57 +57,6 @@ pub(crate) fn provide(providers: &mut ty::query::Providers) {
57
57
ty:: query:: Providers { inhabited_predicate_adt, inhabited_predicate_type, ..* providers } ;
58
58
}
59
59
60
- impl < ' tcx > TyCtxt < ' tcx > {
61
- /// Checks whether a type is visibly uninhabited from a particular module.
62
- ///
63
- /// # Example
64
- /// ```
65
- /// #![feature(never_type)]
66
- /// # fn main() {}
67
- /// enum Void {}
68
- /// mod a {
69
- /// pub mod b {
70
- /// pub struct SecretlyUninhabited {
71
- /// _priv: !,
72
- /// }
73
- /// }
74
- /// }
75
- ///
76
- /// mod c {
77
- /// use super::Void;
78
- /// pub struct AlsoSecretlyUninhabited {
79
- /// _priv: Void,
80
- /// }
81
- /// mod d {
82
- /// }
83
- /// }
84
- ///
85
- /// struct Foo {
86
- /// x: a::b::SecretlyUninhabited,
87
- /// y: c::AlsoSecretlyUninhabited,
88
- /// }
89
- /// ```
90
- /// In this code, the type `Foo` will only be visibly uninhabited inside the
91
- /// modules b, c and d. This effects pattern-matching on `Foo` or types that
92
- /// contain `Foo`.
93
- ///
94
- /// # Example
95
- /// ```ignore (illustrative)
96
- /// let foo_result: Result<T, Foo> = ... ;
97
- /// let Ok(t) = foo_result;
98
- /// ```
99
- /// This code should only compile in modules where the uninhabitedness of Foo is
100
- /// visible.
101
- pub fn is_ty_uninhabited_from (
102
- self ,
103
- module : DefId ,
104
- ty : Ty < ' tcx > ,
105
- param_env : ty:: ParamEnv < ' tcx > ,
106
- ) -> bool {
107
- !ty. inhabited_predicate ( self ) . apply ( self , param_env, module)
108
- }
109
- }
110
-
111
60
/// Returns an `InhabitedPredicate` that is generic over type parameters and
112
61
/// requires calling [`InhabitedPredicate::subst`]
113
62
fn inhabited_predicate_adt ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> InhabitedPredicate < ' _ > {
@@ -171,6 +120,55 @@ impl<'tcx> Ty<'tcx> {
171
120
_ => InhabitedPredicate :: True ,
172
121
}
173
122
}
123
+
124
+ /// Checks whether a type is visibly uninhabited from a particular module.
125
+ ///
126
+ /// # Example
127
+ /// ```
128
+ /// #![feature(never_type)]
129
+ /// # fn main() {}
130
+ /// enum Void {}
131
+ /// mod a {
132
+ /// pub mod b {
133
+ /// pub struct SecretlyUninhabited {
134
+ /// _priv: !,
135
+ /// }
136
+ /// }
137
+ /// }
138
+ ///
139
+ /// mod c {
140
+ /// use super::Void;
141
+ /// pub struct AlsoSecretlyUninhabited {
142
+ /// _priv: Void,
143
+ /// }
144
+ /// mod d {
145
+ /// }
146
+ /// }
147
+ ///
148
+ /// struct Foo {
149
+ /// x: a::b::SecretlyUninhabited,
150
+ /// y: c::AlsoSecretlyUninhabited,
151
+ /// }
152
+ /// ```
153
+ /// In this code, the type `Foo` will only be visibly uninhabited inside the
154
+ /// modules b, c and d. This effects pattern-matching on `Foo` or types that
155
+ /// contain `Foo`.
156
+ ///
157
+ /// # Example
158
+ /// ```ignore (illustrative)
159
+ /// let foo_result: Result<T, Foo> = ... ;
160
+ /// let Ok(t) = foo_result;
161
+ /// ```
162
+ /// This code should only compile in modules where the uninhabitedness of Foo is
163
+ /// visible.
164
+ pub fn is_inhabited_from (
165
+ self ,
166
+ tcx : TyCtxt < ' tcx > ,
167
+ module : DefId ,
168
+ param_env : ty:: ParamEnv < ' tcx > ,
169
+ ) -> bool {
170
+ self . inhabited_predicate ( tcx) . apply ( tcx, param_env, module)
171
+ }
174
172
}
175
173
176
174
/// N.B. this query should only be called through `Ty::inhabited_predicate`
0 commit comments