mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
⬆️ rust-analyzer
This commit is contained in:
parent
544b4cfe4d
commit
dbf04a5ee2
106 changed files with 2219 additions and 609 deletions
|
@ -5,7 +5,7 @@
|
|||
//! But we need this for at least LRU caching at the query level.
|
||||
pub use hir_def::db::*;
|
||||
pub use hir_expand::db::{
|
||||
AstDatabase, AstDatabaseStorage, AstIdMapQuery, ExpandProcMacroQuery, HygieneFrameQuery,
|
||||
AstIdMapQuery, ExpandDatabase, ExpandDatabaseStorage, ExpandProcMacroQuery, HygieneFrameQuery,
|
||||
InternMacroCallQuery, MacroArgTextQuery, MacroDefQuery, MacroExpandErrorQuery,
|
||||
MacroExpandQuery, ParseMacroExpansionQuery,
|
||||
};
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
//!
|
||||
//! This probably isn't the best way to do this -- ideally, diagnostics should
|
||||
//! be expressed in terms of hir types themselves.
|
||||
pub use hir_ty::diagnostics::{IncoherentImpl, IncorrectCase};
|
||||
|
||||
use base_db::CrateId;
|
||||
use cfg::{CfgExpr, CfgOptions};
|
||||
use either::Either;
|
||||
|
@ -35,6 +37,7 @@ diagnostics![
|
|||
InactiveCode,
|
||||
IncorrectCase,
|
||||
InvalidDeriveTarget,
|
||||
IncoherentImpl,
|
||||
MacroError,
|
||||
MalformedDerive,
|
||||
MismatchedArgCount,
|
||||
|
@ -220,5 +223,3 @@ pub struct NeedMut {
|
|||
pub struct UnusedMut {
|
||||
pub local: Local,
|
||||
}
|
||||
|
||||
pub use hir_ty::diagnostics::IncorrectCase;
|
||||
|
|
|
@ -85,10 +85,10 @@ use crate::db::{DefDatabase, HirDatabase};
|
|||
pub use crate::{
|
||||
attrs::{HasAttrs, Namespace},
|
||||
diagnostics::{
|
||||
AnyDiagnostic, BreakOutsideOfLoop, ExpectedFunction, InactiveCode, IncorrectCase,
|
||||
InvalidDeriveTarget, MacroError, MalformedDerive, MismatchedArgCount, MissingFields,
|
||||
MissingMatchArms, MissingUnsafe, NeedMut, NoSuchField, PrivateAssocItem, PrivateField,
|
||||
ReplaceFilterMapNextWithFindMap, TypeMismatch, UnimplementedBuiltinMacro,
|
||||
AnyDiagnostic, BreakOutsideOfLoop, ExpectedFunction, InactiveCode, IncoherentImpl,
|
||||
IncorrectCase, InvalidDeriveTarget, MacroError, MalformedDerive, MismatchedArgCount,
|
||||
MissingFields, MissingMatchArms, MissingUnsafe, NeedMut, NoSuchField, PrivateAssocItem,
|
||||
PrivateField, ReplaceFilterMapNextWithFindMap, TypeMismatch, UnimplementedBuiltinMacro,
|
||||
UnresolvedExternCrate, UnresolvedField, UnresolvedImport, UnresolvedMacroCall,
|
||||
UnresolvedMethodCall, UnresolvedModule, UnresolvedProcMacro, UnusedMut,
|
||||
},
|
||||
|
@ -604,11 +604,23 @@ impl Module {
|
|||
}
|
||||
}
|
||||
|
||||
let inherent_impls = db.inherent_impls_in_crate(self.id.krate());
|
||||
|
||||
for impl_def in self.impl_defs(db) {
|
||||
for diag in db.impl_data_with_diagnostics(impl_def.id).1.iter() {
|
||||
emit_def_diagnostic(db, acc, diag);
|
||||
}
|
||||
|
||||
if inherent_impls.invalid_impls().contains(&impl_def.id) {
|
||||
let loc = impl_def.id.lookup(db.upcast());
|
||||
let tree = loc.id.item_tree(db.upcast());
|
||||
let node = &tree[loc.id.value];
|
||||
let file_id = loc.id.file_id();
|
||||
let ast_id_map = db.ast_id_map(file_id);
|
||||
|
||||
acc.push(IncoherentImpl { 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(),
|
||||
|
@ -3210,6 +3222,14 @@ impl Type {
|
|||
matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Uint(UintTy::Usize)))
|
||||
}
|
||||
|
||||
pub fn is_float(&self) -> bool {
|
||||
matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Float(_)))
|
||||
}
|
||||
|
||||
pub fn is_char(&self) -> bool {
|
||||
matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Char))
|
||||
}
|
||||
|
||||
pub fn is_int_or_uint(&self) -> bool {
|
||||
match self.ty.kind(Interner) {
|
||||
TyKind::Scalar(Scalar::Int(_) | Scalar::Uint(_)) => true,
|
||||
|
@ -3224,6 +3244,13 @@ impl Type {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn as_slice(&self) -> Option<Type> {
|
||||
match &self.ty.kind(Interner) {
|
||||
TyKind::Slice(ty) => Some(self.derived(ty.clone())),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn strip_references(&self) -> Type {
|
||||
self.derived(self.ty.strip_references().clone())
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ use hir_def::{
|
|||
AsMacroCall, DefWithBodyId, FieldId, FunctionId, MacroId, TraitId, VariantId,
|
||||
};
|
||||
use hir_expand::{
|
||||
db::AstDatabase,
|
||||
db::ExpandDatabase,
|
||||
name::{known, AsName},
|
||||
ExpansionInfo, MacroCallId,
|
||||
};
|
||||
|
@ -411,7 +411,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
|||
self.imp.resolve_record_field(field)
|
||||
}
|
||||
|
||||
pub fn resolve_record_pat_field(&self, field: &ast::RecordPatField) -> Option<Field> {
|
||||
pub fn resolve_record_pat_field(&self, field: &ast::RecordPatField) -> Option<(Field, Type)> {
|
||||
self.imp.resolve_record_pat_field(field)
|
||||
}
|
||||
|
||||
|
@ -1201,7 +1201,7 @@ impl<'db> SemanticsImpl<'db> {
|
|||
self.analyze(field.syntax())?.resolve_record_field(self.db, field)
|
||||
}
|
||||
|
||||
fn resolve_record_pat_field(&self, field: &ast::RecordPatField) -> Option<Field> {
|
||||
fn resolve_record_pat_field(&self, field: &ast::RecordPatField) -> Option<(Field, Type)> {
|
||||
self.analyze(field.syntax())?.resolve_record_pat_field(self.db, field)
|
||||
}
|
||||
|
||||
|
@ -1536,7 +1536,7 @@ impl<'db> SemanticsImpl<'db> {
|
|||
|
||||
fn macro_call_to_macro_id(
|
||||
ctx: &mut SourceToDefCtx<'_, '_>,
|
||||
db: &dyn AstDatabase,
|
||||
db: &dyn ExpandDatabase,
|
||||
macro_call_id: MacroCallId,
|
||||
) -> Option<MacroId> {
|
||||
let loc = db.lookup_intern_macro_call(macro_call_id);
|
||||
|
|
|
@ -441,14 +441,17 @@ impl SourceAnalyzer {
|
|||
&self,
|
||||
db: &dyn HirDatabase,
|
||||
field: &ast::RecordPatField,
|
||||
) -> Option<Field> {
|
||||
) -> Option<(Field, Type)> {
|
||||
let field_name = field.field_name()?.as_name();
|
||||
let record_pat = ast::RecordPat::cast(field.syntax().parent().and_then(|p| p.parent())?)?;
|
||||
let pat_id = self.pat_id(&record_pat.into())?;
|
||||
let variant = self.infer.as_ref()?.variant_resolution_for_pat(pat_id)?;
|
||||
let variant_data = variant.variant_data(db.upcast());
|
||||
let field = FieldId { parent: variant, local_id: variant_data.field(&field_name)? };
|
||||
Some(field.into())
|
||||
let (_, subst) = self.infer.as_ref()?.type_of_pat.get(pat_id)?.as_adt()?;
|
||||
let field_ty =
|
||||
db.field_types(variant).get(field.local_id)?.clone().substitute(Interner, subst);
|
||||
Some((field.into(), Type::new_with_resolver(db, &self.resolver, field_ty)))
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_macro_call(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue