2014-11-26 11:11:29 +00:00
|
|
|
/*!
|
2012-11-29 00:20:41 +00:00
|
|
|
|
2019-02-08 13:53:55 +00:00
|
|
|
# typeck
|
2012-11-29 00:20:41 +00:00
|
|
|
|
|
|
|
The type checker is responsible for:
|
|
|
|
|
2018-11-27 02:59:49 +00:00
|
|
|
1. Determining the type of each expression.
|
|
|
|
2. Resolving methods and traits.
|
|
|
|
3. Guaranteeing that most type rules are met. ("Most?", you say, "why most?"
|
2021-01-30 07:03:35 +00:00
|
|
|
Well, dear reader, read on.)
|
2012-11-29 00:20:41 +00:00
|
|
|
|
2021-01-30 07:03:35 +00:00
|
|
|
The main entry point is [`check_crate()`]. Type checking operates in
|
2013-10-29 10:08:34 +00:00
|
|
|
several major phases:
|
2012-11-29 00:20:41 +00:00
|
|
|
|
2013-10-29 10:08:34 +00:00
|
|
|
1. The collect phase first passes over all items and determines their
|
|
|
|
type, without examining their "innards".
|
|
|
|
|
2018-11-27 02:59:49 +00:00
|
|
|
2. Variance inference then runs to compute the variance of each parameter.
|
2013-10-29 10:08:34 +00:00
|
|
|
|
2018-11-27 02:59:49 +00:00
|
|
|
3. Coherence checks for overlapping or orphaned impls.
|
2013-10-29 10:08:34 +00:00
|
|
|
|
|
|
|
4. Finally, the check phase then checks function bodies and so forth.
|
|
|
|
Within the check phase, we check each function body one at a time
|
|
|
|
(bodies of function expressions are checked as part of the
|
2022-11-16 20:34:16 +00:00
|
|
|
containing function). Inference is used to supply types wherever
|
2013-10-29 10:08:34 +00:00
|
|
|
they are unknown. The actual checking of a function itself has
|
|
|
|
several phases (check, regionck, writeback), as discussed in the
|
2021-01-30 07:03:35 +00:00
|
|
|
documentation for the [`check`] module.
|
2012-11-29 00:20:41 +00:00
|
|
|
|
|
|
|
The type checker is defined into various submodules which are documented
|
|
|
|
independently:
|
|
|
|
|
2024-02-11 10:09:25 +00:00
|
|
|
- hir_ty_lowering: lowers type-system entities from the [HIR][hir] to the
|
2024-02-11 08:22:52 +00:00
|
|
|
[`rustc_middle::ty`] representation.
|
2012-11-29 00:20:41 +00:00
|
|
|
|
|
|
|
- collect: computes the types of each top-level item and enters them into
|
2018-11-27 02:59:49 +00:00
|
|
|
the `tcx.types` table for later use.
|
2012-11-29 00:20:41 +00:00
|
|
|
|
2018-11-27 02:59:49 +00:00
|
|
|
- coherence: enforces coherence rules, builds some tables.
|
2013-10-29 10:08:34 +00:00
|
|
|
|
|
|
|
- variance: variance inference
|
|
|
|
|
2017-09-28 00:18:41 +00:00
|
|
|
- outlives: outlives inference
|
|
|
|
|
2012-11-29 00:20:41 +00:00
|
|
|
- check: walks over function bodies and type checks them, inferring types for
|
|
|
|
local variables, type parameters, etc as necessary.
|
|
|
|
|
|
|
|
- infer: finds the types to use for each type variable such that
|
2022-11-16 20:34:16 +00:00
|
|
|
all subtyping and assignment constraints are met. In essence, the check
|
2012-11-29 00:20:41 +00:00
|
|
|
module specifies the constraints, and the infer module solves them.
|
|
|
|
|
2018-11-27 02:59:49 +00:00
|
|
|
## Note
|
2014-11-26 11:11:29 +00:00
|
|
|
|
|
|
|
This API is completely unstable and subject to change.
|
|
|
|
|
2012-11-29 00:20:41 +00:00
|
|
|
*/
|
2015-12-11 21:07:11 +00:00
|
|
|
|
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 03:49:36 +00:00
|
|
|
// tidy-alphabetical-start
|
|
|
|
#![allow(internal_features)]
|
2024-02-05 22:51:39 +00:00
|
|
|
#![allow(rustc::diagnostic_outside_of_impl)]
|
|
|
|
#![allow(rustc::untranslatable_diagnostic)]
|
2020-09-23 19:51:56 +00:00
|
|
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
2023-11-13 12:39:17 +00:00
|
|
|
#![doc(rust_logo)]
|
2024-08-11 16:10:36 +00:00
|
|
|
#![feature(assert_matches)]
|
2024-10-22 17:59:26 +00:00
|
|
|
#![feature(coroutines)]
|
2025-01-23 19:48:54 +00:00
|
|
|
#![feature(debug_closure_helpers)]
|
2021-08-16 15:29:49 +00:00
|
|
|
#![feature(if_let_guard)]
|
2024-10-22 17:59:26 +00:00
|
|
|
#![feature(iter_from_coroutine)]
|
2022-04-13 14:49:03 +00:00
|
|
|
#![feature(iter_intersperse)]
|
2022-08-20 18:40:08 +00:00
|
|
|
#![feature(let_chains)]
|
2019-12-11 14:55:29 +00:00
|
|
|
#![feature(never_type)]
|
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 03:49:36 +00:00
|
|
|
#![feature(rustdoc_internals)]
|
2022-02-26 10:43:47 +00:00
|
|
|
#![feature(slice_partition_dedup)]
|
|
|
|
#![feature(try_blocks)]
|
2024-07-06 22:24:51 +00:00
|
|
|
#![feature(unwrap_infallible)]
|
2024-08-27 03:14:50 +00: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 03:49:36 +00:00
|
|
|
// tidy-alphabetical-end
|
2017-05-08 21:36:44 +00:00
|
|
|
|
2020-08-03 00:19:33 +00:00
|
|
|
// These are used by Clippy.
|
|
|
|
pub mod check;
|
2019-11-09 10:38:06 +00:00
|
|
|
|
2022-12-27 00:39:36 +00:00
|
|
|
pub mod autoderef;
|
2020-08-19 17:07:03 +00:00
|
|
|
mod bounds;
|
2017-05-03 15:28:22 +00:00
|
|
|
mod check_unused;
|
2018-01-23 02:07:35 +00:00
|
|
|
mod coherence;
|
2025-01-28 23:52:24 +00:00
|
|
|
mod collect;
|
2019-03-29 00:28:07 +00:00
|
|
|
mod constrained_generic_params;
|
2025-01-28 23:52:24 +00:00
|
|
|
mod delegation;
|
2020-08-27 10:00:21 +00:00
|
|
|
mod errors;
|
2025-01-28 23:52:24 +00:00
|
|
|
pub mod hir_ty_lowering;
|
Add initial implementation of HIR-based WF checking for diagnostics
During well-formed checking, we walk through all types 'nested' in
generic arguments. For example, WF-checking `Option<MyStruct<u8>>`
will cause us to check `MyStruct<u8>` and `u8`. However, this is done
on a `rustc_middle::ty::Ty`, which has no span information. As a result,
any errors that occur will have a very general span (e.g. the
definintion of an associated item).
This becomes a problem when macros are involved. In general, an
associated type like `type MyType = Option<MyStruct<u8>>;` may
have completely different spans for each nested type in the HIR. Using
the span of the entire associated item might end up pointing to a macro
invocation, even though a user-provided span is available in one of the
nested types.
This PR adds a framework for HIR-based well formed checking. This check
is only run during error reporting, and is used to obtain a more precise
span for an existing error. This is accomplished by individually
checking each 'nested' type in the HIR for the type, allowing us to
find the most-specific type (and span) that produces a given error.
The majority of the changes are to the error-reporting code. However,
some of the general trait code is modified to pass through more
information.
Since this has no soundness implications, I've implemented a minimal
version to begin with, which can be extended over time. In particular,
this only works for HIR items with a corresponding `DefId` (e.g. it will
not work for WF-checking performed within function bodies).
2021-04-04 20:55:39 +00:00
|
|
|
pub mod hir_wf_check;
|
2016-11-11 14:52:46 +00:00
|
|
|
mod impl_wf_check;
|
2017-09-28 00:18:41 +00:00
|
|
|
mod outlives;
|
2017-05-03 15:28:22 +00:00
|
|
|
mod variance;
|
2014-11-26 10:48:57 +00:00
|
|
|
|
2024-11-03 02:32:56 +00:00
|
|
|
use rustc_abi::ExternAbi;
|
2020-01-05 01:37:57 +00:00
|
|
|
use rustc_hir as hir;
|
2024-03-15 01:19:29 +00:00
|
|
|
use rustc_hir::def::DefKind;
|
2020-03-29 14:41:09 +00:00
|
|
|
use rustc_middle::middle;
|
2024-02-22 09:35:33 +00:00
|
|
|
use rustc_middle::mir::interpret::GlobalId;
|
2023-05-15 04:24:45 +00:00
|
|
|
use rustc_middle::query::Providers;
|
2024-11-19 05:01:59 +00:00
|
|
|
use rustc_middle::ty::{self, Const, Ty, TyCtxt};
|
2025-02-12 01:22:27 +00:00
|
|
|
use rustc_session::parse::feature_err;
|
|
|
|
use rustc_span::symbol::sym;
|
2025-01-30 05:59:07 +00:00
|
|
|
use rustc_span::{ErrorGuaranteed, Span};
|
2023-09-17 18:13:05 +00:00
|
|
|
use rustc_trait_selection::traits;
|
2018-11-27 02:59:49 +00:00
|
|
|
|
2025-01-28 23:52:24 +00:00
|
|
|
pub use crate::collect::suggest_impl_trait;
|
|
|
|
use crate::hir_ty_lowering::{FeedConstTy, HirTyLowerer};
|
2024-11-19 05:01:59 +00:00
|
|
|
|
2023-11-21 22:53:07 +00:00
|
|
|
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
2022-10-13 09:13:02 +00:00
|
|
|
|
2024-11-03 02:32:56 +00:00
|
|
|
fn require_c_abi_if_c_variadic(
|
|
|
|
tcx: TyCtxt<'_>,
|
|
|
|
decl: &hir::FnDecl<'_>,
|
|
|
|
abi: ExternAbi,
|
|
|
|
span: Span,
|
|
|
|
) {
|
2025-02-12 01:22:27 +00:00
|
|
|
const CONVENTIONS_UNSTABLE: &str =
|
|
|
|
"`C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`";
|
|
|
|
const CONVENTIONS_STABLE: &str = "`C` or `cdecl`";
|
|
|
|
const UNSTABLE_EXPLAIN: &str =
|
|
|
|
"using calling conventions other than `C` or `cdecl` for varargs functions is unstable";
|
|
|
|
|
2025-02-12 18:35:32 +00:00
|
|
|
// ABIs which can stably use varargs
|
2025-02-12 01:22:27 +00:00
|
|
|
if !decl.c_variadic || matches!(abi, ExternAbi::C { .. } | ExternAbi::Cdecl { .. }) {
|
|
|
|
return;
|
2022-08-08 13:31:32 +00:00
|
|
|
}
|
2025-02-12 01:22:27 +00:00
|
|
|
|
2025-02-12 18:35:32 +00:00
|
|
|
// ABIs with feature-gated stability
|
2025-02-12 01:22:27 +00:00
|
|
|
let extended_abi_support = tcx.features().extended_varargs_abi_support();
|
2025-02-12 18:35:32 +00:00
|
|
|
let extern_system_varargs = tcx.features().extern_system_varargs();
|
2025-02-12 01:22:27 +00:00
|
|
|
|
2025-02-12 18:35:32 +00:00
|
|
|
// If the feature gate has been enabled, we can stop here
|
|
|
|
if extern_system_varargs && let ExternAbi::System { .. } = abi {
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
if extended_abi_support && abi.supports_varargs() {
|
|
|
|
return;
|
2025-02-12 01:22:27 +00:00
|
|
|
};
|
|
|
|
|
2025-02-12 18:35:32 +00:00
|
|
|
// Looks like we need to pick an error to emit.
|
|
|
|
// Is there any feature which we could have enabled to make this work?
|
|
|
|
match abi {
|
|
|
|
ExternAbi::System { .. } => {
|
|
|
|
feature_err(&tcx.sess, sym::extern_system_varargs, span, UNSTABLE_EXPLAIN)
|
|
|
|
}
|
|
|
|
abi if abi.supports_varargs() => {
|
|
|
|
feature_err(&tcx.sess, sym::extended_varargs_abi_support, span, UNSTABLE_EXPLAIN)
|
|
|
|
}
|
|
|
|
_ => tcx.dcx().create_err(errors::VariadicFunctionCompatibleConvention {
|
|
|
|
span,
|
|
|
|
conventions: if tcx.sess.opts.unstable_features.is_nightly_build() {
|
|
|
|
CONVENTIONS_UNSTABLE
|
|
|
|
} else {
|
|
|
|
CONVENTIONS_STABLE
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
.emit();
|
2015-07-21 15:41:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-05 20:00:14 +00:00
|
|
|
pub fn provide(providers: &mut Providers) {
|
2017-02-13 23:11:24 +00:00
|
|
|
collect::provide(providers);
|
2017-02-19 12:46:29 +00:00
|
|
|
coherence::provide(providers);
|
2017-02-14 09:32:00 +00:00
|
|
|
check::provide(providers);
|
2022-01-30 16:14:54 +00:00
|
|
|
check_unused::provide(providers);
|
2017-04-24 15:15:12 +00:00
|
|
|
variance::provide(providers);
|
2017-09-28 01:01:48 +00:00
|
|
|
outlives::provide(providers);
|
Add initial implementation of HIR-based WF checking for diagnostics
During well-formed checking, we walk through all types 'nested' in
generic arguments. For example, WF-checking `Option<MyStruct<u8>>`
will cause us to check `MyStruct<u8>` and `u8`. However, this is done
on a `rustc_middle::ty::Ty`, which has no span information. As a result,
any errors that occur will have a very general span (e.g. the
definintion of an associated item).
This becomes a problem when macros are involved. In general, an
associated type like `type MyType = Option<MyStruct<u8>>;` may
have completely different spans for each nested type in the HIR. Using
the span of the entire associated item might end up pointing to a macro
invocation, even though a user-provided span is available in one of the
nested types.
This PR adds a framework for HIR-based well formed checking. This check
is only run during error reporting, and is used to obtain a more precise
span for an existing error. This is accomplished by individually
checking each 'nested' type in the HIR for the type, allowing us to
find the most-specific type (and span) that produces a given error.
The majority of the changes are to the error-reporting code. However,
some of the general trait code is modified to pass through more
information.
Since this has no soundness implications, I've implemented a minimal
version to begin with, which can be extended over time. In particular,
this only works for HIR items with a corresponding `DefId` (e.g. it will
not work for WF-checking performed within function bodies).
2021-04-04 20:55:39 +00:00
|
|
|
hir_wf_check::provide(providers);
|
2024-05-30 19:00:44 +00:00
|
|
|
*providers = Providers {
|
|
|
|
inherit_sig_for_delegation_item: delegation::inherit_sig_for_delegation_item,
|
2025-01-03 05:01:14 +00:00
|
|
|
enforce_impl_non_lifetime_params_are_constrained:
|
|
|
|
impl_wf_check::enforce_impl_non_lifetime_params_are_constrained,
|
2024-05-30 19:00:44 +00:00
|
|
|
..*providers
|
|
|
|
};
|
2017-02-13 23:11:24 +00:00
|
|
|
}
|
|
|
|
|
2024-04-08 14:44:10 +00:00
|
|
|
pub fn check_crate(tcx: TyCtxt<'_>) {
|
2020-01-01 01:24:05 +00:00
|
|
|
let _prof_timer = tcx.sess.timer("type_check_crate");
|
2018-05-19 17:50:58 +00:00
|
|
|
|
2024-01-11 22:13:39 +00:00
|
|
|
tcx.sess.time("coherence_checking", || {
|
2025-01-30 05:59:07 +00:00
|
|
|
// When discarding query call results, use an explicit type to indicate
|
|
|
|
// what we are intending to discard, to help future type-based refactoring.
|
|
|
|
type R = Result<(), ErrorGuaranteed>;
|
|
|
|
|
2024-02-15 17:12:05 +00:00
|
|
|
tcx.hir().par_for_each_module(|module| {
|
2025-01-30 05:59:07 +00:00
|
|
|
let _: R = tcx.ensure_ok().check_mod_type_wf(module);
|
2024-02-15 17:12:05 +00:00
|
|
|
});
|
2023-10-24 16:51:26 +00:00
|
|
|
|
2024-01-23 15:23:22 +00:00
|
|
|
for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
|
2025-01-30 05:59:07 +00:00
|
|
|
let _: R = tcx.ensure_ok().coherent_trait(trait_def_id);
|
2024-01-23 15:23:22 +00:00
|
|
|
}
|
2024-01-12 14:29:54 +00:00
|
|
|
// these queries are executed for side-effects (error reporting):
|
2025-01-30 05:59:07 +00:00
|
|
|
let _: R = tcx.ensure_ok().crate_inherent_impls_validity_check(());
|
|
|
|
let _: R = tcx.ensure_ok().crate_inherent_impls_overlap_check(());
|
2024-02-15 17:12:05 +00:00
|
|
|
});
|
2013-03-21 10:28:58 +00:00
|
|
|
|
2024-10-09 07:01:57 +00:00
|
|
|
if tcx.features().rustc_attrs() {
|
2025-01-10 20:09:10 +00:00
|
|
|
tcx.sess.time("dumping_rustc_attr_data", || {
|
|
|
|
outlives::dump::inferred_outlives(tcx);
|
|
|
|
variance::dump::variances(tcx);
|
|
|
|
collect::dump::opaque_hidden_types(tcx);
|
|
|
|
collect::dump::predicates_and_item_bounds(tcx);
|
|
|
|
collect::dump::def_parents(tcx);
|
|
|
|
collect::dump::vtables(tcx);
|
|
|
|
});
|
2024-03-11 21:28:16 +00:00
|
|
|
}
|
|
|
|
|
2024-02-14 12:28:07 +00:00
|
|
|
// Make sure we evaluate all static and (non-associated) const items, even if unused.
|
|
|
|
// If any of these fail to evaluate, we do not want this crate to pass compilation.
|
|
|
|
tcx.hir().par_body_owners(|item_def_id| {
|
|
|
|
let def_kind = tcx.def_kind(item_def_id);
|
|
|
|
match def_kind {
|
2025-01-30 05:20:09 +00:00
|
|
|
DefKind::Static { .. } => tcx.ensure_ok().eval_static_initializer(item_def_id),
|
2024-05-11 09:46:25 +00:00
|
|
|
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
|
2024-02-22 09:35:33 +00:00
|
|
|
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
|
|
|
|
let cid = GlobalId { instance, promoted: None };
|
2024-11-19 19:10:42 +00:00
|
|
|
let typing_env = ty::TypingEnv::fully_monomorphized();
|
2025-01-30 05:20:09 +00:00
|
|
|
tcx.ensure_ok().eval_to_const_value_raw(typing_env.as_query_input(cid));
|
2024-02-22 09:35:33 +00:00
|
|
|
}
|
2024-02-14 12:28:07 +00:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-03-11 21:28:16 +00:00
|
|
|
// FIXME: Remove this when we implement creating `DefId`s
|
|
|
|
// for anon constants during their parents' typeck.
|
|
|
|
// Typeck all body owners in parallel will produce queries
|
|
|
|
// cycle errors because it may typeck on anon constants directly.
|
|
|
|
tcx.hir().par_body_owners(|item_def_id| {
|
|
|
|
let def_kind = tcx.def_kind(item_def_id);
|
|
|
|
if !matches!(def_kind, DefKind::AnonConst) {
|
2025-01-30 05:20:09 +00:00
|
|
|
tcx.ensure_ok().typeck(item_def_id);
|
2024-03-11 21:28:16 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-01-30 05:20:09 +00:00
|
|
|
tcx.ensure_ok().check_unused_traits(());
|
2012-11-29 00:20:41 +00:00
|
|
|
}
|
2015-04-28 02:48:22 +00:00
|
|
|
|
2024-02-11 08:22:52 +00:00
|
|
|
/// Lower a [`hir::Ty`] to a [`Ty`].
|
|
|
|
///
|
|
|
|
/// <div class="warning">
|
|
|
|
///
|
|
|
|
/// This function is **quasi-deprecated**. It can cause ICEs if called inside of a body
|
|
|
|
/// (of a function or constant) and especially if it contains inferred types (`_`).
|
|
|
|
///
|
|
|
|
/// It's used in rustdoc and Clippy.
|
|
|
|
///
|
|
|
|
/// </div>
|
2024-03-15 02:21:55 +00:00
|
|
|
pub fn lower_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
|
2019-02-28 22:43:53 +00:00
|
|
|
// In case there are any projections, etc., find the "environment"
|
|
|
|
// def-ID that will be used to determine the traits/predicates in
|
2022-11-16 20:34:16 +00:00
|
|
|
// scope. This is derived from the enclosing item-like thing.
|
2021-10-21 17:41:47 +00:00
|
|
|
let env_def_id = tcx.hir().get_parent_item(hir_ty.hir_id);
|
2024-03-15 02:21:55 +00:00
|
|
|
collect::ItemCtxt::new(tcx, env_def_id.def_id).lower_ty(hir_ty)
|
2017-05-03 15:28:22 +00:00
|
|
|
}
|
2024-11-19 05:01:59 +00:00
|
|
|
|
|
|
|
/// This is for rustdoc.
|
|
|
|
// FIXME(const_generics): having special methods for rustdoc in `rustc_hir_analysis` is cursed
|
|
|
|
pub fn lower_const_arg_for_rustdoc<'tcx>(
|
|
|
|
tcx: TyCtxt<'tcx>,
|
|
|
|
hir_ct: &hir::ConstArg<'tcx>,
|
|
|
|
feed: FeedConstTy,
|
|
|
|
) -> Const<'tcx> {
|
|
|
|
let env_def_id = tcx.hir().get_parent_item(hir_ct.hir_id);
|
|
|
|
collect::ItemCtxt::new(tcx, env_def_id.def_id).lowerer().lower_const_arg(hir_ct, feed)
|
|
|
|
}
|