1use std::fmt::Debug;
7use std::hash::Hash;
8
9use rustc_ast_ir::Mutability;
10
11use crate::elaborate::Elaboratable;
12use crate::fold::{TypeFoldable, TypeSuperFoldable};
13use crate::relate::Relate;
14use crate::solve::{AdtDestructorKind, SizedTraitKind};
15use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable};
16use crate::{
17 self as ty, ClauseKind, CollectAndApply, FieldInfo, Interner, PredicateKind, Region, UpcastFrom,
18};
19
20#[rust_analyzer::prefer_underscore_import]
21pub trait Ty<I: Interner<Ty = Self>>:
22 Copy
23 + Debug
24 + Hash
25 + Eq
26 + Into<I::GenericArg>
27 + Into<I::Term>
28 + IntoKind<Kind = ty::TyKind<I>>
29 + TypeSuperVisitable<I>
30 + TypeSuperFoldable<I>
31 + Relate<I>
32 + Flags
33{
34 fn new_unit(interner: I) -> Self;
35
36 fn new_bool(interner: I) -> Self;
37
38 fn new_u8(interner: I) -> Self;
39
40 fn new_usize(interner: I) -> Self;
41
42 fn new_infer(interner: I, var: ty::InferTy) -> Self;
43
44 fn new_var(interner: I, var: ty::TyVid) -> Self;
45
46 fn new_param(interner: I, param: I::ParamTy) -> Self;
47
48 fn new_placeholder(interner: I, param: ty::PlaceholderType<I>) -> Self;
49
50 fn new_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundTy<I>) -> Self;
51
52 fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self;
53
54 fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self;
55
56 fn new_alias(interner: I, is_rigid: ty::IsRigid, alias_ty: ty::AliasTy<I>) -> Self;
57
58 fn new_projection_from_args(
59 interner: I,
60 is_rigid: ty::IsRigid,
61 def_id: I::TraitAssocTyId,
62 args: I::GenericArgs,
63 ) -> Self {
64 Self::new_alias(
65 interner,
66 is_rigid,
67 ty::AliasTy::new_from_args(interner, ty::AliasTyKind::Projection { def_id }, args),
68 )
69 }
70
71 fn new_projection(
72 interner: I,
73 is_rigid: ty::IsRigid,
74 def_id: I::TraitAssocTyId,
75 args: impl IntoIterator<Item: Into<I::GenericArg>>,
76 ) -> Self {
77 Self::new_alias(
78 interner,
79 is_rigid,
80 ty::AliasTy::new(interner, ty::AliasTyKind::Projection { def_id }, args),
81 )
82 }
83
84 fn new_error(interner: I, guar: I::ErrorGuaranteed) -> Self;
85
86 fn new_adt(interner: I, adt_def: I::AdtDef, args: I::GenericArgs) -> Self;
87
88 fn new_foreign(interner: I, def_id: I::ForeignId) -> Self;
89
90 fn new_dynamic(interner: I, preds: I::BoundExistentialPredicates, region: Region<I>) -> Self;
91
92 fn new_coroutine(interner: I, def_id: I::CoroutineId, args: I::GenericArgs) -> Self;
93
94 fn new_coroutine_closure(
95 interner: I,
96 def_id: I::CoroutineClosureId,
97 args: I::GenericArgs,
98 ) -> Self;
99
100 fn new_closure(interner: I, def_id: I::ClosureId, args: I::GenericArgs) -> Self;
101
102 fn new_coroutine_witness(interner: I, def_id: I::CoroutineId, args: I::GenericArgs) -> Self;
103
104 fn new_coroutine_witness_for_coroutine(
105 interner: I,
106 def_id: I::CoroutineId,
107 coroutine_args: I::GenericArgs,
108 ) -> Self;
109
110 fn new_ptr(interner: I, ty: Self, mutbl: Mutability) -> Self;
111
112 fn new_ref(interner: I, region: Region<I>, ty: Self, mutbl: Mutability) -> Self;
113
114 fn new_array_with_const_len(interner: I, ty: Self, len: I::Const) -> Self;
115
116 fn new_slice(interner: I, ty: Self) -> Self;
117
118 fn new_tup(interner: I, tys: &[I::Ty]) -> Self;
119
120 fn new_tup_from_iter<It, T>(interner: I, iter: It) -> T::Output
121 where
122 It: Iterator<Item = T>,
123 T: CollectAndApply<Self, Self>;
124
125 fn new_fn_def(interner: I, def_id: I::FunctionId, args: ty::Binder<I, I::GenericArgs>) -> Self;
126
127 fn new_fn_ptr(interner: I, sig: ty::Binder<I, ty::FnSig<I>>) -> Self;
128
129 fn new_pat(interner: I, ty: Self, pat: I::Pat) -> Self;
130
131 fn new_unsafe_binder(interner: I, ty: ty::Binder<I, I::Ty>) -> Self;
132
133 fn tuple_fields(self) -> I::Tys;
134
135 fn to_opt_closure_kind(self) -> Option<ty::ClosureKind>;
136
137 fn from_closure_kind(interner: I, kind: ty::ClosureKind) -> Self;
138
139 fn from_coroutine_closure_kind(interner: I, kind: ty::ClosureKind) -> Self;
140
141 fn is_ty_var(self) -> bool {
142 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::Infer(ty::TyVar(_)) => true,
_ => false,
}matches!(self.kind(), ty::Infer(ty::TyVar(_)))
143 }
144
145 fn is_ty_error(self) -> bool {
146 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::Error(_) => true,
_ => false,
}matches!(self.kind(), ty::Error(_))
147 }
148
149 fn is_floating_point(self) -> bool {
150 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::Float(_) | ty::Infer(ty::FloatVar(_)) => true,
_ => false,
}matches!(self.kind(), ty::Float(_) | ty::Infer(ty::FloatVar(_)))
151 }
152
153 fn is_integral(self) -> bool {
154 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::Infer(ty::IntVar(_)) | ty::Int(_) | ty::Uint(_) => true,
_ => false,
}matches!(self.kind(), ty::Infer(ty::IntVar(_)) | ty::Int(_) | ty::Uint(_))
155 }
156
157 fn is_fn_ptr(self) -> bool {
158 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::FnPtr(..) => true,
_ => false,
}matches!(self.kind(), ty::FnPtr(..))
159 }
160
161 fn has_unsafe_fields(self) -> bool;
163
164 fn fn_sig(self, interner: I) -> ty::Binder<I, ty::FnSig<I>> {
165 self.kind().fn_sig(interner)
166 }
167
168 fn discriminant_ty(self, interner: I) -> I::Ty;
169
170 fn is_known_rigid(self) -> bool {
171 self.kind().is_known_rigid()
172 }
173
174 fn is_guaranteed_unsized_raw(self) -> bool {
175 match self.kind() {
176 ty::Dynamic(_, _) | ty::Slice(_) | ty::Str => true,
177 ty::Bool
178 | ty::Char
179 | ty::Int(_)
180 | ty::Uint(_)
181 | ty::Float(_)
182 | ty::Adt(_, _)
183 | ty::Foreign(_)
184 | ty::Array(_, _)
185 | ty::Pat(_, _)
186 | ty::RawPtr(_, _)
187 | ty::Ref(_, _, _)
188 | ty::FnDef(_, _)
189 | ty::FnPtr(_, _)
190 | ty::UnsafeBinder(_)
191 | ty::Closure(_, _)
192 | ty::CoroutineClosure(_, _)
193 | ty::Coroutine(_, _)
194 | ty::CoroutineWitness(_, _)
195 | ty::Never
196 | ty::Tuple(_)
197 | ty::Alias(_, _)
198 | ty::Param(_)
199 | ty::Bound(_, _)
200 | ty::Placeholder(_)
201 | ty::Infer(_)
202 | ty::Error(_) => false,
203 }
204 }
205}
206
207#[rust_analyzer::prefer_underscore_import]
208pub trait Tys<I: Interner<Tys = Self>>:
209 Copy + Debug + Hash + Eq + SliceLike<Item = I::Ty> + TypeFoldable<I> + Default
210{
211 fn inputs(self) -> I::FnInputTys;
212
213 fn output(self) -> I::Ty;
214}
215
216#[rust_analyzer::prefer_underscore_import]
217pub trait Safety<I: Interner<Safety = Self>>: Copy + Debug + Hash + Eq {
218 fn safe() -> Self;
220
221 fn unsafe_mode() -> Self;
223
224 fn is_safe(self) -> bool;
226
227 fn prefix_str(self) -> &'static str;
229}
230
231pub trait Const<I: Interner<Const = Self>>:
232 Copy
233 + Debug
234 + Hash
235 + Eq
236 + Into<I::GenericArg>
237 + Into<I::Term>
238 + IntoKind<Kind = ty::ConstKind<I>>
239 + TypeSuperVisitable<I>
240 + TypeSuperFoldable<I>
241 + Relate<I>
242 + Flags
243{
244 fn new_infer(interner: I, var: ty::InferConst) -> Self;
245
246 fn new_var(interner: I, var: ty::ConstVid) -> Self;
247
248 fn new_bound(interner: I, debruijn: ty::DebruijnIndex, bound_const: ty::BoundConst<I>) -> Self;
249
250 fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self;
251
252 fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self;
253
254 fn new_placeholder(interner: I, param: ty::PlaceholderConst<I>) -> Self;
255
256 fn new_alias(interner: I, is_rigid: ty::IsRigid, alias_const: ty::AliasConst<I>) -> Self;
257
258 fn new_expr(interner: I, expr: I::ExprConst) -> Self;
259
260 fn new_error(interner: I, guar: I::ErrorGuaranteed) -> Self;
261
262 fn new_error_with_message(interner: I, msg: impl ToString) -> Self {
263 Self::new_error(interner, interner.delay_bug(msg))
264 }
265
266 fn is_ct_var(self) -> bool {
267 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::ConstKind::Infer(ty::InferConst::Var(_)) => true,
_ => false,
}matches!(self.kind(), ty::ConstKind::Infer(ty::InferConst::Var(_)))
268 }
269
270 fn is_ct_error(self) -> bool {
271 #[allow(non_exhaustive_omitted_patterns)] match self.kind() {
ty::ConstKind::Error(_) => true,
_ => false,
}matches!(self.kind(), ty::ConstKind::Error(_))
272 }
273}
274
275#[rust_analyzer::prefer_underscore_import]
276pub trait ValueConst<I: Interner<ValueConst = Self>>: Copy + Debug + Hash + Eq {
277 fn ty(self) -> I::Ty;
278 fn valtree(self) -> I::ValTree;
279}
280
281#[rust_analyzer::prefer_underscore_import]
282pub trait ExprConst<I: Interner<ExprConst = Self>>: Copy + Debug + Hash + Eq + Relate<I> {
283 fn args(self) -> I::GenericArgs;
284}
285
286#[rust_analyzer::prefer_underscore_import]
287pub trait GenericsOf<I: Interner<GenericsOf = Self>> {
288 fn count(&self) -> usize;
289 fn param_region_def_id(self, interner: I, ebr: I::EarlyParamRegion) -> I::DefId;
290}
291
292#[rust_analyzer::prefer_underscore_import]
293pub trait GenericArg<I: Interner<GenericArg = Self>>:
294 Copy
295 + Debug
296 + Hash
297 + Eq
298 + IntoKind<Kind = ty::GenericArgKind<I>>
299 + TypeVisitable<I>
300 + Relate<I>
301 + From<I::Ty>
302 + From<Region<I>>
303 + From<I::Const>
304 + From<I::Term>
305{
306 fn as_term(&self) -> Option<I::Term> {
307 match self.kind() {
308 ty::GenericArgKind::Lifetime(_) => None,
309 ty::GenericArgKind::Type(ty) => Some(ty.into()),
310 ty::GenericArgKind::Const(ct) => Some(ct.into()),
311 }
312 }
313
314 fn as_type(&self) -> Option<I::Ty> {
315 if let ty::GenericArgKind::Type(ty) = self.kind() { Some(ty) } else { None }
316 }
317
318 fn expect_ty(&self) -> I::Ty {
319 self.as_type().expect("expected a type")
320 }
321
322 fn as_const(&self) -> Option<I::Const> {
323 if let ty::GenericArgKind::Const(c) = self.kind() { Some(c) } else { None }
324 }
325
326 fn expect_const(&self) -> I::Const {
327 self.as_const().expect("expected a const")
328 }
329
330 fn as_region(&self) -> Option<Region<I>> {
331 if let ty::GenericArgKind::Lifetime(c) = self.kind() { Some(c) } else { None }
332 }
333
334 fn expect_region(&self) -> Region<I> {
335 self.as_region().expect("expected a const")
336 }
337
338 fn is_non_region_infer(self) -> bool {
339 match self.kind() {
340 ty::GenericArgKind::Lifetime(_) => false,
341 ty::GenericArgKind::Type(ty) => ty.is_ty_var(),
342 ty::GenericArgKind::Const(ct) => ct.is_ct_var(),
343 }
344 }
345}
346
347#[rust_analyzer::prefer_underscore_import]
348pub trait Term<I: Interner<Term = Self>>:
349 Copy + Debug + Hash + Eq + IntoKind<Kind = ty::TermKind<I>> + TypeFoldable<I> + Relate<I>
350{
351 fn as_type(&self) -> Option<I::Ty> {
352 if let ty::TermKind::Ty(ty) = self.kind() { Some(ty) } else { None }
353 }
354
355 fn expect_ty(&self) -> I::Ty {
356 self.as_type().expect("expected a type, but found a const")
357 }
358
359 fn as_const(&self) -> Option<I::Const> {
360 if let ty::TermKind::Const(c) = self.kind() { Some(c) } else { None }
361 }
362
363 fn expect_const(&self) -> I::Const {
364 self.as_const().expect("expected a const, but found a type")
365 }
366
367 fn is_infer(self) -> bool {
368 match self.kind() {
369 ty::TermKind::Ty(ty) => ty.is_ty_var(),
370 ty::TermKind::Const(ct) => ct.is_ct_var(),
371 }
372 }
373
374 fn is_error(self) -> bool {
375 match self.kind() {
376 ty::TermKind::Ty(ty) => ty.is_ty_error(),
377 ty::TermKind::Const(ct) => ct.is_ct_error(),
378 }
379 }
380
381 fn to_alias_term(self) -> Option<ty::AliasTerm<I>> {
382 match self.kind() {
383 ty::TermKind::Ty(ty) => match ty.kind() {
384 ty::Alias(_, alias_ty) => Some(alias_ty.into()),
385 _ => None,
386 },
387 ty::TermKind::Const(ct) => match ct.kind() {
388 ty::ConstKind::Alias(_, alias_const) => Some(alias_const.into()),
389 _ => None,
390 },
391 }
392 }
393
394 fn is_non_rigid_alias(self) -> bool {
395 match self.kind() {
396 ty::TermKind::Ty(ty) => match ty.kind() {
397 ty::Alias(is_rigid, _) => is_rigid == ty::IsRigid::No,
398 _ => false,
399 },
400 ty::TermKind::Const(ct) => match ct.kind() {
401 ty::ConstKind::Alias(is_rigid, _) => is_rigid == ty::IsRigid::No,
402 _ => false,
403 },
404 }
405 }
406}
407
408#[rust_analyzer::prefer_underscore_import]
409pub trait GenericArgs<I: Interner<GenericArgs = Self>>:
410 Copy + Debug + Hash + Eq + SliceLike<Item = I::GenericArg> + Default + Relate<I>
411{
412 fn rebase_onto(
413 self,
414 interner: I,
415 source_def_id: I::DefId,
416 target: I::GenericArgs,
417 ) -> I::GenericArgs;
418
419 fn type_at(self, i: usize) -> I::Ty;
420
421 fn region_at(self, i: usize) -> Region<I>;
422
423 fn const_at(self, i: usize) -> I::Const;
424
425 fn identity_for_item(interner: I, def_id: I::DefId) -> I::GenericArgs;
426
427 fn extend_with_error(
428 interner: I,
429 def_id: I::DefId,
430 original_args: &[I::GenericArg],
431 ) -> I::GenericArgs;
432
433 fn split_closure_args(self) -> ty::ClosureArgsParts<I>;
434 fn split_coroutine_closure_args(self) -> ty::CoroutineClosureArgsParts<I>;
435 fn split_coroutine_args(self) -> ty::CoroutineArgsParts<I>;
436
437 fn as_closure(self) -> ty::ClosureArgs<I> {
438 ty::ClosureArgs { args: self }
439 }
440 fn as_coroutine_closure(self) -> ty::CoroutineClosureArgs<I> {
441 ty::CoroutineClosureArgs { args: self }
442 }
443 fn as_coroutine(self) -> ty::CoroutineArgs<I> {
444 ty::CoroutineArgs { args: self }
445 }
446}
447
448#[rust_analyzer::prefer_underscore_import]
449pub trait Predicate<I: Interner<Predicate = Self>>:
450 Copy
451 + Debug
452 + Hash
453 + Eq
454 + TypeSuperVisitable<I>
455 + TypeSuperFoldable<I>
456 + Flags
457 + UpcastFrom<I, ty::PredicateKind<I>>
458 + UpcastFrom<I, ty::Binder<I, ty::PredicateKind<I>>>
459 + UpcastFrom<I, ty::ClauseKind<I>>
460 + UpcastFrom<I, ty::Binder<I, ty::ClauseKind<I>>>
461 + UpcastFrom<I, I::Clause>
462 + UpcastFrom<I, ty::NormalizesTo<I>>
463 + UpcastFrom<I, ty::TraitRef<I>>
464 + UpcastFrom<I, ty::Binder<I, ty::TraitRef<I>>>
465 + UpcastFrom<I, ty::TraitClause<I>>
466 + UpcastFrom<I, ty::ProjectionClause<I>>
467 + UpcastFrom<I, ty::OutlivesClause<I, I::Ty>>
468 + UpcastFrom<I, ty::OutlivesClause<I, Region<I>>>
469 + IntoKind<Kind = ty::Binder<I, ty::PredicateKind<I>>>
470 + Elaboratable<I>
471{
472 fn as_clause(self) -> Option<I::Clause>;
473
474 fn allow_normalization(self) -> bool {
475 match self.kind().skip_binder() {
476 PredicateKind::Clause(ClauseKind::WellFormed(_)) => false,
477 PredicateKind::Clause(ClauseKind::Trait(_))
478 | PredicateKind::Clause(ClauseKind::HostEffect(..))
479 | PredicateKind::Clause(ClauseKind::RegionOutlives(_))
480 | PredicateKind::Clause(ClauseKind::TypeOutlives(_))
481 | PredicateKind::Clause(ClauseKind::Projection(_))
482 | PredicateKind::Clause(ClauseKind::ConstArgHasType(..))
483 | PredicateKind::Clause(ClauseKind::UnstableFeature(_))
484 | PredicateKind::DynCompatible(_)
485 | PredicateKind::Subtype(_)
486 | PredicateKind::Coerce(_)
487 | PredicateKind::Clause(ClauseKind::ConstEvaluatable(_))
488 | PredicateKind::ConstEquate(_, _)
489 | PredicateKind::NormalizesTo(..)
490 | PredicateKind::Ambiguous => true,
491 }
492 }
493}
494
495#[rust_analyzer::prefer_underscore_import]
496pub trait Clause<I: Interner<Clause = Self>>:
497 Copy
498 + Debug
499 + Hash
500 + Eq
501 + TypeFoldable<I>
502 + Flags
503 + UpcastFrom<I, ty::Binder<I, ty::ClauseKind<I>>>
504 + UpcastFrom<I, ty::TraitRef<I>>
505 + UpcastFrom<I, ty::Binder<I, ty::TraitRef<I>>>
506 + UpcastFrom<I, ty::TraitClause<I>>
507 + UpcastFrom<I, ty::Binder<I, ty::TraitClause<I>>>
508 + UpcastFrom<I, ty::ProjectionClause<I>>
509 + UpcastFrom<I, ty::Binder<I, ty::ProjectionClause<I>>>
510 + IntoKind<Kind = ty::Binder<I, ty::ClauseKind<I>>>
511 + Elaboratable<I>
512{
513 fn as_predicate(self) -> I::Predicate;
514
515 fn as_type_outlives_clause(self) -> Option<ty::Binder<I, ty::OutlivesClause<I, I::Ty>>> {
516 self.kind()
517 .map_bound(|clause| {
518 if let ty::ClauseKind::TypeOutlives(outlives) = clause {
519 Some(outlives)
520 } else {
521 None
522 }
523 })
524 .transpose()
525 }
526
527 fn as_trait_clause(self) -> Option<ty::Binder<I, ty::TraitClause<I>>> {
528 self.kind()
529 .map_bound(|clause| if let ty::ClauseKind::Trait(t) = clause { Some(t) } else { None })
530 .transpose()
531 }
532
533 fn as_host_effect_clause(self) -> Option<ty::Binder<I, ty::HostEffectClause<I>>> {
534 self.kind()
535 .map_bound(
536 |clause| if let ty::ClauseKind::HostEffect(t) = clause { Some(t) } else { None },
537 )
538 .transpose()
539 }
540
541 fn as_projection_clause(self) -> Option<ty::Binder<I, ty::ProjectionClause<I>>> {
542 self.kind()
543 .map_bound(
544 |clause| {
545 if let ty::ClauseKind::Projection(p) = clause { Some(p) } else { None }
546 },
547 )
548 .transpose()
549 }
550
551 fn instantiate_supertrait(self, cx: I, trait_ref: ty::Binder<I, ty::TraitRef<I>>) -> Self;
556}
557
558#[rust_analyzer::prefer_underscore_import]
559pub trait Clauses<I: Interner<Clauses = Self>>:
560 Copy
561 + Debug
562 + Hash
563 + Eq
564 + TypeSuperVisitable<I>
565 + TypeSuperFoldable<I>
566 + Flags
567 + SliceLike<Item = I::Clause>
568{
569}
570
571#[rust_analyzer::prefer_underscore_import]
572pub trait IntoKind {
573 type Kind;
574
575 fn kind(self) -> Self::Kind;
576}
577
578#[rust_analyzer::prefer_underscore_import]
579pub trait ParamLike: Copy + Debug + Hash + Eq {
580 fn index(self) -> u32;
581}
582
583#[rust_analyzer::prefer_underscore_import]
584pub trait AdtDef<I: Interner>: Copy + Debug + Hash + Eq {
585 fn def_id(self) -> I::AdtId;
586
587 fn is_struct(self) -> bool;
588
589 fn is_packed(self) -> bool;
590
591 fn struct_tail_ty(self, interner: I) -> Option<ty::EarlyBinder<I, I::Ty>>;
595
596 fn is_phantom_data(self) -> bool;
597
598 fn is_manually_drop(self) -> bool;
599
600 fn field_representing_type_info(
601 self,
602 interner: I,
603 args: I::GenericArgs,
604 ) -> Option<FieldInfo<I>>;
605
606 fn all_field_tys(self, interner: I) -> ty::EarlyBinder<I, impl IntoIterator<Item = I::Ty>>;
608
609 fn sizedness_constraint(
610 self,
611 interner: I,
612 sizedness: SizedTraitKind,
613 ) -> Option<ty::EarlyBinder<I, I::Ty>>;
614
615 fn is_fundamental(self) -> bool;
616
617 fn destructor(self, interner: I) -> Option<AdtDestructorKind>;
618}
619
620#[rust_analyzer::prefer_underscore_import]
621pub trait ParamEnv<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
622 fn caller_bounds(self) -> impl Iterator<Item = I::Clause>;
623}
624
625#[rust_analyzer::prefer_underscore_import]
626pub trait Features<I: Interner>: Copy {
627 fn generic_const_exprs(self) -> bool;
628
629 fn generic_const_args(self) -> bool;
630
631 fn coroutine_clone(self) -> bool;
632
633 fn feature_bound_holds_in_crate(self, symbol: I::Symbol) -> bool;
634}
635
636#[rust_analyzer::prefer_underscore_import]
637pub trait DefId<I: Interner, Local = <I as Interner>::LocalDefId>:
638 Copy + Debug + Hash + Eq + TypeFoldable<I>
639{
640 fn is_local(self) -> bool;
641
642 fn as_local(self) -> Option<Local>;
643}
644
645pub trait SpecificDefId<I: Interner, Local = <I as Interner>::LocalDefId>:
646 DefId<I, Local> + Into<I::DefId> + TryFrom<I::DefId, Error: std::fmt::Debug>
647{
648}
649
650impl<
651 I: Interner,
652 T: DefId<I, Local> + Into<I::DefId> + TryFrom<I::DefId, Error: std::fmt::Debug>,
653 Local,
654> SpecificDefId<I, Local> for T
655{
656}
657
658#[rust_analyzer::prefer_underscore_import]
659pub trait BoundExistentialPredicates<I: Interner>:
660 Copy + Debug + Hash + Eq + Relate<I> + SliceLike<Item = ty::Binder<I, ty::ExistentialPredicate<I>>>
661{
662 fn principal_def_id(self) -> Option<I::TraitId>;
663
664 fn principal(self) -> Option<ty::Binder<I, ty::ExistentialTraitRef<I>>>;
665
666 fn auto_traits(self) -> impl IntoIterator<Item = I::TraitId>;
667
668 fn projection_bounds(
669 self,
670 ) -> impl IntoIterator<Item = ty::Binder<I, ty::ExistentialProjection<I>>>;
671}
672
673#[rust_analyzer::prefer_underscore_import]
674pub trait Span<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
675 fn dummy() -> Self;
676}
677
678#[rust_analyzer::prefer_underscore_import]
679pub trait OpaqueTypeStorageEntries: Debug + Copy + Default {
680 fn needs_reevaluation(self, canonicalized: usize) -> bool;
684}
685
686pub trait BoundVarKinds<I: Interner>:
687 Copy + Debug + Hash + Eq + SliceLike<Item = ty::BoundVariableKind<I>> + Default
688{
689 fn from_vars(cx: I, iter: impl IntoIterator<Item = ty::BoundVariableKind<I>>) -> Self;
690}
691
692pub trait SliceLike: Sized + Copy {
693 type Item: Copy;
694 type IntoIter: Iterator<Item = Self::Item> + DoubleEndedIterator;
695
696 fn iter(self) -> Self::IntoIter;
697
698 fn as_slice(&self) -> &[Self::Item];
699
700 fn get(self, idx: usize) -> Option<Self::Item> {
701 self.as_slice().get(idx).copied()
702 }
703
704 fn len(self) -> usize {
705 self.as_slice().len()
706 }
707
708 fn is_empty(self) -> bool {
709 self.len() == 0
710 }
711
712 fn contains(self, t: &Self::Item) -> bool
713 where
714 Self::Item: PartialEq,
715 {
716 self.as_slice().contains(t)
717 }
718
719 fn to_vec(self) -> Vec<Self::Item> {
720 self.as_slice().to_vec()
721 }
722
723 fn last(self) -> Option<Self::Item> {
724 self.as_slice().last().copied()
725 }
726
727 fn split_last(&self) -> Option<(&Self::Item, &[Self::Item])> {
728 self.as_slice().split_last()
729 }
730}
731
732impl<'a, T: Copy> SliceLike for &'a [T] {
733 type Item = T;
734 type IntoIter = std::iter::Copied<std::slice::Iter<'a, T>>;
735
736 fn iter(self) -> Self::IntoIter {
737 self.iter().copied()
738 }
739
740 fn as_slice(&self) -> &[Self::Item] {
741 *self
742 }
743}
744
745impl<'a, T: Copy, const N: usize> SliceLike for &'a [T; N] {
746 type Item = T;
747 type IntoIter = std::iter::Copied<std::slice::Iter<'a, T>>;
748
749 fn iter(self) -> Self::IntoIter {
750 self.into_iter().copied()
751 }
752
753 fn as_slice(&self) -> &[Self::Item] {
754 *self
755 }
756}
757
758impl<'a, S: SliceLike> SliceLike for &'a S {
759 type Item = S::Item;
760 type IntoIter = S::IntoIter;
761
762 fn iter(self) -> Self::IntoIter {
763 (*self).iter()
764 }
765
766 fn as_slice(&self) -> &[Self::Item] {
767 (*self).as_slice()
768 }
769}
770
771#[rust_analyzer::prefer_underscore_import]
772pub trait Symbol<I: Interner>: Copy + Hash + PartialEq + Eq + Debug {
773 const KW_UNDERSCORE_LIFETIME: Self;
774 const KW_STATIC_LIFETIME: Self;
775 const SYM_ANON: Self;
776}
777
778pub trait RegionName<I: Interner>: Copy + Hash + PartialEq + Eq + Debug {
779 fn get_name(&self, interner: I) -> Option<I::Symbol>;
780 fn is_named(&self, interner: I) -> bool;
781}
782
783pub trait DefIdGetter<I: Interner>: Copy + Hash + PartialEq + Eq + Debug {
784 fn get_def_id(self) -> Option<I::DefId>;
785}