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

Borrows of unsafe immubtable static items is permitted on constructors #13005

Closed
flaper87 opened this issue Mar 18, 2014 · 0 comments · Fixed by #13083
Closed

Borrows of unsafe immubtable static items is permitted on constructors #13005

flaper87 opened this issue Mar 18, 2014 · 0 comments · Fixed by #13083

Comments

@flaper87
Copy link
Contributor

This is currently valid and it shouldn't be.

The issue is in borrowck::gather_loans::mod:: specifically in the gather_loans_for_static_initializer function. This should be fixed by implementing a small Visitor that will walk the passed expr and look for cases like the one in the example below:

struct Wrap<T> { value: T }
static UNSAFE: Unsafe<int> = Unsafe{value: 1, marker1: marker::InvariantType};
static WRAPPED_UNSAFE: Wrap<&'static Unsafe<int>> = Wrap { value: &UNSAFE };

fn main() {}

cc @nikomatsakis

@flaper87 flaper87 self-assigned this Mar 18, 2014
bors added a commit that referenced this issue Mar 25, 2014
…, r=nikomatsakis

It was possible to borrow unsafe static items in static initializers.
This patch implements a small `Visitor` that walks static initializer's
expressions and checks borrows aliasability.

Fixes #13005

cc @nikomatsakis r?
@flaper87 flaper87 removed their assignment Jun 16, 2014
JohnTitor pushed a commit to JohnTitor/rust that referenced this issue Sep 6, 2022
…-to-matches-macro, r=jonas-schievink

feature: Assist to turn match into matches! invocation

Resolves rust-lang#12510

This PR adds an assist, which convert 2-arm match that evaluates to a boolean into the equivalent matches! invocation.
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 a pull request may close this issue.

1 participant