Rollup merge of #126575 - fmease:update-lint-type_alias_bounds, r=compiler-errors
Make it crystal clear what lint `type_alias_bounds` actually signifies This is part of my work on https://github.com/rust-lang/rust/labels/F-lazy_type_alias ([tracking issue](#112792)). --- To recap, the lint `type_alias_bounds` detects bounds on generic parameters and where clauses on (eager) type aliases. These bounds should've never been allowed because they are currently neither enforced[^1] at usage sites of type aliases nor thoroughly checked for correctness at definition sites due to the way type aliases are represented in the compiler. Allowing them was an oversight. Explicitly label this as a known limitation of the type checker/system and establish the experimental feature `lazy_type_alias` as its eventual proper solution. Where this becomes a bit tricky (for me as a rustc dev) are the "secondary effects" of these bounds whose existence I sadly can't deny. As a matter of fact, type alias bounds do play some small roles during type checking. However, after a lot of thinking over the last two weeks I've come to the conclusion (not without second-guessing myself though) that these use cases should not trump the fact that these bounds are currently *inherently broken*. Therefore the lint `type_alias_bounds` should and will continue to flag bounds that may have subordinate uses. The two *known* secondary effects are: 1. They may enable the use of "shorthand" associated type paths `T::Assoc` (as opposed to fully qualified paths `<T as Trait>::Assoc`) where `T` is a type param bounded by some trait `Trait` which defines that assoc ty. 2. They may affect the default lifetime of trait object types passed as a type argument to the type alias. That concept is called (trait) object lifetime default. The second one is negligible, no question asked. The first one however is actually "kinda nice" (for writability) and comes up in practice from time to time. So why don't I just special-case trait bounds that "define" shorthand assoc type paths as originally planned in #125709? 1. Starting to permit even a tiny subset of bounds would already be enough to send a signal to users that bounds in type aliases have been legitimized and that they can expect to see type alias bounds in the wild from now on (proliferation). This would be actively misleading and dangerous because those bounds don't behave at all like one would expect, they are *not real*[^2]! 1. Let's take `type A<T: Trait> = T::Proj;` for example. Everywhere else in the language `T: Trait` means `T: Trait + Sized`. For type aliases, that's not the case though: `T: Trait` and `T: Trait + ?Sized` for that matter do neither mean `T: Trait + Sized` nor `T: Trait + ?Sized` (for both!). Instead, whether `T` requires `Sized` or not entirely depends on the definition of `Trait`[^2]. Namely, whether or not it is bounded by `Sized`. 2. Given `type A<T: Trait<AssocA = ()>> = T::AssocB;`, while `X: Trait` gets checked given `A<X>` (by virtue of projection wfchecking post alias expansion[^2]), the associated type constraint `AssocA = ()` gets dropped entirely! While we could choose to warn on such cases, it would inevitably lead to a huge pile of special cases. 3. While it's common knowledge that the body / aliased type / RHS of an (eager) type alias does not get checked for well-formedness, I'm not sure if people would realize that that extends to bounds as well. Namely, `type A<T: Trait<[u8]>> = T::Proj;` compiles even if `Trait`'s generic parameter requires `Sized`. Of course, at usage sites `[u8]: Sized` would still end up getting checked[^2], so it's not a huge problem if you have full control over `A`. However, imagine that `A` was actually part of a public API and was never used inside the defining crate (not unreasonable). In such a scenario, downstream users would be presented with an impossible to use type alias! Remember, bounds may grow arbitrarily complex and nuanced in practice. 4. Even if we allowed trait bounds that "define" shorthand assoc type paths, we would still need to continue to warn in cases where the assoc ty comes from a supertrait despite the fact that the shorthand syntax can be used: `type A<T: Sub> = T::Assoc;` does compile given `trait Sub: Super {}` and `trait Super { type Assoc; }`. However, `A<X>` does not enforce `X: Sub`, only `X: Super`[^2]. All that to say, type alias bounds are simply not real and we shouldn't pretend they are! 5. Summarizing the points above, we would be legitimizing bounds that are completely broken! 2. It's infeasible to implement: Due to the lack of `TypeckResults` in `ItemCtxt` (and a way to propagate it to other parts of the compiler), the resolution of type-dependent paths in non-`Body` items (most notably type aliases) is not recoverable from the HIR alone which would be necessary because the information of whether an associated type path (projection) is a shorthand is only present pre&in-HIR and doesn't survive HIR ty lowering. Of course, I could rerun parts of HIR ty lowering inside the lint `type_alias_bounds` (namely, `probe_single_ty_param_bound_for_assoc_ty` which would need to be exposed or alternatively a stripped-down version of it). This likely has a performance impact and introduces complexity. In short, the "benefits" are not worth the costs. --- * 3rd commit: Update a diagnostic to avoid suggesting type alias bounds * 4th commit: Flag type alias bounds even if the RHS contains inherent associated types. * I started to allow them at some point in the past which was not correct (see commit for details) * 5th commit: Allow type alias bounds if the RHS contains const projections and GCEs are enabled * (and add a `FIXME(generic_const_exprs)` to be revisited before (M)GCE's stabilization) * As a matter of fact type alias bounds are enforced in this case because the contained AnonConsts do get checked for well-formedness and crucially they inherit the generics and predicates of their parent item (here: the type alias) * Remaining commits: Improve the lint `type_alias_bounds` itself --- Fixes #125789 (sugg diag fix). Fixes #125709 (wontfix, acknowledgement, sugg diag applic fix). Fixes #104918 (sugg diag applic fix). Fixes #100270 (wontfix, acknowledgement, sugg diag applic fix). Fixes #94398 (true fix). r? `@compiler-errors` `@oli-obk` [^1]: From the perspective of the trait solver. [^2]: Given `type A<T: Trait> = T::Proj;`, the reason why the trait bound "`T: Trait`" gets *seemingly* enforced at usage sites of the type alias `A` is simply because `A<X>` gets expanded to "`<X as Trait>::Proj`" very early on and it's the *expansion* that gets checked for well-formedness, not the type alias reference.
This commit is contained in:
commit
ceae37188b
26 changed files with 829 additions and 456 deletions
|
@ -31,12 +31,11 @@ use crate::{
|
|||
BuiltinIncompleteFeaturesHelp, BuiltinInternalFeatures, BuiltinKeywordIdents,
|
||||
BuiltinMissingCopyImpl, BuiltinMissingDebugImpl, BuiltinMissingDoc,
|
||||
BuiltinMutablesTransmutes, BuiltinNoMangleGeneric, BuiltinNonShorthandFieldPatterns,
|
||||
BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds, BuiltinTypeAliasGenericBounds,
|
||||
BuiltinTypeAliasGenericBoundsSuggestion, BuiltinTypeAliasWhereClause,
|
||||
BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds, BuiltinTypeAliasBounds,
|
||||
BuiltinUngatedAsyncFnTrackCaller, BuiltinUnpermittedTypeInit,
|
||||
BuiltinUnpermittedTypeInitSub, BuiltinUnreachablePub, BuiltinUnsafe,
|
||||
BuiltinUnstableFeatures, BuiltinUnusedDocComment, BuiltinUnusedDocCommentSub,
|
||||
BuiltinWhileTrue, InvalidAsmLabel, SuggestChangingAssocTypes,
|
||||
BuiltinWhileTrue, InvalidAsmLabel,
|
||||
},
|
||||
EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext,
|
||||
};
|
||||
|
@ -1391,64 +1390,80 @@ declare_lint! {
|
|||
///
|
||||
/// ### Explanation
|
||||
///
|
||||
/// The trait bounds in a type alias are currently ignored, and should not
|
||||
/// be included to avoid confusion. This was previously allowed
|
||||
/// unintentionally; this may become a hard error in the future.
|
||||
/// Trait and lifetime bounds on generic parameters and in where clauses of
|
||||
/// type aliases are not checked at usage sites of the type alias. Moreover,
|
||||
/// they are not thoroughly checked for correctness at their definition site
|
||||
/// either similar to the aliased type.
|
||||
///
|
||||
/// This is a known limitation of the type checker that may be lifted in a
|
||||
/// future edition. Permitting such bounds in light of this was unintentional.
|
||||
///
|
||||
/// While these bounds may have secondary effects such as enabling the use of
|
||||
/// "shorthand" associated type paths[^1] and affecting the default trait
|
||||
/// object lifetime[^2] of trait object types passed to the type alias, this
|
||||
/// should not have been allowed until the aforementioned restrictions of the
|
||||
/// type checker have been lifted.
|
||||
///
|
||||
/// Using such bounds is highly discouraged as they are actively misleading.
|
||||
///
|
||||
/// [^1]: I.e., paths of the form `T::Assoc` where `T` is a type parameter
|
||||
/// bounded by trait `Trait` which defines an associated type called `Assoc`
|
||||
/// as opposed to a fully qualified path of the form `<T as Trait>::Assoc`.
|
||||
/// [^2]: <https://doc.rust-lang.org/reference/lifetime-elision.html#default-trait-object-lifetimes>
|
||||
TYPE_ALIAS_BOUNDS,
|
||||
Warn,
|
||||
"bounds in type aliases are not enforced"
|
||||
}
|
||||
|
||||
declare_lint_pass!(
|
||||
/// Lint for trait and lifetime bounds in type aliases being mostly ignored.
|
||||
/// They are relevant when using associated types, but otherwise neither checked
|
||||
/// at definition site nor enforced at use site.
|
||||
TypeAliasBounds => [TYPE_ALIAS_BOUNDS]
|
||||
);
|
||||
declare_lint_pass!(TypeAliasBounds => [TYPE_ALIAS_BOUNDS]);
|
||||
|
||||
impl TypeAliasBounds {
|
||||
pub(crate) fn is_type_variable_assoc(qpath: &hir::QPath<'_>) -> bool {
|
||||
match *qpath {
|
||||
hir::QPath::TypeRelative(ty, _) => {
|
||||
// If this is a type variable, we found a `T::Assoc`.
|
||||
match ty.kind {
|
||||
hir::TyKind::Path(hir::QPath::Resolved(None, path)) => {
|
||||
matches!(path.res, Res::Def(DefKind::TyParam, _))
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
hir::QPath::Resolved(..) | hir::QPath::LangItem(..) => false,
|
||||
pub(crate) fn affects_object_lifetime_defaults(pred: &hir::WherePredicate<'_>) -> bool {
|
||||
// Bounds of the form `T: 'a` with `T` type param affect object lifetime defaults.
|
||||
if let hir::WherePredicate::BoundPredicate(pred) = pred
|
||||
&& pred.bounds.iter().any(|bound| matches!(bound, hir::GenericBound::Outlives(_)))
|
||||
&& pred.bound_generic_params.is_empty() // indeed, even if absent from the RHS
|
||||
&& pred.bounded_ty.as_generic_param().is_some()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
|
||||
let hir::ItemKind::TyAlias(hir_ty, type_alias_generics) = &item.kind else { return };
|
||||
let hir::ItemKind::TyAlias(hir_ty, generics) = item.kind else { return };
|
||||
|
||||
// There must not be a where clause.
|
||||
if generics.predicates.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bounds of lazy type aliases and TAITs are respected.
|
||||
if cx.tcx.type_alias_is_lazy(item.owner_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
let ty = cx.tcx.type_of(item.owner_id).skip_binder();
|
||||
if ty.has_inherent_projections() {
|
||||
// Bounds of type aliases that contain opaque types or inherent projections are
|
||||
// respected. E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`, `type X =
|
||||
// Type::Inherent;`.
|
||||
// FIXME(generic_const_exprs): Revisit this before stabilization.
|
||||
// See also `tests/ui/const-generics/generic_const_exprs/type-alias-bounds.rs`.
|
||||
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||
if ty.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION)
|
||||
&& cx.tcx.features().generic_const_exprs
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// There must not be a where clause
|
||||
if type_alias_generics.predicates.is_empty() {
|
||||
return;
|
||||
}
|
||||
// NOTE(inherent_associated_types): While we currently do take some bounds in type
|
||||
// aliases into consideration during IAT *selection*, we don't perform full use+def
|
||||
// site wfchecking for such type aliases. Therefore TAB should still trigger.
|
||||
// See also `tests/ui/associated-inherent-types/type-alias-bounds.rs`.
|
||||
|
||||
let mut where_spans = Vec::new();
|
||||
let mut inline_spans = Vec::new();
|
||||
let mut inline_sugg = Vec::new();
|
||||
for p in type_alias_generics.predicates {
|
||||
|
||||
for p in generics.predicates {
|
||||
let span = p.span();
|
||||
if p.in_where_clause() {
|
||||
where_spans.push(span);
|
||||
|
@ -1460,37 +1475,57 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
|
|||
}
|
||||
}
|
||||
|
||||
let mut suggested_changing_assoc_types = false;
|
||||
if !where_spans.is_empty() {
|
||||
let sub = (!suggested_changing_assoc_types).then(|| {
|
||||
suggested_changing_assoc_types = true;
|
||||
SuggestChangingAssocTypes { ty: hir_ty }
|
||||
});
|
||||
let mut ty = Some(hir_ty);
|
||||
let enable_feat_help = cx.tcx.sess.is_nightly_build();
|
||||
|
||||
if let [.., label_sp] = *where_spans {
|
||||
cx.emit_span_lint(
|
||||
TYPE_ALIAS_BOUNDS,
|
||||
where_spans,
|
||||
BuiltinTypeAliasWhereClause {
|
||||
suggestion: type_alias_generics.where_clause_span,
|
||||
sub,
|
||||
BuiltinTypeAliasBounds {
|
||||
in_where_clause: true,
|
||||
label: label_sp,
|
||||
enable_feat_help,
|
||||
suggestions: vec![(generics.where_clause_span, String::new())],
|
||||
preds: generics.predicates,
|
||||
ty: ty.take(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if !inline_spans.is_empty() {
|
||||
let suggestion = BuiltinTypeAliasGenericBoundsSuggestion { suggestions: inline_sugg };
|
||||
let sub = (!suggested_changing_assoc_types).then(|| {
|
||||
suggested_changing_assoc_types = true;
|
||||
SuggestChangingAssocTypes { ty: hir_ty }
|
||||
});
|
||||
if let [.., label_sp] = *inline_spans {
|
||||
cx.emit_span_lint(
|
||||
TYPE_ALIAS_BOUNDS,
|
||||
inline_spans,
|
||||
BuiltinTypeAliasGenericBounds { suggestion, sub },
|
||||
BuiltinTypeAliasBounds {
|
||||
in_where_clause: false,
|
||||
label: label_sp,
|
||||
enable_feat_help,
|
||||
suggestions: inline_sugg,
|
||||
preds: generics.predicates,
|
||||
ty,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct ShorthandAssocTyCollector {
|
||||
pub(crate) qselves: Vec<Span>,
|
||||
}
|
||||
|
||||
impl hir::intravisit::Visitor<'_> for ShorthandAssocTyCollector {
|
||||
fn visit_qpath(&mut self, qpath: &hir::QPath<'_>, id: hir::HirId, _: Span) {
|
||||
// Look for "type-parameter shorthand-associated-types". I.e., paths of the
|
||||
// form `T::Assoc` with `T` type param. These are reliant on trait bounds.
|
||||
if let hir::QPath::TypeRelative(qself, _) = qpath
|
||||
&& qself.as_generic_param().is_some()
|
||||
{
|
||||
self.qselves.push(qself.span);
|
||||
}
|
||||
hir::intravisit::walk_qpath(self, qpath, id)
|
||||
}
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `trivial_bounds` lint detects trait bounds that don't depend on
|
||||
/// any type parameters.
|
||||
|
|
|
@ -2,14 +2,16 @@
|
|||
#![allow(rustc::untranslatable_diagnostic)]
|
||||
use std::num::NonZero;
|
||||
|
||||
use crate::errors::RequestedLevel;
|
||||
use crate::builtin::{InitError, ShorthandAssocTyCollector, TypeAliasBounds};
|
||||
use crate::errors::{OverruledAttributeSub, RequestedLevel};
|
||||
use crate::fluent_generated as fluent;
|
||||
use crate::LateContext;
|
||||
use rustc_errors::{
|
||||
codes::*, Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString,
|
||||
ElidedLifetimeInPathSubdiag, EmissionGuarantee, LintDiagnostic, MultiSpan, SubdiagMessageOp,
|
||||
Subdiagnostic, SuggestionStyle,
|
||||
};
|
||||
use rustc_hir::{def::Namespace, def_id::DefId};
|
||||
use rustc_hir::{self as hir, def::Namespace, def_id::DefId};
|
||||
use rustc_macros::{LintDiagnostic, Subdiagnostic};
|
||||
use rustc_middle::ty::{
|
||||
inhabitedness::InhabitedPredicate, Clause, PolyExistentialTraitRef, Ty, TyCtxt,
|
||||
|
@ -22,10 +24,6 @@ use rustc_span::{
|
|||
Span, Symbol,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
builtin::InitError, builtin::TypeAliasBounds, errors::OverruledAttributeSub, LateContext,
|
||||
};
|
||||
|
||||
// array_into_iter.rs
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_shadowed_into_iter)]
|
||||
|
@ -263,62 +261,6 @@ pub struct BuiltinUnreachablePub<'a> {
|
|||
pub help: Option<()>,
|
||||
}
|
||||
|
||||
pub struct SuggestChangingAssocTypes<'a, 'b> {
|
||||
pub ty: &'a rustc_hir::Ty<'b>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> Subdiagnostic for SuggestChangingAssocTypes<'a, 'b> {
|
||||
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_f: &F,
|
||||
) {
|
||||
// Access to associates types should use `<T as Bound>::Assoc`, which does not need a
|
||||
// bound. Let's see if this type does that.
|
||||
|
||||
// We use a HIR visitor to walk the type.
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
struct WalkAssocTypes<'a, 'b, G: EmissionGuarantee> {
|
||||
err: &'a mut Diag<'b, G>,
|
||||
}
|
||||
impl<'a, 'b, G: EmissionGuarantee> Visitor<'_> for WalkAssocTypes<'a, 'b, G> {
|
||||
fn visit_qpath(
|
||||
&mut self,
|
||||
qpath: &rustc_hir::QPath<'_>,
|
||||
id: rustc_hir::HirId,
|
||||
span: Span,
|
||||
) {
|
||||
if TypeAliasBounds::is_type_variable_assoc(qpath) {
|
||||
self.err.span_help(span, fluent::lint_builtin_type_alias_bounds_help);
|
||||
}
|
||||
intravisit::walk_qpath(self, qpath, id)
|
||||
}
|
||||
}
|
||||
|
||||
// Let's go for a walk!
|
||||
let mut visitor = WalkAssocTypes { err: diag };
|
||||
visitor.visit_ty(self.ty);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_builtin_type_alias_where_clause)]
|
||||
pub struct BuiltinTypeAliasWhereClause<'a, 'b> {
|
||||
#[suggestion(code = "", applicability = "machine-applicable")]
|
||||
pub suggestion: Span,
|
||||
#[subdiagnostic]
|
||||
pub sub: Option<SuggestChangingAssocTypes<'a, 'b>>,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_builtin_type_alias_generic_bounds)]
|
||||
pub struct BuiltinTypeAliasGenericBounds<'a, 'b> {
|
||||
#[subdiagnostic]
|
||||
pub suggestion: BuiltinTypeAliasGenericBoundsSuggestion,
|
||||
#[subdiagnostic]
|
||||
pub sub: Option<SuggestChangingAssocTypes<'a, 'b>>,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_macro_expr_fragment_specifier_2024_migration)]
|
||||
pub struct MacroExprFragment2024 {
|
||||
|
@ -326,21 +268,72 @@ pub struct MacroExprFragment2024 {
|
|||
pub suggestion: Span,
|
||||
}
|
||||
|
||||
pub struct BuiltinTypeAliasGenericBoundsSuggestion {
|
||||
pub struct BuiltinTypeAliasBounds<'a, 'hir> {
|
||||
pub in_where_clause: bool,
|
||||
pub label: Span,
|
||||
pub enable_feat_help: bool,
|
||||
pub suggestions: Vec<(Span, String)>,
|
||||
pub preds: &'hir [hir::WherePredicate<'hir>],
|
||||
pub ty: Option<&'a hir::Ty<'hir>>,
|
||||
}
|
||||
|
||||
impl Subdiagnostic for BuiltinTypeAliasGenericBoundsSuggestion {
|
||||
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
|
||||
self,
|
||||
diag: &mut Diag<'_, G>,
|
||||
_f: &F,
|
||||
) {
|
||||
diag.multipart_suggestion(
|
||||
fluent::lint_suggestion,
|
||||
self.suggestions,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
impl<'a> LintDiagnostic<'a, ()> for BuiltinTypeAliasBounds<'_, '_> {
|
||||
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, ()>) {
|
||||
diag.primary_message(if self.in_where_clause {
|
||||
fluent::lint_builtin_type_alias_bounds_where_clause
|
||||
} else {
|
||||
fluent::lint_builtin_type_alias_bounds_param_bounds
|
||||
});
|
||||
diag.span_label(self.label, fluent::lint_builtin_type_alias_bounds_label);
|
||||
diag.note(fluent::lint_builtin_type_alias_bounds_limitation_note);
|
||||
if self.enable_feat_help {
|
||||
diag.help(fluent::lint_builtin_type_alias_bounds_enable_feat_help);
|
||||
}
|
||||
|
||||
// We perform the walk in here instead of in `<TypeAliasBounds as LateLintPass>` to
|
||||
// avoid doing throwaway work in case the lint ends up getting suppressed.
|
||||
let mut collector = ShorthandAssocTyCollector { qselves: Vec::new() };
|
||||
if let Some(ty) = self.ty {
|
||||
hir::intravisit::Visitor::visit_ty(&mut collector, ty);
|
||||
}
|
||||
|
||||
let affect_object_lifetime_defaults = self
|
||||
.preds
|
||||
.iter()
|
||||
.filter(|pred| pred.in_where_clause() == self.in_where_clause)
|
||||
.any(|pred| TypeAliasBounds::affects_object_lifetime_defaults(pred));
|
||||
|
||||
// If there are any shorthand assoc tys, then the bounds can't be removed automatically.
|
||||
// The user first needs to fully qualify the assoc tys.
|
||||
let applicability = if !collector.qselves.is_empty() || affect_object_lifetime_defaults {
|
||||
Applicability::MaybeIncorrect
|
||||
} else {
|
||||
Applicability::MachineApplicable
|
||||
};
|
||||
|
||||
diag.arg("count", self.suggestions.len());
|
||||
diag.multipart_suggestion(fluent::lint_suggestion, self.suggestions, applicability);
|
||||
|
||||
// Suggest fully qualifying paths of the form `T::Assoc` with `T` type param via
|
||||
// `<T as /* Trait */>::Assoc` to remove their reliance on any type param bounds.
|
||||
//
|
||||
// Instead of attempting to figure out the necessary trait ref, just use a
|
||||
// placeholder. Since we don't record type-dependent resolutions for non-body
|
||||
// items like type aliases, we can't simply deduce the corresp. trait from
|
||||
// the HIR path alone without rerunning parts of HIR ty lowering here
|
||||
// (namely `probe_single_ty_param_bound_for_assoc_ty`) which is infeasible.
|
||||
//
|
||||
// (We could employ some simple heuristics but that's likely not worth it).
|
||||
for qself in collector.qselves {
|
||||
diag.multipart_suggestion(
|
||||
fluent::lint_builtin_type_alias_bounds_qualify_assoc_tys_sugg,
|
||||
vec![
|
||||
(qself.shrink_to_lo(), "<".into()),
|
||||
(qself.shrink_to_hi(), " as /* Trait */>".into()),
|
||||
],
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue