Skip to content

Commit 03e2828

Browse files
committed
Fix span edition for 2024 RPIT coming from an external macro
This fixes a problem where code generated by an external macro with an RPIT would end up using the call-site edition instead of the macro's edition for the RPIT. When used from a 2024 crate, this caused the code to change behavior to the 2024 capturing rules, which we don't want. This was caused by the impl-trait lowering code would replace the span with one marked with `DesugaringKind::OpaqueTy` desugaring. However, it was also overriding the edition of the span with the edition of the local crate. Instead it should be using the edition of the span itself. Fixes #132917
1 parent d163541 commit 03e2828

File tree

3 files changed

+2
-94
lines changed

3 files changed

+2
-94
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
738738
allow_internal_unstable: Option<Lrc<[Symbol]>>,
739739
) -> Span {
740740
self.tcx.with_stable_hashing_context(|hcx| {
741-
span.mark_with_reason(allow_internal_unstable, reason, self.tcx.sess.edition(), hcx)
741+
span.mark_with_reason(allow_internal_unstable, reason, span.edition(), hcx)
742742
})
743743
}
744744

tests/ui/impl-trait/precise-capturing/external-macro.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,21 @@
66
//@ aux-crate: no_use_macro=no-use-macro.rs
77
//@ edition: 2024
88
//@ compile-flags:-Z unstable-options
9+
//@ check-pass
910

1011
no_use_pm::pm_rpit!{}
11-
//~^ ERROR: cannot borrow `x` as mutable
1212

1313
no_use_macro::macro_rpit!{}
14-
//~^ ERROR: cannot borrow `x` as mutable
1514

1615
fn main() {
1716
let mut x = vec![];
1817
x.push(1);
1918

2019
let element = test_pm(&x);
2120
x.push(2);
22-
//~^ ERROR: cannot borrow `x` as mutable
2321
println!("{element}");
2422

2523
let element = test_mbe(&x);
2624
x.push(2);
27-
//~^ ERROR: cannot borrow `x` as mutable
2825
println!("{element}");
2926
}

tests/ui/impl-trait/precise-capturing/external-macro.stderr

-89
This file was deleted.

0 commit comments

Comments
 (0)