Skip to content

Commit 917a50a

Browse files
committed
Auto merge of rust-lang#133079 - matthiaskrgr:rollup-k8u7syk, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#132817 (Recurse into APITs in `impl_trait_overcaptures`) - rust-lang#133021 (Refactor `configure_annotatable`) - rust-lang#133045 (tests: Test pac-ret flag merging on clang with LTO) - rust-lang#133049 (Change Visitor::visit_precise_capturing_arg so it returns a Visitor::Result) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ce40196 + a111716 commit 917a50a

File tree

7 files changed

+117
-119
lines changed

7 files changed

+117
-119
lines changed

Diff for: compiler/rustc_ast/src/visit.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ pub trait Visitor<'ast>: Sized {
200200
fn visit_param_bound(&mut self, bounds: &'ast GenericBound, _ctxt: BoundKind) -> Self::Result {
201201
walk_param_bound(self, bounds)
202202
}
203-
fn visit_precise_capturing_arg(&mut self, arg: &'ast PreciseCapturingArg) {
204-
walk_precise_capturing_arg(self, arg);
203+
fn visit_precise_capturing_arg(&mut self, arg: &'ast PreciseCapturingArg) -> Self::Result {
204+
walk_precise_capturing_arg(self, arg)
205205
}
206206
fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef) -> Self::Result {
207207
walk_poly_trait_ref(self, t)
@@ -730,14 +730,10 @@ pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericB
730730
pub fn walk_precise_capturing_arg<'a, V: Visitor<'a>>(
731731
visitor: &mut V,
732732
arg: &'a PreciseCapturingArg,
733-
) {
733+
) -> V::Result {
734734
match arg {
735-
PreciseCapturingArg::Lifetime(lt) => {
736-
visitor.visit_lifetime(lt, LifetimeCtxt::GenericArg);
737-
}
738-
PreciseCapturingArg::Arg(path, id) => {
739-
visitor.visit_path(path, *id);
740-
}
735+
PreciseCapturingArg::Lifetime(lt) => visitor.visit_lifetime(lt, LifetimeCtxt::GenericArg),
736+
PreciseCapturingArg::Arg(path, id) => visitor.visit_path(path, *id),
741737
}
742738
}
743739

Diff for: compiler/rustc_builtin_macros/src/cfg_eval.rs

+47-90
Original file line numberDiff line numberDiff line change
@@ -39,50 +39,10 @@ pub(crate) fn cfg_eval(
3939
let features = Some(features);
4040
CfgEval(StripUnconfigured { sess, features, config_tokens: true, lint_node_id })
4141
.configure_annotatable(annotatable)
42-
// Since the item itself has already been configured by the `InvocationCollector`,
43-
// we know that fold result vector will contain exactly one element.
44-
.unwrap()
4542
}
4643

4744
struct CfgEval<'a>(StripUnconfigured<'a>);
4845

49-
fn flat_map_annotatable(
50-
vis: &mut impl MutVisitor,
51-
annotatable: Annotatable,
52-
) -> Option<Annotatable> {
53-
match annotatable {
54-
Annotatable::Item(item) => vis.flat_map_item(item).pop().map(Annotatable::Item),
55-
Annotatable::AssocItem(item, ctxt) => {
56-
Some(Annotatable::AssocItem(vis.flat_map_assoc_item(item, ctxt).pop()?, ctxt))
57-
}
58-
Annotatable::ForeignItem(item) => {
59-
vis.flat_map_foreign_item(item).pop().map(Annotatable::ForeignItem)
60-
}
61-
Annotatable::Stmt(stmt) => {
62-
vis.flat_map_stmt(stmt.into_inner()).pop().map(P).map(Annotatable::Stmt)
63-
}
64-
Annotatable::Expr(mut expr) => {
65-
vis.visit_expr(&mut expr);
66-
Some(Annotatable::Expr(expr))
67-
}
68-
Annotatable::Arm(arm) => vis.flat_map_arm(arm).pop().map(Annotatable::Arm),
69-
Annotatable::ExprField(field) => {
70-
vis.flat_map_expr_field(field).pop().map(Annotatable::ExprField)
71-
}
72-
Annotatable::PatField(fp) => vis.flat_map_pat_field(fp).pop().map(Annotatable::PatField),
73-
Annotatable::GenericParam(param) => {
74-
vis.flat_map_generic_param(param).pop().map(Annotatable::GenericParam)
75-
}
76-
Annotatable::Param(param) => vis.flat_map_param(param).pop().map(Annotatable::Param),
77-
Annotatable::FieldDef(sf) => vis.flat_map_field_def(sf).pop().map(Annotatable::FieldDef),
78-
Annotatable::Variant(v) => vis.flat_map_variant(v).pop().map(Annotatable::Variant),
79-
Annotatable::Crate(mut krate) => {
80-
vis.visit_crate(&mut krate);
81-
Some(Annotatable::Crate(krate))
82-
}
83-
}
84-
}
85-
8646
fn has_cfg_or_cfg_attr(annotatable: &Annotatable) -> bool {
8747
struct CfgFinder;
8848

@@ -106,14 +66,7 @@ fn has_cfg_or_cfg_attr(annotatable: &Annotatable) -> bool {
10666
Annotatable::ForeignItem(item) => CfgFinder.visit_foreign_item(item),
10767
Annotatable::Stmt(stmt) => CfgFinder.visit_stmt(stmt),
10868
Annotatable::Expr(expr) => CfgFinder.visit_expr(expr),
109-
Annotatable::Arm(arm) => CfgFinder.visit_arm(arm),
110-
Annotatable::ExprField(field) => CfgFinder.visit_expr_field(field),
111-
Annotatable::PatField(field) => CfgFinder.visit_pat_field(field),
112-
Annotatable::GenericParam(param) => CfgFinder.visit_generic_param(param),
113-
Annotatable::Param(param) => CfgFinder.visit_param(param),
114-
Annotatable::FieldDef(field) => CfgFinder.visit_field_def(field),
115-
Annotatable::Variant(variant) => CfgFinder.visit_variant(variant),
116-
Annotatable::Crate(krate) => CfgFinder.visit_crate(krate),
69+
_ => unreachable!(),
11770
};
11871
res.is_break()
11972
}
@@ -123,11 +76,11 @@ impl CfgEval<'_> {
12376
self.0.configure(node)
12477
}
12578

126-
fn configure_annotatable(&mut self, mut annotatable: Annotatable) -> Option<Annotatable> {
79+
fn configure_annotatable(mut self, annotatable: Annotatable) -> Annotatable {
12780
// Tokenizing and re-parsing the `Annotatable` can have a significant
12881
// performance impact, so try to avoid it if possible
12982
if !has_cfg_or_cfg_attr(&annotatable) {
130-
return Some(annotatable);
83+
return annotatable;
13184
}
13285

13386
// The majority of parsed attribute targets will never need to have early cfg-expansion
@@ -140,39 +93,6 @@ impl CfgEval<'_> {
14093
// the location of `#[cfg]` and `#[cfg_attr]` in the token stream. The tokenization
14194
// process is lossless, so this process is invisible to proc-macros.
14295

143-
let parse_annotatable_with: for<'a> fn(&mut Parser<'a>) -> PResult<'a, _> =
144-
match annotatable {
145-
Annotatable::Item(_) => {
146-
|parser| Ok(Annotatable::Item(parser.parse_item(ForceCollect::Yes)?.unwrap()))
147-
}
148-
Annotatable::AssocItem(_, AssocCtxt::Trait) => |parser| {
149-
Ok(Annotatable::AssocItem(
150-
parser.parse_trait_item(ForceCollect::Yes)?.unwrap().unwrap(),
151-
AssocCtxt::Trait,
152-
))
153-
},
154-
Annotatable::AssocItem(_, AssocCtxt::Impl) => |parser| {
155-
Ok(Annotatable::AssocItem(
156-
parser.parse_impl_item(ForceCollect::Yes)?.unwrap().unwrap(),
157-
AssocCtxt::Impl,
158-
))
159-
},
160-
Annotatable::ForeignItem(_) => |parser| {
161-
Ok(Annotatable::ForeignItem(
162-
parser.parse_foreign_item(ForceCollect::Yes)?.unwrap().unwrap(),
163-
))
164-
},
165-
Annotatable::Stmt(_) => |parser| {
166-
Ok(Annotatable::Stmt(P(parser
167-
.parse_stmt_without_recovery(false, ForceCollect::Yes)?
168-
.unwrap())))
169-
},
170-
Annotatable::Expr(_) => {
171-
|parser| Ok(Annotatable::Expr(parser.parse_expr_force_collect()?))
172-
}
173-
_ => unreachable!(),
174-
};
175-
17696
// 'Flatten' all nonterminals (i.e. `TokenKind::Interpolated`)
17797
// to `None`-delimited groups containing the corresponding tokens. This
17898
// is normally delayed until the proc-macro server actually needs to
@@ -191,19 +111,56 @@ impl CfgEval<'_> {
191111
// Re-parse the tokens, setting the `capture_cfg` flag to save extra information
192112
// to the captured `AttrTokenStream` (specifically, we capture
193113
// `AttrTokenTree::AttrsTarget` for all occurrences of `#[cfg]` and `#[cfg_attr]`)
114+
//
115+
// After that we have our re-parsed `AttrTokenStream`, recursively configuring
116+
// our attribute target will correctly configure the tokens as well.
194117
let mut parser = Parser::new(&self.0.sess.psess, orig_tokens, None);
195118
parser.capture_cfg = true;
196-
match parse_annotatable_with(&mut parser) {
197-
Ok(a) => annotatable = a,
119+
let res: PResult<'_, Annotatable> = try {
120+
match annotatable {
121+
Annotatable::Item(_) => {
122+
let item = parser.parse_item(ForceCollect::Yes)?.unwrap();
123+
Annotatable::Item(self.flat_map_item(item).pop().unwrap())
124+
}
125+
Annotatable::AssocItem(_, AssocCtxt::Trait) => {
126+
let item = parser.parse_trait_item(ForceCollect::Yes)?.unwrap().unwrap();
127+
Annotatable::AssocItem(
128+
self.flat_map_assoc_item(item, AssocCtxt::Trait).pop().unwrap(),
129+
AssocCtxt::Trait,
130+
)
131+
}
132+
Annotatable::AssocItem(_, AssocCtxt::Impl) => {
133+
let item = parser.parse_impl_item(ForceCollect::Yes)?.unwrap().unwrap();
134+
Annotatable::AssocItem(
135+
self.flat_map_assoc_item(item, AssocCtxt::Impl).pop().unwrap(),
136+
AssocCtxt::Impl,
137+
)
138+
}
139+
Annotatable::ForeignItem(_) => {
140+
let item = parser.parse_foreign_item(ForceCollect::Yes)?.unwrap().unwrap();
141+
Annotatable::ForeignItem(self.flat_map_foreign_item(item).pop().unwrap())
142+
}
143+
Annotatable::Stmt(_) => {
144+
let stmt =
145+
parser.parse_stmt_without_recovery(false, ForceCollect::Yes)?.unwrap();
146+
Annotatable::Stmt(P(self.flat_map_stmt(stmt).pop().unwrap()))
147+
}
148+
Annotatable::Expr(_) => {
149+
let mut expr = parser.parse_expr_force_collect()?;
150+
self.visit_expr(&mut expr);
151+
Annotatable::Expr(expr)
152+
}
153+
_ => unreachable!(),
154+
}
155+
};
156+
157+
match res {
158+
Ok(ann) => ann,
198159
Err(err) => {
199160
err.emit();
200-
return Some(annotatable);
161+
annotatable
201162
}
202163
}
203-
204-
// Now that we have our re-parsed `AttrTokenStream`, recursively configuring
205-
// our attribute target will correctly configure the tokens as well.
206-
flat_map_annotatable(self, annotatable)
207164
}
208165
}
209166

Diff for: compiler/rustc_lint/src/impl_trait_overcaptures.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ where
262262
// If it's owned by this function
263263
&& let opaque =
264264
self.tcx.hir_node_by_def_id(opaque_def_id).expect_opaque_ty()
265-
&& let hir::OpaqueTyOrigin::FnReturn { parent, .. } = opaque.origin
265+
// We want to recurse into RPITs and async fns, even though the latter
266+
// doesn't overcapture on its own, it may mention additional RPITs
267+
// in its bounds.
268+
&& let hir::OpaqueTyOrigin::FnReturn { parent, .. }
269+
| hir::OpaqueTyOrigin::AsyncFn { parent, .. } = opaque.origin
266270
&& parent == self.parent_def_id
267271
{
268272
let opaque_span = self.tcx.def_span(opaque_def_id);

Diff for: tests/run-make/pointer-auth-link-with-c-lto-clang/rmake.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
//@ ignore-cross-compile
1111
// Reason: the compiled binary is executed
1212

13-
use run_make_support::{clang, env_var, llvm_ar, run, rustc, static_lib_name};
13+
use run_make_support::{clang, env_var, llvm_ar, llvm_objdump, run, rustc, static_lib_name};
14+
15+
static PAUTH_A_KEY_PATTERN: &'static str = "paciasp";
16+
static PAUTH_B_KEY_PATTERN: &'static str = "pacibsp";
1417

1518
fn main() {
1619
clang()
1720
.arg("-v")
1821
.lto("thin")
19-
.arg("-mbranch-protection=bti+pac-ret+leaf")
20-
.arg("-O2")
22+
.arg("-mbranch-protection=bti+pac-ret+b-key+leaf")
2123
.arg("-c")
2224
.out_exe("test.o")
2325
.input("test.c")
@@ -32,5 +34,15 @@ fn main() {
3234
.input("test.rs")
3335
.output("test.bin")
3436
.run();
37+
38+
// Check that both a-key and b-key pac-ret survived LTO
39+
llvm_objdump()
40+
.disassemble()
41+
.input("test.bin")
42+
.run()
43+
.assert_stdout_contains_regex(PAUTH_A_KEY_PATTERN)
44+
.assert_stdout_contains_regex(PAUTH_B_KEY_PATTERN);
45+
46+
// Check that the binary actually runs
3547
run("test.bin");
3648
}

Diff for: tests/ui/impl-trait/precise-capturing/overcaptures-2024.fixed

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ run-rustfix
2+
//@ edition: 2018
23

34
#![allow(unused)]
45
#![deny(impl_trait_overcaptures)]
@@ -37,4 +38,8 @@ fn apit2<U, T: Sized>(_: &T, _: U) -> impl Sized + use<U, T> {}
3738
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
3839
//~| WARN this changes meaning in Rust 2024
3940

41+
async fn async_fn<'a>(x: &'a ()) -> impl Sized + use<> {}
42+
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
43+
//~| WARN this changes meaning in Rust 2024
44+
4045
fn main() {}

Diff for: tests/ui/impl-trait/precise-capturing/overcaptures-2024.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//@ run-rustfix
2+
//@ edition: 2018
23

34
#![allow(unused)]
45
#![deny(impl_trait_overcaptures)]
@@ -37,4 +38,8 @@ fn apit2<U>(_: &impl Sized, _: U) -> impl Sized {}
3738
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
3839
//~| WARN this changes meaning in Rust 2024
3940

41+
async fn async_fn<'a>(x: &'a ()) -> impl Sized {}
42+
//~^ ERROR `impl Sized` will capture more lifetimes than possibly intended in edition 2024
43+
//~| WARN this changes meaning in Rust 2024
44+
4045
fn main() {}

0 commit comments

Comments
 (0)