mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-11-03 13:13:18 +00:00 
			
		
		
		
	Simplify unresolved proc-macro handling
This commit is contained in:
		
							parent
							
								
									7b11fdeb68
								
							
						
					
					
						commit
						882ae7105d
					
				@ -637,10 +637,6 @@ impl<'a> AssocItemCollector<'a> {
 | 
			
		||||
                    attr,
 | 
			
		||||
                ) {
 | 
			
		||||
                    Ok(ResolvedAttr::Macro(call_id)) => {
 | 
			
		||||
                        // If proc attribute macro expansion is disabled, skip expanding it here
 | 
			
		||||
                        if !self.db.expand_proc_attr_macros() {
 | 
			
		||||
                            continue 'attrs;
 | 
			
		||||
                        }
 | 
			
		||||
                        let loc = self.db.lookup_intern_macro_call(call_id);
 | 
			
		||||
                        if let MacroDefKind::ProcMacro(_, exp, _) = loc.def.kind {
 | 
			
		||||
                            // If there's no expander for the proc macro (e.g. the
 | 
			
		||||
 | 
			
		||||
@ -83,7 +83,9 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, def_map: DefMap, tree_id: TreeI
 | 
			
		||||
                    let name = Name::new_text_dont_use(it.name.clone());
 | 
			
		||||
                    (
 | 
			
		||||
                        name,
 | 
			
		||||
                        if it.disabled {
 | 
			
		||||
                        if !db.expand_proc_attr_macros() {
 | 
			
		||||
                            CustomProcMacroExpander::dummy()
 | 
			
		||||
                        } else if it.disabled {
 | 
			
		||||
                            CustomProcMacroExpander::disabled()
 | 
			
		||||
                        } else {
 | 
			
		||||
                            CustomProcMacroExpander::new(hir_expand::proc_macro::ProcMacroId::new(
 | 
			
		||||
@ -1331,16 +1333,6 @@ impl DefCollector<'_> {
 | 
			
		||||
 | 
			
		||||
                    let call_id = call_id();
 | 
			
		||||
                    if let MacroDefKind::ProcMacro(_, exp, _) = def.kind {
 | 
			
		||||
                        // If proc attribute macro expansion is disabled, skip expanding it here
 | 
			
		||||
                        if !self.db.expand_proc_attr_macros() {
 | 
			
		||||
                            self.def_map.diagnostics.push(DefDiagnostic::unresolved_proc_macro(
 | 
			
		||||
                                directive.module_id,
 | 
			
		||||
                                self.db.lookup_intern_macro_call(call_id).kind,
 | 
			
		||||
                                def.krate,
 | 
			
		||||
                            ));
 | 
			
		||||
                            return recollect_without(self);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        // If there's no expander for the proc macro (e.g.
 | 
			
		||||
                        // because proc macros are disabled, or building the
 | 
			
		||||
                        // proc macro crate failed), report this and skip
 | 
			
		||||
 | 
			
		||||
@ -17,16 +17,47 @@ use crate::{
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, PartialEq, Eq)]
 | 
			
		||||
pub enum DefDiagnosticKind {
 | 
			
		||||
    UnresolvedModule { ast: AstId<ast::Module>, candidates: Box<[String]> },
 | 
			
		||||
    UnresolvedExternCrate { ast: AstId<ast::ExternCrate> },
 | 
			
		||||
    UnresolvedImport { id: ItemTreeId<item_tree::Use>, index: Idx<ast::UseTree> },
 | 
			
		||||
    UnconfiguredCode { ast: ErasedAstId, cfg: CfgExpr, opts: CfgOptions },
 | 
			
		||||
    UnresolvedProcMacro { ast: MacroCallKind, krate: CrateId },
 | 
			
		||||
    UnresolvedMacroCall { ast: MacroCallKind, path: ModPath },
 | 
			
		||||
    UnimplementedBuiltinMacro { ast: AstId<ast::Macro> },
 | 
			
		||||
    InvalidDeriveTarget { ast: AstId<ast::Item>, id: usize },
 | 
			
		||||
    MalformedDerive { ast: AstId<ast::Adt>, id: usize },
 | 
			
		||||
    MacroDefError { ast: AstId<ast::Macro>, message: String },
 | 
			
		||||
    UnresolvedModule {
 | 
			
		||||
        ast: AstId<ast::Module>,
 | 
			
		||||
        candidates: Box<[String]>,
 | 
			
		||||
    },
 | 
			
		||||
    UnresolvedExternCrate {
 | 
			
		||||
        ast: AstId<ast::ExternCrate>,
 | 
			
		||||
    },
 | 
			
		||||
    UnresolvedImport {
 | 
			
		||||
        id: ItemTreeId<item_tree::Use>,
 | 
			
		||||
        index: Idx<ast::UseTree>,
 | 
			
		||||
    },
 | 
			
		||||
    UnconfiguredCode {
 | 
			
		||||
        ast: ErasedAstId,
 | 
			
		||||
        cfg: CfgExpr,
 | 
			
		||||
        opts: CfgOptions,
 | 
			
		||||
    },
 | 
			
		||||
    /// A proc-macro that is lacking an expander, this might be due to build scripts not yet having
 | 
			
		||||
    /// run or proc-macro expansion being disabled.
 | 
			
		||||
    UnresolvedProcMacro {
 | 
			
		||||
        ast: MacroCallKind,
 | 
			
		||||
        krate: CrateId,
 | 
			
		||||
    },
 | 
			
		||||
    UnresolvedMacroCall {
 | 
			
		||||
        ast: MacroCallKind,
 | 
			
		||||
        path: ModPath,
 | 
			
		||||
    },
 | 
			
		||||
    UnimplementedBuiltinMacro {
 | 
			
		||||
        ast: AstId<ast::Macro>,
 | 
			
		||||
    },
 | 
			
		||||
    InvalidDeriveTarget {
 | 
			
		||||
        ast: AstId<ast::Item>,
 | 
			
		||||
        id: usize,
 | 
			
		||||
    },
 | 
			
		||||
    MalformedDerive {
 | 
			
		||||
        ast: AstId<ast::Adt>,
 | 
			
		||||
        id: usize,
 | 
			
		||||
    },
 | 
			
		||||
    MacroDefError {
 | 
			
		||||
        ast: AstId<ast::Macro>,
 | 
			
		||||
        message: String,
 | 
			
		||||
    },
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Clone, Debug, PartialEq, Eq)]
 | 
			
		||||
@ -92,10 +123,6 @@ impl DefDiagnostic {
 | 
			
		||||
        Self { in_module: container, kind: DefDiagnosticKind::UnconfiguredCode { ast, cfg, opts } }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // FIXME: Whats the difference between this and unresolved_macro_call
 | 
			
		||||
    // FIXME: This is used for a lot of things, unresolved proc macros, disabled proc macros, etc
 | 
			
		||||
    // yet the diagnostic handler in ide-diagnostics has to figure out what happened because this
 | 
			
		||||
    // struct loses all that information!
 | 
			
		||||
    pub fn unresolved_proc_macro(
 | 
			
		||||
        container: LocalModuleId,
 | 
			
		||||
        ast: MacroCallKind,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user