Skip to content

Commit 0b5204f

Browse files
committed
Enable deprecation lint on crate-local items
Previously the lint considered cross-crate items only. That's appropriate for unstable and experimental levels, but not for deprecation. Closes #16409 Due to deny(deprecation), this is a: [breaking-change]
1 parent e2273d9 commit 0b5204f

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

src/librustc/lint/builtin.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1479,20 +1479,20 @@ impl LintPass for Stability {
14791479
_ => return
14801480
};
14811481

1482-
// stability attributes are promises made across crates; do not
1483-
// check anything for crate-local usage.
1484-
if ast_util::is_local(id) { return }
1485-
14861482
let stability = stability::lookup(cx.tcx, id);
1483+
let cross_crate = !ast_util::is_local(id);
1484+
1485+
// stability attributes are promises made across crates; only
1486+
// check DEPRECATED for crate-local usage.
14871487
let (lint, label) = match stability {
14881488
// no stability attributes == Unstable
1489-
None => (UNSTABLE, "unmarked"),
1490-
Some(attr::Stability { level: attr::Unstable, .. }) =>
1491-
(UNSTABLE, "unstable"),
1492-
Some(attr::Stability { level: attr::Experimental, .. }) =>
1493-
(EXPERIMENTAL, "experimental"),
1489+
None if cross_crate => (UNSTABLE, "unmarked"),
1490+
Some(attr::Stability { level: attr::Unstable, .. }) if cross_crate =>
1491+
(UNSTABLE, "unstable"),
1492+
Some(attr::Stability { level: attr::Experimental, .. }) if cross_crate =>
1493+
(EXPERIMENTAL, "experimental"),
14941494
Some(attr::Stability { level: attr::Deprecated, .. }) =>
1495-
(DEPRECATED, "deprecated"),
1495+
(DEPRECATED, "deprecated"),
14961496
_ => return
14971497
};
14981498

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

+17-18
Original file line numberDiff line numberDiff line change
@@ -329,19 +329,19 @@ mod this_crate {
329329
pub struct LockedTupleStruct(int);
330330

331331
fn test() {
332-
// None of the following should generate errors, because
333-
// stability attributes now have meaning only *across* crates,
334-
// not within a single crate.
332+
// Only the deprecated cases of the following should generate
333+
// errors, because other stability attributes now have meaning
334+
// only *across* crates, not within a single crate.
335335

336336
let foo = MethodTester;
337337

338-
deprecated();
339-
foo.method_deprecated();
340-
foo.trait_deprecated();
338+
deprecated(); //~ ERROR use of deprecated item
339+
foo.method_deprecated(); //~ ERROR use of deprecated item
340+
foo.trait_deprecated(); //~ ERROR use of deprecated item
341341

342-
deprecated_text();
343-
foo.method_deprecated_text();
344-
foo.trait_deprecated_text();
342+
deprecated_text(); //~ ERROR use of deprecated item: text
343+
foo.method_deprecated_text(); //~ ERROR use of deprecated item: text
344+
foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
345345

346346
experimental();
347347
foo.method_experimental();
@@ -387,32 +387,31 @@ mod this_crate {
387387
foo.method_locked_text();
388388
foo.trait_locked_text();
389389

390-
391-
let _ = DeprecatedStruct { i: 0 };
390+
let _ = DeprecatedStruct { i: 0 }; //~ ERROR use of deprecated item
392391
let _ = ExperimentalStruct { i: 0 };
393392
let _ = UnstableStruct { i: 0 };
394393
let _ = UnmarkedStruct { i: 0 };
395394
let _ = StableStruct { i: 0 };
396395
let _ = FrozenStruct { i: 0 };
397396
let _ = LockedStruct { i: 0 };
398397

399-
let _ = DeprecatedUnitStruct;
398+
let _ = DeprecatedUnitStruct; //~ ERROR use of deprecated item
400399
let _ = ExperimentalUnitStruct;
401400
let _ = UnstableUnitStruct;
402401
let _ = UnmarkedUnitStruct;
403402
let _ = StableUnitStruct;
404403
let _ = FrozenUnitStruct;
405404
let _ = LockedUnitStruct;
406405

407-
let _ = DeprecatedVariant;
406+
let _ = DeprecatedVariant; //~ ERROR use of deprecated item
408407
let _ = ExperimentalVariant;
409408
let _ = UnstableVariant;
410409
let _ = UnmarkedVariant;
411410
let _ = StableVariant;
412411
let _ = FrozenVariant;
413412
let _ = LockedVariant;
414413

415-
let _ = DeprecatedTupleStruct (1);
414+
let _ = DeprecatedTupleStruct (1); //~ ERROR use of deprecated item
416415
let _ = ExperimentalTupleStruct (1);
417416
let _ = UnstableTupleStruct (1);
418417
let _ = UnmarkedTupleStruct (1);
@@ -422,8 +421,8 @@ mod this_crate {
422421
}
423422

424423
fn test_method_param<F: Trait>(foo: F) {
425-
foo.trait_deprecated();
426-
foo.trait_deprecated_text();
424+
foo.trait_deprecated(); //~ ERROR use of deprecated item
425+
foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
427426
foo.trait_experimental();
428427
foo.trait_experimental_text();
429428
foo.trait_unstable();
@@ -433,8 +432,8 @@ mod this_crate {
433432
}
434433

435434
fn test_method_object(foo: &Trait) {
436-
foo.trait_deprecated();
437-
foo.trait_deprecated_text();
435+
foo.trait_deprecated(); //~ ERROR use of deprecated item
436+
foo.trait_deprecated_text(); //~ ERROR use of deprecated item: text
438437
foo.trait_experimental();
439438
foo.trait_experimental_text();
440439
foo.trait_unstable();

0 commit comments

Comments
 (0)