Skip to content

Commit c59d3e3

Browse files
committed
Auto merge of #125536 - workingjubilee:rollup-jpdt4t3, r=workingjubilee
Rollup of 7 pull requests Successful merges: - #125271 (use posix_memalign on almost all Unix targets) - #125433 (A small diagnostic improvement for dropping_copy_types) - #125498 (Stop using the avx512er and avx512pf x86 target features) - #125510 (remove proof tree formatting, make em shallow) - #125513 (Don't eagerly monomorphize drop for types that are impossible to instantiate) - #125514 (Structurally resolve before `builtin_index` in EUV) - #125527 (Add manual Sync impl for ReentrantLockGuard) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 21e6de7 + 8743112 commit c59d3e3

40 files changed

+409
-534
lines changed

Diff for: compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,11 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
17411741
}
17421742

17431743
PatKind::Slice(before, ref slice, after) => {
1744-
let Some(element_ty) = place_with_id.place.ty().builtin_index() else {
1744+
let Some(element_ty) = self
1745+
.cx
1746+
.try_structurally_resolve_type(pat.span, place_with_id.place.ty())
1747+
.builtin_index()
1748+
else {
17451749
debug!("explicit index of non-indexable type {:?}", place_with_id);
17461750
return Err(self
17471751
.cx

Diff for: compiler/rustc_interface/src/tests.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -799,10 +799,7 @@ fn test_unstable_options_tracking_hash() {
799799
tracked!(mir_opt_level, Some(4));
800800
tracked!(move_size_limit, Some(4096));
801801
tracked!(mutable_noalias, false);
802-
tracked!(
803-
next_solver,
804-
Some(NextSolverConfig { coherence: true, globally: false, dump_tree: Default::default() })
805-
);
802+
tracked!(next_solver, Some(NextSolverConfig { coherence: true, globally: false }));
806803
tracked!(no_generate_arange_section, true);
807804
tracked!(no_jump_tables, true);
808805
tracked!(no_link, true);

Diff for: compiler/rustc_lint/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ lint_drop_trait_constraints =
233233
lint_dropping_copy_types = calls to `std::mem::drop` with a value that implements `Copy` does nothing
234234
.label = argument has type `{$arg_ty}`
235235
.note = use `let _ = ...` to ignore the expression or result
236+
.suggestion = use `let _ = ...` to ignore the expression or result
236237
237238
lint_dropping_references = calls to `std::mem::drop` with a reference instead of an owned value does nothing
238239
.label = argument has type `{$arg_ty}`

Diff for: compiler/rustc_lint/src/drop_forget_useless.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use rustc_hir::{Arm, Expr, ExprKind, Node};
1+
use rustc_hir::{Arm, Expr, ExprKind, Node, StmtKind};
22
use rustc_middle::ty;
33
use rustc_session::{declare_lint, declare_lint_pass};
44
use rustc_span::sym;
55

66
use crate::{
77
lints::{
8-
DropCopyDiag, DropRefDiag, ForgetCopyDiag, ForgetRefDiag, UndroppedManuallyDropsDiag,
9-
UndroppedManuallyDropsSuggestion,
8+
DropCopyDiag, DropCopySuggestion, DropRefDiag, ForgetCopyDiag, ForgetRefDiag,
9+
UndroppedManuallyDropsDiag, UndroppedManuallyDropsSuggestion,
1010
},
1111
LateContext, LateLintPass, LintContext,
1212
};
@@ -164,10 +164,23 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
164164
);
165165
}
166166
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => {
167+
let sugg = if let Some((_, node)) = cx.tcx.hir().parent_iter(expr.hir_id).nth(0)
168+
&& let Node::Stmt(stmt) = node
169+
&& let StmtKind::Semi(e) = stmt.kind
170+
&& e.hir_id == expr.hir_id
171+
{
172+
DropCopySuggestion::Suggestion {
173+
start_span: expr.span.shrink_to_lo().until(arg.span),
174+
end_span: arg.span.shrink_to_hi().until(expr.span.shrink_to_hi()),
175+
}
176+
} else {
177+
DropCopySuggestion::Note
178+
};
179+
167180
cx.emit_span_lint(
168181
DROPPING_COPY_TYPES,
169182
expr.span,
170-
DropCopyDiag { arg_ty, label: arg.span },
183+
DropCopyDiag { arg_ty, label: arg.span, sugg },
171184
);
172185
}
173186
sym::mem_forget if is_copy => {

Diff for: compiler/rustc_lint/src/lints.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,25 @@ pub struct DropRefDiag<'a> {
677677

678678
#[derive(LintDiagnostic)]
679679
#[diag(lint_dropping_copy_types)]
680-
#[note]
681680
pub struct DropCopyDiag<'a> {
682681
pub arg_ty: Ty<'a>,
683682
#[label]
684683
pub label: Span,
684+
#[subdiagnostic]
685+
pub sugg: DropCopySuggestion,
686+
}
687+
688+
#[derive(Subdiagnostic)]
689+
pub enum DropCopySuggestion {
690+
#[note(lint_note)]
691+
Note,
692+
#[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
693+
Suggestion {
694+
#[suggestion_part(code = "let _ = ")]
695+
start_span: Span,
696+
#[suggestion_part(code = "")]
697+
end_span: Span,
698+
},
685699
}
686700

687701
#[derive(LintDiagnostic)]

Diff for: compiler/rustc_middle/src/arena.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ macro_rules! arena_types {
6161
[] dtorck_constraint: rustc_middle::traits::query::DropckConstraint<'tcx>,
6262
[] candidate_step: rustc_middle::traits::query::CandidateStep<'tcx>,
6363
[] autoderef_bad_ty: rustc_middle::traits::query::MethodAutoderefBadTy<'tcx>,
64-
[] canonical_goal_evaluation: rustc_next_trait_solver::solve::inspect::GoalEvaluationStep<rustc_middle::ty::TyCtxt<'tcx>>,
64+
[] canonical_goal_evaluation:
65+
rustc_next_trait_solver::solve::inspect::CanonicalGoalEvaluationStep<
66+
rustc_middle::ty::TyCtxt<'tcx>
67+
>,
6568
[] query_region_constraints: rustc_middle::infer::canonical::QueryRegionConstraints<'tcx>,
6669
[] type_op_subtype:
6770
rustc_middle::infer::canonical::Canonical<'tcx,

Diff for: compiler/rustc_middle/src/traits/solve/cache.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct EvaluationCache<'tcx> {
1717
#[derive(Debug, PartialEq, Eq)]
1818
pub struct CacheData<'tcx> {
1919
pub result: QueryResult<'tcx>,
20-
pub proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<TyCtxt<'tcx>>]>,
20+
pub proof_tree: Option<&'tcx inspect::CanonicalGoalEvaluationStep<TyCtxt<'tcx>>>,
2121
pub additional_depth: usize,
2222
pub encountered_overflow: bool,
2323
}
@@ -28,7 +28,7 @@ impl<'tcx> EvaluationCache<'tcx> {
2828
&self,
2929
tcx: TyCtxt<'tcx>,
3030
key: CanonicalInput<'tcx>,
31-
proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<TyCtxt<'tcx>>]>,
31+
proof_tree: Option<&'tcx inspect::CanonicalGoalEvaluationStep<TyCtxt<'tcx>>>,
3232
additional_depth: usize,
3333
encountered_overflow: bool,
3434
cycle_participants: FxHashSet<CanonicalInput<'tcx>>,
@@ -107,7 +107,7 @@ struct Success<'tcx> {
107107
#[derive(Clone, Copy)]
108108
pub struct QueryData<'tcx> {
109109
pub result: QueryResult<'tcx>,
110-
pub proof_tree: Option<&'tcx [inspect::GoalEvaluationStep<TyCtxt<'tcx>>]>,
110+
pub proof_tree: Option<&'tcx inspect::CanonicalGoalEvaluationStep<TyCtxt<'tcx>>>,
111111
}
112112

113113
/// The cache entry for a goal `CanonicalInput`.

Diff for: compiler/rustc_middle/src/ty/context.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
103103
type PredefinedOpaques = solve::PredefinedOpaques<'tcx>;
104104
type DefiningOpaqueTypes = &'tcx ty::List<LocalDefId>;
105105
type ExternalConstraints = ExternalConstraints<'tcx>;
106-
type GoalEvaluationSteps = &'tcx [solve::inspect::GoalEvaluationStep<TyCtxt<'tcx>>];
106+
type CanonicalGoalEvaluationStepRef =
107+
&'tcx solve::inspect::CanonicalGoalEvaluationStep<TyCtxt<'tcx>>;
107108

108109
type Ty = Ty<'tcx>;
109110
type Tys = &'tcx List<Ty<'tcx>>;

Diff for: compiler/rustc_mir_build/src/build/expr/as_place.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::build::expr::category::Category;
44
use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};
55
use crate::build::{BlockAnd, BlockAndExtension, Builder, Capture, CaptureMap};
66
use rustc_hir::def_id::LocalDefId;
7-
use rustc_middle::bug;
87
use rustc_middle::hir::place::Projection as HirProjection;
98
use rustc_middle::hir::place::ProjectionKind as HirProjectionKind;
109
use rustc_middle::middle::region;
@@ -13,6 +12,7 @@ use rustc_middle::mir::*;
1312
use rustc_middle::thir::*;
1413
use rustc_middle::ty::AdtDef;
1514
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty, Variance};
15+
use rustc_middle::{bug, span_bug};
1616
use rustc_span::Span;
1717
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
1818
use tracing::{debug, instrument, trace};
@@ -252,7 +252,18 @@ fn strip_prefix<'a, 'tcx>(
252252

253253
impl<'tcx> PlaceBuilder<'tcx> {
254254
pub(in crate::build) fn to_place(&self, cx: &Builder<'_, 'tcx>) -> Place<'tcx> {
255-
self.try_to_place(cx).unwrap()
255+
self.try_to_place(cx).unwrap_or_else(|| match self.base {
256+
PlaceBase::Local(local) => span_bug!(
257+
cx.local_decls[local].source_info.span,
258+
"could not resolve local: {local:#?} + {:?}",
259+
self.projection
260+
),
261+
PlaceBase::Upvar { var_hir_id, closure_def_id: _ } => span_bug!(
262+
cx.tcx.hir().span(var_hir_id.0),
263+
"could not resolve upvar: {var_hir_id:?} + {:?}",
264+
self.projection
265+
),
266+
})
256267
}
257268

258269
/// Creates a `Place` or returns `None` if an upvar cannot be resolved

Diff for: compiler/rustc_monomorphize/src/collector.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,15 @@ impl<'v> RootCollector<'_, 'v> {
14341434
{
14351435
debug!("RootCollector: ADT drop-glue for `{id:?}`",);
14361436

1437+
// This type is impossible to instantiate, so we should not try to
1438+
// generate a `drop_in_place` instance for it.
1439+
if self.tcx.instantiate_and_check_impossible_predicates((
1440+
id.owner_id.to_def_id(),
1441+
ty::List::empty(),
1442+
)) {
1443+
return;
1444+
}
1445+
14371446
let ty = self.tcx.type_of(id.owner_id.to_def_id()).no_bound_vars().unwrap();
14381447
visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output);
14391448
}

Diff for: compiler/rustc_session/src/config.rs

-10
Original file line numberDiff line numberDiff line change
@@ -796,16 +796,6 @@ pub struct NextSolverConfig {
796796
/// Whether the new trait solver should be enabled everywhere.
797797
/// This is only `true` if `coherence` is also enabled.
798798
pub globally: bool,
799-
/// Whether to dump proof trees after computing a proof tree.
800-
pub dump_tree: DumpSolverProofTree,
801-
}
802-
803-
#[derive(Default, Debug, Copy, Clone, Hash, PartialEq, Eq)]
804-
pub enum DumpSolverProofTree {
805-
Always,
806-
OnError,
807-
#[default]
808-
Never,
809799
}
810800

811801
#[derive(Clone)]

Diff for: compiler/rustc_session/src/options.rs

+4-22
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,8 @@ mod desc {
399399
pub const parse_instrument_xray: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), or a comma separated list of settings: `always` or `never` (mutually exclusive), `ignore-loops`, `instruction-threshold=N`, `skip-entry`, `skip-exit`";
400400
pub const parse_unpretty: &str = "`string` or `string=string`";
401401
pub const parse_treat_err_as_bug: &str = "either no value or a non-negative number";
402-
pub const parse_next_solver_config: &str = "a comma separated list of solver configurations: `globally` (default), `coherence`, `dump-tree`, `dump-tree-on-error";
402+
pub const parse_next_solver_config: &str =
403+
"a comma separated list of solver configurations: `globally` (default), and `coherence`";
403404
pub const parse_lto: &str =
404405
"either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
405406
pub const parse_linker_plugin_lto: &str =
@@ -1058,39 +1059,20 @@ mod parse {
10581059
if let Some(config) = v {
10591060
let mut coherence = false;
10601061
let mut globally = true;
1061-
let mut dump_tree = None;
10621062
for c in config.split(',') {
10631063
match c {
10641064
"globally" => globally = true,
10651065
"coherence" => {
10661066
globally = false;
10671067
coherence = true;
10681068
}
1069-
"dump-tree" => {
1070-
if dump_tree.replace(DumpSolverProofTree::Always).is_some() {
1071-
return false;
1072-
}
1073-
}
1074-
"dump-tree-on-error" => {
1075-
if dump_tree.replace(DumpSolverProofTree::OnError).is_some() {
1076-
return false;
1077-
}
1078-
}
10791069
_ => return false,
10801070
}
10811071
}
10821072

1083-
*slot = Some(NextSolverConfig {
1084-
coherence: coherence || globally,
1085-
globally,
1086-
dump_tree: dump_tree.unwrap_or_default(),
1087-
});
1073+
*slot = Some(NextSolverConfig { coherence: coherence || globally, globally });
10881074
} else {
1089-
*slot = Some(NextSolverConfig {
1090-
coherence: true,
1091-
globally: true,
1092-
dump_tree: Default::default(),
1093-
});
1075+
*slot = Some(NextSolverConfig { coherence: true, globally: true });
10941076
}
10951077

10961078
true

Diff for: compiler/rustc_target/src/target_features.rs

-2
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,9 @@ const X86_ALLOWED_FEATURES: &[(&str, Stability)] = &[
199199
("avx512bw", Unstable(sym::avx512_target_feature)),
200200
("avx512cd", Unstable(sym::avx512_target_feature)),
201201
("avx512dq", Unstable(sym::avx512_target_feature)),
202-
("avx512er", Unstable(sym::avx512_target_feature)),
203202
("avx512f", Unstable(sym::avx512_target_feature)),
204203
("avx512fp16", Unstable(sym::avx512_target_feature)),
205204
("avx512ifma", Unstable(sym::avx512_target_feature)),
206-
("avx512pf", Unstable(sym::avx512_target_feature)),
207205
("avx512vbmi", Unstable(sym::avx512_target_feature)),
208206
("avx512vbmi2", Unstable(sym::avx512_target_feature)),
209207
("avx512vl", Unstable(sym::avx512_target_feature)),

Diff for: compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs

+5-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use std::io::Write;
2-
use std::ops::ControlFlow;
3-
41
use rustc_data_structures::stack::ensure_sufficient_stack;
52
use rustc_hir::def_id::DefId;
63
use rustc_infer::infer::at::ToTrace;
@@ -20,10 +17,10 @@ use rustc_middle::ty::{
2017
self, InferCtxtLike, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable,
2118
TypeVisitable, TypeVisitableExt, TypeVisitor,
2219
};
23-
use rustc_session::config::DumpSolverProofTree;
2420
use rustc_span::DUMMY_SP;
2521
use rustc_type_ir::{self as ir, CanonicalVarValues, Interner};
2622
use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic};
23+
use std::ops::ControlFlow;
2724

2825
use crate::traits::coherence;
2926
use crate::traits::vtable::{count_own_vtable_entries, prepare_vtable_segments, VtblSegment};
@@ -135,8 +132,7 @@ impl<I: Interner> NestedGoals<I> {
135132
#[derive(PartialEq, Eq, Debug, Hash, HashStable, Clone, Copy)]
136133
pub enum GenerateProofTree {
137134
Yes,
138-
IfEnabled,
139-
Never,
135+
No,
140136
}
141137

142138
#[extension(pub trait InferCtxtEvalExt<'tcx>)]
@@ -182,7 +178,7 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
182178
infcx,
183179
search_graph: &mut search_graph,
184180
nested_goals: NestedGoals::new(),
185-
inspect: ProofTreeBuilder::new_maybe_root(infcx.tcx, generate_proof_tree),
181+
inspect: ProofTreeBuilder::new_maybe_root(generate_proof_tree),
186182

187183
// Only relevant when canonicalizing the response,
188184
// which we don't do within this evaluation context.
@@ -197,23 +193,14 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
197193
};
198194
let result = f(&mut ecx);
199195

200-
let tree = ecx.inspect.finalize();
201-
if let (Some(tree), DumpSolverProofTree::Always) = (
202-
&tree,
203-
infcx.tcx.sess.opts.unstable_opts.next_solver.map(|c| c.dump_tree).unwrap_or_default(),
204-
) {
205-
let mut lock = std::io::stdout().lock();
206-
let _ = lock.write_fmt(format_args!("{tree:?}\n"));
207-
let _ = lock.flush();
208-
}
209-
196+
let proof_tree = ecx.inspect.finalize();
210197
assert!(
211198
ecx.nested_goals.is_empty(),
212199
"root `EvalCtxt` should not have any goals added to it"
213200
);
214201

215202
assert!(search_graph.is_empty());
216-
(result, tree)
203+
(result, proof_tree)
217204
}
218205

219206
/// Creates a nested evaluation context that shares the same search graph as the
@@ -483,7 +470,6 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
483470
// the certainty of all the goals.
484471
#[instrument(level = "trace", skip(self))]
485472
pub(super) fn try_evaluate_added_goals(&mut self) -> Result<Certainty, NoSolution> {
486-
self.inspect.start_evaluate_added_goals();
487473
let mut response = Ok(Certainty::overflow(false));
488474
for _ in 0..FIXPOINT_STEP_LIMIT {
489475
// FIXME: This match is a bit ugly, it might be nice to change the inspect
@@ -501,8 +487,6 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
501487
}
502488
}
503489

504-
self.inspect.evaluate_added_goals_result(response);
505-
506490
if response.is_err() {
507491
self.tainted = Err(NoSolution);
508492
}
@@ -515,7 +499,6 @@ impl<'a, 'tcx> EvalCtxt<'a, InferCtxt<'tcx>> {
515499
/// Goals for the next step get directly added to the nested goals of the `EvalCtxt`.
516500
fn evaluate_added_goals_step(&mut self) -> Result<Option<Certainty>, NoSolution> {
517501
let tcx = self.tcx();
518-
self.inspect.start_evaluate_added_goals_step();
519502
let mut goals = core::mem::take(&mut self.nested_goals);
520503

521504
// If this loop did not result in any progress, what's our final certainty.

Diff for: compiler/rustc_trait_selection/src/solve/fulfill.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'tcx> ObligationStorage<'tcx> {
7979
// change.
8080
self.overflowed.extend(self.pending.extract_if(|o| {
8181
let goal = o.clone().into();
82-
let result = infcx.evaluate_root_goal(goal, GenerateProofTree::Never).0;
82+
let result = infcx.evaluate_root_goal(goal, GenerateProofTree::No).0;
8383
match result {
8484
Ok((has_changed, _)) => has_changed,
8585
_ => false,
@@ -159,7 +159,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
159159
let mut has_changed = false;
160160
for obligation in self.obligations.unstalled_for_select() {
161161
let goal = obligation.clone().into();
162-
let result = infcx.evaluate_root_goal(goal, GenerateProofTree::IfEnabled).0;
162+
let result = infcx.evaluate_root_goal(goal, GenerateProofTree::No).0;
163163
self.inspect_evaluated_obligation(infcx, &obligation, &result);
164164
let (changed, certainty) = match result {
165165
Ok(result) => result,
@@ -246,7 +246,7 @@ fn fulfillment_error_for_stalled<'tcx>(
246246
root_obligation: PredicateObligation<'tcx>,
247247
) -> FulfillmentError<'tcx> {
248248
let (code, refine_obligation) = infcx.probe(|_| {
249-
match infcx.evaluate_root_goal(root_obligation.clone().into(), GenerateProofTree::Never).0 {
249+
match infcx.evaluate_root_goal(root_obligation.clone().into(), GenerateProofTree::No).0 {
250250
Ok((_, Certainty::Maybe(MaybeCause::Ambiguity))) => {
251251
(FulfillmentErrorCode::Ambiguity { overflow: None }, true)
252252
}

0 commit comments

Comments
 (0)