about summary refs log tree commit diff
path: root/tests/pretty
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2025-03-25 08:21:28 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2025-03-28 10:15:23 +1100
commit8d2c63f514a74752a3186b0bf3e8f3aef57dc12e (patch)
tree887b83d34fc08db03dd8b3c09fc80183a15734b5 /tests/pretty
parentcfd00f9c16d9b3ab98d6e06125c6baa83dfa4a03 (diff)
downloadrust-8d2c63f514a74752a3186b0bf3e8f3aef57dc12e.tar.gz
rust-8d2c63f514a74752a3186b0bf3e8f3aef57dc12e.zip
Don't use `kw::Empty` in `hir::Lifetime::ident`.
`hir::Lifetime::ident` currently sometimes uses `kw::Empty` for elided
lifetimes and sometimes uses `kw::UnderscoreLifetime`, and the
distinction is used when creating some error suggestions, e.g. in
`Lifetime::suggestion` and `ImplicitLifetimeFinder::visit_ty`. I found
this *really* confusing, and it took me a while to understand what was
going on.

This commit replaces all uses of `kw::Empty` in `hir::Lifetime::ident`
with `kw::UnderscoreLifetime`. It adds a new field
`hir::Lifetime::is_path_anon` that mostly replaces the old
empty/underscore distinction and makes things much clearer.

Some other notable changes:

- Adds a big comment to `Lifetime` talking about permissable field
  values.

- Adds some assertions in `new_named_lifetime` about what ident values
  are permissible for the different `LifetimeRes` values.

- Adds a `Lifetime::new` constructor that does some checking to make
  sure the `is_elided` and `is_anonymous` states are valid.

- `add_static_impl_trait_suggestion` now looks at `Lifetime::res`
  instead of the ident when creating the suggestion. This is the one
  case where `is_path_anon` doesn't replace the old empty/underscore
  distinction.

- A couple of minor pretty-printing improvements.
Diffstat (limited to 'tests/pretty')
-rw-r--r--tests/pretty/hir-lifetimes.pp4
1 files changed, 2 insertions, 2 deletions
diff --git a/tests/pretty/hir-lifetimes.pp b/tests/pretty/hir-lifetimes.pp
index df3aba516b9..e545b0c8f57 100644
--- a/tests/pretty/hir-lifetimes.pp
+++ b/tests/pretty/hir-lifetimes.pp
@@ -73,7 +73,7 @@ fn h<'b, F>(f: F, y: Foo<'b>) where F: for<'d> MyTrait<'d, 'b> { }
 struct S<'a>(&'a u32);
 
 extern "C" {
-    unsafe fn g1(s: S<>);
+    unsafe fn g1(s: S<'_>);
     unsafe fn g2(s: S<'_>);
     unsafe fn g3<'a>(s: S<'a>);
 }
@@ -86,7 +86,7 @@ fn f() { { let _ = St{ x: &0,}; }; { let _ = St{ x: &0,}; }; }
 
 struct Name<'a>(&'a str);
 
-const A: Name<> = Name("a");
+const A: Name<'_> = Name("a");
 const B: &'_ str = "";
 static C: &'_ str = "";
 static D: &'static str = "";