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

Issue:
base trait method not resolved when using impl in return position
<!--
Troubleshooting guide: https://rust-analyzer.github.io/manual.html#troubleshooting
Forum for questions: https://users.rust-lang.org/c/ide/14

Before submitting, please make sure that you're not running into one of these known issues:

 1. local imports (`use` statements) don't work: #1165
 2. local items don't work: #1559
 3. on-the-fly diagnostics are mostly unimplemented (`cargo check` diagnostics will be shown when saving a file)
 4. some settings are required for procedural macro and build script support (`rust-analyzer.cargo.loadOutDirsFromCheck`, `rust-analyzer.procMacro.enable`): #6448
 5. some platform-specific imports are not resolved: #6038
 6. the official `rust-lang.rust` VS Code extension conflicts with `rust-analyzer`: #6463

Otherwise please try to provide information which will help us to fix the issue faster. Minimal reproducible examples with few dependencies are especially lovely <3.
-->
Code that reproduces the issue:
```rust
fn elements_iter() -> impl Iterator<Item = usize> {
    [].iter().copied()
}

fn elements_exacte_size_iter() -> impl ExactSizeIterator<Item = usize> {
    [].iter().copied()
}

fn test() {
    for x in elements_iter() {}
    //  ^ is correctly inferred to be `usize`
    for x in elements_exacte_size_iter() {}
    //  ^ is not inferred
}
```
After investigating in the rust-analyzer source and playing around with a test in `crates/hir_ty/src/tests/traits.rs` I found out that inference works when it's an argument:
```rust
fn foo(xs: impl ExactSizeIterator<Item = usize>) {
    for x in xs {}
    //  ^ inferred `usize`
}
fn bar<I: ExactSizeIterator<Item = usize>>(xs: I) {
    for x in xs {}
    //  ^ inferred `usize`
}
```
This is the test:
```rust
#[test]
fn super_trait_assoc_type_impl_return() {
    check_infer(
        r#"
        trait Base {
            type Item;
            fn foo(self) -> Self::Item;
        }

        trait Super : Base {}
        
        fn base1() -> impl Base<Item = usize> { loop {} }
        fn super1() -> impl Super<Item = usize> { loop {} }

        fn test(base2: impl Base<Item = usize>, super2: impl Super<Item = usize>) {            
            base1().foo();
            super1().foo();
            base2.foo();
            super2.foo();
        }
        "#,
        expect![[r#"..."#]],
    );
}
```

which at the moment gives:
```
39..43 'self': Self
124..135 '{ loop {} }': !
126..133 'loop {}': !
131..133 '{}': ()
176..187 '{ loop {} }': !
178..185 'loop {}': !
183..185 '{}': ()
197..202 'base2': impl Base<Item = usize>
229..235 'super2': impl Super<Item = usize>
263..352 '{     ...o(); }': ()
281..286 'base1': fn base1() -> impl Base<Item = usize>
281..288 'base1()': impl Base<Item = usize>
281..294 'base1().foo()': usize
300..306 'super1': fn super1() -> impl Super<Item = usize>
300..308 'super1()': impl Super<Item = usize>
300..314 'super1().foo()': {unknown}
320..325 'base2': impl Base<Item = usize>
320..331 'base2.foo()': usize
337..343 'super2': impl Super<Item = usize>
337..349 'super2.foo()': usize
```

Pull request description:
Bump deps
Closes #7273

bors r+

Patch:
diff --git a/Cargo.lock b/Cargo.lock
index e8d9020d67..2a8ef7ef37 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,5 +1,7 @@
 # This file is automatically @generated by Cargo.
 # It is not intended for manual editing.
+version = 3
+
 [[package]]
 name = "addr2line"
 version = "0.14.1"
@@ -172,9 +174,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
 
 [[package]]
 name = "chalk-derive"
-version = "0.56.0"
+version = "0.58.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "51f6c7a4b1a119cff6c5a17cf68056069dece7bc525c2a2e26e1117e27f48ca2"
+checksum = "e625b7c688272783140509a0de8f7aa9000217cb0982c9b10606a12b0b747ba8"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -184,9 +186,9 @@ dependencies = [
 
 [[package]]
 name = "chalk-ir"
-version = "0.56.0"
+version = "0.58.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7d5f524bc3a5798fe3711c360fde350bffb938b52ef7b302d637550229995e20"
+checksum = "c220d870128959d7d56667060d556ffdebd490f32ee0fc9f4060a76c1193f206"
 dependencies = [
  "bitflags",
  "chalk-derive",
@@ -195,9 +197,9 @@ dependencies = [
 
 [[package]]
 name = "chalk-recursive"
-version = "0.56.0"
+version = "0.58.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f7c0525fb9c43f8f1d7ba4fb42f9ada2a2415901a04b5c655cfe11e559085d4d"
+checksum = "7d8cd81a15aa936215378e695a8907b9f1af8626a27a32ee22e97a50984960da"
 dependencies = [
  "chalk-derive",
  "chalk-ir",
@@ -208,9 +210,9 @@ dependencies = [
 
 [[package]]
 name = "chalk-solve"
-version = "0.56.0"
+version = "0.58.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3c2e7b54add0f18d5ee7bb043a3108b819e60b1b409d214291bcdc97927cdc32"
+checksum = "55571250dfe096a4c899be88c81418284c952ce1c8a06aa16afb5781b298e9c9"
 dependencies = [
  "chalk-derive",
  "chalk-ir",
@@ -245,12 +247,6 @@ dependencies = [
  "cc",
 ]
 
-[[package]]
-name = "const_fn"
-version = "0.4.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6"
-
 [[package]]
 name = "countme"
 version = "2.0.4"
@@ -294,27 +290,28 @@ dependencies = [
 
 [[package]]
 name = "crossbeam-epoch"
-version = "0.9.1"
+version = "0.9.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d"
+checksum = "d60ab4a8dba064f2fbb5aa270c28da5cf4bbd0e72dae1140a6b0353a779dbe00"
 dependencies = [
  "cfg-if",
- "const_fn",
  "crossbeam-utils",
  "lazy_static",
+ "loom",
  "memoffset",
  "scopeguard",
 ]
 
 [[package]]
 name = "crossbeam-utils"
-version = "0.8.1"
+version = "0.8.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d"
+checksum = "bae8f328835f8f5a6ceb6a7842a7f2d0c03692adb5c889347235d59194731fe3"
 dependencies = [
  "autocfg",
  "cfg-if",
  "lazy_static",
+ "loom",
 ]
 
 [[package]]
@@ -457,6 +454,19 @@ version = "0.4.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d79238883cf0307100b90aba4a755d8051a3182305dfe7f649a1e9dc0517006f"
 
+[[package]]
+name = "generator"
+version = "0.6.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a9fed24fd1e18827652b4d55652899a1e9da8e54d91624dc3437a5bc3a9f9a9c"
+dependencies = [
+ "cc",
+ "libc",
+ "log",
+ "rustversion",
+ "winapi",
+]
+
 [[package]]
 name = "gimli"
 version = "0.23.0"
@@ -820,6 +830,17 @@ dependencies = [
  "cfg-if",
 ]
 
+[[package]]
+name = "loom"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d44c73b4636e497b4917eb21c33539efa3816741a2d3ff26c6316f1b529481a4"
+dependencies = [
+ "cfg-if",
+ "generator",
+ "scoped-tls",
+]
+
 [[package]]
 name = "lsp-server"
 version = "0.5.0"
@@ -1299,9 +1320,9 @@ checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581"
 
 [[package]]
 name = "rowan"
-version = "0.12.5"
+version = "0.12.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e29b035c9f476b43074a36257464c487788a0a1b9aaf427b068dc147135eb1ab"
+checksum = "a1b36e449f3702f3b0c821411db1cbdf30fb451726a9456dce5dabcd44420043"
 dependencies = [
  "countme",
  "hashbrown",
@@ -1364,9 +1385,9 @@ dependencies = [
 
 [[package]]
 name = "rustc-ap-rustc_lexer"
-version = "705.0.0"
+version = "707.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3a030d00510966cd31e13dca5e6c1bd40d303a932c54eca40e854188bca8c49e"
+checksum = "e27206aceb3b2153a3c367727d534362a1ce63a43ece8fd878195738a83aaf6f"
 dependencies = [
  "unicode-xid",
 ]
@@ -1383,6 +1404,12 @@ version = "1.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
 
+[[package]]
+name = "rustversion"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd"
+
 [[package]]
 name = "ryu"
 version = "1.0.5"
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml
index 418ac8cbbf..6ef9d1e7e0 100644
--- a/crates/hir_ty/Cargo.toml
+++ b/crates/hir_ty/Cargo.toml
@@ -17,9 +17,9 @@ ena = "0.14.0"
 log = "0.4.8"
 rustc-hash = "1.1.0"
 scoped-tls = "1"
-chalk-solve = { version = "0.56", default-features = false }
-chalk-ir = "0.56"
-chalk-recursive = "0.56"
+chalk-solve = { version = "0.58", default-features = false }
+chalk-ir = "0.58"
+chalk-recursive = "0.58"
 la-arena = { version = "0.2.0", path = "../../lib/arena" }
 
 stdx = { path = "../stdx", version = "0.0.0" }
diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml
index e3ef716504..e41171b57a 100644
--- a/crates/syntax/Cargo.toml
+++ b/crates/syntax/Cargo.toml
@@ -13,7 +13,7 @@ doctest = false
 [dependencies]
 itertools = "0.10.0"
 rowan = "0.12.2"
-rustc_lexer = { version = "705.0.0", package = "rustc-ap-rustc_lexer" }
+rustc_lexer = { version = "707.0.0", package = "rustc-ap-rustc_lexer" }
 rustc-hash = "1.1.0"
 arrayvec = "0.5.1"
 once_cell = "1.3.1"
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index 4e6b439fd6..b379797f98 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -15,7 +15,7 @@ flate2 = "1.0"
 pico-args = "0.4.0"
 proc-macro2 = "1.0.8"
 quote = "1.0.2"
-ungrammar = "1.9"
+ungrammar = "=1.11"
 walkdir = "2.3.1"
 write-json = "0.1.0"
 xshell = "0.1"


Test patch:
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs
index 659b8fce9c..a9901d7b85 100644
--- a/crates/hir_ty/src/tests/method_resolution.rs
+++ b/crates/hir_ty/src/tests/method_resolution.rs
@@ -955,6 +955,51 @@ fn test() { foo.call(); }
     );
 }
 
+#[test]
+fn super_trait_impl_return_trait_method_resolution() {
+    check_infer(
+        r#"
+        trait Base {
+            fn foo(self) -> usize;
+        }
+
+        trait Super : Base {}
+
+        fn base1() -> impl Base { loop {} }
+        fn super1() -> impl Super { loop {} }
+
+        fn test(base2: impl Base, super2: impl Super) {
+            base1().foo();
+            super1().foo();
+            base2.foo();
+            super2.foo();
+        }
+        "#,
+        expect![[r#"
+            24..28 'self': Self
+            90..101 '{ loop {} }': !
+            92..99 'loop {}': !
+            97..99 '{}': ()
+            128..139 '{ loop {} }': !
+            130..137 'loop {}': !
+            135..137 '{}': ()
+            149..154 'base2': impl Base
+            167..173 'super2': impl Super
+            187..264 '{     ...o(); }': ()
+            193..198 'base1': fn base1() -> impl Base
+            193..200 'base1()': impl Base
+            193..206 'base1().foo()': usize
+            212..218 'super1': fn super1() -> impl Super
+            212..220 'super1()': impl Super
+            212..226 'super1().foo()': usize
+            232..237 'base2': impl Base
+            232..243 'base2.foo()': usize
+            249..255 'super2': impl Super
+            249..261 'super2.foo()': usize
+        "#]],
+    );
+}
+
 #[test]
 fn method_resolution_non_parameter_type() {
     check_types(