From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/cross/cross-borrow-trait.rs | 13 +++++++++ tests/ui/cross/cross-borrow-trait.stderr | 14 ++++++++++ .../auxiliary/extern_macro_crate.rs | 13 +++++++++ tests/ui/cross/cross-crate-macro-backtrace/main.rs | 8 ++++++ .../cross/cross-crate-macro-backtrace/main.stderr | 10 +++++++ tests/ui/cross/cross-file-errors/main.rs | 7 +++++ tests/ui/cross/cross-file-errors/main.stderr | 15 +++++++++++ tests/ui/cross/cross-file-errors/underscore.rs | 10 +++++++ tests/ui/cross/cross-fn-cache-hole.rs | 31 ++++++++++++++++++++++ tests/ui/cross/cross-fn-cache-hole.stderr | 12 +++++++++ 10 files changed, 133 insertions(+) create mode 100644 tests/ui/cross/cross-borrow-trait.rs create mode 100644 tests/ui/cross/cross-borrow-trait.stderr create mode 100644 tests/ui/cross/cross-crate-macro-backtrace/auxiliary/extern_macro_crate.rs create mode 100644 tests/ui/cross/cross-crate-macro-backtrace/main.rs create mode 100644 tests/ui/cross/cross-crate-macro-backtrace/main.stderr create mode 100644 tests/ui/cross/cross-file-errors/main.rs create mode 100644 tests/ui/cross/cross-file-errors/main.stderr create mode 100644 tests/ui/cross/cross-file-errors/underscore.rs create mode 100644 tests/ui/cross/cross-fn-cache-hole.rs create mode 100644 tests/ui/cross/cross-fn-cache-hole.stderr (limited to 'tests/ui/cross') 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` 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 = Box::new(Foo); + let _y: &dyn Trait = x; //~ ERROR E0308 + //~| expected reference `&dyn Trait` + //~| found struct `Box` +} 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` + +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` pending #48214 + +trait Foo: Bar { +} + +trait Bar { } + +// We don't always check where clauses for sanity, but in this case +// wfcheck does report an error here: +fn vacuous() + where i32: Foo //~ ERROR the trait bound `i32: Bar` 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::(); +} + +fn require() + where A: Bar +{ +} + +fn main() { + require::(); +} 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` is not satisfied + --> $DIR/cross-fn-cache-hole.rs:16:11 + | +LL | where i32: Foo + | ^^^^^^^^^^^^^^^^ the trait `Bar` 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`. -- cgit v1.2.3