Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_middle::ty::{
};
use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
use rustc_span::kw;
use rustc_trait_selection::traits;
use smallvec::SmallVec;
use tracing::{debug, instrument};

Expand Down Expand Up @@ -535,9 +536,26 @@ pub(crate) fn check_generic_arg_count(
.map(|param| param.name)
.collect();
if constraint_names == param_names {
let has_assoc_ty_with_same_name =
if let DefKind::Trait = cx.tcx().def_kind(def_id) {
gen_args.constraints.iter().any(|constraint| {
traits::supertrait_def_ids(cx.tcx(), def_id).any(|trait_did| {
cx.probe_trait_that_defines_assoc_item(
trait_did,
ty::AssocTag::Type,
constraint.ident,
)
})
})
} else {
false
};
// We set this to true and delay emitting `WrongNumberOfGenericArgs`
// to provide a succinct error for cases like issue #113073
all_params_are_binded = true;
// to provide a succinct error for cases like issue #113073,
// but only if when we don't have any assoc type with the same name with a
// generic arg. Otherwise it will cause an ICE due to a delayed error because we
// don't have any error other than `WrongNumberOfGenericArgs`.
all_params_are_binded = !has_assoc_ty_with_same_name;
};
}

Expand Down
11 changes: 7 additions & 4 deletions tests/run-make/dump-ice-to-disk/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
//! # Test history
//!
//! The previous rmake.rs iteration of this test was flaky for unknown reason on
//! `i686-pc-windows-gnu` *specifically*, so assertion failures in this test was made extremely
//! verbose to help diagnose why the ICE messages was different. It appears that backtraces on
//! `i686-pc-windows-gnu` specifically are quite unpredictable in how many backtrace frames are
//! involved.
//! `i686-pc-windows-gnu`, so assertion failures in this test was made extremely verbose to help
//! diagnose why the ICE messages was different. It appears that backtraces on `i686-pc-windows-gnu`
//! specifically are quite unpredictable in how many backtrace frames are involved.
//!
//! Disabled on `i686-pc-windows-msvc` as well, because sometimes the middle portion of the ICE
//! backtrace becomes `<unknown>`.

//@ ignore-cross-compile (exercising ICE dump on host)
//@ ignore-i686-pc-windows-gnu (unwind mechanism produces unpredictable backtraces)
//@ ignore-i686-pc-windows-msvc (sometimes partial backtrace becomes `<unknown>`)

use std::cell::OnceCell;
use std::path::{Path, PathBuf};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// A regression test for https://github.com/rust-lang/rust/issues/148121

pub trait Super<X> {
type X;
}

pub trait Zelf<X>: Super<X> {}

pub trait A {}

impl A for dyn Super<X = ()> {}
//~^ ERROR: trait takes 1 generic argument but 0 generic arguments were supplied

impl A for dyn Zelf<X = ()> {}
//~^ ERROR: trait takes 1 generic argument but 0 generic arguments were supplied

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied
--> $DIR/assoc-type-bounds-with-the-same-name-with-lacking-generic-arg-148121.rs:11:16
|
LL | impl A for dyn Super<X = ()> {}
| ^^^^^ expected 1 generic argument
|
note: trait defined here, with 1 generic parameter: `X`
--> $DIR/assoc-type-bounds-with-the-same-name-with-lacking-generic-arg-148121.rs:3:11
|
LL | pub trait Super<X> {
| ^^^^^ -
help: add missing generic argument
|
LL | impl A for dyn Super<X, X = ()> {}
| ++

error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied
--> $DIR/assoc-type-bounds-with-the-same-name-with-lacking-generic-arg-148121.rs:14:16
|
LL | impl A for dyn Zelf<X = ()> {}
| ^^^^ expected 1 generic argument
|
note: trait defined here, with 1 generic parameter: `X`
--> $DIR/assoc-type-bounds-with-the-same-name-with-lacking-generic-arg-148121.rs:7:11
|
LL | pub trait Zelf<X>: Super<X> {}
| ^^^^ -
help: add missing generic argument
|
LL | impl A for dyn Zelf<X, X = ()> {}
| ++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0107`.
Loading