-
Notifications
You must be signed in to change notification settings - Fork 39
document Rust 1.90 changes #580
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
base: main
Are you sure you want to change the base?
Conversation
1826: FLS: Rust 1.89 and 1.90 updates r=Hoverbear a=tshepang This includes these upstream changes: - rust-lang/fls#579 - rust-lang/fls#580 Also included are some text fixes not strictly related to Rust compiler changes. Co-authored-by: Tshepang Mbambo <[email protected]>
1826: FLS: Rust 1.89 and 1.90 updates r=Hoverbear a=tshepang This includes these upstream changes: - rust-lang/fls#579 - rust-lang/fls#580 Also included are some text fixes not strictly related to Rust compiler changes. Co-authored-by: Tshepang Mbambo <[email protected]>
1826: FLS: Rust 1.89 and 1.90 updates r=Hoverbear a=tshepang This includes these upstream changes: - rust-lang/fls#579 - rust-lang/fls#580 Also included are some text fixes not strictly related to Rust compiler changes. Co-authored-by: Tshepang Mbambo <[email protected]>
a2ae9bd to
a9fdd2d
Compare
| * :dp:`fls_zyuxqty09SDO` | ||
| All forms of :t:`[borrow]s` except those of expressions that would be subject to | ||
| :t:`drop scope extension`, | ||
| and which are either :t:`[mutable borrow]s` | ||
| or borrows of expressions that result in values with :t:`interior mutability`. |
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.
Two things. One, it's OK for the expression to be subject to drop scope extension. It's not OK for that extension to extend the scope outside of the initializer to the end of the program.
const _: () = { let x = { &mut 0u8 }; x; }; //~ OK
// ^^^
// The drop scope of this temporary is extended.Two, the comma in "..., and which are either..." causes me to read it as a clause independent from "except...". I.e., this says (applying commutativity) "all forms of borrows 1) that are either mutable or result in values with interior mutability and 2) where the expression would not be subject to drop scope extension".
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.
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.
@traviscross -- did this address the issue raised?
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 is correct, except that, if I'm reading the diff correctly, it's putting this language in the list of what constitutes a constant context rather than about what constitutes a constant expression. We're defining constant expressions here, and the existing rules about "borrows" and "immutable borrow expressions" will need to be changed (and then that reflected in the changelog, etc.).
| :dp:`fls_ooOYxhVh8hZo` | ||
| The type of a :t:`constant` cannot be a :t:`mutable reference type`. | ||
|
|
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.
Two things. One, even with the other rule, this needs to talk about containing a mutable reference rather than being one.
Two, it's not enough to talk about types here. We actually do this reasoning by value, not by type.
trait Tr {}
impl<T: ?Sized> Tr for T {}
static mut X: u8 = 0;
const _: &dyn Tr = unsafe { &&mut X }; //~ ERROR
// ^^^^^^^
// This type does not contain any mutable references.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.
am not sure how to word this simply, given the complexities
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.
I will give this a shot.
The paragraph
The type of a :t:
constantcannot be a :t:mutable reference type.
should be removed.
Insert the following after
7.1:8 The value of a constant is determined by evaluating its constant initializer.
The value of a constant cannot contain any mutable references, except when:
- The type of the constant is an immutable reference and the initializer contains a reference to a mutable static, or
- The type of the constant is subject to interior mutability and the initializer contains a reference to a value subject to interior mutability, or
- The type of the constant is a zero-sized type and the initializer contains a reference to a value of a zero-sized type, or
- The initializer contains a reference to an external static.
I am not sure whether the type of the constant plays a role in the external static case.
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.
The value of a constant cannot contain any mutable references, except when... The initializer contains a reference to an external static.
unsafe extern "C" {
safe static S1: u8;
}
static mut S2: u8 = 0;
const C: (&u8, &mut u8) = (&S1, unsafe { &mut S2 }); //~ ERROR
// ^^^
// The initializer contains a reference to an external static.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.
Similarly:
The value of a constant cannot contain any mutable references, except when... The type of the constant is an immutable reference and the initializer contains a reference to a mutable static...
static mut S1: u8 = 0;
static mut S2: u8 = 0;
const C: &(&u8, &mut u8) = unsafe { &(&S1, &mut S2) }; //~ ERROR
// ^ ^^^
// The type of the constant is an immutable reference and the
// initializer contains a reference to a mutable static.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.
How about
The final value of a constant, after the constant initializer is evaluated to a value of the declared type, cannot contain any mutable references except when
- The mutable reference is coercible to an immutable reference, or
- The mutable reference is contained within an external static, or
- The mutable reference is contained within an union, or
- The referent is subject to interior mutability, or
- The referent is of a zero-sized type.
My experiments.
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.
Right direction, and thanks for doing and posting the experiments. Good process. (Doing such experiments is how @ehuss and I write and review Reference text as well.)
The mutable reference is coercible to an immutable reference, or
This may be a nit, but I'd say that all mutable references are coercible to immutable References; the important thing here is whether that coercion actually happens when evaluating to the final value.
The referent is subject to interior mutability, or
This only allows an immutable reference (to the interior mutable value), not a mutable one (which is what I think the text would imply).
- The mutable reference is contained within an external static, or
There should be a similar rule for being contained in a mutable static.
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 only allows an immutable reference (to the interior mutable value), not a mutable one (which is what I think the text would imply).
Are you referring to this case?
static mut MA: AtomicU8 = AtomicU8::new(0);
const _: &AtomicU8 = unsafe { &mut MA };
If yes, then doesn't this case fall under the "the mutable reference is coerced to an immutable reference"?
This case
static mut MA: AtomicU8 = AtomicU8::new(0);
const _: &mut AtomicU8 = unsafe { &mut MA };
is illegal. I think these are the only two cases involving mutable references to values subject to interior mutability.
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.
The second case is the one I mean. Agreed it's illegal. What rule are we suggesting makes it illegal?
My reading is that this language, by itself, would allow it:
The final value of a constant, after the constant initializer is evaluated to a value of the declared type, cannot contain any mutable references except when... The referent is subject to interior mutability...
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.
Perhaps
The final value of a constant, after the constant initializer is evaluated to a value of the declared type, cannot contain any mutable references except when...
- The type of the constant is an immutable reference and the referent is subject to interior mutability, or ...
Assuming the above is correct, the full set of rules becomes
The final value of a constant, after the constant initializer is evaluated to a value of the declared type, cannot contain any mutable references except when
- The mutable reference is successfully coerced to an immutable reference, or
- The mutable reference is contained within an external static, or
- The mutable reference is contained within an union, or
- The type of the constant is an immutable reference and the referent is subject to interior mutability, or
- The referent is of a zero-sized type.
🙏
No description provided.