Skip to content

Commit fbb9396

Browse files
committed
Move check_for_entry_fn and check_unused to a later stage
1 parent 6674519 commit fbb9396

File tree

11 files changed

+60
-52
lines changed

11 files changed

+60
-52
lines changed

src/librustc_interface/passes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,9 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
871871
tcx.ensure().check_mod_intrinsics(local_def_id);
872872
});
873873
});
874+
},
875+
{
876+
typeck::check_crate_late(tcx);
874877
}
875878
);
876879
});

src/librustc_typeck/check_unused.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use rustc_span::Span;
1010
use syntax::ast;
1111

1212
pub fn check_crate(tcx: TyCtxt<'_>) {
13+
let _timer = tcx.sess.timer("check_unused_imports");
14+
1315
let mut used_trait_imports = DefIdSet::default();
1416
for &body_id in tcx.hir().krate().bodies.keys() {
1517
let item_def_id = tcx.hir().body_owner_def_id(body_id);

src/librustc_typeck/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
290290
}
291291

292292
fn check_for_entry_fn(tcx: TyCtxt<'_>) {
293+
let _timer = tcx.sess.prof.generic_activity("check_entry_fn");
293294
match tcx.entry_fn(LOCAL_CRATE) {
294295
Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id),
295296
Some((def_id, EntryFnType::Start)) => check_start_fn_ty(tcx, def_id),
@@ -361,12 +362,13 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
361362
)
362363
});
363364

364-
check_unused::check_crate(tcx);
365-
check_for_entry_fn(tcx);
366-
367365
if tcx.sess.err_count() == 0 { Ok(()) } else { Err(ErrorReported) }
368366
}
369367

368+
pub fn check_crate_late(tcx: TyCtxt<'_>) {
369+
join(|| check_unused::check_crate(tcx), || check_for_entry_fn(tcx));
370+
}
371+
370372
/// A quasi-deprecated helper used in rustdoc and clippy to get
371373
/// the type from a HIR node.
372374
pub fn hir_ty_to_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'_>) -> Ty<'tcx> {

src/test/ui/bad/bad-expr-path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod m1 {}
22

3-
fn main(arguments: Vec<String>) { //~ ERROR `main` function has wrong type
3+
fn main(arguments: Vec<String>) {
44
log(debug, m1::arguments);
55
//~^ ERROR cannot find function `log` in this scope
66
//~| ERROR cannot find value `debug` in this scope

src/test/ui/bad/bad-expr-path.stderr

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ error[E0425]: cannot find value `arguments` in module `m1`
1616
LL | log(debug, m1::arguments);
1717
| ^^^^^^^^^ not found in `m1`
1818

19-
error[E0580]: `main` function has wrong type
20-
--> $DIR/bad-expr-path.rs:3:1
21-
|
22-
LL | fn main(arguments: Vec<String>) {
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters
24-
|
25-
= note: expected fn pointer `fn()`
26-
found fn pointer `fn(std::vec::Vec<std::string::String>)`
27-
28-
error: aborting due to 4 previous errors
19+
error: aborting due to 3 previous errors
2920

30-
Some errors have detailed explanations: E0425, E0580.
31-
For more information about an error, try `rustc --explain E0425`.
21+
For more information about this error, try `rustc --explain E0425`.

src/test/ui/bad/bad-expr-path2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod m1 {
22
pub mod arguments {}
33
}
44

5-
fn main(arguments: Vec<String>) { //~ ERROR `main` function has wrong type
5+
fn main(arguments: Vec<String>) {
66
log(debug, m1::arguments);
77
//~^ ERROR cannot find function `log` in this scope
88
//~| ERROR cannot find value `debug` in this scope

src/test/ui/bad/bad-expr-path2.stderr

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,7 @@ error[E0423]: expected value, found module `m1::arguments`
1616
LL | log(debug, m1::arguments);
1717
| ^^^^^^^^^^^^^ not a value
1818

19-
error[E0580]: `main` function has wrong type
20-
--> $DIR/bad-expr-path2.rs:5:1
21-
|
22-
LL | fn main(arguments: Vec<String>) {
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters
24-
|
25-
= note: expected fn pointer `fn()`
26-
found fn pointer `fn(std::vec::Vec<std::string::String>)`
27-
28-
error: aborting due to 4 previous errors
19+
error: aborting due to 3 previous errors
2920

30-
Some errors have detailed explanations: E0423, E0425, E0580.
21+
Some errors have detailed explanations: E0423, E0425.
3122
For more information about an error, try `rustc --explain E0423`.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![deny(unused_imports)]
2+
#![allow(dead_code)]
3+
4+
// Be sure that if we just bring some methods into scope that they're also
5+
// counted as being used.
6+
use test::B;
7+
// But only when actually used: do not get confused by the method with the same name.
8+
use test::B2; //~ ERROR unused import: `test::B2`
9+
10+
mod test {
11+
pub trait B {
12+
fn b(&self) {}
13+
}
14+
pub trait B2 {
15+
fn b(&self) {}
16+
}
17+
pub struct C;
18+
impl B for C {}
19+
}
20+
21+
fn main() {
22+
test::C.b();
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unused import: `test::B2`
2+
--> $DIR/lint-unused-imports-2.rs:8:5
3+
|
4+
LL | use test::B2;
5+
| ^^^^^^^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/lint-unused-imports-2.rs:1:9
9+
|
10+
LL | #![deny(unused_imports)]
11+
| ^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+

src/test/ui/lint/lint-unused-imports.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ use std::option::Option::{Some, None};
1313
//~^ ERROR unused imports: `None`, `Some`
1414

1515
use test::A; //~ ERROR unused import: `test::A`
16-
// Be sure that if we just bring some methods into scope that they're also
17-
// counted as being used.
18-
use test::B;
19-
// But only when actually used: do not get confused by the method with the same name.
20-
use test::B2; //~ ERROR unused import: `test::B2`
2116

2217
// Make sure this import is warned about when at least one of its imported names
2318
// is unused
@@ -30,11 +25,6 @@ mod test2 {
3025

3126
mod test {
3227
pub trait A { fn a(&self) {} }
33-
pub trait B { fn b(&self) {} }
34-
pub trait B2 { fn b(&self) {} }
35-
pub struct C;
36-
impl A for C {}
37-
impl B for C {}
3828
}
3929

4030
mod foo {
@@ -85,6 +75,5 @@ fn main() {
8575
let mut a = 3;
8676
let mut b = 4;
8777
swap(&mut a, &mut b);
88-
test::C.b();
8978
let _a = foo();
9079
}

src/test/ui/lint/lint-unused-imports.stderr

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ LL | use test::A;
2323
| ^^^^^^^
2424

2525
error: unused import: `bar`
26-
--> $DIR/lint-unused-imports.rs:24:18
26+
--> $DIR/lint-unused-imports.rs:19:18
2727
|
2828
LL | use test2::{foo, bar};
2929
| ^^^
3030

3131
error: unused import: `foo::Square`
32-
--> $DIR/lint-unused-imports.rs:52:13
32+
--> $DIR/lint-unused-imports.rs:42:13
3333
|
3434
LL | use foo::Square;
3535
| ^^^^^^^^^^^
3636

3737
error: the item `g` is imported redundantly
38-
--> $DIR/lint-unused-imports.rs:68:9
38+
--> $DIR/lint-unused-imports.rs:58:9
3939
|
4040
LL | / fn g() {
4141
LL | | use self::g;
@@ -48,13 +48,13 @@ LL | | }
4848
| |_- the item `g` is already defined here
4949

5050
error: unused import: `self::g`
51-
--> $DIR/lint-unused-imports.rs:68:9
51+
--> $DIR/lint-unused-imports.rs:58:9
5252
|
5353
LL | use self::g;
5454
| ^^^^^^^
5555

5656
error: the item `foo` is imported redundantly
57-
--> $DIR/lint-unused-imports.rs:78:9
57+
--> $DIR/lint-unused-imports.rs:68:9
5858
|
5959
LL | use test2::{foo, bar};
6060
| --- the item `foo` is already imported here
@@ -63,16 +63,10 @@ LL | use test2::foo;
6363
| ^^^^^^^^^^
6464

6565
error: unused import: `test2::foo`
66-
--> $DIR/lint-unused-imports.rs:78:9
66+
--> $DIR/lint-unused-imports.rs:68:9
6767
|
6868
LL | use test2::foo;
6969
| ^^^^^^^^^^
7070

71-
error: unused import: `test::B2`
72-
--> $DIR/lint-unused-imports.rs:20:5
73-
|
74-
LL | use test::B2;
75-
| ^^^^^^^^
76-
77-
error: aborting due to 10 previous errors
71+
error: aborting due to 9 previous errors
7872

0 commit comments

Comments
 (0)