Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix span edition for 2024 RPIT coming from an external macro #133080

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
20 changes: 20 additions & 0 deletions tests/ui/impl-trait/precise-capturing/auxiliary/no-use-macro.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 29 additions & 0 deletions tests/ui/impl-trait/precise-capturing/auxiliary/no-use-pm.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 26 additions & 0 deletions tests/ui/impl-trait/precise-capturing/external-macro.rs
Original file line number Diff line number Diff line change
@@ -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