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

~Foo should auto-borrow to &Foo when casting to a trait object #10347

Closed
sfackler opened this issue Nov 8, 2013 · 5 comments
Closed

~Foo should auto-borrow to &Foo when casting to a trait object #10347

sfackler opened this issue Nov 8, 2013 · 5 comments

Comments

@sfackler
Copy link
Member

sfackler commented Nov 8, 2013

It'd be nice if this would work:

trait Foo {}
impl<'self> Foo for &'self str {}
let a = ~"";
let b = &a as &Foo;

You currently have to manually borrow

trait Foo {}
impl<'self> Foo for &'self str {}
let a = ~"";
let b: &str = a;
let b = &b as &Foo;
sfackler added a commit to sfackler/rust-postgres that referenced this issue Nov 8, 2013
Turns out ~T won't actually autoborrow to &T when casting to a trait
object. See rust-lang/rust#10347

This reverts commit c2a755d.
@nikomatsakis
Copy link
Contributor

I feel like this is a dup but can't find the other issue. I agree; this shouldn't be too hard. cc me.

@jdm
Copy link
Contributor

jdm commented Nov 8, 2013

Dup of #10039.

@sfackler
Copy link
Member Author

sfackler commented Nov 8, 2013

I don't think this is a dup of #10039. Auto-borrowing of a ~MyStruct to a &MyStruct seems distinct from auto casting &MyStruct to &SomeTrait.

@nikomatsakis
Copy link
Contributor

Agreed, not a dup of that particular issue.

@alexcrichton
Copy link
Member

Due to RFC 37, I don't think that this is as high priority any more, and it should go through the RFC process if so (it's a language change).

Jarcho pushed a commit to Jarcho/rust that referenced this issue Feb 26, 2023
Add new lint no_mangle_with_rust_abi

Fixes issue rust-lang#10347

This PR adds a new lint `no_mangle_with_rust_abi` that suggests converting a function to the C ABI to if the function has the `#[no_mangle]` attribute and `Abi == Abi::Rust`. It will not run for any of the other variants defined in [rustc_target::spec::abi::Abi](https://doc.rust-lang.org/beta/nightly-rustc/rustc_target/spec/abi/enum.Abi.html), nor suggest any conversion other than conversion to the C ABI.

Functions that explicitly opt into the Rust ABI with `extern "Rust"` are ignored by this lint.

---

changelog: [`no_mangle_with_rust_abi`]: add lint that converts Rust ABI functions with the `#[no_mangle]` attribute to C ABI
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