Skip to content

Commit 1b6d4cd

Browse files
committed
Auto merge of #112839 - GuillaumeGomez:rollup-jc5nqug, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #112464 (Fix windows `Socket::connect_timeout` overflow) - #112720 (Rustdoc: search: color item type and reduce size to avoid clashing) - #112762 (Sort the errors from arguments checking so that suggestions are handled properly) - #112786 (change binders from tuple structs to named fields) - #112794 (Fix linker failures when #[global_allocator] is used in a dependency) - #112819 (Disable feature(unboxed_closures, fn_traits) in weird-exprs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6fc0273 + 2368fa2 commit 1b6d4cd

25 files changed

+226
-92
lines changed

compiler/rustc_codegen_ssa/src/base.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::mir::place::PlaceRef;
1313
use crate::traits::*;
1414
use crate::{CachedModuleCodegen, CompiledModule, CrateInfo, MemFlags, ModuleCodegen, ModuleKind};
1515

16-
use rustc_ast::expand::allocator::AllocatorKind;
16+
use rustc_ast::expand::allocator::{global_fn_name, AllocatorKind, ALLOCATOR_METHODS};
1717
use rustc_attr as attr;
1818
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1919
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
@@ -921,7 +921,21 @@ impl CrateInfo {
921921
missing_weak_lang_items
922922
.iter()
923923
.map(|item| (format!("{prefix}{item}"), SymbolExportKind::Text)),
924-
)
924+
);
925+
if tcx.allocator_kind(()).is_some() {
926+
// At least one crate needs a global allocator. This crate may be placed
927+
// after the crate that defines it in the linker order, in which case some
928+
// linkers return an error. By adding the global allocator shim methods to
929+
// the linked_symbols list, linking the generated symbols.o will ensure that
930+
// circular dependencies involving the global allocator don't lead to linker
931+
// errors.
932+
linked_symbols.extend(ALLOCATOR_METHODS.iter().map(|method| {
933+
(
934+
format!("{prefix}{}", global_fn_name(method.name).as_str()),
935+
SymbolExportKind::Text,
936+
)
937+
}));
938+
}
925939
});
926940
}
927941

compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs

+36-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::cmp;
2-
1+
use core::cmp::Ordering;
32
use rustc_index::IndexVec;
43
use rustc_middle::ty::error::TypeError;
4+
use std::cmp;
55

66
rustc_index::newtype_index! {
77
#[debug_format = "ExpectedIdx({})"]
@@ -34,14 +34,14 @@ enum Issue {
3434
Permutation(Vec<Option<usize>>),
3535
}
3636

37-
#[derive(Clone, Debug)]
37+
#[derive(Clone, Debug, Eq, PartialEq)]
3838
pub(crate) enum Compatibility<'tcx> {
3939
Compatible,
4040
Incompatible(Option<TypeError<'tcx>>),
4141
}
4242

4343
/// Similar to `Issue`, but contains some extra information
44-
#[derive(Debug)]
44+
#[derive(Debug, PartialEq, Eq)]
4545
pub(crate) enum Error<'tcx> {
4646
/// The provided argument is the invalid type for the expected input
4747
Invalid(ProvidedIdx, ExpectedIdx, Compatibility<'tcx>),
@@ -55,6 +55,34 @@ pub(crate) enum Error<'tcx> {
5555
Permutation(Vec<(ExpectedIdx, ProvidedIdx)>),
5656
}
5757

58+
impl Ord for Error<'_> {
59+
fn cmp(&self, other: &Self) -> Ordering {
60+
let key = |error: &Error<'_>| -> usize {
61+
match error {
62+
Error::Invalid(..) => 0,
63+
Error::Extra(_) => 1,
64+
Error::Missing(_) => 2,
65+
Error::Swap(..) => 3,
66+
Error::Permutation(..) => 4,
67+
}
68+
};
69+
match (self, other) {
70+
(Error::Invalid(a, _, _), Error::Invalid(b, _, _)) => a.cmp(b),
71+
(Error::Extra(a), Error::Extra(b)) => a.cmp(b),
72+
(Error::Missing(a), Error::Missing(b)) => a.cmp(b),
73+
(Error::Swap(a, b, ..), Error::Swap(c, d, ..)) => a.cmp(c).then(b.cmp(d)),
74+
(Error::Permutation(a), Error::Permutation(b)) => a.cmp(b),
75+
_ => key(self).cmp(&key(other)),
76+
}
77+
}
78+
}
79+
80+
impl PartialOrd for Error<'_> {
81+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
82+
Some(self.cmp(other))
83+
}
84+
}
85+
5886
pub(crate) struct ArgMatrix<'tcx> {
5987
/// Maps the indices in the `compatibility_matrix` rows to the indices of
6088
/// the *user provided* inputs
@@ -177,7 +205,7 @@ impl<'tcx> ArgMatrix<'tcx> {
177205
// If an argument is unsatisfied, and the input in its position is useless
178206
// then the most likely explanation is that we just got the types wrong
179207
(true, true, true, true) => return Some(Issue::Invalid(i)),
180-
// Otherwise, if an input is useless, then indicate that this is an extra argument
208+
// Otherwise, if an input is useless then indicate that this is an extra input
181209
(true, _, true, _) => return Some(Issue::Extra(i)),
182210
// Otherwise, if an argument is unsatisfiable, indicate that it's missing
183211
(_, true, _, true) => return Some(Issue::Missing(i)),
@@ -376,6 +404,9 @@ impl<'tcx> ArgMatrix<'tcx> {
376404
};
377405
}
378406

407+
// sort errors with same type by the order they appear in the source
408+
// so that suggestion will be handled properly, see #112507
409+
errors.sort();
379410
return (errors, matched_inputs);
380411
}
381412
}

compiler/rustc_middle/src/ty/sty.rs

+32-30
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,10 @@ impl BoundVariableKind {
10071007
/// `Decodable` and `Encodable` are implemented for `Binder<T>` using the `impl_binder_encode_decode!` macro.
10081008
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
10091009
#[derive(HashStable, Lift)]
1010-
pub struct Binder<'tcx, T>(T, &'tcx List<BoundVariableKind>);
1010+
pub struct Binder<'tcx, T> {
1011+
value: T,
1012+
bound_vars: &'tcx List<BoundVariableKind>,
1013+
}
10111014

10121015
impl<'tcx, T> Binder<'tcx, T>
10131016
where
@@ -1023,15 +1026,15 @@ where
10231026
!value.has_escaping_bound_vars(),
10241027
"`{value:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder."
10251028
);
1026-
Binder(value, ty::List::empty())
1029+
Binder { value, bound_vars: ty::List::empty() }
10271030
}
10281031

1029-
pub fn bind_with_vars(value: T, vars: &'tcx List<BoundVariableKind>) -> Binder<'tcx, T> {
1032+
pub fn bind_with_vars(value: T, bound_vars: &'tcx List<BoundVariableKind>) -> Binder<'tcx, T> {
10301033
if cfg!(debug_assertions) {
1031-
let mut validator = ValidateBoundVars::new(vars);
1034+
let mut validator = ValidateBoundVars::new(bound_vars);
10321035
value.visit_with(&mut validator);
10331036
}
1034-
Binder(value, vars)
1037+
Binder { value, bound_vars }
10351038
}
10361039
}
10371040

@@ -1053,30 +1056,30 @@ impl<'tcx, T> Binder<'tcx, T> {
10531056
/// - comparing the self type of a PolyTraitRef to see if it is equal to
10541057
/// a type parameter `X`, since the type `X` does not reference any regions
10551058
pub fn skip_binder(self) -> T {
1056-
self.0
1059+
self.value
10571060
}
10581061

10591062
pub fn bound_vars(&self) -> &'tcx List<BoundVariableKind> {
1060-
self.1
1063+
self.bound_vars
10611064
}
10621065

10631066
pub fn as_ref(&self) -> Binder<'tcx, &T> {
1064-
Binder(&self.0, self.1)
1067+
Binder { value: &self.value, bound_vars: self.bound_vars }
10651068
}
10661069

10671070
pub fn as_deref(&self) -> Binder<'tcx, &T::Target>
10681071
where
10691072
T: Deref,
10701073
{
1071-
Binder(&self.0, self.1)
1074+
Binder { value: &self.value, bound_vars: self.bound_vars }
10721075
}
10731076

10741077
pub fn map_bound_ref_unchecked<F, U>(&self, f: F) -> Binder<'tcx, U>
10751078
where
10761079
F: FnOnce(&T) -> U,
10771080
{
1078-
let value = f(&self.0);
1079-
Binder(value, self.1)
1081+
let value = f(&self.value);
1082+
Binder { value, bound_vars: self.bound_vars }
10801083
}
10811084

10821085
pub fn map_bound_ref<F, U: TypeVisitable<TyCtxt<'tcx>>>(&self, f: F) -> Binder<'tcx, U>
@@ -1090,12 +1093,13 @@ impl<'tcx, T> Binder<'tcx, T> {
10901093
where
10911094
F: FnOnce(T) -> U,
10921095
{
1093-
let value = f(self.0);
1096+
let Binder { value, bound_vars } = self;
1097+
let value = f(value);
10941098
if cfg!(debug_assertions) {
1095-
let mut validator = ValidateBoundVars::new(self.1);
1099+
let mut validator = ValidateBoundVars::new(bound_vars);
10961100
value.visit_with(&mut validator);
10971101
}
1098-
Binder(value, self.1)
1102+
Binder { value, bound_vars }
10991103
}
11001104

11011105
pub fn try_map_bound<F, U: TypeVisitable<TyCtxt<'tcx>>, E>(
@@ -1105,12 +1109,13 @@ impl<'tcx, T> Binder<'tcx, T> {
11051109
where
11061110
F: FnOnce(T) -> Result<U, E>,
11071111
{
1108-
let value = f(self.0)?;
1112+
let Binder { value, bound_vars } = self;
1113+
let value = f(value)?;
11091114
if cfg!(debug_assertions) {
1110-
let mut validator = ValidateBoundVars::new(self.1);
1115+
let mut validator = ValidateBoundVars::new(bound_vars);
11111116
value.visit_with(&mut validator);
11121117
}
1113-
Ok(Binder(value, self.1))
1118+
Ok(Binder { value, bound_vars })
11141119
}
11151120

11161121
/// Wraps a `value` in a binder, using the same bound variables as the
@@ -1126,11 +1131,7 @@ impl<'tcx, T> Binder<'tcx, T> {
11261131
where
11271132
U: TypeVisitable<TyCtxt<'tcx>>,
11281133
{
1129-
if cfg!(debug_assertions) {
1130-
let mut validator = ValidateBoundVars::new(self.bound_vars());
1131-
value.visit_with(&mut validator);
1132-
}
1133-
Binder(value, self.1)
1134+
Binder::bind_with_vars(value, self.bound_vars)
11341135
}
11351136

11361137
/// Unwraps and returns the value within, but only if it contains
@@ -1147,7 +1148,7 @@ impl<'tcx, T> Binder<'tcx, T> {
11471148
where
11481149
T: TypeVisitable<TyCtxt<'tcx>>,
11491150
{
1150-
if self.0.has_escaping_bound_vars() { None } else { Some(self.skip_binder()) }
1151+
if self.value.has_escaping_bound_vars() { None } else { Some(self.skip_binder()) }
11511152
}
11521153

11531154
/// Splits the contents into two things that share the same binder
@@ -1160,22 +1161,23 @@ impl<'tcx, T> Binder<'tcx, T> {
11601161
where
11611162
F: FnOnce(T) -> (U, V),
11621163
{
1163-
let (u, v) = f(self.0);
1164-
(Binder(u, self.1), Binder(v, self.1))
1164+
let Binder { value, bound_vars } = self;
1165+
let (u, v) = f(value);
1166+
(Binder { value: u, bound_vars }, Binder { value: v, bound_vars })
11651167
}
11661168
}
11671169

11681170
impl<'tcx, T> Binder<'tcx, Option<T>> {
11691171
pub fn transpose(self) -> Option<Binder<'tcx, T>> {
1170-
let bound_vars = self.1;
1171-
self.0.map(|v| Binder(v, bound_vars))
1172+
let Binder { value, bound_vars } = self;
1173+
value.map(|value| Binder { value, bound_vars })
11721174
}
11731175
}
11741176

11751177
impl<'tcx, T: IntoIterator> Binder<'tcx, T> {
11761178
pub fn iter(self) -> impl Iterator<Item = ty::Binder<'tcx, T::Item>> {
1177-
let bound_vars = self.1;
1178-
self.0.into_iter().map(|v| Binder(v, bound_vars))
1179+
let Binder { value, bound_vars } = self;
1180+
value.into_iter().map(|value| Binder { value, bound_vars })
11791181
}
11801182
}
11811183

@@ -1184,7 +1186,7 @@ where
11841186
T: IntoDiagnosticArg,
11851187
{
11861188
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
1187-
self.0.into_diagnostic_arg()
1189+
self.value.into_diagnostic_arg()
11881190
}
11891191
}
11901192

0 commit comments

Comments
 (0)