1#![feature(box_patterns)]
35#![feature(if_let_guard)]
36use std::mem;
39use std::sync::Arc;
40
41use rustc_ast::node_id::NodeMap;
42use rustc_ast::{self as ast, *};
43use rustc_attr_parsing::{AttributeParser, Late, OmitDoc};
44use rustc_data_structures::fingerprint::Fingerprint;
45use rustc_data_structures::sorted_map::SortedMap;
46use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
47use rustc_data_structures::sync::spawn;
48use rustc_data_structures::tagged_ptr::TaggedRef;
49use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
50use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
51use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId};
52use rustc_hir::definitions::{DefPathData, DisambiguatorState};
53use rustc_hir::lints::DelayedLint;
54use rustc_hir::{
55 self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LifetimeSource,
56 LifetimeSyntax, ParamName, Target, TraitCandidate,
57};
58use rustc_index::{Idx, IndexSlice, IndexVec};
59use rustc_macros::extension;
60use rustc_middle::span_bug;
61use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
62use rustc_session::parse::add_feature_diagnostics;
63use rustc_span::symbol::{Ident, Symbol, kw, sym};
64use rustc_span::{DUMMY_SP, DesugaringKind, Span};
65use smallvec::SmallVec;
66use thin_vec::ThinVec;
67use tracing::{debug, instrument, trace};
68
69use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait};
70
71macro_rules! arena_vec {
72 ($this:expr; $($x:expr),*) => (
73 $this.arena.alloc_from_iter([$($x),*])
74 );
75}
76
77mod asm;
78mod block;
79mod contract;
80mod delegation;
81mod errors;
82mod expr;
83mod format;
84mod index;
85mod item;
86mod pat;
87mod path;
88pub mod stability;
89
90#[allow(non_upper_case_globals)]
#[doc(hidden)]
#[doc =
r" Auto-generated constants for type-checked references to Fluent messages."]
pub(crate) mod fluent_generated {
#[doc =
"Constant referring to Fluent message `ast_lowering_abi_specified_multiple_times` from `ast_lowering`"]
pub const ast_lowering_abi_specified_multiple_times:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_abi_specified_multiple_times"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_abi_specified_multiple_times.label` from `ast_lowering`"]
pub const ast_lowering_label: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("label"));
#[doc =
"Constant referring to Fluent message `ast_lowering_abi_specified_multiple_times.note` from `ast_lowering`"]
pub const ast_lowering_note: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("note"));
#[doc =
"Constant referring to Fluent message `ast_lowering_arbitrary_expression_in_pattern` from `ast_lowering`"]
pub const ast_lowering_arbitrary_expression_in_pattern:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_arbitrary_expression_in_pattern"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_arbitrary_expression_in_pattern.pattern_from_macro_note` from `ast_lowering`"]
pub const ast_lowering_pattern_from_macro_note:
rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("pattern_from_macro_note"));
#[doc =
"Constant referring to Fluent message `ast_lowering_argument` from `ast_lowering`"]
pub const ast_lowering_argument: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_argument"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_assoc_ty_binding_in_dyn` from `ast_lowering`"]
pub const ast_lowering_assoc_ty_binding_in_dyn: rustc_errors::DiagMessage
=
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_assoc_ty_binding_in_dyn"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_assoc_ty_binding_in_dyn.suggestion` from `ast_lowering`"]
pub const ast_lowering_suggestion: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("suggestion"));
#[doc =
"Constant referring to Fluent message `ast_lowering_assoc_ty_parentheses` from `ast_lowering`"]
pub const ast_lowering_assoc_ty_parentheses: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_assoc_ty_parentheses"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_async_bound_not_on_trait` from `ast_lowering`"]
pub const ast_lowering_async_bound_not_on_trait: rustc_errors::DiagMessage
=
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_async_bound_not_on_trait"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_async_bound_only_for_fn_traits` from `ast_lowering`"]
pub const ast_lowering_async_bound_only_for_fn_traits:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_async_bound_only_for_fn_traits"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_async_coroutines_not_supported` from `ast_lowering`"]
pub const ast_lowering_async_coroutines_not_supported:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_async_coroutines_not_supported"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_att_syntax_only_x86` from `ast_lowering`"]
pub const ast_lowering_att_syntax_only_x86: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_att_syntax_only_x86"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_await_only_in_async_fn_and_blocks` from `ast_lowering`"]
pub const ast_lowering_await_only_in_async_fn_and_blocks:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_await_only_in_async_fn_and_blocks"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_bad_return_type_notation_inputs` from `ast_lowering`"]
pub const ast_lowering_bad_return_type_notation_inputs:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_bad_return_type_notation_inputs"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_bad_return_type_notation_needs_dots` from `ast_lowering`"]
pub const ast_lowering_bad_return_type_notation_needs_dots:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_bad_return_type_notation_needs_dots"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_bad_return_type_notation_output` from `ast_lowering`"]
pub const ast_lowering_bad_return_type_notation_output:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_bad_return_type_notation_output"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_bad_return_type_notation_output_suggestion` from `ast_lowering`"]
pub const ast_lowering_bad_return_type_notation_output_suggestion:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_bad_return_type_notation_output_suggestion"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_bad_return_type_notation_position` from `ast_lowering`"]
pub const ast_lowering_bad_return_type_notation_position:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_bad_return_type_notation_position"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_clobber_abi_not_supported` from `ast_lowering`"]
pub const ast_lowering_clobber_abi_not_supported:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_clobber_abi_not_supported"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_closure_cannot_be_static` from `ast_lowering`"]
pub const ast_lowering_closure_cannot_be_static: rustc_errors::DiagMessage
=
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_closure_cannot_be_static"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_coroutine_too_many_parameters` from `ast_lowering`"]
pub const ast_lowering_coroutine_too_many_parameters:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_coroutine_too_many_parameters"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_default_field_in_tuple` from `ast_lowering`"]
pub const ast_lowering_default_field_in_tuple: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_default_field_in_tuple"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_delegation_cycle_in_signature_resolution` from `ast_lowering`"]
pub const ast_lowering_delegation_cycle_in_signature_resolution:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_delegation_cycle_in_signature_resolution"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_delegation_unresolved_callee` from `ast_lowering`"]
pub const ast_lowering_delegation_unresolved_callee:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_delegation_unresolved_callee"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_does_not_support_modifiers` from `ast_lowering`"]
pub const ast_lowering_does_not_support_modifiers:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_does_not_support_modifiers"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_extra_double_dot` from `ast_lowering`"]
pub const ast_lowering_extra_double_dot: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_extra_double_dot"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_functional_record_update_destructuring_assignment` from `ast_lowering`"]
pub const ast_lowering_functional_record_update_destructuring_assignment:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_functional_record_update_destructuring_assignment"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_generic_param_default_in_binder` from `ast_lowering`"]
pub const ast_lowering_generic_param_default_in_binder:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_generic_param_default_in_binder"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_generic_type_with_parentheses` from `ast_lowering`"]
pub const ast_lowering_generic_type_with_parentheses:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_generic_type_with_parentheses"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_inclusive_range_with_no_end` from `ast_lowering`"]
pub const ast_lowering_inclusive_range_with_no_end:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_inclusive_range_with_no_end"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_inline_asm_unsupported_target` from `ast_lowering`"]
pub const ast_lowering_inline_asm_unsupported_target:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_inline_asm_unsupported_target"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_invalid_abi` from `ast_lowering`"]
pub const ast_lowering_invalid_abi: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_invalid_abi"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_invalid_abi_clobber_abi` from `ast_lowering`"]
pub const ast_lowering_invalid_abi_clobber_abi: rustc_errors::DiagMessage
=
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_invalid_abi_clobber_abi"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_invalid_abi_suggestion` from `ast_lowering`"]
pub const ast_lowering_invalid_abi_suggestion: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_invalid_abi_suggestion"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_invalid_asm_template_modifier_const` from `ast_lowering`"]
pub const ast_lowering_invalid_asm_template_modifier_const:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_invalid_asm_template_modifier_const"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_invalid_asm_template_modifier_label` from `ast_lowering`"]
pub const ast_lowering_invalid_asm_template_modifier_label:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_invalid_asm_template_modifier_label"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_invalid_asm_template_modifier_reg_class` from `ast_lowering`"]
pub const ast_lowering_invalid_asm_template_modifier_reg_class:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_invalid_asm_template_modifier_reg_class"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_invalid_asm_template_modifier_sym` from `ast_lowering`"]
pub const ast_lowering_invalid_asm_template_modifier_sym:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_invalid_asm_template_modifier_sym"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_invalid_legacy_const_generic_arg` from `ast_lowering`"]
pub const ast_lowering_invalid_legacy_const_generic_arg:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_invalid_legacy_const_generic_arg"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_invalid_legacy_const_generic_arg_suggestion` from `ast_lowering`"]
pub const ast_lowering_invalid_legacy_const_generic_arg_suggestion:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_invalid_legacy_const_generic_arg_suggestion"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_invalid_register` from `ast_lowering`"]
pub const ast_lowering_invalid_register: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_invalid_register"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_invalid_register_class` from `ast_lowering`"]
pub const ast_lowering_invalid_register_class: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_invalid_register_class"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_match_arm_with_no_body` from `ast_lowering`"]
pub const ast_lowering_match_arm_with_no_body: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_match_arm_with_no_body"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_misplaced_double_dot` from `ast_lowering`"]
pub const ast_lowering_misplaced_double_dot: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_misplaced_double_dot"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_misplaced_impl_trait` from `ast_lowering`"]
pub const ast_lowering_misplaced_impl_trait: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_misplaced_impl_trait"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_never_pattern_with_body` from `ast_lowering`"]
pub const ast_lowering_never_pattern_with_body: rustc_errors::DiagMessage
=
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_never_pattern_with_body"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_never_pattern_with_guard` from `ast_lowering`"]
pub const ast_lowering_never_pattern_with_guard: rustc_errors::DiagMessage
=
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_never_pattern_with_guard"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_no_precise_captures_on_apit` from `ast_lowering`"]
pub const ast_lowering_no_precise_captures_on_apit:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_no_precise_captures_on_apit"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_previously_used_here` from `ast_lowering`"]
pub const ast_lowering_previously_used_here: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_previously_used_here"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_register1` from `ast_lowering`"]
pub const ast_lowering_register1: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_register1"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_register2` from `ast_lowering`"]
pub const ast_lowering_register2: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_register2"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_register_class_only_clobber` from `ast_lowering`"]
pub const ast_lowering_register_class_only_clobber:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_register_class_only_clobber"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_register_class_only_clobber_stable` from `ast_lowering`"]
pub const ast_lowering_register_class_only_clobber_stable:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_register_class_only_clobber_stable"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_register_conflict` from `ast_lowering`"]
pub const ast_lowering_register_conflict: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_register_conflict"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_register_conflict.help` from `ast_lowering`"]
pub const ast_lowering_help: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("help"));
#[doc =
"Constant referring to Fluent message `ast_lowering_remove_parentheses` from `ast_lowering`"]
pub const ast_lowering_remove_parentheses: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_remove_parentheses"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_sub_tuple_binding` from `ast_lowering`"]
pub const ast_lowering_sub_tuple_binding: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_sub_tuple_binding"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_sub_tuple_binding_suggestion` from `ast_lowering`"]
pub const ast_lowering_sub_tuple_binding_suggestion:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_sub_tuple_binding_suggestion"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_support_modifiers` from `ast_lowering`"]
pub const ast_lowering_support_modifiers: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_support_modifiers"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_template_modifier` from `ast_lowering`"]
pub const ast_lowering_template_modifier: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_template_modifier"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_this_not_async` from `ast_lowering`"]
pub const ast_lowering_this_not_async: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_this_not_async"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_underscore_expr_lhs_assign` from `ast_lowering`"]
pub const ast_lowering_underscore_expr_lhs_assign:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_underscore_expr_lhs_assign"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_union_default_field_values` from `ast_lowering`"]
pub const ast_lowering_union_default_field_values:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_union_default_field_values"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_unstable_inline_assembly` from `ast_lowering`"]
pub const ast_lowering_unstable_inline_assembly: rustc_errors::DiagMessage
=
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_unstable_inline_assembly"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_unstable_inline_assembly_label_operand_with_outputs` from `ast_lowering`"]
pub const
ast_lowering_unstable_inline_assembly_label_operand_with_outputs:
rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_unstable_inline_assembly_label_operand_with_outputs"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_unstable_may_unwind` from `ast_lowering`"]
pub const ast_lowering_unstable_may_unwind: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_unstable_may_unwind"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_use_angle_brackets` from `ast_lowering`"]
pub const ast_lowering_use_angle_brackets: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_use_angle_brackets"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_yield` from `ast_lowering`"]
pub const ast_lowering_yield: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_yield"),
None);
#[doc =
"Constant referring to Fluent message `ast_lowering_yield_in_closure` from `ast_lowering`"]
pub const ast_lowering_yield_in_closure: rustc_errors::DiagMessage =
rustc_errors::DiagMessage::FluentIdentifier(std::borrow::Cow::Borrowed("ast_lowering_yield_in_closure"),
None);
#[doc =
r" Constants expected to exist by the diagnostic derive macros to use as default Fluent"]
#[doc = r" identifiers for different subdiagnostic kinds."]
pub mod _subdiag {
#[doc = r" Default for `#[help]`"]
pub const help: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("help"));
#[doc = r" Default for `#[note]`"]
pub const note: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("note"));
#[doc = r" Default for `#[warn]`"]
pub const warn: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("warn"));
#[doc = r" Default for `#[label]`"]
pub const label: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("label"));
#[doc = r" Default for `#[suggestion]`"]
pub const suggestion: rustc_errors::SubdiagMessage =
rustc_errors::SubdiagMessage::FluentAttr(std::borrow::Cow::Borrowed("suggestion"));
}
}rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
91
92struct LoweringContext<'a, 'hir> {
93 tcx: TyCtxt<'hir>,
94 resolver: &'a mut ResolverAstLowering,
95 disambiguator: DisambiguatorState,
96
97 arena: &'hir hir::Arena<'hir>,
99
100 bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>,
102 define_opaque: Option<&'hir [(Span, LocalDefId)]>,
104 attrs: SortedMap<hir::ItemLocalId, &'hir [hir::Attribute]>,
106 children: Vec<(LocalDefId, hir::MaybeOwner<'hir>)>,
108
109 contract_ensures: Option<(Span, Ident, HirId)>,
110
111 coroutine_kind: Option<hir::CoroutineKind>,
112
113 task_context: Option<HirId>,
116
117 current_item: Option<Span>,
120
121 try_block_scope: TryBlockScope,
122 loop_scope: Option<HirId>,
123 is_in_loop_condition: bool,
124 is_in_dyn_type: bool,
125
126 current_hir_id_owner: hir::OwnerId,
127 item_local_id_counter: hir::ItemLocalId,
128 trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
129
130 impl_trait_defs: Vec<hir::GenericParam<'hir>>,
131 impl_trait_bounds: Vec<hir::WherePredicate<'hir>>,
132
133 ident_and_label_to_local_id: NodeMap<hir::ItemLocalId>,
135 #[cfg(debug_assertions)]
137 node_id_to_local_id: NodeMap<hir::ItemLocalId>,
138
139 allow_contracts: Arc<[Symbol]>,
140 allow_try_trait: Arc<[Symbol]>,
141 allow_gen_future: Arc<[Symbol]>,
142 allow_pattern_type: Arc<[Symbol]>,
143 allow_async_gen: Arc<[Symbol]>,
144 allow_async_iterator: Arc<[Symbol]>,
145 allow_for_await: Arc<[Symbol]>,
146 allow_async_fn_traits: Arc<[Symbol]>,
147
148 delayed_lints: Vec<DelayedLint>,
149
150 attribute_parser: AttributeParser<'hir>,
151}
152
153impl<'a, 'hir> LoweringContext<'a, 'hir> {
154 fn new(tcx: TyCtxt<'hir>, resolver: &'a mut ResolverAstLowering) -> Self {
155 let registered_tools = tcx.registered_tools(()).iter().map(|x| x.name).collect();
156 Self {
157 tcx,
159 resolver,
160 disambiguator: DisambiguatorState::new(),
161 arena: tcx.hir_arena,
162
163 bodies: Vec::new(),
165 define_opaque: None,
166 attrs: SortedMap::default(),
167 children: Vec::default(),
168 contract_ensures: None,
169 current_hir_id_owner: hir::CRATE_OWNER_ID,
170 item_local_id_counter: hir::ItemLocalId::ZERO,
171 ident_and_label_to_local_id: Default::default(),
172 #[cfg(debug_assertions)]
173 node_id_to_local_id: Default::default(),
174 trait_map: Default::default(),
175
176 try_block_scope: TryBlockScope::Function,
178 loop_scope: None,
179 is_in_loop_condition: false,
180 is_in_dyn_type: false,
181 coroutine_kind: None,
182 task_context: None,
183 current_item: None,
184 impl_trait_defs: Vec::new(),
185 impl_trait_bounds: Vec::new(),
186 allow_contracts: [sym::contracts_internals].into(),
187 allow_try_trait: [
188 sym::try_trait_v2,
189 sym::try_trait_v2_residual,
190 sym::yeet_desugar_details,
191 ]
192 .into(),
193 allow_pattern_type: [sym::pattern_types, sym::pattern_type_range_trait].into(),
194 allow_gen_future: if tcx.features().async_fn_track_caller() {
195 [sym::gen_future, sym::closure_track_caller].into()
196 } else {
197 [sym::gen_future].into()
198 },
199 allow_for_await: [sym::async_gen_internals, sym::async_iterator].into(),
200 allow_async_fn_traits: [sym::async_fn_traits].into(),
201 allow_async_gen: [sym::async_gen_internals].into(),
202 allow_async_iterator: [sym::gen_future, sym::async_iterator].into(),
205
206 attribute_parser: AttributeParser::new(
207 tcx.sess,
208 tcx.features(),
209 registered_tools,
210 Late,
211 ),
212 delayed_lints: Vec::new(),
213 }
214 }
215
216 pub(crate) fn dcx(&self) -> DiagCtxtHandle<'hir> {
217 self.tcx.dcx()
218 }
219}
220
221struct SpanLowerer {
222 is_incremental: bool,
223 def_id: LocalDefId,
224}
225
226impl SpanLowerer {
227 fn lower(&self, span: Span) -> Span {
228 if self.is_incremental {
229 span.with_parent(Some(self.def_id))
230 } else {
231 span
233 }
234 }
235}
236
237impl ResolverAstLoweringExt for ResolverAstLowering {
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>> {
let ExprKind::Path(None, path) = &expr.kind else { return None; };
if path.segments.last().unwrap().args.is_some() { return None; }
let def_id =
self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
if def_id.is_local() { return None; }
if let Some(v) = self.legacy_const_generic_args.get(&def_id) {
return v.clone();
}
None
}
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
self.partial_res_map.get(&id).copied()
}
#[doc =
" Obtains per-namespace resolutions for `use` statement with the given `NodeId`."]
fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res<NodeId>>> {
self.import_res_map.get(&id).copied().unwrap_or_default()
}
#[doc = " Obtains resolution for a label with the given `NodeId`."]
fn get_label_res(&self, id: NodeId) -> Option<NodeId> {
self.label_res_map.get(&id).copied()
}
#[doc = " Obtains resolution for a lifetime with the given `NodeId`."]
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes> {
self.lifetimes_res_map.get(&id).copied()
}
#[doc = " Obtain the list of lifetimes parameters to add to an item."]
#[doc = ""]
#[doc =
" Extra lifetime parameters should only be added in places that can appear"]
#[doc = " as a `binder` in `LifetimeRes`."]
#[doc = ""]
#[doc =
" The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring"]
#[doc = " should appear at the enclosing `PolyTraitRef`."]
fn extra_lifetime_params(&mut self, id: NodeId)
-> Vec<(Ident, NodeId, LifetimeRes)> {
self.extra_lifetime_params_map.get(&id).cloned().unwrap_or_default()
}
}#[extension(trait ResolverAstLoweringExt)]
238impl ResolverAstLowering {
239 fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>> {
240 let ExprKind::Path(None, path) = &expr.kind else {
241 return None;
242 };
243
244 if path.segments.last().unwrap().args.is_some() {
247 return None;
248 }
249
250 let def_id = self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
251
252 if def_id.is_local() {
256 return None;
257 }
258
259 if let Some(v) = self.legacy_const_generic_args.get(&def_id) {
260 return v.clone();
261 }
262
263 None
264 }
265
266 fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
267 self.partial_res_map.get(&id).copied()
268 }
269
270 fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res<NodeId>>> {
272 self.import_res_map.get(&id).copied().unwrap_or_default()
273 }
274
275 fn get_label_res(&self, id: NodeId) -> Option<NodeId> {
277 self.label_res_map.get(&id).copied()
278 }
279
280 fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes> {
282 self.lifetimes_res_map.get(&id).copied()
283 }
284
285 fn extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)> {
293 self.extra_lifetime_params_map.get(&id).cloned().unwrap_or_default()
294 }
295}
296
297#[derive(#[automatically_derived]
impl<'a> ::core::clone::Clone for RelaxedBoundPolicy<'a> {
#[inline]
fn clone(&self) -> RelaxedBoundPolicy<'a> {
let _: ::core::clone::AssertParamIsClone<NodeId>;
let _: ::core::clone::AssertParamIsClone<&'a [ast::GenericParam]>;
let _: ::core::clone::AssertParamIsClone<RelaxedBoundForbiddenReason>;
*self
}
}Clone, #[automatically_derived]
impl<'a> ::core::marker::Copy for RelaxedBoundPolicy<'a> { }Copy, #[automatically_derived]
impl<'a> ::core::fmt::Debug for RelaxedBoundPolicy<'a> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
RelaxedBoundPolicy::Allowed =>
::core::fmt::Formatter::write_str(f, "Allowed"),
RelaxedBoundPolicy::AllowedIfOnTyParam(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"AllowedIfOnTyParam", __self_0, &__self_1),
RelaxedBoundPolicy::Forbidden(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Forbidden", &__self_0),
}
}
}Debug)]
302enum RelaxedBoundPolicy<'a> {
303 Allowed,
304 AllowedIfOnTyParam(NodeId, &'a [ast::GenericParam]),
305 Forbidden(RelaxedBoundForbiddenReason),
306}
307
308#[derive(#[automatically_derived]
impl ::core::clone::Clone for RelaxedBoundForbiddenReason {
#[inline]
fn clone(&self) -> RelaxedBoundForbiddenReason { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for RelaxedBoundForbiddenReason { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for RelaxedBoundForbiddenReason {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
RelaxedBoundForbiddenReason::TraitObjectTy => "TraitObjectTy",
RelaxedBoundForbiddenReason::SuperTrait => "SuperTrait",
RelaxedBoundForbiddenReason::TraitAlias => "TraitAlias",
RelaxedBoundForbiddenReason::AssocTyBounds => "AssocTyBounds",
RelaxedBoundForbiddenReason::LateBoundVarsInScope =>
"LateBoundVarsInScope",
})
}
}Debug)]
309enum RelaxedBoundForbiddenReason {
310 TraitObjectTy,
311 SuperTrait,
312 TraitAlias,
313 AssocTyBounds,
314 LateBoundVarsInScope,
315}
316
317#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ImplTraitContext {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ImplTraitContext::Universal =>
::core::fmt::Formatter::write_str(f, "Universal"),
ImplTraitContext::OpaqueTy { origin: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"OpaqueTy", "origin", &__self_0),
ImplTraitContext::InBinding =>
::core::fmt::Formatter::write_str(f, "InBinding"),
ImplTraitContext::FeatureGated(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"FeatureGated", __self_0, &__self_1),
ImplTraitContext::Disallowed(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Disallowed", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for ImplTraitContext { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ImplTraitContext {
#[inline]
fn clone(&self) -> ImplTraitContext {
let _:
::core::clone::AssertParamIsClone<hir::OpaqueTyOrigin<LocalDefId>>;
let _: ::core::clone::AssertParamIsClone<ImplTraitPosition>;
let _: ::core::clone::AssertParamIsClone<Symbol>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ImplTraitContext {
#[inline]
fn eq(&self, other: &ImplTraitContext) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ImplTraitContext::OpaqueTy { origin: __self_0 },
ImplTraitContext::OpaqueTy { origin: __arg1_0 }) =>
__self_0 == __arg1_0,
(ImplTraitContext::FeatureGated(__self_0, __self_1),
ImplTraitContext::FeatureGated(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(ImplTraitContext::Disallowed(__self_0),
ImplTraitContext::Disallowed(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ImplTraitContext {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<hir::OpaqueTyOrigin<LocalDefId>>;
let _: ::core::cmp::AssertParamIsEq<ImplTraitPosition>;
let _: ::core::cmp::AssertParamIsEq<Symbol>;
}
}Eq)]
320enum ImplTraitContext {
321 Universal,
327
328 OpaqueTy { origin: hir::OpaqueTyOrigin<LocalDefId> },
333
334 InBinding,
339
340 FeatureGated(ImplTraitPosition, Symbol),
342 Disallowed(ImplTraitPosition),
344}
345
346#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ImplTraitPosition {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ImplTraitPosition::Path => "Path",
ImplTraitPosition::Variable => "Variable",
ImplTraitPosition::Trait => "Trait",
ImplTraitPosition::Bound => "Bound",
ImplTraitPosition::Generic => "Generic",
ImplTraitPosition::ExternFnParam => "ExternFnParam",
ImplTraitPosition::ClosureParam => "ClosureParam",
ImplTraitPosition::PointerParam => "PointerParam",
ImplTraitPosition::FnTraitParam => "FnTraitParam",
ImplTraitPosition::ExternFnReturn => "ExternFnReturn",
ImplTraitPosition::ClosureReturn => "ClosureReturn",
ImplTraitPosition::PointerReturn => "PointerReturn",
ImplTraitPosition::FnTraitReturn => "FnTraitReturn",
ImplTraitPosition::GenericDefault => "GenericDefault",
ImplTraitPosition::ConstTy => "ConstTy",
ImplTraitPosition::StaticTy => "StaticTy",
ImplTraitPosition::AssocTy => "AssocTy",
ImplTraitPosition::FieldTy => "FieldTy",
ImplTraitPosition::Cast => "Cast",
ImplTraitPosition::ImplSelf => "ImplSelf",
ImplTraitPosition::OffsetOf => "OffsetOf",
})
}
}Debug, #[automatically_derived]
impl ::core::marker::Copy for ImplTraitPosition { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ImplTraitPosition {
#[inline]
fn clone(&self) -> ImplTraitPosition { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ImplTraitPosition {
#[inline]
fn eq(&self, other: &ImplTraitPosition) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ImplTraitPosition {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {}
}Eq)]
348enum ImplTraitPosition {
349 Path,
350 Variable,
351 Trait,
352 Bound,
353 Generic,
354 ExternFnParam,
355 ClosureParam,
356 PointerParam,
357 FnTraitParam,
358 ExternFnReturn,
359 ClosureReturn,
360 PointerReturn,
361 FnTraitReturn,
362 GenericDefault,
363 ConstTy,
364 StaticTy,
365 AssocTy,
366 FieldTy,
367 Cast,
368 ImplSelf,
369 OffsetOf,
370}
371
372impl std::fmt::Display for ImplTraitPosition {
373 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
374 let name = match self {
375 ImplTraitPosition::Path => "paths",
376 ImplTraitPosition::Variable => "the type of variable bindings",
377 ImplTraitPosition::Trait => "traits",
378 ImplTraitPosition::Bound => "bounds",
379 ImplTraitPosition::Generic => "generics",
380 ImplTraitPosition::ExternFnParam => "`extern fn` parameters",
381 ImplTraitPosition::ClosureParam => "closure parameters",
382 ImplTraitPosition::PointerParam => "`fn` pointer parameters",
383 ImplTraitPosition::FnTraitParam => "the parameters of `Fn` trait bounds",
384 ImplTraitPosition::ExternFnReturn => "`extern fn` return types",
385 ImplTraitPosition::ClosureReturn => "closure return types",
386 ImplTraitPosition::PointerReturn => "`fn` pointer return types",
387 ImplTraitPosition::FnTraitReturn => "the return type of `Fn` trait bounds",
388 ImplTraitPosition::GenericDefault => "generic parameter defaults",
389 ImplTraitPosition::ConstTy => "const types",
390 ImplTraitPosition::StaticTy => "static types",
391 ImplTraitPosition::AssocTy => "associated types",
392 ImplTraitPosition::FieldTy => "field types",
393 ImplTraitPosition::Cast => "cast expression types",
394 ImplTraitPosition::ImplSelf => "impl headers",
395 ImplTraitPosition::OffsetOf => "`offset_of!` parameters",
396 };
397
398 f.write_fmt(format_args!("{0}", name))write!(f, "{name}")
399 }
400}
401
402#[derive(#[automatically_derived]
impl ::core::marker::Copy for FnDeclKind { }Copy, #[automatically_derived]
impl ::core::clone::Clone for FnDeclKind {
#[inline]
fn clone(&self) -> FnDeclKind { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for FnDeclKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
FnDeclKind::Fn => "Fn",
FnDeclKind::Inherent => "Inherent",
FnDeclKind::ExternFn => "ExternFn",
FnDeclKind::Closure => "Closure",
FnDeclKind::Pointer => "Pointer",
FnDeclKind::Trait => "Trait",
FnDeclKind::Impl => "Impl",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for FnDeclKind {
#[inline]
fn eq(&self, other: &FnDeclKind) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for FnDeclKind {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {}
}Eq)]
403enum FnDeclKind {
404 Fn,
405 Inherent,
406 ExternFn,
407 Closure,
408 Pointer,
409 Trait,
410 Impl,
411}
412
413#[derive(#[automatically_derived]
impl<'a> ::core::marker::Copy for AstOwner<'a> { }Copy, #[automatically_derived]
impl<'a> ::core::clone::Clone for AstOwner<'a> {
#[inline]
fn clone(&self) -> AstOwner<'a> {
let _: ::core::clone::AssertParamIsClone<&'a ast::Crate>;
let _: ::core::clone::AssertParamIsClone<&'a ast::Item>;
let _: ::core::clone::AssertParamIsClone<&'a ast::AssocItem>;
let _: ::core::clone::AssertParamIsClone<visit::AssocCtxt>;
let _: ::core::clone::AssertParamIsClone<&'a ast::ForeignItem>;
*self
}
}Clone)]
414enum AstOwner<'a> {
415 NonOwner,
416 Crate(&'a ast::Crate),
417 Item(&'a ast::Item),
418 AssocItem(&'a ast::AssocItem, visit::AssocCtxt),
419 ForeignItem(&'a ast::ForeignItem),
420}
421
422#[derive(#[automatically_derived]
impl ::core::marker::Copy for TryBlockScope { }Copy, #[automatically_derived]
impl ::core::clone::Clone for TryBlockScope {
#[inline]
fn clone(&self) -> TryBlockScope {
let _: ::core::clone::AssertParamIsClone<HirId>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for TryBlockScope {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
TryBlockScope::Function =>
::core::fmt::Formatter::write_str(f, "Function"),
TryBlockScope::Homogeneous(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Homogeneous", &__self_0),
TryBlockScope::Heterogeneous(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Heterogeneous", &__self_0),
}
}
}Debug)]
423enum TryBlockScope {
424 Function,
426 Homogeneous(HirId),
429 Heterogeneous(HirId),
432}
433
434fn index_crate<'a>(
435 node_id_to_def_id: &NodeMap<LocalDefId>,
436 krate: &'a Crate,
437) -> IndexVec<LocalDefId, AstOwner<'a>> {
438 let mut indexer = Indexer { node_id_to_def_id, index: IndexVec::new() };
439 *indexer.index.ensure_contains_elem(CRATE_DEF_ID, || AstOwner::NonOwner) =
440 AstOwner::Crate(krate);
441 visit::walk_crate(&mut indexer, krate);
442 return indexer.index;
443
444 struct Indexer<'s, 'a> {
445 node_id_to_def_id: &'s NodeMap<LocalDefId>,
446 index: IndexVec<LocalDefId, AstOwner<'a>>,
447 }
448
449 impl<'a> visit::Visitor<'a> for Indexer<'_, 'a> {
450 fn visit_attribute(&mut self, _: &'a Attribute) {
451 }
454
455 fn visit_item(&mut self, item: &'a ast::Item) {
456 let def_id = self.node_id_to_def_id[&item.id];
457 *self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner) = AstOwner::Item(item);
458 visit::walk_item(self, item)
459 }
460
461 fn visit_assoc_item(&mut self, item: &'a ast::AssocItem, ctxt: visit::AssocCtxt) {
462 let def_id = self.node_id_to_def_id[&item.id];
463 *self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner) =
464 AstOwner::AssocItem(item, ctxt);
465 visit::walk_assoc_item(self, item, ctxt);
466 }
467
468 fn visit_foreign_item(&mut self, item: &'a ast::ForeignItem) {
469 let def_id = self.node_id_to_def_id[&item.id];
470 *self.index.ensure_contains_elem(def_id, || AstOwner::NonOwner) =
471 AstOwner::ForeignItem(item);
472 visit::walk_item(self, item);
473 }
474 }
475}
476
477fn compute_hir_hash(
480 tcx: TyCtxt<'_>,
481 owners: &IndexSlice<LocalDefId, hir::MaybeOwner<'_>>,
482) -> Fingerprint {
483 let mut hir_body_nodes: Vec<_> = owners
484 .iter_enumerated()
485 .filter_map(|(def_id, info)| {
486 let info = info.as_owner()?;
487 let def_path_hash = tcx.hir_def_path_hash(def_id);
488 Some((def_path_hash, info))
489 })
490 .collect();
491 hir_body_nodes.sort_unstable_by_key(|bn| bn.0);
492
493 tcx.with_stable_hashing_context(|mut hcx| {
494 let mut stable_hasher = StableHasher::new();
495 hir_body_nodes.hash_stable(&mut hcx, &mut stable_hasher);
496 stable_hasher.finish()
497 })
498}
499
500pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
501 let sess = tcx.sess;
502 tcx.ensure_done().output_filenames(());
504 tcx.ensure_done().early_lint_checks(());
505 tcx.ensure_done().debugger_visualizers(LOCAL_CRATE);
506 tcx.ensure_done().get_lang_items(());
507 let (mut resolver, krate) = tcx.resolver_for_lowering().steal();
508
509 let ast_index = index_crate(&resolver.node_id_to_def_id, &krate);
510 let mut owners = IndexVec::from_fn_n(
511 |_| hir::MaybeOwner::Phantom,
512 tcx.definitions_untracked().def_index_count(),
513 );
514
515 let mut lowerer = item::ItemLowerer {
516 tcx,
517 resolver: &mut resolver,
518 ast_index: &ast_index,
519 owners: &mut owners,
520 };
521 for def_id in ast_index.indices() {
522 lowerer.lower_node(def_id);
523 }
524
525 drop(ast_index);
526
527 let prof = sess.prof.clone();
529 spawn(move || {
530 let _timer = prof.verbose_generic_activity("drop_ast");
531 drop(krate);
532 });
533
534 let opt_hir_hash =
536 if tcx.needs_crate_hash() { Some(compute_hir_hash(tcx, &owners)) } else { None };
537 hir::Crate { owners, opt_hir_hash }
538}
539
540#[derive(#[automatically_derived]
impl ::core::marker::Copy for ParamMode { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ParamMode {
#[inline]
fn clone(&self) -> ParamMode { *self }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for ParamMode {
#[inline]
fn eq(&self, other: &ParamMode) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for ParamMode {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ParamMode::Explicit => "Explicit",
ParamMode::Optional => "Optional",
})
}
}Debug)]
541enum ParamMode {
542 Explicit,
544 Optional,
546}
547
548#[derive(#[automatically_derived]
impl ::core::marker::Copy for AllowReturnTypeNotation { }Copy, #[automatically_derived]
impl ::core::clone::Clone for AllowReturnTypeNotation {
#[inline]
fn clone(&self) -> AllowReturnTypeNotation { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for AllowReturnTypeNotation {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
AllowReturnTypeNotation::Yes => "Yes",
AllowReturnTypeNotation::No => "No",
})
}
}Debug)]
549enum AllowReturnTypeNotation {
550 Yes,
552 No,
554}
555
556enum GenericArgsMode {
557 ParenSugar,
559 ReturnTypeNotation,
561 Err,
563 Silence,
565}
566
567impl<'a, 'hir> LoweringContext<'a, 'hir> {
568 fn create_def(
569 &mut self,
570 node_id: ast::NodeId,
571 name: Option<Symbol>,
572 def_kind: DefKind,
573 def_path_data: DefPathData,
574 span: Span,
575 ) -> LocalDefId {
576 let parent = self.current_hir_id_owner.def_id;
577 match (&node_id, &ast::DUMMY_NODE_ID) {
(left_val, right_val) => {
if *left_val == *right_val {
let kind = ::core::panicking::AssertKind::Ne;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_ne!(node_id, ast::DUMMY_NODE_ID);
578 if !self.opt_local_def_id(node_id).is_none() {
{
::core::panicking::panic_fmt(format_args!("adding a def\'n for node-id {0:?} and def kind {1:?} but a previous def\'n exists: {2:?}",
node_id, def_kind,
self.tcx.hir_def_key(self.local_def_id(node_id))));
}
};assert!(
579 self.opt_local_def_id(node_id).is_none(),
580 "adding a def'n for node-id {:?} and def kind {:?} but a previous def'n exists: {:?}",
581 node_id,
582 def_kind,
583 self.tcx.hir_def_key(self.local_def_id(node_id)),
584 );
585
586 let def_id = self
587 .tcx
588 .at(span)
589 .create_def(parent, name, def_kind, Some(def_path_data), &mut self.disambiguator)
590 .def_id();
591
592 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:592",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(592u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("create_def: def_id_to_node_id[{0:?}] <-> {1:?}",
def_id, node_id) as &dyn Value))])
});
} else { ; }
};debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id);
593 self.resolver.node_id_to_def_id.insert(node_id, def_id);
594
595 def_id
596 }
597
598 fn next_node_id(&mut self) -> NodeId {
599 let start = self.resolver.next_node_id;
600 let next = start.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
601 self.resolver.next_node_id = ast::NodeId::from_u32(next);
602 start
603 }
604
605 fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> {
608 self.resolver.node_id_to_def_id.get(&node).copied()
609 }
610
611 fn local_def_id(&self, node: NodeId) -> LocalDefId {
612 self.opt_local_def_id(node).unwrap_or_else(|| {
::core::panicking::panic_fmt(format_args!("no entry for node id: `{0:?}`",
node));
}panic!("no entry for node id: `{node:?}`"))
613 }
614
615 fn owner_id(&self, node: NodeId) -> hir::OwnerId {
617 hir::OwnerId { def_id: self.local_def_id(node) }
618 }
619
620 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("with_hir_id_owner",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(625u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["owner"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&owner)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let owner_id = self.owner_id(owner);
let current_attrs = std::mem::take(&mut self.attrs);
let current_bodies = std::mem::take(&mut self.bodies);
let current_define_opaque =
std::mem::take(&mut self.define_opaque);
let current_ident_and_label_to_local_id =
std::mem::take(&mut self.ident_and_label_to_local_id);
let current_node_id_to_local_id =
std::mem::take(&mut self.node_id_to_local_id);
let current_trait_map = std::mem::take(&mut self.trait_map);
let current_owner =
std::mem::replace(&mut self.current_hir_id_owner, owner_id);
let current_local_counter =
std::mem::replace(&mut self.item_local_id_counter,
hir::ItemLocalId::new(1));
let current_impl_trait_defs =
std::mem::take(&mut self.impl_trait_defs);
let current_impl_trait_bounds =
std::mem::take(&mut self.impl_trait_bounds);
let current_delayed_lints =
std::mem::take(&mut self.delayed_lints);
{
let _old =
self.node_id_to_local_id.insert(owner,
hir::ItemLocalId::ZERO);
if true {
match (&_old, &None) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
};
}
let item = f(self);
match (&owner_id, &item.def_id()) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
if !self.impl_trait_defs.is_empty() {
::core::panicking::panic("assertion failed: self.impl_trait_defs.is_empty()")
};
if !self.impl_trait_bounds.is_empty() {
::core::panicking::panic("assertion failed: self.impl_trait_bounds.is_empty()")
};
let info = self.make_owner_info(item);
self.attrs = current_attrs;
self.bodies = current_bodies;
self.define_opaque = current_define_opaque;
self.ident_and_label_to_local_id =
current_ident_and_label_to_local_id;
{ self.node_id_to_local_id = current_node_id_to_local_id; }
self.trait_map = current_trait_map;
self.current_hir_id_owner = current_owner;
self.item_local_id_counter = current_local_counter;
self.impl_trait_defs = current_impl_trait_defs;
self.impl_trait_bounds = current_impl_trait_bounds;
self.delayed_lints = current_delayed_lints;
if true {
if !!self.children.iter().any(|(id, _)|
id == &owner_id.def_id) {
::core::panicking::panic("assertion failed: !self.children.iter().any(|(id, _)| id == &owner_id.def_id)")
};
};
self.children.push((owner_id.def_id,
hir::MaybeOwner::Owner(info)));
}
}
}#[instrument(level = "debug", skip(self, f))]
626 fn with_hir_id_owner(
627 &mut self,
628 owner: NodeId,
629 f: impl FnOnce(&mut Self) -> hir::OwnerNode<'hir>,
630 ) {
631 let owner_id = self.owner_id(owner);
632
633 let current_attrs = std::mem::take(&mut self.attrs);
634 let current_bodies = std::mem::take(&mut self.bodies);
635 let current_define_opaque = std::mem::take(&mut self.define_opaque);
636 let current_ident_and_label_to_local_id =
637 std::mem::take(&mut self.ident_and_label_to_local_id);
638
639 #[cfg(debug_assertions)]
640 let current_node_id_to_local_id = std::mem::take(&mut self.node_id_to_local_id);
641 let current_trait_map = std::mem::take(&mut self.trait_map);
642 let current_owner = std::mem::replace(&mut self.current_hir_id_owner, owner_id);
643 let current_local_counter =
644 std::mem::replace(&mut self.item_local_id_counter, hir::ItemLocalId::new(1));
645 let current_impl_trait_defs = std::mem::take(&mut self.impl_trait_defs);
646 let current_impl_trait_bounds = std::mem::take(&mut self.impl_trait_bounds);
647 let current_delayed_lints = std::mem::take(&mut self.delayed_lints);
648
649 #[cfg(debug_assertions)]
655 {
656 let _old = self.node_id_to_local_id.insert(owner, hir::ItemLocalId::ZERO);
657 debug_assert_eq!(_old, None);
658 }
659
660 let item = f(self);
661 assert_eq!(owner_id, item.def_id());
662 assert!(self.impl_trait_defs.is_empty());
664 assert!(self.impl_trait_bounds.is_empty());
665 let info = self.make_owner_info(item);
666
667 self.attrs = current_attrs;
668 self.bodies = current_bodies;
669 self.define_opaque = current_define_opaque;
670 self.ident_and_label_to_local_id = current_ident_and_label_to_local_id;
671
672 #[cfg(debug_assertions)]
673 {
674 self.node_id_to_local_id = current_node_id_to_local_id;
675 }
676 self.trait_map = current_trait_map;
677 self.current_hir_id_owner = current_owner;
678 self.item_local_id_counter = current_local_counter;
679 self.impl_trait_defs = current_impl_trait_defs;
680 self.impl_trait_bounds = current_impl_trait_bounds;
681 self.delayed_lints = current_delayed_lints;
682
683 debug_assert!(!self.children.iter().any(|(id, _)| id == &owner_id.def_id));
684 self.children.push((owner_id.def_id, hir::MaybeOwner::Owner(info)));
685 }
686
687 fn make_owner_info(&mut self, node: hir::OwnerNode<'hir>) -> &'hir hir::OwnerInfo<'hir> {
688 let attrs = std::mem::take(&mut self.attrs);
689 let mut bodies = std::mem::take(&mut self.bodies);
690 let define_opaque = std::mem::take(&mut self.define_opaque);
691 let trait_map = std::mem::take(&mut self.trait_map);
692 let delayed_lints = std::mem::take(&mut self.delayed_lints).into_boxed_slice();
693
694 #[cfg(debug_assertions)]
695 for (id, attrs) in attrs.iter() {
696 if attrs.is_empty() {
698 {
::core::panicking::panic_fmt(format_args!("Stored empty attributes for {0:?}",
id));
};panic!("Stored empty attributes for {:?}", id);
699 }
700 }
701
702 bodies.sort_by_key(|(k, _)| *k);
703 let bodies = SortedMap::from_presorted_elements(bodies);
704
705 let rustc_middle::hir::Hashes { opt_hash_including_bodies, attrs_hash, delayed_lints_hash } =
707 self.tcx.hash_owner_nodes(node, &bodies, &attrs, &delayed_lints, define_opaque);
708 let num_nodes = self.item_local_id_counter.as_usize();
709 let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
710 let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };
711 let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash, define_opaque };
712 let delayed_lints =
713 hir::lints::DelayedLints { lints: delayed_lints, opt_hash: delayed_lints_hash };
714
715 self.arena.alloc(hir::OwnerInfo { nodes, parenting, attrs, trait_map, delayed_lints })
716 }
717
718 x;#[instrument(level = "debug", skip(self), ret)]
724 fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId {
725 assert_ne!(ast_node_id, DUMMY_NODE_ID);
726
727 let owner = self.current_hir_id_owner;
728 let local_id = self.item_local_id_counter;
729 assert_ne!(local_id, hir::ItemLocalId::ZERO);
730 self.item_local_id_counter.increment_by(1);
731 let hir_id = HirId { owner, local_id };
732
733 if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
734 self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
735 }
736
737 if let Some(traits) = self.resolver.trait_map.remove(&ast_node_id) {
738 self.trait_map.insert(hir_id.local_id, traits.into_boxed_slice());
739 }
740
741 #[cfg(debug_assertions)]
743 {
744 let old = self.node_id_to_local_id.insert(ast_node_id, local_id);
745 assert_eq!(old, None);
746 }
747
748 hir_id
749 }
750
751 x;#[instrument(level = "debug", skip(self), ret)]
753 fn next_id(&mut self) -> HirId {
754 let owner = self.current_hir_id_owner;
755 let local_id = self.item_local_id_counter;
756 assert_ne!(local_id, hir::ItemLocalId::ZERO);
757 self.item_local_id_counter.increment_by(1);
758 HirId { owner, local_id }
759 }
760
761 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_res",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(761u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["res"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Res = loop {};
return __tracing_attr_fake_return;
}
{
let res: Result<Res, ()> =
res.apply_id(|id|
{
let owner = self.current_hir_id_owner;
let local_id =
self.ident_and_label_to_local_id.get(&id).copied().ok_or(())?;
Ok(HirId { owner, local_id })
});
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:768",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(768u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["res"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&res) as
&dyn Value))])
});
} else { ; }
};
res.unwrap_or(Res::Err)
}
}
}#[instrument(level = "trace", skip(self))]
762 fn lower_res(&mut self, res: Res<NodeId>) -> Res {
763 let res: Result<Res, ()> = res.apply_id(|id| {
764 let owner = self.current_hir_id_owner;
765 let local_id = self.ident_and_label_to_local_id.get(&id).copied().ok_or(())?;
766 Ok(HirId { owner, local_id })
767 });
768 trace!(?res);
769
770 res.unwrap_or(Res::Err)
776 }
777
778 fn expect_full_res(&mut self, id: NodeId) -> Res<NodeId> {
779 self.resolver.get_partial_res(id).map_or(Res::Err, |pr| pr.expect_full_res())
780 }
781
782 fn lower_import_res(&mut self, id: NodeId, span: Span) -> PerNS<Option<Res>> {
783 let per_ns = self.resolver.get_import_res(id);
784 let per_ns = per_ns.map(|res| res.map(|res| self.lower_res(res)));
785 if per_ns.is_empty() {
786 self.dcx().span_delayed_bug(span, "no resolution for an import");
788 let err = Some(Res::Err);
789 return PerNS { type_ns: err, value_ns: err, macro_ns: err };
790 }
791 per_ns
792 }
793
794 fn make_lang_item_qpath(
795 &mut self,
796 lang_item: hir::LangItem,
797 span: Span,
798 args: Option<&'hir hir::GenericArgs<'hir>>,
799 ) -> hir::QPath<'hir> {
800 hir::QPath::Resolved(None, self.make_lang_item_path(lang_item, span, args))
801 }
802
803 fn make_lang_item_path(
804 &mut self,
805 lang_item: hir::LangItem,
806 span: Span,
807 args: Option<&'hir hir::GenericArgs<'hir>>,
808 ) -> &'hir hir::Path<'hir> {
809 let def_id = self.tcx.require_lang_item(lang_item, span);
810 let def_kind = self.tcx.def_kind(def_id);
811 let res = Res::Def(def_kind, def_id);
812 self.arena.alloc(hir::Path {
813 span,
814 res,
815 segments: self.arena.alloc_from_iter([hir::PathSegment {
816 ident: Ident::new(lang_item.name(), span),
817 hir_id: self.next_id(),
818 res,
819 args,
820 infer_args: args.is_none(),
821 }]),
822 })
823 }
824
825 fn mark_span_with_reason(
828 &self,
829 reason: DesugaringKind,
830 span: Span,
831 allow_internal_unstable: Option<Arc<[Symbol]>>,
832 ) -> Span {
833 self.tcx.with_stable_hashing_context(|hcx| {
834 span.mark_with_reason(allow_internal_unstable, reason, span.edition(), hcx)
835 })
836 }
837
838 fn span_lowerer(&self) -> SpanLowerer {
839 SpanLowerer {
840 is_incremental: self.tcx.sess.opts.incremental.is_some(),
841 def_id: self.current_hir_id_owner.def_id,
842 }
843 }
844
845 fn lower_span(&self, span: Span) -> Span {
848 self.span_lowerer().lower(span)
849 }
850
851 fn lower_ident(&self, ident: Ident) -> Ident {
852 Ident::new(ident.name, self.lower_span(ident.span))
853 }
854
855 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lifetime_res_to_generic_param",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(856u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["ident", "node_id",
"res", "source"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&node_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Option<hir::GenericParam<'hir>> =
loop {};
return __tracing_attr_fake_return;
}
{
let (name, kind) =
match res {
LifetimeRes::Param { .. } => {
(hir::ParamName::Plain(ident),
hir::LifetimeParamKind::Explicit)
}
LifetimeRes::Fresh { param, kind, .. } => {
let _def_id =
self.create_def(param, Some(kw::UnderscoreLifetime),
DefKind::LifetimeParam,
DefPathData::DesugaredAnonymousLifetime, ident.span);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:877",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(877u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["_def_id"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&_def_id) as
&dyn Value))])
});
} else { ; }
};
(hir::ParamName::Fresh,
hir::LifetimeParamKind::Elided(kind))
}
LifetimeRes::Static { .. } | LifetimeRes::Error =>
return None,
res => {
::core::panicking::panic_fmt(format_args!("Unexpected lifetime resolution {0:?} for {1:?} at {2:?}",
res, ident, ident.span));
}
};
let hir_id = self.lower_node_id(node_id);
let def_id = self.local_def_id(node_id);
Some(hir::GenericParam {
hir_id,
def_id,
name,
span: self.lower_span(ident.span),
pure_wrt_drop: false,
kind: hir::GenericParamKind::Lifetime { kind },
colon_span: None,
source,
})
}
}
}#[instrument(level = "debug", skip(self))]
857 fn lifetime_res_to_generic_param(
858 &mut self,
859 ident: Ident,
860 node_id: NodeId,
861 res: LifetimeRes,
862 source: hir::GenericParamSource,
863 ) -> Option<hir::GenericParam<'hir>> {
864 let (name, kind) = match res {
865 LifetimeRes::Param { .. } => {
866 (hir::ParamName::Plain(ident), hir::LifetimeParamKind::Explicit)
867 }
868 LifetimeRes::Fresh { param, kind, .. } => {
869 let _def_id = self.create_def(
871 param,
872 Some(kw::UnderscoreLifetime),
873 DefKind::LifetimeParam,
874 DefPathData::DesugaredAnonymousLifetime,
875 ident.span,
876 );
877 debug!(?_def_id);
878
879 (hir::ParamName::Fresh, hir::LifetimeParamKind::Elided(kind))
880 }
881 LifetimeRes::Static { .. } | LifetimeRes::Error => return None,
882 res => panic!(
883 "Unexpected lifetime resolution {:?} for {:?} at {:?}",
884 res, ident, ident.span
885 ),
886 };
887 let hir_id = self.lower_node_id(node_id);
888 let def_id = self.local_def_id(node_id);
889 Some(hir::GenericParam {
890 hir_id,
891 def_id,
892 name,
893 span: self.lower_span(ident.span),
894 pure_wrt_drop: false,
895 kind: hir::GenericParamKind::Lifetime { kind },
896 colon_span: None,
897 source,
898 })
899 }
900
901 x;#[instrument(level = "debug", skip(self), ret)]
907 #[inline]
908 fn lower_lifetime_binder(
909 &mut self,
910 binder: NodeId,
911 generic_params: &[GenericParam],
912 ) -> &'hir [hir::GenericParam<'hir>] {
913 let extra_lifetimes = self.resolver.extra_lifetime_params(binder);
916 debug!(?extra_lifetimes);
917 let extra_lifetimes: Vec<_> = extra_lifetimes
918 .into_iter()
919 .filter_map(|(ident, node_id, res)| {
920 self.lifetime_res_to_generic_param(
921 ident,
922 node_id,
923 res,
924 hir::GenericParamSource::Binder,
925 )
926 })
927 .collect();
928 let arena = self.arena;
929 let explicit_generic_params =
930 self.lower_generic_params_mut(generic_params, hir::GenericParamSource::Binder);
931 arena.alloc_from_iter(explicit_generic_params.chain(extra_lifetimes.into_iter()))
932 }
933
934 fn with_dyn_type_scope<T>(&mut self, in_scope: bool, f: impl FnOnce(&mut Self) -> T) -> T {
935 let was_in_dyn_type = self.is_in_dyn_type;
936 self.is_in_dyn_type = in_scope;
937
938 let result = f(self);
939
940 self.is_in_dyn_type = was_in_dyn_type;
941
942 result
943 }
944
945 fn with_new_scopes<T>(&mut self, scope_span: Span, f: impl FnOnce(&mut Self) -> T) -> T {
946 let current_item = self.current_item;
947 self.current_item = Some(scope_span);
948
949 let was_in_loop_condition = self.is_in_loop_condition;
950 self.is_in_loop_condition = false;
951
952 let old_contract = self.contract_ensures.take();
953
954 let try_block_scope = mem::replace(&mut self.try_block_scope, TryBlockScope::Function);
955 let loop_scope = self.loop_scope.take();
956 let ret = f(self);
957 self.try_block_scope = try_block_scope;
958 self.loop_scope = loop_scope;
959
960 self.contract_ensures = old_contract;
961
962 self.is_in_loop_condition = was_in_loop_condition;
963
964 self.current_item = current_item;
965
966 ret
967 }
968
969 fn lower_attrs(
970 &mut self,
971 id: HirId,
972 attrs: &[Attribute],
973 target_span: Span,
974 target: Target,
975 ) -> &'hir [hir::Attribute] {
976 self.lower_attrs_with_extra(id, attrs, target_span, target, &[])
977 }
978
979 fn lower_attrs_with_extra(
980 &mut self,
981 id: HirId,
982 attrs: &[Attribute],
983 target_span: Span,
984 target: Target,
985 extra_hir_attributes: &[hir::Attribute],
986 ) -> &'hir [hir::Attribute] {
987 if attrs.is_empty() && extra_hir_attributes.is_empty() {
988 &[]
989 } else {
990 let mut lowered_attrs =
991 self.lower_attrs_vec(attrs, self.lower_span(target_span), id, target);
992 lowered_attrs.extend(extra_hir_attributes.iter().cloned());
993
994 match (&id.owner, &self.current_hir_id_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(id.owner, self.current_hir_id_owner);
995 let ret = self.arena.alloc_from_iter(lowered_attrs);
996
997 if ret.is_empty() {
1004 &[]
1005 } else {
1006 self.attrs.insert(id.local_id, ret);
1007 ret
1008 }
1009 }
1010 }
1011
1012 fn lower_attrs_vec(
1013 &mut self,
1014 attrs: &[Attribute],
1015 target_span: Span,
1016 target_hir_id: HirId,
1017 target: Target,
1018 ) -> Vec<hir::Attribute> {
1019 let l = self.span_lowerer();
1020 self.attribute_parser.parse_attribute_list(
1021 attrs,
1022 target_span,
1023 target_hir_id,
1024 target,
1025 OmitDoc::Lower,
1026 |s| l.lower(s),
1027 |l| {
1028 self.delayed_lints.push(DelayedLint::AttributeParsing(l));
1029 },
1030 )
1031 }
1032
1033 fn alias_attrs(&mut self, id: HirId, target_id: HirId) {
1034 match (&id.owner, &self.current_hir_id_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(id.owner, self.current_hir_id_owner);
1035 match (&target_id.owner, &self.current_hir_id_owner) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(target_id.owner, self.current_hir_id_owner);
1036 if let Some(&a) = self.attrs.get(&target_id.local_id) {
1037 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
1038 self.attrs.insert(id.local_id, a);
1039 }
1040 }
1041
1042 fn lower_delim_args(&self, args: &DelimArgs) -> DelimArgs {
1043 args.clone()
1044 }
1045
1046 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_assoc_item_constraint",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1047u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::AssocItemConstraint<'hir> =
loop {};
return __tracing_attr_fake_return;
}
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:1053",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1053u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["constraint",
"itctx"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&constraint)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&itctx) as
&dyn Value))])
});
} else { ; }
};
let gen_args =
if let Some(gen_args) = &constraint.gen_args {
let gen_args_ctor =
match gen_args {
GenericArgs::AngleBracketed(data) => {
self.lower_angle_bracketed_parameter_data(data,
ParamMode::Explicit, itctx).0
}
GenericArgs::Parenthesized(data) => {
if let Some(first_char) =
constraint.ident.as_str().chars().next() &&
first_char.is_ascii_lowercase() {
let err =
match (&data.inputs[..], &data.output) {
([_, ..], FnRetTy::Default(_)) => {
errors::BadReturnTypeNotation::Inputs {
span: data.inputs_span,
}
}
([], FnRetTy::Default(_)) => {
errors::BadReturnTypeNotation::NeedsDots {
span: data.inputs_span,
}
}
(_, FnRetTy::Ty(ty)) => {
let span = data.inputs_span.shrink_to_hi().to(ty.span);
errors::BadReturnTypeNotation::Output {
span,
suggestion: errors::RTNSuggestion {
output: span,
input: data.inputs_span,
},
}
}
};
let mut err = self.dcx().create_err(err);
if !self.tcx.features().return_type_notation() &&
self.tcx.sess.is_nightly_build() {
add_feature_diagnostics(&mut err, &self.tcx.sess,
sym::return_type_notation);
}
err.emit();
GenericArgsCtor {
args: Default::default(),
constraints: &[],
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
span: data.span,
}
} else {
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
self.lower_angle_bracketed_parameter_data(&data.as_angle_bracketed_args(),
ParamMode::Explicit, itctx).0
}
}
GenericArgs::ParenthesizedElided(span) =>
GenericArgsCtor {
args: Default::default(),
constraints: &[],
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
span: *span,
},
};
gen_args_ctor.into_generic_args(self)
} else { self.arena.alloc(hir::GenericArgs::none()) };
let kind =
match &constraint.kind {
AssocItemConstraintKind::Equality { term } => {
let term =
match term {
Term::Ty(ty) => self.lower_ty(ty, itctx).into(),
Term::Const(c) =>
self.lower_anon_const_to_const_arg(c).into(),
};
hir::AssocItemConstraintKind::Equality { term }
}
AssocItemConstraintKind::Bound { bounds } => {
if self.is_in_dyn_type {
let suggestion =
match itctx {
ImplTraitContext::OpaqueTy { .. } |
ImplTraitContext::Universal => {
let bound_end_span =
constraint.gen_args.as_ref().map_or(constraint.ident.span,
|args| args.span());
if bound_end_span.eq_ctxt(constraint.span) {
Some(self.tcx.sess.source_map().next_point(bound_end_span))
} else { None }
}
_ => None,
};
let guar =
self.dcx().emit_err(errors::MisplacedAssocTyBinding {
span: constraint.span,
suggestion,
});
let err_ty =
&*self.arena.alloc(self.ty(constraint.span,
hir::TyKind::Err(guar)));
hir::AssocItemConstraintKind::Equality {
term: err_ty.into(),
}
} else {
let bounds =
self.lower_param_bounds(bounds,
RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::AssocTyBounds),
itctx);
hir::AssocItemConstraintKind::Bound { bounds }
}
}
};
hir::AssocItemConstraint {
hir_id: self.lower_node_id(constraint.id),
ident: self.lower_ident(constraint.ident),
gen_args,
kind,
span: self.lower_span(constraint.span),
}
}
}
}#[instrument(level = "debug", skip_all)]
1048 fn lower_assoc_item_constraint(
1049 &mut self,
1050 constraint: &AssocItemConstraint,
1051 itctx: ImplTraitContext,
1052 ) -> hir::AssocItemConstraint<'hir> {
1053 debug!(?constraint, ?itctx);
1054 let gen_args = if let Some(gen_args) = &constraint.gen_args {
1056 let gen_args_ctor = match gen_args {
1057 GenericArgs::AngleBracketed(data) => {
1058 self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
1059 }
1060 GenericArgs::Parenthesized(data) => {
1061 if let Some(first_char) = constraint.ident.as_str().chars().next()
1062 && first_char.is_ascii_lowercase()
1063 {
1064 let err = match (&data.inputs[..], &data.output) {
1065 ([_, ..], FnRetTy::Default(_)) => {
1066 errors::BadReturnTypeNotation::Inputs { span: data.inputs_span }
1067 }
1068 ([], FnRetTy::Default(_)) => {
1069 errors::BadReturnTypeNotation::NeedsDots { span: data.inputs_span }
1070 }
1071 (_, FnRetTy::Ty(ty)) => {
1073 let span = data.inputs_span.shrink_to_hi().to(ty.span);
1074 errors::BadReturnTypeNotation::Output {
1075 span,
1076 suggestion: errors::RTNSuggestion {
1077 output: span,
1078 input: data.inputs_span,
1079 },
1080 }
1081 }
1082 };
1083 let mut err = self.dcx().create_err(err);
1084 if !self.tcx.features().return_type_notation()
1085 && self.tcx.sess.is_nightly_build()
1086 {
1087 add_feature_diagnostics(
1088 &mut err,
1089 &self.tcx.sess,
1090 sym::return_type_notation,
1091 );
1092 }
1093 err.emit();
1094 GenericArgsCtor {
1095 args: Default::default(),
1096 constraints: &[],
1097 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1098 span: data.span,
1099 }
1100 } else {
1101 self.emit_bad_parenthesized_trait_in_assoc_ty(data);
1102 self.lower_angle_bracketed_parameter_data(
1105 &data.as_angle_bracketed_args(),
1106 ParamMode::Explicit,
1107 itctx,
1108 )
1109 .0
1110 }
1111 }
1112 GenericArgs::ParenthesizedElided(span) => GenericArgsCtor {
1113 args: Default::default(),
1114 constraints: &[],
1115 parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1116 span: *span,
1117 },
1118 };
1119 gen_args_ctor.into_generic_args(self)
1120 } else {
1121 self.arena.alloc(hir::GenericArgs::none())
1122 };
1123 let kind = match &constraint.kind {
1124 AssocItemConstraintKind::Equality { term } => {
1125 let term = match term {
1126 Term::Ty(ty) => self.lower_ty(ty, itctx).into(),
1127 Term::Const(c) => self.lower_anon_const_to_const_arg(c).into(),
1128 };
1129 hir::AssocItemConstraintKind::Equality { term }
1130 }
1131 AssocItemConstraintKind::Bound { bounds } => {
1132 if self.is_in_dyn_type {
1134 let suggestion = match itctx {
1135 ImplTraitContext::OpaqueTy { .. } | ImplTraitContext::Universal => {
1136 let bound_end_span = constraint
1137 .gen_args
1138 .as_ref()
1139 .map_or(constraint.ident.span, |args| args.span());
1140 if bound_end_span.eq_ctxt(constraint.span) {
1141 Some(self.tcx.sess.source_map().next_point(bound_end_span))
1142 } else {
1143 None
1144 }
1145 }
1146 _ => None,
1147 };
1148
1149 let guar = self.dcx().emit_err(errors::MisplacedAssocTyBinding {
1150 span: constraint.span,
1151 suggestion,
1152 });
1153 let err_ty =
1154 &*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar)));
1155 hir::AssocItemConstraintKind::Equality { term: err_ty.into() }
1156 } else {
1157 let bounds = self.lower_param_bounds(
1158 bounds,
1159 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::AssocTyBounds),
1160 itctx,
1161 );
1162 hir::AssocItemConstraintKind::Bound { bounds }
1163 }
1164 }
1165 };
1166
1167 hir::AssocItemConstraint {
1168 hir_id: self.lower_node_id(constraint.id),
1169 ident: self.lower_ident(constraint.ident),
1170 gen_args,
1171 kind,
1172 span: self.lower_span(constraint.span),
1173 }
1174 }
1175
1176 fn emit_bad_parenthesized_trait_in_assoc_ty(&self, data: &ParenthesizedArgs) {
1177 let sub = if data.inputs.is_empty() {
1179 let parentheses_span =
1180 data.inputs_span.shrink_to_lo().to(data.inputs_span.shrink_to_hi());
1181 AssocTyParenthesesSub::Empty { parentheses_span }
1182 }
1183 else {
1185 let open_param = data.inputs_span.shrink_to_lo().to(data
1187 .inputs
1188 .first()
1189 .unwrap()
1190 .span
1191 .shrink_to_lo());
1192 let close_param =
1194 data.inputs.last().unwrap().span.shrink_to_hi().to(data.inputs_span.shrink_to_hi());
1195 AssocTyParenthesesSub::NotEmpty { open_param, close_param }
1196 };
1197 self.dcx().emit_err(AssocTyParentheses { span: data.span, sub });
1198 }
1199
1200 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_generic_arg",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1200u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["arg", "itctx"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&arg)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::GenericArg<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
match arg {
ast::GenericArg::Lifetime(lt) =>
GenericArg::Lifetime(self.lower_lifetime(lt,
LifetimeSource::Path {
angle_brackets: hir::AngleBrackets::Full,
}, lt.ident.into())),
ast::GenericArg::Type(ty) => {
if ty.is_maybe_parenthesised_infer() {
return GenericArg::Infer(hir::InferArg {
hir_id: self.lower_node_id(ty.id),
span: self.lower_span(ty.span),
});
}
match &ty.kind {
TyKind::Path(None, path) => {
if let Some(res) =
self.resolver.get_partial_res(ty.id).and_then(|partial_res|
partial_res.full_res()) {
if !res.matches_ns(Namespace::TypeNS) &&
path.is_potential_trivial_const_arg() {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:1238",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1238u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("lower_generic_arg: Lowering type argument as const argument: {0:?}",
ty) as &dyn Value))])
});
} else { ; }
};
let ct =
self.lower_const_path_to_const_arg(path, res, ty.id,
ty.span);
return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
}
}
}
_ => {}
}
GenericArg::Type(self.lower_ty(ty,
itctx).try_as_ambig_ty().unwrap())
}
ast::GenericArg::Const(ct) => {
GenericArg::Const(self.lower_anon_const_to_const_arg(ct).try_as_ambig_ct().unwrap())
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1201 fn lower_generic_arg(
1202 &mut self,
1203 arg: &ast::GenericArg,
1204 itctx: ImplTraitContext,
1205 ) -> hir::GenericArg<'hir> {
1206 match arg {
1207 ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(
1208 lt,
1209 LifetimeSource::Path { angle_brackets: hir::AngleBrackets::Full },
1210 lt.ident.into(),
1211 )),
1212 ast::GenericArg::Type(ty) => {
1213 if ty.is_maybe_parenthesised_infer() {
1216 return GenericArg::Infer(hir::InferArg {
1217 hir_id: self.lower_node_id(ty.id),
1218 span: self.lower_span(ty.span),
1219 });
1220 }
1221
1222 match &ty.kind {
1223 TyKind::Path(None, path) => {
1230 if let Some(res) = self
1231 .resolver
1232 .get_partial_res(ty.id)
1233 .and_then(|partial_res| partial_res.full_res())
1234 {
1235 if !res.matches_ns(Namespace::TypeNS)
1236 && path.is_potential_trivial_const_arg()
1237 {
1238 debug!(
1239 "lower_generic_arg: Lowering type argument as const argument: {:?}",
1240 ty,
1241 );
1242
1243 let ct =
1244 self.lower_const_path_to_const_arg(path, res, ty.id, ty.span);
1245 return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
1246 }
1247 }
1248 }
1249 _ => {}
1250 }
1251 GenericArg::Type(self.lower_ty(ty, itctx).try_as_ambig_ty().unwrap())
1252 }
1253 ast::GenericArg::Const(ct) => {
1254 GenericArg::Const(self.lower_anon_const_to_const_arg(ct).try_as_ambig_ct().unwrap())
1255 }
1256 }
1257 }
1258
1259 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_ty",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1259u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["t", "itctx"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&t)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: &'hir hir::Ty<'hir> = loop {};
return __tracing_attr_fake_return;
}
{ self.arena.alloc(self.lower_ty_direct(t, itctx)) }
}
}#[instrument(level = "debug", skip(self))]
1260 fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext) -> &'hir hir::Ty<'hir> {
1261 self.arena.alloc(self.lower_ty_direct(t, itctx))
1262 }
1263
1264 fn lower_path_ty(
1265 &mut self,
1266 t: &Ty,
1267 qself: &Option<Box<QSelf>>,
1268 path: &Path,
1269 param_mode: ParamMode,
1270 itctx: ImplTraitContext,
1271 ) -> hir::Ty<'hir> {
1272 if qself.is_none()
1278 && let Some(partial_res) = self.resolver.get_partial_res(t.id)
1279 && let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res()
1280 {
1281 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1282 let bound = this.lower_poly_trait_ref(
1283 &PolyTraitRef {
1284 bound_generic_params: ThinVec::new(),
1285 modifiers: TraitBoundModifiers::NONE,
1286 trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
1287 span: t.span,
1288 parens: ast::Parens::No,
1289 },
1290 RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::TraitObjectTy),
1291 itctx,
1292 );
1293 let bounds = this.arena.alloc_from_iter([bound]);
1294 let lifetime_bound = this.elided_dyn_bound(t.span);
1295 (bounds, lifetime_bound)
1296 });
1297 let kind = hir::TyKind::TraitObject(
1298 bounds,
1299 TaggedRef::new(lifetime_bound, TraitObjectSyntax::None),
1300 );
1301 return hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.next_id() };
1302 }
1303
1304 let id = self.lower_node_id(t.id);
1305 let qpath = self.lower_qpath(
1306 t.id,
1307 qself,
1308 path,
1309 param_mode,
1310 AllowReturnTypeNotation::Yes,
1311 itctx,
1312 None,
1313 );
1314 self.ty_path(id, t.span, qpath)
1315 }
1316
1317 fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> {
1318 hir::Ty { hir_id: self.next_id(), kind, span: self.lower_span(span) }
1319 }
1320
1321 fn ty_tup(&mut self, span: Span, tys: &'hir [hir::Ty<'hir>]) -> hir::Ty<'hir> {
1322 self.ty(span, hir::TyKind::Tup(tys))
1323 }
1324
1325 fn lower_ty_direct(&mut self, t: &Ty, itctx: ImplTraitContext) -> hir::Ty<'hir> {
1326 let kind = match &t.kind {
1327 TyKind::Infer => hir::TyKind::Infer(()),
1328 TyKind::Err(guar) => hir::TyKind::Err(*guar),
1329 TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
1330 TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
1331 TyKind::Ref(region, mt) => {
1332 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1333 hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx))
1334 }
1335 TyKind::PinnedRef(region, mt) => {
1336 let lifetime = self.lower_ty_direct_lifetime(t, *region);
1337 let kind = hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx));
1338 let span = self.lower_span(t.span);
1339 let arg = hir::Ty { kind, span, hir_id: self.next_id() };
1340 let args = self.arena.alloc(hir::GenericArgs {
1341 args: self.arena.alloc([hir::GenericArg::Type(self.arena.alloc(arg))]),
1342 constraints: &[],
1343 parenthesized: hir::GenericArgsParentheses::No,
1344 span_ext: span,
1345 });
1346 let path = self.make_lang_item_qpath(hir::LangItem::Pin, span, Some(args));
1347 hir::TyKind::Path(path)
1348 }
1349 TyKind::FnPtr(f) => {
1350 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1351 hir::TyKind::FnPtr(self.arena.alloc(hir::FnPtrTy {
1352 generic_params,
1353 safety: self.lower_safety(f.safety, hir::Safety::Safe),
1354 abi: self.lower_extern(f.ext),
1355 decl: self.lower_fn_decl(&f.decl, t.id, t.span, FnDeclKind::Pointer, None),
1356 param_idents: self.lower_fn_params_to_idents(&f.decl),
1357 }))
1358 }
1359 TyKind::UnsafeBinder(f) => {
1360 let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
1361 hir::TyKind::UnsafeBinder(self.arena.alloc(hir::UnsafeBinderTy {
1362 generic_params,
1363 inner_ty: self.lower_ty(&f.inner_ty, itctx),
1364 }))
1365 }
1366 TyKind::Never => hir::TyKind::Never,
1367 TyKind::Tup(tys) => hir::TyKind::Tup(
1368 self.arena.alloc_from_iter(tys.iter().map(|ty| self.lower_ty_direct(ty, itctx))),
1369 ),
1370 TyKind::Paren(ty) => {
1371 return self.lower_ty_direct(ty, itctx);
1372 }
1373 TyKind::Path(qself, path) => {
1374 return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
1375 }
1376 TyKind::ImplicitSelf => {
1377 let hir_id = self.next_id();
1378 let res = self.expect_full_res(t.id);
1379 let res = self.lower_res(res);
1380 hir::TyKind::Path(hir::QPath::Resolved(
1381 None,
1382 self.arena.alloc(hir::Path {
1383 res,
1384 segments: self.arena.alloc_from_iter([hir::PathSegment::new(Ident::with_dummy_span(kw::SelfUpper),
hir_id, res)])arena_vec![self; hir::PathSegment::new(
1385 Ident::with_dummy_span(kw::SelfUpper),
1386 hir_id,
1387 res
1388 )],
1389 span: self.lower_span(t.span),
1390 }),
1391 ))
1392 }
1393 TyKind::Array(ty, length) => hir::TyKind::Array(
1394 self.lower_ty(ty, itctx),
1395 self.lower_array_length_to_const_arg(length),
1396 ),
1397 TyKind::TraitObject(bounds, kind) => {
1398 let mut lifetime_bound = None;
1399 let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1400 let bounds =
1401 this.arena.alloc_from_iter(bounds.iter().filter_map(|bound| match bound {
1402 GenericBound::Trait(ty) => {
1406 let trait_ref = this.lower_poly_trait_ref(
1407 ty,
1408 RelaxedBoundPolicy::Forbidden(
1409 RelaxedBoundForbiddenReason::TraitObjectTy,
1410 ),
1411 itctx,
1412 );
1413 Some(trait_ref)
1414 }
1415 GenericBound::Outlives(lifetime) => {
1416 if lifetime_bound.is_none() {
1417 lifetime_bound = Some(this.lower_lifetime(
1418 lifetime,
1419 LifetimeSource::Other,
1420 lifetime.ident.into(),
1421 ));
1422 }
1423 None
1424 }
1425 GenericBound::Use(_, span) => {
1427 this.dcx()
1428 .span_delayed_bug(*span, "use<> not allowed in dyn types");
1429 None
1430 }
1431 }));
1432 let lifetime_bound =
1433 lifetime_bound.unwrap_or_else(|| this.elided_dyn_bound(t.span));
1434 (bounds, lifetime_bound)
1435 });
1436 hir::TyKind::TraitObject(bounds, TaggedRef::new(lifetime_bound, *kind))
1437 }
1438 TyKind::ImplTrait(def_node_id, bounds) => {
1439 let span = t.span;
1440 match itctx {
1441 ImplTraitContext::OpaqueTy { origin } => {
1442 self.lower_opaque_impl_trait(span, origin, *def_node_id, bounds, itctx)
1443 }
1444 ImplTraitContext::Universal => {
1445 if let Some(span) = bounds.iter().find_map(|bound| match *bound {
1446 ast::GenericBound::Use(_, span) => Some(span),
1447 _ => None,
1448 }) {
1449 self.tcx.dcx().emit_err(errors::NoPreciseCapturesOnApit { span });
1450 }
1451
1452 let def_id = self.local_def_id(*def_node_id);
1453 let name = self.tcx.item_name(def_id.to_def_id());
1454 let ident = Ident::new(name, span);
1455 let (param, bounds, path) = self.lower_universal_param_and_bounds(
1456 *def_node_id,
1457 span,
1458 ident,
1459 bounds,
1460 );
1461 self.impl_trait_defs.push(param);
1462 if let Some(bounds) = bounds {
1463 self.impl_trait_bounds.push(bounds);
1464 }
1465 path
1466 }
1467 ImplTraitContext::InBinding => hir::TyKind::TraitAscription(
1468 self.lower_param_bounds(bounds, RelaxedBoundPolicy::Allowed, itctx),
1469 ),
1470 ImplTraitContext::FeatureGated(position, feature) => {
1471 let guar = self
1472 .tcx
1473 .sess
1474 .create_feature_err(
1475 MisplacedImplTrait {
1476 span: t.span,
1477 position: DiagArgFromDisplay(&position),
1478 },
1479 feature,
1480 )
1481 .emit();
1482 hir::TyKind::Err(guar)
1483 }
1484 ImplTraitContext::Disallowed(position) => {
1485 let guar = self.dcx().emit_err(MisplacedImplTrait {
1486 span: t.span,
1487 position: DiagArgFromDisplay(&position),
1488 });
1489 hir::TyKind::Err(guar)
1490 }
1491 }
1492 }
1493 TyKind::Pat(ty, pat) => {
1494 hir::TyKind::Pat(self.lower_ty(ty, itctx), self.lower_ty_pat(pat, ty.span))
1495 }
1496 TyKind::MacCall(_) => {
1497 ::rustc_middle::util::bug::span_bug_fmt(t.span,
format_args!("`TyKind::MacCall` should have been expanded by now"))span_bug!(t.span, "`TyKind::MacCall` should have been expanded by now")
1498 }
1499 TyKind::CVarArgs => {
1500 let guar = self.dcx().span_delayed_bug(
1501 t.span,
1502 "`TyKind::CVarArgs` should have been handled elsewhere",
1503 );
1504 hir::TyKind::Err(guar)
1505 }
1506 TyKind::Dummy => {
::core::panicking::panic_fmt(format_args!("`TyKind::Dummy` should never be lowered"));
}panic!("`TyKind::Dummy` should never be lowered"),
1507 };
1508
1509 hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
1510 }
1511
1512 fn lower_ty_direct_lifetime(
1513 &mut self,
1514 t: &Ty,
1515 region: Option<Lifetime>,
1516 ) -> &'hir hir::Lifetime {
1517 let (region, syntax) = match region {
1518 Some(region) => (region, region.ident.into()),
1519
1520 None => {
1521 let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1522 self.resolver.get_lifetime_res(t.id)
1523 {
1524 match (&start.plus(1), &end) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(start.plus(1), end);
1525 start
1526 } else {
1527 self.next_node_id()
1528 };
1529 let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
1530 let region = Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id };
1531 (region, LifetimeSyntax::Implicit)
1532 }
1533 };
1534 self.lower_lifetime(®ion, LifetimeSource::Reference, syntax)
1535 }
1536
1537 x;#[instrument(level = "debug", skip(self), ret)]
1569 fn lower_opaque_impl_trait(
1570 &mut self,
1571 span: Span,
1572 origin: hir::OpaqueTyOrigin<LocalDefId>,
1573 opaque_ty_node_id: NodeId,
1574 bounds: &GenericBounds,
1575 itctx: ImplTraitContext,
1576 ) -> hir::TyKind<'hir> {
1577 let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
1583
1584 self.lower_opaque_inner(opaque_ty_node_id, origin, opaque_ty_span, |this| {
1585 this.lower_param_bounds(bounds, RelaxedBoundPolicy::Allowed, itctx)
1586 })
1587 }
1588
1589 fn lower_opaque_inner(
1590 &mut self,
1591 opaque_ty_node_id: NodeId,
1592 origin: hir::OpaqueTyOrigin<LocalDefId>,
1593 opaque_ty_span: Span,
1594 lower_item_bounds: impl FnOnce(&mut Self) -> &'hir [hir::GenericBound<'hir>],
1595 ) -> hir::TyKind<'hir> {
1596 let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
1597 let opaque_ty_hir_id = self.lower_node_id(opaque_ty_node_id);
1598 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:1598",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1598u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["opaque_ty_def_id",
"opaque_ty_hir_id"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&opaque_ty_def_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&opaque_ty_hir_id)
as &dyn Value))])
});
} else { ; }
};debug!(?opaque_ty_def_id, ?opaque_ty_hir_id);
1599
1600 let bounds = lower_item_bounds(self);
1601 let opaque_ty_def = hir::OpaqueTy {
1602 hir_id: opaque_ty_hir_id,
1603 def_id: opaque_ty_def_id,
1604 bounds,
1605 origin,
1606 span: self.lower_span(opaque_ty_span),
1607 };
1608 let opaque_ty_def = self.arena.alloc(opaque_ty_def);
1609
1610 hir::TyKind::OpaqueDef(opaque_ty_def)
1611 }
1612
1613 fn lower_precise_capturing_args(
1614 &mut self,
1615 precise_capturing_args: &[PreciseCapturingArg],
1616 ) -> &'hir [hir::PreciseCapturingArg<'hir>] {
1617 self.arena.alloc_from_iter(precise_capturing_args.iter().map(|arg| match arg {
1618 PreciseCapturingArg::Lifetime(lt) => hir::PreciseCapturingArg::Lifetime(
1619 self.lower_lifetime(lt, LifetimeSource::PreciseCapturing, lt.ident.into()),
1620 ),
1621 PreciseCapturingArg::Arg(path, id) => {
1622 let [segment] = path.segments.as_slice() else {
1623 ::core::panicking::panic("explicit panic");panic!();
1624 };
1625 let res = self.resolver.get_partial_res(*id).map_or(Res::Err, |partial_res| {
1626 partial_res.full_res().expect("no partial res expected for precise capture arg")
1627 });
1628 hir::PreciseCapturingArg::Param(hir::PreciseCapturingNonLifetimeArg {
1629 hir_id: self.lower_node_id(*id),
1630 ident: self.lower_ident(segment.ident),
1631 res: self.lower_res(res),
1632 })
1633 }
1634 }))
1635 }
1636
1637 fn lower_fn_params_to_idents(&mut self, decl: &FnDecl) -> &'hir [Option<Ident>] {
1638 self.arena.alloc_from_iter(decl.inputs.iter().map(|param| match param.pat.kind {
1639 PatKind::Missing => None,
1640 PatKind::Ident(_, ident, _) => Some(self.lower_ident(ident)),
1641 PatKind::Wild => Some(Ident::new(kw::Underscore, self.lower_span(param.pat.span))),
1642 _ => {
1643 self.dcx().span_delayed_bug(
1644 param.pat.span,
1645 "non-missing/ident/wild param pat must trigger an error",
1646 );
1647 None
1648 }
1649 }))
1650 }
1651
1652 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_fn_decl",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1661u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["decl", "fn_node_id",
"fn_span", "kind", "coro"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&decl)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_node_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_span)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&coro)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: &'hir hir::FnDecl<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let c_variadic = decl.c_variadic();
let mut inputs = &decl.inputs[..];
if c_variadic { inputs = &inputs[..inputs.len() - 1]; }
let inputs =
self.arena.alloc_from_iter(inputs.iter().map(|param|
{
let itctx =
match kind {
FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl |
FnDeclKind::Trait => {
ImplTraitContext::Universal
}
FnDeclKind::ExternFn => {
ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnParam)
}
FnDeclKind::Closure => {
ImplTraitContext::Disallowed(ImplTraitPosition::ClosureParam)
}
FnDeclKind::Pointer => {
ImplTraitContext::Disallowed(ImplTraitPosition::PointerParam)
}
};
self.lower_ty_direct(¶m.ty, itctx)
}));
let output =
match coro {
Some(coro) => {
let fn_def_id = self.local_def_id(fn_node_id);
self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id,
coro, kind)
}
None =>
match &decl.output {
FnRetTy::Ty(ty) => {
let itctx =
match kind {
FnDeclKind::Fn | FnDeclKind::Inherent =>
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: self.local_def_id(fn_node_id),
in_trait_or_impl: None,
},
},
FnDeclKind::Trait =>
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: self.local_def_id(fn_node_id),
in_trait_or_impl: Some(hir::RpitContext::Trait),
},
},
FnDeclKind::Impl =>
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: self.local_def_id(fn_node_id),
in_trait_or_impl: Some(hir::RpitContext::TraitImpl),
},
},
FnDeclKind::ExternFn => {
ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnReturn)
}
FnDeclKind::Closure => {
ImplTraitContext::Disallowed(ImplTraitPosition::ClosureReturn)
}
FnDeclKind::Pointer => {
ImplTraitContext::Disallowed(ImplTraitPosition::PointerReturn)
}
};
hir::FnRetTy::Return(self.lower_ty(ty, itctx))
}
FnRetTy::Default(span) =>
hir::FnRetTy::DefaultReturn(self.lower_span(*span)),
},
};
self.arena.alloc(hir::FnDecl {
inputs,
output,
c_variadic,
lifetime_elision_allowed: self.resolver.lifetime_elision_allowed.contains(&fn_node_id),
implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None,
|arg|
{
let is_mutable_pat =
#[allow(non_exhaustive_omitted_patterns)] match arg.pat.kind
{
PatKind::Ident(hir::BindingMode(_, Mutability::Mut), ..) =>
true,
_ => false,
};
match &arg.ty.kind {
TyKind::ImplicitSelf if is_mutable_pat =>
hir::ImplicitSelfKind::Mut,
TyKind::ImplicitSelf => hir::ImplicitSelfKind::Imm,
TyKind::Ref(_, mt) | TyKind::PinnedRef(_, mt) if
mt.ty.kind.is_implicit_self() => {
match mt.mutbl {
hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
}
}
_ => hir::ImplicitSelfKind::None,
}
}),
})
}
}
}#[instrument(level = "debug", skip(self))]
1662 fn lower_fn_decl(
1663 &mut self,
1664 decl: &FnDecl,
1665 fn_node_id: NodeId,
1666 fn_span: Span,
1667 kind: FnDeclKind,
1668 coro: Option<CoroutineKind>,
1669 ) -> &'hir hir::FnDecl<'hir> {
1670 let c_variadic = decl.c_variadic();
1671
1672 let mut inputs = &decl.inputs[..];
1676 if c_variadic {
1677 inputs = &inputs[..inputs.len() - 1];
1678 }
1679 let inputs = self.arena.alloc_from_iter(inputs.iter().map(|param| {
1680 let itctx = match kind {
1681 FnDeclKind::Fn | FnDeclKind::Inherent | FnDeclKind::Impl | FnDeclKind::Trait => {
1682 ImplTraitContext::Universal
1683 }
1684 FnDeclKind::ExternFn => {
1685 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnParam)
1686 }
1687 FnDeclKind::Closure => {
1688 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureParam)
1689 }
1690 FnDeclKind::Pointer => {
1691 ImplTraitContext::Disallowed(ImplTraitPosition::PointerParam)
1692 }
1693 };
1694 self.lower_ty_direct(¶m.ty, itctx)
1695 }));
1696
1697 let output = match coro {
1698 Some(coro) => {
1699 let fn_def_id = self.local_def_id(fn_node_id);
1700 self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind)
1701 }
1702 None => match &decl.output {
1703 FnRetTy::Ty(ty) => {
1704 let itctx = match kind {
1705 FnDeclKind::Fn | FnDeclKind::Inherent => ImplTraitContext::OpaqueTy {
1706 origin: hir::OpaqueTyOrigin::FnReturn {
1707 parent: self.local_def_id(fn_node_id),
1708 in_trait_or_impl: None,
1709 },
1710 },
1711 FnDeclKind::Trait => ImplTraitContext::OpaqueTy {
1712 origin: hir::OpaqueTyOrigin::FnReturn {
1713 parent: self.local_def_id(fn_node_id),
1714 in_trait_or_impl: Some(hir::RpitContext::Trait),
1715 },
1716 },
1717 FnDeclKind::Impl => ImplTraitContext::OpaqueTy {
1718 origin: hir::OpaqueTyOrigin::FnReturn {
1719 parent: self.local_def_id(fn_node_id),
1720 in_trait_or_impl: Some(hir::RpitContext::TraitImpl),
1721 },
1722 },
1723 FnDeclKind::ExternFn => {
1724 ImplTraitContext::Disallowed(ImplTraitPosition::ExternFnReturn)
1725 }
1726 FnDeclKind::Closure => {
1727 ImplTraitContext::Disallowed(ImplTraitPosition::ClosureReturn)
1728 }
1729 FnDeclKind::Pointer => {
1730 ImplTraitContext::Disallowed(ImplTraitPosition::PointerReturn)
1731 }
1732 };
1733 hir::FnRetTy::Return(self.lower_ty(ty, itctx))
1734 }
1735 FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(*span)),
1736 },
1737 };
1738
1739 self.arena.alloc(hir::FnDecl {
1740 inputs,
1741 output,
1742 c_variadic,
1743 lifetime_elision_allowed: self.resolver.lifetime_elision_allowed.contains(&fn_node_id),
1744 implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
1745 let is_mutable_pat = matches!(
1746 arg.pat.kind,
1747 PatKind::Ident(hir::BindingMode(_, Mutability::Mut), ..)
1748 );
1749
1750 match &arg.ty.kind {
1751 TyKind::ImplicitSelf if is_mutable_pat => hir::ImplicitSelfKind::Mut,
1752 TyKind::ImplicitSelf => hir::ImplicitSelfKind::Imm,
1753 TyKind::Ref(_, mt) | TyKind::PinnedRef(_, mt)
1757 if mt.ty.kind.is_implicit_self() =>
1758 {
1759 match mt.mutbl {
1760 hir::Mutability::Not => hir::ImplicitSelfKind::RefImm,
1761 hir::Mutability::Mut => hir::ImplicitSelfKind::RefMut,
1762 }
1763 }
1764 _ => hir::ImplicitSelfKind::None,
1765 }
1766 }),
1767 })
1768 }
1769
1770 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_coroutine_fn_ret_ty",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1778u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["output",
"fn_def_id", "coro", "fn_kind"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&output)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_def_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&coro)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_kind)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::FnRetTy<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let span = self.lower_span(output.span());
let (opaque_ty_node_id, allowed_features) =
match coro {
CoroutineKind::Async { return_impl_trait_id, .. } =>
(return_impl_trait_id, None),
CoroutineKind::Gen { return_impl_trait_id, .. } =>
(return_impl_trait_id, None),
CoroutineKind::AsyncGen { return_impl_trait_id, .. } => {
(return_impl_trait_id,
Some(Arc::clone(&self.allow_async_iterator)))
}
};
let opaque_ty_span =
self.mark_span_with_reason(DesugaringKind::Async, span,
allowed_features);
let in_trait_or_impl =
match fn_kind {
FnDeclKind::Trait => Some(hir::RpitContext::Trait),
FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
FnDeclKind::Fn | FnDeclKind::Inherent => None,
FnDeclKind::ExternFn | FnDeclKind::Closure |
FnDeclKind::Pointer =>
::core::panicking::panic("internal error: entered unreachable code"),
};
let opaque_ty_ref =
self.lower_opaque_inner(opaque_ty_node_id,
hir::OpaqueTyOrigin::AsyncFn {
parent: fn_def_id,
in_trait_or_impl,
}, opaque_ty_span,
|this|
{
let bound =
this.lower_coroutine_fn_output_type_to_bound(output, coro,
opaque_ty_span,
ImplTraitContext::OpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn {
parent: fn_def_id,
in_trait_or_impl,
},
});
this.arena.alloc_from_iter([bound])
});
let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
}
}
}#[instrument(level = "debug", skip(self))]
1779 fn lower_coroutine_fn_ret_ty(
1780 &mut self,
1781 output: &FnRetTy,
1782 fn_def_id: LocalDefId,
1783 coro: CoroutineKind,
1784 fn_kind: FnDeclKind,
1785 ) -> hir::FnRetTy<'hir> {
1786 let span = self.lower_span(output.span());
1787
1788 let (opaque_ty_node_id, allowed_features) = match coro {
1789 CoroutineKind::Async { return_impl_trait_id, .. } => (return_impl_trait_id, None),
1790 CoroutineKind::Gen { return_impl_trait_id, .. } => (return_impl_trait_id, None),
1791 CoroutineKind::AsyncGen { return_impl_trait_id, .. } => {
1792 (return_impl_trait_id, Some(Arc::clone(&self.allow_async_iterator)))
1793 }
1794 };
1795
1796 let opaque_ty_span =
1797 self.mark_span_with_reason(DesugaringKind::Async, span, allowed_features);
1798
1799 let in_trait_or_impl = match fn_kind {
1800 FnDeclKind::Trait => Some(hir::RpitContext::Trait),
1801 FnDeclKind::Impl => Some(hir::RpitContext::TraitImpl),
1802 FnDeclKind::Fn | FnDeclKind::Inherent => None,
1803 FnDeclKind::ExternFn | FnDeclKind::Closure | FnDeclKind::Pointer => unreachable!(),
1804 };
1805
1806 let opaque_ty_ref = self.lower_opaque_inner(
1807 opaque_ty_node_id,
1808 hir::OpaqueTyOrigin::AsyncFn { parent: fn_def_id, in_trait_or_impl },
1809 opaque_ty_span,
1810 |this| {
1811 let bound = this.lower_coroutine_fn_output_type_to_bound(
1812 output,
1813 coro,
1814 opaque_ty_span,
1815 ImplTraitContext::OpaqueTy {
1816 origin: hir::OpaqueTyOrigin::FnReturn {
1817 parent: fn_def_id,
1818 in_trait_or_impl,
1819 },
1820 },
1821 );
1822 arena_vec![this; bound]
1823 },
1824 );
1825
1826 let opaque_ty = self.ty(opaque_ty_span, opaque_ty_ref);
1827 hir::FnRetTy::Return(self.arena.alloc(opaque_ty))
1828 }
1829
1830 fn lower_coroutine_fn_output_type_to_bound(
1832 &mut self,
1833 output: &FnRetTy,
1834 coro: CoroutineKind,
1835 opaque_ty_span: Span,
1836 itctx: ImplTraitContext,
1837 ) -> hir::GenericBound<'hir> {
1838 let output_ty = match output {
1840 FnRetTy::Ty(ty) => {
1841 self.lower_ty(ty, itctx)
1845 }
1846 FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
1847 };
1848
1849 let (assoc_ty_name, trait_lang_item) = match coro {
1851 CoroutineKind::Async { .. } => (sym::Output, hir::LangItem::Future),
1852 CoroutineKind::Gen { .. } => (sym::Item, hir::LangItem::Iterator),
1853 CoroutineKind::AsyncGen { .. } => (sym::Item, hir::LangItem::AsyncIterator),
1854 };
1855
1856 let bound_args = self.arena.alloc(hir::GenericArgs {
1857 args: &[],
1858 constraints: self.arena.alloc_from_iter([self.assoc_ty_binding(assoc_ty_name,
opaque_ty_span, output_ty)])arena_vec![self; self.assoc_ty_binding(assoc_ty_name, opaque_ty_span, output_ty)],
1859 parenthesized: hir::GenericArgsParentheses::No,
1860 span_ext: DUMMY_SP,
1861 });
1862
1863 hir::GenericBound::Trait(hir::PolyTraitRef {
1864 bound_generic_params: &[],
1865 modifiers: hir::TraitBoundModifiers::NONE,
1866 trait_ref: hir::TraitRef {
1867 path: self.make_lang_item_path(trait_lang_item, opaque_ty_span, Some(bound_args)),
1868 hir_ref_id: self.next_id(),
1869 },
1870 span: opaque_ty_span,
1871 })
1872 }
1873
1874 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_param_bound",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1874u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["tpb", "rbp",
"itctx"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&tpb)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rbp)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::GenericBound<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
match tpb {
GenericBound::Trait(p) => {
hir::GenericBound::Trait(self.lower_poly_trait_ref(p, rbp,
itctx))
}
GenericBound::Outlives(lifetime) =>
hir::GenericBound::Outlives(self.lower_lifetime(lifetime,
LifetimeSource::OutlivesBound, lifetime.ident.into())),
GenericBound::Use(args, span) =>
hir::GenericBound::Use(self.lower_precise_capturing_args(args),
self.lower_span(*span)),
}
}
}
}#[instrument(level = "trace", skip(self))]
1875 fn lower_param_bound(
1876 &mut self,
1877 tpb: &GenericBound,
1878 rbp: RelaxedBoundPolicy<'_>,
1879 itctx: ImplTraitContext,
1880 ) -> hir::GenericBound<'hir> {
1881 match tpb {
1882 GenericBound::Trait(p) => {
1883 hir::GenericBound::Trait(self.lower_poly_trait_ref(p, rbp, itctx))
1884 }
1885 GenericBound::Outlives(lifetime) => hir::GenericBound::Outlives(self.lower_lifetime(
1886 lifetime,
1887 LifetimeSource::OutlivesBound,
1888 lifetime.ident.into(),
1889 )),
1890 GenericBound::Use(args, span) => hir::GenericBound::Use(
1891 self.lower_precise_capturing_args(args),
1892 self.lower_span(*span),
1893 ),
1894 }
1895 }
1896
1897 fn lower_lifetime(
1898 &mut self,
1899 l: &Lifetime,
1900 source: LifetimeSource,
1901 syntax: LifetimeSyntax,
1902 ) -> &'hir hir::Lifetime {
1903 self.new_named_lifetime(l.id, l.id, l.ident, source, syntax)
1904 }
1905
1906 fn lower_lifetime_hidden_in_path(
1907 &mut self,
1908 id: NodeId,
1909 span: Span,
1910 angle_brackets: AngleBrackets,
1911 ) -> &'hir hir::Lifetime {
1912 self.new_named_lifetime(
1913 id,
1914 id,
1915 Ident::new(kw::UnderscoreLifetime, span),
1916 LifetimeSource::Path { angle_brackets },
1917 LifetimeSyntax::Implicit,
1918 )
1919 }
1920
1921 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("new_named_lifetime",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1921u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["id", "new_id",
"ident", "source", "syntax"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&new_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ident)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&syntax)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: &'hir hir::Lifetime = loop {};
return __tracing_attr_fake_return;
}
{
let res =
self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error);
let res =
match res {
LifetimeRes::Param { param, .. } =>
hir::LifetimeKind::Param(param),
LifetimeRes::Fresh { param, .. } => {
match (&ident.name, &kw::UnderscoreLifetime) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
let param = self.local_def_id(param);
hir::LifetimeKind::Param(param)
}
LifetimeRes::Infer => {
match (&ident.name, &kw::UnderscoreLifetime) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
hir::LifetimeKind::Infer
}
LifetimeRes::Static { .. } => {
if !#[allow(non_exhaustive_omitted_patterns)] match ident.name
{
kw::StaticLifetime | kw::UnderscoreLifetime => true,
_ => false,
} {
::core::panicking::panic("assertion failed: matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime)")
};
hir::LifetimeKind::Static
}
LifetimeRes::Error => hir::LifetimeKind::Error,
LifetimeRes::ElidedAnchor { .. } => {
{
::core::panicking::panic_fmt(format_args!("Unexpected `ElidedAnchar` {0:?} at {1:?}",
ident, ident.span));
};
}
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:1952",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1952u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["res"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&res) as
&dyn Value))])
});
} else { ; }
};
self.arena.alloc(hir::Lifetime::new(self.lower_node_id(new_id),
self.lower_ident(ident), res, source, syntax))
}
}
}#[instrument(level = "debug", skip(self))]
1922 fn new_named_lifetime(
1923 &mut self,
1924 id: NodeId,
1925 new_id: NodeId,
1926 ident: Ident,
1927 source: LifetimeSource,
1928 syntax: LifetimeSyntax,
1929 ) -> &'hir hir::Lifetime {
1930 let res = self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error);
1931 let res = match res {
1932 LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
1933 LifetimeRes::Fresh { param, .. } => {
1934 assert_eq!(ident.name, kw::UnderscoreLifetime);
1935 let param = self.local_def_id(param);
1936 hir::LifetimeKind::Param(param)
1937 }
1938 LifetimeRes::Infer => {
1939 assert_eq!(ident.name, kw::UnderscoreLifetime);
1940 hir::LifetimeKind::Infer
1941 }
1942 LifetimeRes::Static { .. } => {
1943 assert!(matches!(ident.name, kw::StaticLifetime | kw::UnderscoreLifetime));
1944 hir::LifetimeKind::Static
1945 }
1946 LifetimeRes::Error => hir::LifetimeKind::Error,
1947 LifetimeRes::ElidedAnchor { .. } => {
1948 panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
1949 }
1950 };
1951
1952 debug!(?res);
1953 self.arena.alloc(hir::Lifetime::new(
1954 self.lower_node_id(new_id),
1955 self.lower_ident(ident),
1956 res,
1957 source,
1958 syntax,
1959 ))
1960 }
1961
1962 fn lower_generic_params_mut(
1963 &mut self,
1964 params: &[GenericParam],
1965 source: hir::GenericParamSource,
1966 ) -> impl Iterator<Item = hir::GenericParam<'hir>> {
1967 params.iter().map(move |param| self.lower_generic_param(param, source))
1968 }
1969
1970 fn lower_generic_params(
1971 &mut self,
1972 params: &[GenericParam],
1973 source: hir::GenericParamSource,
1974 ) -> &'hir [hir::GenericParam<'hir>] {
1975 self.arena.alloc_from_iter(self.lower_generic_params_mut(params, source))
1976 }
1977
1978 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_generic_param",
"rustc_ast_lowering", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(1978u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["param", "source"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(¶m)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&source)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::GenericParam<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let (name, kind) = self.lower_generic_param_kind(param, source);
let hir_id = self.lower_node_id(param.id);
self.lower_attrs(hir_id, ¶m.attrs, param.span(),
Target::Param);
hir::GenericParam {
hir_id,
def_id: self.local_def_id(param.id),
name,
span: self.lower_span(param.span()),
pure_wrt_drop: attr::contains_name(¶m.attrs,
sym::may_dangle),
kind,
colon_span: param.colon_span.map(|s| self.lower_span(s)),
source,
}
}
}
}#[instrument(level = "trace", skip(self))]
1979 fn lower_generic_param(
1980 &mut self,
1981 param: &GenericParam,
1982 source: hir::GenericParamSource,
1983 ) -> hir::GenericParam<'hir> {
1984 let (name, kind) = self.lower_generic_param_kind(param, source);
1985
1986 let hir_id = self.lower_node_id(param.id);
1987 self.lower_attrs(hir_id, ¶m.attrs, param.span(), Target::Param);
1988 hir::GenericParam {
1989 hir_id,
1990 def_id: self.local_def_id(param.id),
1991 name,
1992 span: self.lower_span(param.span()),
1993 pure_wrt_drop: attr::contains_name(¶m.attrs, sym::may_dangle),
1994 kind,
1995 colon_span: param.colon_span.map(|s| self.lower_span(s)),
1996 source,
1997 }
1998 }
1999
2000 fn lower_generic_param_kind(
2001 &mut self,
2002 param: &GenericParam,
2003 source: hir::GenericParamSource,
2004 ) -> (hir::ParamName, hir::GenericParamKind<'hir>) {
2005 match ¶m.kind {
2006 GenericParamKind::Lifetime => {
2007 let ident = self.lower_ident(param.ident);
2010 let param_name =
2011 if let Some(LifetimeRes::Error) = self.resolver.get_lifetime_res(param.id) {
2012 ParamName::Error(ident)
2013 } else {
2014 ParamName::Plain(ident)
2015 };
2016 let kind =
2017 hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
2018
2019 (param_name, kind)
2020 }
2021 GenericParamKind::Type { default, .. } => {
2022 let default = default
2025 .as_ref()
2026 .filter(|_| match source {
2027 hir::GenericParamSource::Generics => true,
2028 hir::GenericParamSource::Binder => {
2029 self.dcx().emit_err(errors::GenericParamDefaultInBinder {
2030 span: param.span(),
2031 });
2032
2033 false
2034 }
2035 })
2036 .map(|def| {
2037 self.lower_ty(
2038 def,
2039 ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault),
2040 )
2041 });
2042
2043 let kind = hir::GenericParamKind::Type { default, synthetic: false };
2044
2045 (hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
2046 }
2047 GenericParamKind::Const { ty, span: _, default } => {
2048 let ty = self
2049 .lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::GenericDefault));
2050
2051 let default = default
2054 .as_ref()
2055 .filter(|_| match source {
2056 hir::GenericParamSource::Generics => true,
2057 hir::GenericParamSource::Binder => {
2058 self.dcx().emit_err(errors::GenericParamDefaultInBinder {
2059 span: param.span(),
2060 });
2061
2062 false
2063 }
2064 })
2065 .map(|def| self.lower_anon_const_to_const_arg(def));
2066
2067 (
2068 hir::ParamName::Plain(self.lower_ident(param.ident)),
2069 hir::GenericParamKind::Const { ty, default },
2070 )
2071 }
2072 }
2073 }
2074
2075 fn lower_trait_ref(
2076 &mut self,
2077 modifiers: ast::TraitBoundModifiers,
2078 p: &TraitRef,
2079 itctx: ImplTraitContext,
2080 ) -> hir::TraitRef<'hir> {
2081 let path = match self.lower_qpath(
2082 p.ref_id,
2083 &None,
2084 &p.path,
2085 ParamMode::Explicit,
2086 AllowReturnTypeNotation::No,
2087 itctx,
2088 Some(modifiers),
2089 ) {
2090 hir::QPath::Resolved(None, path) => path,
2091 qpath => {
::core::panicking::panic_fmt(format_args!("lower_trait_ref: unexpected QPath `{0:?}`",
qpath));
}panic!("lower_trait_ref: unexpected QPath `{qpath:?}`"),
2092 };
2093 hir::TraitRef { path, hir_ref_id: self.lower_node_id(p.ref_id) }
2094 }
2095
2096 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_poly_trait_ref",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2096u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["bound_generic_params",
"modifiers", "trait_ref", "span", "rbp", "itctx"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&bound_generic_params)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&modifiers)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_ref)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&rbp)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&itctx)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::PolyTraitRef<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let bound_generic_params =
self.lower_lifetime_binder(trait_ref.ref_id,
bound_generic_params);
let trait_ref =
self.lower_trait_ref(*modifiers, trait_ref, itctx);
let modifiers = self.lower_trait_bound_modifiers(*modifiers);
if let ast::BoundPolarity::Maybe(_) = modifiers.polarity {
self.validate_relaxed_bound(trait_ref, *span, rbp);
}
hir::PolyTraitRef {
bound_generic_params,
modifiers,
trait_ref,
span: self.lower_span(*span),
}
}
}
}#[instrument(level = "debug", skip(self))]
2097 fn lower_poly_trait_ref(
2098 &mut self,
2099 PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens: _ }: &PolyTraitRef,
2100 rbp: RelaxedBoundPolicy<'_>,
2101 itctx: ImplTraitContext,
2102 ) -> hir::PolyTraitRef<'hir> {
2103 let bound_generic_params =
2104 self.lower_lifetime_binder(trait_ref.ref_id, bound_generic_params);
2105 let trait_ref = self.lower_trait_ref(*modifiers, trait_ref, itctx);
2106 let modifiers = self.lower_trait_bound_modifiers(*modifiers);
2107
2108 if let ast::BoundPolarity::Maybe(_) = modifiers.polarity {
2109 self.validate_relaxed_bound(trait_ref, *span, rbp);
2110 }
2111
2112 hir::PolyTraitRef {
2113 bound_generic_params,
2114 modifiers,
2115 trait_ref,
2116 span: self.lower_span(*span),
2117 }
2118 }
2119
2120 fn validate_relaxed_bound(
2121 &self,
2122 trait_ref: hir::TraitRef<'_>,
2123 span: Span,
2124 rbp: RelaxedBoundPolicy<'_>,
2125 ) {
2126 match rbp {
2136 RelaxedBoundPolicy::Allowed => return,
2137 RelaxedBoundPolicy::AllowedIfOnTyParam(id, params) => {
2138 if let Some(res) = self.resolver.get_partial_res(id).and_then(|r| r.full_res())
2139 && let Res::Def(DefKind::TyParam, def_id) = res
2140 && params.iter().any(|p| def_id == self.local_def_id(p.id).to_def_id())
2141 {
2142 return;
2143 }
2144 }
2145 RelaxedBoundPolicy::Forbidden(reason) => {
2146 let gate = |context, subject| {
2147 let extended = self.tcx.features().more_maybe_bounds();
2148 let is_sized = trait_ref
2149 .trait_def_id()
2150 .is_some_and(|def_id| self.tcx.is_lang_item(def_id, hir::LangItem::Sized));
2151
2152 if extended && !is_sized {
2153 return;
2154 }
2155
2156 let prefix = if extended { "`Sized` " } else { "" };
2157 let mut diag = self.dcx().struct_span_err(
2158 span,
2159 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("relaxed {0}bounds are not permitted in {1}",
prefix, context))
})format!("relaxed {prefix}bounds are not permitted in {context}"),
2160 );
2161 if is_sized {
2162 diag.note(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0} are not implicitly bounded by `Sized`, so there is nothing to relax",
subject))
})format!(
2163 "{subject} are not implicitly bounded by `Sized`, \
2164 so there is nothing to relax"
2165 ));
2166 }
2167 diag.emit();
2168 };
2169
2170 match reason {
2171 RelaxedBoundForbiddenReason::TraitObjectTy => {
2172 gate("trait object types", "trait object types");
2173 return;
2174 }
2175 RelaxedBoundForbiddenReason::SuperTrait => {
2176 gate("supertrait bounds", "traits");
2177 return;
2178 }
2179 RelaxedBoundForbiddenReason::TraitAlias => {
2180 gate("trait alias bounds", "trait aliases");
2181 return;
2182 }
2183 RelaxedBoundForbiddenReason::AssocTyBounds
2184 | RelaxedBoundForbiddenReason::LateBoundVarsInScope => {}
2185 };
2186 }
2187 }
2188
2189 self.dcx()
2190 .struct_span_err(span, "this relaxed bound is not permitted here")
2191 .with_note(
2192 "in this context, relaxed bounds are only allowed on \
2193 type parameters defined on the closest item",
2194 )
2195 .emit();
2196 }
2197
2198 fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
2199 hir::MutTy { ty: self.lower_ty(&mt.ty, itctx), mutbl: mt.mutbl }
2200 }
2201
2202 x;#[instrument(level = "debug", skip(self), ret)]
2203 fn lower_param_bounds(
2204 &mut self,
2205 bounds: &[GenericBound],
2206 rbp: RelaxedBoundPolicy<'_>,
2207 itctx: ImplTraitContext,
2208 ) -> hir::GenericBounds<'hir> {
2209 self.arena.alloc_from_iter(self.lower_param_bounds_mut(bounds, rbp, itctx))
2210 }
2211
2212 fn lower_param_bounds_mut(
2213 &mut self,
2214 bounds: &[GenericBound],
2215 rbp: RelaxedBoundPolicy<'_>,
2216 itctx: ImplTraitContext,
2217 ) -> impl Iterator<Item = hir::GenericBound<'hir>> {
2218 bounds.iter().map(move |bound| self.lower_param_bound(bound, rbp, itctx))
2219 }
2220
2221 x;#[instrument(level = "debug", skip(self), ret)]
2222 fn lower_universal_param_and_bounds(
2223 &mut self,
2224 node_id: NodeId,
2225 span: Span,
2226 ident: Ident,
2227 bounds: &[GenericBound],
2228 ) -> (hir::GenericParam<'hir>, Option<hir::WherePredicate<'hir>>, hir::TyKind<'hir>) {
2229 let def_id = self.local_def_id(node_id);
2231 let span = self.lower_span(span);
2232
2233 let param = hir::GenericParam {
2235 hir_id: self.lower_node_id(node_id),
2236 def_id,
2237 name: ParamName::Plain(self.lower_ident(ident)),
2238 pure_wrt_drop: false,
2239 span,
2240 kind: hir::GenericParamKind::Type { default: None, synthetic: true },
2241 colon_span: None,
2242 source: hir::GenericParamSource::Generics,
2243 };
2244
2245 let preds = self.lower_generic_bound_predicate(
2246 ident,
2247 node_id,
2248 &GenericParamKind::Type { default: None },
2249 bounds,
2250 None,
2251 span,
2252 RelaxedBoundPolicy::Allowed,
2253 ImplTraitContext::Universal,
2254 hir::PredicateOrigin::ImplTrait,
2255 );
2256
2257 let hir_id = self.next_id();
2258 let res = Res::Def(DefKind::TyParam, def_id.to_def_id());
2259 let ty = hir::TyKind::Path(hir::QPath::Resolved(
2260 None,
2261 self.arena.alloc(hir::Path {
2262 span,
2263 res,
2264 segments:
2265 arena_vec![self; hir::PathSegment::new(self.lower_ident(ident), hir_id, res)],
2266 }),
2267 ));
2268
2269 (param, preds, ty)
2270 }
2271
2272 fn lower_block_expr(&mut self, b: &Block) -> hir::Expr<'hir> {
2275 let block = self.lower_block(b, false);
2276 self.expr_block(block)
2277 }
2278
2279 fn lower_array_length_to_const_arg(&mut self, c: &AnonConst) -> &'hir hir::ConstArg<'hir> {
2280 match c.value.peel_parens().kind {
2283 ExprKind::Underscore => {
2284 let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span), ());
2285 self.arena.alloc(hir::ConstArg { hir_id: self.lower_node_id(c.id), kind: ct_kind })
2286 }
2287 _ => self.lower_anon_const_to_const_arg(c),
2288 }
2289 }
2290
2291 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_const_path_to_const_arg",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2294u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["path", "res",
"ty_id", "span"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&path)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&res)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: &'hir hir::ConstArg<'hir> =
loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
let is_trivial_path =
path.is_potential_trivial_const_arg() &&
#[allow(non_exhaustive_omitted_patterns)] match res {
Res::Def(DefKind::ConstParam, _) => true,
_ => false,
};
let ct_kind =
if is_trivial_path || tcx.features().min_generic_const_args()
{
let qpath =
self.lower_qpath(ty_id, &None, path, ParamMode::Explicit,
AllowReturnTypeNotation::No,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None);
hir::ConstArgKind::Path(qpath)
} else {
let node_id = self.next_node_id();
let span = self.lower_span(span);
let def_id =
self.create_def(node_id, None, DefKind::AnonConst,
DefPathData::LateAnonConst, span);
let hir_id = self.lower_node_id(node_id);
let path_expr =
Expr {
id: ty_id,
kind: ExprKind::Path(None, path.clone()),
span,
attrs: AttrVec::new(),
tokens: None,
};
let ct =
self.with_new_scopes(span,
|this|
{
self.arena.alloc(hir::AnonConst {
def_id,
hir_id,
body: this.lower_const_body(path_expr.span,
Some(&path_expr)),
span,
})
});
hir::ConstArgKind::Anon(ct)
};
self.arena.alloc(hir::ConstArg {
hir_id: self.next_id(),
kind: ct_kind,
})
}
}
}#[instrument(level = "debug", skip(self))]
2295 fn lower_const_path_to_const_arg(
2296 &mut self,
2297 path: &Path,
2298 res: Res<NodeId>,
2299 ty_id: NodeId,
2300 span: Span,
2301 ) -> &'hir hir::ConstArg<'hir> {
2302 let tcx = self.tcx;
2303
2304 let is_trivial_path = path.is_potential_trivial_const_arg()
2305 && matches!(res, Res::Def(DefKind::ConstParam, _));
2306 let ct_kind = if is_trivial_path || tcx.features().min_generic_const_args() {
2307 let qpath = self.lower_qpath(
2308 ty_id,
2309 &None,
2310 path,
2311 ParamMode::Explicit,
2312 AllowReturnTypeNotation::No,
2313 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2315 None,
2316 );
2317 hir::ConstArgKind::Path(qpath)
2318 } else {
2319 let node_id = self.next_node_id();
2321 let span = self.lower_span(span);
2322
2323 let def_id = self.create_def(
2328 node_id,
2329 None,
2330 DefKind::AnonConst,
2331 DefPathData::LateAnonConst,
2332 span,
2333 );
2334 let hir_id = self.lower_node_id(node_id);
2335
2336 let path_expr = Expr {
2337 id: ty_id,
2338 kind: ExprKind::Path(None, path.clone()),
2339 span,
2340 attrs: AttrVec::new(),
2341 tokens: None,
2342 };
2343
2344 let ct = self.with_new_scopes(span, |this| {
2345 self.arena.alloc(hir::AnonConst {
2346 def_id,
2347 hir_id,
2348 body: this.lower_const_body(path_expr.span, Some(&path_expr)),
2349 span,
2350 })
2351 });
2352 hir::ConstArgKind::Anon(ct)
2353 };
2354
2355 self.arena.alloc(hir::ConstArg { hir_id: self.next_id(), kind: ct_kind })
2356 }
2357
2358 fn lower_const_item_rhs(
2359 &mut self,
2360 attrs: &[hir::Attribute],
2361 rhs: Option<&ConstItemRhs>,
2362 span: Span,
2363 ) -> hir::ConstItemRhs<'hir> {
2364 match rhs {
2365 Some(ConstItemRhs::TypeConst(anon)) => {
2366 hir::ConstItemRhs::TypeConst(self.lower_anon_const_to_const_arg(anon))
2367 }
2368 None if attr::contains_name(attrs, sym::type_const) => {
2369 let const_arg = ConstArg {
2370 hir_id: self.next_id(),
2371 kind: hir::ConstArgKind::Error(
2372 DUMMY_SP,
2373 self.dcx().span_delayed_bug(DUMMY_SP, "no block"),
2374 ),
2375 };
2376 hir::ConstItemRhs::TypeConst(self.arena.alloc(const_arg))
2377 }
2378 Some(ConstItemRhs::Body(body)) => {
2379 hir::ConstItemRhs::Body(self.lower_const_body(span, Some(body)))
2380 }
2381 None => hir::ConstItemRhs::Body(self.lower_const_body(span, None)),
2382 }
2383 }
2384
2385 x;#[instrument(level = "debug", skip(self), ret)]
2386 fn lower_expr_to_const_arg_direct(&mut self, expr: &Expr) -> hir::ConstArg<'hir> {
2387 let overly_complex_const = |this: &mut Self| {
2388 let e = this.dcx().struct_span_err(
2389 expr.span,
2390 "complex const arguments must be placed inside of a `const` block",
2391 );
2392
2393 ConstArg { hir_id: this.next_id(), kind: hir::ConstArgKind::Error(expr.span, e.emit()) }
2394 };
2395
2396 match &expr.kind {
2397 ExprKind::Path(qself, path) => {
2398 let qpath = self.lower_qpath(
2399 expr.id,
2400 qself,
2401 path,
2402 ParamMode::Explicit,
2403 AllowReturnTypeNotation::No,
2404 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2406 None,
2407 );
2408
2409 ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Path(qpath) }
2410 }
2411 ExprKind::Underscore => ConstArg {
2412 hir_id: self.lower_node_id(expr.id),
2413 kind: hir::ConstArgKind::Infer(expr.span, ()),
2414 },
2415 ExprKind::Block(block, _) => {
2416 if let [stmt] = block.stmts.as_slice()
2417 && let StmtKind::Expr(expr) = &stmt.kind
2418 && matches!(
2419 expr.kind,
2420 ExprKind::Block(..) | ExprKind::Path(..) | ExprKind::Struct(..)
2421 )
2422 {
2423 return self.lower_expr_to_const_arg_direct(expr);
2424 }
2425
2426 overly_complex_const(self)
2427 }
2428 _ => overly_complex_const(self),
2429 }
2430 }
2431
2432 fn lower_anon_const_to_const_arg(&mut self, anon: &AnonConst) -> &'hir hir::ConstArg<'hir> {
2435 self.arena.alloc(self.lower_anon_const_to_const_arg_direct(anon))
2436 }
2437
2438 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("lower_anon_const_to_const_arg_direct",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2438u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["anon"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&anon)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: hir::ConstArg<'hir> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
if tcx.features().min_generic_const_args() {
return match anon.mgca_disambiguation {
MgcaDisambiguation::AnonConst => {
let lowered_anon =
self.lower_anon_const_to_anon_const(anon);
ConstArg {
hir_id: self.next_id(),
kind: hir::ConstArgKind::Anon(lowered_anon),
}
}
MgcaDisambiguation::Direct =>
self.lower_expr_to_const_arg_direct(&anon.value),
};
}
let expr =
if let ExprKind::Block(block, _) = &anon.value.kind &&
let [stmt] = block.stmts.as_slice() &&
let StmtKind::Expr(expr) = &stmt.kind &&
let ExprKind::Path(..) = &expr.kind {
expr
} else { &anon.value };
let maybe_res =
self.resolver.get_partial_res(expr.id).and_then(|partial_res|
partial_res.full_res());
if let ExprKind::Path(qself, path) = &expr.kind &&
path.is_potential_trivial_const_arg() &&
#[allow(non_exhaustive_omitted_patterns)] match maybe_res {
Some(Res::Def(DefKind::ConstParam, _)) => true,
_ => false,
} {
let qpath =
self.lower_qpath(expr.id, qself, path, ParamMode::Explicit,
AllowReturnTypeNotation::No,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None);
return ConstArg {
hir_id: self.lower_node_id(anon.id),
kind: hir::ConstArgKind::Path(qpath),
};
}
let lowered_anon = self.lower_anon_const_to_anon_const(anon);
ConstArg {
hir_id: self.next_id(),
kind: hir::ConstArgKind::Anon(lowered_anon),
}
}
}
}#[instrument(level = "debug", skip(self))]
2439 fn lower_anon_const_to_const_arg_direct(&mut self, anon: &AnonConst) -> hir::ConstArg<'hir> {
2440 let tcx = self.tcx;
2441
2442 if tcx.features().min_generic_const_args() {
2448 return match anon.mgca_disambiguation {
2449 MgcaDisambiguation::AnonConst => {
2450 let lowered_anon = self.lower_anon_const_to_anon_const(anon);
2451 ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Anon(lowered_anon) }
2452 }
2453 MgcaDisambiguation::Direct => self.lower_expr_to_const_arg_direct(&anon.value),
2454 };
2455 }
2456
2457 let expr = if let ExprKind::Block(block, _) = &anon.value.kind
2460 && let [stmt] = block.stmts.as_slice()
2461 && let StmtKind::Expr(expr) = &stmt.kind
2462 && let ExprKind::Path(..) = &expr.kind
2463 {
2464 expr
2465 } else {
2466 &anon.value
2467 };
2468
2469 let maybe_res =
2470 self.resolver.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
2471 if let ExprKind::Path(qself, path) = &expr.kind
2472 && path.is_potential_trivial_const_arg()
2473 && matches!(maybe_res, Some(Res::Def(DefKind::ConstParam, _)))
2474 {
2475 let qpath = self.lower_qpath(
2476 expr.id,
2477 qself,
2478 path,
2479 ParamMode::Explicit,
2480 AllowReturnTypeNotation::No,
2481 ImplTraitContext::Disallowed(ImplTraitPosition::Path),
2482 None,
2483 );
2484
2485 return ConstArg {
2486 hir_id: self.lower_node_id(anon.id),
2487 kind: hir::ConstArgKind::Path(qpath),
2488 };
2489 }
2490
2491 let lowered_anon = self.lower_anon_const_to_anon_const(anon);
2492 ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Anon(lowered_anon) }
2493 }
2494
2495 fn lower_anon_const_to_anon_const(&mut self, c: &AnonConst) -> &'hir hir::AnonConst {
2498 self.arena.alloc(self.with_new_scopes(c.value.span, |this| {
2499 let def_id = this.local_def_id(c.id);
2500 let hir_id = this.lower_node_id(c.id);
2501 hir::AnonConst {
2502 def_id,
2503 hir_id,
2504 body: this.lower_const_body(c.value.span, Some(&c.value)),
2505 span: this.lower_span(c.value.span),
2506 }
2507 }))
2508 }
2509
2510 fn lower_unsafe_source(&mut self, u: UnsafeSource) -> hir::UnsafeSource {
2511 match u {
2512 CompilerGenerated => hir::UnsafeSource::CompilerGenerated,
2513 UserProvided => hir::UnsafeSource::UserProvided,
2514 }
2515 }
2516
2517 fn lower_trait_bound_modifiers(
2518 &mut self,
2519 modifiers: TraitBoundModifiers,
2520 ) -> hir::TraitBoundModifiers {
2521 let constness = match modifiers.constness {
2522 BoundConstness::Never => BoundConstness::Never,
2523 BoundConstness::Always(span) => BoundConstness::Always(self.lower_span(span)),
2524 BoundConstness::Maybe(span) => BoundConstness::Maybe(self.lower_span(span)),
2525 };
2526 let polarity = match modifiers.polarity {
2527 BoundPolarity::Positive => BoundPolarity::Positive,
2528 BoundPolarity::Negative(span) => BoundPolarity::Negative(self.lower_span(span)),
2529 BoundPolarity::Maybe(span) => BoundPolarity::Maybe(self.lower_span(span)),
2530 };
2531 hir::TraitBoundModifiers { constness, polarity }
2532 }
2533
2534 fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
2537 hir::Stmt { span: self.lower_span(span), kind, hir_id: self.next_id() }
2538 }
2539
2540 fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {
2541 self.stmt(span, hir::StmtKind::Expr(self.arena.alloc(expr)))
2542 }
2543
2544 fn stmt_let_pat(
2545 &mut self,
2546 attrs: Option<&'hir [hir::Attribute]>,
2547 span: Span,
2548 init: Option<&'hir hir::Expr<'hir>>,
2549 pat: &'hir hir::Pat<'hir>,
2550 source: hir::LocalSource,
2551 ) -> hir::Stmt<'hir> {
2552 let hir_id = self.next_id();
2553 if let Some(a) = attrs {
2554 if !!a.is_empty() {
::core::panicking::panic("assertion failed: !a.is_empty()")
};assert!(!a.is_empty());
2555 self.attrs.insert(hir_id.local_id, a);
2556 }
2557 let local = hir::LetStmt {
2558 super_: None,
2559 hir_id,
2560 init,
2561 pat,
2562 els: None,
2563 source,
2564 span: self.lower_span(span),
2565 ty: None,
2566 };
2567 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
2568 }
2569
2570 fn stmt_super_let_pat(
2571 &mut self,
2572 span: Span,
2573 pat: &'hir hir::Pat<'hir>,
2574 init: Option<&'hir hir::Expr<'hir>>,
2575 ) -> hir::Stmt<'hir> {
2576 let hir_id = self.next_id();
2577 let span = self.lower_span(span);
2578 let local = hir::LetStmt {
2579 super_: Some(span),
2580 hir_id,
2581 init,
2582 pat,
2583 els: None,
2584 source: hir::LocalSource::Normal,
2585 span,
2586 ty: None,
2587 };
2588 self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
2589 }
2590
2591 fn block_expr(&mut self, expr: &'hir hir::Expr<'hir>) -> &'hir hir::Block<'hir> {
2592 self.block_all(expr.span, &[], Some(expr))
2593 }
2594
2595 fn block_all(
2596 &mut self,
2597 span: Span,
2598 stmts: &'hir [hir::Stmt<'hir>],
2599 expr: Option<&'hir hir::Expr<'hir>>,
2600 ) -> &'hir hir::Block<'hir> {
2601 let blk = hir::Block {
2602 stmts,
2603 expr,
2604 hir_id: self.next_id(),
2605 rules: hir::BlockCheckMode::DefaultBlock,
2606 span: self.lower_span(span),
2607 targeted_by_break: false,
2608 };
2609 self.arena.alloc(blk)
2610 }
2611
2612 fn pat_cf_continue(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
2613 let field = self.single_pat_field(span, pat);
2614 self.pat_lang_item_variant(span, hir::LangItem::ControlFlowContinue, field)
2615 }
2616
2617 fn pat_cf_break(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
2618 let field = self.single_pat_field(span, pat);
2619 self.pat_lang_item_variant(span, hir::LangItem::ControlFlowBreak, field)
2620 }
2621
2622 fn pat_some(&mut self, span: Span, pat: &'hir hir::Pat<'hir>) -> &'hir hir::Pat<'hir> {
2623 let field = self.single_pat_field(span, pat);
2624 self.pat_lang_item_variant(span, hir::LangItem::OptionSome, field)
2625 }
2626
2627 fn pat_none(&mut self, span: Span) -> &'hir hir::Pat<'hir> {
2628 self.pat_lang_item_variant(span, hir::LangItem::OptionNone, &[])
2629 }
2630
2631 fn single_pat_field(
2632 &mut self,
2633 span: Span,
2634 pat: &'hir hir::Pat<'hir>,
2635 ) -> &'hir [hir::PatField<'hir>] {
2636 let field = hir::PatField {
2637 hir_id: self.next_id(),
2638 ident: Ident::new(sym::integer(0), self.lower_span(span)),
2639 is_shorthand: false,
2640 pat,
2641 span: self.lower_span(span),
2642 };
2643 self.arena.alloc_from_iter([field])arena_vec![self; field]
2644 }
2645
2646 fn pat_lang_item_variant(
2647 &mut self,
2648 span: Span,
2649 lang_item: hir::LangItem,
2650 fields: &'hir [hir::PatField<'hir>],
2651 ) -> &'hir hir::Pat<'hir> {
2652 let path = self.make_lang_item_qpath(lang_item, self.lower_span(span), None);
2653 self.pat(span, hir::PatKind::Struct(path, fields, None))
2654 }
2655
2656 fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
2657 self.pat_ident_binding_mode(span, ident, hir::BindingMode::NONE)
2658 }
2659
2660 fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) {
2661 self.pat_ident_binding_mode_mut(span, ident, hir::BindingMode::NONE)
2662 }
2663
2664 fn pat_ident_binding_mode(
2665 &mut self,
2666 span: Span,
2667 ident: Ident,
2668 bm: hir::BindingMode,
2669 ) -> (&'hir hir::Pat<'hir>, HirId) {
2670 let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
2671 (self.arena.alloc(pat), hir_id)
2672 }
2673
2674 fn pat_ident_binding_mode_mut(
2675 &mut self,
2676 span: Span,
2677 ident: Ident,
2678 bm: hir::BindingMode,
2679 ) -> (hir::Pat<'hir>, HirId) {
2680 let hir_id = self.next_id();
2681
2682 (
2683 hir::Pat {
2684 hir_id,
2685 kind: hir::PatKind::Binding(bm, hir_id, self.lower_ident(ident), None),
2686 span: self.lower_span(span),
2687 default_binding_modes: true,
2688 },
2689 hir_id,
2690 )
2691 }
2692
2693 fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> {
2694 self.arena.alloc(hir::Pat {
2695 hir_id: self.next_id(),
2696 kind,
2697 span: self.lower_span(span),
2698 default_binding_modes: true,
2699 })
2700 }
2701
2702 fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> {
2703 hir::Pat {
2704 hir_id: self.next_id(),
2705 kind,
2706 span: self.lower_span(span),
2707 default_binding_modes: false,
2708 }
2709 }
2710
2711 fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
2712 let kind = match qpath {
2713 hir::QPath::Resolved(None, path) => {
2714 match path.res {
2716 Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
2717 let principal = hir::PolyTraitRef {
2718 bound_generic_params: &[],
2719 modifiers: hir::TraitBoundModifiers::NONE,
2720 trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
2721 span: self.lower_span(span),
2722 };
2723
2724 hir_id = self.next_id();
2727 hir::TyKind::TraitObject(
2728 self.arena.alloc_from_iter([principal])arena_vec![self; principal],
2729 TaggedRef::new(self.elided_dyn_bound(span), TraitObjectSyntax::None),
2730 )
2731 }
2732 _ => hir::TyKind::Path(hir::QPath::Resolved(None, path)),
2733 }
2734 }
2735 _ => hir::TyKind::Path(qpath),
2736 };
2737
2738 hir::Ty { hir_id, kind, span: self.lower_span(span) }
2739 }
2740
2741 fn elided_dyn_bound(&mut self, span: Span) -> &'hir hir::Lifetime {
2746 let r = hir::Lifetime::new(
2747 self.next_id(),
2748 Ident::new(kw::UnderscoreLifetime, self.lower_span(span)),
2749 hir::LifetimeKind::ImplicitObjectLifetimeDefault,
2750 LifetimeSource::Other,
2751 LifetimeSyntax::Implicit,
2752 );
2753 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_ast_lowering/src/lib.rs:2753",
"rustc_ast_lowering", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_ast_lowering/src/lib.rs"),
::tracing_core::__macro_support::Option::Some(2753u32),
::tracing_core::__macro_support::Option::Some("rustc_ast_lowering"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("elided_dyn_bound: r={0:?}",
r) as &dyn Value))])
});
} else { ; }
};debug!("elided_dyn_bound: r={:?}", r);
2754 self.arena.alloc(r)
2755 }
2756}
2757
2758struct GenericArgsCtor<'hir> {
2760 args: SmallVec<[hir::GenericArg<'hir>; 4]>,
2761 constraints: &'hir [hir::AssocItemConstraint<'hir>],
2762 parenthesized: hir::GenericArgsParentheses,
2763 span: Span,
2764}
2765
2766impl<'hir> GenericArgsCtor<'hir> {
2767 fn is_empty(&self) -> bool {
2768 self.args.is_empty()
2769 && self.constraints.is_empty()
2770 && self.parenthesized == hir::GenericArgsParentheses::No
2771 }
2772
2773 fn into_generic_args(self, this: &LoweringContext<'_, 'hir>) -> &'hir hir::GenericArgs<'hir> {
2774 let ga = hir::GenericArgs {
2775 args: this.arena.alloc_from_iter(self.args),
2776 constraints: self.constraints,
2777 parenthesized: self.parenthesized,
2778 span_ext: this.lower_span(self.span),
2779 };
2780 this.arena.alloc(ga)
2781 }
2782}