dtolnay/trybuild

API/config to pass --verbose to avoid name shortening

sandersaares opened this issue · 1 comments

I observe that in some scenarios, my trybuild tests are triggering the Rust long type name shortening logic. This is inconsistent between usages: in some situations my trybuild tests trigger this shortening, in others not. Perhaps due to filesystem paths or whatnot differences? Hard to say. Anyway, this changes the stderr output, so causes inconsistent test results.

Example of this happening to others: rust-lang/rust#113424

This is not desirable, so I am looking for a way to disable this behavior in all my trybuild tests (running in stable toolchain). As per rust-lang/rust#119130 it seems that passing --verbose can be used to disable this logic, which seems suitable (though I wonder what else it does).

I would like to pass this flag in all my trybuild tests. Today, no feature for this appears to exist - I request such a feature (in a form that would not require me to apply it globally in env variables).

I was able to reproduce this using this test case:

use std::marker::PhantomData as P;

fn f(_: ()) {}

fn main() {
    let p: (P<P<P<P<P<P<P<P<()>>>>>>>>, _) = (P, || {});
    f(p);
}

When running ui tests from a directory that has a relatively short filepath, the normalized stderr is:

error[E0308]: mismatched types
 --> tests/ui/long-type-name.rs:7:7
  |
6 |     let p: (P<P<P<P<P<P<P<P<()>>>>>>>>, _) = (P, || {});
  |                                                  -- the found closure
7 |     f(p);
  |     - ^ expected `()`, found `(PhantomData<...>, ...)`
  |     |
  |     arguments to this function are incorrect
  |
  = note: expected unit type `()`
                 found tuple `(PhantomData<PhantomData<PhantomData<PhantomData<PhantomData<PhantomData<PhantomData<PhantomData<()>>>>>>>>, {closure@$DIR/tests/ui/long-type-name.rs:6:50: 6:52})`
note: function defined here
 --> tests/ui/long-type-name.rs:3:4
  |
3 | fn f(_: ()) {}
  |    ^ -----

In a longer filepath, the same test produces:

error[E0308]: mismatched types
 --> tests/ui/long-type-name.rs:7:7
  |
6 |     let p: (P<P<P<P<P<P<P<P<()>>>>>>>>, _) = (P, || {});
  |                                                  -- the found closure
7 |     f(p);
  |     - ^ expected `()`, found `(PhantomData<...>, ...)`
  |     |
  |     arguments to this function are incorrect
  |
  = note: expected unit type `()`
                 found tuple `(PhantomData<PhantomData<PhantomData<PhantomData<PhantomData<PhantomData<PhantomData<...>>>>>>>, ...)`
  = note: consider using `--verbose` to print the full type name to the console
note: function defined here
 --> tests/ui/long-type-name.rs:3:4
  |
3 | fn f(_: ()) {}
  |    ^ -----

I think it would be fine for trybuild to pass --verbose unconditionally to circumvent this discrepancy.