-
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?
Changes from all commits
6cecf63
f669cc9
b874b5d
a9fdd2d
af19a30
47ce8fd
00c1bfd
d261499
6465ff2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,9 @@ The :t:`type specification` of a :t:`constant` shall have ``'static`` | |
| The :t:`type` of a :t:`constant` shall implement the :std:`core::marker::Sized` | ||
| :t:`trait`. | ||
|
|
||
| :dp:`fls_ooOYxhVh8hZo` | ||
| The type of a :t:`constant` cannot be a :t:`mutable reference type`. | ||
|
|
||
|
Comment on lines
+98
to
+100
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. am not sure how to word this simply, given the complexities
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will give this a shot. The paragraph
should be removed. Insert the following after The value of a constant cannot contain any mutable references, except when:
I am not sure whether the type of the constant plays a role in the external static case.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly:
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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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...
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
🙏
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This does actually happen to be true, in one particular case: #![allow(static_mut_refs)]
use core::cell::UnsafeCell;
struct W<T>(UnsafeCell<T>);
unsafe impl<T> Sync for W<T> {}
static S: W<&mut u8> = {
static mut I: u8 = 0; W(UnsafeCell::new(unsafe { &mut I }))
};
const _: &W<&mut u8> = &S;Good catch there. I don't think the Reference actually covers this. I've asked @RalfJung and @oli-obk about this. Of course, one does have to consider this in the context of the rules for valid constant expressions, which include:
That is, one can't simply write However, the statement is not general enough, as we also accept similar cases where the type of the constant itself is not an immutable reference. #![allow(static_mut_refs)]
use core::cell::UnsafeCell;
struct W<T>(UnsafeCell<T>);
unsafe impl<T> Sync for W<T> {}
static S: W<&mut u8> = {
static mut I: u8 = 0; W(UnsafeCell::new(unsafe { &mut I }))
};
struct Outer<T>(T);
const _: Outer<&W<&mut u8>> = Outer(&S);
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More generally, in this and other cases, I might suggest that we try to use verbiage that is as close as possible to the relevant rules in the Reference (i.e., trying to adjust only as minimally as possible for style). (And if we think the phrasing in the Reference can be improved, making that PR first.) Doing this would seem best to help align the documents and to minimize the correctness-checking effort on the FLS side. Thoughts?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| :dp:`fls_ndmfqxjpvsqy` | ||
| A :t:`constant initializer` is a :t:`construct` that provides the :t:`value` of | ||
| its related :t:`constant`. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| .. SPDX-License-Identifier: MIT OR Apache-2.0 | ||
| SPDX-FileCopyrightText: The Ferrocene Developers | ||
| SPDX-FileCopyrightText: The Rust Project Developers | ||
| .. |spec_version| replace:: 1.88.0 | ||
| .. |spec_version| replace:: 1.90.0 |
Uh oh!
There was an error while loading. Please reload this page.