From e10262ca0aa2ff434b33898d1d03413fdde60edf Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 2 Sep 2023 04:02:11 +0000 Subject: Implement refinement lint for RPITIT --- compiler/rustc_hir_analysis/src/errors.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'compiler/rustc_hir_analysis/src/errors.rs') diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 9471ad9ca90..a1b306edd64 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -919,6 +919,21 @@ pub struct UnusedAssociatedTypeBounds { pub span: Span, } +#[derive(LintDiagnostic)] +#[diag(hir_analysis_rpitit_refined)] +pub(crate) struct ReturnPositionImplTraitInTraitRefined<'tcx> { + #[suggestion(applicability = "maybe-incorrect", code = "{pre}{return_ty}{post}")] + pub impl_return_span: Span, + #[label] + pub trait_return_span: Option, + #[label(hir_analysis_unmatched_bound_label)] + pub unmatched_bound: Option, + + pub pre: &'static str, + pub post: &'static str, + pub return_ty: Ty<'tcx>, +} + #[derive(Diagnostic)] #[diag(hir_analysis_assoc_bound_on_const)] #[note] -- cgit 1.4.1-3-g733a5 From 7714db873e3172f34bed004ac1976cf72a54c2e9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 7 Sep 2023 00:49:04 +0000 Subject: Add note --- compiler/rustc_hir_analysis/messages.ftl | 1 + compiler/rustc_hir_analysis/src/errors.rs | 1 + tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr | 1 + tests/ui/impl-trait/in-trait/refine.stderr | 4 ++++ 4 files changed, 7 insertions(+) (limited to 'compiler/rustc_hir_analysis/src/errors.rs') diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index 6a08fc528d7..50da2278312 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -226,6 +226,7 @@ hir_analysis_rpitit_refined = impl trait in impl method signature does not match .suggestion = replace the return type so that it matches the trait .label = return type from trait method defined here .unmatched_bound_label = this bound is stronger than that defined on the trait + .note = add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate hir_analysis_self_in_impl_self = `Self` is not valid in the self type of an impl block diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index a1b306edd64..7614913f4bf 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -921,6 +921,7 @@ pub struct UnusedAssociatedTypeBounds { #[derive(LintDiagnostic)] #[diag(hir_analysis_rpitit_refined)] +#[note] pub(crate) struct ReturnPositionImplTraitInTraitRefined<'tcx> { #[suggestion(applicability = "maybe-incorrect", code = "{pre}{return_ty}{post}")] pub impl_return_span: Span, diff --git a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr index c0e07e94dab..a5fb338ea4e 100644 --- a/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr +++ b/tests/ui/impl-trait/in-trait/bad-item-bound-within-rpitit.stderr @@ -21,6 +21,7 @@ LL | fn iter(&self) -> impl '_ + Iterator>; LL | fn iter(&self) -> impl 'a + Iterator> { | ^^ this bound is stronger than that defined on the trait | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate = note: `#[warn(refining_impl_trait)]` on by default help: replace the return type so that it matches the trait | diff --git a/tests/ui/impl-trait/in-trait/refine.stderr b/tests/ui/impl-trait/in-trait/refine.stderr index 65dfdf869e4..29aa08e25bb 100644 --- a/tests/ui/impl-trait/in-trait/refine.stderr +++ b/tests/ui/impl-trait/in-trait/refine.stderr @@ -7,6 +7,7 @@ LL | fn bar() -> impl Sized; LL | fn bar() -> impl Copy {} | ^^^^ this bound is stronger than that defined on the trait | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate note: the lint level is defined here --> $DIR/refine.rs:2:9 | @@ -26,6 +27,7 @@ LL | fn bar() -> impl Sized; LL | fn bar() {} | ^^^^^^^^ | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate help: replace the return type so that it matches the trait | LL | fn bar() -> impl Sized {} @@ -40,6 +42,7 @@ LL | fn bar() -> impl Sized; LL | fn bar() -> () {} | ^^ | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate help: replace the return type so that it matches the trait | LL | fn bar() -> impl Sized {} @@ -54,6 +57,7 @@ LL | fn bar<'a>(&'a self) -> impl Sized + 'a; LL | fn bar(&self) -> impl Copy + '_ {} | ^^^^ this bound is stronger than that defined on the trait | + = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate help: replace the return type so that it matches the trait | LL | fn bar(&self) -> impl Sized + '_ {} -- cgit 1.4.1-3-g733a5