Skip to content

Commit 99cc250

Browse files
committed
Auto merge of rust-lang#137982 - matthiaskrgr:rollup-12jvilg, r=matthiaskrgr
Rollup of 12 pull requests Successful merges: - rust-lang#136975 (Look for `python3` first on MacOS, not `py`) - rust-lang#137240 (Slightly reformat `std::fs::remove_dir_all` error docs) - rust-lang#137303 (Remove `MaybeForgetReturn` suggestion) - rust-lang#137463 ([illumos] attempt to use posix_spawn to spawn processes) - rust-lang#137722 (`librustdoc`: 2024 edition! 🎊) - rust-lang#137758 (fix usage of ty decl macro fragments in attributes) - rust-lang#137772 (Fix char count in `Display` for `ByteStr`) - 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#137913 (Allow struct field default values to reference struct's generics) - rust-lang#137963 (Add ``dyn`` keyword to `E0373` examples) - rust-lang#137975 (Remove unused `PpMode::needs_hir`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fd17dea + 98c6bd4 commit 99cc250

File tree

66 files changed

+636
-809
lines changed

Some content is hidden

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

66 files changed

+636
-809
lines changed

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_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/captures.rs

-8
This file was deleted.

compiler/rustc_data_structures/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub use rustc_index::static_assert_size;
4848
pub mod aligned;
4949
pub mod base_n;
5050
pub mod binary_search_util;
51-
pub mod captures;
5251
pub mod fingerprint;
5352
pub mod flat_map_in_place;
5453
pub mod flock;

compiler/rustc_error_codes/src/error_codes/E0373.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ A captured variable in a closure may not live long enough.
33
Erroneous code example:
44

55
```compile_fail,E0373
6-
fn foo() -> Box<Fn(u32) -> u32> {
6+
fn foo() -> Box<dyn Fn(u32) -> u32> {
77
let x = 0u32;
88
Box::new(|y| x + y)
99
}
@@ -42,7 +42,7 @@ This approach moves (or copies, where possible) data into the closure, rather
4242
than taking references to it. For example:
4343

4444
```
45-
fn foo() -> Box<Fn(u32) -> u32> {
45+
fn foo() -> Box<dyn Fn(u32) -> u32> {
4646
let x = 0u32;
4747
Box::new(move |y| x + y)
4848
}

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

-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

compiler/rustc_hir_analysis/src/check/check.rs

-32
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId) {
7070

7171
check_transparent(tcx, def);
7272
check_packed(tcx, span, def);
73-
check_unsafe_fields(tcx, def_id);
7473
}
7574

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

147-
/// Check that the unsafe fields do not need dropping.
148-
fn check_unsafe_fields(tcx: TyCtxt<'_>, item_def_id: LocalDefId) {
149-
let span = tcx.def_span(item_def_id);
150-
let def = tcx.adt_def(item_def_id);
151-
152-
let typing_env = ty::TypingEnv::non_body_analysis(tcx, item_def_id);
153-
let args = ty::GenericArgs::identity_for_item(tcx, item_def_id);
154-
155-
for field in def.all_fields() {
156-
if !field.safety.is_unsafe() {
157-
continue;
158-
}
159-
160-
if !allowed_union_or_unsafe_field(tcx, field.ty(tcx, args), typing_env, span) {
161-
let hir::Node::Field(field) = tcx.hir_node_by_def_id(field.did.expect_local()) else {
162-
unreachable!("field has to correspond to hir field")
163-
};
164-
let ty_span = field.ty.span;
165-
tcx.dcx().emit_err(errors::InvalidUnsafeField {
166-
field_span: field.span,
167-
sugg: errors::InvalidUnsafeFieldSuggestion {
168-
lo: ty_span.shrink_to_lo(),
169-
hi: ty_span.shrink_to_hi(),
170-
},
171-
note: (),
172-
});
173-
}
174-
}
175-
}
176-
177146
/// Check that a `static` is inhabited.
178147
fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
179148
// Make sure statics are inhabited.
@@ -1517,7 +1486,6 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
15171486

15181487
detect_discriminant_duplicate(tcx, def);
15191488
check_transparent(tcx, def);
1520-
check_unsafe_fields(tcx, def_id);
15211489
}
15221490

15231491
/// Part of enum check. Given the discriminants of an enum, errors if two or more discriminants are equal

compiler/rustc_hir_analysis/src/collect/generics_of.rs

+2
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
187187
Some(parent_did)
188188
}
189189
Node::TyPat(_) => Some(parent_did),
190+
// Field default values inherit the ADT's generics.
191+
Node::Field(_) => Some(parent_did),
190192
_ => None,
191193
}
192194
}

compiler/rustc_hir_analysis/src/errors.rs

-23
Original file line numberDiff line numberDiff line change
@@ -710,17 +710,6 @@ pub(crate) struct InvalidUnionField {
710710
pub note: (),
711711
}
712712

713-
#[derive(Diagnostic)]
714-
#[diag(hir_analysis_invalid_unsafe_field, code = E0740)]
715-
pub(crate) struct InvalidUnsafeField {
716-
#[primary_span]
717-
pub field_span: Span,
718-
#[subdiagnostic]
719-
pub sugg: InvalidUnsafeFieldSuggestion,
720-
#[note]
721-
pub note: (),
722-
}
723-
724713
#[derive(Diagnostic)]
725714
#[diag(hir_analysis_return_type_notation_on_non_rpitit)]
726715
pub(crate) struct ReturnTypeNotationOnNonRpitit<'tcx> {
@@ -742,18 +731,6 @@ pub(crate) struct InvalidUnionFieldSuggestion {
742731
pub hi: Span,
743732
}
744733

745-
#[derive(Subdiagnostic)]
746-
#[multipart_suggestion(
747-
hir_analysis_invalid_unsafe_field_sugg,
748-
applicability = "machine-applicable"
749-
)]
750-
pub(crate) struct InvalidUnsafeFieldSuggestion {
751-
#[suggestion_part(code = "std::mem::ManuallyDrop<")]
752-
pub lo: Span,
753-
#[suggestion_part(code = ">")]
754-
pub hi: Span,
755-
}
756-
757734
#[derive(Diagnostic)]
758735
#[diag(hir_analysis_return_type_notation_equality_bound)]
759736
pub(crate) struct ReturnTypeNotationEqualityBound {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

-5
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
669669

670670
if !errors.is_empty() {
671671
self.adjust_fulfillment_errors_for_expr_obligation(&mut errors);
672-
let errors_causecode = errors
673-
.iter()
674-
.map(|e| (e.obligation.cause.span, e.root_obligation.cause.code().clone()))
675-
.collect::<Vec<_>>();
676672
self.err_ctxt().report_fulfillment_errors(errors);
677-
self.collect_unused_stmts_for_coerce_return_ty(errors_causecode);
678673
}
679674
}
680675

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-59
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use std::{fmt, iter, mem};
33
use itertools::Itertools;
44
use rustc_data_structures::fx::FxIndexSet;
55
use rustc_errors::codes::*;
6-
use rustc_errors::{
7-
Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey, a_or_an, listify, pluralize,
8-
};
6+
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, MultiSpan, a_or_an, listify, pluralize};
97
use rustc_hir::def::{CtorOf, DefKind, Res};
108
use rustc_hir::def_id::DefId;
119
use rustc_hir::intravisit::Visitor;
@@ -2193,62 +2191,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21932191
}
21942192
}
21952193

2196-
pub(super) fn collect_unused_stmts_for_coerce_return_ty(
2197-
&self,
2198-
errors_causecode: Vec<(Span, ObligationCauseCode<'tcx>)>,
2199-
) {
2200-
for (span, code) in errors_causecode {
2201-
self.dcx().try_steal_modify_and_emit_err(span, StashKey::MaybeForgetReturn, |err| {
2202-
if let Some(fn_sig) = self.body_fn_sig()
2203-
&& let ObligationCauseCode::WhereClauseInExpr(_, _, binding_hir_id, ..) = code
2204-
&& !fn_sig.output().is_unit()
2205-
{
2206-
let mut block_num = 0;
2207-
let mut found_semi = false;
2208-
for (hir_id, node) in self.tcx.hir_parent_iter(binding_hir_id) {
2209-
// Don't proceed into parent bodies
2210-
if hir_id.owner != binding_hir_id.owner {
2211-
break;
2212-
}
2213-
match node {
2214-
hir::Node::Stmt(stmt) => {
2215-
if let hir::StmtKind::Semi(expr) = stmt.kind {
2216-
let expr_ty = self.typeck_results.borrow().expr_ty(expr);
2217-
let return_ty = fn_sig.output();
2218-
if !matches!(expr.kind, hir::ExprKind::Ret(..))
2219-
&& self.may_coerce(expr_ty, return_ty)
2220-
{
2221-
found_semi = true;
2222-
}
2223-
}
2224-
}
2225-
hir::Node::Block(_block) => {
2226-
if found_semi {
2227-
block_num += 1;
2228-
}
2229-
}
2230-
hir::Node::Item(item) => {
2231-
if let hir::ItemKind::Fn { .. } = item.kind {
2232-
break;
2233-
}
2234-
}
2235-
_ => {}
2236-
}
2237-
}
2238-
if block_num > 1 && found_semi {
2239-
err.span_suggestion_verbose(
2240-
// use the span of the *whole* expr
2241-
self.tcx.hir().span(binding_hir_id).shrink_to_lo(),
2242-
"you might have meant to return this to infer its type parameters",
2243-
"return ",
2244-
Applicability::MaybeIncorrect,
2245-
);
2246-
}
2247-
}
2248-
});
2249-
}
2250-
}
2251-
22522194
/// Given a vector of fulfillment errors, try to adjust the spans of the
22532195
/// errors to more accurately point at the cause of the failure.
22542196
///

compiler/rustc_resolve/src/late.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct IsNeverPattern;
7878
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
7979
enum AnonConstKind {
8080
EnumDiscriminant,
81+
FieldDefaultValue,
8182
InlineConst,
8283
ConstArg(IsRepeatExpr),
8384
}
@@ -1406,7 +1407,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
14061407
visit_opt!(self, visit_ident, ident);
14071408
try_visit!(self.visit_ty(ty));
14081409
if let Some(v) = &default {
1409-
self.resolve_anon_const(v, AnonConstKind::ConstArg(IsRepeatExpr::No));
1410+
self.resolve_anon_const(v, AnonConstKind::FieldDefaultValue);
14101411
}
14111412
}
14121413
}
@@ -4658,6 +4659,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
46584659
AnonConstKind::EnumDiscriminant => {
46594660
ConstantHasGenerics::No(NoConstantGenericsReason::IsEnumDiscriminant)
46604661
}
4662+
AnonConstKind::FieldDefaultValue => ConstantHasGenerics::Yes,
46614663
AnonConstKind::InlineConst => ConstantHasGenerics::Yes,
46624664
AnonConstKind::ConstArg(_) => {
46634665
if self.r.tcx.features().generic_const_exprs() || is_trivial_const_arg {

compiler/rustc_session/src/config.rs

-8
Original file line numberDiff line numberDiff line change
@@ -2887,14 +2887,6 @@ impl PpMode {
28872887
| StableMir => true,
28882888
}
28892889
}
2890-
pub fn needs_hir(&self) -> bool {
2891-
use PpMode::*;
2892-
match *self {
2893-
Source(_) | AstTree | AstTreeExpanded => false,
2894-
2895-
Hir(_) | HirTree | ThirTree | ThirFlat | Mir | MirCFG | StableMir => true,
2896-
}
2897-
}
28982890

28992891
pub fn needs_analysis(&self) -> bool {
29002892
use PpMode::*;

compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::ops::ControlFlow;
22

3-
use rustc_errors::{
4-
Applicability, Diag, E0283, E0284, E0790, MultiSpan, StashKey, struct_span_code_err,
5-
};
3+
use rustc_errors::{Applicability, Diag, E0283, E0284, E0790, MultiSpan, struct_span_code_err};
64
use rustc_hir as hir;
75
use rustc_hir::LangItem;
86
use rustc_hir::def::{DefKind, Res};
@@ -197,7 +195,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
197195
// be ignoring the fact that we don't KNOW the type works
198196
// out. Though even that would probably be harmless, given that
199197
// we're only talking about builtin traits, which are known to be
200-
// inhabited. We used to check for `self.tcx.sess.has_errors()` to
198+
// inhabited. We used to check for `self.tainted_by_errors()` to
201199
// avoid inundating the user with unnecessary errors, but we now
202200
// check upstream for type errors and don't add the obligations to
203201
// begin with in those cases.
@@ -211,7 +209,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
211209
TypeAnnotationNeeded::E0282,
212210
false,
213211
);
214-
return err.stash(span, StashKey::MaybeForgetReturn).unwrap();
212+
return err.emit();
215213
}
216214
Some(e) => return e,
217215
}

library/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ dependencies = [
151151

152152
[[package]]
153153
name = "libc"
154-
version = "0.2.169"
154+
version = "0.2.170"
155155
source = "registry+https://github.com/rust-lang/crates.io-index"
156-
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
156+
checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828"
157157
dependencies = [
158158
"rustc-std-workspace-core",
159159
]

library/core/src/bstr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ impl fmt::Display for ByteStr {
151151
};
152152
let nchars: usize = self
153153
.utf8_chunks()
154-
.map(|chunk| chunk.valid().len() + if chunk.invalid().is_empty() { 0 } else { 1 })
154+
.map(|chunk| {
155+
chunk.valid().chars().count() + if chunk.invalid().is_empty() { 0 } else { 1 }
156+
})
155157
.sum();
156158
let padding = f.width().unwrap_or(0).saturating_sub(nchars);
157159
let fill = f.fill();

library/core/src/marker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ impl Copy for ! {}
453453
#[stable(feature = "rust1", since = "1.0.0")]
454454
impl<T: ?Sized> Copy for &T {}
455455

456-
/// Marker trait for the types that are allowed in union fields, unsafe fields,
457-
/// and unsafe binder types.
456+
/// Marker trait for the types that are allowed in union fields and unsafe
457+
/// binder types.
458458
///
459459
/// Implemented for:
460460
/// * `&T`, `&mut T` for all `T`,

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ miniz_oxide = { version = "0.8.0", optional = true, default-features = false }
3535
addr2line = { version = "0.24.0", optional = true, default-features = false }
3636

3737
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
38-
libc = { version = "0.2.169", default-features = false, features = [
38+
libc = { version = "0.2.170", default-features = false, features = [
3939
'rustc-dep-of-std',
4040
], public = true }
4141

library/std/src/fs.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2857,9 +2857,11 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
28572857
///
28582858
/// See [`fs::remove_file`] and [`fs::remove_dir`].
28592859
///
2860-
/// `remove_dir_all` will fail if `remove_dir` or `remove_file` fail on any constituent paths, including the root `path`.
2861-
/// As a result, the directory you are deleting must exist, meaning that this function is not idempotent.
2862-
/// Additionally, `remove_dir_all` will also fail if the `path` is not a directory.
2860+
/// [`remove_dir_all`] will fail if [`remove_dir`] or [`remove_file`] fail on *any* constituent
2861+
/// paths, *including* the root `path`. Consequently,
2862+
///
2863+
/// - The directory you are deleting *must* exist, meaning that this function is *not idempotent*.
2864+
/// - [`remove_dir_all`] will fail if the `path` is *not* a directory.
28632865
///
28642866
/// Consider ignoring the error if validating the removal is not required for your use case.
28652867
///

0 commit comments

Comments
 (0)