about summary refs log tree commit diff
diff options
context:
space:
mode:
authory21 <30553356+y21@users.noreply.github.com>2024-02-11 12:57:26 +0100
committery21 <30553356+y21@users.noreply.github.com>2024-02-11 13:10:57 +0100
commit67bdb0e11c27df7c8f089976141a1a7526903743 (patch)
tree1ce16a5d71f7c0eacac110c3192594a29105e144
parentd29f2eebddc3095f4b5536ae59a27c91497f6da4 (diff)
downloadrust-67bdb0e11c27df7c8f089976141a1a7526903743.tar.gz
rust-67bdb0e11c27df7c8f089976141a1a7526903743.zip
[`incompatible_msrv`]: allow expressions that come from desugaring
-rw-r--r--clippy_lints/src/incompatible_msrv.rs7
-rw-r--r--tests/ui/incompatible_msrv.rs8
-rw-r--r--tests/ui/incompatible_msrv.stderr6
3 files changed, 17 insertions, 4 deletions
diff --git a/clippy_lints/src/incompatible_msrv.rs b/clippy_lints/src/incompatible_msrv.rs
index 475938d6adf..cd000fcd184 100644
--- a/clippy_lints/src/incompatible_msrv.rs
+++ b/clippy_lints/src/incompatible_msrv.rs
@@ -9,7 +9,7 @@ use rustc_middle::ty::TyCtxt;
 use rustc_semver::RustcVersion;
 use rustc_session::impl_lint_pass;
 use rustc_span::def_id::DefId;
-use rustc_span::Span;
+use rustc_span::{ExpnKind, Span};
 
 declare_clippy_lint! {
     /// ### What it does
@@ -91,6 +91,11 @@ impl IncompatibleMsrv {
         if self.msrv.meets(version) || is_in_test_function(cx.tcx, node) {
             return;
         }
+        if let ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) = span.ctxt().outer_expn_data().kind {
+            // Desugared expressions get to cheat and stability is ignored.
+            // Intentionally not using `.from_expansion()`, since we do still care about macro expansions
+            return;
+        }
         self.emit_lint_for(cx, span, version);
     }
 
diff --git a/tests/ui/incompatible_msrv.rs b/tests/ui/incompatible_msrv.rs
index 0fa047c7102..8ef1f554bc3 100644
--- a/tests/ui/incompatible_msrv.rs
+++ b/tests/ui/incompatible_msrv.rs
@@ -4,6 +4,7 @@
 
 use std::collections::hash_map::Entry;
 use std::collections::HashMap;
+use std::future::Future;
 use std::thread::sleep;
 use std::time::Duration;
 
@@ -25,4 +26,11 @@ fn test() {
     sleep(Duration::new(1, 0));
 }
 
+#[clippy::msrv = "1.63.0"]
+async fn issue12273(v: impl Future<Output = ()>) {
+    // `.await` desugaring has a call to `IntoFuture::into_future` marked #[stable(since = "1.64.0")],
+    // but its stability is ignored
+    v.await;
+}
+
 fn main() {}
diff --git a/tests/ui/incompatible_msrv.stderr b/tests/ui/incompatible_msrv.stderr
index bd5ecd6ed2f..9e1c81b82bc 100644
--- a/tests/ui/incompatible_msrv.stderr
+++ b/tests/ui/incompatible_msrv.stderr
@@ -1,5 +1,5 @@
 error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.10.0`
-  --> $DIR/incompatible_msrv.rs:12:39
+  --> $DIR/incompatible_msrv.rs:13:39
    |
 LL |     assert_eq!(map.entry("poneyland").key(), &"poneyland");
    |                                       ^^^^^
@@ -8,13 +8,13 @@ LL |     assert_eq!(map.entry("poneyland").key(), &"poneyland");
    = help: to override `-D warnings` add `#[allow(clippy::incompatible_msrv)]`
 
 error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.12.0`
-  --> $DIR/incompatible_msrv.rs:15:11
+  --> $DIR/incompatible_msrv.rs:16:11
    |
 LL |         v.into_key();
    |           ^^^^^^^^^^
 
 error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.4.0`
-  --> $DIR/incompatible_msrv.rs:19:5
+  --> $DIR/incompatible_msrv.rs:20:5
    |
 LL |     sleep(Duration::new(1, 0));
    |     ^^^^^