Skip to content

Commit c150ce6

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35434 - intrepion:fix-compile-fail-e0121, r=jonathandturner
Fixing compiler error E0121 Fixes rust-lang#35254 and part of rust-lang#35233
2 parents 1c203e3 + 6eba89e commit c150ce6

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/librustc_typeck/collect.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,13 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
367367
_substs: Option<&mut Substs<'tcx>>,
368368
_space: Option<ParamSpace>,
369369
span: Span) -> Ty<'tcx> {
370-
span_err!(self.tcx().sess, span, E0121,
371-
"the type placeholder `_` is not allowed within types on item signatures");
370+
struct_span_err!(
371+
self.tcx().sess,
372+
span,
373+
E0121,
374+
"the type placeholder `_` is not allowed within types on item signatures"
375+
).span_label(span, &format!("not allowed in type signatures"))
376+
.emit();
372377
self.tcx().types.err
373378
}
374379

src/test/compile-fail/typeck_type_placeholder_item.rs

+34
Original file line numberDiff line numberDiff line change
@@ -13,107 +13,141 @@
1313

1414
fn test() -> _ { 5 }
1515
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
16+
//~| NOTE not allowed in type signatures
1617

1718
fn test2() -> (_, _) { (5, 5) }
1819
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
1920
//~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
21+
//~| NOTE not allowed in type signatures
22+
//~| NOTE not allowed in type signatures
2023

2124
static TEST3: _ = "test";
2225
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
26+
//~| NOTE not allowed in type signatures
2327

2428
static TEST4: _ = 145;
2529
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
30+
//~| NOTE not allowed in type signatures
2631

2732
static TEST5: (_, _) = (1, 2);
2833
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
2934
//~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
35+
//~| NOTE not allowed in type signatures
36+
//~| NOTE not allowed in type signatures
3037

3138
fn test6(_: _) { }
3239
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
40+
//~| NOTE not allowed in type signatures
3341

3442
fn test7(x: _) { let _x: usize = x; }
3543
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
44+
//~| NOTE not allowed in type signatures
3645

3746
fn test8(_f: fn() -> _) { }
3847
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
48+
//~| NOTE not allowed in type signatures
3949

4050
struct Test9;
4151

4252
impl Test9 {
4353
fn test9(&self) -> _ { () }
4454
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
55+
//~| NOTE not allowed in type signatures
4556

4657
fn test10(&self, _x : _) { }
4758
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
59+
//~| NOTE not allowed in type signatures
4860
}
4961

5062
impl Clone for Test9 {
5163
fn clone(&self) -> _ { Test9 }
5264
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
65+
//~| NOTE not allowed in type signatures
5366

5467
fn clone_from(&mut self, other: _) { *self = Test9; }
5568
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
69+
//~| NOTE not allowed in type signatures
5670
}
5771

5872
struct Test10 {
5973
a: _,
6074
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
75+
//~| NOTE not allowed in type signatures
6176
b: (_, _),
6277
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
6378
//~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
79+
//~| NOTE not allowed in type signatures
80+
//~| NOTE not allowed in type signatures
6481
}
6582

6683
pub fn main() {
6784
fn fn_test() -> _ { 5 }
6885
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
86+
//~| NOTE not allowed in type signatures
6987

7088
fn fn_test2() -> (_, _) { (5, 5) }
7189
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
7290
//~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
91+
//~| NOTE not allowed in type signatures
92+
//~| NOTE not allowed in type signatures
7393

7494
static FN_TEST3: _ = "test";
7595
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
96+
//~| NOTE not allowed in type signatures
7697

7798
static FN_TEST4: _ = 145;
7899
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
100+
//~| NOTE not allowed in type signatures
79101

80102
static FN_TEST5: (_, _) = (1, 2);
81103
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
82104
//~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
105+
//~| NOTE not allowed in type signatures
106+
//~| NOTE not allowed in type signatures
83107

84108
fn fn_test6(_: _) { }
85109
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
110+
//~| NOTE not allowed in type signatures
86111

87112
fn fn_test7(x: _) { let _x: usize = x; }
88113
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
114+
//~| NOTE not allowed in type signatures
89115

90116
fn fn_test8(_f: fn() -> _) { }
91117
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
118+
//~| NOTE not allowed in type signatures
92119

93120
struct FnTest9;
94121

95122
impl FnTest9 {
96123
fn fn_test9(&self) -> _ { () }
97124
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
125+
//~| NOTE not allowed in type signatures
98126

99127
fn fn_test10(&self, _x : _) { }
100128
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
129+
//~| NOTE not allowed in type signatures
101130
}
102131

103132
impl Clone for FnTest9 {
104133
fn clone(&self) -> _ { FnTest9 }
105134
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
135+
//~| NOTE not allowed in type signatures
106136

107137
fn clone_from(&mut self, other: _) { *self = FnTest9; }
108138
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
139+
//~| NOTE not allowed in type signatures
109140
}
110141

111142
struct FnTest10 {
112143
a: _,
113144
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
145+
//~| NOTE not allowed in type signatures
114146
b: (_, _),
115147
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
116148
//~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
149+
//~| NOTE not allowed in type signatures
150+
//~| NOTE not allowed in type signatures
117151
}
118152

119153
}

0 commit comments

Comments
 (0)