Skip to content

Commit 26a9e08

Browse files
authored
Rollup merge of #117159 - oli-obk:error_shenanigans, r=estebank
Work around the fact that `check_mod_type_wf` may spuriously return `ErrorGuaranteed` Even if that error is only emitted by `check_mod_item_types`. fixes #117153 A cleaner refactoring would merge/chain these queries in ways that ensure we only actually get an `ErrorGuaranteed` if there was an error emitted.
2 parents 74c2b98 + beaf46f commit 26a9e08

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

+5-1
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

+6-2
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

+12-2
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

+1
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

+9-3
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

+13-1
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

+1-1
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

+1-1
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

+1
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

+1
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() { }

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ help: consider further restricting `Self`
2121
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
2222
| +++++++++++++++
2323

24-
error: aborting due to 2 previous errors
24+
error[E0277]: the trait bound `(T, U): Get` is not satisfied
25+
--> $DIR/associated-types-no-suitable-supertrait.rs:22:5
26+
|
27+
LL | fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `(T, U)`
29+
|
30+
help: this trait has no implementations, consider adding one
31+
--> $DIR/associated-types-no-suitable-supertrait.rs:12:1
32+
|
33+
LL | trait Get {
34+
| ^^^^^^^^^
35+
36+
error: aborting due to 3 previous errors
2537

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

tests/ui/coherence/coherence-impl-trait-for-trait-object-safe.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
trait NotObjectSafe { fn eq(&self, other: Self); }
77
impl NotObjectSafe for dyn NotObjectSafe { }
88
//~^ ERROR E0038
9+
//~| ERROR E0046
910

1011
fn main() { }

tests/ui/coherence/coherence-impl-trait-for-trait-object-safe.stderr

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ LL | trait NotObjectSafe { fn eq(&self, other: Self); }
1313
| this trait cannot be made into an object...
1414
= help: consider moving `eq` to another trait
1515

16-
error: aborting due to previous error
16+
error[E0046]: not all trait items implemented, missing: `eq`
17+
--> $DIR/coherence-impl-trait-for-trait-object-safe.rs:7:1
18+
|
19+
LL | trait NotObjectSafe { fn eq(&self, other: Self); }
20+
| -------------------------- `eq` from trait
21+
LL | impl NotObjectSafe for dyn NotObjectSafe { }
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `eq` in implementation
23+
24+
error: aborting due to 2 previous errors
1725

18-
For more information about this error, try `rustc --explain E0038`.
26+
Some errors have detailed explanations: E0038, E0046.
27+
For more information about an error, try `rustc --explain E0038`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
trait Q {
5+
const ASSOC: usize;
6+
}
7+
8+
impl<const N: u64> Q for [u8; N] {}
9+
//~^ ERROR not all trait items implemented
10+
11+
pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {}
12+
13+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0046]: not all trait items implemented, missing: `ASSOC`
2+
--> $DIR/type_mismatch.rs:8:1
3+
|
4+
LL | const ASSOC: usize;
5+
| ------------------ `ASSOC` from trait
6+
...
7+
LL | impl<const N: u64> Q for [u8; N] {}
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `ASSOC` in implementation
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0046`.

tests/ui/consts/const-unsized.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ use std::fmt::Debug;
22

33
const CONST_0: dyn Debug + Sync = *(&0 as &(dyn Debug + Sync));
44
//~^ ERROR the size for values of type
5+
//~| ERROR the size for values of type
56

67
const CONST_FOO: str = *"foo";
78
//~^ ERROR the size for values of type
9+
//~| ERROR the size for values of type
810

911
static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync));
1012
//~^ ERROR the size for values of type
13+
//~| ERROR the size for values of type
1114

1215
static STATIC_BAR: str = *"bar";
1316
//~^ ERROR the size for values of type
17+
//~| ERROR the size for values of type
1418

1519
fn main() {
1620
println!("{:?} {:?} {:?} {:?}", &CONST_0, &CONST_FOO, &STATIC_1, &STATIC_BAR);

tests/ui/consts/const-unsized.stderr

+40-4
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,65 @@ LL | const CONST_0: dyn Debug + Sync = *(&0 as &(dyn Debug + Sync));
77
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
88

99
error[E0277]: the size for values of type `str` cannot be known at compilation time
10-
--> $DIR/const-unsized.rs:6:18
10+
--> $DIR/const-unsized.rs:7:18
1111
|
1212
LL | const CONST_FOO: str = *"foo";
1313
| ^^^ doesn't have a size known at compile-time
1414
|
1515
= help: the trait `Sized` is not implemented for `str`
1616

1717
error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
18-
--> $DIR/const-unsized.rs:9:18
18+
--> $DIR/const-unsized.rs:11:18
1919
|
2020
LL | static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync));
2121
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
2222
|
2323
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
2424

2525
error[E0277]: the size for values of type `str` cannot be known at compilation time
26-
--> $DIR/const-unsized.rs:12:20
26+
--> $DIR/const-unsized.rs:15:20
2727
|
2828
LL | static STATIC_BAR: str = *"bar";
2929
| ^^^ doesn't have a size known at compile-time
3030
|
3131
= help: the trait `Sized` is not implemented for `str`
3232

33-
error: aborting due to 4 previous errors
33+
error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
34+
--> $DIR/const-unsized.rs:3:35
35+
|
36+
LL | const CONST_0: dyn Debug + Sync = *(&0 as &(dyn Debug + Sync));
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
38+
|
39+
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
40+
= note: constant expressions must have a statically known size
41+
42+
error[E0277]: the size for values of type `str` cannot be known at compilation time
43+
--> $DIR/const-unsized.rs:7:24
44+
|
45+
LL | const CONST_FOO: str = *"foo";
46+
| ^^^^^^ doesn't have a size known at compile-time
47+
|
48+
= help: the trait `Sized` is not implemented for `str`
49+
= note: constant expressions must have a statically known size
50+
51+
error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
52+
--> $DIR/const-unsized.rs:11:37
53+
|
54+
LL | static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync));
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
56+
|
57+
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
58+
= note: constant expressions must have a statically known size
59+
60+
error[E0277]: the size for values of type `str` cannot be known at compilation time
61+
--> $DIR/const-unsized.rs:15:26
62+
|
63+
LL | static STATIC_BAR: str = *"bar";
64+
| ^^^^^^ doesn't have a size known at compile-time
65+
|
66+
= help: the trait `Sized` is not implemented for `str`
67+
= note: constant expressions must have a statically known size
68+
69+
error: aborting due to 8 previous errors
3470

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

tests/ui/generic-associated-types/issue-84931.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ struct StreamingSliceIter<'a, T> {
1212

1313
impl<'b, T: 'b> StreamingIter for StreamingSliceIter<'b, T> {
1414
type Item<'a> = &'a mut T;
15-
//~^ the parameter type
15+
//~^ ERROR: the parameter type
16+
//~| ERROR: does not fulfill the required lifetime
1617
fn next(&mut self) -> Option<&mut T> {
1718
loop {}
1819
}

tests/ui/generic-associated-types/issue-84931.stderr

+22-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,26 @@ help: consider adding an explicit lifetime bound
1111
LL | type Item<'a> = &'a mut T where T: 'a;
1212
| +++++++++++
1313

14-
error: aborting due to previous error
14+
error[E0477]: the type `StreamingSliceIter<'b, T>` does not fulfill the required lifetime
15+
--> $DIR/issue-84931.rs:14:21
16+
|
17+
LL | type Item<'a> where Self: 'a;
18+
| ------------- definition of `Item` from trait
19+
...
20+
LL | type Item<'a> = &'a mut T;
21+
| ^^^^^^^^^
22+
|
23+
note: type must outlive the lifetime `'a` as defined here
24+
--> $DIR/issue-84931.rs:14:15
25+
|
26+
LL | type Item<'a> = &'a mut T;
27+
| ^^
28+
help: copy the `where` clause predicates from the trait
29+
|
30+
LL | type Item<'a> = &'a mut T where Self: 'a;
31+
| ++++++++++++++
32+
33+
error: aborting due to 2 previous errors
1534

16-
For more information about this error, try `rustc --explain E0309`.
35+
Some errors have detailed explanations: E0309, E0477.
36+
For more information about an error, try `rustc --explain E0309`.

tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub trait X {
77

88
impl X for () {
99
type Y<'a> = &'a ();
10+
//~^ ERROR lifetime bound not satisfied
1011
}
1112

1213
struct B<'a, T: for<'r> X<Y<'r> = &'r ()>> {

0 commit comments

Comments
 (0)