diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-02-18 18:40:49 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-18 18:40:49 +0100 |
| commit | 7edd17cfbbca044c165dc01f73ebea04f7eec588 (patch) | |
| tree | 63ec4ce3608afc8673c4c68039528927ee31b00e /tests/ui/structs | |
| parent | 3b022d8ceea570db9730be34d964f0cc663a567f (diff) | |
| parent | 08ee5f5e63afe3e6a3d852932484c506d0eaee87 (diff) | |
| download | rust-7edd17cfbbca044c165dc01f73ebea04f7eec588.tar.gz rust-7edd17cfbbca044c165dc01f73ebea04f7eec588.zip | |
Rollup merge of #135711 - estebank:issue-135649, r=davidtwco
Do not ICE on default_field_value const with lifetimes `#![feature(default_field_values)]` uses a `const` body that should be treated as inline `const`s, but is actually being detected otherwise. This is similar to the situation in #78174, so we take the same solution: we check if the const actually comes from a field, and if it does, we use that logic to get the appropriate lifetimes and not ICE during borrowck. Fix #135649.
Diffstat (limited to 'tests/ui/structs')
| -rw-r--r-- | tests/ui/structs/default-field-values/do-not-ice-on-invalid-lifetime.rs | 6 | ||||
| -rw-r--r-- | tests/ui/structs/default-field-values/do-not-ice-on-invalid-lifetime.stderr | 23 |
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/ui/structs/default-field-values/do-not-ice-on-invalid-lifetime.rs b/tests/ui/structs/default-field-values/do-not-ice-on-invalid-lifetime.rs new file mode 100644 index 00000000000..71d90ddd935 --- /dev/null +++ b/tests/ui/structs/default-field-values/do-not-ice-on-invalid-lifetime.rs @@ -0,0 +1,6 @@ +#![feature(default_field_values)] +struct A<'a> { //~ ERROR lifetime parameter `'a` is never used + x: Vec<A> = Vec::new(), //~ ERROR missing lifetime specifier +} + +fn main() {} diff --git a/tests/ui/structs/default-field-values/do-not-ice-on-invalid-lifetime.stderr b/tests/ui/structs/default-field-values/do-not-ice-on-invalid-lifetime.stderr new file mode 100644 index 00000000000..20b9afe80cd --- /dev/null +++ b/tests/ui/structs/default-field-values/do-not-ice-on-invalid-lifetime.stderr @@ -0,0 +1,23 @@ +error[E0106]: missing lifetime specifier + --> $DIR/do-not-ice-on-invalid-lifetime.rs:3:12 + | +LL | x: Vec<A> = Vec::new(), + | ^ expected named lifetime parameter + | +help: consider using the `'a` lifetime + | +LL | x: Vec<A<'a>> = Vec::new(), + | ++++ + +error[E0392]: lifetime parameter `'a` is never used + --> $DIR/do-not-ice-on-invalid-lifetime.rs:2:10 + | +LL | struct A<'a> { + | ^^ unused lifetime parameter + | + = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0106, E0392. +For more information about an error, try `rustc --explain E0106`. |
