Skip to content

Commit e91364b

Browse files
committed
Auto merge of #109376 - matthiaskrgr:rollup-0aut57k, r=matthiaskrgr
Rollup of 13 pull requests Successful merges: - #109249 (Update names/comments for new return-position impl trait in trait lowering strategy) - #109259 (rustdoc: Fix missing private inlining) - #109269 (rustdoc: cleanup some intermediate allocs) - #109301 (fix: fix ICE in `custom-test-frameworks` feature) - #109319 (Add test for `c_variadic` in rustdoc-json) - #109323 (Ignore files in .gitignore in mir opt check) - #109331 (rustdoc: implement bag semantics for function parameter search) - #109337 (Improve `Iterator::collect_into` documentation) - #109351 (rustdoc: Remove footnote references from doc summary) - #109353 (Fix wrong crate name in custom MIR docs) - #109362 (Split `items` from `-Zmeta-stats` in two.) - #109370 (fix ClashingExternDeclarations lint ICE) - #109375 (rustdoc: Fix improper escaping of deprecation reasons) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9d0eac4 + 1309235 commit e91364b

File tree

31 files changed

+400
-162
lines changed

31 files changed

+400
-162
lines changed

compiler/rustc_builtin_macros/src/test.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,23 @@ pub fn expand_test_case(
3333
}
3434

3535
let sp = ecx.with_def_site_ctxt(attr_sp);
36-
let mut item = anno_item.expect_item();
36+
let (mut item, is_stmt) = match anno_item {
37+
Annotatable::Item(item) => (item, false),
38+
Annotatable::Stmt(stmt) if let ast::StmtKind::Item(_) = stmt.kind => if let ast::StmtKind::Item(i) = stmt.into_inner().kind {
39+
(i, true)
40+
} else {
41+
unreachable!()
42+
},
43+
_ => {
44+
ecx.struct_span_err(
45+
anno_item.span(),
46+
"`#[test_case]` attribute is only allowed on items",
47+
)
48+
.emit();
49+
50+
return vec![];
51+
}
52+
};
3753
item = item.map(|mut item| {
3854
let test_path_symbol = Symbol::intern(&item_path(
3955
// skip the name of the root module
@@ -50,7 +66,13 @@ pub fn expand_test_case(
5066
item
5167
});
5268

53-
return vec![Annotatable::Item(item)];
69+
let ret = if is_stmt {
70+
Annotatable::Stmt(P(ecx.stmt_item(item.span, item)))
71+
} else {
72+
Annotatable::Item(item)
73+
};
74+
75+
vec![ret]
5476
}
5577

5678
pub fn expand_test(

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3068,7 +3068,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
30683068
// generate the def_id of an associated type for the trait and return as
30693069
// type a projection.
30703070
let def_id = if in_trait && tcx.lower_impl_trait_in_trait_to_assoc_ty() {
3071-
tcx.associated_item_for_impl_trait_in_trait(local_def_id).to_def_id()
3071+
tcx.associated_type_for_impl_trait_in_trait(local_def_id).to_def_id()
30723072
} else {
30733073
local_def_id.to_def_id()
30743074
};

compiler/rustc_lint/src/builtin.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -2781,8 +2781,7 @@ impl ClashingExternDeclarations {
27812781

27822782
// Given a transparent newtype, reach through and grab the inner
27832783
// type unless the newtype makes the type non-null.
2784-
let non_transparent_ty = |ty: Ty<'tcx>| -> Ty<'tcx> {
2785-
let mut ty = ty;
2784+
let non_transparent_ty = |mut ty: Ty<'tcx>| -> Ty<'tcx> {
27862785
loop {
27872786
if let ty::Adt(def, substs) = *ty.kind() {
27882787
let is_transparent = def.repr().transparent();
@@ -2792,14 +2791,14 @@ impl ClashingExternDeclarations {
27922791
ty, is_transparent, is_non_null
27932792
);
27942793
if is_transparent && !is_non_null {
2795-
debug_assert!(def.variants().len() == 1);
2794+
debug_assert_eq!(def.variants().len(), 1);
27962795
let v = &def.variant(VariantIdx::new(0));
2797-
ty = transparent_newtype_field(tcx, v)
2798-
.expect(
2799-
"single-variant transparent structure with zero-sized field",
2800-
)
2801-
.ty(tcx, substs);
2802-
continue;
2796+
// continue with `ty`'s non-ZST field,
2797+
// otherwise `ty` is a ZST and we can return
2798+
if let Some(field) = transparent_newtype_field(tcx, v) {
2799+
ty = field.ty(tcx, substs);
2800+
continue;
2801+
}
28032802
}
28042803
}
28052804
debug!("non_transparent_ty -> {:?}", ty);
@@ -2813,10 +2812,8 @@ impl ClashingExternDeclarations {
28132812
if !seen_types.insert((a, b)) {
28142813
// We've encountered a cycle. There's no point going any further -- the types are
28152814
// structurally the same.
2816-
return true;
2817-
}
2818-
let tcx = cx.tcx;
2819-
if a == b {
2815+
true
2816+
} else if a == b {
28202817
// All nominally-same types are structurally same, too.
28212818
true
28222819
} else {

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ provide! { tcx, def_id, other, cdata,
254254
.process_decoded(tcx, || panic!("{def_id:?} does not have trait_impl_trait_tys")))
255255
}
256256

257-
associated_items_for_impl_trait_in_trait => { table_defaulted_array }
257+
associated_types_for_impl_traits_in_associated_fn => { table_defaulted_array }
258258

259259
visibility => { cdata.get_visibility(def_id.index) }
260260
adt_def => { cdata.get_adt_def(def_id.index, tcx) }

compiler/rustc_metadata/src/rmeta/encoder.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
609609

610610
_ = stat!("mir", || self.encode_mir());
611611

612-
_ = stat!("items", || {
613-
self.encode_def_ids();
614-
self.encode_info_for_items();
615-
});
612+
_ = stat!("def-ids", || self.encode_def_ids());
613+
614+
_ = stat!("items", || self.encode_info_for_items());
616615

617616
let interpret_alloc_index = stat!("interpret-alloc-index", || {
618617
let mut interpret_alloc_index = Vec::new();
@@ -1198,8 +1197,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11981197
record!(self.tables.trait_impl_trait_tys[def_id] <- table);
11991198
}
12001199
if should_encode_fn_impl_trait_in_trait(tcx, def_id) {
1201-
let table = tcx.associated_items_for_impl_trait_in_trait(def_id);
1202-
record_defaulted_array!(self.tables.associated_items_for_impl_trait_in_trait[def_id] <- table);
1200+
let table = tcx.associated_types_for_impl_traits_in_associated_fn(def_id);
1201+
record_defaulted_array!(self.tables.associated_types_for_impl_traits_in_associated_fn[def_id] <- table);
12031202
}
12041203
}
12051204

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ define_tables! {
354354
explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Predicate<'static>, Span)>>,
355355
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
356356
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
357-
associated_items_for_impl_trait_in_trait: Table<DefIndex, LazyArray<DefId>>,
357+
associated_types_for_impl_traits_in_associated_fn: Table<DefIndex, LazyArray<DefId>>,
358358
opt_rpitit_info: Table<DefIndex, Option<LazyValue<ty::ImplTraitInTraitData>>>,
359359
unused_generic_params: Table<DefIndex, UnusedGenericParams>,
360360

compiler/rustc_middle/src/query/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -785,15 +785,15 @@ rustc_queries! {
785785
/// if `fn_def_id` is the def id of a function defined inside an impl that implements a trait, then it
786786
/// creates and returns the associated items that correspond to each impl trait in return position
787787
/// of the implemented trait.
788-
query associated_items_for_impl_trait_in_trait(fn_def_id: DefId) -> &'tcx [DefId] {
788+
query associated_types_for_impl_traits_in_associated_fn(fn_def_id: DefId) -> &'tcx [DefId] {
789789
desc { |tcx| "creating associated items for impl trait in trait returned by `{}`", tcx.def_path_str(fn_def_id) }
790790
cache_on_disk_if { fn_def_id.is_local() }
791791
separate_provide_extern
792792
}
793793

794794
/// Given an impl trait in trait `opaque_ty_def_id`, create and return the corresponding
795795
/// associated item.
796-
query associated_item_for_impl_trait_in_trait(opaque_ty_def_id: LocalDefId) -> LocalDefId {
796+
query associated_type_for_impl_trait_in_trait(opaque_ty_def_id: LocalDefId) -> LocalDefId {
797797
desc { |tcx| "creates the associated item corresponding to the opaque type `{}`", tcx.def_path_str(opaque_ty_def_id.to_def_id()) }
798798
cache_on_disk_if { true }
799799
separate_provide_extern

compiler/rustc_middle/src/ty/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2579,7 +2579,9 @@ impl<'tcx> TyCtxt<'tcx> {
25792579
let Some(trait_item_def_id) = item.trait_item_def_id else { return false; };
25802580

25812581
if self.lower_impl_trait_in_trait_to_assoc_ty() {
2582-
return !self.associated_items_for_impl_trait_in_trait(trait_item_def_id).is_empty();
2582+
return !self
2583+
.associated_types_for_impl_traits_in_associated_fn(trait_item_def_id)
2584+
.is_empty();
25832585
}
25842586

25852587
// FIXME(RPITIT): This does a somewhat manual walk through the signature

compiler/rustc_ty_utils/src/assoc.rs

+37-24
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
1111
associated_item,
1212
associated_item_def_ids,
1313
associated_items,
14-
associated_items_for_impl_trait_in_trait,
15-
associated_item_for_impl_trait_in_trait,
14+
associated_types_for_impl_traits_in_associated_fn,
15+
associated_type_for_impl_trait_in_trait,
1616
impl_item_implementor_ids,
1717
..*providers
1818
};
@@ -24,7 +24,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
2424
hir::ItemKind::Trait(.., ref trait_item_refs) => {
2525
if tcx.lower_impl_trait_in_trait_to_assoc_ty() {
2626
// We collect RPITITs for each trait method's return type and create a
27-
// corresponding associated item using associated_items_for_impl_trait_in_trait
27+
// corresponding associated item using associated_types_for_impl_traits_in_associated_fn
2828
// query.
2929
tcx.arena.alloc_from_iter(
3030
trait_item_refs
@@ -39,7 +39,9 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
3939
.flat_map(|trait_item_ref| {
4040
let trait_fn_def_id =
4141
trait_item_ref.id.owner_id.def_id.to_def_id();
42-
tcx.associated_items_for_impl_trait_in_trait(trait_fn_def_id)
42+
tcx.associated_types_for_impl_traits_in_associated_fn(
43+
trait_fn_def_id,
44+
)
4345
})
4446
.map(|def_id| *def_id),
4547
),
@@ -56,7 +58,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
5658
if tcx.lower_impl_trait_in_trait_to_assoc_ty() {
5759
// We collect RPITITs for each trait method's return type, on the impl side too and
5860
// create a corresponding associated item using
59-
// associated_items_for_impl_trait_in_trait query.
61+
// associated_types_for_impl_traits_in_associated_fn query.
6062
tcx.arena.alloc_from_iter(
6163
impl_
6264
.items
@@ -72,7 +74,9 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
7274
.flat_map(|impl_item_ref| {
7375
let impl_fn_def_id =
7476
impl_item_ref.id.owner_id.def_id.to_def_id();
75-
tcx.associated_items_for_impl_trait_in_trait(impl_fn_def_id)
77+
tcx.associated_types_for_impl_traits_in_associated_fn(
78+
impl_fn_def_id,
79+
)
7680
})
7781
.map(|def_id| *def_id)
7882
})),
@@ -176,13 +180,19 @@ fn associated_item_from_impl_item_ref(impl_item_ref: &hir::ImplItemRef) -> ty::A
176180
}
177181
}
178182

179-
/// Given an `fn_def_id` of a trait or of an impl that implements a given trait:
180-
/// if `fn_def_id` is the def id of a function defined inside a trait, then it creates and returns
181-
/// the associated items that correspond to each impl trait in return position for that trait.
182-
/// if `fn_def_id` is the def id of a function defined inside an impl that implements a trait, then it
183-
/// creates and returns the associated items that correspond to each impl trait in return position
184-
/// of the implemented trait.
185-
fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -> &'_ [DefId] {
183+
/// Given an `fn_def_id` of a trait or a trait implementation:
184+
///
185+
/// if `fn_def_id` is a function defined inside a trait, then it synthesizes
186+
/// a new def id corresponding to a new associated type for each return-
187+
/// position `impl Trait` in the signature.
188+
///
189+
/// if `fn_def_id` is a function inside of an impl, then for each synthetic
190+
/// associated type generated for the corresponding trait function described
191+
/// above, synthesize a corresponding associated type in the impl.
192+
fn associated_types_for_impl_traits_in_associated_fn(
193+
tcx: TyCtxt<'_>,
194+
fn_def_id: DefId,
195+
) -> &'_ [DefId] {
186196
let parent_def_id = tcx.parent(fn_def_id);
187197

188198
match tcx.def_kind(parent_def_id) {
@@ -206,7 +216,7 @@ fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -
206216
visitor.visit_fn_ret_ty(output);
207217

208218
tcx.arena.alloc_from_iter(visitor.rpits.iter().map(|opaque_ty_def_id| {
209-
tcx.associated_item_for_impl_trait_in_trait(opaque_ty_def_id).to_def_id()
219+
tcx.associated_type_for_impl_trait_in_trait(opaque_ty_def_id).to_def_id()
210220
}))
211221
} else {
212222
&[]
@@ -217,9 +227,9 @@ fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -
217227
let Some(trait_fn_def_id) = tcx.associated_item(fn_def_id).trait_item_def_id else { return &[] };
218228

219229
tcx.arena.alloc_from_iter(
220-
tcx.associated_items_for_impl_trait_in_trait(trait_fn_def_id).iter().map(
230+
tcx.associated_types_for_impl_traits_in_associated_fn(trait_fn_def_id).iter().map(
221231
move |trait_assoc_def_id| {
222-
impl_associated_item_for_impl_trait_in_trait(
232+
associated_type_for_impl_trait_in_impl(
223233
tcx,
224234
trait_assoc_def_id.expect_local(),
225235
fn_def_id.expect_local(),
@@ -231,16 +241,17 @@ fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -
231241
}
232242

233243
def_kind => bug!(
234-
"associated_items_for_impl_trait_in_trait: {:?} should be Trait or Impl but is {:?}",
244+
"associated_types_for_impl_traits_in_associated_fn: {:?} should be Trait or Impl but is {:?}",
235245
parent_def_id,
236246
def_kind
237247
),
238248
}
239249
}
240250

241-
/// Given an `opaque_ty_def_id` corresponding to an impl trait in trait, create and return the
242-
/// corresponding associated item.
243-
fn associated_item_for_impl_trait_in_trait(
251+
/// Given an `opaque_ty_def_id` corresponding to an `impl Trait` in an associated
252+
/// function from a trait, synthesize an associated type for that `impl Trait`
253+
/// that inherits properties that we infer from the method and the opaque type.
254+
fn associated_type_for_impl_trait_in_trait(
244255
tcx: TyCtxt<'_>,
245256
opaque_ty_def_id: LocalDefId,
246257
) -> LocalDefId {
@@ -335,10 +346,12 @@ fn associated_item_for_impl_trait_in_trait(
335346
local_def_id
336347
}
337348

338-
/// Given an `trait_assoc_def_id` that corresponds to a previously synthesized impl trait in trait
339-
/// into an associated type and an `impl_def_id` corresponding to an impl block, create and return
340-
/// the corresponding associated item inside the impl block.
341-
fn impl_associated_item_for_impl_trait_in_trait(
349+
/// Given an `trait_assoc_def_id` corresponding to an associated item synthesized
350+
/// from an `impl Trait` in an associated function from a trait, and an
351+
/// `impl_fn_def_id` that represents an implementation of the associated function
352+
/// that the `impl Trait` comes from, synthesize an associated type for that `impl Trait`
353+
/// that inherits properties that we infer from the method and the associated type.
354+
fn associated_type_for_impl_trait_in_impl(
342355
tcx: TyCtxt<'_>,
343356
trait_assoc_def_id: LocalDefId,
344357
impl_fn_def_id: LocalDefId,

library/core/src/intrinsics/mir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//!
99
//! The documentation for this module describes how to use this feature. If you are interested in
1010
//! hacking on the implementation, most of that documentation lives at
11-
//! `rustc_mir_building/src/build/custom/mod.rs`.
11+
//! `rustc_mir_build/src/build/custom/mod.rs`.
1212
//!
1313
//! Typical usage will look like this:
1414
//!

library/core/src/iter/traits/iterator.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2003,7 +2003,7 @@ pub trait Iterator {
20032003
/// a.iter().map(|&x| x * 2).collect_into(&mut vec);
20042004
/// a.iter().map(|&x| x * 10).collect_into(&mut vec);
20052005
///
2006-
/// assert_eq!(vec![0, 1, 2, 4, 6, 10, 20, 30], vec);
2006+
/// assert_eq!(vec, vec![0, 1, 2, 4, 6, 10, 20, 30]);
20072007
/// ```
20082008
///
20092009
/// `Vec` can have a manual set capacity to avoid reallocating it:
@@ -2018,7 +2018,7 @@ pub trait Iterator {
20182018
/// a.iter().map(|&x| x * 10).collect_into(&mut vec);
20192019
///
20202020
/// assert_eq!(6, vec.capacity());
2021-
/// println!("{:?}", vec);
2021+
/// assert_eq!(vec, vec![2, 4, 6, 10, 20, 30]);
20222022
/// ```
20232023
///
20242024
/// The returned mutable reference can be used to continue the call chain:
@@ -2032,12 +2032,12 @@ pub trait Iterator {
20322032
/// let count = a.iter().collect_into(&mut vec).iter().count();
20332033
///
20342034
/// assert_eq!(count, vec.len());
2035-
/// println!("Vec len is {}", count);
2035+
/// assert_eq!(vec, vec![1, 2, 3]);
20362036
///
20372037
/// let count = a.iter().collect_into(&mut vec).iter().count();
20382038
///
20392039
/// assert_eq!(count, vec.len());
2040-
/// println!("Vec len now is {}", count);
2040+
/// assert_eq!(vec, vec![1, 2, 3, 1, 2, 3]);
20412041
/// ```
20422042
#[inline]
20432043
#[unstable(feature = "iter_collect_into", reason = "new API", issue = "94780")]

src/librustdoc/html/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>(
14801480
debug!("path={:?}", path);
14811481
// modified from `resolved_path()` to work with `DefPathData`
14821482
let last_name = path.data.last().unwrap().data.get_opt_name().unwrap();
1483-
let anchor = anchor(vis_did, last_name, cx).to_string();
1483+
let anchor = anchor(vis_did, last_name, cx);
14841484

14851485
let mut s = "pub(in ".to_owned();
14861486
for seg in &path.data[..path.data.len() - 1] {

src/librustdoc/html/markdown.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,15 @@ fn check_if_allowed_tag(t: &Tag<'_>) -> bool {
556556
}
557557

558558
fn is_forbidden_tag(t: &Tag<'_>) -> bool {
559-
matches!(t, Tag::CodeBlock(_) | Tag::Table(_) | Tag::TableHead | Tag::TableRow | Tag::TableCell)
559+
matches!(
560+
t,
561+
Tag::CodeBlock(_)
562+
| Tag::Table(_)
563+
| Tag::TableHead
564+
| Tag::TableRow
565+
| Tag::TableCell
566+
| Tag::FootnoteDefinition(_)
567+
)
560568
}
561569

562570
impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
@@ -589,6 +597,10 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
589597
is_start = false;
590598
check_if_allowed_tag(c)
591599
}
600+
Event::FootnoteReference(_) => {
601+
self.skipped_tags += 1;
602+
false
603+
}
592604
_ => true,
593605
};
594606
if !is_allowed_tag {

src/librustdoc/html/render/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl<'tcx> Context<'tcx> {
352352
},
353353
);
354354

355-
path = href.into_inner().to_string_lossy().to_string();
355+
path = href.into_inner().to_string_lossy().into_owned();
356356

357357
if let Some(c) = path.as_bytes().last() && *c != b'/' {
358358
path.push('/');

0 commit comments

Comments
 (0)