Skip to content

Stabilize feature(generic_arg_infer) #141610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ ast_lowering_template_modifier = template modifier
ast_lowering_this_not_async = this is not `async`
ast_lowering_underscore_array_length_unstable =
using `_` for array lengths is unstable
ast_lowering_underscore_expr_lhs_assign =
in expressions, `_` can only be used on the left-hand side of an assignment
.label = `_` not allowed here
Expand Down
13 changes: 2 additions & 11 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::spawn;
use rustc_data_structures::tagged_ptr::TaggedRef;
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, StashKey};
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId};
use rustc_hir::{
Expand All @@ -61,7 +61,7 @@ use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_macros::extension;
use rustc_middle::span_bug;
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
use rustc_session::parse::{add_feature_diagnostics, feature_err};
use rustc_session::parse::add_feature_diagnostics;
use rustc_span::symbol::{Ident, Symbol, kw, sym};
use rustc_span::{DUMMY_SP, DesugaringKind, Span};
use smallvec::{SmallVec, smallvec};
Expand Down Expand Up @@ -2068,15 +2068,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// `ExprKind::Paren(ExprKind::Underscore)` and should also be lowered to `GenericArg::Infer`
match c.value.peel_parens().kind {
ExprKind::Underscore => {
if !self.tcx.features().generic_arg_infer() {
feature_err(
&self.tcx.sess,
sym::generic_arg_infer,
c.value.span,
fluent_generated::ast_lowering_underscore_array_length_unstable,
)
.stash(c.value.span, StashKey::UnderscoreForArrayLengths);
}
let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span), ());
self.arena.alloc(hir::ConstArg { hir_id: self.lower_node_id(c.id), kind: ct_kind })
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ declare_features! (
(accepted, fn_must_use, "1.27.0", Some(43302)),
/// Allows capturing variables in scope using format_args!
(accepted, format_args_capture, "1.58.0", Some(67984)),
/// Infer generic args for both consts and types.
(accepted, generic_arg_infer, "CURRENT_RUSTC_VERSION", Some(85077)),
/// Allows associated types to be generic, e.g., `type Foo<T>;` (RFC 1598).
(accepted, generic_associated_types, "1.65.0", Some(44265)),
/// Allows attributes on lifetime/type formal parameters in generics (RFC 1327).
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,6 @@ declare_features! (
(unstable, frontmatter, "1.88.0", Some(136889)),
/// Allows defining gen blocks and `gen fn`.
(unstable, gen_blocks, "1.75.0", Some(117078)),
/// Infer generic args for both consts and types.
(unstable, generic_arg_infer, "1.55.0", Some(85077)),
/// Allows non-trivial generic constants which have to have wfness manually propagated to callers
(incomplete, generic_const_exprs, "1.56.0", Some(76560)),
/// Allows generic parameters and where-clauses on free & associated const items.
Expand Down
17 changes: 1 addition & 16 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,6 @@ fn infer_placeholder_type<'tcx>(
if let Some(ty) = node.ty() {
visitor.visit_ty_unambig(ty);
}
// If we have just one span, let's try to steal a const `_` feature error.
let try_steal_span = if !tcx.features().generic_arg_infer() && visitor.spans.len() == 1
{
visitor.spans.first().copied()
} else {
None
};
// If we didn't find any infer tys, then just fallback to `span`.
if visitor.spans.is_empty() {
visitor.spans.push(span);
Expand Down Expand Up @@ -489,15 +482,7 @@ fn infer_placeholder_type<'tcx>(
}
}

if let Some(try_steal_span) = try_steal_span {
cx.dcx().try_steal_replace_and_emit_err(
try_steal_span,
StashKey::UnderscoreForArrayLengths,
diag,
)
} else {
diag.emit()
}
diag.emit()
});
Ty::new_error(tcx, guar)
}
Expand Down
15 changes: 1 addition & 14 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::ty::{
self, GenericArgsRef, GenericParamDef, GenericParamDefKind, IsSuggestable, Ty,
};
use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
use rustc_span::{kw, sym};
use rustc_span::kw;
use smallvec::SmallVec;
use tracing::{debug, instrument};

Expand Down Expand Up @@ -258,19 +258,6 @@ pub fn lower_generic_args<'tcx: 'a, 'a>(
GenericParamDefKind::Const { .. },
_,
) => {
if let GenericParamDefKind::Const { .. } = param.kind
&& let GenericArg::Infer(inf) = arg
&& !tcx.features().generic_arg_infer()
{
rustc_session::parse::feature_err(
tcx.sess,
sym::generic_arg_infer,
inf.span,
"const arguments cannot yet be inferred with `_`",
)
.emit();
}

// We lower to an infer even when the feature gate is not enabled
// as it is useful for diagnostics to be able to see a `ConstKind::Infer`
args.push(ctx.provided_kind(&args, param, arg));
Expand Down
1 change: 0 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@
#![feature(f16)]
#![feature(freeze_impls)]
#![feature(fundamental)]
#![feature(generic_arg_infer)]
#![feature(if_let_guard)]
#![feature(intra_doc_pointers)]
#![feature(intrinsics)]
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/tests/ui/single_range_in_vec_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//@no-rustfix: overlapping suggestions
#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::useless_vec, unused)]
#![warn(clippy::single_range_in_vec_init)]
#![feature(generic_arg_infer)]

#[macro_use]
extern crate proc_macros;
Expand Down
20 changes: 10 additions & 10 deletions src/tools/clippy/tests/ui/single_range_in_vec_init.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: an array of `Range` that is only one element
--> tests/ui/single_range_in_vec_init.rs:26:5
--> tests/ui/single_range_in_vec_init.rs:25:5
|
LL | [0..200];
| ^^^^^^^^
Expand All @@ -18,7 +18,7 @@ LL + [0; 200];
|

error: a `Vec` of `Range` that is only one element
--> tests/ui/single_range_in_vec_init.rs:28:5
--> tests/ui/single_range_in_vec_init.rs:27:5
|
LL | vec![0..200];
| ^^^^^^^^^^^^
Expand All @@ -35,7 +35,7 @@ LL + vec![0; 200];
|

error: an array of `Range` that is only one element
--> tests/ui/single_range_in_vec_init.rs:30:5
--> tests/ui/single_range_in_vec_init.rs:29:5
|
LL | [0u8..200];
| ^^^^^^^^^^
Expand All @@ -52,7 +52,7 @@ LL + [0u8; 200];
|

error: an array of `Range` that is only one element
--> tests/ui/single_range_in_vec_init.rs:32:5
--> tests/ui/single_range_in_vec_init.rs:31:5
|
LL | [0usize..200];
| ^^^^^^^^^^^^^
Expand All @@ -69,7 +69,7 @@ LL + [0usize; 200];
|

error: an array of `Range` that is only one element
--> tests/ui/single_range_in_vec_init.rs:34:5
--> tests/ui/single_range_in_vec_init.rs:33:5
|
LL | [0..200usize];
| ^^^^^^^^^^^^^
Expand All @@ -86,7 +86,7 @@ LL + [0; 200usize];
|

error: a `Vec` of `Range` that is only one element
--> tests/ui/single_range_in_vec_init.rs:36:5
--> tests/ui/single_range_in_vec_init.rs:35:5
|
LL | vec![0u8..200];
| ^^^^^^^^^^^^^^
Expand All @@ -103,7 +103,7 @@ LL + vec![0u8; 200];
|

error: a `Vec` of `Range` that is only one element
--> tests/ui/single_range_in_vec_init.rs:38:5
--> tests/ui/single_range_in_vec_init.rs:37:5
|
LL | vec![0usize..200];
| ^^^^^^^^^^^^^^^^^
Expand All @@ -120,7 +120,7 @@ LL + vec![0usize; 200];
|

error: a `Vec` of `Range` that is only one element
--> tests/ui/single_range_in_vec_init.rs:40:5
--> tests/ui/single_range_in_vec_init.rs:39:5
|
LL | vec![0..200usize];
| ^^^^^^^^^^^^^^^^^
Expand All @@ -137,7 +137,7 @@ LL + vec![0; 200usize];
|

error: an array of `Range` that is only one element
--> tests/ui/single_range_in_vec_init.rs:43:5
--> tests/ui/single_range_in_vec_init.rs:42:5
|
LL | [0..200isize];
| ^^^^^^^^^^^^^
Expand All @@ -149,7 +149,7 @@ LL + (0..200isize).collect::<std::vec::Vec<isize>>();
|

error: a `Vec` of `Range` that is only one element
--> tests/ui/single_range_in_vec_init.rs:45:5
--> tests/ui/single_range_in_vec_init.rs:44:5
|
LL | vec![0..200isize];
| ^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/crashes/111419.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ known-bug: #111419
#![allow(incomplete_features)]
#![feature(generic_const_exprs, generic_arg_infer)]
#![feature(generic_const_exprs)]

pub trait Example<const X: usize, const Y: usize, const Z: usize = { X + Y }>
where
Expand Down
15 changes: 5 additions & 10 deletions tests/ui/array-slice-vec/suggest-array-length.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ fn main() {
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
static REF_STATIK: &[u8; 1] = &[1];
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
let foo: [i32; 3] = [1, 2, 3];
//~^ ERROR using `_` for array lengths is unstable
let bar: [i32; 3] = [0; 3];
//~^ ERROR using `_` for array lengths is unstable
let ref_foo: &[i32; 3] = &[1, 2, 3];
//~^ ERROR using `_` for array lengths is unstable
let ref_bar: &[i32; 3] = &[0; 3];
//~^ ERROR using `_` for array lengths is unstable
let multiple_ref_foo: &&[i32; 3] = &&[1, 2, 3];
//~^ ERROR using `_` for array lengths is unstable
let foo: [i32; _] = [1, 2, 3];
let bar: [i32; _] = [0; 3];
let ref_foo: &[i32; _] = &[1, 2, 3];
let ref_bar: &[i32; _] = &[0; 3];
let multiple_ref_foo: &&[i32; _] = &&[1, 2, 3];
}
5 changes: 0 additions & 5 deletions tests/ui/array-slice-vec/suggest-array-length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ fn main() {
static REF_STATIK: &[u8; _] = &[1];
//~^ ERROR the placeholder `_` is not allowed within types on item signatures for static variables
let foo: [i32; _] = [1, 2, 3];
//~^ ERROR using `_` for array lengths is unstable
let bar: [i32; _] = [0; 3];
//~^ ERROR using `_` for array lengths is unstable
let ref_foo: &[i32; _] = &[1, 2, 3];
//~^ ERROR using `_` for array lengths is unstable
let ref_bar: &[i32; _] = &[0; 3];
//~^ ERROR using `_` for array lengths is unstable
let multiple_ref_foo: &&[i32; _] = &&[1, 2, 3];
//~^ ERROR using `_` for array lengths is unstable
}
55 changes: 2 additions & 53 deletions tests/ui/array-slice-vec/suggest-array-length.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -46,57 +46,6 @@ LL - static REF_STATIK: &[u8; _] = &[1];
LL + static REF_STATIK: &[u8; 1] = &[1];
|

error[E0658]: using `_` for array lengths is unstable
--> $DIR/suggest-array-length.rs:13:20
|
LL | let foo: [i32; _] = [1, 2, 3];
| ^ help: consider specifying the array length: `3`
|
= note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: using `_` for array lengths is unstable
--> $DIR/suggest-array-length.rs:15:20
|
LL | let bar: [i32; _] = [0; 3];
| ^ help: consider specifying the array length: `3`
|
= note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: using `_` for array lengths is unstable
--> $DIR/suggest-array-length.rs:17:25
|
LL | let ref_foo: &[i32; _] = &[1, 2, 3];
| ^ help: consider specifying the array length: `3`
|
= note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: using `_` for array lengths is unstable
--> $DIR/suggest-array-length.rs:19:25
|
LL | let ref_bar: &[i32; _] = &[0; 3];
| ^ help: consider specifying the array length: `3`
|
= note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: using `_` for array lengths is unstable
--> $DIR/suggest-array-length.rs:21:35
|
LL | let multiple_ref_foo: &&[i32; _] = &&[1, 2, 3];
| ^ help: consider specifying the array length: `3`
|
= note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 9 previous errors
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0121, E0658.
For more information about an error, try `rustc --explain E0121`.
For more information about this error, try `rustc --explain E0121`.
1 change: 0 additions & 1 deletion tests/ui/async-await/issues/issue-95307.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
pub trait C {
async fn new() -> [u8; _];
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for functions
//~| ERROR using `_` for array lengths is unstable
}

fn main() {}
15 changes: 2 additions & 13 deletions tests/ui/async-await/issues/issue-95307.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures
LL | async fn new() -> [u8; _];
| ^ not allowed in type signatures

error[E0658]: using `_` for array lengths is unstable
--> $DIR/issue-95307.rs:7:28
|
LL | async fn new() -> [u8; _];
| ^
|
= note: see issue #85077 <https://github.com/rust-lang/rust/issues/85077> for more information
= help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

Some errors have detailed explanations: E0121, E0658.
For more information about an error, try `rustc --explain E0121`.
For more information about this error, try `rustc --explain E0121`.
2 changes: 1 addition & 1 deletion tests/ui/closures/binder/forbid_ambig_const_infers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(generic_arg_infer, closure_lifetime_binder)]
#![feature(closure_lifetime_binder)]

struct Foo<const N: usize>([u32; N]);

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/closures/binder/forbid_ambig_type_infers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(generic_arg_infer, closure_lifetime_binder)]
#![feature(closure_lifetime_binder)]

struct Foo<T>(T);

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/closures/binder/forbid_const_infer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(generic_arg_infer, closure_lifetime_binder)]
#![feature(closure_lifetime_binder)]

fn main() {
let c = for<'a> |b: &'a [u32; _]| -> u32 { b[0] };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(generic_arg_infer, associated_const_equality, generic_const_items)]
#![feature(associated_const_equality, generic_const_items)]
#![expect(incomplete_features)]

// Regression test for #133066 where we would try to evaluate `<() as Foo>::ASSOC<_>` even
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ check-pass

#![feature(generic_arg_infer)]
#![crate_type = "lib"]

// Test that encoding the hallucinated `DefId` for the `_` const argument doesn't
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ run-pass

// To avoid having to `or` gate `_` as an expr.
#![feature(generic_arg_infer)]

fn foo() -> [u8; 3] {
let x: [u8; _] = [0; _];
Expand Down
Loading
Loading