about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-07-24 20:44:19 +0000
committerMichael Goulet <michael@errs.io>2022-07-25 03:39:23 +0000
commit10b69ab0d20bdbbcdfc5bfe443a50cf2b12b66de (patch)
tree05f7cb13bf3a462e8ec3e5289fa2c1269da275c2 /compiler/rustc_trait_selection/src
parentc1f54c30bb3200239849649ebc08d7ac2877db6c (diff)
downloadrust-10b69ab0d20bdbbcdfc5bfe443a50cf2b12b66de.tar.gz
rust-10b69ab0d20bdbbcdfc5bfe443a50cf2b12b66de.zip
Remove non-descriptive boolean from search_for_structural_match_violation
Diffstat (limited to 'compiler/rustc_trait_selection/src')
-rw-r--r--compiler/rustc_trait_selection/src/traits/mod.rs4
-rw-r--r--compiler/rustc_trait_selection/src/traits/structural_match.rs33
2 files changed, 26 insertions, 11 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs
index 5397baefb9c..d0a17f712d3 100644
--- a/compiler/rustc_trait_selection/src/traits/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/mod.rs
@@ -60,7 +60,9 @@ pub use self::select::{EvaluationResult, IntercrateAmbiguityCause, OverflowError
 pub use self::specialize::specialization_graph::FutureCompatOverlapError;
 pub use self::specialize::specialization_graph::FutureCompatOverlapErrorKind;
 pub use self::specialize::{specialization_graph, translate_substs, OverlapError};
-pub use self::structural_match::search_for_structural_match_violation;
+pub use self::structural_match::{
+    search_for_adt_const_param_violation, search_for_structural_match_violation,
+};
 pub use self::util::{
     elaborate_obligations, elaborate_predicates, elaborate_predicates_with_span,
     elaborate_trait_ref, elaborate_trait_refs,
diff --git a/compiler/rustc_trait_selection/src/traits/structural_match.rs b/compiler/rustc_trait_selection/src/traits/structural_match.rs
index ea11670ee77..c278752e3d9 100644
--- a/compiler/rustc_trait_selection/src/traits/structural_match.rs
+++ b/compiler/rustc_trait_selection/src/traits/structural_match.rs
@@ -35,16 +35,28 @@ use std::ops::ControlFlow;
 /// For more background on why Rust has this requirement, and issues
 /// that arose when the requirement was not enforced completely, see
 /// Rust RFC 1445, rust-lang/rust#61188, and rust-lang/rust#62307.
-///
-/// When the `valtree_semantics` flag is set, then we also deny additional
-/// types that are not evaluatable to valtrees, such as floats and fn ptrs.
 pub fn search_for_structural_match_violation<'tcx>(
     span: Span,
     tcx: TyCtxt<'tcx>,
     ty: Ty<'tcx>,
-    valtree_semantics: bool,
 ) -> Option<Ty<'tcx>> {
-    ty.visit_with(&mut Search { tcx, span, seen: FxHashSet::default(), valtree_semantics })
+    ty.visit_with(&mut Search { tcx, span, seen: FxHashSet::default(), adt_const_param: false })
+        .break_value()
+}
+
+/// This method traverses the structure of `ty`, trying to find any
+/// types that are not allowed to be used in a const generic.
+///
+/// This is either because the type does not implement `StructuralEq`
+/// and `StructuralPartialEq`, or because the type is intentionally
+/// not supported in const generics (such as floats and raw pointers,
+/// which are allowed in match blocks).
+pub fn search_for_adt_const_param_violation<'tcx>(
+    span: Span,
+    tcx: TyCtxt<'tcx>,
+    ty: Ty<'tcx>,
+) -> Option<Ty<'tcx>> {
+    ty.visit_with(&mut Search { tcx, span, seen: FxHashSet::default(), adt_const_param: true })
         .break_value()
 }
 
@@ -108,8 +120,9 @@ struct Search<'tcx> {
     seen: FxHashSet<hir::def_id::DefId>,
 
     // Additionally deny things that have been allowed in patterns,
-    // but are not evaluatable to a valtree, such as floats and fn ptrs.
-    valtree_semantics: bool,
+    // but are not allowed in adt const params, such as floats and
+    // fn ptrs.
+    adt_const_param: bool,
 }
 
 impl<'tcx> Search<'tcx> {
@@ -167,7 +180,7 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
             }
 
             ty::FnPtr(..) => {
-                if !self.valtree_semantics {
+                if !self.adt_const_param {
                     return ControlFlow::CONTINUE;
                 } else {
                     return ControlFlow::Break(ty);
@@ -175,7 +188,7 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
             }
 
             ty::RawPtr(..) => {
-                if !self.valtree_semantics {
+                if !self.adt_const_param {
                     // structural-match ignores substructure of
                     // `*const _`/`*mut _`, so skip `super_visit_with`.
                     //
@@ -197,7 +210,7 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
             }
 
             ty::Float(_) => {
-                if !self.valtree_semantics {
+                if !self.adt_const_param {
                     return ControlFlow::CONTINUE;
                 } else {
                     return ControlFlow::Break(ty);