7396: More annoying asserts r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2021-01-22 16:16:22 +00:00 committed by GitHub
commit e73cc8b4ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 128 additions and 139 deletions

View File

@ -83,7 +83,7 @@ fn foo(s: S) { s.$0 }
"#,
expect![[r#"
fd foo u32
me bar() fn bar(&self)
me bar() -> ()
"#]],
);
}
@ -99,7 +99,7 @@ impl S {
"#,
expect![[r#"
fd the_field (u32,)
me foo() fn foo(self)
me foo() -> ()
"#]],
)
}
@ -115,7 +115,7 @@ impl A {
"#,
expect![[r#"
fd the_field (u32, i32)
me foo() fn foo(&self)
me foo() -> ()
"#]],
)
}
@ -165,7 +165,7 @@ mod m {
fn foo(a: A) { a.$0 }
"#,
expect![[r#"
me the_method() pub(crate) fn the_method(&self)
me the_method() -> ()
"#]],
);
}
@ -198,7 +198,7 @@ impl A<i32> {
fn foo(a: A<u32>) { a.$0 }
"#,
expect![[r#"
me the_method() fn the_method(&self)
me the_method() -> ()
"#]],
)
}
@ -213,7 +213,7 @@ impl Trait for A {}
fn foo(a: A) { a.$0 }
"#,
expect![[r#"
me the_method() fn the_method(&self)
me the_method() -> ()
"#]],
);
}
@ -228,7 +228,7 @@ impl<T> Trait for T {}
fn foo(a: &A) { a.$0 }
",
expect![[r#"
me the_method() fn the_method(&self)
me the_method() -> ()
"#]],
);
}
@ -246,7 +246,7 @@ impl Trait for A {}
fn foo(a: A) { a.$0 }
",
expect![[r#"
me the_method() fn the_method(&self)
me the_method() -> ()
"#]],
);
}
@ -300,7 +300,7 @@ impl T {
}
"#,
expect![[r#"
me blah() pub fn blah(&self)
me blah() -> ()
"#]],
);
}
@ -409,7 +409,7 @@ fn foo() {
}
"#,
expect![[r#"
me the_method() pub fn the_method(&self)
me the_method() -> ()
"#]],
);
}
@ -424,7 +424,7 @@ macro_rules! make_s { () => { S }; }
fn main() { make_s!().f$0; }
"#,
expect![[r#"
me foo() fn foo(&self)
me foo() -> ()
"#]],
)
}

View File

@ -366,8 +366,8 @@ fn main() {
check(
fixture,
expect![[r#"
fn weird_function() (dep::test_mod::TestTrait) fn weird_function()
"#]],
fn weird_function() (dep::test_mod::TestTrait) -> ()
"#]],
);
check_edit(
@ -459,8 +459,8 @@ fn main() {
check(
fixture,
expect![[r#"
me random_method() (dep::test_mod::TestTrait) fn random_method(&self)
"#]],
me random_method() (dep::test_mod::TestTrait) -> ()
"#]],
);
check_edit(
@ -629,8 +629,8 @@ fn main() {
}
"#,
expect![[r#"
me random_method() (dep::test_mod::TestTrait) fn random_method(&self) DEPRECATED
"#]],
me random_method() (dep::test_mod::TestTrait) -> () DEPRECATED
"#]],
);
check(
@ -660,8 +660,8 @@ fn main() {
"#,
expect![[r#"
ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED
fn weird_function() (dep::test_mod::TestTrait) fn weird_function() DEPRECATED
"#]],
fn weird_function() (dep::test_mod::TestTrait) -> () DEPRECATED
"#]],
);
}
}

View File

@ -359,8 +359,8 @@ impl S {
fn foo() { let _ = S::$0 }
"#,
expect![[r#"
fn a() fn a()
me b() fn b(&self)
fn a() -> ()
me b() -> ()
ct C const C: i32 = 42;
ta T type T = i32;
"#]],
@ -387,7 +387,7 @@ mod m {
fn foo() { let _ = S::$0 }
"#,
expect![[r#"
fn public_method() pub(crate) fn public_method()
fn public_method() -> ()
ct PUBLIC_CONST pub(crate) const PUBLIC_CONST: u32 = 1;
ta PublicType pub(crate) type PublicType = u32;
"#]],
@ -404,7 +404,7 @@ impl E { fn m() { } }
fn foo() { let _ = E::$0 }
"#,
expect![[r#"
fn m() fn m()
fn m() -> ()
"#]],
);
}
@ -419,7 +419,7 @@ impl U { fn m() { } }
fn foo() { let _ = U::$0 }
"#,
expect![[r#"
fn m() fn m()
fn m() -> ()
"#]],
);
}
@ -449,7 +449,7 @@ trait Trait { fn m(); }
fn foo() { let _ = Trait::$0 }
"#,
expect![[r#"
fn m() fn m()
fn m() -> ()
"#]],
);
}
@ -466,7 +466,7 @@ impl Trait for S {}
fn foo() { let _ = S::$0 }
"#,
expect![[r#"
fn m() fn m()
fn m() -> ()
"#]],
);
}
@ -483,7 +483,7 @@ impl Trait for S {}
fn foo() { let _ = <S as Trait>::$0 }
"#,
expect![[r#"
fn m() fn m()
fn m() -> ()
"#]],
);
}
@ -512,11 +512,11 @@ fn foo<T: Sub>() { T::$0 }
ta SubTy type SubTy;
ta Ty type Ty;
ct C2 const C2: ();
fn subfunc() fn subfunc()
me submethod() fn submethod(&self)
fn subfunc() -> ()
me submethod() -> ()
ct CONST const CONST: u8;
fn func() fn func()
me method() fn method(&self)
fn func() -> ()
me method() -> ()
"#]],
);
}
@ -552,11 +552,11 @@ impl<T> Sub for Wrap<T> {
ta SubTy type SubTy;
ta Ty type Ty;
ct CONST const CONST: u8 = 0;
fn func() fn func()
me method() fn method(&self)
fn func() -> ()
me method() -> ()
ct C2 const C2: () = ();
fn subfunc() fn subfunc()
me submethod() fn submethod(&self)
fn subfunc() -> ()
me submethod() -> ()
"#]],
);
}
@ -573,8 +573,8 @@ impl T { fn bar() {} }
fn main() { T::$0; }
"#,
expect![[r#"
fn foo() fn foo()
fn bar() fn bar()
fn foo() -> ()
fn bar() -> ()
"#]],
);
}
@ -589,7 +589,7 @@ macro_rules! foo { () => {} }
fn main() { let _ = crate::$0 }
"#,
expect![[r##"
fn main() fn main()
fn main() -> ()
ma foo!() #[macro_export] macro_rules! foo
"##]],
);
@ -633,7 +633,7 @@ mod p {
"#,
expect![[r#"
ct RIGHT_CONST
fn right_fn() fn wrong_fn()
fn right_fn() -> ()
st RightType
"#]],
);
@ -680,8 +680,8 @@ fn main() { m!(self::f$0); }
fn foo() {}
"#,
expect![[r#"
fn main() fn main()
fn foo() fn foo()
fn main() -> ()
fn foo() -> ()
"#]],
);
}
@ -699,7 +699,7 @@ mod m {
"#,
expect![[r#"
md z
fn z() pub fn z()
fn z() -> ()
"#]],
);
}
@ -719,7 +719,7 @@ fn foo() {
}
"#,
expect![[r#"
fn new() pub fn new() -> HashMap<K, V, RandomState>
fn new() -> HashMap<K, V, RandomState>
"#]],
);
}
@ -752,8 +752,8 @@ fn main() {
}
"#,
expect![[r#"
fn main() fn main()
fn foo() fn foo(a: i32, b: i32)
fn main() -> ()
fn foo() -> ()
"#]],
);
}
@ -776,7 +776,7 @@ impl Foo {
expect![[r#"
ev Bar ()
ev Baz ()
me foo() fn foo(self)
me foo() -> ()
"#]],
);
}

View File

@ -679,11 +679,6 @@ impl Test for () {
#[test]
fn complete_without_name() {
let test = |completion: &str, hint: &str, completed: &str, next_sibling: &str| {
println!(
"completion='{}', hint='{}', next_sibling='{}'",
completion, hint, next_sibling
);
check_edit(
completion,
&format!(

View File

@ -167,7 +167,7 @@ fn quux(x: i32) {
expect![[r#"
lc y i32
lc x i32
fn quux() fn quux(x: i32)
fn quux() -> ()
"#]],
);
}
@ -189,7 +189,7 @@ fn quux() {
expect![[r#"
lc b i32
lc a
fn quux() fn quux()
fn quux() -> ()
"#]],
);
}
@ -204,7 +204,7 @@ fn quux() {
"#,
expect![[r#"
lc x
fn quux() fn quux()
fn quux() -> ()
"#]],
);
}
@ -235,14 +235,14 @@ fn main() {
r#"fn quux<T>() { $0 }"#,
expect![[r#"
tp T
fn quux() fn quux<T>()
fn quux() -> ()
"#]],
);
check(
r#"fn quux<const C: usize>() { $0 }"#,
expect![[r#"
cp C
fn quux() fn quux<const C: usize>()
fn quux() -> ()
"#]],
);
}
@ -253,7 +253,7 @@ fn main() {
check(
r#"fn quux<'a>() { $0 }"#,
expect![[r#"
fn quux() fn quux<'a>()
fn quux() -> ()
"#]],
);
}
@ -291,7 +291,7 @@ fn quux() { $0 }
"#,
expect![[r#"
st S
fn quux() fn quux()
fn quux() -> ()
en E
"#]],
);
@ -344,7 +344,7 @@ mod m {
}
"#,
expect![[r#"
fn quux() fn quux()
fn quux() -> ()
st Bar
"#]],
);
@ -359,7 +359,7 @@ fn x() -> $0
"#,
expect![[r#"
st Foo
fn x() fn x()
fn x() -> ()
"#]],
);
}
@ -380,7 +380,7 @@ fn foo() {
expect![[r#"
lc bar i32
lc bar i32
fn foo() fn foo()
fn foo() -> ()
"#]],
);
}
@ -410,7 +410,7 @@ use prelude::*;
mod prelude { struct Option; }
"#,
expect![[r#"
fn foo() fn foo()
fn foo() -> ()
md std
st Option
"#]],
@ -440,7 +440,7 @@ mod macros {
}
"#,
expect![[r##"
fn f() fn f()
fn f() -> ()
ma concat!() #[macro_export] macro_rules! concat
md std
"##]],
@ -467,7 +467,7 @@ use prelude::*;
mod prelude { struct String; }
"#,
expect![[r#"
fn foo() fn foo()
fn foo() -> ()
md std
md core
st String
@ -498,7 +498,7 @@ fn main() { let v = $0 }
expect![[r##"
md m1
ma baz!() #[macro_export] macro_rules! baz
fn main() fn main()
fn main() -> ()
md m2
ma bar!() macro_rules! bar
ma foo!() macro_rules! foo
@ -514,7 +514,7 @@ macro_rules! foo { () => {} }
fn foo() { $0 }
"#,
expect![[r#"
fn foo() fn foo()
fn foo() -> ()
ma foo!() macro_rules! foo
"#]],
);
@ -528,7 +528,7 @@ macro_rules! foo { () => {} }
fn main() { let x: $0 }
"#,
expect![[r#"
fn main() fn main()
fn main() -> ()
ma foo!() macro_rules! foo
"#]],
);
@ -542,7 +542,7 @@ macro_rules! foo { () => {} }
fn main() { $0 }
"#,
expect![[r#"
fn main() fn main()
fn main() -> ()
ma foo!() macro_rules! foo
"#]],
);
@ -558,8 +558,8 @@ fn main() {
}
"#,
expect![[r#"
fn frobnicate() fn frobnicate()
fn main() fn main()
fn frobnicate() -> ()
fn main() -> ()
"#]],
);
}
@ -577,7 +577,7 @@ fn quux(x: i32) {
expect![[r#"
lc y i32
lc x i32
fn quux() fn quux(x: i32)
fn quux() -> ()
ma m!() macro_rules! m
"#]],
);
@ -596,7 +596,7 @@ fn quux(x: i32) {
expect![[r#"
lc y i32
lc x i32
fn quux() fn quux(x: i32)
fn quux() -> ()
ma m!() macro_rules! m
"#]],
);
@ -615,7 +615,7 @@ fn quux(x: i32) {
expect![[r#"
lc y i32
lc x i32
fn quux() fn quux(x: i32)
fn quux() -> ()
ma m!() macro_rules! m
"#]],
);
@ -630,7 +630,7 @@ use spam::Quux;
fn main() { $0 }
"#,
expect![[r#"
fn main() fn main()
fn main() -> ()
?? Quux
"#]],
);
@ -708,7 +708,7 @@ fn main() { let foo: Foo = Q$0 }
ev Foo::Baz ()
ev Foo::Quux ()
en Foo
fn main() fn main()
fn main() -> ()
"#]],
)
}
@ -723,7 +723,7 @@ fn f() -> m::E { V$0 }
expect![[r#"
ev m::E::V ()
md m
fn f() fn f() -> m::E
fn f() -> E
"#]],
)
}

View File

@ -398,14 +398,13 @@ impl Builder {
self.insert_text_format = InsertTextFormat::Snippet;
self.text_edit(edit)
}
#[allow(unused)]
pub(crate) fn detail(self, detail: impl Into<String>) -> Builder {
self.set_detail(Some(detail))
}
pub(crate) fn set_detail(mut self, detail: Option<impl Into<String>>) -> Builder {
self.detail = detail.map(Into::into);
if let Some(detail) = &self.detail {
if assert_never!(detail.contains('\n'), "multiline detail: {}", detail) {
if assert_never!(detail.contains('\n'), "multiline detail:\n{}", detail) {
self.detail = Some(detail.splitn(2, '\n').next().unwrap().to_string());
}
}

View File

@ -209,25 +209,24 @@ mod tests {
fn test_completion_detail_from_macro_generated_struct_fn_doc_attr() {
check_detail_and_documentation(
r#"
//- /lib.rs
macro_rules! bar {
() => {
struct Bar;
impl Bar {
#[doc = "Do the foo"]
fn foo(&self) {}
}
}
}
macro_rules! bar {
() => {
struct Bar;
impl Bar {
#[doc = "Do the foo"]
fn foo(&self) {}
}
}
}
bar!();
bar!();
fn foo() {
let bar = Bar;
bar.fo$0;
}
"#,
DetailAndDocumentation { detail: "fn foo(&self)", documentation: "Do the foo" },
fn foo() {
let bar = Bar;
bar.fo$0;
}
"#,
DetailAndDocumentation { detail: "-> ()", documentation: "Do the foo" },
);
}
@ -235,52 +234,42 @@ mod tests {
fn test_completion_detail_from_macro_generated_struct_fn_doc_comment() {
check_detail_and_documentation(
r#"
//- /lib.rs
macro_rules! bar {
() => {
struct Bar;
impl Bar {
/// Do the foo
fn foo(&self) {}
}
}
}
macro_rules! bar {
() => {
struct Bar;
impl Bar {
/// Do the foo
fn foo(&self) {}
}
}
}
bar!();
bar!();
fn foo() {
let bar = Bar;
bar.fo$0;
}
"#,
DetailAndDocumentation { detail: "fn foo(&self)", documentation: " Do the foo" },
fn foo() {
let bar = Bar;
bar.fo$0;
}
"#,
DetailAndDocumentation { detail: "-> ()", documentation: " Do the foo" },
);
}
#[test]
fn test_no_completions_required() {
// There must be no hint for 'in' keyword.
check_no_completion(
r#"
fn foo() {
for i i$0
}
"#,
);
check_no_completion(r#"fn foo() { for i i$0 }"#);
// After 'in' keyword hints may be spawned.
check_detail_and_documentation(
r#"
/// Do the foo
fn foo() -> &'static str { "foo" }
/// Do the foo
fn foo() -> &'static str { "foo" }
fn bar() {
for c in fo$0
}
"#,
DetailAndDocumentation {
detail: "fn foo() -> &'static str",
documentation: "Do the foo",
},
fn bar() {
for c in fo$0
}
"#,
DetailAndDocumentation { detail: "-> &str", documentation: "Do the foo" },
);
}
}

View File

@ -523,7 +523,7 @@ fn main() { let _: m::Spam = S$0 }
Function,
),
lookup: "main",
detail: "fn main()",
detail: "-> ()",
},
]
"#]],
@ -552,7 +552,7 @@ fn main() { som$0 }
Function,
),
lookup: "main",
detail: "fn main()",
detail: "-> ()",
},
CompletionItem {
label: "something_deprecated()",
@ -563,7 +563,7 @@ fn main() { som$0 }
Function,
),
lookup: "something_deprecated",
detail: "fn something_deprecated()",
detail: "-> ()",
deprecated: true,
},
CompletionItem {
@ -575,7 +575,7 @@ fn main() { som$0 }
Function,
),
lookup: "something_else_deprecated",
detail: "fn something_else_deprecated()",
detail: "-> ()",
deprecated: true,
},
]
@ -626,7 +626,7 @@ impl S {
insert: "bar()$0",
kind: Method,
lookup: "bar",
detail: "fn bar(self)",
detail: "-> ()",
documentation: Documentation(
"Method docs",
),
@ -726,7 +726,7 @@ fn foo(s: S) { s.$0 }
insert: "the_method()$0",
kind: Method,
lookup: "the_method",
detail: "fn the_method(&self)",
detail: "-> ()",
},
]
"#]],

View File

@ -1,8 +1,8 @@
//! Renderer for function calls.
use hir::{HasSource, Type};
use hir::{HasSource, HirDisplay, Type};
use ide_db::SymbolKind;
use syntax::{ast::Fn, display::function_declaration};
use syntax::ast::Fn;
use test_utils::mark;
use crate::{
@ -55,7 +55,8 @@ impl<'a> FunctionRender<'a> {
}
fn detail(&self) -> String {
function_declaration(&self.ast_node)
let ty = self.func.ret_type(self.ctx.db());
format!("-> {}", ty.display(self.ctx.db()))
}
fn add_arg(&self, arg: &str, ty: &Type) -> String {

View File

@ -76,7 +76,12 @@ fn setup_logging(log_file: Option<PathBuf>) -> Result<()> {
profile::init();
if !cfg!(debug_assertions) {
stdx::set_assert_hook(|loc, args| log::error!("assertion failed at {}: {}", loc, args));
stdx::set_assert_hook(|loc, args| {
if env::var("RA_PROFILE").is_ok() {
panic!("assertion failed at {}: {}", loc, args)
}
log::error!("assertion failed at {}: {}", loc, args)
});
}
Ok(())