Skip to content

ICE when trying to assign to unsafe pointer #9706

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

Closed
toffaletti opened this issue Oct 3, 2013 · 5 comments
Closed

ICE when trying to assign to unsafe pointer #9706

toffaletti opened this issue Oct 3, 2013 · 5 comments

Comments

@toffaletti
Copy link
Contributor

use std::ptr::{mut_null, to_mut_unsafe_ptr};

struct Foo {
    priv data: *mut Foo,
}

impl Foo {
    fn get_foo(&mut self) -> *mut Foo {
        self.data
    }
}

fn main() {
    let mut f = Foo{data: mut_null()};
    f.get_foo() = to_mut_unsafe_ptr(&mut f);
}
$ rustc ice.rs 
ice.rs:15:4: 15:17 error: internal compiler error: trans_lvalue reached fall-through case: ExprMethodCall(33, @syntax::ast::Expr{id: 34, node: ExprPath(syntax::ast::Path{span: syntax::codemap::Span{lo: syntax::codemap::BytePos(220u), hi: syntax::codemap::BytePos(221u), expn_info: None}, global: false, segments: ~[syntax::ast::PathSegment{identifier: syntax::ast::Ident{name: 78u, ctxt: 29u}, lifetime: None, types: Empty}]}), span: syntax::codemap::Span{lo: syntax::codemap::BytePos(220u), hi: syntax::codemap::BytePos(221u), expn_info: None}}, syntax::ast::Ident{name: 77u, ctxt: 29u}, ~[], ~[], NoSugar)
ice.rs:15     f.get_foo() = to_mut_unsafe_ptr(&mut f);
@bmaxa
Copy link

bmaxa commented Oct 3, 2013

I think this is not related to unsafe pointer,rather to assigning to a value, eg return anything
not assignable and you will get ICE.

@alexcrichton
Copy link
Member

It appears that @bmaxa is correct, this code also ICEs

fn foo() -> int { 3 }

fn main() {          
    foo() = 3;       
}                    

It appears the typechecker ensures that the lhs and rhs have the same type, but not that the lhs is actually an assignable location...

@alexcrichton
Copy link
Member

cc @nikomatsakis

@klutzy
Copy link
Contributor

klutzy commented Oct 4, 2013

Seems like dup of #7507.

@toffaletti
Copy link
Contributor Author

Agreed.

flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 21, 2022
Fix `bool_to_int_with_if` false positive with `if let`

Fixes rust-lang#9706

changelog: FP: [`bool_to_int_with_if`]: Now ignores `if let` statements
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

No branches or pull requests

4 participants