Skip to content

Commit 841d57c

Browse files
committed
Auto merge of #148308 - GuillaumeGomez:rollup-mxz6q4j, r=GuillaumeGomez
Rollup of 4 pull requests Successful merges: - #144291 (Constify trait aliases) - #147633 (Add new `--bypass-ignore-backends` option) - #148262 (Fix types being marked as dead when they are inferred generic arguments) - #148268 (rustdoc: fix `--emit=dep-info` on scraped examples) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d5419f1 + a3633c3 commit 841d57c

File tree

65 files changed

+380
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+380
-115
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3540,8 +3540,9 @@ impl Item {
35403540
ItemKind::Const(i) => Some(&i.generics),
35413541
ItemKind::Fn(i) => Some(&i.generics),
35423542
ItemKind::TyAlias(i) => Some(&i.generics),
3543-
ItemKind::TraitAlias(_, generics, _)
3544-
| ItemKind::Enum(_, generics, _)
3543+
ItemKind::TraitAlias(i) => Some(&i.generics),
3544+
3545+
ItemKind::Enum(_, generics, _)
35453546
| ItemKind::Struct(_, generics, _)
35463547
| ItemKind::Union(_, generics, _) => Some(&generics),
35473548
ItemKind::Trait(i) => Some(&i.generics),
@@ -3623,6 +3624,15 @@ impl Default for FnHeader {
36233624
}
36243625
}
36253626

3627+
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
3628+
pub struct TraitAlias {
3629+
pub constness: Const,
3630+
pub ident: Ident,
3631+
pub generics: Generics,
3632+
#[visitable(extra = BoundKind::Bound)]
3633+
pub bounds: GenericBounds,
3634+
}
3635+
36263636
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
36273637
pub struct Trait {
36283638
pub constness: Const,
@@ -3798,7 +3808,7 @@ pub enum ItemKind {
37983808
/// Trait alias.
37993809
///
38003810
/// E.g., `trait Foo = Bar + Quux;`.
3801-
TraitAlias(Ident, Generics, GenericBounds),
3811+
TraitAlias(Box<TraitAlias>),
38023812
/// An implementation.
38033813
///
38043814
/// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`.
@@ -3831,7 +3841,7 @@ impl ItemKind {
38313841
| ItemKind::Struct(ident, ..)
38323842
| ItemKind::Union(ident, ..)
38333843
| ItemKind::Trait(box Trait { ident, .. })
3834-
| ItemKind::TraitAlias(ident, ..)
3844+
| ItemKind::TraitAlias(box TraitAlias { ident, .. })
38353845
| ItemKind::MacroDef(ident, _)
38363846
| ItemKind::Delegation(box Delegation { ident, .. }) => Some(ident),
38373847

@@ -3888,7 +3898,7 @@ impl ItemKind {
38883898
| Self::Struct(_, generics, _)
38893899
| Self::Union(_, generics, _)
38903900
| Self::Trait(box Trait { generics, .. })
3891-
| Self::TraitAlias(_, generics, _)
3901+
| Self::TraitAlias(box TraitAlias { generics, .. })
38923902
| Self::Impl(Impl { generics, .. }) => Some(generics),
38933903
_ => None,
38943904
}
@@ -4050,8 +4060,8 @@ mod size_asserts {
40504060
static_assert_size!(GenericBound, 88);
40514061
static_assert_size!(Generics, 40);
40524062
static_assert_size!(Impl, 64);
4053-
static_assert_size!(Item, 144);
4054-
static_assert_size!(ItemKind, 80);
4063+
static_assert_size!(Item, 136);
4064+
static_assert_size!(ItemKind, 72);
40554065
static_assert_size!(LitKind, 24);
40564066
static_assert_size!(Local, 96);
40574067
static_assert_size!(MetaItemLit, 40);

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,8 @@ macro_rules! common_visitor_and_walkers {
833833
visit_visitable!($($mut)? vis, impl_),
834834
ItemKind::Trait(trait_) =>
835835
visit_visitable!($($mut)? vis, trait_),
836-
ItemKind::TraitAlias(ident, generics, bounds) => {
837-
visit_visitable!($($mut)? vis, ident, generics);
836+
ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds}) => {
837+
visit_visitable!($($mut)? vis, constness, ident, generics);
838838
visit_visitable_with!($($mut)? vis, bounds, BoundKind::Bound)
839839
}
840840
ItemKind::MacCall(m) =>

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
415415
);
416416
hir::ItemKind::Trait(constness, *is_auto, safety, ident, generics, bounds, items)
417417
}
418-
ItemKind::TraitAlias(ident, generics, bounds) => {
418+
ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds }) => {
419+
let constness = self.lower_constness(*constness);
419420
let ident = self.lower_ident(*ident);
420421
let (generics, bounds) = self.lower_generics(
421422
generics,
@@ -429,7 +430,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
429430
)
430431
},
431432
);
432-
hir::ItemKind::TraitAlias(ident, generics, bounds)
433+
hir::ItemKind::TraitAlias(constness, ident, generics, bounds)
433434
}
434435
ItemKind::MacroDef(ident, MacroDef { body, macro_rules }) => {
435436
let ident = self.lower_ident(*ident);

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11921192
walk_list!(this, visit_assoc_item, items, AssocCtxt::Trait);
11931193
});
11941194
}
1195+
ItemKind::TraitAlias(box TraitAlias { constness, generics, bounds, .. }) => {
1196+
let disallowed = matches!(constness, ast::Const::No)
1197+
.then(|| TildeConstReason::Trait { span: item.span });
1198+
self.with_tilde_const(disallowed, |this| {
1199+
this.visit_generics(generics);
1200+
walk_list!(this, visit_param_bound, bounds, BoundKind::SuperTraits)
1201+
});
1202+
}
11951203
ItemKind::Mod(safety, ident, mod_kind) => {
11961204
if let &Safety::Unsafe(span) = safety {
11971205
self.dcx().emit_err(errors::UnsafeItem { span, kind: "module" });

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use ast::StaticItem;
22
use itertools::{Itertools, Position};
3-
use rustc_ast as ast;
4-
use rustc_ast::ModKind;
3+
use rustc_ast::{self as ast, ModKind, TraitAlias};
54
use rustc_span::Ident;
65

76
use crate::pp::BoxMarker;
@@ -386,8 +385,11 @@ impl<'a> State<'a> {
386385
let empty = item.attrs.is_empty() && items.is_empty();
387386
self.bclose(item.span, empty, cb);
388387
}
389-
ast::ItemKind::TraitAlias(ident, generics, bounds) => {
390-
let (cb, ib) = self.head(visibility_qualified(&item.vis, "trait"));
388+
ast::ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds }) => {
389+
let (cb, ib) = self.head("");
390+
self.print_visibility(&item.vis);
391+
self.print_constness(*constness);
392+
self.word_nbsp("trait");
391393
self.print_ident(*ident);
392394
self.print_generic_params(&generics.params);
393395
self.nbsp();

compiler/rustc_hir/src/hir.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,8 +4151,8 @@ impl<'hir> Item<'hir> {
41514151
ItemKind::Trait(constness, is_auto, safety, ident, generics, bounds, items),
41524152
(*constness, *is_auto, *safety, *ident, generics, bounds, items);
41534153

4154-
expect_trait_alias, (Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
4155-
ItemKind::TraitAlias(ident, generics, bounds), (*ident, generics, bounds);
4154+
expect_trait_alias, (Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
4155+
ItemKind::TraitAlias(constness, ident, generics, bounds), (*constness, *ident, generics, bounds);
41564156

41574157
expect_impl, &Impl<'hir>, ItemKind::Impl(imp), imp;
41584158
}
@@ -4329,7 +4329,7 @@ pub enum ItemKind<'hir> {
43294329
&'hir [TraitItemId],
43304330
),
43314331
/// A trait alias.
4332-
TraitAlias(Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
4332+
TraitAlias(Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
43334333

43344334
/// An implementation, e.g., `impl<A> Trait for Foo { .. }`.
43354335
Impl(Impl<'hir>),
@@ -4374,7 +4374,7 @@ impl ItemKind<'_> {
43744374
| ItemKind::Struct(ident, ..)
43754375
| ItemKind::Union(ident, ..)
43764376
| ItemKind::Trait(_, _, _, ident, ..)
4377-
| ItemKind::TraitAlias(ident, ..) => Some(ident),
4377+
| ItemKind::TraitAlias(_, ident, ..) => Some(ident),
43784378

43794379
ItemKind::Use(_, UseKind::Glob | UseKind::ListStem)
43804380
| ItemKind::ForeignMod { .. }
@@ -4392,7 +4392,7 @@ impl ItemKind<'_> {
43924392
| ItemKind::Struct(_, generics, _)
43934393
| ItemKind::Union(_, generics, _)
43944394
| ItemKind::Trait(_, _, _, _, generics, _, _)
4395-
| ItemKind::TraitAlias(_, generics, _)
4395+
| ItemKind::TraitAlias(_, _, generics, _)
43964396
| ItemKind::Impl(Impl { generics, .. }) => generics,
43974397
_ => return None,
43984398
})

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
626626
walk_list!(visitor, visit_param_bound, bounds);
627627
walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
628628
}
629-
ItemKind::TraitAlias(ident, ref generics, bounds) => {
629+
ItemKind::TraitAlias(_constness, ident, ref generics, bounds) => {
630630
try_visit!(visitor.visit_ident(ident));
631631
try_visit!(visitor.visit_generics(generics));
632632
walk_list!(visitor, visit_param_bound, bounds);

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
847847
hir::ItemKind::Trait(constness, is_auto, safety, ..) => {
848848
(constness, false, is_auto == hir::IsAuto::Yes, safety)
849849
}
850-
hir::ItemKind::TraitAlias(..) => (hir::Constness::NotConst, true, false, hir::Safety::Safe),
850+
hir::ItemKind::TraitAlias(constness, ..) => (constness, true, false, hir::Safety::Safe),
851851
_ => span_bug!(item.span, "trait_def_of_item invoked on non-trait"),
852852
};
853853

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
167167
}
168168
}
169169
ItemKind::Trait(_, _, _, _, _, self_bounds, ..)
170-
| ItemKind::TraitAlias(_, _, self_bounds) => {
170+
| ItemKind::TraitAlias(_, _, _, self_bounds) => {
171171
is_trait = Some((self_bounds, item.span));
172172
}
173173
_ => {}
@@ -654,7 +654,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
654654

655655
let (generics, superbounds) = match item.kind {
656656
hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits),
657-
hir::ItemKind::TraitAlias(_, generics, supertraits) => (generics, supertraits),
657+
hir::ItemKind::TraitAlias(_, _, generics, supertraits) => (generics, supertraits),
658658
_ => span_bug!(item.span, "super_predicates invoked on non-trait"),
659659
};
660660

@@ -1032,7 +1032,10 @@ pub(super) fn const_conditions<'tcx>(
10321032
hir::ItemKind::Impl(impl_) => (impl_.generics, None, false),
10331033
hir::ItemKind::Fn { generics, .. } => (generics, None, false),
10341034
hir::ItemKind::Trait(_, _, _, _, generics, supertraits, _) => {
1035-
(generics, Some((item.owner_id.def_id, supertraits)), false)
1035+
(generics, Some((Some(item.owner_id.def_id), supertraits)), false)
1036+
}
1037+
hir::ItemKind::TraitAlias(_, _, generics, supertraits) => {
1038+
(generics, Some((None, supertraits)), false)
10361039
}
10371040
_ => bug!("const_conditions called on wrong item: {def_id:?}"),
10381041
},
@@ -1089,12 +1092,14 @@ pub(super) fn const_conditions<'tcx>(
10891092
}
10901093

10911094
if let Some((def_id, supertraits)) = trait_def_id_and_supertraits {
1092-
// We've checked above that the trait is conditionally const.
1093-
bounds.push((
1094-
ty::Binder::dummy(ty::TraitRef::identity(tcx, def_id.to_def_id()))
1095-
.to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
1096-
DUMMY_SP,
1097-
));
1095+
if let Some(def_id) = def_id {
1096+
// We've checked above that the trait is conditionally const.
1097+
bounds.push((
1098+
ty::Binder::dummy(ty::TraitRef::identity(tcx, def_id.to_def_id()))
1099+
.to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
1100+
DUMMY_SP,
1101+
));
1102+
}
10981103

10991104
icx.lowerer().lower_bounds(
11001105
tcx.types.self_param,
@@ -1143,13 +1148,14 @@ pub(super) fn explicit_implied_const_bounds<'tcx>(
11431148
span_bug!(tcx.def_span(def_id), "RPITIT in impl should not have item bounds")
11441149
}
11451150
None => match tcx.hir_node_by_def_id(def_id) {
1146-
Node::Item(hir::Item { kind: hir::ItemKind::Trait(..), .. }) => {
1147-
implied_predicates_with_filter(
1148-
tcx,
1149-
def_id.to_def_id(),
1150-
PredicateFilter::SelfConstIfConst,
1151-
)
1152-
}
1151+
Node::Item(hir::Item {
1152+
kind: hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..),
1153+
..
1154+
}) => implied_predicates_with_filter(
1155+
tcx,
1156+
def_id.to_def_id(),
1157+
PredicateFilter::SelfConstIfConst,
1158+
),
11531159
Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Type(..), .. })
11541160
| Node::OpaqueTy(_) => {
11551161
explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::ConstIfConst)

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
632632
| hir::ItemKind::Struct(_, generics, _)
633633
| hir::ItemKind::Union(_, generics, _)
634634
| hir::ItemKind::Trait(_, _, _, _, generics, ..)
635-
| hir::ItemKind::TraitAlias(_, generics, ..)
635+
| hir::ItemKind::TraitAlias(_, _, generics, ..)
636636
| hir::ItemKind::Impl(hir::Impl { generics, .. }) => {
637637
// These kinds of items have only early-bound lifetime parameters.
638638
self.visit_early(item.hir_id(), generics, |this| intravisit::walk_item(this, item));

0 commit comments

Comments
 (0)