-
Notifications
You must be signed in to change notification settings - Fork 13.4k
implement RFC 1238: nonparametric dropck. #28861
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
Merged
bors
merged 16 commits into
rust-lang:master
from
pnkfelix:fsk-nonparam-dropck-issue28498
Oct 10, 2015
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9868df2
Non-parametric dropck; instead trust an unsafe attribute (RFC 1238).
pnkfelix d778e57
Add RFC 1238's `unsafe_destructor_blind_to_params` (UGEH) where needed.
pnkfelix eea299b
run-pass tests for RFC 1238.
pnkfelix 83077be
compile-fail tests.
pnkfelix 5708f44
shorten URLs to placate `make tidy`.
pnkfelix 7a4743f
review comment: use RFC example for compile-fail/issue28498-reject-ex…
pnkfelix 92da3f9
review comment: reduce the `is_adt_dtorck` method to just a check for…
pnkfelix e2e261f
Added tests illustrating when and when not to use the UGEH attribute …
pnkfelix 7eda5b5
Added tests illustrating when and when not to use the UGEH attribute …
pnkfelix 73f35cf
Added tests illustrating when and when not to use the UGEH attribute …
pnkfelix 9ed5faa
Document the new more conservative dropck rule and the escape hatch.
pnkfelix 61f8def
placate check-pretty via comment rearrangement.
pnkfelix b6a4f03
revise cfail test, removing ugeh attribute that was erroneously cut-a…
pnkfelix e1aba75
review comment: point out that the dropck analysis is now trivial.
pnkfelix 34076bc
Added the param-blindness attribute to `Rc` and `Arc`.
pnkfelix a445f23
review comment: further refinement of comment above `fn is_adt_dtorck`.
pnkfelix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Ensure that attempts to use the unsafe attribute are feature-gated. | ||
|
||
// Example adapted from RFC 1238 text (just left out the feature gate). | ||
|
||
// https://github.com/rust-lang/rfcs/blob/master/text/1238-nonparametric-dropck.md | ||
// #example-of-the-unguarded-escape-hatch | ||
|
||
// #![feature(dropck_parametricity)] | ||
|
||
use std::cell::Cell; | ||
|
||
struct Concrete<'a>(u32, Cell<Option<&'a Concrete<'a>>>); | ||
|
||
struct Foo<T> { data: Vec<T> } | ||
|
||
impl<T> Drop for Foo<T> { | ||
#[unsafe_destructor_blind_to_params] // This is the UGEH attribute | ||
//~^ ERROR unsafe_destructor_blind_to_params has unstable semantics | ||
fn drop(&mut self) { } | ||
} | ||
|
||
fn main() { | ||
let mut foo = Foo { data: Vec::new() }; | ||
foo.data.push(Concrete(0, Cell::new(None))); | ||
foo.data.push(Concrete(0, Cell::new(None))); | ||
|
||
foo.data[0].1.set(Some(&foo.data[1])); | ||
foo.data[1].1.set(Some(&foo.data[0])); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole method should be
!self.has_attr(dtor_method, "unsafe_destructor_blind_to_params")
- unless you have some other plan.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yes, this code as it stands could be reduced to that.
My intention had originally been to continue returning
true
fromis_adt_dtorck
if the adt has region params.Looking now, I see that the RFC directly says in its description of UGEH that the attribute "will allow a destructor to side-step the dropck's constraints." For some reason while writing the RFC I had thought that was only talking about the type parameters (that's why there's the explicit alternative of having UGEH for lifetime parameters).
But at this point, I don't see much reason to stick with my original interpretation. This one (where UGEH causes all constraints to be ignored) is easier to explain and implement.