Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
1cac5fa
Look for `python3` first on MacOS, not `py`
jyn514 Feb 13, 2025
477a2ee
std::fs: slightly reformat `remove_dir_all` error docs
jieyouxu Feb 18, 2025
ef337a6
Make `ptr_cast_add_auto_to_object` lint into hard error
traviscross Feb 9, 2025
b340545
[illumos] attempt to use posix_spawn to spawn processes
sunshowers Feb 11, 2025
78615ff
Stablize `string_extend_from_within`
aDotInTheVoid Feb 24, 2025
b60aeb0
Stop passing --lib to cargo test
bjorn3 Feb 26, 2025
b491494
Also test coretests when running ./x.py test core
bjorn3 Feb 19, 2025
169e731
Fix unused import in coretests on wasm32
bjorn3 Feb 26, 2025
44cccae
Delete tuple unsizing
Darksonn Feb 27, 2025
8cab0ba
Remove unneeded import
Darksonn Feb 27, 2025
0ca1c9c
Count char width at most once in Formatter::pad
thaliaarchi Feb 6, 2025
86aae8e
uefi: Add Service Binding Protocol abstraction
Ayush1325 Feb 23, 2025
3998690
compiletest: remove legacy `Makefile`-based `run-make` support
jieyouxu Feb 5, 2025
413b824
run-make: remove `tools.mk`
jieyouxu Feb 5, 2025
9b17c98
run-make: update test suite README
jieyouxu Feb 5, 2025
ed168e7
run-make-support: remove outdated comments
jieyouxu Mar 1, 2025
efec638
tidy: remove legacy `Makefile` checks
jieyouxu Feb 5, 2025
b0d6a84
rustc-dev-guide: remove mentions of legacy `Makefile` run-make infra
jieyouxu Feb 5, 2025
95b030f
triagebot: stop backlinking to the test porting tracking issue
jieyouxu Feb 5, 2025
a0ed304
float: Update some constants to `pub(crate)`
tgross35 Dec 9, 2024
5a2da96
dec2flt: Update documentation of existing methods
tgross35 Dec 9, 2024
49a2d4c
dec2flt: Rename `Decimal` to `DecimalSeq`
tgross35 Dec 9, 2024
626d2c5
dec2flt: Rename `Number` to `Decimal`
tgross35 Dec 9, 2024
6c34daf
dec2flt: Rename fields to be consistent with documented notation
tgross35 Dec 9, 2024
19a909a
dec2flt: Refactor float traits
tgross35 Dec 9, 2024
37e223c
dec2flt: Refactor the fast path
tgross35 Dec 9, 2024
7e0a2fc
compiletest: change `TEST_BUILD_DIR` to maximally normalize
jieyouxu Feb 11, 2025
8342914
tests: remove explicit long type filename hash normalization from som…
jieyouxu Feb 11, 2025
12cd0f1
tests: rebless some tests as a side-effect of `TEST_BUILD_DIR` changes
jieyouxu Feb 11, 2025
4f2a3dc
tests: manually rebless `tests/ui-fulldeps/codegen-backend/hotplug.rs`
jieyouxu Feb 11, 2025
c566318
Tweak error code for sized checks of const/static
compiler-errors Feb 18, 2025
9d3d5a7
Check signature WF when lowering MIR body
compiler-errors Feb 20, 2025
0baee24
Don't typeck during WF, instead check outside of WF in check_crate
compiler-errors Feb 21, 2025
68df70d
List the feature in removed.rs
Darksonn Mar 4, 2025
c392cf7
Added documentation for flushing
pcorwin Feb 10, 2025
d759958
Only use implied bounds hack if bevy, and use deeply normalize in imp…
compiler-errors Mar 4, 2025
1f32f7b
compiler: add `ExternAbi::is_rustic_abi`
workingjubilee Mar 5, 2025
08b5783
compiler: use `is_rustic_abi` in mir_transform
workingjubilee Mar 5, 2025
5abf36b
compiler: use `is_rustic_abi` in ImproperCTypesVisitor
workingjubilee Mar 5, 2025
e81fbe3
compiler: use `is_rustic_abi` in abi_check
workingjubilee Mar 5, 2025
cc1e4ed
resume one waiter at a call
Mar 5, 2025
8a68987
compiler: use `is_rustic_abi` in ty_utils
workingjubilee Mar 5, 2025
31e612b
move `rust.description` to `build.description`
onur-ozkan Feb 27, 2025
92956e8
add change-entry
onur-ozkan Feb 27, 2025
853e34d
pass `CFG_VER_DESCRIPTION` to tool builds
onur-ozkan Feb 27, 2025
9646c2f
replace `rust.description` with `build.description`
onur-ozkan Feb 27, 2025
26e42de
Make citool compilation faster
Kobzol Feb 13, 2025
6130b3d
Upload Datadog average CPU usage metric in citool
Kobzol Feb 13, 2025
6166f3d
Remove Python metric upload script and package.json
Kobzol Feb 13, 2025
6c2c5dc
Apply review remarks
Kobzol Mar 5, 2025
7a31456
Make `field_match_pairs` push its output nodes to a vector
Zalathar Mar 5, 2025
281455a
Make `MatchPairTree::for_pattern` push its output node to a vector
Zalathar Mar 5, 2025
ef44273
Populate pattern bindings/ascriptions while building `MatchPairTree`
Zalathar Mar 5, 2025
854feae
Remove `TestCase::Irrefutable`
Zalathar Mar 5, 2025
e05df1c
Remove the separate simplify step for match-pair trees
Zalathar Mar 5, 2025
e3e74bc
Make `MatchPairTree::place` non-optional
Zalathar Mar 5, 2025
9b8accb
Rollup merge of #134063 - tgross35:dec2flt-refactoring, r=Noratrieb
jieyouxu Mar 5, 2025
65da1ff
Rollup merge of #136581 - jieyouxu:makefile-be-gone, r=Kobzol
jieyouxu Mar 5, 2025
1b9b515
Rollup merge of #136662 - thaliaarchi:formatter-pad-char-count, r=m-o…
jieyouxu Mar 5, 2025
21b4733
Rollup merge of #136764 - traviscross:TC/make-ptr_cast_add_auto_to_ob…
jieyouxu Mar 5, 2025
6c4ce3a
Rollup merge of #136798 - pcorwin:master, r=tgross35
jieyouxu Mar 5, 2025
9aaf46e
Rollup merge of #136865 - jieyouxu:long-type-path-compare-mode, r=lqd
jieyouxu Mar 5, 2025
f22b939
Rollup merge of #136975 - jyn514:macos-x, r=Mark-Simulacrum
jieyouxu Mar 5, 2025
ab29c70
Rollup merge of #136977 - Kobzol:citool-datadog, r=marcoieni
jieyouxu Mar 5, 2025
4f1a047
Rollup merge of #137240 - jieyouxu:remove_dir_all, r=Mark-Simulacrum
jieyouxu Mar 5, 2025
5df9a9f
Rollup merge of #137298 - compiler-errors:mir-wf, r=lcnr
jieyouxu Mar 5, 2025
fde23c8
Rollup merge of #137463 - sunshowers:illumos-posix-spawn, r=Mark-Simu…
jieyouxu Mar 5, 2025
24d481c
Rollup merge of #137477 - Ayush1325:uefi-service-binding, r=Noratrieb
jieyouxu Mar 5, 2025
604d1ba
Rollup merge of #137569 - aDotInTheVoid:for-iurii, r=ibraheemdev
jieyouxu Mar 5, 2025
6c60abf
Rollup merge of #137633 - compiler-errors:no-implied-bounds-hack-unle…
jieyouxu Mar 5, 2025
4aa61e7
Rollup merge of #137679 - bjorn3:coretests_improvements, r=jieyouxu,o…
jieyouxu Mar 5, 2025
dac4ffd
Rollup merge of #137723 - onur-ozkan:cfg-ver-description, r=pietroalb…
jieyouxu Mar 5, 2025
257b494
Rollup merge of #137728 - Darksonn:no-tuple-unsize, r=oli-obk
jieyouxu Mar 5, 2025
927c11f
Rollup merge of #137731 - SparrowLii:waiter, r=nnethercote
jieyouxu Mar 5, 2025
9d1b2f7
Rollup merge of #137875 - Zalathar:irrefutable, r=Nadrieril
jieyouxu Mar 5, 2025
fe4c085
Rollup merge of #138028 - workingjubilee:is-rustic-abi, r=compiler-er…
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
41 changes: 41 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0804.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
An auto trait cannot be added to the bounds of a `dyn Trait` type via
a pointer cast.

Erroneous code example:

```rust,edition2021,compile_fail,E0804
let ptr: *const dyn core::any::Any = &();
_ = ptr as *const (dyn core::any::Any + Send);
```

Adding an auto trait can make the vtable invalid, potentially causing
UB in safe code afterwards. For example:

```rust,edition2021,no_run
use core::{mem::transmute, ptr::NonNull};

trait Trait {
fn f(&self)
where
Self: Send;
}

impl Trait for NonNull<()> {
fn f(&self) {
unreachable!()
}
}

fn main() {
let unsend: &dyn Trait = &NonNull::dangling();
let bad: &(dyn Trait + Send) = unsafe { transmute(unsend) };
// This crashes, since the vtable for `NonNull as dyn Trait` does
// not have an entry for `Trait::f`.
bad.f();
}
```

To fix this error, you can use `transmute` rather than pointer casts,
but you must ensure that the vtable is valid for the pointer's type
before calling a method on the trait object or allowing other code to
do so.
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ E0800: 0800,
E0801: 0801,
E0802: 0802,
E0803: 0803,
E0804: 0804,
);
)
}
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_hir_typeck/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,13 @@ hir_typeck_pass_to_variadic_function = can't pass `{$ty}` to variadic function
.suggestion = cast the value to `{$cast_ty}`
.teach_help = certain types, like `{$ty}`, must be casted before passing them to a variadic function, because of arcane ABI rules dictated by the C standard

hir_typeck_ptr_cast_add_auto_to_object = adding {$traits_len ->
[1] an auto trait {$traits}
hir_typeck_ptr_cast_add_auto_to_object = cannot add {$traits_len ->
[1] auto trait {$traits}
*[other] auto traits {$traits}
} to a trait object in a pointer cast may cause UB later on
} to dyn bound via pointer cast
.note = this could allow UB elsewhere
.help = use `transmute` if you're sure this is sound
.label = unsupported cast

hir_typeck_remove_semi_for_coerce = you might have meant to return the `match` expression
hir_typeck_remove_semi_for_coerce_expr = this could be implicitly returned but it is a statement, not a tail expression
Expand Down
28 changes: 12 additions & 16 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,23 +940,19 @@ impl<'a, 'tcx> CastCheck<'tcx> {
.collect::<Vec<_>>();

if !added.is_empty() {
tcx.emit_node_span_lint(
lint::builtin::PTR_CAST_ADD_AUTO_TO_OBJECT,
self.expr.hir_id,
self.span,
errors::PtrCastAddAutoToObject {
traits_len: added.len(),
traits: {
let mut traits: Vec<_> = added
.into_iter()
.map(|trait_did| tcx.def_path_str(trait_did))
.collect();

traits.sort();
traits.into()
},
tcx.dcx().emit_err(errors::PtrCastAddAutoToObject {
span: self.span,
traits_len: added.len(),
traits: {
let mut traits: Vec<_> = added
.into_iter()
.map(|trait_did| tcx.def_path_str(trait_did))
.collect();

traits.sort();
traits.into()
},
)
});
}

Ok(CastKind::PtrPtrCast)
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_hir_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,14 @@ pub(crate) struct LossyProvenanceInt2Ptr<'tcx> {
pub sugg: LossyProvenanceInt2PtrSuggestion,
}

#[derive(LintDiagnostic)]
#[diag(hir_typeck_ptr_cast_add_auto_to_object)]
#[derive(Diagnostic)]
#[diag(hir_typeck_ptr_cast_add_auto_to_object, code = E0804)]
#[note]
#[help]
pub(crate) struct PtrCastAddAutoToObject {
#[primary_span]
#[label]
pub span: Span,
pub traits_len: usize,
pub traits: DiagSymbolList<String>,
}
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,11 @@ fn register_builtins(store: &mut LintStore) {
"converted into hard error, \
see <https://github.com/rust-lang/rust/issues/73333> for more information",
);
store.register_removed(
"ptr_cast_add_auto_to_object",
"converted into hard error, see issue #127323 \
<https://github.com/rust-lang/rust/issues/127323> for more information",
);
}

fn register_internals(store: &mut LintStore) {
Expand Down
53 changes: 0 additions & 53 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ declare_lint_pass! {
PRIVATE_BOUNDS,
PRIVATE_INTERFACES,
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
PTR_CAST_ADD_AUTO_TO_OBJECT,
PTR_TO_INTEGER_TRANSMUTE_IN_CONSTS,
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
REDUNDANT_IMPORTS,
Expand Down Expand Up @@ -4827,58 +4826,6 @@ declare_lint! {
};
}

declare_lint! {
/// The `ptr_cast_add_auto_to_object` lint detects casts of raw pointers to trait
/// objects, which add auto traits.
///
/// ### Example
///
/// ```rust,edition2021,compile_fail
/// let ptr: *const dyn core::any::Any = &();
/// _ = ptr as *const dyn core::any::Any + Send;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Adding an auto trait can make the vtable invalid, potentially causing
/// UB in safe code afterwards. For example:
///
/// ```ignore (causes a warning)
/// #![feature(arbitrary_self_types)]
///
/// trait Trait {
/// fn f(self: *const Self)
/// where
/// Self: Send;
/// }
///
/// impl Trait for *const () {
/// fn f(self: *const Self) {
/// unreachable!()
/// }
/// }
///
/// fn main() {
/// let unsend: *const () = &();
/// let unsend: *const dyn Trait = &unsend;
/// let send_bad: *const (dyn Trait + Send) = unsend as _;
/// send_bad.f(); // this crashes, since vtable for `*const ()` does not have an entry for `f`
/// }
/// ```
///
/// Generally you must ensure that vtable is right for the pointer's type,
/// before passing the pointer to safe code.
pub PTR_CAST_ADD_AUTO_TO_OBJECT,
Warn,
"detects `as` casts from pointers to `dyn Trait` to pointers to `dyn Trait + Auto`",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
reference: "issue #127323 <https://github.com/rust-lang/rust/issues/127323>",
};
}

declare_lint! {
/// The `out_of_scope_macro_calls` lint detects `macro_rules` called when they are not in scope,
/// above their definition, which may happen in key-value attributes.
Expand Down
14 changes: 8 additions & 6 deletions tests/ui/cast/ptr-to-trait-obj-add-auto.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
//@ check-pass

trait Trait<'a> {}

fn add_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send) {
x as _
//~^ warning: adding an auto trait `Send` to a trait object in a pointer cast may cause UB later on
//~| warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~^ ERROR cannot add auto trait `Send` to dyn bound via pointer cast
//~| NOTE unsupported cast
//~| NOTE this could allow UB elsewhere
//~| HELP use `transmute` if you're sure this is sound
}

// (to test diagnostic list formatting)
fn add_multiple_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send + Sync + Unpin) {
x as _
//~^ warning: adding auto traits `Send`, `Sync`, and `Unpin` to a trait object in a pointer cast may cause UB later on
//~| warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~^ ERROR cannot add auto traits `Send`, `Sync`, and `Unpin` to dyn bound via pointer cast
//~| NOTE unsupported cast
//~| NOTE this could allow UB elsewhere
//~| HELP use `transmute` if you're sure this is sound
}

fn main() {}
44 changes: 11 additions & 33 deletions tests/ui/cast/ptr-to-trait-obj-add-auto.stderr
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
warning: adding an auto trait `Send` to a trait object in a pointer cast may cause UB later on
--> $DIR/ptr-to-trait-obj-add-auto.rs:6:5
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast
--> $DIR/ptr-to-trait-obj-add-auto.rs:4:5
|
LL | x as _
| ^^^^^^
| ^^^^^^ unsupported cast
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #127323 <https://github.com/rust-lang/rust/issues/127323>
= note: `#[warn(ptr_cast_add_auto_to_object)]` on by default
= note: this could allow UB elsewhere
= help: use `transmute` if you're sure this is sound

warning: adding auto traits `Send`, `Sync`, and `Unpin` to a trait object in a pointer cast may cause UB later on
error[E0804]: cannot add auto traits `Send`, `Sync`, and `Unpin` to dyn bound via pointer cast
--> $DIR/ptr-to-trait-obj-add-auto.rs:13:5
|
LL | x as _
| ^^^^^^
| ^^^^^^ unsupported cast
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #127323 <https://github.com/rust-lang/rust/issues/127323>
= note: this could allow UB elsewhere
= help: use `transmute` if you're sure this is sound

warning: 2 warnings emitted

Future incompatibility report: Future breakage diagnostic:
warning: adding an auto trait `Send` to a trait object in a pointer cast may cause UB later on
--> $DIR/ptr-to-trait-obj-add-auto.rs:6:5
|
LL | x as _
| ^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #127323 <https://github.com/rust-lang/rust/issues/127323>
= note: `#[warn(ptr_cast_add_auto_to_object)]` on by default

Future breakage diagnostic:
warning: adding auto traits `Send`, `Sync`, and `Unpin` to a trait object in a pointer cast may cause UB later on
--> $DIR/ptr-to-trait-obj-add-auto.rs:13:5
|
LL | x as _
| ^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #127323 <https://github.com/rust-lang/rust/issues/127323>
= note: `#[warn(ptr_cast_add_auto_to_object)]` on by default
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0804`.
4 changes: 4 additions & 0 deletions tests/ui/lint/removed-lints/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Removed lints

This directory contains tests to confirm that lints that have been
removed do not cause errors and produce the appropriate warnings.
5 changes: 5 additions & 0 deletions tests/ui/lint/removed-lints/ptr_cast_add_auto_to_object.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@ check-pass

#![deny(ptr_cast_add_auto_to_object)]
//~^ WARN lint `ptr_cast_add_auto_to_object` has been removed
fn main() {}
10 changes: 10 additions & 0 deletions tests/ui/lint/removed-lints/ptr_cast_add_auto_to_object.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
warning: lint `ptr_cast_add_auto_to_object` has been removed: converted into hard error, see issue #127323 <https://github.com/rust-lang/rust/issues/127323> for more information
--> $DIR/ptr_cast_add_auto_to_object.rs:3:9
|
LL | #![deny(ptr_cast_add_auto_to_object)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(renamed_and_removed_lints)]` on by default

warning: 1 warning emitted