Skip to content

Commit d693a43

Browse files
committed
Auto merge of rust-lang#138044 - workingjubilee:rollup-lf771sb, r=workingjubilee
Rollup of 25 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#136798 (Added documentation for flushing per rust-lang#74348) - rust-lang#137240 (Slightly reformat `std::fs::remove_dir_all` error docs) - rust-lang#137303 (Remove `MaybeForgetReturn` suggestion) - rust-lang#137327 (Undeprecate env::home_dir) - rust-lang#137463 ([illumos] attempt to use posix_spawn to spawn processes) - rust-lang#137477 (uefi: Add Service Binding Protocol abstraction) - rust-lang#137565 (Try to point of macro expansion from resolver and method errors if it involves macro var) - rust-lang#137569 (Stabilize `string_extend_from_within`) - rust-lang#137612 (Update bootstrap to edition 2024) - rust-lang#137633 (Only use implied bounds hack if bevy, and use deeply normalize in implied bounds hack) - rust-lang#137643 (Add DWARF test case for non-C-like `repr128` enums) - rust-lang#137679 (Various coretests improvements) - rust-lang#137723 (Make `rust.description` more general-purpose and pass `CFG_VER_DESCRIPTION`) - rust-lang#137758 (fix usage of ty decl macro fragments in attributes) - rust-lang#137764 (Ensure that negative auto impls are always applicable) - rust-lang#137772 (Fix char count in `Display` for `ByteStr`) - rust-lang#137798 (ci: use ubuntu 24 on arm large runner) - rust-lang#137805 (adjust Layout debug printing to match the internal field name) - rust-lang#137808 (Do not require that unsafe fields lack drop glue) - rust-lang#137820 (Clarify why InhabitedPredicate::instantiate_opt exists) - rust-lang#137825 (Provide more context on resolve error caused from incorrect RTN) - rust-lang#138028 (compiler: add `ExternAbi::is_rustic_abi`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4559163 + 2d6b3c2 commit d693a43

File tree

171 files changed

+2478
-2341
lines changed

Some content is hidden

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

171 files changed

+2478
-2341
lines changed

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.

compiler/rustc_abi/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ where
18121812
f.debug_struct("Layout")
18131813
.field("size", size)
18141814
.field("align", align)
1815-
.field("abi", backend_repr)
1815+
.field("backend_repr", backend_repr)
18161816
.field("fields", fields)
18171817
.field("largest_niche", largest_niche)
18181818
.field("uninhabited", uninhabited)

compiler/rustc_ast_lowering/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
926926
if let Some(first_char) = constraint.ident.as_str().chars().next()
927927
&& first_char.is_ascii_lowercase()
928928
{
929-
tracing::info!(?data, ?data.inputs);
930929
let err = match (&data.inputs[..], &data.output) {
931930
([_, ..], FnRetTy::Default(_)) => {
932931
errors::BadReturnTypeNotation::Inputs { span: data.inputs_span }

compiler/rustc_ast_lowering/src/path.rs

-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
268268
}
269269
GenericArgs::Parenthesized(data) => match generic_args_mode {
270270
GenericArgsMode::ReturnTypeNotation => {
271-
tracing::info!(?data, ?data.inputs);
272271
let err = match (&data.inputs[..], &data.output) {
273272
([_, ..], FnRetTy::Default(_)) => {
274273
BadReturnTypeNotation::Inputs { span: data.inputs_span }

compiler/rustc_attr_parsing/src/parser.rs

+9
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,15 @@ impl<'a> MetaItemListParserContext<'a> {
473473
{
474474
self.inside_delimiters.next();
475475
return Some(MetaItemOrLitParser::Lit(lit));
476+
} else if let Some(TokenTree::Delimited(.., Delimiter::Invisible(_), inner_tokens)) =
477+
self.inside_delimiters.peek()
478+
{
479+
self.inside_delimiters.next();
480+
return MetaItemListParserContext {
481+
inside_delimiters: inner_tokens.iter().peekable(),
482+
dcx: self.dcx,
483+
}
484+
.next();
476485
}
477486

478487
// or a path.

compiler/rustc_data_structures/src/marker.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::alloc::Allocator;
2+
13
#[rustc_on_unimplemented(message = "`{Self}` doesn't implement `DynSend`. \
24
Add it to `rustc_data_structures::marker` or use `IntoDynSyncSend` if it's already `Send`")]
35
// This is an auto trait for types which can be sent across threads if `sync::is_dyn_thread_safe()`
@@ -28,8 +30,8 @@ impls_dyn_send_neg!(
2830
[*const T where T: ?Sized]
2931
[*mut T where T: ?Sized]
3032
[std::ptr::NonNull<T> where T: ?Sized]
31-
[std::rc::Rc<T> where T: ?Sized]
32-
[std::rc::Weak<T> where T: ?Sized]
33+
[std::rc::Rc<T, A> where T: ?Sized, A: Allocator]
34+
[std::rc::Weak<T, A> where T: ?Sized, A: Allocator]
3335
[std::sync::MutexGuard<'_, T> where T: ?Sized]
3436
[std::sync::RwLockReadGuard<'_, T> where T: ?Sized]
3537
[std::sync::RwLockWriteGuard<'_, T> where T: ?Sized]
@@ -96,8 +98,8 @@ impls_dyn_sync_neg!(
9698
[std::cell::RefCell<T> where T: ?Sized]
9799
[std::cell::UnsafeCell<T> where T: ?Sized]
98100
[std::ptr::NonNull<T> where T: ?Sized]
99-
[std::rc::Rc<T> where T: ?Sized]
100-
[std::rc::Weak<T> where T: ?Sized]
101+
[std::rc::Rc<T, A> where T: ?Sized, A: Allocator]
102+
[std::rc::Weak<T, A> where T: ?Sized, A: Allocator]
101103
[std::cell::OnceCell<T> where T]
102104
[std::sync::mpsc::Receiver<T> where T]
103105
[std::sync::mpsc::Sender<T> where T]

compiler/rustc_errors/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,6 @@ pub enum StashKey {
626626
MaybeFruTypo,
627627
CallAssocMethod,
628628
AssociatedTypeSuggestion,
629-
MaybeForgetReturn,
630629
/// Query cycle detected, stashing in favor of a better error.
631630
Cycle,
632631
UndeterminedMacroResolution,

compiler/rustc_hir_analysis/messages.ftl

+2-7
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,6 @@ hir_analysis_invalid_union_field =
278278
hir_analysis_invalid_union_field_sugg =
279279
wrap the field type in `ManuallyDrop<...>`
280280
281-
hir_analysis_invalid_unsafe_field =
282-
field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be unsafe
283-
.note = unsafe fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`
284-
285-
hir_analysis_invalid_unsafe_field_sugg =
286-
wrap the field type in `ManuallyDrop<...>`
287-
288281
hir_analysis_late_bound_const_in_apit = `impl Trait` can only mention const parameters from an fn or impl
289282
.label = const parameter declared here
290283
@@ -620,6 +613,8 @@ hir_analysis_variances_of = {$variances}
620613
hir_analysis_where_clause_on_main = `main` function is not allowed to have a `where` clause
621614
.label = `main` cannot have a `where` clause
622615
616+
hir_analysis_within_macro = due to this macro variable
617+
623618
hir_analysis_wrong_number_of_generic_arguments_to_intrinsic =
624619
intrinsic has wrong number of {$descr} parameters: found {$found}, expected {$expected}
625620
.label = expected {$expected} {$descr} {$expected ->

compiler/rustc_hir_analysis/src/check/dropck.rs compiler/rustc_hir_analysis/src/check/always_applicable.rs

+110-41
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
//! This module contains methods that assist in checking that impls are general
2+
//! enough, i.e. that they always apply to every valid instantaiton of the ADT
3+
//! they're implemented for.
4+
//!
5+
//! This is necessary for `Drop` and negative impls to be well-formed.
6+
17
use rustc_data_structures::fx::FxHashSet;
28
use rustc_errors::codes::*;
39
use rustc_errors::{ErrorGuaranteed, struct_span_code_err};
410
use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
511
use rustc_infer::traits::{ObligationCause, ObligationCauseCode};
12+
use rustc_middle::span_bug;
613
use rustc_middle::ty::util::CheckRegions;
714
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypingMode};
815
use rustc_trait_selection::regions::InferCtxtRegionExt;
@@ -27,11 +34,12 @@ use crate::hir::def_id::{DefId, LocalDefId};
2734
/// 3. Any bounds on the generic parameters must be reflected in the
2835
/// struct/enum definition for the nominal type itself (i.e.
2936
/// cannot do `struct S<T>; impl<T:Clone> Drop for S<T> { ... }`).
30-
///
3137
pub(crate) fn check_drop_impl(
3238
tcx: TyCtxt<'_>,
3339
drop_impl_did: DefId,
3440
) -> Result<(), ErrorGuaranteed> {
41+
let drop_impl_did = drop_impl_did.expect_local();
42+
3543
match tcx.impl_polarity(drop_impl_did) {
3644
ty::ImplPolarity::Positive => {}
3745
ty::ImplPolarity::Negative => {
@@ -45,55 +53,107 @@ pub(crate) fn check_drop_impl(
4553
}));
4654
}
4755
}
48-
let dtor_self_type = tcx.type_of(drop_impl_did).instantiate_identity();
49-
match dtor_self_type.kind() {
56+
57+
tcx.ensure_ok().orphan_check_impl(drop_impl_did)?;
58+
59+
let dtor_impl_trait_ref = tcx.impl_trait_ref(drop_impl_did).unwrap().instantiate_identity();
60+
61+
match dtor_impl_trait_ref.self_ty().kind() {
5062
ty::Adt(adt_def, adt_to_impl_args) => {
51-
ensure_drop_params_and_item_params_correspond(
63+
ensure_impl_params_and_item_params_correspond(
5264
tcx,
53-
drop_impl_did.expect_local(),
65+
drop_impl_did,
5466
adt_def.did(),
5567
adt_to_impl_args,
5668
)?;
5769

58-
ensure_drop_predicates_are_implied_by_item_defn(
70+
ensure_impl_predicates_are_implied_by_item_defn(
5971
tcx,
60-
drop_impl_did.expect_local(),
61-
adt_def.did().expect_local(),
72+
drop_impl_did,
73+
adt_def.did(),
6274
adt_to_impl_args,
6375
)
6476
}
6577
_ => {
66-
// Destructors only work on nominal types. This was
67-
// already checked by coherence, but compilation may
68-
// not have been terminated.
69-
let span = tcx.def_span(drop_impl_did);
70-
let reported = tcx.dcx().span_delayed_bug(
71-
span,
72-
format!("should have been rejected by coherence check: {dtor_self_type}"),
73-
);
74-
Err(reported)
78+
span_bug!(tcx.def_span(drop_impl_did), "incoherent impl of Drop");
7579
}
7680
}
7781
}
7882

79-
fn ensure_drop_params_and_item_params_correspond<'tcx>(
83+
pub(crate) fn check_negative_auto_trait_impl<'tcx>(
8084
tcx: TyCtxt<'tcx>,
81-
drop_impl_did: LocalDefId,
82-
self_type_did: DefId,
85+
impl_def_id: LocalDefId,
86+
impl_trait_ref: ty::TraitRef<'tcx>,
87+
polarity: ty::ImplPolarity,
88+
) -> Result<(), ErrorGuaranteed> {
89+
let ty::ImplPolarity::Negative = polarity else {
90+
return Ok(());
91+
};
92+
93+
if !tcx.trait_is_auto(impl_trait_ref.def_id) {
94+
return Ok(());
95+
}
96+
97+
if tcx.defaultness(impl_def_id).is_default() {
98+
tcx.dcx().span_delayed_bug(tcx.def_span(impl_def_id), "default impl cannot be negative");
99+
}
100+
101+
tcx.ensure_ok().orphan_check_impl(impl_def_id)?;
102+
103+
match impl_trait_ref.self_ty().kind() {
104+
ty::Adt(adt_def, adt_to_impl_args) => {
105+
ensure_impl_params_and_item_params_correspond(
106+
tcx,
107+
impl_def_id,
108+
adt_def.did(),
109+
adt_to_impl_args,
110+
)?;
111+
112+
ensure_impl_predicates_are_implied_by_item_defn(
113+
tcx,
114+
impl_def_id,
115+
adt_def.did(),
116+
adt_to_impl_args,
117+
)
118+
}
119+
_ => {
120+
if tcx.features().auto_traits() {
121+
// NOTE: We ignore the applicability check for negative auto impls
122+
// defined in libcore. In the (almost impossible) future where we
123+
// stabilize auto impls, then the proper applicability check MUST
124+
// be implemented here to handle non-ADT rigid types.
125+
Ok(())
126+
} else {
127+
span_bug!(tcx.def_span(impl_def_id), "incoherent impl of negative auto trait");
128+
}
129+
}
130+
}
131+
}
132+
133+
fn ensure_impl_params_and_item_params_correspond<'tcx>(
134+
tcx: TyCtxt<'tcx>,
135+
impl_def_id: LocalDefId,
136+
adt_def_id: DefId,
83137
adt_to_impl_args: GenericArgsRef<'tcx>,
84138
) -> Result<(), ErrorGuaranteed> {
85139
let Err(arg) = tcx.uses_unique_generic_params(adt_to_impl_args, CheckRegions::OnlyParam) else {
86140
return Ok(());
87141
};
88142

89-
let drop_impl_span = tcx.def_span(drop_impl_did);
90-
let item_span = tcx.def_span(self_type_did);
91-
let self_descr = tcx.def_descr(self_type_did);
143+
let impl_span = tcx.def_span(impl_def_id);
144+
let item_span = tcx.def_span(adt_def_id);
145+
let self_descr = tcx.def_descr(adt_def_id);
146+
let polarity = match tcx.impl_polarity(impl_def_id) {
147+
ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => "",
148+
ty::ImplPolarity::Negative => "!",
149+
};
150+
let trait_name = tcx
151+
.item_name(tcx.trait_id_of_impl(impl_def_id.to_def_id()).expect("expected impl of trait"));
92152
let mut err = struct_span_code_err!(
93153
tcx.dcx(),
94-
drop_impl_span,
154+
impl_span,
95155
E0366,
96-
"`Drop` impls cannot be specialized"
156+
"`{polarity}{trait_name}` impls cannot be specialized",
97157
);
98158
match arg {
99159
ty::util::NotUniqueParam::DuplicateParam(arg) => {
@@ -116,17 +176,22 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
116176
/// Confirms that all predicates defined on the `Drop` impl (`drop_impl_def_id`) are able to be
117177
/// proven from within `adt_def_id`'s environment. I.e. all the predicates on the impl are
118178
/// implied by the ADT being well formed.
119-
fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
179+
fn ensure_impl_predicates_are_implied_by_item_defn<'tcx>(
120180
tcx: TyCtxt<'tcx>,
121-
drop_impl_def_id: LocalDefId,
122-
adt_def_id: LocalDefId,
181+
impl_def_id: LocalDefId,
182+
adt_def_id: DefId,
123183
adt_to_impl_args: GenericArgsRef<'tcx>,
124184
) -> Result<(), ErrorGuaranteed> {
125185
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
126186
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
127187

128-
let impl_span = tcx.def_span(drop_impl_def_id.to_def_id());
129-
188+
let impl_span = tcx.def_span(impl_def_id.to_def_id());
189+
let trait_name = tcx
190+
.item_name(tcx.trait_id_of_impl(impl_def_id.to_def_id()).expect("expected impl of trait"));
191+
let polarity = match tcx.impl_polarity(impl_def_id) {
192+
ty::ImplPolarity::Positive | ty::ImplPolarity::Reservation => "",
193+
ty::ImplPolarity::Negative => "!",
194+
};
130195
// Take the param-env of the adt and instantiate the args that show up in
131196
// the implementation's self type. This gives us the assumptions that the
132197
// self ty of the implementation is allowed to know just from it being a
@@ -145,17 +210,21 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
145210
let adt_env =
146211
ty::EarlyBinder::bind(tcx.param_env(adt_def_id)).instantiate(tcx, adt_to_impl_args);
147212

148-
let fresh_impl_args = infcx.fresh_args_for_item(impl_span, drop_impl_def_id.to_def_id());
213+
let fresh_impl_args = infcx.fresh_args_for_item(impl_span, impl_def_id.to_def_id());
149214
let fresh_adt_ty =
150-
tcx.impl_trait_ref(drop_impl_def_id).unwrap().instantiate(tcx, fresh_impl_args).self_ty();
215+
tcx.impl_trait_ref(impl_def_id).unwrap().instantiate(tcx, fresh_impl_args).self_ty();
151216

152217
ocx.eq(&ObligationCause::dummy_with_span(impl_span), adt_env, fresh_adt_ty, impl_adt_ty)
153-
.unwrap();
218+
.expect("equating fully generic trait ref should never fail");
154219

155-
for (clause, span) in tcx.predicates_of(drop_impl_def_id).instantiate(tcx, fresh_impl_args) {
156-
let normalize_cause = traits::ObligationCause::misc(span, adt_def_id);
220+
for (clause, span) in tcx.predicates_of(impl_def_id).instantiate(tcx, fresh_impl_args) {
221+
let normalize_cause = traits::ObligationCause::misc(span, impl_def_id);
157222
let pred = ocx.normalize(&normalize_cause, adt_env, clause);
158-
let cause = traits::ObligationCause::new(span, adt_def_id, ObligationCauseCode::DropImpl);
223+
let cause = traits::ObligationCause::new(
224+
span,
225+
impl_def_id,
226+
ObligationCauseCode::AlwaysApplicableImpl,
227+
);
159228
ocx.register_obligation(traits::Obligation::new(tcx, cause, adt_env, pred));
160229
}
161230

@@ -173,13 +242,13 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
173242
let root_predicate = error.root_obligation.predicate;
174243
if root_predicates.insert(root_predicate) {
175244
let item_span = tcx.def_span(adt_def_id);
176-
let self_descr = tcx.def_descr(adt_def_id.to_def_id());
245+
let self_descr = tcx.def_descr(adt_def_id);
177246
guar = Some(
178247
struct_span_code_err!(
179248
tcx.dcx(),
180249
error.root_obligation.cause.span,
181250
E0367,
182-
"`Drop` impl requires `{root_predicate}` \
251+
"`{polarity}{trait_name}` impl requires `{root_predicate}` \
183252
but the {self_descr} it is implemented for does not",
184253
)
185254
.with_span_note(item_span, "the implementor must specify the same requirement")
@@ -190,12 +259,12 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
190259
return Err(guar.unwrap());
191260
}
192261

193-
let errors = ocx.infcx.resolve_regions(adt_def_id, adt_env, []);
262+
let errors = ocx.infcx.resolve_regions(impl_def_id, adt_env, []);
194263
if !errors.is_empty() {
195264
let mut guar = None;
196265
for error in errors {
197266
let item_span = tcx.def_span(adt_def_id);
198-
let self_descr = tcx.def_descr(adt_def_id.to_def_id());
267+
let self_descr = tcx.def_descr(adt_def_id);
199268
let outlives = match error {
200269
RegionResolutionError::ConcreteFailure(_, a, b) => format!("{b}: {a}"),
201270
RegionResolutionError::GenericBoundFailure(_, generic, r) => {
@@ -212,7 +281,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
212281
tcx.dcx(),
213282
error.origin().span(),
214283
E0367,
215-
"`Drop` impl requires `{outlives}` \
284+
"`{polarity}{trait_name}` impl requires `{outlives}` \
216285
but the {self_descr} it is implemented for does not",
217286
)
218287
.with_span_note(item_span, "the implementor must specify the same requirement")

0 commit comments

Comments
 (0)