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

Improve the error explanations for check_const #30932

Merged
merged 1 commit into from
Jan 24, 2016

Conversation

arielb1
Copy link
Contributor

@arielb1 arielb1 commented Jan 15, 2016

Fixes #30705

r? @nagisa

const Y: usize = &X as *const u32 as usize;
println!("{}", Y);
static MY_STATIC_ADDR: &'static u32 = &MY_STATIC;
// ..and also
Copy link
Member

Choose a reason for hiding this comment

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

"// ..and also"? Isn't "// ... and also" better?

@nagisa
Copy link
Member

nagisa commented Jan 15, 2016

Looks like an overall improvement.

@arielb1
Copy link
Contributor Author

arielb1 commented Jan 15, 2016

improved

To fix this error, please do not assign this value to a constant expression.
Example:
To fix this, you should dereference your pointer at some point in
run-time.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is wrong. This document already contains various cases of wrong advice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

If the problem is that you need the value behind a pointer in a static variable, then not putting the value in a static variable does not fix the problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not like you can solve the problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure how important is the "how to fix this" advice, because each issue will have its own fix.

Then MY_STATIC_ADDR would contain the address of MY_STATIC. However,
the address can change when the program is linked, as well as change
between different executions due to ASLR, and many linkers would
not be able to calculate the value of WHAT.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This paragraph should use inline code for the constant names.

@nagisa
Copy link
Member

nagisa commented Jan 15, 2016

r=me once the two nits are fixed.

@arielb1
Copy link
Contributor Author

arielb1 commented Jan 19, 2016

fixed ^

@nagisa
Copy link
Member

nagisa commented Jan 19, 2016

@bors r+ cad3882

@nagisa
Copy link
Member

nagisa commented Jan 19, 2016

@bors rollup

@bors
Copy link
Contributor

bors commented Jan 21, 2016

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

@bors
Copy link
Contributor

bors commented Jan 23, 2016

🔒 Merge conflict

@arielb1
Copy link
Contributor Author

arielb1 commented Jan 24, 2016

@bors r=nagisa rollup

@bors
Copy link
Contributor

bors commented Jan 24, 2016

📌 Commit 47593da has been approved by nagisa

@bors
Copy link
Contributor

bors commented Jan 24, 2016

⌛ Testing commit 47593da with merge 5a81d9a...

bors added a commit that referenced this pull request Jan 24, 2016
@bors bors merged commit 47593da into rust-lang:master Jan 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants