Skip to content

Commit 5f86009

Browse files
authoredAug 8, 2023
Rollup merge of rust-lang#114566 - fmease:type-alias-laziness-is-crate-specific, r=oli-obk
Store the laziness of type aliases in their `DefKind` Previously, we would treat paths referring to type aliases as *lazy* type aliases if the current crate had lazy type aliases enabled independently of whether the crate which the alias was defined in had the feature enabled or not. With this PR, the laziness of a type alias depends on the crate it is defined in. This generally makes more sense to me especially if / once lazy type aliases become the default in a new edition and we need to think about *edition interoperability*: Consider the hypothetical case where the dependency crate has an older edition (and thus eager type aliases), it exports a type alias with bounds & a where-clause (which are void but technically valid), the dependent crate has the latest edition (and thus lazy type aliases) and it uses that type alias. Arguably, the bounds should *not* be checked since at any time, the dependency crate should be allowed to change the bounds at will with a *non*-major version bump & without negatively affecting downstream crates. As for the reverse case (dependency: lazy type aliases, dependent: eager type aliases), I guess it rules out anything from slight confusion to mild annoyance from upstream crate authors that would be caused by the compiler ignoring the bounds of their type aliases in downstream crates with older editions. --- This fixes rust-lang#114468 since before, my assumption that the type alias associated with a given weak projection was lazy (and therefore had its variances computed) did not necessarily hold in cross-crate scenarios (which [I kinda had a hunch about](rust-lang#114253 (comment))) as outlined above. Now it does hold. `@rustbot` label F-lazy_type_alias r? `@oli-obk`
2 parents 261837c + 3ff6fd2 commit 5f86009

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed
 

‎clippy_lints/src/init_numbered_fields.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for NumberedFields {
5050
&& fields
5151
.iter()
5252
.all(|f| f.ident.as_str().as_bytes().iter().all(u8::is_ascii_digit))
53-
&& !matches!(cx.qpath_res(path, e.hir_id), Res::Def(DefKind::TyAlias, ..))
53+
&& !matches!(cx.qpath_res(path, e.hir_id), Res::Def(DefKind::TyAlias { .. }, ..))
5454
{
5555
let expr_spans = fields
5656
.iter()

‎clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ pub fn is_wild(pat: &Pat<'_>) -> bool {
286286
/// Checks if the given `QPath` belongs to a type alias.
287287
pub fn is_ty_alias(qpath: &QPath<'_>) -> bool {
288288
match *qpath {
289-
QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias | DefKind::AssocTy, ..)),
289+
QPath::Resolved(_, path) => matches!(path.res, Res::Def(DefKind::TyAlias { .. } | DefKind::AssocTy, ..)),
290290
QPath::TypeRelative(ty, _) if let TyKind::Path(qpath) = ty.kind => { is_ty_alias(&qpath) },
291291
_ => false,
292292
}

‎clippy_utils/src/ty/type_certainty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn path_segment_certainty(
219219
// See the comment preceding `qpath_certainty`. `def_id` could refer to a type or a value.
220220
let certainty = lhs.join_clearing_def_ids(rhs);
221221
if resolves_to_type {
222-
if cx.tcx.def_kind(def_id) == DefKind::TyAlias {
222+
if let DefKind::TyAlias { .. } = cx.tcx.def_kind(def_id) {
223223
adt_def_id(cx.tcx.type_of(def_id).instantiate_identity())
224224
.map_or(certainty, |def_id| certainty.with_def_id(def_id))
225225
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.