Skip to content

Commit af2c7e0

Browse files
committed
Auto merge of #110978 - Dylan-DPC:rollup-xclzwax, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #110614 (Clear response values for overflow in new solver) - #110894 (Bump libffi-sys to 2.3.0) - #110932 (include source error for LoadLibraryExW) - #110958 (Make sure that some stdlib method signatures aren't accidental refinements) - #110962 (Make drop_flags an IndexVec.) - #110965 (Don't duplicate anonymous lifetimes for async fn in traits) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 572c0d5 + 81910a1 commit af2c7e0

File tree

21 files changed

+390
-63
lines changed

21 files changed

+390
-63
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1956,9 +1956,9 @@ dependencies = [
19561956

19571957
[[package]]
19581958
name = "libffi-sys"
1959-
version = "2.2.1"
1959+
version = "2.3.0"
19601960
source = "registry+https://github.com/rust-lang/crates.io-index"
1961-
checksum = "dc65067b78c0fc069771e8b9a9e02df71e08858bec92c1f101377c67b9dca7c7"
1961+
checksum = "f36115160c57e8529781b4183c2bb51fdc1f6d6d1ed345591d84be7703befb3c"
19621962
dependencies = [
19631963
"cc",
19641964
]

compiler/rustc_metadata/src/creader.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use rustc_span::{Span, DUMMY_SP};
2727
use rustc_target::spec::{PanicStrategy, TargetTriple};
2828

2929
use proc_macro::bridge::client::ProcMacro;
30+
use std::error::Error;
3031
use std::ops::Fn;
3132
use std::path::Path;
3233
use std::time::Duration;
@@ -1094,5 +1095,12 @@ fn load_dylib(path: &Path, max_attempts: usize) -> Result<libloading::Library, S
10941095
}
10951096

10961097
debug!("Failed to load proc-macro `{}` even after {} attempts.", path.display(), max_attempts);
1097-
Err(format!("{} (retried {} times)", last_error.unwrap(), max_attempts))
1098+
1099+
let last_error = last_error.unwrap();
1100+
let message = if let Some(src) = last_error.source() {
1101+
format!("{last_error} ({src}) (retried {max_attempts} times)")
1102+
} else {
1103+
format!("{last_error} (retried {max_attempts} times)")
1104+
};
1105+
Err(message)
10981106
}

compiler/rustc_mir_transform/src/elaborate_drops.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::deref_separator::deref_finder;
22
use crate::MirPass;
3-
use rustc_data_structures::fx::FxHashMap;
43
use rustc_index::bit_set::BitSet;
4+
use rustc_index::IndexVec;
55
use rustc_middle::mir::patch::MirPatch;
66
use rustc_middle::mir::*;
77
use rustc_middle::ty::{self, TyCtxt};
@@ -84,12 +84,13 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
8484

8585
let reachable = traversal::reachable_as_bitset(body);
8686

87+
let drop_flags = IndexVec::from_elem(None, &env.move_data.move_paths);
8788
ElaborateDropsCtxt {
8889
tcx,
8990
body,
9091
env: &env,
9192
init_data: InitializationData { inits, uninits },
92-
drop_flags: Default::default(),
93+
drop_flags,
9394
patch: MirPatch::new(body),
9495
un_derefer: un_derefer,
9596
reachable,
@@ -293,7 +294,7 @@ struct ElaborateDropsCtxt<'a, 'tcx> {
293294
body: &'a Body<'tcx>,
294295
env: &'a MoveDataParamEnv<'tcx>,
295296
init_data: InitializationData<'a, 'tcx>,
296-
drop_flags: FxHashMap<MovePathIndex, Local>,
297+
drop_flags: IndexVec<MovePathIndex, Option<Local>>,
297298
patch: MirPatch<'tcx>,
298299
un_derefer: UnDerefer<'tcx>,
299300
reachable: BitSet<BasicBlock>,
@@ -312,11 +313,11 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
312313
let tcx = self.tcx;
313314
let patch = &mut self.patch;
314315
debug!("create_drop_flag({:?})", self.body.span);
315-
self.drop_flags.entry(index).or_insert_with(|| patch.new_internal(tcx.types.bool, span));
316+
self.drop_flags[index].get_or_insert_with(|| patch.new_internal(tcx.types.bool, span));
316317
}
317318

318319
fn drop_flag(&mut self, index: MovePathIndex) -> Option<Place<'tcx>> {
319-
self.drop_flags.get(&index).map(|t| Place::from(*t))
320+
self.drop_flags[index].map(Place::from)
320321
}
321322

322323
/// create a patch that elaborates all drops in the input
@@ -463,7 +464,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
463464
}
464465

465466
fn set_drop_flag(&mut self, loc: Location, path: MovePathIndex, val: DropFlagState) {
466-
if let Some(&flag) = self.drop_flags.get(&path) {
467+
if let Some(flag) = self.drop_flags[path] {
467468
let span = self.patch.source_info_for_location(self.body, loc).span;
468469
let val = self.constant_bool(span, val.value());
469470
self.patch.add_assign(loc, Place::from(flag), val);
@@ -474,7 +475,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
474475
let loc = Location::START;
475476
let span = self.patch.source_info_for_location(self.body, loc).span;
476477
let false_ = self.constant_bool(span, false);
477-
for flag in self.drop_flags.values() {
478+
for flag in self.drop_flags.iter().flatten() {
478479
self.patch.add_assign(loc, Place::from(*flag), false_.clone());
479480
}
480481
}

compiler/rustc_resolve/src/late.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -859,13 +859,9 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
859859
sig.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)),
860860
&sig.decl.output,
861861
);
862-
863-
this.record_lifetime_params_for_async(
864-
fn_id,
865-
sig.header.asyncness.opt_return_id(),
866-
);
867862
},
868863
);
864+
self.record_lifetime_params_for_async(fn_id, sig.header.asyncness.opt_return_id());
869865
return;
870866
}
871867
FnKind::Fn(..) => {

compiler/rustc_trait_selection/src/solve/eval_ctxt.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use rustc_infer::infer::at::ToTrace;
33
use rustc_infer::infer::canonical::CanonicalVarValues;
44
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
55
use rustc_infer::infer::{
6-
DefineOpaqueTypes, InferCtxt, InferOk, LateBoundRegionConversionTime, TyCtxtInferExt,
6+
DefineOpaqueTypes, InferCtxt, InferOk, LateBoundRegionConversionTime, RegionVariableOrigin,
7+
TyCtxtInferExt,
78
};
89
use rustc_infer::traits::query::NoSolution;
910
use rustc_infer::traits::ObligationCause;
@@ -223,18 +224,20 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
223224
{
224225
debug!("rerunning goal to check result is stable");
225226
let (_orig_values, canonical_goal) = self.canonicalize_goal(goal);
226-
let canonical_response =
227+
let new_canonical_response =
227228
EvalCtxt::evaluate_canonical_goal(self.tcx(), self.search_graph, canonical_goal)?;
228-
if !canonical_response.value.var_values.is_identity() {
229+
if !new_canonical_response.value.var_values.is_identity() {
229230
bug!(
230231
"unstable result: re-canonicalized goal={canonical_goal:#?} \
231-
response={canonical_response:#?}"
232+
first_response={canonical_response:#?} \
233+
second_response={new_canonical_response:#?}"
232234
);
233235
}
234-
if certainty != canonical_response.value.certainty {
236+
if certainty != new_canonical_response.value.certainty {
235237
bug!(
236238
"unstable certainty: {certainty:#?} re-canonicalized goal={canonical_goal:#?} \
237-
response={canonical_response:#?}"
239+
first_response={canonical_response:#?} \
240+
second_response={new_canonical_response:#?}"
238241
);
239242
}
240243
}
@@ -434,6 +437,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
434437
})
435438
}
436439

440+
pub(super) fn next_region_infer(&self) -> ty::Region<'tcx> {
441+
self.infcx.next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP))
442+
}
443+
437444
pub(super) fn next_const_infer(&self, ty: Ty<'tcx>) -> ty::Const<'tcx> {
438445
self.infcx.next_const_var(
439446
ty,

compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs

+55-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_infer::infer::canonical::query_response::make_query_region_constraints
1616
use rustc_infer::infer::canonical::CanonicalVarValues;
1717
use rustc_infer::infer::canonical::{CanonicalExt, QueryRegionConstraints};
1818
use rustc_middle::traits::query::NoSolution;
19-
use rustc_middle::traits::solve::{ExternalConstraints, ExternalConstraintsData};
19+
use rustc_middle::traits::solve::{ExternalConstraints, ExternalConstraintsData, MaybeCause};
2020
use rustc_middle::ty::{self, BoundVar, GenericArgKind};
2121
use rustc_span::DUMMY_SP;
2222
use std::iter;
@@ -60,9 +60,27 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
6060

6161
let certainty = certainty.unify_with(goals_certainty);
6262

63-
let external_constraints = self.compute_external_query_constraints()?;
63+
let response = match certainty {
64+
Certainty::Yes | Certainty::Maybe(MaybeCause::Ambiguity) => {
65+
let external_constraints = self.compute_external_query_constraints()?;
66+
Response { var_values: self.var_values, external_constraints, certainty }
67+
}
68+
Certainty::Maybe(MaybeCause::Overflow) => {
69+
// If we have overflow, it's probable that we're substituting a type
70+
// into itself infinitely and any partial substitutions in the query
71+
// response are probably not useful anyways, so just return an empty
72+
// query response.
73+
//
74+
// This may prevent us from potentially useful inference, e.g.
75+
// 2 candidates, one ambiguous and one overflow, which both
76+
// have the same inference constraints.
77+
//
78+
// Changing this to retain some constraints in the future
79+
// won't be a breaking change, so this is good enough for now.
80+
return Ok(self.make_ambiguous_response_no_constraints(MaybeCause::Overflow));
81+
}
82+
};
6483

65-
let response = Response { var_values: self.var_values, external_constraints, certainty };
6684
let canonical = Canonicalizer::canonicalize(
6785
self.infcx,
6886
CanonicalizeMode::Response { max_input_universe: self.max_input_universe },
@@ -72,6 +90,40 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
7290
Ok(canonical)
7391
}
7492

93+
/// Constructs a totally unconstrained, ambiguous response to a goal.
94+
///
95+
/// Take care when using this, since often it's useful to respond with
96+
/// ambiguity but return constrained variables to guide inference.
97+
pub(in crate::solve) fn make_ambiguous_response_no_constraints(
98+
&self,
99+
maybe_cause: MaybeCause,
100+
) -> CanonicalResponse<'tcx> {
101+
let unconstrained_response = Response {
102+
var_values: CanonicalVarValues {
103+
var_values: self.tcx().mk_substs_from_iter(self.var_values.var_values.iter().map(
104+
|arg| -> ty::GenericArg<'tcx> {
105+
match arg.unpack() {
106+
GenericArgKind::Lifetime(_) => self.next_region_infer().into(),
107+
GenericArgKind::Type(_) => self.next_ty_infer().into(),
108+
GenericArgKind::Const(ct) => self.next_const_infer(ct.ty()).into(),
109+
}
110+
},
111+
)),
112+
},
113+
external_constraints: self
114+
.tcx()
115+
.mk_external_constraints(ExternalConstraintsData::default()),
116+
certainty: Certainty::Maybe(maybe_cause),
117+
};
118+
119+
Canonicalizer::canonicalize(
120+
self.infcx,
121+
CanonicalizeMode::Response { max_input_universe: self.max_input_universe },
122+
&mut Default::default(),
123+
unconstrained_response,
124+
)
125+
}
126+
75127
#[instrument(level = "debug", skip(self), ret)]
76128
fn compute_external_query_constraints(&self) -> Result<ExternalConstraints<'tcx>, NoSolution> {
77129
// Cannot use `take_registered_region_obligations` as we may compute the response

compiler/rustc_trait_selection/src/solve/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,17 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
340340
if responses.is_empty() {
341341
return Err(NoSolution);
342342
}
343-
let certainty = responses.iter().fold(Certainty::AMBIGUOUS, |certainty, response| {
344-
certainty.unify_with(response.value.certainty)
345-
});
346-
347-
let response = self.evaluate_added_goals_and_make_canonical_response(certainty);
348-
if let Ok(response) = response {
349-
assert!(response.has_no_inference_or_external_constraints());
350-
Ok(response)
351-
} else {
352-
bug!("failed to make floundered response: {responses:?}");
353-
}
343+
344+
let Certainty::Maybe(maybe_cause) = responses.iter().fold(
345+
Certainty::AMBIGUOUS,
346+
|certainty, response| {
347+
certainty.unify_with(response.value.certainty)
348+
},
349+
) else {
350+
bug!("expected flounder response to be ambiguous")
351+
};
352+
353+
Ok(self.make_ambiguous_response_no_constraints(maybe_cause))
354354
}
355355
}
356356

library/alloc/src/collections/btree/map.rs

+48-12
Original file line numberDiff line numberDiff line change
@@ -1543,11 +1543,17 @@ impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> {
15431543
self.next_back()
15441544
}
15451545

1546-
fn min(mut self) -> Option<(&'a K, &'a V)> {
1546+
fn min(mut self) -> Option<(&'a K, &'a V)>
1547+
where
1548+
(&'a K, &'a V): Ord,
1549+
{
15471550
self.next()
15481551
}
15491552

1550-
fn max(mut self) -> Option<(&'a K, &'a V)> {
1553+
fn max(mut self) -> Option<(&'a K, &'a V)>
1554+
where
1555+
(&'a K, &'a V): Ord,
1556+
{
15511557
self.next_back()
15521558
}
15531559
}
@@ -1612,11 +1618,17 @@ impl<'a, K, V> Iterator for IterMut<'a, K, V> {
16121618
self.next_back()
16131619
}
16141620

1615-
fn min(mut self) -> Option<(&'a K, &'a mut V)> {
1621+
fn min(mut self) -> Option<(&'a K, &'a mut V)>
1622+
where
1623+
(&'a K, &'a mut V): Ord,
1624+
{
16161625
self.next()
16171626
}
16181627

1619-
fn max(mut self) -> Option<(&'a K, &'a mut V)> {
1628+
fn max(mut self) -> Option<(&'a K, &'a mut V)>
1629+
where
1630+
(&'a K, &'a mut V): Ord,
1631+
{
16201632
self.next_back()
16211633
}
16221634
}
@@ -1779,11 +1791,17 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> {
17791791
self.next_back()
17801792
}
17811793

1782-
fn min(mut self) -> Option<&'a K> {
1794+
fn min(mut self) -> Option<&'a K>
1795+
where
1796+
&'a K: Ord,
1797+
{
17831798
self.next()
17841799
}
17851800

1786-
fn max(mut self) -> Option<&'a K> {
1801+
fn max(mut self) -> Option<&'a K>
1802+
where
1803+
&'a K: Ord,
1804+
{
17871805
self.next_back()
17881806
}
17891807
}
@@ -2008,11 +2026,17 @@ impl<'a, K, V> Iterator for Range<'a, K, V> {
20082026
self.next_back()
20092027
}
20102028

2011-
fn min(mut self) -> Option<(&'a K, &'a V)> {
2029+
fn min(mut self) -> Option<(&'a K, &'a V)>
2030+
where
2031+
(&'a K, &'a V): Ord,
2032+
{
20122033
self.next()
20132034
}
20142035

2015-
fn max(mut self) -> Option<(&'a K, &'a V)> {
2036+
fn max(mut self) -> Option<(&'a K, &'a V)>
2037+
where
2038+
(&'a K, &'a V): Ord,
2039+
{
20162040
self.next_back()
20172041
}
20182042
}
@@ -2081,11 +2105,17 @@ impl<K, V, A: Allocator + Clone> Iterator for IntoKeys<K, V, A> {
20812105
self.next_back()
20822106
}
20832107

2084-
fn min(mut self) -> Option<K> {
2108+
fn min(mut self) -> Option<K>
2109+
where
2110+
K: Ord,
2111+
{
20852112
self.next()
20862113
}
20872114

2088-
fn max(mut self) -> Option<K> {
2115+
fn max(mut self) -> Option<K>
2116+
where
2117+
K: Ord,
2118+
{
20892119
self.next_back()
20902120
}
20912121
}
@@ -2204,11 +2234,17 @@ impl<'a, K, V> Iterator for RangeMut<'a, K, V> {
22042234
self.next_back()
22052235
}
22062236

2207-
fn min(mut self) -> Option<(&'a K, &'a mut V)> {
2237+
fn min(mut self) -> Option<(&'a K, &'a mut V)>
2238+
where
2239+
(&'a K, &'a mut V): Ord,
2240+
{
22082241
self.next()
22092242
}
22102243

2211-
fn max(mut self) -> Option<(&'a K, &'a mut V)> {
2244+
fn max(mut self) -> Option<(&'a K, &'a mut V)>
2245+
where
2246+
(&'a K, &'a mut V): Ord,
2247+
{
22122248
self.next_back()
22132249
}
22142250
}

0 commit comments

Comments
 (0)