Repository: rust-analyzer/rust-analyzer (rust)

Issue:
Doctest syntax highlighting disabled for macro_rules
The new doctest syntax highlighting is awesome!

I noticed that it seems to be disabled for `macro_rules` definitions:
![Screen Shot 2020-06-19 at 09 24 53](https://user-images.githubusercontent.com/11131775/85137402-27310900-b20f-11ea-8532-0bc6df7a49e2.png)

Strangely enough, by adding some characters I can force the syntax highlighting on, but then of course my code is invalid :)
Example:
![Screen Recording 2020-06-19 at 09 25 20 mov](https://user-images.githubusercontent.com/11131775/85138151-509e6480-b210-11ea-9033-e483889efaa8.gif)

Some output from the inspector when it is off and on:
![Screen Shot 2020-06-19 at 09 25 50](https://user-images.githubusercontent.com/11131775/85138180-5b58f980-b210-11ea-98bf-998f639ef60e.png)
![Screen Shot 2020-06-19 at 09 26 06](https://user-images.githubusercontent.com/11131775/85138181-5b58f980-b210-11ea-8a7c-a70f557d8213.png)
 

Pull request:
Syntax highlighting for documentation comments on macro definitions
Two minor changes with regards to syntax highlighting of comments attached to macro definitions.

Before
<img width="290" alt="Bildschirmfoto 2020-06-20 um 00 05 19" src="https://user-images.githubusercontent.com/201808/85182705-c561b500-b289-11ea-944e-0bdf6508a44f.png">

After
<img width="288" alt="Bildschirmfoto 2020-06-20 um 00 03 36" src="https://user-images.githubusercontent.com/201808/85182727-d90d1b80-b289-11ea-9d2d-234731f19302.png">
Fixes #4949

Patch:
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index e6af990355..bf26048f2a 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -254,12 +254,12 @@ impl CrateGraph {
             return false;
         }
 
-        if target == from {
-            return true;
-        }
-
         for dep in &self[from].dependencies {
             let crate_id = dep.crate_id;
+            if crate_id == target {
+                return true;
+            }
+
             if self.dfs_find(target, crate_id, visited) {
                 return true;
             }
@@ -369,7 +369,7 @@ mod tests {
     use super::{CfgOptions, CrateGraph, CrateName, Dependency, Edition::Edition2018, Env, FileId};
 
     #[test]
-    fn detect_cyclic_dependency_indirect() {
+    fn it_should_panic_because_of_cycle_dependencies() {
         let mut graph = CrateGraph::default();
         let crate1 = graph.add_crate_root(
             FileId(1u32),
@@ -403,31 +403,6 @@ mod tests {
         assert!(graph.add_dep(crate3, CrateName::new("crate1").unwrap(), crate1).is_err());
     }
 
-    #[test]
-    fn detect_cyclic_dependency_direct() {
-        let mut graph = CrateGraph::default();
-        let crate1 = graph.add_crate_root(
-            FileId(1u32),
-            Edition2018,
-            None,
-            CfgOptions::default(),
-            Env::default(),
-            Default::default(),
-            Default::default(),
-        );
-        let crate2 = graph.add_crate_root(
-            FileId(2u32),
-            Edition2018,
-            None,
-            CfgOptions::default(),
-            Env::default(),
-            Default::default(),
-            Default::default(),
-        );
-        assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok());
-        assert!(graph.add_dep(crate2, CrateName::new("crate2").unwrap(), crate2).is_err());
-    }
-
     #[test]
     fn it_works() {
         let mut graph = CrateGraph::default();
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index b8f6aac8f2..77baa4c696 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -36,8 +36,8 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> Cr
 
     // populate external prelude
     for dep in &crate_graph[def_map.krate].dependencies {
-        log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id);
         let dep_def_map = db.crate_def_map(dep.crate_id);
+        log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id);
         def_map.extern_prelude.insert(
             dep.as_name(),
             ModuleId { krate: dep.crate_id, local_id: dep_def_map.root }.into(),
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index d5154f436e..7a7fcb0aba 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -467,9 +467,6 @@ impl Ty {
                             }
                             TypeParamLoweringMode::Variable => t.substs.clone(),
                         };
-                        // We need to shift in the bound vars, since
-                        // associated_type_shorthand_candidates does not do that
-                        let substs = substs.shift_bound_vars(ctx.in_binders);
                         // FIXME handle type parameters on the segment
                         return Some(Ty::Projection(ProjectionTy {
                             associated_ty,
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index f8f790e590..448645bdc3 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -121,7 +121,6 @@ pub(crate) fn highlight(
                 assert!(current_macro_call == Some(mc));
                 current_macro_call = None;
                 format_string = None;
-                continue;
             }
             _ => (),
         }
@@ -150,7 +149,7 @@ pub(crate) fn highlight(
 
         let range = element.text_range();
 
-        let element_to_highlight = if current_macro_call.is_some() {
+        let element_to_highlight = if current_macro_call.is_some() && element.kind() != COMMENT {
             // Inside a macro -- expand it first
             let token = match element.clone().into_token() {
                 Some(it) if it.parent().kind() == TOKEN_TREE => it,


Test patch:
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs
index 4da2e972bd..8dc5603b74 100644
--- a/crates/ra_hir_ty/src/tests/regression.rs
+++ b/crates/ra_hir_ty/src/tests/regression.rs
@@ -693,94 +693,3 @@ fn check<T: PrimInt>(i: T) {
     "###
     );
 }
-
-#[test]
-fn issue_4885() {
-    assert_snapshot!(
-        infer(r#"
-#[lang = "coerce_unsized"]
-pub trait CoerceUnsized<T> {}
-
-trait Future {
-    type Output;
-}
-trait Foo<R> {
-    type Bar;
-}
-fn foo<R, K>(key: &K) -> impl Future<Output = K::Bar>
-where
-    K: Foo<R>,
-{
-    bar(key)
-}
-fn bar<R, K>(key: &K) -> impl Future<Output = K::Bar>
-where
-    K: Foo<R>,
-{
-}
-"#),
-        @r###"
-    137..140 'key': &K
-    199..215 '{     ...key) }': impl Future<Output = <K as Foo<R>>::Bar>
-    205..208 'bar': fn bar<R, K>(&K) -> impl Future<Output = <K as Foo<R>>::Bar>
-    205..213 'bar(key)': impl Future<Output = <K as Foo<R>>::Bar>
-    209..212 'key': &K
-    229..232 'key': &K
-    291..294 '{ }': ()
-    "###
-    );
-}
-
-#[test]
-fn issue_4800() {
-    assert_snapshot!(
-        infer(r#"
-trait Debug {}
-
-struct Foo<T>;
-
-type E1<T> = (T, T, T);
-type E2<T> = E1<E1<E1<(T, T, T)>>>;
-
-impl Debug for Foo<E2<()>> {}
-
-struct Request;
-
-pub trait Future {
-    type Output;
-}
-
-pub struct PeerSet<D>;
-
-impl<D> Service<Request> for PeerSet<D>
-where
-    D: Discover,
-    D::Key: Debug,
-{
-    type Error = ();
-    type Future = dyn Future<Output = Self::Error>;
-
-    fn call(&mut self) -> Self::Future {
-        loop {}
-    }
-}
-
-pub trait Discover {
-    type Key;
-}
-
-pub trait Service<Request> {
-    type Error;
-    type Future: Future<Output = Self::Error>;
-    fn call(&mut self) -> Self::Future;
-}
-"#),
-        @r###"
-    380..384 'self': &mut PeerSet<D>
-    402..425 '{     ...     }': dyn Future<Output = ()>
-    412..419 'loop {}': !
-    417..419 '{}': ()
-    576..580 'self': &mut Self
-    "###
-    );
-}
diff --git a/crates/ra_ide/src/snapshots/highlight_doctest.html b/crates/ra_ide/src/snapshots/highlight_doctest.html
index f61c0daa50..63199cdbe2 100644
--- a/crates/ra_ide/src/snapshots/highlight_doctest.html
+++ b/crates/ra_ide/src/snapshots/highlight_doctest.html
@@ -84,4 +84,13 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
     <span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration">foo</span>(&<span class="self_keyword">self</span>) -&gt; <span class="builtin_type">bool</span> {
         <span class="bool_literal">true</span>
     }
+}
+
+<span class="comment documentation">/// ```</span>
+<span class="comment documentation">/// </span><span class="macro">noop!</span>(<span class="numeric_literal">1</span>);
+<span class="comment documentation">/// ```</span>
+<span class="macro">macro_rules!</span> <span class="macro declaration">noop</span> {
+    ($expr:expr) =&gt; {
+        $expr
+    }
 }</code></pre>
\ No newline at end of file
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index b4d56a7a06..93a276ffe1 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -344,6 +344,15 @@ impl Foo {
         true
     }
 }
+
+/// ```
+/// noop!(1);
+/// ```
+macro_rules! noop {
+    ($expr:expr) => {
+        $expr
+    }
+}
 "#
         .trim(),
         "crates/ra_ide/src/snapshots/highlight_doctest.html",