Skip to content

Commit 74fb87e

Browse files
committed
Stop sorting bodies by span.
The definition order is already close to the span order, and only differs in corner cases.
1 parent ad3407f commit 74fb87e

File tree

17 files changed

+130
-151
lines changed

17 files changed

+130
-151
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
516516
self.owners.ensure_contains_elem(CRATE_DEF_ID, || None);
517517
self.owners[CRATE_DEF_ID] = Some(hir::OwnerNode::Crate(module));
518518

519-
let body_ids = body_ids(&self.bodies);
520519
let proc_macros =
521520
c.proc_macros.iter().map(|id| self.node_id_to_hir_id[*id].unwrap()).collect();
522521

@@ -552,7 +551,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
552551
let krate = hir::Crate {
553552
owners: self.owners,
554553
bodies: self.bodies,
555-
body_ids,
556554
trait_impls: self.trait_impls,
557555
modules: self.modules,
558556
proc_macros,
@@ -2771,14 +2769,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
27712769
}
27722770
}
27732771

2774-
fn body_ids(bodies: &BTreeMap<hir::BodyId, hir::Body<'_>>) -> Vec<hir::BodyId> {
2775-
// Sorting by span ensures that we get things in order within a
2776-
// file, and also puts the files in a sensible order.
2777-
let mut body_ids: Vec<_> = bodies.keys().cloned().collect();
2778-
body_ids.sort_by_key(|b| bodies[b].value.span);
2779-
body_ids
2780-
}
2781-
27822772
/// Helper struct for delayed construction of GenericArgs.
27832773
struct GenericArgsCtor<'hir> {
27842774
args: SmallVec<[hir::GenericArg<'hir>; 4]>,

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -674,12 +674,6 @@ pub struct Crate<'hir> {
674674
pub bodies: BTreeMap<BodyId, Body<'hir>>,
675675
pub trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
676676

677-
/// A list of the body ids written out in the order in which they
678-
/// appear in the crate. If you're going to process all the bodies
679-
/// in the crate, you should iterate over this list rather than the keys
680-
/// of bodies.
681-
pub body_ids: Vec<BodyId>,
682-
683677
/// A list of modules written out in the order in which they
684678
/// appear in the crate. This includes the main crate module.
685679
pub modules: BTreeMap<LocalDefId, ModuleItems>,

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,16 +1677,12 @@ impl<'tcx> TyCtxt<'tcx> {
16771677
/// crate. If you would prefer to iterate over the bodies
16781678
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
16791679
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + Captures<'tcx> + 'tcx {
1680-
self.hir()
1681-
.krate()
1682-
.body_ids
1683-
.iter()
1684-
.map(move |&body_id| self.hir().body_owner_def_id(body_id))
1680+
self.hir().krate().bodies.keys().map(move |&body_id| self.hir().body_owner_def_id(body_id))
16851681
}
16861682

16871683
pub fn par_body_owners<F: Fn(LocalDefId) + sync::Sync + sync::Send>(self, f: F) {
1688-
par_iter(&self.hir().krate().body_ids)
1689-
.for_each(|&body_id| f(self.hir().body_owner_def_id(body_id)));
1684+
par_iter(&self.hir().krate().bodies)
1685+
.for_each(|(&body_id, _)| f(self.hir().body_owner_def_id(body_id)));
16901686
}
16911687

16921688
pub fn provided_trait_methods(self, id: DefId) -> impl 'tcx + Iterator<Item = &'tcx AssocItem> {

compiler/rustc_typeck/src/check_unused.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use rustc_span::{Span, Symbol};
99

1010
pub fn check_crate(tcx: TyCtxt<'_>) {
1111
let mut used_trait_imports = FxHashSet::default();
12-
for &body_id in tcx.hir().krate().bodies.keys() {
13-
let item_def_id = tcx.hir().body_owner_def_id(body_id);
12+
for item_def_id in tcx.body_owners() {
1413
let imports = tcx.used_trait_imports(item_def_id);
1514
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);
1615
used_trait_imports.extend(imports.iter());

src/test/ui/asm/type-check-1.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ LL | let x = 0;
2525
LL | asm!("{}", const const_bar(x));
2626
| ^ non-constant value
2727

28+
error[E0308]: mismatched types
29+
--> $DIR/type-check-1.rs:48:26
30+
|
31+
LL | asm!("{}", const 0f32);
32+
| ^^^^ expected integer, found `f32`
33+
34+
error[E0308]: mismatched types
35+
--> $DIR/type-check-1.rs:50:26
36+
|
37+
LL | asm!("{}", const 0 as *mut u8);
38+
| ^^^^^^^^^^^^ expected integer, found *-ptr
39+
|
40+
= note: expected type `{integer}`
41+
found raw pointer `*mut u8`
42+
2843
error: invalid asm output
2944
--> $DIR/type-check-1.rs:10:29
3045
|
@@ -64,21 +79,6 @@ LL | asm!("{}", inout(reg) v[..]);
6479
= help: the trait `Sized` is not implemented for `[u64]`
6580
= note: all inline asm arguments must have a statically known size
6681

67-
error[E0308]: mismatched types
68-
--> $DIR/type-check-1.rs:48:26
69-
|
70-
LL | asm!("{}", const 0f32);
71-
| ^^^^ expected integer, found `f32`
72-
73-
error[E0308]: mismatched types
74-
--> $DIR/type-check-1.rs:50:26
75-
|
76-
LL | asm!("{}", const 0 as *mut u8);
77-
| ^^^^^^^^^^^^ expected integer, found *-ptr
78-
|
79-
= note: expected type `{integer}`
80-
found raw pointer `*mut u8`
81-
8282
error[E0308]: mismatched types
8383
--> $DIR/type-check-1.rs:60:25
8484
|

src/test/ui/borrowck/issue-64453.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
error[E0507]: cannot move out of static item `settings_dir`
2-
--> $DIR/issue-64453.rs:14:37
3-
|
4-
LL | let settings_data = from_string(settings_dir);
5-
| ^^^^^^^^^^^^ move occurs because `settings_dir` has type `String`, which does not implement the `Copy` trait
6-
71
error: `Arguments::<'a>::new_v1` is not yet stable as a const fn
82
--> $DIR/issue-64453.rs:4:31
93
|
@@ -21,6 +15,12 @@ LL | static settings_dir: String = format!("");
2115
|
2216
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
2317

18+
error[E0507]: cannot move out of static item `settings_dir`
19+
--> $DIR/issue-64453.rs:14:37
20+
|
21+
LL | let settings_data = from_string(settings_dir);
22+
| ^^^^^^^^^^^^ move occurs because `settings_dir` has type `String`, which does not implement the `Copy` trait
23+
2424
error: aborting due to 3 previous errors
2525

2626
Some errors have detailed explanations: E0015, E0507.

src/test/ui/const-generics/type_mismatch.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ error[E0308]: mismatched types
44
LL | bar::<N>()
55
| ^ expected `u8`, found `usize`
66

7-
error[E0308]: mismatched types
8-
--> $DIR/type_mismatch.rs:5:31
9-
|
10-
LL | fn bar<const N: u8>() -> [u8; N] {}
11-
| ^ expected `usize`, found `u8`
12-
137
error[E0308]: mismatched types
148
--> $DIR/type_mismatch.rs:5:26
159
|
@@ -18,6 +12,12 @@ LL | fn bar<const N: u8>() -> [u8; N] {}
1812
| |
1913
| implicitly returns `()` as its body has no tail or `return` expression
2014

15+
error[E0308]: mismatched types
16+
--> $DIR/type_mismatch.rs:5:31
17+
|
18+
LL | fn bar<const N: u8>() -> [u8; N] {}
19+
| ^ expected `usize`, found `u8`
20+
2121
error: aborting due to 3 previous errors
2222

2323
For more information about this error, try `rustc --explain E0308`.

src/test/ui/consts/const-extern-fn/const-extern-fn-requires-unsafe.mir.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
2-
--> $DIR/const-extern-fn-requires-unsafe.rs:11:5
2+
--> $DIR/const-extern-fn-requires-unsafe.rs:9:17
33
|
4-
LL | foo();
5-
| ^^^^^ call to unsafe function
4+
LL | let a: [u8; foo()];
5+
| ^^^^^ call to unsafe function
66
|
77
= note: consult the function's documentation for information on how to avoid undefined behavior
88

99
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
10-
--> $DIR/const-extern-fn-requires-unsafe.rs:9:17
10+
--> $DIR/const-extern-fn-requires-unsafe.rs:11:5
1111
|
12-
LL | let a: [u8; foo()];
13-
| ^^^^^ call to unsafe function
12+
LL | foo();
13+
| ^^^^^ call to unsafe function
1414
|
1515
= note: consult the function's documentation for information on how to avoid undefined behavior
1616

src/test/ui/consts/issue-66693.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
error: argument to `panic!()` in a const context must have type `&str`
2-
--> $DIR/issue-66693.rs:13:5
3-
|
4-
LL | panic!(&1);
5-
| ^^^^^^^^^^^
6-
|
7-
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
8-
91
error: argument to `panic!()` in a const context must have type `&str`
102
--> $DIR/issue-66693.rs:6:15
113
|
@@ -22,5 +14,13 @@ LL | static _FOO: () = panic!(true);
2214
|
2315
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
2416

17+
error: argument to `panic!()` in a const context must have type `&str`
18+
--> $DIR/issue-66693.rs:13:5
19+
|
20+
LL | panic!(&1);
21+
| ^^^^^^^^^^^
22+
|
23+
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
24+
2525
error: aborting due to 3 previous errors
2626

src/test/ui/issues/issue-47486.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/issue-47486.rs:3:31
3+
|
4+
LL | [0u8; std::mem::size_of::<_>()];
5+
| ^ cannot infer type
6+
17
error[E0308]: mismatched types
28
--> $DIR/issue-47486.rs:2:10
39
|
410
LL | () < std::mem::size_of::<_>();
511
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize`
612

7-
error[E0282]: type annotations needed
8-
--> $DIR/issue-47486.rs:3:11
9-
|
10-
LL | [0u8; std::mem::size_of::<_>()];
11-
| ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
12-
1313
error: aborting due to 2 previous errors
1414

1515
Some errors have detailed explanations: E0282, E0308.

src/test/ui/liveness/liveness-return-last-stmt-semi.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/liveness-return-last-stmt-semi.rs:4:41
3-
|
4-
LL | macro_rules! test { () => { fn foo() -> i32 { 1; } } }
5-
| --- ^^^ - help: consider removing this semicolon
6-
| | |
7-
| | expected `i32`, found `()`
8-
| implicitly returns `()` as its body has no tail or `return` expression
9-
...
10-
LL | test!();
11-
| -------- in this macro invocation
12-
|
13-
= note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
14-
151
error[E0308]: mismatched types
162
--> $DIR/liveness-return-last-stmt-semi.rs:7:19
173
|
@@ -38,6 +24,20 @@ LL | fn baz(x: u64) -> u32 {
3824
| |
3925
| implicitly returns `()` as its body has no tail or `return` expression
4026

27+
error[E0308]: mismatched types
28+
--> $DIR/liveness-return-last-stmt-semi.rs:4:41
29+
|
30+
LL | macro_rules! test { () => { fn foo() -> i32 { 1; } } }
31+
| --- ^^^ - help: consider removing this semicolon
32+
| | |
33+
| | expected `i32`, found `()`
34+
| implicitly returns `()` as its body has no tail or `return` expression
35+
...
36+
LL | test!();
37+
| -------- in this macro invocation
38+
|
39+
= note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
40+
4141
error: aborting due to 4 previous errors
4242

4343
For more information about this error, try `rustc --explain E0308`.

src/test/ui/proc-macro/attribute-with-error.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/attribute-with-error.rs:25:22
3+
|
4+
LL | let a: i32 = "foo";
5+
| --- ^^^^^ expected `i32`, found `&str`
6+
| |
7+
| expected due to this
8+
19
error[E0308]: mismatched types
210
--> $DIR/attribute-with-error.rs:10:18
311
|
@@ -14,14 +22,6 @@ LL | let b: i32 = "f'oo";
1422
| |
1523
| expected due to this
1624

17-
error[E0308]: mismatched types
18-
--> $DIR/attribute-with-error.rs:25:22
19-
|
20-
LL | let a: i32 = "foo";
21-
| --- ^^^^^ expected `i32`, found `&str`
22-
| |
23-
| expected due to this
24-
2525
error[E0308]: mismatched types
2626
--> $DIR/attribute-with-error.rs:35:22
2727
|

src/test/ui/repeat_count.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ error[E0308]: mismatched types
3030
LL | let e = [0; "foo"];
3131
| ^^^^^ expected `usize`, found `&str`
3232

33-
error[E0308]: mismatched types
34-
--> $DIR/repeat_count.rs:31:17
35-
|
36-
LL | let g = [0; G { g: () }];
37-
| ^^^^^^^^^^^ expected `usize`, found struct `G`
38-
3933
error[E0308]: mismatched types
4034
--> $DIR/repeat_count.rs:19:17
4135
|
@@ -63,6 +57,12 @@ help: change the type of the numeric literal from `u8` to `usize`
6357
LL | let f = [0; 4usize];
6458
| ~~~~~~
6559

60+
error[E0308]: mismatched types
61+
--> $DIR/repeat_count.rs:31:17
62+
|
63+
LL | let g = [0; G { g: () }];
64+
| ^^^^^^^^^^^ expected `usize`, found struct `G`
65+
6666
error: aborting due to 9 previous errors
6767

6868
Some errors have detailed explanations: E0308, E0435.

src/test/ui/suggestions/impl-trait-with-missing-bounds.stderr

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
error[E0277]: `<impl Iterator as Iterator>::Item` doesn't implement `Debug`
2-
--> $DIR/impl-trait-with-missing-bounds.rs:6:13
3-
|
4-
LL | qux(constraint);
5-
| ^^^^^^^^^^ `<impl Iterator as Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `Debug`
6-
|
7-
= help: the trait `Debug` is not implemented for `<impl Iterator as Iterator>::Item`
8-
note: required by a bound in `qux`
9-
--> $DIR/impl-trait-with-missing-bounds.rs:50:16
10-
|
11-
LL | fn qux(_: impl std::fmt::Debug) {}
12-
| ^^^^^^^^^^^^^^^ required by this bound in `qux`
13-
help: introduce a type parameter with a trait bound instead of using `impl Trait`
14-
|
15-
LL | fn foo<I: Iterator>(constraints: I) where <I as Iterator>::Item: Debug {
16-
| +++++++++++++ ~ ++++++++++++++++++++++++++++++++++
17-
181
error[E0277]: `<impl Iterator as Iterator>::Item` doesn't implement `Debug`
192
--> $DIR/impl-trait-with-missing-bounds.rs:14:13
203
|
@@ -83,6 +66,23 @@ help: introduce a type parameter with a trait bound instead of using `impl Trait
8366
LL | fn bak<I: Iterator + std::fmt::Debug>(constraints: I) where <I as Iterator>::Item: Debug {
8467
| +++++++++++++++++++++++++++++++ ~ ++++++++++++++++++++++++++++++++++
8568

69+
error[E0277]: `<impl Iterator as Iterator>::Item` doesn't implement `Debug`
70+
--> $DIR/impl-trait-with-missing-bounds.rs:6:13
71+
|
72+
LL | qux(constraint);
73+
| ^^^^^^^^^^ `<impl Iterator as Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `Debug`
74+
|
75+
= help: the trait `Debug` is not implemented for `<impl Iterator as Iterator>::Item`
76+
note: required by a bound in `qux`
77+
--> $DIR/impl-trait-with-missing-bounds.rs:50:16
78+
|
79+
LL | fn qux(_: impl std::fmt::Debug) {}
80+
| ^^^^^^^^^^^^^^^ required by this bound in `qux`
81+
help: introduce a type parameter with a trait bound instead of using `impl Trait`
82+
|
83+
LL | fn foo<I: Iterator>(constraints: I) where <I as Iterator>::Item: Debug {
84+
| +++++++++++++ ~ ++++++++++++++++++++++++++++++++++
85+
8686
error[E0277]: `<impl Iterator as Iterator>::Item` doesn't implement `Debug`
8787
--> $DIR/impl-trait-with-missing-bounds.rs:45:13
8888
|

0 commit comments

Comments
 (0)