summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:32 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:32 +0000
commit4547b622d8d29df964fa2914213088b148c498fc (patch)
tree9fc6b25f3c3add6b745be9a2400a6e96140046e9 /compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
parentReleasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz
rustc-4547b622d8d29df964fa2914213088b148c498fc.zip
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs')
-rw-r--r--compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs33
1 files changed, 20 insertions, 13 deletions
diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
index 00bf287ba..03d6f4fd9 100644
--- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
+++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
@@ -26,19 +26,23 @@ declare_lint! {
///
/// ### Example
///
- /// ```
+ /// ```rust
+ /// trait Duh {}
+ ///
+ /// impl Duh for i32 {}
+ ///
/// trait Trait {
- /// type Assoc: Send;
+ /// type Assoc: Duh;
/// }
///
/// struct Struct;
///
- /// impl Trait for Struct {
- /// type Assoc = i32;
+ /// impl<F: Duh> Trait for F {
+ /// type Assoc = F;
/// }
///
/// fn test() -> impl Trait<Assoc = impl Sized> {
- /// Struct
+ /// 42
/// }
/// ```
///
@@ -70,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
// Liberate bound regions in the predicate since we
// don't actually care about lifetimes in this check.
let predicate = cx.tcx.liberate_late_bound_regions(def_id, pred.kind());
- let ty::PredicateKind::Projection(proj) = predicate else {
+ let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = predicate else {
continue;
};
// Only check types, since those are the only things that may
@@ -104,6 +108,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
// then we must've taken advantage of the hack in `project_and_unify_types` where
// we replace opaques with inference vars. Emit a warning!
if !infcx.predicate_must_hold_modulo_regions(&traits::Obligation::new(
+ cx.tcx,
traits::ObligationCause::dummy(),
cx.param_env,
assoc_pred,
@@ -111,12 +116,13 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
// If it's a trait bound and an opaque that doesn't satisfy it,
// then we can emit a suggestion to add the bound.
let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) {
- (ty::Opaque(def_id, _), ty::PredicateKind::Trait(trait_pred)) => {
- Some(AddBound {
- suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),
- trait_ref: trait_pred.print_modifiers_and_trait_path(),
- })
- }
+ (
+ ty::Opaque(def_id, _),
+ ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)),
+ ) => Some(AddBound {
+ suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),
+ trait_ref: trait_pred.print_modifiers_and_trait_path(),
+ }),
_ => None,
};
cx.emit_spanned_lint(
@@ -150,8 +156,9 @@ struct OpaqueHiddenInferredBoundLint<'tcx> {
}
#[derive(Subdiagnostic)]
-#[suggestion_verbose(
+#[suggestion(
lint_opaque_hidden_inferred_bound_sugg,
+ style = "verbose",
applicability = "machine-applicable",
code = " + {trait_ref}"
)]