From 6d997876c1f3a9fe5b06ea2b2f64e77eecc41adb Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 23 Jun 2023 18:18:05 -0300 Subject: [PATCH] Fix associated type suggestion when -Zlower-impl-trait-in-trait-to-assoc-ty --- .../rustc_hir_analysis/src/astconv/errors.rs | 20 +++++++++----- ...te-return_type_notation.cfg_current.stderr | 27 +++++++++++++++++++ ...-gate-return_type_notation.cfg_next.stderr | 27 +++++++++++++++++++ ...ate-return_type_notation.no_current.stderr | 13 +++++++++ ...e-gate-return_type_notation.no_next.stderr | 13 +++++++++ .../feature-gate-return_type_notation.rs | 24 +++++++++++------ 6 files changed, 110 insertions(+), 14 deletions(-) create mode 100644 tests/ui/feature-gates/feature-gate-return_type_notation.cfg_current.stderr create mode 100644 tests/ui/feature-gates/feature-gate-return_type_notation.cfg_next.stderr create mode 100644 tests/ui/feature-gates/feature-gate-return_type_notation.no_current.stderr create mode 100644 tests/ui/feature-gates/feature-gate-return_type_notation.no_next.stderr diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs index 7f060af224556..dc17ef7048d01 100644 --- a/compiler/rustc_hir_analysis/src/astconv/errors.rs +++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs @@ -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) = ( @@ -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) = ( diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_current.stderr b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_current.stderr new file mode 100644 index 0000000000000..ce39f6b29713f --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_current.stderr @@ -0,0 +1,27 @@ +error[E0658]: return type notation is experimental + --> $DIR/feature-gate-return_type_notation.rs:17:17 + | +LL | fn foo>() {} + | ^^^^^^^^^ + | + = note: see issue #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>() {} + | ^-- + | | + | 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>() {} + | ^ 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`. diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_next.stderr b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_next.stderr new file mode 100644 index 0000000000000..ce39f6b29713f --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_next.stderr @@ -0,0 +1,27 @@ +error[E0658]: return type notation is experimental + --> $DIR/feature-gate-return_type_notation.rs:17:17 + | +LL | fn foo>() {} + | ^^^^^^^^^ + | + = note: see issue #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>() {} + | ^-- + | | + | 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>() {} + | ^ 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`. diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.no_current.stderr b/tests/ui/feature-gates/feature-gate-return_type_notation.no_current.stderr new file mode 100644 index 0000000000000..d11359e7f48cd --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-return_type_notation.no_current.stderr @@ -0,0 +1,13 @@ +warning: return type notation is experimental + --> $DIR/feature-gate-return_type_notation.rs:17:17 + | +LL | fn foo>() {} + | ^^^^^^^^^ + | + = note: see issue #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 + +warning: 1 warning emitted + diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.no_next.stderr b/tests/ui/feature-gates/feature-gate-return_type_notation.no_next.stderr new file mode 100644 index 0000000000000..d11359e7f48cd --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-return_type_notation.no_next.stderr @@ -0,0 +1,13 @@ +warning: return type notation is experimental + --> $DIR/feature-gate-return_type_notation.rs:17:17 + | +LL | fn foo>() {} + | ^^^^^^^^^ + | + = note: see issue #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 + +warning: 1 warning emitted + diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.rs b/tests/ui/feature-gates/feature-gate-return_type_notation.rs index d9bcb65feba9a..7e8c1eb95ca8f 100644 --- a/tests/ui/feature-gates/feature-gate-return_type_notation.rs +++ b/tests/ui/feature-gates/feature-gate-return_type_notation.rs @@ -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)] @@ -10,12 +13,17 @@ trait Trait { async fn m(); } -#[cfg(cfg)] +#[cfg(any(cfg_current, cfg_next))] fn foo>() {} -//[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() {}