Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Always show error lifetime arguments as '_ #17963

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Show and render error lifetime args as '_
  • Loading branch information
avrong committed Aug 26, 2024
commit 7ea4241afa8432b43b0a8d31b172171d02390d86
20 changes: 7 additions & 13 deletions crates/hir-ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1523,18 +1523,6 @@ fn hir_fmt_generic_arguments(
None => (parameters, &[][..]),
};
for generic_arg in lifetimes.iter().chain(ty_or_const) {
// FIXME: Remove this
// most of our lifetimes will be errors as we lack elision and inference
// so don't render them for now
if !cfg!(test)
&& matches!(
generic_arg.lifetime(Interner),
Some(l) if ***l.interned() == LifetimeData::Error
)
{
continue;
}

if !mem::take(&mut first) {
write!(f, ", ")?;
}
Expand Down Expand Up @@ -1872,7 +1860,13 @@ impl HirDisplay for LifetimeData {
LifetimeData::BoundVar(idx) => idx.hir_fmt(f),
LifetimeData::InferenceVar(_) => write!(f, "_"),
LifetimeData::Static => write!(f, "'static"),
LifetimeData::Error => write!(f, "'?"),
LifetimeData::Error => {
if cfg!(test) {
write!(f, "'?")
} else {
write!(f, "'_")
}
}
LifetimeData::Erased => write!(f, "'<erased>"),
LifetimeData::Phantom(void, _) => match *void {},
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/extract_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5649,7 +5649,7 @@ fn func<T: Debug>(i: Struct<'_, T>) {
fun_name(i);
}

fn $0fun_name(i: Struct<T>) {
fn $0fun_name(i: Struct<'_, T>) {
foo(i);
}
"#,
Expand Down
4 changes: 2 additions & 2 deletions crates/ide-completion/src/tests/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct Foo<'lt, T, const C: usize> where $0 {}
en Enum Enum
ma makro!(…) macro_rules! makro
md module
st Foo<…> Foo<{unknown}, _>
st Foo<…> Foo<'_, {unknown}, _>
st Record Record
st Tuple Tuple
st Unit Unit
Expand Down Expand Up @@ -92,7 +92,7 @@ struct Foo<'lt, T, const C: usize> where for<'a> $0 {}
en Enum Enum
ma makro!(…) macro_rules! makro
md module
st Foo<…> Foo<{unknown}, _>
st Foo<…> Foo<'_, {unknown}, _>
st Record Record
st Tuple Tuple
st Unit Unit
Expand Down
8 changes: 4 additions & 4 deletions crates/ide-completion/src/tests/type_pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ struct Foo<'lt, T, const C: usize> {
en Enum Enum
ma makro!(…) macro_rules! makro
md module
sp Self Foo<{unknown}, _>
st Foo<…> Foo<{unknown}, _>
sp Self Foo<'_, {unknown}, _>
st Foo<…> Foo<'_, {unknown}, _>
st Record Record
st Tuple Tuple
st Unit Unit
Expand All @@ -45,8 +45,8 @@ struct Foo<'lt, T, const C: usize>(f$0);
en Enum Enum
ma makro!(…) macro_rules! makro
md module
sp Self Foo<{unknown}, _>
st Foo<…> Foo<{unknown}, _>
sp Self Foo<'_, {unknown}, _>
st Foo<…> Foo<'_, {unknown}, _>
st Record Record
st Tuple Tuple
st Unit Unit
Expand Down
2 changes: 1 addition & 1 deletion crates/ide/src/inlay_hints/bind_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ fn f<'a>() {
let x = S::<'static>;
//^ S<'static>
let y = S::<'_>;
//^ S
//^ S<'_>
let z = S::<'a>;
//^ S<'a>

Expand Down