From 905ec74f6a5c094d105d1bcb4ed3e53267b033b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastian=20K=C3=B6cher?= <bkchr@users.noreply.github.com>
Date: Mon, 11 Apr 2022 11:31:39 +0200
Subject: [PATCH] Prepare for rust 1.60 (#5282)

* Prepare for rust 1.60

* change ci image to staging

* empty commit for pipeline rerun

* ci image production

Co-authored-by: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>
Co-authored-by: alvicsam <alvicsam@gmail.com>
---
 polkadot/.gitlab-ci.yml                       |  2 +
 polkadot/Cargo.lock                           |  1 +
 .../node/overseer/overseer-gen/Cargo.toml     |  1 +
 .../node/overseer/overseer-gen/src/tests.rs   | 30 ++++++++++++--
 .../tests/ui/err-01-duplicate-consumer.stderr |  8 ++--
 polkadot/scripts/update-rust-stable.sh        | 39 +++++++++++++++++++
 6 files changed, 74 insertions(+), 7 deletions(-)
 create mode 100755 polkadot/scripts/update-rust-stable.sh

diff --git a/polkadot/.gitlab-ci.yml b/polkadot/.gitlab-ci.yml
index 0e8c64dc074..84d63aa9818 100644
--- a/polkadot/.gitlab-ci.yml
+++ b/polkadot/.gitlab-ci.yml
@@ -227,6 +227,8 @@ build-linux-stable:
     # Enable debug assertions since we are running optimized builds for testing
     # but still want to have debug assertions.
     RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings"
+    # Ensure we run the UI tests.
+    RUN_UI_TESTS: 1
   script:
     - time cargo build --profile testnet --features pyroscope --verbose --bin polkadot
     - sccache -s
diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock
index 4e989fd4502..5365e05947f 100644
--- a/polkadot/Cargo.lock
+++ b/polkadot/Cargo.lock
@@ -7106,6 +7106,7 @@ dependencies = [
  "polkadot-node-network-protocol",
  "polkadot-node-primitives",
  "polkadot-overseer-gen-proc-macro",
+ "rustversion",
  "thiserror",
  "tracing-gum",
  "trybuild",
diff --git a/polkadot/node/overseer/overseer-gen/Cargo.toml b/polkadot/node/overseer/overseer-gen/Cargo.toml
index 7296a1aaf74..282113d2449 100644
--- a/polkadot/node/overseer/overseer-gen/Cargo.toml
+++ b/polkadot/node/overseer/overseer-gen/Cargo.toml
@@ -20,6 +20,7 @@ pin-project = "1.0"
 
 [dev-dependencies]
 trybuild = "1.0.53"
+rustversion = "1.0.6"
 
 [features]
 default = []
diff --git a/polkadot/node/overseer/overseer-gen/src/tests.rs b/polkadot/node/overseer/overseer-gen/src/tests.rs
index ad8745b3866..09de7ed4d3d 100644
--- a/polkadot/node/overseer/overseer-gen/src/tests.rs
+++ b/polkadot/node/overseer/overseer-gen/src/tests.rs
@@ -1,15 +1,39 @@
-// The generated code requires quite a bit of surrounding code to work.
-// Please refer to [the examples](examples/dummy.rs) and
-// [the minimal usage example](../examples/minimal-example.rs).
+// Copyright 2022 Parity Technologies (UK) Ltd.
+// This file is part of Polkadot.
+
+// Polkadot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Polkadot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
 
 #[test]
+#[rustversion::attr(not(stable), ignore)]
 fn ui_compile_fail() {
+	// Only run the ui tests when `RUN_UI_TESTS` is set.
+	if std::env::var("RUN_UI_TESTS").is_err() {
+		return
+	}
+
 	let t = trybuild::TestCases::new();
 	t.compile_fail("tests/ui/err-*.rs");
 }
 
 #[test]
+#[rustversion::attr(not(stable), ignore)]
 fn ui_pass() {
+	// Only run the ui tests when `RUN_UI_TESTS` is set.
+	if std::env::var("RUN_UI_TESTS").is_err() {
+		return
+	}
+
 	let t = trybuild::TestCases::new();
 	t.pass("tests/ui/ok-*.rs");
 }
diff --git a/polkadot/node/overseer/overseer-gen/tests/ui/err-01-duplicate-consumer.stderr b/polkadot/node/overseer/overseer-gen/tests/ui/err-01-duplicate-consumer.stderr
index 18ba674324b..ea67ef7aad5 100644
--- a/polkadot/node/overseer/overseer-gen/tests/ui/err-01-duplicate-consumer.stderr
+++ b/polkadot/node/overseer/overseer-gen/tests/ui/err-01-duplicate-consumer.stderr
@@ -1,21 +1,21 @@
-error[E0119]: conflicting implementations of trait `std::convert::From<MsgStrukt>` for type `AllMessages`
+error[E0119]: conflicting implementations of trait `polkadot_overseer_gen::SubsystemSender<MsgStrukt>` for type `OverseerSubsystemSender`
   --> tests/ui/err-01-duplicate-consumer.rs:19:1
    |
 19 | #[overlord(signal=SigSigSig, event=Event, gen=AllMessages, error=OverseerError)]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | |
    | first implementation here
-   | conflicting implementation for `AllMessages`
+   | conflicting implementation for `OverseerSubsystemSender`
    |
    = note: this error originates in the attribute macro `overlord` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error[E0119]: conflicting implementations of trait `polkadot_overseer_gen::SubsystemSender<MsgStrukt>` for type `OverseerSubsystemSender`
+error[E0119]: conflicting implementations of trait `std::convert::From<MsgStrukt>` for type `AllMessages`
   --> tests/ui/err-01-duplicate-consumer.rs:19:1
    |
 19 | #[overlord(signal=SigSigSig, event=Event, gen=AllMessages, error=OverseerError)]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | |
    | first implementation here
-   | conflicting implementation for `OverseerSubsystemSender`
+   | conflicting implementation for `AllMessages`
    |
    = note: this error originates in the attribute macro `overlord` (in Nightly builds, run with -Z macro-backtrace for more info)
diff --git a/polkadot/scripts/update-rust-stable.sh b/polkadot/scripts/update-rust-stable.sh
new file mode 100755
index 00000000000..4e24d6338d5
--- /dev/null
+++ b/polkadot/scripts/update-rust-stable.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+#
+# Script for updating the UI tests for a new rust stable version.
+#
+# It needs to be called like this:
+#
+# update-rust-stable.sh 1.61
+#
+# This will run all UI tests with the rust stable 1.61. The script
+# requires that rustup is installed.
+set -e
+
+if [ "$#" -ne 1 ]; then
+	echo "Please specify the rust version to use. E.g. update-rust-stable.sh 1.61"
+	exit
+fi
+
+RUST_VERSION=$1
+
+if ! command -v rustup &> /dev/null
+then
+	echo "rustup needs to be installed"
+	exit
+fi
+
+rustup install $RUST_VERSION
+rustup component add rust-src --toolchain $RUST_VERSION
+
+# Ensure we run the ui tests
+export RUN_UI_TESTS=1
+# We don't need any wasm files for ui tests
+export SKIP_WASM_BUILD=1
+# Let trybuild overwrite the .stderr files
+export TRYBUILD=overwrite
+
+# Run all the relevant UI tests
+#
+# Any new UI tests in different crates need to be added here as well.
+rustup run $RUST_VERSION cargo test -p polkadot-overseer-gen ui
-- 
GitLab