Skip to content

Commit febd59e

Browse files
committed
Auto merge of #109384 - matthiaskrgr:rollup-hu348gs, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #109170 (Set `CMAKE_SYSTEM_NAME` for Linux targets) - #109266 (rustdoc: Correctly merge import's and its target's docs in one more case) - #109267 (Add tests for configure.py) - #109273 (Make `slice::is_sorted_by` implementation nicer) - #109277 (Fix generics_of for impl's RPITIT synthesized associated type) - #109307 (Ignore `Inlined` spans when computing caller location.) - #109364 (Only expect a GAT const param for `type_of` of GAT const arg) - #109365 (Update mdbook) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 13b7aa4 + 58ffabb commit febd59e

File tree

32 files changed

+460
-260
lines changed

32 files changed

+460
-260
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -3103,9 +3103,9 @@ dependencies = [
31033103

31043104
[[package]]
31053105
name = "mdbook"
3106-
version = "0.4.25"
3106+
version = "0.4.28"
31073107
source = "registry+https://github.com/rust-lang/crates.io-index"
3108-
checksum = "d1ed28d5903dde77bd5182645078a37ee57014cac6ccb2d54e1d6496386648e4"
3108+
checksum = "764dcbfc2e5f868bc1b566eb179dff1a06458fd0cff846aae2579392dd3f01a0"
31093109
dependencies = [
31103110
"ammonia",
31113111
"anyhow",

compiler/rustc_codegen_ssa/src/mir/block.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
14751475
) -> OperandRef<'tcx, Bx::Value> {
14761476
let tcx = bx.tcx();
14771477

1478-
let mut span_to_caller_location = |span: Span| {
1478+
let mut span_to_caller_location = |mut span: Span| {
1479+
// Remove `Inlined` marks as they pollute `expansion_cause`.
1480+
while span.is_inlined() {
1481+
span.remove_mark();
1482+
}
14791483
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
14801484
let caller = tcx.sess.source_map().lookup_char_pos(topmost.lo());
14811485
let const_loc = tcx.const_caller_location((

compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
111111
location
112112
}
113113

114-
pub(crate) fn location_triple_for_span(&self, span: Span) -> (Symbol, u32, u32) {
114+
pub(crate) fn location_triple_for_span(&self, mut span: Span) -> (Symbol, u32, u32) {
115+
// Remove `Inlined` marks as they pollute `expansion_cause`.
116+
while span.is_inlined() {
117+
span.remove_mark();
118+
}
115119
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
116120
let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
117121
(

compiler/rustc_hir_analysis/src/astconv/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3152,8 +3152,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
31523152

31533153
debug!("impl_trait_ty_to_ty: generics={:?}", generics);
31543154
let substs = InternalSubsts::for_item(tcx, def_id, |param, _| {
3155-
if let Some(i) = (param.index as usize).checked_sub(generics.parent_count) {
3156-
// Our own parameters are the resolved lifetimes.
3155+
// We use `generics.count() - lifetimes.len()` here instead of `generics.parent_count`
3156+
// since return-position impl trait in trait squashes all of the generics from its source fn
3157+
// into its own generics, so the opaque's "own" params isn't always just lifetimes.
3158+
if let Some(i) = (param.index as usize).checked_sub(generics.count() - lifetimes.len())
3159+
{
3160+
// Resolve our own lifetime parameters.
31573161
let GenericParamDefKind::Lifetime { .. } = param.kind else { bug!() };
31583162
let hir::GenericArg::Lifetime(lifetime) = &lifetimes[i] else { bug!() };
31593163
self.ast_region_to_region(lifetime, None).into()

compiler/rustc_hir_analysis/src/collect/type_of.rs

+40-28
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,11 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
278278
}
279279
TraitItemKind::Const(ty, body_id) => body_id
280280
.and_then(|body_id| {
281-
is_suggestable_infer_ty(ty)
282-
.then(|| infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident, "constant",))
281+
is_suggestable_infer_ty(ty).then(|| {
282+
infer_placeholder_type(
283+
tcx, def_id, body_id, ty.span, item.ident, "constant",
284+
)
285+
})
283286
})
284287
.unwrap_or_else(|| icx.to_ty(ty)),
285288
TraitItemKind::Type(_, Some(ty)) => icx.to_ty(ty),
@@ -335,14 +338,15 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
335338
}
336339
}
337340
ItemKind::TyAlias(self_ty, _) => icx.to_ty(self_ty),
338-
ItemKind::Impl(hir::Impl { self_ty, .. }) => {
339-
match self_ty.find_self_aliases() {
340-
spans if spans.len() > 0 => {
341-
let guar = tcx.sess.emit_err(crate::errors::SelfInImplSelf { span: spans.into(), note: () });
342-
tcx.ty_error(guar)
343-
},
344-
_ => icx.to_ty(*self_ty),
341+
ItemKind::Impl(hir::Impl { self_ty, .. }) => match self_ty.find_self_aliases() {
342+
spans if spans.len() > 0 => {
343+
let guar = tcx.sess.emit_err(crate::errors::SelfInImplSelf {
344+
span: spans.into(),
345+
note: (),
346+
});
347+
tcx.ty_error(guar)
345348
}
349+
_ => icx.to_ty(*self_ty),
346350
},
347351
ItemKind::Fn(..) => {
348352
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
@@ -364,7 +368,10 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
364368
..
365369
}) => {
366370
if in_trait && !tcx.impl_defaultness(owner).has_value() {
367-
span_bug!(tcx.def_span(def_id), "tried to get type of this RPITIT with no definition");
371+
span_bug!(
372+
tcx.def_span(def_id),
373+
"tried to get type of this RPITIT with no definition"
374+
);
368375
}
369376
find_opaque_ty_constraints_for_rpit(tcx, def_id, owner)
370377
}
@@ -453,15 +460,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
453460
tcx.adt_def(tcx.hir().get_parent_item(hir_id)).repr().discr_type().to_ty(tcx)
454461
}
455462

456-
Node::TypeBinding(
457-
TypeBinding {
458-
hir_id: binding_id,
459-
kind: TypeBindingKind::Equality { term: Term::Const(e) },
460-
ident,
461-
..
462-
},
463-
) if let Node::TraitRef(trait_ref) =
464-
tcx.hir().get_parent(*binding_id)
463+
Node::TypeBinding(TypeBinding {
464+
hir_id: binding_id,
465+
kind: TypeBindingKind::Equality { term: Term::Const(e) },
466+
ident,
467+
..
468+
}) if let Node::TraitRef(trait_ref) = tcx.hir().get_parent(*binding_id)
465469
&& e.hir_id == hir_id =>
466470
{
467471
let Some(trait_def_id) = trait_ref.trait_def_id() else {
@@ -475,7 +479,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
475479
def_id.to_def_id(),
476480
);
477481
if let Some(assoc_item) = assoc_item {
478-
tcx.type_of(assoc_item.def_id).subst_identity()
482+
tcx.type_of(assoc_item.def_id)
483+
.no_bound_vars()
484+
.expect("const parameter types cannot be generic")
479485
} else {
480486
// FIXME(associated_const_equality): add a useful error message here.
481487
tcx.ty_error_with_message(
@@ -485,10 +491,13 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
485491
}
486492
}
487493

488-
Node::TypeBinding(
489-
TypeBinding { hir_id: binding_id, gen_args, kind, ident, .. },
490-
) if let Node::TraitRef(trait_ref) =
491-
tcx.hir().get_parent(*binding_id)
494+
Node::TypeBinding(TypeBinding {
495+
hir_id: binding_id,
496+
gen_args,
497+
kind,
498+
ident,
499+
..
500+
}) if let Node::TraitRef(trait_ref) = tcx.hir().get_parent(*binding_id)
492501
&& let Some((idx, _)) =
493502
gen_args.args.iter().enumerate().find(|(_, arg)| {
494503
if let GenericArg::Const(ct) = arg {
@@ -517,15 +526,18 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<Ty<'_>>
517526
},
518527
def_id.to_def_id(),
519528
);
520-
if let Some(param)
521-
= assoc_item.map(|item| &tcx.generics_of(item.def_id).params[idx]).filter(|param| param.kind.is_ty_or_const())
529+
if let Some(assoc_item) = assoc_item
530+
&& let param = &tcx.generics_of(assoc_item.def_id).params[idx]
531+
&& matches!(param.kind, ty::GenericParamDefKind::Const { .. })
522532
{
523-
tcx.type_of(param.def_id).subst_identity()
533+
tcx.type_of(param.def_id)
534+
.no_bound_vars()
535+
.expect("const parameter types cannot be generic")
524536
} else {
525537
// FIXME(associated_const_equality): add a useful error message here.
526538
tcx.ty_error_with_message(
527539
DUMMY_SP,
528-
"Could not find associated const on trait",
540+
"Could not find const param on associated item",
529541
)
530542
}
531543
}

compiler/rustc_span/src/hygiene.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ impl Span {
880880
pub fn fresh_expansion(self, expn_id: LocalExpnId) -> Span {
881881
HygieneData::with(|data| {
882882
self.with_ctxt(data.apply_mark(
883-
SyntaxContext::root(),
883+
self.ctxt(),
884884
expn_id.to_expn_id(),
885885
Transparency::Transparent,
886886
))

compiler/rustc_ty_utils/src/assoc.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ fn associated_type_for_impl_trait_in_impl(
396396
impl_assoc_ty.impl_defaultness(tcx.impl_defaultness(impl_fn_def_id));
397397

398398
// Copy generics_of the trait's associated item but the impl as the parent.
399+
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) resolves to the trait instead of the impl
400+
// generics.
399401
impl_assoc_ty.generics_of({
400402
let trait_assoc_generics = tcx.generics_of(trait_assoc_def_id);
401403
let trait_assoc_parent_count = trait_assoc_generics.parent_count;
@@ -404,16 +406,10 @@ fn associated_type_for_impl_trait_in_impl(
404406
let parent_generics = tcx.generics_of(impl_def_id);
405407
let parent_count = parent_generics.parent_count + parent_generics.params.len();
406408

407-
let mut impl_fn_params = tcx.generics_of(impl_fn_def_id).params.clone();
408-
409409
for param in &mut params {
410-
param.index = param.index + parent_count as u32 + impl_fn_params.len() as u32
411-
- trait_assoc_parent_count as u32;
410+
param.index = param.index + parent_count as u32 - trait_assoc_parent_count as u32;
412411
}
413412

414-
impl_fn_params.extend(params);
415-
params = impl_fn_params;
416-
417413
let param_def_id_to_index =
418414
params.iter().map(|param| (param.def_id, param.index)).collect();
419415

library/core/src/slice/iter.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ iterator! {struct Iter -> *const T, &'a T, const, {/* no mut */}, {
132132
Self: Sized,
133133
F: FnMut(&Self::Item, &Self::Item) -> Option<Ordering>,
134134
{
135-
self.as_slice().windows(2).all(|w| {
136-
compare(&&w[0], &&w[1]).map(|o| o != Ordering::Greater).unwrap_or(false)
137-
})
135+
self.as_slice().is_sorted_by(|a, b| compare(&a, &b))
138136
}
139137
}}
140138

library/core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3822,7 +3822,7 @@ impl<T> [T] {
38223822
where
38233823
F: FnMut(&'a T, &'a T) -> Option<Ordering>,
38243824
{
3825-
self.iter().is_sorted_by(|a, b| compare(*a, *b))
3825+
self.array_windows().all(|[a, b]| compare(a, b).map_or(false, Ordering::is_le))
38263826
}
38273827

38283828
/// Checks if the elements of this slice are sorted using the given key extraction function.

src/bootstrap/bootstrap_test.py

+39
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from shutil import rmtree
1212

1313
import bootstrap
14+
import configure
1415

1516

1617
class VerifyTestCase(unittest.TestCase):
@@ -74,12 +75,50 @@ def test_same_dates(self):
7475
self.assertFalse(self.build.program_out_of_date(self.rustc_stamp_path, self.key))
7576

7677

78+
class GenerateAndParseConfig(unittest.TestCase):
79+
"""Test that we can serialize and deserialize a config.toml file"""
80+
def serialize_and_parse(self, args):
81+
from io import StringIO
82+
83+
section_order, sections, targets = configure.parse_args(args)
84+
buffer = StringIO()
85+
configure.write_config_toml(buffer, section_order, targets, sections)
86+
build = bootstrap.RustBuild()
87+
build.config_toml = buffer.getvalue()
88+
89+
try:
90+
import tomllib
91+
# Verify this is actually valid TOML.
92+
tomllib.loads(build.config_toml)
93+
except ImportError:
94+
print("warning: skipping TOML validation, need at least python 3.11", file=sys.stderr)
95+
return build
96+
97+
def test_no_args(self):
98+
build = self.serialize_and_parse([])
99+
self.assertEqual(build.get_toml("changelog-seen"), '2')
100+
self.assertIsNone(build.get_toml("llvm.download-ci-llvm"))
101+
102+
def test_set_section(self):
103+
build = self.serialize_and_parse(["--set", "llvm.download-ci-llvm"])
104+
self.assertEqual(build.get_toml("download-ci-llvm", section="llvm"), 'true')
105+
106+
def test_set_target(self):
107+
build = self.serialize_and_parse(["--set", "target.x86_64-unknown-linux-gnu.cc=gcc"])
108+
self.assertEqual(build.get_toml("cc", section="target.x86_64-unknown-linux-gnu"), 'gcc')
109+
110+
# Uncomment when #108928 is fixed.
111+
# def test_set_top_level(self):
112+
# build = self.serialize_and_parse(["--set", "profile=compiler"])
113+
# self.assertEqual(build.get_toml("profile"), 'compiler')
114+
77115
if __name__ == '__main__':
78116
SUITE = unittest.TestSuite()
79117
TEST_LOADER = unittest.TestLoader()
80118
SUITE.addTest(doctest.DocTestSuite(bootstrap))
81119
SUITE.addTests([
82120
TEST_LOADER.loadTestsFromTestCase(VerifyTestCase),
121+
TEST_LOADER.loadTestsFromTestCase(GenerateAndParseConfig),
83122
TEST_LOADER.loadTestsFromTestCase(ProgramOutOfDate)])
84123

85124
RUNNER = unittest.TextTestRunner(stream=sys.stdout, verbosity=2)

0 commit comments

Comments
 (0)