Stop sorting bodies by span.

The definition order is already close to the span order, and only differs
in corner cases.
This commit is contained in:
Camille GILLOT 2021-07-16 16:54:47 +02:00
parent ad3407f482
commit 74fb87e3a0
17 changed files with 132 additions and 153 deletions

View File

@ -516,7 +516,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.owners.ensure_contains_elem(CRATE_DEF_ID, || None);
self.owners[CRATE_DEF_ID] = Some(hir::OwnerNode::Crate(module));
let body_ids = body_ids(&self.bodies);
let proc_macros =
c.proc_macros.iter().map(|id| self.node_id_to_hir_id[*id].unwrap()).collect();
@ -552,7 +551,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let krate = hir::Crate {
owners: self.owners,
bodies: self.bodies,
body_ids,
trait_impls: self.trait_impls,
modules: self.modules,
proc_macros,
@ -2771,14 +2769,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}
fn body_ids(bodies: &BTreeMap<hir::BodyId, hir::Body<'_>>) -> Vec<hir::BodyId> {
// Sorting by span ensures that we get things in order within a
// file, and also puts the files in a sensible order.
let mut body_ids: Vec<_> = bodies.keys().cloned().collect();
body_ids.sort_by_key(|b| bodies[b].value.span);
body_ids
}
/// Helper struct for delayed construction of GenericArgs.
struct GenericArgsCtor<'hir> {
args: SmallVec<[hir::GenericArg<'hir>; 4]>,

View File

@ -674,12 +674,6 @@ pub struct Crate<'hir> {
pub bodies: BTreeMap<BodyId, Body<'hir>>,
pub trait_impls: BTreeMap<DefId, Vec<LocalDefId>>,
/// A list of the body ids written out in the order in which they
/// appear in the crate. If you're going to process all the bodies
/// in the crate, you should iterate over this list rather than the keys
/// of bodies.
pub body_ids: Vec<BodyId>,
/// A list of modules written out in the order in which they
/// appear in the crate. This includes the main crate module.
pub modules: BTreeMap<LocalDefId, ModuleItems>,

View File

@ -1677,16 +1677,12 @@ impl<'tcx> TyCtxt<'tcx> {
/// crate. If you would prefer to iterate over the bodies
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
pub fn body_owners(self) -> impl Iterator<Item = LocalDefId> + Captures<'tcx> + 'tcx {
self.hir()
.krate()
.body_ids
.iter()
.map(move |&body_id| self.hir().body_owner_def_id(body_id))
self.hir().krate().bodies.keys().map(move |&body_id| self.hir().body_owner_def_id(body_id))
}
pub fn par_body_owners<F: Fn(LocalDefId) + sync::Sync + sync::Send>(self, f: F) {
par_iter(&self.hir().krate().body_ids)
.for_each(|&body_id| f(self.hir().body_owner_def_id(body_id)));
par_iter(&self.hir().krate().bodies)
.for_each(|(&body_id, _)| f(self.hir().body_owner_def_id(body_id)));
}
pub fn provided_trait_methods(self, id: DefId) -> impl 'tcx + Iterator<Item = &'tcx AssocItem> {

View File

@ -9,8 +9,7 @@ use rustc_span::{Span, Symbol};
pub fn check_crate(tcx: TyCtxt<'_>) {
let mut used_trait_imports = FxHashSet::default();
for &body_id in tcx.hir().krate().bodies.keys() {
let item_def_id = tcx.hir().body_owner_def_id(body_id);
for item_def_id in tcx.body_owners() {
let imports = tcx.used_trait_imports(item_def_id);
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);
used_trait_imports.extend(imports.iter());

View File

@ -25,6 +25,21 @@ LL | let x = 0;
LL | asm!("{}", const const_bar(x));
| ^ non-constant value
error[E0308]: mismatched types
--> $DIR/type-check-1.rs:48:26
|
LL | asm!("{}", const 0f32);
| ^^^^ expected integer, found `f32`
error[E0308]: mismatched types
--> $DIR/type-check-1.rs:50:26
|
LL | asm!("{}", const 0 as *mut u8);
| ^^^^^^^^^^^^ expected integer, found *-ptr
|
= note: expected type `{integer}`
found raw pointer `*mut u8`
error: invalid asm output
--> $DIR/type-check-1.rs:10:29
|
@ -64,21 +79,6 @@ LL | asm!("{}", inout(reg) v[..]);
= help: the trait `Sized` is not implemented for `[u64]`
= note: all inline asm arguments must have a statically known size
error[E0308]: mismatched types
--> $DIR/type-check-1.rs:48:26
|
LL | asm!("{}", const 0f32);
| ^^^^ expected integer, found `f32`
error[E0308]: mismatched types
--> $DIR/type-check-1.rs:50:26
|
LL | asm!("{}", const 0 as *mut u8);
| ^^^^^^^^^^^^ expected integer, found *-ptr
|
= note: expected type `{integer}`
found raw pointer `*mut u8`
error[E0308]: mismatched types
--> $DIR/type-check-1.rs:60:25
|

View File

@ -1,9 +1,3 @@
error[E0507]: cannot move out of static item `settings_dir`
--> $DIR/issue-64453.rs:14:37
|
LL | let settings_data = from_string(settings_dir);
| ^^^^^^^^^^^^ move occurs because `settings_dir` has type `String`, which does not implement the `Copy` trait
error: `Arguments::<'a>::new_v1` is not yet stable as a const fn
--> $DIR/issue-64453.rs:4:31
|
@ -21,6 +15,12 @@ LL | static settings_dir: String = format!("");
|
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0507]: cannot move out of static item `settings_dir`
--> $DIR/issue-64453.rs:14:37
|
LL | let settings_data = from_string(settings_dir);
| ^^^^^^^^^^^^ move occurs because `settings_dir` has type `String`, which does not implement the `Copy` trait
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0015, E0507.

View File

@ -4,12 +4,6 @@ error[E0308]: mismatched types
LL | bar::<N>()
| ^ expected `u8`, found `usize`
error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:5:31
|
LL | fn bar<const N: u8>() -> [u8; N] {}
| ^ expected `usize`, found `u8`
error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:5:26
|
@ -18,6 +12,12 @@ LL | fn bar<const N: u8>() -> [u8; N] {}
| |
| implicitly returns `()` as its body has no tail or `return` expression
error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:5:31
|
LL | fn bar<const N: u8>() -> [u8; N] {}
| ^ expected `usize`, found `u8`
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.

View File

@ -1,11 +1,3 @@
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/const-extern-fn-requires-unsafe.rs:11:5
|
LL | foo();
| ^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/const-extern-fn-requires-unsafe.rs:9:17
|
@ -14,6 +6,14 @@ LL | let a: [u8; foo()];
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/const-extern-fn-requires-unsafe.rs:11:5
|
LL | foo();
| ^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0133`.

View File

@ -1,11 +1,3 @@
error: argument to `panic!()` in a const context must have type `&str`
--> $DIR/issue-66693.rs:13:5
|
LL | panic!(&1);
| ^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
error: argument to `panic!()` in a const context must have type `&str`
--> $DIR/issue-66693.rs:6:15
|
@ -22,5 +14,13 @@ LL | static _FOO: () = panic!(true);
|
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
error: argument to `panic!()` in a const context must have type `&str`
--> $DIR/issue-66693.rs:13:5
|
LL | panic!(&1);
| ^^^^^^^^^^^
|
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 3 previous errors

View File

@ -1,15 +1,15 @@
error[E0282]: type annotations needed
--> $DIR/issue-47486.rs:3:31
|
LL | [0u8; std::mem::size_of::<_>()];
| ^ cannot infer type
error[E0308]: mismatched types
--> $DIR/issue-47486.rs:2:10
|
LL | () < std::mem::size_of::<_>();
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize`
error[E0282]: type annotations needed
--> $DIR/issue-47486.rs:3:11
|
LL | [0u8; std::mem::size_of::<_>()];
| ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0282, E0308.

View File

@ -1,17 +1,3 @@
error[E0308]: mismatched types
--> $DIR/liveness-return-last-stmt-semi.rs:4:41
|
LL | macro_rules! test { () => { fn foo() -> i32 { 1; } } }
| --- ^^^ - help: consider removing this semicolon
| | |
| | expected `i32`, found `()`
| implicitly returns `()` as its body has no tail or `return` expression
...
LL | test!();
| -------- in this macro invocation
|
= note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> $DIR/liveness-return-last-stmt-semi.rs:7:19
|
@ -38,6 +24,20 @@ LL | fn baz(x: u64) -> u32 {
| |
| implicitly returns `()` as its body has no tail or `return` expression
error[E0308]: mismatched types
--> $DIR/liveness-return-last-stmt-semi.rs:4:41
|
LL | macro_rules! test { () => { fn foo() -> i32 { 1; } } }
| --- ^^^ - help: consider removing this semicolon
| | |
| | expected `i32`, found `()`
| implicitly returns `()` as its body has no tail or `return` expression
...
LL | test!();
| -------- in this macro invocation
|
= note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0308`.

View File

@ -1,3 +1,11 @@
error[E0308]: mismatched types
--> $DIR/attribute-with-error.rs:25:22
|
LL | let a: i32 = "foo";
| --- ^^^^^ expected `i32`, found `&str`
| |
| expected due to this
error[E0308]: mismatched types
--> $DIR/attribute-with-error.rs:10:18
|
@ -14,14 +22,6 @@ LL | let b: i32 = "f'oo";
| |
| expected due to this
error[E0308]: mismatched types
--> $DIR/attribute-with-error.rs:25:22
|
LL | let a: i32 = "foo";
| --- ^^^^^ expected `i32`, found `&str`
| |
| expected due to this
error[E0308]: mismatched types
--> $DIR/attribute-with-error.rs:35:22
|

View File

@ -30,12 +30,6 @@ error[E0308]: mismatched types
LL | let e = [0; "foo"];
| ^^^^^ expected `usize`, found `&str`
error[E0308]: mismatched types
--> $DIR/repeat_count.rs:31:17
|
LL | let g = [0; G { g: () }];
| ^^^^^^^^^^^ expected `usize`, found struct `G`
error[E0308]: mismatched types
--> $DIR/repeat_count.rs:19:17
|
@ -63,6 +57,12 @@ help: change the type of the numeric literal from `u8` to `usize`
LL | let f = [0; 4usize];
| ~~~~~~
error[E0308]: mismatched types
--> $DIR/repeat_count.rs:31:17
|
LL | let g = [0; G { g: () }];
| ^^^^^^^^^^^ expected `usize`, found struct `G`
error: aborting due to 9 previous errors
Some errors have detailed explanations: E0308, E0435.

View File

@ -1,20 +1,3 @@
error[E0277]: `<impl Iterator as Iterator>::Item` doesn't implement `Debug`
--> $DIR/impl-trait-with-missing-bounds.rs:6:13
|
LL | qux(constraint);
| ^^^^^^^^^^ `<impl Iterator as Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= help: the trait `Debug` is not implemented for `<impl Iterator as Iterator>::Item`
note: required by a bound in `qux`
--> $DIR/impl-trait-with-missing-bounds.rs:50:16
|
LL | fn qux(_: impl std::fmt::Debug) {}
| ^^^^^^^^^^^^^^^ required by this bound in `qux`
help: introduce a type parameter with a trait bound instead of using `impl Trait`
|
LL | fn foo<I: Iterator>(constraints: I) where <I as Iterator>::Item: Debug {
| +++++++++++++ ~ ++++++++++++++++++++++++++++++++++
error[E0277]: `<impl Iterator as Iterator>::Item` doesn't implement `Debug`
--> $DIR/impl-trait-with-missing-bounds.rs:14:13
|
@ -83,6 +66,23 @@ help: introduce a type parameter with a trait bound instead of using `impl Trait
LL | fn bak<I: Iterator + std::fmt::Debug>(constraints: I) where <I as Iterator>::Item: Debug {
| +++++++++++++++++++++++++++++++ ~ ++++++++++++++++++++++++++++++++++
error[E0277]: `<impl Iterator as Iterator>::Item` doesn't implement `Debug`
--> $DIR/impl-trait-with-missing-bounds.rs:6:13
|
LL | qux(constraint);
| ^^^^^^^^^^ `<impl Iterator as Iterator>::Item` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
= help: the trait `Debug` is not implemented for `<impl Iterator as Iterator>::Item`
note: required by a bound in `qux`
--> $DIR/impl-trait-with-missing-bounds.rs:50:16
|
LL | fn qux(_: impl std::fmt::Debug) {}
| ^^^^^^^^^^^^^^^ required by this bound in `qux`
help: introduce a type parameter with a trait bound instead of using `impl Trait`
|
LL | fn foo<I: Iterator>(constraints: I) where <I as Iterator>::Item: Debug {
| +++++++++++++ ~ ++++++++++++++++++++++++++++++++++
error[E0277]: `<impl Iterator as Iterator>::Item` doesn't implement `Debug`
--> $DIR/impl-trait-with-missing-bounds.rs:45:13
|

View File

@ -1,11 +1,3 @@
error[E0308]: mismatched types
--> $DIR/suggest-ref-macro.rs:8:1
|
LL | #[hello]
| ^^^^^^^^ expected `&mut i32`, found integer
|
= note: this error originates in the attribute macro `hello` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> $DIR/suggest-ref-macro.rs:15:11
|
@ -29,6 +21,14 @@ LL | bla!(456);
| expected `&mut i32`, found integer
| help: consider mutably borrowing here: `&mut 456`
error[E0308]: mismatched types
--> $DIR/suggest-ref-macro.rs:8:1
|
LL | #[hello]
| ^^^^^^^^ expected `&mut i32`, found integer
|
= note: this error originates in the attribute macro `hello` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.

View File

@ -1,16 +1,3 @@
error[E0277]: the trait bound `U1: Copy` is not satisfied
--> $DIR/union-derive-clone.rs:6:10
|
LL | #[derive(Clone)]
| ^^^^^ the trait `Copy` is not implemented for `U1`
|
note: required by a bound in `AssertParamIsCopy`
--> $SRC_DIR/core/src/clone.rs:LL:COL
|
LL | pub struct AssertParamIsCopy<T: Copy + ?Sized> {
| ^^^^ required by this bound in `AssertParamIsCopy`
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0599]: the method `clone` exists for union `U5<CloneNoCopy>`, but its trait bounds were not satisfied
--> $DIR/union-derive-clone.rs:38:15
|
@ -30,6 +17,19 @@ LL | let w = u.clone();
`CloneNoCopy: Copy`
which is required by `U5<CloneNoCopy>: Clone`
error[E0277]: the trait bound `U1: Copy` is not satisfied
--> $DIR/union-derive-clone.rs:6:10
|
LL | #[derive(Clone)]
| ^^^^^ the trait `Copy` is not implemented for `U1`
|
note: required by a bound in `AssertParamIsCopy`
--> $SRC_DIR/core/src/clone.rs:LL:COL
|
LL | pub struct AssertParamIsCopy<T: Copy + ?Sized> {
| ^^^^ required by this bound in `AssertParamIsCopy`
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0277, E0599.

View File

@ -1,16 +1,3 @@
error[E0277]: the trait bound `U1: Copy` is not satisfied
--> $DIR/union-derive-clone.rs:6:10
|
LL | #[derive(Clone)]
| ^^^^^ the trait `Copy` is not implemented for `U1`
|
note: required by a bound in `AssertParamIsCopy`
--> $SRC_DIR/core/src/clone.rs:LL:COL
|
LL | pub struct AssertParamIsCopy<T: Copy + ?Sized> {
| ^^^^ required by this bound in `AssertParamIsCopy`
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0599]: the method `clone` exists for union `U5<CloneNoCopy>`, but its trait bounds were not satisfied
--> $DIR/union-derive-clone.rs:38:15
|
@ -30,6 +17,19 @@ LL | let w = u.clone();
`CloneNoCopy: Copy`
which is required by `U5<CloneNoCopy>: Clone`
error[E0277]: the trait bound `U1: Copy` is not satisfied
--> $DIR/union-derive-clone.rs:6:10
|
LL | #[derive(Clone)]
| ^^^^^ the trait `Copy` is not implemented for `U1`
|
note: required by a bound in `AssertParamIsCopy`
--> $SRC_DIR/core/src/clone.rs:LL:COL
|
LL | pub struct AssertParamIsCopy<T: Copy + ?Sized> {
| ^^^^ required by this bound in `AssertParamIsCopy`
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0277, E0599.