1
Fork 0

Auto merge of #104170 - cjgillot:hir-def-id, r=fee1-dead

Record `LocalDefId` in HIR nodes instead of a side table

This is part of an attempt to remove the `HirId -> LocalDefId` table from HIR.
This attempt is a prerequisite to creation of `LocalDefId` after HIR lowering (https://github.com/rust-lang/rust/pull/96840), by controlling how `def_id` information is accessed.

This first part adds the information to HIR nodes themselves instead of a table.
The second part is https://github.com/rust-lang/rust/pull/103902
The third part will be to make `hir::Visitor::visit_fn` take a `LocalDefId` as last parameter.
The fourth part will be to completely remove the side table.
This commit is contained in:
bors 2022-11-17 07:42:27 +00:00
commit 7c75fe4c85
63 changed files with 449 additions and 549 deletions

View file

@ -643,6 +643,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `static |_task_context| -> <ret_ty> { body }`: // `static |_task_context| -> <ret_ty> { body }`:
let generator_kind = { let generator_kind = {
let c = self.arena.alloc(hir::Closure { let c = self.arena.alloc(hir::Closure {
def_id: self.local_def_id(closure_node_id),
binder: hir::ClosureBinder::Default, binder: hir::ClosureBinder::Default,
capture_clause, capture_clause,
bound_generic_params: &[], bound_generic_params: &[],
@ -895,6 +896,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let fn_decl = self.lower_fn_decl(decl, None, fn_decl_span, FnDeclKind::Closure, None); let fn_decl = self.lower_fn_decl(decl, None, fn_decl_span, FnDeclKind::Closure, None);
let c = self.arena.alloc(hir::Closure { let c = self.arena.alloc(hir::Closure {
def_id: self.local_def_id(closure_id),
binder: binder_clause, binder: binder_clause,
capture_clause, capture_clause,
bound_generic_params, bound_generic_params,
@ -999,6 +1001,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_fn_decl(&outer_decl, None, fn_decl_span, FnDeclKind::Closure, None); self.lower_fn_decl(&outer_decl, None, fn_decl_span, FnDeclKind::Closure, None);
let c = self.arena.alloc(hir::Closure { let c = self.arena.alloc(hir::Closure {
def_id: self.local_def_id(closure_id),
binder: binder_clause, binder: binder_clause,
capture_clause, capture_clause,
bound_generic_params, bound_generic_params,

View file

@ -307,8 +307,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
} }
fn visit_variant(&mut self, v: &'hir Variant<'hir>) { fn visit_variant(&mut self, v: &'hir Variant<'hir>) {
self.insert(v.span, v.id, Node::Variant(v)); self.insert(v.span, v.hir_id, Node::Variant(v));
self.with_parent(v.id, |this| { self.with_parent(v.hir_id, |this| {
// Register the constructor of this variant. // Register the constructor of this variant.
if let Some(ctor_hir_id) = v.data.ctor_hir_id() { if let Some(ctor_hir_id) = v.data.ctor_hir_id() {
this.insert(v.span, ctor_hir_id, Node::Ctor(&v.data)); this.insert(v.span, ctor_hir_id, Node::Ctor(&v.data));

View file

@ -709,11 +709,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> { fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
let id = self.lower_node_id(v.id); let hir_id = self.lower_node_id(v.id);
self.lower_attrs(id, &v.attrs); self.lower_attrs(hir_id, &v.attrs);
hir::Variant { hir::Variant {
id, hir_id,
data: self.lower_variant_data(id, &v.data), def_id: self.local_def_id(v.id),
data: self.lower_variant_data(hir_id, &v.data),
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const(e)), disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
ident: self.lower_ident(v.ident), ident: self.lower_ident(v.ident),
span: self.lower_span(v.span), span: self.lower_span(v.span),
@ -739,12 +740,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
fields.iter().enumerate().map(|f| self.lower_field_def(f)), fields.iter().enumerate().map(|f| self.lower_field_def(f)),
), ),
ctor_id, ctor_id,
self.local_def_id(id),
) )
} }
VariantData::Unit(id) => { VariantData::Unit(id) => {
let ctor_id = self.lower_node_id(id); let ctor_id = self.lower_node_id(id);
self.alias_attrs(ctor_id, parent_id); self.alias_attrs(ctor_id, parent_id);
hir::VariantData::Unit(ctor_id) hir::VariantData::Unit(ctor_id, self.local_def_id(id))
} }
} }
} }
@ -767,6 +769,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::FieldDef { hir::FieldDef {
span: self.lower_span(f.span), span: self.lower_span(f.span),
hir_id, hir_id,
def_id: self.local_def_id(f.id),
ident: match f.ident { ident: match f.ident {
Some(ident) => self.lower_ident(ident), Some(ident) => self.lower_ident(ident),
// FIXME(jseyfried): positional field hygiene. // FIXME(jseyfried): positional field hygiene.

View file

@ -830,8 +830,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
), ),
}; };
let hir_id = self.lower_node_id(node_id); let hir_id = self.lower_node_id(node_id);
let def_id = self.local_def_id(node_id);
Some(hir::GenericParam { Some(hir::GenericParam {
hir_id, hir_id,
def_id,
name, name,
span: self.lower_span(ident.span), span: self.lower_span(ident.span),
pure_wrt_drop: false, pure_wrt_drop: false,
@ -1165,7 +1167,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let node_id = self.next_node_id(); let node_id = self.next_node_id();
// Add a definition for the in-band const def. // Add a definition for the in-band const def.
self.create_def( let def_id = self.create_def(
parent_def_id.def_id, parent_def_id.def_id,
node_id, node_id,
DefPathData::AnonConst, DefPathData::AnonConst,
@ -1181,6 +1183,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}; };
let ct = self.with_new_scopes(|this| hir::AnonConst { let ct = self.with_new_scopes(|this| hir::AnonConst {
def_id,
hir_id: this.lower_node_id(node_id), hir_id: this.lower_node_id(node_id),
body: this.lower_const_body(path_expr.span, Some(&path_expr)), body: this.lower_const_body(path_expr.span, Some(&path_expr)),
}); });
@ -1528,6 +1531,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::GenericParam { hir::GenericParam {
hir_id, hir_id,
def_id: lctx.local_def_id(new_node_id),
name, name,
span: lifetime.ident.span, span: lifetime.ident.span,
pure_wrt_drop: false, pure_wrt_drop: false,
@ -1985,6 +1989,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::GenericParam { hir::GenericParam {
hir_id, hir_id,
def_id: this.local_def_id(new_node_id),
name, name,
span: lifetime.ident.span, span: lifetime.ident.span,
pure_wrt_drop: false, pure_wrt_drop: false,
@ -2183,6 +2188,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.lower_attrs(hir_id, &param.attrs); self.lower_attrs(hir_id, &param.attrs);
hir::GenericParam { hir::GenericParam {
hir_id, hir_id,
def_id: self.local_def_id(param.id),
name, name,
span: self.lower_span(param.span()), span: self.lower_span(param.span()),
pure_wrt_drop: self.tcx.sess.contains_name(&param.attrs, sym::may_dangle), pure_wrt_drop: self.tcx.sess.contains_name(&param.attrs, sym::may_dangle),
@ -2287,6 +2293,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Set the name to `impl Bound1 + Bound2`. // Set the name to `impl Bound1 + Bound2`.
let param = hir::GenericParam { let param = hir::GenericParam {
hir_id: self.lower_node_id(node_id), hir_id: self.lower_node_id(node_id),
def_id,
name: ParamName::Plain(self.lower_ident(ident)), name: ParamName::Plain(self.lower_ident(ident)),
pure_wrt_drop: false, pure_wrt_drop: false,
span: self.lower_span(span), span: self.lower_span(span),
@ -2347,6 +2354,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_anon_const(&mut self, c: &AnonConst) -> hir::AnonConst { fn lower_anon_const(&mut self, c: &AnonConst) -> hir::AnonConst {
self.with_new_scopes(|this| hir::AnonConst { self.with_new_scopes(|this| hir::AnonConst {
def_id: this.local_def_id(c.id),
hir_id: this.lower_node_id(c.id), hir_id: this.lower_node_id(c.id),
body: this.lower_const_body(c.value.span, Some(&c.value)), body: this.lower_const_body(c.value.span, Some(&c.value)),
}) })

View file

@ -42,8 +42,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
user_provided_sig = None; user_provided_sig = None;
} else { } else {
let typeck_results = self.tcx().typeck(mir_def_id); let typeck_results = self.tcx().typeck(mir_def_id);
user_provided_sig = typeck_results.user_provided_sigs.get(&mir_def_id.to_def_id()).map( user_provided_sig =
|user_provided_poly_sig| { typeck_results.user_provided_sigs.get(&mir_def_id).map(|user_provided_poly_sig| {
// Instantiate the canonicalized variables from // Instantiate the canonicalized variables from
// user-provided signature (e.g., the `_` in the code // user-provided signature (e.g., the `_` in the code
// above) with fresh variables. // above) with fresh variables.
@ -60,8 +60,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
LateBoundRegionConversionTime::FnCall, LateBoundRegionConversionTime::FnCall,
poly_sig, poly_sig,
) )
}, });
);
} }
debug!(?normalized_input_tys, ?body.local_decls); debug!(?normalized_input_tys, ?body.local_decls);

View file

@ -40,12 +40,12 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
.iter() .iter()
.map(|(op, op_sp)| match *op { .map(|(op, op_sp)| match *op {
hir::InlineAsmOperand::Const { ref anon_const } => { hir::InlineAsmOperand::Const { ref anon_const } => {
let anon_const_def_id = let const_value = cx
cx.tcx().hir().local_def_id(anon_const.hir_id).to_def_id(); .tcx()
let const_value = .const_eval_poly(anon_const.def_id.to_def_id())
cx.tcx().const_eval_poly(anon_const_def_id).unwrap_or_else( .unwrap_or_else(|_| {
|_| span_bug!(*op_sp, "asm const cannot be resolved"), span_bug!(*op_sp, "asm const cannot be resolved")
); });
let ty = cx let ty = cx
.tcx() .tcx()
.typeck_body(anon_const.body) .typeck_body(anon_const.body)

View file

@ -487,6 +487,7 @@ pub enum GenericParamKind<'hir> {
#[derive(Debug, HashStable_Generic)] #[derive(Debug, HashStable_Generic)]
pub struct GenericParam<'hir> { pub struct GenericParam<'hir> {
pub hir_id: HirId, pub hir_id: HirId,
pub def_id: LocalDefId,
pub name: ParamName, pub name: ParamName,
pub span: Span, pub span: Span,
pub pure_wrt_drop: bool, pub pure_wrt_drop: bool,
@ -921,6 +922,7 @@ pub struct Crate<'hir> {
#[derive(Debug, HashStable_Generic)] #[derive(Debug, HashStable_Generic)]
pub struct Closure<'hir> { pub struct Closure<'hir> {
pub def_id: LocalDefId,
pub binder: ClosureBinder, pub binder: ClosureBinder,
pub capture_clause: CaptureBy, pub capture_clause: CaptureBy,
pub bound_generic_params: &'hir [GenericParam<'hir>], pub bound_generic_params: &'hir [GenericParam<'hir>],
@ -1615,7 +1617,7 @@ pub enum ArrayLen {
impl ArrayLen { impl ArrayLen {
pub fn hir_id(&self) -> HirId { pub fn hir_id(&self) -> HirId {
match self { match self {
&ArrayLen::Infer(hir_id, _) | &ArrayLen::Body(AnonConst { hir_id, body: _ }) => hir_id, &ArrayLen::Infer(hir_id, _) | &ArrayLen::Body(AnonConst { hir_id, .. }) => hir_id,
} }
} }
} }
@ -1627,10 +1629,11 @@ impl ArrayLen {
/// explicit discriminant values for enum variants. /// explicit discriminant values for enum variants.
/// ///
/// You can check if this anon const is a default in a const param /// You can check if this anon const is a default in a const param
/// `const N: usize = { ... }` with `tcx.hir().opt_const_param_default_param_hir_id(..)` /// `const N: usize = { ... }` with `tcx.hir().opt_const_param_default_param_def_id(..)`
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)] #[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
pub struct AnonConst { pub struct AnonConst {
pub hir_id: HirId, pub hir_id: HirId,
pub def_id: LocalDefId,
pub body: BodyId, pub body: BodyId,
} }
@ -2798,7 +2801,8 @@ pub struct Variant<'hir> {
/// Name of the variant. /// Name of the variant.
pub ident: Ident, pub ident: Ident,
/// Id of the variant (not the constructor, see `VariantData::ctor_hir_id()`). /// Id of the variant (not the constructor, see `VariantData::ctor_hir_id()`).
pub id: HirId, pub hir_id: HirId,
pub def_id: LocalDefId,
/// Fields and constructor id of the variant. /// Fields and constructor id of the variant.
pub data: VariantData<'hir>, pub data: VariantData<'hir>,
/// Explicit discriminant (e.g., `Foo = 1`). /// Explicit discriminant (e.g., `Foo = 1`).
@ -2865,6 +2869,7 @@ pub struct FieldDef<'hir> {
pub vis_span: Span, pub vis_span: Span,
pub ident: Ident, pub ident: Ident,
pub hir_id: HirId, pub hir_id: HirId,
pub def_id: LocalDefId,
pub ty: &'hir Ty<'hir>, pub ty: &'hir Ty<'hir>,
} }
@ -2886,11 +2891,11 @@ pub enum VariantData<'hir> {
/// A tuple variant. /// A tuple variant.
/// ///
/// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`. /// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`.
Tuple(&'hir [FieldDef<'hir>], HirId), Tuple(&'hir [FieldDef<'hir>], HirId, LocalDefId),
/// A unit variant. /// A unit variant.
/// ///
/// E.g., `Bar = ..` as in `enum Foo { Bar = .. }`. /// E.g., `Bar = ..` as in `enum Foo { Bar = .. }`.
Unit(HirId), Unit(HirId, LocalDefId),
} }
impl<'hir> VariantData<'hir> { impl<'hir> VariantData<'hir> {
@ -2902,11 +2907,19 @@ impl<'hir> VariantData<'hir> {
} }
} }
/// Return the `LocalDefId` of this variant's constructor, if it has one.
pub fn ctor_def_id(&self) -> Option<LocalDefId> {
match *self {
VariantData::Struct(_, _) => None,
VariantData::Tuple(_, _, def_id) | VariantData::Unit(_, def_id) => Some(def_id),
}
}
/// Return the `HirId` of this variant's constructor, if it has one. /// Return the `HirId` of this variant's constructor, if it has one.
pub fn ctor_hir_id(&self) -> Option<HirId> { pub fn ctor_hir_id(&self) -> Option<HirId> {
match *self { match *self {
VariantData::Struct(_, _) => None, VariantData::Struct(_, _) => None,
VariantData::Tuple(_, hir_id) | VariantData::Unit(hir_id) => Some(hir_id), VariantData::Tuple(_, hir_id, _) | VariantData::Unit(hir_id, _) => Some(hir_id),
} }
} }
} }
@ -3532,7 +3545,7 @@ impl<'hir> Node<'hir> {
/// Get the fields for the tuple-constructor, /// Get the fields for the tuple-constructor,
/// if this node is a tuple constructor, otherwise None /// if this node is a tuple constructor, otherwise None
pub fn tuple_fields(&self) -> Option<&'hir [FieldDef<'hir>]> { pub fn tuple_fields(&self) -> Option<&'hir [FieldDef<'hir>]> {
if let Node::Ctor(&VariantData::Tuple(fields, _)) = self { Some(fields) } else { None } if let Node::Ctor(&VariantData::Tuple(fields, _, _)) = self { Some(fields) } else { None }
} }
} }
@ -3548,7 +3561,7 @@ mod size_asserts {
static_assert_size!(FnDecl<'_>, 40); static_assert_size!(FnDecl<'_>, 40);
static_assert_size!(ForeignItem<'_>, 72); static_assert_size!(ForeignItem<'_>, 72);
static_assert_size!(ForeignItemKind<'_>, 40); static_assert_size!(ForeignItemKind<'_>, 40);
static_assert_size!(GenericArg<'_>, 24); static_assert_size!(GenericArg<'_>, 32);
static_assert_size!(GenericBound<'_>, 48); static_assert_size!(GenericBound<'_>, 48);
static_assert_size!(Generics<'_>, 56); static_assert_size!(Generics<'_>, 56);
static_assert_size!(Impl<'_>, 80); static_assert_size!(Impl<'_>, 80);

View file

@ -733,6 +733,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
walk_list!(visitor, visit_arm, arms); walk_list!(visitor, visit_arm, arms);
} }
ExprKind::Closure(&Closure { ExprKind::Closure(&Closure {
def_id: _,
binder: _, binder: _,
bound_generic_params, bound_generic_params,
fn_decl, fn_decl,
@ -1084,7 +1085,7 @@ pub fn walk_enum_def<'v, V: Visitor<'v>>(
pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, variant: &'v Variant<'v>) { pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, variant: &'v Variant<'v>) {
visitor.visit_ident(variant.ident); visitor.visit_ident(variant.ident);
visitor.visit_id(variant.id); visitor.visit_id(variant.hir_id);
visitor.visit_variant_data(&variant.data); visitor.visit_variant_data(&variant.data);
walk_list!(visitor, visit_anon_const, &variant.disr_expr); walk_list!(visitor, visit_anon_const, &variant.disr_expr);
} }

View file

@ -432,7 +432,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
ty::Const::from_opt_const_arg_anon_const( ty::Const::from_opt_const_arg_anon_const(
tcx, tcx,
ty::WithOptConstParam { ty::WithOptConstParam {
did: tcx.hir().local_def_id(ct.value.hir_id), did: ct.value.def_id,
const_param_did: Some(param.def_id), const_param_did: Some(param.def_id),
}, },
) )
@ -570,8 +570,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
ConvertedBindingKind::Equality(self.ast_ty_to_ty(ty).into()) ConvertedBindingKind::Equality(self.ast_ty_to_ty(ty).into())
} }
hir::Term::Const(ref c) => { hir::Term::Const(ref c) => {
let local_did = self.tcx().hir().local_def_id(c.hir_id); let c = Const::from_anon_const(self.tcx(), c.def_id);
let c = Const::from_anon_const(self.tcx(), local_did);
ConvertedBindingKind::Equality(c.into()) ConvertedBindingKind::Equality(c.into())
} }
}, },
@ -856,7 +855,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&self, &self,
bounds: &mut Bounds<'hir>, bounds: &mut Bounds<'hir>,
ast_bounds: &'hir [hir::GenericBound<'hir>], ast_bounds: &'hir [hir::GenericBound<'hir>],
self_ty_where_predicates: Option<(hir::HirId, &'hir [hir::WherePredicate<'hir>])>, self_ty_where_predicates: Option<(LocalDefId, &'hir [hir::WherePredicate<'hir>])>,
span: Span, span: Span,
) { ) {
let tcx = self.tcx(); let tcx = self.tcx();
@ -876,10 +875,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}; };
search_bounds(ast_bounds); search_bounds(ast_bounds);
if let Some((self_ty, where_clause)) = self_ty_where_predicates { if let Some((self_ty, where_clause)) = self_ty_where_predicates {
let self_ty_def_id = tcx.hir().local_def_id(self_ty).to_def_id();
for clause in where_clause { for clause in where_clause {
if let hir::WherePredicate::BoundPredicate(pred) = clause { if let hir::WherePredicate::BoundPredicate(pred) = clause {
if pred.is_param_bound(self_ty_def_id) { if pred.is_param_bound(self_ty.to_def_id()) {
search_bounds(pred.bounds); search_bounds(pred.bounds);
} }
} }
@ -2722,8 +2720,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let length = match length { let length = match length {
&hir::ArrayLen::Infer(_, span) => self.ct_infer(tcx.types.usize, None, span), &hir::ArrayLen::Infer(_, span) => self.ct_infer(tcx.types.usize, None, span),
hir::ArrayLen::Body(constant) => { hir::ArrayLen::Body(constant) => {
let length_def_id = tcx.hir().local_def_id(constant.hir_id); ty::Const::from_anon_const(tcx, constant.def_id)
ty::Const::from_anon_const(tcx, length_def_id)
} }
}; };
@ -2731,7 +2728,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.normalize_ty(ast_ty.span, array_ty) self.normalize_ty(ast_ty.span, array_ty)
} }
hir::TyKind::Typeof(ref e) => { hir::TyKind::Typeof(ref e) => {
let ty_erased = tcx.type_of(tcx.hir().local_def_id(e.hir_id)); let ty_erased = tcx.type_of(e.def_id);
let ty = tcx.fold_regions(ty_erased, |r, _| { let ty = tcx.fold_regions(ty_erased, |r, _| {
if r.is_erased() { tcx.lifetimes.re_static } else { r } if r.is_erased() { tcx.lifetimes.re_static } else { r }
}); });

View file

@ -853,7 +853,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
// Const parameters are well formed if their type is structural match. // Const parameters are well formed if their type is structural match.
hir::GenericParamKind::Const { ty: hir_ty, default: _ } => { hir::GenericParamKind::Const { ty: hir_ty, default: _ } => {
let ty = tcx.type_of(tcx.hir().local_def_id(param.hir_id)); let ty = tcx.type_of(param.def_id);
if tcx.features().adt_const_params { if tcx.features().adt_const_params {
if let Some(non_structural_match_ty) = if let Some(non_structural_match_ty) =

View file

@ -291,18 +291,15 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
match param.kind { match param.kind {
hir::GenericParamKind::Lifetime { .. } => {} hir::GenericParamKind::Lifetime { .. } => {}
hir::GenericParamKind::Type { default: Some(_), .. } => { hir::GenericParamKind::Type { default: Some(_), .. } => {
let def_id = self.tcx.hir().local_def_id(param.hir_id); self.tcx.ensure().type_of(param.def_id);
self.tcx.ensure().type_of(def_id);
} }
hir::GenericParamKind::Type { .. } => {} hir::GenericParamKind::Type { .. } => {}
hir::GenericParamKind::Const { default, .. } => { hir::GenericParamKind::Const { default, .. } => {
let def_id = self.tcx.hir().local_def_id(param.hir_id); self.tcx.ensure().type_of(param.def_id);
self.tcx.ensure().type_of(def_id);
if let Some(default) = default { if let Some(default) = default {
let default_def_id = self.tcx.hir().local_def_id(default.hir_id);
// need to store default and type of default // need to store default and type of default
self.tcx.ensure().type_of(default_def_id); self.tcx.ensure().type_of(default.def_id);
self.tcx.ensure().const_param_default(def_id); self.tcx.ensure().const_param_default(param.def_id);
} }
} }
} }
@ -311,9 +308,9 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
} }
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
if let hir::ExprKind::Closure { .. } = expr.kind { if let hir::ExprKind::Closure(closure) = expr.kind {
let def_id = self.tcx.hir().local_def_id(expr.hir_id); self.tcx.ensure().generics_of(closure.def_id);
self.tcx.ensure().generics_of(def_id); self.tcx.ensure().codegen_fn_attrs(closure.def_id);
// We do not call `type_of` for closures here as that // We do not call `type_of` for closures here as that
// depends on typecheck and would therefore hide // depends on typecheck and would therefore hide
// any further errors in case one typeck fails. // any further errors in case one typeck fails.
@ -586,8 +583,12 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
tcx.ensure().type_of(item.owner_id); tcx.ensure().type_of(item.owner_id);
tcx.ensure().predicates_of(item.owner_id); tcx.ensure().predicates_of(item.owner_id);
match item.kind { match item.kind {
hir::ForeignItemKind::Fn(..) => tcx.ensure().fn_sig(item.owner_id), hir::ForeignItemKind::Fn(..) => {
tcx.ensure().codegen_fn_attrs(item.owner_id);
tcx.ensure().fn_sig(item.owner_id)
}
hir::ForeignItemKind::Static(..) => { hir::ForeignItemKind::Static(..) => {
tcx.ensure().codegen_fn_attrs(item.owner_id);
let mut visitor = HirPlaceholderCollector::default(); let mut visitor = HirPlaceholderCollector::default();
visitor.visit_foreign_item(item); visitor.visit_foreign_item(item);
placeholder_type_error( placeholder_type_error(
@ -632,14 +633,12 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
tcx.ensure().predicates_of(def_id); tcx.ensure().predicates_of(def_id);
for f in struct_def.fields() { for f in struct_def.fields() {
let def_id = tcx.hir().local_def_id(f.hir_id); tcx.ensure().generics_of(f.def_id);
tcx.ensure().generics_of(def_id); tcx.ensure().type_of(f.def_id);
tcx.ensure().type_of(def_id); tcx.ensure().predicates_of(f.def_id);
tcx.ensure().predicates_of(def_id);
} }
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() { if let Some(ctor_def_id) = struct_def.ctor_def_id() {
let ctor_def_id = tcx.hir().local_def_id(ctor_hir_id);
convert_variant_ctor(tcx, ctor_def_id); convert_variant_ctor(tcx, ctor_def_id);
} }
} }
@ -676,6 +675,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
tcx.ensure().type_of(def_id); tcx.ensure().type_of(def_id);
tcx.ensure().predicates_of(def_id); tcx.ensure().predicates_of(def_id);
tcx.ensure().fn_sig(def_id); tcx.ensure().fn_sig(def_id);
tcx.ensure().codegen_fn_attrs(def_id);
} }
} }
} }
@ -687,6 +687,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
match trait_item.kind { match trait_item.kind {
hir::TraitItemKind::Fn(..) => { hir::TraitItemKind::Fn(..) => {
tcx.ensure().codegen_fn_attrs(def_id);
tcx.ensure().type_of(def_id); tcx.ensure().type_of(def_id);
tcx.ensure().fn_sig(def_id); tcx.ensure().fn_sig(def_id);
} }
@ -736,6 +737,7 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
let impl_item = tcx.hir().impl_item(impl_item_id); let impl_item = tcx.hir().impl_item(impl_item_id);
match impl_item.kind { match impl_item.kind {
hir::ImplItemKind::Fn(..) => { hir::ImplItemKind::Fn(..) => {
tcx.ensure().codegen_fn_attrs(def_id);
tcx.ensure().fn_sig(def_id); tcx.ensure().fn_sig(def_id);
} }
hir::ImplItemKind::Type(_) => { hir::ImplItemKind::Type(_) => {
@ -813,7 +815,6 @@ fn convert_variant(
.fields() .fields()
.iter() .iter()
.map(|f| { .map(|f| {
let fid = tcx.hir().local_def_id(f.hir_id);
let dup_span = seen_fields.get(&f.ident.normalize_to_macros_2_0()).cloned(); let dup_span = seen_fields.get(&f.ident.normalize_to_macros_2_0()).cloned();
if let Some(prev_span) = dup_span { if let Some(prev_span) = dup_span {
tcx.sess.emit_err(errors::FieldAlreadyDeclared { tcx.sess.emit_err(errors::FieldAlreadyDeclared {
@ -825,7 +826,11 @@ fn convert_variant(
seen_fields.insert(f.ident.normalize_to_macros_2_0(), f.span); seen_fields.insert(f.ident.normalize_to_macros_2_0(), f.span);
} }
ty::FieldDef { did: fid.to_def_id(), name: f.ident.name, vis: tcx.visibility(fid) } ty::FieldDef {
did: f.def_id.to_def_id(),
name: f.ident.name,
vis: tcx.visibility(f.def_id),
}
}) })
.collect(); .collect();
let recovered = match def { let recovered = match def {
@ -866,13 +871,9 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
.variants .variants
.iter() .iter()
.map(|v| { .map(|v| {
let variant_did = Some(tcx.hir().local_def_id(v.id));
let ctor_did =
v.data.ctor_hir_id().map(|hir_id| tcx.hir().local_def_id(hir_id));
let discr = if let Some(ref e) = v.disr_expr { let discr = if let Some(ref e) = v.disr_expr {
distance_from_explicit = 0; distance_from_explicit = 0;
ty::VariantDiscr::Explicit(tcx.hir().local_def_id(e.hir_id).to_def_id()) ty::VariantDiscr::Explicit(e.def_id.to_def_id())
} else { } else {
ty::VariantDiscr::Relative(distance_from_explicit) ty::VariantDiscr::Relative(distance_from_explicit)
}; };
@ -880,8 +881,8 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
convert_variant( convert_variant(
tcx, tcx,
variant_did, Some(v.def_id),
ctor_did, v.data.ctor_def_id(),
v.ident, v.ident,
discr, discr,
&v.data, &v.data,
@ -894,13 +895,10 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
(AdtKind::Enum, variants) (AdtKind::Enum, variants)
} }
ItemKind::Struct(ref def, _) => { ItemKind::Struct(ref def, _) => {
let variant_did = None::<LocalDefId>;
let ctor_did = def.ctor_hir_id().map(|hir_id| tcx.hir().local_def_id(hir_id));
let variants = std::iter::once(convert_variant( let variants = std::iter::once(convert_variant(
tcx, tcx,
variant_did, None,
ctor_did, def.ctor_def_id(),
item.ident, item.ident,
ty::VariantDiscr::Relative(0), ty::VariantDiscr::Relative(0),
def, def,
@ -912,13 +910,10 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
(AdtKind::Struct, variants) (AdtKind::Struct, variants)
} }
ItemKind::Union(ref def, _) => { ItemKind::Union(ref def, _) => {
let variant_did = None;
let ctor_did = def.ctor_hir_id().map(|hir_id| tcx.hir().local_def_id(hir_id));
let variants = std::iter::once(convert_variant( let variants = std::iter::once(convert_variant(
tcx, tcx,
variant_did, None,
ctor_did, def.ctor_def_id(),
item.ident, item.ident,
ty::VariantDiscr::Relative(0), ty::VariantDiscr::Relative(0),
def, def,
@ -1178,8 +1173,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor_hir_id().is_some() => { Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor_hir_id().is_some() => {
let ty = tcx.type_of(tcx.hir().get_parent_item(hir_id)); let ty = tcx.type_of(tcx.hir().get_parent_item(hir_id));
let inputs = let inputs = data.fields().iter().map(|f| tcx.type_of(f.def_id));
data.fields().iter().map(|f| tcx.type_of(tcx.hir().local_def_id(f.hir_id)));
ty::Binder::dummy(tcx.mk_fn_sig( ty::Binder::dummy(tcx.mk_fn_sig(
inputs, inputs,
ty, ty,

View file

@ -51,7 +51,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
// of a const parameter type, e.g. `struct Foo<const N: usize, const M: [u8; N]>` is not allowed. // of a const parameter type, e.g. `struct Foo<const N: usize, const M: [u8; N]>` is not allowed.
None None
} else if tcx.lazy_normalization() { } else if tcx.lazy_normalization() {
if let Some(param_id) = tcx.hir().opt_const_param_default_param_hir_id(hir_id) { if let Some(param_id) = tcx.hir().opt_const_param_default_param_def_id(hir_id) {
// If the def_id we are calling generics_of on is an anon ct default i.e: // If the def_id we are calling generics_of on is an anon ct default i.e:
// //
// struct Foo<const N: usize = { .. }>; // struct Foo<const N: usize = { .. }>;
@ -77,8 +77,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
// This has some implications for how we get the predicates available to the anon const // This has some implications for how we get the predicates available to the anon const
// see `explicit_predicates_of` for more information on this // see `explicit_predicates_of` for more information on this
let generics = tcx.generics_of(parent_def_id.to_def_id()); let generics = tcx.generics_of(parent_def_id.to_def_id());
let param_def = tcx.hir().local_def_id(param_id).to_def_id(); let param_def_idx = generics.param_def_id_to_index[&param_id.to_def_id()];
let param_def_idx = generics.param_def_id_to_index[&param_def];
// In the above example this would be .params[..N#0] // In the above example this would be .params[..N#0]
let params = generics.params[..param_def_idx as usize].to_owned(); let params = generics.params[..param_def_idx as usize].to_owned();
let param_def_id_to_index = let param_def_id_to_index =
@ -241,7 +240,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
params.extend(early_lifetimes.enumerate().map(|(i, param)| ty::GenericParamDef { params.extend(early_lifetimes.enumerate().map(|(i, param)| ty::GenericParamDef {
name: param.name.ident().name, name: param.name.ident().name,
index: own_start + i as u32, index: own_start + i as u32,
def_id: tcx.hir().local_def_id(param.hir_id).to_def_id(), def_id: param.def_id.to_def_id(),
pure_wrt_drop: param.pure_wrt_drop, pure_wrt_drop: param.pure_wrt_drop,
kind: ty::GenericParamDefKind::Lifetime, kind: ty::GenericParamDefKind::Lifetime,
})); }));
@ -286,7 +285,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
Some(ty::GenericParamDef { Some(ty::GenericParamDef {
index: next_index(), index: next_index(),
name: param.name.ident().name, name: param.name.ident().name,
def_id: tcx.hir().local_def_id(param.hir_id).to_def_id(), def_id: param.def_id.to_def_id(),
pure_wrt_drop: param.pure_wrt_drop, pure_wrt_drop: param.pure_wrt_drop,
kind, kind,
}) })
@ -303,7 +302,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
Some(ty::GenericParamDef { Some(ty::GenericParamDef {
index: next_index(), index: next_index(),
name: param.name.ident().name, name: param.name.ident().name,
def_id: tcx.hir().local_def_id(param.hir_id).to_def_id(), def_id: param.def_id.to_def_id(),
pure_wrt_drop: param.pure_wrt_drop, pure_wrt_drop: param.pure_wrt_drop,
kind: ty::GenericParamDefKind::Const { has_default: default.is_some() }, kind: ty::GenericParamDefKind::Const { has_default: default.is_some() },
}) })

View file

@ -15,7 +15,6 @@ use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirIdMap, LifetimeName, Node}; use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirIdMap, LifetimeName, Node};
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::hir::map::Map;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::middle::resolve_lifetime::*; use rustc_middle::middle::resolve_lifetime::*;
use rustc_middle::ty::{self, DefIdTree, TyCtxt, TypeSuperVisitable, TypeVisitor}; use rustc_middle::ty::{self, DefIdTree, TyCtxt, TypeSuperVisitable, TypeVisitor};
@ -25,9 +24,9 @@ use rustc_span::Span;
use std::fmt; use std::fmt;
trait RegionExt { trait RegionExt {
fn early(hir_map: Map<'_>, param: &GenericParam<'_>) -> (LocalDefId, Region); fn early(param: &GenericParam<'_>) -> (LocalDefId, Region);
fn late(index: u32, hir_map: Map<'_>, param: &GenericParam<'_>) -> (LocalDefId, Region); fn late(index: u32, param: &GenericParam<'_>) -> (LocalDefId, Region);
fn id(&self) -> Option<DefId>; fn id(&self) -> Option<DefId>;
@ -35,20 +34,18 @@ trait RegionExt {
} }
impl RegionExt for Region { impl RegionExt for Region {
fn early(hir_map: Map<'_>, param: &GenericParam<'_>) -> (LocalDefId, Region) { fn early(param: &GenericParam<'_>) -> (LocalDefId, Region) {
let def_id = hir_map.local_def_id(param.hir_id); debug!("Region::early: def_id={:?}", param.def_id);
debug!("Region::early: def_id={:?}", def_id); (param.def_id, Region::EarlyBound(param.def_id.to_def_id()))
(def_id, Region::EarlyBound(def_id.to_def_id()))
} }
fn late(idx: u32, hir_map: Map<'_>, param: &GenericParam<'_>) -> (LocalDefId, Region) { fn late(idx: u32, param: &GenericParam<'_>) -> (LocalDefId, Region) {
let depth = ty::INNERMOST; let depth = ty::INNERMOST;
let def_id = hir_map.local_def_id(param.hir_id);
debug!( debug!(
"Region::late: idx={:?}, param={:?} depth={:?} def_id={:?}", "Region::late: idx={:?}, param={:?} depth={:?} def_id={:?}",
idx, param, depth, def_id, idx, param, depth, param.def_id,
); );
(def_id, Region::LateBound(depth, idx, def_id.to_def_id())) (param.def_id, Region::LateBound(depth, idx, param.def_id.to_def_id()))
} }
fn id(&self) -> Option<DefId> { fn id(&self) -> Option<DefId> {
@ -395,7 +392,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
.filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. })) .filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
.enumerate() .enumerate()
.map(|(late_bound_idx, param)| { .map(|(late_bound_idx, param)| {
let pair = Region::late(late_bound_idx as u32, self.tcx.hir(), param); let pair = Region::late(late_bound_idx as u32, param);
let r = late_region_as_bound_region(self.tcx, &pair.1); let r = late_region_as_bound_region(self.tcx, &pair.1);
(pair, r) (pair, r)
}) })
@ -492,7 +489,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
for param in generics.params { for param in generics.params {
match param.kind { match param.kind {
GenericParamKind::Lifetime { .. } => { GenericParamKind::Lifetime { .. } => {
let (def_id, reg) = Region::early(self.tcx.hir(), &param); let (def_id, reg) = Region::early(&param);
lifetimes.insert(def_id, reg); lifetimes.insert(def_id, reg);
} }
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {} GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {}
@ -523,9 +520,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
.params .params
.iter() .iter()
.filter_map(|param| match param.kind { .filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => { GenericParamKind::Lifetime { .. } => Some(Region::early(param)),
Some(Region::early(self.tcx.hir(), param))
}
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => None, GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => None,
}) })
.collect(); .collect();
@ -573,7 +568,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
.filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. })) .filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
.enumerate() .enumerate()
.map(|(late_bound_idx, param)| { .map(|(late_bound_idx, param)| {
let pair = Region::late(late_bound_idx as u32, self.tcx.hir(), param); let pair = Region::late(late_bound_idx as u32, param);
let r = late_region_as_bound_region(self.tcx, &pair.1); let r = late_region_as_bound_region(self.tcx, &pair.1);
(pair, r) (pair, r)
}) })
@ -731,9 +726,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
.params .params
.iter() .iter()
.filter_map(|param| match param.kind { .filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => { GenericParamKind::Lifetime { .. } => Some(Region::early(param)),
Some(Region::early(self.tcx.hir(), param))
}
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => None, GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => None,
}) })
.collect(); .collect();
@ -779,9 +772,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
.params .params
.iter() .iter()
.filter_map(|param| match param.kind { .filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => { GenericParamKind::Lifetime { .. } => Some(Region::early(param)),
Some(Region::early(self.tcx.hir(), param))
}
GenericParamKind::Const { .. } | GenericParamKind::Type { .. } => None, GenericParamKind::Const { .. } | GenericParamKind::Type { .. } => None,
}) })
.collect(); .collect();
@ -886,7 +877,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
}) })
.enumerate() .enumerate()
.map(|(late_bound_idx, param)| { .map(|(late_bound_idx, param)| {
Region::late(late_bound_idx as u32, this.tcx.hir(), param) Region::late(late_bound_idx as u32, param)
}) })
.collect(); .collect();
let binders: Vec<_> = let binders: Vec<_> =
@ -999,8 +990,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
.filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. })) .filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
.enumerate() .enumerate()
.map(|(late_bound_idx, param)| { .map(|(late_bound_idx, param)| {
let pair = let pair = Region::late(initial_bound_vars + late_bound_idx as u32, param);
Region::late(initial_bound_vars + late_bound_idx as u32, self.tcx.hir(), param);
let r = late_region_as_bound_region(self.tcx, &pair.1); let r = late_region_as_bound_region(self.tcx, &pair.1);
lifetimes.insert(pair.0, pair.1); lifetimes.insert(pair.0, pair.1);
r r
@ -1131,9 +1121,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
if self.tcx.is_late_bound(param.hir_id) { if self.tcx.is_late_bound(param.hir_id) {
let late_bound_idx = named_late_bound_vars; let late_bound_idx = named_late_bound_vars;
named_late_bound_vars += 1; named_late_bound_vars += 1;
Some(Region::late(late_bound_idx, self.tcx.hir(), param)) Some(Region::late(late_bound_idx, param))
} else { } else {
Some(Region::early(self.tcx.hir(), param)) Some(Region::early(param))
} }
} }
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => None, GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => None,
@ -1149,7 +1139,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}) })
.enumerate() .enumerate()
.map(|(late_bound_idx, param)| { .map(|(late_bound_idx, param)| {
let pair = Region::late(late_bound_idx as u32, self.tcx.hir(), param); let pair = Region::late(late_bound_idx as u32, param);
late_region_as_bound_region(self.tcx, &pair.1) late_region_as_bound_region(self.tcx, &pair.1)
}) })
.collect(); .collect();

View file

@ -199,7 +199,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
&icx, &icx,
&mut bounds, &mut bounds,
&[], &[],
Some((param.hir_id, ast_generics.predicates)), Some((param.def_id, ast_generics.predicates)),
param.span, param.span,
); );
trace!(?bounds); trace!(?bounds);
@ -316,10 +316,9 @@ fn const_evaluatable_predicates_of<'tcx>(
impl<'tcx> intravisit::Visitor<'tcx> for ConstCollector<'tcx> { impl<'tcx> intravisit::Visitor<'tcx> for ConstCollector<'tcx> {
fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) { fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
let def_id = self.tcx.hir().local_def_id(c.hir_id); let ct = ty::Const::from_anon_const(self.tcx, c.def_id);
let ct = ty::Const::from_anon_const(self.tcx, def_id);
if let ty::ConstKind::Unevaluated(_) = ct.kind() { if let ty::ConstKind::Unevaluated(_) = ct.kind() {
let span = self.tcx.hir().span(c.hir_id); let span = self.tcx.def_span(c.def_id);
self.preds.insert(( self.preds.insert((
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(ct)) ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(ct))
.to_predicate(self.tcx), .to_predicate(self.tcx),
@ -429,7 +428,7 @@ pub(super) fn explicit_predicates_of<'tcx>(
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let parent_def_id = tcx.hir().get_parent_item(hir_id); let parent_def_id = tcx.hir().get_parent_item(hir_id);
if tcx.hir().opt_const_param_default_param_hir_id(hir_id).is_some() { if tcx.hir().opt_const_param_default_param_def_id(hir_id).is_some() {
// In `generics_of` we set the generics' parent to be our parent's parent which means that // In `generics_of` we set the generics' parent to be our parent's parent which means that
// we lose out on the predicates of our actual parent if we dont return those predicates here. // we lose out on the predicates of our actual parent if we dont return those predicates here.
// (See comment in `generics_of` for more information on why the parent shenanigans is necessary) // (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
@ -531,7 +530,7 @@ pub(super) fn super_predicates_that_define_assoc_type(
let is_trait_alias = tcx.is_trait_alias(trait_def_id); let is_trait_alias = tcx.is_trait_alias(trait_def_id);
let superbounds2 = icx.type_parameter_bounds_in_generics( let superbounds2 = icx.type_parameter_bounds_in_generics(
generics, generics,
item.hir_id(), item.owner_id.def_id,
self_param_ty, self_param_ty,
OnlySelfBounds(!is_trait_alias), OnlySelfBounds(!is_trait_alias),
assoc_name, assoc_name,
@ -641,7 +640,7 @@ pub(super) fn type_param_predicates(
let extra_predicates = extend.into_iter().chain( let extra_predicates = extend.into_iter().chain(
icx.type_parameter_bounds_in_generics( icx.type_parameter_bounds_in_generics(
ast_generics, ast_generics,
param_id, def_id,
ty, ty,
OnlySelfBounds(true), OnlySelfBounds(true),
Some(assoc_name), Some(assoc_name),
@ -666,13 +665,11 @@ impl<'tcx> ItemCtxt<'tcx> {
fn type_parameter_bounds_in_generics( fn type_parameter_bounds_in_generics(
&self, &self,
ast_generics: &'tcx hir::Generics<'tcx>, ast_generics: &'tcx hir::Generics<'tcx>,
param_id: hir::HirId, param_def_id: LocalDefId,
ty: Ty<'tcx>, ty: Ty<'tcx>,
only_self_bounds: OnlySelfBounds, only_self_bounds: OnlySelfBounds,
assoc_name: Option<Ident>, assoc_name: Option<Ident>,
) -> Vec<(ty::Predicate<'tcx>, Span)> { ) -> Vec<(ty::Predicate<'tcx>, Span)> {
let param_def_id = self.tcx.hir().local_def_id(param_id).to_def_id();
trace!(?param_def_id);
ast_generics ast_generics
.predicates .predicates
.iter() .iter()
@ -681,7 +678,7 @@ impl<'tcx> ItemCtxt<'tcx> {
_ => None, _ => None,
}) })
.flat_map(|bp| { .flat_map(|bp| {
let bt = if bp.is_param_bound(param_def_id) { let bt = if bp.is_param_bound(param_def_id.to_def_id()) {
Some(ty) Some(ty)
} else if !only_self_bounds.0 { } else if !only_self_bounds.0 {
Some(self.to_ty(bp.bounded_ty)) Some(self.to_ty(bp.bounded_ty))

View file

@ -514,10 +514,10 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
} }
Node::GenericParam(&GenericParam { Node::GenericParam(&GenericParam {
hir_id: param_hir_id, def_id: param_def_id,
kind: GenericParamKind::Const { default: Some(ct), .. }, kind: GenericParamKind::Const { default: Some(ct), .. },
.. ..
}) if ct.hir_id == hir_id => tcx.type_of(tcx.hir().local_def_id(param_hir_id)), }) if ct.hir_id == hir_id => tcx.type_of(param_def_id),
x => tcx.ty_error_with_message( x => tcx.ty_error_with_message(
DUMMY_SP, DUMMY_SP,
@ -636,9 +636,8 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
self.tcx.hir() self.tcx.hir()
} }
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) { fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
if let hir::ExprKind::Closure { .. } = ex.kind { if let hir::ExprKind::Closure(closure) = ex.kind {
let def_id = self.tcx.hir().local_def_id(ex.hir_id); self.check(closure.def_id);
self.check(def_id);
} }
intravisit::walk_expr(self, ex); intravisit::walk_expr(self, ex);
} }
@ -771,9 +770,8 @@ fn find_opaque_ty_constraints_for_rpit(
self.tcx.hir() self.tcx.hir()
} }
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) { fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
if let hir::ExprKind::Closure { .. } = ex.kind { if let hir::ExprKind::Closure(closure) = ex.kind {
let def_id = self.tcx.hir().local_def_id(ex.hir_id); self.check(closure.def_id);
self.check(def_id);
} }
intravisit::walk_expr(self, ex); intravisit::walk_expr(self, ex);
} }

View file

@ -22,7 +22,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
if matches!(tcx.def_kind(item_def_id), hir::def::DefKind::AnonConst) && tcx.lazy_normalization() if matches!(tcx.def_kind(item_def_id), hir::def::DefKind::AnonConst) && tcx.lazy_normalization()
{ {
if tcx.hir().opt_const_param_default_param_hir_id(id).is_some() { if tcx.hir().opt_const_param_default_param_def_id(id).is_some() {
// In `generics_of` we set the generics' parent to be our parent's parent which means that // In `generics_of` we set the generics' parent to be our parent's parent which means that
// we lose out on the predicates of our actual parent if we dont return those predicates here. // we lose out on the predicates of our actual parent if we dont return those predicates here.
// (See comment in `generics_of` for more information on why the parent shenanigans is necessary) // (See comment in `generics_of` for more information on why the parent shenanigans is necessary)

View file

@ -754,7 +754,7 @@ impl<'a> State<'a> {
for v in variants { for v in variants {
self.space_if_not_bol(); self.space_if_not_bol();
self.maybe_print_comment(v.span.lo()); self.maybe_print_comment(v.span.lo());
self.print_outer_attributes(self.attrs(v.id)); self.print_outer_attributes(self.attrs(v.hir_id));
self.ibox(INDENT_UNIT); self.ibox(INDENT_UNIT);
self.print_variant(v); self.print_variant(v);
self.word(","); self.word(",");
@ -1481,6 +1481,7 @@ impl<'a> State<'a> {
body, body,
fn_decl_span: _, fn_decl_span: _,
movability: _, movability: _,
def_id: _,
}) => { }) => {
self.print_closure_binder(binder, bound_generic_params); self.print_closure_binder(binder, bound_generic_params);
self.print_capture_clause(capture_clause); self.print_capture_clause(capture_clause);

View file

@ -26,10 +26,12 @@ pub(super) fn check_fn<'a, 'tcx>(
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
fn_sig: ty::FnSig<'tcx>, fn_sig: ty::FnSig<'tcx>,
decl: &'tcx hir::FnDecl<'tcx>, decl: &'tcx hir::FnDecl<'tcx>,
fn_id: hir::HirId, fn_def_id: LocalDefId,
body: &'tcx hir::Body<'tcx>, body: &'tcx hir::Body<'tcx>,
can_be_generator: Option<hir::Movability>, can_be_generator: Option<hir::Movability>,
) -> (FnCtxt<'a, 'tcx>, Option<GeneratorTypes<'tcx>>) { ) -> (FnCtxt<'a, 'tcx>, Option<GeneratorTypes<'tcx>>) {
let fn_id = inherited.tcx.hir().local_def_id_to_hir_id(fn_def_id);
// Create the function context. This is either derived from scratch or, // Create the function context. This is either derived from scratch or,
// in the case of closures, based on the outer context. // in the case of closures, based on the outer context.
let mut fcx = FnCtxt::new(inherited, param_env, body.value.hir_id); let mut fcx = FnCtxt::new(inherited, param_env, body.value.hir_id);

View file

@ -4,7 +4,7 @@ use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
use hir::def::DefKind; use hir::def::DefKind;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir_analysis::astconv::AstConv; use rustc_hir_analysis::astconv::AstConv;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@ -41,18 +41,14 @@ struct ClosureSignatures<'tcx> {
} }
impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[instrument(skip(self, expr, _capture, decl, body_id), level = "debug")] #[instrument(skip(self, closure), level = "debug")]
pub fn check_expr_closure( pub fn check_expr_closure(
&self, &self,
expr: &hir::Expr<'_>, closure: &hir::Closure<'tcx>,
_capture: hir::CaptureBy, expr_span: Span,
decl: &'tcx hir::FnDecl<'tcx>,
body_id: hir::BodyId,
gen: Option<hir::Movability>,
expected: Expectation<'tcx>, expected: Expectation<'tcx>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
trace!("decl = {:#?}", decl); trace!("decl = {:#?}", closure.fn_decl);
trace!("expr = {:#?}", expr);
// It's always helpful for inference if we know the kind of // It's always helpful for inference if we know the kind of
// closure sooner rather than later, so first examine the expected // closure sooner rather than later, so first examine the expected
@ -61,26 +57,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(ty) => self.deduce_expectations_from_expected_type(ty), Some(ty) => self.deduce_expectations_from_expected_type(ty),
None => (None, None), None => (None, None),
}; };
let body = self.tcx.hir().body(body_id); let body = self.tcx.hir().body(closure.body);
self.check_closure(expr, expected_kind, decl, body, gen, expected_sig) self.check_closure(closure, expr_span, expected_kind, body, expected_sig)
} }
#[instrument(skip(self, expr, body, decl), level = "debug", ret)] #[instrument(skip(self, closure, body), level = "debug", ret)]
fn check_closure( fn check_closure(
&self, &self,
expr: &hir::Expr<'_>, closure: &hir::Closure<'tcx>,
expr_span: Span,
opt_kind: Option<ty::ClosureKind>, opt_kind: Option<ty::ClosureKind>,
decl: &'tcx hir::FnDecl<'tcx>,
body: &'tcx hir::Body<'tcx>, body: &'tcx hir::Body<'tcx>,
gen: Option<hir::Movability>,
expected_sig: Option<ExpectedSig<'tcx>>, expected_sig: Option<ExpectedSig<'tcx>>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
trace!("decl = {:#?}", decl); trace!("decl = {:#?}", closure.fn_decl);
let expr_def_id = self.tcx.hir().local_def_id(expr.hir_id); let expr_def_id = closure.def_id;
debug!(?expr_def_id); debug!(?expr_def_id);
let ClosureSignatures { bound_sig, liberated_sig } = let ClosureSignatures { bound_sig, liberated_sig } =
self.sig_of_closure(expr.hir_id, expr_def_id.to_def_id(), decl, body, expected_sig); self.sig_of_closure(expr_def_id, closure.fn_decl, body, expected_sig);
debug!(?bound_sig, ?liberated_sig); debug!(?bound_sig, ?liberated_sig);
@ -88,10 +83,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self, self,
self.param_env.without_const(), self.param_env.without_const(),
liberated_sig, liberated_sig,
decl, closure.fn_decl,
expr.hir_id, expr_def_id,
body, body,
gen, closure.movability,
) )
.1; .1;
@ -102,7 +97,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let tupled_upvars_ty = self.next_ty_var(TypeVariableOrigin { let tupled_upvars_ty = self.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::ClosureSynthetic, kind: TypeVariableOriginKind::ClosureSynthetic,
span: self.tcx.hir().span(expr.hir_id), span: self.tcx.def_span(expr_def_id),
}); });
if let Some(GeneratorTypes { resume_ty, yield_ty, interior, movability }) = generator_types if let Some(GeneratorTypes { resume_ty, yield_ty, interior, movability }) = generator_types
@ -148,7 +143,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None => self.next_ty_var(TypeVariableOrigin { None => self.next_ty_var(TypeVariableOrigin {
// FIXME(eddyb) distinguish closure kind inference variables from the rest. // FIXME(eddyb) distinguish closure kind inference variables from the rest.
kind: TypeVariableOriginKind::ClosureSynthetic, kind: TypeVariableOriginKind::ClosureSynthetic,
span: expr.span, span: expr_span,
}), }),
}; };
@ -319,30 +314,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn sig_of_closure( fn sig_of_closure(
&self, &self,
hir_id: hir::HirId, expr_def_id: LocalDefId,
expr_def_id: DefId,
decl: &hir::FnDecl<'_>, decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>, body: &hir::Body<'_>,
expected_sig: Option<ExpectedSig<'tcx>>, expected_sig: Option<ExpectedSig<'tcx>>,
) -> ClosureSignatures<'tcx> { ) -> ClosureSignatures<'tcx> {
if let Some(e) = expected_sig { if let Some(e) = expected_sig {
self.sig_of_closure_with_expectation(hir_id, expr_def_id, decl, body, e) self.sig_of_closure_with_expectation(expr_def_id, decl, body, e)
} else { } else {
self.sig_of_closure_no_expectation(hir_id, expr_def_id, decl, body) self.sig_of_closure_no_expectation(expr_def_id, decl, body)
} }
} }
/// If there is no expected signature, then we will convert the /// If there is no expected signature, then we will convert the
/// types that the user gave into a signature. /// types that the user gave into a signature.
#[instrument(skip(self, hir_id, expr_def_id, decl, body), level = "debug")] #[instrument(skip(self, expr_def_id, decl, body), level = "debug")]
fn sig_of_closure_no_expectation( fn sig_of_closure_no_expectation(
&self, &self,
hir_id: hir::HirId, expr_def_id: LocalDefId,
expr_def_id: DefId,
decl: &hir::FnDecl<'_>, decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>, body: &hir::Body<'_>,
) -> ClosureSignatures<'tcx> { ) -> ClosureSignatures<'tcx> {
let bound_sig = self.supplied_sig_of_closure(hir_id, expr_def_id, decl, body); let bound_sig = self.supplied_sig_of_closure(expr_def_id, decl, body);
self.closure_sigs(expr_def_id, body, bound_sig) self.closure_sigs(expr_def_id, body, bound_sig)
} }
@ -388,17 +381,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// ///
/// # Arguments /// # Arguments
/// ///
/// - `expr_def_id`: the `DefId` of the closure expression /// - `expr_def_id`: the `LocalDefId` of the closure expression
/// - `decl`: the HIR declaration of the closure /// - `decl`: the HIR declaration of the closure
/// - `body`: the body of the closure /// - `body`: the body of the closure
/// - `expected_sig`: the expected signature (if any). Note that /// - `expected_sig`: the expected signature (if any). Note that
/// this is missing a binder: that is, there may be late-bound /// this is missing a binder: that is, there may be late-bound
/// regions with depth 1, which are bound then by the closure. /// regions with depth 1, which are bound then by the closure.
#[instrument(skip(self, hir_id, expr_def_id, decl, body), level = "debug")] #[instrument(skip(self, expr_def_id, decl, body), level = "debug")]
fn sig_of_closure_with_expectation( fn sig_of_closure_with_expectation(
&self, &self,
hir_id: hir::HirId, expr_def_id: LocalDefId,
expr_def_id: DefId,
decl: &hir::FnDecl<'_>, decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>, body: &hir::Body<'_>,
expected_sig: ExpectedSig<'tcx>, expected_sig: ExpectedSig<'tcx>,
@ -407,7 +399,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// expectation if things don't see to match up with what we // expectation if things don't see to match up with what we
// expect. // expect.
if expected_sig.sig.c_variadic() != decl.c_variadic { if expected_sig.sig.c_variadic() != decl.c_variadic {
return self.sig_of_closure_no_expectation(hir_id, expr_def_id, decl, body); return self.sig_of_closure_no_expectation(expr_def_id, decl, body);
} else if expected_sig.sig.skip_binder().inputs_and_output.len() != decl.inputs.len() + 1 { } else if expected_sig.sig.skip_binder().inputs_and_output.len() != decl.inputs.len() + 1 {
return self.sig_of_closure_with_mismatched_number_of_arguments( return self.sig_of_closure_with_mismatched_number_of_arguments(
expr_def_id, expr_def_id,
@ -443,27 +435,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Along the way, it also writes out entries for types that the user // Along the way, it also writes out entries for types that the user
// wrote into our typeck results, which are then later used by the privacy // wrote into our typeck results, which are then later used by the privacy
// check. // check.
match self.merge_supplied_sig_with_expectation( match self.merge_supplied_sig_with_expectation(expr_def_id, decl, body, closure_sigs) {
hir_id,
expr_def_id,
decl,
body,
closure_sigs,
) {
Ok(infer_ok) => self.register_infer_ok_obligations(infer_ok), Ok(infer_ok) => self.register_infer_ok_obligations(infer_ok),
Err(_) => self.sig_of_closure_no_expectation(hir_id, expr_def_id, decl, body), Err(_) => self.sig_of_closure_no_expectation(expr_def_id, decl, body),
} }
} }
fn sig_of_closure_with_mismatched_number_of_arguments( fn sig_of_closure_with_mismatched_number_of_arguments(
&self, &self,
expr_def_id: DefId, expr_def_id: LocalDefId,
decl: &hir::FnDecl<'_>, decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>, body: &hir::Body<'_>,
expected_sig: ExpectedSig<'tcx>, expected_sig: ExpectedSig<'tcx>,
) -> ClosureSignatures<'tcx> { ) -> ClosureSignatures<'tcx> {
let hir = self.tcx.hir(); let hir = self.tcx.hir();
let expr_map_node = hir.get_if_local(expr_def_id).unwrap(); let expr_map_node = hir.get_by_def_id(expr_def_id);
let expected_args: Vec<_> = expected_sig let expected_args: Vec<_> = expected_sig
.sig .sig
.skip_binder() .skip_binder()
@ -476,7 +462,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None => (None, Vec::new()), None => (None, Vec::new()),
}; };
let expected_span = let expected_span =
expected_sig.cause_span.unwrap_or_else(|| hir.span_if_local(expr_def_id).unwrap()); expected_sig.cause_span.unwrap_or_else(|| self.tcx.def_span(expr_def_id));
self.report_arg_count_mismatch( self.report_arg_count_mismatch(
expected_span, expected_span,
closure_span, closure_span,
@ -494,11 +480,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Enforce the user's types against the expectation. See /// Enforce the user's types against the expectation. See
/// `sig_of_closure_with_expectation` for details on the overall /// `sig_of_closure_with_expectation` for details on the overall
/// strategy. /// strategy.
#[instrument(level = "debug", skip(self, hir_id, expr_def_id, decl, body, expected_sigs))] #[instrument(level = "debug", skip(self, expr_def_id, decl, body, expected_sigs))]
fn merge_supplied_sig_with_expectation( fn merge_supplied_sig_with_expectation(
&self, &self,
hir_id: hir::HirId, expr_def_id: LocalDefId,
expr_def_id: DefId,
decl: &hir::FnDecl<'_>, decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>, body: &hir::Body<'_>,
mut expected_sigs: ClosureSignatures<'tcx>, mut expected_sigs: ClosureSignatures<'tcx>,
@ -507,7 +492,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// //
// (See comment on `sig_of_closure_with_expectation` for the // (See comment on `sig_of_closure_with_expectation` for the
// meaning of these letters.) // meaning of these letters.)
let supplied_sig = self.supplied_sig_of_closure(hir_id, expr_def_id, decl, body); let supplied_sig = self.supplied_sig_of_closure(expr_def_id, decl, body);
debug!(?supplied_sig); debug!(?supplied_sig);
@ -587,8 +572,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[instrument(skip(self, decl, body), level = "debug", ret)] #[instrument(skip(self, decl, body), level = "debug", ret)]
fn supplied_sig_of_closure( fn supplied_sig_of_closure(
&self, &self,
hir_id: hir::HirId, expr_def_id: LocalDefId,
expr_def_id: DefId,
decl: &hir::FnDecl<'_>, decl: &hir::FnDecl<'_>,
body: &hir::Body<'_>, body: &hir::Body<'_>,
) -> ty::PolyFnSig<'tcx> { ) -> ty::PolyFnSig<'tcx> {
@ -597,6 +581,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
trace!("decl = {:#?}", decl); trace!("decl = {:#?}", decl);
debug!(?body.generator_kind); debug!(?body.generator_kind);
let hir_id = self.tcx.hir().local_def_id_to_hir_id(expr_def_id);
let bound_vars = self.tcx.late_bound_vars(hir_id); let bound_vars = self.tcx.late_bound_vars(hir_id);
// First, convert the types that the user supplied (if any). // First, convert the types that the user supplied (if any).
@ -655,7 +640,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[instrument(skip(self), level = "debug", ret)] #[instrument(skip(self), level = "debug", ret)]
fn deduce_future_output_from_obligations( fn deduce_future_output_from_obligations(
&self, &self,
expr_def_id: DefId, expr_def_id: LocalDefId,
body_id: hir::HirId, body_id: hir::HirId,
) -> Option<Ty<'tcx>> { ) -> Option<Ty<'tcx>> {
let ret_coercion = self.ret_coercion.as_ref().unwrap_or_else(|| { let ret_coercion = self.ret_coercion.as_ref().unwrap_or_else(|| {
@ -804,14 +789,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn closure_sigs( fn closure_sigs(
&self, &self,
expr_def_id: DefId, expr_def_id: LocalDefId,
body: &hir::Body<'_>, body: &hir::Body<'_>,
bound_sig: ty::PolyFnSig<'tcx>, bound_sig: ty::PolyFnSig<'tcx>,
) -> ClosureSignatures<'tcx> { ) -> ClosureSignatures<'tcx> {
let liberated_sig = self.tcx().liberate_late_bound_regions(expr_def_id, bound_sig); let liberated_sig =
self.tcx().liberate_late_bound_regions(expr_def_id.to_def_id(), bound_sig);
let liberated_sig = self.inh.normalize_associated_types_in( let liberated_sig = self.inh.normalize_associated_types_in(
body.value.span, body.value.span,
body.value.hir_id, self.tcx.hir().local_def_id_to_hir_id(expr_def_id),
self.param_env, self.param_env,
liberated_sig, liberated_sig,
); );

View file

@ -30,7 +30,7 @@ use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir::{Closure, ExprKind, HirId, QPath}; use rustc_hir::{ExprKind, HirId, QPath};
use rustc_hir_analysis::astconv::AstConv as _; use rustc_hir_analysis::astconv::AstConv as _;
use rustc_hir_analysis::check::ty_kind_suggestion; use rustc_hir_analysis::check::ty_kind_suggestion;
use rustc_infer::infer; use rustc_infer::infer;
@ -324,9 +324,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ExprKind::Match(discrim, arms, match_src) => { ExprKind::Match(discrim, arms, match_src) => {
self.check_match(expr, &discrim, arms, expected, match_src) self.check_match(expr, &discrim, arms, expected, match_src)
} }
ExprKind::Closure(&Closure { capture_clause, fn_decl, body, movability, .. }) => { ExprKind::Closure(closure) => self.check_expr_closure(closure, expr.span, expected),
self.check_expr_closure(expr, capture_clause, &fn_decl, body, movability, expected)
}
ExprKind::Block(body, _) => self.check_block_with_expected(&body, expected), ExprKind::Block(body, _) => self.check_block_with_expected(&body, expected),
ExprKind::Call(callee, args) => self.check_call(expr, &callee, args, expected), ExprKind::Call(callee, args) => self.check_call(expr, &callee, args, expected),
ExprKind::MethodCall(segment, receiver, args, _) => { ExprKind::MethodCall(segment, receiver, args, _) => {

View file

@ -352,8 +352,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
self.consume_expr(base); self.consume_expr(base);
} }
hir::ExprKind::Closure { .. } => { hir::ExprKind::Closure(closure) => {
self.walk_captures(expr); self.walk_captures(closure);
} }
hir::ExprKind::Box(ref base) => { hir::ExprKind::Box(ref base) => {
@ -745,7 +745,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
/// ///
/// - When reporting the Place back to the Delegate, ensure that the UpvarId uses the enclosing /// - When reporting the Place back to the Delegate, ensure that the UpvarId uses the enclosing
/// closure as the DefId. /// closure as the DefId.
fn walk_captures(&mut self, closure_expr: &hir::Expr<'_>) { fn walk_captures(&mut self, closure_expr: &hir::Closure<'_>) {
fn upvar_is_local_variable<'tcx>( fn upvar_is_local_variable<'tcx>(
upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>, upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
upvar_id: hir::HirId, upvar_id: hir::HirId,
@ -757,7 +757,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
debug!("walk_captures({:?})", closure_expr); debug!("walk_captures({:?})", closure_expr);
let tcx = self.tcx(); let tcx = self.tcx();
let closure_def_id = tcx.hir().local_def_id(closure_expr.hir_id); let closure_def_id = closure_expr.def_id;
let upvars = tcx.upvars_mentioned(self.body_owner); let upvars = tcx.upvars_mentioned(self.body_owner);
// For purposes of this function, generator and closures are equivalent. // For purposes of this function, generator and closures are equivalent.
@ -829,10 +829,11 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
// be a local variable // be a local variable
PlaceBase::Local(*var_hir_id) PlaceBase::Local(*var_hir_id)
}; };
let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id);
let place_with_id = PlaceWithHirId::new( let place_with_id = PlaceWithHirId::new(
capture_info.path_expr_id.unwrap_or( capture_info
capture_info.capture_kind_expr_id.unwrap_or(closure_expr.hir_id), .path_expr_id
), .unwrap_or(capture_info.capture_kind_expr_id.unwrap_or(closure_hir_id)),
place.base_ty, place.base_ty,
place_base, place_base,
place.projections.clone(), place.projections.clone(),

View file

@ -488,9 +488,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
match length { match length {
&hir::ArrayLen::Infer(_, span) => self.ct_infer(self.tcx.types.usize, None, span), &hir::ArrayLen::Infer(_, span) => self.ct_infer(self.tcx.types.usize, None, span),
hir::ArrayLen::Body(anon_const) => { hir::ArrayLen::Body(anon_const) => {
let const_def_id = self.tcx.hir().local_def_id(anon_const.hir_id); let span = self.tcx.def_span(anon_const.def_id);
let span = self.tcx.hir().span(anon_const.hir_id); let c = ty::Const::from_anon_const(self.tcx, anon_const.def_id);
let c = ty::Const::from_anon_const(self.tcx, const_def_id);
self.register_wf_obligation(c.into(), span, ObligationCauseCode::WellFormed(None)); self.register_wf_obligation(c.into(), span, ObligationCauseCode::WellFormed(None));
self.normalize_associated_types_in(span, c) self.normalize_associated_types_in(span, c)
} }
@ -502,10 +501,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ast_c: &hir::AnonConst, ast_c: &hir::AnonConst,
param_def_id: DefId, param_def_id: DefId,
) -> ty::Const<'tcx> { ) -> ty::Const<'tcx> {
let const_def = ty::WithOptConstParam { let const_def =
did: self.tcx.hir().local_def_id(ast_c.hir_id), ty::WithOptConstParam { did: ast_c.def_id, const_param_did: Some(param_def_id) };
const_param_did: Some(param_def_id),
};
let c = ty::Const::from_opt_const_arg_anon_const(self.tcx, const_def); let c = ty::Const::from_opt_const_arg_anon_const(self.tcx, const_def);
self.register_wf_obligation( self.register_wf_obligation(
c.into(), c.into(),

View file

@ -251,7 +251,7 @@ fn typeck_with_fallback<'tcx>(
param_env, param_env,
fn_sig, fn_sig,
); );
check_fn(&inh, param_env, fn_sig, decl, id, body, None).0 check_fn(&inh, param_env, fn_sig, decl, def_id, body, None).0
} else { } else {
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id); let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
let expected_type = body_ty let expected_type = body_ty

View file

@ -514,7 +514,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
for (&def_id, c_sig) in fcx_typeck_results.user_provided_sigs.iter() { for (&def_id, c_sig) in fcx_typeck_results.user_provided_sigs.iter() {
if cfg!(debug_assertions) && c_sig.needs_infer() { if cfg!(debug_assertions) && c_sig.needs_infer() {
span_bug!( span_bug!(
self.fcx.tcx.hir().span_if_local(def_id).unwrap(), self.fcx.tcx.def_span(def_id),
"writeback: `{:?}` has inference variables", "writeback: `{:?}` has inference variables",
c_sig c_sig
); );

View file

@ -186,9 +186,8 @@ impl<'tcx> LateLintPass<'tcx> for BoxPointers {
// If it's a struct, we also have to check the fields' types // If it's a struct, we also have to check the fields' types
match it.kind { match it.kind {
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
for struct_field in struct_def.fields() { for field in struct_def.fields() {
let def_id = cx.tcx.hir().local_def_id(struct_field.hir_id); self.check_heap_type(cx, field.span, cx.tcx.type_of(field.def_id));
self.check_heap_type(cx, struct_field.span, cx.tcx.type_of(def_id));
} }
} }
_ => (), _ => (),
@ -674,13 +673,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
fn check_field_def(&mut self, cx: &LateContext<'_>, sf: &hir::FieldDef<'_>) { fn check_field_def(&mut self, cx: &LateContext<'_>, sf: &hir::FieldDef<'_>) {
if !sf.is_positional() { if !sf.is_positional() {
let def_id = cx.tcx.hir().local_def_id(sf.hir_id); self.check_missing_docs_attrs(cx, sf.def_id, "a", "struct field")
self.check_missing_docs_attrs(cx, def_id, "a", "struct field")
} }
} }
fn check_variant(&mut self, cx: &LateContext<'_>, v: &hir::Variant<'_>) { fn check_variant(&mut self, cx: &LateContext<'_>, v: &hir::Variant<'_>) {
self.check_missing_docs_attrs(cx, cx.tcx.hir().local_def_id(v.id), "a", "variant"); self.check_missing_docs_attrs(cx, v.def_id, "a", "variant");
} }
} }
@ -1425,11 +1423,10 @@ impl<'tcx> LateLintPass<'tcx> for UnreachablePub {
fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) { fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
let map = cx.tcx.hir(); let map = cx.tcx.hir();
let def_id = map.local_def_id(field.hir_id);
if matches!(map.get(map.get_parent_node(field.hir_id)), Node::Variant(_)) { if matches!(map.get(map.get_parent_node(field.hir_id)), Node::Variant(_)) {
return; return;
} }
self.perform_lint(cx, "field", def_id, field.vis_span, false); self.perform_lint(cx, "field", field.def_id, field.vis_span, false);
} }
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) { fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {

View file

@ -205,7 +205,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
} }
fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) { fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) {
self.with_lint_attrs(v.id, |cx| { self.with_lint_attrs(v.hir_id, |cx| {
lint_callback!(cx, check_variant, v); lint_callback!(cx, check_variant, v);
hir_visit::walk_variant(cx, v); hir_visit::walk_variant(cx, v);
}) })

View file

@ -320,7 +320,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
} }
fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) { fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) {
self.add_id(v.id); self.add_id(v.hir_id);
intravisit::walk_variant(self, v); intravisit::walk_variant(self, v);
} }
@ -392,7 +392,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, QueryMapExpectationsWrapper<'
} }
fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) { fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) {
self.add_id(v.id); self.add_id(v.hir_id);
intravisit::walk_variant(self, v); intravisit::walk_variant(self, v);
} }

View file

@ -1558,9 +1558,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
// Encode def_ids for each field and method // Encode def_ids for each field and method
// for methods, write all the stuff get_trait_method // for methods, write all the stuff get_trait_method
// needs to know // needs to know
let ctor = struct_def let ctor = struct_def.ctor_def_id().map(|ctor_def_id| ctor_def_id.local_def_index);
.ctor_hir_id()
.map(|ctor_hir_id| self.tcx.hir().local_def_id(ctor_hir_id).local_def_index);
let variant = adt_def.non_enum_variant(); let variant = adt_def.non_enum_variant();
record!(self.tables.variant_data[def_id] <- VariantData { record!(self.tables.variant_data[def_id] <- VariantData {
@ -1685,8 +1683,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
hir::ItemKind::Struct(ref struct_def, _) => { hir::ItemKind::Struct(ref struct_def, _) => {
let def = self.tcx.adt_def(item.owner_id.to_def_id()); let def = self.tcx.adt_def(item.owner_id.to_def_id());
// If the struct has a constructor, encode it. // If the struct has a constructor, encode it.
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() { if let Some(ctor_def_id) = struct_def.ctor_def_id() {
let ctor_def_id = self.tcx.hir().local_def_id(ctor_hir_id);
self.encode_struct_ctor(def, ctor_def_id.to_def_id()); self.encode_struct_ctor(def, ctor_def_id.to_def_id());
} }
} }
@ -1708,12 +1705,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
} }
} }
fn encode_info_for_closure(&mut self, hir_id: hir::HirId) { #[instrument(level = "debug", skip(self))]
let def_id = self.tcx.hir().local_def_id(hir_id); fn encode_info_for_closure(&mut self, def_id: LocalDefId) {
debug!("EncodeContext::encode_info_for_closure({:?})", def_id);
// NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic, // NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic,
// including on the signature, which is inferred in `typeck. // including on the signature, which is inferred in `typeck.
let typeck_result: &'tcx ty::TypeckResults<'tcx> = self.tcx.typeck(def_id); let typeck_result: &'tcx ty::TypeckResults<'tcx> = self.tcx.typeck(def_id);
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
let ty = typeck_result.node_type(hir_id); let ty = typeck_result.node_type(hir_id);
match ty.kind() { match ty.kind() {
ty::Generator(..) => { ty::Generator(..) => {
@ -2101,11 +2098,10 @@ impl<'a, 'tcx> Visitor<'tcx> for EncodeContext<'a, 'tcx> {
impl<'a, 'tcx> EncodeContext<'a, 'tcx> { impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
fn encode_info_for_generics(&mut self, generics: &hir::Generics<'tcx>) { fn encode_info_for_generics(&mut self, generics: &hir::Generics<'tcx>) {
for param in generics.params { for param in generics.params {
let def_id = self.tcx.hir().local_def_id(param.hir_id);
match param.kind { match param.kind {
hir::GenericParamKind::Lifetime { .. } | hir::GenericParamKind::Type { .. } => {} hir::GenericParamKind::Lifetime { .. } | hir::GenericParamKind::Type { .. } => {}
hir::GenericParamKind::Const { ref default, .. } => { hir::GenericParamKind::Const { ref default, .. } => {
let def_id = def_id.to_def_id(); let def_id = param.def_id.to_def_id();
if default.is_some() { if default.is_some() {
record!(self.tables.const_param_default[def_id] <- self.tcx.const_param_default(def_id)) record!(self.tables.const_param_default[def_id] <- self.tcx.const_param_default(def_id))
} }
@ -2115,8 +2111,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
} }
fn encode_info_for_expr(&mut self, expr: &hir::Expr<'_>) { fn encode_info_for_expr(&mut self, expr: &hir::Expr<'_>) {
if let hir::ExprKind::Closure { .. } = expr.kind { if let hir::ExprKind::Closure(closure) = expr.kind {
self.encode_info_for_closure(expr.hir_id); self.encode_info_for_closure(closure.def_id);
} }
} }
} }

View file

@ -1086,10 +1086,10 @@ impl<'hir> Map<'hir> {
/// Returns the HirId of `N` in `struct Foo<const N: usize = { ... }>` when /// Returns the HirId of `N` in `struct Foo<const N: usize = { ... }>` when
/// called with the HirId for the `{ ... }` anon const /// called with the HirId for the `{ ... }` anon const
pub fn opt_const_param_default_param_hir_id(self, anon_const: HirId) -> Option<HirId> { pub fn opt_const_param_default_param_def_id(self, anon_const: HirId) -> Option<LocalDefId> {
match self.get(self.get_parent_node(anon_const)) { match self.get(self.get_parent_node(anon_const)) {
Node::GenericParam(GenericParam { Node::GenericParam(GenericParam {
hir_id: param_id, def_id: param_id,
kind: GenericParamKind::Const { .. }, kind: GenericParamKind::Const { .. },
.. ..
}) => Some(*param_id), }) => Some(*param_id),
@ -1198,20 +1198,7 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
fn hir_id_to_string(map: Map<'_>, id: HirId) -> String { fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
let id_str = format!(" (hir_id={})", id); let id_str = format!(" (hir_id={})", id);
let path_str = || { let path_str = |def_id: LocalDefId| map.tcx.def_path_str(def_id.to_def_id());
// This functionality is used for debugging, try to use `TyCtxt` to get
// the user-friendly path, otherwise fall back to stringifying `DefPath`.
crate::ty::tls::with_opt(|tcx| {
if let Some(tcx) = tcx {
let def_id = map.local_def_id(id);
tcx.def_path_str(def_id.to_def_id())
} else if let Some(path) = map.def_path_from_hir_id(id) {
path.data.into_iter().map(|elem| elem.to_string()).collect::<Vec<_>>().join("::")
} else {
String::from("<missing path>")
}
})
};
let span_str = || map.tcx.sess.source_map().span_to_snippet(map.span(id)).unwrap_or_default(); let span_str = || map.tcx.sess.source_map().span_to_snippet(map.span(id)).unwrap_or_default();
let node_str = |prefix| format!("{} {}{}", prefix, span_str(), id_str); let node_str = |prefix| format!("{} {}{}", prefix, span_str(), id_str);
@ -1243,18 +1230,19 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
ItemKind::TraitAlias(..) => "trait alias", ItemKind::TraitAlias(..) => "trait alias",
ItemKind::Impl { .. } => "impl", ItemKind::Impl { .. } => "impl",
}; };
format!("{} {}{}", item_str, path_str(), id_str) format!("{} {}{}", item_str, path_str(item.owner_id.def_id), id_str)
}
Some(Node::ForeignItem(item)) => {
format!("foreign item {}{}", path_str(item.owner_id.def_id), id_str)
}
Some(Node::ImplItem(ii)) => {
let kind = match ii.kind {
ImplItemKind::Const(..) => "assoc const",
ImplItemKind::Fn(..) => "method",
ImplItemKind::Type(_) => "assoc type",
};
format!("{} {} in {}{}", kind, ii.ident, path_str(ii.owner_id.def_id), id_str)
} }
Some(Node::ForeignItem(_)) => format!("foreign item {}{}", path_str(), id_str),
Some(Node::ImplItem(ii)) => match ii.kind {
ImplItemKind::Const(..) => {
format!("assoc const {} in {}{}", ii.ident, path_str(), id_str)
}
ImplItemKind::Fn(..) => format!("method {} in {}{}", ii.ident, path_str(), id_str),
ImplItemKind::Type(_) => {
format!("assoc type {} in {}{}", ii.ident, path_str(), id_str)
}
},
Some(Node::TraitItem(ti)) => { Some(Node::TraitItem(ti)) => {
let kind = match ti.kind { let kind = match ti.kind {
TraitItemKind::Const(..) => "assoc constant", TraitItemKind::Const(..) => "assoc constant",
@ -1262,13 +1250,13 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
TraitItemKind::Type(..) => "assoc type", TraitItemKind::Type(..) => "assoc type",
}; };
format!("{} {} in {}{}", kind, ti.ident, path_str(), id_str) format!("{} {} in {}{}", kind, ti.ident, path_str(ti.owner_id.def_id), id_str)
} }
Some(Node::Variant(ref variant)) => { Some(Node::Variant(ref variant)) => {
format!("variant {} in {}{}", variant.ident, path_str(), id_str) format!("variant {} in {}{}", variant.ident, path_str(variant.def_id), id_str)
} }
Some(Node::Field(ref field)) => { Some(Node::Field(ref field)) => {
format!("field {} in {}{}", field.ident, path_str(), id_str) format!("field {} in {}{}", field.ident, path_str(field.def_id), id_str)
} }
Some(Node::AnonConst(_)) => node_str("const"), Some(Node::AnonConst(_)) => node_str("const"),
Some(Node::Expr(_)) => node_str("expr"), Some(Node::Expr(_)) => node_str("expr"),
@ -1285,9 +1273,15 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
Some(Node::Block(_)) => node_str("block"), Some(Node::Block(_)) => node_str("block"),
Some(Node::Infer(_)) => node_str("infer"), Some(Node::Infer(_)) => node_str("infer"),
Some(Node::Local(_)) => node_str("local"), Some(Node::Local(_)) => node_str("local"),
Some(Node::Ctor(..)) => format!("ctor {}{}", path_str(), id_str), Some(Node::Ctor(ctor)) => format!(
"ctor {}{}",
ctor.ctor_def_id().map_or("<missing path>".into(), |def_id| path_str(def_id)),
id_str
),
Some(Node::Lifetime(_)) => node_str("lifetime"), Some(Node::Lifetime(_)) => node_str("lifetime"),
Some(Node::GenericParam(ref param)) => format!("generic_param {:?}{}", param, id_str), Some(Node::GenericParam(ref param)) => {
format!("generic_param {}{}", path_str(param.def_id), id_str)
}
Some(Node::Crate(..)) => String::from("root_crate"), Some(Node::Crate(..)) => String::from("root_crate"),
None => format!("unknown node{}", id_str), None => format!("unknown node{}", id_str),
} }
@ -1407,13 +1401,13 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
} }
fn visit_anon_const(&mut self, c: &'hir AnonConst) { fn visit_anon_const(&mut self, c: &'hir AnonConst) {
self.body_owners.push(self.tcx.hir().local_def_id(c.hir_id)); self.body_owners.push(c.def_id);
intravisit::walk_anon_const(self, c) intravisit::walk_anon_const(self, c)
} }
fn visit_expr(&mut self, ex: &'hir Expr<'hir>) { fn visit_expr(&mut self, ex: &'hir Expr<'hir>) {
if matches!(ex.kind, ExprKind::Closure { .. }) { if let ExprKind::Closure(closure) = ex.kind {
self.body_owners.push(self.tcx.hir().local_def_id(ex.hir_id)); self.body_owners.push(closure.def_id);
} }
intravisit::walk_expr(self, ex) intravisit::walk_expr(self, ex)
} }

View file

@ -10,7 +10,7 @@ use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable}; use crate::ty::fold::{FallibleTypeFolder, TypeFoldable};
use crate::ty::print::{FmtPrinter, Printer}; use crate::ty::print::{FmtPrinter, Printer};
use crate::ty::visit::{TypeVisitable, TypeVisitor}; use crate::ty::visit::{TypeVisitable, TypeVisitor};
use crate::ty::{self, List, Ty, TyCtxt}; use crate::ty::{self, DefIdTree, List, Ty, TyCtxt};
use crate::ty::{AdtDef, InstanceDef, ScalarInt, UserTypeAnnotationIndex}; use crate::ty::{AdtDef, InstanceDef, ScalarInt, UserTypeAnnotationIndex};
use crate::ty::{GenericArg, InternalSubsts, SubstsRef}; use crate::ty::{GenericArg, InternalSubsts, SubstsRef};
@ -2523,12 +2523,10 @@ impl<'tcx> ConstantKind<'tcx> {
ExprKind::Path(QPath::Resolved(_, &Path { res: Res::Def(ConstParam, def_id), .. })) => { ExprKind::Path(QPath::Resolved(_, &Path { res: Res::Def(ConstParam, def_id), .. })) => {
// Find the name and index of the const parameter by indexing the generics of // Find the name and index of the const parameter by indexing the generics of
// the parent item and construct a `ParamConst`. // the parent item and construct a `ParamConst`.
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let item_def_id = tcx.parent(def_id);
let item_id = tcx.hir().get_parent_node(hir_id); let generics = tcx.generics_of(item_def_id);
let item_def_id = tcx.hir().local_def_id(item_id);
let generics = tcx.generics_of(item_def_id.to_def_id());
let index = generics.param_def_id_to_index[&def_id]; let index = generics.param_def_id_to_index[&def_id];
let name = tcx.hir().name(hir_id); let name = tcx.item_name(def_id);
let ty_const = let ty_const =
tcx.mk_const(ty::ConstKind::Param(ty::ParamConst::new(index, name)), ty); tcx.mk_const(ty::ConstKind::Param(ty::ParamConst::new(index, name)), ty);
debug!(?ty_const); debug!(?ty_const);

View file

@ -1,6 +1,6 @@
use crate::mir::interpret::LitToConstInput; use crate::mir::interpret::LitToConstInput;
use crate::mir::ConstantKind; use crate::mir::ConstantKind;
use crate::ty::{self, InternalSubsts, ParamEnv, ParamEnvAnd, Ty, TyCtxt}; use crate::ty::{self, DefIdTree, InternalSubsts, ParamEnv, ParamEnvAnd, Ty, TyCtxt};
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
@ -131,12 +131,10 @@ impl<'tcx> Const<'tcx> {
ExprKind::Path(QPath::Resolved(_, &Path { res: Res::Def(ConstParam, def_id), .. })) => { ExprKind::Path(QPath::Resolved(_, &Path { res: Res::Def(ConstParam, def_id), .. })) => {
// Find the name and index of the const parameter by indexing the generics of // Find the name and index of the const parameter by indexing the generics of
// the parent item and construct a `ParamConst`. // the parent item and construct a `ParamConst`.
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let item_def_id = tcx.parent(def_id);
let item_id = tcx.hir().get_parent_node(hir_id); let generics = tcx.generics_of(item_def_id);
let item_def_id = tcx.hir().local_def_id(item_id);
let generics = tcx.generics_of(item_def_id.to_def_id());
let index = generics.param_def_id_to_index[&def_id]; let index = generics.param_def_id_to_index[&def_id];
let name = tcx.hir().name(hir_id); let name = tcx.item_name(def_id);
Some(tcx.mk_const(ty::ConstKind::Param(ty::ParamConst::new(index, name)), ty)) Some(tcx.mk_const(ty::ConstKind::Param(ty::ParamConst::new(index, name)), ty))
} }
_ => None, _ => None,
@ -268,9 +266,9 @@ impl<'tcx> Const<'tcx> {
pub fn const_param_default<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Const<'tcx> { pub fn const_param_default<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Const<'tcx> {
let default_def_id = match tcx.hir().get_by_def_id(def_id.expect_local()) { let default_def_id = match tcx.hir().get_by_def_id(def_id.expect_local()) {
hir::Node::GenericParam(hir::GenericParam { hir::Node::GenericParam(hir::GenericParam {
kind: hir::GenericParamKind::Const { ty: _, default: Some(ac) }, kind: hir::GenericParamKind::Const { default: Some(ac), .. },
.. ..
}) => tcx.hir().local_def_id(ac.hir_id), }) => ac.def_id,
_ => span_bug!( _ => span_bug!(
tcx.def_span(def_id), tcx.def_span(def_id),
"`const_param_default` expected a generic parameter with a constant" "`const_param_default` expected a generic parameter with a constant"

View file

@ -41,7 +41,7 @@ use rustc_errors::{
}; };
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, LOCAL_CRATE};
use rustc_hir::definitions::Definitions; use rustc_hir::definitions::Definitions;
use rustc_hir::hir_id::OwnerId; use rustc_hir::hir_id::OwnerId;
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
@ -443,7 +443,7 @@ pub struct TypeckResults<'tcx> {
/// Stores the canonicalized types provided by the user. See also /// Stores the canonicalized types provided by the user. See also
/// `AscribeUserType` statement in MIR. /// `AscribeUserType` statement in MIR.
pub user_provided_sigs: DefIdMap<CanonicalPolyFnSig<'tcx>>, pub user_provided_sigs: LocalDefIdMap<CanonicalPolyFnSig<'tcx>>,
adjustments: ItemLocalMap<Vec<ty::adjustment::Adjustment<'tcx>>>, adjustments: ItemLocalMap<Vec<ty::adjustment::Adjustment<'tcx>>>,

View file

@ -151,7 +151,6 @@ enum SuggestChangingConstraintsMessage<'a> {
} }
fn suggest_removing_unsized_bound( fn suggest_removing_unsized_bound(
tcx: TyCtxt<'_>,
generics: &hir::Generics<'_>, generics: &hir::Generics<'_>,
suggestions: &mut Vec<(Span, String, SuggestChangingConstraintsMessage<'_>)>, suggestions: &mut Vec<(Span, String, SuggestChangingConstraintsMessage<'_>)>,
param: &hir::GenericParam<'_>, param: &hir::GenericParam<'_>,
@ -160,17 +159,16 @@ fn suggest_removing_unsized_bound(
// See if there's a `?Sized` bound that can be removed to suggest that. // See if there's a `?Sized` bound that can be removed to suggest that.
// First look at the `where` clause because we can have `where T: ?Sized`, // First look at the `where` clause because we can have `where T: ?Sized`,
// then look at params. // then look at params.
let param_def_id = tcx.hir().local_def_id(param.hir_id);
for (where_pos, predicate) in generics.predicates.iter().enumerate() { for (where_pos, predicate) in generics.predicates.iter().enumerate() {
let WherePredicate::BoundPredicate(predicate) = predicate else { let WherePredicate::BoundPredicate(predicate) = predicate else {
continue; continue;
}; };
if !predicate.is_param_bound(param_def_id.to_def_id()) { if !predicate.is_param_bound(param.def_id.to_def_id()) {
continue; continue;
}; };
for (pos, bound) in predicate.bounds.iter().enumerate() { for (pos, bound) in predicate.bounds.iter().enumerate() {
let hir::GenericBound::Trait(poly, hir::TraitBoundModifier::Maybe) = bound else { let hir::GenericBound::Trait(poly, hir::TraitBoundModifier::Maybe) = bound else {
continue; continue;
}; };
if poly.trait_ref.trait_def_id() != def_id { if poly.trait_ref.trait_def_id() != def_id {
@ -232,7 +230,7 @@ pub fn suggest_constraining_type_params<'a>(
param.span, param.span,
&format!("this type parameter needs to be `{}`", constraint), &format!("this type parameter needs to be `{}`", constraint),
); );
suggest_removing_unsized_bound(tcx, generics, &mut suggestions, param, def_id); suggest_removing_unsized_bound(generics, &mut suggestions, param, def_id);
} }
} }
@ -283,8 +281,7 @@ pub fn suggest_constraining_type_params<'a>(
// -- // --
// | // |
// replace with: `T: Bar +` // replace with: `T: Bar +`
let param_def_id = tcx.hir().local_def_id(param.hir_id); if let Some(span) = generics.bounds_span_for_suggestions(param.def_id) {
if let Some(span) = generics.bounds_span_for_suggestions(param_def_id) {
suggest_restrict(span, true); suggest_restrict(span, true);
continue; continue;
} }

View file

@ -608,24 +608,22 @@ impl<'tcx> Cx<'tcx> {
out_expr: out_expr.as_ref().map(|expr| self.mirror_expr(expr)), out_expr: out_expr.as_ref().map(|expr| self.mirror_expr(expr)),
}, },
hir::InlineAsmOperand::Const { ref anon_const } => { hir::InlineAsmOperand::Const { ref anon_const } => {
let anon_const_def_id = tcx.hir().local_def_id(anon_const.hir_id);
let value = mir::ConstantKind::from_anon_const( let value = mir::ConstantKind::from_anon_const(
tcx, tcx,
anon_const_def_id, anon_const.def_id,
self.param_env, self.param_env,
); );
let span = tcx.hir().span(anon_const.hir_id); let span = tcx.def_span(anon_const.def_id);
InlineAsmOperand::Const { value, span } InlineAsmOperand::Const { value, span }
} }
hir::InlineAsmOperand::SymFn { ref anon_const } => { hir::InlineAsmOperand::SymFn { ref anon_const } => {
let anon_const_def_id = tcx.hir().local_def_id(anon_const.hir_id);
let value = mir::ConstantKind::from_anon_const( let value = mir::ConstantKind::from_anon_const(
tcx, tcx,
anon_const_def_id, anon_const.def_id,
self.param_env, self.param_env,
); );
let span = tcx.hir().span(anon_const.hir_id); let span = tcx.def_span(anon_const.def_id);
InlineAsmOperand::SymFn { value, span } InlineAsmOperand::SymFn { value, span }
} }
@ -640,7 +638,7 @@ impl<'tcx> Cx<'tcx> {
hir::ExprKind::ConstBlock(ref anon_const) => { hir::ExprKind::ConstBlock(ref anon_const) => {
let ty = self.typeck_results().node_type(anon_const.hir_id); let ty = self.typeck_results().node_type(anon_const.hir_id);
let did = tcx.hir().local_def_id(anon_const.hir_id).to_def_id(); let did = anon_const.def_id.to_def_id();
let typeck_root_def_id = tcx.typeck_root_def_id(did); let typeck_root_def_id = tcx.typeck_root_def_id(did);
let parent_substs = let parent_substs =
tcx.erase_regions(InternalSubsts::identity_for_item(tcx, typeck_root_def_id)); tcx.erase_regions(InternalSubsts::identity_for_item(tcx, typeck_root_def_id));
@ -859,9 +857,7 @@ impl<'tcx> Cx<'tcx> {
Res::Def(DefKind::ConstParam, def_id) => { Res::Def(DefKind::ConstParam, def_id) => {
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let item_id = self.tcx.hir().get_parent_node(hir_id); let generics = self.tcx.generics_of(hir_id.owner);
let item_def_id = self.tcx.hir().local_def_id(item_id);
let generics = self.tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&def_id]; let index = generics.param_def_id_to_index[&def_id];
let name = self.tcx.hir().name(hir_id); let name = self.tcx.hir().name(hir_id);
let param = ty::ParamConst::new(index, name); let param = ty::ParamConst::new(index, name);

View file

@ -565,8 +565,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
id: hir::HirId, id: hir::HirId,
span: Span, span: Span,
) -> PatKind<'tcx> { ) -> PatKind<'tcx> {
let anon_const_def_id = self.tcx.hir().local_def_id(anon_const.hir_id); let value = mir::ConstantKind::from_inline_const(self.tcx, anon_const.def_id);
let value = mir::ConstantKind::from_inline_const(self.tcx, anon_const_def_id);
// Evaluate early like we do in `lower_path`. // Evaluate early like we do in `lower_path`.
let value = value.eval(self.tcx, self.param_env); let value = value.eval(self.tcx, self.param_env);

View file

@ -220,19 +220,18 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
// Additionally, tuple struct/variant constructors have MIR, but // Additionally, tuple struct/variant constructors have MIR, but
// they don't have a BodyId, so we need to build them separately. // they don't have a BodyId, so we need to build them separately.
struct GatherCtors<'a, 'tcx> { struct GatherCtors<'a> {
tcx: TyCtxt<'tcx>,
set: &'a mut FxIndexSet<LocalDefId>, set: &'a mut FxIndexSet<LocalDefId>,
} }
impl<'tcx> Visitor<'tcx> for GatherCtors<'_, 'tcx> { impl<'tcx> Visitor<'tcx> for GatherCtors<'_> {
fn visit_variant_data(&mut self, v: &'tcx hir::VariantData<'tcx>) { fn visit_variant_data(&mut self, v: &'tcx hir::VariantData<'tcx>) {
if let hir::VariantData::Tuple(_, hir_id) = *v { if let hir::VariantData::Tuple(_, _, def_id) = *v {
self.set.insert(self.tcx.hir().local_def_id(hir_id)); self.set.insert(def_id);
} }
intravisit::walk_struct_def(self, v) intravisit::walk_struct_def(self, v)
} }
} }
tcx.hir().visit_all_item_likes_in_crate(&mut GatherCtors { tcx, set: &mut set }); tcx.hir().visit_all_item_likes_in_crate(&mut GatherCtors { set: &mut set });
set set
} }

View file

@ -219,18 +219,6 @@ impl CheckAttrVisitor<'_> {
return; return;
} }
// FIXME(@lcnr): this doesn't belong here.
if matches!(
target,
Target::Closure
| Target::Fn
| Target::Method(_)
| Target::ForeignFn
| Target::ForeignStatic
) {
self.tcx.ensure().codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
}
self.check_repr(attrs, span, target, item, hir_id); self.check_repr(attrs, span, target, item, hir_id);
self.check_used(attrs, target); self.check_used(attrs, target);
} }
@ -423,8 +411,7 @@ impl CheckAttrVisitor<'_> {
if let Some(generics) = tcx.hir().get_generics(tcx.hir().local_def_id(hir_id)) { if let Some(generics) = tcx.hir().get_generics(tcx.hir().local_def_id(hir_id)) {
for p in generics.params { for p in generics.params {
let hir::GenericParamKind::Type { .. } = p.kind else { continue }; let hir::GenericParamKind::Type { .. } = p.kind else { continue };
let param_id = tcx.hir().local_def_id(p.hir_id); let default = tcx.object_lifetime_default(p.def_id);
let default = tcx.object_lifetime_default(param_id);
let repr = match default { let repr = match default {
ObjectLifetimeDefault::Empty => "BaseDefault".to_owned(), ObjectLifetimeDefault::Empty => "BaseDefault".to_owned(),
ObjectLifetimeDefault::Static => "'static".to_owned(), ObjectLifetimeDefault::Static => "'static".to_owned(),
@ -2150,7 +2137,7 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
} }
fn visit_variant(&mut self, variant: &'tcx hir::Variant<'tcx>) { fn visit_variant(&mut self, variant: &'tcx hir::Variant<'tcx>) {
self.check_attributes(variant.id, variant.span, Target::Variant, None); self.check_attributes(variant.hir_id, variant.span, Target::Variant, None);
intravisit::walk_variant(self, variant) intravisit::walk_variant(self, variant)
} }

View file

@ -362,7 +362,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
let has_repr_c = self.repr_has_repr_c; let has_repr_c = self.repr_has_repr_c;
let has_repr_simd = self.repr_has_repr_simd; let has_repr_simd = self.repr_has_repr_simd;
let live_fields = def.fields().iter().filter_map(|f| { let live_fields = def.fields().iter().filter_map(|f| {
let def_id = tcx.hir().local_def_id(f.hir_id); let def_id = f.def_id;
if has_repr_c || (f.is_positional() && has_repr_simd) { if has_repr_c || (f.is_positional() && has_repr_simd) {
return Some(def_id); return Some(def_id);
} }
@ -522,17 +522,13 @@ fn check_item<'tcx>(
DefKind::Enum => { DefKind::Enum => {
let item = tcx.hir().item(id); let item = tcx.hir().item(id);
if let hir::ItemKind::Enum(ref enum_def, _) = item.kind { if let hir::ItemKind::Enum(ref enum_def, _) = item.kind {
let hir = tcx.hir();
if allow_dead_code { if allow_dead_code {
worklist.extend( worklist.extend(enum_def.variants.iter().map(|variant| variant.def_id));
enum_def.variants.iter().map(|variant| hir.local_def_id(variant.id)),
);
} }
for variant in enum_def.variants { for variant in enum_def.variants {
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() { if let Some(ctor_def_id) = variant.data.ctor_def_id() {
struct_constructors struct_constructors.insert(ctor_def_id, variant.def_id);
.insert(hir.local_def_id(ctor_hir_id), hir.local_def_id(variant.id));
} }
} }
} }

View file

@ -219,7 +219,7 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
let item = tcx.hir().item(id); let item = tcx.hir().item(id);
if let hir::ItemKind::Enum(def, ..) = &item.kind { if let hir::ItemKind::Enum(def, ..) = &item.kind {
for variant in def.variants { for variant in def.variants {
collector.check_for_lang(Target::Variant, variant.id); collector.check_for_lang(Target::Variant, variant.hir_id);
} }
} }
} }

View file

@ -413,7 +413,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
} }
intravisit::walk_expr(self, expr); intravisit::walk_expr(self, expr);
} }
hir::ExprKind::Closure { .. } => { hir::ExprKind::Closure(closure) => {
// Interesting control flow (for loops can contain labeled // Interesting control flow (for loops can contain labeled
// breaks or continues) // breaks or continues)
self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id)); self.add_live_node_for_node(expr.hir_id, ExprNode(expr.span, expr.hir_id));
@ -423,8 +423,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
// in better error messages than just pointing at the closure // in better error messages than just pointing at the closure
// construction site. // construction site.
let mut call_caps = Vec::new(); let mut call_caps = Vec::new();
let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id); if let Some(upvars) = self.tcx.upvars_mentioned(closure.def_id) {
if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
call_caps.extend(upvars.keys().map(|var_id| { call_caps.extend(upvars.keys().map(|var_id| {
let upvar = upvars[var_id]; let upvar = upvars[var_id];
let upvar_ln = self.add_live_node(UpvarNode(upvar.span)); let upvar_ln = self.add_live_node(UpvarNode(upvar.span));

View file

@ -358,9 +358,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
const_stab_inherit = InheritConstStability::Yes; const_stab_inherit = InheritConstStability::Yes;
} }
hir::ItemKind::Struct(ref sd, _) => { hir::ItemKind::Struct(ref sd, _) => {
if let Some(ctor_hir_id) = sd.ctor_hir_id() { if let Some(ctor_def_id) = sd.ctor_def_id() {
self.annotate( self.annotate(
self.tcx.hir().local_def_id(ctor_hir_id), ctor_def_id,
i.span, i.span,
None, None,
AnnotationKind::Required, AnnotationKind::Required,
@ -435,7 +435,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) { fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) {
self.annotate( self.annotate(
self.tcx.hir().local_def_id(var.id), var.def_id,
var.span, var.span,
None, None,
AnnotationKind::Required, AnnotationKind::Required,
@ -443,9 +443,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
InheritConstStability::No, InheritConstStability::No,
InheritStability::Yes, InheritStability::Yes,
|v| { |v| {
if let Some(ctor_hir_id) = var.data.ctor_hir_id() { if let Some(ctor_def_id) = var.data.ctor_def_id() {
v.annotate( v.annotate(
v.tcx.hir().local_def_id(ctor_hir_id), ctor_def_id,
var.span, var.span,
None, None,
AnnotationKind::Required, AnnotationKind::Required,
@ -463,7 +463,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) { fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) {
self.annotate( self.annotate(
self.tcx.hir().local_def_id(s.hir_id), s.def_id,
s.span, s.span,
None, None,
AnnotationKind::Required, AnnotationKind::Required,
@ -500,7 +500,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
}; };
self.annotate( self.annotate(
self.tcx.hir().local_def_id(p.hir_id), p.def_id,
p.span, p.span,
None, None,
kind, kind,
@ -601,15 +601,15 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
} }
fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) { fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) {
self.check_missing_stability(self.tcx.hir().local_def_id(var.id), var.span); self.check_missing_stability(var.def_id, var.span);
if let Some(ctor_hir_id) = var.data.ctor_hir_id() { if let Some(ctor_def_id) = var.data.ctor_def_id() {
self.check_missing_stability(self.tcx.hir().local_def_id(ctor_hir_id), var.span); self.check_missing_stability(ctor_def_id, var.span);
} }
intravisit::walk_variant(self, var); intravisit::walk_variant(self, var);
} }
fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) { fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) {
self.check_missing_stability(self.tcx.hir().local_def_id(s.hir_id), s.span); self.check_missing_stability(s.def_id, s.span);
intravisit::walk_field_def(self, s); intravisit::walk_field_def(self, s);
} }

View file

@ -75,9 +75,8 @@ impl<'tcx> Visitor<'tcx> for CaptureCollector<'_, 'tcx> {
} }
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
if let hir::ExprKind::Closure { .. } = expr.kind { if let hir::ExprKind::Closure(closure) = expr.kind {
let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id); if let Some(upvars) = self.tcx.upvars_mentioned(closure.def_id) {
if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
// Every capture of a closure expression is a local in scope, // Every capture of a closure expression is a local in scope,
// that is moved/copied/borrowed into the closure value, and // that is moved/copied/borrowed into the closure value, and
// for this analysis they are like any other access to a local. // for this analysis they are like any other access to a local.

View file

@ -419,11 +419,6 @@ impl<'tcx> EmbargoVisitor<'tcx> {
self.effective_visibilities.public_at_level(def_id) self.effective_visibilities.public_at_level(def_id)
} }
fn update_with_hir_id(&mut self, hir_id: hir::HirId, level: Option<Level>) -> Option<Level> {
let def_id = self.tcx.hir().local_def_id(hir_id);
self.update(def_id, level)
}
/// Updates node level and returns the updated level. /// Updates node level and returns the updated level.
fn update(&mut self, def_id: LocalDefId, level: Option<Level>) -> Option<Level> { fn update(&mut self, def_id: LocalDefId, level: Option<Level>) -> Option<Level> {
let old_level = self.get(def_id); let old_level = self.get(def_id);
@ -573,10 +568,9 @@ impl<'tcx> EmbargoVisitor<'tcx> {
| hir::ItemKind::Union(ref struct_def, _) = item.kind | hir::ItemKind::Union(ref struct_def, _) = item.kind
{ {
for field in struct_def.fields() { for field in struct_def.fields() {
let def_id = self.tcx.hir().local_def_id(field.hir_id); let field_vis = self.tcx.local_visibility(field.def_id);
let field_vis = self.tcx.local_visibility(def_id);
if field_vis.is_accessible_from(module, self.tcx) { if field_vis.is_accessible_from(module, self.tcx) {
self.reach(def_id, level).ty(); self.reach(field.def_id, level).ty();
} }
} }
} else { } else {
@ -641,12 +635,12 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
match item.kind { match item.kind {
hir::ItemKind::Enum(ref def, _) => { hir::ItemKind::Enum(ref def, _) => {
for variant in def.variants { for variant in def.variants {
let variant_level = self.update_with_hir_id(variant.id, item_level); let variant_level = self.update(variant.def_id, item_level);
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() { if let Some(ctor_def_id) = variant.data.ctor_def_id() {
self.update_with_hir_id(ctor_hir_id, item_level); self.update(ctor_def_id, item_level);
} }
for field in variant.data.fields() { for field in variant.data.fields() {
self.update_with_hir_id(field.hir_id, variant_level); self.update(field.def_id, variant_level);
} }
} }
} }
@ -665,14 +659,13 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
} }
} }
hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => { hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => {
if let Some(ctor_hir_id) = def.ctor_hir_id() { if let Some(ctor_def_id) = def.ctor_def_id() {
self.update_with_hir_id(ctor_hir_id, item_level); self.update(ctor_def_id, item_level);
} }
for field in def.fields() { for field in def.fields() {
let def_id = self.tcx.hir().local_def_id(field.hir_id); let vis = self.tcx.visibility(field.def_id);
let vis = self.tcx.visibility(def_id);
if vis.is_public() { if vis.is_public() {
self.update_with_hir_id(field.hir_id, item_level); self.update(field.def_id, item_level);
} }
} }
} }
@ -782,18 +775,16 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
self.reach(item.owner_id.def_id, item_level).generics().predicates(); self.reach(item.owner_id.def_id, item_level).generics().predicates();
} }
for variant in def.variants { for variant in def.variants {
let variant_level = self.get(self.tcx.hir().local_def_id(variant.id)); let variant_level = self.get(variant.def_id);
if variant_level.is_some() { if variant_level.is_some() {
for field in variant.data.fields() { for field in variant.data.fields() {
self.reach(self.tcx.hir().local_def_id(field.hir_id), variant_level) self.reach(field.def_id, variant_level).ty();
.ty();
} }
// Corner case: if the variant is reachable, but its // Corner case: if the variant is reachable, but its
// enum is not, make the enum reachable as well. // enum is not, make the enum reachable as well.
self.reach(item.owner_id.def_id, variant_level).ty(); self.reach(item.owner_id.def_id, variant_level).ty();
} }
if let Some(hir_id) = variant.data.ctor_hir_id() { if let Some(ctor_def_id) = variant.data.ctor_def_id() {
let ctor_def_id = self.tcx.hir().local_def_id(hir_id);
let ctor_level = self.get(ctor_def_id); let ctor_level = self.get(ctor_def_id);
if ctor_level.is_some() { if ctor_level.is_some() {
self.reach(item.owner_id.def_id, ctor_level).ty(); self.reach(item.owner_id.def_id, ctor_level).ty();
@ -818,15 +809,13 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
if item_level.is_some() { if item_level.is_some() {
self.reach(item.owner_id.def_id, item_level).generics().predicates(); self.reach(item.owner_id.def_id, item_level).generics().predicates();
for field in struct_def.fields() { for field in struct_def.fields() {
let def_id = self.tcx.hir().local_def_id(field.hir_id); let field_level = self.get(field.def_id);
let field_level = self.get(def_id);
if field_level.is_some() { if field_level.is_some() {
self.reach(def_id, field_level).ty(); self.reach(field.def_id, field_level).ty();
} }
} }
} }
if let Some(hir_id) = struct_def.ctor_hir_id() { if let Some(ctor_def_id) = struct_def.ctor_def_id() {
let ctor_def_id = self.tcx.hir().local_def_id(hir_id);
let ctor_level = self.get(ctor_def_id); let ctor_level = self.get(ctor_def_id);
if ctor_level.is_some() { if ctor_level.is_some() {
self.reach(item.owner_id.def_id, ctor_level).ty(); self.reach(item.owner_id.def_id, ctor_level).ty();
@ -957,26 +946,21 @@ impl<'tcx, 'a> Visitor<'tcx> for TestReachabilityVisitor<'tcx, 'a> {
match item.kind { match item.kind {
hir::ItemKind::Enum(ref def, _) => { hir::ItemKind::Enum(ref def, _) => {
for variant in def.variants.iter() { for variant in def.variants.iter() {
let variant_id = self.tcx.hir().local_def_id(variant.id); self.effective_visibility_diagnostic(variant.def_id);
self.effective_visibility_diagnostic(variant_id); if let Some(ctor_def_id) = variant.data.ctor_def_id() {
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() {
let ctor_def_id = self.tcx.hir().local_def_id(ctor_hir_id);
self.effective_visibility_diagnostic(ctor_def_id); self.effective_visibility_diagnostic(ctor_def_id);
} }
for field in variant.data.fields() { for field in variant.data.fields() {
let def_id = self.tcx.hir().local_def_id(field.hir_id); self.effective_visibility_diagnostic(field.def_id);
self.effective_visibility_diagnostic(def_id);
} }
} }
} }
hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => { hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => {
if let Some(ctor_hir_id) = def.ctor_hir_id() { if let Some(ctor_def_id) = def.ctor_def_id() {
let ctor_def_id = self.tcx.hir().local_def_id(ctor_hir_id);
self.effective_visibility_diagnostic(ctor_def_id); self.effective_visibility_diagnostic(ctor_def_id);
} }
for field in def.fields() { for field in def.fields() {
let def_id = self.tcx.hir().local_def_id(field.hir_id); self.effective_visibility_diagnostic(field.def_id);
self.effective_visibility_diagnostic(def_id);
} }
} }
_ => {} _ => {}
@ -1719,7 +1703,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
} }
fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) { fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) {
if self.effective_visibilities.is_reachable(self.tcx.hir().local_def_id(v.id)) { if self.effective_visibilities.is_reachable(v.def_id) {
self.in_variant = true; self.in_variant = true;
intravisit::walk_variant(self, v); intravisit::walk_variant(self, v);
self.in_variant = false; self.in_variant = false;
@ -1727,8 +1711,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
} }
fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) { fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) {
let def_id = self.tcx.hir().local_def_id(s.hir_id); let vis = self.tcx.visibility(s.def_id);
let vis = self.tcx.visibility(def_id);
if vis.is_public() || self.in_variant { if vis.is_public() || self.in_variant {
intravisit::walk_field_def(self, s); intravisit::walk_field_def(self, s);
} }
@ -1982,8 +1965,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
for variant in def.variants { for variant in def.variants {
for field in variant.data.fields() { for field in variant.data.fields() {
self.check(self.tcx.hir().local_def_id(field.hir_id), item_visibility) self.check(field.def_id, item_visibility).ty();
.ty();
} }
} }
} }
@ -2010,9 +1992,8 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
self.check(item.owner_id.def_id, item_visibility).generics().predicates(); self.check(item.owner_id.def_id, item_visibility).generics().predicates();
for field in struct_def.fields() { for field in struct_def.fields() {
let def_id = tcx.hir().local_def_id(field.hir_id); let field_visibility = tcx.local_visibility(field.def_id);
let field_visibility = tcx.local_visibility(def_id); self.check(field.def_id, min(item_visibility, field_visibility, tcx)).ty();
self.check(def_id, min(item_visibility, field_visibility, tcx)).ty();
} }
} }
} }

View file

@ -527,9 +527,9 @@ impl<'tcx> DumpVisitor<'tcx> {
let value = format!("{}::{} {{ {} }}", enum_data.name, name, fields_str); let value = format!("{}::{} {{ {} }}", enum_data.name, name, fields_str);
if !self.span.filter_generated(name_span) { if !self.span.filter_generated(name_span) {
let span = self.span_from_span(name_span); let span = self.span_from_span(name_span);
let id = id_from_hir_id(variant.id, &self.save_ctxt); let id = id_from_hir_id(variant.hir_id, &self.save_ctxt);
let parent = Some(id_from_def_id(item.owner_id.to_def_id())); let parent = Some(id_from_def_id(item.owner_id.to_def_id()));
let attrs = self.tcx.hir().attrs(variant.id); let attrs = self.tcx.hir().attrs(variant.hir_id);
self.dumper.dump_def( self.dumper.dump_def(
&access, &access,
@ -552,7 +552,7 @@ impl<'tcx> DumpVisitor<'tcx> {
} }
ref v => { ref v => {
let mut value = format!("{}::{}", enum_data.name, name); let mut value = format!("{}::{}", enum_data.name, name);
if let hir::VariantData::Tuple(fields, _) = v { if let hir::VariantData::Tuple(fields, _, _) = v {
value.push('('); value.push('(');
value.push_str( value.push_str(
&fields &fields
@ -565,9 +565,9 @@ impl<'tcx> DumpVisitor<'tcx> {
} }
if !self.span.filter_generated(name_span) { if !self.span.filter_generated(name_span) {
let span = self.span_from_span(name_span); let span = self.span_from_span(name_span);
let id = id_from_hir_id(variant.id, &self.save_ctxt); let id = id_from_hir_id(variant.hir_id, &self.save_ctxt);
let parent = Some(id_from_def_id(item.owner_id.to_def_id())); let parent = Some(id_from_def_id(item.owner_id.to_def_id()));
let attrs = self.tcx.hir().attrs(variant.id); let attrs = self.tcx.hir().attrs(variant.hir_id);
self.dumper.dump_def( self.dumper.dump_def(
&access, &access,
@ -591,7 +591,7 @@ impl<'tcx> DumpVisitor<'tcx> {
} }
for field in variant.data.fields() { for field in variant.data.fields() {
self.process_struct_field_def(field, variant.id); self.process_struct_field_def(field, variant.hir_id);
self.visit_ty(field.ty); self.visit_ty(field.ty);
} }
} }

View file

@ -319,7 +319,7 @@ impl<'tcx> SaveContext<'tcx> {
qualname, qualname,
value, value,
parent: None, parent: None,
children: def.variants.iter().map(|v| id_from_hir_id(v.id, self)).collect(), children: def.variants.iter().map(|v| id_from_hir_id(v.hir_id, self)).collect(),
decl_id: None, decl_id: None,
docs: self.docs_for_attrs(attrs), docs: self.docs_for_attrs(attrs),
sig: sig::item_signature(item, self), sig: sig::item_signature(item, self),

View file

@ -693,7 +693,7 @@ impl<'hir> Sig for hir::Variant<'hir> {
text.push('}'); text.push('}');
Ok(Signature { text, defs, refs }) Ok(Signature { text, defs, refs })
} }
hir::VariantData::Tuple(fields, id) => { hir::VariantData::Tuple(fields, id, _) => {
let name_def = SigElement { let name_def = SigElement {
id: id_from_hir_id(id, scx), id: id_from_hir_id(id, scx),
start: offset, start: offset,
@ -712,7 +712,7 @@ impl<'hir> Sig for hir::Variant<'hir> {
text.push(')'); text.push(')');
Ok(Signature { text, defs, refs }) Ok(Signature { text, defs, refs })
} }
hir::VariantData::Unit(id) => { hir::VariantData::Unit(id, _) => {
let name_def = SigElement { let name_def = SigElement {
id: id_from_hir_id(id, scx), id: id_from_hir_id(id, scx),
start: offset, start: offset,

View file

@ -2592,11 +2592,10 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let Some(param) = generics.params.iter().find(|param| param.span == span) else { let Some(param) = generics.params.iter().find(|param| param.span == span) else {
return; return;
}; };
let param_def_id = self.tcx.hir().local_def_id(param.hir_id);
// Check that none of the explicit trait bounds is `Sized`. Assume that an explicit // Check that none of the explicit trait bounds is `Sized`. Assume that an explicit
// `Sized` bound is there intentionally and we don't need to suggest relaxing it. // `Sized` bound is there intentionally and we don't need to suggest relaxing it.
let explicitly_sized = generics let explicitly_sized = generics
.bounds_for_param(param_def_id) .bounds_for_param(param.def_id)
.flat_map(|bp| bp.bounds) .flat_map(|bp| bp.bounds)
.any(|bound| bound.trait_ref().and_then(|tr| tr.trait_def_id()) == sized_trait); .any(|bound| bound.trait_ref().and_then(|tr| tr.trait_def_id()) == sized_trait);
if explicitly_sized { if explicitly_sized {
@ -2619,7 +2618,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
_ => {} _ => {}
}; };
// Didn't add an indirection suggestion, so add a general suggestion to relax `Sized`. // Didn't add an indirection suggestion, so add a general suggestion to relax `Sized`.
let (span, separator) = if let Some(s) = generics.bounds_span_for_suggestions(param_def_id) let (span, separator) = if let Some(s) = generics.bounds_span_for_suggestions(param.def_id)
{ {
(s, " +") (s, " +")
} else { } else {

View file

@ -2125,7 +2125,7 @@ fn clean_maybe_renamed_item<'tcx>(
fn clean_variant<'tcx>(variant: &hir::Variant<'tcx>, cx: &mut DocContext<'tcx>) -> Item { fn clean_variant<'tcx>(variant: &hir::Variant<'tcx>, cx: &mut DocContext<'tcx>) -> Item {
let kind = VariantItem(clean_variant_data(&variant.data, &variant.disr_expr, cx)); let kind = VariantItem(clean_variant_data(&variant.data, &variant.disr_expr, cx));
Item::from_hir_id_and_parts(variant.id, Some(variant.ident.name), kind, cx) Item::from_hir_id_and_parts(variant.hir_id, Some(variant.ident.name), kind, cx)
} }
fn clean_impl<'tcx>( fn clean_impl<'tcx>(

View file

@ -1293,7 +1293,7 @@ impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx>
} }
fn visit_variant(&mut self, v: &'hir hir::Variant<'_>) { fn visit_variant(&mut self, v: &'hir hir::Variant<'_>) {
self.visit_testable(v.ident.to_string(), v.id, v.span, |this| { self.visit_testable(v.ident.to_string(), v.hir_id, v.span, |this| {
intravisit::walk_variant(this, v); intravisit::walk_variant(this, v);
}); });
} }

View file

@ -244,10 +244,10 @@ impl<'a, 'b> DocVisitor for CoverageCalculator<'a, 'b> {
matches!( matches!(
node, node,
hir::Node::Variant(hir::Variant { hir::Node::Variant(hir::Variant {
data: hir::VariantData::Tuple(_, _), data: hir::VariantData::Tuple(_, _, _),
.. ..
}) | hir::Node::Item(hir::Item { }) | hir::Node::Item(hir::Item {
kind: hir::ItemKind::Struct(hir::VariantData::Tuple(_, _), _), kind: hir::ItemKind::Struct(hir::VariantData::Tuple(_, _, _), _),
.. ..
}) })
) )

View file

@ -22,8 +22,6 @@ trait MyIndex<'a, T> {}
#[lang = "phantom_data"] #[lang = "phantom_data"]
//~^ ERROR `phantom_data` language item must be applied to a struct with 1 generic argument //~^ ERROR `phantom_data` language item must be applied to a struct with 1 generic argument
struct MyPhantomData<T, U>; struct MyPhantomData<T, U>;
//~^ ERROR parameter `T` is never used
//~| ERROR parameter `U` is never used
#[lang = "owned_box"] #[lang = "owned_box"]
//~^ ERROR `owned_box` language item must be applied to a struct with at least 1 generic argument //~^ ERROR `owned_box` language item must be applied to a struct with at least 1 generic argument

View file

@ -33,7 +33,7 @@ LL | struct MyPhantomData<T, U>;
| ------ this struct has 2 generic arguments | ------ this struct has 2 generic arguments
error[E0718]: `owned_box` language item must be applied to a struct with at least 1 generic argument error[E0718]: `owned_box` language item must be applied to a struct with at least 1 generic argument
--> $DIR/lang-item-generic-requirements.rs:28:1 --> $DIR/lang-item-generic-requirements.rs:26:1
| |
LL | #[lang = "owned_box"] LL | #[lang = "owned_box"]
| ^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^
@ -42,7 +42,7 @@ LL | struct Foo;
| - this struct has 0 generic arguments | - this struct has 0 generic arguments
error[E0718]: `start` language item must be applied to a function with 1 generic argument error[E0718]: `start` language item must be applied to a function with 1 generic argument
--> $DIR/lang-item-generic-requirements.rs:34:1 --> $DIR/lang-item-generic-requirements.rs:32:1
| |
LL | #[lang = "start"] LL | #[lang = "start"]
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
@ -50,25 +50,6 @@ LL |
LL | fn start(_: *const u8, _: isize, _: *const *const u8) -> isize { LL | fn start(_: *const u8, _: isize, _: *const *const u8) -> isize {
| - this function has 0 generic arguments | - this function has 0 generic arguments
error[E0392]: parameter `T` is never used error: aborting due to 6 previous errors
--> $DIR/lang-item-generic-requirements.rs:24:22
|
LL | struct MyPhantomData<T, U>;
| ^ unused parameter
|
= help: consider removing `T` or referring to it in a field
= help: if you intended `T` to be a const parameter, use `const T: usize` instead
error[E0392]: parameter `U` is never used For more information about this error, try `rustc --explain E0718`.
--> $DIR/lang-item-generic-requirements.rs:24:25
|
LL | struct MyPhantomData<T, U>;
| ^ unused parameter
|
= help: consider removing `U` or referring to it in a field
= help: if you intended `U` to be a const parameter, use `const U: usize` instead
error: aborting due to 8 previous errors
Some errors have detailed explanations: E0392, E0718.
For more information about an error, try `rustc --explain E0392`.

View file

@ -3,7 +3,11 @@ fn main() {
.map( .map(
#[target_feature(enable = "")] #[target_feature(enable = "")]
//~^ ERROR: attribute should be applied to a function //~^ ERROR: attribute should be applied to a function
//~| ERROR: feature named `` is not valid
//~| NOTE: `` is not valid for this target
#[track_caller] #[track_caller]
//~^ ERROR: `#[track_caller]` on closures is currently unstable
//~| NOTE: see issue #87417
|_| (), |_| (),
//~^ NOTE: not a function //~^ NOTE: not a function
) )

View file

@ -7,5 +7,21 @@ LL | #[target_feature(enable = "")]
LL | |_| (), LL | |_| (),
| ------ not a function definition | ------ not a function definition
error: aborting due to previous error error: the feature named `` is not valid for this target
--> $DIR/issue-68060.rs:4:30
|
LL | #[target_feature(enable = "")]
| ^^^^^^^^^^^ `` is not valid for this target
error[E0658]: `#[track_caller]` on closures is currently unstable
--> $DIR/issue-68060.rs:8:13
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^
|
= note: see issue #87417 <https://github.com/rust-lang/rust/issues/87417> for more information
= help: add `#![feature(closure_track_caller)]` to the crate attributes to enable
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0658`.

View file

@ -8,12 +8,6 @@ LL | fn panic(info: PanicInfo) -> ! {
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib = note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
= note: second definition in the local crate (`panic_handler_std`) = note: second definition in the local crate (`panic_handler_std`)
error: argument should be `&PanicInfo` error: aborting due to previous error
--> $DIR/panic-handler-std.rs:8:16
|
LL | fn panic(info: PanicInfo) -> ! {
| ^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0152`. For more information about this error, try `rustc --explain E0152`.

View file

@ -1,5 +1,3 @@
// error-pattern: `#[panic_handler]` function required, but not found
// Regression test for #54505 - range borrowing suggestion had // Regression test for #54505 - range borrowing suggestion had
// incorrect syntax (missing parentheses). // incorrect syntax (missing parentheses).
@ -18,6 +16,10 @@ extern "C" fn eh_personality() {}
#[lang = "eh_catch_typeinfo"] #[lang = "eh_catch_typeinfo"]
static EH_CATCH_TYPEINFO: u8 = 0; static EH_CATCH_TYPEINFO: u8 = 0;
#[panic_handler]
fn panic_handler() {}
//~^ ERROR return type should be `!`
//~| ERROR function should have one argument
// take a reference to any built-in range // take a reference to any built-in range
fn take_range(_r: &impl RangeBounds<i8>) {} fn take_range(_r: &impl RangeBounds<i8>) {}

View file

@ -1,7 +1,17 @@
error: `#[panic_handler]` function required, but not found error: return type should be `!`
--> $DIR/issue-54505-no-std.rs:20:20
|
LL | fn panic_handler() {}
| ^
error: function should have one argument
--> $DIR/issue-54505-no-std.rs:20:1
|
LL | fn panic_handler() {}
| ^^^^^^^^^^^^^^^^^^
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-54505-no-std.rs:27:16 --> $DIR/issue-54505-no-std.rs:29:16
| |
LL | take_range(0..1); LL | take_range(0..1);
| ---------- ^^^^ | ---------- ^^^^
@ -13,13 +23,13 @@ LL | take_range(0..1);
= note: expected reference `&_` = note: expected reference `&_`
found struct `Range<{integer}>` found struct `Range<{integer}>`
note: function defined here note: function defined here
--> $DIR/issue-54505-no-std.rs:23:4 --> $DIR/issue-54505-no-std.rs:25:4
| |
LL | fn take_range(_r: &impl RangeBounds<i8>) {} LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ ------------------------- | ^^^^^^^^^^ -------------------------
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-54505-no-std.rs:32:16 --> $DIR/issue-54505-no-std.rs:34:16
| |
LL | take_range(1..); LL | take_range(1..);
| ---------- ^^^ | ---------- ^^^
@ -31,13 +41,13 @@ LL | take_range(1..);
= note: expected reference `&_` = note: expected reference `&_`
found struct `RangeFrom<{integer}>` found struct `RangeFrom<{integer}>`
note: function defined here note: function defined here
--> $DIR/issue-54505-no-std.rs:23:4 --> $DIR/issue-54505-no-std.rs:25:4
| |
LL | fn take_range(_r: &impl RangeBounds<i8>) {} LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ ------------------------- | ^^^^^^^^^^ -------------------------
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-54505-no-std.rs:37:16 --> $DIR/issue-54505-no-std.rs:39:16
| |
LL | take_range(..); LL | take_range(..);
| ---------- ^^ | ---------- ^^
@ -49,13 +59,13 @@ LL | take_range(..);
= note: expected reference `&_` = note: expected reference `&_`
found struct `RangeFull` found struct `RangeFull`
note: function defined here note: function defined here
--> $DIR/issue-54505-no-std.rs:23:4 --> $DIR/issue-54505-no-std.rs:25:4
| |
LL | fn take_range(_r: &impl RangeBounds<i8>) {} LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ ------------------------- | ^^^^^^^^^^ -------------------------
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-54505-no-std.rs:42:16 --> $DIR/issue-54505-no-std.rs:44:16
| |
LL | take_range(0..=1); LL | take_range(0..=1);
| ---------- ^^^^^ | ---------- ^^^^^
@ -67,13 +77,13 @@ LL | take_range(0..=1);
= note: expected reference `&_` = note: expected reference `&_`
found struct `RangeInclusive<{integer}>` found struct `RangeInclusive<{integer}>`
note: function defined here note: function defined here
--> $DIR/issue-54505-no-std.rs:23:4 --> $DIR/issue-54505-no-std.rs:25:4
| |
LL | fn take_range(_r: &impl RangeBounds<i8>) {} LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ ------------------------- | ^^^^^^^^^^ -------------------------
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-54505-no-std.rs:47:16 --> $DIR/issue-54505-no-std.rs:49:16
| |
LL | take_range(..5); LL | take_range(..5);
| ---------- ^^^ | ---------- ^^^
@ -85,13 +95,13 @@ LL | take_range(..5);
= note: expected reference `&_` = note: expected reference `&_`
found struct `RangeTo<{integer}>` found struct `RangeTo<{integer}>`
note: function defined here note: function defined here
--> $DIR/issue-54505-no-std.rs:23:4 --> $DIR/issue-54505-no-std.rs:25:4
| |
LL | fn take_range(_r: &impl RangeBounds<i8>) {} LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ ------------------------- | ^^^^^^^^^^ -------------------------
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/issue-54505-no-std.rs:52:16 --> $DIR/issue-54505-no-std.rs:54:16
| |
LL | take_range(..=42); LL | take_range(..=42);
| ---------- ^^^^^ | ---------- ^^^^^
@ -103,11 +113,11 @@ LL | take_range(..=42);
= note: expected reference `&_` = note: expected reference `&_`
found struct `RangeToInclusive<{integer}>` found struct `RangeToInclusive<{integer}>`
note: function defined here note: function defined here
--> $DIR/issue-54505-no-std.rs:23:4 --> $DIR/issue-54505-no-std.rs:25:4
| |
LL | fn take_range(_r: &impl RangeBounds<i8>) {} LL | fn take_range(_r: &impl RangeBounds<i8>) {}
| ^^^^^^^^^^ ------------------------- | ^^^^^^^^^^ -------------------------
error: aborting due to 7 previous errors error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0308`. For more information about this error, try `rustc --explain E0308`.

View file

@ -119,40 +119,40 @@ hir-stats HIR STATS
hir-stats Name Accumulated Size Count Item Size hir-stats Name Accumulated Size Count Item Size
hir-stats ---------------------------------------------------------------- hir-stats ----------------------------------------------------------------
hir-stats ForeignItemRef 24 ( 0.3%) 1 24 hir-stats ForeignItemRef 24 ( 0.3%) 1 24
hir-stats Lifetime 32 ( 0.4%) 1 32 hir-stats Lifetime 32 ( 0.3%) 1 32
hir-stats Mod 32 ( 0.4%) 1 32 hir-stats Mod 32 ( 0.3%) 1 32
hir-stats ExprField 40 ( 0.4%) 1 40 hir-stats ExprField 40 ( 0.4%) 1 40
hir-stats TraitItemRef 56 ( 0.6%) 2 28 hir-stats TraitItemRef 56 ( 0.6%) 2 28
hir-stats Local 64 ( 0.7%) 1 64 hir-stats Local 64 ( 0.7%) 1 64
hir-stats Param 64 ( 0.7%) 2 32 hir-stats Param 64 ( 0.7%) 2 32
hir-stats InlineAsm 72 ( 0.8%) 1 72 hir-stats InlineAsm 72 ( 0.8%) 1 72
hir-stats ImplItemRef 72 ( 0.8%) 2 36 hir-stats ImplItemRef 72 ( 0.8%) 2 36
hir-stats Body 96 ( 1.1%) 3 32 hir-stats Body 96 ( 1.0%) 3 32
hir-stats GenericArg 96 ( 1.1%) 4 24 hir-stats FieldDef 96 ( 1.0%) 2 48
hir-stats - Type 24 ( 0.3%) 1 hir-stats Arm 96 ( 1.0%) 2 48
hir-stats - Lifetime 72 ( 0.8%) 3 hir-stats Stmt 96 ( 1.0%) 3 32
hir-stats FieldDef 96 ( 1.1%) 2 48 hir-stats - Local 32 ( 0.3%) 1
hir-stats Arm 96 ( 1.1%) 2 48 hir-stats - Semi 32 ( 0.3%) 1
hir-stats Stmt 96 ( 1.1%) 3 32 hir-stats - Expr 32 ( 0.3%) 1
hir-stats - Local 32 ( 0.4%) 1
hir-stats - Semi 32 ( 0.4%) 1
hir-stats - Expr 32 ( 0.4%) 1
hir-stats FnDecl 120 ( 1.3%) 3 40 hir-stats FnDecl 120 ( 1.3%) 3 40
hir-stats Attribute 128 ( 1.4%) 4 32 hir-stats Attribute 128 ( 1.4%) 4 32
hir-stats GenericArg 128 ( 1.4%) 4 32
hir-stats - Type 32 ( 0.3%) 1
hir-stats - Lifetime 96 ( 1.0%) 3
hir-stats GenericArgs 144 ( 1.6%) 3 48 hir-stats GenericArgs 144 ( 1.6%) 3 48
hir-stats Variant 160 ( 1.8%) 2 80 hir-stats Variant 176 ( 1.9%) 2 88
hir-stats GenericBound 192 ( 2.1%) 4 48 hir-stats GenericBound 192 ( 2.1%) 4 48
hir-stats - Trait 192 ( 2.1%) 4 hir-stats - Trait 192 ( 2.1%) 4
hir-stats WherePredicate 192 ( 2.1%) 3 64 hir-stats WherePredicate 192 ( 2.1%) 3 64
hir-stats - BoundPredicate 192 ( 2.1%) 3 hir-stats - BoundPredicate 192 ( 2.1%) 3
hir-stats Block 288 ( 3.2%) 6 48 hir-stats Block 288 ( 3.1%) 6 48
hir-stats Pat 360 ( 3.9%) 5 72 hir-stats Pat 360 ( 3.9%) 5 72
hir-stats - Wild 72 ( 0.8%) 1 hir-stats - Wild 72 ( 0.8%) 1
hir-stats - Struct 72 ( 0.8%) 1 hir-stats - Struct 72 ( 0.8%) 1
hir-stats - Binding 216 ( 2.4%) 3 hir-stats - Binding 216 ( 2.4%) 3
hir-stats GenericParam 400 ( 4.4%) 5 80 hir-stats GenericParam 400 ( 4.4%) 5 80
hir-stats Generics 560 ( 6.1%) 10 56 hir-stats Generics 560 ( 6.1%) 10 56
hir-stats Ty 720 ( 7.9%) 15 48 hir-stats Ty 720 ( 7.8%) 15 48
hir-stats - Ptr 48 ( 0.5%) 1 hir-stats - Ptr 48 ( 0.5%) 1
hir-stats - Rptr 48 ( 0.5%) 1 hir-stats - Rptr 48 ( 0.5%) 1
hir-stats - Path 624 ( 6.8%) 13 hir-stats - Path 624 ( 6.8%) 13
@ -169,10 +169,10 @@ hir-stats - Enum 80 ( 0.9%) 1
hir-stats - ExternCrate 80 ( 0.9%) 1 hir-stats - ExternCrate 80 ( 0.9%) 1
hir-stats - ForeignMod 80 ( 0.9%) 1 hir-stats - ForeignMod 80 ( 0.9%) 1
hir-stats - Impl 80 ( 0.9%) 1 hir-stats - Impl 80 ( 0.9%) 1
hir-stats - Fn 160 ( 1.8%) 2 hir-stats - Fn 160 ( 1.7%) 2
hir-stats - Use 400 ( 4.4%) 5 hir-stats - Use 400 ( 4.4%) 5
hir-stats Path 1_280 (14.0%) 32 40 hir-stats Path 1_280 (13.9%) 32 40
hir-stats PathSegment 1_920 (21.0%) 40 48 hir-stats PathSegment 1_920 (20.9%) 40 48
hir-stats ---------------------------------------------------------------- hir-stats ----------------------------------------------------------------
hir-stats Total 9_128 hir-stats Total 9_176
hir-stats hir-stats

View file

@ -4,36 +4,6 @@ error: malformed `target_feature` attribute input
LL | #[target_feature = "+sse2"] LL | #[target_feature = "+sse2"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[target_feature(enable = "name")]` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[target_feature(enable = "name")]`
error: the feature named `foo` is not valid for this target
--> $DIR/invalid-attribute.rs:19:18
|
LL | #[target_feature(enable = "foo")]
| ^^^^^^^^^^^^^^ `foo` is not valid for this target
error: malformed `target_feature` attribute input
--> $DIR/invalid-attribute.rs:22:18
|
LL | #[target_feature(bar)]
| ^^^ help: must be of the form: `enable = ".."`
error: malformed `target_feature` attribute input
--> $DIR/invalid-attribute.rs:24:18
|
LL | #[target_feature(disable = "baz")]
| ^^^^^^^^^^^^^^^ help: must be of the form: `enable = ".."`
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
--> $DIR/invalid-attribute.rs:28:1
|
LL | #[target_feature(enable = "sse2")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | fn bar() {}
| -------- not an `unsafe` function
|
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
error: attribute should be applied to a function definition error: attribute should be applied to a function definition
--> $DIR/invalid-attribute.rs:34:1 --> $DIR/invalid-attribute.rs:34:1
| |
@ -92,12 +62,6 @@ LL |
LL | trait Baz {} LL | trait Baz {}
| ------------ not a function definition | ------------ not a function definition
error: cannot use `#[inline(always)]` with `#[target_feature]`
--> $DIR/invalid-attribute.rs:67:1
|
LL | #[inline(always)]
| ^^^^^^^^^^^^^^^^^
error: attribute should be applied to a function definition error: attribute should be applied to a function definition
--> $DIR/invalid-attribute.rs:85:5 --> $DIR/invalid-attribute.rs:85:5
| |
@ -119,6 +83,42 @@ LL |
LL | || {}; LL | || {};
| ----- not a function definition | ----- not a function definition
error: the feature named `foo` is not valid for this target
--> $DIR/invalid-attribute.rs:19:18
|
LL | #[target_feature(enable = "foo")]
| ^^^^^^^^^^^^^^ `foo` is not valid for this target
error: malformed `target_feature` attribute input
--> $DIR/invalid-attribute.rs:22:18
|
LL | #[target_feature(bar)]
| ^^^ help: must be of the form: `enable = ".."`
error: malformed `target_feature` attribute input
--> $DIR/invalid-attribute.rs:24:18
|
LL | #[target_feature(disable = "baz")]
| ^^^^^^^^^^^^^^^ help: must be of the form: `enable = ".."`
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
--> $DIR/invalid-attribute.rs:28:1
|
LL | #[target_feature(enable = "sse2")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | fn bar() {}
| -------- not an `unsafe` function
|
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
error: cannot use `#[inline(always)]` with `#[target_feature]`
--> $DIR/invalid-attribute.rs:67:1
|
LL | #[inline(always)]
| ^^^^^^^^^^^^^^^^^
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
--> $DIR/invalid-attribute.rs:77:5 --> $DIR/invalid-attribute.rs:77:5
| |

View file

@ -7,10 +7,8 @@ trait Sized { } //~ ERROR found duplicate lang item `sized`
fn ref_Struct(self: &Struct, f: &u32) -> &u32 { fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
//~^ ERROR `self` parameter is only allowed in associated functions //~^ ERROR `self` parameter is only allowed in associated functions
//~| ERROR cannot find type `Struct` in this scope //~| ERROR cannot find type `Struct` in this scope
//~| ERROR mismatched types
let x = x << 1; let x = x << 1;
//~^ ERROR the size for values of type `{integer}` cannot be known at compilation time //~^ ERROR cannot find value `x` in this scope
//~| ERROR cannot find value `x` in this scope
} }
fn main() {} fn main() {}

View file

@ -13,7 +13,7 @@ LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
| ^^^^^^ not found in this scope | ^^^^^^ not found in this scope
error[E0425]: cannot find value `x` in this scope error[E0425]: cannot find value `x` in this scope
--> $DIR/issue-102989.rs:11:13 --> $DIR/issue-102989.rs:10:13
| |
LL | let x = x << 1; LL | let x = x << 1;
| ^ help: a local variable with a similar name exists: `f` | ^ help: a local variable with a similar name exists: `f`
@ -28,32 +28,7 @@ LL | trait Sized { }
= note: first definition in `core` loaded from SYSROOT/libcore-*.rlib = note: first definition in `core` loaded from SYSROOT/libcore-*.rlib
= note: second definition in the local crate (`issue_102989`) = note: second definition in the local crate (`issue_102989`)
error[E0277]: the size for values of type `{integer}` cannot be known at compilation time error: aborting due to 4 previous errors
--> $DIR/issue-102989.rs:11:15
|
LL | let x = x << 1;
| ^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `{integer}`
error[E0308]: mismatched types Some errors have detailed explanations: E0152, E0412, E0425.
--> $DIR/issue-102989.rs:7:42
|
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
| ---------- ^^^^ expected `&u32`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
note: consider returning one of these bindings
--> $DIR/issue-102989.rs:7:30
|
LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
| ^
...
LL | let x = x << 1;
| ^
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0152, E0277, E0308, E0412, E0425.
For more information about an error, try `rustc --explain E0152`. For more information about an error, try `rustc --explain E0152`.

View file

@ -157,10 +157,10 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
&& def.variants.len() > 1 && def.variants.len() > 1
{ {
let mut iter = def.variants.iter().filter_map(|v| { let mut iter = def.variants.iter().filter_map(|v| {
let id = cx.tcx.hir().local_def_id(v.id); let id = cx.tcx.hir().local_def_id(v.hir_id);
(matches!(v.data, hir::VariantData::Unit(_)) (matches!(v.data, hir::VariantData::Unit(..))
&& v.ident.as_str().starts_with('_') && v.ident.as_str().starts_with('_')
&& is_doc_hidden(cx.tcx.hir().attrs(v.id))) && is_doc_hidden(cx.tcx.hir().attrs(v.hir_id)))
.then_some((id, v.span)) .then_some((id, v.span))
}); });
if let Some((id, span)) = iter.next() if let Some((id, span)) = iter.next()

View file

@ -199,7 +199,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
} }
fn check_variant(&mut self, cx: &LateContext<'tcx>, v: &'tcx hir::Variant<'_>) { fn check_variant(&mut self, cx: &LateContext<'tcx>, v: &'tcx hir::Variant<'_>) {
let attrs = cx.tcx.hir().attrs(v.id); let attrs = cx.tcx.hir().attrs(v.hir_id);
if !is_from_proc_macro(cx, v) { if !is_from_proc_macro(cx, v) {
self.check_missing_docs_attrs(cx, attrs, v.span, "a", "variant"); self.check_missing_docs_attrs(cx, attrs, v.span, "a", "variant");
} }