Skip to content

Commit 07b5eee

Browse files
committed
Auto merge of rust-lang#138058 - jieyouxu:rollup-skdt0oz, r=jieyouxu
Rollup of 20 pull requests Successful merges: - rust-lang#134063 (dec2flt: Clean up float parsing modules) - rust-lang#136581 (Retire the legacy `Makefile`-based `run-make` test infra) - rust-lang#136662 (Count char width at most once in `Formatter::pad`) - rust-lang#136764 (Make `ptr_cast_add_auto_to_object` lint into hard error) - rust-lang#136798 (Added documentation for flushing per rust-lang#74348) - rust-lang#136865 (Perform deeper compiletest path normalization for `$TEST_BUILD_DIR` to account for compare-mode/debugger cases, and normalize long type file filename hashes) - rust-lang#136975 (Look for `python3` first on MacOS, not `py`) - rust-lang#136977 (Upload Datadog metrics with citool) - rust-lang#137240 (Slightly reformat `std::fs::remove_dir_all` error docs) - rust-lang#137298 (Check signature WF when lowering MIR body) - rust-lang#137463 ([illumos] attempt to use posix_spawn to spawn processes) - rust-lang#137477 (uefi: Add Service Binding Protocol abstraction) - rust-lang#137569 (Stabilize `string_extend_from_within`) - rust-lang#137633 (Only use implied bounds hack if bevy, and use deeply normalize in implied bounds hack) - rust-lang#137679 (Various coretests improvements) - rust-lang#137723 (Make `rust.description` more general-purpose and pass `CFG_VER_DESCRIPTION`) - rust-lang#137728 (Remove unsizing coercions for tuples) - rust-lang#137731 (Resume one waiter at once in deadlock handler) - rust-lang#137875 (mir_build: Integrate "simplification" steps into match-pair-tree creation) - rust-lang#138028 (compiler: add `ExternAbi::is_rustic_abi`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4559163 + fe4c085 commit 07b5eee

File tree

254 files changed

+2860
-8349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

254 files changed

+2860
-8349
lines changed

.github/workflows/ci.yml

+5-9
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ jobs:
5858
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
5959
run: |
6060
cd src/ci/citool
61-
cargo test
62-
cargo run calculate-job-matrix >> $GITHUB_OUTPUT
61+
CARGO_INCREMENTAL=0 cargo test
62+
CARGO_INCREMENTAL=0 cargo run calculate-job-matrix >> $GITHUB_OUTPUT
6363
id: jobs
6464
job:
6565
name: ${{ matrix.full_name }}
@@ -183,11 +183,11 @@ jobs:
183183
run: src/ci/scripts/dump-environment.sh
184184

185185
# Pre-build citool before the following step uninstalls rustup
186-
# Build is into the build directory, to avoid modifying sources
186+
# Build it into the build directory, to avoid modifying sources
187187
- name: build citool
188188
run: |
189189
cd src/ci/citool
190-
CARGO_TARGET_DIR=../../../build/citool cargo build
190+
CARGO_INCREMENTAL=0 CARGO_TARGET_DIR=../../../build/citool cargo build
191191
192192
- name: run the build
193193
# Redirect stderr to stdout to avoid reordering the two streams in the GHA logs.
@@ -238,13 +238,9 @@ jobs:
238238
- name: upload job metrics to DataDog
239239
if: needs.calculate_matrix.outputs.run_type != 'pr'
240240
env:
241-
DATADOG_SITE: datadoghq.com
242241
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
243242
DD_GITHUB_JOB_NAME: ${{ matrix.full_name }}
244-
run: |
245-
cd src/ci
246-
npm ci
247-
python3 scripts/upload-build-metrics.py ../../build/cpu-usage.csv
243+
run: ./build/citool/debug/citool upload-build-metrics build/cpu-usage.csv
248244

249245
# This job isused to tell bors the final status of the build, as there is no practical way to detect
250246
# when a workflow is successful listening to webhooks only in our current bors implementation (homu).

compiler/rustc_abi/src/extern_abi.rs

+11
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ impl StableOrd for ExternAbi {
191191
}
192192

193193
impl ExternAbi {
194+
/// An ABI "like Rust"
195+
///
196+
/// These ABIs are fully controlled by the Rust compiler, which means they
197+
/// - support unwinding with `-Cpanic=unwind`, unlike `extern "C"`
198+
/// - often diverge from the C ABI
199+
/// - are subject to change between compiler versions
200+
pub fn is_rustic_abi(self) -> bool {
201+
use ExternAbi::*;
202+
matches!(self, Rust | RustCall | RustIntrinsic | RustCold)
203+
}
204+
194205
pub fn supports_varargs(self) -> bool {
195206
// * C and Cdecl obviously support varargs.
196207
// * C can be based on Aapcs, SysV64 or Win64, so they must support varargs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
An auto trait cannot be added to the bounds of a `dyn Trait` type via
2+
a pointer cast.
3+
4+
Erroneous code example:
5+
6+
```rust,edition2021,compile_fail,E0804
7+
let ptr: *const dyn core::any::Any = &();
8+
_ = ptr as *const (dyn core::any::Any + Send);
9+
```
10+
11+
Adding an auto trait can make the vtable invalid, potentially causing
12+
UB in safe code afterwards. For example:
13+
14+
```rust,edition2021,no_run
15+
use core::{mem::transmute, ptr::NonNull};
16+
17+
trait Trait {
18+
fn f(&self)
19+
where
20+
Self: Send;
21+
}
22+
23+
impl Trait for NonNull<()> {
24+
fn f(&self) {
25+
unreachable!()
26+
}
27+
}
28+
29+
fn main() {
30+
let unsend: &dyn Trait = &NonNull::dangling();
31+
let bad: &(dyn Trait + Send) = unsafe { transmute(unsend) };
32+
// This crashes, since the vtable for `NonNull as dyn Trait` does
33+
// not have an entry for `Trait::f`.
34+
bad.f();
35+
}
36+
```
37+
38+
To fix this error, you can use `transmute` rather than pointer casts,
39+
but you must ensure that the vtable is valid for the pointer's type
40+
before calling a method on the trait object or allowing other code to
41+
do so.

compiler/rustc_error_codes/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ E0800: 0800,
547547
E0801: 0801,
548548
E0802: 0802,
549549
E0803: 0803,
550+
E0804: 0804,
550551
);
551552
)
552553
}

compiler/rustc_feature/src/removed.rs

+2
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ declare_features! (
244244
/// Allows unnamed fields of struct and union type
245245
(removed, unnamed_fields, "1.83.0", Some(49804), Some("feature needs redesign")),
246246
(removed, unsafe_no_drop_flag, "1.0.0", None, None),
247+
(removed, unsized_tuple_coercion, "CURRENT_RUSTC_VERSION", Some(42877),
248+
Some("The feature restricts possible layouts for tuples, and this restriction is not worth it.")),
247249
/// Allows `union` fields that don't implement `Copy` as long as they don't have any drop glue.
248250
(removed, untagged_unions, "1.13.0", Some(55149),
249251
Some("unions with `Copy` and `ManuallyDrop` fields are stable; there is no intent to stabilize more")),

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,6 @@ declare_features! (
659659
(internal, unsized_fn_params, "1.49.0", Some(48055)),
660660
/// Allows unsized rvalues at arguments and parameters.
661661
(incomplete, unsized_locals, "1.30.0", Some(48055)),
662-
/// Allows unsized tuple coercion.
663-
(unstable, unsized_tuple_coercion, "1.20.0", Some(42877)),
664662
/// Allows using the `#[used(linker)]` (or `#[used(compiler)]`) attribute.
665663
(unstable, used_with_arg, "1.60.0", Some(93798)),
666664
/// Allows use of attributes in `where` clauses.

compiler/rustc_hir_analysis/src/check/check.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -745,14 +745,10 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
745745
pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
746746
match tcx.def_kind(def_id) {
747747
DefKind::Static { .. } => {
748-
tcx.ensure_ok().typeck(def_id);
749-
maybe_check_static_with_link_section(tcx, def_id);
750748
check_static_inhabited(tcx, def_id);
751749
check_static_linkage(tcx, def_id);
752750
}
753-
DefKind::Const => {
754-
tcx.ensure_ok().typeck(def_id);
755-
}
751+
DefKind::Const => {}
756752
DefKind::Enum => {
757753
check_enum(tcx, def_id);
758754
}
@@ -766,7 +762,6 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
766762
ExternAbi::Rust,
767763
)
768764
}
769-
// Everything else is checked entirely within check_item_body
770765
}
771766
DefKind::Impl { of_trait } => {
772767
if of_trait && let Some(impl_trait_header) = tcx.impl_trait_header(def_id) {

compiler/rustc_hir_analysis/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub fn forbid_intrinsic_abi(tcx: TyCtxt<'_>, sp: Span, abi: ExternAbi) {
145145
}
146146
}
147147

148-
fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
148+
pub(super) fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
149149
// Only restricted on wasm target for now
150150
if !tcx.sess.target.is_like_wasm {
151151
return;

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+30-52
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ where
126126

127127
let infcx_compat = infcx.fork();
128128

129-
// We specifically want to call the non-compat version of `implied_bounds_tys`; we do this always.
129+
// We specifically want to *disable* the implied bounds hack, first,
130+
// so we can detect when failures are due to bevy's implied bounds.
130131
let outlives_env = OutlivesEnvironment::new_with_implied_bounds_compat(
131132
&infcx,
132133
body_def_id,
133134
param_env,
134135
assumed_wf_types.iter().copied(),
135-
false,
136+
true,
136137
);
137138

138139
lint_redundant_lifetimes(tcx, body_def_id, &outlives_env);
@@ -142,53 +143,22 @@ where
142143
return Ok(());
143144
}
144145

145-
let is_bevy = assumed_wf_types.visit_with(&mut ContainsBevyParamSet { tcx }).is_break();
146-
147-
// If we have set `no_implied_bounds_compat`, then do not attempt compatibility.
148-
// We could also just always enter if `is_bevy`, and call `implied_bounds_tys`,
149-
// but that does result in slightly more work when this option is set and
150-
// just obscures what we mean here anyways. Let's just be explicit.
151-
if is_bevy && !infcx.tcx.sess.opts.unstable_opts.no_implied_bounds_compat {
152-
let outlives_env = OutlivesEnvironment::new_with_implied_bounds_compat(
153-
&infcx,
154-
body_def_id,
155-
param_env,
156-
assumed_wf_types,
157-
true,
158-
);
159-
let errors_compat = infcx_compat.resolve_regions_with_outlives_env(&outlives_env);
160-
if errors_compat.is_empty() {
161-
Ok(())
162-
} else {
163-
Err(infcx_compat.err_ctxt().report_region_errors(body_def_id, &errors_compat))
164-
}
146+
let outlives_env = OutlivesEnvironment::new_with_implied_bounds_compat(
147+
&infcx_compat,
148+
body_def_id,
149+
param_env,
150+
assumed_wf_types,
151+
// Don't *disable* the implied bounds hack; though this will only apply
152+
// the implied bounds hack if this contains `bevy_ecs`'s `ParamSet` type.
153+
false,
154+
);
155+
let errors_compat = infcx_compat.resolve_regions_with_outlives_env(&outlives_env);
156+
if errors_compat.is_empty() {
157+
// FIXME: Once we fix bevy, this would be the place to insert a warning
158+
// to upgrade bevy.
159+
Ok(())
165160
} else {
166-
Err(infcx.err_ctxt().report_region_errors(body_def_id, &errors))
167-
}
168-
}
169-
170-
struct ContainsBevyParamSet<'tcx> {
171-
tcx: TyCtxt<'tcx>,
172-
}
173-
174-
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ContainsBevyParamSet<'tcx> {
175-
type Result = ControlFlow<()>;
176-
177-
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
178-
// We only care to match `ParamSet<T>` or `&ParamSet<T>`.
179-
match t.kind() {
180-
ty::Adt(def, _) => {
181-
if self.tcx.item_name(def.did()) == sym::ParamSet
182-
&& self.tcx.crate_name(def.did().krate) == sym::bevy_ecs
183-
{
184-
return ControlFlow::Break(());
185-
}
186-
}
187-
ty::Ref(_, ty, _) => ty.visit_with(self)?,
188-
_ => {}
189-
}
190-
191-
ControlFlow::Continue(())
161+
Err(infcx_compat.err_ctxt().report_region_errors(body_def_id, &errors_compat))
192162
}
193163
}
194164

@@ -201,7 +171,7 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua
201171
hir::Node::ImplItem(item) => check_impl_item(tcx, item),
202172
hir::Node::ForeignItem(item) => check_foreign_item(tcx, item),
203173
hir::Node::OpaqueTy(_) => Ok(crate::check::check::check_item_type(tcx, def_id)),
204-
_ => unreachable!(),
174+
_ => unreachable!("{node:?}"),
205175
};
206176

207177
if let Some(generics) = node.generics() {
@@ -1108,7 +1078,13 @@ fn check_associated_item(
11081078
let ty = tcx.type_of(item.def_id).instantiate_identity();
11091079
let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty);
11101080
wfcx.register_wf_obligation(span, loc, ty.into());
1111-
check_sized_if_body(wfcx, item.def_id.expect_local(), ty, Some(span));
1081+
check_sized_if_body(
1082+
wfcx,
1083+
item.def_id.expect_local(),
1084+
ty,
1085+
Some(span),
1086+
ObligationCauseCode::SizedConstOrStatic,
1087+
);
11121088
Ok(())
11131089
}
11141090
ty::AssocKind::Fn => {
@@ -1354,7 +1330,7 @@ fn check_item_type(
13541330
traits::ObligationCause::new(
13551331
ty_span,
13561332
wfcx.body_def_id,
1357-
ObligationCauseCode::WellFormed(None),
1333+
ObligationCauseCode::SizedConstOrStatic,
13581334
),
13591335
wfcx.param_env,
13601336
item_ty,
@@ -1698,6 +1674,7 @@ fn check_fn_or_method<'tcx>(
16981674
hir::FnRetTy::Return(ty) => Some(ty.span),
16991675
hir::FnRetTy::DefaultReturn(_) => None,
17001676
},
1677+
ObligationCauseCode::SizedReturnType,
17011678
);
17021679
}
17031680

@@ -1706,13 +1683,14 @@ fn check_sized_if_body<'tcx>(
17061683
def_id: LocalDefId,
17071684
ty: Ty<'tcx>,
17081685
maybe_span: Option<Span>,
1686+
code: ObligationCauseCode<'tcx>,
17091687
) {
17101688
let tcx = wfcx.tcx();
17111689
if let Some(body) = tcx.hir_maybe_body_owned_by(def_id) {
17121690
let span = maybe_span.unwrap_or(body.value.span);
17131691

17141692
wfcx.register_bound(
1715-
ObligationCause::new(span, def_id, traits::ObligationCauseCode::SizedReturnType),
1693+
ObligationCause::new(span, def_id, code),
17161694
wfcx.param_env,
17171695
ty,
17181696
tcx.require_lang_item(LangItem::Sized, Some(span)),

compiler/rustc_hir_analysis/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
212212
tcx.par_hir_body_owners(|item_def_id| {
213213
let def_kind = tcx.def_kind(item_def_id);
214214
match def_kind {
215-
DefKind::Static { .. } => tcx.ensure_ok().eval_static_initializer(item_def_id),
215+
DefKind::Static { .. } => {
216+
tcx.ensure_ok().eval_static_initializer(item_def_id);
217+
check::maybe_check_static_with_link_section(tcx, item_def_id);
218+
}
216219
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
217220
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
218221
let cid = GlobalId { instance, promoted: None };
@@ -223,12 +226,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
223226
}
224227
});
225228

226-
// FIXME: Remove this when we implement creating `DefId`s
227-
// for anon constants during their parents' typeck.
228-
// Typeck all body owners in parallel will produce queries
229-
// cycle errors because it may typeck on anon constants directly.
230229
tcx.par_hir_body_owners(|item_def_id| {
231230
let def_kind = tcx.def_kind(item_def_id);
231+
// Skip `AnonConst`s because we feed their `type_of`.
232232
if !matches!(def_kind, DefKind::AnonConst) {
233233
tcx.ensure_ok().typeck(item_def_id);
234234
}

compiler/rustc_hir_typeck/messages.ftl

+6-3
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,13 @@ hir_typeck_pass_to_variadic_function = can't pass `{$ty}` to variadic function
171171
.suggestion = cast the value to `{$cast_ty}`
172172
.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
173173
174-
hir_typeck_ptr_cast_add_auto_to_object = adding {$traits_len ->
175-
[1] an auto trait {$traits}
174+
hir_typeck_ptr_cast_add_auto_to_object = cannot add {$traits_len ->
175+
[1] auto trait {$traits}
176176
*[other] auto traits {$traits}
177-
} to a trait object in a pointer cast may cause UB later on
177+
} to dyn bound via pointer cast
178+
.note = this could allow UB elsewhere
179+
.help = use `transmute` if you're sure this is sound
180+
.label = unsupported cast
178181
179182
hir_typeck_remove_semi_for_coerce = you might have meant to return the `match` expression
180183
hir_typeck_remove_semi_for_coerce_expr = this could be implicitly returned but it is a statement, not a tail expression

compiler/rustc_hir_typeck/src/cast.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -940,23 +940,19 @@ impl<'a, 'tcx> CastCheck<'tcx> {
940940
.collect::<Vec<_>>();
941941

942942
if !added.is_empty() {
943-
tcx.emit_node_span_lint(
944-
lint::builtin::PTR_CAST_ADD_AUTO_TO_OBJECT,
945-
self.expr.hir_id,
946-
self.span,
947-
errors::PtrCastAddAutoToObject {
948-
traits_len: added.len(),
949-
traits: {
950-
let mut traits: Vec<_> = added
951-
.into_iter()
952-
.map(|trait_did| tcx.def_path_str(trait_did))
953-
.collect();
954-
955-
traits.sort();
956-
traits.into()
957-
},
943+
tcx.dcx().emit_err(errors::PtrCastAddAutoToObject {
944+
span: self.span,
945+
traits_len: added.len(),
946+
traits: {
947+
let mut traits: Vec<_> = added
948+
.into_iter()
949+
.map(|trait_did| tcx.def_path_str(trait_did))
950+
.collect();
951+
952+
traits.sort();
953+
traits.into()
958954
},
959-
)
955+
});
960956
}
961957

962958
Ok(CastKind::PtrPtrCast)

0 commit comments

Comments
 (0)