Skip to content

Commit 03113a9

Browse files
committed
Auto merge of rust-lang#12275 - y21:incompatible_msrv_desugaring, r=Manishearth
[`incompatible_msrv`]: allow expressions that come from desugaring Fixes rust-lang#12273 changelog: [`incompatible_msrv`]: don't lint on the `IntoFuture::into_future` call desugared by `.await`
2 parents 3e264ba + 67bdb0e commit 03113a9

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

clippy_lints/src/incompatible_msrv.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::ty::TyCtxt;
99
use rustc_semver::RustcVersion;
1010
use rustc_session::impl_lint_pass;
1111
use rustc_span::def_id::DefId;
12-
use rustc_span::Span;
12+
use rustc_span::{ExpnKind, Span};
1313

1414
declare_clippy_lint! {
1515
/// ### What it does
@@ -91,6 +91,11 @@ impl IncompatibleMsrv {
9191
if self.msrv.meets(version) || is_in_test_function(cx.tcx, node) {
9292
return;
9393
}
94+
if let ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) = span.ctxt().outer_expn_data().kind {
95+
// Desugared expressions get to cheat and stability is ignored.
96+
// Intentionally not using `.from_expansion()`, since we do still care about macro expansions
97+
return;
98+
}
9499
self.emit_lint_for(cx, span, version);
95100
}
96101

tests/ui/incompatible_msrv.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use std::collections::hash_map::Entry;
66
use std::collections::HashMap;
7+
use std::future::Future;
78
use std::thread::sleep;
89
use std::time::Duration;
910

@@ -25,4 +26,11 @@ fn test() {
2526
sleep(Duration::new(1, 0));
2627
}
2728

29+
#[clippy::msrv = "1.63.0"]
30+
async fn issue12273(v: impl Future<Output = ()>) {
31+
// `.await` desugaring has a call to `IntoFuture::into_future` marked #[stable(since = "1.64.0")],
32+
// but its stability is ignored
33+
v.await;
34+
}
35+
2836
fn main() {}

tests/ui/incompatible_msrv.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.10.0`
2-
--> $DIR/incompatible_msrv.rs:12:39
2+
--> $DIR/incompatible_msrv.rs:13:39
33
|
44
LL | assert_eq!(map.entry("poneyland").key(), &"poneyland");
55
| ^^^^^
@@ -8,13 +8,13 @@ LL | assert_eq!(map.entry("poneyland").key(), &"poneyland");
88
= help: to override `-D warnings` add `#[allow(clippy::incompatible_msrv)]`
99

1010
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.12.0`
11-
--> $DIR/incompatible_msrv.rs:15:11
11+
--> $DIR/incompatible_msrv.rs:16:11
1212
|
1313
LL | v.into_key();
1414
| ^^^^^^^^^^
1515

1616
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.4.0`
17-
--> $DIR/incompatible_msrv.rs:19:5
17+
--> $DIR/incompatible_msrv.rs:20:5
1818
|
1919
LL | sleep(Duration::new(1, 0));
2020
| ^^^^^

0 commit comments

Comments
 (0)