mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-11-03 21:25:25 +00:00 
			
		
		
		
	Remove all upcasts!
It turns out there were a lot redundant too.
This commit is contained in:
		
							parent
							
								
									a775d21112
								
							
						
					
					
						commit
						8a9a1e3345
					
				
					 80 changed files with 1009 additions and 1257 deletions
				
			
		| 
						 | 
				
			
			@ -234,6 +234,8 @@ fn _format(
 | 
			
		|||
    file_id: FileId,
 | 
			
		||||
    expansion: &str,
 | 
			
		||||
) -> Option<String> {
 | 
			
		||||
    use ide_db::base_db::RootQueryDb;
 | 
			
		||||
 | 
			
		||||
    // hack until we get hygiene working (same character amount to preserve formatting as much as possible)
 | 
			
		||||
    const DOLLAR_CRATE_REPLACE: &str = "__r_a_";
 | 
			
		||||
    const BUILTIN_REPLACE: &str = "builtin__POUND";
 | 
			
		||||
| 
						 | 
				
			
			@ -247,9 +249,8 @@ fn _format(
 | 
			
		|||
    };
 | 
			
		||||
    let expansion = format!("{prefix}{expansion}{suffix}");
 | 
			
		||||
 | 
			
		||||
    let upcast_db = ide_db::base_db::Upcast::<dyn ide_db::base_db::RootQueryDb>::upcast(db);
 | 
			
		||||
    let &crate_id = upcast_db.relevant_crates(file_id).iter().next()?;
 | 
			
		||||
    let edition = crate_id.data(upcast_db).edition;
 | 
			
		||||
    let &crate_id = db.relevant_crates(file_id).iter().next()?;
 | 
			
		||||
    let edition = crate_id.data(db).edition;
 | 
			
		||||
 | 
			
		||||
    #[allow(clippy::disallowed_methods)]
 | 
			
		||||
    let mut cmd = std::process::Command::new(toolchain::Tool::Rustfmt.path());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,7 +11,7 @@ use hir::{
 | 
			
		|||
};
 | 
			
		||||
use ide_db::{
 | 
			
		||||
    RootDatabase, SymbolKind,
 | 
			
		||||
    base_db::{AnchoredPath, RootQueryDb, SourceDatabase, Upcast},
 | 
			
		||||
    base_db::{AnchoredPath, SourceDatabase},
 | 
			
		||||
    defs::{Definition, IdentClass},
 | 
			
		||||
    famous_defs::FamousDefs,
 | 
			
		||||
    helpers::pick_best_token,
 | 
			
		||||
| 
						 | 
				
			
			@ -222,8 +222,7 @@ fn try_lookup_include_path(
 | 
			
		|||
    }
 | 
			
		||||
    let path = token.value.value().ok()?;
 | 
			
		||||
 | 
			
		||||
    let file_id = Upcast::<dyn RootQueryDb>::upcast(sema.db)
 | 
			
		||||
        .resolve_path(AnchoredPath { anchor: file_id, path: &path })?;
 | 
			
		||||
    let file_id = sema.db.resolve_path(AnchoredPath { anchor: file_id, path: &path })?;
 | 
			
		||||
    let size = sema.db.file_text(file_id).text(sema.db).len().try_into().ok()?;
 | 
			
		||||
    Some(NavigationTarget {
 | 
			
		||||
        file_id,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
use hir::GenericParam;
 | 
			
		||||
use ide_db::{RootDatabase, base_db::Upcast, defs::Definition, helpers::pick_best_token};
 | 
			
		||||
use ide_db::{RootDatabase, defs::Definition, helpers::pick_best_token};
 | 
			
		||||
use syntax::{AstNode, SyntaxKind::*, SyntaxToken, T, ast, match_ast};
 | 
			
		||||
 | 
			
		||||
use crate::{FilePosition, NavigationTarget, RangeInfo, TryToNav};
 | 
			
		||||
| 
						 | 
				
			
			@ -87,7 +87,7 @@ pub(crate) fn goto_type_definition(
 | 
			
		|||
                            ast::Pat(it) => sema.type_of_pat(&it)?.original,
 | 
			
		||||
                            ast::SelfParam(it) => sema.type_of_self(&it)?,
 | 
			
		||||
                            ast::Type(it) => sema.resolve_type(&it)?,
 | 
			
		||||
                            ast::RecordField(it) => sema.to_def(&it)?.ty(db.upcast()),
 | 
			
		||||
                            ast::RecordField(it) => sema.to_def(&it)?.ty(db),
 | 
			
		||||
                            // can't match on RecordExprField directly as `ast::Expr` will match an iteration too early otherwise
 | 
			
		||||
                            ast::NameRef(it) => {
 | 
			
		||||
                                if let Some(record_field) = ast::RecordExprField::for_name_ref(&it) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -66,8 +66,7 @@ use hir::{ChangeWithProcMacros, sym};
 | 
			
		|||
use ide_db::{
 | 
			
		||||
    FxHashMap, FxIndexSet, LineIndexDatabase,
 | 
			
		||||
    base_db::{
 | 
			
		||||
        CrateOrigin, CrateWorkspaceData, Env, FileSet, RootQueryDb, SourceDatabase, Upcast,
 | 
			
		||||
        VfsPath,
 | 
			
		||||
        CrateOrigin, CrateWorkspaceData, Env, FileSet, RootQueryDb, SourceDatabase, VfsPath,
 | 
			
		||||
        salsa::{AsDynDatabase, Cancelled},
 | 
			
		||||
    },
 | 
			
		||||
    prime_caches, symbol_index,
 | 
			
		||||
| 
						 | 
				
			
			@ -623,10 +622,7 @@ impl Analysis {
 | 
			
		|||
 | 
			
		||||
    /// Returns crates that this file *might* belong to.
 | 
			
		||||
    pub fn relevant_crates_for(&self, file_id: FileId) -> Cancellable<Vec<Crate>> {
 | 
			
		||||
        self.with_db(|db| {
 | 
			
		||||
            let db = Upcast::<dyn RootQueryDb>::upcast(db);
 | 
			
		||||
            db.relevant_crates(file_id).iter().copied().collect()
 | 
			
		||||
        })
 | 
			
		||||
        self.with_db(|db| db.relevant_crates(file_id).iter().copied().collect())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Returns the edition of the given crate.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
use hir::{Semantics, db::DefDatabase};
 | 
			
		||||
use ide_db::{
 | 
			
		||||
    FileId, FilePosition, RootDatabase,
 | 
			
		||||
    base_db::{Crate, RootQueryDb, Upcast},
 | 
			
		||||
    base_db::{Crate, RootQueryDb},
 | 
			
		||||
};
 | 
			
		||||
use itertools::Itertools;
 | 
			
		||||
use syntax::{
 | 
			
		||||
| 
						 | 
				
			
			@ -54,9 +54,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
 | 
			
		|||
 | 
			
		||||
/// This returns `Vec` because a module may be included from several places.
 | 
			
		||||
pub(crate) fn crates_for(db: &RootDatabase, file_id: FileId) -> Vec<Crate> {
 | 
			
		||||
    let root_db = Upcast::<dyn RootQueryDb>::upcast(db);
 | 
			
		||||
    root_db
 | 
			
		||||
        .relevant_crates(file_id)
 | 
			
		||||
    db.relevant_crates(file_id)
 | 
			
		||||
        .iter()
 | 
			
		||||
        .copied()
 | 
			
		||||
        .filter(|&crate_id| db.crate_def_map(crate_id).modules_for_file(file_id).next().is_some())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue