Skip to content

Commit

Permalink
Unrolled build for rust-lang#117159
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#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 rust-lang#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.
  • Loading branch information
rust-timer authored Oct 25, 2023
2 parents cf226e9 + beaf46f commit dc8cfe1
Show file tree
Hide file tree
Showing 64 changed files with 661 additions and 80 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b

let param_env = tcx.param_env(item_def_id);
for field in &def.non_enum_variant().fields {
let field_ty = tcx.normalize_erasing_regions(param_env, field.ty(tcx, args));
let Ok(field_ty) = tcx.try_normalize_erasing_regions(param_env, field.ty(tcx, args))
else {
tcx.sess.delay_span_bug(span, "could not normalize field type");
continue;
};

if !allowed_union_field(field_ty, tcx, param_env) {
let (field_span, ty_span) = match tcx.hir().get_if_local(field.did) {
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,19 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
})?;
}

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

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

// HACK: `check_mod_type_wf` may spuriously emit errors due to `delay_span_bug`, even if those errors
// only actually get emitted in `check_mod_item_types`.
errs?;

if tcx.features().rustc_attrs {
tcx.sess.track_errors(|| collect::test_opaque_hidden_types(tcx))?;
}
Expand Down
14 changes: 12 additions & 2 deletions src/tools/clippy/tests/ui/crashes/ice-6252.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ help: you might be missing a type parameter
LL | impl<N, M, VAL> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| +++++

error: aborting due to 2 previous errors
error[E0046]: not all trait items implemented, missing: `VAL`
--> $DIR/ice-6252.rs:11:1
|
LL | const VAL: T;
| ------------ `VAL` from trait
...
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0412`.
Some errors have detailed explanations: E0046, E0412.
For more information about an error, try `rustc --explain E0046`.
1 change: 1 addition & 0 deletions tests/ui/associated-consts/issue-105330.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ fn foo<A: TraitWAssocConst<A=32>>() { //~ ERROR E0658

fn main<A: TraitWAssocConst<A=32>>() {
//~^ ERROR E0658
//~| ERROR E0131
foo::<Demo>();
}
12 changes: 9 additions & 3 deletions tests/ui/associated-consts/issue-105330.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ error[E0562]: `impl Trait` only allowed in function and inherent method argument
LL | impl TraitWAssocConst for impl Demo {
| ^^^^^^^^^

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

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0404, E0562, E0658.
For more information about an error, try `rustc --explain E0404`.
Some errors have detailed explanations: E0131, E0404, E0562, E0658.
For more information about an error, try `rustc --explain E0131`.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ note: required by a bound in `Ty::Pr`
LL | type Pr<T: Copy> = T;
| ^^^^ required by this bound in `Ty::Pr`

error: aborting due to previous error
error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/generic-associated-types-bad.rs:16:27
|
LL | const _: Ty::Pr<String> = String::new();
| ^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
note: required by a bound in `Ty::Pr`
--> $DIR/generic-associated-types-bad.rs:10:16
|
LL | type Pr<T: Copy> = T;
| ^^^^ required by this bound in `Ty::Pr`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `Vec<()>: Copy` is not satisfied
--> $DIR/generic-associated-types-bad.rs:20:12
--> $DIR/generic-associated-types-bad.rs:21:12
|
LL | let _: Ty::Pr<Vec<()>>;
| ^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Vec<()>`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: lifetime may not live long enough
--> $DIR/generic-associated-types-bad.rs:25:12
--> $DIR/generic-associated-types-bad.rs:26:12
|
LL | fn user<'a>() {
| -- lifetime `'a` defined here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl Ty {

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

fn main() {
#[cfg(local)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ trait Other {
impl<T:Get> Other for T {
fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
//~^ ERROR the trait bound `(T, U): Get` is not satisfied
//~| ERROR the trait bound `(T, U): Get` is not satisfied
}

fn main() { }
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ help: consider further restricting `Self`
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) where Self: Get {}
| +++++++++++++++

error: aborting due to 2 previous errors
error[E0277]: the trait bound `(T, U): Get` is not satisfied
--> $DIR/associated-types-no-suitable-supertrait.rs:22:5
|
LL | fn uhoh<U:Get>(&self, foo: U, bar: <(T, U) as Get>::Value) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `(T, U)`
|
help: this trait has no implementations, consider adding one
--> $DIR/associated-types-no-suitable-supertrait.rs:12:1
|
LL | trait Get {
| ^^^^^^^^^

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
trait NotObjectSafe { fn eq(&self, other: Self); }
impl NotObjectSafe for dyn NotObjectSafe { }
//~^ ERROR E0038
//~| ERROR E0046

fn main() { }
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ LL | trait NotObjectSafe { fn eq(&self, other: Self); }
| this trait cannot be made into an object...
= help: consider moving `eq` to another trait

error: aborting due to previous error
error[E0046]: not all trait items implemented, missing: `eq`
--> $DIR/coherence-impl-trait-for-trait-object-safe.rs:7:1
|
LL | trait NotObjectSafe { fn eq(&self, other: Self); }
| -------------------------- `eq` from trait
LL | impl NotObjectSafe for dyn NotObjectSafe { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `eq` in implementation

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0038`.
Some errors have detailed explanations: E0038, E0046.
For more information about an error, try `rustc --explain E0038`.
13 changes: 13 additions & 0 deletions tests/ui/const-generics/generic_const_exprs/type_mismatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

trait Q {
const ASSOC: usize;
}

impl<const N: u64> Q for [u8; N] {}
//~^ ERROR not all trait items implemented

pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {}

pub fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/const-generics/generic_const_exprs/type_mismatch.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0046]: not all trait items implemented, missing: `ASSOC`
--> $DIR/type_mismatch.rs:8:1
|
LL | const ASSOC: usize;
| ------------------ `ASSOC` from trait
...
LL | impl<const N: u64> Q for [u8; N] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `ASSOC` in implementation

error: aborting due to previous error

For more information about this error, try `rustc --explain E0046`.
4 changes: 4 additions & 0 deletions tests/ui/consts/const-unsized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ use std::fmt::Debug;

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

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

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

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

fn main() {
println!("{:?} {:?} {:?} {:?}", &CONST_0, &CONST_FOO, &STATIC_1, &STATIC_BAR);
Expand Down
44 changes: 40 additions & 4 deletions tests/ui/consts/const-unsized.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,65 @@ LL | const CONST_0: dyn Debug + Sync = *(&0 as &(dyn Debug + Sync));
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`

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

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

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

error: aborting due to 4 previous errors
error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
--> $DIR/const-unsized.rs:3:35
|
LL | const CONST_0: dyn Debug + Sync = *(&0 as &(dyn Debug + Sync));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
= note: constant expressions must have a statically known size

error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/const-unsized.rs:7:24
|
LL | const CONST_FOO: str = *"foo";
| ^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: constant expressions must have a statically known size

error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
--> $DIR/const-unsized.rs:11:37
|
LL | static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
= note: constant expressions must have a statically known size

error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/const-unsized.rs:15:26
|
LL | static STATIC_BAR: str = *"bar";
| ^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: constant expressions must have a statically known size

error: aborting due to 8 previous errors

For more information about this error, try `rustc --explain E0277`.
3 changes: 2 additions & 1 deletion tests/ui/generic-associated-types/issue-84931.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ struct StreamingSliceIter<'a, T> {

impl<'b, T: 'b> StreamingIter for StreamingSliceIter<'b, T> {
type Item<'a> = &'a mut T;
//~^ the parameter type
//~^ ERROR: the parameter type
//~| ERROR: does not fulfill the required lifetime
fn next(&mut self) -> Option<&mut T> {
loop {}
}
Expand Down
24 changes: 22 additions & 2 deletions tests/ui/generic-associated-types/issue-84931.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ help: consider adding an explicit lifetime bound
LL | type Item<'a> = &'a mut T where T: 'a;
| +++++++++++

error: aborting due to previous error
error[E0477]: the type `StreamingSliceIter<'b, T>` does not fulfill the required lifetime
--> $DIR/issue-84931.rs:14:21
|
LL | type Item<'a> where Self: 'a;
| ------------- definition of `Item` from trait
...
LL | type Item<'a> = &'a mut T;
| ^^^^^^^^^
|
note: type must outlive the lifetime `'a` as defined here
--> $DIR/issue-84931.rs:14:15
|
LL | type Item<'a> = &'a mut T;
| ^^
help: copy the `where` clause predicates from the trait
|
LL | type Item<'a> = &'a mut T where Self: 'a;
| ++++++++++++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0309`.
Some errors have detailed explanations: E0309, E0477.
For more information about an error, try `rustc --explain E0309`.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub trait X {

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

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

0 comments on commit dc8cfe1

Please sign in to comment.