about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-03-19 11:37:28 -0400
committerMichael Goulet <michael@errs.io>2024-03-19 12:02:21 -0400
commit3d56178880a8f03b3d6322930de778d4064790ba (patch)
tree5bdf4f66649641365f0c7ee49a9c3b8c6c1154a2
parent200e3f7995e231535fdea3be9cb9a3f098b4c856 (diff)
downloadrust-3d56178880a8f03b3d6322930de778d4064790ba.tar.gz
rust-3d56178880a8f03b3d6322930de778d4064790ba.zip
Remove redundant coroutine captures note
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs118
-rw-r--r--tests/ui/async-await/async-await-let-else.stderr1
-rw-r--r--tests/ui/async-await/issue-68112.stderr1
-rw-r--r--tests/ui/async-await/issue-70935-complex-spans.stderr2
-rw-r--r--tests/ui/async-await/issues/issue-67893.stderr1
-rw-r--r--tests/ui/async-await/partial-drop-partial-reinit.rs1
-rw-r--r--tests/ui/async-await/partial-drop-partial-reinit.stderr5
-rw-r--r--tests/ui/coroutine/issue-68112.rs1
-rw-r--r--tests/ui/coroutine/issue-68112.stderr1
-rw-r--r--tests/ui/coroutine/print/coroutine-print-verbose-1.stderr1
10 files changed, 60 insertions, 72 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
index ee390d9c9f0..e5f7f805b05 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
@@ -3199,71 +3199,69 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
                     }
                 };
 
-                // Don't print the tuple of capture types
-                'print: {
-                    if !is_upvar_tys_infer_tuple {
-                        let ty_str = tcx.short_ty_string(ty, &mut long_ty_file);
-                        let msg = format!("required because it appears within the type `{ty_str}`");
-                        match ty.kind() {
-                            ty::Adt(def, _) => match tcx.opt_item_ident(def.did()) {
-                                Some(ident) => err.span_note(ident.span, msg),
-                                None => err.note(msg),
-                            },
-                            ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
-                                // If the previous type is async fn, this is the future generated by the body of an async function.
-                                // Avoid printing it twice (it was already printed in the `ty::Coroutine` arm below).
-                                let is_future = tcx.ty_is_opaque_future(ty);
-                                debug!(
-                                    ?obligated_types,
-                                    ?is_future,
-                                    "note_obligation_cause_code: check for async fn"
-                                );
-                                if is_future
-                                    && obligated_types.last().is_some_and(|ty| match ty.kind() {
-                                        ty::Coroutine(last_def_id, ..) => {
-                                            tcx.coroutine_is_async(*last_def_id)
-                                        }
-                                        _ => false,
-                                    })
-                                {
-                                    break 'print;
-                                }
-                                err.span_note(tcx.def_span(def_id), msg)
+                if !is_upvar_tys_infer_tuple {
+                    let ty_str = tcx.short_ty_string(ty, &mut long_ty_file);
+                    let msg = format!("required because it appears within the type `{ty_str}`");
+                    match ty.kind() {
+                        ty::Adt(def, _) => match tcx.opt_item_ident(def.did()) {
+                            Some(ident) => {
+                                err.span_note(ident.span, msg);
                             }
-                            ty::CoroutineWitness(def_id, args) => {
-                                use std::fmt::Write;
-
-                                // FIXME: this is kind of an unusual format for rustc, can we make it more clear?
-                                // Maybe we should just remove this note altogether?
-                                // FIXME: only print types which don't meet the trait requirement
-                                let mut msg =
-                                    "required because it captures the following types: ".to_owned();
-                                for bty in tcx.coroutine_hidden_types(*def_id) {
-                                    let ty = bty.instantiate(tcx, args);
-                                    write!(msg, "`{ty}`, ").unwrap();
-                                }
-                                err.note(msg.trim_end_matches(", ").to_string())
+                            None => {
+                                err.note(msg);
                             }
-                            ty::Coroutine(def_id, _) => {
-                                let sp = tcx.def_span(def_id);
-
-                                // Special-case this to say "async block" instead of `[static coroutine]`.
-                                let kind = tcx.coroutine_kind(def_id).unwrap();
-                                err.span_note(
-                                    sp,
-                                    with_forced_trimmed_paths!(format!(
-                                        "required because it's used within this {kind:#}",
-                                    )),
-                                )
+                        },
+                        ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
+                            // If the previous type is async fn, this is the future generated by the body of an async function.
+                            // Avoid printing it twice (it was already printed in the `ty::Coroutine` arm below).
+                            let is_future = tcx.ty_is_opaque_future(ty);
+                            debug!(
+                                ?obligated_types,
+                                ?is_future,
+                                "note_obligation_cause_code: check for async fn"
+                            );
+                            if is_future
+                                && obligated_types.last().is_some_and(|ty| match ty.kind() {
+                                    ty::Coroutine(last_def_id, ..) => {
+                                        tcx.coroutine_is_async(*last_def_id)
+                                    }
+                                    _ => false,
+                                })
+                            {
+                                // See comment above; skip printing twice.
+                            } else {
+                                err.span_note(tcx.def_span(def_id), msg);
                             }
-                            ty::Closure(def_id, _) => err.span_note(
+                        }
+                        ty::Coroutine(def_id, _) => {
+                            let sp = tcx.def_span(def_id);
+
+                            // Special-case this to say "async block" instead of `[static coroutine]`.
+                            let kind = tcx.coroutine_kind(def_id).unwrap();
+                            err.span_note(
+                                sp,
+                                with_forced_trimmed_paths!(format!(
+                                    "required because it's used within this {kind:#}",
+                                )),
+                            );
+                        }
+                        ty::CoroutineWitness(..) => {
+                            // Skip printing coroutine-witnesses, since we'll drill into
+                            // the bad field in another derived obligation cause.
+                        }
+                        ty::Closure(def_id, _) | ty::CoroutineClosure(def_id, _) => {
+                            err.span_note(
                                 tcx.def_span(def_id),
                                 "required because it's used within this closure",
-                            ),
-                            ty::Str => err.note("`str` is considered to contain a `[u8]` slice for auto trait purposes"),
-                            _ => err.note(msg),
-                        };
-                    }
+                            );
+                        }
+                        ty::Str => {
+                            err.note("`str` is considered to contain a `[u8]` slice for auto trait purposes");
+                        }
+                        _ => {
+                            err.note(msg);
+                        }
+                    };
                 }
 
                 obligated_types.push(ty);
diff --git a/tests/ui/async-await/async-await-let-else.stderr b/tests/ui/async-await/async-await-let-else.stderr
index 057906b49a3..0952be2abe5 100644
--- a/tests/ui/async-await/async-await-let-else.stderr
+++ b/tests/ui/async-await/async-await-let-else.stderr
@@ -38,7 +38,6 @@ LL |   async fn bar2<T>(_: T) -> ! {
 LL | |     panic!()
 LL | | }
    | |_^
-   = note: required because it captures the following types: `impl Future<Output = !>`
 note: required because it's used within this `async` fn body
   --> $DIR/async-await-let-else.rs:18:32
    |
diff --git a/tests/ui/async-await/issue-68112.stderr b/tests/ui/async-await/issue-68112.stderr
index f92ac5dd0bc..96fc1633cc9 100644
--- a/tests/ui/async-await/issue-68112.stderr
+++ b/tests/ui/async-await/issue-68112.stderr
@@ -58,7 +58,6 @@ note: required because it appears within the type `impl Future<Output = Arc<RefC
    |
 LL | fn make_non_send_future2() -> impl Future<Output = Arc<RefCell<i32>>> {
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   = note: required because it captures the following types: `impl Future<Output = Arc<RefCell<i32>>>`, `Ready<i32>`
 note: required because it's used within this `async` block
   --> $DIR/issue-68112.rs:57:20
    |
diff --git a/tests/ui/async-await/issue-70935-complex-spans.stderr b/tests/ui/async-await/issue-70935-complex-spans.stderr
index 8dc3f476ec8..85c0c0c3088 100644
--- a/tests/ui/async-await/issue-70935-complex-spans.stderr
+++ b/tests/ui/async-await/issue-70935-complex-spans.stderr
@@ -25,7 +25,6 @@ LL |   async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> {
    |  ___________________________________________________________________^
 LL | | }
    | |_^
-   = note: required because it captures the following types: `impl Future<Output = ()>`
 note: required because it's used within this `async` block
   --> $DIR/issue-70935-complex-spans.rs:18:5
    |
@@ -63,7 +62,6 @@ LL |   async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> {
    |  ___________________________________________________________________^
 LL | | }
    | |_^
-   = note: required because it captures the following types: `impl Future<Output = ()>`
 note: required because it's used within this `async` block
   --> $DIR/issue-70935-complex-spans.rs:18:5
    |
diff --git a/tests/ui/async-await/issues/issue-67893.stderr b/tests/ui/async-await/issues/issue-67893.stderr
index 12bbfc12552..0c28aea44bb 100644
--- a/tests/ui/async-await/issues/issue-67893.stderr
+++ b/tests/ui/async-await/issues/issue-67893.stderr
@@ -12,7 +12,6 @@ LL | pub async fn run() {
    | ------------------ within this `impl Future<Output = ()>`
    |
    = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `MutexGuard<'_, ()>`, which is required by `impl Future<Output = ()>: Send`
-   = note: required because it captures the following types: `Arc<Mutex<()>>`, `MutexGuard<'_, ()>`, `impl Future<Output = ()>`
 note: required because it's used within this `async` fn body
   --> $DIR/auxiliary/issue_67893.rs:9:20
    |
diff --git a/tests/ui/async-await/partial-drop-partial-reinit.rs b/tests/ui/async-await/partial-drop-partial-reinit.rs
index 36b3f2bc9ff..b72552ed324 100644
--- a/tests/ui/async-await/partial-drop-partial-reinit.rs
+++ b/tests/ui/async-await/partial-drop-partial-reinit.rs
@@ -8,7 +8,6 @@ fn main() {
     //~| NOTE cannot be sent
     //~| NOTE bound introduced by
     //~| NOTE appears within the type
-    //~| NOTE captures the following types
 }
 
 fn gimme_send<T: Send>(t: T) {
diff --git a/tests/ui/async-await/partial-drop-partial-reinit.stderr b/tests/ui/async-await/partial-drop-partial-reinit.stderr
index a6140c6db82..0bd7d50b941 100644
--- a/tests/ui/async-await/partial-drop-partial-reinit.stderr
+++ b/tests/ui/async-await/partial-drop-partial-reinit.stderr
@@ -11,9 +11,8 @@ LL | async fn foo() {
    |
    = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `NotSend`, which is required by `impl Future<Output = ()>: Send`
    = note: required because it appears within the type `(NotSend,)`
-   = note: required because it captures the following types: `(NotSend,)`, `impl Future<Output = ()>`
 note: required because it's used within this `async` fn body
-  --> $DIR/partial-drop-partial-reinit.rs:28:16
+  --> $DIR/partial-drop-partial-reinit.rs:27:16
    |
 LL |   async fn foo() {
    |  ________________^
@@ -25,7 +24,7 @@ LL | |     bar().await;
 LL | | }
    | |_^
 note: required by a bound in `gimme_send`
-  --> $DIR/partial-drop-partial-reinit.rs:14:18
+  --> $DIR/partial-drop-partial-reinit.rs:13:18
    |
 LL | fn gimme_send<T: Send>(t: T) {
    |                  ^^^^ required by this bound in `gimme_send`
diff --git a/tests/ui/coroutine/issue-68112.rs b/tests/ui/coroutine/issue-68112.rs
index e2be704dab7..ccec2acc976 100644
--- a/tests/ui/coroutine/issue-68112.rs
+++ b/tests/ui/coroutine/issue-68112.rs
@@ -65,7 +65,6 @@ fn test2() {
     //~^ ERROR `RefCell<i32>` cannot be shared between threads safely
     //~| NOTE `RefCell<i32>` cannot be shared between threads safely
     //~| NOTE required for
-    //~| NOTE captures the following types
     //~| NOTE use `std::sync::RwLock` instead
 }
 
diff --git a/tests/ui/coroutine/issue-68112.stderr b/tests/ui/coroutine/issue-68112.stderr
index ded325eda54..443195d36a3 100644
--- a/tests/ui/coroutine/issue-68112.stderr
+++ b/tests/ui/coroutine/issue-68112.stderr
@@ -44,7 +44,6 @@ note: required because it appears within the type `impl Coroutine<Return = Arc<R
    |
 LL | fn make_non_send_coroutine2() -> impl Coroutine<Return = Arc<RefCell<i32>>> {
    |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   = note: required because it captures the following types: `impl Coroutine<Return = Arc<RefCell<i32>>>`
 note: required because it's used within this coroutine
   --> $DIR/issue-68112.rs:60:20
    |
diff --git a/tests/ui/coroutine/print/coroutine-print-verbose-1.stderr b/tests/ui/coroutine/print/coroutine-print-verbose-1.stderr
index 1b9ca632f0c..37db83d57f7 100644
--- a/tests/ui/coroutine/print/coroutine-print-verbose-1.stderr
+++ b/tests/ui/coroutine/print/coroutine-print-verbose-1.stderr
@@ -43,7 +43,6 @@ note: required because it appears within the type `Opaque(DefId(0:36 ~ coroutine
    |
 LL | fn make_non_send_coroutine2() -> impl Coroutine<Return = Arc<RefCell<i32>>> {
    |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   = note: required because it captures the following types: `Opaque(DefId(0:36 ~ coroutine_print_verbose_1[75fb]::make_non_send_coroutine2::{opaque#0}), [])`
 note: required because it's used within this coroutine
   --> $DIR/coroutine-print-verbose-1.rs:52:20
    |