Skip to content

Commit 844a419

Browse files
authored
Rollup merge of rust-lang#148290 - oli-obk:push-qwxvxyopypry, r=nnethercote
Do not emit solver errors that contain error types any follow-up errors are going to either be duplicates or often disappear if the error itself is fixed. in this PR it mostly silences dyn-compat errors as all the other errors are already deduplicated outside of the test suite. The dyn compat errors are independent errors and I think if the dyn compatiblity depended on an error type it would not actually show, so this is PR is actually silencing independent errors, too. I am opening this PR because I am seeing lots of `{type error}: const Trait` errors when adding more const checking. So instead of targetting just those specific errors, I wanted to try out fully avoiding such errors near the trait solver. cc ````@rust-lang/types```` for thoughts
2 parents c6b9df8 + cac6f87 commit 844a419

25 files changed

+35
-670
lines changed

compiler/rustc_infer/src/traits/project.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use rustc_data_structures::snapshot_map::{self, SnapshotMapRef, SnapshotMapStorage};
44
use rustc_data_structures::undo_log::Rollback;
5+
use rustc_macros::TypeVisitable;
56
use rustc_middle::traits::EvaluationResult;
67
use rustc_middle::ty;
78
use tracing::{debug, info};
@@ -12,7 +13,7 @@ use crate::infer::snapshot::undo_log::InferCtxtUndoLogs;
1213
pub(crate) type UndoLog<'tcx> =
1314
snapshot_map::UndoLog<ProjectionCacheKey<'tcx>, ProjectionCacheEntry<'tcx>>;
1415

15-
#[derive(Clone)]
16+
#[derive(Clone, TypeVisitable)]
1617
pub struct MismatchedProjectionTypes<'tcx> {
1718
pub err: ty::error::TypeError<'tcx>,
1819
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_infer::traits::{
2020
PredicateObligation, SelectionError,
2121
};
2222
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
23-
use rustc_middle::ty::{self, Ty, TyCtxt};
23+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt as _};
2424
use rustc_span::{DesugaringKind, ErrorGuaranteed, ExpnKind, Span};
2525
use tracing::{info, instrument};
2626

@@ -253,7 +253,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
253253

254254
for from_expansion in [false, true] {
255255
for (error, suppressed) in iter::zip(&errors, &is_suppressed) {
256-
if !suppressed && error.obligation.cause.span.from_expansion() == from_expansion {
256+
if !suppressed
257+
&& error.obligation.cause.span.from_expansion() == from_expansion
258+
&& !error.references_error()
259+
{
257260
let guar = self.report_fulfillment_error(error);
258261
self.infcx.set_tainted_by_errors(guar);
259262
reported = Some(guar);

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use std::ops::ControlFlow;
2929
use rustc_errors::ErrorGuaranteed;
3030
use rustc_hir::def::DefKind;
3131
pub use rustc_infer::traits::*;
32+
use rustc_macros::TypeVisitable;
3233
use rustc_middle::query::Providers;
3334
use rustc_middle::span_bug;
3435
use rustc_middle::ty::error::{ExpectedFound, TypeError};
@@ -75,7 +76,7 @@ use crate::infer::{InferCtxt, TyCtxtInferExt};
7576
use crate::regions::InferCtxtRegionExt;
7677
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
7778

78-
#[derive(Debug)]
79+
#[derive(Debug, TypeVisitable)]
7980
pub struct FulfillmentError<'tcx> {
8081
pub obligation: PredicateObligation<'tcx>,
8182
pub code: FulfillmentErrorCode<'tcx>,
@@ -107,7 +108,7 @@ impl<'tcx> FulfillmentError<'tcx> {
107108
}
108109
}
109110

110-
#[derive(Clone)]
111+
#[derive(Clone, TypeVisitable)]
111112
pub enum FulfillmentErrorCode<'tcx> {
112113
/// Inherently impossible to fulfill; this trait is implemented if and only
113114
/// if it is already implemented.

tests/rustdoc-ui/invalid_const_in_lifetime_position.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,3 @@ trait X {
44
fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
55
//~^ ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
66
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
7-
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
8-
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
9-
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
10-
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
11-
//~| ERROR trait `X` is not dyn compatible

tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -28,87 +28,6 @@ note: associated type defined here, with 0 generic parameters
2828
LL | type Y<'a>;
2929
| ^
3030

31-
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
32-
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
33-
|
34-
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
35-
| ^ expected 1 lifetime argument
36-
|
37-
note: associated type defined here, with 1 lifetime parameter: `'a`
38-
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
39-
|
40-
LL | type Y<'a>;
41-
| ^ --
42-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
43-
help: add missing lifetime argument
44-
|
45-
LL | fn f<'a>(arg : Box<dyn X<Y<'_, 1> = &'a ()>>) {}
46-
| +++
47-
48-
error[E0107]: associated type takes 0 generic arguments but 1 generic argument was supplied
49-
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
50-
|
51-
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
52-
| ^--- help: remove the unnecessary generics
53-
| |
54-
| expected 0 generic arguments
55-
|
56-
note: associated type defined here, with 0 generic parameters
57-
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
58-
|
59-
LL | type Y<'a>;
60-
| ^
61-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
62-
63-
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
64-
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
65-
|
66-
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
67-
| ^ expected 1 lifetime argument
68-
|
69-
note: associated type defined here, with 1 lifetime parameter: `'a`
70-
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
71-
|
72-
LL | type Y<'a>;
73-
| ^ --
74-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
75-
help: add missing lifetime argument
76-
|
77-
LL | fn f<'a>(arg : Box<dyn X<Y<'_, 1> = &'a ()>>) {}
78-
| +++
79-
80-
error[E0107]: associated type takes 0 generic arguments but 1 generic argument was supplied
81-
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
82-
|
83-
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
84-
| ^--- help: remove the unnecessary generics
85-
| |
86-
| expected 0 generic arguments
87-
|
88-
note: associated type defined here, with 0 generic parameters
89-
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
90-
|
91-
LL | type Y<'a>;
92-
| ^
93-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
94-
95-
error[E0038]: the trait `X` is not dyn compatible
96-
--> $DIR/invalid_const_in_lifetime_position.rs:4:20
97-
|
98-
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
99-
| ^^^^^^^^^^^^^^^^^^^^ `X` is not dyn compatible
100-
|
101-
note: for a trait to be dyn compatible it needs to allow building a vtable
102-
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
103-
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
104-
|
105-
LL | trait X {
106-
| - this trait is not dyn compatible...
107-
LL | type Y<'a>;
108-
| ^ ...because it contains the generic associated type `Y`
109-
= help: consider moving `Y` to another trait
110-
111-
error: aborting due to 7 previous errors
31+
error: aborting due to 2 previous errors
11232

113-
Some errors have detailed explanations: E0038, E0107.
114-
For more information about an error, try `rustc --explain E0038`.
33+
For more information about this error, try `rustc --explain E0107`.

tests/ui/const-generics/generic_const_exprs/issue-102768.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ const _: () = {
99
fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
1010
//~^ ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
1111
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
12-
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
13-
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
14-
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
15-
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
16-
//~| ERROR `X` is not dyn compatible
1712
};
1813

1914
fn main() {}

tests/ui/const-generics/generic_const_exprs/issue-102768.stderr

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -28,87 +28,6 @@ note: associated type defined here, with 0 generic parameters
2828
LL | type Y<'a>;
2929
| ^
3030

31-
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
32-
--> $DIR/issue-102768.rs:9:30
33-
|
34-
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
35-
| ^ expected 1 lifetime argument
36-
|
37-
note: associated type defined here, with 1 lifetime parameter: `'a`
38-
--> $DIR/issue-102768.rs:5:10
39-
|
40-
LL | type Y<'a>;
41-
| ^ --
42-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
43-
help: add missing lifetime argument
44-
|
45-
LL | fn f2<'a>(arg: Box<dyn X<Y<'_, 1> = &'a ()>>) {}
46-
| +++
47-
48-
error[E0107]: associated type takes 0 generic arguments but 1 generic argument was supplied
49-
--> $DIR/issue-102768.rs:9:30
50-
|
51-
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
52-
| ^--- help: remove the unnecessary generics
53-
| |
54-
| expected 0 generic arguments
55-
|
56-
note: associated type defined here, with 0 generic parameters
57-
--> $DIR/issue-102768.rs:5:10
58-
|
59-
LL | type Y<'a>;
60-
| ^
61-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
62-
63-
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
64-
--> $DIR/issue-102768.rs:9:30
65-
|
66-
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
67-
| ^ expected 1 lifetime argument
68-
|
69-
note: associated type defined here, with 1 lifetime parameter: `'a`
70-
--> $DIR/issue-102768.rs:5:10
71-
|
72-
LL | type Y<'a>;
73-
| ^ --
74-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
75-
help: add missing lifetime argument
76-
|
77-
LL | fn f2<'a>(arg: Box<dyn X<Y<'_, 1> = &'a ()>>) {}
78-
| +++
79-
80-
error[E0107]: associated type takes 0 generic arguments but 1 generic argument was supplied
81-
--> $DIR/issue-102768.rs:9:30
82-
|
83-
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
84-
| ^--- help: remove the unnecessary generics
85-
| |
86-
| expected 0 generic arguments
87-
|
88-
note: associated type defined here, with 0 generic parameters
89-
--> $DIR/issue-102768.rs:5:10
90-
|
91-
LL | type Y<'a>;
92-
| ^
93-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
94-
95-
error[E0038]: the trait `X` is not dyn compatible
96-
--> $DIR/issue-102768.rs:9:24
97-
|
98-
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
99-
| ^^^^^^^^^^^^^^^^^^^^ `X` is not dyn compatible
100-
|
101-
note: for a trait to be dyn compatible it needs to allow building a vtable
102-
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
103-
--> $DIR/issue-102768.rs:5:10
104-
|
105-
LL | trait X {
106-
| - this trait is not dyn compatible...
107-
LL | type Y<'a>;
108-
| ^ ...because it contains the generic associated type `Y`
109-
= help: consider moving `Y` to another trait
110-
111-
error: aborting due to 7 previous errors
31+
error: aborting due to 2 previous errors
11232

113-
Some errors have detailed explanations: E0038, E0107.
114-
For more information about an error, try `rustc --explain E0038`.
33+
For more information about this error, try `rustc --explain E0107`.

tests/ui/generic-associated-types/gat-in-trait-path-undeclared-lifetime.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,4 @@ fn main() {
66
fn _f(arg : Box<dyn for<'a> X<Y<'x> = &'a [u32]>>) {}
77
//~^ ERROR: use of undeclared lifetime name `'x`
88
//~| ERROR: binding for associated type `Y` references lifetime
9-
//~| ERROR: binding for associated type `Y` references lifetime
10-
//~| ERROR: binding for associated type `Y` references lifetime
11-
//~| ERROR: the trait `X` is not dyn compatible
129
}

tests/ui/generic-associated-types/gat-in-trait-path-undeclared-lifetime.stderr

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,7 @@ error[E0582]: binding for associated type `Y` references lifetime `'a`, which do
2020
LL | fn _f(arg : Box<dyn for<'a> X<Y<'x> = &'a [u32]>>) {}
2121
| ^^^^^^^^^^^^^^^^^
2222

23-
error[E0582]: binding for associated type `Y` references lifetime `'a`, which does not appear in the trait input types
24-
--> $DIR/gat-in-trait-path-undeclared-lifetime.rs:6:33
25-
|
26-
LL | fn _f(arg : Box<dyn for<'a> X<Y<'x> = &'a [u32]>>) {}
27-
| ^^^^^^^^^^^^^^^^^
28-
|
29-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
30-
31-
error[E0582]: binding for associated type `Y` references lifetime `'a`, which does not appear in the trait input types
32-
--> $DIR/gat-in-trait-path-undeclared-lifetime.rs:6:33
33-
|
34-
LL | fn _f(arg : Box<dyn for<'a> X<Y<'x> = &'a [u32]>>) {}
35-
| ^^^^^^^^^^^^^^^^^
36-
|
37-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
38-
39-
error[E0038]: the trait `X` is not dyn compatible
40-
--> $DIR/gat-in-trait-path-undeclared-lifetime.rs:6:19
41-
|
42-
LL | fn _f(arg : Box<dyn for<'a> X<Y<'x> = &'a [u32]>>) {}
43-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `X` is not dyn compatible
44-
|
45-
note: for a trait to be dyn compatible it needs to allow building a vtable
46-
for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
47-
--> $DIR/gat-in-trait-path-undeclared-lifetime.rs:2:8
48-
|
49-
LL | trait X {
50-
| - this trait is not dyn compatible...
51-
LL | type Y<'x>;
52-
| ^ ...because it contains the generic associated type `Y`
53-
= help: consider moving `Y` to another trait
54-
55-
error: aborting due to 5 previous errors
23+
error: aborting due to 2 previous errors
5624

57-
Some errors have detailed explanations: E0038, E0261, E0582.
58-
For more information about an error, try `rustc --explain E0038`.
25+
Some errors have detailed explanations: E0261, E0582.
26+
For more information about an error, try `rustc --explain E0261`.

tests/ui/generic-associated-types/gat-trait-path-parenthesised-args.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,10 @@ fn foo<'a>(arg: Box<dyn X<Y('a) = &'a ()>>) {}
77
//~| ERROR: parenthesized generic arguments cannot be used
88
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
99
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
10-
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
11-
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
12-
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
13-
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
14-
//~| ERROR at least one trait is required
15-
//~| ERROR: the trait `X` is not dyn compatible
1610

1711

1812
fn bar<'a>(arg: Box<dyn X<Y() = ()>>) {}
1913
//~^ ERROR: parenthesized generic arguments cannot be used
2014
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
21-
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
22-
//~| ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
23-
//~| ERROR: the trait `X` is not dyn compatible
2415

2516
fn main() {}

0 commit comments

Comments
 (0)