Skip to content

Commit

Permalink
impl review
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Aug 5, 2020
1 parent a5a5ca0 commit 0d54f57
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/librustc_ast_passes/feature_gate.rs
Expand Up @@ -530,7 +530,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
&self,
|x: &Features| x.const_generics || x.min_const_generics,
param.ident.span,
sym::const_generics,
sym::min_const_generics,
"const generics are unstable"
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/generics.rs
Expand Up @@ -54,7 +54,7 @@ impl<'a> Parser<'a> {
self.expect(&token::Colon)?;
let ty = self.parse_ty()?;

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

Ok(GenericParam {
ident,
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_typeck/collect/type_of.rs
Expand Up @@ -330,6 +330,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
let err = if tcx.features().min_const_generics {
match ty.kind {
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Error(_) => None,
ty::FnPtr(_) => Some("function pointers"),
ty::RawPtr(_) => Some("raw pointers"),
_ => {
err_ty_str = format!("`{}`", ty);
Some(err_ty_str.as_str())
Expand All @@ -352,7 +354,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
);

if tcx.features().min_const_generics {
err.note("the only supported types are integers, `bool` and `char`").emit()
err.note("the only supported types are integers, `bool` and `char`")
.note("more complex types are supported with `#[feature(const_generics)]`").emit()
} else {
err.emit();
}
Expand Down
Expand Up @@ -4,8 +4,8 @@ error[E0658]: const generics are unstable
LL | trait Trait<const T: ()> {}
| ^
|
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
= help: add `#![feature(const_generics)]` to the crate attributes to enable
= note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
= help: add `#![feature(min_const_generics)]` to the crate attributes to enable

error: aborting due to previous error

Expand Down
Expand Up @@ -10,8 +10,8 @@ error[E0658]: const generics are unstable
LL | struct B<T, const N: T>(PhantomData<[T; N]>);
| ^
|
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
= help: add `#![feature(const_generics)]` to the crate attributes to enable
= note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
= help: add `#![feature(min_const_generics)]` to the crate attributes to enable

error: aborting due to 2 previous errors

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/issues/issue-60263.stderr
Expand Up @@ -4,8 +4,8 @@ error[E0658]: const generics are unstable
LL | struct B<const I: u8>;
| ^
|
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
= help: add `#![feature(const_generics)]` to the crate attributes to enable
= note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
= help: add `#![feature(min_const_generics)]` to the crate attributes to enable

error: aborting due to previous error

Expand Down
Expand Up @@ -5,6 +5,7 @@ LL | struct Foo<const N: [u8; 0]>;
| ^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: more complex types are supported with `#[feature(const_generics)]`

error: using `()` as const generic parameters is forbidden
--> $DIR/complex-types.rs:6:21
Expand All @@ -13,6 +14,7 @@ LL | struct Bar<const N: ()>;
| ^^
|
= note: the only supported types are integers, `bool` and `char`
= note: more complex types are supported with `#[feature(const_generics)]`

error: using `No` as const generic parameters is forbidden
--> $DIR/complex-types.rs:12:21
Expand All @@ -21,6 +23,7 @@ LL | struct Fez<const N: No>;
| ^^
|
= note: the only supported types are integers, `bool` and `char`
= note: more complex types are supported with `#[feature(const_generics)]`

error: using `&'static u8` as const generic parameters is forbidden
--> $DIR/complex-types.rs:15:21
Expand All @@ -29,6 +32,7 @@ LL | struct Faz<const N: &'static u8>;
| ^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: more complex types are supported with `#[feature(const_generics)]`

error: aborting due to 4 previous errors

Expand Up @@ -4,8 +4,8 @@ error[E0658]: const generics are unstable
LL | fn test<const N: usize>() {}
| ^
|
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
= help: add `#![feature(const_generics)]` to the crate attributes to enable
= note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
= help: add `#![feature(min_const_generics)]` to the crate attributes to enable

error: aborting due to previous error

Expand Down
Expand Up @@ -4,17 +4,17 @@ error[E0658]: const generics are unstable
LL | struct ConstFn<const F: fn()>;
| ^
|
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
= help: add `#![feature(const_generics)]` to the crate attributes to enable
= note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
= help: add `#![feature(min_const_generics)]` to the crate attributes to enable

error[E0658]: const generics are unstable
--> $DIR/feature-gate-const_generics-ptr.rs:5:23
|
LL | struct ConstPtr<const P: *const u32>;
| ^
|
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
= help: add `#![feature(const_generics)]` to the crate attributes to enable
= note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
= help: add `#![feature(min_const_generics)]` to the crate attributes to enable

error: using function pointers as const generic parameters is forbidden
--> $DIR/feature-gate-const_generics-ptr.rs:1:25
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/feature-gates/feature-gate-const_generics.stderr
Expand Up @@ -4,17 +4,17 @@ error[E0658]: const generics are unstable
LL | fn foo<const X: ()>() {}
| ^
|
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
= help: add `#![feature(const_generics)]` to the crate attributes to enable
= note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
= help: add `#![feature(min_const_generics)]` to the crate attributes to enable

error[E0658]: const generics are unstable
--> $DIR/feature-gate-const_generics.rs:3:18
|
LL | struct Foo<const X: usize>([(); X]);
| ^
|
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
= help: add `#![feature(const_generics)]` to the crate attributes to enable
= note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
= help: add `#![feature(min_const_generics)]` to the crate attributes to enable

error: aborting due to 2 previous errors

Expand Down

0 comments on commit 0d54f57

Please sign in to comment.