Skip to content

Commit 477dbc3

Browse files
committed
[WIP] [crater-only] Make a watered-down version of lazy type aliases the default
1 parent af69f4c commit 477dbc3

File tree

8 files changed

+40
-30
lines changed

8 files changed

+40
-30
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,18 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
321321
// `ForeignItem`s are handled separately.
322322
hir::ItemKind::ForeignMod { .. } => Ok(()),
323323
hir::ItemKind::TyAlias(hir_ty, hir_generics) => {
324-
if tcx.type_alias_is_lazy(item.owner_id) {
325-
// Bounds of lazy type aliases and of eager ones that contain opaque types are respected.
326-
// E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`.
327-
let res = check_item_type(tcx, def_id, hir_ty.span, UnsizedHandling::Allow);
328-
check_variances_for_type_defn(tcx, item, hir_generics);
329-
res
324+
// [[[[ /!\ CRATER-ONLY /!\ ]]]]
325+
// Do not check the watered-down version of lazy type aliases for well-formedness.
326+
let ty = tcx.type_of(item.owner_id).instantiate_identity();
327+
let result = if !ty.references_error() && ty.has_opaque_types() {
328+
check_item_type(tcx, def_id, hir_ty.span, UnsizedHandling::Allow)
330329
} else {
331330
Ok(())
331+
};
332+
if tcx.type_alias_is_lazy(item.owner_id) {
333+
check_variances_for_type_defn(tcx, item, hir_generics);
332334
}
335+
result
333336
}
334337
_ => Ok(()),
335338
};
@@ -1843,6 +1846,11 @@ fn check_variances_for_type_defn<'tcx>(
18431846
assert_eq!(ty_predicates.parent, None);
18441847
let variances = tcx.variances_of(item.owner_id);
18451848

1849+
if let ItemKind::TyAlias(..) = item.kind {
1850+
// [[[[ /!\ CRATER-ONLY /!\ ]]]]
1851+
return;
1852+
}
1853+
18461854
let mut constrained_parameters: FxHashSet<_> = variances
18471855
.iter()
18481856
.enumerate()

compiler/rustc_hir_analysis/src/collect/type_of.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -671,21 +671,8 @@ fn check_feature_inherent_assoc_ty(tcx: TyCtxt<'_>, span: Span) {
671671
}
672672
}
673673

674-
pub fn type_alias_is_lazy<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> bool {
675-
use hir::intravisit::Visitor;
676-
if tcx.features().lazy_type_alias {
677-
return true;
678-
}
679-
struct HasTait;
680-
impl<'tcx> Visitor<'tcx> for HasTait {
681-
type Result = ControlFlow<()>;
682-
fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) -> Self::Result {
683-
if let hir::TyKind::OpaqueDef(..) = t.kind {
684-
ControlFlow::Break(())
685-
} else {
686-
hir::intravisit::walk_ty(self, t)
687-
}
688-
}
689-
}
690-
HasTait.visit_ty(tcx.hir().expect_item(def_id).expect_ty_alias().0).is_break()
674+
pub fn type_alias_is_lazy<'tcx>(_: TyCtxt<'tcx>, _: LocalDefId) -> bool {
675+
// [[[[ /!\ CRATER-ONLY /!\ ]]]]
676+
// All type aliases are lazy.
677+
true
691678
}

compiler/rustc_hir_analysis/src/outlives/utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(
2121
) {
2222
// If the `'a` region is bound within the field type itself, we
2323
// don't want to propagate this constraint to the header.
24-
if !is_free_region(outlived_region) {
24+
if !is_early_bound_region(outlived_region) {
2525
return;
2626
}
2727

@@ -132,7 +132,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(
132132
}
133133

134134
GenericArgKind::Lifetime(r) => {
135-
if !is_free_region(r) {
135+
if !is_early_bound_region(r) {
136136
return;
137137
}
138138
required_predicates.entry(ty::OutlivesPredicate(kind, outlived_region)).or_insert(span);
@@ -144,7 +144,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(
144144
}
145145
}
146146

147-
fn is_free_region(region: Region<'_>) -> bool {
147+
fn is_early_bound_region(region: Region<'_>) -> bool {
148148
// First, screen for regions that might appear in a type header.
149149
match *region {
150150
// These correspond to `T: 'a` relationships:

compiler/rustc_infer/src/infer/outlives/components.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn compute_components<'tcx>(
138138
// trait-ref. Therefore, if we see any higher-ranked regions,
139139
// we simply fallback to the most restrictive rule, which
140140
// requires that `Pi: 'a` for all `i`.
141-
ty::Alias(_, alias_ty) => {
141+
ty::Alias(ty::Projection | ty::Inherent | ty::Opaque, alias_ty) => {
142142
if !alias_ty.has_escaping_bound_vars() {
143143
// best case: no escaping regions, so push the
144144
// projection and skip the subtree (thus generating no
@@ -178,6 +178,7 @@ fn compute_components<'tcx>(
178178
ty::Float(..) | // OutlivesScalar
179179
ty::Never | // ...
180180
ty::Adt(..) | // OutlivesNominalType
181+
ty::Alias(ty::Weak, _) |
181182
ty::Foreign(..) | // OutlivesNominalType
182183
ty::Str | // OutlivesScalar (ish)
183184
ty::Slice(..) | // ...

compiler/rustc_passes/src/stability.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,8 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
567567
i.kind,
568568
hir::ItemKind::Impl(hir::Impl { of_trait: None, .. })
569569
| hir::ItemKind::ForeignMod { .. }
570+
// [[[[ /!\ CRATER-ONLY /!\ ]]]]
571+
| hir::ItemKind::TyAlias(..)
570572
) {
571573
self.check_missing_stability(i.owner_id.def_id, i.span);
572574
}
@@ -585,8 +587,13 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
585587
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
586588
let impl_def_id = self.tcx.hir().get_parent_item(ii.hir_id());
587589
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
588-
self.check_missing_stability(ii.owner_id.def_id, ii.span);
589-
self.check_missing_const_stability(ii.owner_id.def_id, ii.span);
590+
// [[[[ /!\ CRATER-ONLY /!\ ]]]]
591+
// FIXME(fmease): The proper fix would be to peel_off_weak_alias_tys(impl_self_ty)
592+
// and to get the owner this way. Not entirely sure.
593+
if false {
594+
self.check_missing_stability(ii.owner_id.def_id, ii.span);
595+
self.check_missing_const_stability(ii.owner_id.def_id, ii.span);
596+
}
590597
}
591598
intravisit::walk_impl_item(self, ii);
592599
}

compiler/rustc_privacy/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ where
203203
}
204204
}
205205
}
206-
ty::Alias(kind @ (ty::Inherent | ty::Weak | ty::Projection), data) => {
206+
// [[[[ /!\ CRATER-ONLY /!\ ]]]]
207+
ty::Alias(kind @ (ty::Inherent | ty::Projection), data) => {
207208
if V::SKIP_ASSOC_TYS {
208209
// Visitors searching for minimal visibility/reachability want to
209210
// conservatively approximate associated types like `Type::Alias`
@@ -234,6 +235,10 @@ where
234235
)
235236
};
236237
}
238+
// [[[[ /!\ CRATER-ONLY /!\ ]]]]
239+
ty::Alias(ty::Weak, _) => {
240+
return V::Result::output();
241+
}
237242
ty::Dynamic(predicates, ..) => {
238243
// All traits in the list are considered the "primary" part of the type
239244
// and are visited by shallow visitors.

compiler/rustc_trait_selection/src/traits/wf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
801801
}
802802
}
803803

804+
// NOTE(fmease): It should be fine to keep this.
804805
ty::Alias(ty::Weak, ty::AliasTy { def_id, args, .. }) => {
805806
let obligations = self.nominal_obligations(def_id, args);
806807
self.out.extend(obligations);

compiler/rustc_traits/src/normalize_projection_ty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ fn normalize_canonicalized_weak_ty<'tcx>(
7979
tcx.infer_ctxt().enter_canonical_trait_query(
8080
&goal,
8181
|ocx, ParamEnvAnd { param_env, value: goal }| {
82+
// NOTE(fmease): It should be fine to keep this for the crater run.
8283
let obligations = tcx.predicates_of(goal.def_id).instantiate_own(tcx, goal.args).map(
8384
|(predicate, span)| {
8485
traits::Obligation::new(

0 commit comments

Comments
 (0)