Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue compilation even if inherent impl checks fail #121113

Merged
merged 1 commit into from
Feb 15, 2024
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
5 changes: 3 additions & 2 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
let _ = tcx.ensure().coherent_trait(trait_def_id);
}
// these queries are executed for side-effects (error reporting):
res.and(tcx.ensure().crate_inherent_impls(()))
.and(tcx.ensure().crate_inherent_impls_overlap_check(()))
let _ = tcx.ensure().crate_inherent_impls(());
let _ = tcx.ensure().crate_inherent_impls_overlap_check(());
res
})?;

if tcx.features().rustc_attrs {
Expand Down
1 change: 1 addition & 0 deletions tests/ui/const-generics/wrong-normalization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ pub struct I8<const F: i8>;

impl <I8<{i8::MIN}> as Identity>::Identity {
//~^ ERROR no nominal type found for inherent implementation
//~| ERROR no associated item named `MIN` found for type `i8`
pub fn foo(&self) {}
}
16 changes: 14 additions & 2 deletions tests/ui/const-generics/wrong-normalization.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ LL | impl <I8<{i8::MIN}> as Identity>::Identity {
|
= note: either implement a trait on it or create a newtype to wrap it instead

error: aborting due to 1 previous error
error[E0599]: no associated item named `MIN` found for type `i8` in the current scope
--> $DIR/wrong-normalization.rs:16:15
|
LL | impl <I8<{i8::MIN}> as Identity>::Identity {
| ^^^ associated item not found in `i8`
|
help: you are looking for the module in `std`, not the primitive type
|
LL | impl <I8<{std::i8::MIN}> as Identity>::Identity {
| +++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0118`.
Some errors have detailed explanations: E0118, E0599.
For more information about an error, try `rustc --explain E0118`.
6 changes: 6 additions & 0 deletions tests/ui/impl-trait/where-allowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }

// Allowed
fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() }
//~^ ERROR: type annotations needed

// Disallowed
fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() }
Expand All @@ -58,9 +59,11 @@ fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() }
fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() }
//~^ ERROR `impl Trait` is not allowed in the parameters of `Fn` trait bounds
//~| ERROR nested `impl Trait` is not allowed
//~| ERROR: type annotations needed

// Allowed
fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() }
//~^ ERROR: type annotations needed

// Disallowed
fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() }
Expand All @@ -77,6 +80,7 @@ fn in_impl_Trait_in_parameters(_: impl Iterator<Item = impl Iterator>) { panic!(
// Allowed
fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> {
vec![vec![0; 10], vec![12; 7], vec![8; 3]]
//~^ ERROR: no function or associated item named `into_vec` found for slice `[_]`
}

// Disallowed
Expand Down Expand Up @@ -118,11 +122,13 @@ trait DummyTrait {
impl DummyTrait for () {
type Out = impl Debug;
//~^ ERROR `impl Trait` in associated types is unstable
//~| ERROR unconstrained opaque type

fn in_trait_impl_parameter(_: impl Debug) { }
// Allowed

fn in_trait_impl_return() -> impl Debug { () }
//~^ ERROR `in_trait_impl_return` has an incompatible type for trait
// Allowed
}

Expand Down
Loading
Loading