Stream: t-compiler/help

Topic: stability flags


Alex Griffiths (Jul 25 2020 at 04:18, on Zulip):

Hi there. I'm currently working on issue #60302, cleaning up some of the longer files in the compiler code.

I think I'm making some okay progress (albeit slowly - sorry). I've come across a build error about stability flags. I had a quick read about the stability process and I had a few questions. I'm currently just extracting various structs and impl blocks that I think (I am not sure if anything I'm doing is correct, I guess I'll find out during the pull request phase?) can be kept in their own modules while still trying to keep them related to their original file. Some of these structs that I'm putting into their own modules are throwing errors like this: error: field has missing stability attribute.

How should I proceed with these errors. Is there a flag I can add to ignore this (would I even want to ignore this) or do I need to go through the process of adding the stability attribute? After all these aren't really new features. I've just copied and pasted some code into new files.

Joshua Nelson (Jul 25 2020 at 10:07, on Zulip):

@Alex Griffiths it would help if you could give an example of the errors. Maybe some of these fields are being explicitly whitelisted elsewhere?

Alex Griffiths (Jul 25 2020 at 10:12, on Zulip):

Sure thing. Give me a sec.

Alex Griffiths (Jul 25 2020 at 10:17, on Zulip):
error: field has missing stability attribute
 --> src/libcore/str/utf8.rs:6:5
  |
6 |     pub valid_up_to: usize,
  |     ^^^^^^^^^^^^^^^^^^^^^^

error: field has missing stability attribute
 --> src/libcore/str/utf8.rs:7:5
  |
7 |     pub error_len: Option<u8>,
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^

Then the struct in utf8.rs

pub struct Utf8Error {
    pub valid_up_to: usize,
    pub error_len: Option<u8>,
}

The Utf8Error struct is included in the libcore/str/mod.rs

Alex Griffiths (Jul 25 2020 at 10:18, on Zulip):

Oh also, sorry, since I directly cut this struct out of the mod.rs file as well,

Alex Griffiths (Jul 25 2020 at 10:18, on Zulip):

Above it is the flag #[stable(feature = "rust1", since="1.0.0")]

lcnr (Jul 25 2020 at 10:20, on Zulip):

can you push your commits to github?

lcnr (Jul 25 2020 at 10:20, on Zulip):

even if they are failing rn, I think I know the problem here but am not completely sure yet

Alex Griffiths (Jul 25 2020 at 10:21, on Zulip):

Sure thing. One moment. Takes my computer a while to handle this repo apparently.

Alex Griffiths (Jul 25 2020 at 10:28, on Zulip):

@lcnr https://github.com/alex-griffiths/rust/commit/bdbfb4b6de73567ff0b57da9959dfafb4d2c51de

lcnr (Jul 25 2020 at 10:29, on Zulip):

yeha, so you now export the fields of drain here

lcnr (Jul 25 2020 at 10:29, on Zulip):

by changing adding pub to the fields

lcnr (Jul 25 2020 at 10:30, on Zulip):

You probably can fix this by either using pub(super)

lcnr (Jul 25 2020 at 10:30, on Zulip):

or adding a pub(super) constructor to Drain and keep the fields private, which is probably the best solution imo

Alex Griffiths (Jul 25 2020 at 10:31, on Zulip):

And so I should do that in Utf8Error and CharIndices right?

lcnr (Jul 25 2020 at 10:31, on Zulip):

yeah, the same there

Alex Griffiths (Jul 25 2020 at 10:33, on Zulip):

I don't know if you've looked at the issue I'm working on at the moment, but would you be able to give me a quick yes or no to let me know if I'm heading in the right direction with what I'm doing right now?

lcnr (Jul 25 2020 at 10:33, on Zulip):

This is pretty much what you've done here:

mod outer {
    pub struct Foo {
        field: u8,
    }
}

mod new_outer {
    mod inner {
        pub struct Foo {
            pub field: u8,
        }
    }

    pub use inner::Foo;
}

fn main() {
    // outer::Foo { field: 7 };
    // ^ this fails
    new_outer::Foo { field: 7 };
}
lcnr (Jul 25 2020 at 10:35, on Zulip):

Yeah, I think moving the iterators and stuff into a separate module/file is a good idea.

Somewhat ambivalent about str/utf8 as it's a fairly small module, but I think that's also not a bad change.

lcnr (Jul 25 2020 at 10:36, on Zulip):

So what you are doing looks right to me :thumbs_up:

Last update: Sep 28 2020 at 15:45UTC