Skip to content

Commit

Permalink
Continue compilation after check_mod_type_wf errors
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 12, 2024
1 parent aebf451 commit 6c70bf6
Show file tree
Hide file tree
Showing 212 changed files with 2,715 additions and 284 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
}

tcx.sess.time("wf_checking", || {
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_type_wf(module))
})?;
tcx.hir().par_for_each_module(|module| {
let _ = tcx.ensure().check_mod_type_wf(module);
})
});

if tcx.features().rustc_attrs {
collect::test_opaque_hidden_types(tcx)?;
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
.report_mismatched_types(&cause, method_self_ty, self_ty, terr)
.emit();
} else {
span_bug!(
self.span,
"{} was a subtype of {} but now is not?",
self_ty,
method_self_ty
);
error!("{self_ty} was a subtype of {method_self_ty} but now is not?");
// This must already have errored elsewhere.
self.dcx().has_errors().unwrap();
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::thir::cx::region::Scope;
use crate::thir::cx::Cx;
use crate::thir::util::UserAnnotatedTyHelpers;
use itertools::Itertools;
use rustc_ast::LitKind;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
Expand All @@ -20,7 +21,8 @@ use rustc_middle::ty::GenericArgs;
use rustc_middle::ty::{
self, AdtKind, InlineConstArgs, InlineConstArgsParts, ScalarInt, Ty, UpvarArgs, UserType,
};
use rustc_span::{sym, Span};
use rustc_span::source_map::Spanned;
use rustc_span::{sym, Span, DUMMY_SP};
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};

impl<'tcx> Cx<'tcx> {
Expand Down Expand Up @@ -884,7 +886,14 @@ impl<'tcx> Cx<'tcx> {
Res::Def(DefKind::ConstParam, def_id) => {
let hir_id = self.tcx.local_def_id_to_hir_id(def_id.expect_local());
let generics = self.tcx.generics_of(hir_id.owner);
let index = generics.param_def_id_to_index[&def_id];
let Some(&index) = generics.param_def_id_to_index.get(&def_id) else {
self.tcx.dcx().has_errors().unwrap();
// We already errored about a late bound const
return ExprKind::Literal {
lit: &Spanned { span: DUMMY_SP, node: LitKind::Err },
neg: false,
};
};
let name = self.tcx.hir().name(hir_id);
let param = ty::ParamConst::new(index, name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3115,10 +3115,11 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
obligation.param_env,
trait_ref.args.const_at(3),
) else {
span_bug!(
self.dcx().span_delayed_bug(
span,
"Unable to construct rustc_transmute::Assume where it was previously possible"
"Unable to construct rustc_transmute::Assume where it was previously possible",
);
return GetSafeTransmuteErrorAndReason::Silent;
};

match rustc_transmute::TransmuteTypeEnv::new(self.infcx).is_transmutable(
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/abi/issues/issue-22565-rust-call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ impl Tr for Foo {

fn main() {
b(10);
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
Foo::bar();
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
<Foo as Tr>::a();
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
<Foo as Tr>::b();
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
}
26 changes: 25 additions & 1 deletion tests/ui/abi/issues/issue-22565-rust-call.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ error: functions with the "rust-call" ABI must take a single non-self tuple argu
LL | extern "rust-call" fn b() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 5 previous errors
error[E0277]: functions with the "rust-call" ABI must take a single non-self tuple argument
--> $DIR/issue-22565-rust-call.rs:27:7
|
LL | b(10);
| ^^ the trait `Tuple` is not implemented for `i32`

error: functions with the "rust-call" ABI must take a single non-self tuple argument
--> $DIR/issue-22565-rust-call.rs:29:5
|
LL | Foo::bar();
| ^^^^^^^^^^

error: functions with the "rust-call" ABI must take a single non-self tuple argument
--> $DIR/issue-22565-rust-call.rs:31:5
|
LL | <Foo as Tr>::a();
| ^^^^^^^^^^^^^^^^

error: functions with the "rust-call" ABI must take a single non-self tuple argument
--> $DIR/issue-22565-rust-call.rs:33:5
|
LL | <Foo as Tr>::b();
| ^^^^^^^^^^^^^^^^

error: aborting due to 9 previous errors

For more information about this error, try `rustc --explain E0277`.
1 change: 1 addition & 0 deletions tests/ui/associated-consts/associated-const-in-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ trait Trait {
impl dyn Trait {
//~^ ERROR the trait `Trait` cannot be made into an object [E0038]
const fn n() -> usize { Self::N }
//~^ ERROR the trait `Trait` cannot be made into an object [E0038]
}

fn main() {}
17 changes: 16 additions & 1 deletion tests/ui/associated-consts/associated-const-in-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ LL | const N: usize;
| ^ ...because it contains this associated `const`
= help: consider moving `N` to another trait

error: aborting due to 1 previous error
error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/associated-const-in-trait.rs:9:29
|
LL | const fn n() -> usize { Self::N }
| ^^^^ `Trait` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/associated-const-in-trait.rs:4:11
|
LL | trait Trait {
| ----- this trait cannot be made into an object...
LL | const N: usize;
| ^ ...because it contains this associated `const`
= help: consider moving `N` to another trait

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0038`.
5 changes: 5 additions & 0 deletions tests/ui/associated-consts/issue-105330.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ impl TraitWAssocConst for impl Demo { //~ ERROR E0404

fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658
foo::<Demo>()();
//~^ ERROR is not satisfied
//~| ERROR type mismatch
//~| ERROR expected function, found `()`
}

fn main<A: TraitWAssocConst<A=32>>() {
//~^ ERROR E0658
//~| ERROR E0131
foo::<Demo>();
//~^ ERROR type mismatch
//~| ERROR is not satisfied
}
72 changes: 68 additions & 4 deletions tests/ui/associated-consts/issue-105330.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LL | fn foo<A: TraitWAssocConst<A=32>>() {
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: associated const equality is incomplete
--> $DIR/issue-105330.rs:15:29
--> $DIR/issue-105330.rs:18:29
|
LL | fn main<A: TraitWAssocConst<A=32>>() {
| ^^^^
Expand All @@ -44,12 +44,76 @@ LL | impl TraitWAssocConst for impl Demo {
= note: `impl Trait` is only allowed in arguments and return types of functions and methods

error[E0131]: `main` function is not allowed to have generic parameters
--> $DIR/issue-105330.rs:15:8
--> $DIR/issue-105330.rs:18:8
|
LL | fn main<A: TraitWAssocConst<A=32>>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` cannot have generic parameters

error: aborting due to 6 previous errors
error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
--> $DIR/issue-105330.rs:12:11
|
LL | foo::<Demo>()();
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
|
= help: the trait `TraitWAssocConst` is implemented for `{type error}`
note: required by a bound in `foo`
--> $DIR/issue-105330.rs:11:11
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error[E0271]: type mismatch resolving `<Demo as TraitWAssocConst>::A == 32`
--> $DIR/issue-105330.rs:12:11
|
LL | foo::<Demo>()();
| ^^^^ expected `32`, found `<Demo as TraitWAssocConst>::A`
|
= note: expected constant `32`
found constant `<Demo as TraitWAssocConst>::A`
note: required by a bound in `foo`
--> $DIR/issue-105330.rs:11:28
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
| ^^^^ required by this bound in `foo`

error[E0618]: expected function, found `()`
--> $DIR/issue-105330.rs:12:5
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
| ----------------------------------- `foo::<Demo>` defined here returns `()`
LL | foo::<Demo>()();
| ^^^^^^^^^^^^^--
| |
| call expression requires function

error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
--> $DIR/issue-105330.rs:21:11
|
LL | foo::<Demo>();
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
|
= help: the trait `TraitWAssocConst` is implemented for `{type error}`
note: required by a bound in `foo`
--> $DIR/issue-105330.rs:11:11
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`

error[E0271]: type mismatch resolving `<Demo as TraitWAssocConst>::A == 32`
--> $DIR/issue-105330.rs:21:11
|
LL | foo::<Demo>();
| ^^^^ expected `32`, found `<Demo as TraitWAssocConst>::A`
|
= note: expected constant `32`
found constant `<Demo as TraitWAssocConst>::A`
note: required by a bound in `foo`
--> $DIR/issue-105330.rs:11:28
|
LL | fn foo<A: TraitWAssocConst<A=32>>() {
| ^^^^ required by this bound in `foo`

error: aborting due to 11 previous errors

Some errors have detailed explanations: E0131, E0404, E0562, E0658.
Some errors have detailed explanations: E0131, E0271, E0277, E0404, E0562, E0618, E0658.
For more information about an error, try `rustc --explain E0131`.
1 change: 1 addition & 0 deletions tests/ui/associated-inherent-types/issue-109299.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ impl Lexer<'d> { //~ ERROR use of undeclared lifetime name `'d`
}

fn test(_: Lexer::Cursor) {}
//~^ ERROR: lifetime may not live long enough

fn main() {}
11 changes: 10 additions & 1 deletion tests/ui/associated-inherent-types/issue-109299.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ LL | impl Lexer<'d> {
| |
| help: consider introducing lifetime `'d` here: `<'d>`

error: aborting due to 1 previous error
error: lifetime may not live long enough
--> $DIR/issue-109299.rs:10:1
|
LL | fn test(_: Lexer::Cursor) {}
| ^^^^^^^^-^^^^^^^^^^^^^^^^
| | |
| | has type `Lexer<'1>::Cursor`
| requires that `'1` must outlive `'static`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0261`.
2 changes: 2 additions & 0 deletions tests/ui/associated-inherent-types/issue-109789.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ impl Other for u32 {}
fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
//~^ ERROR mismatched types
//~| ERROR mismatched types
//~| ERROR higher-ranked subtype error
//~| ERROR higher-ranked subtype error

fn main() {}
16 changes: 15 additions & 1 deletion tests/ui/associated-inherent-types/issue-109789.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ LL | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
found struct `Foo<for<'a> fn(&'a ())>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors
error: higher-ranked subtype error
--> $DIR/issue-109789.rs:18:1
|
LL | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: higher-ranked subtype error
--> $DIR/issue-109789.rs:18:1
|
LL | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0308`.
1 change: 1 addition & 0 deletions tests/ui/associated-inherent-types/regionck-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ impl Lexer<'static> {
}

fn test(_: Lexer::Cursor) {} //~ ERROR mismatched types
//~^ ERROR: lifetime may not live long enough

fn main() {}
11 changes: 10 additions & 1 deletion tests/ui/associated-inherent-types/regionck-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ LL | fn test(_: Lexer::Cursor) {}
| ^^^^^
= note: ...does not necessarily outlive the static lifetime

error: aborting due to 1 previous error
error: lifetime may not live long enough
--> $DIR/regionck-2.rs:12:1
|
LL | fn test(_: Lexer::Cursor) {}
| ^^^^^^^^-^^^^^^^^^^^^^^^^
| | |
| | has type `Lexer<'1>::Cursor`
| requires that `'1` must outlive `'static`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ trait Get {
}

trait Other {
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized, Self: Get, Self: Get {}
//~^ ERROR the trait bound `Self: Get` is not satisfied
//~| ERROR the trait bound `Self: Get` is not satisfied
}

fn main() {
}
fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ trait Get {
}

trait Other {
fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized {}
//~^ ERROR the trait bound `Self: Get` is not satisfied
//~| ERROR the trait bound `Self: Get` is not satisfied
}

fn main() {
}
fn main() {}
23 changes: 17 additions & 6 deletions tests/ui/associated-types/associated-types-for-unimpl-trait.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
error[E0277]: the trait bound `Self: Get` is not satisfied
--> $DIR/associated-types-for-unimpl-trait.rs:11:40
--> $DIR/associated-types-for-unimpl-trait.rs:11:41
|
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
| ^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized {}
| ^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
|
help: consider further restricting `Self`
|
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
| +++++++++++++++
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized, Self: Get {}
| +++++++++++

error: aborting due to 1 previous error
error[E0277]: the trait bound `Self: Get` is not satisfied
--> $DIR/associated-types-for-unimpl-trait.rs:11:81
|
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized {}
| ^^ the trait `Get` is not implemented for `Self`
|
help: consider further restricting `Self`
|
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized, Self: Get {}
| +++++++++++

error: aborting due to 2 previous errors

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

0 comments on commit 6c70bf6

Please sign in to comment.