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

Diff for: compiler/rustc_hir_analysis/src/collect/type_of.rs

+3-1
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)

Diff for: tests/ui/associated-inherent-types/issue-109071.rs

+1-1
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() {}

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

+2-15
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`.

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

+1-1
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`

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

+18-2
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`.

Diff for: tests/ui/const-generics/issues/issue-71381.rs

+2
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
) {

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

+9-1
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`.

Diff for: tests/ui/const-generics/issues/issue-71611.rs

+1
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

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

+1
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

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

+7-1
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`.

Diff for: tests/ui/generic-associated-types/issue-71176.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ impl Provider for () {
99
struct Holder<B> {
1010
inner: Box<dyn Provider<A = B>>,
1111
//~^ ERROR: missing generics for associated type
12+
//~| ERROR: missing generics for associated type
13+
//~| ERROR: missing generics for associated type
14+
//~| ERROR: the trait `Provider` cannot be made into an object
1215
}
1316

1417
fn main() {

Diff for: tests/ui/generic-associated-types/issue-71176.stderr

+53-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,57 @@ help: add missing lifetime argument
1414
LL | inner: Box<dyn Provider<A<'a> = B>>,
1515
| ++++
1616

17-
error: aborting due to 1 previous error
17+
error[E0107]: missing generics for associated type `Provider::A`
18+
--> $DIR/issue-71176.rs:10:27
19+
|
20+
LL | inner: Box<dyn Provider<A = B>>,
21+
| ^ expected 1 lifetime argument
22+
|
23+
note: associated type defined here, with 1 lifetime parameter: `'a`
24+
--> $DIR/issue-71176.rs:2:10
25+
|
26+
LL | type A<'a>;
27+
| ^ --
28+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
29+
help: add missing lifetime argument
30+
|
31+
LL | inner: Box<dyn Provider<A<'a> = B>>,
32+
| ++++
33+
34+
error[E0107]: missing generics for associated type `Provider::A`
35+
--> $DIR/issue-71176.rs:10:27
36+
|
37+
LL | inner: Box<dyn Provider<A = B>>,
38+
| ^ expected 1 lifetime argument
39+
|
40+
note: associated type defined here, with 1 lifetime parameter: `'a`
41+
--> $DIR/issue-71176.rs:2:10
42+
|
43+
LL | type A<'a>;
44+
| ^ --
45+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
46+
help: add missing lifetime argument
47+
|
48+
LL | inner: Box<dyn Provider<A<'a> = B>>,
49+
| ++++
50+
51+
error[E0038]: the trait `Provider` cannot be made into an object
52+
--> $DIR/issue-71176.rs:10:14
53+
|
54+
LL | inner: Box<dyn Provider<A = B>>,
55+
| ^^^^^^^^^^^^^^^^^^^ `Provider` cannot be made into an object
56+
|
57+
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
58+
--> $DIR/issue-71176.rs:2:10
59+
|
60+
LL | trait Provider {
61+
| -------- this trait cannot be made into an object...
62+
LL | type A<'a>;
63+
| ^ ...because it contains the generic associated type `A`
64+
= help: consider moving `A` to another trait
65+
= help: only type `()` implements the trait, consider using it directly instead
66+
67+
error: aborting due to 4 previous errors
1868

19-
For more information about this error, try `rustc --explain E0107`.
69+
Some errors have detailed explanations: E0038, E0107.
70+
For more information about an error, try `rustc --explain E0038`.

Diff for: tests/ui/layout/issue-84108.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ static FOO: (dyn AsRef<OsStr>, u8) = ("hello", 42);
88

99
const BAR: (&Path, [u8], usize) = ("hello", [], 42);
1010
//~^ ERROR cannot find type `Path` in this scope
11+
//~| ERROR the size for values of type `[u8]` cannot be known at compilation time
12+
//~| ERROR the size for values of type `[u8]` cannot be known at compilation time
13+
//~| ERROR mismatched types
1114

1215
static BAZ: ([u8], usize) = ([], 0);
1316
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time

Diff for: tests/ui/layout/issue-84108.stderr

+32-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,35 @@ LL + use std::path::Path;
2121
|
2222

2323
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
24-
--> $DIR/issue-84108.rs:12:13
24+
--> $DIR/issue-84108.rs:9:12
25+
|
26+
LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
27+
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
28+
|
29+
= help: the trait `Sized` is not implemented for `[u8]`
30+
= note: only the last element of a tuple may have a dynamically sized type
31+
32+
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
33+
--> $DIR/issue-84108.rs:9:12
34+
|
35+
LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
36+
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
37+
|
38+
= help: the trait `Sized` is not implemented for `[u8]`
39+
= note: only the last element of a tuple may have a dynamically sized type
40+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
41+
42+
error[E0308]: mismatched types
43+
--> $DIR/issue-84108.rs:9:45
44+
|
45+
LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
46+
| ^^ expected `[u8]`, found `[_; 0]`
47+
|
48+
= note: expected slice `[u8]`
49+
found array `[_; 0]`
50+
51+
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
52+
--> $DIR/issue-84108.rs:15:13
2553
|
2654
LL | static BAZ: ([u8], usize) = ([], 0);
2755
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time
@@ -30,7 +58,7 @@ LL | static BAZ: ([u8], usize) = ([], 0);
3058
= note: only the last element of a tuple may have a dynamically sized type
3159

3260
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
33-
--> $DIR/issue-84108.rs:12:13
61+
--> $DIR/issue-84108.rs:15:13
3462
|
3563
LL | static BAZ: ([u8], usize) = ([], 0);
3664
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time
@@ -40,15 +68,15 @@ LL | static BAZ: ([u8], usize) = ([], 0);
4068
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
4169

4270
error[E0308]: mismatched types
43-
--> $DIR/issue-84108.rs:12:30
71+
--> $DIR/issue-84108.rs:15:30
4472
|
4573
LL | static BAZ: ([u8], usize) = ([], 0);
4674
| ^^ expected `[u8]`, found `[_; 0]`
4775
|
4876
= note: expected slice `[u8]`
4977
found array `[_; 0]`
5078

51-
error: aborting due to 5 previous errors
79+
error: aborting due to 8 previous errors
5280

5381
Some errors have detailed explanations: E0277, E0308, E0412.
5482
For more information about an error, try `rustc --explain E0277`.

Diff for: tests/ui/lifetimes/unusual-rib-combinations.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ struct S<'a>(&'a u8);
22
fn foo() {}
33

44
// Paren generic args in AnonConst
5-
fn a() -> [u8; foo::()] {
6-
//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
7-
//~| ERROR mismatched types
5+
fn a() -> [u8; foo()] {
6+
//~^ ERROR mismatched types
87
panic!()
98
}
109

@@ -26,5 +25,6 @@ fn d<const C: S>() {}
2625
trait Foo<'a> {}
2726
struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
2827
//~^ ERROR the type of const parameters must not depend on other generic parameters
28+
//~| ERROR `&dyn for<'a> Foo<'a>` is forbidden as the type of a const generic parameter
2929

3030
fn main() {}

Diff for: tests/ui/lifetimes/unusual-rib-combinations.stderr

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
11
error[E0106]: missing lifetime specifier
2-
--> $DIR/unusual-rib-combinations.rs:22:15
2+
--> $DIR/unusual-rib-combinations.rs:21:15
33
|
44
LL | fn d<const C: S>() {}
55
| ^ expected named lifetime parameter
66

77
error[E0770]: the type of const parameters must not depend on other generic parameters
8-
--> $DIR/unusual-rib-combinations.rs:27:22
8+
--> $DIR/unusual-rib-combinations.rs:26:22
99
|
1010
LL | struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
1111
| ^^ the type must not depend on the parameter `'a`
1212
|
1313
= note: lifetime parameters may not be used in the type of const parameters
1414

1515
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
16-
--> $DIR/unusual-rib-combinations.rs:5:16
17-
|
18-
LL | fn a() -> [u8; foo::()] {
19-
| ^^^^^^^ only `Fn` traits may use parentheses
20-
21-
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
22-
--> $DIR/unusual-rib-combinations.rs:12:15
16+
--> $DIR/unusual-rib-combinations.rs:11:15
2317
|
2418
LL | fn b<const C: u8()>() {}
2519
| ^^^^ only `Fn` traits may use parentheses
2620

2721
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
28-
--> $DIR/unusual-rib-combinations.rs:16:10
22+
--> $DIR/unusual-rib-combinations.rs:15:10
2923
|
3024
LL | fn c<T = u8()>() {}
3125
| ^^^^ only `Fn` traits may use parentheses
3226

3327
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
34-
--> $DIR/unusual-rib-combinations.rs:16:6
28+
--> $DIR/unusual-rib-combinations.rs:15:6
3529
|
3630
LL | fn c<T = u8()>() {}
3731
| ^^^^^^^^
@@ -43,14 +37,11 @@ LL | fn c<T = u8()>() {}
4337
error[E0308]: mismatched types
4438
--> $DIR/unusual-rib-combinations.rs:5:16
4539
|
46-
LL | fn a() -> [u8; foo::()] {
47-
| ^^^^^^^ expected `usize`, found fn item
48-
|
49-
= note: expected type `usize`
50-
found fn item `fn() {foo}`
40+
LL | fn a() -> [u8; foo()] {
41+
| ^^^^^ expected `usize`, found `()`
5142

5243
error: `S<'_>` is forbidden as the type of a const generic parameter
53-
--> $DIR/unusual-rib-combinations.rs:22:15
44+
--> $DIR/unusual-rib-combinations.rs:21:15
5445
|
5546
LL | fn d<const C: S>() {}
5647
| ^
@@ -61,6 +52,18 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
6152
LL + #![feature(adt_const_params)]
6253
|
6354

55+
error: `&dyn for<'a> Foo<'a>` is forbidden as the type of a const generic parameter
56+
--> $DIR/unusual-rib-combinations.rs:26:21
57+
|
58+
LL | struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
59+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
60+
|
61+
= note: the only supported types are integers, `bool` and `char`
62+
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
63+
|
64+
LL + #![feature(adt_const_params)]
65+
|
66+
6467
error: aborting due to 8 previous errors
6568

6669
Some errors have detailed explanations: E0106, E0214, E0308, E0770.

Diff for: tests/ui/parser/issues/issue-103748-ICE-wrong-braces.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ struct Apple((Apple, Option(Banana ? Citron)));
55
//~| ERROR expected one of `)` or `,`, found `Citron`
66
//~| ERROR cannot find type `Citron` in this scope [E0412]
77
//~| ERROR parenthesized type parameters may only be used with a `Fn` trait [E0214]
8+
//~| ERROR `Apple` has infinite size

0 commit comments

Comments
 (0)