diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/cross | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/cross')
-rw-r--r-- | tests/ui/cross/cross-borrow-trait.rs | 13 | ||||
-rw-r--r-- | tests/ui/cross/cross-borrow-trait.stderr | 14 | ||||
-rw-r--r-- | tests/ui/cross/cross-crate-macro-backtrace/auxiliary/extern_macro_crate.rs | 13 | ||||
-rw-r--r-- | tests/ui/cross/cross-crate-macro-backtrace/main.rs | 8 | ||||
-rw-r--r-- | tests/ui/cross/cross-crate-macro-backtrace/main.stderr | 10 | ||||
-rw-r--r-- | tests/ui/cross/cross-file-errors/main.rs | 7 | ||||
-rw-r--r-- | tests/ui/cross/cross-file-errors/main.stderr | 15 | ||||
-rw-r--r-- | tests/ui/cross/cross-file-errors/underscore.rs | 10 | ||||
-rw-r--r-- | tests/ui/cross/cross-fn-cache-hole.rs | 31 | ||||
-rw-r--r-- | tests/ui/cross/cross-fn-cache-hole.stderr | 12 |
10 files changed, 133 insertions, 0 deletions
diff --git a/tests/ui/cross/cross-borrow-trait.rs b/tests/ui/cross/cross-borrow-trait.rs new file mode 100644 index 000000000..180a75e3d --- /dev/null +++ b/tests/ui/cross/cross-borrow-trait.rs @@ -0,0 +1,13 @@ +// Test that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is +// forbidden when `T` is a trait. + +struct Foo; +trait Trait { fn foo(&self) {} } +impl Trait for Foo {} + +pub fn main() { + let x: Box<dyn Trait> = Box::new(Foo); + let _y: &dyn Trait = x; //~ ERROR E0308 + //~| expected reference `&dyn Trait` + //~| found struct `Box<dyn Trait>` +} diff --git a/tests/ui/cross/cross-borrow-trait.stderr b/tests/ui/cross/cross-borrow-trait.stderr new file mode 100644 index 000000000..81f309eae --- /dev/null +++ b/tests/ui/cross/cross-borrow-trait.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/cross-borrow-trait.rs:10:26 + | +LL | let _y: &dyn Trait = x; + | ---------- ^ expected `&dyn Trait`, found struct `Box` + | | + | expected due to this + | + = note: expected reference `&dyn Trait` + found struct `Box<dyn Trait>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/cross/cross-crate-macro-backtrace/auxiliary/extern_macro_crate.rs b/tests/ui/cross/cross-crate-macro-backtrace/auxiliary/extern_macro_crate.rs new file mode 100644 index 000000000..fbda3dbe9 --- /dev/null +++ b/tests/ui/cross/cross-crate-macro-backtrace/auxiliary/extern_macro_crate.rs @@ -0,0 +1,13 @@ +#![crate_type = "dylib"] + +pub fn print(_args: std::fmt::Arguments) {} + +#[macro_export] +macro_rules! myprint { + ($($arg:tt)*) => ($crate::print(format_args!($($arg)*))); +} + +#[macro_export] +macro_rules! myprintln { + ($fmt:expr) => (myprint!(concat!($fmt, "\n"))); +} diff --git a/tests/ui/cross/cross-crate-macro-backtrace/main.rs b/tests/ui/cross/cross-crate-macro-backtrace/main.rs new file mode 100644 index 000000000..f7d4330ab --- /dev/null +++ b/tests/ui/cross/cross-crate-macro-backtrace/main.rs @@ -0,0 +1,8 @@ +// aux-build:extern_macro_crate.rs +#[macro_use(myprintln, myprint)] +extern crate extern_macro_crate; + +fn main() { + myprintln!("{}"); + //~^ ERROR in format string +} diff --git a/tests/ui/cross/cross-crate-macro-backtrace/main.stderr b/tests/ui/cross/cross-crate-macro-backtrace/main.stderr new file mode 100644 index 000000000..5bd4ea97e --- /dev/null +++ b/tests/ui/cross/cross-crate-macro-backtrace/main.stderr @@ -0,0 +1,10 @@ +error: 1 positional argument in format string, but no arguments were given + --> $DIR/main.rs:6:5 + | +LL | myprintln!("{}"); + | ^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `concat` which comes from the expansion of the macro `myprintln` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + diff --git a/tests/ui/cross/cross-file-errors/main.rs b/tests/ui/cross/cross-file-errors/main.rs new file mode 100644 index 000000000..4219f892d --- /dev/null +++ b/tests/ui/cross/cross-file-errors/main.rs @@ -0,0 +1,7 @@ +#[macro_use] +mod underscore; + +fn main() { + underscore!(); + //~^ ERROR `_` can only be used on the left-hand side of an assignment +} diff --git a/tests/ui/cross/cross-file-errors/main.stderr b/tests/ui/cross/cross-file-errors/main.stderr new file mode 100644 index 000000000..293a300ed --- /dev/null +++ b/tests/ui/cross/cross-file-errors/main.stderr @@ -0,0 +1,15 @@ +error: in expressions, `_` can only be used on the left-hand side of an assignment + --> $DIR/underscore.rs:8:9 + | +LL | _ + | ^ `_` not allowed here + | + ::: $DIR/main.rs:5:5 + | +LL | underscore!(); + | ------------- in this macro invocation + | + = note: this error originates in the macro `underscore` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + diff --git a/tests/ui/cross/cross-file-errors/underscore.rs b/tests/ui/cross/cross-file-errors/underscore.rs new file mode 100644 index 000000000..76e72a93f --- /dev/null +++ b/tests/ui/cross/cross-file-errors/underscore.rs @@ -0,0 +1,10 @@ +// We want this file only so we can test cross-file error +// messages, but we don't want it in an external crate. +// ignore-test +#![crate_type = "lib"] + +macro_rules! underscore { + () => ( + _ + ) +} diff --git a/tests/ui/cross/cross-fn-cache-hole.rs b/tests/ui/cross/cross-fn-cache-hole.rs new file mode 100644 index 000000000..c38a5001a --- /dev/null +++ b/tests/ui/cross/cross-fn-cache-hole.rs @@ -0,0 +1,31 @@ +// Check that when there are vacuous predicates in the environment +// (which make a fn uncallable) we don't erroneously cache those and +// then consider them satisfied elsewhere. The current technique for +// doing this is to not use global caches when there is a chance that +// the environment contains such a predicate. +// We still error for `i32: Bar<u32>` pending #48214 + +trait Foo<X,Y>: Bar<X> { +} + +trait Bar<X> { } + +// We don't always check where clauses for sanity, but in this case +// wfcheck does report an error here: +fn vacuous<A>() + where i32: Foo<u32, A> //~ ERROR the trait bound `i32: Bar<u32>` is not satisfied +{ + // ... the original intention was to check that we don't use that + // vacuous where clause (which could never be satisfied) to accept + // the following line and then mess up calls elsewhere. + require::<i32, u32>(); +} + +fn require<A,B>() + where A: Bar<B> +{ +} + +fn main() { + require::<i32, u32>(); +} diff --git a/tests/ui/cross/cross-fn-cache-hole.stderr b/tests/ui/cross/cross-fn-cache-hole.stderr new file mode 100644 index 000000000..7e15562b0 --- /dev/null +++ b/tests/ui/cross/cross-fn-cache-hole.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `i32: Bar<u32>` is not satisfied + --> $DIR/cross-fn-cache-hole.rs:16:11 + | +LL | where i32: Foo<u32, A> + | ^^^^^^^^^^^^^^^^ the trait `Bar<u32>` is not implemented for `i32` + | + = help: see issue #48214 + = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. |