Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2c752bc
Undeprecate env::home_dir
arlosi Feb 20, 2025
812b1de
ref_pat_eat_one_layer_2024: add context and examples to the unstable …
dianne Feb 21, 2025
9323ba5
Remove MaybeForgetReturn suggestion
compiler-errors Feb 20, 2025
a7bd4a3
Add DWARF test case for non-C-like `repr128` enums
beetrees Feb 25, 2025
fb3aa33
Revert "Derive `Clone` on fewer THIR types."
skius Feb 27, 2025
b5f0c82
Add note to Thir struct about necessity of Clone derive
skius Feb 27, 2025
b2bb7cc
Fix char count in Display for ByteStr
thaliaarchi Feb 28, 2025
41dd80a
add test to reproduce #137662 (using ty decl macro fragment in an att…
jdonszelmann Feb 26, 2025
50a37ca
miri native-call support: all previously exposed provenance is access…
RalfJung Feb 28, 2025
88f988c
use fixed-width integer types in C code
RalfJung Feb 28, 2025
476b098
adjust Layout debug printing to match the internal field names
RalfJung Feb 28, 2025
91034ad
Do not require that unsafe fields lack drop glue
jswrenn Feb 28, 2025
adff091
Check dyn flavor before registering upcast goal on wide pointer cast …
compiler-errors Feb 25, 2025
e213f4b
Improve error message for AsyncFn trait failure for RPIT
compiler-errors Mar 3, 2025
0aacfe9
interpret/provenance_map: consistently use range_is_empty
RalfJung Mar 3, 2025
133705c
[rustdoc] hide item that is not marked as doc(inline) and whose src i…
xizheyin Feb 27, 2025
a23566a
Provide more context on resolve error caused from incorrect RTN
estebank Feb 28, 2025
ab31129
Point of macro expansion from call expr if it involves macro var
compiler-errors Feb 24, 2025
e4dfca8
Point out macro expansion ident in resolver errors too
compiler-errors Feb 24, 2025
0607246
Fix associated type errors too
compiler-errors Feb 24, 2025
09e5846
Also note struct access, and fix macro expansion from foreign crates
compiler-errors Feb 24, 2025
69c4651
ci: use ubuntu 24 on arm large runner
marcoieni Mar 4, 2025
da3e736
Clarify why InhabitedPredicate::instantiate_opt exists
meithecatte Feb 28, 2025
a3d63fb
InhabitedPredicate: avoid using a wildcard branch
meithecatte Mar 3, 2025
3d62b27
Ensure that negative auto impls are always applicable
compiler-errors Feb 28, 2025
05a8060
Make rustdoc tests use always applicable negative auto impls
compiler-errors Feb 28, 2025
7923031
Update `compiler-builtins` to 0.1.151
tgross35 Mar 5, 2025
1cacddc
bootstrap and compiletest: Use size_of_val from the prelude instead o…
thaliaarchi Mar 5, 2025
056ec72
trim channel value in `get_closest_merge_commit`
onur-ozkan Mar 5, 2025
3dbf3dc
Increase the max. custom try jobs requested to `20`
Kobzol Mar 5, 2025
afc1428
Rollup merge of #137303 - compiler-errors:maybe-forgor, r=cjgillot
jieyouxu Mar 5, 2025
957f48a
Rollup merge of #137327 - arlosi:home-dir, r=Mark-Simulacrum
jieyouxu Mar 5, 2025
f97b56d
Rollup merge of #137358 - dianne:new-match-ergonomics-examples, r=Nad…
jieyouxu Mar 5, 2025
0e38ad8
Rollup merge of #137534 - xizheyin:issue-137342, r=GuillaumeGomez
jieyouxu Mar 5, 2025
3de6310
Rollup merge of #137565 - compiler-errors:macro-ex, r=estebank
jieyouxu Mar 5, 2025
e1748bb
Rollup merge of #137637 - compiler-errors:dyn-cast-from-dyn-star, r=o…
jieyouxu Mar 5, 2025
ede3cc0
Rollup merge of #137643 - beetrees:repr128-dwarf-variant-test, r=jiey…
jieyouxu Mar 5, 2025
acd2c35
Rollup merge of #137744 - skius:master, r=Nadrieril
jieyouxu Mar 5, 2025
ff89925
Rollup merge of #137758 - jdonszelmann:fix-137662, r=nnethercote
jieyouxu Mar 5, 2025
3f76128
Rollup merge of #137764 - compiler-errors:always-applicable-negative-…
jieyouxu Mar 5, 2025
9590cec
Rollup merge of #137772 - thaliaarchi:bstr-display, r=joshtriplett
jieyouxu Mar 5, 2025
9d9489d
Rollup merge of #137798 - marcoieni:ubuntu-24-large-runner-arm, r=Kobzol
jieyouxu Mar 5, 2025
b8855d8
Rollup merge of #137802 - RalfJung:miri-native-call-exposed, r=oli-obk
jieyouxu Mar 5, 2025
007cdfe
Rollup merge of #137805 - RalfJung:layout-debug-print, r=Noratrieb
jieyouxu Mar 5, 2025
0dbea0e
Rollup merge of #137808 - jswrenn:droppy-unsafe-fields, r=nnethercote
jieyouxu Mar 5, 2025
b738027
Rollup merge of #137820 - meithecatte:instantiate-opt, r=BoxyUwU
jieyouxu Mar 5, 2025
68281b7
Rollup merge of #137825 - estebank:rtn-sugg-2, r=compiler-errors
jieyouxu Mar 5, 2025
3b3e934
Rollup merge of #137910 - compiler-errors:async-fn-goal-error, r=oli-obk
jieyouxu Mar 5, 2025
9c2a21c
Rollup merge of #137920 - RalfJung:provenance-map-emptiness, r=oli-obk
jieyouxu Mar 5, 2025
78d2633
Rollup merge of #138038 - tgross35:update-builtins, r=tgross35
jieyouxu Mar 5, 2025
0b02900
Rollup merge of #138041 - thaliaarchi:use-prelude-size-of.boostrap-co…
jieyouxu Mar 5, 2025
3e983fd
Rollup merge of #138046 - onur-ozkan:trim-include-str, r=jieyouxu
jieyouxu Mar 5, 2025
e37d5bb
Rollup merge of #138053 - Kobzol:more-try-jobs, r=marcoieni
jieyouxu Mar 5, 2025
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
Prev Previous commit
Next Next commit
Do not require that unsafe fields lack drop glue
Instead, we adopt the position that introducing an `unsafe` field
itself carries a safety invariant: that if you assign an invariant
to that field weaker than what the field's destructor requires,
you must ensure that field is in a droppable state in your
destructor.

See:
- rust-lang/rfcs#3458 (comment)
- https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/unsafe.20fields.20RFC/near/502113897
  • Loading branch information
jswrenn committed Feb 28, 2025
commit 91034adf30b3055e489d59f4483ed5def9cc9f19
7 changes: 0 additions & 7 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,6 @@ hir_analysis_invalid_union_field =
hir_analysis_invalid_union_field_sugg =
wrap the field type in `ManuallyDrop<...>`

hir_analysis_invalid_unsafe_field =
field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be unsafe
.note = unsafe fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`

hir_analysis_invalid_unsafe_field_sugg =
wrap the field type in `ManuallyDrop<...>`

hir_analysis_late_bound_const_in_apit = `impl Trait` can only mention const parameters from an fn or impl
.label = const parameter declared here

Expand Down
32 changes: 0 additions & 32 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId) {

check_transparent(tcx, def);
check_packed(tcx, span, def);
check_unsafe_fields(tcx, def_id);
}

fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId) {
Expand Down Expand Up @@ -144,36 +143,6 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
true
}

/// Check that the unsafe fields do not need dropping.
fn check_unsafe_fields(tcx: TyCtxt<'_>, item_def_id: LocalDefId) {
let span = tcx.def_span(item_def_id);
let def = tcx.adt_def(item_def_id);

let typing_env = ty::TypingEnv::non_body_analysis(tcx, item_def_id);
let args = ty::GenericArgs::identity_for_item(tcx, item_def_id);

for field in def.all_fields() {
if !field.safety.is_unsafe() {
continue;
}

if !allowed_union_or_unsafe_field(tcx, field.ty(tcx, args), typing_env, span) {
let hir::Node::Field(field) = tcx.hir_node_by_def_id(field.did.expect_local()) else {
unreachable!("field has to correspond to hir field")
};
let ty_span = field.ty.span;
tcx.dcx().emit_err(errors::InvalidUnsafeField {
field_span: field.span,
sugg: errors::InvalidUnsafeFieldSuggestion {
lo: ty_span.shrink_to_lo(),
hi: ty_span.shrink_to_hi(),
},
note: (),
});
}
}
}

/// Check that a `static` is inhabited.
fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
// Make sure statics are inhabited.
Expand Down Expand Up @@ -1517,7 +1486,6 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {

detect_discriminant_duplicate(tcx, def);
check_transparent(tcx, def);
check_unsafe_fields(tcx, def_id);
}

/// Part of enum check. Given the discriminants of an enum, errors if two or more discriminants are equal
Expand Down
23 changes: 0 additions & 23 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,17 +710,6 @@ pub(crate) struct InvalidUnionField {
pub note: (),
}

#[derive(Diagnostic)]
#[diag(hir_analysis_invalid_unsafe_field, code = E0740)]
pub(crate) struct InvalidUnsafeField {
#[primary_span]
pub field_span: Span,
#[subdiagnostic]
pub sugg: InvalidUnsafeFieldSuggestion,
#[note]
pub note: (),
}

#[derive(Diagnostic)]
#[diag(hir_analysis_return_type_notation_on_non_rpitit)]
pub(crate) struct ReturnTypeNotationOnNonRpitit<'tcx> {
Expand All @@ -742,18 +731,6 @@ pub(crate) struct InvalidUnionFieldSuggestion {
pub hi: Span,
}

#[derive(Subdiagnostic)]
#[multipart_suggestion(
hir_analysis_invalid_unsafe_field_sugg,
applicability = "machine-applicable"
)]
pub(crate) struct InvalidUnsafeFieldSuggestion {
#[suggestion_part(code = "std::mem::ManuallyDrop<")]
pub lo: Span,
#[suggestion_part(code = ">")]
pub hi: Span,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_return_type_notation_equality_bound)]
pub(crate) struct ReturnTypeNotationEqualityBound {
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ impl Copy for ! {}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Copy for &T {}

/// Marker trait for the types that are allowed in union fields, unsafe fields,
/// and unsafe binder types.
/// Marker trait for the types that are allowed in union fields and unsafe
/// binder types.
///
/// Implemented for:
/// * `&T`, `&mut T` for all `T`,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/unsafe-fields/unsafe-fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn f(a: A) {
}

struct WithInvalidUnsafeField {
unsafe unsafe_noncopy_field: Vec<u32>, //~ ERROR
unsafe unsafe_noncopy_field: Vec<u32>,
}

struct WithManuallyDropUnsafeField {
Expand Down
17 changes: 2 additions & 15 deletions tests/ui/unsafe-fields/unsafe-fields.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be unsafe
--> $DIR/unsafe-fields.rs:20:5
|
LL | unsafe unsafe_noncopy_field: Vec<u32>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: unsafe fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
help: wrap the field type in `ManuallyDrop<...>`
|
LL | unsafe unsafe_noncopy_field: std::mem::ManuallyDrop<Vec<u32>>,
| +++++++++++++++++++++++ +

error[E0133]: use of unsafe field is unsafe and requires unsafe block
--> $DIR/unsafe-fields.rs:15:30
|
Expand Down Expand Up @@ -69,7 +57,6 @@ LL | &raw const self.unsafe_field
|
= note: unsafe fields may carry library invariants

error: aborting due to 8 previous errors
error: aborting due to 7 previous errors

Some errors have detailed explanations: E0133, E0740.
For more information about an error, try `rustc --explain E0133`.
For more information about this error, try `rustc --explain E0133`.
Loading