Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 12cc9b4

Browse files
authoredJan 3, 2025
Rollup merge of #135044 - compiler-errors:better-infer-suggestions-in-const, r=oli-obk
Improve infer (`_`) suggestions in `const`s and `static`s Fixes #135010. This PR does a few things to (imo) greatly improve the error message when users write something like `static FOO: [i32; _] = [1, 2, 3]`. Firstly, it adapts the recovery code for when we encounter `_` in a const/static to work a bit more like `fn foo() -> _`, and removes the somewhat redundant query `diagnostic_only_typeck`. Secondly, it changes the lowering for `[T; _]` to always lower under the `feature(generic_arg_infer)` logic to `ConstArgKind::Infer`. We still issue the feature error, so it's not doing anything *observable* on the good path, but it does mean that we no longer erroneously interpret `[T; _]`'s array length as a `_` **wildcard expression** (à la destructuring assignment, like `(_, y) = expr`). Lastly it makes the suggestions verbose and fixes (well, suppresses) a bug with stashing and suggestions. r? oli-obk
2 parents f0c03f6 + 0fd64ef commit 12cc9b4

33 files changed

+388
-316
lines changed
 

‎compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,20 +2031,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20312031
fn lower_array_length_to_const_arg(&mut self, c: &AnonConst) -> &'hir hir::ConstArg<'hir> {
20322032
match c.value.kind {
20332033
ExprKind::Underscore => {
2034-
if self.tcx.features().generic_arg_infer() {
2035-
let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span));
2036-
self.arena
2037-
.alloc(hir::ConstArg { hir_id: self.lower_node_id(c.id), kind: ct_kind })
2038-
} else {
2034+
if !self.tcx.features().generic_arg_infer() {
20392035
feature_err(
20402036
&self.tcx.sess,
20412037
sym::generic_arg_infer,
20422038
c.value.span,
20432039
fluent_generated::ast_lowering_underscore_array_length_unstable,
20442040
)
20452041
.stash(c.value.span, StashKey::UnderscoreForArrayLengths);
2046-
self.lower_anon_const_to_const_arg(c)
20472042
}
2043+
let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span));
2044+
self.arena.alloc(hir::ConstArg { hir_id: self.lower_node_id(c.id), kind: ct_kind })
20482045
}
20492046
_ => self.lower_anon_const_to_const_arg(c),
20502047
}

‎compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3387,7 +3387,7 @@ impl<'hir> FnRetTy<'hir> {
33873387
}
33883388
}
33893389

3390-
pub fn get_infer_ret_ty(&self) -> Option<&'hir Ty<'hir>> {
3390+
pub fn is_suggestable_infer_ty(&self) -> Option<&'hir Ty<'hir>> {
33913391
if let Self::Return(ty) = self {
33923392
if ty.is_suggestable_infer_ty() {
33933393
return Some(*ty);

‎compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,25 @@ pub struct ItemCtxt<'tcx> {
131131
///////////////////////////////////////////////////////////////////////////
132132

133133
#[derive(Default)]
134-
pub(crate) struct HirPlaceholderCollector(pub(crate) Vec<Span>);
134+
pub(crate) struct HirPlaceholderCollector {
135+
pub spans: Vec<Span>,
136+
// If any of the spans points to a const infer var, then suppress any messages
137+
// that may try to turn that const infer into a type parameter.
138+
pub may_contain_const_infer: bool,
139+
}
135140

136141
impl<'v> Visitor<'v> for HirPlaceholderCollector {
137142
fn visit_ty(&mut self, t: &'v hir::Ty<'v>) {
138143
if let hir::TyKind::Infer = t.kind {
139-
self.0.push(t.span);
144+
self.spans.push(t.span);
140145
}
141146
intravisit::walk_ty(self, t)
142147
}
143148
fn visit_generic_arg(&mut self, generic_arg: &'v hir::GenericArg<'v>) {
144149
match generic_arg {
145150
hir::GenericArg::Infer(inf) => {
146-
self.0.push(inf.span);
151+
self.spans.push(inf.span);
152+
self.may_contain_const_infer = true;
147153
intravisit::walk_inf(self, inf);
148154
}
149155
hir::GenericArg::Type(t) => self.visit_ty(t),
@@ -152,7 +158,8 @@ impl<'v> Visitor<'v> for HirPlaceholderCollector {
152158
}
153159
fn visit_const_arg(&mut self, const_arg: &'v hir::ConstArg<'v>) {
154160
if let hir::ConstArgKind::Infer(span) = const_arg.kind {
155-
self.0.push(span);
161+
self.may_contain_const_infer = true;
162+
self.spans.push(span);
156163
}
157164
intravisit::walk_const_arg(self, const_arg)
158165
}
@@ -277,8 +284,8 @@ fn reject_placeholder_type_signatures_in_item<'tcx>(
277284
placeholder_type_error(
278285
icx.lowerer(),
279286
Some(generics),
280-
visitor.0,
281-
suggest,
287+
visitor.spans,
288+
suggest && !visitor.may_contain_const_infer,
282289
None,
283290
item.kind.descr(),
284291
);
@@ -607,16 +614,16 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
607614
hir::FnRetTy::DefaultReturn(..) => tcx.types.unit,
608615
};
609616

610-
if !(visitor.0.is_empty() && infer_replacements.is_empty()) {
617+
if !(visitor.spans.is_empty() && infer_replacements.is_empty()) {
611618
// We check for the presence of
612619
// `ident_span` to not emit an error twice when we have `fn foo(_: fn() -> _)`.
613620

614621
let mut diag = crate::collect::placeholder_type_error_diag(
615622
self,
616623
generics,
617-
visitor.0,
624+
visitor.spans,
618625
infer_replacements.iter().map(|(s, _)| *s).collect(),
619-
true,
626+
!visitor.may_contain_const_infer,
620627
hir_ty,
621628
"function",
622629
);
@@ -712,7 +719,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
712719
placeholder_type_error(
713720
icx.lowerer(),
714721
None,
715-
visitor.0,
722+
visitor.spans,
716723
false,
717724
None,
718725
"static variable",
@@ -780,7 +787,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
780787
placeholder_type_error(
781788
icx.lowerer(),
782789
None,
783-
visitor.0,
790+
visitor.spans,
784791
false,
785792
None,
786793
it.kind.descr(),
@@ -822,7 +829,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
822829
placeholder_type_error(
823830
icx.lowerer(),
824831
None,
825-
visitor.0,
832+
visitor.spans,
826833
false,
827834
None,
828835
"associated constant",
@@ -837,7 +844,14 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
837844
// Account for `type T = _;`.
838845
let mut visitor = HirPlaceholderCollector::default();
839846
visitor.visit_trait_item(trait_item);
840-
placeholder_type_error(icx.lowerer(), None, visitor.0, false, None, "associated type");
847+
placeholder_type_error(
848+
icx.lowerer(),
849+
None,
850+
visitor.spans,
851+
false,
852+
None,
853+
"associated type",
854+
);
841855
}
842856

843857
hir::TraitItemKind::Type(_, None) => {
@@ -848,7 +862,14 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
848862
let mut visitor = HirPlaceholderCollector::default();
849863
visitor.visit_trait_item(trait_item);
850864

851-
placeholder_type_error(icx.lowerer(), None, visitor.0, false, None, "associated type");
865+
placeholder_type_error(
866+
icx.lowerer(),
867+
None,
868+
visitor.spans,
869+
false,
870+
None,
871+
"associated type",
872+
);
852873
}
853874
};
854875

@@ -872,7 +893,14 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
872893
let mut visitor = HirPlaceholderCollector::default();
873894
visitor.visit_impl_item(impl_item);
874895

875-
placeholder_type_error(icx.lowerer(), None, visitor.0, false, None, "associated type");
896+
placeholder_type_error(
897+
icx.lowerer(),
898+
None,
899+
visitor.spans,
900+
false,
901+
None,
902+
"associated type",
903+
);
876904
}
877905
hir::ImplItemKind::Const(ty, _) => {
878906
// Account for `const T: _ = ..;`
@@ -882,7 +910,7 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
882910
placeholder_type_error(
883911
icx.lowerer(),
884912
None,
885-
visitor.0,
913+
visitor.spans,
886914
false,
887915
None,
888916
"associated constant",
@@ -1371,7 +1399,7 @@ fn lower_fn_sig_recovering_infer_ret_ty<'tcx>(
13711399
generics: &'tcx hir::Generics<'tcx>,
13721400
def_id: LocalDefId,
13731401
) -> ty::PolyFnSig<'tcx> {
1374-
if let Some(infer_ret_ty) = sig.decl.output.get_infer_ret_ty() {
1402+
if let Some(infer_ret_ty) = sig.decl.output.is_suggestable_infer_ty() {
13751403
return recover_infer_ret_ty(icx, infer_ret_ty, generics, def_id);
13761404
}
13771405

@@ -1422,7 +1450,7 @@ fn recover_infer_ret_ty<'tcx>(
14221450
let mut visitor = HirPlaceholderCollector::default();
14231451
visitor.visit_ty(infer_ret_ty);
14241452

1425-
let mut diag = bad_placeholder(icx.lowerer(), visitor.0, "return type");
1453+
let mut diag = bad_placeholder(icx.lowerer(), visitor.spans, "return type");
14261454
let ret_ty = fn_sig.output();
14271455

14281456
// Don't leak types into signatures unless they're nameable!

‎compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_errors::{Applicability, StashKey, Suggestions};
44
use rustc_hir as hir;
55
use rustc_hir::HirId;
66
use rustc_hir::def_id::{DefId, LocalDefId};
7+
use rustc_hir::intravisit::Visitor;
78
use rustc_middle::query::plumbing::CyclePlaceholder;
89
use rustc_middle::ty::fold::fold_regions;
910
use rustc_middle::ty::print::with_forced_trimmed_paths;
@@ -12,7 +13,7 @@ use rustc_middle::ty::{self, Article, IsSuggestable, Ty, TyCtxt, TypeVisitableEx
1213
use rustc_middle::{bug, span_bug};
1314
use rustc_span::{DUMMY_SP, Ident, Span};
1415

15-
use super::{ItemCtxt, bad_placeholder};
16+
use super::{HirPlaceholderCollector, ItemCtxt, bad_placeholder};
1617
use crate::errors::TypeofReservedKeywordUsed;
1718
use crate::hir_ty_lowering::HirTyLowerer;
1819

@@ -412,7 +413,7 @@ fn infer_placeholder_type<'tcx>(
412413
kind: &'static str,
413414
) -> Ty<'tcx> {
414415
let tcx = cx.tcx();
415-
let ty = tcx.diagnostic_only_typeck(def_id).node_type(body_id.hir_id);
416+
let ty = tcx.typeck(def_id).node_type(body_id.hir_id);
416417

417418
// If this came from a free `const` or `static mut?` item,
418419
// then the user may have written e.g. `const A = 42;`.
@@ -447,13 +448,37 @@ fn infer_placeholder_type<'tcx>(
447448
}
448449
})
449450
.unwrap_or_else(|| {
450-
let mut diag = bad_placeholder(cx, vec![span], kind);
451-
452-
if !ty.references_error() {
451+
let mut visitor = HirPlaceholderCollector::default();
452+
let node = tcx.hir_node_by_def_id(def_id);
453+
if let Some(ty) = node.ty() {
454+
visitor.visit_ty(ty);
455+
}
456+
// If we have just one span, let's try to steal a const `_` feature error.
457+
let try_steal_span = if !tcx.features().generic_arg_infer() && visitor.spans.len() == 1
458+
{
459+
visitor.spans.first().copied()
460+
} else {
461+
None
462+
};
463+
// If we didn't find any infer tys, then just fallback to `span`.
464+
if visitor.spans.is_empty() {
465+
visitor.spans.push(span);
466+
}
467+
let mut diag = bad_placeholder(cx, visitor.spans, kind);
468+
469+
// HACK(#69396): Stashing and stealing diagnostics does not interact
470+
// well with macros which may delay more than one diagnostic on the
471+
// same span. If this happens, we will fall through to this arm, so
472+
// we need to suppress the suggestion since it's invalid. Ideally we
473+
// would suppress the duplicated error too, but that's really hard.
474+
if span.is_empty() && span.from_expansion() {
475+
// An approximately better primary message + no suggestion...
476+
diag.primary_message("missing type for item");
477+
} else if !ty.references_error() {
453478
if let Some(ty) = ty.make_suggestable(tcx, false, None) {
454-
diag.span_suggestion(
479+
diag.span_suggestion_verbose(
455480
span,
456-
"replace with the correct type",
481+
"replace this with a fully-specified type",
457482
ty,
458483
Applicability::MachineApplicable,
459484
);
@@ -464,7 +489,16 @@ fn infer_placeholder_type<'tcx>(
464489
));
465490
}
466491
}
467-
diag.emit()
492+
493+
if let Some(try_steal_span) = try_steal_span {
494+
cx.dcx().try_steal_replace_and_emit_err(
495+
try_steal_span,
496+
StashKey::UnderscoreForArrayLengths,
497+
diag,
498+
)
499+
} else {
500+
diag.emit()
501+
}
468502
});
469503
Ty::new_error(tcx, guar)
470504
}

‎compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl TaitConstraintLocator<'_> {
187187
"foreign items cannot constrain opaque types",
188188
);
189189
if let Some(hir_sig) = hir_node.fn_sig()
190-
&& hir_sig.decl.output.get_infer_ret_ty().is_some()
190+
&& hir_sig.decl.output.is_suggestable_infer_ty().is_some()
191191
{
192192
let guar = self.tcx.dcx().span_delayed_bug(
193193
hir_sig.decl.output.span(),

‎compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,12 +1771,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17711771
let parent_node = self.tcx.hir().parent_iter(expr.hir_id).find(|(_, node)| {
17721772
!matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::AddrOf(..), .. }))
17731773
});
1774-
let Some((
1775-
_,
1776-
hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), .. })
1777-
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _, _), .. }),
1778-
)) = parent_node
1779-
else {
1774+
let Some((_, hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), .. }))) = parent_node else {
17801775
return;
17811776
};
17821777
if let hir::TyKind::Array(_, ct) = ty.peel_refs().kind {

‎compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,7 @@ fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet<LocalDef
8787
}
8888

8989
fn typeck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
90-
let fallback = move || tcx.type_of(def_id.to_def_id()).instantiate_identity();
91-
typeck_with_fallback(tcx, def_id, fallback, None)
92-
}
93-
94-
/// Used only to get `TypeckResults` for type inference during error recovery.
95-
/// Currently only used for type inference of `static`s and `const`s to avoid type cycle errors.
96-
fn diagnostic_only_typeck<'tcx>(
97-
tcx: TyCtxt<'tcx>,
98-
def_id: LocalDefId,
99-
) -> &'tcx ty::TypeckResults<'tcx> {
100-
let fallback = move || {
101-
let span = tcx.hir().span(tcx.local_def_id_to_hir_id(def_id));
102-
Ty::new_error_with_message(tcx, span, "diagnostic only typeck table used")
103-
};
104-
typeck_with_fallback(tcx, def_id, fallback, None)
90+
typeck_with_fallback(tcx, def_id, None)
10591
}
10692

10793
/// Same as `typeck` but `inspect` is invoked on evaluation of each root obligation.
@@ -113,15 +99,13 @@ pub fn inspect_typeck<'tcx>(
11399
def_id: LocalDefId,
114100
inspect: ObligationInspector<'tcx>,
115101
) -> &'tcx ty::TypeckResults<'tcx> {
116-
let fallback = move || tcx.type_of(def_id.to_def_id()).instantiate_identity();
117-
typeck_with_fallback(tcx, def_id, fallback, Some(inspect))
102+
typeck_with_fallback(tcx, def_id, Some(inspect))
118103
}
119104

120-
#[instrument(level = "debug", skip(tcx, fallback, inspector), ret)]
105+
#[instrument(level = "debug", skip(tcx, inspector), ret)]
121106
fn typeck_with_fallback<'tcx>(
122107
tcx: TyCtxt<'tcx>,
123108
def_id: LocalDefId,
124-
fallback: impl Fn() -> Ty<'tcx> + 'tcx,
125109
inspector: Option<ObligationInspector<'tcx>>,
126110
) -> &'tcx ty::TypeckResults<'tcx> {
127111
// Closures' typeck results come from their outermost function,
@@ -150,7 +134,11 @@ fn typeck_with_fallback<'tcx>(
150134
let mut fcx = FnCtxt::new(&root_ctxt, param_env, def_id);
151135

152136
if let Some(hir::FnSig { header, decl, .. }) = node.fn_sig() {
153-
let fn_sig = if decl.output.get_infer_ret_ty().is_some() {
137+
let fn_sig = if decl.output.is_suggestable_infer_ty().is_some() {
138+
// In the case that we're recovering `fn() -> W<_>` or some other return
139+
// type that has an infer in it, lower the type directly so that it'll
140+
// be correctly filled with infer. We'll use this inference to provide
141+
// a suggestion later on.
154142
fcx.lowerer().lower_fn_ty(id, header.safety, header.abi, decl, None, None)
155143
} else {
156144
tcx.fn_sig(def_id).instantiate_identity()
@@ -164,8 +152,19 @@ fn typeck_with_fallback<'tcx>(
164152

165153
check_fn(&mut fcx, fn_sig, None, decl, def_id, body, tcx.features().unsized_fn_params());
166154
} else {
167-
let expected_type = infer_type_if_missing(&fcx, node);
168-
let expected_type = expected_type.unwrap_or_else(fallback);
155+
let expected_type = if let Some(infer_ty) = infer_type_if_missing(&fcx, node) {
156+
infer_ty
157+
} else if let Some(ty) = node.ty()
158+
&& ty.is_suggestable_infer_ty()
159+
{
160+
// In the case that we're recovering `const X: [T; _]` or some other
161+
// type that has an infer in it, lower the type directly so that it'll
162+
// be correctly filled with infer. We'll use this inference to provide
163+
// a suggestion later on.
164+
fcx.lowerer().lower_ty(ty)
165+
} else {
166+
tcx.type_of(def_id).instantiate_identity()
167+
};
169168

170169
let expected_type = fcx.normalize(body.value.span, expected_type);
171170

@@ -506,5 +505,5 @@ fn fatally_break_rust(tcx: TyCtxt<'_>, span: Span) -> ! {
506505

507506
pub fn provide(providers: &mut Providers) {
508507
method::provide(providers);
509-
*providers = Providers { typeck, diagnostic_only_typeck, used_trait_imports, ..*providers };
508+
*providers = Providers { typeck, used_trait_imports, ..*providers };
510509
}

‎compiler/rustc_middle/src/query/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,9 +1100,6 @@ rustc_queries! {
11001100
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key) }
11011101
cache_on_disk_if(tcx) { !tcx.is_typeck_child(key.to_def_id()) }
11021102
}
1103-
query diagnostic_only_typeck(key: LocalDefId) -> &'tcx ty::TypeckResults<'tcx> {
1104-
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key) }
1105-
}
11061103

11071104
query used_trait_imports(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
11081105
desc { |tcx| "finding used_trait_imports `{}`", tcx.def_path_str(key) }

‎compiler/rustc_ty_utils/src/sig_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
3131
// If the type of the item uses `_`, we're gonna error out anyway, but
3232
// typeck (which type_of invokes below), will call back into opaque_types_defined_by
3333
// causing a cycle. So we just bail out in this case.
34-
if hir_sig.output.get_infer_ret_ty().is_some() {
34+
if hir_sig.output.is_suggestable_infer_ty().is_some() {
3535
return V::Result::output();
3636
}
3737
let ty_sig = tcx.fn_sig(item).instantiate_identity();

‎tests/ui/array-slice-vec/suggest-array-length.fixed

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33

44
fn main() {
55
const Foo: [i32; 3] = [1, 2, 3];
6-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
7-
//~| ERROR using `_` for array lengths is unstable
6+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
87
const REF_FOO: &[u8; 1] = &[1];
9-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
10-
//~| ERROR using `_` for array lengths is unstable
8+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
9+
static Statik: [i32; 3] = [1, 2, 3];
10+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
11+
static REF_STATIK: &[u8; 1] = &[1];
12+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
1113
let foo: [i32; 3] = [1, 2, 3];
12-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
13-
//~| ERROR using `_` for array lengths is unstable
14+
//~^ ERROR using `_` for array lengths is unstable
1415
let bar: [i32; 3] = [0; 3];
15-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
16-
//~| ERROR using `_` for array lengths is unstable
16+
//~^ ERROR using `_` for array lengths is unstable
1717
let ref_foo: &[i32; 3] = &[1, 2, 3];
18-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
19-
//~| ERROR using `_` for array lengths is unstable
18+
//~^ ERROR using `_` for array lengths is unstable
2019
let ref_bar: &[i32; 3] = &[0; 3];
21-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
22-
//~| ERROR using `_` for array lengths is unstable
20+
//~^ ERROR using `_` for array lengths is unstable
2321
let multiple_ref_foo: &&[i32; 3] = &&[1, 2, 3];
24-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
25-
//~| ERROR using `_` for array lengths is unstable
22+
//~^ ERROR using `_` for array lengths is unstable
2623
}

‎tests/ui/array-slice-vec/suggest-array-length.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,21 @@
33

44
fn main() {
55
const Foo: [i32; _] = [1, 2, 3];
6-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
7-
//~| ERROR using `_` for array lengths is unstable
6+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
87
const REF_FOO: &[u8; _] = &[1];
9-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
10-
//~| ERROR using `_` for array lengths is unstable
8+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
9+
static Statik: [i32; _] = [1, 2, 3];
10+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
11+
static REF_STATIK: &[u8; _] = &[1];
12+
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
1113
let foo: [i32; _] = [1, 2, 3];
12-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
13-
//~| ERROR using `_` for array lengths is unstable
14+
//~^ ERROR using `_` for array lengths is unstable
1415
let bar: [i32; _] = [0; 3];
15-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
16-
//~| ERROR using `_` for array lengths is unstable
16+
//~^ ERROR using `_` for array lengths is unstable
1717
let ref_foo: &[i32; _] = &[1, 2, 3];
18-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
19-
//~| ERROR using `_` for array lengths is unstable
18+
//~^ ERROR using `_` for array lengths is unstable
2019
let ref_bar: &[i32; _] = &[0; 3];
21-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
22-
//~| ERROR using `_` for array lengths is unstable
20+
//~^ ERROR using `_` for array lengths is unstable
2321
let multiple_ref_foo: &&[i32; _] = &&[1, 2, 3];
24-
//~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment
25-
//~| ERROR using `_` for array lengths is unstable
22+
//~^ ERROR using `_` for array lengths is unstable
2623
}
Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,49 @@
1-
error: in expressions, `_` can only be used on the left-hand side of an assignment
2-
--> $DIR/suggest-array-length.rs:11:20
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
2+
--> $DIR/suggest-array-length.rs:5:22
33
|
4-
LL | let foo: [i32; _] = [1, 2, 3];
5-
| ^ `_` not allowed here
6-
7-
error: in expressions, `_` can only be used on the left-hand side of an assignment
8-
--> $DIR/suggest-array-length.rs:14:20
4+
LL | const Foo: [i32; _] = [1, 2, 3];
5+
| ^ not allowed in type signatures
96
|
10-
LL | let bar: [i32; _] = [0; 3];
11-
| ^ `_` not allowed here
12-
13-
error: in expressions, `_` can only be used on the left-hand side of an assignment
14-
--> $DIR/suggest-array-length.rs:17:25
7+
help: replace this with a fully-specified type
158
|
16-
LL | let ref_foo: &[i32; _] = &[1, 2, 3];
17-
| ^ `_` not allowed here
9+
LL | const Foo: [i32; 3] = [1, 2, 3];
10+
| ~~~~~~~~
1811

19-
error: in expressions, `_` can only be used on the left-hand side of an assignment
20-
--> $DIR/suggest-array-length.rs:20:25
12+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
13+
--> $DIR/suggest-array-length.rs:7:26
2114
|
22-
LL | let ref_bar: &[i32; _] = &[0; 3];
23-
| ^ `_` not allowed here
24-
25-
error: in expressions, `_` can only be used on the left-hand side of an assignment
26-
--> $DIR/suggest-array-length.rs:23:35
15+
LL | const REF_FOO: &[u8; _] = &[1];
16+
| ^ not allowed in type signatures
2717
|
28-
LL | let multiple_ref_foo: &&[i32; _] = &&[1, 2, 3];
29-
| ^ `_` not allowed here
30-
31-
error: in expressions, `_` can only be used on the left-hand side of an assignment
32-
--> $DIR/suggest-array-length.rs:5:22
18+
help: replace this with a fully-specified type
3319
|
34-
LL | const Foo: [i32; _] = [1, 2, 3];
35-
| ^ `_` not allowed here
20+
LL | const REF_FOO: &[u8; 1] = &[1];
21+
| ~~~~~~~~
3622

37-
error: in expressions, `_` can only be used on the left-hand side of an assignment
38-
--> $DIR/suggest-array-length.rs:8:26
23+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
24+
--> $DIR/suggest-array-length.rs:9:26
3925
|
40-
LL | const REF_FOO: &[u8; _] = &[1];
41-
| ^ `_` not allowed here
42-
43-
error[E0658]: using `_` for array lengths is unstable
44-
--> $DIR/suggest-array-length.rs:5:22
26+
LL | static Statik: [i32; _] = [1, 2, 3];
27+
| ^ not allowed in type signatures
4528
|
46-
LL | const Foo: [i32; _] = [1, 2, 3];
47-
| ^ help: consider specifying the array length: `3`
29+
help: replace this with a fully-specified type
4830
|
49-
= note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
50-
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
51-
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
31+
LL | static Statik: [i32; 3] = [1, 2, 3];
32+
| ~~~~~~~~
5233

53-
error[E0658]: using `_` for array lengths is unstable
54-
--> $DIR/suggest-array-length.rs:8:26
34+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
35+
--> $DIR/suggest-array-length.rs:11:30
5536
|
56-
LL | const REF_FOO: &[u8; _] = &[1];
57-
| ^ help: consider specifying the array length: `1`
37+
LL | static REF_STATIK: &[u8; _] = &[1];
38+
| ^ not allowed in type signatures
5839
|
59-
= note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
60-
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
61-
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
40+
help: replace this with a fully-specified type
41+
|
42+
LL | static REF_STATIK: &[u8; 1] = &[1];
43+
| ~~~~~~~~
6244

6345
error[E0658]: using `_` for array lengths is unstable
64-
--> $DIR/suggest-array-length.rs:11:20
46+
--> $DIR/suggest-array-length.rs:13:20
6547
|
6648
LL | let foo: [i32; _] = [1, 2, 3];
6749
| ^ help: consider specifying the array length: `3`
@@ -71,7 +53,7 @@ LL | let foo: [i32; _] = [1, 2, 3];
7153
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
7254

7355
error[E0658]: using `_` for array lengths is unstable
74-
--> $DIR/suggest-array-length.rs:14:20
56+
--> $DIR/suggest-array-length.rs:15:20
7557
|
7658
LL | let bar: [i32; _] = [0; 3];
7759
| ^ help: consider specifying the array length: `3`
@@ -91,7 +73,7 @@ LL | let ref_foo: &[i32; _] = &[1, 2, 3];
9173
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
9274

9375
error[E0658]: using `_` for array lengths is unstable
94-
--> $DIR/suggest-array-length.rs:20:25
76+
--> $DIR/suggest-array-length.rs:19:25
9577
|
9678
LL | let ref_bar: &[i32; _] = &[0; 3];
9779
| ^ help: consider specifying the array length: `3`
@@ -101,7 +83,7 @@ LL | let ref_bar: &[i32; _] = &[0; 3];
10183
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10284

10385
error[E0658]: using `_` for array lengths is unstable
104-
--> $DIR/suggest-array-length.rs:23:35
86+
--> $DIR/suggest-array-length.rs:21:35
10587
|
10688
LL | let multiple_ref_foo: &&[i32; _] = &&[1, 2, 3];
10789
| ^ help: consider specifying the array length: `3`
@@ -110,6 +92,7 @@ LL | let multiple_ref_foo: &&[i32; _] = &&[1, 2, 3];
11092
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
11193
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
11294

113-
error: aborting due to 14 previous errors
95+
error: aborting due to 9 previous errors
11496

115-
For more information about this error, try `rustc --explain E0658`.
97+
Some errors have detailed explanations: E0121, E0658.
98+
For more information about an error, try `rustc --explain E0121`.

‎tests/ui/async-await/issues/issue-95307.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
pub trait C {
77
async fn new() -> [u8; _];
8-
//~^ ERROR: using `_` for array lengths is unstable
9-
//~| ERROR: in expressions, `_` can only be used on the left-hand side of an assignment
8+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for functions
9+
//~| ERROR using `_` for array lengths is unstable
1010
}
1111

1212
fn main() {}

‎tests/ui/async-await/issues/issue-95307.stderr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: in expressions, `_` can only be used on the left-hand side of an assignment
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
22
--> $DIR/issue-95307.rs:7:28
33
|
44
LL | async fn new() -> [u8; _];
5-
| ^ `_` not allowed here
5+
| ^ not allowed in type signatures
66

77
error[E0658]: using `_` for array lengths is unstable
88
--> $DIR/issue-95307.rs:7:28
@@ -16,4 +16,5 @@ LL | async fn new() -> [u8; _];
1616

1717
error: aborting due to 2 previous errors
1818

19-
For more information about this error, try `rustc --explain E0658`.
19+
Some errors have detailed explanations: E0121, E0658.
20+
For more information about an error, try `rustc --explain E0121`.

‎tests/ui/const-generics/generic_arg_infer/in-signature.stderr

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,52 +27,74 @@ LL | fn ty_fn_mixed() -> Bar<_, _> {
2727
| help: replace with the correct return type: `Bar<i32, 3>`
2828

2929
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
30-
--> $DIR/in-signature.rs:22:15
30+
--> $DIR/in-signature.rs:22:20
3131
|
3232
LL | const ARR_CT: [u8; _] = [0; 3];
33-
| ^^^^^^^ not allowed in type signatures
33+
| ^ not allowed in type signatures
34+
|
35+
help: replace this with a fully-specified type
36+
|
37+
LL | const ARR_CT: [u8; 3] = [0; 3];
38+
| ~~~~~~~
3439

3540
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
36-
--> $DIR/in-signature.rs:24:20
41+
--> $DIR/in-signature.rs:24:25
3742
|
3843
LL | static ARR_STATIC: [u8; _] = [0; 3];
39-
| ^^^^^^^ not allowed in type signatures
44+
| ^ not allowed in type signatures
45+
|
46+
help: replace this with a fully-specified type
47+
|
48+
LL | static ARR_STATIC: [u8; 3] = [0; 3];
49+
| ~~~~~~~
4050

4151
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
42-
--> $DIR/in-signature.rs:26:14
52+
--> $DIR/in-signature.rs:26:23
4353
|
4454
LL | const TY_CT: Bar<i32, _> = Bar::<i32, 3>(0);
45-
| ^^^^^^^^^^^
46-
| |
47-
| not allowed in type signatures
48-
| help: replace with the correct type: `Bar<i32, 3>`
55+
| ^ not allowed in type signatures
56+
|
57+
help: replace this with a fully-specified type
58+
|
59+
LL | const TY_CT: Bar<i32, 3> = Bar::<i32, 3>(0);
60+
| ~~~~~~~~~~~
4961

5062
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
51-
--> $DIR/in-signature.rs:28:19
63+
--> $DIR/in-signature.rs:28:28
5264
|
5365
LL | static TY_STATIC: Bar<i32, _> = Bar::<i32, 3>(0);
54-
| ^^^^^^^^^^^
55-
| |
56-
| not allowed in type signatures
57-
| help: replace with the correct type: `Bar<i32, 3>`
66+
| ^ not allowed in type signatures
67+
|
68+
help: replace this with a fully-specified type
69+
|
70+
LL | static TY_STATIC: Bar<i32, 3> = Bar::<i32, 3>(0);
71+
| ~~~~~~~~~~~
5872

5973
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
60-
--> $DIR/in-signature.rs:30:20
74+
--> $DIR/in-signature.rs:30:24
6175
|
6276
LL | const TY_CT_MIXED: Bar<_, _> = Bar::<i32, 3>(0);
63-
| ^^^^^^^^^
64-
| |
65-
| not allowed in type signatures
66-
| help: replace with the correct type: `Bar<i32, 3>`
77+
| ^ ^ not allowed in type signatures
78+
| |
79+
| not allowed in type signatures
80+
|
81+
help: replace this with a fully-specified type
82+
|
83+
LL | const TY_CT_MIXED: Bar<i32, 3> = Bar::<i32, 3>(0);
84+
| ~~~~~~~~~~~
6785

6886
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
69-
--> $DIR/in-signature.rs:32:25
87+
--> $DIR/in-signature.rs:32:29
7088
|
7189
LL | static TY_STATIC_MIXED: Bar<_, _> = Bar::<i32, 3>(0);
72-
| ^^^^^^^^^
73-
| |
74-
| not allowed in type signatures
75-
| help: replace with the correct type: `Bar<i32, 3>`
90+
| ^ ^ not allowed in type signatures
91+
| |
92+
| not allowed in type signatures
93+
|
94+
help: replace this with a fully-specified type
95+
|
96+
LL | static TY_STATIC_MIXED: Bar<i32, 3> = Bar::<i32, 3>(0);
97+
| ~~~~~~~~~~~
7698

7799
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types
78100
--> $DIR/in-signature.rs:51:23

‎tests/ui/consts/issue-104768.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const A: &_ = 0_u32;
22
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for constants
3+
//~| ERROR: mismatched types
34

45
fn main() {}

‎tests/ui/consts/issue-104768.stderr

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-104768.rs:1:15
3+
|
4+
LL | const A: &_ = 0_u32;
5+
| ^^^^^ expected `&_`, found `u32`
6+
|
7+
= note: expected reference `&'static _`
8+
found type `u32`
9+
help: consider borrowing here
10+
|
11+
LL | const A: &_ = &0_u32;
12+
| +
13+
114
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
2-
--> $DIR/issue-104768.rs:1:10
15+
--> $DIR/issue-104768.rs:1:11
316
|
417
LL | const A: &_ = 0_u32;
5-
| ^^
6-
| |
7-
| not allowed in type signatures
8-
| help: replace with the correct type: `u32`
18+
| ^ not allowed in type signatures
19+
|
20+
help: replace this with a fully-specified type
21+
|
22+
LL | const A: u32 = 0_u32;
23+
| ~~~
924

10-
error: aborting due to 1 previous error
25+
error: aborting due to 2 previous errors
1126

12-
For more information about this error, try `rustc --explain E0121`.
27+
Some errors have detailed explanations: E0121, E0308.
28+
For more information about an error, try `rustc --explain E0121`.

‎tests/ui/error-codes/E0121.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
1111
--> $DIR/E0121.rs:3:13
1212
|
1313
LL | static BAR: _ = "test";
14-
| ^
15-
| |
16-
| not allowed in type signatures
17-
| help: replace with the correct type: `&str`
14+
| ^ not allowed in type signatures
15+
|
16+
help: replace this with a fully-specified type
17+
|
18+
LL | static BAR: &str = "test";
19+
| ~~~~
1820

1921
error: aborting due to 2 previous errors
2022

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
error: in expressions, `_` can only be used on the left-hand side of an assignment
2-
--> $DIR/feature-gate-generic_arg_infer.rs:11:27
3-
|
4-
LL | let _x: [u8; 3] = [0; _];
5-
| ^ `_` not allowed here
6-
7-
error: in expressions, `_` can only be used on the left-hand side of an assignment
8-
--> $DIR/feature-gate-generic_arg_infer.rs:14:18
9-
|
10-
LL | let _y: [u8; _] = [0; 3];
11-
| ^ `_` not allowed here
12-
131
error[E0658]: using `_` for array lengths is unstable
14-
--> $DIR/feature-gate-generic_arg_infer.rs:14:18
2+
--> $DIR/feature-gate-generic_arg_infer.rs:13:18
153
|
164
LL | let _y: [u8; _] = [0; 3];
175
| ^ help: consider specifying the array length: `3`
@@ -21,7 +9,7 @@ LL | let _y: [u8; _] = [0; 3];
219
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2210

2311
error[E0747]: type provided when a constant was expected
24-
--> $DIR/feature-gate-generic_arg_infer.rs:20:20
12+
--> $DIR/feature-gate-generic_arg_infer.rs:18:20
2513
|
2614
LL | let _x = foo::<_>([1,2]);
2715
| ^
@@ -42,7 +30,7 @@ LL | let _x: [u8; 3] = [0; _];
4230
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
4331
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4432

45-
error: aborting due to 5 previous errors
33+
error: aborting due to 3 previous errors
4634

4735
Some errors have detailed explanations: E0658, E0747.
4836
For more information about an error, try `rustc --explain E0658`.

‎tests/ui/feature-gates/feature-gate-generic_arg_infer.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ fn foo<const N: usize>(_: [u8; N]) -> [u8; N] {
1010
fn bar() {
1111
let _x: [u8; 3] = [0; _];
1212
//[normal]~^ ERROR: using `_` for array lengths is unstable
13-
//[normal]~| ERROR: in expressions, `_` can only be used on the left-hand side of an assignment
1413
let _y: [u8; _] = [0; 3];
1514
//[normal]~^ ERROR: using `_` for array lengths is unstable
16-
//[normal]~| ERROR: in expressions, `_` can only be used on the left-hand side of an assignment
1715
}
1816

1917
fn main() {

‎tests/ui/generic-const-items/assoc-const-missing-type.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ impl Trait for () {
1212
const K<T> = ();
1313
//~^ ERROR missing type for `const` item
1414
//~| ERROR mismatched types
15-
//~| ERROR mismatched types
1615
const Q = "";
1716
//~^ ERROR missing type for `const` item
1817
//~| ERROR lifetime parameters or bounds on const `Q` do not match the trait declaration

‎tests/ui/generic-const-items/assoc-const-missing-type.stderr

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | const K<T> = ();
1616
| ^ help: provide a type for the associated constant: `()`
1717

1818
error[E0195]: lifetime parameters or bounds on const `Q` do not match the trait declaration
19-
--> $DIR/assoc-const-missing-type.rs:16:12
19+
--> $DIR/assoc-const-missing-type.rs:15:12
2020
|
2121
LL | const Q<'a>: &'a str;
2222
| ---- lifetimes in impl do not match this const in trait
@@ -25,24 +25,12 @@ LL | const Q = "";
2525
| ^ lifetimes do not match const in trait
2626

2727
error: missing type for `const` item
28-
--> $DIR/assoc-const-missing-type.rs:16:12
28+
--> $DIR/assoc-const-missing-type.rs:15:12
2929
|
3030
LL | const Q = "";
3131
| ^ help: provide a type for the associated constant: `: &str`
3232

33-
error[E0308]: mismatched types
34-
--> $DIR/assoc-const-missing-type.rs:12:18
35-
|
36-
LL | const K<T> = ();
37-
| - ^^ expected type parameter `T`, found `()`
38-
| |
39-
| expected this type parameter
40-
|
41-
= note: expected type parameter `T`
42-
found unit type `()`
43-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
44-
45-
error: aborting due to 5 previous errors
33+
error: aborting due to 4 previous errors
4634

4735
Some errors have detailed explanations: E0195, E0308.
4836
For more information about an error, try `rustc --explain E0195`.

‎tests/ui/macros/issue-69396-const-no-type-in-macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ macro_rules! suite {
44
const A = "A".$fn();
55
//~^ ERROR the name `A` is defined multiple times
66
//~| ERROR missing type for `const` item
7-
//~| ERROR the placeholder `_` is not allowed within types on item signatures for constants
7+
//~| ERROR missing type for item
88
)*
99
}
1010
}

‎tests/ui/macros/issue-69396-const-no-type-in-macro.stderr

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ LL | | }
2727
|
2828
= note: this error originates in the macro `suite` (in Nightly builds, run with -Z macro-backtrace for more info)
2929

30-
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
30+
error[E0121]: missing type for item
3131
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:20
3232
|
3333
LL | const A = "A".$fn();
34-
| ^
35-
| |
36-
| not allowed in type signatures
37-
| help: replace with the correct type: `bool`
34+
| ^ not allowed in type signatures
3835
...
3936
LL | / suite! {
4037
LL | | len;

‎tests/ui/parser/issues/issue-89574.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ fn main() {
22
const EMPTY_ARRAY = [];
33
//~^ missing type for `const` item
44
//~| ERROR type annotations needed
5-
//~| ERROR type annotations needed
65
}

‎tests/ui/parser/issues/issue-89574.stderr

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ help: provide a type for the item
1515
LL | const EMPTY_ARRAY: <type> = [];
1616
| ++++++++
1717

18-
error[E0282]: type annotations needed
19-
--> $DIR/issue-89574.rs:2:25
20-
|
21-
LL | const EMPTY_ARRAY = [];
22-
| ^^ cannot infer type
23-
|
24-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
25-
26-
error: aborting due to 3 previous errors
18+
error: aborting due to 2 previous errors
2719

2820
For more information about this error, try `rustc --explain E0282`.

‎tests/ui/suggestions/unnamable-types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const A = 5;
1010
static B: _ = "abc";
1111
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static variables
1212
//~| NOTE: not allowed in type signatures
13-
//~| HELP: replace with the correct type
13+
//~| HELP: replace this with a fully-specified type
1414

1515

1616
// FIXME: this should also suggest a function pointer, as the closure is non-capturing

‎tests/ui/suggestions/unnamable-types.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
88
--> $DIR/unnamable-types.rs:10:11
99
|
1010
LL | static B: _ = "abc";
11-
| ^
12-
| |
13-
| not allowed in type signatures
14-
| help: replace with the correct type: `&str`
11+
| ^ not allowed in type signatures
12+
|
13+
help: replace this with a fully-specified type
14+
|
15+
LL | static B: &str = "abc";
16+
| ~~~~
1517

1618
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
1719
--> $DIR/unnamable-types.rs:17:10

‎tests/ui/typeck/issue-79040.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
2-
const FOO = "hello" + 1; //~ ERROR cannot add `{integer}` to `&str`
3-
//~^ missing type for `const` item
4-
//~| ERROR cannot add `{integer}` to `&str`
2+
const FOO = "hello" + 1;
3+
//~^ ERROR cannot add `{integer}` to `&str`
4+
//~| missing type for `const` item
55
println!("{}", FOO);
66
}

‎tests/ui/typeck/issue-79040.stderr

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@ help: provide a type for the item
1717
LL | const FOO: <type> = "hello" + 1;
1818
| ++++++++
1919

20-
error[E0369]: cannot add `{integer}` to `&str`
21-
--> $DIR/issue-79040.rs:2:25
22-
|
23-
LL | const FOO = "hello" + 1;
24-
| ------- ^ - {integer}
25-
| |
26-
| &str
27-
|
28-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
29-
30-
error: aborting due to 3 previous errors
20+
error: aborting due to 2 previous errors
3121

3222
For more information about this error, try `rustc --explain E0369`.

‎tests/ui/typeck/typeck_type_placeholder_item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ fn value() -> Option<&'static _> {
221221

222222
const _: Option<_> = map(value);
223223
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants
224+
//~| ERROR cannot call non-const function `map::<u8>` in constants
224225

225226
fn evens_squared(n: usize) -> _ {
226227
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for return types

‎tests/ui/typeck/typeck_type_placeholder_item.stderr

Lines changed: 85 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,36 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
6767
--> $DIR/typeck_type_placeholder_item.rs:13:15
6868
|
6969
LL | static TEST3: _ = "test";
70-
| ^
71-
| |
72-
| not allowed in type signatures
73-
| help: replace with the correct type: `&str`
70+
| ^ not allowed in type signatures
71+
|
72+
help: replace this with a fully-specified type
73+
|
74+
LL | static TEST3: &str = "test";
75+
| ~~~~
7476

7577
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
7678
--> $DIR/typeck_type_placeholder_item.rs:16:15
7779
|
7880
LL | static TEST4: _ = 145;
79-
| ^
80-
| |
81-
| not allowed in type signatures
82-
| help: replace with the correct type: `i32`
81+
| ^ not allowed in type signatures
82+
|
83+
help: replace this with a fully-specified type
84+
|
85+
LL | static TEST4: i32 = 145;
86+
| ~~~
8387

8488
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
85-
--> $DIR/typeck_type_placeholder_item.rs:19:15
89+
--> $DIR/typeck_type_placeholder_item.rs:19:16
8690
|
8791
LL | static TEST5: (_, _) = (1, 2);
88-
| ^^^^^^ not allowed in type signatures
92+
| ^ ^ not allowed in type signatures
93+
| |
94+
| not allowed in type signatures
95+
|
96+
help: replace this with a fully-specified type
97+
|
98+
LL | static TEST5: (i32, i32) = (1, 2);
99+
| ~~~~~~~~~~
89100

90101
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
91102
--> $DIR/typeck_type_placeholder_item.rs:22:13
@@ -220,16 +231,23 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
220231
--> $DIR/typeck_type_placeholder_item.rs:75:15
221232
|
222233
LL | static B: _ = 42;
223-
| ^
224-
| |
225-
| not allowed in type signatures
226-
| help: replace with the correct type: `i32`
234+
| ^ not allowed in type signatures
235+
|
236+
help: replace this with a fully-specified type
237+
|
238+
LL | static B: i32 = 42;
239+
| ~~~
227240

228241
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
229-
--> $DIR/typeck_type_placeholder_item.rs:77:15
242+
--> $DIR/typeck_type_placeholder_item.rs:77:22
230243
|
231244
LL | static C: Option<_> = Some(42);
232-
| ^^^^^^^^^ not allowed in type signatures
245+
| ^ not allowed in type signatures
246+
|
247+
help: replace this with a fully-specified type
248+
|
249+
LL | static C: Option<i32> = Some(42);
250+
| ~~~~~~~~~~~
233251

234252
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
235253
--> $DIR/typeck_type_placeholder_item.rs:79:21
@@ -254,25 +272,36 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
254272
--> $DIR/typeck_type_placeholder_item.rs:85:22
255273
|
256274
LL | static FN_TEST3: _ = "test";
257-
| ^
258-
| |
259-
| not allowed in type signatures
260-
| help: replace with the correct type: `&str`
275+
| ^ not allowed in type signatures
276+
|
277+
help: replace this with a fully-specified type
278+
|
279+
LL | static FN_TEST3: &str = "test";
280+
| ~~~~
261281

262282
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
263283
--> $DIR/typeck_type_placeholder_item.rs:88:22
264284
|
265285
LL | static FN_TEST4: _ = 145;
266-
| ^
267-
| |
268-
| not allowed in type signatures
269-
| help: replace with the correct type: `i32`
286+
| ^ not allowed in type signatures
287+
|
288+
help: replace this with a fully-specified type
289+
|
290+
LL | static FN_TEST4: i32 = 145;
291+
| ~~~
270292

271293
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
272-
--> $DIR/typeck_type_placeholder_item.rs:91:22
294+
--> $DIR/typeck_type_placeholder_item.rs:91:23
273295
|
274296
LL | static FN_TEST5: (_, _) = (1, 2);
275-
| ^^^^^^ not allowed in type signatures
297+
| ^ ^ not allowed in type signatures
298+
| |
299+
| not allowed in type signatures
300+
|
301+
help: replace this with a fully-specified type
302+
|
303+
LL | static FN_TEST5: (i32, i32) = (1, 2);
304+
| ~~~~~~~~~~
276305

277306
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
278307
--> $DIR/typeck_type_placeholder_item.rs:94:20
@@ -539,10 +568,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
539568
--> $DIR/typeck_type_placeholder_item.rs:194:14
540569
|
541570
LL | const D: _ = 42;
542-
| ^
543-
| |
544-
| not allowed in type signatures
545-
| help: replace with the correct type: `i32`
571+
| ^ not allowed in type signatures
572+
|
573+
help: replace this with a fully-specified type
574+
|
575+
LL | const D: i32 = 42;
576+
| ~~~
546577

547578
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants
548579
--> $DIR/typeck_type_placeholder_item.rs:209:14
@@ -569,16 +600,18 @@ LL | fn value() -> Option<&'static _> {
569600
| help: replace with the correct return type: `Option<&'static u8>`
570601

571602
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
572-
--> $DIR/typeck_type_placeholder_item.rs:222:10
603+
--> $DIR/typeck_type_placeholder_item.rs:222:17
573604
|
574605
LL | const _: Option<_> = map(value);
575-
| ^^^^^^^^^
576-
| |
577-
| not allowed in type signatures
578-
| help: replace with the correct type: `Option<u8>`
606+
| ^ not allowed in type signatures
607+
|
608+
help: replace this with a fully-specified type
609+
|
610+
LL | const _: Option<u8> = map(value);
611+
| ~~~~~~~~~~
579612

580613
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
581-
--> $DIR/typeck_type_placeholder_item.rs:225:31
614+
--> $DIR/typeck_type_placeholder_item.rs:226:31
582615
|
583616
LL | fn evens_squared(n: usize) -> _ {
584617
| ^
@@ -587,13 +620,13 @@ LL | fn evens_squared(n: usize) -> _ {
587620
| help: replace with an appropriate return type: `impl Iterator<Item = usize>`
588621

589622
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
590-
--> $DIR/typeck_type_placeholder_item.rs:230:10
623+
--> $DIR/typeck_type_placeholder_item.rs:231:10
591624
|
592625
LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
593626
| ^ not allowed in type signatures
594627
|
595-
note: however, the inferred type `Map<Filter<Range<i32>, {closure@typeck_type_placeholder_item.rs:230:29}>, {closure@typeck_type_placeholder_item.rs:230:49}>` cannot be named
596-
--> $DIR/typeck_type_placeholder_item.rs:230:14
628+
note: however, the inferred type `Map<Filter<Range<i32>, {closure@typeck_type_placeholder_item.rs:231:29}>, {closure@typeck_type_placeholder_item.rs:231:49}>` cannot be named
629+
--> $DIR/typeck_type_placeholder_item.rs:231:14
597630
|
598631
LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
599632
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -668,23 +701,31 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
668701
LL | type F: std::ops::Fn(_);
669702
| ^ not allowed in type signatures
670703

671-
error[E0015]: cannot call non-const method `<std::ops::Range<i32> as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:230:29: 230:32}>` in constants
672-
--> $DIR/typeck_type_placeholder_item.rs:230:22
704+
error[E0015]: cannot call non-const function `map::<u8>` in constants
705+
--> $DIR/typeck_type_placeholder_item.rs:222:22
706+
|
707+
LL | const _: Option<_> = map(value);
708+
| ^^^^^^^^^^
709+
|
710+
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
711+
712+
error[E0015]: cannot call non-const method `<std::ops::Range<i32> as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:231:29: 231:32}>` in constants
713+
--> $DIR/typeck_type_placeholder_item.rs:231:22
673714
|
674715
LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
675716
| ^^^^^^^^^^^^^^^^^^^^^^
676717
|
677718
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
678719

679-
error[E0015]: cannot call non-const method `<Filter<std::ops::Range<i32>, {closure@$DIR/typeck_type_placeholder_item.rs:230:29: 230:32}> as Iterator>::map::<i32, {closure@$DIR/typeck_type_placeholder_item.rs:230:49: 230:52}>` in constants
680-
--> $DIR/typeck_type_placeholder_item.rs:230:45
720+
error[E0015]: cannot call non-const method `<Filter<std::ops::Range<i32>, {closure@$DIR/typeck_type_placeholder_item.rs:231:29: 231:32}> as Iterator>::map::<i32, {closure@$DIR/typeck_type_placeholder_item.rs:231:49: 231:52}>` in constants
721+
--> $DIR/typeck_type_placeholder_item.rs:231:45
681722
|
682723
LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
683724
| ^^^^^^^^^^^^^^
684725
|
685726
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
686727

687-
error: aborting due to 74 previous errors
728+
error: aborting due to 75 previous errors
688729

689730
Some errors have detailed explanations: E0015, E0046, E0121, E0282, E0403.
690731
For more information about an error, try `rustc --explain E0015`.

‎tests/ui/typeck/typeck_type_placeholder_item_help.stderr

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
1111
--> $DIR/typeck_type_placeholder_item_help.rs:7:14
1212
|
1313
LL | const TEST2: _ = 42u32;
14-
| ^
15-
| |
16-
| not allowed in type signatures
17-
| help: replace with the correct type: `u32`
14+
| ^ not allowed in type signatures
15+
|
16+
help: replace this with a fully-specified type
17+
|
18+
LL | const TEST2: u32 = 42u32;
19+
| ~~~
1820

1921
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
2022
--> $DIR/typeck_type_placeholder_item_help.rs:10:14
2123
|
2224
LL | const TEST3: _ = Some(42);
23-
| ^
24-
| |
25-
| not allowed in type signatures
26-
| help: replace with the correct type: `Option<i32>`
25+
| ^ not allowed in type signatures
26+
|
27+
help: replace this with a fully-specified type
28+
|
29+
LL | const TEST3: Option<i32> = Some(42);
30+
| ~~~~~~~~~~~
2731

2832
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
2933
--> $DIR/typeck_type_placeholder_item_help.rs:13:22
@@ -41,19 +45,23 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
4145
--> $DIR/typeck_type_placeholder_item_help.rs:25:18
4246
|
4347
LL | const TEST6: _ = 13;
44-
| ^
45-
| |
46-
| not allowed in type signatures
47-
| help: replace with the correct type: `i32`
48+
| ^ not allowed in type signatures
49+
|
50+
help: replace this with a fully-specified type
51+
|
52+
LL | const TEST6: i32 = 13;
53+
| ~~~
4854

4955
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants
5056
--> $DIR/typeck_type_placeholder_item_help.rs:18:18
5157
|
5258
LL | const TEST5: _ = 42;
53-
| ^
54-
| |
55-
| not allowed in type signatures
56-
| help: replace with the correct type: `i32`
59+
| ^ not allowed in type signatures
60+
|
61+
help: replace this with a fully-specified type
62+
|
63+
LL | const TEST5: i32 = 42;
64+
| ~~~
5765

5866
error[E0308]: mismatched types
5967
--> $DIR/typeck_type_placeholder_item_help.rs:30:28

0 commit comments

Comments
 (0)
Please sign in to comment.