|
1 | | -use std::ops::ControlFlow; |
2 | | - |
3 | 1 | use rustc_ast as ast; |
4 | 2 | use rustc_data_structures::fx::FxHashMap; |
5 | 3 | use rustc_hir::def_id::DefId; |
6 | 4 | use rustc_macros::{HashStable, TyDecodable, TyEncodable}; |
7 | 5 | use rustc_span::{Span, Symbol, kw}; |
8 | | -use rustc_type_ir::{TypeSuperVisitable as _, TypeVisitable, TypeVisitor}; |
9 | 6 | use tracing::instrument; |
10 | 7 |
|
11 | 8 | use super::{Clause, InstantiatedPredicates, ParamConst, ParamTy, Ty, TyCtxt}; |
12 | | -use crate::ty::{self, ClauseKind, EarlyBinder, GenericArgsRef, Region, RegionKind, TyKind}; |
| 9 | +use crate::ty::{self, EarlyBinder, GenericArgsRef}; |
13 | 10 |
|
14 | 11 | #[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)] |
15 | 12 | pub enum GenericParamDefKind { |
@@ -423,70 +420,6 @@ impl<'tcx> GenericPredicates<'tcx> { |
423 | 420 | instantiated.predicates.extend(self.predicates.iter().map(|(p, _)| p)); |
424 | 421 | instantiated.spans.extend(self.predicates.iter().map(|(_, s)| s)); |
425 | 422 | } |
426 | | - |
427 | | - /// Allow simple where bounds like `T: Debug`, but prevent any kind of |
428 | | - /// outlives bounds or uses of generic parameters on the right hand side. |
429 | | - pub fn is_fully_generic_for_reflection(self) -> bool { |
430 | | - struct ParamChecker; |
431 | | - impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParamChecker { |
432 | | - type Result = ControlFlow<()>; |
433 | | - fn visit_region(&mut self, r: Region<'tcx>) -> Self::Result { |
434 | | - match r.kind() { |
435 | | - RegionKind::ReEarlyParam(_) | RegionKind::ReStatic | RegionKind::ReError(_) => { |
436 | | - ControlFlow::Break(()) |
437 | | - } |
438 | | - RegionKind::ReVar(_) |
439 | | - | RegionKind::RePlaceholder(_) |
440 | | - | RegionKind::ReErased |
441 | | - | RegionKind::ReLateParam(_) => { |
442 | | - bug!("unexpected lifetime in impl: {r:?}") |
443 | | - } |
444 | | - RegionKind::ReBound(..) => ControlFlow::Continue(()), |
445 | | - } |
446 | | - } |
447 | | - |
448 | | - fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result { |
449 | | - match t.kind() { |
450 | | - TyKind::Param(_p) => { |
451 | | - // Reject using parameters used in the type in where bounds |
452 | | - return ControlFlow::Break(()); |
453 | | - } |
454 | | - TyKind::Alias(..) => return ControlFlow::Break(()), |
455 | | - _ => (), |
456 | | - } |
457 | | - t.super_visit_with(self) |
458 | | - } |
459 | | - } |
460 | | - |
461 | | - // Pessimistic: if any of the parameters have where bounds |
462 | | - // don't allow this impl to be used. |
463 | | - self.predicates.iter().all(|(clause, _)| { |
464 | | - match clause.kind().skip_binder() { |
465 | | - ClauseKind::Trait(trait_predicate) => { |
466 | | - // In a `T: Trait`, if the rhs bound does not contain any generic params |
467 | | - // or 'static lifetimes, then it cannot transitively cause such requirements, |
468 | | - // considering we apply the fully-generic-for-reflection rules to any impls for |
469 | | - // that trait, too. |
470 | | - if matches!(trait_predicate.self_ty().kind(), ty::Param(_)) |
471 | | - && trait_predicate.trait_ref.args[1..] |
472 | | - .iter() |
473 | | - .all(|arg| arg.visit_with(&mut ParamChecker).is_continue()) |
474 | | - { |
475 | | - return true; |
476 | | - } |
477 | | - } |
478 | | - ClauseKind::RegionOutlives(_) |
479 | | - | ClauseKind::TypeOutlives(_) |
480 | | - | ClauseKind::Projection(_) |
481 | | - | ClauseKind::ConstArgHasType(_, _) |
482 | | - | ClauseKind::WellFormed(_) |
483 | | - | ClauseKind::ConstEvaluatable(_) |
484 | | - | ClauseKind::HostEffect(_) |
485 | | - | ClauseKind::UnstableFeature(_) => {} |
486 | | - } |
487 | | - clause.visit_with(&mut ParamChecker).is_continue() |
488 | | - }) |
489 | | - } |
490 | 423 | } |
491 | 424 |
|
492 | 425 | /// `[const]` bounds for a given item. This is represented using a struct much like |
|
0 commit comments