From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/range/exclusive-range-patterns-2021.rs | 14 ++ .../ui/range/exclusive-range-patterns-2021.stderr | 27 +++ src/test/ui/range/issue-54505-no-literals.fixed | 75 +++++++ src/test/ui/range/issue-54505-no-literals.rs | 75 +++++++ src/test/ui/range/issue-54505-no-literals.stderr | 219 +++++++++++++++++++++ src/test/ui/range/issue-54505-no-std.rs | 56 ++++++ src/test/ui/range/issue-54505-no-std.stderr | 113 +++++++++++ src/test/ui/range/issue-54505.fixed | 43 ++++ src/test/ui/range/issue-54505.rs | 43 ++++ src/test/ui/range/issue-54505.stderr | 111 +++++++++++ .../range/issue-73553-misinterp-range-literal.rs | 16 ++ .../issue-73553-misinterp-range-literal.stderr | 39 ++++ src/test/ui/range/range-1.rs | 16 ++ src/test/ui/range/range-1.stderr | 42 ++++ .../range/range-inclusive-pattern-precedence.fixed | 21 ++ .../ui/range/range-inclusive-pattern-precedence.rs | 21 ++ .../range-inclusive-pattern-precedence.stderr | 22 +++ .../range/range-inclusive-pattern-precedence2.rs | 20 ++ .../range-inclusive-pattern-precedence2.stderr | 22 +++ src/test/ui/range/range_traits-1.rs | 25 +++ src/test/ui/range/range_traits-1.stderr | 141 +++++++++++++ src/test/ui/range/range_traits-2.rs | 6 + src/test/ui/range/range_traits-2.stderr | 13 ++ src/test/ui/range/range_traits-3.rs | 6 + src/test/ui/range/range_traits-3.stderr | 13 ++ src/test/ui/range/range_traits-4.rs | 9 + src/test/ui/range/range_traits-5.rs | 9 + src/test/ui/range/range_traits-6.rs | 6 + src/test/ui/range/range_traits-6.stderr | 13 ++ src/test/ui/range/range_traits-7.rs | 9 + 30 files changed, 1245 insertions(+) create mode 100644 src/test/ui/range/exclusive-range-patterns-2021.rs create mode 100644 src/test/ui/range/exclusive-range-patterns-2021.stderr create mode 100644 src/test/ui/range/issue-54505-no-literals.fixed create mode 100644 src/test/ui/range/issue-54505-no-literals.rs create mode 100644 src/test/ui/range/issue-54505-no-literals.stderr create mode 100644 src/test/ui/range/issue-54505-no-std.rs create mode 100644 src/test/ui/range/issue-54505-no-std.stderr create mode 100644 src/test/ui/range/issue-54505.fixed create mode 100644 src/test/ui/range/issue-54505.rs create mode 100644 src/test/ui/range/issue-54505.stderr create mode 100644 src/test/ui/range/issue-73553-misinterp-range-literal.rs create mode 100644 src/test/ui/range/issue-73553-misinterp-range-literal.stderr create mode 100644 src/test/ui/range/range-1.rs create mode 100644 src/test/ui/range/range-1.stderr create mode 100644 src/test/ui/range/range-inclusive-pattern-precedence.fixed create mode 100644 src/test/ui/range/range-inclusive-pattern-precedence.rs create mode 100644 src/test/ui/range/range-inclusive-pattern-precedence.stderr create mode 100644 src/test/ui/range/range-inclusive-pattern-precedence2.rs create mode 100644 src/test/ui/range/range-inclusive-pattern-precedence2.stderr create mode 100644 src/test/ui/range/range_traits-1.rs create mode 100644 src/test/ui/range/range_traits-1.stderr create mode 100644 src/test/ui/range/range_traits-2.rs create mode 100644 src/test/ui/range/range_traits-2.stderr create mode 100644 src/test/ui/range/range_traits-3.rs create mode 100644 src/test/ui/range/range_traits-3.stderr create mode 100644 src/test/ui/range/range_traits-4.rs create mode 100644 src/test/ui/range/range_traits-5.rs create mode 100644 src/test/ui/range/range_traits-6.rs create mode 100644 src/test/ui/range/range_traits-6.stderr create mode 100644 src/test/ui/range/range_traits-7.rs (limited to 'src/test/ui/range') diff --git a/src/test/ui/range/exclusive-range-patterns-2021.rs b/src/test/ui/range/exclusive-range-patterns-2021.rs new file mode 100644 index 000000000..de69c9bf2 --- /dev/null +++ b/src/test/ui/range/exclusive-range-patterns-2021.rs @@ -0,0 +1,14 @@ +// edition:2021 + +fn main() { + let n = 2; + match n { + 0...3 => {} + //~^ ERROR `...` range patterns are deprecated + 4...10 => {} + //~^ ERROR `...` range patterns are deprecated + (11...100) => {} + //~^ ERROR `...` range patterns are deprecated + _ => {} + } +} diff --git a/src/test/ui/range/exclusive-range-patterns-2021.stderr b/src/test/ui/range/exclusive-range-patterns-2021.stderr new file mode 100644 index 000000000..a96743704 --- /dev/null +++ b/src/test/ui/range/exclusive-range-patterns-2021.stderr @@ -0,0 +1,27 @@ +error[E0783]: `...` range patterns are deprecated + --> $DIR/exclusive-range-patterns-2021.rs:6:9 + | +LL | 0...3 => {} + | ^---^ + | | + | help: use `..=` for an inclusive range + +error[E0783]: `...` range patterns are deprecated + --> $DIR/exclusive-range-patterns-2021.rs:8:9 + | +LL | 4...10 => {} + | ^---^^ + | | + | help: use `..=` for an inclusive range + +error[E0783]: `...` range patterns are deprecated + --> $DIR/exclusive-range-patterns-2021.rs:10:10 + | +LL | (11...100) => {} + | ^^---^^^ + | | + | help: use `..=` for an inclusive range + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0783`. diff --git a/src/test/ui/range/issue-54505-no-literals.fixed b/src/test/ui/range/issue-54505-no-literals.fixed new file mode 100644 index 000000000..4d8f67182 --- /dev/null +++ b/src/test/ui/range/issue-54505-no-literals.fixed @@ -0,0 +1,75 @@ +// run-rustfix + +// Regression test for changes introduced while fixing #54505 + +// This test uses non-literals for Ranges +// (expecting no parens with borrow suggestion) + +use std::ops::RangeBounds; + + +// take a reference to any built-in range +fn take_range(_r: &impl RangeBounds) {} + + +fn main() { + take_range(&std::ops::Range { start: 0, end: 1 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &std::ops::Range { start: 0, end: 1 } + + take_range(&::std::ops::Range { start: 0, end: 1 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &::std::ops::Range { start: 0, end: 1 } + + take_range(&std::ops::RangeFrom { start: 1 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &std::ops::RangeFrom { start: 1 } + + take_range(&::std::ops::RangeFrom { start: 1 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &::std::ops::RangeFrom { start: 1 } + + take_range(&std::ops::RangeFull {}); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &std::ops::RangeFull {} + + take_range(&::std::ops::RangeFull {}); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &::std::ops::RangeFull {} + + take_range(&std::ops::RangeInclusive::new(0, 1)); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &std::ops::RangeInclusive::new(0, 1) + + take_range(&::std::ops::RangeInclusive::new(0, 1)); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &::std::ops::RangeInclusive::new(0, 1) + + take_range(&std::ops::RangeTo { end: 5 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &std::ops::RangeTo { end: 5 } + + take_range(&::std::ops::RangeTo { end: 5 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &::std::ops::RangeTo { end: 5 } + + take_range(&std::ops::RangeToInclusive { end: 5 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &std::ops::RangeToInclusive { end: 5 } + + take_range(&::std::ops::RangeToInclusive { end: 5 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &::std::ops::RangeToInclusive { end: 5 } +} diff --git a/src/test/ui/range/issue-54505-no-literals.rs b/src/test/ui/range/issue-54505-no-literals.rs new file mode 100644 index 000000000..dc21dcbc2 --- /dev/null +++ b/src/test/ui/range/issue-54505-no-literals.rs @@ -0,0 +1,75 @@ +// run-rustfix + +// Regression test for changes introduced while fixing #54505 + +// This test uses non-literals for Ranges +// (expecting no parens with borrow suggestion) + +use std::ops::RangeBounds; + + +// take a reference to any built-in range +fn take_range(_r: &impl RangeBounds) {} + + +fn main() { + take_range(std::ops::Range { start: 0, end: 1 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &std::ops::Range { start: 0, end: 1 } + + take_range(::std::ops::Range { start: 0, end: 1 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &::std::ops::Range { start: 0, end: 1 } + + take_range(std::ops::RangeFrom { start: 1 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &std::ops::RangeFrom { start: 1 } + + take_range(::std::ops::RangeFrom { start: 1 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &::std::ops::RangeFrom { start: 1 } + + take_range(std::ops::RangeFull {}); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &std::ops::RangeFull {} + + take_range(::std::ops::RangeFull {}); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &::std::ops::RangeFull {} + + take_range(std::ops::RangeInclusive::new(0, 1)); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &std::ops::RangeInclusive::new(0, 1) + + take_range(::std::ops::RangeInclusive::new(0, 1)); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &::std::ops::RangeInclusive::new(0, 1) + + take_range(std::ops::RangeTo { end: 5 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &std::ops::RangeTo { end: 5 } + + take_range(::std::ops::RangeTo { end: 5 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &::std::ops::RangeTo { end: 5 } + + take_range(std::ops::RangeToInclusive { end: 5 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &std::ops::RangeToInclusive { end: 5 } + + take_range(::std::ops::RangeToInclusive { end: 5 }); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &::std::ops::RangeToInclusive { end: 5 } +} diff --git a/src/test/ui/range/issue-54505-no-literals.stderr b/src/test/ui/range/issue-54505-no-literals.stderr new file mode 100644 index 000000000..4cbf8869d --- /dev/null +++ b/src/test/ui/range/issue-54505-no-literals.stderr @@ -0,0 +1,219 @@ +error[E0308]: mismatched types + --> $DIR/issue-54505-no-literals.rs:16:16 + | +LL | take_range(std::ops::Range { start: 0, end: 1 }); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `std::ops::Range` + | | help: consider borrowing here: `&std::ops::Range { start: 0, end: 1 }` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `std::ops::Range<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-literals.rs:12:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-literals.rs:21:16 + | +LL | take_range(::std::ops::Range { start: 0, end: 1 }); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `std::ops::Range` + | | help: consider borrowing here: `&::std::ops::Range { start: 0, end: 1 }` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `std::ops::Range<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-literals.rs:12:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-literals.rs:26:16 + | +LL | take_range(std::ops::RangeFrom { start: 1 }); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `RangeFrom` + | | help: consider borrowing here: `&std::ops::RangeFrom { start: 1 }` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeFrom<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-literals.rs:12:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-literals.rs:31:16 + | +LL | take_range(::std::ops::RangeFrom { start: 1 }); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `RangeFrom` + | | help: consider borrowing here: `&::std::ops::RangeFrom { start: 1 }` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeFrom<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-literals.rs:12:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-literals.rs:36:16 + | +LL | take_range(std::ops::RangeFull {}); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `RangeFull` + | | help: consider borrowing here: `&std::ops::RangeFull {}` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeFull` +note: function defined here + --> $DIR/issue-54505-no-literals.rs:12:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-literals.rs:41:16 + | +LL | take_range(::std::ops::RangeFull {}); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `RangeFull` + | | help: consider borrowing here: `&::std::ops::RangeFull {}` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeFull` +note: function defined here + --> $DIR/issue-54505-no-literals.rs:12:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-literals.rs:46:16 + | +LL | take_range(std::ops::RangeInclusive::new(0, 1)); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `RangeInclusive` + | | help: consider borrowing here: `&std::ops::RangeInclusive::new(0, 1)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeInclusive<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-literals.rs:12:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-literals.rs:51:16 + | +LL | take_range(::std::ops::RangeInclusive::new(0, 1)); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `RangeInclusive` + | | help: consider borrowing here: `&::std::ops::RangeInclusive::new(0, 1)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeInclusive<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-literals.rs:12:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-literals.rs:56:16 + | +LL | take_range(std::ops::RangeTo { end: 5 }); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `RangeTo` + | | help: consider borrowing here: `&std::ops::RangeTo { end: 5 }` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeTo<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-literals.rs:12:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-literals.rs:61:16 + | +LL | take_range(::std::ops::RangeTo { end: 5 }); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `RangeTo` + | | help: consider borrowing here: `&::std::ops::RangeTo { end: 5 }` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeTo<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-literals.rs:12:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-literals.rs:66:16 + | +LL | take_range(std::ops::RangeToInclusive { end: 5 }); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `RangeToInclusive` + | | help: consider borrowing here: `&std::ops::RangeToInclusive { end: 5 }` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeToInclusive<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-literals.rs:12:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-literals.rs:71:16 + | +LL | take_range(::std::ops::RangeToInclusive { end: 5 }); + | ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `RangeToInclusive` + | | help: consider borrowing here: `&::std::ops::RangeToInclusive { end: 5 }` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeToInclusive<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-literals.rs:12:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error: aborting due to 12 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/range/issue-54505-no-std.rs b/src/test/ui/range/issue-54505-no-std.rs new file mode 100644 index 000000000..ab1a025b5 --- /dev/null +++ b/src/test/ui/range/issue-54505-no-std.rs @@ -0,0 +1,56 @@ +// error-pattern: `#[panic_handler]` function required, but not found + +// Regression test for #54505 - range borrowing suggestion had +// incorrect syntax (missing parentheses). + +// This test doesn't use std +// (so all Ranges resolve to core::ops::Range...) + +#![no_std] +#![feature(lang_items)] + +use core::ops::RangeBounds; + +#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] +#[lang = "eh_personality"] +extern "C" fn eh_personality() {} +#[cfg(target_os = "emscripten")] +#[lang = "eh_catch_typeinfo"] +static EH_CATCH_TYPEINFO: u8 = 0; + + +// take a reference to any built-in range +fn take_range(_r: &impl RangeBounds) {} + + +fn main() { + take_range(0..1); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(0..1) + + take_range(1..); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(1..) + + take_range(..); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(..) + + take_range(0..=1); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(0..=1) + + take_range(..5); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(..5) + + take_range(..=42); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(..=42) +} diff --git a/src/test/ui/range/issue-54505-no-std.stderr b/src/test/ui/range/issue-54505-no-std.stderr new file mode 100644 index 000000000..c4e36b0b1 --- /dev/null +++ b/src/test/ui/range/issue-54505-no-std.stderr @@ -0,0 +1,113 @@ +error: `#[panic_handler]` function required, but not found + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-std.rs:27:16 + | +LL | take_range(0..1); + | ---------- ^^^^ + | | | + | | expected reference, found struct `Range` + | | help: consider borrowing here: `&(0..1)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `Range<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-std.rs:23:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-std.rs:32:16 + | +LL | take_range(1..); + | ---------- ^^^ + | | | + | | expected reference, found struct `RangeFrom` + | | help: consider borrowing here: `&(1..)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeFrom<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-std.rs:23:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-std.rs:37:16 + | +LL | take_range(..); + | ---------- ^^ + | | | + | | expected reference, found struct `RangeFull` + | | help: consider borrowing here: `&(..)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeFull` +note: function defined here + --> $DIR/issue-54505-no-std.rs:23:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-std.rs:42:16 + | +LL | take_range(0..=1); + | ---------- ^^^^^ + | | | + | | expected reference, found struct `RangeInclusive` + | | help: consider borrowing here: `&(0..=1)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeInclusive<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-std.rs:23:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-std.rs:47:16 + | +LL | take_range(..5); + | ---------- ^^^ + | | | + | | expected reference, found struct `RangeTo` + | | help: consider borrowing here: `&(..5)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeTo<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-std.rs:23:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505-no-std.rs:52:16 + | +LL | take_range(..=42); + | ---------- ^^^^^ + | | | + | | expected reference, found struct `RangeToInclusive` + | | help: consider borrowing here: `&(..=42)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeToInclusive<{integer}>` +note: function defined here + --> $DIR/issue-54505-no-std.rs:23:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/range/issue-54505.fixed b/src/test/ui/range/issue-54505.fixed new file mode 100644 index 000000000..f8298c0b5 --- /dev/null +++ b/src/test/ui/range/issue-54505.fixed @@ -0,0 +1,43 @@ +// run-rustfix + +// Regression test for #54505 - range borrowing suggestion had +// incorrect syntax (missing parentheses). + +use std::ops::RangeBounds; + + +// take a reference to any built-in range +fn take_range(_r: &impl RangeBounds) {} + + +fn main() { + take_range(&(0..1)); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(0..1) + + take_range(&(1..)); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(1..) + + take_range(&(..)); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(..) + + take_range(&(0..=1)); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(0..=1) + + take_range(&(..5)); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(..5) + + take_range(&(..=42)); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(..=42) +} diff --git a/src/test/ui/range/issue-54505.rs b/src/test/ui/range/issue-54505.rs new file mode 100644 index 000000000..03673252d --- /dev/null +++ b/src/test/ui/range/issue-54505.rs @@ -0,0 +1,43 @@ +// run-rustfix + +// Regression test for #54505 - range borrowing suggestion had +// incorrect syntax (missing parentheses). + +use std::ops::RangeBounds; + + +// take a reference to any built-in range +fn take_range(_r: &impl RangeBounds) {} + + +fn main() { + take_range(0..1); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(0..1) + + take_range(1..); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(1..) + + take_range(..); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(..) + + take_range(0..=1); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(0..=1) + + take_range(..5); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(..5) + + take_range(..=42); + //~^ ERROR mismatched types [E0308] + //~| HELP consider borrowing here + //~| SUGGESTION &(..=42) +} diff --git a/src/test/ui/range/issue-54505.stderr b/src/test/ui/range/issue-54505.stderr new file mode 100644 index 000000000..38df6e144 --- /dev/null +++ b/src/test/ui/range/issue-54505.stderr @@ -0,0 +1,111 @@ +error[E0308]: mismatched types + --> $DIR/issue-54505.rs:14:16 + | +LL | take_range(0..1); + | ---------- ^^^^ + | | | + | | expected reference, found struct `std::ops::Range` + | | help: consider borrowing here: `&(0..1)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `std::ops::Range<{integer}>` +note: function defined here + --> $DIR/issue-54505.rs:10:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505.rs:19:16 + | +LL | take_range(1..); + | ---------- ^^^ + | | | + | | expected reference, found struct `RangeFrom` + | | help: consider borrowing here: `&(1..)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeFrom<{integer}>` +note: function defined here + --> $DIR/issue-54505.rs:10:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505.rs:24:16 + | +LL | take_range(..); + | ---------- ^^ + | | | + | | expected reference, found struct `RangeFull` + | | help: consider borrowing here: `&(..)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeFull` +note: function defined here + --> $DIR/issue-54505.rs:10:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505.rs:29:16 + | +LL | take_range(0..=1); + | ---------- ^^^^^ + | | | + | | expected reference, found struct `RangeInclusive` + | | help: consider borrowing here: `&(0..=1)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeInclusive<{integer}>` +note: function defined here + --> $DIR/issue-54505.rs:10:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505.rs:34:16 + | +LL | take_range(..5); + | ---------- ^^^ + | | | + | | expected reference, found struct `RangeTo` + | | help: consider borrowing here: `&(..5)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeTo<{integer}>` +note: function defined here + --> $DIR/issue-54505.rs:10:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error[E0308]: mismatched types + --> $DIR/issue-54505.rs:39:16 + | +LL | take_range(..=42); + | ---------- ^^^^^ + | | | + | | expected reference, found struct `RangeToInclusive` + | | help: consider borrowing here: `&(..=42)` + | arguments to this function are incorrect + | + = note: expected reference `&_` + found struct `RangeToInclusive<{integer}>` +note: function defined here + --> $DIR/issue-54505.rs:10:4 + | +LL | fn take_range(_r: &impl RangeBounds) {} + | ^^^^^^^^^^ ------------------------- + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/range/issue-73553-misinterp-range-literal.rs b/src/test/ui/range/issue-73553-misinterp-range-literal.rs new file mode 100644 index 000000000..e65dba0a0 --- /dev/null +++ b/src/test/ui/range/issue-73553-misinterp-range-literal.rs @@ -0,0 +1,16 @@ +type Range = std::ops::Range; + +fn demo(r: &Range) { + println!("{:?}", r); +} + +fn tell(x: usize) -> usize { + x +} + +fn main() { + demo(tell(1)..tell(10)); + //~^ ERROR mismatched types + demo(1..10); + //~^ ERROR mismatched types +} diff --git a/src/test/ui/range/issue-73553-misinterp-range-literal.stderr b/src/test/ui/range/issue-73553-misinterp-range-literal.stderr new file mode 100644 index 000000000..6badd998f --- /dev/null +++ b/src/test/ui/range/issue-73553-misinterp-range-literal.stderr @@ -0,0 +1,39 @@ +error[E0308]: mismatched types + --> $DIR/issue-73553-misinterp-range-literal.rs:12:10 + | +LL | demo(tell(1)..tell(10)); + | ---- ^^^^^^^^^^^^^^^^^ + | | | + | | expected reference, found struct `std::ops::Range` + | | help: consider borrowing here: `&(tell(1)..tell(10))` + | arguments to this function are incorrect + | + = note: expected reference `&std::ops::Range` + found struct `std::ops::Range` +note: function defined here + --> $DIR/issue-73553-misinterp-range-literal.rs:3:4 + | +LL | fn demo(r: &Range) { + | ^^^^ --------- + +error[E0308]: mismatched types + --> $DIR/issue-73553-misinterp-range-literal.rs:14:10 + | +LL | demo(1..10); + | ---- ^^^^^ + | | | + | | expected reference, found struct `std::ops::Range` + | | help: consider borrowing here: `&(1..10)` + | arguments to this function are incorrect + | + = note: expected reference `&std::ops::Range` + found struct `std::ops::Range<{integer}>` +note: function defined here + --> $DIR/issue-73553-misinterp-range-literal.rs:3:4 + | +LL | fn demo(r: &Range) { + | ^^^^ --------- + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/range/range-1.rs b/src/test/ui/range/range-1.rs new file mode 100644 index 000000000..192426fe2 --- /dev/null +++ b/src/test/ui/range/range-1.rs @@ -0,0 +1,16 @@ +// Test range syntax - type errors. + +pub fn main() { + // Mixed types. + let _ = 0u32..10i32; + //~^ ERROR mismatched types + + // Bool => does not implement iterator. + for i in false..true {} + //~^ ERROR `bool: Step` is not satisfied + + // Unsized type. + let arr: &[_] = &[1, 2, 3]; + let range = *arr..; + //~^ ERROR the size for values of type +} diff --git a/src/test/ui/range/range-1.stderr b/src/test/ui/range/range-1.stderr new file mode 100644 index 000000000..0bbed8704 --- /dev/null +++ b/src/test/ui/range/range-1.stderr @@ -0,0 +1,42 @@ +error[E0308]: mismatched types + --> $DIR/range-1.rs:5:19 + | +LL | let _ = 0u32..10i32; + | ^^^^^ expected `u32`, found `i32` + +error[E0277]: the trait bound `bool: Step` is not satisfied + --> $DIR/range-1.rs:9:14 + | +LL | for i in false..true {} + | ^^^^^^^^^^^ the trait `Step` is not implemented for `bool` + | + = help: the following other types implement trait `Step`: + char + i128 + i16 + i32 + i64 + i8 + isize + u128 + and 5 others + = note: required because of the requirements on the impl of `Iterator` for `std::ops::Range` + = note: required because of the requirements on the impl of `IntoIterator` for `std::ops::Range` + +error[E0277]: the size for values of type `[{integer}]` cannot be known at compilation time + --> $DIR/range-1.rs:14:17 + | +LL | let range = *arr..; + | ^^^^^^ doesn't have a size known at compile-time + | + = help: the trait `Sized` is not implemented for `[{integer}]` +note: required by a bound in `RangeFrom` + --> $SRC_DIR/core/src/ops/range.rs:LL:COL + | +LL | pub struct RangeFrom { + | ^^^ required by this bound in `RangeFrom` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0277, E0308. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/range/range-inclusive-pattern-precedence.fixed b/src/test/ui/range/range-inclusive-pattern-precedence.fixed new file mode 100644 index 000000000..38104bab7 --- /dev/null +++ b/src/test/ui/range/range-inclusive-pattern-precedence.fixed @@ -0,0 +1,21 @@ +// In expression, `&a..=b` is treated as `(&a)..=(b)` and `box a..=b` is +// `(box a)..=(b)`. In a pattern, however, `&a..=b` means `&(a..=b)`. This may +// lead to confusion. + +// run-rustfix + +#![warn(ellipsis_inclusive_range_patterns)] + +pub fn main() { + match &12 { + &(0..=9) => {} + //~^ WARN `...` range patterns are deprecated + //~| WARN this is accepted in the current edition + //~| HELP use `..=` for an inclusive range + &(10..=15) => {} + //~^ ERROR the range pattern here has ambiguous interpretation + //~| HELP add parentheses to clarify the precedence + &(16..=20) => {} + _ => {} + } +} diff --git a/src/test/ui/range/range-inclusive-pattern-precedence.rs b/src/test/ui/range/range-inclusive-pattern-precedence.rs new file mode 100644 index 000000000..b294e436f --- /dev/null +++ b/src/test/ui/range/range-inclusive-pattern-precedence.rs @@ -0,0 +1,21 @@ +// In expression, `&a..=b` is treated as `(&a)..=(b)` and `box a..=b` is +// `(box a)..=(b)`. In a pattern, however, `&a..=b` means `&(a..=b)`. This may +// lead to confusion. + +// run-rustfix + +#![warn(ellipsis_inclusive_range_patterns)] + +pub fn main() { + match &12 { + &0...9 => {} + //~^ WARN `...` range patterns are deprecated + //~| WARN this is accepted in the current edition + //~| HELP use `..=` for an inclusive range + &10..=15 => {} + //~^ ERROR the range pattern here has ambiguous interpretation + //~| HELP add parentheses to clarify the precedence + &(16..=20) => {} + _ => {} + } +} diff --git a/src/test/ui/range/range-inclusive-pattern-precedence.stderr b/src/test/ui/range/range-inclusive-pattern-precedence.stderr new file mode 100644 index 000000000..10513374c --- /dev/null +++ b/src/test/ui/range/range-inclusive-pattern-precedence.stderr @@ -0,0 +1,22 @@ +error: the range pattern here has ambiguous interpretation + --> $DIR/range-inclusive-pattern-precedence.rs:15:10 + | +LL | &10..=15 => {} + | ^^^^^^^ help: add parentheses to clarify the precedence: `(10..=15)` + +warning: `...` range patterns are deprecated + --> $DIR/range-inclusive-pattern-precedence.rs:11:9 + | +LL | &0...9 => {} + | ^^^^^^ help: use `..=` for an inclusive range: `&(0..=9)` + | +note: the lint level is defined here + --> $DIR/range-inclusive-pattern-precedence.rs:7:9 + | +LL | #![warn(ellipsis_inclusive_range_patterns)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + +error: aborting due to previous error; 1 warning emitted + diff --git a/src/test/ui/range/range-inclusive-pattern-precedence2.rs b/src/test/ui/range/range-inclusive-pattern-precedence2.rs new file mode 100644 index 000000000..bede9c579 --- /dev/null +++ b/src/test/ui/range/range-inclusive-pattern-precedence2.rs @@ -0,0 +1,20 @@ +// We are going to disallow `&a..=b` and `box a..=b` in a pattern. However, the +// older ... syntax is still allowed as a stability guarantee. + +#![feature(box_patterns)] +#![warn(ellipsis_inclusive_range_patterns)] + +fn main() { + match Box::new(12) { + // FIXME: can we add suggestions like `&(0..=9)`? + box 0...9 => {} + //~^ WARN `...` range patterns are deprecated + //~| WARN this is accepted in the current edition + //~| HELP use `..=` for an inclusive range + box 10..=15 => {} + //~^ ERROR the range pattern here has ambiguous interpretation + //~^^ HELP add parentheses to clarify the precedence + box (16..=20) => {} + _ => {} + } +} diff --git a/src/test/ui/range/range-inclusive-pattern-precedence2.stderr b/src/test/ui/range/range-inclusive-pattern-precedence2.stderr new file mode 100644 index 000000000..cdec41d7f --- /dev/null +++ b/src/test/ui/range/range-inclusive-pattern-precedence2.stderr @@ -0,0 +1,22 @@ +error: the range pattern here has ambiguous interpretation + --> $DIR/range-inclusive-pattern-precedence2.rs:14:13 + | +LL | box 10..=15 => {} + | ^^^^^^^ help: add parentheses to clarify the precedence: `(10..=15)` + +warning: `...` range patterns are deprecated + --> $DIR/range-inclusive-pattern-precedence2.rs:10:14 + | +LL | box 0...9 => {} + | ^^^ help: use `..=` for an inclusive range + | +note: the lint level is defined here + --> $DIR/range-inclusive-pattern-precedence2.rs:5:9 + | +LL | #![warn(ellipsis_inclusive_range_patterns)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + +error: aborting due to previous error; 1 warning emitted + diff --git a/src/test/ui/range/range_traits-1.rs b/src/test/ui/range/range_traits-1.rs new file mode 100644 index 000000000..e28e47435 --- /dev/null +++ b/src/test/ui/range/range_traits-1.rs @@ -0,0 +1,25 @@ +use std::ops::*; + +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +struct AllTheRanges { + a: Range, + //~^ ERROR can't compare + //~| ERROR Ord + b: RangeTo, + //~^ ERROR can't compare + //~| ERROR Ord + c: RangeFrom, + //~^ ERROR can't compare + //~| ERROR Ord + d: RangeFull, + //~^ ERROR can't compare + //~| ERROR Ord + e: RangeInclusive, + //~^ ERROR can't compare + //~| ERROR Ord + f: RangeToInclusive, + //~^ ERROR can't compare + //~| ERROR Ord +} + +fn main() {} diff --git a/src/test/ui/range/range_traits-1.stderr b/src/test/ui/range/range_traits-1.stderr new file mode 100644 index 000000000..617afc995 --- /dev/null +++ b/src/test/ui/range/range_traits-1.stderr @@ -0,0 +1,141 @@ +error[E0277]: can't compare `std::ops::Range` with `std::ops::Range` + --> $DIR/range_traits-1.rs:5:5 + | +LL | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] + | ---------- in this derive macro expansion +LL | struct AllTheRanges { +LL | a: Range, + | ^^^^^^^^^^^^^^^ no implementation for `std::ops::Range < std::ops::Range` and `std::ops::Range > std::ops::Range` + | + = help: the trait `PartialOrd` is not implemented for `std::ops::Range` + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: can't compare `std::ops::RangeTo` with `std::ops::RangeTo` + --> $DIR/range_traits-1.rs:8:5 + | +LL | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] + | ---------- in this derive macro expansion +... +LL | b: RangeTo, + | ^^^^^^^^^^^^^^^^^ no implementation for `std::ops::RangeTo < std::ops::RangeTo` and `std::ops::RangeTo > std::ops::RangeTo` + | + = help: the trait `PartialOrd` is not implemented for `std::ops::RangeTo` + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: can't compare `std::ops::RangeFrom` with `std::ops::RangeFrom` + --> $DIR/range_traits-1.rs:11:5 + | +LL | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] + | ---------- in this derive macro expansion +... +LL | c: RangeFrom, + | ^^^^^^^^^^^^^^^^^^^ no implementation for `std::ops::RangeFrom < std::ops::RangeFrom` and `std::ops::RangeFrom > std::ops::RangeFrom` + | + = help: the trait `PartialOrd` is not implemented for `std::ops::RangeFrom` + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: can't compare `std::ops::RangeFull` with `std::ops::RangeFull` + --> $DIR/range_traits-1.rs:14:5 + | +LL | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] + | ---------- in this derive macro expansion +... +LL | d: RangeFull, + | ^^^^^^^^^^^^ no implementation for `std::ops::RangeFull < std::ops::RangeFull` and `std::ops::RangeFull > std::ops::RangeFull` + | + = help: the trait `PartialOrd` is not implemented for `std::ops::RangeFull` + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: can't compare `std::ops::RangeInclusive` with `std::ops::RangeInclusive` + --> $DIR/range_traits-1.rs:17:5 + | +LL | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] + | ---------- in this derive macro expansion +... +LL | e: RangeInclusive, + | ^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `std::ops::RangeInclusive < std::ops::RangeInclusive` and `std::ops::RangeInclusive > std::ops::RangeInclusive` + | + = help: the trait `PartialOrd` is not implemented for `std::ops::RangeInclusive` + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: can't compare `std::ops::RangeToInclusive` with `std::ops::RangeToInclusive` + --> $DIR/range_traits-1.rs:20:5 + | +LL | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] + | ---------- in this derive macro expansion +... +LL | f: RangeToInclusive, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `std::ops::RangeToInclusive < std::ops::RangeToInclusive` and `std::ops::RangeToInclusive > std::ops::RangeToInclusive` + | + = help: the trait `PartialOrd` is not implemented for `std::ops::RangeToInclusive` + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `std::ops::Range: Ord` is not satisfied + --> $DIR/range_traits-1.rs:5:5 + | +LL | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] + | --- in this derive macro expansion +LL | struct AllTheRanges { +LL | a: Range, + | ^^^^^^^^^^^^^^^ the trait `Ord` is not implemented for `std::ops::Range` + | + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `std::ops::RangeTo: Ord` is not satisfied + --> $DIR/range_traits-1.rs:8:5 + | +LL | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] + | --- in this derive macro expansion +... +LL | b: RangeTo, + | ^^^^^^^^^^^^^^^^^ the trait `Ord` is not implemented for `std::ops::RangeTo` + | + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `std::ops::RangeFrom: Ord` is not satisfied + --> $DIR/range_traits-1.rs:11:5 + | +LL | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] + | --- in this derive macro expansion +... +LL | c: RangeFrom, + | ^^^^^^^^^^^^^^^^^^^ the trait `Ord` is not implemented for `std::ops::RangeFrom` + | + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `std::ops::RangeFull: Ord` is not satisfied + --> $DIR/range_traits-1.rs:14:5 + | +LL | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] + | --- in this derive macro expansion +... +LL | d: RangeFull, + | ^^^^^^^^^^^^ the trait `Ord` is not implemented for `std::ops::RangeFull` + | + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `std::ops::RangeInclusive: Ord` is not satisfied + --> $DIR/range_traits-1.rs:17:5 + | +LL | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] + | --- in this derive macro expansion +... +LL | e: RangeInclusive, + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Ord` is not implemented for `std::ops::RangeInclusive` + | + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `std::ops::RangeToInclusive: Ord` is not satisfied + --> $DIR/range_traits-1.rs:20:5 + | +LL | #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] + | --- in this derive macro expansion +... +LL | f: RangeToInclusive, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Ord` is not implemented for `std::ops::RangeToInclusive` + | + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 12 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/range/range_traits-2.rs b/src/test/ui/range/range_traits-2.rs new file mode 100644 index 000000000..234d7a64d --- /dev/null +++ b/src/test/ui/range/range_traits-2.rs @@ -0,0 +1,6 @@ +use std::ops::*; + +#[derive(Copy, Clone)] //~ ERROR Copy +struct R(Range); + +fn main() {} diff --git a/src/test/ui/range/range_traits-2.stderr b/src/test/ui/range/range_traits-2.stderr new file mode 100644 index 000000000..61facba53 --- /dev/null +++ b/src/test/ui/range/range_traits-2.stderr @@ -0,0 +1,13 @@ +error[E0204]: the trait `Copy` may not be implemented for this type + --> $DIR/range_traits-2.rs:3:10 + | +LL | #[derive(Copy, Clone)] + | ^^^^ +LL | struct R(Range); + | ------------ this field does not implement `Copy` + | + = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0204`. diff --git a/src/test/ui/range/range_traits-3.rs b/src/test/ui/range/range_traits-3.rs new file mode 100644 index 000000000..2d597cce5 --- /dev/null +++ b/src/test/ui/range/range_traits-3.rs @@ -0,0 +1,6 @@ +use std::ops::*; + +#[derive(Copy, Clone)] //~ ERROR Copy +struct R(RangeFrom); + +fn main() {} diff --git a/src/test/ui/range/range_traits-3.stderr b/src/test/ui/range/range_traits-3.stderr new file mode 100644 index 000000000..e54d17b32 --- /dev/null +++ b/src/test/ui/range/range_traits-3.stderr @@ -0,0 +1,13 @@ +error[E0204]: the trait `Copy` may not be implemented for this type + --> $DIR/range_traits-3.rs:3:10 + | +LL | #[derive(Copy, Clone)] + | ^^^^ +LL | struct R(RangeFrom); + | ---------------- this field does not implement `Copy` + | + = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0204`. diff --git a/src/test/ui/range/range_traits-4.rs b/src/test/ui/range/range_traits-4.rs new file mode 100644 index 000000000..b8e88559b --- /dev/null +++ b/src/test/ui/range/range_traits-4.rs @@ -0,0 +1,9 @@ +// build-pass (FIXME(62277): could be check-pass?) + +use std::ops::*; + +#[derive(Copy, Clone)] +struct R(RangeTo); + + +fn main() {} diff --git a/src/test/ui/range/range_traits-5.rs b/src/test/ui/range/range_traits-5.rs new file mode 100644 index 000000000..4aec7a415 --- /dev/null +++ b/src/test/ui/range/range_traits-5.rs @@ -0,0 +1,9 @@ +// build-pass (FIXME(62277): could be check-pass?) + +use std::ops::*; + +#[derive(Copy, Clone)] +struct R(RangeFull); + + +fn main() {} diff --git a/src/test/ui/range/range_traits-6.rs b/src/test/ui/range/range_traits-6.rs new file mode 100644 index 000000000..bce106bbf --- /dev/null +++ b/src/test/ui/range/range_traits-6.rs @@ -0,0 +1,6 @@ +use std::ops::*; + +#[derive(Copy, Clone)] //~ ERROR Copy +struct R(RangeInclusive); + +fn main() {} diff --git a/src/test/ui/range/range_traits-6.stderr b/src/test/ui/range/range_traits-6.stderr new file mode 100644 index 000000000..addc525f1 --- /dev/null +++ b/src/test/ui/range/range_traits-6.stderr @@ -0,0 +1,13 @@ +error[E0204]: the trait `Copy` may not be implemented for this type + --> $DIR/range_traits-6.rs:3:10 + | +LL | #[derive(Copy, Clone)] + | ^^^^ +LL | struct R(RangeInclusive); + | --------------------- this field does not implement `Copy` + | + = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0204`. diff --git a/src/test/ui/range/range_traits-7.rs b/src/test/ui/range/range_traits-7.rs new file mode 100644 index 000000000..c7b310562 --- /dev/null +++ b/src/test/ui/range/range_traits-7.rs @@ -0,0 +1,9 @@ +// build-pass (FIXME(62277): could be check-pass?) + +use std::ops::*; + +#[derive(Copy, Clone)] +struct R(RangeToInclusive); + + +fn main() {} -- cgit v1.2.3