Files
rust/tests/ui
Matthias Krüger 4cadb5d513 Rollup merge of #135464 - lukas-code:project-infinite-to-error, r=FedericoBruzzone,oli-obk
fix ICE with references to infinite structs in consts

fixes https://github.com/rust-lang/rust/issues/114484

Normalizing `<Type as Pointee>::Metadata` may emit a (non-fatal) error during trait selection if finding the struct tail of `Type` hits the recursion limit. When this happens, prior this PR, we would treat the projection as rigid, i.e. don't normalize it further. This PR changes it so that we normalize to `ty::Error` instead.

This is important, because to compute the layout of `&Type` we need to compute the layout of `<Type as Pointee>::Metadata`

https://github.com/rust-lang/rust/blob/2ae9916816a448fcaab3b2da461de754eda0055a/compiler/rustc_ty_utils/src/layout.rs#L247-L273

and computing the layout of a rigid alias will (correctly) fail and needs to report an error to the user. For example:

```rust
trait Project {
    type Assoc;
}

fn foo<T: Project>() {
    [(); {
        let _: Option<T::Assoc> = None;
                   // ^^^^^^^^ this projection is rigid, so we can't know it's layout
        0
    }];
}
```

```
error: constant expression depends on a generic parameter
  --> src/lib.rs:6:10
   |
6  |       [(); {
   |  __________^
7  | |         let _: Option<T::Assoc> = None;
8  | |                    // ^^^^^^^^ this projection is rigid, so we can't know it's layout
9  | |         0
10 | |     }];
   | |_____^
   |
   = note: this may fail depending on what value the parameter takes
```

For non-generic rigid projections we will currently ICE, because we incorrectly assume that `LayoutError::Unknown` means that a const must be generic (https://github.com/rust-lang/rust/issues/135138). This is being fixed and turned into a proper error in https://github.com/rust-lang/rust/pull/135158.

```rust
#![feature(trivial_bounds)]

trait Project {
    type Assoc;
}

fn foo()
where
    u8: Project,
{
    [(); {
        let _: Option<<u8 as Project>::Assoc> = None; // ICEs currently, but will be an error
        0
    }];
}
```

However, if we hit the recursion limit when normalizing `<Type as Pointee>::Metadata` we don't want to report a layout error, because we already emitted the recursion error. So by normalizing to `ty::Error` here, we get a `LayoutError::ReferencesError` instead of a `LayoutError::Unknown` and don't report the layout error to the user.
2025-01-14 07:56:24 +01:00
..
2024-12-12 23:36:27 +00:00
2024-12-31 15:11:18 +08:00
2024-12-12 23:36:27 +00:00
2024-12-12 23:36:27 +00:00
2024-12-12 23:36:27 +00:00
2024-09-05 06:37:38 -04:00
2024-12-31 23:46:39 +08:00
2024-12-31 23:46:39 +08:00
2024-10-30 16:47:47 -07:00
2024-12-13 14:18:41 -08:00
2024-10-30 16:47:47 -07:00
2024-12-12 23:36:27 +00:00
2024-12-12 23:36:27 +00:00
2025-01-08 07:34:59 +00:00
2024-11-16 20:03:31 +00:00
2025-01-10 02:22:57 +01:00
2024-12-13 00:04:56 +00:00
2024-11-07 18:18:34 -08:00
2024-11-02 03:08:04 +00:00
2024-12-16 14:59:10 -05:00
2025-01-06 06:11:06 +00:00
2024-12-25 10:36:32 +01:00
2024-12-07 22:18:51 +00:00
2025-01-10 02:22:57 +01:00
2025-01-08 07:34:59 +00:00
2024-12-06 16:42:09 -05:00
2024-12-12 23:36:27 +00:00
2024-10-28 14:20:28 +11:00
2024-10-28 14:20:28 +11:00
2024-12-02 03:43:50 -07:00
2024-10-30 16:47:47 -07:00

UI Tests

This folder contains rustc's UI tests.

Test Directives (Headers)

Typically, a UI test will have some test directives / headers which are special comments that tell compiletest how to build and interpret a test.

As part of an ongoing effort to rewrite compiletest (see https://github.com/rust-lang/compiler-team/issues/536), a major change proposal to change legacy compiletest-style headers // <directive> to ui_test-style headers //@ <directive> was accepted (see https://github.com/rust-lang/compiler-team/issues/512.

An example directive is ignore-test. In legacy compiletest style, the header would be written as

// ignore-test

but in ui_test style, the header would be written as

//@ ignore-test

compiletest is changed to accept only //@ directives for UI tests (currently), and will reject and report an error if it encounters any comments // <content> that may be parsed as a legacy compiletest-style test header. To fix this, you should migrate to the ui_test-style header //@ <content>.