Skip to content

Don’t suggest 'help: add #![feature(…)]' when it’s forbidden #23973

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
SimonSapin opened this issue Apr 2, 2015 · 16 comments · Fixed by #23974
Closed

Don’t suggest 'help: add #![feature(…)]' when it’s forbidden #23973

SimonSapin opened this issue Apr 2, 2015 · 16 comments · Fixed by #23974
Assignees
Milestone

Comments

@SimonSapin
Copy link
Contributor

Steps to reproduce:

mkdir foo
cd foo
multirust override beta  # Or obtain Rust beta in some other way
echo 'extern crate core; fn main(){}' > a.rs
echo '#![feature(core)] extern crate core; fn main(){}' > b.rs

The output of rustc a.rs is:

a.rs:1:1: 1:19 error: use of unstable library feature 'core'
a.rs:1 extern crate core; fn main(){}
       ^~~~~~~~~~~~~~~~~~
a.rs:1:19: 1:19 help: add #![feature(core)] to the crate attributes to enable

b.rs does as suggested by the help message, but that fails too (as expected):

b.rs:1:1: 1:18 error: unstable feature
b.rs:1 #![feature(core)] extern crate core; fn main(){}
       ^~~~~~~~~~~~~~~~~
note: this feature may not be used in the beta release channel
error: aborting due to previous error

Proposed fix: in the beta and stable channels (i.e. whenever #![feature(…)] is forbidden), the help message that suggests adding #![feature(…)] should not be shown.

(Clean up the test case with multirust remove-override; cd ..; rm -r foo.)

CC @brson

@steveklabnik steveklabnik added this to the 1.0 beta milestone Apr 2, 2015
@steveklabnik
Copy link
Member

Gonna milestone this real quick, as it seems quite important.

@pnkfelix
Copy link
Member

pnkfelix commented Apr 2, 2015

I might be able to whip up a quick fix, though I'm not 100% sure about testing it properly ... (I've never actually tried building something for a non-dev release channel before...)

@steveklabnik
Copy link
Member

after chatting with @pnkfelix it seems like I have a patch, building it now

@steveklabnik
Copy link
Member

gonna leave @pnkfelix to it

bors added a commit that referenced this issue Apr 3, 2015
Do not suggest `#![feature(...)]` if we are in beta or stable channel.

Fix #23973
@conradkleinespel
Copy link
Contributor

Hello good Rust folks 😄

Before the beta, I used std::slice::bytes:MutableByteVector which is in core. Is there any way to use this trait during the beta ? I'm not sure how I can get the code to compile.

Thanks for any tip / hints you can offer 👍

@SimonSapin
Copy link
Contributor Author

Hi @conradkleinespel. Commenting on random unrelated issues is usually not the right thing to do. You should rather open a new issue, or ask on http://users.rust-lang.org/ . But to answer your question anyway, that trait only has one method:

    /// A trait for operations on mutable `[u8]`s.
    pub trait MutableByteVector {
        /// Sets all bytes of the receiver to the given value.
        fn set_memory(&mut self, value: u8);
    }

    impl MutableByteVector for [u8] {
        #[inline]
        fn set_memory(&mut self, value: u8) {
            unsafe { ptr::write_bytes(self.as_mut_ptr(), value, self.len()) };
        }
    }

… and std::ptr::write_bytes is stable and can be used on beta. So I’d recommend you copy/paste the trait into your code, or make a function.

@conradkleinespel
Copy link
Contributor

@SimonSapin Thanks for taking the time to answer. I appreciate it.

I don't see how this is unrelated. This is related, since the code I'm talking about used to compile with #![feature(core)] and the compiler suggests to do that, during the beta period.

Thanks for your tip on copying the function 👍 I guess I'll just do that if nothing better is available and change this again when the trait is stable.

@SimonSapin
Copy link
Contributor Author

This specific issue is about fixing one of the compiler’s error message, not about fixing code that triggers that error. It really helps everyone to keep discussions on topic.

@conradkleinespel
Copy link
Contributor

Alright. I understand. I'll make sure to open a new issue or go on StackOverflow next time if appropriate. Thanks again 👍

@jonalmeida
Copy link

This doesn't seem to be properly fixed in the beta channel. I'm still being recommended to add #![feature(libc)] in the errors, and then told it's not available in the beta channel.

[/tmp] rustc snappy.rs
snappy.rs:1:1: 1:19 error: use of unstable library feature 'libc'
snappy.rs:1 extern crate libc;
            ^~~~~~~~~~~~~~~~~~
snappy.rs:1:19: 1:19 help: add #![feature(libc)] to the crate attributes to enable
snappy.rs:2:5: 2:17 error: use of unstable library feature 'libc'
snappy.rs:2 use libc::size_t;
                ^~~~~~~~~~~~
snappy.rs:2:17: 2:17 help: add #![feature(libc)] to the crate attributes to enable
snappy.rs:6:56: 6:62 error: use of unstable library feature 'libc'
snappy.rs:6         fn snappy_max_compressed_length(source_length: size_t) -> size_t;
                                                                   ^~~~~~
snappy.rs:6:62: 6:62 help: add #![feature(libc)] to the crate attributes to enable
snappy.rs:6:67: 6:73 error: use of unstable library feature 'libc'
snappy.rs:6         fn snappy_max_compressed_length(source_length: size_t) -> size_t;
                                                                              ^~~~~~
snappy.rs:6:73: 6:73 help: add #![feature(libc)] to the crate attributes to enable
error: aborting due to 4 previous errors
[/tmp] rustc snappy.rs
snappy.rs:1:1: 1:18 error: unstable feature
snappy.rs:1 #![feature(libc)]
            ^~~~~~~~~~~~~~~~~
note: this feature may not be used in the beta release channel
error: aborting due to previous error

Rust version:

[/tmp] rustc --version
rustc 1.0.0-beta (9854143cb 2015-04-02) (built 2015-04-02)

The code I used (snappy example in the docs with the extra addition on the first line:

#![feature(libc)]
extern crate libc;
use libc::size_t;

#[link(name = "snappy")]
extern {
        fn snappy_max_compressed_length(source_length: size_t) -> size_t;
}

fn main() {
        let x = unsafe { snappy_max_compressed_length(100) };
            println!("max compressed length of a 100 byte buffer: {}", x); 
}

@bombless
Copy link
Contributor

bombless commented Apr 8, 2015

This happened after Beta release.
We'll see the effect of this patch in 1.0 and afterwards Beta, etc.

@jonalmeida
Copy link

Whoops, I thought this made it in before beta. Thanks!

@SimonSapin
Copy link
Contributor Author

@brson, are there plans to release updates to the beta channel within a given 6 weeks cycle? Either this one or in the future.

@pnkfelix
Copy link
Member

pnkfelix commented Apr 8, 2015

@ghost
Copy link

ghost commented Apr 16, 2015

So how does one fix this error? I'm a new user of the rust library and I can't seem to use the collections library during the beta due to this problem. Given this git issue is a top google result, it would be nice if there were a solution here.

Edit: Looks like the solution is to switch to the rust nightly. Is the entire collections library off-limits in the beta?

@pnkfelix
Copy link
Member

@Russell91 by design, you have access to the parts of libcollections that are re-exported from libstd (and are stable).

http://doc.rust-lang.org/1.0.0-beta/std/collections/

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.

7 participants