2020-02-15 10:27:04 -06:00
|
|
|
//! Completion for associated items in a trait implementation.
|
|
|
|
//!
|
|
|
|
//! This module adds the completion items related to implementing associated
|
|
|
|
//! items within a `impl Trait for Struct` block. The current context node
|
2020-07-30 11:02:20 -05:00
|
|
|
//! must be within either a `FN`, `TYPE_ALIAS`, or `CONST` node
|
2020-07-30 11:28:28 -05:00
|
|
|
//! and an direct child of an `IMPL`.
|
2020-02-15 10:27:04 -06:00
|
|
|
//!
|
|
|
|
//! # Examples
|
|
|
|
//!
|
|
|
|
//! Considering the following trait `impl`:
|
|
|
|
//!
|
|
|
|
//! ```ignore
|
|
|
|
//! trait SomeTrait {
|
|
|
|
//! fn foo();
|
|
|
|
//! }
|
|
|
|
//!
|
|
|
|
//! impl SomeTrait for () {
|
|
|
|
//! fn f<|>
|
|
|
|
//! }
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! may result in the completion of the following method:
|
|
|
|
//!
|
|
|
|
//! ```ignore
|
|
|
|
//! # trait SomeTrait {
|
|
|
|
//! # fn foo();
|
|
|
|
//! # }
|
|
|
|
//!
|
|
|
|
//! impl SomeTrait for () {
|
|
|
|
//! fn foo() {}<|>
|
|
|
|
//! }
|
|
|
|
//! ```
|
2020-02-11 10:04:30 -06:00
|
|
|
|
2020-08-13 10:33:38 -05:00
|
|
|
use assists::utils::get_missing_assoc_items;
|
2020-08-25 05:13:31 -05:00
|
|
|
use hir::{self, HasAttrs, HasSource};
|
2020-08-12 11:26:51 -05:00
|
|
|
use syntax::{
|
2020-07-30 11:28:28 -05:00
|
|
|
ast::{self, edit, Impl},
|
2020-04-10 10:06:57 -05:00
|
|
|
AstNode, SyntaxKind, SyntaxNode, TextRange, T,
|
2020-02-11 09:40:08 -06:00
|
|
|
};
|
2020-08-12 10:03:06 -05:00
|
|
|
use text_edit::TextEdit;
|
2020-01-22 22:25:41 -06:00
|
|
|
|
2020-02-14 18:54:00 -06:00
|
|
|
use crate::{
|
|
|
|
completion::{
|
|
|
|
CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
|
|
|
|
},
|
2020-07-16 14:33:11 -05:00
|
|
|
display::function_declaration,
|
2020-02-14 18:54:00 -06:00
|
|
|
};
|
|
|
|
|
2020-01-22 22:38:03 -06:00
|
|
|
pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext) {
|
2020-03-08 19:50:41 -05:00
|
|
|
if let Some((trigger, impl_def)) = completion_match(ctx) {
|
2020-02-12 20:21:43 -06:00
|
|
|
match trigger.kind() {
|
2020-05-26 13:12:13 -05:00
|
|
|
SyntaxKind::NAME_REF => get_missing_assoc_items(&ctx.sema, &impl_def)
|
|
|
|
.into_iter()
|
|
|
|
.for_each(|item| match item {
|
2020-03-06 19:35:39 -06:00
|
|
|
hir::AssocItem::Function(fn_item) => {
|
2020-05-26 13:12:13 -05:00
|
|
|
add_function_impl(&trigger, acc, ctx, fn_item)
|
2020-03-06 19:35:39 -06:00
|
|
|
}
|
|
|
|
hir::AssocItem::TypeAlias(type_item) => {
|
2020-05-26 13:12:13 -05:00
|
|
|
add_type_alias_impl(&trigger, acc, ctx, type_item)
|
2020-03-06 19:35:39 -06:00
|
|
|
}
|
|
|
|
hir::AssocItem::Const(const_item) => {
|
2020-05-26 13:12:13 -05:00
|
|
|
add_const_impl(&trigger, acc, ctx, const_item)
|
2020-03-06 19:35:39 -06:00
|
|
|
}
|
2020-05-26 13:12:13 -05:00
|
|
|
}),
|
2020-03-06 19:35:39 -06:00
|
|
|
|
2020-07-30 07:51:08 -05:00
|
|
|
SyntaxKind::FN => {
|
2020-05-26 13:12:13 -05:00
|
|
|
for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def)
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|item| match item {
|
|
|
|
hir::AssocItem::Function(fn_item) => Some(fn_item),
|
|
|
|
_ => None,
|
2020-05-05 10:56:10 -05:00
|
|
|
})
|
|
|
|
{
|
2020-05-26 13:12:13 -05:00
|
|
|
add_function_impl(&trigger, acc, ctx, missing_fn);
|
2020-02-12 20:21:43 -06:00
|
|
|
}
|
2020-02-12 20:46:12 -06:00
|
|
|
}
|
2020-01-28 20:30:53 -06:00
|
|
|
|
2020-07-30 08:25:46 -05:00
|
|
|
SyntaxKind::TYPE_ALIAS => {
|
2020-05-26 13:12:13 -05:00
|
|
|
for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def)
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|item| match item {
|
|
|
|
hir::AssocItem::TypeAlias(type_item) => Some(type_item),
|
|
|
|
_ => None,
|
2020-05-05 10:56:10 -05:00
|
|
|
})
|
|
|
|
{
|
2020-05-26 13:12:13 -05:00
|
|
|
add_type_alias_impl(&trigger, acc, ctx, missing_fn);
|
2020-02-12 20:21:43 -06:00
|
|
|
}
|
2020-02-12 20:46:12 -06:00
|
|
|
}
|
2020-02-12 20:21:43 -06:00
|
|
|
|
2020-07-30 11:02:20 -05:00
|
|
|
SyntaxKind::CONST => {
|
2020-05-26 13:12:13 -05:00
|
|
|
for missing_fn in get_missing_assoc_items(&ctx.sema, &impl_def)
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|item| match item {
|
|
|
|
hir::AssocItem::Const(const_item) => Some(const_item),
|
|
|
|
_ => None,
|
2020-05-05 10:56:10 -05:00
|
|
|
})
|
|
|
|
{
|
2020-05-26 13:12:13 -05:00
|
|
|
add_const_impl(&trigger, acc, ctx, missing_fn);
|
2020-02-12 20:21:43 -06:00
|
|
|
}
|
2020-02-12 20:46:12 -06:00
|
|
|
}
|
2020-02-12 20:21:43 -06:00
|
|
|
|
|
|
|
_ => {}
|
2020-01-22 22:25:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-30 11:28:28 -05:00
|
|
|
fn completion_match(ctx: &CompletionContext) -> Option<(SyntaxNode, Impl)> {
|
2020-03-09 15:01:40 -05:00
|
|
|
let (trigger, impl_def_offset) = ctx.token.ancestors().find_map(|p| match p.kind() {
|
2020-07-30 11:10:07 -05:00
|
|
|
SyntaxKind::FN | SyntaxKind::TYPE_ALIAS | SyntaxKind::CONST | SyntaxKind::BLOCK_EXPR => {
|
|
|
|
Some((p, 2))
|
|
|
|
}
|
2020-03-09 15:01:40 -05:00
|
|
|
SyntaxKind::NAME_REF => Some((p, 5)),
|
|
|
|
_ => None,
|
|
|
|
})?;
|
|
|
|
let impl_def = (0..impl_def_offset - 1)
|
|
|
|
.try_fold(trigger.parent()?, |t, _| t.parent())
|
2020-07-30 11:28:28 -05:00
|
|
|
.and_then(ast::Impl::cast)?;
|
2020-03-08 19:50:41 -05:00
|
|
|
Some((trigger, impl_def))
|
|
|
|
}
|
|
|
|
|
2020-02-12 21:00:47 -06:00
|
|
|
fn add_function_impl(
|
|
|
|
fn_def_node: &SyntaxNode,
|
|
|
|
acc: &mut Completions,
|
|
|
|
ctx: &CompletionContext,
|
2020-05-26 13:12:13 -05:00
|
|
|
func: hir::Function,
|
2020-02-12 21:00:47 -06:00
|
|
|
) {
|
2020-02-13 19:10:08 -06:00
|
|
|
let fn_name = func.name(ctx.db).to_string();
|
2020-02-04 22:04:57 -06:00
|
|
|
|
2020-08-19 06:33:51 -05:00
|
|
|
let label = if func.params(ctx.db).is_empty() {
|
2020-02-13 19:10:08 -06:00
|
|
|
format!("fn {}()", fn_name)
|
2020-08-19 06:33:51 -05:00
|
|
|
} else {
|
|
|
|
format!("fn {}(..)", fn_name)
|
2020-02-04 22:04:57 -06:00
|
|
|
};
|
|
|
|
|
2020-02-18 07:32:19 -06:00
|
|
|
let builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
|
2020-02-13 19:10:08 -06:00
|
|
|
.lookup_by(fn_name)
|
2020-02-08 15:41:25 -06:00
|
|
|
.set_documentation(func.docs(ctx.db));
|
2020-02-04 22:04:57 -06:00
|
|
|
|
2020-08-19 08:16:24 -05:00
|
|
|
let completion_kind = if func.self_param(ctx.db).is_some() {
|
2020-02-04 22:04:57 -06:00
|
|
|
CompletionItemKind::Method
|
|
|
|
} else {
|
|
|
|
CompletionItemKind::Function
|
|
|
|
};
|
2020-04-24 16:40:41 -05:00
|
|
|
let range = TextRange::new(fn_def_node.text_range().start(), ctx.source_range().end());
|
2020-02-15 09:50:07 -06:00
|
|
|
|
2020-07-16 14:33:11 -05:00
|
|
|
let function_decl = function_declaration(&func.source(ctx.db).value);
|
2020-04-23 19:26:38 -05:00
|
|
|
match ctx.config.snippet_cap {
|
|
|
|
Some(cap) => {
|
2020-07-16 14:32:20 -05:00
|
|
|
let snippet = format!("{} {{\n $0\n}}", function_decl);
|
2020-04-23 19:26:38 -05:00
|
|
|
builder.snippet_edit(cap, TextEdit::replace(range, snippet))
|
|
|
|
}
|
|
|
|
None => {
|
2020-07-16 14:32:20 -05:00
|
|
|
let header = format!("{} {{", function_decl);
|
2020-04-23 19:26:38 -05:00
|
|
|
builder.text_edit(TextEdit::replace(range, header))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.kind(completion_kind)
|
|
|
|
.add_to(acc);
|
2020-02-04 22:04:57 -06:00
|
|
|
}
|
|
|
|
|
2020-02-09 12:24:34 -06:00
|
|
|
fn add_type_alias_impl(
|
2020-02-12 21:00:47 -06:00
|
|
|
type_def_node: &SyntaxNode,
|
2020-02-09 12:24:34 -06:00
|
|
|
acc: &mut Completions,
|
|
|
|
ctx: &CompletionContext,
|
2020-05-26 13:12:13 -05:00
|
|
|
type_alias: hir::TypeAlias,
|
2020-02-09 12:24:34 -06:00
|
|
|
) {
|
2020-02-13 19:10:08 -06:00
|
|
|
let alias_name = type_alias.name(ctx.db).to_string();
|
|
|
|
|
|
|
|
let snippet = format!("type {} = ", alias_name);
|
2020-02-08 15:41:25 -06:00
|
|
|
|
2020-04-24 16:40:41 -05:00
|
|
|
let range = TextRange::new(type_def_node.text_range().start(), ctx.source_range().end());
|
2020-02-15 09:50:07 -06:00
|
|
|
|
2020-02-08 15:41:25 -06:00
|
|
|
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
|
2020-02-15 09:50:07 -06:00
|
|
|
.text_edit(TextEdit::replace(range, snippet))
|
2020-02-13 19:10:08 -06:00
|
|
|
.lookup_by(alias_name)
|
2020-02-08 15:41:25 -06:00
|
|
|
.kind(CompletionItemKind::TypeAlias)
|
|
|
|
.set_documentation(type_alias.docs(ctx.db))
|
|
|
|
.add_to(acc);
|
|
|
|
}
|
|
|
|
|
2020-02-12 21:00:47 -06:00
|
|
|
fn add_const_impl(
|
|
|
|
const_def_node: &SyntaxNode,
|
|
|
|
acc: &mut Completions,
|
|
|
|
ctx: &CompletionContext,
|
2020-05-26 13:12:13 -05:00
|
|
|
const_: hir::Const,
|
2020-02-12 21:00:47 -06:00
|
|
|
) {
|
2020-02-13 19:10:08 -06:00
|
|
|
let const_name = const_.name(ctx.db).map(|n| n.to_string());
|
2020-02-09 20:59:12 -06:00
|
|
|
|
2020-02-13 19:10:08 -06:00
|
|
|
if let Some(const_name) = const_name {
|
|
|
|
let snippet = make_const_compl_syntax(&const_.source(ctx.db).value);
|
|
|
|
|
2020-04-24 16:51:02 -05:00
|
|
|
let range = TextRange::new(const_def_node.text_range().start(), ctx.source_range().end());
|
2020-02-15 09:50:07 -06:00
|
|
|
|
2020-02-13 19:10:08 -06:00
|
|
|
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
|
2020-02-15 09:50:07 -06:00
|
|
|
.text_edit(TextEdit::replace(range, snippet))
|
2020-02-13 19:10:08 -06:00
|
|
|
.lookup_by(const_name)
|
|
|
|
.kind(CompletionItemKind::Const)
|
|
|
|
.set_documentation(const_.docs(ctx.db))
|
|
|
|
.add_to(acc);
|
|
|
|
}
|
2020-02-09 20:59:12 -06:00
|
|
|
}
|
|
|
|
|
2020-07-30 11:02:20 -05:00
|
|
|
fn make_const_compl_syntax(const_: &ast::Const) -> String {
|
2020-03-24 06:56:07 -05:00
|
|
|
let const_ = edit::remove_attrs_and_docs(const_);
|
2020-02-10 20:55:49 -06:00
|
|
|
|
2020-02-09 20:59:12 -06:00
|
|
|
let const_start = const_.syntax().text_range().start();
|
|
|
|
let const_end = const_.syntax().text_range().end();
|
|
|
|
|
2020-02-11 09:40:08 -06:00
|
|
|
let start =
|
|
|
|
const_.syntax().first_child_or_token().map_or(const_start, |f| f.text_range().start());
|
2020-02-09 20:59:12 -06:00
|
|
|
|
|
|
|
let end = const_
|
|
|
|
.syntax()
|
|
|
|
.children_with_tokens()
|
2020-04-10 10:06:57 -05:00
|
|
|
.find(|s| s.kind() == T![;] || s.kind() == T![=])
|
2020-02-09 20:59:12 -06:00
|
|
|
.map_or(const_end, |f| f.text_range().start());
|
|
|
|
|
|
|
|
let len = end - start;
|
2020-04-24 16:40:41 -05:00
|
|
|
let range = TextRange::new(0.into(), len);
|
2020-02-09 20:59:12 -06:00
|
|
|
|
|
|
|
let syntax = const_.syntax().text().slice(range).to_string();
|
|
|
|
|
|
|
|
format!("{} = ", syntax.trim_end())
|
|
|
|
}
|
|
|
|
|
2020-01-22 22:25:41 -06:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-08-21 06:19:31 -05:00
|
|
|
use expect_test::{expect, Expect};
|
2020-01-22 22:25:41 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
use crate::completion::{
|
|
|
|
test_utils::{check_edit, completion_list},
|
|
|
|
CompletionKind,
|
|
|
|
};
|
2020-04-17 04:55:06 -05:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
fn check(ra_fixture: &str, expect: Expect) {
|
|
|
|
let actual = completion_list(ra_fixture, CompletionKind::Magic);
|
|
|
|
expect.assert_eq(&actual)
|
2020-01-22 22:25:41 -06:00
|
|
|
}
|
|
|
|
|
2020-03-06 19:35:39 -06:00
|
|
|
#[test]
|
|
|
|
fn name_ref_function_type_const() {
|
2020-07-04 16:22:07 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
type TestType;
|
|
|
|
const TEST_CONST: u16;
|
|
|
|
fn test();
|
|
|
|
}
|
|
|
|
struct T;
|
2020-03-06 19:35:39 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for T {
|
|
|
|
t<|>
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![["
|
|
|
|
ct const TEST_CONST: u16 = \n\
|
|
|
|
fn fn test()
|
|
|
|
ta type TestType = \n\
|
|
|
|
"]],
|
2020-03-06 19:35:39 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-08 19:50:41 -05:00
|
|
|
#[test]
|
|
|
|
fn no_nested_fn_completions() {
|
2020-07-04 16:22:07 -05:00
|
|
|
check(
|
2020-03-08 19:50:41 -05:00
|
|
|
r"
|
2020-07-04 16:22:07 -05:00
|
|
|
trait Test {
|
|
|
|
fn test();
|
|
|
|
fn test2();
|
|
|
|
}
|
|
|
|
struct T;
|
2020-03-08 19:50:41 -05:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for T {
|
|
|
|
fn test() {
|
|
|
|
t<|>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
",
|
|
|
|
expect![[""]],
|
2020-03-08 19:50:41 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-06 19:35:39 -06:00
|
|
|
#[test]
|
|
|
|
fn name_ref_single_function() {
|
2020-07-04 16:22:07 -05:00
|
|
|
check_edit(
|
|
|
|
"test",
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
fn test();
|
|
|
|
}
|
|
|
|
struct T;
|
2020-03-06 19:35:39 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for T {
|
|
|
|
t<|>
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
fn test();
|
|
|
|
}
|
|
|
|
struct T;
|
2020-03-06 19:35:39 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for T {
|
|
|
|
fn test() {
|
|
|
|
$0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
2020-03-06 19:35:39 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-22 22:25:41 -06:00
|
|
|
#[test]
|
|
|
|
fn single_function() {
|
2020-07-04 16:22:07 -05:00
|
|
|
check_edit(
|
|
|
|
"test",
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
fn test();
|
|
|
|
}
|
|
|
|
struct T;
|
2020-01-22 22:25:41 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for T {
|
|
|
|
fn t<|>
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
fn test();
|
|
|
|
}
|
|
|
|
struct T;
|
2020-01-22 22:25:41 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for T {
|
|
|
|
fn test() {
|
|
|
|
$0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
2020-01-22 22:25:41 -06:00
|
|
|
);
|
|
|
|
}
|
2020-01-28 20:30:53 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_implemented_fn() {
|
2020-07-04 16:22:07 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
fn foo();
|
|
|
|
fn foo_bar();
|
|
|
|
}
|
|
|
|
struct T;
|
2020-02-15 09:50:07 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for T {
|
|
|
|
fn foo() {}
|
|
|
|
fn f<|>
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
fn fn foo_bar()
|
|
|
|
"#]],
|
2020-02-15 09:50:07 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-04 22:04:57 -06:00
|
|
|
#[test]
|
|
|
|
fn generic_fn() {
|
2020-07-04 16:22:07 -05:00
|
|
|
check_edit(
|
|
|
|
"foo",
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
fn foo<T>();
|
|
|
|
}
|
|
|
|
struct T;
|
2020-02-04 22:04:57 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for T {
|
|
|
|
fn f<|>
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
fn foo<T>();
|
|
|
|
}
|
|
|
|
struct T;
|
2020-02-04 22:04:57 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for T {
|
|
|
|
fn foo<T>() {
|
|
|
|
$0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
2020-02-04 22:04:57 -06:00
|
|
|
);
|
2020-07-04 16:22:07 -05:00
|
|
|
check_edit(
|
|
|
|
"foo",
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
fn foo<T>() where T: Into<String>;
|
|
|
|
}
|
|
|
|
struct T;
|
2020-02-04 22:04:57 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for T {
|
|
|
|
fn f<|>
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
fn foo<T>() where T: Into<String>;
|
|
|
|
}
|
|
|
|
struct T;
|
2020-02-04 22:04:57 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for T {
|
|
|
|
fn foo<T>()
|
|
|
|
where T: Into<String> {
|
|
|
|
$0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
2020-02-04 22:04:57 -06:00
|
|
|
);
|
|
|
|
}
|
2020-02-10 21:02:51 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn associated_type() {
|
2020-07-04 16:22:07 -05:00
|
|
|
check_edit(
|
|
|
|
"SomeType",
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
type SomeType;
|
|
|
|
}
|
2020-02-10 21:02:51 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for () {
|
|
|
|
type S<|>
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
"
|
|
|
|
trait Test {
|
|
|
|
type SomeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Test for () {
|
|
|
|
type SomeType = \n\
|
|
|
|
}
|
|
|
|
",
|
2020-02-10 21:02:51 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn associated_const() {
|
2020-07-04 16:22:07 -05:00
|
|
|
check_edit(
|
|
|
|
"SOME_CONST",
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
const SOME_CONST: u16;
|
|
|
|
}
|
2020-02-10 21:02:51 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for () {
|
|
|
|
const S<|>
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
"
|
|
|
|
trait Test {
|
|
|
|
const SOME_CONST: u16;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Test for () {
|
|
|
|
const SOME_CONST: u16 = \n\
|
|
|
|
}
|
|
|
|
",
|
2020-02-10 21:02:51 -06:00
|
|
|
);
|
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
check_edit(
|
|
|
|
"SOME_CONST",
|
|
|
|
r#"
|
|
|
|
trait Test {
|
|
|
|
const SOME_CONST: u16 = 92;
|
|
|
|
}
|
2020-02-10 21:02:51 -06:00
|
|
|
|
2020-07-04 16:22:07 -05:00
|
|
|
impl Test for () {
|
|
|
|
const S<|>
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
"
|
|
|
|
trait Test {
|
|
|
|
const SOME_CONST: u16 = 92;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Test for () {
|
|
|
|
const SOME_CONST: u16 = \n\
|
|
|
|
}
|
|
|
|
",
|
2020-02-10 21:02:51 -06:00
|
|
|
);
|
|
|
|
}
|
2020-02-09 12:24:34 -06:00
|
|
|
}
|