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

Prevent Error::type_id overrides #60902

Merged
merged 2 commits into from
May 17, 2019
Merged

Conversation

sfackler
Copy link
Member

type_id now takes an argument that can't be named outside of the
std::error module, which prevents any implementations from overriding
it. It's a pretty grody solution, and there's no way we can stabilize
the method with this API, but it avoids the soudness issue!

Closes #60784

r? @alexcrichton

type_id now takes an argument that can't be named outside of the
std::error module, which prevents any implementations from overriding
it. It's a pretty grody solution, and there's no way we can stabilize
the method with this API, but it avoids the soudness issue!

Closes rust-lang#60784
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 17, 2019
Copy link
Contributor

@Centril Centril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small nit. Looks good to me otherwise.

src/libstd/error.rs Outdated Show resolved Hide resolved
@Centril
Copy link
Contributor

Centril commented May 17, 2019

@bors rollup

Co-Authored-By: Mazdak Farrokhzad <[email protected]>
@RalfJung
Copy link
Member

I guess this is pub in a private module to silence some private-in-public lint? Ouch. :/

Also, right now, doesn't this also prevent calling the method from the outside? Or is that okay because people shouldn't call it anyways?

@pnkfelix
Copy link
Member

pnkfelix commented May 17, 2019

don't we also need the bit from @seanmonstar 's original suggestion with the following?

impl dyn Error + 'static {
    fn type_id(&self) -> TypeId {
        self.__type_id(Internal)
    }
}

@alexcrichton
Copy link
Member

@bors: r+

This sounds like a good stopgap approach for mitigating the impact on nightly. In the meantime discussion can continue on the issue for how to stabilize long-term.

@bors
Copy link
Contributor

bors commented May 17, 2019

📌 Commit 686a611 has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 17, 2019
Manishearth added a commit to Manishearth/rust that referenced this pull request May 17, 2019
…crichton

Prevent Error::type_id overrides

type_id now takes an argument that can't be named outside of the
std::error module, which prevents any implementations from overriding
it. It's a pretty grody solution, and there's no way we can stabilize
the method with this API, but it avoids the soudness issue!

Closes rust-lang#60784

r? @alexcrichton
// implementations, since that can enable unsound downcasting.
#[unstable(feature = "error_type_id", issue = "60784")]
#[derive(Debug)]
pub struct Internal;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would pub(crate) be a better option?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that violates the private types in public interfaces check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hypothetically, what would happen if somebody fixed this technical loophole? Would the fix then be blocked on the grounds of this workaround-hack?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed which loophole? Allowing such a pseudo public type in an exported interface? Fixing that would likely require a new edition, as many libraries already take advantage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors added a commit that referenced this pull request May 17, 2019
Rollup of 4 pull requests

Successful merges:

 - #60791 (Update books)
 - #60891 (Allow claiming issues with triagebot)
 - #60901 (Handle more string addition cases with appropriate suggestions)
 - #60902 (Prevent Error::type_id overrides)

Failed merges:

r? @ghost
@bors bors merged commit 686a611 into rust-lang:master May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking issue for stabilizing Error::type_id
9 participants