mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Rollup merge of #133080 - ehuss:edition-desugar-span, r=compiler-errors
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 https://github.com/rust-lang/rust/issues/132917
This commit is contained in:
commit
fc8d2b38d8
@ -738,7 +738,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
allow_internal_unstable: Option<Lrc<[Symbol]>>,
|
||||
) -> Span {
|
||||
self.tcx.with_stable_hashing_context(|hcx| {
|
||||
span.mark_with_reason(allow_internal_unstable, reason, self.tcx.sess.edition(), hcx)
|
||||
span.mark_with_reason(allow_internal_unstable, reason, span.edition(), hcx)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
// A macro_rules macro in 2015 that has an RPIT without `use<>` that would
|
||||
// cause a problem with 2024 capturing rules.
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! macro_rpit {
|
||||
() => {
|
||||
fn test_mbe(x: &Vec<i32>) -> impl std::fmt::Display {
|
||||
x[0]
|
||||
}
|
||||
|
||||
pub fn from_mbe() {
|
||||
let mut x = vec![];
|
||||
x.push(1);
|
||||
|
||||
let element = test_mbe(&x);
|
||||
x.push(2);
|
||||
println!("{element}");
|
||||
}
|
||||
};
|
||||
}
|
29
tests/ui/impl-trait/precise-capturing/auxiliary/no-use-pm.rs
Normal file
29
tests/ui/impl-trait/precise-capturing/auxiliary/no-use-pm.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// A proc-macro in 2015 that has an RPIT without `use<>` that would cause a
|
||||
// problem with 2024 capturing rules.
|
||||
|
||||
//@ force-host
|
||||
//@ no-prefer-dynamic
|
||||
|
||||
#![crate_type = "proc-macro"]
|
||||
|
||||
extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
#[proc_macro]
|
||||
pub fn pm_rpit(input: TokenStream) -> TokenStream {
|
||||
"fn test_pm(x: &Vec<i32>) -> impl std::fmt::Display {
|
||||
x[0]
|
||||
}
|
||||
|
||||
pub fn from_pm() {
|
||||
let mut x = vec![];
|
||||
x.push(1);
|
||||
|
||||
let element = test_pm(&x);
|
||||
x.push(2);
|
||||
println!(\"{element}\");
|
||||
}
|
||||
"
|
||||
.parse()
|
||||
.unwrap()
|
||||
}
|
26
tests/ui/impl-trait/precise-capturing/external-macro.rs
Normal file
26
tests/ui/impl-trait/precise-capturing/external-macro.rs
Normal file
@ -0,0 +1,26 @@
|
||||
// Tests that code generated from an external macro (MBE and proc-macro) that
|
||||
// has an RPIT will not fail when the call-site is 2024.
|
||||
// https://github.com/rust-lang/rust/issues/132917
|
||||
|
||||
//@ aux-crate: no_use_pm=no-use-pm.rs
|
||||
//@ aux-crate: no_use_macro=no-use-macro.rs
|
||||
//@ edition: 2024
|
||||
//@ compile-flags:-Z unstable-options
|
||||
//@ check-pass
|
||||
|
||||
no_use_pm::pm_rpit!{}
|
||||
|
||||
no_use_macro::macro_rpit!{}
|
||||
|
||||
fn main() {
|
||||
let mut x = vec![];
|
||||
x.push(1);
|
||||
|
||||
let element = test_pm(&x);
|
||||
x.push(2);
|
||||
println!("{element}");
|
||||
|
||||
let element = test_mbe(&x);
|
||||
x.push(2);
|
||||
println!("{element}");
|
||||
}
|
Loading…
Reference in New Issue
Block a user