]> git.lizzy.rs Git - rust.git/commitdiff
Simplify
authorLukas Wirth <lukastw97@gmail.com>
Fri, 3 Dec 2021 16:07:06 +0000 (17:07 +0100)
committerLukas Wirth <lukastw97@gmail.com>
Fri, 3 Dec 2021 16:07:06 +0000 (17:07 +0100)
crates/hir/src/source_analyzer.rs
crates/ide/src/syntax_highlighting/test_data/highlighting.html
crates/ide/src/syntax_highlighting/tests.rs

index 8f6c3d995facd7c612a8ab0adce53291ff00eac4..e14cd43ede85640c86f2585733cef6d7e5c5a77c 100644 (file)
@@ -252,7 +252,9 @@ pub(crate) fn resolve_path(
         db: &dyn HirDatabase,
         path: &ast::Path,
     ) -> Option<PathResolution> {
-        let parent = || path.syntax().parent();
+        let parent = path.syntax().parent();
+        let parent = || parent.clone();
+
         let mut prefer_value_ns = false;
         if let Some(path_expr) = parent().and_then(ast::PathExpr::cast) {
             let expr_id = self.expr_id(db, &path_expr.into())?;
@@ -337,10 +339,10 @@ pub(crate) fn resolve_path(
             return match res {
                 Some(_) => res.map(PathResolution::Macro),
                 None => path.as_single_name_ref().and_then(|name_ref| {
-                    if let Some(builtin) = BuiltinAttr::by_name(&name_ref.text()) {
-                        Some(PathResolution::BuiltinAttr(builtin))
-                    } else if let Some(tool) = Tool::by_name(&name_ref.text()) {
-                        Some(PathResolution::Tool(tool))
+                    if let builtin @ Some(_) = BuiltinAttr::by_name(&name_ref.text()) {
+                        builtin.map(PathResolution::BuiltinAttr)
+                    } else if let tool @ Some(_) = Tool::by_name(&name_ref.text()) {
+                        tool.map(PathResolution::Tool)
                     } else {
                         None
                     }
@@ -355,6 +357,8 @@ pub(crate) fn resolve_path(
         };
         match res {
             Some(_) => res,
+            // this labels any path that starts with a tool module as the tool itself, this is technically wrong
+            // but there is no benefit in differentiating these two cases for the time being
             None if is_path_of_attr => path
                 .first_segment()
                 .and_then(|seg| seg.name_ref())
index da607b51211c356278c740d06860f78354ef505c..370f58080e6bb4379df5b15992961b023f571a13 100644 (file)
@@ -43,6 +43,7 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
 <pre><code><span class="keyword">use</span> <span class="module">inner</span><span class="operator">::</span><span class="brace">{</span><span class="self_keyword">self</span> <span class="keyword">as</span> <span class="module declaration">inner_mod</span><span class="brace">}</span><span class="semicolon">;</span>
 <span class="keyword">mod</span> <span class="module declaration">inner</span> <span class="brace">{</span><span class="brace">}</span>
 
+<span class="attribute attribute">#</span><span class="attribute attribute">[</span><span class="builtin_attr attribute library">allow</span><span class="parenthesis attribute">(</span><span class="parenthesis attribute">)</span><span class="attribute attribute">]</span>
 <span class="attribute attribute">#</span><span class="attribute attribute">[</span><span class="module attribute crate_root library">proc_macros</span><span class="operator attribute">::</span><span class="macro attribute library">identity</span><span class="attribute attribute">]</span>
 <span class="keyword">pub</span> <span class="keyword">mod</span> <span class="module declaration public">ops</span> <span class="brace">{</span>
     <span class="attribute attribute">#</span><span class="attribute attribute">[</span><span class="builtin_attr attribute library">lang</span> <span class="operator attribute">=</span> <span class="string_literal attribute">"fn_once"</span><span class="attribute attribute">]</span>
index e74f39a8650885a40defb70b498878043dbd1032..63a1417c6aaa14f169c984ceebd21d4a36eeec24 100644 (file)
@@ -16,6 +16,7 @@ fn test_highlighting() {
 use inner::{self as inner_mod};
 mod inner {}
 
+#[allow()]
 #[proc_macros::identity]
 pub mod ops {
     #[lang = "fn_once"]