Skip to content

Commit

Permalink
Rollup merge of rust-lang#120531 - oli-obk:track_errors7, r=estebank
Browse files Browse the repository at this point in the history
Remove a bunch of `has_errors` checks that have no meaningful or the wrong effect

r? `@nnethercote`
  • Loading branch information
matthiaskrgr committed Jan 31, 2024
2 parents 958d6f8 + d31905c commit ae02de9
Show file tree
Hide file tree
Showing 20 changed files with 121 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
// FIXME(effects)
let predicate_is_const = false;

if let Some(guar) = self.dcx().has_errors()
&& trait_predicate.references_error()
if let Err(guar) = trait_predicate.error_reported()
{
return guar;
}
Expand Down Expand Up @@ -2625,9 +2624,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if let Some(e) = self.tainted_by_errors() {
return e;
}
if let Some(e) = self.dcx().has_errors() {
return e;
}

self.emit_inference_failure_err(
obligation.cause.body_id,
Expand All @@ -2645,10 +2641,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if let Some(e) = self.tainted_by_errors() {
return e;
}
if let Some(e) = self.dcx().has_errors() {
// no need to overload user in such cases
return e;
}
let SubtypePredicate { a_is_expected: _, a, b } = data;
// both must be type variables, or the other would've been instantiated
assert!(a.is_ty_var() && b.is_ty_var());
Expand Down Expand Up @@ -2728,10 +2720,6 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
if let Some(e) = self.tainted_by_errors() {
return e;
}
if let Some(e) = self.dcx().has_errors() {
// no need to overload user in such cases
return e;
}
struct_span_code_err!(
self.dcx(),
span,
Expand Down
1 change: 1 addition & 0 deletions tests/ui/closures/issue-78720.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
fn server() -> impl {
//~^ ERROR at least one trait must be specified
().map2(|| "")
//~^ ERROR type annotations needed
}

trait FilterBase2 {
Expand Down
16 changes: 11 additions & 5 deletions tests/ui/closures/issue-78720.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | fn server() -> impl {
| ^^^^

error[E0412]: cannot find type `F` in this scope
--> $DIR/issue-78720.rs:13:12
--> $DIR/issue-78720.rs:14:12
|
LL | _func: F,
| ^
Expand All @@ -22,8 +22,14 @@ help: you might be missing a type parameter
LL | struct Map2<Segment2, F> {
| +++

error[E0282]: type annotations needed
--> $DIR/issue-78720.rs:3:5
|
LL | ().map2(|| "")
| ^^^^^^^^^^^^^^ cannot infer type

error[E0308]: mismatched types
--> $DIR/issue-78720.rs:7:39
--> $DIR/issue-78720.rs:8:39
|
LL | fn map2<F>(self, f: F) -> Map2<F> {}
| ^^ expected `Map2<F>`, found `()`
Expand All @@ -32,7 +38,7 @@ LL | fn map2<F>(self, f: F) -> Map2<F> {}
found unit type `()`

error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> $DIR/issue-78720.rs:7:16
--> $DIR/issue-78720.rs:8:16
|
LL | fn map2<F>(self, f: F) -> Map2<F> {}
| ^^^^ doesn't have a size known at compile-time
Expand All @@ -47,7 +53,7 @@ help: function arguments must have a statically known size, borrowed types alway
LL | fn map2<F>(&self, f: F) -> Map2<F> {}
| +

error: aborting due to 4 previous errors
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0277, E0308, E0412.
Some errors have detailed explanations: E0277, E0282, E0308, E0412.
For more information about an error, try `rustc --explain E0277`.
2 changes: 1 addition & 1 deletion tests/ui/const-generics/defaults/rp_impl_trait_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ fn owo() -> impl Traitor {

fn main() {
rawr();
uwu();
uwu(); //~ ERROR: type annotations needed
owo();
}
16 changes: 14 additions & 2 deletions tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ LL | 1_u64
|
= help: the trait `Traitor<1, 2>` is implemented for `u64`

error: aborting due to 3 previous errors
error[E0282]: type annotations needed
--> $DIR/rp_impl_trait_fail.rs:28:5
|
LL | uwu();
| ^^^ cannot infer the value of the const parameter `N` declared on the function `uwu`
|
help: consider specifying the generic argument
|
LL | uwu::<N>();
| +++++

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.
Some errors have detailed explanations: E0277, E0282.
For more information about an error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ LL | ArrayHolder([0; Self::SIZE])
|
= help: try adding a `where` bound using this expression: `where [(); Self::SIZE]:`

error: aborting due to 2 previous errors
error[E0282]: type annotations needed for `ArrayHolder<X>`
--> $DIR/issue-62504.rs:26:9
|
LL | let mut array = ArrayHolder::new();
| ^^^^^^^^^
|
help: consider giving `array` an explicit type, where the value of const parameter `X` is specified
|
LL | let mut array: ArrayHolder<X> = ArrayHolder::new();
| ++++++++++++++++

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0282, E0308.
For more information about an error, try `rustc --explain E0282`.
16 changes: 14 additions & 2 deletions tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ note: tuple struct defined here
LL | struct ArrayHolder<const X: usize>([u32; X]);
| ^^^^^^^^^^^

error: aborting due to 2 previous errors
error[E0282]: type annotations needed for `ArrayHolder<X>`
--> $DIR/issue-62504.rs:26:9
|
LL | let mut array = ArrayHolder::new();
| ^^^^^^^^^
|
help: consider giving `array` an explicit type, where the value of const parameter `X` is specified
|
LL | let mut array: ArrayHolder<X> = ArrayHolder::new();
| ++++++++++++++++

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0282, E0308.
For more information about an error, try `rustc --explain E0282`.
1 change: 1 addition & 0 deletions tests/ui/const-generics/generic_const_exprs/issue-62504.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ impl<const X: usize> ArrayHolder<X> {

fn main() {
let mut array = ArrayHolder::new();
//~^ ERROR: type annotations needed
}
1 change: 1 addition & 0 deletions tests/ui/consts/issue-104609.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fn foo() {

unsafe fn bar() {
std::mem::transmute::<_, *mut _>(1_u8);
//~^ ERROR: type annotations needed
}

fn main() {}
11 changes: 9 additions & 2 deletions tests/ui/consts/issue-104609.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ error[E0425]: cannot find value `oops` in this scope
LL | oops;
| ^^^^ not found in this scope

error: aborting due to 1 previous error
error[E0282]: type annotations needed
--> $DIR/issue-104609.rs:7:5
|
LL | std::mem::transmute::<_, *mut _>(1_u8);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Dst` declared on the function `transmute`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.
Some errors have detailed explanations: E0282, E0425.
For more information about an error, try `rustc --explain E0282`.
2 changes: 1 addition & 1 deletion tests/ui/generic-const-items/parameter-defaults.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[E0282]: type annotations needed for `Option<T>`
--> $DIR/parameter-defaults.rs:13:9
|
LL | let _ = NONE;
| ^
| ^ ---- type must be known at this point
|
help: consider giving this pattern a type, where the type for type parameter `T` is specified
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/inference/need_type_info/type-alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn direct_alias() {

type IndirectAlias<T> = Ty<Box<T>>;
fn indirect_alias() {
IndirectAlias::new();
IndirectAlias::new(); //~ ERROR: type annotations needed
// FIXME: This should also emit an error.
//
// Added it separately as `type-alias-indirect.rs`
Expand Down
8 changes: 7 additions & 1 deletion tests/ui/inference/need_type_info/type-alias.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ error[E0282]: type annotations needed
LL | DirectAlias::new()
| ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`

error[E0282]: type annotations needed
--> $DIR/type-alias.rs:18:5
|
LL | IndirectAlias::new();
| ^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the type alias `IndirectAlias`

error[E0282]: type annotations needed
--> $DIR/type-alias.rs:32:5
|
LL | DirectButWithDefaultAlias::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`

error: aborting due to 2 previous errors
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0282`.
2 changes: 2 additions & 0 deletions tests/ui/parser/issues/issue-89574.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
fn main() {
const EMPTY_ARRAY = [];
//~^ missing type for `const` item
//~| ERROR type annotations needed
//~| ERROR type annotations needed
}
17 changes: 16 additions & 1 deletion tests/ui/parser/issues/issue-89574.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
error[E0282]: type annotations needed
--> $DIR/issue-89574.rs:2:25
|
LL | const EMPTY_ARRAY = [];
| ^^ cannot infer type

error: missing type for `const` item
--> $DIR/issue-89574.rs:2:22
|
LL | const EMPTY_ARRAY = [];
| ^ help: provide a type for the item: `: <type>`

error: aborting due to 1 previous error
error[E0282]: type annotations needed
--> $DIR/issue-89574.rs:2:25
|
LL | const EMPTY_ARRAY = [];
| ^^ cannot infer type
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0282`.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ error[E0282]: type annotations needed for `Vec<_>`
--> $DIR/missing-closing-angle-bracket-eq-constraint.rs:7:7
|
LL | let v : Vec<(u32,_) = vec![];
| ^
| ^ ------ type must be known at this point
|
help: consider giving `v` an explicit type, where the placeholders `_` are specified
|
Expand All @@ -52,7 +52,7 @@ error[E0282]: type annotations needed for `Vec<_>`
--> $DIR/missing-closing-angle-bracket-eq-constraint.rs:18:7
|
LL | let v : Vec<'a = vec![];
| ^
| ^ ------ type must be known at this point
|
help: consider giving `v` an explicit type, where the placeholders `_` are specified
|
Expand Down
1 change: 1 addition & 0 deletions tests/ui/traits/next-solver/specialization-transmute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl<T> Default for T {
default type Id = T; //~ ERROR type annotations needed
// This will be fixed by #111994
fn intu(&self) -> &Self::Id {
//~^ ERROR type annotations needed
self
}
}
Expand Down
11 changes: 9 additions & 2 deletions tests/ui/traits/next-solver/specialization-transmute.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ LL | #![feature(specialization)]

error: cannot normalize `<T as Default>::Id`

error[E0284]: type annotations needed: cannot satisfy `<T as Default>::Id == _`
--> $DIR/specialization-transmute.rs:16:23
|
LL | fn intu(&self) -> &Self::Id {
| ^^^^^^^^^ cannot satisfy `<T as Default>::Id == _`

error[E0282]: type annotations needed
--> $DIR/specialization-transmute.rs:14:23
|
LL | default type Id = T;
| ^ cannot infer type for associated type `<T as Default>::Id`

error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 3 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0282`.
Some errors have detailed explanations: E0282, E0284.
For more information about an error, try `rustc --explain E0282`.
2 changes: 1 addition & 1 deletion tests/ui/typeck/issue-104510-ice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct W<T: ?Sized>(Oops);

unsafe fn test() {
let j = W(());
let pointer = &j as *const _;
let pointer = &j as *const _; //~ ERROR type annotations needed
core::arch::asm!(
"nop",
in("eax") pointer,
Expand Down
16 changes: 14 additions & 2 deletions tests/ui/typeck/issue-104510-ice.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ error[E0412]: cannot find type `Oops` in this scope
LL | struct W<T: ?Sized>(Oops);
| ^^^^ not found in this scope

error: aborting due to 1 previous error
error[E0282]: type annotations needed for `*const W<T>`
--> $DIR/issue-104510-ice.rs:9:9
|
LL | let pointer = &j as *const _;
| ^^^^^^^
|
help: consider giving `pointer` an explicit type, where the type for type parameter `T` is specified
|
LL | let pointer: *const W<T> = &j as *const _;
| +++++++++++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0412`.
Some errors have detailed explanations: E0282, E0412.
For more information about an error, try `rustc --explain E0282`.

0 comments on commit ae02de9

Please sign in to comment.