diff options
Diffstat (limited to 'tests')
18 files changed, 275 insertions, 23 deletions
diff --git a/tests/rustdoc/issue-108231.rs b/tests/rustdoc/issue-108231.rs new file mode 100644 index 00000000000..684f0494fd5 --- /dev/null +++ b/tests/rustdoc/issue-108231.rs @@ -0,0 +1,23 @@ +// Regression test for <https://github.com/rust-lang/rust/issues/108231>. +// Macros with `#[macro_export]` attribute should be visible at the top level +// even if they are inside a doc hidden item. + +#![crate_name = "foo"] + +// @has 'foo/index.html' +// @count - '//*[@id="main-content"]//a[@class="macro"]' 1 +// @has - '//*[@id="main-content"]//a[@class="macro"]' 'foo' + +#[doc(hidden)] +pub mod __internal { + /// This one should be visible. + #[macro_export] + macro_rules! foo { + () => {}; + } + + /// This one should be hidden. + macro_rules! bar { + () => {}; + } +} diff --git a/tests/rustdoc/reexport-hidden-macro.rs b/tests/rustdoc/reexport-hidden-macro.rs new file mode 100644 index 00000000000..afcfa979616 --- /dev/null +++ b/tests/rustdoc/reexport-hidden-macro.rs @@ -0,0 +1,22 @@ +// Ensure that inlined reexport of hidden macros is working as expected. +// Part of <https://github.com/rust-lang/rust/issues/59368>. + +#![crate_name = "foo"] + +// @has 'foo/index.html' +// @has - '//*[@id="main-content"]//a[@href="macro.Macro2.html"]' 'Macro2' + +// @has 'foo/macro.Macro2.html' +// @has - '//*[@class="docblock"]' 'Displayed' + +#[macro_export] +#[doc(hidden)] +macro_rules! foo { + () => {}; +} + +/// not displayed +pub use crate::foo as Macro; +/// Displayed +#[doc(inline)] +pub use crate::foo as Macro2; diff --git a/tests/ui/check-cfg/invalid-cfg-value.stderr b/tests/ui/check-cfg/invalid-cfg-value.stderr index 60abcb18824..83383ea61a4 100644 --- a/tests/ui/check-cfg/invalid-cfg-value.stderr +++ b/tests/ui/check-cfg/invalid-cfg-value.stderr @@ -2,7 +2,9 @@ warning: unexpected `cfg` condition value --> $DIR/invalid-cfg-value.rs:7:7 | LL | #[cfg(feature = "sedre")] - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^------- + | | + | help: did you mean: `"serde"` | = note: expected values for `feature` are: full, serde = note: `#[warn(unexpected_cfgs)]` on by default diff --git a/tests/ui/const-generics/early/invalid-const-arguments.stderr b/tests/ui/const-generics/early/invalid-const-arguments.stderr index b46e7e24f49..cee34e3b715 100644 --- a/tests/ui/const-generics/early/invalid-const-arguments.stderr +++ b/tests/ui/const-generics/early/invalid-const-arguments.stderr @@ -49,12 +49,9 @@ error[E0747]: type provided when a constant was expected --> $DIR/invalid-const-arguments.rs:10:19 | LL | impl<N> Foo for B<N> {} - | ^ - | -help: consider changing this type parameter to be a `const` generic - | -LL | impl<const N: u8> Foo for B<N> {} - | ~~~~~~~~~~~ + | - ^ + | | + | help: consider changing this type parameter to a const parameter: `const N: u8` error[E0747]: unresolved item provided when a constant was expected --> $DIR/invalid-const-arguments.rs:14:32 diff --git a/tests/ui/did_you_mean/println-typo.rs b/tests/ui/did_you_mean/println-typo.rs new file mode 100644 index 00000000000..685b5e1f284 --- /dev/null +++ b/tests/ui/did_you_mean/println-typo.rs @@ -0,0 +1,6 @@ +// https://internals.rust-lang.org/t/18227 + +fn main() { + prinltn!(); //~ ERROR cannot find macro `prinltn` in this scope + //^ a macro with a similar name exists: `println` +} diff --git a/tests/ui/did_you_mean/println-typo.stderr b/tests/ui/did_you_mean/println-typo.stderr new file mode 100644 index 00000000000..43b7b1894e2 --- /dev/null +++ b/tests/ui/did_you_mean/println-typo.stderr @@ -0,0 +1,11 @@ +error: cannot find macro `prinltn` in this scope + --> $DIR/println-typo.rs:4:5 + | +LL | prinltn!(); + | ^^^^^^^ help: a macro with a similar name exists: `println` + --> $SRC_DIR/std/src/macros.rs:LL:COL + | + = note: similarly named macro `println` defined here + +error: aborting due to previous error + diff --git a/tests/ui/errors/traits/blame-trait-error-spans-on-exprs.rs b/tests/ui/errors/traits/blame-trait-error-spans-on-exprs.rs index 2b75f432412..6fea409ed47 100644 --- a/tests/ui/errors/traits/blame-trait-error-spans-on-exprs.rs +++ b/tests/ui/errors/traits/blame-trait-error-spans-on-exprs.rs @@ -71,6 +71,8 @@ struct DoubleWrapper<T> { impl<T: T1> T1 for DoubleWrapper<T> {} +impl<'a, T: T2> T1 for &'a T {} + fn example<Q>(q: Q) { // In each of the following examples, we expect the error span to point at the 'q' variable, // since the missing constraint is `Q: T3`. @@ -126,6 +128,10 @@ fn example<Q>(q: Q) { Two { a: Two { a: (), b: Two { a: Two { a: (), b: q }, b: () } }, b: () }, //~^ ERROR the trait bound `Q: T1` is not satisfied [E0277] ); + + // Verifies for reference: + want(&Burrito { spicy: false, filling: q }); + //~^ ERROR the trait bound `Q: T3` is not satisfied [E0277] } fn main() {} diff --git a/tests/ui/errors/traits/blame-trait-error-spans-on-exprs.stderr b/tests/ui/errors/traits/blame-trait-error-spans-on-exprs.stderr index 5f87c670d8a..6913771f288 100644 --- a/tests/ui/errors/traits/blame-trait-error-spans-on-exprs.stderr +++ b/tests/ui/errors/traits/blame-trait-error-spans-on-exprs.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Q: T3` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:79:60 + --> $DIR/blame-trait-error-spans-on-exprs.rs:81:60 | LL | want(Wrapper { value: Burrito { spicy: false, filling: q } }); | ---- required by a bound introduced by this call ^ the trait `T3` is not implemented for `Q` @@ -29,7 +29,7 @@ LL | fn example<Q: T3>(q: Q) { | ++++ error[E0277]: the trait bound `Q: T3` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:83:84 + --> $DIR/blame-trait-error-spans-on-exprs.rs:85:84 | LL | want(Wrapper { value: BurritoKinds::SmallBurrito { spicy: true, small_filling: q } }); | ---- required by a bound introduced by this call ^ the trait `T3` is not implemented for `Q` @@ -59,7 +59,7 @@ LL | fn example<Q: T3>(q: Q) { | ++++ error[E0277]: the trait bound `Q: T3` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:87:39 + --> $DIR/blame-trait-error-spans-on-exprs.rs:89:39 | LL | want(Wrapper { value: Taco(false, q) }); | ---- ^ the trait `T3` is not implemented for `Q` @@ -91,7 +91,7 @@ LL | fn example<Q: T3>(q: Q) { | ++++ error[E0277]: the trait bound `Q: T3` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:91:27 + --> $DIR/blame-trait-error-spans-on-exprs.rs:93:27 | LL | want(Wrapper { value: TacoKinds::OneTaco(false, q) }); | ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `T3` is not implemented for `Q` @@ -123,7 +123,7 @@ LL | fn example<Q: T3>(q: Q) { | ++++ error[E0277]: the trait bound `Q: T3` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:95:74 + --> $DIR/blame-trait-error-spans-on-exprs.rs:97:74 | LL | want(Wrapper { value: GenericBurrito { spiciness: NotSpicy, filling: q } }); | ---- required by a bound introduced by this call ^ the trait `T3` is not implemented for `Q` @@ -153,7 +153,7 @@ LL | fn example<Q: T3>(q: Q) { | ++++ error[E0277]: the trait bound `Q: T2` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:99:14 + --> $DIR/blame-trait-error-spans-on-exprs.rs:101:14 | LL | want((3, q)); | ---- ^ the trait `T2` is not implemented for `Q` @@ -178,7 +178,7 @@ LL | fn example<Q: T2>(q: Q) { | ++++ error[E0277]: the trait bound `Q: T3` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:103:31 + --> $DIR/blame-trait-error-spans-on-exprs.rs:105:31 | LL | want(Wrapper { value: (3, q) }); | ---- ^ the trait `T3` is not implemented for `Q` @@ -210,7 +210,7 @@ LL | fn example<Q: T3>(q: Q) { | ++++ error[E0277]: the trait bound `Q: T3` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:107:15 + --> $DIR/blame-trait-error-spans-on-exprs.rs:109:15 | LL | want(((3, q), 5)); | ---- ^ the trait `T3` is not implemented for `Q` @@ -242,7 +242,7 @@ LL | fn example<Q: T3>(q: Q) { | ++++ error[E0277]: the trait bound `Q: T1` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:110:49 + --> $DIR/blame-trait-error-spans-on-exprs.rs:112:49 | LL | want(DoubleWrapper { item: Wrapper { value: q } }); | ---- ^ the trait `T1` is not implemented for `Q` @@ -267,7 +267,7 @@ LL | fn example<Q: T1>(q: Q) { | ++++ error[E0277]: the trait bound `Q: T1` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:113:88 + --> $DIR/blame-trait-error-spans-on-exprs.rs:115:88 | LL | want(DoubleWrapper { item: Wrapper { value: DoubleWrapper { item: Wrapper { value: q } } } }); | ---- required by a bound introduced by this call ^ the trait `T1` is not implemented for `Q` @@ -292,7 +292,7 @@ LL | fn example<Q: T1>(q: Q) { | ++++ error[E0277]: the trait bound `Q: T3` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:117:27 + --> $DIR/blame-trait-error-spans-on-exprs.rs:119:27 | LL | want(Wrapper { value: AliasBurrito { spiciness: q, filling: q } }); | ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `T3` is not implemented for `Q` @@ -324,7 +324,7 @@ LL | fn example<Q: T3>(q: Q) { | ++++ error[E0277]: the trait bound `Q: T1` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:120:35 + --> $DIR/blame-trait-error-spans-on-exprs.rs:122:35 | LL | want(Two { a: Two { a: (), b: q }, b: () }); | ---- ^ the trait `T1` is not implemented for `Q` @@ -349,7 +349,7 @@ LL | fn example<Q: T1>(q: Q) { | ++++ error[E0277]: the trait bound `Q: T1` is not satisfied - --> $DIR/blame-trait-error-spans-on-exprs.rs:126:59 + --> $DIR/blame-trait-error-spans-on-exprs.rs:128:59 | LL | want( | ---- required by a bound introduced by this call @@ -375,6 +375,38 @@ help: consider restricting type parameter `Q` LL | fn example<Q: T1>(q: Q) { | ++++ -error: aborting due to 13 previous errors +error[E0277]: the trait bound `Q: T3` is not satisfied + --> $DIR/blame-trait-error-spans-on-exprs.rs:133:44 + | +LL | want(&Burrito { spicy: false, filling: q }); + | ---- ^ the trait `T3` is not implemented for `Q` + | | + | required by a bound introduced by this call + | +note: required for `Burrito<Q>` to implement `T2` + --> $DIR/blame-trait-error-spans-on-exprs.rs:22:13 + | +LL | impl<A: T3> T2 for Burrito<A> {} + | -- ^^ ^^^^^^^^^^ + | | + | unsatisfied trait bound introduced here +note: required for `&Burrito<Q>` to implement `T1` + --> $DIR/blame-trait-error-spans-on-exprs.rs:74:17 + | +LL | impl<'a, T: T2> T1 for &'a T {} + | -- ^^ ^^^^^ + | | + | unsatisfied trait bound introduced here +note: required by a bound in `want` + --> $DIR/blame-trait-error-spans-on-exprs.rs:53:12 + | +LL | fn want<V: T1>(_x: V) {} + | ^^ required by this bound in `want` +help: consider restricting type parameter `Q` + | +LL | fn example<Q: T3>(q: Q) { + | ++++ + +error: aborting due to 14 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/mir/field-projection-invariant.rs b/tests/ui/mir/field-projection-invariant.rs new file mode 100644 index 00000000000..b5d6add043c --- /dev/null +++ b/tests/ui/mir/field-projection-invariant.rs @@ -0,0 +1,24 @@ +// build-pass +struct Inv<'a>(&'a mut &'a ()); +enum Foo<T> { + Bar, + Var(T), +} +type Supertype = Foo<for<'a> fn(Inv<'a>, Inv<'a>)>; + +fn foo(x: Foo<for<'a, 'b> fn(Inv<'a>, Inv<'b>)>) { + match x { + Supertype::Bar => {} + Supertype::Var(x) => {} + } +} + +fn foo_nested(x: Foo<Foo<for<'a, 'b> fn(Inv<'a>, Inv<'b>)>>) { + match x { + Foo::Bar => {} + Foo::Var(Supertype::Bar) => {} + Foo::Var(Supertype::Var(x)) => {} + } +} + +fn main() {} diff --git a/tests/ui/mir/field-projection-mutating-context.rs b/tests/ui/mir/field-projection-mutating-context.rs new file mode 100644 index 00000000000..a1002c088dc --- /dev/null +++ b/tests/ui/mir/field-projection-mutating-context.rs @@ -0,0 +1,19 @@ +use std::sync::Mutex; + +static GLOBAL: Mutex<&'static str> = Mutex::new("global str"); + +struct Foo<T>(T); // `T` is covariant. + +fn foo() { + let mut x: Foo<for<'a> fn(&'a str)> = Foo(|_| ()); + let Foo(ref mut y): Foo<fn(&'static str)> = x; + //~^ ERROR mismatched types + *y = |s| *GLOBAL.lock().unwrap() = s; + let string = String::from("i am shortlived"); + (x.0)(&string); +} + +fn main() { + foo(); + println!("{}", GLOBAL.lock().unwrap()); +} diff --git a/tests/ui/mir/field-projection-mutating-context.stderr b/tests/ui/mir/field-projection-mutating-context.stderr new file mode 100644 index 00000000000..9b18b3427ad --- /dev/null +++ b/tests/ui/mir/field-projection-mutating-context.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/field-projection-mutating-context.rs:9:13 + | +LL | let Foo(ref mut y): Foo<fn(&'static str)> = x; + | ^^^^^^^^^ one type is more general than the other + | + = note: expected fn pointer `for<'a> fn(&'a str)` + found fn pointer `fn(&str)` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/mir/field-projection-mutating-context2.rs b/tests/ui/mir/field-projection-mutating-context2.rs new file mode 100644 index 00000000000..dd9c44a16d3 --- /dev/null +++ b/tests/ui/mir/field-projection-mutating-context2.rs @@ -0,0 +1,17 @@ +use std::sync::Mutex; + +static GLOBAL: Mutex<&'static str> = Mutex::new("global str"); + +struct Foo<T>(T); // `T` is covariant. + +fn foo<'a>(mut x: Foo<fn(&'a str)>, string: &'a str) { + let Foo(ref mut y): Foo<fn(&'static str)> = x; + //~^ ERROR lifetime may not live long enough + *y = |s| *GLOBAL.lock().unwrap() = s; + (x.0)(&string); +} + +fn main() { + foo(Foo(|_| ()), &String::from("i am shortlived")); + println!("{}", GLOBAL.lock().unwrap()); +} diff --git a/tests/ui/mir/field-projection-mutating-context2.stderr b/tests/ui/mir/field-projection-mutating-context2.stderr new file mode 100644 index 00000000000..a7b66fe10ce --- /dev/null +++ b/tests/ui/mir/field-projection-mutating-context2.stderr @@ -0,0 +1,10 @@ +error: lifetime may not live long enough + --> $DIR/field-projection-mutating-context2.rs:8:25 + | +LL | fn foo<'a>(mut x: Foo<fn(&'a str)>, string: &'a str) { + | -- lifetime `'a` defined here +LL | let Foo(ref mut y): Foo<fn(&'static str)> = x; + | ^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` + +error: aborting due to previous error + diff --git a/tests/ui/mir/field-ty-ascription-enums.rs b/tests/ui/mir/field-ty-ascription-enums.rs new file mode 100644 index 00000000000..179af617090 --- /dev/null +++ b/tests/ui/mir/field-ty-ascription-enums.rs @@ -0,0 +1,15 @@ +// build-pass + +enum Foo<T> { + Var(T), +} // `T` is covariant. + +fn foo<'b>(x: Foo<for<'a> fn(&'a ())>) { + let Foo::Var(x): Foo<fn(&'b ())> = x; +} + +fn foo_nested<'b>(x: Foo<Foo<for<'a> fn(&'a ())>>) { + let Foo::Var(Foo::Var(x)): Foo<Foo<fn(&'b ())>> = x; +} + +fn main() {} diff --git a/tests/ui/mir/field-ty-ascription.rs b/tests/ui/mir/field-ty-ascription.rs new file mode 100644 index 00000000000..178c7916bc5 --- /dev/null +++ b/tests/ui/mir/field-ty-ascription.rs @@ -0,0 +1,37 @@ +// build-pass + +struct Foo<T>(T); // `T` is covariant. + +struct Bar<T> { + x: T, +} // `T` is covariant. + +fn bar<'b>(x: Bar<for<'a> fn(&'a ())>) { + let Bar { x }: Bar<fn(&'b ())> = x; +} + +fn bar_nested<'b>(x: Bar<Bar<for<'a> fn(&'a ())>>) { + let Bar { x: Bar { x } }: Bar<Bar<fn(&'b ())>> = x; +} + +fn bar_foo_nested<'b>(x: Bar<Foo<for<'a> fn(&'a ())>>) { + let Bar { x: Foo ( x ) }: Bar<Foo<fn(&'b ())>> = x; +} + +fn foo<'b>(x: Foo<for<'a> fn(&'a ())>) { + let Foo(y): Foo<fn(&'b ())> = x; +} + +fn foo_nested<'b>(x: Foo<Foo<for<'a> fn(&'a ())>>) { + let Foo(Foo(y)): Foo<Foo<fn(&'b ())>> = x; +} + +fn tuple<'b>(x: (u32, for<'a> fn(&'a ()))) { + let (_, y): (u32, fn(&'b ())) = x; +} + +fn tuple_nested<'b>(x: (u32, (u32, for<'a> fn(&'a ())))) { + let (_, (_, y)): (u32, (u32, fn(&'b ()))) = x; +} + +fn main() {} diff --git a/tests/ui/recursion_limit/issue_21102.rs b/tests/ui/recursion_limit/issue_21102.rs new file mode 100644 index 00000000000..e1fee46313d --- /dev/null +++ b/tests/ui/recursion_limit/issue_21102.rs @@ -0,0 +1,9 @@ +#![recursion_limit="4"] +#![invalid_attribute] +#![invalid_attribute] +#![invalid_attribute] +#![invalid_attribute] +#![invalid_attribute] +//~^ERROR recursion limit reached while expanding + +fn main() {} diff --git a/tests/ui/recursion_limit/issue_21102.stderr b/tests/ui/recursion_limit/issue_21102.stderr new file mode 100644 index 00000000000..1bd722c492b --- /dev/null +++ b/tests/ui/recursion_limit/issue_21102.stderr @@ -0,0 +1,10 @@ +error: recursion limit reached while expanding `#[invalid_attribute]` + --> $DIR/issue_21102.rs:6:1 + | +LL | #![invalid_attribute] + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "8"]` attribute to your crate (`issue_21102`) + +error: aborting due to previous error + diff --git a/tests/ui/traits/suggest-deferences/issue-39029.stderr b/tests/ui/traits/suggest-deferences/issue-39029.stderr index 49e20c6a76a..49105de3d69 100644 --- a/tests/ui/traits/suggest-deferences/issue-39029.stderr +++ b/tests/ui/traits/suggest-deferences/issue-39029.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied - --> $DIR/issue-39029.rs:16:37 + --> $DIR/issue-39029.rs:16:38 | LL | let _errors = TcpListener::bind(&bad); - | ----------------- ^^^^ the trait `ToSocketAddrs` is not implemented for `NoToSocketAddrs` + | ----------------- ^^^ the trait `ToSocketAddrs` is not implemented for `NoToSocketAddrs` | | | required by a bound introduced by this call | |
