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:
commit
7c75fe4c85
63 changed files with 449 additions and 549 deletions
|
@ -643,6 +643,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
// `static |_task_context| -> <ret_ty> { body }`:
|
||||
let generator_kind = {
|
||||
let c = self.arena.alloc(hir::Closure {
|
||||
def_id: self.local_def_id(closure_node_id),
|
||||
binder: hir::ClosureBinder::Default,
|
||||
capture_clause,
|
||||
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 c = self.arena.alloc(hir::Closure {
|
||||
def_id: self.local_def_id(closure_id),
|
||||
binder: binder_clause,
|
||||
capture_clause,
|
||||
bound_generic_params,
|
||||
|
@ -999,6 +1001,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
self.lower_fn_decl(&outer_decl, None, fn_decl_span, FnDeclKind::Closure, None);
|
||||
|
||||
let c = self.arena.alloc(hir::Closure {
|
||||
def_id: self.local_def_id(closure_id),
|
||||
binder: binder_clause,
|
||||
capture_clause,
|
||||
bound_generic_params,
|
||||
|
|
|
@ -307,8 +307,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &'hir Variant<'hir>) {
|
||||
self.insert(v.span, v.id, Node::Variant(v));
|
||||
self.with_parent(v.id, |this| {
|
||||
self.insert(v.span, v.hir_id, Node::Variant(v));
|
||||
self.with_parent(v.hir_id, |this| {
|
||||
// Register the constructor of this variant.
|
||||
if let Some(ctor_hir_id) = v.data.ctor_hir_id() {
|
||||
this.insert(v.span, ctor_hir_id, Node::Ctor(&v.data));
|
||||
|
|
|
@ -709,11 +709,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
}
|
||||
|
||||
fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
|
||||
let id = self.lower_node_id(v.id);
|
||||
self.lower_attrs(id, &v.attrs);
|
||||
let hir_id = self.lower_node_id(v.id);
|
||||
self.lower_attrs(hir_id, &v.attrs);
|
||||
hir::Variant {
|
||||
id,
|
||||
data: self.lower_variant_data(id, &v.data),
|
||||
hir_id,
|
||||
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)),
|
||||
ident: self.lower_ident(v.ident),
|
||||
span: self.lower_span(v.span),
|
||||
|
@ -739,12 +740,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
fields.iter().enumerate().map(|f| self.lower_field_def(f)),
|
||||
),
|
||||
ctor_id,
|
||||
self.local_def_id(id),
|
||||
)
|
||||
}
|
||||
VariantData::Unit(id) => {
|
||||
let ctor_id = self.lower_node_id(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 {
|
||||
span: self.lower_span(f.span),
|
||||
hir_id,
|
||||
def_id: self.local_def_id(f.id),
|
||||
ident: match f.ident {
|
||||
Some(ident) => self.lower_ident(ident),
|
||||
// FIXME(jseyfried): positional field hygiene.
|
||||
|
|
|
@ -830,8 +830,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
),
|
||||
};
|
||||
let hir_id = self.lower_node_id(node_id);
|
||||
let def_id = self.local_def_id(node_id);
|
||||
Some(hir::GenericParam {
|
||||
hir_id,
|
||||
def_id,
|
||||
name,
|
||||
span: self.lower_span(ident.span),
|
||||
pure_wrt_drop: false,
|
||||
|
@ -1165,7 +1167,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
let node_id = self.next_node_id();
|
||||
|
||||
// Add a definition for the in-band const def.
|
||||
self.create_def(
|
||||
let def_id = self.create_def(
|
||||
parent_def_id.def_id,
|
||||
node_id,
|
||||
DefPathData::AnonConst,
|
||||
|
@ -1181,6 +1183,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
};
|
||||
|
||||
let ct = self.with_new_scopes(|this| hir::AnonConst {
|
||||
def_id,
|
||||
hir_id: this.lower_node_id(node_id),
|
||||
body: this.lower_const_body(path_expr.span, Some(&path_expr)),
|
||||
});
|
||||
|
@ -1528,6 +1531,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
|
||||
hir::GenericParam {
|
||||
hir_id,
|
||||
def_id: lctx.local_def_id(new_node_id),
|
||||
name,
|
||||
span: lifetime.ident.span,
|
||||
pure_wrt_drop: false,
|
||||
|
@ -1985,6 +1989,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
|
||||
hir::GenericParam {
|
||||
hir_id,
|
||||
def_id: this.local_def_id(new_node_id),
|
||||
name,
|
||||
span: lifetime.ident.span,
|
||||
pure_wrt_drop: false,
|
||||
|
@ -2183,6 +2188,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
self.lower_attrs(hir_id, ¶m.attrs);
|
||||
hir::GenericParam {
|
||||
hir_id,
|
||||
def_id: self.local_def_id(param.id),
|
||||
name,
|
||||
span: self.lower_span(param.span()),
|
||||
pure_wrt_drop: self.tcx.sess.contains_name(¶m.attrs, sym::may_dangle),
|
||||
|
@ -2287,6 +2293,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
// Set the name to `impl Bound1 + Bound2`.
|
||||
let param = hir::GenericParam {
|
||||
hir_id: self.lower_node_id(node_id),
|
||||
def_id,
|
||||
name: ParamName::Plain(self.lower_ident(ident)),
|
||||
pure_wrt_drop: false,
|
||||
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 {
|
||||
self.with_new_scopes(|this| hir::AnonConst {
|
||||
def_id: this.local_def_id(c.id),
|
||||
hir_id: this.lower_node_id(c.id),
|
||||
body: this.lower_const_body(c.value.span, Some(&c.value)),
|
||||
})
|
||||
|
|
|
@ -42,8 +42,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
user_provided_sig = None;
|
||||
} else {
|
||||
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_poly_sig| {
|
||||
user_provided_sig =
|
||||
typeck_results.user_provided_sigs.get(&mir_def_id).map(|user_provided_poly_sig| {
|
||||
// Instantiate the canonicalized variables from
|
||||
// user-provided signature (e.g., the `_` in the code
|
||||
// above) with fresh variables.
|
||||
|
@ -60,8 +60,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||
LateBoundRegionConversionTime::FnCall,
|
||||
poly_sig,
|
||||
)
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
debug!(?normalized_input_tys, ?body.local_decls);
|
||||
|
|
|
@ -40,12 +40,12 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
|
|||
.iter()
|
||||
.map(|(op, op_sp)| match *op {
|
||||
hir::InlineAsmOperand::Const { ref anon_const } => {
|
||||
let anon_const_def_id =
|
||||
cx.tcx().hir().local_def_id(anon_const.hir_id).to_def_id();
|
||||
let const_value =
|
||||
cx.tcx().const_eval_poly(anon_const_def_id).unwrap_or_else(
|
||||
|_| span_bug!(*op_sp, "asm const cannot be resolved"),
|
||||
);
|
||||
let const_value = cx
|
||||
.tcx()
|
||||
.const_eval_poly(anon_const.def_id.to_def_id())
|
||||
.unwrap_or_else(|_| {
|
||||
span_bug!(*op_sp, "asm const cannot be resolved")
|
||||
});
|
||||
let ty = cx
|
||||
.tcx()
|
||||
.typeck_body(anon_const.body)
|
||||
|
|
|
@ -487,6 +487,7 @@ pub enum GenericParamKind<'hir> {
|
|||
#[derive(Debug, HashStable_Generic)]
|
||||
pub struct GenericParam<'hir> {
|
||||
pub hir_id: HirId,
|
||||
pub def_id: LocalDefId,
|
||||
pub name: ParamName,
|
||||
pub span: Span,
|
||||
pub pure_wrt_drop: bool,
|
||||
|
@ -921,6 +922,7 @@ pub struct Crate<'hir> {
|
|||
|
||||
#[derive(Debug, HashStable_Generic)]
|
||||
pub struct Closure<'hir> {
|
||||
pub def_id: LocalDefId,
|
||||
pub binder: ClosureBinder,
|
||||
pub capture_clause: CaptureBy,
|
||||
pub bound_generic_params: &'hir [GenericParam<'hir>],
|
||||
|
@ -1615,7 +1617,7 @@ pub enum ArrayLen {
|
|||
impl ArrayLen {
|
||||
pub fn hir_id(&self) -> HirId {
|
||||
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.
|
||||
///
|
||||
/// 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)]
|
||||
pub struct AnonConst {
|
||||
pub hir_id: HirId,
|
||||
pub def_id: LocalDefId,
|
||||
pub body: BodyId,
|
||||
}
|
||||
|
||||
|
@ -2798,7 +2801,8 @@ pub struct Variant<'hir> {
|
|||
/// Name of the variant.
|
||||
pub ident: Ident,
|
||||
/// 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.
|
||||
pub data: VariantData<'hir>,
|
||||
/// Explicit discriminant (e.g., `Foo = 1`).
|
||||
|
@ -2865,6 +2869,7 @@ pub struct FieldDef<'hir> {
|
|||
pub vis_span: Span,
|
||||
pub ident: Ident,
|
||||
pub hir_id: HirId,
|
||||
pub def_id: LocalDefId,
|
||||
pub ty: &'hir Ty<'hir>,
|
||||
}
|
||||
|
||||
|
@ -2886,11 +2891,11 @@ pub enum VariantData<'hir> {
|
|||
/// A tuple variant.
|
||||
///
|
||||
/// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`.
|
||||
Tuple(&'hir [FieldDef<'hir>], HirId),
|
||||
Tuple(&'hir [FieldDef<'hir>], HirId, LocalDefId),
|
||||
/// A unit variant.
|
||||
///
|
||||
/// E.g., `Bar = ..` as in `enum Foo { Bar = .. }`.
|
||||
Unit(HirId),
|
||||
Unit(HirId, LocalDefId),
|
||||
}
|
||||
|
||||
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.
|
||||
pub fn ctor_hir_id(&self) -> Option<HirId> {
|
||||
match *self {
|
||||
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,
|
||||
/// if this node is a tuple constructor, otherwise None
|
||||
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!(ForeignItem<'_>, 72);
|
||||
static_assert_size!(ForeignItemKind<'_>, 40);
|
||||
static_assert_size!(GenericArg<'_>, 24);
|
||||
static_assert_size!(GenericArg<'_>, 32);
|
||||
static_assert_size!(GenericBound<'_>, 48);
|
||||
static_assert_size!(Generics<'_>, 56);
|
||||
static_assert_size!(Impl<'_>, 80);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
ExprKind::Closure(&Closure {
|
||||
def_id: _,
|
||||
binder: _,
|
||||
bound_generic_params,
|
||||
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>) {
|
||||
visitor.visit_ident(variant.ident);
|
||||
visitor.visit_id(variant.id);
|
||||
visitor.visit_id(variant.hir_id);
|
||||
visitor.visit_variant_data(&variant.data);
|
||||
walk_list!(visitor, visit_anon_const, &variant.disr_expr);
|
||||
}
|
||||
|
|
|
@ -432,7 +432,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
ty::Const::from_opt_const_arg_anon_const(
|
||||
tcx,
|
||||
ty::WithOptConstParam {
|
||||
did: tcx.hir().local_def_id(ct.value.hir_id),
|
||||
did: ct.value.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())
|
||||
}
|
||||
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(), local_did);
|
||||
let c = Const::from_anon_const(self.tcx(), c.def_id);
|
||||
ConvertedBindingKind::Equality(c.into())
|
||||
}
|
||||
},
|
||||
|
@ -856,7 +855,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
&self,
|
||||
bounds: &mut Bounds<'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,
|
||||
) {
|
||||
let tcx = self.tcx();
|
||||
|
@ -876,10 +875,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
};
|
||||
search_bounds(ast_bounds);
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -2722,8 +2720,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let length = match length {
|
||||
&hir::ArrayLen::Infer(_, span) => self.ct_infer(tcx.types.usize, None, span),
|
||||
hir::ArrayLen::Body(constant) => {
|
||||
let length_def_id = tcx.hir().local_def_id(constant.hir_id);
|
||||
ty::Const::from_anon_const(tcx, length_def_id)
|
||||
ty::Const::from_anon_const(tcx, constant.def_id)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2731,7 +2728,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
self.normalize_ty(ast_ty.span, array_ty)
|
||||
}
|
||||
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, _| {
|
||||
if r.is_erased() { tcx.lifetimes.re_static } else { r }
|
||||
});
|
||||
|
|
|
@ -853,7 +853,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
|
|||
|
||||
// Const parameters are well formed if their type is structural match.
|
||||
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 let Some(non_structural_match_ty) =
|
||||
|
|
|
@ -291,18 +291,15 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
|||
match param.kind {
|
||||
hir::GenericParamKind::Lifetime { .. } => {}
|
||||
hir::GenericParamKind::Type { default: Some(_), .. } => {
|
||||
let def_id = self.tcx.hir().local_def_id(param.hir_id);
|
||||
self.tcx.ensure().type_of(def_id);
|
||||
self.tcx.ensure().type_of(param.def_id);
|
||||
}
|
||||
hir::GenericParamKind::Type { .. } => {}
|
||||
hir::GenericParamKind::Const { default, .. } => {
|
||||
let def_id = self.tcx.hir().local_def_id(param.hir_id);
|
||||
self.tcx.ensure().type_of(def_id);
|
||||
self.tcx.ensure().type_of(param.def_id);
|
||||
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
|
||||
self.tcx.ensure().type_of(default_def_id);
|
||||
self.tcx.ensure().const_param_default(def_id);
|
||||
self.tcx.ensure().type_of(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>) {
|
||||
if let hir::ExprKind::Closure { .. } = expr.kind {
|
||||
let def_id = self.tcx.hir().local_def_id(expr.hir_id);
|
||||
self.tcx.ensure().generics_of(def_id);
|
||||
if let hir::ExprKind::Closure(closure) = expr.kind {
|
||||
self.tcx.ensure().generics_of(closure.def_id);
|
||||
self.tcx.ensure().codegen_fn_attrs(closure.def_id);
|
||||
// We do not call `type_of` for closures here as that
|
||||
// depends on typecheck and would therefore hide
|
||||
// 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().predicates_of(item.owner_id);
|
||||
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(..) => {
|
||||
tcx.ensure().codegen_fn_attrs(item.owner_id);
|
||||
let mut visitor = HirPlaceholderCollector::default();
|
||||
visitor.visit_foreign_item(item);
|
||||
placeholder_type_error(
|
||||
|
@ -632,14 +633,12 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
|||
tcx.ensure().predicates_of(def_id);
|
||||
|
||||
for f in struct_def.fields() {
|
||||
let def_id = tcx.hir().local_def_id(f.hir_id);
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure().generics_of(f.def_id);
|
||||
tcx.ensure().type_of(f.def_id);
|
||||
tcx.ensure().predicates_of(f.def_id);
|
||||
}
|
||||
|
||||
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() {
|
||||
let ctor_def_id = tcx.hir().local_def_id(ctor_hir_id);
|
||||
if let Some(ctor_def_id) = struct_def.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().predicates_of(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 {
|
||||
hir::TraitItemKind::Fn(..) => {
|
||||
tcx.ensure().codegen_fn_attrs(def_id);
|
||||
tcx.ensure().type_of(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);
|
||||
match impl_item.kind {
|
||||
hir::ImplItemKind::Fn(..) => {
|
||||
tcx.ensure().codegen_fn_attrs(def_id);
|
||||
tcx.ensure().fn_sig(def_id);
|
||||
}
|
||||
hir::ImplItemKind::Type(_) => {
|
||||
|
@ -813,7 +815,6 @@ fn convert_variant(
|
|||
.fields()
|
||||
.iter()
|
||||
.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();
|
||||
if let Some(prev_span) = dup_span {
|
||||
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);
|
||||
}
|
||||
|
||||
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();
|
||||
let recovered = match def {
|
||||
|
@ -866,13 +871,9 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
|
|||
.variants
|
||||
.iter()
|
||||
.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 {
|
||||
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 {
|
||||
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(
|
||||
tcx,
|
||||
variant_did,
|
||||
ctor_did,
|
||||
Some(v.def_id),
|
||||
v.data.ctor_def_id(),
|
||||
v.ident,
|
||||
discr,
|
||||
&v.data,
|
||||
|
@ -894,13 +895,10 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
|
|||
(AdtKind::Enum, variants)
|
||||
}
|
||||
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(
|
||||
tcx,
|
||||
variant_did,
|
||||
ctor_did,
|
||||
None,
|
||||
def.ctor_def_id(),
|
||||
item.ident,
|
||||
ty::VariantDiscr::Relative(0),
|
||||
def,
|
||||
|
@ -912,13 +910,10 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AdtDef<'tcx> {
|
|||
(AdtKind::Struct, variants)
|
||||
}
|
||||
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(
|
||||
tcx,
|
||||
variant_did,
|
||||
ctor_did,
|
||||
None,
|
||||
def.ctor_def_id(),
|
||||
item.ident,
|
||||
ty::VariantDiscr::Relative(0),
|
||||
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() => {
|
||||
let ty = tcx.type_of(tcx.hir().get_parent_item(hir_id));
|
||||
let inputs =
|
||||
data.fields().iter().map(|f| tcx.type_of(tcx.hir().local_def_id(f.hir_id)));
|
||||
let inputs = data.fields().iter().map(|f| tcx.type_of(f.def_id));
|
||||
ty::Binder::dummy(tcx.mk_fn_sig(
|
||||
inputs,
|
||||
ty,
|
||||
|
|
|
@ -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.
|
||||
None
|
||||
} 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:
|
||||
//
|
||||
// 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
|
||||
// see `explicit_predicates_of` for more information on this
|
||||
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[¶m_def];
|
||||
let param_def_idx = generics.param_def_id_to_index[¶m_id.to_def_id()];
|
||||
// In the above example this would be .params[..N#0]
|
||||
let params = generics.params[..param_def_idx as usize].to_owned();
|
||||
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 {
|
||||
name: param.name.ident().name,
|
||||
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,
|
||||
kind: ty::GenericParamDefKind::Lifetime,
|
||||
}));
|
||||
|
@ -286,7 +285,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
Some(ty::GenericParamDef {
|
||||
index: next_index(),
|
||||
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,
|
||||
kind,
|
||||
})
|
||||
|
@ -303,7 +302,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
Some(ty::GenericParamDef {
|
||||
index: next_index(),
|
||||
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,
|
||||
kind: ty::GenericParamDefKind::Const { has_default: default.is_some() },
|
||||
})
|
||||
|
|
|
@ -15,7 +15,6 @@ use rustc_hir::def_id::LocalDefId;
|
|||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirIdMap, LifetimeName, Node};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::middle::resolve_lifetime::*;
|
||||
use rustc_middle::ty::{self, DefIdTree, TyCtxt, TypeSuperVisitable, TypeVisitor};
|
||||
|
@ -25,9 +24,9 @@ use rustc_span::Span;
|
|||
use std::fmt;
|
||||
|
||||
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>;
|
||||
|
||||
|
@ -35,20 +34,18 @@ trait RegionExt {
|
|||
}
|
||||
|
||||
impl RegionExt for Region {
|
||||
fn early(hir_map: Map<'_>, param: &GenericParam<'_>) -> (LocalDefId, Region) {
|
||||
let def_id = hir_map.local_def_id(param.hir_id);
|
||||
debug!("Region::early: def_id={:?}", def_id);
|
||||
(def_id, Region::EarlyBound(def_id.to_def_id()))
|
||||
fn early(param: &GenericParam<'_>) -> (LocalDefId, Region) {
|
||||
debug!("Region::early: def_id={:?}", param.def_id);
|
||||
(param.def_id, Region::EarlyBound(param.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 def_id = hir_map.local_def_id(param.hir_id);
|
||||
debug!(
|
||||
"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> {
|
||||
|
@ -395,7 +392,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
.filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
|
||||
.enumerate()
|
||||
.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);
|
||||
(pair, r)
|
||||
})
|
||||
|
@ -492,7 +489,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
for param in generics.params {
|
||||
match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
let (def_id, reg) = Region::early(self.tcx.hir(), ¶m);
|
||||
let (def_id, reg) = Region::early(¶m);
|
||||
lifetimes.insert(def_id, reg);
|
||||
}
|
||||
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {}
|
||||
|
@ -523,9 +520,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
.params
|
||||
.iter()
|
||||
.filter_map(|param| match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
Some(Region::early(self.tcx.hir(), param))
|
||||
}
|
||||
GenericParamKind::Lifetime { .. } => Some(Region::early(param)),
|
||||
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => None,
|
||||
})
|
||||
.collect();
|
||||
|
@ -573,7 +568,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
.filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
|
||||
.enumerate()
|
||||
.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);
|
||||
(pair, r)
|
||||
})
|
||||
|
@ -731,9 +726,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
.params
|
||||
.iter()
|
||||
.filter_map(|param| match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
Some(Region::early(self.tcx.hir(), param))
|
||||
}
|
||||
GenericParamKind::Lifetime { .. } => Some(Region::early(param)),
|
||||
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => None,
|
||||
})
|
||||
.collect();
|
||||
|
@ -779,9 +772,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
.params
|
||||
.iter()
|
||||
.filter_map(|param| match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => {
|
||||
Some(Region::early(self.tcx.hir(), param))
|
||||
}
|
||||
GenericParamKind::Lifetime { .. } => Some(Region::early(param)),
|
||||
GenericParamKind::Const { .. } | GenericParamKind::Type { .. } => None,
|
||||
})
|
||||
.collect();
|
||||
|
@ -886,7 +877,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
})
|
||||
.enumerate()
|
||||
.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();
|
||||
let binders: Vec<_> =
|
||||
|
@ -999,8 +990,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
.filter(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))
|
||||
.enumerate()
|
||||
.map(|(late_bound_idx, param)| {
|
||||
let pair =
|
||||
Region::late(initial_bound_vars + late_bound_idx as u32, self.tcx.hir(), param);
|
||||
let pair = Region::late(initial_bound_vars + late_bound_idx as u32, param);
|
||||
let r = late_region_as_bound_region(self.tcx, &pair.1);
|
||||
lifetimes.insert(pair.0, pair.1);
|
||||
r
|
||||
|
@ -1131,9 +1121,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
if self.tcx.is_late_bound(param.hir_id) {
|
||||
let late_bound_idx = named_late_bound_vars;
|
||||
named_late_bound_vars += 1;
|
||||
Some(Region::late(late_bound_idx, self.tcx.hir(), param))
|
||||
Some(Region::late(late_bound_idx, param))
|
||||
} else {
|
||||
Some(Region::early(self.tcx.hir(), param))
|
||||
Some(Region::early(param))
|
||||
}
|
||||
}
|
||||
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => None,
|
||||
|
@ -1149,7 +1139,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
})
|
||||
.enumerate()
|
||||
.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)
|
||||
})
|
||||
.collect();
|
||||
|
|
|
@ -199,7 +199,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
|||
&icx,
|
||||
&mut bounds,
|
||||
&[],
|
||||
Some((param.hir_id, ast_generics.predicates)),
|
||||
Some((param.def_id, ast_generics.predicates)),
|
||||
param.span,
|
||||
);
|
||||
trace!(?bounds);
|
||||
|
@ -316,10 +316,9 @@ fn const_evaluatable_predicates_of<'tcx>(
|
|||
|
||||
impl<'tcx> intravisit::Visitor<'tcx> for ConstCollector<'tcx> {
|
||||
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, def_id);
|
||||
let ct = ty::Const::from_anon_const(self.tcx, c.def_id);
|
||||
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((
|
||||
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(ct))
|
||||
.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 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
|
||||
// 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)
|
||||
|
@ -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 superbounds2 = icx.type_parameter_bounds_in_generics(
|
||||
generics,
|
||||
item.hir_id(),
|
||||
item.owner_id.def_id,
|
||||
self_param_ty,
|
||||
OnlySelfBounds(!is_trait_alias),
|
||||
assoc_name,
|
||||
|
@ -641,7 +640,7 @@ pub(super) fn type_param_predicates(
|
|||
let extra_predicates = extend.into_iter().chain(
|
||||
icx.type_parameter_bounds_in_generics(
|
||||
ast_generics,
|
||||
param_id,
|
||||
def_id,
|
||||
ty,
|
||||
OnlySelfBounds(true),
|
||||
Some(assoc_name),
|
||||
|
@ -666,13 +665,11 @@ impl<'tcx> ItemCtxt<'tcx> {
|
|||
fn type_parameter_bounds_in_generics(
|
||||
&self,
|
||||
ast_generics: &'tcx hir::Generics<'tcx>,
|
||||
param_id: hir::HirId,
|
||||
param_def_id: LocalDefId,
|
||||
ty: Ty<'tcx>,
|
||||
only_self_bounds: OnlySelfBounds,
|
||||
assoc_name: Option<Ident>,
|
||||
) -> 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
|
||||
.predicates
|
||||
.iter()
|
||||
|
@ -681,7 +678,7 @@ impl<'tcx> ItemCtxt<'tcx> {
|
|||
_ => None,
|
||||
})
|
||||
.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)
|
||||
} else if !only_self_bounds.0 {
|
||||
Some(self.to_ty(bp.bounded_ty))
|
||||
|
|
|
@ -514,10 +514,10 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
|
|||
}
|
||||
|
||||
Node::GenericParam(&GenericParam {
|
||||
hir_id: param_hir_id,
|
||||
def_id: param_def_id,
|
||||
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(
|
||||
DUMMY_SP,
|
||||
|
@ -636,9 +636,8 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
|
|||
self.tcx.hir()
|
||||
}
|
||||
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
|
||||
if let hir::ExprKind::Closure { .. } = ex.kind {
|
||||
let def_id = self.tcx.hir().local_def_id(ex.hir_id);
|
||||
self.check(def_id);
|
||||
if let hir::ExprKind::Closure(closure) = ex.kind {
|
||||
self.check(closure.def_id);
|
||||
}
|
||||
intravisit::walk_expr(self, ex);
|
||||
}
|
||||
|
@ -771,9 +770,8 @@ fn find_opaque_ty_constraints_for_rpit(
|
|||
self.tcx.hir()
|
||||
}
|
||||
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
|
||||
if let hir::ExprKind::Closure { .. } = ex.kind {
|
||||
let def_id = self.tcx.hir().local_def_id(ex.hir_id);
|
||||
self.check(def_id);
|
||||
if let hir::ExprKind::Closure(closure) = ex.kind {
|
||||
self.check(closure.def_id);
|
||||
}
|
||||
intravisit::walk_expr(self, ex);
|
||||
}
|
||||
|
|
|
@ -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 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
|
||||
// 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)
|
||||
|
|
|
@ -754,7 +754,7 @@ impl<'a> State<'a> {
|
|||
for v in variants {
|
||||
self.space_if_not_bol();
|
||||
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.print_variant(v);
|
||||
self.word(",");
|
||||
|
@ -1481,6 +1481,7 @@ impl<'a> State<'a> {
|
|||
body,
|
||||
fn_decl_span: _,
|
||||
movability: _,
|
||||
def_id: _,
|
||||
}) => {
|
||||
self.print_closure_binder(binder, bound_generic_params);
|
||||
self.print_capture_clause(capture_clause);
|
||||
|
|
|
@ -26,10 +26,12 @@ pub(super) fn check_fn<'a, 'tcx>(
|
|||
param_env: ty::ParamEnv<'tcx>,
|
||||
fn_sig: ty::FnSig<'tcx>,
|
||||
decl: &'tcx hir::FnDecl<'tcx>,
|
||||
fn_id: hir::HirId,
|
||||
fn_def_id: LocalDefId,
|
||||
body: &'tcx hir::Body<'tcx>,
|
||||
can_be_generator: Option<hir::Movability>,
|
||||
) -> (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,
|
||||
// in the case of closures, based on the outer context.
|
||||
let mut fcx = FnCtxt::new(inherited, param_env, body.value.hir_id);
|
||||
|
|
|
@ -4,7 +4,7 @@ use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
|
|||
|
||||
use hir::def::DefKind;
|
||||
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_analysis::astconv::AstConv;
|
||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
|
@ -41,18 +41,14 @@ struct ClosureSignatures<'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(
|
||||
&self,
|
||||
expr: &hir::Expr<'_>,
|
||||
_capture: hir::CaptureBy,
|
||||
decl: &'tcx hir::FnDecl<'tcx>,
|
||||
body_id: hir::BodyId,
|
||||
gen: Option<hir::Movability>,
|
||||
closure: &hir::Closure<'tcx>,
|
||||
expr_span: Span,
|
||||
expected: Expectation<'tcx>,
|
||||
) -> Ty<'tcx> {
|
||||
trace!("decl = {:#?}", decl);
|
||||
trace!("expr = {:#?}", expr);
|
||||
trace!("decl = {:#?}", closure.fn_decl);
|
||||
|
||||
// It's always helpful for inference if we know the kind of
|
||||
// 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),
|
||||
None => (None, None),
|
||||
};
|
||||
let body = self.tcx.hir().body(body_id);
|
||||
self.check_closure(expr, expected_kind, decl, body, gen, expected_sig)
|
||||
let body = self.tcx.hir().body(closure.body);
|
||||
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(
|
||||
&self,
|
||||
expr: &hir::Expr<'_>,
|
||||
closure: &hir::Closure<'tcx>,
|
||||
expr_span: Span,
|
||||
opt_kind: Option<ty::ClosureKind>,
|
||||
decl: &'tcx hir::FnDecl<'tcx>,
|
||||
body: &'tcx hir::Body<'tcx>,
|
||||
gen: Option<hir::Movability>,
|
||||
expected_sig: Option<ExpectedSig<'tcx>>,
|
||||
) -> Ty<'tcx> {
|
||||
trace!("decl = {:#?}", decl);
|
||||
let expr_def_id = self.tcx.hir().local_def_id(expr.hir_id);
|
||||
trace!("decl = {:#?}", closure.fn_decl);
|
||||
let expr_def_id = closure.def_id;
|
||||
debug!(?expr_def_id);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -88,10 +83,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
self,
|
||||
self.param_env.without_const(),
|
||||
liberated_sig,
|
||||
decl,
|
||||
expr.hir_id,
|
||||
closure.fn_decl,
|
||||
expr_def_id,
|
||||
body,
|
||||
gen,
|
||||
closure.movability,
|
||||
)
|
||||
.1;
|
||||
|
||||
|
@ -102,7 +97,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
|
||||
let tupled_upvars_ty = self.next_ty_var(TypeVariableOrigin {
|
||||
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
|
||||
|
@ -148,7 +143,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
None => self.next_ty_var(TypeVariableOrigin {
|
||||
// FIXME(eddyb) distinguish closure kind inference variables from the rest.
|
||||
kind: TypeVariableOriginKind::ClosureSynthetic,
|
||||
span: expr.span,
|
||||
span: expr_span,
|
||||
}),
|
||||
};
|
||||
|
||||
|
@ -319,30 +314,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
|
||||
fn sig_of_closure(
|
||||
&self,
|
||||
hir_id: hir::HirId,
|
||||
expr_def_id: DefId,
|
||||
expr_def_id: LocalDefId,
|
||||
decl: &hir::FnDecl<'_>,
|
||||
body: &hir::Body<'_>,
|
||||
expected_sig: Option<ExpectedSig<'tcx>>,
|
||||
) -> ClosureSignatures<'tcx> {
|
||||
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 {
|
||||
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
|
||||
/// 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(
|
||||
&self,
|
||||
hir_id: hir::HirId,
|
||||
expr_def_id: DefId,
|
||||
expr_def_id: LocalDefId,
|
||||
decl: &hir::FnDecl<'_>,
|
||||
body: &hir::Body<'_>,
|
||||
) -> 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)
|
||||
}
|
||||
|
@ -388,17 +381,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
///
|
||||
/// # 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
|
||||
/// - `body`: the body of the closure
|
||||
/// - `expected_sig`: the expected signature (if any). Note that
|
||||
/// this is missing a binder: that is, there may be late-bound
|
||||
/// 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(
|
||||
&self,
|
||||
hir_id: hir::HirId,
|
||||
expr_def_id: DefId,
|
||||
expr_def_id: LocalDefId,
|
||||
decl: &hir::FnDecl<'_>,
|
||||
body: &hir::Body<'_>,
|
||||
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
|
||||
// expect.
|
||||
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 {
|
||||
return self.sig_of_closure_with_mismatched_number_of_arguments(
|
||||
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
|
||||
// wrote into our typeck results, which are then later used by the privacy
|
||||
// check.
|
||||
match self.merge_supplied_sig_with_expectation(
|
||||
hir_id,
|
||||
expr_def_id,
|
||||
decl,
|
||||
body,
|
||||
closure_sigs,
|
||||
) {
|
||||
match self.merge_supplied_sig_with_expectation(expr_def_id, decl, body, closure_sigs) {
|
||||
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(
|
||||
&self,
|
||||
expr_def_id: DefId,
|
||||
expr_def_id: LocalDefId,
|
||||
decl: &hir::FnDecl<'_>,
|
||||
body: &hir::Body<'_>,
|
||||
expected_sig: ExpectedSig<'tcx>,
|
||||
) -> ClosureSignatures<'tcx> {
|
||||
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
|
||||
.sig
|
||||
.skip_binder()
|
||||
|
@ -476,7 +462,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
None => (None, Vec::new()),
|
||||
};
|
||||
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(
|
||||
expected_span,
|
||||
closure_span,
|
||||
|
@ -494,11 +480,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
/// Enforce the user's types against the expectation. See
|
||||
/// `sig_of_closure_with_expectation` for details on the overall
|
||||
/// 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(
|
||||
&self,
|
||||
hir_id: hir::HirId,
|
||||
expr_def_id: DefId,
|
||||
expr_def_id: LocalDefId,
|
||||
decl: &hir::FnDecl<'_>,
|
||||
body: &hir::Body<'_>,
|
||||
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
|
||||
// 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);
|
||||
|
||||
|
@ -587,8 +572,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
#[instrument(skip(self, decl, body), level = "debug", ret)]
|
||||
fn supplied_sig_of_closure(
|
||||
&self,
|
||||
hir_id: hir::HirId,
|
||||
expr_def_id: DefId,
|
||||
expr_def_id: LocalDefId,
|
||||
decl: &hir::FnDecl<'_>,
|
||||
body: &hir::Body<'_>,
|
||||
) -> ty::PolyFnSig<'tcx> {
|
||||
|
@ -597,6 +581,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
trace!("decl = {:#?}", decl);
|
||||
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);
|
||||
|
||||
// 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)]
|
||||
fn deduce_future_output_from_obligations(
|
||||
&self,
|
||||
expr_def_id: DefId,
|
||||
expr_def_id: LocalDefId,
|
||||
body_id: hir::HirId,
|
||||
) -> Option<Ty<'tcx>> {
|
||||
let ret_coercion = self.ret_coercion.as_ref().unwrap_or_else(|| {
|
||||
|
@ -804,14 +789,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
|
||||
fn closure_sigs(
|
||||
&self,
|
||||
expr_def_id: DefId,
|
||||
expr_def_id: LocalDefId,
|
||||
body: &hir::Body<'_>,
|
||||
bound_sig: ty::PolyFnSig<'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(
|
||||
body.value.span,
|
||||
body.value.hir_id,
|
||||
self.tcx.hir().local_def_id_to_hir_id(expr_def_id),
|
||||
self.param_env,
|
||||
liberated_sig,
|
||||
);
|
||||
|
|
|
@ -30,7 +30,7 @@ use rustc_hir::def::{CtorKind, DefKind, Res};
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
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::check::ty_kind_suggestion;
|
||||
use rustc_infer::infer;
|
||||
|
@ -324,9 +324,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
ExprKind::Match(discrim, arms, match_src) => {
|
||||
self.check_match(expr, &discrim, arms, expected, match_src)
|
||||
}
|
||||
ExprKind::Closure(&Closure { capture_clause, fn_decl, body, movability, .. }) => {
|
||||
self.check_expr_closure(expr, capture_clause, &fn_decl, body, movability, expected)
|
||||
}
|
||||
ExprKind::Closure(closure) => self.check_expr_closure(closure, expr.span, expected),
|
||||
ExprKind::Block(body, _) => self.check_block_with_expected(&body, expected),
|
||||
ExprKind::Call(callee, args) => self.check_call(expr, &callee, args, expected),
|
||||
ExprKind::MethodCall(segment, receiver, args, _) => {
|
||||
|
|
|
@ -352,8 +352,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
self.consume_expr(base);
|
||||
}
|
||||
|
||||
hir::ExprKind::Closure { .. } => {
|
||||
self.walk_captures(expr);
|
||||
hir::ExprKind::Closure(closure) => {
|
||||
self.walk_captures(closure);
|
||||
}
|
||||
|
||||
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
|
||||
/// 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>(
|
||||
upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
|
||||
upvar_id: hir::HirId,
|
||||
|
@ -757,7 +757,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
debug!("walk_captures({:?})", closure_expr);
|
||||
|
||||
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);
|
||||
|
||||
// For purposes of this function, generator and closures are equivalent.
|
||||
|
@ -829,10 +829,11 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||
// be a local variable
|
||||
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(
|
||||
capture_info.path_expr_id.unwrap_or(
|
||||
capture_info.capture_kind_expr_id.unwrap_or(closure_expr.hir_id),
|
||||
),
|
||||
capture_info
|
||||
.path_expr_id
|
||||
.unwrap_or(capture_info.capture_kind_expr_id.unwrap_or(closure_hir_id)),
|
||||
place.base_ty,
|
||||
place_base,
|
||||
place.projections.clone(),
|
||||
|
|
|
@ -488,9 +488,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
match length {
|
||||
&hir::ArrayLen::Infer(_, span) => self.ct_infer(self.tcx.types.usize, None, span),
|
||||
hir::ArrayLen::Body(anon_const) => {
|
||||
let const_def_id = self.tcx.hir().local_def_id(anon_const.hir_id);
|
||||
let span = self.tcx.hir().span(anon_const.hir_id);
|
||||
let c = ty::Const::from_anon_const(self.tcx, const_def_id);
|
||||
let span = self.tcx.def_span(anon_const.def_id);
|
||||
let c = ty::Const::from_anon_const(self.tcx, anon_const.def_id);
|
||||
self.register_wf_obligation(c.into(), span, ObligationCauseCode::WellFormed(None));
|
||||
self.normalize_associated_types_in(span, c)
|
||||
}
|
||||
|
@ -502,10 +501,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
ast_c: &hir::AnonConst,
|
||||
param_def_id: DefId,
|
||||
) -> ty::Const<'tcx> {
|
||||
let const_def = ty::WithOptConstParam {
|
||||
did: self.tcx.hir().local_def_id(ast_c.hir_id),
|
||||
const_param_did: Some(param_def_id),
|
||||
};
|
||||
let const_def =
|
||||
ty::WithOptConstParam { did: ast_c.def_id, const_param_did: Some(param_def_id) };
|
||||
let c = ty::Const::from_opt_const_arg_anon_const(self.tcx, const_def);
|
||||
self.register_wf_obligation(
|
||||
c.into(),
|
||||
|
|
|
@ -251,7 +251,7 @@ fn typeck_with_fallback<'tcx>(
|
|||
param_env,
|
||||
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 {
|
||||
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
|
||||
let expected_type = body_ty
|
||||
|
|
|
@ -514,7 +514,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||
for (&def_id, c_sig) in fcx_typeck_results.user_provided_sigs.iter() {
|
||||
if cfg!(debug_assertions) && c_sig.needs_infer() {
|
||||
span_bug!(
|
||||
self.fcx.tcx.hir().span_if_local(def_id).unwrap(),
|
||||
self.fcx.tcx.def_span(def_id),
|
||||
"writeback: `{:?}` has inference variables",
|
||||
c_sig
|
||||
);
|
||||
|
|
|
@ -186,9 +186,8 @@ impl<'tcx> LateLintPass<'tcx> for BoxPointers {
|
|||
// If it's a struct, we also have to check the fields' types
|
||||
match it.kind {
|
||||
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
|
||||
for struct_field in struct_def.fields() {
|
||||
let def_id = cx.tcx.hir().local_def_id(struct_field.hir_id);
|
||||
self.check_heap_type(cx, struct_field.span, cx.tcx.type_of(def_id));
|
||||
for field in struct_def.fields() {
|
||||
self.check_heap_type(cx, field.span, cx.tcx.type_of(field.def_id));
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
|
@ -674,13 +673,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
|||
|
||||
fn check_field_def(&mut self, cx: &LateContext<'_>, sf: &hir::FieldDef<'_>) {
|
||||
if !sf.is_positional() {
|
||||
let def_id = cx.tcx.hir().local_def_id(sf.hir_id);
|
||||
self.check_missing_docs_attrs(cx, def_id, "a", "struct field")
|
||||
self.check_missing_docs_attrs(cx, sf.def_id, "a", "struct field")
|
||||
}
|
||||
}
|
||||
|
||||
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<'_>) {
|
||||
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(_)) {
|
||||
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<'_>) {
|
||||
|
|
|
@ -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>) {
|
||||
self.with_lint_attrs(v.id, |cx| {
|
||||
self.with_lint_attrs(v.hir_id, |cx| {
|
||||
lint_callback!(cx, check_variant, v);
|
||||
hir_visit::walk_variant(cx, v);
|
||||
})
|
||||
|
|
|
@ -320,7 +320,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'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);
|
||||
}
|
||||
|
||||
|
@ -392,7 +392,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, QueryMapExpectationsWrapper<'
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1558,9 +1558,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
// Encode def_ids for each field and method
|
||||
// for methods, write all the stuff get_trait_method
|
||||
// needs to know
|
||||
let ctor = struct_def
|
||||
.ctor_hir_id()
|
||||
.map(|ctor_hir_id| self.tcx.hir().local_def_id(ctor_hir_id).local_def_index);
|
||||
let ctor = struct_def.ctor_def_id().map(|ctor_def_id| ctor_def_id.local_def_index);
|
||||
|
||||
let variant = adt_def.non_enum_variant();
|
||||
record!(self.tables.variant_data[def_id] <- VariantData {
|
||||
|
@ -1685,8 +1683,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
hir::ItemKind::Struct(ref struct_def, _) => {
|
||||
let def = self.tcx.adt_def(item.owner_id.to_def_id());
|
||||
// If the struct has a constructor, encode it.
|
||||
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() {
|
||||
let ctor_def_id = self.tcx.hir().local_def_id(ctor_hir_id);
|
||||
if let Some(ctor_def_id) = struct_def.ctor_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) {
|
||||
let def_id = self.tcx.hir().local_def_id(hir_id);
|
||||
debug!("EncodeContext::encode_info_for_closure({:?})", def_id);
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
fn encode_info_for_closure(&mut self, def_id: LocalDefId) {
|
||||
// NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic,
|
||||
// including on the signature, which is inferred in `typeck.
|
||||
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);
|
||||
match ty.kind() {
|
||||
ty::Generator(..) => {
|
||||
|
@ -2101,11 +2098,10 @@ impl<'a, 'tcx> Visitor<'tcx> for EncodeContext<'a, 'tcx> {
|
|||
impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
fn encode_info_for_generics(&mut self, generics: &hir::Generics<'tcx>) {
|
||||
for param in generics.params {
|
||||
let def_id = self.tcx.hir().local_def_id(param.hir_id);
|
||||
match param.kind {
|
||||
hir::GenericParamKind::Lifetime { .. } | hir::GenericParamKind::Type { .. } => {}
|
||||
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() {
|
||||
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<'_>) {
|
||||
if let hir::ExprKind::Closure { .. } = expr.kind {
|
||||
self.encode_info_for_closure(expr.hir_id);
|
||||
if let hir::ExprKind::Closure(closure) = expr.kind {
|
||||
self.encode_info_for_closure(closure.def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1086,10 +1086,10 @@ impl<'hir> Map<'hir> {
|
|||
|
||||
/// Returns the HirId of `N` in `struct Foo<const N: usize = { ... }>` when
|
||||
/// 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)) {
|
||||
Node::GenericParam(GenericParam {
|
||||
hir_id: param_id,
|
||||
def_id: param_id,
|
||||
kind: GenericParamKind::Const { .. },
|
||||
..
|
||||
}) => 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 {
|
||||
let id_str = format!(" (hir_id={})", id);
|
||||
|
||||
let path_str = || {
|
||||
// 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 path_str = |def_id: LocalDefId| map.tcx.def_path_str(def_id.to_def_id());
|
||||
|
||||
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);
|
||||
|
@ -1243,18 +1230,19 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
|
|||
ItemKind::TraitAlias(..) => "trait alias",
|
||||
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(_)) => 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)
|
||||
Some(Node::ForeignItem(item)) => {
|
||||
format!("foreign item {}{}", path_str(item.owner_id.def_id), 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::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::TraitItem(ti)) => {
|
||||
let kind = match ti.kind {
|
||||
TraitItemKind::Const(..) => "assoc constant",
|
||||
|
@ -1262,13 +1250,13 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
|
|||
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)) => {
|
||||
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)) => {
|
||||
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::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::Infer(_)) => node_str("infer"),
|
||||
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::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"),
|
||||
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) {
|
||||
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)
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, ex: &'hir Expr<'hir>) {
|
||||
if matches!(ex.kind, ExprKind::Closure { .. }) {
|
||||
self.body_owners.push(self.tcx.hir().local_def_id(ex.hir_id));
|
||||
if let ExprKind::Closure(closure) = ex.kind {
|
||||
self.body_owners.push(closure.def_id);
|
||||
}
|
||||
intravisit::walk_expr(self, ex)
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::ty::codec::{TyDecoder, TyEncoder};
|
|||
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable};
|
||||
use crate::ty::print::{FmtPrinter, Printer};
|
||||
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::{GenericArg, InternalSubsts, SubstsRef};
|
||||
|
||||
|
@ -2523,12 +2523,10 @@ impl<'tcx> ConstantKind<'tcx> {
|
|||
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
|
||||
// the parent item and construct a `ParamConst`.
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
let item_id = tcx.hir().get_parent_node(hir_id);
|
||||
let item_def_id = tcx.hir().local_def_id(item_id);
|
||||
let generics = tcx.generics_of(item_def_id.to_def_id());
|
||||
let item_def_id = tcx.parent(def_id);
|
||||
let generics = tcx.generics_of(item_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 =
|
||||
tcx.mk_const(ty::ConstKind::Param(ty::ParamConst::new(index, name)), ty);
|
||||
debug!(?ty_const);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::mir::interpret::LitToConstInput;
|
||||
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_hir as hir;
|
||||
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), .. })) => {
|
||||
// Find the name and index of the const parameter by indexing the generics of
|
||||
// the parent item and construct a `ParamConst`.
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
let item_id = tcx.hir().get_parent_node(hir_id);
|
||||
let item_def_id = tcx.hir().local_def_id(item_id);
|
||||
let generics = tcx.generics_of(item_def_id.to_def_id());
|
||||
let item_def_id = tcx.parent(def_id);
|
||||
let generics = tcx.generics_of(item_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))
|
||||
}
|
||||
_ => None,
|
||||
|
@ -268,9 +266,9 @@ impl<'tcx> 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()) {
|
||||
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!(
|
||||
tcx.def_span(def_id),
|
||||
"`const_param_default` expected a generic parameter with a constant"
|
||||
|
|
|
@ -41,7 +41,7 @@ use rustc_errors::{
|
|||
};
|
||||
use rustc_hir as hir;
|
||||
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::hir_id::OwnerId;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
|
@ -443,7 +443,7 @@ pub struct TypeckResults<'tcx> {
|
|||
|
||||
/// Stores the canonicalized types provided by the user. See also
|
||||
/// `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>>>,
|
||||
|
||||
|
|
|
@ -151,7 +151,6 @@ enum SuggestChangingConstraintsMessage<'a> {
|
|||
}
|
||||
|
||||
fn suggest_removing_unsized_bound(
|
||||
tcx: TyCtxt<'_>,
|
||||
generics: &hir::Generics<'_>,
|
||||
suggestions: &mut Vec<(Span, String, SuggestChangingConstraintsMessage<'_>)>,
|
||||
param: &hir::GenericParam<'_>,
|
||||
|
@ -160,12 +159,11 @@ fn suggest_removing_unsized_bound(
|
|||
// 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`,
|
||||
// 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() {
|
||||
let WherePredicate::BoundPredicate(predicate) = predicate else {
|
||||
continue;
|
||||
};
|
||||
if !predicate.is_param_bound(param_def_id.to_def_id()) {
|
||||
if !predicate.is_param_bound(param.def_id.to_def_id()) {
|
||||
continue;
|
||||
};
|
||||
|
||||
|
@ -232,7 +230,7 @@ pub fn suggest_constraining_type_params<'a>(
|
|||
param.span,
|
||||
&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 +`
|
||||
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);
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -608,24 +608,22 @@ impl<'tcx> Cx<'tcx> {
|
|||
out_expr: out_expr.as_ref().map(|expr| self.mirror_expr(expr)),
|
||||
},
|
||||
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(
|
||||
tcx,
|
||||
anon_const_def_id,
|
||||
anon_const.def_id,
|
||||
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 }
|
||||
}
|
||||
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(
|
||||
tcx,
|
||||
anon_const_def_id,
|
||||
anon_const.def_id,
|
||||
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 }
|
||||
}
|
||||
|
@ -640,7 +638,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
|
||||
hir::ExprKind::ConstBlock(ref anon_const) => {
|
||||
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 parent_substs =
|
||||
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) => {
|
||||
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 item_def_id = self.tcx.hir().local_def_id(item_id);
|
||||
let generics = self.tcx.generics_of(item_def_id);
|
||||
let generics = self.tcx.generics_of(hir_id.owner);
|
||||
let index = generics.param_def_id_to_index[&def_id];
|
||||
let name = self.tcx.hir().name(hir_id);
|
||||
let param = ty::ParamConst::new(index, name);
|
||||
|
|
|
@ -565,8 +565,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
id: hir::HirId,
|
||||
span: Span,
|
||||
) -> 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`.
|
||||
let value = value.eval(self.tcx, self.param_env);
|
||||
|
|
|
@ -220,19 +220,18 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
|
|||
|
||||
// Additionally, tuple struct/variant constructors have MIR, but
|
||||
// they don't have a BodyId, so we need to build them separately.
|
||||
struct GatherCtors<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
struct GatherCtors<'a> {
|
||||
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>) {
|
||||
if let hir::VariantData::Tuple(_, hir_id) = *v {
|
||||
self.set.insert(self.tcx.hir().local_def_id(hir_id));
|
||||
if let hir::VariantData::Tuple(_, _, def_id) = *v {
|
||||
self.set.insert(def_id);
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
|
@ -219,18 +219,6 @@ impl CheckAttrVisitor<'_> {
|
|||
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_used(attrs, target);
|
||||
}
|
||||
|
@ -423,8 +411,7 @@ impl CheckAttrVisitor<'_> {
|
|||
if let Some(generics) = tcx.hir().get_generics(tcx.hir().local_def_id(hir_id)) {
|
||||
for p in generics.params {
|
||||
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(param_id);
|
||||
let default = tcx.object_lifetime_default(p.def_id);
|
||||
let repr = match default {
|
||||
ObjectLifetimeDefault::Empty => "BaseDefault".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>) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -362,7 +362,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
|
|||
let has_repr_c = self.repr_has_repr_c;
|
||||
let has_repr_simd = self.repr_has_repr_simd;
|
||||
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) {
|
||||
return Some(def_id);
|
||||
}
|
||||
|
@ -522,17 +522,13 @@ fn check_item<'tcx>(
|
|||
DefKind::Enum => {
|
||||
let item = tcx.hir().item(id);
|
||||
if let hir::ItemKind::Enum(ref enum_def, _) = item.kind {
|
||||
let hir = tcx.hir();
|
||||
if allow_dead_code {
|
||||
worklist.extend(
|
||||
enum_def.variants.iter().map(|variant| hir.local_def_id(variant.id)),
|
||||
);
|
||||
worklist.extend(enum_def.variants.iter().map(|variant| variant.def_id));
|
||||
}
|
||||
|
||||
for variant in enum_def.variants {
|
||||
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() {
|
||||
struct_constructors
|
||||
.insert(hir.local_def_id(ctor_hir_id), hir.local_def_id(variant.id));
|
||||
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
|
||||
struct_constructors.insert(ctor_def_id, variant.def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems {
|
|||
let item = tcx.hir().item(id);
|
||||
if let hir::ItemKind::Enum(def, ..) = &item.kind {
|
||||
for variant in def.variants {
|
||||
collector.check_for_lang(Target::Variant, variant.id);
|
||||
collector.check_for_lang(Target::Variant, variant.hir_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -413,7 +413,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
|
|||
}
|
||||
intravisit::walk_expr(self, expr);
|
||||
}
|
||||
hir::ExprKind::Closure { .. } => {
|
||||
hir::ExprKind::Closure(closure) => {
|
||||
// Interesting control flow (for loops can contain labeled
|
||||
// breaks or continues)
|
||||
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
|
||||
// construction site.
|
||||
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| {
|
||||
let upvar = upvars[var_id];
|
||||
let upvar_ln = self.add_live_node(UpvarNode(upvar.span));
|
||||
|
|
|
@ -358,9 +358,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||
const_stab_inherit = InheritConstStability::Yes;
|
||||
}
|
||||
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.tcx.hir().local_def_id(ctor_hir_id),
|
||||
ctor_def_id,
|
||||
i.span,
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
|
@ -435,7 +435,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||
|
||||
fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) {
|
||||
self.annotate(
|
||||
self.tcx.hir().local_def_id(var.id),
|
||||
var.def_id,
|
||||
var.span,
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
|
@ -443,9 +443,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||
InheritConstStability::No,
|
||||
InheritStability::Yes,
|
||||
|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.tcx.hir().local_def_id(ctor_hir_id),
|
||||
ctor_def_id,
|
||||
var.span,
|
||||
None,
|
||||
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>) {
|
||||
self.annotate(
|
||||
self.tcx.hir().local_def_id(s.hir_id),
|
||||
s.def_id,
|
||||
s.span,
|
||||
None,
|
||||
AnnotationKind::Required,
|
||||
|
@ -500,7 +500,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||
};
|
||||
|
||||
self.annotate(
|
||||
self.tcx.hir().local_def_id(p.hir_id),
|
||||
p.def_id,
|
||||
p.span,
|
||||
None,
|
||||
kind,
|
||||
|
@ -601,15 +601,15 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) {
|
||||
self.check_missing_stability(self.tcx.hir().local_def_id(var.id), var.span);
|
||||
if let Some(ctor_hir_id) = var.data.ctor_hir_id() {
|
||||
self.check_missing_stability(self.tcx.hir().local_def_id(ctor_hir_id), var.span);
|
||||
self.check_missing_stability(var.def_id, var.span);
|
||||
if let Some(ctor_def_id) = var.data.ctor_def_id() {
|
||||
self.check_missing_stability(ctor_def_id, var.span);
|
||||
}
|
||||
intravisit::walk_variant(self, var);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -75,9 +75,8 @@ impl<'tcx> Visitor<'tcx> for CaptureCollector<'_, 'tcx> {
|
|||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
|
||||
if let hir::ExprKind::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 hir::ExprKind::Closure(closure) = expr.kind {
|
||||
if let Some(upvars) = self.tcx.upvars_mentioned(closure.def_id) {
|
||||
// Every capture of a closure expression is a local in scope,
|
||||
// that is moved/copied/borrowed into the closure value, and
|
||||
// for this analysis they are like any other access to a local.
|
||||
|
|
|
@ -419,11 +419,6 @@ impl<'tcx> EmbargoVisitor<'tcx> {
|
|||
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.
|
||||
fn update(&mut self, def_id: LocalDefId, level: Option<Level>) -> Option<Level> {
|
||||
let old_level = self.get(def_id);
|
||||
|
@ -573,10 +568,9 @@ impl<'tcx> EmbargoVisitor<'tcx> {
|
|||
| hir::ItemKind::Union(ref struct_def, _) = item.kind
|
||||
{
|
||||
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(def_id);
|
||||
let field_vis = self.tcx.local_visibility(field.def_id);
|
||||
if field_vis.is_accessible_from(module, self.tcx) {
|
||||
self.reach(def_id, level).ty();
|
||||
self.reach(field.def_id, level).ty();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -641,12 +635,12 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
|||
match item.kind {
|
||||
hir::ItemKind::Enum(ref def, _) => {
|
||||
for variant in def.variants {
|
||||
let variant_level = self.update_with_hir_id(variant.id, item_level);
|
||||
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() {
|
||||
self.update_with_hir_id(ctor_hir_id, item_level);
|
||||
let variant_level = self.update(variant.def_id, item_level);
|
||||
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
|
||||
self.update(ctor_def_id, item_level);
|
||||
}
|
||||
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, _) => {
|
||||
if let Some(ctor_hir_id) = def.ctor_hir_id() {
|
||||
self.update_with_hir_id(ctor_hir_id, item_level);
|
||||
if let Some(ctor_def_id) = def.ctor_def_id() {
|
||||
self.update(ctor_def_id, item_level);
|
||||
}
|
||||
for field in def.fields() {
|
||||
let def_id = self.tcx.hir().local_def_id(field.hir_id);
|
||||
let vis = self.tcx.visibility(def_id);
|
||||
let vis = self.tcx.visibility(field.def_id);
|
||||
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();
|
||||
}
|
||||
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() {
|
||||
for field in variant.data.fields() {
|
||||
self.reach(self.tcx.hir().local_def_id(field.hir_id), variant_level)
|
||||
.ty();
|
||||
self.reach(field.def_id, variant_level).ty();
|
||||
}
|
||||
// Corner case: if the variant is reachable, but its
|
||||
// enum is not, make the enum reachable as well.
|
||||
self.reach(item.owner_id.def_id, variant_level).ty();
|
||||
}
|
||||
if let Some(hir_id) = variant.data.ctor_hir_id() {
|
||||
let ctor_def_id = self.tcx.hir().local_def_id(hir_id);
|
||||
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
|
||||
let ctor_level = self.get(ctor_def_id);
|
||||
if ctor_level.is_some() {
|
||||
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() {
|
||||
self.reach(item.owner_id.def_id, item_level).generics().predicates();
|
||||
for field in struct_def.fields() {
|
||||
let def_id = self.tcx.hir().local_def_id(field.hir_id);
|
||||
let field_level = self.get(def_id);
|
||||
let field_level = self.get(field.def_id);
|
||||
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() {
|
||||
let ctor_def_id = self.tcx.hir().local_def_id(hir_id);
|
||||
if let Some(ctor_def_id) = struct_def.ctor_def_id() {
|
||||
let ctor_level = self.get(ctor_def_id);
|
||||
if ctor_level.is_some() {
|
||||
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 {
|
||||
hir::ItemKind::Enum(ref def, _) => {
|
||||
for variant in def.variants.iter() {
|
||||
let variant_id = self.tcx.hir().local_def_id(variant.id);
|
||||
self.effective_visibility_diagnostic(variant_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(variant.def_id);
|
||||
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
|
||||
self.effective_visibility_diagnostic(ctor_def_id);
|
||||
}
|
||||
for field in variant.data.fields() {
|
||||
let def_id = self.tcx.hir().local_def_id(field.hir_id);
|
||||
self.effective_visibility_diagnostic(def_id);
|
||||
self.effective_visibility_diagnostic(field.def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => {
|
||||
if let Some(ctor_hir_id) = def.ctor_hir_id() {
|
||||
let ctor_def_id = self.tcx.hir().local_def_id(ctor_hir_id);
|
||||
if let Some(ctor_def_id) = def.ctor_def_id() {
|
||||
self.effective_visibility_diagnostic(ctor_def_id);
|
||||
}
|
||||
for field in def.fields() {
|
||||
let def_id = self.tcx.hir().local_def_id(field.hir_id);
|
||||
self.effective_visibility_diagnostic(def_id);
|
||||
self.effective_visibility_diagnostic(field.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>) {
|
||||
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;
|
||||
intravisit::walk_variant(self, v);
|
||||
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>) {
|
||||
let def_id = self.tcx.hir().local_def_id(s.hir_id);
|
||||
let vis = self.tcx.visibility(def_id);
|
||||
let vis = self.tcx.visibility(s.def_id);
|
||||
if vis.is_public() || self.in_variant {
|
||||
intravisit::walk_field_def(self, s);
|
||||
}
|
||||
|
@ -1982,8 +1965,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
|
|||
|
||||
for variant in def.variants {
|
||||
for field in variant.data.fields() {
|
||||
self.check(self.tcx.hir().local_def_id(field.hir_id), item_visibility)
|
||||
.ty();
|
||||
self.check(field.def_id, item_visibility).ty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2010,9 +1992,8 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
|
|||
self.check(item.owner_id.def_id, item_visibility).generics().predicates();
|
||||
|
||||
for field in struct_def.fields() {
|
||||
let def_id = tcx.hir().local_def_id(field.hir_id);
|
||||
let field_visibility = tcx.local_visibility(def_id);
|
||||
self.check(def_id, min(item_visibility, field_visibility, tcx)).ty();
|
||||
let field_visibility = tcx.local_visibility(field.def_id);
|
||||
self.check(field.def_id, min(item_visibility, field_visibility, tcx)).ty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -527,9 +527,9 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||
let value = format!("{}::{} {{ {} }}", enum_data.name, name, fields_str);
|
||||
if !self.span.filter_generated(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 attrs = self.tcx.hir().attrs(variant.id);
|
||||
let attrs = self.tcx.hir().attrs(variant.hir_id);
|
||||
|
||||
self.dumper.dump_def(
|
||||
&access,
|
||||
|
@ -552,7 +552,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||
}
|
||||
ref v => {
|
||||
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_str(
|
||||
&fields
|
||||
|
@ -565,9 +565,9 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||
}
|
||||
if !self.span.filter_generated(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 attrs = self.tcx.hir().attrs(variant.id);
|
||||
let attrs = self.tcx.hir().attrs(variant.hir_id);
|
||||
|
||||
self.dumper.dump_def(
|
||||
&access,
|
||||
|
@ -591,7 +591,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -319,7 +319,7 @@ impl<'tcx> SaveContext<'tcx> {
|
|||
qualname,
|
||||
value,
|
||||
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,
|
||||
docs: self.docs_for_attrs(attrs),
|
||||
sig: sig::item_signature(item, self),
|
||||
|
|
|
@ -693,7 +693,7 @@ impl<'hir> Sig for hir::Variant<'hir> {
|
|||
text.push('}');
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
hir::VariantData::Tuple(fields, id) => {
|
||||
hir::VariantData::Tuple(fields, id, _) => {
|
||||
let name_def = SigElement {
|
||||
id: id_from_hir_id(id, scx),
|
||||
start: offset,
|
||||
|
@ -712,7 +712,7 @@ impl<'hir> Sig for hir::Variant<'hir> {
|
|||
text.push(')');
|
||||
Ok(Signature { text, defs, refs })
|
||||
}
|
||||
hir::VariantData::Unit(id) => {
|
||||
hir::VariantData::Unit(id, _) => {
|
||||
let name_def = SigElement {
|
||||
id: id_from_hir_id(id, scx),
|
||||
start: offset,
|
||||
|
|
|
@ -2592,11 +2592,10 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
let Some(param) = generics.params.iter().find(|param| param.span == span) else {
|
||||
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
|
||||
// `Sized` bound is there intentionally and we don't need to suggest relaxing it.
|
||||
let explicitly_sized = generics
|
||||
.bounds_for_param(param_def_id)
|
||||
.bounds_for_param(param.def_id)
|
||||
.flat_map(|bp| bp.bounds)
|
||||
.any(|bound| bound.trait_ref().and_then(|tr| tr.trait_def_id()) == sized_trait);
|
||||
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`.
|
||||
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, " +")
|
||||
} else {
|
||||
|
|
|
@ -2125,7 +2125,7 @@ fn clean_maybe_renamed_item<'tcx>(
|
|||
|
||||
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));
|
||||
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>(
|
||||
|
|
|
@ -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<'_>) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -244,10 +244,10 @@ impl<'a, 'b> DocVisitor for CoverageCalculator<'a, 'b> {
|
|||
matches!(
|
||||
node,
|
||||
hir::Node::Variant(hir::Variant {
|
||||
data: hir::VariantData::Tuple(_, _),
|
||||
data: hir::VariantData::Tuple(_, _, _),
|
||||
..
|
||||
}) | hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Struct(hir::VariantData::Tuple(_, _), _),
|
||||
kind: hir::ItemKind::Struct(hir::VariantData::Tuple(_, _, _), _),
|
||||
..
|
||||
})
|
||||
)
|
||||
|
|
|
@ -22,8 +22,6 @@ trait MyIndex<'a, T> {}
|
|||
#[lang = "phantom_data"]
|
||||
//~^ ERROR `phantom_data` language item must be applied to a struct with 1 generic argument
|
||||
struct MyPhantomData<T, U>;
|
||||
//~^ ERROR parameter `T` is never used
|
||||
//~| ERROR parameter `U` is never used
|
||||
|
||||
#[lang = "owned_box"]
|
||||
//~^ ERROR `owned_box` language item must be applied to a struct with at least 1 generic argument
|
||||
|
|
|
@ -33,7 +33,7 @@ LL | struct MyPhantomData<T, U>;
|
|||
| ------ this struct has 2 generic arguments
|
||||
|
||||
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"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -42,7 +42,7 @@ LL | struct Foo;
|
|||
| - this struct has 0 generic arguments
|
||||
|
||||
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"]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
@ -50,25 +50,6 @@ LL |
|
|||
LL | fn start(_: *const u8, _: isize, _: *const *const u8) -> isize {
|
||||
| - this function has 0 generic arguments
|
||||
|
||||
error[E0392]: parameter `T` is never used
|
||||
--> $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: aborting due to 6 previous errors
|
||||
|
||||
error[E0392]: parameter `U` is never used
|
||||
--> $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`.
|
||||
For more information about this error, try `rustc --explain E0718`.
|
||||
|
|
|
@ -3,7 +3,11 @@ fn main() {
|
|||
.map(
|
||||
#[target_feature(enable = "")]
|
||||
//~^ ERROR: attribute should be applied to a function
|
||||
//~| ERROR: feature named `` is not valid
|
||||
//~| NOTE: `` is not valid for this target
|
||||
#[track_caller]
|
||||
//~^ ERROR: `#[track_caller]` on closures is currently unstable
|
||||
//~| NOTE: see issue #87417
|
||||
|_| (),
|
||||
//~^ NOTE: not a function
|
||||
)
|
||||
|
|
|
@ -7,5 +7,21 @@ LL | #[target_feature(enable = "")]
|
|||
LL | |_| (),
|
||||
| ------ 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`.
|
||||
|
|
|
@ -8,12 +8,6 @@ LL | fn panic(info: PanicInfo) -> ! {
|
|||
= note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
|
||||
= note: second definition in the local crate (`panic_handler_std`)
|
||||
|
||||
error: argument should be `&PanicInfo`
|
||||
--> $DIR/panic-handler-std.rs:8:16
|
||||
|
|
||||
LL | fn panic(info: PanicInfo) -> ! {
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0152`.
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// error-pattern: `#[panic_handler]` function required, but not found
|
||||
|
||||
// Regression test for #54505 - range borrowing suggestion had
|
||||
// incorrect syntax (missing parentheses).
|
||||
|
||||
|
@ -18,6 +16,10 @@ extern "C" fn eh_personality() {}
|
|||
#[lang = "eh_catch_typeinfo"]
|
||||
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
|
||||
fn take_range(_r: &impl RangeBounds<i8>) {}
|
||||
|
|
|
@ -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
|
||||
--> $DIR/issue-54505-no-std.rs:27:16
|
||||
--> $DIR/issue-54505-no-std.rs:29:16
|
||||
|
|
||||
LL | take_range(0..1);
|
||||
| ---------- ^^^^
|
||||
|
@ -13,13 +23,13 @@ LL | take_range(0..1);
|
|||
= note: expected reference `&_`
|
||||
found struct `Range<{integer}>`
|
||||
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>) {}
|
||||
| ^^^^^^^^^^ -------------------------
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-54505-no-std.rs:32:16
|
||||
--> $DIR/issue-54505-no-std.rs:34:16
|
||||
|
|
||||
LL | take_range(1..);
|
||||
| ---------- ^^^
|
||||
|
@ -31,13 +41,13 @@ LL | take_range(1..);
|
|||
= note: expected reference `&_`
|
||||
found struct `RangeFrom<{integer}>`
|
||||
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>) {}
|
||||
| ^^^^^^^^^^ -------------------------
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-54505-no-std.rs:37:16
|
||||
--> $DIR/issue-54505-no-std.rs:39:16
|
||||
|
|
||||
LL | take_range(..);
|
||||
| ---------- ^^
|
||||
|
@ -49,13 +59,13 @@ LL | take_range(..);
|
|||
= note: expected reference `&_`
|
||||
found struct `RangeFull`
|
||||
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>) {}
|
||||
| ^^^^^^^^^^ -------------------------
|
||||
|
||||
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);
|
||||
| ---------- ^^^^^
|
||||
|
@ -67,13 +77,13 @@ LL | take_range(0..=1);
|
|||
= note: expected reference `&_`
|
||||
found struct `RangeInclusive<{integer}>`
|
||||
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>) {}
|
||||
| ^^^^^^^^^^ -------------------------
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-54505-no-std.rs:47:16
|
||||
--> $DIR/issue-54505-no-std.rs:49:16
|
||||
|
|
||||
LL | take_range(..5);
|
||||
| ---------- ^^^
|
||||
|
@ -85,13 +95,13 @@ LL | take_range(..5);
|
|||
= note: expected reference `&_`
|
||||
found struct `RangeTo<{integer}>`
|
||||
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>) {}
|
||||
| ^^^^^^^^^^ -------------------------
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-54505-no-std.rs:52:16
|
||||
--> $DIR/issue-54505-no-std.rs:54:16
|
||||
|
|
||||
LL | take_range(..=42);
|
||||
| ---------- ^^^^^
|
||||
|
@ -103,11 +113,11 @@ LL | take_range(..=42);
|
|||
= note: expected reference `&_`
|
||||
found struct `RangeToInclusive<{integer}>`
|
||||
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>) {}
|
||||
| ^^^^^^^^^^ -------------------------
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
|
|
|
@ -119,40 +119,40 @@ hir-stats HIR STATS
|
|||
hir-stats Name Accumulated Size Count Item Size
|
||||
hir-stats ----------------------------------------------------------------
|
||||
hir-stats ForeignItemRef 24 ( 0.3%) 1 24
|
||||
hir-stats Lifetime 32 ( 0.4%) 1 32
|
||||
hir-stats Mod 32 ( 0.4%) 1 32
|
||||
hir-stats Lifetime 32 ( 0.3%) 1 32
|
||||
hir-stats Mod 32 ( 0.3%) 1 32
|
||||
hir-stats ExprField 40 ( 0.4%) 1 40
|
||||
hir-stats TraitItemRef 56 ( 0.6%) 2 28
|
||||
hir-stats Local 64 ( 0.7%) 1 64
|
||||
hir-stats Param 64 ( 0.7%) 2 32
|
||||
hir-stats InlineAsm 72 ( 0.8%) 1 72
|
||||
hir-stats ImplItemRef 72 ( 0.8%) 2 36
|
||||
hir-stats Body 96 ( 1.1%) 3 32
|
||||
hir-stats GenericArg 96 ( 1.1%) 4 24
|
||||
hir-stats - Type 24 ( 0.3%) 1
|
||||
hir-stats - Lifetime 72 ( 0.8%) 3
|
||||
hir-stats FieldDef 96 ( 1.1%) 2 48
|
||||
hir-stats Arm 96 ( 1.1%) 2 48
|
||||
hir-stats Stmt 96 ( 1.1%) 3 32
|
||||
hir-stats - Local 32 ( 0.4%) 1
|
||||
hir-stats - Semi 32 ( 0.4%) 1
|
||||
hir-stats - Expr 32 ( 0.4%) 1
|
||||
hir-stats Body 96 ( 1.0%) 3 32
|
||||
hir-stats FieldDef 96 ( 1.0%) 2 48
|
||||
hir-stats Arm 96 ( 1.0%) 2 48
|
||||
hir-stats Stmt 96 ( 1.0%) 3 32
|
||||
hir-stats - Local 32 ( 0.3%) 1
|
||||
hir-stats - Semi 32 ( 0.3%) 1
|
||||
hir-stats - Expr 32 ( 0.3%) 1
|
||||
hir-stats FnDecl 120 ( 1.3%) 3 40
|
||||
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 Variant 160 ( 1.8%) 2 80
|
||||
hir-stats Variant 176 ( 1.9%) 2 88
|
||||
hir-stats GenericBound 192 ( 2.1%) 4 48
|
||||
hir-stats - Trait 192 ( 2.1%) 4
|
||||
hir-stats WherePredicate 192 ( 2.1%) 3 64
|
||||
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 - Wild 72 ( 0.8%) 1
|
||||
hir-stats - Struct 72 ( 0.8%) 1
|
||||
hir-stats - Binding 216 ( 2.4%) 3
|
||||
hir-stats GenericParam 400 ( 4.4%) 5 80
|
||||
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 - Rptr 48 ( 0.5%) 1
|
||||
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 - ForeignMod 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 Path 1_280 (14.0%) 32 40
|
||||
hir-stats PathSegment 1_920 (21.0%) 40 48
|
||||
hir-stats Path 1_280 (13.9%) 32 40
|
||||
hir-stats PathSegment 1_920 (20.9%) 40 48
|
||||
hir-stats ----------------------------------------------------------------
|
||||
hir-stats Total 9_128
|
||||
hir-stats Total 9_176
|
||||
hir-stats
|
||||
|
|
|
@ -4,36 +4,6 @@ error: malformed `target_feature` attribute input
|
|||
LL | #[target_feature = "+sse2"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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
|
||||
--> $DIR/invalid-attribute.rs:34:1
|
||||
|
|
||||
|
@ -92,12 +62,6 @@ LL |
|
|||
LL | trait Baz {}
|
||||
| ------------ 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
|
||||
--> $DIR/invalid-attribute.rs:85:5
|
||||
|
|
||||
|
@ -119,6 +83,42 @@ LL |
|
|||
LL | || {};
|
||||
| ----- 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
|
||||
--> $DIR/invalid-attribute.rs:77:5
|
||||
|
|
||||
|
|
|
@ -7,10 +7,8 @@ trait Sized { } //~ ERROR found duplicate lang item `sized`
|
|||
fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
|
||||
//~^ ERROR `self` parameter is only allowed in associated functions
|
||||
//~| ERROR cannot find type `Struct` in this scope
|
||||
//~| ERROR mismatched types
|
||||
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() {}
|
||||
|
|
|
@ -13,7 +13,7 @@ LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
|
|||
| ^^^^^^ not found 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;
|
||||
| ^ 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: second definition in the local crate (`issue_102989`)
|
||||
|
||||
error[E0277]: the size for values of type `{integer}` cannot be known at compilation time
|
||||
--> $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: aborting due to 4 previous errors
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $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.
|
||||
Some errors have detailed explanations: E0152, E0412, E0425.
|
||||
For more information about an error, try `rustc --explain E0152`.
|
||||
|
|
|
@ -157,10 +157,10 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustiveEnum {
|
|||
&& def.variants.len() > 1
|
||||
{
|
||||
let mut iter = def.variants.iter().filter_map(|v| {
|
||||
let id = cx.tcx.hir().local_def_id(v.id);
|
||||
(matches!(v.data, hir::VariantData::Unit(_))
|
||||
let id = cx.tcx.hir().local_def_id(v.hir_id);
|
||||
(matches!(v.data, hir::VariantData::Unit(..))
|
||||
&& 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))
|
||||
});
|
||||
if let Some((id, span)) = iter.next()
|
||||
|
|
|
@ -199,7 +199,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
|
|||
}
|
||||
|
||||
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) {
|
||||
self.check_missing_docs_attrs(cx, attrs, v.span, "a", "variant");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue