Skip to content

Commit a04ac26

Browse files
committed
Allow type_of to return partially non-error types if the type was already tainted
1 parent f989d2f commit a04ac26

18 files changed

+174
-51
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
502502
bug!("unexpected sort of node in type_of(): {:?}", x);
503503
}
504504
};
505-
if let Err(e) = icx.check_tainted_by_errors() {
505+
if let Err(e) = icx.check_tainted_by_errors()
506+
&& !output.references_error()
507+
{
506508
ty::EarlyBinder::bind(Ty::new_error(tcx, e))
507509
} else {
508510
ty::EarlyBinder::bind(output)

tests/ui/associated-inherent-types/issue-109071.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl<T> Windows { //~ ERROR: missing generics for struct `Windows`
1313

1414
impl<T> Windows<T> {
1515
fn T() -> Option<Self::Item> {}
16-
//~^ ERROR: ambiguous associated type
16+
//[no_gate]~^ ERROR: ambiguous associated type
1717
}
1818

1919
fn main() {}

tests/ui/associated-inherent-types/issue-109071.with_gate.stderr

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,7 @@ help: add missing generic argument
2020
LL | impl<T> Windows<T> {
2121
| +++
2222

23-
error[E0223]: ambiguous associated type
24-
--> $DIR/issue-109071.rs:15:22
25-
|
26-
LL | fn T() -> Option<Self::Item> {}
27-
| ^^^^^^^^^^
28-
|
29-
help: use fully-qualified syntax
30-
|
31-
LL | fn T() -> Option<<Windows<T> as IntoAsyncIterator>::Item> {}
32-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33-
LL | fn T() -> Option<<Windows<T> as IntoIterator>::Item> {}
34-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35-
36-
error: aborting due to 3 previous errors
23+
error: aborting due to 2 previous errors
3724

38-
Some errors have detailed explanations: E0107, E0223, E0637.
25+
Some errors have detailed explanations: E0107, E0637.
3926
For more information about an error, try `rustc --explain E0107`.

tests/ui/const-generics/issues/issue-71381.full.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
77
= note: type parameters may not be used in the type of const parameters
88

99
error[E0770]: the type of const parameters must not depend on other generic parameters
10-
--> $DIR/issue-71381.rs:22:40
10+
--> $DIR/issue-71381.rs:23:40
1111
|
1212
LL | const FN: unsafe extern "C" fn(Args),
1313
| ^^^^ the type must not depend on the parameter `Args`

tests/ui/const-generics/issues/issue-71381.min.stderr

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,29 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
77
= note: type parameters may not be used in the type of const parameters
88

99
error[E0770]: the type of const parameters must not depend on other generic parameters
10-
--> $DIR/issue-71381.rs:22:40
10+
--> $DIR/issue-71381.rs:23:40
1111
|
1212
LL | const FN: unsafe extern "C" fn(Args),
1313
| ^^^^ the type must not depend on the parameter `Args`
1414
|
1515
= note: type parameters may not be used in the type of const parameters
1616

17-
error: aborting due to 2 previous errors
17+
error: using function pointers as const generic parameters is forbidden
18+
--> $DIR/issue-71381.rs:14:61
19+
|
20+
LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&self) {
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
|
23+
= note: the only supported types are integers, `bool` and `char`
24+
25+
error: using function pointers as const generic parameters is forbidden
26+
--> $DIR/issue-71381.rs:23:19
27+
|
28+
LL | const FN: unsafe extern "C" fn(Args),
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
|
31+
= note: the only supported types are integers, `bool` and `char`
32+
33+
error: aborting due to 4 previous errors
1834

1935
For more information about this error, try `rustc --explain E0770`.

tests/ui/const-generics/issues/issue-71381.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ unsafe extern "C" fn pass(args: PassArg) {
1313
impl Test {
1414
pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&self) {
1515
//~^ ERROR: the type of const parameters must not depend on other generic parameters
16+
//[min]~^^ ERROR: using function pointers as const generic parameters is forbidden
1617
self.0 = Self::trampiline::<Args, IDX, FN> as _
1718
}
1819

@@ -21,6 +22,7 @@ impl Test {
2122
const IDX: usize,
2223
const FN: unsafe extern "C" fn(Args),
2324
//~^ ERROR: the type of const parameters must not depend on other generic parameters
25+
//[min]~^^ ERROR: using function pointers as const generic parameters is forbidden
2426
>(
2527
args: Args,
2628
) {

tests/ui/const-generics/issues/issue-71611.min.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ LL | fn func<A, const F: fn(inner: A)>(outer: A) {
66
|
77
= note: type parameters may not be used in the type of const parameters
88

9-
error: aborting due to 1 previous error
9+
error: using function pointers as const generic parameters is forbidden
10+
--> $DIR/issue-71611.rs:5:21
11+
|
12+
LL | fn func<A, const F: fn(inner: A)>(outer: A) {
13+
| ^^^^^^^^^^^^
14+
|
15+
= note: the only supported types are integers, `bool` and `char`
16+
17+
error: aborting due to 2 previous errors
1018

1119
For more information about this error, try `rustc --explain E0770`.

tests/ui/const-generics/issues/issue-71611.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
fn func<A, const F: fn(inner: A)>(outer: A) {
66
//~^ ERROR: the type of const parameters must not depend on other generic parameters
7+
//[min]~| ERROR: using function pointers as const generic parameters is forbidden
78
F(outer);
89
}
910

tests/ui/const_prop/ice-type-mismatch-when-copying-112824.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ impl Opcode2 {
1313
pub fn example2(msg_type: Opcode2) -> impl FnMut(&[u8]) {
1414
move |i| match msg_type {
1515
Opcode2::OP2 => unimplemented!(),
16+
//~^ ERROR: could not evaluate constant pattern
1617
}
1718
}
1819

tests/ui/const_prop/ice-type-mismatch-when-copying-112824.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ help: you might be missing a type parameter
1717
LL | pub struct Opcode2<S>(&'a S);
1818
| +++
1919

20-
error: aborting due to 2 previous errors
20+
error: could not evaluate constant pattern
21+
--> $DIR/ice-type-mismatch-when-copying-112824.rs:15:9
22+
|
23+
LL | Opcode2::OP2 => unimplemented!(),
24+
| ^^^^^^^^^^^^
25+
26+
error: aborting due to 3 previous errors
2127

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

0 commit comments

Comments
 (0)