rust/tests/ui/impl-trait/auto-trait-leakage/auto-trait-leak2.rs
Esteban Küber 99196657fc Use tcx.short_string() in more diagnostics
`TyCtxt::short_string` ensures that user visible type paths aren't overwhelming on the terminal output, and properly saves the long name to disk as a side-channel. We already use these throughout the compiler and have been using them as needed when users find cases where the output is verbose. This is a proactive search of some cases to use `short_string`.

We add support for shortening the path of "trait path only".

Every manual use of `short_string` is a bright marker that that error should be using structured diagnostics instead (as they have proper handling of long types without the maintainer having to think abou tthem).

When we don't actually print out a shortened type we don't need the "use `--verbose`" note.

On E0599 show type identity to avoid expanding the receiver's generic parameters.

Unify wording on `long_ty_path` everywhere.
2025-08-07 21:18:00 +00:00

41 lines
1.2 KiB
Rust

//@ compile-flags: -Zwrite-long-types-to-disk=yes
use std::cell::Cell;
use std::rc::Rc;
// Fast path, main can see the concrete type returned.
fn before() -> impl Fn(i32) {
//~^ NOTE within this `impl Fn
//~| NOTE within the type `impl Fn
//~| NOTE expansion of desugaring
let p = Rc::new(Cell::new(0));
move |x| p.set(x) //~ NOTE used within this closure
}
fn send<T: Send>(_: T) {}
//~^ NOTE required by a bound
//~| NOTE required by a bound
//~| NOTE required by this bound
//~| NOTE required by this bound
fn main() {
send(before());
//~^ ERROR `Rc<Cell<i32>>` cannot be sent between threads safely
//~| NOTE `Rc<Cell<i32>>` cannot be sent between threads safely
//~| NOTE required by a bound
send(after());
//~^ ERROR `Rc<Cell<i32>>` cannot be sent between threads safely
//~| NOTE `Rc<Cell<i32>>` cannot be sent between threads safely
//~| NOTE required by a bound
}
// Deferred path, main has to wait until typeck finishes,
// to check if the return type of after is Send.
fn after() -> impl Fn(i32) {
//~^ NOTE within this `impl Fn(i32)`
//~| NOTE in this expansion
//~| NOTE appears within the type
let p = Rc::new(Cell::new(0));
move |x| p.set(x) //~ NOTE used within this closure
}