Use `tidy` to sort crate attributes for all compiler crates.
We already do this for a number of crates, e.g. `rustc_middle`,
`rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`.
For the ones we don't, in many cases the attributes are a mess.
- There is no consistency about order of attribute kinds (e.g.
`allow`/`deny`/`feature`).
- Within attribute kind groups (e.g. the `feature` attributes),
sometimes the order is alphabetical, and sometimes there is no
particular order.
- Sometimes the attributes of a particular kind aren't even grouped
all together, e.g. there might be a `feature`, then an `allow`, then
another `feature`.
This commit extends the existing sorting to all compiler crates,
increasing consistency. If any new attribute line is added there is now
only one place it can go -- no need for arbitrary decisions.
Exceptions:
- `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`,
because they have no crate attributes.
- `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's
ignored in `rustfmt.toml`).
2024-06-12 13:49:36 +10:00
|
|
|
// tidy-alphabetical-start
|
2021-01-02 14:42:15 +01:00
|
|
|
#![feature(array_windows)]
|
2024-09-05 00:34:04 +03:00
|
|
|
#![feature(if_let_guard)]
|
|
|
|
#![feature(let_chains)]
|
2024-08-29 15:08:07 +10:00
|
|
|
#![warn(unreachable_pub)]
|
Use `tidy` to sort crate attributes for all compiler crates.
We already do this for a number of crates, e.g. `rustc_middle`,
`rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`.
For the ones we don't, in many cases the attributes are a mess.
- There is no consistency about order of attribute kinds (e.g.
`allow`/`deny`/`feature`).
- Within attribute kind groups (e.g. the `feature` attributes),
sometimes the order is alphabetical, and sometimes there is no
particular order.
- Sometimes the attributes of a particular kind aren't even grouped
all together, e.g. there might be a `feature`, then an `allow`, then
another `feature`.
This commit extends the existing sorting to all compiler crates,
increasing consistency. If any new attribute line is added there is now
only one place it can go -- no need for arbitrary decisions.
Exceptions:
- `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`,
because they have no crate attributes.
- `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's
ignored in `rustfmt.toml`).
2024-06-12 13:49:36 +10:00
|
|
|
// tidy-alphabetical-end
|
2021-01-02 14:42:15 +01:00
|
|
|
|
|
|
|
use rustc_hir::lang_items::LangItem;
|
2024-07-15 19:54:47 +00:00
|
|
|
use rustc_middle::query::TyCtxtAt;
|
2020-03-29 16:41:09 +02:00
|
|
|
use rustc_middle::ty::adjustment::CustomCoerceUnsized;
|
2022-11-17 14:39:19 +00:00
|
|
|
use rustc_middle::ty::{self, Ty};
|
2024-07-15 19:54:47 +00:00
|
|
|
use rustc_middle::util::Providers;
|
2020-03-29 16:41:09 +02:00
|
|
|
use rustc_middle::{bug, traits};
|
2024-01-23 15:23:22 +00:00
|
|
|
use rustc_span::ErrorGuaranteed;
|
2017-10-25 16:14:51 +02:00
|
|
|
|
2021-01-02 14:42:15 +01:00
|
|
|
mod collector;
|
2022-08-18 15:51:47 -06:00
|
|
|
mod errors;
|
2021-01-02 14:42:15 +01:00
|
|
|
mod partitioning;
|
|
|
|
mod polymorphize;
|
|
|
|
mod util;
|
2017-10-25 16:14:51 +02:00
|
|
|
|
2023-11-22 09:53:07 +11:00
|
|
|
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
2022-10-13 10:13:02 +01:00
|
|
|
|
2021-01-07 00:41:55 -05:00
|
|
|
fn custom_coerce_unsize_info<'tcx>(
|
2022-11-17 14:39:19 +00:00
|
|
|
tcx: TyCtxtAt<'tcx>,
|
2019-06-12 00:11:55 +03:00
|
|
|
source_ty: Ty<'tcx>,
|
|
|
|
target_ty: Ty<'tcx>,
|
2024-01-23 15:23:22 +00:00
|
|
|
) -> Result<CustomCoerceUnsized, ErrorGuaranteed> {
|
2024-05-10 14:59:56 -04:00
|
|
|
let trait_ref = ty::TraitRef::new(
|
2023-04-26 10:55:11 +00:00
|
|
|
tcx.tcx,
|
2024-05-10 14:59:56 -04:00
|
|
|
tcx.require_lang_item(LangItem::CoerceUnsized, Some(tcx.span)),
|
2023-04-25 16:07:48 +00:00
|
|
|
[source_ty, target_ty],
|
2023-07-04 01:18:31 +00:00
|
|
|
);
|
2017-10-25 16:14:51 +02:00
|
|
|
|
2022-09-09 13:36:27 +02:00
|
|
|
match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), trait_ref)) {
|
2020-09-24 19:22:36 +02:00
|
|
|
Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {
|
2020-06-02 15:54:24 +00:00
|
|
|
impl_def_id,
|
|
|
|
..
|
2024-01-23 15:23:22 +00:00
|
|
|
})) => Ok(tcx.coerce_unsized_info(impl_def_id)?.custom_kind.unwrap()),
|
2020-05-11 15:25:33 +00:00
|
|
|
impl_source => {
|
|
|
|
bug!("invalid `CoerceUnsized` impl_source: {:?}", impl_source);
|
2017-10-25 16:14:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-02 14:42:15 +01:00
|
|
|
|
|
|
|
pub fn provide(providers: &mut Providers) {
|
|
|
|
partitioning::provide(providers);
|
|
|
|
polymorphize::provide(providers);
|
|
|
|
}
|