unicode-org / icu4x

Solving i18n for client-side and resource-constrained environments.
https://icu4x.unicode.org
Other
1.37k stars 176 forks source link

Change all compile_fail tests to use error number annotations #5752

Open sffc opened 3 days ago

sffc commented 3 days ago

Apparently (#5747) we can use notation such as

```compile_fail,E0271
// test that fails with code E0271
```

This isn't documented anywhere, but it is a feature for Rust developers according to @Manishearth. We should use it everywhere to make sure our compile_fail tests continue failing for the same reason.

CC @robertbastian

sffc commented 2 days ago

@Manishearth found the documentation for it:

https://doc.rust-lang.org/nightly/rustdoc/unstable-features.html#error-numbers-for-compile-fail-doctests

It says:

As detailed in the chapter on documentation tests, you can add a compile_fail attribute to a doctest to state that the test should fail to compile. However, on nightly, you can optionally add an error number to state that a doctest should emit a specific error number:

```compile_fail,E0044
extern { fn some_func<T>(x: T); }
```

This is used by the error index to ensure that the samples that correspond to a given error number properly emit that error code. However, these error codes aren't guaranteed to be the only thing that a piece of code emits from version to version, so this is unlikely to be stabilized in the future.

Attempting to use these error numbers on stable will result in the code sample being interpreted as plain text.

We do run tests on nightly each night.

However, I'm a bit concerned by the last line. I think it would be nice if on stable we would still enforce the compile_fail. But maybe that's not necessary.

I wonder if it still produces the "this code does not compile" CSS styles in the rustdoc?

robertbastian commented 2 days ago

Huh I thought this was already stable.