Skip to content

Commit db6d3b3

Browse files
Filter impl and where-clause candidates that reference errors
1 parent ecdf7f0 commit db6d3b3

File tree

10 files changed

+54
-64
lines changed

10 files changed

+54
-64
lines changed

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
174174
.param_env
175175
.caller_bounds()
176176
.iter()
177-
.filter_map(|o| o.to_opt_poly_trait_pred());
177+
.filter_map(|p| p.to_opt_poly_trait_pred())
178+
.filter(|p| !p.references_error());
178179

179180
// Micro-optimization: filter out predicates relating to different traits.
180181
let matching_bounds =

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

+3
Original file line numberDiff line numberDiff line change
@@ -2378,6 +2378,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
23782378
let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id);
23792379

23802380
let impl_trait_ref = impl_trait_ref.subst(self.tcx(), impl_substs);
2381+
if impl_trait_ref.references_error() {
2382+
return Err(());
2383+
}
23812384

23822385
debug!(?impl_trait_ref);
23832386

src/test/ui/c-variadic/issue-86053-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// error-pattern:unexpected `self` parameter in function
33
// error-pattern:`...` must be the last argument of a C-variadic function
44
// error-pattern:cannot find type `F` in this scope
5-
// error-pattern:in type `&'a &'b usize`, reference has a longer lifetime than the data it references
5+
66

77
#![feature(c_variadic)]
88
#![crate_type="lib"]

src/test/ui/c-variadic/issue-86053-1.stderr

+2-20
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,6 @@ help: you might be missing a type parameter
7676
LL | fn ordering4 < 'a , 'b, F > ( a : , self , self , self ,
7777
| +++
7878

79-
error[E0491]: in type `&'a &'b usize`, reference has a longer lifetime than the data it references
80-
--> $DIR/issue-86053-1.rs:11:52
81-
|
82-
LL | self , ... , self , self , ... ) where F : FnOnce ( & 'a & 'b usize ) {
83-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
84-
|
85-
note: the pointer is valid for the lifetime `'a` as defined here
86-
--> $DIR/issue-86053-1.rs:10:16
87-
|
88-
LL | fn ordering4 < 'a , 'b > ( a : , self , self , self ,
89-
| ^^
90-
note: but the referenced data is only valid for the lifetime `'b` as defined here
91-
--> $DIR/issue-86053-1.rs:10:21
92-
|
93-
LL | fn ordering4 < 'a , 'b > ( a : , self , self , self ,
94-
| ^^
95-
96-
error: aborting due to 12 previous errors
79+
error: aborting due to 11 previous errors
9780

98-
Some errors have detailed explanations: E0412, E0491.
99-
For more information about an error, try `rustc --explain E0412`.
81+
For more information about this error, try `rustc --explain E0412`.

src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr

+3-40
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | Condition<{ LHS <= RHS }>: True
1717
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
1818

1919
error: generic parameters may not be used in const operations
20-
--> $DIR/issue-72787.rs:25:25
20+
--> $DIR/issue-72787.rs:23:25
2121
|
2222
LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
2323
| ^ cannot perform const operation using `I`
@@ -26,50 +26,13 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
2626
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
2727

2828
error: generic parameters may not be used in const operations
29-
--> $DIR/issue-72787.rs:25:36
29+
--> $DIR/issue-72787.rs:23:36
3030
|
3131
LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
3232
| ^ cannot perform const operation using `J`
3333
|
3434
= help: const parameters may only be used as standalone arguments, i.e. `J`
3535
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
3636

37-
error[E0283]: type annotations needed: cannot satisfy `IsLessOrEqual<I, 8>: True`
38-
--> $DIR/issue-72787.rs:21:26
39-
|
40-
LL | IsLessOrEqual<I, 8>: True,
41-
| ^^^^
42-
|
43-
note: multiple `impl`s or `where` clauses satisfying `IsLessOrEqual<I, 8>: True` found
44-
--> $DIR/issue-72787.rs:10:1
45-
|
46-
LL | impl<const LHS: u32, const RHS: u32> True for IsLessOrEqual<LHS, RHS> where
47-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48-
...
49-
LL | IsLessOrEqual<I, 8>: True,
50-
| ^^^^
51-
...
52-
LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
53-
| ^^^^
54-
55-
error[E0283]: type annotations needed: cannot satisfy `IsLessOrEqual<I, 8>: True`
56-
--> $DIR/issue-72787.rs:21:26
57-
|
58-
LL | IsLessOrEqual<I, 8>: True,
59-
| ^^^^
60-
|
61-
note: multiple `impl`s or `where` clauses satisfying `IsLessOrEqual<I, 8>: True` found
62-
--> $DIR/issue-72787.rs:10:1
63-
|
64-
LL | impl<const LHS: u32, const RHS: u32> True for IsLessOrEqual<LHS, RHS> where
65-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66-
...
67-
LL | IsLessOrEqual<I, 8>: True,
68-
| ^^^^
69-
...
70-
LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
71-
| ^^^^
72-
73-
error: aborting due to 6 previous errors
37+
error: aborting due to 4 previous errors
7438

75-
For more information about this error, try `rustc --explain E0283`.

src/test/ui/const-generics/generic_const_exprs/issue-72787.rs

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ struct S<const I: u32, const J: u32>;
1919
impl<const I: u32, const J: u32> S<I, J>
2020
where
2121
IsLessOrEqual<I, 8>: True,
22-
//[min]~^ Error type annotations needed
23-
//[min]~| Error type annotations needed
2422
IsLessOrEqual<J, 8>: True,
2523
IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
2624
//[min]~^ Error generic parameters may not be used in const operations
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub struct S;
2+
3+
trait Generic<T> {}
4+
5+
impl<'a, T> Generic<&'a T> for S {}
6+
impl Generic<Type> for S {}
7+
//~^ ERROR cannot find type `Type` in this scope
8+
9+
fn main() {}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0412]: cannot find type `Type` in this scope
2+
--> $DIR/ignore-err-impls.rs:6:14
3+
|
4+
LL | impl Generic<Type> for S {}
5+
| - ^^^^ not found in this scope
6+
| |
7+
| help: you might be missing a type parameter: `<Type>`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0412`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use std::ops::Add;
2+
3+
fn dbl<T>(x: T) -> <T as Add>::Output
4+
where
5+
T: Copy + Add,
6+
UUU: Copy,
7+
//~^ ERROR cannot find type `UUU` in this scope
8+
{
9+
x + x
10+
}
11+
12+
fn main() {
13+
println!("{}", dbl(3));
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0412]: cannot find type `UUU` in this scope
2+
--> $DIR/ignore-err-clauses.rs:6:5
3+
|
4+
LL | UUU: Copy,
5+
| ^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)