Auto merge of #142074 - oli-obk:its-finally-gone, r=petrochenkov

Remove CollectItemTypesVisitor

I always felt like we were very unnecessarily walking the HIR, let's see if perf agrees

There is lots to ~~improve~~ consolidate further here, as we still have 3 item wfchecks:

* check_item (matching on the hir::ItemKind)
    * actually doing trait solver based checks (by using HIR spans)
* lower_item (matching on the hir::ItemKind after loading it again??)
    * just ensure_ok-ing a bunch of queries
* check_item_type (matching on DefKind)
    * some type based checks, mostly ensure_ok-ing a bunch of queries

fixes rust-lang/rust#121429
This commit is contained in:
bors
2025-06-08 02:04:41 +00:00
11 changed files with 220 additions and 246 deletions

View File

@@ -702,6 +702,29 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
} }
pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) { pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let generics = tcx.generics_of(def_id);
for param in &generics.own_params {
match param.kind {
ty::GenericParamDefKind::Lifetime { .. } => {}
ty::GenericParamDefKind::Type { has_default, .. } => {
if has_default {
tcx.ensure_ok().type_of(param.def_id);
}
}
ty::GenericParamDefKind::Const { has_default, .. } => {
tcx.ensure_ok().type_of(param.def_id);
if has_default {
// need to store default and type of default
let ct = tcx.const_param_default(param.def_id).skip_binder();
if let ty::ConstKind::Unevaluated(uv) = ct.kind() {
tcx.ensure_ok().type_of(uv.def);
}
}
}
}
}
match tcx.def_kind(def_id) { match tcx.def_kind(def_id) {
DefKind::Static { .. } => { DefKind::Static { .. } => {
check_static_inhabited(tcx, def_id); check_static_inhabited(tcx, def_id);
@@ -770,6 +793,16 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
} else { } else {
check_opaque(tcx, def_id); check_opaque(tcx, def_id);
} }
tcx.ensure_ok().predicates_of(def_id);
tcx.ensure_ok().explicit_item_bounds(def_id);
tcx.ensure_ok().explicit_item_self_bounds(def_id);
tcx.ensure_ok().item_bounds(def_id);
tcx.ensure_ok().item_self_bounds(def_id);
if tcx.is_conditionally_const(def_id) {
tcx.ensure_ok().explicit_implied_const_bounds(def_id);
tcx.ensure_ok().const_conditions(def_id);
}
} }
DefKind::TyAlias => { DefKind::TyAlias => {
check_type_alias_type_params_are_used(tcx, def_id); check_type_alias_type_params_are_used(tcx, def_id);
@@ -827,6 +860,15 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
} }
} }
} }
DefKind::Closure => {
// This is guaranteed to be called by metadata encoding,
// we still call it in wfcheck eagerly to ensure errors in codegen
// attrs prevent lints from spamming the output.
tcx.ensure_ok().codegen_fn_attrs(def_id);
// We do not call `type_of` for closures here as that
// depends on typecheck and would therefore hide
// any further errors in case one typeck fails.
}
_ => {} _ => {}
} }
} }

View File

@@ -40,7 +40,6 @@ use tracing::{debug, instrument};
use {rustc_ast as ast, rustc_hir as hir}; use {rustc_ast as ast, rustc_hir as hir};
use crate::autoderef::Autoderef; use crate::autoderef::Autoderef;
use crate::collect::CollectItemTypesVisitor;
use crate::constrained_generic_params::{Parameter, identify_constrained_generic_params}; use crate::constrained_generic_params::{Parameter, identify_constrained_generic_params};
use crate::errors::InvalidReceiverTyHint; use crate::errors::InvalidReceiverTyHint;
use crate::{errors, fluent_generated as fluent}; use crate::{errors, fluent_generated as fluent};
@@ -195,7 +194,9 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua
hir::Node::TraitItem(item) => check_trait_item(tcx, item), hir::Node::TraitItem(item) => check_trait_item(tcx, item),
hir::Node::ImplItem(item) => check_impl_item(tcx, item), hir::Node::ImplItem(item) => check_impl_item(tcx, item),
hir::Node::ForeignItem(item) => check_foreign_item(tcx, item), hir::Node::ForeignItem(item) => check_foreign_item(tcx, item),
hir::Node::OpaqueTy(_) => Ok(crate::check::check::check_item_type(tcx, def_id)), hir::Node::ConstBlock(_) | hir::Node::Expr(_) | hir::Node::OpaqueTy(_) => {
Ok(crate::check::check::check_item_type(tcx, def_id))
}
_ => unreachable!("{node:?}"), _ => unreachable!("{node:?}"),
}; };
@@ -229,7 +230,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
?item.owner_id, ?item.owner_id,
item.name = ? tcx.def_path_str(def_id) item.name = ? tcx.def_path_str(def_id)
); );
CollectItemTypesVisitor { tcx }.visit_item(item); crate::collect::lower_item(tcx, item.item_id());
crate::collect::reject_placeholder_type_signatures_in_item(tcx, item);
let res = match item.kind { let res = match item.kind {
// Right now we check that every default trait implementation // Right now we check that every default trait implementation
@@ -350,8 +352,6 @@ fn check_foreign_item<'tcx>(
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
let def_id = item.owner_id.def_id; let def_id = item.owner_id.def_id;
CollectItemTypesVisitor { tcx }.visit_foreign_item(item);
debug!( debug!(
?item.owner_id, ?item.owner_id,
item.name = ? tcx.def_path_str(def_id) item.name = ? tcx.def_path_str(def_id)
@@ -374,7 +374,7 @@ fn check_trait_item<'tcx>(
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
let def_id = trait_item.owner_id.def_id; let def_id = trait_item.owner_id.def_id;
CollectItemTypesVisitor { tcx }.visit_trait_item(trait_item); crate::collect::lower_trait_item(tcx, trait_item.trait_item_id());
let (method_sig, span) = match trait_item.kind { let (method_sig, span) = match trait_item.kind {
hir::TraitItemKind::Fn(ref sig, _) => (Some(sig), trait_item.span), hir::TraitItemKind::Fn(ref sig, _) => (Some(sig), trait_item.span),
@@ -939,7 +939,7 @@ fn check_impl_item<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
impl_item: &'tcx hir::ImplItem<'tcx>, impl_item: &'tcx hir::ImplItem<'tcx>,
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
CollectItemTypesVisitor { tcx }.visit_impl_item(impl_item); crate::collect::lower_impl_item(tcx, impl_item.impl_item_id());
let (method_sig, span) = match impl_item.kind { let (method_sig, span) = match impl_item.kind {
hir::ImplItemKind::Fn(ref sig, _) => (Some(sig), impl_item.span), hir::ImplItemKind::Fn(ref sig, _) => (Some(sig), impl_item.span),
@@ -2411,6 +2411,7 @@ fn check_type_wf(tcx: TyCtxt<'_>, (): ()) -> Result<(), ErrorGuaranteed> {
.and( .and(
items.par_foreign_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)), items.par_foreign_items(|item| tcx.ensure_ok().check_well_formed(item.owner_id.def_id)),
) )
.and(items.par_nested_bodies(|item| tcx.ensure_ok().check_well_formed(item)))
.and(items.par_opaques(|item| tcx.ensure_ok().check_well_formed(item))); .and(items.par_opaques(|item| tcx.ensure_ok().check_well_formed(item)));
super::entry::check_for_entry_fn(tcx); super::entry::check_for_entry_fn(tcx);

View File

@@ -28,11 +28,10 @@ use rustc_errors::{
}; };
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, InferKind, Visitor, VisitorExt, walk_generics}; use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_generics};
use rustc_hir::{self as hir, GenericParamKind, HirId, Node, PreciseCapturingArgKind}; use rustc_hir::{self as hir, GenericParamKind, HirId, Node, PreciseCapturingArgKind};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::{DynCompatibilityViolation, ObligationCause}; use rustc_infer::traits::{DynCompatibilityViolation, ObligationCause};
use rustc_middle::hir::nested_filter;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::util::{Discr, IntTypeExt}; use rustc_middle::ty::util::{Discr, IntTypeExt};
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypingMode, fold_regions}; use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypingMode, fold_regions};
@@ -148,10 +147,6 @@ impl<'v> Visitor<'v> for HirPlaceholderCollector {
} }
} }
pub(crate) struct CollectItemTypesVisitor<'tcx> {
pub tcx: TyCtxt<'tcx>,
}
/// If there are any placeholder types (`_`), emit an error explaining that this is not allowed /// If there are any placeholder types (`_`), emit an error explaining that this is not allowed
/// and suggest adding type parameters in the appropriate place, taking into consideration any and /// and suggest adding type parameters in the appropriate place, taking into consideration any and
/// all already existing generic type parameters to avoid suggesting a name that is already in use. /// all already existing generic type parameters to avoid suggesting a name that is already in use.
@@ -243,7 +238,7 @@ pub(crate) fn placeholder_type_error_diag<'cx, 'tcx>(
err err
} }
fn reject_placeholder_type_signatures_in_item<'tcx>( pub(super) fn reject_placeholder_type_signatures_in_item<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
item: &'tcx hir::Item<'tcx>, item: &'tcx hir::Item<'tcx>,
) { ) {
@@ -274,81 +269,6 @@ fn reject_placeholder_type_signatures_in_item<'tcx>(
); );
} }
impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
type NestedFilter = nested_filter::OnlyBodies;
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
self.tcx
}
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
lower_item(self.tcx, item.item_id());
reject_placeholder_type_signatures_in_item(self.tcx, item);
intravisit::walk_item(self, item);
}
fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
for param in generics.params {
match param.kind {
hir::GenericParamKind::Lifetime { .. } => {}
hir::GenericParamKind::Type { default: Some(_), .. } => {
self.tcx.ensure_ok().type_of(param.def_id);
}
hir::GenericParamKind::Type { .. } => {}
hir::GenericParamKind::Const { default, .. } => {
self.tcx.ensure_ok().type_of(param.def_id);
if let Some(default) = default {
// need to store default and type of default
self.tcx.ensure_ok().const_param_default(param.def_id);
if let hir::ConstArgKind::Anon(ac) = default.kind {
self.tcx.ensure_ok().type_of(ac.def_id);
}
}
}
}
}
intravisit::walk_generics(self, generics);
}
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
if let hir::ExprKind::Closure(closure) = expr.kind {
self.tcx.ensure_ok().generics_of(closure.def_id);
self.tcx.ensure_ok().codegen_fn_attrs(closure.def_id);
// We do not call `type_of` for closures here as that
// depends on typecheck and would therefore hide
// any further errors in case one typeck fails.
}
intravisit::walk_expr(self, expr);
}
/// Don't call `type_of` on opaque types, since that depends on type checking function bodies.
/// `check_item_type` ensures that it's called instead.
fn visit_opaque_ty(&mut self, opaque: &'tcx hir::OpaqueTy<'tcx>) {
let def_id = opaque.def_id;
self.tcx.ensure_ok().generics_of(def_id);
self.tcx.ensure_ok().predicates_of(def_id);
self.tcx.ensure_ok().explicit_item_bounds(def_id);
self.tcx.ensure_ok().explicit_item_self_bounds(def_id);
self.tcx.ensure_ok().item_bounds(def_id);
self.tcx.ensure_ok().item_self_bounds(def_id);
if self.tcx.is_conditionally_const(def_id) {
self.tcx.ensure_ok().explicit_implied_const_bounds(def_id);
self.tcx.ensure_ok().const_conditions(def_id);
}
intravisit::walk_opaque_ty(self, opaque);
}
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
lower_trait_item(self.tcx, trait_item.trait_item_id());
intravisit::walk_trait_item(self, trait_item);
}
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
lower_impl_item(self.tcx, impl_item.impl_item_id());
intravisit::walk_impl_item(self, impl_item);
}
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Utility types and common code for the above passes. // Utility types and common code for the above passes.
@@ -669,7 +589,7 @@ fn get_new_lifetime_name<'tcx>(
} }
#[instrument(level = "debug", skip_all)] #[instrument(level = "debug", skip_all)]
fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { pub(super) fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
let it = tcx.hir_item(item_id); let it = tcx.hir_item(item_id);
debug!(item = ?it.kind.ident(), id = %it.hir_id()); debug!(item = ?it.kind.ident(), id = %it.hir_id());
let def_id = item_id.owner_id.def_id; let def_id = item_id.owner_id.def_id;
@@ -790,7 +710,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
} }
} }
fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) { pub(crate) fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
let trait_item = tcx.hir_trait_item(trait_item_id); let trait_item = tcx.hir_trait_item(trait_item_id);
let def_id = trait_item_id.owner_id; let def_id = trait_item_id.owner_id;
tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
@@ -861,7 +781,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
tcx.ensure_ok().predicates_of(def_id); tcx.ensure_ok().predicates_of(def_id);
} }
fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { pub(super) fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
let def_id = impl_item_id.owner_id; let def_id = impl_item_id.owner_id;
tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().generics_of(def_id);
tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().type_of(def_id);

View File

@@ -71,6 +71,7 @@ impl ModuleItems {
self.opaques.iter().copied() self.opaques.iter().copied()
} }
/// Closures and inline consts
pub fn nested_bodies(&self) -> impl Iterator<Item = LocalDefId> { pub fn nested_bodies(&self) -> impl Iterator<Item = LocalDefId> {
self.nested_bodies.iter().copied() self.nested_bodies.iter().copied()
} }
@@ -79,6 +80,14 @@ impl ModuleItems {
self.owners().map(|id| id.def_id) self.owners().map(|id| id.def_id)
} }
/// Closures and inline consts
pub fn par_nested_bodies(
&self,
f: impl Fn(LocalDefId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,
) -> Result<(), ErrorGuaranteed> {
try_par_for_each_in(&self.nested_bodies[..], |&&id| f(id))
}
pub fn par_items( pub fn par_items(
&self, &self,
f: impl Fn(ItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync, f: impl Fn(ItemId) -> Result<(), ErrorGuaranteed> + DynSend + DynSync,

View File

@@ -1,14 +0,0 @@
//@ known-bug: #121429
#![feature(generic_const_exprs)]
struct FixedI8<const X: usize>;
const FRAC_LHS: usize = 0;
const FRAC_RHS: usize = 1;
pub trait True {}
impl<const N: usize = { const { 3 } }> PartialEq<FixedI8<FRAC_RHS>> for FixedI8<FRAC_LHS> where
If<{}>: True
{
}

View File

@@ -1,3 +1,11 @@
error: unconstrained opaque type
--> $DIR/issue-109299-1.rs:10:10
|
LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `X` must be used in combination with a concrete type within the same crate
error[E0220]: associated type `Cursor` not found for `Lexer<T>` in the current scope error[E0220]: associated type `Cursor` not found for `Lexer<T>` in the current scope
--> $DIR/issue-109299-1.rs:10:40 --> $DIR/issue-109299-1.rs:10:40
| |
@@ -23,14 +31,6 @@ LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor;
- `Lexer<i32>` - `Lexer<i32>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: unconstrained opaque type
--> $DIR/issue-109299-1.rs:10:10
|
LL | type X = impl for<T> Fn() -> Lexer<T>::Cursor;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `X` must be used in combination with a concrete type within the same crate
error: aborting due to 3 previous errors error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0220`. For more information about this error, try `rustc --explain E0220`.

View File

@@ -198,16 +198,6 @@ LL | fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> {
| | | |
| `Item` bound here first | `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:133:42
|
LL | fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> {
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:139:42 --> $DIR/duplicate.rs:139:42
| |
@@ -216,24 +206,6 @@ LL | fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> {
| | | |
| `Item` bound here first | `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:139:42
|
LL | fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> {
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:145:45
|
LL | fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> {
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:145:45 --> $DIR/duplicate.rs:145:45
| |
@@ -241,8 +213,6 @@ LL | fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> {
| ------------- ^^^^^^^^^^^^^ re-bound here | ------------- ^^^^^^^^^^^^^ re-bound here
| | | |
| `Item` bound here first | `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:151:40 --> $DIR/duplicate.rs:151:40
@@ -340,60 +310,6 @@ LL | type ETAI3<T: Iterator<Item: 'static, Item: 'static>> = impl Copy;
| | | |
| `Item` bound here first | `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:189:40
|
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:189:40
|
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:193:40
|
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:193:40
|
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:197:43
|
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:197:43
|
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:202:36 --> $DIR/duplicate.rs:202:36
| |
@@ -664,6 +580,16 @@ LL | type A: Iterator<Item: 'static, Item: 'static>;
| |
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:133:42
|
LL | fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> {
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0282]: type annotations needed error[E0282]: type annotations needed
--> $DIR/duplicate.rs:136:5 --> $DIR/duplicate.rs:136:5
| |
@@ -675,6 +601,16 @@ help: consider specifying the generic argument
LL | iter::empty::<T>() LL | iter::empty::<T>()
| +++++ | +++++
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:139:42
|
LL | fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> {
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0282]: type annotations needed error[E0282]: type annotations needed
--> $DIR/duplicate.rs:142:5 --> $DIR/duplicate.rs:142:5
| |
@@ -686,6 +622,16 @@ help: consider specifying the generic argument
LL | iter::empty::<T>() LL | iter::empty::<T>()
| +++++ | +++++
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:145:45
|
LL | fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> {
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0282]: type annotations needed error[E0282]: type annotations needed
--> $DIR/duplicate.rs:148:5 --> $DIR/duplicate.rs:148:5
| |
@@ -729,6 +675,24 @@ LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
| |
= note: `ETAI4` must be used in combination with a concrete type within the same crate = note: `ETAI4` must be used in combination with a concrete type within the same crate
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:189:40
|
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:189:40
|
LL | type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: unconstrained opaque type error: unconstrained opaque type
--> $DIR/duplicate.rs:193:14 --> $DIR/duplicate.rs:193:14
| |
@@ -737,6 +701,24 @@ LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
| |
= note: `ETAI5` must be used in combination with a concrete type within the same crate = note: `ETAI5` must be used in combination with a concrete type within the same crate
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:193:40
|
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:193:40
|
LL | type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
| ---------- ^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: unconstrained opaque type error: unconstrained opaque type
--> $DIR/duplicate.rs:197:14 --> $DIR/duplicate.rs:197:14
| |
@@ -745,6 +727,24 @@ LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
| |
= note: `ETAI6` must be used in combination with a concrete type within the same crate = note: `ETAI6` must be used in combination with a concrete type within the same crate
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:197:43
|
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate.rs:197:43
|
LL | type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
| ------------- ^^^^^^^^^^^^^ re-bound here
| |
| `Item` bound here first
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: aborting due to 87 previous errors error: aborting due to 87 previous errors
Some errors have detailed explanations: E0282, E0719. Some errors have detailed explanations: E0282, E0719.

View File

@@ -8,6 +8,7 @@ type PairCoupledTypes: Trait<
}], }],
> = impl Trait< > = impl Trait<
//~^ ERROR: cannot find trait `Trait` in this scope //~^ ERROR: cannot find trait `Trait` in this scope
//~| ERROR: unconstrained opaque type
[u32; { [u32; {
static FOO: usize; //~ ERROR: free static item without body static FOO: usize; //~ ERROR: free static item without body
}], }],

View File

@@ -20,7 +20,7 @@ LL | static FOO: usize;
| help: provide a definition for the static: `= <expr>;` | help: provide a definition for the static: `= <expr>;`
error: free static item without body error: free static item without body
--> $DIR/issue-83479.rs:12:9 --> $DIR/issue-83479.rs:13:9
| |
LL | static FOO: usize; LL | static FOO: usize;
| ^^^^^^^^^^^^^^^^^- | ^^^^^^^^^^^^^^^^^-
@@ -39,6 +39,21 @@ error[E0405]: cannot find trait `Trait` in this scope
LL | > = impl Trait< LL | > = impl Trait<
| ^^^^^ not found in this scope | ^^^^^ not found in this scope
error: aborting due to 5 previous errors error: unconstrained opaque type
--> $DIR/issue-83479.rs:9:5
|
LL | > = impl Trait<
| _____^
LL | |
LL | |
LL | | [u32; {
LL | | static FOO: usize;
LL | | }],
LL | | >;
| |_^
|
= note: `PairCoupledTypes` must be used in combination with a concrete type within the same crate
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0405`. For more information about this error, try `rustc --explain E0405`.

View File

@@ -48,23 +48,6 @@ help: replace the generic bound with the associated type
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> { LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> {
| +++++++ | +++++++
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:19:46
|
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> {
| ^^^^^ expected 1 generic argument
|
note: trait defined here, with 1 generic parameter: `T`
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11
|
LL | pub trait Trait<T> {
| ^^^^^ -
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: replace the generic bound with the associated type
|
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> {
| +++++++
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:26:18 --> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:26:18
| |
@@ -127,6 +110,23 @@ note: struct defined here, with 1 generic parameter: `T`
LL | struct Struct<T: Trait<u32, String>> { LL | struct Struct<T: Trait<u32, String>> {
| ^^^^^^ - | ^^^^^^ -
error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:19:46
|
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), i32> {
| ^^^^^ expected 1 generic argument
|
note: trait defined here, with 1 generic parameter: `T`
--> $DIR/116464-invalid-assoc-type-suggestion-in-trait-impl.rs:5:11
|
LL | pub trait Trait<T> {
| ^^^^^ -
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: replace the generic bound with the associated type
|
LL | fn func<T: Trait<u32, String>>(t: T) -> impl Trait<(), Assoc = i32> {
| +++++++
error: aborting due to 9 previous errors error: aborting due to 9 previous errors
Some errors have detailed explanations: E0107, E0207. Some errors have detailed explanations: E0107, E0207.

View File

@@ -32,35 +32,6 @@ LL | x: impl ~const PartialEq + ~const Destruct,
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]` note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL --> $SRC_DIR/core/src/cmp.rs:LL:COL
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:17:11
|
LL | ) -> impl ~const PartialEq + ~const Destruct {
| ^^^^^^ can't be applied to `PartialEq`
|
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:17:11
|
LL | ) -> impl ~const PartialEq + ~const Destruct {
| ^^^^^^ can't be applied to `PartialEq`
|
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:17:11
|
LL | ) -> impl ~const PartialEq + ~const Destruct {
| ^^^^^^ can't be applied to `PartialEq`
|
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `~const` can only be applied to `#[const_trait]` traits error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:16:13 --> $DIR/const-impl-trait.rs:16:13
| |
@@ -71,6 +42,25 @@ note: `PartialEq` can't be used with `~const` because it isn't annotated with `#
--> $SRC_DIR/core/src/cmp.rs:LL:COL --> $SRC_DIR/core/src/cmp.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:17:11
|
LL | ) -> impl ~const PartialEq + ~const Destruct {
| ^^^^^^ can't be applied to `PartialEq`
|
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:17:11
|
LL | ) -> impl ~const PartialEq + ~const Destruct {
| ^^^^^^ can't be applied to `PartialEq`
|
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `~const` can only be applied to `#[const_trait]` traits error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:23:22 --> $DIR/const-impl-trait.rs:23:22
| |
@@ -89,6 +79,16 @@ LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy {
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]` note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL --> $SRC_DIR/core/src/cmp.rs:LL:COL
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:17:11
|
LL | ) -> impl ~const PartialEq + ~const Destruct {
| ^^^^^^ can't be applied to `PartialEq`
|
note: `PartialEq` can't be used with `~const` because it isn't annotated with `#[const_trait]`
--> $SRC_DIR/core/src/cmp.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `~const` can only be applied to `#[const_trait]` traits error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-impl-trait.rs:27:22 --> $DIR/const-impl-trait.rs:27:22
| |