Skip to content

Commit bfe6e5c

Browse files
Rollup merge of rust-lang#112983 - spastorino:new-rpitit-23, r=compiler-errors
Fix return type notation associated type suggestion when -Zlower-impl-trait-in-trait-to-assoc-ty This avoid suggesting the associated types generated for RPITITs when the one the code refers to doesn't exist and rustc looks for a suggestion. r? `@compiler-errors`
2 parents 4a17552 + 6d99787 commit bfe6e5c

6 files changed

+110
-14
lines changed

compiler/rustc_hir_analysis/src/astconv/errors.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
122122

123123
let all_candidate_names: Vec<_> = all_candidates()
124124
.flat_map(|r| self.tcx().associated_items(r.def_id()).in_definition_order())
125-
.filter_map(
126-
|item| if item.kind == ty::AssocKind::Type { Some(item.name) } else { None },
127-
)
125+
.filter_map(|item| {
126+
if item.opt_rpitit_info.is_none() && item.kind == ty::AssocKind::Type {
127+
Some(item.name)
128+
} else {
129+
None
130+
}
131+
})
128132
.collect();
129133

130134
if let (Some(suggested_name), true) = (
@@ -159,9 +163,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
159163
.flat_map(|trait_def_id| {
160164
self.tcx().associated_items(*trait_def_id).in_definition_order()
161165
})
162-
.filter_map(
163-
|item| if item.kind == ty::AssocKind::Type { Some(item.name) } else { None },
164-
)
166+
.filter_map(|item| {
167+
if item.opt_rpitit_info.is_none() && item.kind == ty::AssocKind::Type {
168+
Some(item.name)
169+
} else {
170+
None
171+
}
172+
})
165173
.collect();
166174

167175
if let (Some(suggested_name), true) = (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0658]: return type notation is experimental
2+
--> $DIR/feature-gate-return_type_notation.rs:17:17
3+
|
4+
LL | fn foo<T: Trait<m(): Send>>() {}
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= help: add `#![feature(return_type_notation)]` to the crate attributes to enable
9+
10+
error: parenthesized generic arguments cannot be used in associated type constraints
11+
--> $DIR/feature-gate-return_type_notation.rs:17:17
12+
|
13+
LL | fn foo<T: Trait<m(): Send>>() {}
14+
| ^--
15+
| |
16+
| help: remove these parentheses
17+
18+
error[E0220]: associated type `m` not found for `Trait`
19+
--> $DIR/feature-gate-return_type_notation.rs:17:17
20+
|
21+
LL | fn foo<T: Trait<m(): Send>>() {}
22+
| ^ associated type `m` not found
23+
24+
error: aborting due to 3 previous errors
25+
26+
Some errors have detailed explanations: E0220, E0658.
27+
For more information about an error, try `rustc --explain E0220`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0658]: return type notation is experimental
2+
--> $DIR/feature-gate-return_type_notation.rs:17:17
3+
|
4+
LL | fn foo<T: Trait<m(): Send>>() {}
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= help: add `#![feature(return_type_notation)]` to the crate attributes to enable
9+
10+
error: parenthesized generic arguments cannot be used in associated type constraints
11+
--> $DIR/feature-gate-return_type_notation.rs:17:17
12+
|
13+
LL | fn foo<T: Trait<m(): Send>>() {}
14+
| ^--
15+
| |
16+
| help: remove these parentheses
17+
18+
error[E0220]: associated type `m` not found for `Trait`
19+
--> $DIR/feature-gate-return_type_notation.rs:17:17
20+
|
21+
LL | fn foo<T: Trait<m(): Send>>() {}
22+
| ^ associated type `m` not found
23+
24+
error: aborting due to 3 previous errors
25+
26+
Some errors have detailed explanations: E0220, E0658.
27+
For more information about an error, try `rustc --explain E0220`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
warning: return type notation is experimental
2+
--> $DIR/feature-gate-return_type_notation.rs:17:17
3+
|
4+
LL | fn foo<T: Trait<m(): Send>>() {}
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= help: add `#![feature(return_type_notation)]` to the crate attributes to enable
9+
= warning: unstable syntax can change at any point in the future, causing a hard error!
10+
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>
11+
12+
warning: 1 warning emitted
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
warning: return type notation is experimental
2+
--> $DIR/feature-gate-return_type_notation.rs:17:17
3+
|
4+
LL | fn foo<T: Trait<m(): Send>>() {}
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= help: add `#![feature(return_type_notation)]` to the crate attributes to enable
9+
= warning: unstable syntax can change at any point in the future, causing a hard error!
10+
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>
11+
12+
warning: 1 warning emitted
13+
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// edition: 2021
2-
// revisions: cfg no
2+
// revisions: cfg_current cfg_next no_current no_next
3+
// [cfg_next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
4+
// [no_next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
35

4-
//[no] check-pass
6+
// [no_current] check-pass
7+
// [no_next] check-pass
58
// Since we're not adding new syntax, `cfg`'d out RTN must pass.
69

710
#![feature(async_fn_in_trait)]
@@ -10,12 +13,17 @@ trait Trait {
1013
async fn m();
1114
}
1215

13-
#[cfg(cfg)]
16+
#[cfg(any(cfg_current, cfg_next))]
1417
fn foo<T: Trait<m(): Send>>() {}
15-
//[cfg]~^ ERROR return type notation is experimental
16-
//[cfg]~| ERROR parenthesized generic arguments cannot be used in associated type constraints
17-
//[cfg]~| ERROR associated type `m` not found for `Trait`
18-
//[no]~^^^^ WARN return type notation is experimental
19-
//[no]~| WARN unstable syntax can change at any point in the future, causing a hard error!
18+
//[cfg_current]~^ ERROR return type notation is experimental
19+
//[cfg_current]~| ERROR parenthesized generic arguments cannot be used in associated type constraints
20+
//[cfg_current]~| ERROR associated type `m` not found for `Trait`
21+
//[cfg_next]~^^^^ ERROR return type notation is experimental
22+
//[cfg_next]~| ERROR parenthesized generic arguments cannot be used in associated type constraints
23+
//[cfg_next]~| ERROR associated type `m` not found for `Trait`
24+
//[no_current]~^^^^^^^ WARN return type notation is experimental
25+
//[no_current]~| WARN unstable syntax can change at any point in the future, causing a hard error!
26+
//[no_next]~^^^^^^^^^ WARN return type notation is experimental
27+
//[no_next]~| WARN unstable syntax can change at any point in the future, causing a hard error!
2028

2129
fn main() {}

0 commit comments

Comments
 (0)