Skip to content

Commit beaf46f

Browse files
committed
Work around the fact that check_mod_type_wf may spuriously return ErrorGuaranteed, even if that error is only emitted by check_modwitem_types
1 parent c716f18 commit beaf46f

File tree

64 files changed

+661
-80
lines changed

Some content is hidden

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

64 files changed

+661
-80
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
128128

129129
let param_env = tcx.param_env(item_def_id);
130130
for field in &def.non_enum_variant().fields {
131-
let field_ty = tcx.normalize_erasing_regions(param_env, field.ty(tcx, args));
131+
let Ok(field_ty) = tcx.try_normalize_erasing_regions(param_env, field.ty(tcx, args))
132+
else {
133+
tcx.sess.delay_span_bug(span, "could not normalize field type");
134+
continue;
135+
};
132136

133137
if !allowed_union_field(field_ty, tcx, param_env) {
134138
let (field_span, ty_span) = match tcx.hir().get_if_local(field.did) {

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,19 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
205205
})?;
206206
}
207207

208-
tcx.sess.time("wf_checking", || {
208+
let errs = tcx.sess.time("wf_checking", || {
209209
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_type_wf(module))
210-
})?;
210+
});
211211

212212
// NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync.
213213
tcx.sess.time("item_types_checking", || {
214214
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_item_types(module))
215215
});
216216

217+
// HACK: `check_mod_type_wf` may spuriously emit errors due to `delay_span_bug`, even if those errors
218+
// only actually get emitted in `check_mod_item_types`.
219+
errs?;
220+
217221
if tcx.features().rustc_attrs {
218222
tcx.sess.track_errors(|| collect::test_opaque_hidden_types(tcx))?;
219223
}

src/tools/clippy/tests/ui/crashes/ice-6252.stderr

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ help: you might be missing a type parameter
2424
LL | impl<N, M, VAL> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
2525
| +++++
2626

27-
error: aborting due to 2 previous errors
27+
error[E0046]: not all trait items implemented, missing: `VAL`
28+
--> $DIR/ice-6252.rs:11:1
29+
|
30+
LL | const VAL: T;
31+
| ------------ `VAL` from trait
32+
...
33+
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
34+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation
35+
36+
error: aborting due to 3 previous errors
2837

29-
For more information about this error, try `rustc --explain E0412`.
38+
Some errors have detailed explanations: E0046, E0412.
39+
For more information about an error, try `rustc --explain E0046`.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658
1414

1515
fn main<A: TraitWAssocConst<A=32>>() {
1616
//~^ ERROR E0658
17+
//~| ERROR E0131
1718
foo::<Demo>();
1819
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ error[E0562]: `impl Trait` only allowed in function and inherent method argument
3939
LL | impl TraitWAssocConst for impl Demo {
4040
| ^^^^^^^^^
4141

42-
error: aborting due to 5 previous errors
42+
error[E0131]: `main` function is not allowed to have generic parameters
43+
--> $DIR/issue-105330.rs:15:8
44+
|
45+
LL | fn main<A: TraitWAssocConst<A=32>>() {
46+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` cannot have generic parameters
47+
48+
error: aborting due to 6 previous errors
4349

44-
Some errors have detailed explanations: E0404, E0562, E0658.
45-
For more information about an error, try `rustc --explain E0404`.
50+
Some errors have detailed explanations: E0131, E0404, E0562, E0658.
51+
For more information about an error, try `rustc --explain E0131`.

tests/ui/associated-inherent-types/generic-associated-types-bad.item.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ note: required by a bound in `Ty::Pr`
1010
LL | type Pr<T: Copy> = T;
1111
| ^^^^ required by this bound in `Ty::Pr`
1212

13-
error: aborting due to previous error
13+
error[E0277]: the trait bound `String: Copy` is not satisfied
14+
--> $DIR/generic-associated-types-bad.rs:16:27
15+
|
16+
LL | const _: Ty::Pr<String> = String::new();
17+
| ^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
18+
|
19+
note: required by a bound in `Ty::Pr`
20+
--> $DIR/generic-associated-types-bad.rs:10:16
21+
|
22+
LL | type Pr<T: Copy> = T;
23+
| ^^^^ required by this bound in `Ty::Pr`
24+
25+
error: aborting due to 2 previous errors
1426

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

tests/ui/associated-inherent-types/generic-associated-types-bad.local.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `Vec<()>: Copy` is not satisfied
2-
--> $DIR/generic-associated-types-bad.rs:20:12
2+
--> $DIR/generic-associated-types-bad.rs:21:12
33
|
44
LL | let _: Ty::Pr<Vec<()>>;
55
| ^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Vec<()>`

tests/ui/associated-inherent-types/generic-associated-types-bad.region.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/generic-associated-types-bad.rs:25:12
2+
--> $DIR/generic-associated-types-bad.rs:26:12
33
|
44
LL | fn user<'a>() {
55
| -- lifetime `'a` defined here

tests/ui/associated-inherent-types/generic-associated-types-bad.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ impl Ty {
1414

1515
#[cfg(item)]
1616
const _: Ty::Pr<String> = String::new(); //[item]~ the trait bound `String: Copy` is not satisfied
17+
//[item]~^ the trait bound `String: Copy` is not satisfied
1718

1819
fn main() {
1920
#[cfg(local)]

tests/ui/associated-types/associated-types-no-suitable-supertrait.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ trait Other {
2121
impl<T:Get> Other for T {
2222
fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
2323
//~^ ERROR the trait bound `(T, U): Get` is not satisfied
24+
//~| ERROR the trait bound `(T, U): Get` is not satisfied
2425
}
2526

2627
fn main() { }

0 commit comments

Comments
 (0)