mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
fix: address suggestions
This commit is contained in:
parent
15f73008f8
commit
83177a7cfe
12 changed files with 72 additions and 65 deletions
|
@ -395,22 +395,14 @@ pub fn unknown_const_as_generic(ty: Ty) -> GenericArg {
|
|||
}
|
||||
|
||||
/// Interns a constant scalar with the given type
|
||||
pub fn intern_const_scalar_with_type(value: ConstScalar, ty: Ty) -> Const {
|
||||
pub fn intern_const_scalar(value: ConstScalar, ty: Ty) -> Const {
|
||||
ConstData { ty, value: ConstValue::Concrete(chalk_ir::ConcreteConst { interned: value }) }
|
||||
.intern(Interner)
|
||||
}
|
||||
|
||||
/// Interns a possibly-unknown target usize
|
||||
pub fn usize_const(value: Option<u128>) -> Const {
|
||||
intern_const_scalar_with_type(
|
||||
value.map(ConstScalar::UInt).unwrap_or(ConstScalar::Unknown),
|
||||
TyBuilder::usize(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Interns a constant scalar with the default type
|
||||
pub fn intern_const_scalar(value: ConstScalar) -> Const {
|
||||
intern_const_scalar_with_type(value, TyBuilder::builtin(value.builtin_type()))
|
||||
intern_const_scalar(value.map_or(ConstScalar::Unknown, ConstScalar::UInt), TyBuilder::usize())
|
||||
}
|
||||
|
||||
pub(crate) fn const_eval_recover(
|
||||
|
@ -470,7 +462,7 @@ pub(crate) fn eval_to_const<'a>(
|
|||
Ok(ComputedExpr::Literal(literal)) => literal.into(),
|
||||
_ => ConstScalar::Unknown,
|
||||
};
|
||||
intern_const_scalar_with_type(const_scalar, TyBuilder::usize())
|
||||
intern_const_scalar(const_scalar, TyBuilder::usize())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -273,6 +273,7 @@ impl<'a> InferenceContext<'a> {
|
|||
elem_ty.clone(),
|
||||
intern_const_scalar(
|
||||
len.map_or(ConstScalar::Unknown, |len| ConstScalar::UInt(len)),
|
||||
TyBuilder::usize(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
c1: &Self::InternedConcreteConst,
|
||||
c2: &Self::InternedConcreteConst,
|
||||
) -> bool {
|
||||
c1 == c2
|
||||
(c1 == &ConstScalar::Unknown) || (c2 == &ConstScalar::Unknown) || (c1 == c2)
|
||||
}
|
||||
|
||||
fn intern_generic_arg(
|
||||
|
|
|
@ -44,9 +44,7 @@ use syntax::{ast, SmolStr};
|
|||
|
||||
use crate::{
|
||||
all_super_traits,
|
||||
consteval::{
|
||||
intern_const_scalar_with_type, path_to_const, unknown_const, unknown_const_as_generic,
|
||||
},
|
||||
consteval::{intern_const_scalar, path_to_const, unknown_const, unknown_const_as_generic},
|
||||
db::HirDatabase,
|
||||
make_binders,
|
||||
mapping::ToChalk,
|
||||
|
@ -1744,7 +1742,7 @@ pub(crate) fn const_or_path_to_chalk(
|
|||
debruijn: DebruijnIndex,
|
||||
) -> Const {
|
||||
match value {
|
||||
ConstScalarOrPath::Scalar(s) => intern_const_scalar_with_type(s.clone(), expected_ty),
|
||||
ConstScalarOrPath::Scalar(s) => intern_const_scalar(s.clone(), expected_ty),
|
||||
ConstScalarOrPath::Path(n) => {
|
||||
let path = ModPath::from_segments(PathKind::Plain, Some(n.clone()));
|
||||
path_to_const(db, resolver, &path, mode, args, debruijn)
|
||||
|
|
|
@ -3011,14 +3011,14 @@ struct TS(usize);
|
|||
fn main() {
|
||||
let x;
|
||||
[x,] = &[1,];
|
||||
//^^^^expected &[i32; 1], got [{unknown}; {unknown}]
|
||||
//^^^^expected &[i32; 1], got [{unknown}; _]
|
||||
|
||||
// FIXME we only want the outermost error, but this matches the current
|
||||
// behavior of slice patterns
|
||||
let x;
|
||||
[(x,),] = &[(1,),];
|
||||
// ^^^^expected {unknown}, got ({unknown},)
|
||||
//^^^^^^^expected &[(i32,); 1], got [{unknown}; {unknown}]
|
||||
//^^^^^^^expected &[(i32,); 1], got [{unknown}; _]
|
||||
|
||||
let x;
|
||||
((x,),) = &((1,),);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue