Skip to content

Commit 102c61f

Browse files
Simplify create_substs_for_associated_item
1 parent 6e83da1 commit 102c61f

File tree

5 files changed

+33
-32
lines changed

5 files changed

+33
-32
lines changed

compiler/rustc_typeck/src/astconv/mod.rs

+10-19
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
591591

592592
pub(crate) fn create_substs_for_associated_item(
593593
&self,
594-
tcx: TyCtxt<'tcx>,
595594
span: Span,
596595
item_def_id: DefId,
597596
item_segment: &hir::PathSegment<'_>,
@@ -601,22 +600,16 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
601600
"create_substs_for_associated_item(span: {:?}, item_def_id: {:?}, item_segment: {:?}",
602601
span, item_def_id, item_segment
603602
);
604-
if tcx.generics_of(item_def_id).params.is_empty() {
605-
self.prohibit_generics(slice::from_ref(item_segment).iter(), |_| {});
606-
607-
parent_substs
608-
} else {
609-
self.create_substs_for_ast_path(
610-
span,
611-
item_def_id,
612-
parent_substs,
613-
item_segment,
614-
item_segment.args(),
615-
item_segment.infer_args,
616-
None,
617-
)
618-
.0
619-
}
603+
self.create_substs_for_ast_path(
604+
span,
605+
item_def_id,
606+
parent_substs,
607+
item_segment,
608+
item_segment.args(),
609+
item_segment.infer_args,
610+
None,
611+
)
612+
.0
620613
}
621614

622615
/// Instantiates the path for the given trait reference, assuming that it's
@@ -1129,7 +1122,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11291122
};
11301123

11311124
let substs_trait_ref_and_assoc_item = self.create_substs_for_associated_item(
1132-
tcx,
11331125
path_span,
11341126
assoc_item.def_id,
11351127
&item_segment,
@@ -2105,7 +2097,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21052097
self.ast_path_to_mono_trait_ref(span, trait_def_id, self_ty, trait_segment, false);
21062098

21072099
let item_substs = self.create_substs_for_associated_item(
2108-
tcx,
21092100
span,
21102101
item_def_id,
21112102
item_segment,

compiler/rustc_typeck/src/check/fn_ctxt/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
279279

280280
let item_substs = <dyn AstConv<'tcx>>::create_substs_for_associated_item(
281281
self,
282-
self.tcx,
283282
span,
284283
item_def_id,
285284
item_segment,

compiler/rustc_typeck/src/collect.rs

-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
430430
if let Some(trait_ref) = poly_trait_ref.no_bound_vars() {
431431
let item_substs = <dyn AstConv<'tcx>>::create_substs_for_associated_item(
432432
self,
433-
self.tcx,
434433
span,
435434
item_def_id,
436435
item_segment,

src/test/ui/structs/struct-path-associated-type.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn f<T: Tr>() {
1313
//~^ ERROR expected struct, variant or union type, found associated type
1414
let z = T::A::<u8> {};
1515
//~^ ERROR expected struct, variant or union type, found associated type
16-
//~| ERROR type arguments are not allowed on this type
16+
//~| ERROR this associated type takes 0 generic arguments but 1 generic argument was supplied
1717
match S {
1818
T::A {} => {}
1919
//~^ ERROR expected struct, variant or union type, found associated type
@@ -22,7 +22,7 @@ fn f<T: Tr>() {
2222

2323
fn g<T: Tr<A = S>>() {
2424
let s = T::A {}; // OK
25-
let z = T::A::<u8> {}; //~ ERROR type arguments are not allowed on this type
25+
let z = T::A::<u8> {}; //~ ERROR this associated type takes 0 generic arguments but 1 generic argument was supplied
2626
match S {
2727
T::A {} => {} // OK
2828
}

src/test/ui/structs/struct-path-associated-type.stderr

+21-9
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ error[E0071]: expected struct, variant or union type, found associated type
44
LL | let s = T::A {};
55
| ^^^^ not a struct
66

7-
error[E0109]: type arguments are not allowed on this type
8-
--> $DIR/struct-path-associated-type.rs:14:20
7+
error[E0107]: this associated type takes 0 generic arguments but 1 generic argument was supplied
8+
--> $DIR/struct-path-associated-type.rs:14:16
99
|
1010
LL | let z = T::A::<u8> {};
11-
| - ^^ type argument not allowed
11+
| ^------ help: remove these generics
1212
| |
13-
| not allowed on this type
13+
| expected 0 generic arguments
14+
|
15+
note: associated type defined here, with 0 generic parameters
16+
--> $DIR/struct-path-associated-type.rs:4:10
17+
|
18+
LL | type A;
19+
| ^
1420

1521
error[E0071]: expected struct, variant or union type, found associated type
1622
--> $DIR/struct-path-associated-type.rs:14:13
@@ -24,13 +30,19 @@ error[E0071]: expected struct, variant or union type, found associated type
2430
LL | T::A {} => {}
2531
| ^^^^ not a struct
2632

27-
error[E0109]: type arguments are not allowed on this type
28-
--> $DIR/struct-path-associated-type.rs:25:20
33+
error[E0107]: this associated type takes 0 generic arguments but 1 generic argument was supplied
34+
--> $DIR/struct-path-associated-type.rs:25:16
2935
|
3036
LL | let z = T::A::<u8> {};
31-
| - ^^ type argument not allowed
37+
| ^------ help: remove these generics
3238
| |
33-
| not allowed on this type
39+
| expected 0 generic arguments
40+
|
41+
note: associated type defined here, with 0 generic parameters
42+
--> $DIR/struct-path-associated-type.rs:4:10
43+
|
44+
LL | type A;
45+
| ^
3446

3547
error[E0223]: ambiguous associated type
3648
--> $DIR/struct-path-associated-type.rs:32:13
@@ -52,5 +64,5 @@ LL | S::A {} => {}
5264

5365
error: aborting due to 8 previous errors
5466

55-
Some errors have detailed explanations: E0071, E0109, E0223.
67+
Some errors have detailed explanations: E0071, E0107, E0223.
5668
For more information about an error, try `rustc --explain E0071`.

0 commit comments

Comments
 (0)