Skip to content

Commit ee9c7c9

Browse files
committed
Auto merge of #120847 - oli-obk:track_errors9, r=compiler-errors
Continue compilation after check_mod_type_wf errors The ICEs fixed here were probably reachable through const eval gymnastics before, but now they are easily reachable without that, too. The new errors are often bugfixes, where useful errors were missing, because they were reported after the early abort. In other cases sometimes they are just duplication of already emitted errors, which won't be user-visible due to deduplication. fixes #120860
2 parents 502ce82 + 25806f8 commit ee9c7c9

File tree

215 files changed

+2723
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+2723
-293
lines changed

compiler/rustc_hir_analysis/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,10 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
187187
}
188188

189189
tcx.sess.time("wf_checking", || {
190-
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_type_wf(module))
191-
})?;
190+
tcx.hir().par_for_each_module(|module| {
191+
let _ = tcx.ensure().check_mod_type_wf(module);
192+
})
193+
});
192194

193195
if tcx.features().rustc_attrs {
194196
collect::test_opaque_hidden_types(tcx)?;

compiler/rustc_hir_typeck/src/method/confirm.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -518,12 +518,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
518518
.report_mismatched_types(&cause, method_self_ty, self_ty, terr)
519519
.emit();
520520
} else {
521-
span_bug!(
522-
self.span,
523-
"{} was a subtype of {} but now is not?",
524-
self_ty,
525-
method_self_ty
526-
);
521+
error!("{self_ty} was a subtype of {method_self_ty} but now is not?");
522+
// This must already have errored elsewhere.
523+
self.dcx().has_errors().unwrap();
527524
}
528525
}
529526
}

compiler/rustc_mir_build/src/thir/cx/expr.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::thir::cx::region::Scope;
33
use crate::thir::cx::Cx;
44
use crate::thir::util::UserAnnotatedTyHelpers;
55
use itertools::Itertools;
6+
use rustc_ast::LitKind;
67
use rustc_data_structures::stack::ensure_sufficient_stack;
78
use rustc_hir as hir;
89
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
@@ -20,7 +21,8 @@ use rustc_middle::ty::GenericArgs;
2021
use rustc_middle::ty::{
2122
self, AdtKind, InlineConstArgs, InlineConstArgsParts, ScalarInt, Ty, UpvarArgs, UserType,
2223
};
23-
use rustc_span::{sym, Span};
24+
use rustc_span::source_map::Spanned;
25+
use rustc_span::{sym, Span, DUMMY_SP};
2426
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
2527

2628
impl<'tcx> Cx<'tcx> {
@@ -894,7 +896,14 @@ impl<'tcx> Cx<'tcx> {
894896
Res::Def(DefKind::ConstParam, def_id) => {
895897
let hir_id = self.tcx.local_def_id_to_hir_id(def_id.expect_local());
896898
let generics = self.tcx.generics_of(hir_id.owner);
897-
let index = generics.param_def_id_to_index[&def_id];
899+
let Some(&index) = generics.param_def_id_to_index.get(&def_id) else {
900+
self.tcx.dcx().has_errors().unwrap();
901+
// We already errored about a late bound const
902+
return ExprKind::Literal {
903+
lit: &Spanned { span: DUMMY_SP, node: LitKind::Err },
904+
neg: false,
905+
};
906+
};
898907
let name = self.tcx.hir().name(hir_id);
899908
let param = ty::ParamConst::new(index, name);
900909

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3116,10 +3116,11 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
31163116
obligation.param_env,
31173117
trait_ref.args.const_at(3),
31183118
) else {
3119-
span_bug!(
3119+
self.dcx().span_delayed_bug(
31203120
span,
3121-
"Unable to construct rustc_transmute::Assume where it was previously possible"
3121+
"Unable to construct rustc_transmute::Assume where it was previously possible",
31223122
);
3123+
return GetSafeTransmuteErrorAndReason::Silent;
31233124
};
31243125

31253126
match rustc_transmute::TransmuteTypeEnv::new(self.infcx).is_transmutable(

tests/ui/abi/issues/issue-22565-rust-call.rs

+4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ impl Tr for Foo {
2525

2626
fn main() {
2727
b(10);
28+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
2829
Foo::bar();
30+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
2931
<Foo as Tr>::a();
32+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
3033
<Foo as Tr>::b();
34+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
3135
}

tests/ui/abi/issues/issue-22565-rust-call.stderr

+25-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ error: functions with the "rust-call" ABI must take a single non-self tuple argu
2828
LL | extern "rust-call" fn b() {}
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3030

31-
error: aborting due to 5 previous errors
31+
error[E0277]: functions with the "rust-call" ABI must take a single non-self tuple argument
32+
--> $DIR/issue-22565-rust-call.rs:27:7
33+
|
34+
LL | b(10);
35+
| ^^ the trait `Tuple` is not implemented for `i32`
36+
37+
error: functions with the "rust-call" ABI must take a single non-self tuple argument
38+
--> $DIR/issue-22565-rust-call.rs:29:5
39+
|
40+
LL | Foo::bar();
41+
| ^^^^^^^^^^
42+
43+
error: functions with the "rust-call" ABI must take a single non-self tuple argument
44+
--> $DIR/issue-22565-rust-call.rs:31:5
45+
|
46+
LL | <Foo as Tr>::a();
47+
| ^^^^^^^^^^^^^^^^
48+
49+
error: functions with the "rust-call" ABI must take a single non-self tuple argument
50+
--> $DIR/issue-22565-rust-call.rs:33:5
51+
|
52+
LL | <Foo as Tr>::b();
53+
| ^^^^^^^^^^^^^^^^
54+
55+
error: aborting due to 9 previous errors
3256

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

tests/ui/associated-consts/associated-const-in-trait.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ trait Trait {
77
impl dyn Trait {
88
//~^ ERROR the trait `Trait` cannot be made into an object [E0038]
99
const fn n() -> usize { Self::N }
10+
//~^ ERROR the trait `Trait` cannot be made into an object [E0038]
1011
}
1112

1213
fn main() {}

tests/ui/associated-consts/associated-const-in-trait.stderr

+16-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ LL | const N: usize;
1313
| ^ ...because it contains this associated `const`
1414
= help: consider moving `N` to another trait
1515

16-
error: aborting due to 1 previous error
16+
error[E0038]: the trait `Trait` cannot be made into an object
17+
--> $DIR/associated-const-in-trait.rs:9:29
18+
|
19+
LL | const fn n() -> usize { Self::N }
20+
| ^^^^ `Trait` cannot be made into an object
21+
|
22+
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>
23+
--> $DIR/associated-const-in-trait.rs:4:11
24+
|
25+
LL | trait Trait {
26+
| ----- this trait cannot be made into an object...
27+
LL | const N: usize;
28+
| ^ ...because it contains this associated `const`
29+
= help: consider moving `N` to another trait
30+
31+
error: aborting due to 2 previous errors
1732

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

tests/ui/associated-consts/issue-105330.rs

+5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ impl TraitWAssocConst for impl Demo { //~ ERROR E0404
1010

1111
fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658
1212
foo::<Demo>()();
13+
//~^ ERROR is not satisfied
14+
//~| ERROR type mismatch
15+
//~| ERROR expected function, found `()`
1316
}
1417

1518
fn main<A: TraitWAssocConst<A=32>>() {
1619
//~^ ERROR E0658
1720
//~| ERROR E0131
1821
foo::<Demo>();
22+
//~^ ERROR type mismatch
23+
//~| ERROR is not satisfied
1924
}

tests/ui/associated-consts/issue-105330.stderr

+68-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ LL | fn foo<A: TraitWAssocConst<A=32>>() {
2626
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2727

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

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

52-
error: aborting due to 6 previous errors
52+
error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
53+
--> $DIR/issue-105330.rs:12:11
54+
|
55+
LL | foo::<Demo>()();
56+
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
57+
|
58+
= help: the trait `TraitWAssocConst` is implemented for `{type error}`
59+
note: required by a bound in `foo`
60+
--> $DIR/issue-105330.rs:11:11
61+
|
62+
LL | fn foo<A: TraitWAssocConst<A=32>>() {
63+
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`
64+
65+
error[E0271]: type mismatch resolving `<Demo as TraitWAssocConst>::A == 32`
66+
--> $DIR/issue-105330.rs:12:11
67+
|
68+
LL | foo::<Demo>()();
69+
| ^^^^ expected `32`, found `<Demo as TraitWAssocConst>::A`
70+
|
71+
= note: expected constant `32`
72+
found constant `<Demo as TraitWAssocConst>::A`
73+
note: required by a bound in `foo`
74+
--> $DIR/issue-105330.rs:11:28
75+
|
76+
LL | fn foo<A: TraitWAssocConst<A=32>>() {
77+
| ^^^^ required by this bound in `foo`
78+
79+
error[E0618]: expected function, found `()`
80+
--> $DIR/issue-105330.rs:12:5
81+
|
82+
LL | fn foo<A: TraitWAssocConst<A=32>>() {
83+
| ----------------------------------- `foo::<Demo>` defined here returns `()`
84+
LL | foo::<Demo>()();
85+
| ^^^^^^^^^^^^^--
86+
| |
87+
| call expression requires function
88+
89+
error[E0277]: the trait bound `Demo: TraitWAssocConst` is not satisfied
90+
--> $DIR/issue-105330.rs:21:11
91+
|
92+
LL | foo::<Demo>();
93+
| ^^^^ the trait `TraitWAssocConst` is not implemented for `Demo`
94+
|
95+
= help: the trait `TraitWAssocConst` is implemented for `{type error}`
96+
note: required by a bound in `foo`
97+
--> $DIR/issue-105330.rs:11:11
98+
|
99+
LL | fn foo<A: TraitWAssocConst<A=32>>() {
100+
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`
101+
102+
error[E0271]: type mismatch resolving `<Demo as TraitWAssocConst>::A == 32`
103+
--> $DIR/issue-105330.rs:21:11
104+
|
105+
LL | foo::<Demo>();
106+
| ^^^^ expected `32`, found `<Demo as TraitWAssocConst>::A`
107+
|
108+
= note: expected constant `32`
109+
found constant `<Demo as TraitWAssocConst>::A`
110+
note: required by a bound in `foo`
111+
--> $DIR/issue-105330.rs:11:28
112+
|
113+
LL | fn foo<A: TraitWAssocConst<A=32>>() {
114+
| ^^^^ required by this bound in `foo`
115+
116+
error: aborting due to 11 previous errors
53117

54-
Some errors have detailed explanations: E0131, E0404, E0562, E0658.
118+
Some errors have detailed explanations: E0131, E0271, E0277, E0404, E0562, E0618, E0658.
55119
For more information about an error, try `rustc --explain E0131`.

tests/ui/associated-inherent-types/issue-109299.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ impl Lexer<'d> { //~ ERROR use of undeclared lifetime name `'d`
88
}
99

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

1213
fn main() {}

tests/ui/associated-inherent-types/issue-109299.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ LL | impl Lexer<'d> {
66
| |
77
| help: consider introducing lifetime `'d` here: `<'d>`
88

9-
error: aborting due to 1 previous error
9+
error: lifetime may not live long enough
10+
--> $DIR/issue-109299.rs:10:1
11+
|
12+
LL | fn test(_: Lexer::Cursor) {}
13+
| ^^^^^^^^-^^^^^^^^^^^^^^^^
14+
| | |
15+
| | has type `Lexer<'1>::Cursor`
16+
| requires that `'1` must outlive `'static`
17+
18+
error: aborting due to 2 previous errors
1019

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

tests/ui/associated-inherent-types/issue-109789.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ impl Other for u32 {}
1818
fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
1919
//~^ ERROR mismatched types
2020
//~| ERROR mismatched types
21+
//~| ERROR higher-ranked subtype error
22+
//~| ERROR higher-ranked subtype error
2123

2224
fn main() {}

tests/ui/associated-inherent-types/issue-109789.stderr

+15-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ LL | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
1717
found struct `Foo<for<'a> fn(&'a ())>`
1818
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1919

20-
error: aborting due to 2 previous errors
20+
error: higher-ranked subtype error
21+
--> $DIR/issue-109789.rs:18:1
22+
|
23+
LL | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25+
26+
error: higher-ranked subtype error
27+
--> $DIR/issue-109789.rs:18:1
28+
|
29+
LL | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
33+
34+
error: aborting due to 4 previous errors
2135

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

tests/ui/associated-inherent-types/regionck-2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ impl Lexer<'static> {
1010
}
1111

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

1415
fn main() {}

tests/ui/associated-inherent-types/regionck-2.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ LL | fn test(_: Lexer::Cursor) {}
1313
| ^^^^^
1414
= note: ...does not necessarily outlive the static lifetime
1515

16-
error: aborting due to 1 previous error
16+
error: lifetime may not live long enough
17+
--> $DIR/regionck-2.rs:12:1
18+
|
19+
LL | fn test(_: Lexer::Cursor) {}
20+
| ^^^^^^^^-^^^^^^^^^^^^^^^^
21+
| | |
22+
| | has type `Lexer<'1>::Cursor`
23+
| requires that `'1` must outlive `'static`
24+
25+
error: aborting due to 2 previous errors
1726

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

tests/ui/associated-types/associated-types-for-unimpl-trait.fixed

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ trait Get {
88
}
99

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

15-
fn main() {
16-
}
16+
fn main() {}

tests/ui/associated-types/associated-types-for-unimpl-trait.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ trait Get {
88
}
99

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

15-
fn main() {
16-
}
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
error[E0277]: the trait bound `Self: Get` is not satisfied
2-
--> $DIR/associated-types-for-unimpl-trait.rs:11:40
2+
--> $DIR/associated-types-for-unimpl-trait.rs:11:41
33
|
4-
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
5-
| ^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
4+
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized {}
5+
| ^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
66
|
77
help: consider further restricting `Self`
88
|
9-
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
10-
| +++++++++++++++
9+
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized, Self: Get {}
10+
| +++++++++++
1111

12-
error: aborting due to 1 previous error
12+
error[E0277]: the trait bound `Self: Get` is not satisfied
13+
--> $DIR/associated-types-for-unimpl-trait.rs:11:81
14+
|
15+
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized {}
16+
| ^^ the trait `Get` is not implemented for `Self`
17+
|
18+
help: consider further restricting `Self`
19+
|
20+
LL | fn uhoh<U: Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Sized, Self: Get {}
21+
| +++++++++++
22+
23+
error: aborting due to 2 previous errors
1324

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

0 commit comments

Comments
 (0)