Skip to content

Commit

Permalink
Fix inlay-hint tests being invalidated by minicore chanes
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Nov 14, 2023
1 parent 6ddccc9 commit e3047cb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
10 changes: 10 additions & 0 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ impl Module {
acc.push(TraitImplOrphan { impl_: ast_id_map.get(node.ast_id()), file_id }.into())
}

let impl_is_unsafe = impl_def.is_unsafe(db);
if !impl_def.check_orphan_rules(db) {
let ast_id_map = db.ast_id_map(file_id);
acc.push(TraitImplOrphan { impl_: ast_id_map.get(node.ast_id()), file_id }.into())
}

for item in impl_def.items(db) {
let def: DefWithBody = match item {
AssocItem::Function(it) => it.into(),
Expand Down Expand Up @@ -3403,6 +3409,10 @@ impl Impl {
db.impl_data(self.id).is_negative
}

pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool {
db.impl_data(self.id).is_unique()
}

pub fn module(self, db: &dyn HirDatabase) -> Module {
self.id.lookup(db.upcast()).container.into()
}
Expand Down
17 changes: 17 additions & 0 deletions crates/ide/src/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ mod tests {
use hir::ClosureStyle;
use itertools::Itertools;
use test_utils::extract_annotations;
use text_edit::{TextRange, TextSize};

use crate::inlay_hints::{AdjustmentHints, AdjustmentHintsMode};
use crate::DiscriminantHints;
Expand Down Expand Up @@ -629,6 +630,22 @@ mod tests {
expect.assert_debug_eq(&inlay_hints)
}

#[track_caller]
pub(super) fn check_expect_clear_loc(
config: InlayHintsConfig,
ra_fixture: &str,
expect: Expect,
) {
let (analysis, file_id) = fixture::file(ra_fixture);
let mut inlay_hints = analysis.inlay_hints(&config, file_id, None).unwrap();
inlay_hints.iter_mut().flat_map(|hint| &mut hint.label.parts).for_each(|hint| {
if let Some(loc) = &mut hint.linked_location {
loc.range = TextRange::empty(TextSize::from(0));
}
});
expect.assert_debug_eq(&inlay_hints)
}

/// Computes inlay hints for the fixture, applies all the provided text edits and then runs
/// expect test.
#[track_caller]
Expand Down
20 changes: 11 additions & 9 deletions crates/ide/src/inlay_hints/chaining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ mod tests {
use expect_test::expect;

use crate::{
inlay_hints::tests::{check_expect, check_with_config, DISABLED_CONFIG, TEST_CONFIG},
inlay_hints::tests::{
check_expect, check_expect_clear_loc, check_with_config, DISABLED_CONFIG, TEST_CONFIG,
},
InlayHintsConfig,
};

Expand Down Expand Up @@ -444,7 +446,7 @@ fn main() {

#[test]
fn shorten_iterator_chaining_hints() {
check_expect(
check_expect_clear_loc(
InlayHintsConfig { chaining_hints: true, ..DISABLED_CONFIG },
r#"
//- minicore: iterators
Expand Down Expand Up @@ -484,7 +486,7 @@ fn main() {
file_id: FileId(
1,
),
range: 10752..10760,
range: 0..0,
},
),
tooltip: "",
Expand All @@ -497,7 +499,7 @@ fn main() {
file_id: FileId(
1,
),
range: 10784..10788,
range: 0..0,
},
),
tooltip: "",
Expand All @@ -522,7 +524,7 @@ fn main() {
file_id: FileId(
1,
),
range: 10752..10760,
range: 0..0,
},
),
tooltip: "",
Expand All @@ -535,7 +537,7 @@ fn main() {
file_id: FileId(
1,
),
range: 10784..10788,
range: 0..0,
},
),
tooltip: "",
Expand All @@ -560,7 +562,7 @@ fn main() {
file_id: FileId(
1,
),
range: 10752..10760,
range: 0..0,
},
),
tooltip: "",
Expand All @@ -573,7 +575,7 @@ fn main() {
file_id: FileId(
1,
),
range: 10784..10788,
range: 0..0,
},
),
tooltip: "",
Expand All @@ -598,7 +600,7 @@ fn main() {
file_id: FileId(
0,
),
range: 24..30,
range: 0..0,
},
),
tooltip: "",
Expand Down

0 comments on commit e3047cb

Please sign in to comment.