format!(", {}", type_name),
));
}
- let mut err = struct_span_err!(
- tcx.sess,
- placeholder_types.clone(),
- E0121,
- "the type placeholder `_` is not allowed within types on item signatures",
- );
- for span in &placeholder_types {
- err.span_label(*span, "not allowed in type signatures");
- }
+ let mut err = bad_placeholder_type(tcx, placeholder_types);
if suggest {
err.multipart_suggestion(
"use type parameters instead",
hir::ItemKind::Union(_, generics)
| hir::ItemKind::Enum(_, generics)
| hir::ItemKind::Struct(_, generics) => (&generics.params[..], true),
- hir::ItemKind::Static(ty, ..) => {
- if let hir::TyKind::Infer = ty.kind {
- return; // We handle it elsewhere to attempt to suggest an appropriate type.
- } else {
- (&[][..], false)
- }
- }
hir::ItemKind::TyAlias(_, generics) => (&generics.params[..], false),
+ // hir::ItemKind::Static(ty, ..) => {
// hir::ItemKind::Fn(..) |
// hir::ItemKind::Const(..) => {} // We handle these elsewhere to suggest appropriate type.
_ => return,
///////////////////////////////////////////////////////////////////////////
// Utility types and common code for the above passes.
-fn bad_placeholder_type(tcx: TyCtxt<'tcx>, span: Span) -> errors::DiagnosticBuilder<'tcx> {
- let mut diag = struct_span_err!(
+fn bad_placeholder_type(
+ tcx: TyCtxt<'tcx>,
+ mut spans: Vec<Span>,
+) -> errors::DiagnosticBuilder<'tcx> {
+ spans.sort();
+ let mut err = struct_span_err!(
tcx.sess,
- span,
+ spans.clone(),
E0121,
"the type placeholder `_` is not allowed within types on item signatures",
);
- diag.span_label(span, "not allowed in type signatures");
- diag
+ for span in spans {
+ err.span_label(span, "not allowed in type signatures");
+ }
+ err
}
impl ItemCtxt<'tcx> {
}
fn ty_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
- self.tcx().sess.delay_span_bug(span, "bad placeholder type, but no error was emitted");
+ self.tcx().sess.delay_span_bug(span, "bad placeholder type");
self.tcx().types.err
}
_: Option<&ty::GenericParamDef>,
span: Span,
) -> &'tcx Const<'tcx> {
- bad_placeholder_type(self.tcx(), span).emit();
+ bad_placeholder_type(self.tcx(), vec![span]).emit();
self.tcx().consts.err
}
span: Span,
item_ident: Ident,
) -> Ty<'_> {
- let ty = tcx.typeck_tables_of(def_id).node_type(body_id.hir_id);
+ let ty = tcx.diagnostic_only_typeck_tables_of(def_id).node_type(body_id.hir_id);
// If this came from a free `const` or `static mut?` item,
// then the user may have written e.g. `const A = 42;`.
.emit();
}
None => {
- let mut diag = bad_placeholder_type(tcx, span);
+ let mut diag = bad_placeholder_type(tcx, vec![span]);
if ty != tcx.types.err {
diag.span_suggestion(
span,
}
TraitItemKind::Const(ref ty, body_id) => body_id
.and_then(|body_id| {
- if let hir::TyKind::Infer = ty.kind {
+ if is_infer_ty(ty) {
Some(infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident))
- } else if is_infer_ty(ty) {
- // Infering this would cause a cycle error.
- tcx.sess.delay_span_bug(ty.span, "`_` placeholder but no error emitted");
- Some(tcx.types.err)
} else {
None
}
tcx.mk_fn_def(def_id, substs)
}
ImplItemKind::Const(ref ty, body_id) => {
- if let hir::TyKind::Infer = ty.kind {
+ if is_infer_ty(ty) {
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident)
- } else if is_infer_ty(ty) {
- // Infering this would cause a cycle error.
- tcx.sess.delay_span_bug(ty.span, "`_` placeholder but no error emitted");
- tcx.types.err
} else {
icx.to_ty(ty)
}
Node::Item(item) => {
match item.kind {
ItemKind::Static(ref ty, .., body_id) | ItemKind::Const(ref ty, body_id) => {
- if let hir::TyKind::Infer = ty.kind {
+ if is_infer_ty(ty) {
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident)
- } else if is_infer_ty(ty) {
- // Infering this would cause a cycle error.
- tcx.sess.delay_span_bug(ty.span, "`_` placeholder but no error emitted");
- tcx.types.err
} else {
icx.to_ty(ty)
}
hir::TyKind::Slice(ty) | hir::TyKind::Array(ty, _) => is_infer_ty(ty),
hir::TyKind::Tup(tys)
if !tys.is_empty()
- && tys.iter().all(|ty| match ty.kind {
+ && tys.iter().any(|ty| match ty.kind {
hir::TyKind::Infer => true,
_ => false,
}) =>
match get_infer_ret_ty(&sig.decl.output) {
Some(ty) => {
let fn_sig = tcx.typeck_tables_of(def_id).liberated_fn_sigs()[hir_id];
- let mut diag = bad_placeholder_type(tcx, ty.span);
+ let mut visitor = PlaceholderHirTyCollector::new();
+ visitor.visit_ty(ty);
+ let mut diag = bad_placeholder_type(tcx, visitor.0);
let ret_ty = fn_sig.output();
if ret_ty != tcx.types.err {
diag.span_suggestion(
ty.span,
- "replace this with the correct return type",
+ "replace with the correct return type",
ret_ty.to_string(),
Applicability::MaybeIncorrect,
);
| ^
| |
| not allowed in type signatures
- | help: replace this with the correct return type: `i32`
+ | help: replace with the correct return type: `i32`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:7:15
+ --> $DIR/typeck_type_placeholder_item.rs:7:16
|
LL | fn test2() -> (_, _) { (5, 5) }
- | ^^^^^^
- | |
- | not allowed in type signatures
- | help: replace this with the correct return type: `(i32, i32)`
+ | -^--^-
+ | || |
+ | || not allowed in type signatures
+ | |not allowed in type signatures
+ | help: replace with the correct return type: `(i32, i32)`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:10:15
| help: replace `_` with the correct type: `i32`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:16:16
+ --> $DIR/typeck_type_placeholder_item.rs:16:15
|
LL | static TEST5: (_, _) = (1, 2);
- | ^ ^ not allowed in type signatures
- | |
- | not allowed in type signatures
+ | ^^^^^^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:19:13
LL | fn test7<T>(x: T) { let _x: usize = x; }
| ^^^ ^
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures
+ --> $DIR/typeck_type_placeholder_item.rs:31:22
+ |
+LL | fn test8(_f: fn() -> _) { }
+ | ^ not allowed in type signatures
+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:31:22
|
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:53:8
+ --> $DIR/typeck_type_placeholder_item.rs:54:8
|
LL | a: _,
| ^ not allowed in type signatures
|
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:59:21
+ --> $DIR/typeck_type_placeholder_item.rs:60:21
|
LL | fn fn_test() -> _ { 5 }
| ^
| |
| not allowed in type signatures
- | help: replace this with the correct return type: `i32`
+ | help: replace with the correct return type: `i32`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:62:22
+ --> $DIR/typeck_type_placeholder_item.rs:63:23
|
LL | fn fn_test2() -> (_, _) { (5, 5) }
- | ^^^^^^
- | |
- | not allowed in type signatures
- | help: replace this with the correct return type: `(i32, i32)`
+ | -^--^-
+ | || |
+ | || not allowed in type signatures
+ | |not allowed in type signatures
+ | help: replace with the correct return type: `(i32, i32)`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:65:22
+ --> $DIR/typeck_type_placeholder_item.rs:66:22
|
LL | static FN_TEST3: _ = "test";
| ^
| help: replace `_` with the correct type: `&'static str`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:68:22
+ --> $DIR/typeck_type_placeholder_item.rs:69:22
|
LL | static FN_TEST4: _ = 145;
| ^
| help: replace `_` with the correct type: `i32`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:71:23
+ --> $DIR/typeck_type_placeholder_item.rs:72:22
|
LL | static FN_TEST5: (_, _) = (1, 2);
- | ^ ^ not allowed in type signatures
- | |
- | not allowed in type signatures
+ | ^^^^^^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:74:20
+ --> $DIR/typeck_type_placeholder_item.rs:75:20
|
LL | fn fn_test6(_: _) { }
| ^ not allowed in type signatures
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:77:20
+ --> $DIR/typeck_type_placeholder_item.rs:78:20
|
LL | fn fn_test7(x: _) { let _x: usize = x; }
| ^ not allowed in type signatures
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:80:29
+ --> $DIR/typeck_type_placeholder_item.rs:81:29
+ |
+LL | fn fn_test8(_f: fn() -> _) { }
+ | ^ not allowed in type signatures
+
+error[E0121]: the type placeholder `_` is not allowed within types on item signatures
+ --> $DIR/typeck_type_placeholder_item.rs:81:29
|
LL | fn fn_test8(_f: fn() -> _) { }
| ^ not allowed in type signatures
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:102:12
+ --> $DIR/typeck_type_placeholder_item.rs:104:12
|
LL | a: _,
| ^ not allowed in type signatures
|
error[E0282]: type annotations needed
- --> $DIR/typeck_type_placeholder_item.rs:107:27
+ --> $DIR/typeck_type_placeholder_item.rs:109:27
|
LL | fn fn_test11(_: _) -> (_, _) { panic!() }
| ^^^^^^ cannot infer type
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:107:27
+ --> $DIR/typeck_type_placeholder_item.rs:109:28
|
LL | fn fn_test11(_: _) -> (_, _) { panic!() }
- | ^^^^^^ not allowed in type signatures
+ | ^ ^ not allowed in type signatures
+ | |
+ | not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:111:29
+ --> $DIR/typeck_type_placeholder_item.rs:113:30
|
LL | fn fn_test12(x: i32) -> (_, _) { (x, x) }
- | ^^^^^^
- | |
- | not allowed in type signatures
- | help: replace this with the correct return type: `(i32, i32)`
+ | -^--^-
+ | || |
+ | || not allowed in type signatures
+ | |not allowed in type signatures
+ | help: replace with the correct return type: `(i32, i32)`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:114:21
+ --> $DIR/typeck_type_placeholder_item.rs:116:33
|
LL | fn fn_test13(x: _) -> (i32, _) { (x, x) }
- | ^ ^ not allowed in type signatures
- | |
- | not allowed in type signatures
- |
-help: use type parameters instead
- |
-LL | fn fn_test13<T>(x: T) -> (i32, T) { (x, x) }
- | ^^^ ^ ^
+ | ------^-
+ | | |
+ | | not allowed in type signatures
+ | help: replace with the correct return type: `(i32, i32)`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:119:31
+ --> $DIR/typeck_type_placeholder_item.rs:121:31
|
LL | fn method_test1(&self, x: _);
| ^ not allowed in type signatures
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:121:31
+ --> $DIR/typeck_type_placeholder_item.rs:123:31
|
LL | fn method_test2(&self, x: _) -> _;
| ^ ^ not allowed in type signatures
| ^^^ ^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:123:31
+ --> $DIR/typeck_type_placeholder_item.rs:125:31
|
LL | fn method_test3(&self) -> _;
| ^ not allowed in type signatures
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:125:26
+ --> $DIR/typeck_type_placeholder_item.rs:127:26
|
LL | fn assoc_fn_test1(x: _);
| ^ not allowed in type signatures
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:127:26
+ --> $DIR/typeck_type_placeholder_item.rs:129:26
|
LL | fn assoc_fn_test2(x: _) -> _;
| ^ ^ not allowed in type signatures
| ^^^ ^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:129:28
+ --> $DIR/typeck_type_placeholder_item.rs:131:28
|
LL | fn assoc_fn_test3() -> _;
| ^ not allowed in type signatures
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:37:24
+ --> $DIR/typeck_type_placeholder_item.rs:38:24
|
LL | fn test9(&self) -> _ { () }
| ^
| |
| not allowed in type signatures
- | help: replace this with the correct return type: `()`
+ | help: replace with the correct return type: `()`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:40:27
+ --> $DIR/typeck_type_placeholder_item.rs:41:27
|
LL | fn test10(&self, _x : _) { }
| ^ not allowed in type signatures
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:45:24
+ --> $DIR/typeck_type_placeholder_item.rs:46:24
|
LL | fn clone(&self) -> _ { Test9 }
| ^
| |
| not allowed in type signatures
- | help: replace this with the correct return type: `Test9`
+ | help: replace with the correct return type: `Test9`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:48:37
+ --> $DIR/typeck_type_placeholder_item.rs:49:37
|
LL | fn clone_from(&mut self, other: _) { *self = Test9; }
| ^ not allowed in type signatures
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:86:31
+ --> $DIR/typeck_type_placeholder_item.rs:88:31
|
LL | fn fn_test9(&self) -> _ { () }
| ^
| |
| not allowed in type signatures
- | help: replace this with the correct return type: `()`
+ | help: replace with the correct return type: `()`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:89:34
+ --> $DIR/typeck_type_placeholder_item.rs:91:34
|
LL | fn fn_test10(&self, _x : _) { }
| ^ not allowed in type signatures
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:94:28
+ --> $DIR/typeck_type_placeholder_item.rs:96:28
|
LL | fn clone(&self) -> _ { FnTest9 }
| ^
| |
| not allowed in type signatures
- | help: replace this with the correct return type: `main::FnTest9`
+ | help: replace with the correct return type: `main::FnTest9`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
- --> $DIR/typeck_type_placeholder_item.rs:97:41
+ --> $DIR/typeck_type_placeholder_item.rs:99:41
|
LL | fn clone_from(&mut self, other: _) { *self = FnTest9; }
| ^ not allowed in type signatures
LL | fn clone_from<T>(&mut self, other: T) { *self = FnTest9; }
| ^^^ ^
-error: aborting due to 38 previous errors
+error: aborting due to 40 previous errors
Some errors have detailed explanations: E0121, E0282.
For more information about an error, try `rustc --explain E0121`.