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

const fn: Improve wording #59646

Merged
merged 3 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ fn check_terminator(
abi::Abi::Rust if tcx.is_min_const_fn(def_id) => {},
abi::Abi::Rust => return Err((
span,
"can only call other `min_const_fn` within a `min_const_fn`".into(),
"can only call other `const` within a `const`".into(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like can only call another `const fn` within a `const` block sounds more natural.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither this PR nor the suggestion is accurate. This is not a const block (and with rust-lang/rfcs#2632 it will not always behave in a similar fashion).

Moreover, I think we lose out on the difference between stable const fns and unstable ones. This is the main point of min_const_fns... I think we should check whether the current compiler can use unstable features and tweak the message based on that. E.g. a stable compiler can just talk about const fns but the nightly compiler should emphasize the difference between stable and unstable ones.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change it to

can only call other stable `const fn` within a stable `const fn`

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, in that case we should make the error more explicit and add a note to the unstable const fn pointing out that it is undertake.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is, it's not clear whether it's the containing function or the called function that is the problem (or both).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is to be used same wording without distinction, I think. Should we try to work on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinda both. I'm not sure how easy it is to point to the unstable const fn, since it might be in another crate. We can just use a more verbose wording like

can only call other const fn within a const fn, but insert_fn_name_here is not stable as const fn

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oli-obk I changed wording.

)),
abi => return Err((
span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const fn foo() -> u32 { 42 }

#[stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const fn bar() -> u32 { foo() } //~ ERROR can only call other `min_const_fn`
const fn bar() -> u32 { foo() } //~ ERROR can only call other `const`

#[unstable(feature = "rust1", issue="0")]
const fn foo2() -> u32 { 42 }

#[stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const fn bar2() -> u32 { foo2() } //~ ERROR can only call other `min_const_fn`
const fn bar2() -> u32 { foo2() } //~ ERROR can only call other `const`

#[stable(feature = "rust1", since = "1.0.0")]
// conformity is required, even with `const_fn` feature gate
Expand All @@ -31,6 +31,6 @@ const fn foo2_gated() -> u32 { 42 }

#[stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const fn bar2_gated() -> u32 { foo2_gated() } //~ ERROR can only call other `min_const_fn`
const fn bar2_gated() -> u32 { foo2_gated() } //~ ERROR can only call other `const`

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563)
error[E0723]: can only call other `const` within a `const` (see issue #57563)
--> $DIR/min_const_fn_libstd_stability.rs:15:25
|
LL | const fn bar() -> u32 { foo() }
| ^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563)
error[E0723]: can only call other `const` within a `const` (see issue #57563)
--> $DIR/min_const_fn_libstd_stability.rs:22:26
|
LL | const fn bar2() -> u32 { foo2() }
Expand All @@ -22,7 +22,7 @@ LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 }
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563)
error[E0723]: can only call other `const` within a `const` (see issue #57563)
--> $DIR/min_const_fn_libstd_stability.rs:34:32
|
LL | const fn bar2_gated() -> u32 { foo2_gated() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const unsafe fn foo() -> u32 { 42 }

#[stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const unsafe fn bar() -> u32 { unsafe { foo() } } //~ ERROR can only call other `min_const_fn`
const unsafe fn bar() -> u32 { unsafe { foo() } } //~ ERROR can only call other `const`

#[unstable(feature = "rust1", issue="0")]
const unsafe fn foo2() -> u32 { 42 }

#[stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const unsafe fn bar2() -> u32 { unsafe { foo2() } } //~ ERROR can only call other `min_const_fn`
const unsafe fn bar2() -> u32 { unsafe { foo2() } } //~ ERROR can only call other `const`

#[stable(feature = "rust1", since = "1.0.0")]
// conformity is required, even with `const_fn` feature gate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563)
error[E0723]: can only call other `const` within a `const` (see issue #57563)
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:15:41
|
LL | const unsafe fn bar() -> u32 { unsafe { foo() } }
| ^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563)
error[E0723]: can only call other `const` within a `const` (see issue #57563)
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:22:42
|
LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } }
Expand All @@ -22,7 +22,7 @@ LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 }
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563)
error[E0723]: can only call other `const` within a `const` (see issue #57563)
--> $DIR/min_const_unsafe_fn_libstd_stability.rs:34:48
|
LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ const fn foo() -> u32 { 42 }

#[stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const unsafe fn bar() -> u32 { foo() } //~ ERROR can only call other `min_const_fn`
const unsafe fn bar() -> u32 { foo() } //~ ERROR can only call other `const`

#[unstable(feature = "rust1", issue="0")]
const fn foo2() -> u32 { 42 }

#[stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const unsafe fn bar2() -> u32 { foo2() } //~ ERROR can only call other `min_const_fn`
const unsafe fn bar2() -> u32 { foo2() } //~ ERROR can only call other `const`

// check whether this function cannot be called even with the feature gate active
#[unstable(feature = "foo2", issue="0")]
const fn foo2_gated() -> u32 { 42 }

#[stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const unsafe fn bar2_gated() -> u32 { foo2_gated() } //~ ERROR can only call other `min_const_fn`
const unsafe fn bar2_gated() -> u32 { foo2_gated() } //~ ERROR can only call other `const`

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563)
error[E0723]: can only call other `const` within a `const` (see issue #57563)
--> $DIR/min_const_unsafe_fn_libstd_stability2.rs:15:32
|
LL | const unsafe fn bar() -> u32 { foo() }
| ^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563)
error[E0723]: can only call other `const` within a `const` (see issue #57563)
--> $DIR/min_const_unsafe_fn_libstd_stability2.rs:22:33
|
LL | const unsafe fn bar2() -> u32 { foo2() }
| ^^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563)
error[E0723]: can only call other `const` within a `const` (see issue #57563)
--> $DIR/min_const_unsafe_fn_libstd_stability2.rs:30:39
|
LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() }
Expand Down