Skip to content

Alternative to full-string matching #320

@MauriceKayser

Description

@MauriceKayser

The Rust compiler can emit error messages that include file paths as well as line and column numbers (e.g. of the standard library). Because these details can vary across environments and compiler versions, tests that rely on trybuild's current full-string matching become fragile and difficult to maintain. It would be very helpful if trybuild provided a more flexible way to handle such volatile output - for instance, by supporting substring matching like should_panic for normal Rust unit tests.

Example Rust Playground:

fn main() {
    trait A { fn a(); }
    impl<T> A for T where T: std::fmt::Display { fn a() {} }

    struct X;
    X::a();
}

Volatile part of the error message:

note: the trait `std::fmt::Display` must be implemented
    --> /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:1006:1
     |
1006 | pub trait Display: PointeeSized {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For this code snippet I have observed many different paths like:

C:\Users\Maurice.Kayser\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\fmt\mod.rs:984:1
         /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:1186:1
          /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:1006:1
            /playground/.rustup/toolchains/beta-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:1007:1
                                     /builddir/build/BUILD/rust-1.91.0-build/rustc-1.91.0-src/library/core/src/fmt/mod.rs:1006:1
                                              /rustc/1159e78c4747b02ef996e55082b704c09b970588/library/core/src/fmt/mod.rs:1006:1

Implementing an alternative to full-string matching might also help for #317.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions