Skip to content

Commit 560185a

Browse files
committed
Remove useless note
When we don't actually print out a shortened type we don't need the "use `--verbose`" note.
1 parent 4d2ec8c commit 560185a

File tree

5 files changed

+26
-33
lines changed

5 files changed

+26
-33
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,17 +3323,22 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
33233323
tcx.async_fn_trait_kind_from_def_id(data.parent_trait_pred.def_id()).is_some();
33243324

33253325
if !is_upvar_tys_infer_tuple && !is_builtin_async_fn_trait {
3326-
let ty_str = tcx.short_string(ty, err.long_ty_path());
3327-
let msg = format!("required because it appears within the type `{ty_str}`");
3326+
let mut msg = || {
3327+
let ty_str = tcx.short_string(ty, err.long_ty_path());
3328+
format!("required because it appears within the type `{ty_str}`")
3329+
};
33283330
match ty.kind() {
3329-
ty::Adt(def, _) => match tcx.opt_item_ident(def.did()) {
3330-
Some(ident) => {
3331-
err.span_note(ident.span, msg);
3332-
}
3333-
None => {
3334-
err.note(msg);
3331+
ty::Adt(def, _) => {
3332+
let msg = msg();
3333+
match tcx.opt_item_ident(def.did()) {
3334+
Some(ident) => {
3335+
err.span_note(ident.span, msg);
3336+
}
3337+
None => {
3338+
err.note(msg);
3339+
}
33353340
}
3336-
},
3341+
}
33373342
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
33383343
// If the previous type is async fn, this is the future generated by the body of an async function.
33393344
// Avoid printing it twice (it was already printed in the `ty::Coroutine` arm below).
@@ -3353,6 +3358,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
33533358
{
33543359
// See comment above; skip printing twice.
33553360
} else {
3361+
let msg = msg();
33563362
err.span_note(tcx.def_span(def_id), msg);
33573363
}
33583364
}
@@ -3382,6 +3388,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
33823388
err.note("`str` is considered to contain a `[u8]` slice for auto trait purposes");
33833389
}
33843390
_ => {
3391+
let msg = msg();
33853392
err.note(msg);
33863393
}
33873394
};

tests/ui/impl-trait/auto-trait-leakage/auto-trait-leak2.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// FIXME(estebank): diagnostics with long type paths that don't print out the full path anywhere
2-
// still prints the note explaining where the type was written to.
31
//@ compile-flags: -Zwrite-long-types-to-disk=yes
42
use std::cell::Cell;
53
use std::rc::Rc;
@@ -24,15 +22,11 @@ fn main() {
2422
//~^ ERROR `Rc<Cell<i32>>` cannot be sent between threads safely
2523
//~| NOTE `Rc<Cell<i32>>` cannot be sent between threads safely
2624
//~| NOTE required by a bound
27-
//~| NOTE the full name for the type has been written
28-
//~| NOTE consider using `--verbose`
2925

3026
send(after());
3127
//~^ ERROR `Rc<Cell<i32>>` cannot be sent between threads safely
3228
//~| NOTE `Rc<Cell<i32>>` cannot be sent between threads safely
3329
//~| NOTE required by a bound
34-
//~| NOTE the full name for the type has been written
35-
//~| NOTE consider using `--verbose`
3630
}
3731

3832
// Deferred path, main has to wait until typeck finishes,

tests/ui/impl-trait/auto-trait-leakage/auto-trait-leak2.stderr

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: `Rc<Cell<i32>>` cannot be sent between threads safely
2-
--> $DIR/auto-trait-leak2.rs:23:10
2+
--> $DIR/auto-trait-leak2.rs:21:10
33
|
44
LL | fn before() -> impl Fn(i32) {
55
| ------------ within this `impl Fn(i32)`
@@ -11,25 +11,23 @@ LL | send(before());
1111
|
1212
= help: within `impl Fn(i32)`, the trait `Send` is not implemented for `Rc<Cell<i32>>`
1313
note: required because it's used within this closure
14-
--> $DIR/auto-trait-leak2.rs:13:5
14+
--> $DIR/auto-trait-leak2.rs:11:5
1515
|
1616
LL | move |x| p.set(x)
1717
| ^^^^^^^^
1818
note: required because it appears within the type `impl Fn(i32)`
19-
--> $DIR/auto-trait-leak2.rs:8:16
19+
--> $DIR/auto-trait-leak2.rs:6:16
2020
|
2121
LL | fn before() -> impl Fn(i32) {
2222
| ^^^^^^^^^^^^
2323
note: required by a bound in `send`
24-
--> $DIR/auto-trait-leak2.rs:16:12
24+
--> $DIR/auto-trait-leak2.rs:14:12
2525
|
2626
LL | fn send<T: Send>(_: T) {}
2727
| ^^^^ required by this bound in `send`
28-
= note: the full name for the type has been written to '$TEST_BUILD_DIR/auto-trait-leak2.long-type-$LONG_TYPE_HASH.txt'
29-
= note: consider using `--verbose` to print the full type name to the console
3028

3129
error[E0277]: `Rc<Cell<i32>>` cannot be sent between threads safely
32-
--> $DIR/auto-trait-leak2.rs:30:10
30+
--> $DIR/auto-trait-leak2.rs:26:10
3331
|
3432
LL | send(after());
3533
| ---- ^^^^^^^ `Rc<Cell<i32>>` cannot be sent between threads safely
@@ -41,22 +39,20 @@ LL | fn after() -> impl Fn(i32) {
4139
|
4240
= help: within `impl Fn(i32)`, the trait `Send` is not implemented for `Rc<Cell<i32>>`
4341
note: required because it's used within this closure
44-
--> $DIR/auto-trait-leak2.rs:45:5
42+
--> $DIR/auto-trait-leak2.rs:39:5
4543
|
4644
LL | move |x| p.set(x)
4745
| ^^^^^^^^
4846
note: required because it appears within the type `impl Fn(i32)`
49-
--> $DIR/auto-trait-leak2.rs:40:15
47+
--> $DIR/auto-trait-leak2.rs:34:15
5048
|
5149
LL | fn after() -> impl Fn(i32) {
5250
| ^^^^^^^^^^^^
5351
note: required by a bound in `send`
54-
--> $DIR/auto-trait-leak2.rs:16:12
52+
--> $DIR/auto-trait-leak2.rs:14:12
5553
|
5654
LL | fn send<T: Send>(_: T) {}
5755
| ^^^^ required by this bound in `send`
58-
= note: the full name for the type has been written to '$TEST_BUILD_DIR/auto-trait-leak2.long-type-$LONG_TYPE_HASH.txt'
59-
= note: consider using `--verbose` to print the full type name to the console
6056

6157
error: aborting due to 2 previous errors
6258

tests/ui/interior-mutability/interior-mutability.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// FIXME(estebank): diagnostics with long type paths that don't print out the full path anywhere
2-
// still prints the note explaining where the type was written to.
31
//@ compile-flags: -Zwrite-long-types-to-disk=yes
42
use std::cell::Cell;
53
use std::panic::catch_unwind;

tests/ui/interior-mutability/interior-mutability.stderr

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the type `UnsafeCell<i32>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
2-
--> $DIR/interior-mutability.rs:8:18
2+
--> $DIR/interior-mutability.rs:6:18
33
|
44
LL | catch_unwind(|| { x.set(23); });
55
| ------------ ^^^^^^^^^^^^^^^^^ `UnsafeCell<i32>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
@@ -11,14 +11,12 @@ note: required because it appears within the type `Cell<i32>`
1111
--> $SRC_DIR/core/src/cell.rs:LL:COL
1212
= note: required for `&Cell<i32>` to implement `UnwindSafe`
1313
note: required because it's used within this closure
14-
--> $DIR/interior-mutability.rs:8:18
14+
--> $DIR/interior-mutability.rs:6:18
1515
|
1616
LL | catch_unwind(|| { x.set(23); });
1717
| ^^
1818
note: required by a bound in `std::panic::catch_unwind`
1919
--> $SRC_DIR/std/src/panic.rs:LL:COL
20-
= note: the full name for the type has been written to '$TEST_BUILD_DIR/interior-mutability.long-type-$LONG_TYPE_HASH.txt'
21-
= note: consider using `--verbose` to print the full type name to the console
2220

2321
error: aborting due to 1 previous error
2422

0 commit comments

Comments
 (0)