diff options
Diffstat (limited to 'src')
11 files changed, 187 insertions, 29 deletions
diff --git a/src/test/ui/allocator/not-an-allocator.stderr b/src/test/ui/allocator/not-an-allocator.stderr index e7a9ce94af4..c0f6118a9f1 100644 --- a/src/test/ui/allocator/not-an-allocator.stderr +++ b/src/test/ui/allocator/not-an-allocator.stderr @@ -1,40 +1,40 @@ error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied - --> $DIR/not-an-allocator.rs:2:1 + --> $DIR/not-an-allocator.rs:2:11 | LL | #[global_allocator] | ------------------- in this procedural macro expansion LL | static A: usize = 0; - | ^^^^^^^^^^^^^^^^^^^^ the trait `GlobalAlloc` is not implemented for `usize` + | ^^^^^ the trait `GlobalAlloc` is not implemented for `usize` | = note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied - --> $DIR/not-an-allocator.rs:2:1 + --> $DIR/not-an-allocator.rs:2:11 | LL | #[global_allocator] | ------------------- in this procedural macro expansion LL | static A: usize = 0; - | ^^^^^^^^^^^^^^^^^^^^ the trait `GlobalAlloc` is not implemented for `usize` + | ^^^^^ the trait `GlobalAlloc` is not implemented for `usize` | = note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied - --> $DIR/not-an-allocator.rs:2:1 + --> $DIR/not-an-allocator.rs:2:11 | LL | #[global_allocator] | ------------------- in this procedural macro expansion LL | static A: usize = 0; - | ^^^^^^^^^^^^^^^^^^^^ the trait `GlobalAlloc` is not implemented for `usize` + | ^^^^^ the trait `GlobalAlloc` is not implemented for `usize` | = note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied - --> $DIR/not-an-allocator.rs:2:1 + --> $DIR/not-an-allocator.rs:2:11 | LL | #[global_allocator] | ------------------- in this procedural macro expansion LL | static A: usize = 0; - | ^^^^^^^^^^^^^^^^^^^^ the trait `GlobalAlloc` is not implemented for `usize` + | ^^^^^ the trait `GlobalAlloc` is not implemented for `usize` | = note: this error originates in the attribute macro `global_allocator` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/generic-associated-types/issue-74824.rs b/src/test/ui/generic-associated-types/issue-74824.rs index 1bbf7aac5cd..01f99fa4487 100644 --- a/src/test/ui/generic-associated-types/issue-74824.rs +++ b/src/test/ui/generic-associated-types/issue-74824.rs @@ -17,6 +17,7 @@ impl<T> UnsafeCopy for T {} fn main() { let b = Box::new(42usize); let copy = <()>::copy(&b); + //~^ type annotations needed let raw_b = Box::deref(&b) as *const _; let raw_copy = Box::deref(©) as *const _; diff --git a/src/test/ui/generic-associated-types/issue-74824.stderr b/src/test/ui/generic-associated-types/issue-74824.stderr index 8517eb9fa21..e7ebf5964ba 100644 --- a/src/test/ui/generic-associated-types/issue-74824.stderr +++ b/src/test/ui/generic-associated-types/issue-74824.stderr @@ -27,6 +27,13 @@ help: consider restricting type parameter `T` LL | type Copy<T: std::clone::Clone>: Copy = Box<T>; | +++++++++++++++++++ -error: aborting due to 2 previous errors +error[E0282]: type annotations needed + --> $DIR/issue-74824.rs:19:16 + | +LL | let copy = <()>::copy(&b); + | ^^^^^^^^^^ cannot infer type for type parameter `T` declared on the associated function `copy` + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0277`. +Some errors have detailed explanations: E0277, E0282. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/generic-associated-types/issue-91762.rs b/src/test/ui/generic-associated-types/issue-91762.rs new file mode 100644 index 00000000000..b259a3c6e06 --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-91762.rs @@ -0,0 +1,30 @@ +// check-fail + +// FIXME(generic_associated_types): We almost certaintly want this to pass, but +// it's particularly difficult currently, because we need a way of specifying +// that `<Self::Base as Functor>::With<T> = Self` without using that when we have +// a `U`. See `https://github.com/rust-lang/rust/pull/92728` for a (hacky) +// solution. This might be better to just wait for Chalk. + +#![feature(generic_associated_types)] + +pub trait Functor { + type With<T>; + + fn fmap<T, U>(this: Self::With<T>) -> Self::With<U>; +} + +pub trait FunctorExt<T>: Sized { + type Base: Functor<With<T> = Self>; + + fn fmap<U>(self) { + let arg: <Self::Base as Functor>::With<T>; + let ret: <Self::Base as Functor>::With<U>; + + arg = self; + ret = <Self::Base as Functor>::fmap(arg); + //~^ type annotations needed + } +} + +fn main() {} diff --git a/src/test/ui/generic-associated-types/issue-91762.stderr b/src/test/ui/generic-associated-types/issue-91762.stderr new file mode 100644 index 00000000000..a9c465cdd7e --- /dev/null +++ b/src/test/ui/generic-associated-types/issue-91762.stderr @@ -0,0 +1,9 @@ +error[E0282]: type annotations needed + --> $DIR/issue-91762.rs:25:15 + | +LL | ret = <Self::Base as Functor>::fmap(arg); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the associated function `fmap` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.rs b/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.rs new file mode 100644 index 00000000000..d9de73a38ef --- /dev/null +++ b/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.rs @@ -0,0 +1,51 @@ +// A test exploiting the bug behind #25860 except with +// implied trait bounds which currently don't exist without `-Zchalk`. +use std::marker::PhantomData; +struct Foo<'a, 'b, T>(PhantomData<(&'a (), &'b (), T)>) +where + T: Convert<'a, 'b>; + +trait Convert<'a, 'b>: Sized { + fn cast(&'a self) -> &'b Self; +} +impl<'long: 'short, 'short, T> Convert<'long, 'short> for T { + fn cast(&'long self) -> &'short T { + self + } +} + +// This function will compile once we add implied trait bounds. +// +// If we're not careful with our impl, the transformations +// in `bad` would succeed, which is unsound ✨ +// +// FIXME: the error is pretty bad, this should say +// +// `T: Convert<'in_, 'out>` is not implemented +// +// help: needed by `Foo<'in_, 'out, T>` +// +// Please ping @lcnr if your changes end up causing `badboi` to compile. +fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ T) -> &'out T { + //~^ ERROR lifetime mismatch + sadness.cast() +} + +fn bad<'short, T>(value: &'short T) -> &'static T { + let x: for<'in_, 'out> fn(Foo<'in_, 'out, T>, &'in_ T) -> &'out T = badboi; + let x: for<'out> fn(Foo<'short, 'out, T>, &'short T) -> &'out T = x; + let x: for<'out> fn(Foo<'static, 'out, T>, &'short T) -> &'out T = x; + let x: fn(Foo<'static, 'static, T>, &'short T) -> &'static T = x; + x(Foo(PhantomData), value) +} + +// Use `bad` to cause a segfault. +fn main() { + let mut outer: Option<&'static u32> = Some(&3); + let static_ref: &'static &'static u32 = match outer { + Some(ref reference) => bad(reference), + None => unreachable!(), + }; + outer = None; + println!("{}", static_ref); +} diff --git a/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.stderr b/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.stderr new file mode 100644 index 00000000000..b020ea64bf4 --- /dev/null +++ b/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-guard.stderr @@ -0,0 +1,12 @@ +error[E0623]: lifetime mismatch + --> $DIR/hrlt-implied-trait-bounds-guard.rs:29:29 + | +LL | fn badboi<'in_, 'out, T>(x: Foo<'in_, 'out, T>, sadness: &'in_ T) -> &'out T { + | ^^^^^^^^^^^^^^^^^^ ------- + | | + | this parameter and the return type are declared with different lifetimes... + | ...but data from `x` is returned here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0623`. diff --git a/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-roundtrip.rs b/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-roundtrip.rs new file mode 100644 index 00000000000..69847d6a8bb --- /dev/null +++ b/src/test/ui/implied-bounds/hrlt-implied-trait-bounds-roundtrip.rs @@ -0,0 +1,35 @@ +// check-pass +struct Foo<'a>(&'a ()) +where + (): Trait<'a>; + +trait Trait<'a> { + fn id<T>(value: &'a T) -> &'static T; +} + +impl Trait<'static> for () { + fn id<T>(value: &'static T) -> &'static T { + value + } +} + +fn could_use_implied_bounds<'a, T>(_: Foo<'a>, x: &'a T) -> &'static T +where + (): Trait<'a>, // This could be an implied bound +{ + <()>::id(x) +} + +fn main() { + let bar: for<'a, 'b> fn(Foo<'a>, &'b ()) = |_, _| {}; + + // If `could_use_implied_bounds` were to use implied bounds, + // keeping 'a late-bound, then we could assign that function + // to this variable. + let bar: for<'a> fn(Foo<'a>, &'a ()) = bar; + + // In this case, the subtyping relation here would be unsound, + // allowing us to transmute lifetimes. This currently compiles + // because we incorrectly deal with implied bounds inside of binders. + let _bar: for<'a, 'b> fn(Foo<'a>, &'b ()) = bar; +} diff --git a/src/test/ui/inference/char-as-str-multi.rs b/src/test/ui/inference/char-as-str-multi.rs index 21bbc6f20b2..c29a15025a9 100644 --- a/src/test/ui/inference/char-as-str-multi.rs +++ b/src/test/ui/inference/char-as-str-multi.rs @@ -1,6 +1,7 @@ -// When a MULTI-character string literal is used where a char should be, +// When a MULTI/NO-character string literal is used where a char should be, // DO NOT suggest changing to single quotes. fn main() { let _: char = "foo"; //~ ERROR mismatched types + let _: char = ""; //~ ERROR mismatched types } diff --git a/src/test/ui/inference/char-as-str-multi.stderr b/src/test/ui/inference/char-as-str-multi.stderr index c3ba17a5579..297ca2b548f 100644 --- a/src/test/ui/inference/char-as-str-multi.stderr +++ b/src/test/ui/inference/char-as-str-multi.stderr @@ -6,6 +6,14 @@ LL | let _: char = "foo"; | | | expected due to this -error: aborting due to previous error +error[E0308]: mismatched types + --> $DIR/char-as-str-multi.rs:6:19 + | +LL | let _: char = ""; + | ---- ^^ expected `char`, found `&str` + | | + | expected due to this + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/src/tools/rust-analyzer b/src/tools/rust-analyzer -Subproject 9700addc82111200a2150b9a796f62dd8e600dd +Subproject ba330548023607717295f0dfd61b72eda41aa9d |
