Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e533559

Browse files
committedMay 26, 2020
Auto merge of rust-lang#72627 - Dylan-DPC:rollup-bavnoq5, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#72270 (add a lint against references to packed fields) - rust-lang#72294 (JS cleanup) - rust-lang#72342 (Warn about unused crate deps) - rust-lang#72401 (Use correct function for detecting `const fn` in unsafety checking) - rust-lang#72581 (Allow unlabeled breaks from desugared `?` in labeled blocks) - rust-lang#72592 (Update books) Failed merges: r? @ghost
2 parents 5239f5c + e061c40 commit e533559

39 files changed

+682
-327
lines changed
 

‎src/librustc_lint/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
276276
UNUSED_ALLOCATION,
277277
UNUSED_DOC_COMMENTS,
278278
UNUSED_EXTERN_CRATES,
279+
UNUSED_CRATE_DEPENDENCIES,
279280
UNUSED_FEATURES,
280281
UNUSED_LABELS,
281282
UNUSED_PARENS,

‎src/librustc_metadata/creader.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob
55

66
use rustc_ast::expand::allocator::{global_allocator_spans, AllocatorKind};
77
use rustc_ast::{ast, attr};
8+
use rustc_data_structures::fx::FxHashSet;
89
use rustc_data_structures::svh::Svh;
910
use rustc_data_structures::sync::Lrc;
1011
use rustc_errors::struct_span_err;
@@ -18,6 +19,7 @@ use rustc_middle::middle::cstore::{
1819
};
1920
use rustc_middle::ty::TyCtxt;
2021
use rustc_session::config::{self, CrateType};
22+
use rustc_session::lint;
2123
use rustc_session::output::validate_crate_name;
2224
use rustc_session::search_paths::PathKind;
2325
use rustc_session::{CrateDisambiguator, Session};
@@ -49,6 +51,7 @@ pub struct CrateLoader<'a> {
4951
local_crate_name: Symbol,
5052
// Mutable output.
5153
cstore: CStore,
54+
used_extern_options: FxHashSet<Symbol>,
5255
}
5356

5457
pub enum LoadedMacro {
@@ -205,6 +208,7 @@ impl<'a> CrateLoader<'a> {
205208
allocator_kind: None,
206209
has_global_allocator: false,
207210
},
211+
used_extern_options: Default::default(),
208212
}
209213
}
210214

@@ -445,6 +449,9 @@ impl<'a> CrateLoader<'a> {
445449
dep_kind: DepKind,
446450
dep: Option<(&'b CratePaths, &'b CrateDep)>,
447451
) -> CrateNum {
452+
if dep.is_none() {
453+
self.used_extern_options.insert(name);
454+
}
448455
self.maybe_resolve_crate(name, span, dep_kind, dep).unwrap_or_else(|err| err.report())
449456
}
450457

@@ -839,6 +846,26 @@ impl<'a> CrateLoader<'a> {
839846
});
840847
}
841848

849+
fn report_unused_deps(&mut self, krate: &ast::Crate) {
850+
// Make a point span rather than covering the whole file
851+
let span = krate.span.shrink_to_lo();
852+
// Complain about anything left over
853+
for (name, _) in self.sess.opts.externs.iter() {
854+
if !self.used_extern_options.contains(&Symbol::intern(name)) {
855+
self.sess.parse_sess.buffer_lint(
856+
lint::builtin::UNUSED_CRATE_DEPENDENCIES,
857+
span,
858+
ast::CRATE_NODE_ID,
859+
&format!(
860+
"external crate `{}` unused in `{}`: remove the dependency or add `use {} as _;`",
861+
name,
862+
self.local_crate_name,
863+
name),
864+
);
865+
}
866+
}
867+
}
868+
842869
pub fn postprocess(&mut self, krate: &ast::Crate) {
843870
self.inject_profiler_runtime();
844871
self.inject_allocator_crate(krate);
@@ -847,6 +874,8 @@ impl<'a> CrateLoader<'a> {
847874
if log_enabled!(log::Level::Info) {
848875
dump_crates(&self.cstore);
849876
}
877+
878+
self.report_unused_deps(krate);
850879
}
851880

852881
pub fn process_extern_crate(
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
use rustc_middle::mir::visit::{PlaceContext, Visitor};
2+
use rustc_middle::mir::*;
3+
use rustc_middle::ty::{self, TyCtxt};
4+
use rustc_session::lint::builtin::UNALIGNED_REFERENCES;
5+
6+
use crate::transform::{MirPass, MirSource};
7+
use crate::util;
8+
9+
pub struct CheckPackedRef;
10+
11+
impl<'tcx> MirPass<'tcx> for CheckPackedRef {
12+
fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx>) {
13+
let param_env = tcx.param_env(src.instance.def_id());
14+
let source_info = SourceInfo::outermost(body.span);
15+
let mut checker = PackedRefChecker { body, tcx, param_env, source_info };
16+
checker.visit_body(&body);
17+
}
18+
}
19+
20+
struct PackedRefChecker<'a, 'tcx> {
21+
body: &'a Body<'tcx>,
22+
tcx: TyCtxt<'tcx>,
23+
param_env: ty::ParamEnv<'tcx>,
24+
source_info: SourceInfo,
25+
}
26+
27+
impl<'a, 'tcx> Visitor<'tcx> for PackedRefChecker<'a, 'tcx> {
28+
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
29+
// Make sure we know where in the MIR we are.
30+
self.source_info = terminator.source_info;
31+
self.super_terminator(terminator, location);
32+
}
33+
34+
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
35+
// Make sure we know where in the MIR we are.
36+
self.source_info = statement.source_info;
37+
self.super_statement(statement, location);
38+
}
39+
40+
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
41+
if context.is_borrow() {
42+
if util::is_disaligned(self.tcx, self.body, self.param_env, *place) {
43+
let source_info = self.source_info;
44+
let lint_root = self.body.source_scopes[source_info.scope]
45+
.local_data
46+
.as_ref()
47+
.assert_crate_local()
48+
.lint_root;
49+
self.tcx.struct_span_lint_hir(
50+
UNALIGNED_REFERENCES,
51+
lint_root,
52+
source_info.span,
53+
|lint| {
54+
lint.build(&format!("reference to packed field is unaligned",))
55+
.note(
56+
"fields of packed structs are not properly aligned, and creating \
57+
a misaligned reference is undefined behavior (even if that \
58+
reference is never dereferenced)",
59+
)
60+
.emit()
61+
},
62+
);
63+
}
64+
}
65+
}
66+
}

‎src/librustc_mir/transform/check_unsafety.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_span::symbol::{sym, Symbol};
1414

1515
use std::ops::Bound;
1616

17-
use crate::const_eval::{is_const_fn, is_min_const_fn};
17+
use crate::const_eval::is_min_const_fn;
1818
use crate::util;
1919

2020
pub struct UnsafetyChecker<'a, 'tcx> {
@@ -527,7 +527,7 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: LocalDefId) -> UnsafetyCheckRe
527527
let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) {
528528
hir::BodyOwnerKind::Closure => (false, false),
529529
hir::BodyOwnerKind::Fn => {
530-
(is_const_fn(tcx, def_id.to_def_id()), is_min_const_fn(tcx, def_id.to_def_id()))
530+
(tcx.is_const_fn_raw(def_id.to_def_id()), is_min_const_fn(tcx, def_id.to_def_id()))
531531
}
532532
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => (true, false),
533533
};

‎src/librustc_mir/transform/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub mod add_call_guards;
1717
pub mod add_moves_for_packed_drops;
1818
pub mod add_retag;
1919
pub mod check_consts;
20+
pub mod check_packed_ref;
2021
pub mod check_unsafety;
2122
pub mod cleanup_post_borrowck;
2223
pub mod const_prop;
@@ -228,10 +229,11 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
228229
validator.qualifs_in_return_place()
229230
}
230231

232+
/// Make MIR ready for const evaluation. This is run on all MIR, not just on consts!
231233
fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> Steal<Body<'_>> {
232234
let def_id = def_id.expect_local();
233235

234-
// Unsafety check uses the raw mir, so make sure it is run
236+
// Unsafety check uses the raw mir, so make sure it is run.
235237
let _ = tcx.unsafety_check_result(def_id);
236238

237239
let mut body = tcx.mir_built(def_id).steal();
@@ -247,6 +249,8 @@ fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> Steal<Body<'_>> {
247249
None,
248250
MirPhase::Const,
249251
&[&[
252+
// MIR-level lints.
253+
&check_packed_ref::CheckPackedRef,
250254
// What we need to do constant evaluation.
251255
&simplify::SimplifyCfg::new("initial"),
252256
&rustc_peek::SanityCheck,

‎src/librustc_passes/loops.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_middle::hir::map::Map;
99
use rustc_middle::ty::query::Providers;
1010
use rustc_middle::ty::TyCtxt;
1111
use rustc_session::Session;
12+
use rustc_span::hygiene::DesugaringKind;
1213
use rustc_span::Span;
1314

1415
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -203,7 +204,7 @@ impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
203204
label: &Destination,
204205
cf_type: &str,
205206
) -> bool {
206-
if self.cx == LabeledBlock {
207+
if !span.is_desugaring(DesugaringKind::QuestionMark) && self.cx == LabeledBlock {
207208
if label.label.is_none() {
208209
struct_span_err!(
209210
self.sess,

‎src/librustc_session/lint/builtin.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ declare_lint! {
7171
"extern crates that are never used"
7272
}
7373

74+
declare_lint! {
75+
pub UNUSED_CRATE_DEPENDENCIES,
76+
Allow,
77+
"crate dependencies that are never used"
78+
}
79+
7480
declare_lint! {
7581
pub UNUSED_QUALIFICATIONS,
7682
Allow,
@@ -216,10 +222,16 @@ declare_lint! {
216222
"lints that have been renamed or removed"
217223
}
218224

225+
declare_lint! {
226+
pub UNALIGNED_REFERENCES,
227+
Allow,
228+
"detects unaligned references to fields of packed structs",
229+
}
230+
219231
declare_lint! {
220232
pub SAFE_PACKED_BORROWS,
221233
Warn,
222-
"safe borrows of fields of packed structs were was erroneously allowed",
234+
"safe borrows of fields of packed structs were erroneously allowed",
223235
@future_incompatible = FutureIncompatibleInfo {
224236
reference: "issue #46043 <https://github.com/rust-lang/rust/issues/46043>",
225237
edition: None,
@@ -523,6 +535,7 @@ declare_lint_pass! {
523535
UNCONDITIONAL_PANIC,
524536
UNUSED_IMPORTS,
525537
UNUSED_EXTERN_CRATES,
538+
UNUSED_CRATE_DEPENDENCIES,
526539
UNUSED_QUALIFICATIONS,
527540
UNKNOWN_LINTS,
528541
UNUSED_VARIABLES,
@@ -545,6 +558,7 @@ declare_lint_pass! {
545558
INVALID_TYPE_PARAM_DEFAULT,
546559
CONST_ERR,
547560
RENAMED_AND_REMOVED_LINTS,
561+
UNALIGNED_REFERENCES,
548562
SAFE_PACKED_BORROWS,
549563
PATTERNS_IN_FNS_WITHOUT_BODY,
550564
MISSING_FRAGMENT_SPECIFIER,

‎src/librustdoc/html/static/main.js

Lines changed: 293 additions & 295 deletions
Large diffs are not rendered by default.

‎src/librustdoc/html/static/settings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Local js definitions:
2+
/* global getCurrentValue, updateLocalStorage */
3+
14
(function () {
25
function changeSetting(settingName, isEnabled) {
36
updateLocalStorage('rustdoc-' + settingName, isEnabled);

‎src/librustdoc/html/static/source-script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// From rust:
2-
/* global sourcesIndex */
2+
/* global search, sourcesIndex */
33

44
// Local js definitions:
55
/* global addClass, getCurrentValue, hasClass, removeClass, updateLocalStorage */

‎src/librustdoc/html/static/storage.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ function removeClass(elem, className) {
2727
function onEach(arr, func, reversed) {
2828
if (arr && arr.length > 0 && func) {
2929
var length = arr.length;
30+
var i;
3031
if (reversed !== true) {
31-
for (var i = 0; i < length; ++i) {
32+
for (i = 0; i < length; ++i) {
3233
if (func(arr[i]) === true) {
3334
return true;
3435
}
3536
}
3637
} else {
37-
for (var i = length - 1; i >= 0; --i) {
38+
for (i = length - 1; i >= 0; --i) {
3839
if (func(arr[i]) === true) {
3940
return true;
4041
}
@@ -51,6 +52,10 @@ function onEachLazy(lazyArray, func, reversed) {
5152
reversed);
5253
}
5354

55+
function hasOwnProperty(obj, property) {
56+
return Object.prototype.hasOwnProperty.call(obj, property);
57+
}
58+
5459
function usableLocalStorage() {
5560
// Check if the browser supports localStorage at all:
5661
if (typeof Storage === "undefined") {

‎src/test/ui/issues/issue-27060-rpass.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,10 @@ pub struct Good {
77
aligned: [u8; 32],
88
}
99

10-
#[repr(packed)]
11-
pub struct JustArray {
12-
array: [u32]
13-
}
14-
1510
// kill this test when that turns to a hard error
1611
#[allow(safe_packed_borrows)]
1712
fn main() {
18-
let good = Good {
19-
data: &0,
20-
data2: [&0, &0],
21-
aligned: [0; 32]
22-
};
13+
let good = Good { data: &0, data2: [&0, &0], aligned: [0; 32] };
2314

2415
unsafe {
2516
let _ = &good.data; // ok

‎src/test/ui/issues/issue-27060.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ pub struct Good {
55
aligned: [u8; 32],
66
}
77

8-
#[repr(packed)]
9-
pub struct JustArray {
10-
array: [u32]
11-
}
12-
138
#[deny(safe_packed_borrows)]
149
fn main() {
1510
let good = Good {

‎src/test/ui/issues/issue-27060.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
2-
--> $DIR/issue-27060.rs:26:13
2+
--> $DIR/issue-27060.rs:21:13
33
|
44
LL | let _ = &good.data;
55
| ^^^^^^^^^^
66
|
77
note: the lint level is defined here
8-
--> $DIR/issue-27060.rs:13:8
8+
--> $DIR/issue-27060.rs:8:8
99
|
1010
LL | #[deny(safe_packed_borrows)]
1111
| ^^^^^^^^^^^^^^^^^^^
@@ -14,7 +14,7 @@ LL | #[deny(safe_packed_borrows)]
1414
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
1515

1616
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
17-
--> $DIR/issue-27060.rs:28:13
17+
--> $DIR/issue-27060.rs:23:13
1818
|
1919
LL | let _ = &good.data2[0];
2020
| ^^^^^^^^^^^^^^
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: --edition 2018
2+
#![feature(label_break_value, try_blocks)]
3+
4+
// run-pass
5+
fn main() {
6+
let _: Result<(), ()> = try {
7+
'foo: {
8+
Err(())?;
9+
break 'foo;
10+
}
11+
};
12+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![deny(unaligned_references)]
2+
3+
#[repr(packed)]
4+
pub struct Good {
5+
data: &'static u32,
6+
data2: [&'static u32; 2],
7+
aligned: [u8; 32],
8+
}
9+
10+
fn main() {
11+
unsafe {
12+
let good = Good { data: &0, data2: [&0, &0], aligned: [0; 32] };
13+
14+
let _ = &good.data; //~ ERROR reference to packed field
15+
let _ = &good.data as *const _; //~ ERROR reference to packed field
16+
let _: *const _ = &good.data; //~ ERROR reference to packed field
17+
let _ = &good.data2[0]; //~ ERROR reference to packed field
18+
let _ = &*good.data; // ok, behind a pointer
19+
let _ = &good.aligned; // ok, has align 1
20+
let _ = &good.aligned[2]; // ok, has align 1
21+
}
22+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error: reference to packed field is unaligned
2+
--> $DIR/unaligned_references.rs:14:17
3+
|
4+
LL | let _ = &good.data;
5+
| ^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unaligned_references.rs:1:9
9+
|
10+
LL | #![deny(unaligned_references)]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
13+
14+
error: reference to packed field is unaligned
15+
--> $DIR/unaligned_references.rs:15:17
16+
|
17+
LL | let _ = &good.data as *const _;
18+
| ^^^^^^^^^^
19+
|
20+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
21+
22+
error: reference to packed field is unaligned
23+
--> $DIR/unaligned_references.rs:16:27
24+
|
25+
LL | let _: *const _ = &good.data;
26+
| ^^^^^^^^^^
27+
|
28+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
29+
30+
error: reference to packed field is unaligned
31+
--> $DIR/unaligned_references.rs:17:17
32+
|
33+
LL | let _ = &good.data2[0];
34+
| ^^^^^^^^^^^^^^
35+
|
36+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
37+
38+
error: aborting due to 4 previous errors
39+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![stable(feature = "foo", since = "1.33.0")]
2+
#![feature(staged_api)]
3+
#![feature(const_compare_raw_pointers)]
4+
#![feature(const_fn)]
5+
6+
#[stable(feature = "foo", since = "1.33.0")]
7+
#[rustc_const_unstable(feature = "const_foo", issue = "none")]
8+
const fn unstable(a: *const i32, b: *const i32) -> bool {
9+
a == b
10+
//~^ pointer operation is unsafe
11+
}
12+
13+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0133]: pointer operation is unsafe and requires unsafe function or block
2+
--> $DIR/unsafe-unstable-const-fn.rs:9:5
3+
|
4+
LL | a == b
5+
| ^^^^^^ pointer operation
6+
|
7+
= note: operations on pointers in constants
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0133`.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub const BAR: &str = "bar";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// edition:2018
2+
// aux-crate:bar=bar.rs
3+
4+
pub const FOO: &str = "foo";
5+
pub use bar::BAR;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Test warnings for a library crate
2+
3+
// check-pass
4+
// aux-crate:bar=bar.rs
5+
// compile-flags:--crate-type lib -Wunused-crate-dependencies
6+
7+
pub fn fib(n: u32) -> Vec<u32> {
8+
//~^ WARNING external crate `bar` unused in
9+
let mut prev = 0;
10+
let mut cur = 1;
11+
let mut v = vec![];
12+
13+
for _ in 0..n {
14+
v.push(prev);
15+
let n = prev + cur;
16+
prev = cur;
17+
cur = n;
18+
}
19+
20+
v
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: external crate `bar` unused in `libfib`: remove the dependency or add `use bar as _;`
2+
--> $DIR/libfib.rs:7:1
3+
|
4+
LL | pub fn fib(n: u32) -> Vec<u32> {
5+
| ^
6+
|
7+
= note: requested on the command line with `-W unused-crate-dependencies`
8+
9+
warning: 1 warning emitted
10+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Suppress by using crate
2+
3+
// edition:2018
4+
// check-pass
5+
// aux-crate:bar=bar.rs
6+
7+
#![warn(unused_crate_dependencies)]
8+
9+
use bar as _;
10+
11+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Warn about unused aliased for the crate
2+
3+
// edition:2018
4+
// check-pass
5+
// aux-crate:bar=bar.rs
6+
// aux-crate:barbar=bar.rs
7+
8+
#![warn(unused_crate_dependencies)]
9+
//~^ WARNING external crate `barbar` unused in
10+
11+
use bar as _;
12+
13+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: external crate `barbar` unused in `unused_aliases`: remove the dependency or add `use barbar as _;`
2+
--> $DIR/unused-aliases.rs:8:1
3+
|
4+
LL | #![warn(unused_crate_dependencies)]
5+
| ^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unused-aliases.rs:8:9
9+
|
10+
LL | #![warn(unused_crate_dependencies)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
warning: 1 warning emitted
14+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Suppress by using crate
2+
3+
// edition:2015
4+
// check-pass
5+
// aux-crate:bar=bar.rs
6+
7+
#![warn(unused_crate_dependencies)]
8+
9+
extern crate bar;
10+
11+
fn main() {
12+
println!("bar {}", bar::BAR);
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Check for unused crate dep, no path
2+
3+
// edition:2018
4+
// check-pass
5+
// aux-crate:bar=bar.rs
6+
7+
#![warn(unused_crate_dependencies)]
8+
//~^ WARNING external crate `bar` unused in
9+
10+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: external crate `bar` unused in `warn_attr`: remove the dependency or add `use bar as _;`
2+
--> $DIR/warn-attr.rs:7:1
3+
|
4+
LL | #![warn(unused_crate_dependencies)]
5+
| ^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/warn-attr.rs:7:9
9+
|
10+
LL | #![warn(unused_crate_dependencies)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
warning: 1 warning emitted
14+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Check for unused crate dep, no path
2+
3+
// edition:2018
4+
// check-pass
5+
// compile-flags: -Wunused-crate-dependencies
6+
// aux-crate:bar=bar.rs
7+
// no-prefer-dynamic
8+
9+
fn main() {}
10+
//~^ WARNING external crate `bar` unused in
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: external crate `bar` unused in `warn_cmdline_static`: remove the dependency or add `use bar as _;`
2+
--> $DIR/warn-cmdline-static.rs:9:1
3+
|
4+
LL | fn main() {}
5+
| ^
6+
|
7+
= note: requested on the command line with `-W unused-crate-dependencies`
8+
9+
warning: 1 warning emitted
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Check for unused crate dep, no path
2+
3+
// edition:2018
4+
// check-pass
5+
// compile-flags: -Wunused-crate-dependencies
6+
// aux-crate:bar=bar.rs
7+
8+
fn main() {}
9+
//~^ WARNING external crate `bar` unused in
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: external crate `bar` unused in `warn_cmdline`: remove the dependency or add `use bar as _;`
2+
--> $DIR/warn-cmdline.rs:8:1
3+
|
4+
LL | fn main() {}
5+
| ^
6+
|
7+
= note: requested on the command line with `-W unused-crate-dependencies`
8+
9+
warning: 1 warning emitted
10+

‎src/tools/rustdoc-js/tester.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function loadMainJsAndIndex(mainJs, searchIndex, storageJs, crate) {
241241
ALIASES = {};
242242
finalJS += 'window = { "currentCrate": "' + crate + '" };\n';
243243
finalJS += 'var rootPath = "../";\n';
244-
finalJS += loadThings(["onEach"], 'function', extractFunction, storageJs);
244+
finalJS += loadThings(["hasOwnProperty", "onEach"], 'function', extractFunction, storageJs);
245245
finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs);
246246
finalJS += loadThings(variablesToLoad, 'variable', extractVariable, mainJs);
247247
finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs);

0 commit comments

Comments
 (0)
This repository has been archived.