-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Remove a few Rc
s from RegionInferenceCtxt
#69967
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
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//! An immutable, owned value. | ||
//! | ||
//! The purpose of `Frozen` is to make a value immutable for the sake of defensive programming. For example, | ||
//! suppose we have the following: | ||
//! | ||
//! ```rust | ||
//! struct Bar { /* some data */ } | ||
//! | ||
//! struct Foo { | ||
//! /// Some computed data that should never change after construction. | ||
//! pub computed: Bar, | ||
//! | ||
//! /* some other fields */ | ||
//! } | ||
//! | ||
//! impl Bar { | ||
//! /// Mutate the `Bar`. | ||
//! pub fn mutate(&mut self) { } | ||
//! } | ||
//! ``` | ||
//! | ||
//! Now suppose we want to pass around a mutable `Foo` instance but, we want to make sure that | ||
//! `computed` does not change accidentally (e.g. somebody might accidentally call | ||
//! `foo.computed.mutate()`). This is what `Frozen` is for. We can do the following: | ||
//! | ||
//! ```rust | ||
//! use rustc_data_structures::frozen::Frozen; | ||
//! | ||
//! struct Foo { | ||
//! /// Some computed data that should never change after construction. | ||
//! pub computed: Frozen<Bar>, | ||
//! | ||
//! /* some other fields */ | ||
//! } | ||
//! ``` | ||
//! | ||
//! `Frozen` impls `Deref`, so we can ergonomically call methods on `Bar`, but it doesn't `impl | ||
//! DerefMut`. Now calling `foo.compute.mutate()` will result in a compile-time error stating that | ||
//! `mutate` requires a mutable reference but we don't have one. | ||
|
||
/// An owned immutable value. | ||
#[derive(Debug)] | ||
pub struct Frozen<T>(T); | ||
|
||
impl<T> Frozen<T> { | ||
pub fn freeze(val: T) -> Self { | ||
Frozen(val) | ||
} | ||
} | ||
|
||
impl<T> std::ops::Deref for Frozen<T> { | ||
type Target = T; | ||
|
||
fn deref(&self) -> &T { | ||
&self.0 | ||
} | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.