Skip to content

Commit a584f94

Browse files
committed
Auto merge of #137212 - GuillaumeGomez:rollup-fc4rqfu, r=GuillaumeGomez
Rollup of 11 pull requests Successful merges: - #127793 (Added project-specific Zed IDE settings) - #134995 (Stabilize const_slice_flatten) - #135767 (Future incompatibility warning `unsupported_fn_ptr_calling_conventions`: Also warn in dependencies) - #136599 (librustdoc: more usages of `Joined::joined`) - #136750 (Make ub_check message clear that it's not an assert) - #137000 (Deeply normalize item bounds in new solver) - #137126 (fix docs for inherent str constructors) - #137151 (Install more signal stack trace handlers) - #137161 (Pattern Migration 2024: fix incorrect messages/suggestions when errors arise in macro expansions) - #137167 (tests: Also gate `f16::erfc()` doctest with `reliable_f16_math` cfg) - #137177 (Update `minifier-rs` version to `0.3.5`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3b022d8 + 2f3a29a commit a584f94

File tree

43 files changed

+1044
-211
lines changed

Some content is hidden

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

43 files changed

+1044
-211
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2303,9 +2303,9 @@ dependencies = [
23032303

23042304
[[package]]
23052305
name = "minifier"
2306-
version = "0.3.4"
2306+
version = "0.3.5"
23072307
source = "registry+https://github.com/rust-lang/crates.io-index"
2308-
checksum = "1cf47565b1430f5fe6c81d3afcb4b835271348d7eb35294a4d592e38dd09ea22"
2308+
checksum = "9bfdc64e2f805f3d12965f10522000bae36e88d2cfea44112331f467d4f4bf68"
23092309

23102310
[[package]]
23112311
name = "minimal-lexical"

compiler/rustc_driver_impl/src/signal_handler.rs

+39-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ use std::{fmt, mem, ptr, slice};
66

77
use rustc_interface::util::{DEFAULT_STACK_SIZE, STACK_SIZE};
88

9+
/// Signals that represent that we have a bug, and our prompt termination has
10+
/// been ordered.
11+
#[rustfmt::skip]
12+
const KILL_SIGNALS: [(libc::c_int, &str); 3] = [
13+
(libc::SIGILL, "SIGILL"),
14+
(libc::SIGBUS, "SIGBUS"),
15+
(libc::SIGSEGV, "SIGSEGV")
16+
];
17+
918
unsafe extern "C" {
1019
fn backtrace_symbols_fd(buffer: *const *mut libc::c_void, size: libc::c_int, fd: libc::c_int);
1120
}
@@ -39,8 +48,19 @@ macro raw_errln($tokens:tt) {
3948
/// # Safety
4049
///
4150
/// Caller must ensure that this function is not re-entered.
42-
unsafe extern "C" fn print_stack_trace(_: libc::c_int) {
51+
unsafe extern "C" fn print_stack_trace(signum: libc::c_int) {
4352
const MAX_FRAMES: usize = 256;
53+
54+
let signame = {
55+
let mut signame = "<unknown>";
56+
for sig in KILL_SIGNALS {
57+
if sig.0 == signum {
58+
signame = sig.1;
59+
}
60+
}
61+
signame
62+
};
63+
4464
let stack = unsafe {
4565
// Reserve data segment so we don't have to malloc in a signal handler, which might fail
4666
// in incredibly undesirable and unexpected ways due to e.g. the allocator deadlocking
@@ -54,7 +74,8 @@ unsafe extern "C" fn print_stack_trace(_: libc::c_int) {
5474
};
5575

5676
// Just a stack trace is cryptic. Explain what we're doing.
57-
raw_errln!("error: rustc interrupted by SIGSEGV, printing backtrace\n");
77+
raw_errln!("error: rustc interrupted by {signame}, printing backtrace\n");
78+
5879
let mut written = 1;
5980
let mut consumed = 0;
6081
// Begin elaborating return addrs into symbols and writing them directly to stderr
@@ -94,7 +115,7 @@ unsafe extern "C" fn print_stack_trace(_: libc::c_int) {
94115
written += rem.len() + 1;
95116

96117
let random_depth = || 8 * 16; // chosen by random diceroll (2d20)
97-
if cyclic || stack.len() > random_depth() {
118+
if (cyclic || stack.len() > random_depth()) && signum == libc::SIGSEGV {
98119
// technically speculation, but assert it with confidence anyway.
99120
// rustc only arrived in this signal handler because bad things happened
100121
// and this message is for explaining it's not the programmer's fault
@@ -106,17 +127,22 @@ unsafe extern "C" fn print_stack_trace(_: libc::c_int) {
106127
written += 1;
107128
}
108129
raw_errln!("note: we would appreciate a report at https://github.com/rust-lang/rust");
109-
// get the current stack size WITHOUT blocking and double it
110-
let new_size = STACK_SIZE.get().copied().unwrap_or(DEFAULT_STACK_SIZE) * 2;
111-
raw_errln!("help: you can increase rustc's stack size by setting RUST_MIN_STACK={new_size}");
112-
written += 2;
130+
written += 1;
131+
if signum == libc::SIGSEGV {
132+
// get the current stack size WITHOUT blocking and double it
133+
let new_size = STACK_SIZE.get().copied().unwrap_or(DEFAULT_STACK_SIZE) * 2;
134+
raw_errln!(
135+
"help: you can increase rustc's stack size by setting RUST_MIN_STACK={new_size}"
136+
);
137+
written += 1;
138+
}
113139
if written > 24 {
114-
// We probably just scrolled the earlier "we got SIGSEGV" message off the terminal
115-
raw_errln!("note: backtrace dumped due to SIGSEGV! resuming signal");
140+
// We probably just scrolled the earlier "interrupted by {signame}" message off the terminal
141+
raw_errln!("note: backtrace dumped due to {signame}! resuming signal");
116142
};
117143
}
118144

119-
/// When SIGSEGV is delivered to the process, print a stack trace and then exit.
145+
/// When one of the KILL signals is delivered to the process, print a stack trace and then exit.
120146
pub(super) fn install() {
121147
unsafe {
122148
let alt_stack_size: usize = min_sigstack_size() + 64 * 1024;
@@ -129,7 +155,9 @@ pub(super) fn install() {
129155
sa.sa_sigaction = print_stack_trace as libc::sighandler_t;
130156
sa.sa_flags = libc::SA_NODEFER | libc::SA_RESETHAND | libc::SA_ONSTACK;
131157
libc::sigemptyset(&mut sa.sa_mask);
132-
libc::sigaction(libc::SIGSEGV, &sa, ptr::null_mut());
158+
for (signum, _signame) in KILL_SIGNALS {
159+
libc::sigaction(signum, &sa, ptr::null_mut());
160+
}
133161
}
134162
}
135163

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+22-42
Original file line numberDiff line numberDiff line change
@@ -2104,18 +2104,21 @@ pub(super) fn check_type_bounds<'tcx>(
21042104
ObligationCause::new(impl_ty_span, impl_ty_def_id, code)
21052105
};
21062106

2107-
let mut obligations: Vec<_> = tcx
2108-
.explicit_item_bounds(trait_ty.def_id)
2109-
.iter_instantiated_copied(tcx, rebased_args)
2110-
.map(|(concrete_ty_bound, span)| {
2111-
debug!(?concrete_ty_bound);
2112-
traits::Obligation::new(tcx, mk_cause(span), param_env, concrete_ty_bound)
2113-
})
2114-
.collect();
2107+
let mut obligations: Vec<_> = util::elaborate(
2108+
tcx,
2109+
tcx.explicit_item_bounds(trait_ty.def_id).iter_instantiated_copied(tcx, rebased_args).map(
2110+
|(concrete_ty_bound, span)| {
2111+
debug!(?concrete_ty_bound);
2112+
traits::Obligation::new(tcx, mk_cause(span), param_env, concrete_ty_bound)
2113+
},
2114+
),
2115+
)
2116+
.collect();
21152117

21162118
// Only in a const implementation do we need to check that the `~const` item bounds hold.
21172119
if tcx.is_conditionally_const(impl_ty_def_id) {
2118-
obligations.extend(
2120+
obligations.extend(util::elaborate(
2121+
tcx,
21192122
tcx.explicit_implied_const_bounds(trait_ty.def_id)
21202123
.iter_instantiated_copied(tcx, rebased_args)
21212124
.map(|(c, span)| {
@@ -2126,34 +2129,27 @@ pub(super) fn check_type_bounds<'tcx>(
21262129
c.to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
21272130
)
21282131
}),
2129-
);
2132+
));
21302133
}
21312134
debug!(item_bounds=?obligations);
21322135

21332136
// Normalize predicates with the assumption that the GAT may always normalize
21342137
// to its definition type. This should be the param-env we use to *prove* the
21352138
// predicate too, but we don't do that because of performance issues.
21362139
// See <https://github.com/rust-lang/rust/pull/117542#issue-1976337685>.
2137-
let trait_projection_ty = Ty::new_projection_from_args(tcx, trait_ty.def_id, rebased_args);
2138-
let impl_identity_ty = tcx.type_of(impl_ty.def_id).instantiate_identity();
21392140
let normalize_param_env = param_env_with_gat_bounds(tcx, impl_ty, impl_trait_ref);
2140-
for mut obligation in util::elaborate(tcx, obligations) {
2141-
let normalized_predicate = if infcx.next_trait_solver() {
2142-
obligation.predicate.fold_with(&mut ReplaceTy {
2143-
tcx,
2144-
from: trait_projection_ty,
2145-
to: impl_identity_ty,
2146-
})
2147-
} else {
2148-
ocx.normalize(&normalize_cause, normalize_param_env, obligation.predicate)
2149-
};
2150-
debug!(?normalized_predicate);
2151-
obligation.predicate = normalized_predicate;
2152-
2153-
ocx.register_obligation(obligation);
2141+
for obligation in &mut obligations {
2142+
match ocx.deeply_normalize(&normalize_cause, normalize_param_env, obligation.predicate) {
2143+
Ok(pred) => obligation.predicate = pred,
2144+
Err(e) => {
2145+
return Err(infcx.err_ctxt().report_fulfillment_errors(e));
2146+
}
2147+
}
21542148
}
2149+
21552150
// Check that all obligations are satisfied by the implementation's
21562151
// version.
2152+
ocx.register_obligations(obligations);
21572153
let errors = ocx.select_all_or_error();
21582154
if !errors.is_empty() {
21592155
let reported = infcx.err_ctxt().report_fulfillment_errors(errors);
@@ -2165,22 +2161,6 @@ pub(super) fn check_type_bounds<'tcx>(
21652161
ocx.resolve_regions_and_report_errors(impl_ty_def_id, param_env, assumed_wf_types)
21662162
}
21672163

2168-
struct ReplaceTy<'tcx> {
2169-
tcx: TyCtxt<'tcx>,
2170-
from: Ty<'tcx>,
2171-
to: Ty<'tcx>,
2172-
}
2173-
2174-
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceTy<'tcx> {
2175-
fn cx(&self) -> TyCtxt<'tcx> {
2176-
self.tcx
2177-
}
2178-
2179-
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
2180-
if self.from == ty { self.to } else { ty.super_fold_with(self) }
2181-
}
2182-
}
2183-
21842164
/// Install projection predicates that allow GATs to project to their own
21852165
/// definition types. This is not allowed in general in cases of default
21862166
/// associated types in trait definitions, or when specialization is involved,

compiler/rustc_hir_typeck/src/pat.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -2806,31 +2806,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28062806
&& !self.tcx.features().ref_pat_eat_one_layer_2024_structural(),
28072807
});
28082808

2809+
let pat_kind = if let PatKind::Binding(user_bind_annot, _, _, _) = subpat.kind {
2810+
info.bad_modifiers = true;
2811+
// If the user-provided binding modifier doesn't match the default binding mode, we'll
2812+
// need to suggest reference patterns, which can affect other bindings.
2813+
// For simplicity, we opt to suggest making the pattern fully explicit.
2814+
info.suggest_eliding_modes &=
2815+
user_bind_annot == BindingMode(ByRef::Yes(def_br_mutbl), Mutability::Not);
2816+
"binding modifier"
2817+
} else {
2818+
info.bad_ref_pats = true;
2819+
// For simplicity, we don't try to suggest eliding reference patterns. Thus, we'll
2820+
// suggest adding them instead, which can affect the types assigned to bindings.
2821+
// As such, we opt to suggest making the pattern fully explicit.
2822+
info.suggest_eliding_modes = false;
2823+
"reference pattern"
2824+
};
28092825
// Only provide a detailed label if the problematic subpattern isn't from an expansion.
28102826
// In the case that it's from a macro, we'll add a more detailed note in the emitter.
28112827
let from_expansion = subpat.span.from_expansion();
28122828
let primary_label = if from_expansion {
2829+
// We can't suggest eliding modifiers within expansions.
2830+
info.suggest_eliding_modes = false;
28132831
// NB: This wording assumes the only expansions that can produce problematic reference
28142832
// patterns and bindings are macros. If a desugaring or AST pass is added that can do
28152833
// so, we may want to inspect the span's source callee or macro backtrace.
28162834
"occurs within macro expansion".to_owned()
28172835
} else {
2818-
let pat_kind = if let PatKind::Binding(user_bind_annot, _, _, _) = subpat.kind {
2819-
info.bad_modifiers |= true;
2820-
// If the user-provided binding modifier doesn't match the default binding mode, we'll
2821-
// need to suggest reference patterns, which can affect other bindings.
2822-
// For simplicity, we opt to suggest making the pattern fully explicit.
2823-
info.suggest_eliding_modes &=
2824-
user_bind_annot == BindingMode(ByRef::Yes(def_br_mutbl), Mutability::Not);
2825-
"binding modifier"
2826-
} else {
2827-
info.bad_ref_pats |= true;
2828-
// For simplicity, we don't try to suggest eliding reference patterns. Thus, we'll
2829-
// suggest adding them instead, which can affect the types assigned to bindings.
2830-
// As such, we opt to suggest making the pattern fully explicit.
2831-
info.suggest_eliding_modes = false;
2832-
"reference pattern"
2833-
};
28342836
let dbm_str = match def_br_mutbl {
28352837
Mutability::Not => "ref",
28362838
Mutability::Mut => "ref mut",

compiler/rustc_lint_defs/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3782,7 +3782,7 @@ declare_lint! {
37823782
Warn,
37833783
"use of unsupported calling convention for function pointer",
37843784
@future_incompatible = FutureIncompatibleInfo {
3785-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
3785+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
37863786
reference: "issue #130260 <https://github.com/rust-lang/rust/issues/130260>",
37873787
};
37883788
}

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

+29-8
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ where
791791
return Ok(self.make_ambiguous_response_no_constraints(MaybeCause::Ambiguity));
792792
};
793793

794-
let responses: Vec<_> = match proven_via {
794+
match proven_via {
795795
// Even when a trait bound has been proven using a where-bound, we
796796
// still need to consider alias-bounds for normalization, see
797797
// tests/ui/next-solver/alias-bound-shadowed-by-env.rs.
@@ -800,7 +800,7 @@ where
800800
// constness checking. Doing so is *at least theoretically* breaking,
801801
// see github.com/rust-lang/rust/issues/133044#issuecomment-2500709754
802802
TraitGoalProvenVia::ParamEnv | TraitGoalProvenVia::AliasBound => {
803-
let mut candidates_from_env: Vec<_> = candidates
803+
let mut candidates_from_env_and_bounds: Vec<_> = candidates
804804
.iter()
805805
.filter(|c| {
806806
matches!(
@@ -813,16 +813,37 @@ where
813813

814814
// If the trait goal has been proven by using the environment, we want to treat
815815
// aliases as rigid if there are no applicable projection bounds in the environment.
816-
if candidates_from_env.is_empty() {
816+
if candidates_from_env_and_bounds.is_empty() {
817817
if let Ok(response) = inject_normalize_to_rigid_candidate(self) {
818-
candidates_from_env.push(response);
818+
candidates_from_env_and_bounds.push(response);
819819
}
820820
}
821-
candidates_from_env
821+
822+
if let Some(response) = self.try_merge_responses(&candidates_from_env_and_bounds) {
823+
Ok(response)
824+
} else {
825+
self.flounder(&candidates_from_env_and_bounds)
826+
}
822827
}
823-
TraitGoalProvenVia::Misc => candidates.iter().map(|c| c.result).collect(),
824-
};
828+
TraitGoalProvenVia::Misc => {
829+
// Prefer "orphaned" param-env normalization predicates, which are used
830+
// (for example, and ideally only) when proving item bounds for an impl.
831+
let candidates_from_env: Vec<_> = candidates
832+
.iter()
833+
.filter(|c| matches!(c.source, CandidateSource::ParamEnv(_)))
834+
.map(|c| c.result)
835+
.collect();
836+
if let Some(response) = self.try_merge_responses(&candidates_from_env) {
837+
return Ok(response);
838+
}
825839

826-
self.try_merge_responses(&responses).map_or_else(|| self.flounder(&responses), Ok)
840+
let responses: Vec<_> = candidates.iter().map(|c| c.result).collect();
841+
if let Some(response) = self.try_merge_responses(&responses) {
842+
Ok(response)
843+
} else {
844+
self.flounder(&responses)
845+
}
846+
}
847+
}
827848
}
828849
}

library/core/src/slice/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4796,7 +4796,7 @@ impl<T, const N: usize> [[T; N]] {
47964796
/// assert!(empty_slice_of_arrays.as_flattened().is_empty());
47974797
/// ```
47984798
#[stable(feature = "slice_flatten", since = "1.80.0")]
4799-
#[rustc_const_unstable(feature = "const_slice_flatten", issue = "95629")]
4799+
#[rustc_const_stable(feature = "const_slice_flatten", since = "CURRENT_RUSTC_VERSION")]
48004800
pub const fn as_flattened(&self) -> &[T] {
48014801
let len = if T::IS_ZST {
48024802
self.len().checked_mul(N).expect("slice len overflow")
@@ -4833,7 +4833,7 @@ impl<T, const N: usize> [[T; N]] {
48334833
/// assert_eq!(array, [[6, 7, 8], [9, 10, 11], [12, 13, 14]]);
48344834
/// ```
48354835
#[stable(feature = "slice_flatten", since = "1.80.0")]
4836-
#[rustc_const_unstable(feature = "const_slice_flatten", issue = "95629")]
4836+
#[rustc_const_stable(feature = "const_slice_flatten", since = "CURRENT_RUSTC_VERSION")]
48374837
pub const fn as_flattened_mut(&mut self) -> &mut [T] {
48384838
let len = if T::IS_ZST {
48394839
self.len().checked_mul(N).expect("slice len overflow")

0 commit comments

Comments
 (0)