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

Are generics under #![no_std] implicitly DST now? #15788

Closed
pnkfelix opened this issue Jul 18, 2014 · 2 comments
Closed

Are generics under #![no_std] implicitly DST now? #15788

pnkfelix opened this issue Jul 18, 2014 · 2 comments
Labels
A-DSTs Area: Dynamically-sized types (DSTs) A-type-system Area: Type system

Comments

@pnkfelix
Copy link
Member

Transcript of something that I saw today that I thought was odd:

% cat /tmp/foo_no_std.rs
#![no_std]
#![crate_type="lib"]

pub fn foo<T>(b: bool, x: T, f: |T| -> int) -> int {
    if b {
        f(x)
    } else {
        3
    }
}
% cat /tmp/foo_w_std.rs
#![crate_type="lib"]

pub fn foo<T>(b: bool, x: T, f: |T| -> int) -> int {
    if b {
        f(x)
    } else {
        3
    }
}
% ~/opt/rust-0.10/bin/rustc --version
/Users/fklock/opt/rust-0.10/bin/rustc 0.10 (46867cc 2014-04-02 16:59:39 -0700)
host: x86_64-apple-darwin
% ~/opt/rust-0.11/bin/rustc --version
rustc 0.11.0 (aa1163b92de7717eb7c5eba002b4012e0574a7fe 2014-06-27 12:50:16 -0700)
% ~/opt/rust-0.10/bin/rustc /tmp/foo_w_std.rs
% ~/opt/rust-0.10/bin/rustc /tmp/foo_no_std.rs
% ~/opt/rust-0.11/bin/rustc /tmp/foo_w_std.rs
% ~/opt/rust-0.11/bin/rustc /tmp/foo_no_std.rs
/tmp/foo_no_std.rs:4:24: 4:25 error: variable `x` has dynamically sized type `T`
/tmp/foo_no_std.rs:4 pub fn foo<T>(b: bool, x: T, f: |T| -> int) -> int {
                                            ^
error: aborting due to previous error
% 

Now, to be fair, I do remember that I had to start adding the trait Sized with the appropriate lang item when using #![no_std] at some point. And that was okay, because I got a message telling me to do so (or at least, a message saying it was missing, which is close enough).

But this seems to go a step further and somehow remove the implicit Sized-ness from generic type parameters? (Or have I overlooked some obvious goof in the code above?)


At @cmr's suggestion, I changed the code to this:

#![feature(lang_items)]
#![no_std]
#![crate_type="lib"]

#[lang="sized"] pub trait Sized { }

pub fn foo<T>(b: bool, x: T, f: |T| -> int) -> int {
    if b {
        f(x)
    } else {
        3
    }
}

And it now compiles.

So okay -- maybe we just need to improve the error reporting for the original case to check if the Sized lang item is defined, and if not, include a note to the user that they may want to add it.

@pnkfelix
Copy link
Member Author

cc @nick29581

@steveklabnik steveklabnik added A-DSTs Area: Dynamically-sized types (DSTs) A-type-system Area: Type system labels Jan 23, 2015
@alexcrichton
Copy link
Member

I think enough has changed that this is no longer a valid bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-DSTs Area: Dynamically-sized types (DSTs) A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

3 participants