mirror of https://github.com/rust-lang/rust.git
Allow type_of to return partially non-error types if the type was already tainted
This commit is contained in:
parent
f989d2f625
commit
a04ac26a9d
|
@ -502,7 +502,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
|||
bug!("unexpected sort of node in type_of(): {:?}", x);
|
||||
}
|
||||
};
|
||||
if let Err(e) = icx.check_tainted_by_errors() {
|
||||
if let Err(e) = icx.check_tainted_by_errors()
|
||||
&& !output.references_error()
|
||||
{
|
||||
ty::EarlyBinder::bind(Ty::new_error(tcx, e))
|
||||
} else {
|
||||
ty::EarlyBinder::bind(output)
|
||||
|
|
|
@ -13,7 +13,7 @@ impl<T> Windows { //~ ERROR: missing generics for struct `Windows`
|
|||
|
||||
impl<T> Windows<T> {
|
||||
fn T() -> Option<Self::Item> {}
|
||||
//~^ ERROR: ambiguous associated type
|
||||
//[no_gate]~^ ERROR: ambiguous associated type
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -20,20 +20,7 @@ help: add missing generic argument
|
|||
LL | impl<T> Windows<T> {
|
||||
| +++
|
||||
|
||||
error[E0223]: ambiguous associated type
|
||||
--> $DIR/issue-109071.rs:15:22
|
||||
|
|
||||
LL | fn T() -> Option<Self::Item> {}
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
help: use fully-qualified syntax
|
||||
|
|
||||
LL | fn T() -> Option<<Windows<T> as IntoAsyncIterator>::Item> {}
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
LL | fn T() -> Option<<Windows<T> as IntoIterator>::Item> {}
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0107, E0223, E0637.
|
||||
Some errors have detailed explanations: E0107, E0637.
|
||||
For more information about an error, try `rustc --explain E0107`.
|
||||
|
|
|
@ -7,7 +7,7 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
|
|||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||
--> $DIR/issue-71381.rs:22:40
|
||||
--> $DIR/issue-71381.rs:23:40
|
||||
|
|
||||
LL | const FN: unsafe extern "C" fn(Args),
|
||||
| ^^^^ the type must not depend on the parameter `Args`
|
||||
|
|
|
@ -7,13 +7,29 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
|
|||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||
--> $DIR/issue-71381.rs:22:40
|
||||
--> $DIR/issue-71381.rs:23:40
|
||||
|
|
||||
LL | const FN: unsafe extern "C" fn(Args),
|
||||
| ^^^^ the type must not depend on the parameter `Args`
|
||||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: using function pointers as const generic parameters is forbidden
|
||||
--> $DIR/issue-71381.rs:14:61
|
||||
|
|
||||
LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&self) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
|
||||
error: using function pointers as const generic parameters is forbidden
|
||||
--> $DIR/issue-71381.rs:23:19
|
||||
|
|
||||
LL | const FN: unsafe extern "C" fn(Args),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0770`.
|
||||
|
|
|
@ -13,6 +13,7 @@ unsafe extern "C" fn pass(args: PassArg) {
|
|||
impl Test {
|
||||
pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&self) {
|
||||
//~^ ERROR: the type of const parameters must not depend on other generic parameters
|
||||
//[min]~^^ ERROR: using function pointers as const generic parameters is forbidden
|
||||
self.0 = Self::trampiline::<Args, IDX, FN> as _
|
||||
}
|
||||
|
||||
|
@ -21,6 +22,7 @@ impl Test {
|
|||
const IDX: usize,
|
||||
const FN: unsafe extern "C" fn(Args),
|
||||
//~^ ERROR: the type of const parameters must not depend on other generic parameters
|
||||
//[min]~^^ ERROR: using function pointers as const generic parameters is forbidden
|
||||
>(
|
||||
args: Args,
|
||||
) {
|
||||
|
|
|
@ -6,6 +6,14 @@ LL | fn func<A, const F: fn(inner: A)>(outer: A) {
|
|||
|
|
||||
= note: type parameters may not be used in the type of const parameters
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error: using function pointers as const generic parameters is forbidden
|
||||
--> $DIR/issue-71611.rs:5:21
|
||||
|
|
||||
LL | fn func<A, const F: fn(inner: A)>(outer: A) {
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0770`.
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
fn func<A, const F: fn(inner: A)>(outer: A) {
|
||||
//~^ ERROR: the type of const parameters must not depend on other generic parameters
|
||||
//[min]~| ERROR: using function pointers as const generic parameters is forbidden
|
||||
F(outer);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ impl Opcode2 {
|
|||
pub fn example2(msg_type: Opcode2) -> impl FnMut(&[u8]) {
|
||||
move |i| match msg_type {
|
||||
Opcode2::OP2 => unimplemented!(),
|
||||
//~^ ERROR: could not evaluate constant pattern
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,13 @@ help: you might be missing a type parameter
|
|||
LL | pub struct Opcode2<S>(&'a S);
|
||||
| +++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: could not evaluate constant pattern
|
||||
--> $DIR/ice-type-mismatch-when-copying-112824.rs:15:9
|
||||
|
|
||||
LL | Opcode2::OP2 => unimplemented!(),
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0261, E0412.
|
||||
For more information about an error, try `rustc --explain E0261`.
|
||||
|
|
|
@ -9,6 +9,9 @@ impl Provider for () {
|
|||
struct Holder<B> {
|
||||
inner: Box<dyn Provider<A = B>>,
|
||||
//~^ ERROR: missing generics for associated type
|
||||
//~| ERROR: missing generics for associated type
|
||||
//~| ERROR: missing generics for associated type
|
||||
//~| ERROR: the trait `Provider` cannot be made into an object
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -14,6 +14,57 @@ help: add missing lifetime argument
|
|||
LL | inner: Box<dyn Provider<A<'a> = B>>,
|
||||
| ++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error[E0107]: missing generics for associated type `Provider::A`
|
||||
--> $DIR/issue-71176.rs:10:27
|
||||
|
|
||||
LL | inner: Box<dyn Provider<A = B>>,
|
||||
| ^ expected 1 lifetime argument
|
||||
|
|
||||
note: associated type defined here, with 1 lifetime parameter: `'a`
|
||||
--> $DIR/issue-71176.rs:2:10
|
||||
|
|
||||
LL | type A<'a>;
|
||||
| ^ --
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
help: add missing lifetime argument
|
||||
|
|
||||
LL | inner: Box<dyn Provider<A<'a> = B>>,
|
||||
| ++++
|
||||
|
||||
For more information about this error, try `rustc --explain E0107`.
|
||||
error[E0107]: missing generics for associated type `Provider::A`
|
||||
--> $DIR/issue-71176.rs:10:27
|
||||
|
|
||||
LL | inner: Box<dyn Provider<A = B>>,
|
||||
| ^ expected 1 lifetime argument
|
||||
|
|
||||
note: associated type defined here, with 1 lifetime parameter: `'a`
|
||||
--> $DIR/issue-71176.rs:2:10
|
||||
|
|
||||
LL | type A<'a>;
|
||||
| ^ --
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
help: add missing lifetime argument
|
||||
|
|
||||
LL | inner: Box<dyn Provider<A<'a> = B>>,
|
||||
| ++++
|
||||
|
||||
error[E0038]: the trait `Provider` cannot be made into an object
|
||||
--> $DIR/issue-71176.rs:10:14
|
||||
|
|
||||
LL | inner: Box<dyn Provider<A = B>>,
|
||||
| ^^^^^^^^^^^^^^^^^^^ `Provider` cannot be made into an object
|
||||
|
|
||||
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>
|
||||
--> $DIR/issue-71176.rs:2:10
|
||||
|
|
||||
LL | trait Provider {
|
||||
| -------- this trait cannot be made into an object...
|
||||
LL | type A<'a>;
|
||||
| ^ ...because it contains the generic associated type `A`
|
||||
= help: consider moving `A` to another trait
|
||||
= help: only type `()` implements the trait, consider using it directly instead
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0038, E0107.
|
||||
For more information about an error, try `rustc --explain E0038`.
|
||||
|
|
|
@ -8,6 +8,9 @@ static FOO: (dyn AsRef<OsStr>, u8) = ("hello", 42);
|
|||
|
||||
const BAR: (&Path, [u8], usize) = ("hello", [], 42);
|
||||
//~^ ERROR cannot find type `Path` in this scope
|
||||
//~| ERROR the size for values of type `[u8]` cannot be known at compilation time
|
||||
//~| ERROR the size for values of type `[u8]` cannot be known at compilation time
|
||||
//~| ERROR mismatched types
|
||||
|
||||
static BAZ: ([u8], usize) = ([], 0);
|
||||
//~^ ERROR the size for values of type `[u8]` cannot be known at compilation time
|
||||
|
|
|
@ -21,7 +21,35 @@ LL + use std::path::Path;
|
|||
|
|
||||
|
||||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
||||
--> $DIR/issue-84108.rs:12:13
|
||||
--> $DIR/issue-84108.rs:9:12
|
||||
|
|
||||
LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `[u8]`
|
||||
= note: only the last element of a tuple may have a dynamically sized type
|
||||
|
||||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
||||
--> $DIR/issue-84108.rs:9:12
|
||||
|
|
||||
LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `[u8]`
|
||||
= note: only the last element of a tuple may have a dynamically sized type
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-84108.rs:9:45
|
||||
|
|
||||
LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
|
||||
| ^^ expected `[u8]`, found `[_; 0]`
|
||||
|
|
||||
= note: expected slice `[u8]`
|
||||
found array `[_; 0]`
|
||||
|
||||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
||||
--> $DIR/issue-84108.rs:15:13
|
||||
|
|
||||
LL | static BAZ: ([u8], usize) = ([], 0);
|
||||
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
@ -30,7 +58,7 @@ LL | static BAZ: ([u8], usize) = ([], 0);
|
|||
= note: only the last element of a tuple may have a dynamically sized type
|
||||
|
||||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
||||
--> $DIR/issue-84108.rs:12:13
|
||||
--> $DIR/issue-84108.rs:15:13
|
||||
|
|
||||
LL | static BAZ: ([u8], usize) = ([], 0);
|
||||
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
@ -40,7 +68,7 @@ LL | static BAZ: ([u8], usize) = ([], 0);
|
|||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-84108.rs:12:30
|
||||
--> $DIR/issue-84108.rs:15:30
|
||||
|
|
||||
LL | static BAZ: ([u8], usize) = ([], 0);
|
||||
| ^^ expected `[u8]`, found `[_; 0]`
|
||||
|
@ -48,7 +76,7 @@ LL | static BAZ: ([u8], usize) = ([], 0);
|
|||
= note: expected slice `[u8]`
|
||||
found array `[_; 0]`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0277, E0308, E0412.
|
||||
For more information about an error, try `rustc --explain E0277`.
|
||||
|
|
|
@ -2,9 +2,8 @@ struct S<'a>(&'a u8);
|
|||
fn foo() {}
|
||||
|
||||
// Paren generic args in AnonConst
|
||||
fn a() -> [u8; foo::()] {
|
||||
//~^ ERROR parenthesized type parameters may only be used with a `Fn` trait
|
||||
//~| ERROR mismatched types
|
||||
fn a() -> [u8; foo()] {
|
||||
//~^ ERROR mismatched types
|
||||
panic!()
|
||||
}
|
||||
|
||||
|
@ -26,5 +25,6 @@ fn d<const C: S>() {}
|
|||
trait Foo<'a> {}
|
||||
struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
|
||||
//~^ ERROR the type of const parameters must not depend on other generic parameters
|
||||
//~| ERROR `&dyn for<'a> Foo<'a>` is forbidden as the type of a const generic parameter
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/unusual-rib-combinations.rs:22:15
|
||||
--> $DIR/unusual-rib-combinations.rs:21:15
|
||||
|
|
||||
LL | fn d<const C: S>() {}
|
||||
| ^ expected named lifetime parameter
|
||||
|
||||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||
--> $DIR/unusual-rib-combinations.rs:27:22
|
||||
--> $DIR/unusual-rib-combinations.rs:26:22
|
||||
|
|
||||
LL | struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
|
||||
| ^^ the type must not depend on the parameter `'a`
|
||||
|
@ -13,25 +13,19 @@ LL | struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
|
|||
= note: lifetime parameters may not be used in the type of const parameters
|
||||
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/unusual-rib-combinations.rs:5:16
|
||||
|
|
||||
LL | fn a() -> [u8; foo::()] {
|
||||
| ^^^^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/unusual-rib-combinations.rs:12:15
|
||||
--> $DIR/unusual-rib-combinations.rs:11:15
|
||||
|
|
||||
LL | fn b<const C: u8()>() {}
|
||||
| ^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error[E0214]: parenthesized type parameters may only be used with a `Fn` trait
|
||||
--> $DIR/unusual-rib-combinations.rs:16:10
|
||||
--> $DIR/unusual-rib-combinations.rs:15:10
|
||||
|
|
||||
LL | fn c<T = u8()>() {}
|
||||
| ^^^^ only `Fn` traits may use parentheses
|
||||
|
||||
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
|
||||
--> $DIR/unusual-rib-combinations.rs:16:6
|
||||
--> $DIR/unusual-rib-combinations.rs:15:6
|
||||
|
|
||||
LL | fn c<T = u8()>() {}
|
||||
| ^^^^^^^^
|
||||
|
@ -43,14 +37,11 @@ LL | fn c<T = u8()>() {}
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/unusual-rib-combinations.rs:5:16
|
||||
|
|
||||
LL | fn a() -> [u8; foo::()] {
|
||||
| ^^^^^^^ expected `usize`, found fn item
|
||||
|
|
||||
= note: expected type `usize`
|
||||
found fn item `fn() {foo}`
|
||||
LL | fn a() -> [u8; foo()] {
|
||||
| ^^^^^ expected `usize`, found `()`
|
||||
|
||||
error: `S<'_>` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/unusual-rib-combinations.rs:22:15
|
||||
--> $DIR/unusual-rib-combinations.rs:21:15
|
||||
|
|
||||
LL | fn d<const C: S>() {}
|
||||
| ^
|
||||
|
@ -61,6 +52,18 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
|||
LL + #![feature(adt_const_params)]
|
||||
|
|
||||
|
||||
error: `&dyn for<'a> Foo<'a>` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/unusual-rib-combinations.rs:26:21
|
||||
|
|
||||
LL | struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
||||
|
|
||||
LL + #![feature(adt_const_params)]
|
||||
|
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0106, E0214, E0308, E0770.
|
||||
|
|
|
@ -5,3 +5,4 @@ struct Apple((Apple, Option(Banana ? Citron)));
|
|||
//~| ERROR expected one of `)` or `,`, found `Citron`
|
||||
//~| ERROR cannot find type `Citron` in this scope [E0412]
|
||||
//~| ERROR parenthesized type parameters may only be used with a `Fn` trait [E0214]
|
||||
//~| ERROR `Apple` has infinite size
|
||||
|
|
|
@ -34,7 +34,18 @@ help: use angle brackets instead
|
|||
LL | struct Apple((Apple, Option<Banana ? Citron>));
|
||||
| ~ ~
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error[E0072]: recursive type `Apple` has infinite size
|
||||
--> $DIR/issue-103748-ICE-wrong-braces.rs:3:1
|
||||
|
|
||||
LL | struct Apple((Apple, Option(Banana ? Citron)));
|
||||
| ^^^^^^^^^^^^ ----- recursive without indirection
|
||||
|
|
||||
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
||||
|
|
||||
LL | struct Apple((Box<Apple>, Option(Banana ? Citron)));
|
||||
| ++++ +
|
||||
|
||||
Some errors have detailed explanations: E0214, E0412.
|
||||
For more information about an error, try `rustc --explain E0214`.
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0072, E0214, E0412.
|
||||
For more information about an error, try `rustc --explain E0072`.
|
||||
|
|
Loading…
Reference in New Issue