Skip to content

Commit de05565

Browse files
author
Jakub Bukaj
committed
rollup merge of #19029: vberger/stability_function_body
Items defined in the body of a function has no visibility outside it, and thus have no reason to inherit its stability. Closes #17488
2 parents f3759dd + 5520050 commit de05565

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/librustc/middle/stability.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,13 @@ impl<'v> Visitor<'v> for Annotator {
8383
b: &'v Block, s: Span, _: NodeId) {
8484
match fk {
8585
FkMethod(_, _, meth) => {
86-
self.annotate(meth.id, &meth.attrs, |v| visit::walk_fn(v, fk, fd, b, s));
86+
// Methods are not already annotated, so we annotate it
87+
self.annotate(meth.id, &meth.attrs, |_| {});
8788
}
88-
_ => visit::walk_fn(self, fk, fd, b, s)
89+
_ => {}
8990
}
91+
// Items defined in a function body have no reason to have
92+
// a stability attribute, so we don't recurse.
9093
}
9194

9295
fn visit_trait_item(&mut self, t: &TraitItem) {

src/test/compile-fail/lint-stability.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,20 @@ mod this_crate {
459459
foo.trait_stable();
460460
}
461461

462+
#[deprecated]
463+
fn test_fn_body() {
464+
fn fn_in_body() {}
465+
fn_in_body();
466+
}
467+
468+
impl MethodTester {
469+
#[deprecated]
470+
fn test_method_body(&self) {
471+
fn fn_in_body() {}
472+
fn_in_body();
473+
}
474+
}
475+
462476
#[deprecated]
463477
pub trait DeprecatedTrait {}
464478

0 commit comments

Comments
 (0)