Skip to content

Commit 4cc494b

Browse files
committed
Auto merge of rust-lang#131495 - matthiaskrgr:rollup-lwf2u4i, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#130625 (Fix a few relative paths in rustc doc) - rust-lang#131397 (fix/update teach_note from 'escaping mutable ref/ptr' const-check) - rust-lang#131479 (Apple: Avoid redundant `-Wl,-dylib` flag when linking) - rust-lang#131480 (Fix hardcoded strip path when cross-compiling from Linux to Darwin) - rust-lang#131482 (structurally resolve adts and tuples expectations too) - rust-lang#131484 (Add myself back to review rotation) - rust-lang#131491 (impossible obligations fast path) r? `@ghost` `@rustbot` modify labels: rollup
2 parents de19f2b + 1c62cff commit 4cc494b

File tree

20 files changed

+171
-87
lines changed

20 files changed

+171
-87
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,9 @@ fn link_natively(
10871087
let strip = sess.opts.cg.strip;
10881088

10891089
if sess.target.is_like_osx {
1090-
let stripcmd = "/usr/bin/strip";
1090+
// Use system `strip` when running on host macOS.
1091+
// <https://github.com/rust-lang/rust/pull/130781>
1092+
let stripcmd = if cfg!(target_os = "macos") { "/usr/bin/strip" } else { "strip" };
10911093
match (strip, crate_type) {
10921094
(Strip::Debuginfo, _) => {
10931095
strip_symbols_with_external_utility(sess, stripcmd, out_filename, Some("-S"))

compiler/rustc_codegen_ssa/src/back/linker.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,14 @@ impl<'a> GccLinker<'a> {
404404
fn build_dylib(&mut self, crate_type: CrateType, out_filename: &Path) {
405405
// On mac we need to tell the linker to let this library be rpathed
406406
if self.sess.target.is_like_osx {
407-
if !self.is_ld {
407+
if self.is_cc() {
408+
// `-dynamiclib` makes `cc` pass `-dylib` to the linker.
408409
self.cc_arg("-dynamiclib");
410+
} else {
411+
self.link_arg("-dylib");
412+
// Clang also sets `-dynamic`, but that's implied by `-dylib`, so unnecessary.
409413
}
410414

411-
self.link_arg("-dylib");
412-
413415
// Note that the `osx_rpath_install_name` option here is a hack
414416
// purely to support bootstrap right now, we should get a more
415417
// principled solution at some point to force the compiler to pass

compiler/rustc_const_eval/messages.ftl

+26-25
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,16 @@ const_eval_incompatible_return_types =
134134
const_eval_incompatible_types =
135135
calling a function with argument of type {$callee_ty} passing data of type {$caller_ty}
136136
137-
const_eval_interior_mutable_data_refer =
137+
const_eval_interior_mutable_ref_escaping =
138138
{const_eval_const_context}s cannot refer to interior mutable data
139139
.label = this borrow of an interior mutable value may end up in the final value
140140
.help = to fix this, the value can be extracted to a separate `static` item and then referenced
141141
.teach_note =
142-
A constant containing interior mutable data behind a reference can allow you to modify that data.
143-
This would make multiple uses of a constant to be able to see different values and allow circumventing
144-
the `Send` and `Sync` requirements for shared mutable data, which is unsound.
142+
References that escape into the final value of a constant or static must be immutable.
143+
This is to avoid accidentally creating shared mutable state.
144+
145+
146+
If you really want global mutable state, try using an interior mutable `static` or a `static mut`.
145147
146148
const_eval_intern_kind = {$kind ->
147149
[static] static
@@ -229,6 +231,24 @@ const_eval_modified_global =
229231
230232
const_eval_mutable_ptr_in_final = encountered mutable pointer in final value of {const_eval_intern_kind}
231233
234+
const_eval_mutable_raw_escaping =
235+
raw mutable pointers are not allowed in the final value of {const_eval_const_context}s
236+
.teach_note =
237+
Pointers that escape into the final value of a constant or static must be immutable.
238+
This is to avoid accidentally creating shared mutable state.
239+
240+
241+
If you really want global mutable state, try using an interior mutable `static` or a `static mut`.
242+
243+
const_eval_mutable_ref_escaping =
244+
mutable references are not allowed in the final value of {const_eval_const_context}s
245+
.teach_note =
246+
References that escape into the final value of a constant or static must be immutable.
247+
This is to avoid accidentally creating shared mutable state.
248+
249+
250+
If you really want global mutable state, try using an interior mutable `static` or a `static mut`.
251+
232252
const_eval_nested_static_in_thread_local = #[thread_local] does not support implicit nested statics, please create explicit static items and refer to them instead
233253
const_eval_non_const_fmt_macro_call =
234254
cannot call non-const formatting macro in {const_eval_const_context}s
@@ -364,30 +384,11 @@ const_eval_unallowed_fn_pointer_call = function pointer calls are not allowed in
364384
const_eval_unallowed_heap_allocations =
365385
allocations are not allowed in {const_eval_const_context}s
366386
.label = allocation not allowed in {const_eval_const_context}s
367-
.teach_note = The value of statics and constants must be known at compile time, and they live for the entire lifetime of a program. Creating a boxed value allocates memory on the heap at runtime, and therefore cannot be done at compile time.
387+
.teach_note =
388+
The runtime heap is not yet available at compile-time, so no runtime heap allocations can be created.
368389
369390
const_eval_unallowed_inline_asm =
370391
inline assembly is not allowed in {const_eval_const_context}s
371-
const_eval_unallowed_mutable_raw =
372-
raw mutable pointers are not allowed in the final value of {const_eval_const_context}s
373-
.teach_note =
374-
References in statics and constants may only refer to immutable values.
375-
376-
377-
Statics are shared everywhere, and if they refer to mutable data one might violate memory
378-
safety since holding multiple mutable references to shared data is not allowed.
379-
380-
381-
If you really want global mutable state, try using static mut or a global UnsafeCell.
382-
383-
const_eval_unallowed_mutable_refs =
384-
mutable references are not allowed in the final value of {const_eval_const_context}s
385-
.teach_note =
386-
Statics are shared everywhere, and if they refer to mutable data one might violate memory
387-
safety since holding multiple mutable references to shared data is not allowed.
388-
389-
390-
If you really want global mutable state, try using static mut or a global UnsafeCell.
391392
392393
const_eval_unallowed_op_in_const_context =
393394
{$msg}

compiler/rustc_const_eval/src/check_consts/check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
666666
}
667667
}
668668

669+
// This can be called on stable via the `vec!` macro.
669670
if tcx.is_lang_item(callee, LangItem::ExchangeMalloc) {
670671
self.check_op(ops::HeapAllocation);
671672
return;

compiler/rustc_const_eval/src/check_consts/ops.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ impl<'tcx> NonConstOp<'tcx> for EscapingCellBorrow {
402402
DiagImportance::Secondary
403403
}
404404
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
405-
ccx.dcx().create_err(errors::InteriorMutableDataRefer {
405+
ccx.dcx().create_err(errors::InteriorMutableRefEscaping {
406406
span,
407407
opt_help: matches!(ccx.const_kind(), hir::ConstContext::Static(_)),
408408
kind: ccx.const_kind(),
@@ -430,12 +430,12 @@ impl<'tcx> NonConstOp<'tcx> for EscapingMutBorrow {
430430

431431
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
432432
match self.0 {
433-
hir::BorrowKind::Raw => ccx.tcx.dcx().create_err(errors::UnallowedMutableRaw {
433+
hir::BorrowKind::Raw => ccx.tcx.dcx().create_err(errors::MutableRawEscaping {
434434
span,
435435
kind: ccx.const_kind(),
436436
teach: ccx.tcx.sess.teach(E0764),
437437
}),
438-
hir::BorrowKind::Ref => ccx.dcx().create_err(errors::UnallowedMutableRefs {
438+
hir::BorrowKind::Ref => ccx.dcx().create_err(errors::MutableRefEscaping {
439439
span,
440440
kind: ccx.const_kind(),
441441
teach: ccx.tcx.sess.teach(E0764),

compiler/rustc_const_eval/src/errors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ pub(crate) struct UnstableConstFn {
118118
}
119119

120120
#[derive(Diagnostic)]
121-
#[diag(const_eval_unallowed_mutable_refs, code = E0764)]
122-
pub(crate) struct UnallowedMutableRefs {
121+
#[diag(const_eval_mutable_ref_escaping, code = E0764)]
122+
pub(crate) struct MutableRefEscaping {
123123
#[primary_span]
124124
pub span: Span,
125125
pub kind: ConstContext,
@@ -128,8 +128,8 @@ pub(crate) struct UnallowedMutableRefs {
128128
}
129129

130130
#[derive(Diagnostic)]
131-
#[diag(const_eval_unallowed_mutable_raw, code = E0764)]
132-
pub(crate) struct UnallowedMutableRaw {
131+
#[diag(const_eval_mutable_raw_escaping, code = E0764)]
132+
pub(crate) struct MutableRawEscaping {
133133
#[primary_span]
134134
pub span: Span,
135135
pub kind: ConstContext,
@@ -181,8 +181,8 @@ pub(crate) struct UnallowedInlineAsm {
181181
}
182182

183183
#[derive(Diagnostic)]
184-
#[diag(const_eval_interior_mutable_data_refer, code = E0492)]
185-
pub(crate) struct InteriorMutableDataRefer {
184+
#[diag(const_eval_interior_mutable_ref_escaping, code = E0492)]
185+
pub(crate) struct InteriorMutableRefEscaping {
186186
#[primary_span]
187187
#[label]
188188
pub span: Span,

compiler/rustc_hir/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub mod weak_lang_items;
3333
#[cfg(test)]
3434
mod tests;
3535

36+
#[doc(no_inline)]
3637
pub use hir::*;
3738
pub use hir_id::*;
3839
pub use lang_items::{LangItem, LanguageItems};

compiler/rustc_hir_typeck/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17831783
expr: &'tcx hir::Expr<'tcx>,
17841784
) -> Ty<'tcx> {
17851785
let flds = expected.only_has_type(self).and_then(|ty| {
1786-
let ty = self.resolve_vars_with_obligations(ty);
1786+
let ty = self.try_structurally_resolve_type(expr.span, ty);
17871787
match ty.kind() {
17881788
ty::Tuple(flds) => Some(&flds[..]),
17891789
_ => None,
@@ -1861,7 +1861,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18611861
) {
18621862
let tcx = self.tcx;
18631863

1864-
let adt_ty = self.resolve_vars_with_obligations(adt_ty);
1864+
let adt_ty = self.try_structurally_resolve_type(span, adt_ty);
18651865
let adt_ty_hint = expected.only_has_type(self).and_then(|expected| {
18661866
self.fudge_inference_if_ok(|| {
18671867
let ocx = ObligationCtxt::new(self);

compiler/rustc_index/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ mod vec;
1717
pub use idx::Idx;
1818
pub use rustc_index_macros::newtype_index;
1919
pub use slice::IndexSlice;
20+
#[doc(no_inline)]
2021
pub use vec::IndexVec;
2122

2223
/// Type size assertion. The first argument is a type and the second argument is its expected size.

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

+54-18
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use crate::solve::inspect::{self, ProofTreeBuilder};
1818
use crate::solve::search_graph::SearchGraph;
1919
use crate::solve::{
2020
CanonicalInput, CanonicalResponse, Certainty, FIXPOINT_STEP_LIMIT, Goal, GoalEvaluationKind,
21-
GoalSource, NestedNormalizationGoals, NoSolution, PredefinedOpaquesData, QueryResult,
22-
SolverMode,
21+
GoalSource, HasChanged, NestedNormalizationGoals, NoSolution, PredefinedOpaquesData,
22+
QueryResult, SolverMode,
2323
};
2424

2525
pub(super) mod canonical;
@@ -126,11 +126,31 @@ pub enum GenerateProofTree {
126126
}
127127

128128
pub trait SolverDelegateEvalExt: SolverDelegate {
129+
/// Evaluates a goal from **outside** of the trait solver.
130+
///
131+
/// Using this while inside of the solver is wrong as it uses a new
132+
/// search graph which would break cycle detection.
129133
fn evaluate_root_goal(
130134
&self,
131135
goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
132136
generate_proof_tree: GenerateProofTree,
133-
) -> (Result<(bool, Certainty), NoSolution>, Option<inspect::GoalEvaluation<Self::Interner>>);
137+
) -> (
138+
Result<(HasChanged, Certainty), NoSolution>,
139+
Option<inspect::GoalEvaluation<Self::Interner>>,
140+
);
141+
142+
/// Check whether evaluating `goal` with a depth of `root_depth` may
143+
/// succeed. This only returns `false` if the goal is guaranteed to
144+
/// not hold. In case evaluation overflows and fails with ambiguity this
145+
/// returns `true`.
146+
///
147+
/// This is only intended to be used as a performance optimization
148+
/// in coherence checking.
149+
fn root_goal_may_hold_with_depth(
150+
&self,
151+
root_depth: usize,
152+
goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
153+
) -> bool;
134154

135155
// FIXME: This is only exposed because we need to use it in `analyse.rs`
136156
// which is not yet uplifted. Once that's done, we should remove this.
@@ -139,7 +159,7 @@ pub trait SolverDelegateEvalExt: SolverDelegate {
139159
goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
140160
generate_proof_tree: GenerateProofTree,
141161
) -> (
142-
Result<(NestedNormalizationGoals<Self::Interner>, bool, Certainty), NoSolution>,
162+
Result<(NestedNormalizationGoals<Self::Interner>, HasChanged, Certainty), NoSolution>,
143163
Option<inspect::GoalEvaluation<Self::Interner>>,
144164
);
145165
}
@@ -149,31 +169,41 @@ where
149169
D: SolverDelegate<Interner = I>,
150170
I: Interner,
151171
{
152-
/// Evaluates a goal from **outside** of the trait solver.
153-
///
154-
/// Using this while inside of the solver is wrong as it uses a new
155-
/// search graph which would break cycle detection.
156172
#[instrument(level = "debug", skip(self))]
157173
fn evaluate_root_goal(
158174
&self,
159175
goal: Goal<I, I::Predicate>,
160176
generate_proof_tree: GenerateProofTree,
161-
) -> (Result<(bool, Certainty), NoSolution>, Option<inspect::GoalEvaluation<I>>) {
162-
EvalCtxt::enter_root(self, generate_proof_tree, |ecx| {
177+
) -> (Result<(HasChanged, Certainty), NoSolution>, Option<inspect::GoalEvaluation<I>>) {
178+
EvalCtxt::enter_root(self, self.cx().recursion_limit(), generate_proof_tree, |ecx| {
163179
ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal)
164180
})
165181
}
166182

183+
fn root_goal_may_hold_with_depth(
184+
&self,
185+
root_depth: usize,
186+
goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
187+
) -> bool {
188+
self.probe(|| {
189+
EvalCtxt::enter_root(self, root_depth, GenerateProofTree::No, |ecx| {
190+
ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal)
191+
})
192+
.0
193+
})
194+
.is_ok()
195+
}
196+
167197
#[instrument(level = "debug", skip(self))]
168198
fn evaluate_root_goal_raw(
169199
&self,
170200
goal: Goal<I, I::Predicate>,
171201
generate_proof_tree: GenerateProofTree,
172202
) -> (
173-
Result<(NestedNormalizationGoals<I>, bool, Certainty), NoSolution>,
203+
Result<(NestedNormalizationGoals<I>, HasChanged, Certainty), NoSolution>,
174204
Option<inspect::GoalEvaluation<I>>,
175205
) {
176-
EvalCtxt::enter_root(self, generate_proof_tree, |ecx| {
206+
EvalCtxt::enter_root(self, self.cx().recursion_limit(), generate_proof_tree, |ecx| {
177207
ecx.evaluate_goal_raw(GoalEvaluationKind::Root, GoalSource::Misc, goal)
178208
})
179209
}
@@ -197,10 +227,11 @@ where
197227
/// over using this manually (such as [`SolverDelegateEvalExt::evaluate_root_goal`]).
198228
pub(super) fn enter_root<R>(
199229
delegate: &D,
230+
root_depth: usize,
200231
generate_proof_tree: GenerateProofTree,
201232
f: impl FnOnce(&mut EvalCtxt<'_, D>) -> R,
202233
) -> (R, Option<inspect::GoalEvaluation<I>>) {
203-
let mut search_graph = SearchGraph::new(delegate.solver_mode());
234+
let mut search_graph = SearchGraph::new(delegate.solver_mode(), root_depth);
204235

205236
let mut ecx = EvalCtxt {
206237
delegate,
@@ -339,7 +370,7 @@ where
339370
goal_evaluation_kind: GoalEvaluationKind,
340371
source: GoalSource,
341372
goal: Goal<I, I::Predicate>,
342-
) -> Result<(bool, Certainty), NoSolution> {
373+
) -> Result<(HasChanged, Certainty), NoSolution> {
343374
let (normalization_nested_goals, has_changed, certainty) =
344375
self.evaluate_goal_raw(goal_evaluation_kind, source, goal)?;
345376
assert!(normalization_nested_goals.is_empty());
@@ -360,7 +391,7 @@ where
360391
goal_evaluation_kind: GoalEvaluationKind,
361392
_source: GoalSource,
362393
goal: Goal<I, I::Predicate>,
363-
) -> Result<(NestedNormalizationGoals<I>, bool, Certainty), NoSolution> {
394+
) -> Result<(NestedNormalizationGoals<I>, HasChanged, Certainty), NoSolution> {
364395
let (orig_values, canonical_goal) = self.canonicalize_goal(goal);
365396
let mut goal_evaluation =
366397
self.inspect.new_goal_evaluation(goal, &orig_values, goal_evaluation_kind);
@@ -378,8 +409,13 @@ where
378409
Ok(response) => response,
379410
};
380411

381-
let has_changed = !response.value.var_values.is_identity_modulo_regions()
382-
|| !response.value.external_constraints.opaque_types.is_empty();
412+
let has_changed = if !response.value.var_values.is_identity_modulo_regions()
413+
|| !response.value.external_constraints.opaque_types.is_empty()
414+
{
415+
HasChanged::Yes
416+
} else {
417+
HasChanged::No
418+
};
383419

384420
let (normalization_nested_goals, certainty) =
385421
self.instantiate_and_apply_query_response(goal.param_env, orig_values, response);
@@ -552,7 +588,7 @@ where
552588
for (source, goal) in goals.goals {
553589
let (has_changed, certainty) =
554590
self.evaluate_goal(GoalEvaluationKind::Nested, source, goal)?;
555-
if has_changed {
591+
if has_changed == HasChanged::Yes {
556592
unchanged_certainty = None;
557593
}
558594

compiler/rustc_next_trait_solver/src/solve/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ enum GoalEvaluationKind {
4848
Nested,
4949
}
5050

51+
/// Whether evaluating this goal ended up changing the
52+
/// inference state.
53+
#[derive(PartialEq, Eq, Debug, Hash, Clone, Copy)]
54+
pub enum HasChanged {
55+
Yes,
56+
No,
57+
}
58+
5159
// FIXME(trait-system-refactor-initiative#117): we don't detect whether a response
5260
// ended up pulling down any universes.
5361
fn has_no_inference_or_external_constraints<I: Interner>(

compiler/rustc_next_trait_solver/src/solve/search_graph.rs

-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ where
4040
}
4141

4242
const DIVIDE_AVAILABLE_DEPTH_ON_OVERFLOW: usize = 4;
43-
fn recursion_limit(cx: I) -> usize {
44-
cx.recursion_limit()
45-
}
4643

4744
fn initial_provisional_result(
4845
cx: I,

compiler/rustc_trait_selection/src/solve.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod inspect;
66
mod normalize;
77
mod select;
88

9+
pub(crate) use delegate::SolverDelegate;
910
pub use fulfill::{FulfillmentCtxt, NextSolverError};
1011
pub(crate) use normalize::deeply_normalize_for_diagnostics;
1112
pub use normalize::{deeply_normalize, deeply_normalize_with_skipped_universes};

0 commit comments

Comments
 (0)