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

Can create &mut with only & in statics #18939

Closed
huonw opened this issue Nov 14, 2014 · 5 comments
Closed

Can create &mut with only & in statics #18939

huonw opened this issue Nov 14, 2014 · 5 comments
Labels
P-medium Medium priority

Comments

@huonw
Copy link
Member

huonw commented Nov 14, 2014

This compiles fine:

#![allow(dead_code)]

static FOO: [uint, .. 2] = [0, 0];
static BAR: &'static mut [uint, .. 2] = & FOO;

fn main() {}
@nikomatsakis
Copy link
Contributor

What the !@#!@#!@

@pnkfelix
Copy link
Member

very weird, seems highly misleading... but ... also not a high priority to fix, since one cannot actually write through *BAR, nor does it work if FOO is static mut.

So, P-high, not 1.0.

@pnkfelix pnkfelix added P-medium Medium priority and removed I-nominated labels Nov 20, 2014
@pythonesque
Copy link
Contributor

@pnkfelix True, but you can still get aliased &muts through it quite easily, which you're not supposed to be able to do in safe code. I agree it's a weird situation.

@nham
Copy link
Contributor

nham commented May 6, 2015

This seems to be fixed in the current nightly. The updated code is

static FOO: [usize; 2] = [0, 0];
static BAR: &'static mut [usize; 2] = & FOO;

fn main() {}

It does not compile:

test_18939.rs:2:39: 2:44 error: mismatched types:
 expected `&'static mut [usize; 2]`,
    found `&[usize; 2]`
(values differ in mutability) [E0308]
test_18939.rs:2 static BAR: &'static mut [usize; 2] = & FOO;
                                                      ^~~~~
error: aborting due to previous error

rustc version:

rustc 1.1.0-nightly (435622028 2015-05-04) (built 2015-05-05)

@steveklabnik
Copy link
Member

Thanks @nham !

lnicola pushed a commit to lnicola/rust that referenced this issue Jan 20, 2025
Flip on typing config to be opt-in, better defaults
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

6 participants