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

Rollup of 11 pull requests #130907

Merged
merged 27 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e2c9831
Document subtleties of `ManuallyDrop`
theemathas Sep 12, 2024
6fa092a
Address WaffleLapkin's comments
theemathas Sep 13, 2024
f604ed6
Fix awkward wording.
theemathas Sep 13, 2024
4788e8c
Add the library workspace to the suggested rust-analyzer config
bjorn3 Sep 18, 2024
de2eba1
Reword ManuallyDrop+Box interaction
theemathas Sep 21, 2024
986e20d
Fixed diagnostics for coroutines with () as input.
91khr Sep 25, 2024
8f1ed9b
Utf8Chunks: add link to Utf8Chunk
RalfJung Sep 25, 2024
afb7eef
Pass Module Analysis Manager to Standard Instrumentations
Sep 25, 2024
a51b0a2
Use `mem::offset_of!` for `sockaddr_un.sun_path`
cuviper Sep 25, 2024
5892187
Fix the misleading diagnostic for let_underscore_drop on type without…
makai410 Sep 26, 2024
1bef68c
Update FIXME comment in s390x_unknown_linux_*.rs
taiki-e Sep 26, 2024
cdd3371
rustdoc: do not animate when user prefers reduced motion
zopsicle Sep 25, 2024
ef87a7f
add missing FIXME(const-hack)
RalfJung Sep 26, 2024
9431d1a
Add `sun_path` to the fake doc `sockaddr_un`
cuviper Sep 26, 2024
e29ff8c
Pass correct HirId to late_bound_vars in diagnostic code
fmease Sep 26, 2024
5b58481
rustdoc: consolidate prefers-reduced-motion-gated rulesets
Sep 26, 2024
8a827c7
Rollup merge of #130279 - theemathas:manually-drop-docs, r=thomcc,tra…
GuillaumeGomez Sep 26, 2024
a4a591a
Rollup merge of #130517 - bjorn3:update_ra_config, r=onur-ozkan
GuillaumeGomez Sep 26, 2024
0acddf5
Rollup merge of #130820 - 91khr:fix-coroutine-unit-arg, r=compiler-er…
GuillaumeGomez Sep 26, 2024
d3cb1ce
Rollup merge of #130833 - makai410:master, r=compiler-errors,fee1-dead
GuillaumeGomez Sep 26, 2024
e650546
Rollup merge of #130845 - RalfJung:utf8chunk, r=tgross35
GuillaumeGomez Sep 26, 2024
c9478ef
Rollup merge of #130850 - saveasguy:pass-mam-to-standrd-instrumentati…
GuillaumeGomez Sep 26, 2024
329f9fc
Rollup merge of #130861 - cuviper:sun-path-offset, r=ibraheemdev
GuillaumeGomez Sep 26, 2024
432b1ff
Rollup merge of #130862 - zopsicle:patch-1, r=notriddle,GuillaumeGomez
GuillaumeGomez Sep 26, 2024
18dfee0
Rollup merge of #130868 - taiki-e:s390x-fixme, r=jieyouxu
GuillaumeGomez Sep 26, 2024
ed902a8
Rollup merge of #130879 - fmease:fix-diag-ice, r=compiler-errors
GuillaumeGomez Sep 26, 2024
3d4d45f
Rollup merge of #130880 - RalfJung:const-hack, r=scottmcm
GuillaumeGomez Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = self.lowerer().lower_ty(hir_ty);
debug!(?ty, "return type (lowered)");
debug!(?expected, "expected type");
let bound_vars = self.tcx.late_bound_vars(hir_ty.hir_id.owner.into());
let bound_vars =
self.tcx.late_bound_vars(self.tcx.local_def_id_to_hir_id(fn_id));
let ty = Binder::bind_with_vars(ty, bound_vars);
let ty = self.normalize(hir_ty.span, ty);
let ty = self.tcx.instantiate_bound_regions_with_erased(ty);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ lint_non_binding_let_multi_suggestion =
consider immediately dropping the value

lint_non_binding_let_on_drop_type =
non-binding let on a type that implements `Drop`
non-binding let on a type that has a destructor

lint_non_binding_let_on_sync_lock = non-binding let on a synchronization lock
.label = this lock is not assigned to a binding and is immediately dropped
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/let_underscore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ declare_lint! {
/// intent.
pub LET_UNDERSCORE_DROP,
Allow,
"non-binding let on a type that implements `Drop`"
"non-binding let on a type that has a destructor"
}

declare_lint! {
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,12 +732,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
PTO.SLPVectorization = SLPVectorize;
PTO.MergeFunctions = MergeFunctions;

// FIXME: We may want to expose this as an option.
bool DebugPassManager = false;

PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(TheModule->getContext(), DebugPassManager);
SI.registerCallbacks(PIC);

if (LlvmSelfProfiler) {
LLVMSelfProfileInitializeCallbacks(PIC, LlvmSelfProfiler,
Expand Down Expand Up @@ -784,6 +779,12 @@ extern "C" LLVMRustResult LLVMRustOptimize(
CGSCCAnalysisManager CGAM;
ModuleAnalysisManager MAM;

// FIXME: We may want to expose this as an option.
bool DebugPassManager = false;

StandardInstrumentations SI(TheModule->getContext(), DebugPassManager);
SI.registerCallbacks(PIC, &MAM);

if (LLVMPluginsLen) {
auto PluginsStr = StringRef(LLVMPlugins, LLVMPluginsLen);
SmallVector<StringRef> Plugins;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ pub(crate) fn target() -> Target {
base.endian = Endian::Big;
// z10 is the oldest CPU supported by LLVM
base.cpu = "z10".into();
// FIXME: The ABI implementation in cabi_s390x.rs is for now hard-coded to assume the no-vector
// ABI. Pass the -vector feature string to LLVM to respect this assumption. On LLVM < 16, we
// also strip v128 from the data_layout below to match the older LLVM's expectation.
// FIXME: The ABI implementation in abi/call/s390x.rs is for now hard-coded to assume the no-vector
// ABI. Pass the -vector feature string to LLVM to respect this assumption.
base.features = "-vector".into();
base.max_atomic_width = Some(128);
base.min_global_align = Some(16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ pub(crate) fn target() -> Target {
base.endian = Endian::Big;
// z10 is the oldest CPU supported by LLVM
base.cpu = "z10".into();
// FIXME: The ABI implementation in cabi_s390x.rs is for now hard-coded to assume the no-vector
// ABI. Pass the -vector feature string to LLVM to respect this assumption. On LLVM < 16, we
// also strip v128 from the data_layout below to match the older LLVM's expectation.
// FIXME: The ABI implementation in abi/call/s390x.rs is for now hard-coded to assume the no-vector
// ABI. Pass the -vector feature string to LLVM to respect this assumption.
base.features = "-vector".into();
base.max_atomic_width = Some(128);
base.min_global_align = Some(16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2635,49 +2635,47 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// This shouldn't be common unless manually implementing one of the
// traits manually, but don't make it more confusing when it does
// happen.
Ok(
if Some(expected_trait_ref.def_id) != self.tcx.lang_items().coroutine_trait()
&& not_tupled
{
self.report_and_explain_type_error(
TypeTrace::trait_refs(
&obligation.cause,
true,
expected_trait_ref,
found_trait_ref,
),
ty::error::TypeError::Mismatch,
)
} else if found.len() == expected.len() {
self.report_closure_arg_mismatch(
span,
found_span,
found_trait_ref,
expected_trait_ref,
obligation.cause.code(),
found_node,
obligation.param_env,
)
} else {
let (closure_span, closure_arg_span, found) = found_did
.and_then(|did| {
let node = self.tcx.hir().get_if_local(did)?;
let (found_span, closure_arg_span, found) =
self.get_fn_like_arguments(node)?;
Some((Some(found_span), closure_arg_span, found))
})
.unwrap_or((found_span, None, found));

self.report_arg_count_mismatch(
if Some(expected_trait_ref.def_id) != self.tcx.lang_items().coroutine_trait() && not_tupled
{
return Ok(self.report_and_explain_type_error(
TypeTrace::trait_refs(&obligation.cause, true, expected_trait_ref, found_trait_ref),
ty::error::TypeError::Mismatch,
));
}
if found.len() != expected.len() {
let (closure_span, closure_arg_span, found) = found_did
.and_then(|did| {
let node = self.tcx.hir().get_if_local(did)?;
let (found_span, closure_arg_span, found) = self.get_fn_like_arguments(node)?;
Some((Some(found_span), closure_arg_span, found))
})
.unwrap_or((found_span, None, found));

// If the coroutine take a single () as its argument,
// the trait argument would found the coroutine take 0 arguments,
// but get_fn_like_arguments would give 1 argument.
// This would result in "Expected to take 1 argument, but it takes 1 argument".
// Check again to avoid this.
if found.len() != expected.len() {
return Ok(self.report_arg_count_mismatch(
span,
closure_span,
expected,
found,
found_trait_ty.is_closure(),
closure_arg_span,
)
},
)
));
}
}
Ok(self.report_closure_arg_mismatch(
span,
found_span,
found_trait_ref,
expected_trait_ref,
obligation.cause.code(),
found_node,
obligation.param_env,
))
}

/// Given some node representing a fn-like thing in the HIR map,
Expand Down
130 changes: 118 additions & 12 deletions library/core/src/mem/manually_drop.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
use crate::ops::{Deref, DerefMut, DerefPure};
use crate::ptr;

/// A wrapper to inhibit the compiler from automatically calling `T`’s destructor.
/// This wrapper is 0-cost.
/// A wrapper to inhibit the compiler from automatically calling `T`’s
/// destructor. This wrapper is 0-cost.
///
/// `ManuallyDrop<T>` is guaranteed to have the same layout and bit validity as
/// `T`, and is subject to the same layout optimizations as `T`. As a consequence,
/// it has *no effect* on the assumptions that the compiler makes about its
/// contents. For example, initializing a `ManuallyDrop<&mut T>` with [`mem::zeroed`]
/// is undefined behavior. If you need to handle uninitialized data, use
/// [`MaybeUninit<T>`] instead.
/// `T`, and is subject to the same layout optimizations as `T`. As a
/// consequence, it has *no effect* on the assumptions that the compiler makes
/// about its contents. For example, initializing a `ManuallyDrop<&mut T>` with
/// [`mem::zeroed`] is undefined behavior. If you need to handle uninitialized
/// data, use [`MaybeUninit<T>`] instead.
///
/// Note that accessing the value inside a `ManuallyDrop<T>` is safe.
/// This means that a `ManuallyDrop<T>` whose content has been dropped must not
/// be exposed through a public safe API.
/// Correspondingly, `ManuallyDrop::drop` is unsafe.
/// Note that accessing the value inside a `ManuallyDrop<T>` is safe. This means
/// that a `ManuallyDrop<T>` whose content has been dropped must not be exposed
/// through a public safe API. Correspondingly, `ManuallyDrop::drop` is unsafe.
///
/// # `ManuallyDrop` and drop order.
/// # `ManuallyDrop` and drop order
///
/// Rust has a well-defined [drop order] of values. To make sure that fields or
/// locals are dropped in a specific order, reorder the declarations such that
Expand All @@ -40,9 +39,116 @@ use crate::ptr;
/// }
/// ```
///
/// # Interaction with `Box`
///
/// Currently, if you have a `ManuallyDrop<T>`, where the type `T` is a `Box` or
/// contains a `Box` inside, then dropping the `T` followed by moving the
/// `ManuallyDrop<T>` is [considered to be undefined
/// behavior](https://github.com/rust-lang/unsafe-code-guidelines/issues/245).
/// That is, the following code causes undefined behavior:
///
/// ```no_run
/// use std::mem::ManuallyDrop;
///
/// let mut x = ManuallyDrop::new(Box::new(42));
/// unsafe {
/// ManuallyDrop::drop(&mut x);
/// }
/// let y = x; // Undefined behavior!
/// ```
///
/// This is [likely to change in the
/// future](https://rust-lang.github.io/rfcs/3336-maybe-dangling.html). In the
/// meantime, consider using [`MaybeUninit`] instead.
///
/// # Safety hazards when storing `ManuallyDrop` in a struct or an enum.
///
/// Special care is needed when all of the conditions below are met:
/// * A struct or enum contains a `ManuallyDrop`.
/// * The `ManuallyDrop` is not inside a `union`.
/// * The struct or enum is part of public API, or is stored in a struct or an
/// enum that is part of public API.
/// * There is code that drops the contents of the `ManuallyDrop` field, and
/// this code is outside the struct or enum's `Drop` implementation.
///
/// In particular, the following hazards may occur:
///
/// #### Storing generic types
///
/// If the `ManuallyDrop` contains a client-supplied generic type, the client
/// might provide a `Box` as that type. This would cause undefined behavior when
/// the struct or enum is later moved, as mentioned in the previous section. For
/// example, the following code causes undefined behavior:
///
/// ```no_run
/// use std::mem::ManuallyDrop;
///
/// pub struct BadOption<T> {
/// // Invariant: Has been dropped iff `is_some` is false.
/// value: ManuallyDrop<T>,
/// is_some: bool,
/// }
/// impl<T> BadOption<T> {
/// pub fn new(value: T) -> Self {
/// Self { value: ManuallyDrop::new(value), is_some: true }
/// }
/// pub fn change_to_none(&mut self) {
/// if self.is_some {
/// self.is_some = false;
/// unsafe {
/// // SAFETY: `value` hasn't been dropped yet, as per the invariant
/// // (This is actually unsound!)
/// ManuallyDrop::drop(&mut self.value);
/// }
/// }
/// }
/// }
///
/// // In another crate:
///
/// let mut option = BadOption::new(Box::new(42));
/// option.change_to_none();
/// let option2 = option; // Undefined behavior!
/// ```
///
/// #### Deriving traits
///
/// Deriving `Debug`, `Clone`, `PartialEq`, `PartialOrd`, `Ord`, or `Hash` on
/// the struct or enum could be unsound, since the derived implementations of
/// these traits would access the `ManuallyDrop` field. For example, the
/// following code causes undefined behavior:
///
/// ```no_run
/// use std::mem::ManuallyDrop;
///
/// // This derive is unsound in combination with the `ManuallyDrop::drop` call.
/// #[derive(Debug)]
/// pub struct Foo {
/// value: ManuallyDrop<String>,
/// }
/// impl Foo {
/// pub fn new() -> Self {
/// let mut temp = Self {
/// value: ManuallyDrop::new(String::from("Unsafe rust is hard."))
/// };
/// unsafe {
/// // SAFETY: `value` hasn't been dropped yet.
/// ManuallyDrop::drop(&mut temp.value);
/// }
/// temp
/// }
/// }
///
/// // In another crate:
///
/// let foo = Foo::new();
/// println!("{:?}", foo); // Undefined behavior!
/// ```
///
/// [drop order]: https://doc.rust-lang.org/reference/destructors.html
/// [`mem::zeroed`]: crate::mem::zeroed
/// [`MaybeUninit<T>`]: crate::mem::MaybeUninit
/// [`MaybeUninit`]: crate::mem::MaybeUninit
#[stable(feature = "manually_drop", since = "1.20.0")]
#[lang = "manually_drop"]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Alignment {
!(unsafe { self.as_usize().unchecked_sub(1) })
}

// Remove me once `Ord::max` is usable in const
// FIXME(const-hack) Remove me once `Ord::max` is usable in const
pub(crate) const fn max(a: Self, b: Self) -> Self {
if a.as_usize() > b.as_usize() { a } else { b }
}
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/str/lossy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ impl [u8] {
/// Creates an iterator over the contiguous valid UTF-8 ranges of this
/// slice, and the non-UTF-8 fragments in between.
///
/// See the [`Utf8Chunk`] type for documenation of the items yielded by this iterator.
///
/// # Examples
///
/// This function formats arbitrary but mostly-UTF-8 bytes into Rust source
Expand Down Expand Up @@ -148,6 +150,8 @@ impl fmt::Debug for Debug<'_> {
/// If you want a simple conversion from UTF-8 byte slices to string slices,
/// [`from_utf8`] is easier to use.
///
/// See the [`Utf8Chunk`] type for documenation of the items yielded by this iterator.
///
/// [byteslice]: slice
/// [`from_utf8`]: super::from_utf8
///
Expand Down
Loading
Loading