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

Add long diagnostics for E0018 #24525

Merged
merged 2 commits into from Apr 20, 2015

Conversation

@GuillaumeGomez
Copy link
Member

commented Apr 17, 2015

Part of #24407.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Apr 17, 2015

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@@ -112,6 +112,11 @@ reference when using guards or refactor the entire expression, perhaps by
putting the condition inside the body of the arm.
"##,

E0018: r##"
The value of static and const variables must be known at the compile-time which is

This comment has been minimized.

Copy link
@apasel422

apasel422 Apr 17, 2015

Member

s/the compile-time which/compile time, which/

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Apr 17, 2015

Author Member

I'm don't get your point.

This comment has been minimized.

Copy link
@bombless

bombless Apr 17, 2015

Contributor

He means "... value of static and const variables must be known at compile time, which is ...".
And I think he's right.

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Apr 17, 2015

Author Member

Oh right ! Thanks !

@@ -112,6 +112,11 @@ reference when using guards or refactor the entire expression, perhaps by
putting the condition inside the body of the arm.
"##,

E0018: r##"
The value of static and const variables must be known at the compile-time which is
not possible with a pointer or with a value pointed by a pointer.

This comment has been minimized.

Copy link
@apasel422

apasel422 Apr 17, 2015

Member

"value pointed by a pointer" -- I'm not sure what to change this to, but it's not exactly grammatically correct as is.

This comment has been minimized.

Copy link
@GuillaumeGomez

GuillaumeGomez Apr 17, 2015

Author Member

I'm not an english native so yes, don't hesitate to correct me !

This comment has been minimized.

Copy link
@pnkfelix

pnkfelix Apr 19, 2015

Member

"a value referenced by a pointer" is probably closer to correct. (Though I would need to review where this error message is used to know if that is actually the intention.)

Valid:

  • "P points at X" or "P points to X"
  • "P references X"

Invalid:

  • "P points X" --- this is wrong (unless P is a mason/bricklayer and X is a chimney -- that's a joke).

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:check-const branch 2 times, most recently from 55eabfc to 3434062 Apr 17, 2015

@pnkfelix

This comment has been minimized.

Copy link
Member

commented Apr 17, 2015

Don't you need to delete the other entry too?

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

commented Apr 18, 2015

@pnkfelix: Totally, thanks for noticing me !

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:check-const branch from 3434062 to 123b7dd Apr 18, 2015

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

commented Apr 18, 2015

And it's done !

@bors

This comment has been minimized.

Copy link
Contributor

commented Apr 18, 2015

☔️ The latest upstream changes (presumably #24562) made this pull request unmergeable. Please resolve the merge conflicts.

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:check-const branch from 123b7dd to 5f20141 Apr 18, 2015

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

commented Apr 18, 2015

@apasel422: Did you find another way ? For my french mind, it seems totally fine haha.

@michaelsproul

This comment has been minimized.

Copy link
Contributor

commented Apr 19, 2015

I think the explanation needs a bit more detail to fully convey the subtlety of this error. Pointers are allowed in const items, just not pointers cast to integers. See RFC 246, particularly the section on const => const and the bug that introduced this error, #18294.

I think an ideal explanation for this error should cover these points:

  • Pointers to other constants are allowed in constants, although the address will be non-constant.
// This is fine.
const X: u32 = 50;
const Y: *const u32 = &X;
println!("{:?}", Y);
  • Therefore, casting one of these non-constant pointers to an integer results in a non-constant integer (as observed by running the above program), thus triggering E0018.

You could also link to the RFC and the issue.

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

commented Apr 19, 2015

@michaelsproul: I don't think giving links to RFC/issue was a good idea. I added your explanations. Do you find something else to correct or add ?

E0018: r##"
The value of static and const variables must be known at compile time. You
can't cast an integer as a pointer because we can't know what value will be
at the address.

This comment has been minimized.

Copy link
@michaelsproul

michaelsproul Apr 19, 2015

Contributor

This looks great except for the second sentence here. I think integer as a pointer should be pointer as an integer and what value will be at the address should be what value the address will take.

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:check-const branch from 91aa6cf to 8a6980c Apr 19, 2015

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

commented Apr 19, 2015

@michaelsproul: It's corrected ! Thanks again !

@michaelsproul

This comment has been minimized.

Copy link
Contributor

commented Apr 19, 2015

@GuillaumeGomez: Looks good to me 👍

```
Therefore, casting one of these non-constant pointers to an integer results
in a non-constant integer whichs lead to this error. Example:

This comment has been minimized.

Copy link
@pnkfelix

pnkfelix Apr 20, 2015

Member

typo: "whichs lead to this error" is not correct. Should be "which"

can't cast a pointer as an integer because we can't know what value the
address will take.
However, pointers to other constants' address are allowed in constants,

This comment has been minimized.

Copy link
@pnkfelix

pnkfelix Apr 20, 2015

Member

hmm, grammatically, it needs to use "address_es_" (plural) here, since you have an apostrophe after the "s" in "constants'".

That, or make it consistently singular, like so:

"However, a pointer to another constant's address is allowed in a constant. Example: ..."

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

commented Apr 20, 2015

@pnkfelix: It's corrected, thanks !

@pnkfelix

This comment has been minimized.

Copy link
Member

commented Apr 20, 2015

@bors r+ 737005a rollup

@bors

This comment has been minimized.

Copy link
Contributor

commented Apr 20, 2015

⌛️ Testing commit 737005a with merge fe11393...

bors added a commit that referenced this pull request Apr 20, 2015

@bors bors merged commit 737005a into rust-lang:master Apr 20, 2015

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@GuillaumeGomez GuillaumeGomez deleted the GuillaumeGomez:check-const branch Apr 20, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.