Skip to content

Commit

Permalink
Rollup merge of #112983 - spastorino:new-rpitit-23, r=compiler-errors
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
compiler-errors authored Jun 24, 2023
2 parents 4a17552 + 6d99787 commit bfe6e5c
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 14 deletions.
20 changes: 14 additions & 6 deletions compiler/rustc_hir_analysis/src/astconv/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {

let all_candidate_names: Vec<_> = all_candidates()
.flat_map(|r| self.tcx().associated_items(r.def_id()).in_definition_order())
.filter_map(
|item| if item.kind == ty::AssocKind::Type { Some(item.name) } else { None },
)
.filter_map(|item| {
if item.opt_rpitit_info.is_none() && item.kind == ty::AssocKind::Type {
Some(item.name)
} else {
None
}
})
.collect();

if let (Some(suggested_name), true) = (
Expand Down Expand Up @@ -159,9 +163,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.flat_map(|trait_def_id| {
self.tcx().associated_items(*trait_def_id).in_definition_order()
})
.filter_map(
|item| if item.kind == ty::AssocKind::Type { Some(item.name) } else { None },
)
.filter_map(|item| {
if item.opt_rpitit_info.is_none() && item.kind == ty::AssocKind::Type {
Some(item.name)
} else {
None
}
})
.collect();

if let (Some(suggested_name), true) = (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0658]: return type notation is experimental
--> $DIR/feature-gate-return_type_notation.rs:17:17
|
LL | fn foo<T: Trait<m(): Send>>() {}
| ^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
= help: add `#![feature(return_type_notation)]` to the crate attributes to enable

error: parenthesized generic arguments cannot be used in associated type constraints
--> $DIR/feature-gate-return_type_notation.rs:17:17
|
LL | fn foo<T: Trait<m(): Send>>() {}
| ^--
| |
| help: remove these parentheses

error[E0220]: associated type `m` not found for `Trait`
--> $DIR/feature-gate-return_type_notation.rs:17:17
|
LL | fn foo<T: Trait<m(): Send>>() {}
| ^ associated type `m` not found

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0220, E0658.
For more information about an error, try `rustc --explain E0220`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0658]: return type notation is experimental
--> $DIR/feature-gate-return_type_notation.rs:17:17
|
LL | fn foo<T: Trait<m(): Send>>() {}
| ^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
= help: add `#![feature(return_type_notation)]` to the crate attributes to enable

error: parenthesized generic arguments cannot be used in associated type constraints
--> $DIR/feature-gate-return_type_notation.rs:17:17
|
LL | fn foo<T: Trait<m(): Send>>() {}
| ^--
| |
| help: remove these parentheses

error[E0220]: associated type `m` not found for `Trait`
--> $DIR/feature-gate-return_type_notation.rs:17:17
|
LL | fn foo<T: Trait<m(): Send>>() {}
| ^ associated type `m` not found

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0220, E0658.
For more information about an error, try `rustc --explain E0220`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
warning: return type notation is experimental
--> $DIR/feature-gate-return_type_notation.rs:17:17
|
LL | fn foo<T: Trait<m(): Send>>() {}
| ^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
= help: add `#![feature(return_type_notation)]` to the crate attributes to enable
= warning: unstable syntax can change at any point in the future, causing a hard error!
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>

warning: 1 warning emitted

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
warning: return type notation is experimental
--> $DIR/feature-gate-return_type_notation.rs:17:17
|
LL | fn foo<T: Trait<m(): Send>>() {}
| ^^^^^^^^^
|
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
= help: add `#![feature(return_type_notation)]` to the crate attributes to enable
= warning: unstable syntax can change at any point in the future, causing a hard error!
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>

warning: 1 warning emitted

24 changes: 16 additions & 8 deletions tests/ui/feature-gates/feature-gate-return_type_notation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// edition: 2021
// revisions: cfg no
// revisions: cfg_current cfg_next no_current no_next
// [cfg_next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
// [no_next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty

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

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

#[cfg(cfg)]
#[cfg(any(cfg_current, cfg_next))]
fn foo<T: Trait<m(): Send>>() {}
//[cfg]~^ ERROR return type notation is experimental
//[cfg]~| ERROR parenthesized generic arguments cannot be used in associated type constraints
//[cfg]~| ERROR associated type `m` not found for `Trait`
//[no]~^^^^ WARN return type notation is experimental
//[no]~| WARN unstable syntax can change at any point in the future, causing a hard error!
//[cfg_current]~^ ERROR return type notation is experimental
//[cfg_current]~| ERROR parenthesized generic arguments cannot be used in associated type constraints
//[cfg_current]~| ERROR associated type `m` not found for `Trait`
//[cfg_next]~^^^^ ERROR return type notation is experimental
//[cfg_next]~| ERROR parenthesized generic arguments cannot be used in associated type constraints
//[cfg_next]~| ERROR associated type `m` not found for `Trait`
//[no_current]~^^^^^^^ WARN return type notation is experimental
//[no_current]~| WARN unstable syntax can change at any point in the future, causing a hard error!
//[no_next]~^^^^^^^^^ WARN return type notation is experimental
//[no_next]~| WARN unstable syntax can change at any point in the future, causing a hard error!

fn main() {}

0 comments on commit bfe6e5c

Please sign in to comment.