mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-16 01:38:13 +00:00
the "add missing members" assists: supported bracketed default const values
This commit is contained in:
parent
4e2be8e959
commit
61cabe029f
3 changed files with 43 additions and 6 deletions
|
@ -52,6 +52,7 @@ use hir_expand::name;
|
||||||
use la_arena::{Arena, Idx};
|
use la_arena::{Arena, Idx};
|
||||||
use mir::{MirEvalError, VTableMap};
|
use mir::{MirEvalError, VTableMap};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
use syntax::AstNode;
|
||||||
use traits::FnTrait;
|
use traits::FnTrait;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
use utils::Generics;
|
use utils::Generics;
|
||||||
|
@ -723,12 +724,12 @@ where
|
||||||
|
|
||||||
pub fn known_const_to_string(konst: &Const, db: &dyn HirDatabase) -> Option<String> {
|
pub fn known_const_to_string(konst: &Const, db: &dyn HirDatabase) -> Option<String> {
|
||||||
if let ConstValue::Concrete(c) = &konst.interned().value {
|
if let ConstValue::Concrete(c) = &konst.interned().value {
|
||||||
if let ConstScalar::UnevaluatedConst(GeneralConstId::InTypeConstId(_), _) = &c.interned {
|
match c.interned {
|
||||||
// FIXME: stringify the block expression
|
ConstScalar::UnevaluatedConst(GeneralConstId::InTypeConstId(cid), _) => {
|
||||||
return None;
|
return Some(cid.source(db.upcast()).syntax().to_string());
|
||||||
}
|
}
|
||||||
if c.interned == ConstScalar::Unknown {
|
ConstScalar::Unknown => return None,
|
||||||
return None;
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(konst.display(db).to_string())
|
Some(konst.display(db).to_string())
|
||||||
|
|
|
@ -549,6 +549,41 @@ impl m::Foo for () {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_const_substitution_with_defaults_3() {
|
||||||
|
check_assist(
|
||||||
|
add_missing_default_members,
|
||||||
|
r#"
|
||||||
|
mod m {
|
||||||
|
pub const VAL: usize = 0;
|
||||||
|
|
||||||
|
pub trait Foo<const N: usize = {40 + 2}, const M: usize = {VAL + 1}> {
|
||||||
|
fn get_n(&self) -> usize { N }
|
||||||
|
fn get_m(&self) -> usize { M }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl m::Foo for () {
|
||||||
|
$0
|
||||||
|
}"#,
|
||||||
|
r#"
|
||||||
|
mod m {
|
||||||
|
pub const VAL: usize = 0;
|
||||||
|
|
||||||
|
pub trait Foo<const N: usize = {40 + 2}, const M: usize = {VAL + 1}> {
|
||||||
|
fn get_n(&self) -> usize { N }
|
||||||
|
fn get_m(&self) -> usize { M }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl m::Foo for () {
|
||||||
|
$0fn get_n(&self) -> usize { {40 + 2} }
|
||||||
|
|
||||||
|
fn get_m(&self) -> usize { {m::VAL + 1} }
|
||||||
|
}"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cursor_after_empty_impl_def() {
|
fn test_cursor_after_empty_impl_def() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
|
|
@ -156,6 +156,7 @@ impl<'a> PathTransform<'a> {
|
||||||
// is a standalone statement or a part of another expresson)
|
// is a standalone statement or a part of another expresson)
|
||||||
// and sometimes require slight modifications; see
|
// and sometimes require slight modifications; see
|
||||||
// https://doc.rust-lang.org/reference/statements.html#expression-statements
|
// https://doc.rust-lang.org/reference/statements.html#expression-statements
|
||||||
|
// (default values in curly brackets can cause the same problem)
|
||||||
const_substs.insert(k, expr.syntax().clone());
|
const_substs.insert(k, expr.syntax().clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue