]> git.lizzy.rs Git - rust.git/commitdiff
Simplify create_substs_for_associated_item
authorMichael Goulet <michael@errs.io>
Mon, 22 Aug 2022 04:28:40 +0000 (04:28 +0000)
committerMichael Goulet <michael@errs.io>
Mon, 22 Aug 2022 04:32:18 +0000 (04:32 +0000)
compiler/rustc_typeck/src/astconv/mod.rs
compiler/rustc_typeck/src/check/fn_ctxt/mod.rs
compiler/rustc_typeck/src/collect.rs
src/test/ui/structs/struct-path-associated-type.rs
src/test/ui/structs/struct-path-associated-type.stderr

index 6bd38c36c2c1b9ec6a27b6b78d43e1e2c3571769..7cedec8987a5713b1b8bf79c2f1055c3bc574d6f 100644 (file)
@@ -591,7 +591,6 @@ fn create_assoc_bindings_for_generic_args<'a>(
 
     pub(crate) fn create_substs_for_associated_item(
         &self,
-        tcx: TyCtxt<'tcx>,
         span: Span,
         item_def_id: DefId,
         item_segment: &hir::PathSegment<'_>,
@@ -601,22 +600,16 @@ pub(crate) fn create_substs_for_associated_item(
             "create_substs_for_associated_item(span: {:?}, item_def_id: {:?}, item_segment: {:?}",
             span, item_def_id, item_segment
         );
-        if tcx.generics_of(item_def_id).params.is_empty() {
-            self.prohibit_generics(slice::from_ref(item_segment).iter(), |_| {});
-
-            parent_substs
-        } else {
-            self.create_substs_for_ast_path(
-                span,
-                item_def_id,
-                parent_substs,
-                item_segment,
-                item_segment.args(),
-                item_segment.infer_args,
-                None,
-            )
-            .0
-        }
+        self.create_substs_for_ast_path(
+            span,
+            item_def_id,
+            parent_substs,
+            item_segment,
+            item_segment.args(),
+            item_segment.infer_args,
+            None,
+        )
+        .0
     }
 
     /// Instantiates the path for the given trait reference, assuming that it's
@@ -1129,7 +1122,6 @@ fn add_predicates_for_ast_type_binding(
             };
 
             let substs_trait_ref_and_assoc_item = self.create_substs_for_associated_item(
-                tcx,
                 path_span,
                 assoc_item.def_id,
                 &item_segment,
@@ -2105,7 +2097,6 @@ fn qpath_to_ty(
             self.ast_path_to_mono_trait_ref(span, trait_def_id, self_ty, trait_segment, false);
 
         let item_substs = self.create_substs_for_associated_item(
-            tcx,
             span,
             item_def_id,
             item_segment,
index e008d50aa514a44b3eaf892010bb8ea3c6dc0372..62a61075231aadd645e29dea51e729c9277e956c 100644 (file)
@@ -279,7 +279,6 @@ fn projected_ty_from_poly_trait_ref(
 
         let item_substs = <dyn AstConv<'tcx>>::create_substs_for_associated_item(
             self,
-            self.tcx,
             span,
             item_def_id,
             item_segment,
index 970b39dc845afbf65225a1b1e966068ef052fa5f..1048f8b1475ee2dd04a3a474142dd9f2da3a9d8a 100644 (file)
@@ -430,7 +430,6 @@ fn projected_ty_from_poly_trait_ref(
         if let Some(trait_ref) = poly_trait_ref.no_bound_vars() {
             let item_substs = <dyn AstConv<'tcx>>::create_substs_for_associated_item(
                 self,
-                self.tcx,
                 span,
                 item_def_id,
                 item_segment,
index f88572f8419c03a1590888658bc41458bb5d6100..2dd7174a9bed8e93e6cd72ec52b592fdd62f944e 100644 (file)
@@ -13,7 +13,7 @@ fn f<T: Tr>() {
     //~^ ERROR expected struct, variant or union type, found associated type
     let z = T::A::<u8> {};
     //~^ ERROR expected struct, variant or union type, found associated type
-    //~| ERROR type arguments are not allowed on this type
+    //~| ERROR this associated type takes 0 generic arguments but 1 generic argument was supplied
     match S {
         T::A {} => {}
         //~^ ERROR expected struct, variant or union type, found associated type
@@ -22,7 +22,7 @@ fn f<T: Tr>() {
 
 fn g<T: Tr<A = S>>() {
     let s = T::A {}; // OK
-    let z = T::A::<u8> {}; //~ ERROR type arguments are not allowed on this type
+    let z = T::A::<u8> {}; //~ ERROR this associated type takes 0 generic arguments but 1 generic argument was supplied
     match S {
         T::A {} => {} // OK
     }
index bdce0e1b331b89a851e086b6db39ffa1bf918cdf..abb445214f362f2d9515cc92195c0ed49870e472 100644 (file)
@@ -4,13 +4,19 @@ error[E0071]: expected struct, variant or union type, found associated type
 LL |     let s = T::A {};
    |             ^^^^ not a struct
 
-error[E0109]: type arguments are not allowed on this type
-  --> $DIR/struct-path-associated-type.rs:14:20
+error[E0107]: this associated type takes 0 generic arguments but 1 generic argument was supplied
+  --> $DIR/struct-path-associated-type.rs:14:16
    |
 LL |     let z = T::A::<u8> {};
-   |                -   ^^ type argument not allowed
+   |                ^------ help: remove these generics
    |                |
-   |                not allowed on this type
+   |                expected 0 generic arguments
+   |
+note: associated type defined here, with 0 generic parameters
+  --> $DIR/struct-path-associated-type.rs:4:10
+   |
+LL |     type A;
+   |          ^
 
 error[E0071]: expected struct, variant or union type, found associated type
   --> $DIR/struct-path-associated-type.rs:14:13
@@ -24,13 +30,19 @@ error[E0071]: expected struct, variant or union type, found associated type
 LL |         T::A {} => {}
    |         ^^^^ not a struct
 
-error[E0109]: type arguments are not allowed on this type
-  --> $DIR/struct-path-associated-type.rs:25:20
+error[E0107]: this associated type takes 0 generic arguments but 1 generic argument was supplied
+  --> $DIR/struct-path-associated-type.rs:25:16
    |
 LL |     let z = T::A::<u8> {};
-   |                -   ^^ type argument not allowed
+   |                ^------ help: remove these generics
    |                |
-   |                not allowed on this type
+   |                expected 0 generic arguments
+   |
+note: associated type defined here, with 0 generic parameters
+  --> $DIR/struct-path-associated-type.rs:4:10
+   |
+LL |     type A;
+   |          ^
 
 error[E0223]: ambiguous associated type
   --> $DIR/struct-path-associated-type.rs:32:13
@@ -52,5 +64,5 @@ LL |         S::A {} => {}
 
 error: aborting due to 8 previous errors
 
-Some errors have detailed explanations: E0071, E0109, E0223.
+Some errors have detailed explanations: E0071, E0107, E0223.
 For more information about an error, try `rustc --explain E0071`.