about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2024-03-16 02:33:21 +0100
committerLeón Orell Valerian Liehr <me@fmease.dev>2024-03-16 02:33:21 +0100
commita37fe00ea16a48652c22af3afa7dd04611a82700 (patch)
tree0465561a0ddbf75fadd35fdb9b774af0a6e2abe0
parentd7723b21910075a3c38c2b6e64b2467394c93724 (diff)
downloadrust-a37fe00ea16a48652c22af3afa7dd04611a82700.tar.gz
rust-a37fe00ea16a48652c22af3afa7dd04611a82700.zip
Remove obsolete parameter `speculative` from `instantiate_poly_trait_ref`
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/bounds.rs101
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/mod.rs4
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/object_safety.rs1
3 files changed, 48 insertions, 58 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/bounds.rs b/compiler/rustc_hir_analysis/src/astconv/bounds.rs
index 17e0aeb044c..c6942b0f456 100644
--- a/compiler/rustc_hir_analysis/src/astconv/bounds.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/bounds.rs
@@ -149,7 +149,6 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
                         polarity,
                         param_ty,
                         bounds,
-                        false,
                         only_self_bounds,
                     );
                 }
@@ -231,14 +230,13 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
     /// **A note on binders:** given something like `T: for<'a> Iterator<Item = &'a u32>`, the
     /// `trait_ref` here will be `for<'a> T: Iterator`. The `binding` data however is from *inside*
     /// the binder (e.g., `&'a u32`) and hence may reference bound regions.
-    #[instrument(level = "debug", skip(self, bounds, speculative, dup_bindings, path_span))]
+    #[instrument(level = "debug", skip(self, bounds, dup_bindings, path_span))]
     pub(super) fn add_predicates_for_ast_type_binding(
         &self,
         hir_ref_id: hir::HirId,
         trait_ref: ty::PolyTraitRef<'tcx>,
         binding: &hir::TypeBinding<'tcx>,
         bounds: &mut Bounds<'tcx>,
-        speculative: bool,
         dup_bindings: &mut FxIndexMap<DefId, Span>,
         path_span: Span,
         only_self_bounds: OnlySelfBounds,
@@ -317,19 +315,17 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
         }
         tcx.check_stability(assoc_item.def_id, Some(hir_ref_id), binding.span, None);
 
-        if !speculative {
-            dup_bindings
-                .entry(assoc_item.def_id)
-                .and_modify(|prev_span| {
-                    tcx.dcx().emit_err(errors::ValueOfAssociatedStructAlreadySpecified {
-                        span: binding.span,
-                        prev_span: *prev_span,
-                        item_name: binding.ident,
-                        def_path: tcx.def_path_str(assoc_item.container_id(tcx)),
-                    });
-                })
-                .or_insert(binding.span);
-        }
+        dup_bindings
+            .entry(assoc_item.def_id)
+            .and_modify(|prev_span| {
+                tcx.dcx().emit_err(errors::ValueOfAssociatedStructAlreadySpecified {
+                    span: binding.span,
+                    prev_span: *prev_span,
+                    item_name: binding.ident,
+                    def_path: tcx.def_path_str(assoc_item.container_id(tcx)),
+                });
+            })
+            .or_insert(binding.span);
 
         let projection_ty = if let ty::AssocKind::Fn = assoc_kind {
             let mut emitted_bad_param_err = None;
@@ -433,9 +429,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
             });
 
             // Provide the resolved type of the associated constant to `type_of(AnonConst)`.
-            if !speculative
-                && let hir::TypeBindingKind::Equality { term: hir::Term::Const(anon_const) } =
-                    binding.kind
+            if let hir::TypeBindingKind::Equality { term: hir::Term::Const(anon_const) } =
+                binding.kind
             {
                 let ty = alias_ty.map_bound(|ty| tcx.type_of(ty.def_id).instantiate(tcx, ty.args));
                 // Since the arguments passed to the alias type above may contain early-bound
@@ -463,42 +458,40 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
                     hir::Term::Const(ct) => ty::Const::from_anon_const(tcx, ct.def_id).into(),
                 };
 
-                if !speculative {
-                    // Find any late-bound regions declared in `ty` that are not
-                    // declared in the trait-ref or assoc_item. These are not well-formed.
-                    //
-                    // Example:
-                    //
-                    //     for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
-                    //     for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
-                    let late_bound_in_projection_ty =
-                        tcx.collect_constrained_late_bound_regions(projection_ty);
-                    let late_bound_in_term =
-                        tcx.collect_referenced_late_bound_regions(trait_ref.rebind(term));
-                    debug!(?late_bound_in_projection_ty);
-                    debug!(?late_bound_in_term);
+                // Find any late-bound regions declared in `ty` that are not
+                // declared in the trait-ref or assoc_item. These are not well-formed.
+                //
+                // Example:
+                //
+                //     for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
+                //     for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
+                let late_bound_in_projection_ty =
+                    tcx.collect_constrained_late_bound_regions(projection_ty);
+                let late_bound_in_term =
+                    tcx.collect_referenced_late_bound_regions(trait_ref.rebind(term));
+                debug!(?late_bound_in_projection_ty);
+                debug!(?late_bound_in_term);
 
-                    // FIXME: point at the type params that don't have appropriate lifetimes:
-                    // struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
-                    //                         ----  ----     ^^^^^^^
-                    // NOTE(associated_const_equality): This error should be impossible to trigger
-                    //                                  with associated const equality bounds.
-                    self.validate_late_bound_regions(
-                        late_bound_in_projection_ty,
-                        late_bound_in_term,
-                        |br_name| {
-                            struct_span_code_err!(
-                                tcx.dcx(),
-                                binding.span,
-                                E0582,
-                                "binding for associated type `{}` references {}, \
-                                 which does not appear in the trait input types",
-                                binding.ident,
-                                br_name
-                            )
-                        },
-                    );
-                }
+                // FIXME: point at the type params that don't have appropriate lifetimes:
+                // struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
+                //                         ----  ----     ^^^^^^^
+                // NOTE(associated_const_equality): This error should be impossible to trigger
+                //                                  with associated const equality bounds.
+                self.validate_late_bound_regions(
+                    late_bound_in_projection_ty,
+                    late_bound_in_term,
+                    |br_name| {
+                        struct_span_code_err!(
+                            tcx.dcx(),
+                            binding.span,
+                            E0582,
+                            "binding for associated type `{}` references {}, \
+                                which does not appear in the trait input types",
+                            binding.ident,
+                            br_name
+                        )
+                    },
+                );
 
                 // "Desugar" a constraint like `T: Iterator<Item = u32>` this to
                 // the "projection predicate" for:
diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs
index 401dd76a9f9..a912d7f578d 100644
--- a/compiler/rustc_hir_analysis/src/astconv/mod.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs
@@ -639,7 +639,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
     /// where `'a` is a bound region at depth 0. Similarly, the `poly_trait_ref` would be
     /// `Bar<'a>`. The returned poly-trait-ref will have this binder instantiated explicitly,
     /// however.
-    #[instrument(level = "debug", skip(self, span, constness, bounds, speculative))]
+    #[instrument(level = "debug", skip(self, span, constness, bounds))]
     pub(crate) fn instantiate_poly_trait_ref(
         &self,
         trait_ref: &hir::TraitRef<'tcx>,
@@ -648,7 +648,6 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
         polarity: ty::ImplPolarity,
         self_ty: Ty<'tcx>,
         bounds: &mut Bounds<'tcx>,
-        speculative: bool,
         only_self_bounds: OnlySelfBounds,
     ) -> GenericArgCountResult {
         let trait_def_id = trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise());
@@ -697,7 +696,6 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
                 poly_trait_ref,
                 binding,
                 bounds,
-                speculative,
                 &mut dup_bindings,
                 binding.span,
                 only_self_bounds,
diff --git a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs
index d97728c3303..70c60e39941 100644
--- a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs
@@ -44,7 +44,6 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
                 ty::ImplPolarity::Positive,
                 dummy_self,
                 &mut bounds,
-                false,
                 // True so we don't populate `bounds` with associated type bounds, even
                 // though they're disallowed from object types.
                 OnlySelfBounds(true),