Skip to content
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

stabilize #![feature(min_const_generics)] in 1.51 #79135

Merged
merged 4 commits into from
Dec 27, 2020
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#![feature(new_uninit)]
#![feature(maybe_uninit_slice)]
#![feature(array_value_iter)]
#![feature(min_const_generics)]
#![cfg_attr(bootstrap, feature(min_const_generics))]
#![feature(min_specialization)]
#![cfg_attr(test, feature(test))]

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ impl Expr {
/// Is this expr either `N`, or `{ N }`.
///
/// If this is not the case, name resolution does not resolve `N` when using
/// `feature(min_const_generics)` as more complex expressions are not supported.
/// `min_const_generics` as more complex expressions are not supported.
pub fn is_potential_trivial_const_param(&self) -> bool {
let this = if let ExprKind::Block(ref block, None) = self.kind {
if block.stmts.len() == 1 {
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,14 +773,12 @@ fn validate_generic_param_order<'a>(
err.span_suggestion(
span,
&format!(
"reorder the parameters: lifetimes{}",
"reorder the parameters: lifetimes, {}",
if sess.features_untracked().const_generics {
", then consts and types"
} else if sess.features_untracked().min_const_generics {
", then types, then consts"
"then consts and types"
} else {
", then types"
},
"then types, then consts"
}
),
ordered_params.clone(),
Applicability::MachineApplicable,
Expand Down
15 changes: 1 addition & 14 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_ast as ast;
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
use rustc_ast::{AssocTyConstraint, AssocTyConstraintKind, NodeId};
use rustc_ast::{GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData};
use rustc_ast::{PatKind, RangeEnd, VariantData};
use rustc_errors::struct_span_err;
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
use rustc_feature::{Features, GateIssue};
Expand Down Expand Up @@ -529,19 +529,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
visit::walk_fn(self, fn_kind, span)
}

fn visit_generic_param(&mut self, param: &'a GenericParam) {
if let GenericParamKind::Const { .. } = param.kind {
gate_feature_fn!(
&self,
|x: &Features| x.const_generics || x.min_const_generics,
param.ident.span,
sym::min_const_generics,
"const generics are unstable"
);
}
visit::walk_generic_param(self, param)
}

fn visit_assoc_ty_constraint(&mut self, constraint: &'a AssocTyConstraint) {
if let AssocTyConstraintKind::Bound { .. } = constraint.kind {
gate_feature_post!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#![feature(thread_id_value)]
#![feature(extend_one)]
#![feature(const_panic)]
#![feature(min_const_generics)]
#![cfg_attr(bootstrap, feature(min_const_generics))]
#![feature(new_uninit)]
#![feature(once_cell)]
#![feature(maybe_uninit_uninit_array)]
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0730.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ An array without a fixed length was pattern-matched.
Erroneous code example:

```compile_fail,E0730
#![feature(const_generics)]

fn is_123<const N: usize>(x: [u32; N]) -> bool {
match x {
[1, 2, ..] => true, // error: cannot pattern-match on an
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0770.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ fn foo<T, const N: T>() {} // error!
To fix this error, use a concrete type for the const parameter:

```
#![feature(const_generics)]
fn foo<T, const N: usize>() {}
```
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ declare_features! (
/// Allows patterns with concurrent by-move and by-ref bindings.
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
(accepted, move_ref_pattern, "1.48.0", Some(68354), None),
/// The smallest useful subset of `const_generics`.
(accepted, min_const_generics, "1.51.0", Some(74878), None),

// -------------------------------------------------------------------------
// feature-group-end: accepted features
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,6 @@ declare_features! (
/// Allows calling `transmute` in const fn
(active, const_fn_transmute, "1.46.0", Some(53605), None),

/// The smallest useful subset of `const_generics`.
(active, min_const_generics, "1.47.0", Some(74878), None),

/// Allows `if let` guard in match arms.
(active, if_let_guard, "1.47.0", Some(51114), None),

Expand Down Expand Up @@ -651,5 +648,7 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[

/// Some features are not allowed to be used together at the same time, if
/// the two are present, produce an error.
pub const INCOMPATIBLE_FEATURES: &[(Symbol, Symbol)] =
&[(sym::const_generics, sym::min_const_generics)];
///
/// Currently empty, but we will probably need this again in the future,
/// so let's keep it in for now.
pub const INCOMPATIBLE_FEATURES: &[(Symbol, Symbol)] = &[];
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2299,7 +2299,7 @@ impl EarlyLintPass for IncompleteFeatures {
}
}

const HAS_MIN_FEATURES: &[Symbol] = &[sym::const_generics, sym::specialization];
const HAS_MIN_FEATURES: &[Symbol] = &[sym::specialization];

declare_lint! {
/// The `invalid_value` lint detects creating a value that is not valid,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn lazy_normalization(self) -> bool {
let features = self.features();
// Note: We do not enable lazy normalization for `features.min_const_generics`.
// Note: We do not enable lazy normalization for `min_const_generics`.
features.const_generics || features.lazy_normalization_consts
}

Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1638,8 +1638,6 @@ pub type PlaceholderConst<'tcx> = Placeholder<BoundConst<'tcx>>;
/// which cause cycle errors.
///
/// ```rust
/// #![feature(const_generics)]
///
/// struct A;
/// impl A {
/// fn foo<const N: usize>(&self) -> [u8; N] { [0; N] }
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_parse/src/parser/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_ast::{
self as ast, Attribute, GenericBounds, GenericParam, GenericParamKind, WhereClause,
};
use rustc_errors::PResult;
use rustc_span::symbol::{kw, sym};
use rustc_span::symbol::kw;

impl<'a> Parser<'a> {
/// Parses bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`.
Expand Down Expand Up @@ -56,8 +56,6 @@ impl<'a> Parser<'a> {
self.expect(&token::Colon)?;
let ty = self.parse_ty()?;

self.sess.gated_spans.gate(sym::min_const_generics, const_span.to(self.prev_token.span));

Ok(GenericParam {
ident,
id: ast::DUMMY_NODE_ID,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1985,8 +1985,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
}
}

/// Non-static lifetimes are prohibited in anonymous constants under `min_const_generics` so
/// this function will emit an error if `min_const_generics` is enabled, the body identified by
/// Non-static lifetimes are prohibited in anonymous constants under `min_const_generics`.
/// This function will emit an error if `const_generics` is not enabled, the body identified by
/// `body_id` is an anonymous constant and `lifetime_ref` is non-static.
crate fn maybe_emit_forbidden_non_static_lifetime_error(
&self,
Expand All @@ -2002,7 +2002,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
hir::LifetimeName::Implicit | hir::LifetimeName::Static | hir::LifetimeName::Underscore
);

if self.tcx.features().min_const_generics && is_anon_const && !is_allowed_lifetime {
if !self.tcx.lazy_normalization() && is_anon_const && !is_allowed_lifetime {
feature_err(
&self.tcx.sess.parse_sess,
sym::const_generics,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1769,8 +1769,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
let result = loop {
match *scope {
Scope::Body { id, s } => {
// Non-static lifetimes are prohibited in anonymous constants under
// `min_const_generics`.
// Non-static lifetimes are prohibited in anonymous constants without
// `const_generics`.
self.maybe_emit_forbidden_non_static_lifetime_error(id, lifetime_ref);

outermost_body = Some(id);
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2624,8 +2624,12 @@ impl<'a> Resolver<'a> {
continue;
}
ConstantItemRibKind(trivial) => {
let features = self.session.features_untracked();
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
if !trivial && self.session.features_untracked().min_const_generics {
if !(trivial
|| features.const_generics
|| features.lazy_normalization_consts)
{
// HACK(min_const_generics): If we encounter `Self` in an anonymous constant
// we can't easily tell if it's generic at this stage, so we instead remember
// this and then enforce the self type to be concrete later on.
Expand Down Expand Up @@ -2713,8 +2717,12 @@ impl<'a> Resolver<'a> {
continue;
}
ConstantItemRibKind(trivial) => {
let features = self.session.features_untracked();
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
if !trivial && self.session.features_untracked().min_const_generics {
if !(trivial
|| features.const_generics
|| features.lazy_normalization_consts)
{
if record_used {
self.report_error(
span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_serialize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Core encoding and decoding interfaces.
#![feature(never_type)]
#![feature(nll)]
#![feature(associated_type_bounds)]
#![feature(min_const_generics)]
#![cfg_attr(bootstrap, feature(min_const_generics))]
#![cfg_attr(test, feature(test))]
#![allow(rustc::internal)]

Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_typeck/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,13 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {

let err_ty_str;
let mut is_ptr = true;
let err = if tcx.features().min_const_generics {
let err = if tcx.features().const_generics {
match ty.peel_refs().kind() {
ty::FnPtr(_) => Some("function pointers"),
ty::RawPtr(_) => Some("raw pointers"),
_ => None,
}
} else {
match ty.kind() {
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Error(_) => None,
ty::FnPtr(_) => Some("function pointers"),
Expand All @@ -304,12 +310,6 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
Some(err_ty_str.as_str())
}
}
} else {
match ty.peel_refs().kind() {
ty::FnPtr(_) => Some("function pointers"),
ty::RawPtr(_) => Some("raw pointers"),
_ => None,
}
};
if let Some(unsupported_type) = err {
if is_ptr {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
// used with const generics, e.g. `Foo<{N+1}>`, can work at all.
//
// Note that we do not supply the parent generics when using
// `feature(min_const_generics)`.
// `min_const_generics`.
Some(parent_def_id.to_def_id())
} else {
let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id));
Expand Down
1 change: 0 additions & 1 deletion src/test/rustdoc-ui/error-in-impl-trait/const-generics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// check-pass
// edition:2018
#![feature(min_const_generics)]
trait ValidTrait {}

/// This has docs
Expand Down
2 changes: 0 additions & 2 deletions src/test/rustdoc/async-fn.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// ignore-tidy-linelength
// edition:2018
#![feature(min_const_generics)]

// @has async_fn/fn.foo.html '//pre[@class="rust fn"]' 'pub async fn foo() -> Option<Foo>'
pub async fn foo() -> Option<Foo> {
None
Expand Down
2 changes: 0 additions & 2 deletions src/test/rustdoc/const-generics/auxiliary/extern_crate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// edition:2018
#![feature(min_const_generics)]

pub fn extern_fn<const N: usize>() -> impl Iterator<Item = [u8; N]> {
[[0; N]; N].iter().copied()
}
Expand Down
1 change: 0 additions & 1 deletion src/test/rustdoc/const-generics/const-generics-docs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// edition:2018
// aux-build: extern_crate.rs
#![feature(min_const_generics)]
#![crate_name = "foo"]

extern crate extern_crate;
Expand Down
1 change: 0 additions & 1 deletion src/test/rustdoc/const-generics/type-alias.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// ignore-tidy-linelength
#![feature(min_const_generics)]
#![crate_name = "foo"]

// @has foo/type.CellIndex.html '//pre[@class="rust typedef"]' 'type CellIndex<const D: usize> = [i64; D];'
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/array-slice-vec/match_arr_unknown_len.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
= help: consider using `min_const_generics` instead, which is more stable and complete

error[E0308]: mismatched types
--> $DIR/match_arr_unknown_len.rs:6:9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ impl Foo for Def {

pub fn test<A: Foo, B: Foo>() {
let _array: [u32; <A as Foo>::Y];
//~^ ERROR the trait bound `A: Foo` is not satisfied [E0277]
//~^ ERROR generic parameters may not be used
}

fn main() {
}
fn main() {}
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
error[E0277]: the trait bound `A: Foo` is not satisfied
--> $DIR/associated-const-type-parameter-arrays.rs:16:23
error: generic parameters may not be used in const operations
--> $DIR/associated-const-type-parameter-arrays.rs:16:24
|
LL | const Y: usize;
| --------------- required by `Foo::Y`
...
LL | let _array: [u32; <A as Foo>::Y];
| ^^^^^^^^^^^^^ the trait `Foo` is not implemented for `A`
| ^ cannot perform const operation using `A`
|
help: consider further restricting this bound
|
LL | pub fn test<A: Foo + Foo, B: Foo>() {
| ^^^^^
= note: type parameters may not be used in const expressions
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ trait Adapter {
struct Foo<A: Adapter> {
adapter: A,
links: [u32; A::LINKS], // Shouldn't suggest bounds already there.
//~^ ERROR: no associated item named `LINKS` found
//~^ ERROR generic parameters may not be used in const operations
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0599]: no associated item named `LINKS` found for type parameter `A` in the current scope
--> $DIR/associated-item-duplicate-bounds.rs:7:21
error: generic parameters may not be used in const operations
--> $DIR/associated-item-duplicate-bounds.rs:7:18
|
LL | links: [u32; A::LINKS], // Shouldn't suggest bounds already there.
| ^^^^^ associated item not found in `A`
| ^^^^^^^^ cannot perform const operation using `A`
|
= help: items from traits can only be used if the type parameter is bounded by the trait
= note: type parameters may not be used in const expressions
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
4 changes: 2 additions & 2 deletions src/test/ui/async-await/issues/issue-78654.full.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0573]: expected type, found built-in attribute `feature`
--> $DIR/issue-78654.rs:10:15
--> $DIR/issue-78654.rs:9:15
|
LL | impl<const H: feature> Foo {
| ^^^^^^^ not a type

error[E0207]: the const parameter `H` is not constrained by the impl trait, self type, or predicates
--> $DIR/issue-78654.rs:10:12
--> $DIR/issue-78654.rs:9:12
|
LL | impl<const H: feature> Foo {
| ^ unconstrained const parameter
Expand Down
Loading