Rollup merge of #122813 - nnethercote:nicer-quals, r=compiler-errors
Qualifier tweaking Adding and removing qualifiers in some cases that make things nicer. Details in individual commits. r? `@compiler-errors`
This commit is contained in:
commit
45940fe6d8
@ -14,6 +14,7 @@ use rustc_ast::*;
|
|||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
|
use rustc_hir::HirId;
|
||||||
use rustc_middle::span_bug;
|
use rustc_middle::span_bug;
|
||||||
use rustc_session::errors::report_lit_error;
|
use rustc_session::errors::report_lit_error;
|
||||||
use rustc_span::source_map::{respan, Spanned};
|
use rustc_span::source_map::{respan, Spanned};
|
||||||
@ -701,8 +702,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
pub(super) fn maybe_forward_track_caller(
|
pub(super) fn maybe_forward_track_caller(
|
||||||
&mut self,
|
&mut self,
|
||||||
span: Span,
|
span: Span,
|
||||||
outer_hir_id: hir::HirId,
|
outer_hir_id: HirId,
|
||||||
inner_hir_id: hir::HirId,
|
inner_hir_id: HirId,
|
||||||
) {
|
) {
|
||||||
if self.tcx.features().async_fn_track_caller
|
if self.tcx.features().async_fn_track_caller
|
||||||
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
|
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
|
||||||
@ -1048,7 +1049,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
binder: &ClosureBinder,
|
binder: &ClosureBinder,
|
||||||
capture_clause: CaptureBy,
|
capture_clause: CaptureBy,
|
||||||
closure_id: NodeId,
|
closure_id: NodeId,
|
||||||
closure_hir_id: hir::HirId,
|
closure_hir_id: HirId,
|
||||||
coroutine_kind: CoroutineKind,
|
coroutine_kind: CoroutineKind,
|
||||||
decl: &FnDecl,
|
decl: &FnDecl,
|
||||||
body: &Expr,
|
body: &Expr,
|
||||||
@ -2036,7 +2037,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
binding: hir::HirId,
|
binding: HirId,
|
||||||
) -> &'hir hir::Expr<'hir> {
|
) -> &'hir hir::Expr<'hir> {
|
||||||
self.arena.alloc(self.expr_ident_mut(sp, ident, binding))
|
self.arena.alloc(self.expr_ident_mut(sp, ident, binding))
|
||||||
}
|
}
|
||||||
@ -2045,7 +2046,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
span: Span,
|
span: Span,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
binding: hir::HirId,
|
binding: HirId,
|
||||||
) -> hir::Expr<'hir> {
|
) -> hir::Expr<'hir> {
|
||||||
let hir_id = self.next_id();
|
let hir_id = self.next_id();
|
||||||
let res = Res::Local(binding);
|
let res = Res::Local(binding);
|
||||||
|
@ -57,7 +57,7 @@ use rustc_hir as hir;
|
|||||||
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
|
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
|
||||||
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap, CRATE_DEF_ID, LOCAL_CRATE};
|
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap, CRATE_DEF_ID, LOCAL_CRATE};
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
ConstArg, GenericArg, ItemLocalMap, MissingLifetimeKind, ParamName, TraitCandidate,
|
ConstArg, GenericArg, HirId, ItemLocalMap, MissingLifetimeKind, ParamName, TraitCandidate,
|
||||||
};
|
};
|
||||||
use rustc_index::{Idx, IndexSlice, IndexVec};
|
use rustc_index::{Idx, IndexSlice, IndexVec};
|
||||||
use rustc_macros::extension;
|
use rustc_macros::extension;
|
||||||
@ -108,7 +108,7 @@ struct LoweringContext<'a, 'hir> {
|
|||||||
|
|
||||||
/// When inside an `async` context, this is the `HirId` of the
|
/// When inside an `async` context, this is the `HirId` of the
|
||||||
/// `task_context` local bound to the resume argument of the coroutine.
|
/// `task_context` local bound to the resume argument of the coroutine.
|
||||||
task_context: Option<hir::HirId>,
|
task_context: Option<HirId>,
|
||||||
|
|
||||||
/// Used to get the current `fn`'s def span to point to when using `await`
|
/// Used to get the current `fn`'s def span to point to when using `await`
|
||||||
/// outside of an `async fn`.
|
/// outside of an `async fn`.
|
||||||
@ -662,18 +662,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
/// `HirIdValidator` later on, which makes sure that all `NodeId`s got mapped
|
/// `HirIdValidator` later on, which makes sure that all `NodeId`s got mapped
|
||||||
/// properly. Calling the method twice with the same `NodeId` is fine though.
|
/// properly. Calling the method twice with the same `NodeId` is fine though.
|
||||||
#[instrument(level = "debug", skip(self), ret)]
|
#[instrument(level = "debug", skip(self), ret)]
|
||||||
fn lower_node_id(&mut self, ast_node_id: NodeId) -> hir::HirId {
|
fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId {
|
||||||
assert_ne!(ast_node_id, DUMMY_NODE_ID);
|
assert_ne!(ast_node_id, DUMMY_NODE_ID);
|
||||||
|
|
||||||
match self.node_id_to_local_id.entry(ast_node_id) {
|
match self.node_id_to_local_id.entry(ast_node_id) {
|
||||||
Entry::Occupied(o) => {
|
Entry::Occupied(o) => HirId { owner: self.current_hir_id_owner, local_id: *o.get() },
|
||||||
hir::HirId { owner: self.current_hir_id_owner, local_id: *o.get() }
|
|
||||||
}
|
|
||||||
Entry::Vacant(v) => {
|
Entry::Vacant(v) => {
|
||||||
// Generate a new `HirId`.
|
// Generate a new `HirId`.
|
||||||
let owner = self.current_hir_id_owner;
|
let owner = self.current_hir_id_owner;
|
||||||
let local_id = self.item_local_id_counter;
|
let local_id = self.item_local_id_counter;
|
||||||
let hir_id = hir::HirId { owner, local_id };
|
let hir_id = HirId { owner, local_id };
|
||||||
|
|
||||||
v.insert(local_id);
|
v.insert(local_id);
|
||||||
self.item_local_id_counter.increment_by(1);
|
self.item_local_id_counter.increment_by(1);
|
||||||
@ -694,12 +692,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
|
|
||||||
/// Generate a new `HirId` without a backing `NodeId`.
|
/// Generate a new `HirId` without a backing `NodeId`.
|
||||||
#[instrument(level = "debug", skip(self), ret)]
|
#[instrument(level = "debug", skip(self), ret)]
|
||||||
fn next_id(&mut self) -> hir::HirId {
|
fn next_id(&mut self) -> HirId {
|
||||||
let owner = self.current_hir_id_owner;
|
let owner = self.current_hir_id_owner;
|
||||||
let local_id = self.item_local_id_counter;
|
let local_id = self.item_local_id_counter;
|
||||||
assert_ne!(local_id, hir::ItemLocalId::ZERO);
|
assert_ne!(local_id, hir::ItemLocalId::ZERO);
|
||||||
self.item_local_id_counter.increment_by(1);
|
self.item_local_id_counter.increment_by(1);
|
||||||
hir::HirId { owner, local_id }
|
HirId { owner, local_id }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "trace", skip(self))]
|
#[instrument(level = "trace", skip(self))]
|
||||||
@ -707,7 +705,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
let res: Result<Res, ()> = res.apply_id(|id| {
|
let res: Result<Res, ()> = res.apply_id(|id| {
|
||||||
let owner = self.current_hir_id_owner;
|
let owner = self.current_hir_id_owner;
|
||||||
let local_id = self.node_id_to_local_id.get(&id).copied().ok_or(())?;
|
let local_id = self.node_id_to_local_id.get(&id).copied().ok_or(())?;
|
||||||
Ok(hir::HirId { owner, local_id })
|
Ok(HirId { owner, local_id })
|
||||||
});
|
});
|
||||||
trace!(?res);
|
trace!(?res);
|
||||||
|
|
||||||
@ -890,7 +888,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_attrs(&mut self, id: hir::HirId, attrs: &[Attribute]) -> Option<&'hir [Attribute]> {
|
fn lower_attrs(&mut self, id: HirId, attrs: &[Attribute]) -> Option<&'hir [Attribute]> {
|
||||||
if attrs.is_empty() {
|
if attrs.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -922,7 +920,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
Attribute { kind, id: attr.id, style: attr.style, span: self.lower_span(attr.span) }
|
Attribute { kind, id: attr.id, style: attr.style, span: self.lower_span(attr.span) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alias_attrs(&mut self, id: hir::HirId, target_id: hir::HirId) {
|
fn alias_attrs(&mut self, id: HirId, target_id: HirId) {
|
||||||
debug_assert_eq!(id.owner, self.current_hir_id_owner);
|
debug_assert_eq!(id.owner, self.current_hir_id_owner);
|
||||||
debug_assert_eq!(target_id.owner, self.current_hir_id_owner);
|
debug_assert_eq!(target_id.owner, self.current_hir_id_owner);
|
||||||
if let Some(&a) = self.attrs.get(&target_id.local_id) {
|
if let Some(&a) = self.attrs.get(&target_id.local_id) {
|
||||||
@ -2479,11 +2477,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
self.pat(span, hir::PatKind::Struct(qpath, fields, false))
|
self.pat(span, hir::PatKind::Struct(qpath, fields, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, hir::HirId) {
|
fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) {
|
||||||
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::NONE)
|
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::NONE)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, hir::HirId) {
|
fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) {
|
||||||
self.pat_ident_binding_mode_mut(span, ident, hir::BindingAnnotation::NONE)
|
self.pat_ident_binding_mode_mut(span, ident, hir::BindingAnnotation::NONE)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2492,7 +2490,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
span: Span,
|
span: Span,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
bm: hir::BindingAnnotation,
|
bm: hir::BindingAnnotation,
|
||||||
) -> (&'hir hir::Pat<'hir>, hir::HirId) {
|
) -> (&'hir hir::Pat<'hir>, HirId) {
|
||||||
let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
|
let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm);
|
||||||
(self.arena.alloc(pat), hir_id)
|
(self.arena.alloc(pat), hir_id)
|
||||||
}
|
}
|
||||||
@ -2502,7 +2500,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
span: Span,
|
span: Span,
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
bm: hir::BindingAnnotation,
|
bm: hir::BindingAnnotation,
|
||||||
) -> (hir::Pat<'hir>, hir::HirId) {
|
) -> (hir::Pat<'hir>, HirId) {
|
||||||
let hir_id = self.next_id();
|
let hir_id = self.next_id();
|
||||||
|
|
||||||
(
|
(
|
||||||
@ -2534,12 +2532,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ty_path(
|
fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
|
||||||
&mut self,
|
|
||||||
mut hir_id: hir::HirId,
|
|
||||||
span: Span,
|
|
||||||
qpath: hir::QPath<'hir>,
|
|
||||||
) -> hir::Ty<'hir> {
|
|
||||||
let kind = match qpath {
|
let kind = match qpath {
|
||||||
hir::QPath::Resolved(None, path) => {
|
hir::QPath::Resolved(None, path) => {
|
||||||
// Turn trait object paths into `TyKind::TraitObject` instead.
|
// Turn trait object paths into `TyKind::TraitObject` instead.
|
||||||
|
@ -3,6 +3,7 @@ use super::*;
|
|||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_span::create_default_session_globals_then;
|
use rustc_span::create_default_session_globals_then;
|
||||||
use rustc_span::symbol::Ident;
|
use rustc_span::symbol::Ident;
|
||||||
|
use rustc_span::DUMMY_SP;
|
||||||
use thin_vec::ThinVec;
|
use thin_vec::ThinVec;
|
||||||
|
|
||||||
fn fun_to_string(
|
fn fun_to_string(
|
||||||
@ -28,10 +29,7 @@ fn test_fun_to_string() {
|
|||||||
create_default_session_globals_then(|| {
|
create_default_session_globals_then(|| {
|
||||||
let abba_ident = Ident::from_str("abba");
|
let abba_ident = Ident::from_str("abba");
|
||||||
|
|
||||||
let decl = ast::FnDecl {
|
let decl = ast::FnDecl { inputs: ThinVec::new(), output: ast::FnRetTy::Default(DUMMY_SP) };
|
||||||
inputs: ThinVec::new(),
|
|
||||||
output: ast::FnRetTy::Default(rustc_span::DUMMY_SP),
|
|
||||||
};
|
|
||||||
let generics = ast::Generics::default();
|
let generics = ast::Generics::default();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
fun_to_string(&decl, ast::FnHeader::default(), abba_ident, &generics),
|
fun_to_string(&decl, ast::FnHeader::default(), abba_ident, &generics),
|
||||||
@ -48,7 +46,7 @@ fn test_variant_to_string() {
|
|||||||
let var = ast::Variant {
|
let var = ast::Variant {
|
||||||
ident,
|
ident,
|
||||||
vis: ast::Visibility {
|
vis: ast::Visibility {
|
||||||
span: rustc_span::DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
kind: ast::VisibilityKind::Inherited,
|
kind: ast::VisibilityKind::Inherited,
|
||||||
tokens: None,
|
tokens: None,
|
||||||
},
|
},
|
||||||
@ -56,7 +54,7 @@ fn test_variant_to_string() {
|
|||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
data: ast::VariantData::Unit(ast::DUMMY_NODE_ID),
|
data: ast::VariantData::Unit(ast::DUMMY_NODE_ID),
|
||||||
disr_expr: None,
|
disr_expr: None,
|
||||||
span: rustc_span::DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
is_placeholder: false,
|
is_placeholder: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,8 +8,7 @@ use rustc_ast::{self as ast, Expr, GenericArg, GenericParamKind, Generics, SelfK
|
|||||||
use rustc_expand::base::ExtCtxt;
|
use rustc_expand::base::ExtCtxt;
|
||||||
use rustc_span::source_map::respan;
|
use rustc_span::source_map::respan;
|
||||||
use rustc_span::symbol::{kw, Ident, Symbol};
|
use rustc_span::symbol::{kw, Ident, Symbol};
|
||||||
use rustc_span::Span;
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
use rustc_span::DUMMY_SP;
|
|
||||||
use thin_vec::ThinVec;
|
use thin_vec::ThinVec;
|
||||||
|
|
||||||
/// A path, e.g., `::std::option::Option::<i32>` (global). Has support
|
/// A path, e.g., `::std::option::Option::<i32>` (global). Has support
|
||||||
|
@ -168,7 +168,7 @@ impl<'ck, 'mir, 'tcx> TypeVisitor<TyCtxt<'tcx>> for LocalReturnTyVisitor<'ck, 'm
|
|||||||
match t.kind() {
|
match t.kind() {
|
||||||
ty::FnPtr(_) => {}
|
ty::FnPtr(_) => {}
|
||||||
ty::Ref(_, _, hir::Mutability::Mut) => {
|
ty::Ref(_, _, hir::Mutability::Mut) => {
|
||||||
self.checker.check_op(ops::ty::MutRef(self.kind));
|
self.checker.check_op(ops::mut_ref::MutRef(self.kind));
|
||||||
t.super_visit_with(self)
|
t.super_visit_with(self)
|
||||||
}
|
}
|
||||||
_ => t.super_visit_with(self),
|
_ => t.super_visit_with(self),
|
||||||
|
@ -9,9 +9,10 @@ use rustc_infer::infer::TyCtxtInferExt;
|
|||||||
use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
|
use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
|
||||||
use rustc_middle::mir::{self, CallSource};
|
use rustc_middle::mir::{self, CallSource};
|
||||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||||
use rustc_middle::ty::TraitRef;
|
use rustc_middle::ty::{
|
||||||
use rustc_middle::ty::{suggest_constraining_type_param, Adt, Closure, FnDef, FnPtr, Param, Ty};
|
self, suggest_constraining_type_param, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef,
|
||||||
use rustc_middle::ty::{GenericArgKind, GenericArgsRef};
|
Param, TraitRef, Ty,
|
||||||
|
};
|
||||||
use rustc_middle::util::{call_kind, CallDesugaringKind, CallKind};
|
use rustc_middle::util::{call_kind, CallDesugaringKind, CallKind};
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
@ -123,7 +124,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Adt(..) => {
|
ty::Adt(..) => {
|
||||||
let obligation =
|
let obligation =
|
||||||
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
|
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
|
||||||
|
|
||||||
@ -620,7 +621,7 @@ impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Types that cannot appear in the signature or locals of a `const fn`.
|
/// Types that cannot appear in the signature or locals of a `const fn`.
|
||||||
pub mod ty {
|
pub mod mut_ref {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -37,7 +37,7 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
|
|||||||
// from the trait itself that *shouldn't* be shown as the source of
|
// from the trait itself that *shouldn't* be shown as the source of
|
||||||
// an obligation and instead be skipped. Otherwise we'd use
|
// an obligation and instead be skipped. Otherwise we'd use
|
||||||
// `tcx.def_span(def_id);`
|
// `tcx.def_span(def_id);`
|
||||||
let span = rustc_span::DUMMY_SP;
|
let span = DUMMY_SP;
|
||||||
|
|
||||||
result.predicates =
|
result.predicates =
|
||||||
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once((
|
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once((
|
||||||
|
@ -13,7 +13,7 @@ use rustc_hir as hir;
|
|||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirIdMap, LifetimeName, Node};
|
use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirId, HirIdMap, LifetimeName, Node};
|
||||||
use rustc_macros::extension;
|
use rustc_macros::extension;
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
@ -107,7 +107,7 @@ enum Scope<'a> {
|
|||||||
/// queried later. However, if we enter an elision scope, we have to
|
/// queried later. However, if we enter an elision scope, we have to
|
||||||
/// later append the elided bound vars to the list and need to know what
|
/// later append the elided bound vars to the list and need to know what
|
||||||
/// to append to.
|
/// to append to.
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
|
|
||||||
s: ScopeRef<'a>,
|
s: ScopeRef<'a>,
|
||||||
|
|
||||||
@ -825,7 +825,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path(&mut self, path: &hir::Path<'tcx>, hir_id: hir::HirId) {
|
fn visit_path(&mut self, path: &hir::Path<'tcx>, hir_id: HirId) {
|
||||||
for (i, segment) in path.segments.iter().enumerate() {
|
for (i, segment) in path.segments.iter().enumerate() {
|
||||||
let depth = path.segments.len() - i - 1;
|
let depth = path.segments.len() - i - 1;
|
||||||
if let Some(args) = segment.args {
|
if let Some(args) = segment.args {
|
||||||
@ -1027,7 +1027,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn record_late_bound_vars(&mut self, hir_id: hir::HirId, binder: Vec<ty::BoundVariableKind>) {
|
fn record_late_bound_vars(&mut self, hir_id: HirId, binder: Vec<ty::BoundVariableKind>) {
|
||||||
if let Some(old) = self.map.late_bound_vars.insert(hir_id, binder) {
|
if let Some(old) = self.map.late_bound_vars.insert(hir_id, binder) {
|
||||||
bug!(
|
bug!(
|
||||||
"overwrote bound vars for {hir_id:?}:\nold={old:?}\nnew={:?}",
|
"overwrote bound vars for {hir_id:?}:\nold={old:?}\nnew={:?}",
|
||||||
@ -1054,12 +1054,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||||||
/// already in scope (for a fn item, that will be 0, but for a method it might not be). Late
|
/// already in scope (for a fn item, that will be 0, but for a method it might not be). Late
|
||||||
/// bound lifetimes are resolved by name and associated with a binder ID (`binder_id`), so the
|
/// bound lifetimes are resolved by name and associated with a binder ID (`binder_id`), so the
|
||||||
/// ordering is not important there.
|
/// ordering is not important there.
|
||||||
fn visit_early_late<F>(
|
fn visit_early_late<F>(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
|
||||||
&mut self,
|
where
|
||||||
hir_id: hir::HirId,
|
|
||||||
generics: &'tcx hir::Generics<'tcx>,
|
|
||||||
walk: F,
|
|
||||||
) where
|
|
||||||
F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
|
F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
|
||||||
{
|
{
|
||||||
let mut named_late_bound_vars = 0;
|
let mut named_late_bound_vars = 0;
|
||||||
@ -1106,7 +1102,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||||||
self.with(scope, walk);
|
self.with(scope, walk);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_early<F>(&mut self, hir_id: hir::HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
|
fn visit_early<F>(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F)
|
||||||
where
|
where
|
||||||
F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
|
F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>),
|
||||||
{
|
{
|
||||||
@ -1332,7 +1328,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_type_ref(&mut self, param_def_id: LocalDefId, hir_id: hir::HirId) {
|
fn resolve_type_ref(&mut self, param_def_id: LocalDefId, hir_id: HirId) {
|
||||||
// Walk up the scope chain, tracking the number of fn scopes
|
// Walk up the scope chain, tracking the number of fn scopes
|
||||||
// that we pass through, until we find a lifetime with the
|
// that we pass through, until we find a lifetime with the
|
||||||
// given name or we run out of scopes.
|
// given name or we run out of scopes.
|
||||||
|
@ -35,7 +35,7 @@ use rustc_hir as hir;
|
|||||||
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
|
use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir::intravisit::{walk_generics, Visitor as _};
|
use rustc_hir::intravisit::{walk_generics, Visitor as _};
|
||||||
use rustc_hir::{GenericArg, GenericArgs};
|
use rustc_hir::{GenericArg, GenericArgs, HirId};
|
||||||
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
||||||
use rustc_infer::traits::ObligationCause;
|
use rustc_infer::traits::ObligationCause;
|
||||||
use rustc_middle::middle::stability::AllowUnstable;
|
use rustc_middle::middle::stability::AllowUnstable;
|
||||||
@ -158,7 +158,7 @@ pub trait HirTyLowerer<'tcx> {
|
|||||||
fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>>;
|
fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>>;
|
||||||
|
|
||||||
/// Record the lowered type of a HIR node in this context.
|
/// Record the lowered type of a HIR node in this context.
|
||||||
fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span);
|
fn record_ty(&self, hir_id: HirId, ty: Ty<'tcx>, span: Span);
|
||||||
|
|
||||||
/// The inference context of the lowering context if applicable.
|
/// The inference context of the lowering context if applicable.
|
||||||
fn infcx(&self) -> Option<&InferCtxt<'tcx>>;
|
fn infcx(&self) -> Option<&InferCtxt<'tcx>>;
|
||||||
@ -999,7 +999,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
#[instrument(level = "debug", skip_all, ret)]
|
#[instrument(level = "debug", skip_all, ret)]
|
||||||
pub fn lower_assoc_path(
|
pub fn lower_assoc_path(
|
||||||
&self,
|
&self,
|
||||||
hir_ref_id: hir::HirId,
|
hir_ref_id: HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
qself_ty: Ty<'tcx>,
|
qself_ty: Ty<'tcx>,
|
||||||
qself: &'tcx hir::Ty<'tcx>,
|
qself: &'tcx hir::Ty<'tcx>,
|
||||||
@ -1200,7 +1200,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
segment: &hir::PathSegment<'tcx>,
|
segment: &hir::PathSegment<'tcx>,
|
||||||
adt_did: DefId,
|
adt_did: DefId,
|
||||||
self_ty: Ty<'tcx>,
|
self_ty: Ty<'tcx>,
|
||||||
block: hir::HirId,
|
block: HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Result<Option<(Ty<'tcx>, DefId)>, ErrorGuaranteed> {
|
) -> Result<Option<(Ty<'tcx>, DefId)>, ErrorGuaranteed> {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
@ -1349,13 +1349,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn probe_assoc_ty(
|
fn probe_assoc_ty(&self, name: Ident, block: HirId, span: Span, scope: DefId) -> Option<DefId> {
|
||||||
&self,
|
|
||||||
name: Ident,
|
|
||||||
block: hir::HirId,
|
|
||||||
span: Span,
|
|
||||||
scope: DefId,
|
|
||||||
) -> Option<DefId> {
|
|
||||||
let (item, def_scope) = self.probe_assoc_ty_unchecked(name, block, scope)?;
|
let (item, def_scope) = self.probe_assoc_ty_unchecked(name, block, scope)?;
|
||||||
self.check_assoc_ty(item, name, def_scope, block, span);
|
self.check_assoc_ty(item, name, def_scope, block, span);
|
||||||
Some(item)
|
Some(item)
|
||||||
@ -1364,7 +1358,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
fn probe_assoc_ty_unchecked(
|
fn probe_assoc_ty_unchecked(
|
||||||
&self,
|
&self,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
block: hir::HirId,
|
block: HirId,
|
||||||
scope: DefId,
|
scope: DefId,
|
||||||
) -> Option<(DefId, DefId)> {
|
) -> Option<(DefId, DefId)> {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
@ -1381,14 +1375,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
Some((item.def_id, def_scope))
|
Some((item.def_id, def_scope))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_assoc_ty(
|
fn check_assoc_ty(&self, item: DefId, name: Ident, def_scope: DefId, block: HirId, span: Span) {
|
||||||
&self,
|
|
||||||
item: DefId,
|
|
||||||
name: Ident,
|
|
||||||
def_scope: DefId,
|
|
||||||
block: hir::HirId,
|
|
||||||
span: Span,
|
|
||||||
) {
|
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
let kind = DefKind::AssocTy;
|
let kind = DefKind::AssocTy;
|
||||||
|
|
||||||
@ -1714,7 +1701,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
&self,
|
&self,
|
||||||
opt_self_ty: Option<Ty<'tcx>>,
|
opt_self_ty: Option<Ty<'tcx>>,
|
||||||
path: &hir::Path<'tcx>,
|
path: &hir::Path<'tcx>,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
permit_variants: bool,
|
permit_variants: bool,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
debug!(?path.res, ?opt_self_ty, ?path.segments);
|
debug!(?path.res, ?opt_self_ty, ?path.segments);
|
||||||
@ -1887,7 +1874,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
///
|
///
|
||||||
/// Early-bound type parameters get lowered to [`ty::Param`]
|
/// Early-bound type parameters get lowered to [`ty::Param`]
|
||||||
/// and late-bound ones to [`ty::Bound`].
|
/// and late-bound ones to [`ty::Bound`].
|
||||||
pub(crate) fn lower_ty_param(&self, hir_id: hir::HirId) -> Ty<'tcx> {
|
pub(crate) fn lower_ty_param(&self, hir_id: HirId) -> Ty<'tcx> {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
match tcx.named_bound_var(hir_id) {
|
match tcx.named_bound_var(hir_id) {
|
||||||
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
|
Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
|
||||||
@ -1914,7 +1901,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
///
|
///
|
||||||
/// Early-bound const parameters get lowered to [`ty::ConstKind::Param`]
|
/// Early-bound const parameters get lowered to [`ty::ConstKind::Param`]
|
||||||
/// and late-bound ones to [`ty::ConstKind::Bound`].
|
/// and late-bound ones to [`ty::ConstKind::Bound`].
|
||||||
pub(crate) fn lower_const_param(&self, hir_id: hir::HirId, param_ty: Ty<'tcx>) -> Const<'tcx> {
|
pub(crate) fn lower_const_param(&self, hir_id: HirId, param_ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
match tcx.named_bound_var(hir_id) {
|
match tcx.named_bound_var(hir_id) {
|
||||||
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
|
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
|
||||||
@ -2341,7 +2328,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
#[instrument(level = "debug", skip(self, hir_id, unsafety, abi, decl, generics, hir_ty), ret)]
|
#[instrument(level = "debug", skip(self, hir_id, unsafety, abi, decl, generics, hir_ty), ret)]
|
||||||
pub fn lower_fn_ty(
|
pub fn lower_fn_ty(
|
||||||
&self,
|
&self,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
unsafety: hir::Unsafety,
|
unsafety: hir::Unsafety,
|
||||||
abi: abi::Abi,
|
abi: abi::Abi,
|
||||||
decl: &hir::FnDecl<'tcx>,
|
decl: &hir::FnDecl<'tcx>,
|
||||||
@ -2469,7 +2456,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
/// corresponds to the return type.
|
/// corresponds to the return type.
|
||||||
fn suggest_trait_fn_ty_for_impl_fn_infer(
|
fn suggest_trait_fn_ty_for_impl_fn_infer(
|
||||||
&self,
|
&self,
|
||||||
fn_hir_id: hir::HirId,
|
fn_hir_id: HirId,
|
||||||
arg_idx: Option<usize>,
|
arg_idx: Option<usize>,
|
||||||
) -> Option<Ty<'tcx>> {
|
) -> Option<Ty<'tcx>> {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
|
@ -9,9 +9,10 @@ use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
|
|||||||
use rustc_ast_pretty::pp::{self, Breaks};
|
use rustc_ast_pretty::pp::{self, Breaks};
|
||||||
use rustc_ast_pretty::pprust::{Comments, PrintState};
|
use rustc_ast_pretty::pprust::{Comments, PrintState};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::LifetimeParamKind;
|
use rustc_hir::{
|
||||||
use rustc_hir::{BindingAnnotation, ByRef, GenericArg, GenericParam, GenericParamKind, Node, Term};
|
BindingAnnotation, ByRef, GenericArg, GenericBound, GenericParam, GenericParamKind, HirId,
|
||||||
use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier};
|
LifetimeParamKind, Node, PatKind, RangeEnd, Term, TraitBoundModifier,
|
||||||
|
};
|
||||||
use rustc_span::source_map::SourceMap;
|
use rustc_span::source_map::SourceMap;
|
||||||
use rustc_span::symbol::{kw, Ident, Symbol};
|
use rustc_span::symbol::{kw, Ident, Symbol};
|
||||||
use rustc_span::FileName;
|
use rustc_span::FileName;
|
||||||
@ -20,7 +21,7 @@ use rustc_target::spec::abi::Abi;
|
|||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
pub fn id_to_string(map: &dyn rustc_hir::intravisit::Map<'_>, hir_id: hir::HirId) -> String {
|
pub fn id_to_string(map: &dyn rustc_hir::intravisit::Map<'_>, hir_id: HirId) -> String {
|
||||||
to_string(&map, |s| s.print_node(map.hir_node(hir_id)))
|
to_string(&map, |s| s.print_node(map.hir_node(hir_id)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ pub enum AnnNode<'a> {
|
|||||||
Name(&'a Symbol),
|
Name(&'a Symbol),
|
||||||
Block(&'a hir::Block<'a>),
|
Block(&'a hir::Block<'a>),
|
||||||
Item(&'a hir::Item<'a>),
|
Item(&'a hir::Item<'a>),
|
||||||
SubItem(hir::HirId),
|
SubItem(HirId),
|
||||||
Expr(&'a hir::Expr<'a>),
|
Expr(&'a hir::Expr<'a>),
|
||||||
Pat(&'a hir::Pat<'a>),
|
Pat(&'a hir::Pat<'a>),
|
||||||
Arm(&'a hir::Arm<'a>),
|
Arm(&'a hir::Arm<'a>),
|
||||||
@ -65,12 +66,12 @@ impl PpAnn for &dyn rustc_hir::intravisit::Map<'_> {
|
|||||||
pub struct State<'a> {
|
pub struct State<'a> {
|
||||||
pub s: pp::Printer,
|
pub s: pp::Printer,
|
||||||
comments: Option<Comments<'a>>,
|
comments: Option<Comments<'a>>,
|
||||||
attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute],
|
attrs: &'a dyn Fn(HirId) -> &'a [ast::Attribute],
|
||||||
ann: &'a (dyn PpAnn + 'a),
|
ann: &'a (dyn PpAnn + 'a),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> State<'a> {
|
impl<'a> State<'a> {
|
||||||
fn attrs(&self, id: hir::HirId) -> &'a [ast::Attribute] {
|
fn attrs(&self, id: HirId) -> &'a [ast::Attribute] {
|
||||||
(self.attrs)(id)
|
(self.attrs)(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +161,7 @@ pub fn print_crate<'a>(
|
|||||||
krate: &hir::Mod<'_>,
|
krate: &hir::Mod<'_>,
|
||||||
filename: FileName,
|
filename: FileName,
|
||||||
input: String,
|
input: String,
|
||||||
attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute],
|
attrs: &'a dyn Fn(HirId) -> &'a [ast::Attribute],
|
||||||
ann: &'a dyn PpAnn,
|
ann: &'a dyn PpAnn,
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut s = State {
|
let mut s = State {
|
||||||
|
@ -59,8 +59,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
|
|||||||
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt};
|
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt};
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::DesugaringKind;
|
use rustc_span::{BytePos, DesugaringKind, Span, DUMMY_SP};
|
||||||
use rustc_span::{BytePos, Span};
|
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use rustc_trait_selection::infer::InferCtxtExt as _;
|
use rustc_trait_selection::infer::InferCtxtExt as _;
|
||||||
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
|
use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
|
||||||
@ -1045,7 +1044,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let source = self.resolve_vars_with_obligations(expr_ty);
|
let source = self.resolve_vars_with_obligations(expr_ty);
|
||||||
debug!("coercion::can_with_predicates({:?} -> {:?})", source, target);
|
debug!("coercion::can_with_predicates({:?} -> {:?})", source, target);
|
||||||
|
|
||||||
let cause = self.cause(rustc_span::DUMMY_SP, ObligationCauseCode::ExprAssignable);
|
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
|
||||||
// We don't ever need two-phase here since we throw out the result of the coercion
|
// We don't ever need two-phase here since we throw out the result of the coercion
|
||||||
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
|
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
|
||||||
self.probe(|_| {
|
self.probe(|_| {
|
||||||
@ -1062,11 +1061,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
/// how many dereference steps needed to achieve `expr_ty <: target`. If
|
/// how many dereference steps needed to achieve `expr_ty <: target`. If
|
||||||
/// it's not possible, return `None`.
|
/// it's not possible, return `None`.
|
||||||
pub fn deref_steps(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> Option<usize> {
|
pub fn deref_steps(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> Option<usize> {
|
||||||
let cause = self.cause(rustc_span::DUMMY_SP, ObligationCauseCode::ExprAssignable);
|
let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable);
|
||||||
// We don't ever need two-phase here since we throw out the result of the coercion
|
// We don't ever need two-phase here since we throw out the result of the coercion
|
||||||
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
|
let coerce = Coerce::new(self, cause, AllowTwoPhase::No);
|
||||||
coerce
|
coerce
|
||||||
.autoderef(rustc_span::DUMMY_SP, expr_ty)
|
.autoderef(DUMMY_SP, expr_ty)
|
||||||
.find_map(|(ty, steps)| self.probe(|_| coerce.unify(ty, target)).ok().map(|_| steps))
|
.find_map(|(ty, steps)| self.probe(|_| coerce.unify(ty, target)).ok().map(|_| steps))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1077,7 +1076,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
/// trait or region sub-obligations. (presumably we could, but it's not
|
/// trait or region sub-obligations. (presumably we could, but it's not
|
||||||
/// particularly important for diagnostics...)
|
/// particularly important for diagnostics...)
|
||||||
pub fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
pub fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||||
self.autoderef(rustc_span::DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
|
self.autoderef(DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
|
||||||
self.infcx
|
self.infcx
|
||||||
.type_implements_trait(
|
.type_implements_trait(
|
||||||
self.tcx.lang_items().deref_mut_trait()?,
|
self.tcx.lang_items().deref_mut_trait()?,
|
||||||
|
@ -2851,7 +2851,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
span: Span,
|
span: Span,
|
||||||
base_ty: Ty<'tcx>,
|
base_ty: Ty<'tcx>,
|
||||||
mod_id: DefId,
|
mod_id: DefId,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
) -> Vec<(Vec<&'tcx ty::FieldDef>, GenericArgsRef<'tcx>)> {
|
) -> Vec<(Vec<&'tcx ty::FieldDef>, GenericArgsRef<'tcx>)> {
|
||||||
debug!("get_field_candidates(span: {:?}, base_t: {:?}", span, base_ty);
|
debug!("get_field_candidates(span: {:?}, base_t: {:?}", span, base_ty);
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ use rustc_data_structures::fx::FxIndexMap;
|
|||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::Res;
|
use rustc_hir::def::Res;
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::PatKind;
|
use rustc_hir::{HirId, PatKind};
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_middle::hir::place::ProjectionKind;
|
use rustc_middle::hir::place::ProjectionKind;
|
||||||
use rustc_middle::mir::FakeReadCause;
|
use rustc_middle::mir::FakeReadCause;
|
||||||
@ -39,20 +39,20 @@ pub trait Delegate<'tcx> {
|
|||||||
/// diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic
|
/// diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic
|
||||||
/// id will be the id of the expression `expr` but the place itself will have
|
/// id will be the id of the expression `expr` but the place itself will have
|
||||||
/// the id of the binding in the pattern `pat`.
|
/// the id of the binding in the pattern `pat`.
|
||||||
fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId);
|
fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId);
|
||||||
|
|
||||||
/// The value found at `place` is being borrowed with kind `bk`.
|
/// The value found at `place` is being borrowed with kind `bk`.
|
||||||
/// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
|
/// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
|
||||||
fn borrow(
|
fn borrow(
|
||||||
&mut self,
|
&mut self,
|
||||||
place_with_id: &PlaceWithHirId<'tcx>,
|
place_with_id: &PlaceWithHirId<'tcx>,
|
||||||
diag_expr_id: hir::HirId,
|
diag_expr_id: HirId,
|
||||||
bk: ty::BorrowKind,
|
bk: ty::BorrowKind,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// The value found at `place` is being copied.
|
/// The value found at `place` is being copied.
|
||||||
/// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
|
/// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
|
||||||
fn copy(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
|
fn copy(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
|
||||||
// In most cases, copying data from `x` is equivalent to doing `*&x`, so by default
|
// In most cases, copying data from `x` is equivalent to doing `*&x`, so by default
|
||||||
// we treat a copy of `x` as a borrow of `x`.
|
// we treat a copy of `x` as a borrow of `x`.
|
||||||
self.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow)
|
self.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow)
|
||||||
@ -60,12 +60,12 @@ pub trait Delegate<'tcx> {
|
|||||||
|
|
||||||
/// The path at `assignee_place` is being assigned to.
|
/// The path at `assignee_place` is being assigned to.
|
||||||
/// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
|
/// `diag_expr_id` is the id used for diagnostics (see `consume` for more details).
|
||||||
fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId);
|
fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId);
|
||||||
|
|
||||||
/// The path at `binding_place` is a binding that is being initialized.
|
/// The path at `binding_place` is a binding that is being initialized.
|
||||||
///
|
///
|
||||||
/// This covers cases such as `let x = 42;`
|
/// This covers cases such as `let x = 42;`
|
||||||
fn bind(&mut self, binding_place: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
|
fn bind(&mut self, binding_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
|
||||||
// Bindings can normally be treated as a regular assignment, so by default we
|
// Bindings can normally be treated as a regular assignment, so by default we
|
||||||
// forward this to the mutate callback.
|
// forward this to the mutate callback.
|
||||||
self.mutate(binding_place, diag_expr_id)
|
self.mutate(binding_place, diag_expr_id)
|
||||||
@ -76,7 +76,7 @@ pub trait Delegate<'tcx> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
place_with_id: &PlaceWithHirId<'tcx>,
|
place_with_id: &PlaceWithHirId<'tcx>,
|
||||||
cause: FakeReadCause,
|
cause: FakeReadCause,
|
||||||
diag_expr_id: hir::HirId,
|
diag_expr_id: HirId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||||||
self.mc.tcx()
|
self.mc.tcx()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delegate_consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
|
fn delegate_consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
|
||||||
delegate_consume(&self.mc, self.delegate, place_with_id, diag_expr_id)
|
delegate_consume(&self.mc, self.delegate, place_with_id, diag_expr_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -775,8 +775,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||||||
/// closure as the DefId.
|
/// closure as the DefId.
|
||||||
fn walk_captures(&mut self, closure_expr: &hir::Closure<'_>) {
|
fn walk_captures(&mut self, closure_expr: &hir::Closure<'_>) {
|
||||||
fn upvar_is_local_variable(
|
fn upvar_is_local_variable(
|
||||||
upvars: Option<&FxIndexMap<hir::HirId, hir::Upvar>>,
|
upvars: Option<&FxIndexMap<HirId, hir::Upvar>>,
|
||||||
upvar_id: hir::HirId,
|
upvar_id: HirId,
|
||||||
body_owner_is_closure: bool,
|
body_owner_is_closure: bool,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
upvars.map(|upvars| !upvars.contains_key(&upvar_id)).unwrap_or(body_owner_is_closure)
|
upvars.map(|upvars| !upvars.contains_key(&upvar_id)).unwrap_or(body_owner_is_closure)
|
||||||
@ -902,7 +902,7 @@ fn delegate_consume<'a, 'tcx>(
|
|||||||
mc: &mc::MemCategorizationContext<'a, 'tcx>,
|
mc: &mc::MemCategorizationContext<'a, 'tcx>,
|
||||||
delegate: &mut (dyn Delegate<'tcx> + 'a),
|
delegate: &mut (dyn Delegate<'tcx> + 'a),
|
||||||
place_with_id: &PlaceWithHirId<'tcx>,
|
place_with_id: &PlaceWithHirId<'tcx>,
|
||||||
diag_expr_id: hir::HirId,
|
diag_expr_id: HirId,
|
||||||
) {
|
) {
|
||||||
debug!("delegate_consume(place_with_id={:?})", place_with_id);
|
debug!("delegate_consume(place_with_id={:?})", place_with_id);
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ use rustc_data_structures::{
|
|||||||
};
|
};
|
||||||
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
use rustc_infer::infer::{DefineOpaqueTypes, InferOk};
|
||||||
use rustc_middle::ty::{self, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
|
use rustc_span::DUMMY_SP;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum DivergingFallbackBehavior {
|
pub enum DivergingFallbackBehavior {
|
||||||
@ -102,7 +103,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
|
|||||||
// that field is only used for type fallback diagnostics.
|
// that field is only used for type fallback diagnostics.
|
||||||
for effect in unsolved_effects {
|
for effect in unsolved_effects {
|
||||||
let expected = self.tcx.consts.true_;
|
let expected = self.tcx.consts.true_;
|
||||||
let cause = self.misc(rustc_span::DUMMY_SP);
|
let cause = self.misc(DUMMY_SP);
|
||||||
match self.at(&cause, self.param_env).eq(DefineOpaqueTypes::Yes, expected, effect) {
|
match self.at(&cause, self.param_env).eq(DefineOpaqueTypes::Yes, expected, effect) {
|
||||||
Ok(InferOk { obligations, value: () }) => {
|
Ok(InferOk { obligations, value: () }) => {
|
||||||
self.register_predicates(obligations);
|
self.register_predicates(obligations);
|
||||||
@ -165,11 +166,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
|
|||||||
};
|
};
|
||||||
debug!("fallback_if_possible(ty={:?}): defaulting to `{:?}`", ty, fallback);
|
debug!("fallback_if_possible(ty={:?}): defaulting to `{:?}`", ty, fallback);
|
||||||
|
|
||||||
let span = self
|
let span = self.infcx.type_var_origin(ty).map(|origin| origin.span).unwrap_or(DUMMY_SP);
|
||||||
.infcx
|
|
||||||
.type_var_origin(ty)
|
|
||||||
.map(|origin| origin.span)
|
|
||||||
.unwrap_or(rustc_span::DUMMY_SP);
|
|
||||||
self.demand_eqtype(span, ty, fallback);
|
self.demand_eqtype(span, ty, fallback);
|
||||||
self.fallback_has_occurred.set(true);
|
self.fallback_has_occurred.set(true);
|
||||||
true
|
true
|
||||||
|
@ -10,7 +10,7 @@ use rustc_hir as hir;
|
|||||||
use rustc_hir::def::{CtorOf, DefKind, Res};
|
use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_hir::{ExprKind, GenericArg, Node, QPath};
|
use rustc_hir::{ExprKind, GenericArg, HirId, Node, QPath};
|
||||||
use rustc_hir_analysis::hir_ty_lowering::errors::GenericsArgsErrExtend;
|
use rustc_hir_analysis::hir_ty_lowering::errors::GenericsArgsErrExtend;
|
||||||
use rustc_hir_analysis::hir_ty_lowering::generics::{
|
use rustc_hir_analysis::hir_ty_lowering::generics::{
|
||||||
check_generic_arg_count_for_call, lower_generic_args,
|
check_generic_arg_count_for_call, lower_generic_args,
|
||||||
@ -47,7 +47,7 @@ use std::slice;
|
|||||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
/// Produces warning on the given node, if the current point in the
|
/// Produces warning on the given node, if the current point in the
|
||||||
/// function is unreachable, and there hasn't been another warning.
|
/// function is unreachable, and there hasn't been another warning.
|
||||||
pub(in super::super) fn warn_if_unreachable(&self, id: hir::HirId, span: Span, kind: &str) {
|
pub(in super::super) fn warn_if_unreachable(&self, id: HirId, span: Span, kind: &str) {
|
||||||
// FIXME: Combine these two 'if' expressions into one once
|
// FIXME: Combine these two 'if' expressions into one once
|
||||||
// let chains are implemented
|
// let chains are implemented
|
||||||
if let Diverges::Always { span: orig_span, custom_note } = self.diverges.get() {
|
if let Diverges::Always { span: orig_span, custom_note } = self.diverges.get() {
|
||||||
@ -130,14 +130,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
format!("{self:p}")
|
format!("{self:p}")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn local_ty(&self, span: Span, nid: hir::HirId) -> Ty<'tcx> {
|
pub fn local_ty(&self, span: Span, nid: HirId) -> Ty<'tcx> {
|
||||||
self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| {
|
self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| {
|
||||||
span_bug!(span, "no type for local variable {}", self.tcx.hir().node_to_string(nid))
|
span_bug!(span, "no type for local variable {}", self.tcx.hir().node_to_string(nid))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn write_ty(&self, id: hir::HirId, ty: Ty<'tcx>) {
|
pub fn write_ty(&self, id: HirId, ty: Ty<'tcx>) {
|
||||||
debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag());
|
debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag());
|
||||||
let mut typeck = self.typeck_results.borrow_mut();
|
let mut typeck = self.typeck_results.borrow_mut();
|
||||||
let mut node_ty = typeck.node_types_mut();
|
let mut node_ty = typeck.node_types_mut();
|
||||||
@ -161,7 +161,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
pub fn write_field_index(
|
pub fn write_field_index(
|
||||||
&self,
|
&self,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
index: FieldIdx,
|
index: FieldIdx,
|
||||||
nested_fields: Vec<(Ty<'tcx>, FieldIdx)>,
|
nested_fields: Vec<(Ty<'tcx>, FieldIdx)>,
|
||||||
) {
|
) {
|
||||||
@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
#[instrument(level = "debug", skip(self))]
|
#[instrument(level = "debug", skip(self))]
|
||||||
pub(in super::super) fn write_resolution(
|
pub(in super::super) fn write_resolution(
|
||||||
&self,
|
&self,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
r: Result<(DefKind, DefId), ErrorGuaranteed>,
|
r: Result<(DefKind, DefId), ErrorGuaranteed>,
|
||||||
) {
|
) {
|
||||||
self.typeck_results.borrow_mut().type_dependent_defs_mut().insert(hir_id, r);
|
self.typeck_results.borrow_mut().type_dependent_defs_mut().insert(hir_id, r);
|
||||||
@ -183,7 +183,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
#[instrument(level = "debug", skip(self))]
|
#[instrument(level = "debug", skip(self))]
|
||||||
pub fn write_method_call_and_enforce_effects(
|
pub fn write_method_call_and_enforce_effects(
|
||||||
&self,
|
&self,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
method: MethodCallee<'tcx>,
|
method: MethodCallee<'tcx>,
|
||||||
) {
|
) {
|
||||||
@ -192,7 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
self.write_args(hir_id, method.args);
|
self.write_args(hir_id, method.args);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_args(&self, node_id: hir::HirId, args: GenericArgsRef<'tcx>) {
|
pub fn write_args(&self, node_id: HirId, args: GenericArgsRef<'tcx>) {
|
||||||
if !args.is_empty() {
|
if !args.is_empty() {
|
||||||
debug!("write_args({:?}, {:?}) in fcx {}", node_id, args, self.tag());
|
debug!("write_args({:?}, {:?}) in fcx {}", node_id, args, self.tag());
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
pub fn write_user_type_annotation_from_args(
|
pub fn write_user_type_annotation_from_args(
|
||||||
&self,
|
&self,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
args: GenericArgsRef<'tcx>,
|
args: GenericArgsRef<'tcx>,
|
||||||
user_self_ty: Option<UserSelfTy<'tcx>>,
|
user_self_ty: Option<UserSelfTy<'tcx>>,
|
||||||
@ -230,7 +230,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
pub fn write_user_type_annotation(
|
pub fn write_user_type_annotation(
|
||||||
&self,
|
&self,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
canonical_user_type_annotation: CanonicalUserType<'tcx>,
|
canonical_user_type_annotation: CanonicalUserType<'tcx>,
|
||||||
) {
|
) {
|
||||||
debug!("fcx {}", self.tag());
|
debug!("fcx {}", self.tag());
|
||||||
@ -464,7 +464,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
t.has_free_regions() || t.has_aliases() || t.has_infer_types()
|
t.has_free_regions() || t.has_aliases() || t.has_infer_types()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> {
|
pub fn node_ty(&self, id: HirId) -> Ty<'tcx> {
|
||||||
match self.typeck_results.borrow().node_types().get(id) {
|
match self.typeck_results.borrow().node_types().get(id) {
|
||||||
Some(&t) => t,
|
Some(&t) => t,
|
||||||
None if let Some(e) = self.tainted_by_errors() => Ty::new_error(self.tcx, e),
|
None if let Some(e) = self.tainted_by_errors() => Ty::new_error(self.tcx, e),
|
||||||
@ -478,7 +478,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_ty_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {
|
pub fn node_ty_opt(&self, id: HirId) -> Option<Ty<'tcx>> {
|
||||||
match self.typeck_results.borrow().node_types().get(id) {
|
match self.typeck_results.borrow().node_types().get(id) {
|
||||||
Some(&t) => Some(t),
|
Some(&t) => Some(t),
|
||||||
None if let Some(e) = self.tainted_by_errors() => Some(Ty::new_error(self.tcx, e)),
|
None if let Some(e) = self.tainted_by_errors() => Some(Ty::new_error(self.tcx, e)),
|
||||||
@ -742,7 +742,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
lang_item: hir::LangItem,
|
lang_item: hir::LangItem,
|
||||||
span: Span,
|
span: Span,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
) -> (Res, Ty<'tcx>) {
|
) -> (Res, Ty<'tcx>) {
|
||||||
let def_id = self.tcx.require_lang_item(lang_item, Some(span));
|
let def_id = self.tcx.require_lang_item(lang_item, Some(span));
|
||||||
let def_kind = self.tcx.def_kind(def_id);
|
let def_kind = self.tcx.def_kind(def_id);
|
||||||
@ -790,7 +790,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
pub fn resolve_ty_and_res_fully_qualified_call(
|
pub fn resolve_ty_and_res_fully_qualified_call(
|
||||||
&self,
|
&self,
|
||||||
qpath: &'tcx QPath<'tcx>,
|
qpath: &'tcx QPath<'tcx>,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
args: Option<&'tcx [hir::Expr<'tcx>]>,
|
args: Option<&'tcx [hir::Expr<'tcx>]>,
|
||||||
) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
|
) -> (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]) {
|
||||||
@ -984,7 +984,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
/// suggestion can be made, `None` otherwise.
|
/// suggestion can be made, `None` otherwise.
|
||||||
pub fn get_fn_decl(
|
pub fn get_fn_decl(
|
||||||
&self,
|
&self,
|
||||||
blk_id: hir::HirId,
|
blk_id: HirId,
|
||||||
) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>, bool)> {
|
) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>, bool)> {
|
||||||
// Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or
|
// Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or
|
||||||
// `while` before reaching it, as block tail returns are not available in them.
|
// `while` before reaching it, as block tail returns are not available in them.
|
||||||
@ -1080,7 +1080,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
res: Res,
|
res: Res,
|
||||||
span: Span,
|
span: Span,
|
||||||
path_span: Span,
|
path_span: Span,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
) -> (Ty<'tcx>, Res) {
|
) -> (Ty<'tcx>, Res) {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
|
||||||
@ -1450,7 +1450,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
span: Span,
|
span: Span,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
args: GenericArgsRef<'tcx>,
|
args: GenericArgsRef<'tcx>,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
) {
|
) {
|
||||||
self.add_required_obligations_with_code(span, def_id, args, |idx, span| {
|
self.add_required_obligations_with_code(span, def_id, args, |idx, span| {
|
||||||
if span.is_dummy() {
|
if span.is_dummy() {
|
||||||
@ -1541,7 +1541,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
pub(in super::super) fn with_breakable_ctxt<F: FnOnce() -> R, R>(
|
pub(in super::super) fn with_breakable_ctxt<F: FnOnce() -> R, R>(
|
||||||
&self,
|
&self,
|
||||||
id: hir::HirId,
|
id: HirId,
|
||||||
ctxt: BreakableCtxt<'tcx>,
|
ctxt: BreakableCtxt<'tcx>,
|
||||||
f: F,
|
f: F,
|
||||||
) -> (BreakableCtxt<'tcx>, R) {
|
) -> (BreakableCtxt<'tcx>, R) {
|
||||||
@ -1580,7 +1580,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if an expression is contained inside the LHS of an assignment expression.
|
/// Returns `true` if an expression is contained inside the LHS of an assignment expression.
|
||||||
pub(in super::super) fn expr_in_place(&self, mut expr_id: hir::HirId) -> bool {
|
pub(in super::super) fn expr_in_place(&self, mut expr_id: HirId) -> bool {
|
||||||
let mut contained_in_place = false;
|
let mut contained_in_place = false;
|
||||||
|
|
||||||
while let hir::Node::Expr(parent_expr) = self.tcx.parent_hir_node(expr_id) {
|
while let hir::Node::Expr(parent_expr) = self.tcx.parent_hir_node(expr_id) {
|
||||||
|
@ -24,7 +24,7 @@ use rustc_hir as hir;
|
|||||||
use rustc_hir::def::{CtorOf, DefKind, Res};
|
use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_hir::{ExprKind, Node, QPath};
|
use rustc_hir::{ExprKind, HirId, Node, QPath};
|
||||||
use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
|
use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
|
||||||
use rustc_hir_analysis::check::potentially_plural_count;
|
use rustc_hir_analysis::check::potentially_plural_count;
|
||||||
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
||||||
@ -1489,7 +1489,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
pub fn check_struct_path(
|
pub fn check_struct_path(
|
||||||
&self,
|
&self,
|
||||||
qpath: &QPath<'tcx>,
|
qpath: &QPath<'tcx>,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
) -> Result<(&'tcx ty::VariantDef, Ty<'tcx>), ErrorGuaranteed> {
|
) -> Result<(&'tcx ty::VariantDef, Ty<'tcx>), ErrorGuaranteed> {
|
||||||
let path_span = qpath.span();
|
let path_span = qpath.span();
|
||||||
let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, hir_id);
|
let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, hir_id);
|
||||||
@ -1554,7 +1554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
pub fn check_decl_initializer(
|
pub fn check_decl_initializer(
|
||||||
&self,
|
&self,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
pat: &'tcx hir::Pat<'tcx>,
|
pat: &'tcx hir::Pat<'tcx>,
|
||||||
init: &'tcx hir::Expr<'tcx>,
|
init: &'tcx hir::Expr<'tcx>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
@ -1879,7 +1879,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
ty
|
ty
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parent_item_span(&self, id: hir::HirId) -> Option<Span> {
|
fn parent_item_span(&self, id: HirId) -> Option<Span> {
|
||||||
let node = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(id).def_id);
|
let node = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(id).def_id);
|
||||||
match node {
|
match node {
|
||||||
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. })
|
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. })
|
||||||
@ -1897,7 +1897,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
/// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise.
|
/// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise.
|
||||||
pub(crate) fn get_parent_fn_decl(
|
pub(crate) fn get_parent_fn_decl(
|
||||||
&self,
|
&self,
|
||||||
blk_id: hir::HirId,
|
blk_id: HirId,
|
||||||
) -> Option<(&'tcx hir::FnDecl<'tcx>, Ident)> {
|
) -> Option<(&'tcx hir::FnDecl<'tcx>, Ident)> {
|
||||||
let parent = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(blk_id).def_id);
|
let parent = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(blk_id).def_id);
|
||||||
self.get_node_fn_decl(parent).map(|(_, fn_decl, ident, _)| (fn_decl, ident))
|
self.get_node_fn_decl(parent).map(|(_, fn_decl, ident, _)| (fn_decl, ident))
|
||||||
@ -1939,12 +1939,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
expr.span
|
expr.span
|
||||||
}
|
}
|
||||||
|
|
||||||
fn overwrite_local_ty_if_err(
|
fn overwrite_local_ty_if_err(&self, hir_id: HirId, pat: &'tcx hir::Pat<'tcx>, ty: Ty<'tcx>) {
|
||||||
&self,
|
|
||||||
hir_id: hir::HirId,
|
|
||||||
pat: &'tcx hir::Pat<'tcx>,
|
|
||||||
ty: Ty<'tcx>,
|
|
||||||
) {
|
|
||||||
if let Err(guar) = ty.error_reported() {
|
if let Err(guar) = ty.error_reported() {
|
||||||
struct OverwritePatternsWithError {
|
struct OverwritePatternsWithError {
|
||||||
pat_hir_ids: Vec<hir::HirId>,
|
pat_hir_ids: Vec<hir::HirId>,
|
||||||
@ -1977,7 +1972,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
qpath: &QPath<'tcx>,
|
qpath: &QPath<'tcx>,
|
||||||
path_span: Span,
|
path_span: Span,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
) -> (Res, LoweredTy<'tcx>) {
|
) -> (Res, LoweredTy<'tcx>) {
|
||||||
match *qpath {
|
match *qpath {
|
||||||
QPath::Resolved(ref maybe_qself, path) => {
|
QPath::Resolved(ref maybe_qself, path) => {
|
||||||
|
@ -71,7 +71,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
blk_id: hir::HirId,
|
blk_id: HirId,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let expr = expr.peel_drop_temps();
|
let expr = expr.peel_drop_temps();
|
||||||
let mut pointing_at_return_type = false;
|
let mut pointing_at_return_type = false;
|
||||||
@ -1031,7 +1031,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
fn_decl: &hir::FnDecl<'tcx>,
|
fn_decl: &hir::FnDecl<'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
id: hir::HirId,
|
id: HirId,
|
||||||
fn_id: LocalDefId,
|
fn_id: LocalDefId,
|
||||||
) {
|
) {
|
||||||
if !expected.is_unit() {
|
if !expected.is_unit() {
|
||||||
@ -1600,12 +1600,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_loop(&self, id: hir::HirId) -> bool {
|
fn is_loop(&self, id: HirId) -> bool {
|
||||||
let node = self.tcx.hir_node(id);
|
let node = self.tcx.hir_node(id);
|
||||||
matches!(node, Node::Expr(Expr { kind: ExprKind::Loop(..), .. }))
|
matches!(node, Node::Expr(Expr { kind: ExprKind::Loop(..), .. }))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_local_statement(&self, id: hir::HirId) -> bool {
|
fn is_local_statement(&self, id: HirId) -> bool {
|
||||||
let node = self.tcx.hir_node(id);
|
let node = self.tcx.hir_node(id);
|
||||||
matches!(node, Node::Stmt(Stmt { kind: StmtKind::Let(..), .. }))
|
matches!(node, Node::Stmt(Stmt { kind: StmtKind::Let(..), .. }))
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::FnCtxt;
|
use crate::FnCtxt;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_hir::PatKind;
|
use rustc_hir::{HirId, PatKind};
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
||||||
use rustc_middle::ty::Ty;
|
use rustc_middle::ty::Ty;
|
||||||
use rustc_middle::ty::UserType;
|
use rustc_middle::ty::UserType;
|
||||||
@ -33,7 +33,7 @@ impl<'a> DeclOrigin<'a> {
|
|||||||
///
|
///
|
||||||
/// It must have a hir_id, as this is how we connect gather_locals to the check functions.
|
/// It must have a hir_id, as this is how we connect gather_locals to the check functions.
|
||||||
pub(super) struct Declaration<'a> {
|
pub(super) struct Declaration<'a> {
|
||||||
pub hir_id: hir::HirId,
|
pub hir_id: HirId,
|
||||||
pub pat: &'a hir::Pat<'a>,
|
pub pat: &'a hir::Pat<'a>,
|
||||||
pub ty: Option<&'a hir::Ty<'a>>,
|
pub ty: Option<&'a hir::Ty<'a>>,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
@ -48,8 +48,8 @@ impl<'a> From<&'a hir::LetStmt<'a>> for Declaration<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<(&'a hir::LetExpr<'a>, hir::HirId)> for Declaration<'a> {
|
impl<'a> From<(&'a hir::LetExpr<'a>, HirId)> for Declaration<'a> {
|
||||||
fn from((let_expr, hir_id): (&'a hir::LetExpr<'a>, hir::HirId)) -> Self {
|
fn from((let_expr, hir_id): (&'a hir::LetExpr<'a>, HirId)) -> Self {
|
||||||
let hir::LetExpr { pat, ty, span, init, is_recovered: _ } = *let_expr;
|
let hir::LetExpr { pat, ty, span, init, is_recovered: _ } = *let_expr;
|
||||||
Declaration { hir_id, pat, ty, span, init: Some(init), origin: DeclOrigin::LetExpr }
|
Declaration { hir_id, pat, ty, span, init: Some(init), origin: DeclOrigin::LetExpr }
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ pub(super) struct GatherLocalsVisitor<'a, 'tcx> {
|
|||||||
// parameters are special cases of patterns, but we want to handle them as
|
// parameters are special cases of patterns, but we want to handle them as
|
||||||
// *distinct* cases. so track when we are hitting a pattern *within* an fn
|
// *distinct* cases. so track when we are hitting a pattern *within* an fn
|
||||||
// parameter.
|
// parameter.
|
||||||
outermost_fn_param_pat: Option<(Span, hir::HirId)>,
|
outermost_fn_param_pat: Option<(Span, HirId)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
|
impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
|
||||||
@ -68,7 +68,7 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
|
|||||||
Self { fcx, outermost_fn_param_pat: None }
|
Self { fcx, outermost_fn_param_pat: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assign(&mut self, span: Span, nid: hir::HirId, ty_opt: Option<Ty<'tcx>>) -> Ty<'tcx> {
|
fn assign(&mut self, span: Span, nid: HirId, ty_opt: Option<Ty<'tcx>>) -> Ty<'tcx> {
|
||||||
match ty_opt {
|
match ty_opt {
|
||||||
None => {
|
None => {
|
||||||
// Infer the variable's type.
|
// Infer the variable's type.
|
||||||
|
@ -57,7 +57,7 @@ use rustc_errors::{codes::*, struct_span_code_err, ErrorGuaranteed};
|
|||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_hir::{HirIdMap, Node};
|
use rustc_hir::{HirId, HirIdMap, Node};
|
||||||
use rustc_hir_analysis::check::check_abi;
|
use rustc_hir_analysis::check::check_abi;
|
||||||
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
||||||
@ -339,13 +339,13 @@ pub struct EnclosingBreakables<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> EnclosingBreakables<'tcx> {
|
impl<'tcx> EnclosingBreakables<'tcx> {
|
||||||
fn find_breakable(&mut self, target_id: hir::HirId) -> &mut BreakableCtxt<'tcx> {
|
fn find_breakable(&mut self, target_id: HirId) -> &mut BreakableCtxt<'tcx> {
|
||||||
self.opt_find_breakable(target_id).unwrap_or_else(|| {
|
self.opt_find_breakable(target_id).unwrap_or_else(|| {
|
||||||
bug!("could not find enclosing breakable with id {}", target_id);
|
bug!("could not find enclosing breakable with id {}", target_id);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn opt_find_breakable(&mut self, target_id: hir::HirId) -> Option<&mut BreakableCtxt<'tcx>> {
|
fn opt_find_breakable(&mut self, target_id: HirId) -> Option<&mut BreakableCtxt<'tcx>> {
|
||||||
match self.by_id.get(&target_id) {
|
match self.by_id.get(&target_id) {
|
||||||
Some(ix) => Some(&mut self.stack[*ix]),
|
Some(ix) => Some(&mut self.stack[*ix]),
|
||||||
None => None,
|
None => None,
|
||||||
|
@ -58,24 +58,24 @@ use rustc_hir as hir;
|
|||||||
use rustc_hir::def::{CtorOf, DefKind, Res};
|
use rustc_hir::def::{CtorOf, DefKind, Res};
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::pat_util::EnumerateAndAdjustIterator;
|
use rustc_hir::pat_util::EnumerateAndAdjustIterator;
|
||||||
use rustc_hir::PatKind;
|
use rustc_hir::{HirId, PatKind};
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
|
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
|
||||||
use rustc_trait_selection::infer::InferCtxtExt;
|
use rustc_trait_selection::infer::InferCtxtExt;
|
||||||
|
|
||||||
pub(crate) trait HirNode {
|
pub(crate) trait HirNode {
|
||||||
fn hir_id(&self) -> hir::HirId;
|
fn hir_id(&self) -> HirId;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HirNode for hir::Expr<'_> {
|
impl HirNode for hir::Expr<'_> {
|
||||||
fn hir_id(&self) -> hir::HirId {
|
fn hir_id(&self) -> HirId {
|
||||||
self.hir_id
|
self.hir_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HirNode for hir::Pat<'_> {
|
impl HirNode for hir::Pat<'_> {
|
||||||
fn hir_id(&self) -> hir::HirId {
|
fn hir_id(&self) -> HirId {
|
||||||
self.hir_id
|
self.hir_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ pub(crate) struct MemCategorizationContext<'a, 'tcx> {
|
|||||||
infcx: &'a InferCtxt<'tcx>,
|
infcx: &'a InferCtxt<'tcx>,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
body_owner: LocalDefId,
|
body_owner: LocalDefId,
|
||||||
upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
|
upvars: Option<&'tcx FxIndexMap<HirId, hir::Upvar>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) type McResult<T> = Result<T, ()>;
|
pub(crate) type McResult<T> = Result<T, ()>;
|
||||||
@ -127,11 +127,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||||||
self.infcx.tainted_by_errors().is_some()
|
self.infcx.tainted_by_errors().is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_type_vars_or_error(
|
fn resolve_type_vars_or_error(&self, id: HirId, ty: Option<Ty<'tcx>>) -> McResult<Ty<'tcx>> {
|
||||||
&self,
|
|
||||||
id: hir::HirId,
|
|
||||||
ty: Option<Ty<'tcx>>,
|
|
||||||
) -> McResult<Ty<'tcx>> {
|
|
||||||
match ty {
|
match ty {
|
||||||
Some(ty) => {
|
Some(ty) => {
|
||||||
let ty = self.resolve_vars_if_possible(ty);
|
let ty = self.resolve_vars_if_possible(ty);
|
||||||
@ -153,7 +149,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn node_ty(&self, hir_id: hir::HirId) -> McResult<Ty<'tcx>> {
|
pub(crate) fn node_ty(&self, hir_id: HirId) -> McResult<Ty<'tcx>> {
|
||||||
self.resolve_type_vars_or_error(hir_id, self.typeck_results.node_type_opt(hir_id))
|
self.resolve_type_vars_or_error(hir_id, self.typeck_results.node_type_opt(hir_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,7 +373,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||||||
#[instrument(level = "debug", skip(self, span), ret)]
|
#[instrument(level = "debug", skip(self, span), ret)]
|
||||||
pub(crate) fn cat_res(
|
pub(crate) fn cat_res(
|
||||||
&self,
|
&self,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
expr_ty: Ty<'tcx>,
|
expr_ty: Ty<'tcx>,
|
||||||
res: Res,
|
res: Res,
|
||||||
@ -416,7 +412,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||||||
/// environment and upvar reference as appropriate. Only regionck cares
|
/// environment and upvar reference as appropriate. Only regionck cares
|
||||||
/// about these dereferences, so we let it compute them as needed.
|
/// about these dereferences, so we let it compute them as needed.
|
||||||
#[instrument(level = "debug", skip(self), ret)]
|
#[instrument(level = "debug", skip(self), ret)]
|
||||||
fn cat_upvar(&self, hir_id: hir::HirId, var_id: hir::HirId) -> McResult<PlaceWithHirId<'tcx>> {
|
fn cat_upvar(&self, hir_id: HirId, var_id: HirId) -> McResult<PlaceWithHirId<'tcx>> {
|
||||||
let closure_expr_def_id = self.body_owner;
|
let closure_expr_def_id = self.body_owner;
|
||||||
|
|
||||||
let upvar_id = ty::UpvarId {
|
let upvar_id = ty::UpvarId {
|
||||||
@ -429,7 +425,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(self), ret)]
|
#[instrument(level = "debug", skip(self), ret)]
|
||||||
pub(crate) fn cat_rvalue(&self, hir_id: hir::HirId, expr_ty: Ty<'tcx>) -> PlaceWithHirId<'tcx> {
|
pub(crate) fn cat_rvalue(&self, hir_id: HirId, expr_ty: Ty<'tcx>) -> PlaceWithHirId<'tcx> {
|
||||||
PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Rvalue, Vec::new())
|
PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Rvalue, Vec::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,7 +519,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||||||
fn variant_index_for_adt(
|
fn variant_index_for_adt(
|
||||||
&self,
|
&self,
|
||||||
qpath: &hir::QPath<'_>,
|
qpath: &hir::QPath<'_>,
|
||||||
pat_hir_id: hir::HirId,
|
pat_hir_id: HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> McResult<VariantIdx> {
|
) -> McResult<VariantIdx> {
|
||||||
let res = self.typeck_results.qpath_res(qpath, pat_hir_id);
|
let res = self.typeck_results.qpath_res(qpath, pat_hir_id);
|
||||||
@ -556,7 +552,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||||||
/// Here `pat_hir_id` is the HirId of the pattern itself.
|
/// Here `pat_hir_id` is the HirId of the pattern itself.
|
||||||
fn total_fields_in_adt_variant(
|
fn total_fields_in_adt_variant(
|
||||||
&self,
|
&self,
|
||||||
pat_hir_id: hir::HirId,
|
pat_hir_id: HirId,
|
||||||
variant_index: VariantIdx,
|
variant_index: VariantIdx,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> McResult<usize> {
|
) -> McResult<usize> {
|
||||||
@ -573,7 +569,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||||||
|
|
||||||
/// Returns the total number of fields in a tuple used within a Tuple pattern.
|
/// Returns the total number of fields in a tuple used within a Tuple pattern.
|
||||||
/// Here `pat_hir_id` is the HirId of the pattern itself.
|
/// Here `pat_hir_id` is the HirId of the pattern itself.
|
||||||
fn total_fields_in_tuple(&self, pat_hir_id: hir::HirId, span: Span) -> McResult<usize> {
|
fn total_fields_in_tuple(&self, pat_hir_id: HirId, span: Span) -> McResult<usize> {
|
||||||
let ty = self.typeck_results.node_type(pat_hir_id);
|
let ty = self.typeck_results.node_type(pat_hir_id);
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Tuple(args) => Ok(args.len()),
|
ty::Tuple(args) => Ok(args.len()),
|
||||||
|
@ -173,7 +173,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
|||||||
let Some((ty, n)) = autoderef.nth(pick.autoderefs) else {
|
let Some((ty, n)) = autoderef.nth(pick.autoderefs) else {
|
||||||
return Ty::new_error_with_message(
|
return Ty::new_error_with_message(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
rustc_span::DUMMY_SP,
|
DUMMY_SP,
|
||||||
format!("failed autoderef {}", pick.autoderefs),
|
format!("failed autoderef {}", pick.autoderefs),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -608,7 +608,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
|||||||
let span = predicates
|
let span = predicates
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|(p, span)| if p == pred { Some(span) } else { None })
|
.find_map(|(p, span)| if p == pred { Some(span) } else { None })
|
||||||
.unwrap_or(rustc_span::DUMMY_SP);
|
.unwrap_or(DUMMY_SP);
|
||||||
Some((trait_pred, span))
|
Some((trait_pred, span))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -8,7 +8,7 @@ use hir::ItemKind;
|
|||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
||||||
use rustc_middle::ty::{Adt, Array, Ref, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS;
|
use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS;
|
||||||
use rustc_span::symbol::kw::{Empty, Underscore};
|
use rustc_span::symbol::kw::{Empty, Underscore};
|
||||||
use rustc_span::symbol::{sym, Ident};
|
use rustc_span::symbol::{sym, Ident};
|
||||||
@ -44,7 +44,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// but `[T; N].into_iter()` doesn't resolve to IntoIterator::into_iter
|
// but `[T; N].into_iter()` doesn't resolve to IntoIterator::into_iter
|
||||||
// before Rust 2021, which results in the same problem.
|
// before Rust 2021, which results in the same problem.
|
||||||
// It is only a problem for arrays.
|
// It is only a problem for arrays.
|
||||||
sym::into_iter if let Array(..) = self_ty.kind() => {
|
sym::into_iter if let ty::Array(..) = self_ty.kind() => {
|
||||||
// In this case, it wasn't really a prelude addition that was the problem.
|
// In this case, it wasn't really a prelude addition that was the problem.
|
||||||
// Instead, the problem is that the array-into_iter hack will no longer apply in Rust 2021.
|
// Instead, the problem is that the array-into_iter hack will no longer apply in Rust 2021.
|
||||||
rustc_lint::ARRAY_INTO_ITER
|
rustc_lint::ARRAY_INTO_ITER
|
||||||
@ -64,7 +64,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
pick.autoref_or_ptr_adjustment,
|
pick.autoref_or_ptr_adjustment,
|
||||||
Some(probe::AutorefOrPtrAdjustment::Autoref { .. })
|
Some(probe::AutorefOrPtrAdjustment::Autoref { .. })
|
||||||
)
|
)
|
||||||
&& matches!(self_ty.kind(), Ref(..))
|
&& matches!(self_ty.kind(), ty::Ref(..))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -278,7 +278,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// the user has written the self type with generics already which we (naively) do by looking
|
// the user has written the self type with generics already which we (naively) do by looking
|
||||||
// for a "<" in `self_ty_name`.
|
// for a "<" in `self_ty_name`.
|
||||||
if !self_ty_name.contains('<') {
|
if !self_ty_name.contains('<') {
|
||||||
if let Adt(def, _) = self_ty.kind() {
|
if let ty::Adt(def, _) = self_ty.kind() {
|
||||||
let generics = self.tcx.generics_of(def.did());
|
let generics = self.tcx.generics_of(def.did());
|
||||||
if !generics.params.is_empty() {
|
if !generics.params.is_empty() {
|
||||||
let counts = generics.own_counts();
|
let counts = generics.own_counts();
|
||||||
|
@ -8,6 +8,7 @@ use rustc_data_structures::fx::FxHashSet;
|
|||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
|
use rustc_hir::HirId;
|
||||||
use rustc_hir_analysis::autoderef::{self, Autoderef};
|
use rustc_hir_analysis::autoderef::{self, Autoderef};
|
||||||
use rustc_infer::infer::canonical::OriginalQueryValues;
|
use rustc_infer::infer::canonical::OriginalQueryValues;
|
||||||
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
|
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
|
||||||
@ -86,7 +87,7 @@ pub(crate) struct ProbeContext<'a, 'tcx> {
|
|||||||
Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>,
|
Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>,
|
||||||
>,
|
>,
|
||||||
|
|
||||||
scope_expr_id: hir::HirId,
|
scope_expr_id: HirId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
|
impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
|
||||||
@ -263,7 +264,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
mode: Mode,
|
mode: Mode,
|
||||||
return_type: Ty<'tcx>,
|
return_type: Ty<'tcx>,
|
||||||
self_ty: Ty<'tcx>,
|
self_ty: Ty<'tcx>,
|
||||||
scope_expr_id: hir::HirId,
|
scope_expr_id: HirId,
|
||||||
candidate_filter: impl Fn(&ty::AssocItem) -> bool,
|
candidate_filter: impl Fn(&ty::AssocItem) -> bool,
|
||||||
) -> Vec<ty::AssocItem> {
|
) -> Vec<ty::AssocItem> {
|
||||||
let method_names = self
|
let method_names = self
|
||||||
@ -307,7 +308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
return_type: Option<Ty<'tcx>>,
|
return_type: Option<Ty<'tcx>>,
|
||||||
is_suggestion: IsSuggestion,
|
is_suggestion: IsSuggestion,
|
||||||
self_ty: Ty<'tcx>,
|
self_ty: Ty<'tcx>,
|
||||||
scope_expr_id: hir::HirId,
|
scope_expr_id: HirId,
|
||||||
scope: ProbeScope,
|
scope: ProbeScope,
|
||||||
) -> PickResult<'tcx> {
|
) -> PickResult<'tcx> {
|
||||||
self.probe_op(
|
self.probe_op(
|
||||||
@ -331,7 +332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
return_type: Option<Ty<'tcx>>,
|
return_type: Option<Ty<'tcx>>,
|
||||||
is_suggestion: IsSuggestion,
|
is_suggestion: IsSuggestion,
|
||||||
self_ty: Ty<'tcx>,
|
self_ty: Ty<'tcx>,
|
||||||
scope_expr_id: hir::HirId,
|
scope_expr_id: HirId,
|
||||||
scope: ProbeScope,
|
scope: ProbeScope,
|
||||||
) -> Vec<Candidate<'tcx>> {
|
) -> Vec<Candidate<'tcx>> {
|
||||||
self.probe_op(
|
self.probe_op(
|
||||||
@ -362,7 +363,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
return_type: Option<Ty<'tcx>>,
|
return_type: Option<Ty<'tcx>>,
|
||||||
is_suggestion: IsSuggestion,
|
is_suggestion: IsSuggestion,
|
||||||
self_ty: Ty<'tcx>,
|
self_ty: Ty<'tcx>,
|
||||||
scope_expr_id: hir::HirId,
|
scope_expr_id: HirId,
|
||||||
scope: ProbeScope,
|
scope: ProbeScope,
|
||||||
op: OP,
|
op: OP,
|
||||||
) -> Result<R, MethodError<'tcx>>
|
) -> Result<R, MethodError<'tcx>>
|
||||||
@ -589,7 +590,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||||||
return_type: Option<Ty<'tcx>>,
|
return_type: Option<Ty<'tcx>>,
|
||||||
orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
|
orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
|
||||||
steps: &'tcx [CandidateStep<'tcx>],
|
steps: &'tcx [CandidateStep<'tcx>],
|
||||||
scope_expr_id: hir::HirId,
|
scope_expr_id: HirId,
|
||||||
) -> ProbeContext<'a, 'tcx> {
|
) -> ProbeContext<'a, 'tcx> {
|
||||||
ProbeContext {
|
ProbeContext {
|
||||||
fcx,
|
fcx,
|
||||||
@ -1381,7 +1382,7 @@ impl<'tcx> Pick<'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
scope_expr_id: hir::HirId,
|
scope_expr_id: HirId,
|
||||||
) {
|
) {
|
||||||
if self.unstable_candidates.is_empty() {
|
if self.unstable_candidates.is_empty() {
|
||||||
return;
|
return;
|
||||||
|
@ -1844,23 +1844,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
has_unsuggestable_args = true;
|
has_unsuggestable_args = true;
|
||||||
match arg.unpack() {
|
match arg.unpack() {
|
||||||
GenericArgKind::Lifetime(_) => self
|
GenericArgKind::Lifetime(_) => self
|
||||||
.next_region_var(RegionVariableOrigin::MiscVariable(
|
.next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP))
|
||||||
rustc_span::DUMMY_SP,
|
|
||||||
))
|
|
||||||
.into(),
|
.into(),
|
||||||
GenericArgKind::Type(_) => self
|
GenericArgKind::Type(_) => self
|
||||||
.next_ty_var(TypeVariableOrigin {
|
.next_ty_var(TypeVariableOrigin {
|
||||||
span: rustc_span::DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
param_def_id: None,
|
param_def_id: None,
|
||||||
})
|
})
|
||||||
.into(),
|
.into(),
|
||||||
GenericArgKind::Const(arg) => self
|
GenericArgKind::Const(arg) => self
|
||||||
.next_const_var(
|
.next_const_var(
|
||||||
arg.ty(),
|
arg.ty(),
|
||||||
ConstVariableOrigin {
|
ConstVariableOrigin { span: DUMMY_SP, param_def_id: None },
|
||||||
span: rustc_span::DUMMY_SP,
|
|
||||||
param_def_id: None,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
}
|
}
|
||||||
@ -2758,7 +2753,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let SelfSource::QPath(ty) = self_source else {
|
let SelfSource::QPath(ty) = self_source else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
for (deref_ty, _) in self.autoderef(rustc_span::DUMMY_SP, rcvr_ty).skip(1) {
|
for (deref_ty, _) in self.autoderef(DUMMY_SP, rcvr_ty).skip(1) {
|
||||||
if let Ok(pick) = self.probe_for_name(
|
if let Ok(pick) = self.probe_for_name(
|
||||||
Mode::Path,
|
Mode::Path,
|
||||||
item_name,
|
item_name,
|
||||||
|
@ -12,7 +12,7 @@ use rustc_infer::infer;
|
|||||||
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
use rustc_infer::infer::type_variable::TypeVariableOrigin;
|
||||||
use rustc_lint as lint;
|
use rustc_lint as lint;
|
||||||
use rustc_middle::mir::interpret::ErrorHandled;
|
use rustc_middle::mir::interpret::ErrorHandled;
|
||||||
use rustc_middle::ty::{self, Adt, Ty, TypeVisitableExt};
|
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
||||||
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
|
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
|
||||||
use rustc_span::edit_distance::find_best_match_for_name;
|
use rustc_span::edit_distance::find_best_match_for_name;
|
||||||
use rustc_span::hygiene::DesugaringKind;
|
use rustc_span::hygiene::DesugaringKind;
|
||||||
@ -1106,7 +1106,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let (type_def_id, item_def_id) = match pat_ty.kind() {
|
let (type_def_id, item_def_id) = match pat_ty.kind() {
|
||||||
Adt(def, _) => match res {
|
ty::Adt(def, _) => match res {
|
||||||
Res::Def(DefKind::Const, def_id) => (Some(def.did()), Some(def_id)),
|
Res::Def(DefKind::Const, def_id) => (Some(def.did()), Some(def_id)),
|
||||||
_ => (None, None),
|
_ => (None, None),
|
||||||
},
|
},
|
||||||
|
@ -3,7 +3,7 @@ use super::callee::DeferredCallResolution;
|
|||||||
use rustc_data_structures::unord::{UnordMap, UnordSet};
|
use rustc_data_structures::unord::{UnordMap, UnordSet};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::HirIdMap;
|
use rustc_hir::{HirId, HirIdMap};
|
||||||
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
|
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
|
||||||
use rustc_middle::ty::visit::TypeVisitableExt;
|
use rustc_middle::ty::visit::TypeVisitableExt;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
@ -52,9 +52,9 @@ pub(crate) struct TypeckRootCtxt<'tcx> {
|
|||||||
|
|
||||||
pub(super) deferred_cast_checks: RefCell<Vec<super::cast::CastCheck<'tcx>>>,
|
pub(super) deferred_cast_checks: RefCell<Vec<super::cast::CastCheck<'tcx>>>,
|
||||||
|
|
||||||
pub(super) deferred_transmute_checks: RefCell<Vec<(Ty<'tcx>, Ty<'tcx>, hir::HirId)>>,
|
pub(super) deferred_transmute_checks: RefCell<Vec<(Ty<'tcx>, Ty<'tcx>, HirId)>>,
|
||||||
|
|
||||||
pub(super) deferred_asm_checks: RefCell<Vec<(&'tcx hir::InlineAsm<'tcx>, hir::HirId)>>,
|
pub(super) deferred_asm_checks: RefCell<Vec<(&'tcx hir::InlineAsm<'tcx>, HirId)>>,
|
||||||
|
|
||||||
pub(super) deferred_coroutine_interiors: RefCell<Vec<(LocalDefId, hir::BodyId, Ty<'tcx>)>>,
|
pub(super) deferred_coroutine_interiors: RefCell<Vec<(LocalDefId, hir::BodyId, Ty<'tcx>)>>,
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ use rustc_errors::{Applicability, MultiSpan};
|
|||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
|
use rustc_hir::HirId;
|
||||||
use rustc_infer::infer::UpvarRegion;
|
use rustc_infer::infer::UpvarRegion;
|
||||||
use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, ProjectionKind};
|
use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, ProjectionKind};
|
||||||
use rustc_middle::mir::FakeReadCause;
|
use rustc_middle::mir::FakeReadCause;
|
||||||
@ -88,7 +89,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
enum UpvarMigrationInfo {
|
enum UpvarMigrationInfo {
|
||||||
/// We previously captured all of `x`, but now we capture some sub-path.
|
/// We previously captured all of `x`, but now we capture some sub-path.
|
||||||
CapturingPrecise { source_expr: Option<hir::HirId>, var_name: String },
|
CapturingPrecise { source_expr: Option<HirId>, var_name: String },
|
||||||
CapturingNothing {
|
CapturingNothing {
|
||||||
// where the variable appears in the closure (but is not captured)
|
// where the variable appears in the closure (but is not captured)
|
||||||
use_span: Span,
|
use_span: Span,
|
||||||
@ -131,7 +132,7 @@ struct MigrationLintNote {
|
|||||||
/// Intermediate format to store the hir id of the root variable and a HashSet containing
|
/// Intermediate format to store the hir id of the root variable and a HashSet containing
|
||||||
/// information on why the root variable should be fully captured
|
/// information on why the root variable should be fully captured
|
||||||
struct NeededMigration {
|
struct NeededMigration {
|
||||||
var_hir_id: hir::HirId,
|
var_hir_id: HirId,
|
||||||
diagnostics_info: Vec<MigrationLintNote>,
|
diagnostics_info: Vec<MigrationLintNote>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +164,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
#[instrument(skip(self, body), level = "debug")]
|
#[instrument(skip(self, body), level = "debug")]
|
||||||
fn analyze_closure(
|
fn analyze_closure(
|
||||||
&self,
|
&self,
|
||||||
closure_hir_id: hir::HirId,
|
closure_hir_id: HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
body_id: hir::BodyId,
|
body_id: hir::BodyId,
|
||||||
body: &'tcx hir::Body<'tcx>,
|
body: &'tcx hir::Body<'tcx>,
|
||||||
@ -1098,7 +1099,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
fn compute_2229_migrations_for_trait(
|
fn compute_2229_migrations_for_trait(
|
||||||
&self,
|
&self,
|
||||||
min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>,
|
min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>,
|
||||||
var_hir_id: hir::HirId,
|
var_hir_id: HirId,
|
||||||
closure_clause: hir::CaptureBy,
|
closure_clause: hir::CaptureBy,
|
||||||
) -> Option<FxIndexMap<UpvarMigrationInfo, UnordSet<&'static str>>> {
|
) -> Option<FxIndexMap<UpvarMigrationInfo, UnordSet<&'static str>>> {
|
||||||
let auto_traits_def_id = [
|
let auto_traits_def_id = [
|
||||||
@ -1210,7 +1211,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
closure_span: Span,
|
closure_span: Span,
|
||||||
min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>,
|
min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>,
|
||||||
closure_clause: hir::CaptureBy,
|
closure_clause: hir::CaptureBy,
|
||||||
var_hir_id: hir::HirId,
|
var_hir_id: HirId,
|
||||||
) -> Option<FxIndexSet<UpvarMigrationInfo>> {
|
) -> Option<FxIndexSet<UpvarMigrationInfo>> {
|
||||||
let ty = self.resolve_vars_if_possible(self.node_ty(var_hir_id));
|
let ty = self.resolve_vars_if_possible(self.node_ty(var_hir_id));
|
||||||
|
|
||||||
@ -1650,7 +1651,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
fn place_for_root_variable(
|
fn place_for_root_variable(
|
||||||
&self,
|
&self,
|
||||||
closure_def_id: LocalDefId,
|
closure_def_id: LocalDefId,
|
||||||
var_hir_id: hir::HirId,
|
var_hir_id: HirId,
|
||||||
) -> Place<'tcx> {
|
) -> Place<'tcx> {
|
||||||
let upvar_id = ty::UpvarId::new(var_hir_id, closure_def_id);
|
let upvar_id = ty::UpvarId::new(var_hir_id, closure_def_id);
|
||||||
|
|
||||||
@ -1881,7 +1882,7 @@ fn apply_capture_kind_on_capture_ty<'tcx>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the Span of where the value with the provided HirId would be dropped
|
/// Returns the Span of where the value with the provided HirId would be dropped
|
||||||
fn drop_location_span(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> Span {
|
fn drop_location_span(tcx: TyCtxt<'_>, hir_id: HirId) -> Span {
|
||||||
let owner_id = tcx.hir().get_enclosing_scope(hir_id).unwrap();
|
let owner_id = tcx.hir().get_enclosing_scope(hir_id).unwrap();
|
||||||
|
|
||||||
let owner_node = tcx.hir_node(owner_id);
|
let owner_node = tcx.hir_node(owner_id);
|
||||||
@ -1933,7 +1934,7 @@ struct InferBorrowKind<'tcx> {
|
|||||||
/// Place { V1, [ProjectionKind::Field(Index=1, Variant=0)] } : CaptureKind { E2, MutableBorrow }
|
/// Place { V1, [ProjectionKind::Field(Index=1, Variant=0)] } : CaptureKind { E2, MutableBorrow }
|
||||||
/// ```
|
/// ```
|
||||||
capture_information: InferredCaptureInformation<'tcx>,
|
capture_information: InferredCaptureInformation<'tcx>,
|
||||||
fake_reads: Vec<(Place<'tcx>, FakeReadCause, hir::HirId)>,
|
fake_reads: Vec<(Place<'tcx>, FakeReadCause, HirId)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
|
impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
|
||||||
@ -1941,7 +1942,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
place: &PlaceWithHirId<'tcx>,
|
place: &PlaceWithHirId<'tcx>,
|
||||||
cause: FakeReadCause,
|
cause: FakeReadCause,
|
||||||
diag_expr_id: hir::HirId,
|
diag_expr_id: HirId,
|
||||||
) {
|
) {
|
||||||
let PlaceBase::Upvar(_) = place.place.base else { return };
|
let PlaceBase::Upvar(_) = place.place.base else { return };
|
||||||
|
|
||||||
@ -1956,7 +1957,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
|
fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
|
||||||
let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return };
|
let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return };
|
||||||
assert_eq!(self.closure_def_id, upvar_id.closure_expr_id);
|
assert_eq!(self.closure_def_id, upvar_id.closure_expr_id);
|
||||||
|
|
||||||
@ -1974,7 +1975,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
|
|||||||
fn borrow(
|
fn borrow(
|
||||||
&mut self,
|
&mut self,
|
||||||
place_with_id: &PlaceWithHirId<'tcx>,
|
place_with_id: &PlaceWithHirId<'tcx>,
|
||||||
diag_expr_id: hir::HirId,
|
diag_expr_id: HirId,
|
||||||
bk: ty::BorrowKind,
|
bk: ty::BorrowKind,
|
||||||
) {
|
) {
|
||||||
let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return };
|
let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return };
|
||||||
@ -2005,7 +2006,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) {
|
fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
|
||||||
self.borrow(assignee_place, diag_expr_id, ty::BorrowKind::MutBorrow);
|
self.borrow(assignee_place, diag_expr_id, ty::BorrowKind::MutBorrow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2192,14 +2193,14 @@ fn construct_capture_info_string<'tcx>(
|
|||||||
format!("{place_str} -> {capture_kind_str}")
|
format!("{place_str} -> {capture_kind_str}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn var_name(tcx: TyCtxt<'_>, var_hir_id: hir::HirId) -> Symbol {
|
fn var_name(tcx: TyCtxt<'_>, var_hir_id: HirId) -> Symbol {
|
||||||
tcx.hir().name(var_hir_id)
|
tcx.hir().name(var_hir_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(tcx))]
|
#[instrument(level = "debug", skip(tcx))]
|
||||||
fn should_do_rust_2021_incompatible_closure_captures_analysis(
|
fn should_do_rust_2021_incompatible_closure_captures_analysis(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
closure_id: hir::HirId,
|
closure_id: HirId,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if tcx.sess.at_least_rust_2021() {
|
if tcx.sess.at_least_rust_2021() {
|
||||||
return false;
|
return false;
|
||||||
|
@ -7,6 +7,7 @@ use rustc_data_structures::unord::ExtendUnord;
|
|||||||
use rustc_errors::{ErrorGuaranteed, StashKey};
|
use rustc_errors::{ErrorGuaranteed, StashKey};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
|
use rustc_hir::HirId;
|
||||||
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
|
use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282;
|
||||||
use rustc_middle::traits::ObligationCause;
|
use rustc_middle::traits::ObligationCause;
|
||||||
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
|
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
|
||||||
@ -134,7 +135,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
self.fcx.tcx
|
self.fcx.tcx
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_ty_to_typeck_results(&mut self, hir_id: hir::HirId, ty: Ty<'tcx>) {
|
fn write_ty_to_typeck_results(&mut self, hir_id: HirId, ty: Ty<'tcx>) {
|
||||||
debug!("write_ty_to_typeck_results({:?}, {:?})", hir_id, ty);
|
debug!("write_ty_to_typeck_results({:?}, {:?})", hir_id, ty);
|
||||||
assert!(
|
assert!(
|
||||||
!ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions(),
|
!ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions(),
|
||||||
@ -461,7 +462,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
fcx_typeck_results.closure_kind_origins().items_in_stable_order();
|
fcx_typeck_results.closure_kind_origins().items_in_stable_order();
|
||||||
|
|
||||||
for (local_id, origin) in fcx_closure_kind_origins {
|
for (local_id, origin) in fcx_closure_kind_origins {
|
||||||
let hir_id = hir::HirId { owner: common_hir_owner, local_id };
|
let hir_id = HirId { owner: common_hir_owner, local_id };
|
||||||
let place_span = origin.0;
|
let place_span = origin.0;
|
||||||
let place = self.resolve(origin.1.clone(), &place_span);
|
let place = self.resolve(origin.1.clone(), &place_span);
|
||||||
self.typeck_results.closure_kind_origins_mut().insert(hir_id, (place_span, place));
|
self.typeck_results.closure_kind_origins_mut().insert(hir_id, (place_span, place));
|
||||||
@ -490,7 +491,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
|
|
||||||
let mut errors_buffer = Vec::new();
|
let mut errors_buffer = Vec::new();
|
||||||
for (local_id, c_ty) in sorted_user_provided_types {
|
for (local_id, c_ty) in sorted_user_provided_types {
|
||||||
let hir_id = hir::HirId { owner: common_hir_owner, local_id };
|
let hir_id = HirId { owner: common_hir_owner, local_id };
|
||||||
|
|
||||||
if let ty::UserType::TypeOf(_, user_args) = c_ty.value {
|
if let ty::UserType::TypeOf(_, user_args) = c_ty.value {
|
||||||
// This is a unit-testing mechanism.
|
// This is a unit-testing mechanism.
|
||||||
@ -513,7 +514,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
|
|
||||||
self.typeck_results.user_provided_types_mut().extend(
|
self.typeck_results.user_provided_types_mut().extend(
|
||||||
fcx_typeck_results.user_provided_types().items().map(|(local_id, c_ty)| {
|
fcx_typeck_results.user_provided_types().items().map(|(local_id, c_ty)| {
|
||||||
let hir_id = hir::HirId { owner: common_hir_owner, local_id };
|
let hir_id = HirId { owner: common_hir_owner, local_id };
|
||||||
|
|
||||||
if cfg!(debug_assertions) && c_ty.has_infer() {
|
if cfg!(debug_assertions) && c_ty.has_infer() {
|
||||||
span_bug!(
|
span_bug!(
|
||||||
@ -604,7 +605,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_field_id(&mut self, hir_id: hir::HirId) {
|
fn visit_field_id(&mut self, hir_id: HirId) {
|
||||||
if let Some(index) = self.fcx.typeck_results.borrow_mut().field_indices_mut().remove(hir_id)
|
if let Some(index) = self.fcx.typeck_results.borrow_mut().field_indices_mut().remove(hir_id)
|
||||||
{
|
{
|
||||||
self.typeck_results.field_indices_mut().insert(hir_id, index);
|
self.typeck_results.field_indices_mut().insert(hir_id, index);
|
||||||
@ -617,7 +618,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self, span), level = "debug")]
|
#[instrument(skip(self, span), level = "debug")]
|
||||||
fn visit_node_id(&mut self, span: Span, hir_id: hir::HirId) {
|
fn visit_node_id(&mut self, span: Span, hir_id: HirId) {
|
||||||
// Export associated path extensions and method resolutions.
|
// Export associated path extensions and method resolutions.
|
||||||
if let Some(def) =
|
if let Some(def) =
|
||||||
self.fcx.typeck_results.borrow_mut().type_dependent_defs_mut().remove(hir_id)
|
self.fcx.typeck_results.borrow_mut().type_dependent_defs_mut().remove(hir_id)
|
||||||
@ -644,7 +645,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self, span), level = "debug")]
|
#[instrument(skip(self, span), level = "debug")]
|
||||||
fn visit_adjustments(&mut self, span: Span, hir_id: hir::HirId) {
|
fn visit_adjustments(&mut self, span: Span, hir_id: HirId) {
|
||||||
let adjustment = self.fcx.typeck_results.borrow_mut().adjustments_mut().remove(hir_id);
|
let adjustment = self.fcx.typeck_results.borrow_mut().adjustments_mut().remove(hir_id);
|
||||||
match adjustment {
|
match adjustment {
|
||||||
None => {
|
None => {
|
||||||
@ -660,7 +661,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self, span), level = "debug")]
|
#[instrument(skip(self, span), level = "debug")]
|
||||||
fn visit_pat_adjustments(&mut self, span: Span, hir_id: hir::HirId) {
|
fn visit_pat_adjustments(&mut self, span: Span, hir_id: HirId) {
|
||||||
let adjustment = self.fcx.typeck_results.borrow_mut().pat_adjustments_mut().remove(hir_id);
|
let adjustment = self.fcx.typeck_results.borrow_mut().pat_adjustments_mut().remove(hir_id);
|
||||||
match adjustment {
|
match adjustment {
|
||||||
None => {
|
None => {
|
||||||
@ -691,7 +692,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
let fcx_liberated_fn_sigs = fcx_typeck_results.liberated_fn_sigs().items_in_stable_order();
|
let fcx_liberated_fn_sigs = fcx_typeck_results.liberated_fn_sigs().items_in_stable_order();
|
||||||
|
|
||||||
for (local_id, &fn_sig) in fcx_liberated_fn_sigs {
|
for (local_id, &fn_sig) in fcx_liberated_fn_sigs {
|
||||||
let hir_id = hir::HirId { owner: common_hir_owner, local_id };
|
let hir_id = HirId { owner: common_hir_owner, local_id };
|
||||||
let fn_sig = self.resolve(fn_sig, &hir_id);
|
let fn_sig = self.resolve(fn_sig, &hir_id);
|
||||||
self.typeck_results.liberated_fn_sigs_mut().insert(hir_id, fn_sig);
|
self.typeck_results.liberated_fn_sigs_mut().insert(hir_id, fn_sig);
|
||||||
}
|
}
|
||||||
@ -705,7 +706,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
let fcx_fru_field_types = fcx_typeck_results.fru_field_types().items_in_stable_order();
|
let fcx_fru_field_types = fcx_typeck_results.fru_field_types().items_in_stable_order();
|
||||||
|
|
||||||
for (local_id, ftys) in fcx_fru_field_types {
|
for (local_id, ftys) in fcx_fru_field_types {
|
||||||
let hir_id = hir::HirId { owner: common_hir_owner, local_id };
|
let hir_id = HirId { owner: common_hir_owner, local_id };
|
||||||
let ftys = self.resolve(ftys.clone(), &hir_id);
|
let ftys = self.resolve(ftys.clone(), &hir_id);
|
||||||
self.typeck_results.fru_field_types_mut().insert(hir_id, ftys);
|
self.typeck_results.fru_field_types_mut().insert(hir_id, ftys);
|
||||||
}
|
}
|
||||||
@ -719,7 +720,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
for (local_id, &(container, ref indices)) in
|
for (local_id, &(container, ref indices)) in
|
||||||
fcx_typeck_results.offset_of_data().items_in_stable_order()
|
fcx_typeck_results.offset_of_data().items_in_stable_order()
|
||||||
{
|
{
|
||||||
let hir_id = hir::HirId { owner: common_hir_owner, local_id };
|
let hir_id = HirId { owner: common_hir_owner, local_id };
|
||||||
let container = self.resolve(container, &hir_id);
|
let container = self.resolve(container, &hir_id);
|
||||||
self.typeck_results.offset_of_data_mut().insert(hir_id, (container, indices.clone()));
|
self.typeck_results.offset_of_data_mut().insert(hir_id, (container, indices.clone()));
|
||||||
}
|
}
|
||||||
@ -754,7 +755,7 @@ impl Locatable for Span {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Locatable for hir::HirId {
|
impl Locatable for HirId {
|
||||||
fn to_span(&self, tcx: TyCtxt<'_>) -> Span {
|
fn to_span(&self, tcx: TyCtxt<'_>) -> Span {
|
||||||
tcx.hir().span(*self)
|
tcx.hir().span(*self)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ use rustc_data_structures::sync::{join, Lrc};
|
|||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
|
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
|
||||||
use rustc_hir::intravisit as hir_visit;
|
use rustc_hir::intravisit as hir_visit;
|
||||||
|
use rustc_hir::HirId;
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_session::lint::LintPass;
|
use rustc_session::lint::LintPass;
|
||||||
@ -53,7 +54,7 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
|
|||||||
/// Merge the lints specified by any lint attributes into the
|
/// Merge the lints specified by any lint attributes into the
|
||||||
/// current lint context, call the provided function, then reset the
|
/// current lint context, call the provided function, then reset the
|
||||||
/// lints in effect to their previous state.
|
/// lints in effect to their previous state.
|
||||||
fn with_lint_attrs<F>(&mut self, id: hir::HirId, f: F)
|
fn with_lint_attrs<F>(&mut self, id: HirId, f: F)
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self),
|
F: FnOnce(&mut Self),
|
||||||
{
|
{
|
||||||
@ -81,7 +82,7 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
|
|||||||
self.context.param_env = old_param_env;
|
self.context.param_env = old_param_env;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_mod(&mut self, m: &'tcx hir::Mod<'tcx>, n: hir::HirId) {
|
fn process_mod(&mut self, m: &'tcx hir::Mod<'tcx>, n: HirId) {
|
||||||
lint_callback!(self, check_mod, m, n);
|
lint_callback!(self, check_mod, m, n);
|
||||||
hir_visit::walk_mod(self, m, n);
|
hir_visit::walk_mod(self, m, n);
|
||||||
}
|
}
|
||||||
@ -231,7 +232,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||||||
hir_visit::walk_inf(self, inf);
|
hir_visit::walk_inf(self, inf);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mod(&mut self, m: &'tcx hir::Mod<'tcx>, _: Span, n: hir::HirId) {
|
fn visit_mod(&mut self, m: &'tcx hir::Mod<'tcx>, _: Span, n: HirId) {
|
||||||
if !self.context.only_module {
|
if !self.context.only_module {
|
||||||
self.process_mod(m, n);
|
self.process_mod(m, n);
|
||||||
}
|
}
|
||||||
@ -305,7 +306,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||||||
hir_visit::walk_lifetime(self, lt);
|
hir_visit::walk_lifetime(self, lt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path(&mut self, p: &hir::Path<'tcx>, id: hir::HirId) {
|
fn visit_path(&mut self, p: &hir::Path<'tcx>, id: HirId) {
|
||||||
lint_callback!(self, check_path, p, id);
|
lint_callback!(self, check_path, p, id);
|
||||||
hir_visit::walk_path(self, p);
|
hir_visit::walk_path(self, p);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ use crate::ty::TyCtxt;
|
|||||||
use rustc_data_structures::fx::FxIndexMap;
|
use rustc_data_structures::fx::FxIndexMap;
|
||||||
use rustc_data_structures::unord::UnordMap;
|
use rustc_data_structures::unord::UnordMap;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::{HirIdMap, Node};
|
use rustc_hir::{HirId, HirIdMap, Node};
|
||||||
use rustc_macros::HashStable;
|
use rustc_macros::HashStable;
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
|
|
||||||
@ -164,10 +164,10 @@ impl Scope {
|
|||||||
self.id
|
self.id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option<hir::HirId> {
|
pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option<HirId> {
|
||||||
scope_tree
|
scope_tree
|
||||||
.root_body
|
.root_body
|
||||||
.map(|hir_id| hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() })
|
.map(|hir_id| HirId { owner: hir_id.owner, local_id: self.item_local_id() })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the span of this `Scope`. Note that in general the
|
/// Returns the span of this `Scope`. Note that in general the
|
||||||
@ -207,7 +207,7 @@ pub type ScopeDepth = u32;
|
|||||||
#[derive(Default, Debug, HashStable)]
|
#[derive(Default, Debug, HashStable)]
|
||||||
pub struct ScopeTree {
|
pub struct ScopeTree {
|
||||||
/// If not empty, this body is the root of this region hierarchy.
|
/// If not empty, this body is the root of this region hierarchy.
|
||||||
pub root_body: Option<hir::HirId>,
|
pub root_body: Option<HirId>,
|
||||||
|
|
||||||
/// Maps from a scope ID to the enclosing scope id;
|
/// Maps from a scope ID to the enclosing scope id;
|
||||||
/// this is usually corresponding to the lexical nesting, though
|
/// this is usually corresponding to the lexical nesting, though
|
||||||
@ -341,11 +341,7 @@ impl ScopeTree {
|
|||||||
self.var_map.insert(var, lifetime);
|
self.var_map.insert(var, lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn record_rvalue_candidate(
|
pub fn record_rvalue_candidate(&mut self, var: HirId, candidate_type: RvalueCandidateType) {
|
||||||
&mut self,
|
|
||||||
var: hir::HirId,
|
|
||||||
candidate_type: RvalueCandidateType,
|
|
||||||
) {
|
|
||||||
debug!("record_rvalue_candidate(var={var:?}, type={candidate_type:?})");
|
debug!("record_rvalue_candidate(var={var:?}, type={candidate_type:?})");
|
||||||
match &candidate_type {
|
match &candidate_type {
|
||||||
RvalueCandidateType::Borrow { lifetime: Some(lifetime), .. }
|
RvalueCandidateType::Borrow { lifetime: Some(lifetime), .. }
|
||||||
|
@ -1545,7 +1545,7 @@ pub struct SourceScopeData<'tcx> {
|
|||||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
|
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
|
||||||
pub struct SourceScopeLocalData {
|
pub struct SourceScopeLocalData {
|
||||||
/// An `HirId` with lint levels equivalent to this scope's lint levels.
|
/// An `HirId` with lint levels equivalent to this scope's lint levels.
|
||||||
pub lint_root: hir::HirId,
|
pub lint_root: HirId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A collection of projections into user types.
|
/// A collection of projections into user types.
|
||||||
|
@ -12,7 +12,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
|||||||
use rustc_errors::{DiagArgValue, IntoDiagArg};
|
use rustc_errors::{DiagArgValue, IntoDiagArg};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::{BindingAnnotation, ByRef, MatchSource, RangeEnd};
|
use rustc_hir::{BindingAnnotation, ByRef, HirId, MatchSource, RangeEnd};
|
||||||
use rustc_index::newtype_index;
|
use rustc_index::newtype_index;
|
||||||
use rustc_index::IndexVec;
|
use rustc_index::IndexVec;
|
||||||
use rustc_middle::middle::region;
|
use rustc_middle::middle::region;
|
||||||
@ -115,13 +115,13 @@ pub struct Param<'tcx> {
|
|||||||
/// Whether this param is `self`, and how it is bound.
|
/// Whether this param is `self`, and how it is bound.
|
||||||
pub self_kind: Option<hir::ImplicitSelfKind>,
|
pub self_kind: Option<hir::ImplicitSelfKind>,
|
||||||
/// HirId for lints.
|
/// HirId for lints.
|
||||||
pub hir_id: Option<hir::HirId>,
|
pub hir_id: Option<HirId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, HashStable)]
|
#[derive(Copy, Clone, Debug, HashStable)]
|
||||||
pub enum LintLevel {
|
pub enum LintLevel {
|
||||||
Inherited,
|
Inherited,
|
||||||
Explicit(hir::HirId),
|
Explicit(HirId),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, HashStable)]
|
#[derive(Clone, Debug, HashStable)]
|
||||||
@ -167,7 +167,7 @@ pub struct ClosureExpr<'tcx> {
|
|||||||
pub args: UpvarArgs<'tcx>,
|
pub args: UpvarArgs<'tcx>,
|
||||||
pub upvars: Box<[ExprId]>,
|
pub upvars: Box<[ExprId]>,
|
||||||
pub movability: Option<hir::Movability>,
|
pub movability: Option<hir::Movability>,
|
||||||
pub fake_reads: Vec<(ExprId, FakeReadCause, hir::HirId)>,
|
pub fake_reads: Vec<(ExprId, FakeReadCause, HirId)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, HashStable)]
|
#[derive(Clone, Debug, HashStable)]
|
||||||
@ -184,7 +184,7 @@ pub enum BlockSafety {
|
|||||||
/// A compiler-generated unsafe block
|
/// A compiler-generated unsafe block
|
||||||
BuiltinUnsafe,
|
BuiltinUnsafe,
|
||||||
/// An `unsafe` block. The `HirId` is the ID of the block.
|
/// An `unsafe` block. The `HirId` is the ID of the block.
|
||||||
ExplicitUnsafe(hir::HirId),
|
ExplicitUnsafe(HirId),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, HashStable)]
|
#[derive(Clone, Debug, HashStable)]
|
||||||
@ -233,7 +233,7 @@ pub enum StmtKind<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
|
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
|
||||||
pub struct LocalVarId(pub hir::HirId);
|
pub struct LocalVarId(pub HirId);
|
||||||
|
|
||||||
/// A THIR expression.
|
/// A THIR expression.
|
||||||
#[derive(Clone, Debug, HashStable)]
|
#[derive(Clone, Debug, HashStable)]
|
||||||
@ -356,7 +356,7 @@ pub enum ExprKind<'tcx> {
|
|||||||
/// A `match` expression.
|
/// A `match` expression.
|
||||||
Match {
|
Match {
|
||||||
scrutinee: ExprId,
|
scrutinee: ExprId,
|
||||||
scrutinee_hir_id: hir::HirId,
|
scrutinee_hir_id: HirId,
|
||||||
arms: Box<[ArmId]>,
|
arms: Box<[ArmId]>,
|
||||||
match_source: MatchSource,
|
match_source: MatchSource,
|
||||||
},
|
},
|
||||||
|
@ -19,6 +19,7 @@ use rustc_data_structures::sync::Lrc;
|
|||||||
use rustc_errors::{Applicability, Diag, EmissionGuarantee};
|
use rustc_errors::{Applicability, Diag, EmissionGuarantee};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
|
use rustc_hir::HirId;
|
||||||
use rustc_span::def_id::{LocalDefId, CRATE_DEF_ID};
|
use rustc_span::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
@ -262,10 +263,10 @@ pub enum ObligationCauseCode<'tcx> {
|
|||||||
/// expression that caused the obligation, and the `usize`
|
/// expression that caused the obligation, and the `usize`
|
||||||
/// indicates exactly which predicate it is in the list of
|
/// indicates exactly which predicate it is in the list of
|
||||||
/// instantiated predicates.
|
/// instantiated predicates.
|
||||||
ExprItemObligation(DefId, rustc_hir::HirId, usize),
|
ExprItemObligation(DefId, HirId, usize),
|
||||||
|
|
||||||
/// Combines `ExprItemObligation` and `BindingObligation`.
|
/// Combines `ExprItemObligation` and `BindingObligation`.
|
||||||
ExprBindingObligation(DefId, Span, rustc_hir::HirId, usize),
|
ExprBindingObligation(DefId, Span, HirId, usize),
|
||||||
|
|
||||||
/// A type like `&'a T` is WF only if `T: 'a`.
|
/// A type like `&'a T` is WF only if `T: 'a`.
|
||||||
ReferenceOutlivesReferent(Ty<'tcx>),
|
ReferenceOutlivesReferent(Ty<'tcx>),
|
||||||
@ -287,9 +288,9 @@ pub enum ObligationCauseCode<'tcx> {
|
|||||||
/// `S { ... }` must be `Sized`.
|
/// `S { ... }` must be `Sized`.
|
||||||
StructInitializerSized,
|
StructInitializerSized,
|
||||||
/// Type of each variable must be `Sized`.
|
/// Type of each variable must be `Sized`.
|
||||||
VariableType(hir::HirId),
|
VariableType(HirId),
|
||||||
/// Argument type must be `Sized`.
|
/// Argument type must be `Sized`.
|
||||||
SizedArgumentType(Option<hir::HirId>),
|
SizedArgumentType(Option<HirId>),
|
||||||
/// Return type must be `Sized`.
|
/// Return type must be `Sized`.
|
||||||
SizedReturnType,
|
SizedReturnType,
|
||||||
/// Return type of a call expression must be `Sized`.
|
/// Return type of a call expression must be `Sized`.
|
||||||
@ -335,9 +336,9 @@ pub enum ObligationCauseCode<'tcx> {
|
|||||||
|
|
||||||
FunctionArgumentObligation {
|
FunctionArgumentObligation {
|
||||||
/// The node of the relevant argument in the function call.
|
/// The node of the relevant argument in the function call.
|
||||||
arg_hir_id: hir::HirId,
|
arg_hir_id: HirId,
|
||||||
/// The node of the function call.
|
/// The node of the function call.
|
||||||
call_hir_id: hir::HirId,
|
call_hir_id: HirId,
|
||||||
/// The obligation introduced by this argument.
|
/// The obligation introduced by this argument.
|
||||||
parent_code: InternedObligationCauseCode<'tcx>,
|
parent_code: InternedObligationCauseCode<'tcx>,
|
||||||
},
|
},
|
||||||
@ -402,18 +403,18 @@ pub enum ObligationCauseCode<'tcx> {
|
|||||||
ReturnNoExpression,
|
ReturnNoExpression,
|
||||||
|
|
||||||
/// `return` with an expression
|
/// `return` with an expression
|
||||||
ReturnValue(hir::HirId),
|
ReturnValue(HirId),
|
||||||
|
|
||||||
/// Opaque return type of this function
|
/// Opaque return type of this function
|
||||||
OpaqueReturnType(Option<(Ty<'tcx>, Span)>),
|
OpaqueReturnType(Option<(Ty<'tcx>, Span)>),
|
||||||
|
|
||||||
/// Block implicit return
|
/// Block implicit return
|
||||||
BlockTailExpression(hir::HirId, hir::MatchSource),
|
BlockTailExpression(HirId, hir::MatchSource),
|
||||||
|
|
||||||
/// #[feature(trivial_bounds)] is not enabled
|
/// #[feature(trivial_bounds)] is not enabled
|
||||||
TrivialBound,
|
TrivialBound,
|
||||||
|
|
||||||
AwaitableExpr(hir::HirId),
|
AwaitableExpr(HirId),
|
||||||
|
|
||||||
ForLoopIterator,
|
ForLoopIterator,
|
||||||
|
|
||||||
@ -431,8 +432,8 @@ pub enum ObligationCauseCode<'tcx> {
|
|||||||
MatchImpl(ObligationCause<'tcx>, DefId),
|
MatchImpl(ObligationCause<'tcx>, DefId),
|
||||||
|
|
||||||
BinOp {
|
BinOp {
|
||||||
lhs_hir_id: hir::HirId,
|
lhs_hir_id: HirId,
|
||||||
rhs_hir_id: Option<hir::HirId>,
|
rhs_hir_id: Option<HirId>,
|
||||||
rhs_span: Option<Span>,
|
rhs_span: Option<Span>,
|
||||||
rhs_is_lit: bool,
|
rhs_is_lit: bool,
|
||||||
output_ty: Option<Ty<'tcx>>,
|
output_ty: Option<Ty<'tcx>>,
|
||||||
@ -562,10 +563,10 @@ pub enum StatementAsExpression {
|
|||||||
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
|
#[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
|
||||||
#[derive(TypeVisitable, TypeFoldable)]
|
#[derive(TypeVisitable, TypeFoldable)]
|
||||||
pub struct MatchExpressionArmCause<'tcx> {
|
pub struct MatchExpressionArmCause<'tcx> {
|
||||||
pub arm_block_id: Option<hir::HirId>,
|
pub arm_block_id: Option<HirId>,
|
||||||
pub arm_ty: Ty<'tcx>,
|
pub arm_ty: Ty<'tcx>,
|
||||||
pub arm_span: Span,
|
pub arm_span: Span,
|
||||||
pub prior_arm_block_id: Option<hir::HirId>,
|
pub prior_arm_block_id: Option<HirId>,
|
||||||
pub prior_arm_ty: Ty<'tcx>,
|
pub prior_arm_ty: Ty<'tcx>,
|
||||||
pub prior_arm_span: Span,
|
pub prior_arm_span: Span,
|
||||||
pub scrut_span: Span,
|
pub scrut_span: Span,
|
||||||
@ -578,8 +579,8 @@ pub struct MatchExpressionArmCause<'tcx> {
|
|||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
#[derive(TypeFoldable, TypeVisitable, HashStable, TyEncodable, TyDecodable)]
|
#[derive(TypeFoldable, TypeVisitable, HashStable, TyEncodable, TyDecodable)]
|
||||||
pub struct IfExpressionCause<'tcx> {
|
pub struct IfExpressionCause<'tcx> {
|
||||||
pub then_id: hir::HirId,
|
pub then_id: HirId,
|
||||||
pub else_id: hir::HirId,
|
pub else_id: HirId,
|
||||||
pub then_ty: Ty<'tcx>,
|
pub then_ty: Ty<'tcx>,
|
||||||
pub else_ty: Ty<'tcx>,
|
pub else_ty: Ty<'tcx>,
|
||||||
pub outer_span: Option<Span>,
|
pub outer_span: Option<Span>,
|
||||||
|
@ -10,6 +10,7 @@ use rustc_data_structures::captures::Captures;
|
|||||||
use rustc_data_structures::fx::FxIndexMap;
|
use rustc_data_structures::fx::FxIndexMap;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
|
use rustc_hir::HirId;
|
||||||
use rustc_span::def_id::LocalDefIdMap;
|
use rustc_span::def_id::LocalDefIdMap;
|
||||||
use rustc_span::symbol::Ident;
|
use rustc_span::symbol::Ident;
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
@ -25,7 +26,7 @@ pub const CAPTURE_STRUCT_LOCAL: mir::Local = mir::Local::from_u32(1);
|
|||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
|
||||||
#[derive(TypeFoldable, TypeVisitable)]
|
#[derive(TypeFoldable, TypeVisitable)]
|
||||||
pub struct UpvarPath {
|
pub struct UpvarPath {
|
||||||
pub hir_id: hir::HirId,
|
pub hir_id: HirId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Upvars do not get their own `NodeId`. Instead, we use the pair of
|
/// Upvars do not get their own `NodeId`. Instead, we use the pair of
|
||||||
@ -39,7 +40,7 @@ pub struct UpvarId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl UpvarId {
|
impl UpvarId {
|
||||||
pub fn new(var_hir_id: hir::HirId, closure_def_id: LocalDefId) -> UpvarId {
|
pub fn new(var_hir_id: HirId, closure_def_id: LocalDefId) -> UpvarId {
|
||||||
UpvarId { var_path: UpvarPath { hir_id: var_hir_id }, closure_expr_id: closure_def_id }
|
UpvarId { var_path: UpvarPath { hir_id: var_hir_id }, closure_expr_id: closure_def_id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,7 +69,7 @@ pub type MinCaptureInformationMap<'tcx> = LocalDefIdMap<RootVariableMinCaptureLi
|
|||||||
///
|
///
|
||||||
/// This provides a convenient and quick way of checking if a variable being used within
|
/// This provides a convenient and quick way of checking if a variable being used within
|
||||||
/// a closure is a capture of a local variable.
|
/// a closure is a capture of a local variable.
|
||||||
pub type RootVariableMinCaptureList<'tcx> = FxIndexMap<hir::HirId, MinCaptureList<'tcx>>;
|
pub type RootVariableMinCaptureList<'tcx> = FxIndexMap<HirId, MinCaptureList<'tcx>>;
|
||||||
|
|
||||||
/// Part of `MinCaptureInformationMap`; List of `CapturePlace`s.
|
/// Part of `MinCaptureInformationMap`; List of `CapturePlace`s.
|
||||||
pub type MinCaptureList<'tcx> = Vec<CapturedPlace<'tcx>>;
|
pub type MinCaptureList<'tcx> = Vec<CapturedPlace<'tcx>>;
|
||||||
@ -135,7 +136,7 @@ impl<'tcx> CapturedPlace<'tcx> {
|
|||||||
|
|
||||||
/// Returns the hir-id of the root variable for the captured place.
|
/// Returns the hir-id of the root variable for the captured place.
|
||||||
/// e.g., if `a.b.c` was captured, would return the hir-id for `a`.
|
/// e.g., if `a.b.c` was captured, would return the hir-id for `a`.
|
||||||
pub fn get_root_variable(&self) -> hir::HirId {
|
pub fn get_root_variable(&self) -> HirId {
|
||||||
match self.place.base {
|
match self.place.base {
|
||||||
HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
|
HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
|
||||||
base => bug!("Expected upvar, found={:?}", base),
|
base => bug!("Expected upvar, found={:?}", base),
|
||||||
@ -286,12 +287,12 @@ pub struct CaptureInfo {
|
|||||||
///
|
///
|
||||||
/// In this example, if `capture_disjoint_fields` is **not** set, then x will be captured,
|
/// In this example, if `capture_disjoint_fields` is **not** set, then x will be captured,
|
||||||
/// but we won't see it being used during capture analysis, since it's essentially a discard.
|
/// but we won't see it being used during capture analysis, since it's essentially a discard.
|
||||||
pub capture_kind_expr_id: Option<hir::HirId>,
|
pub capture_kind_expr_id: Option<HirId>,
|
||||||
/// Expr Id pointing to use that resulted the corresponding place being captured
|
/// Expr Id pointing to use that resulted the corresponding place being captured
|
||||||
///
|
///
|
||||||
/// See `capture_kind_expr_id` for example.
|
/// See `capture_kind_expr_id` for example.
|
||||||
///
|
///
|
||||||
pub path_expr_id: Option<hir::HirId>,
|
pub path_expr_id: Option<HirId>,
|
||||||
|
|
||||||
/// Capture mode that was selected
|
/// Capture mode that was selected
|
||||||
pub capture_kind: UpvarCapture,
|
pub capture_kind: UpvarCapture,
|
||||||
|
@ -192,7 +192,7 @@ pub struct TypeckResults<'tcx> {
|
|||||||
/// we never capture `t`. This becomes an issue when we build MIR as we require
|
/// we never capture `t`. This becomes an issue when we build MIR as we require
|
||||||
/// information on `t` in order to create place `t.0` and `t.1`. We can solve this
|
/// information on `t` in order to create place `t.0` and `t.1`. We can solve this
|
||||||
/// issue by fake reading `t`.
|
/// issue by fake reading `t`.
|
||||||
pub closure_fake_reads: LocalDefIdMap<Vec<(HirPlace<'tcx>, FakeReadCause, hir::HirId)>>,
|
pub closure_fake_reads: LocalDefIdMap<Vec<(HirPlace<'tcx>, FakeReadCause, HirId)>>,
|
||||||
|
|
||||||
/// Tracks the rvalue scoping rules which defines finer scoping for rvalue expressions
|
/// Tracks the rvalue scoping rules which defines finer scoping for rvalue expressions
|
||||||
/// by applying extended parameter rules.
|
/// by applying extended parameter rules.
|
||||||
@ -251,7 +251,7 @@ impl<'tcx> TypeckResults<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the final resolution of a `QPath` in an `Expr` or `Pat` node.
|
/// Returns the final resolution of a `QPath` in an `Expr` or `Pat` node.
|
||||||
pub fn qpath_res(&self, qpath: &hir::QPath<'_>, id: hir::HirId) -> Res {
|
pub fn qpath_res(&self, qpath: &hir::QPath<'_>, id: HirId) -> Res {
|
||||||
match *qpath {
|
match *qpath {
|
||||||
hir::QPath::Resolved(_, path) => path.res,
|
hir::QPath::Resolved(_, path) => path.res,
|
||||||
hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => self
|
hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => self
|
||||||
@ -289,11 +289,11 @@ impl<'tcx> TypeckResults<'tcx> {
|
|||||||
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.field_indices }
|
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.field_indices }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn field_index(&self, id: hir::HirId) -> FieldIdx {
|
pub fn field_index(&self, id: HirId) -> FieldIdx {
|
||||||
self.field_indices().get(id).cloned().expect("no index for a field")
|
self.field_indices().get(id).cloned().expect("no index for a field")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn opt_field_index(&self, id: hir::HirId) -> Option<FieldIdx> {
|
pub fn opt_field_index(&self, id: HirId) -> Option<FieldIdx> {
|
||||||
self.field_indices().get(id).cloned()
|
self.field_indices().get(id).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,7 +305,7 @@ impl<'tcx> TypeckResults<'tcx> {
|
|||||||
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.nested_fields }
|
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.nested_fields }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn nested_field_tys_and_indices(&self, id: hir::HirId) -> &[(Ty<'tcx>, FieldIdx)] {
|
pub fn nested_field_tys_and_indices(&self, id: HirId) -> &[(Ty<'tcx>, FieldIdx)] {
|
||||||
self.nested_fields().get(id).map_or(&[], Vec::as_slice)
|
self.nested_fields().get(id).map_or(&[], Vec::as_slice)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,13 +327,13 @@ impl<'tcx> TypeckResults<'tcx> {
|
|||||||
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_types }
|
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_types }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> {
|
pub fn node_type(&self, id: HirId) -> Ty<'tcx> {
|
||||||
self.node_type_opt(id).unwrap_or_else(|| {
|
self.node_type_opt(id).unwrap_or_else(|| {
|
||||||
bug!("node_type: no type for node {}", tls::with(|tcx| tcx.hir().node_to_string(id)))
|
bug!("node_type: no type for node {}", tls::with(|tcx| tcx.hir().node_to_string(id)))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_type_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {
|
pub fn node_type_opt(&self, id: HirId) -> Option<Ty<'tcx>> {
|
||||||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||||
self.node_types.get(&id.local_id).cloned()
|
self.node_types.get(&id.local_id).cloned()
|
||||||
}
|
}
|
||||||
@ -342,12 +342,12 @@ impl<'tcx> TypeckResults<'tcx> {
|
|||||||
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_args }
|
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_args }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_args(&self, id: hir::HirId) -> GenericArgsRef<'tcx> {
|
pub fn node_args(&self, id: HirId) -> GenericArgsRef<'tcx> {
|
||||||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||||
self.node_args.get(&id.local_id).cloned().unwrap_or_else(|| GenericArgs::empty())
|
self.node_args.get(&id.local_id).cloned().unwrap_or_else(|| GenericArgs::empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_args_opt(&self, id: hir::HirId) -> Option<GenericArgsRef<'tcx>> {
|
pub fn node_args_opt(&self, id: HirId) -> Option<GenericArgsRef<'tcx>> {
|
||||||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||||
self.node_args.get(&id.local_id).cloned()
|
self.node_args.get(&id.local_id).cloned()
|
||||||
}
|
}
|
||||||
@ -512,7 +512,7 @@ impl<'tcx> TypeckResults<'tcx> {
|
|||||||
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.fru_field_types }
|
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.fru_field_types }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_coercion_cast(&self, hir_id: hir::HirId) -> bool {
|
pub fn is_coercion_cast(&self, hir_id: HirId) -> bool {
|
||||||
validate_hir_id_for_typeck_results(self.hir_owner, hir_id);
|
validate_hir_id_for_typeck_results(self.hir_owner, hir_id);
|
||||||
self.coercion_casts.contains(&hir_id.local_id)
|
self.coercion_casts.contains(&hir_id.local_id)
|
||||||
}
|
}
|
||||||
@ -546,7 +546,7 @@ impl<'tcx> TypeckResults<'tcx> {
|
|||||||
/// would result in lookup errors, or worse, in silently wrong data being
|
/// would result in lookup errors, or worse, in silently wrong data being
|
||||||
/// stored/returned.
|
/// stored/returned.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
|
fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: HirId) {
|
||||||
if hir_id.owner != hir_owner {
|
if hir_id.owner != hir_owner {
|
||||||
invalid_hir_id_for_typeck_results(hir_owner, hir_id);
|
invalid_hir_id_for_typeck_results(hir_owner, hir_id);
|
||||||
}
|
}
|
||||||
@ -554,7 +554,7 @@ fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
|
|||||||
|
|
||||||
#[cold]
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn invalid_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) {
|
fn invalid_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: HirId) {
|
||||||
ty::tls::with(|tcx| {
|
ty::tls::with(|tcx| {
|
||||||
bug!(
|
bug!(
|
||||||
"node {} cannot be placed in TypeckResults with hir_owner {:?}",
|
"node {} cannot be placed in TypeckResults with hir_owner {:?}",
|
||||||
@ -570,12 +570,12 @@ pub struct LocalTableInContext<'a, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, V> LocalTableInContext<'a, V> {
|
impl<'a, V> LocalTableInContext<'a, V> {
|
||||||
pub fn contains_key(&self, id: hir::HirId) -> bool {
|
pub fn contains_key(&self, id: HirId) -> bool {
|
||||||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||||
self.data.contains_key(&id.local_id)
|
self.data.contains_key(&id.local_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, id: hir::HirId) -> Option<&'a V> {
|
pub fn get(&self, id: HirId) -> Option<&'a V> {
|
||||||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||||
self.data.get(&id.local_id)
|
self.data.get(&id.local_id)
|
||||||
}
|
}
|
||||||
@ -592,10 +592,10 @@ impl<'a, V> LocalTableInContext<'a, V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, V> ::std::ops::Index<hir::HirId> for LocalTableInContext<'a, V> {
|
impl<'a, V> ::std::ops::Index<HirId> for LocalTableInContext<'a, V> {
|
||||||
type Output = V;
|
type Output = V;
|
||||||
|
|
||||||
fn index(&self, key: hir::HirId) -> &V {
|
fn index(&self, key: HirId) -> &V {
|
||||||
self.get(key).expect("LocalTableInContext: key not found")
|
self.get(key).expect("LocalTableInContext: key not found")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -606,35 +606,32 @@ pub struct LocalTableInContextMut<'a, V> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, V> LocalTableInContextMut<'a, V> {
|
impl<'a, V> LocalTableInContextMut<'a, V> {
|
||||||
pub fn get_mut(&mut self, id: hir::HirId) -> Option<&mut V> {
|
pub fn get_mut(&mut self, id: HirId) -> Option<&mut V> {
|
||||||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||||
self.data.get_mut(&id.local_id)
|
self.data.get_mut(&id.local_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&mut self, id: hir::HirId) -> Option<&V> {
|
pub fn get(&mut self, id: HirId) -> Option<&V> {
|
||||||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||||
self.data.get(&id.local_id)
|
self.data.get(&id.local_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn entry(&mut self, id: hir::HirId) -> Entry<'_, hir::ItemLocalId, V> {
|
pub fn entry(&mut self, id: HirId) -> Entry<'_, hir::ItemLocalId, V> {
|
||||||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||||
self.data.entry(id.local_id)
|
self.data.entry(id.local_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, id: hir::HirId, val: V) -> Option<V> {
|
pub fn insert(&mut self, id: HirId, val: V) -> Option<V> {
|
||||||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||||
self.data.insert(id.local_id, val)
|
self.data.insert(id.local_id, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&mut self, id: hir::HirId) -> Option<V> {
|
pub fn remove(&mut self, id: HirId) -> Option<V> {
|
||||||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||||
self.data.remove(&id.local_id)
|
self.data.remove(&id.local_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extend(
|
pub fn extend(&mut self, items: UnordItems<(HirId, V), impl Iterator<Item = (HirId, V)>>) {
|
||||||
&mut self,
|
|
||||||
items: UnordItems<(hir::HirId, V), impl Iterator<Item = (hir::HirId, V)>>,
|
|
||||||
) {
|
|
||||||
self.data.extend_unord(items.map(|(id, value)| {
|
self.data.extend_unord(items.map(|(id, value)| {
|
||||||
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
validate_hir_id_for_typeck_results(self.hir_owner, id);
|
||||||
(id.local_id, value)
|
(id.local_id, value)
|
||||||
|
@ -9,7 +9,7 @@ use rustc_data_structures::sorted_map::SortedIndexMultiMap;
|
|||||||
use rustc_errors::ErrorGuaranteed;
|
use rustc_errors::ErrorGuaranteed;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_hir::{self as hir, BindingAnnotation, ByRef, Node};
|
use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId, Node};
|
||||||
use rustc_index::bit_set::GrowableBitSet;
|
use rustc_index::bit_set::GrowableBitSet;
|
||||||
use rustc_index::{Idx, IndexSlice, IndexVec};
|
use rustc_index::{Idx, IndexSlice, IndexVec};
|
||||||
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
||||||
@ -158,7 +158,7 @@ struct Builder<'a, 'tcx> {
|
|||||||
cfg: CFG<'tcx>,
|
cfg: CFG<'tcx>,
|
||||||
|
|
||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
parent_module: DefId,
|
parent_module: DefId,
|
||||||
check_overflow: bool,
|
check_overflow: bool,
|
||||||
fn_span: Span,
|
fn_span: Span,
|
||||||
@ -222,7 +222,7 @@ struct Builder<'a, 'tcx> {
|
|||||||
coverage_branch_info: Option<coverageinfo::BranchInfoBuilder>,
|
coverage_branch_info: Option<coverageinfo::BranchInfoBuilder>,
|
||||||
}
|
}
|
||||||
|
|
||||||
type CaptureMap<'tcx> = SortedIndexMultiMap<usize, hir::HirId, Capture<'tcx>>;
|
type CaptureMap<'tcx> = SortedIndexMultiMap<usize, HirId, Capture<'tcx>>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Capture<'tcx> {
|
struct Capture<'tcx> {
|
||||||
@ -721,7 +721,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
thir: &'a Thir<'tcx>,
|
thir: &'a Thir<'tcx>,
|
||||||
infcx: InferCtxt<'tcx>,
|
infcx: InferCtxt<'tcx>,
|
||||||
def: LocalDefId,
|
def: LocalDefId,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
arg_count: usize,
|
arg_count: usize,
|
||||||
return_ty: Ty<'tcx>,
|
return_ty: Ty<'tcx>,
|
||||||
@ -981,7 +981,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
|
|
||||||
fn set_correct_source_scope_for_arg(
|
fn set_correct_source_scope_for_arg(
|
||||||
&mut self,
|
&mut self,
|
||||||
arg_hir_id: hir::HirId,
|
arg_hir_id: HirId,
|
||||||
original_source_scope: SourceScope,
|
original_source_scope: SourceScope,
|
||||||
pattern_span: Span,
|
pattern_span: Span,
|
||||||
) {
|
) {
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
use crate::build::ExprCategory;
|
use crate::build::ExprCategory;
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
|
|
||||||
use rustc_errors::DiagArgValue;
|
use rustc_errors::DiagArgValue;
|
||||||
use rustc_hir::{self as hir, BindingAnnotation, ByRef, Mutability};
|
use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId, Mutability};
|
||||||
use rustc_middle::mir::BorrowKind;
|
use rustc_middle::mir::BorrowKind;
|
||||||
use rustc_middle::thir::visit::Visitor;
|
use rustc_middle::thir::visit::Visitor;
|
||||||
use rustc_middle::thir::*;
|
use rustc_middle::thir::*;
|
||||||
@ -16,6 +14,7 @@ use rustc_span::def_id::{DefId, LocalDefId};
|
|||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
use rustc_span::{sym, Span};
|
use rustc_span::{sym, Span};
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::Bound;
|
use std::ops::Bound;
|
||||||
|
|
||||||
@ -24,7 +23,7 @@ struct UnsafetyVisitor<'a, 'tcx> {
|
|||||||
thir: &'a Thir<'tcx>,
|
thir: &'a Thir<'tcx>,
|
||||||
/// The `HirId` of the current scope, which would be the `HirId`
|
/// The `HirId` of the current scope, which would be the `HirId`
|
||||||
/// of the current HIR node, modulo adjustments. Used for lint levels.
|
/// of the current HIR node, modulo adjustments. Used for lint levels.
|
||||||
hir_context: hir::HirId,
|
hir_context: HirId,
|
||||||
/// The current "safety context". This notably tracks whether we are in an
|
/// The current "safety context". This notably tracks whether we are in an
|
||||||
/// `unsafe` block, and whether it has been used.
|
/// `unsafe` block, and whether it has been used.
|
||||||
safety_context: SafetyContext,
|
safety_context: SafetyContext,
|
||||||
@ -123,7 +122,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
|
|||||||
|
|
||||||
fn warn_unused_unsafe(
|
fn warn_unused_unsafe(
|
||||||
&mut self,
|
&mut self,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
block_span: Span,
|
block_span: Span,
|
||||||
enclosing_unsafe: Option<UnusedUnsafeEnclosing>,
|
enclosing_unsafe: Option<UnusedUnsafeEnclosing>,
|
||||||
) {
|
) {
|
||||||
@ -537,22 +536,17 @@ enum SafetyContext {
|
|||||||
Safe,
|
Safe,
|
||||||
BuiltinUnsafeBlock,
|
BuiltinUnsafeBlock,
|
||||||
UnsafeFn,
|
UnsafeFn,
|
||||||
UnsafeBlock {
|
UnsafeBlock { span: Span, hir_id: HirId, used: bool, nested_used_blocks: Vec<NestedUsedBlock> },
|
||||||
span: Span,
|
|
||||||
hir_id: hir::HirId,
|
|
||||||
used: bool,
|
|
||||||
nested_used_blocks: Vec<NestedUsedBlock>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
struct NestedUsedBlock {
|
struct NestedUsedBlock {
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UnusedUnsafeWarning {
|
struct UnusedUnsafeWarning {
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
block_span: Span,
|
block_span: Span,
|
||||||
enclosing_unsafe: Option<UnusedUnsafeEnclosing>,
|
enclosing_unsafe: Option<UnusedUnsafeEnclosing>,
|
||||||
}
|
}
|
||||||
@ -585,7 +579,7 @@ impl UnsafeOpKind {
|
|||||||
pub fn emit_unsafe_op_in_unsafe_fn_lint(
|
pub fn emit_unsafe_op_in_unsafe_fn_lint(
|
||||||
&self,
|
&self,
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
hir_id: hir::HirId,
|
hir_id: HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
suggest_unsafe_block: bool,
|
suggest_unsafe_block: bool,
|
||||||
) {
|
) {
|
||||||
@ -726,7 +720,7 @@ impl UnsafeOpKind {
|
|||||||
&self,
|
&self,
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
hir_context: hir::HirId,
|
hir_context: HirId,
|
||||||
unsafe_op_in_unsafe_fn_allowed: bool,
|
unsafe_op_in_unsafe_fn_allowed: bool,
|
||||||
) {
|
) {
|
||||||
let note_non_inherited = tcx.hir().parent_iter(hir_context).find(|(id, node)| {
|
let note_non_inherited = tcx.hir().parent_iter(hir_context).find(|(id, node)| {
|
||||||
|
@ -1202,7 +1202,7 @@ impl<'tcx> VnState<'_, 'tcx> {
|
|||||||
// not give the same value as the former mention.
|
// not give the same value as the former mention.
|
||||||
&& value.is_deterministic()
|
&& value.is_deterministic()
|
||||||
{
|
{
|
||||||
return Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_: value });
|
return Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_: value });
|
||||||
}
|
}
|
||||||
|
|
||||||
let op = self.evaluated[index].as_ref()?;
|
let op = self.evaluated[index].as_ref()?;
|
||||||
@ -1219,7 +1219,7 @@ impl<'tcx> VnState<'_, 'tcx> {
|
|||||||
assert!(!value.may_have_provenance(self.tcx, op.layout.size));
|
assert!(!value.may_have_provenance(self.tcx, op.layout.size));
|
||||||
|
|
||||||
let const_ = Const::Val(value, op.layout.ty);
|
let const_ = Const::Val(value, op.layout.ty);
|
||||||
Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_ })
|
Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_ })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If there is a local which is assigned `index`, and its assignment strictly dominates `loc`,
|
/// If there is a local which is assigned `index`, and its assignment strictly dominates `loc`,
|
||||||
|
@ -1968,11 +1968,8 @@ impl<'a> Parser<'a> {
|
|||||||
} else if matches!(is_raw, IdentIsRaw::No) && ident.is_reserved() {
|
} else if matches!(is_raw, IdentIsRaw::No) && ident.is_reserved() {
|
||||||
let snapshot = self.create_snapshot_for_diagnostic();
|
let snapshot = self.create_snapshot_for_diagnostic();
|
||||||
let err = if self.check_fn_front_matter(false, Case::Sensitive) {
|
let err = if self.check_fn_front_matter(false, Case::Sensitive) {
|
||||||
let inherited_vis = Visibility {
|
let inherited_vis =
|
||||||
span: rustc_span::DUMMY_SP,
|
Visibility { span: DUMMY_SP, kind: VisibilityKind::Inherited, tokens: None };
|
||||||
kind: VisibilityKind::Inherited,
|
|
||||||
tokens: None,
|
|
||||||
};
|
|
||||||
// We use `parse_fn` to get a span for the function
|
// We use `parse_fn` to get a span for the function
|
||||||
let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true };
|
let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true };
|
||||||
match self.parse_fn(
|
match self.parse_fn(
|
||||||
|
@ -389,7 +389,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
|||||||
hir_visit::walk_fn(self, fk, fd, b, id)
|
hir_visit::walk_fn(self, fk, fd, b, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_use(&mut self, p: &'v hir::UsePath<'v>, hir_id: hir::HirId) {
|
fn visit_use(&mut self, p: &'v hir::UsePath<'v>, hir_id: HirId) {
|
||||||
// This is `visit_use`, but the type is `Path` so record it that way.
|
// This is `visit_use`, but the type is `Path` so record it that way.
|
||||||
self.record("Path", Id::None, p);
|
self.record("Path", Id::None, p);
|
||||||
hir_visit::walk_use(self, p, hir_id)
|
hir_visit::walk_use(self, p, hir_id)
|
||||||
@ -462,7 +462,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
|||||||
hir_visit::walk_lifetime(self, lifetime)
|
hir_visit::walk_lifetime(self, lifetime)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path(&mut self, path: &hir::Path<'v>, _id: hir::HirId) {
|
fn visit_path(&mut self, path: &hir::Path<'v>, _id: HirId) {
|
||||||
self.record("Path", Id::None, path);
|
self.record("Path", Id::None, path);
|
||||||
hir_visit::walk_path(self, path)
|
hir_visit::walk_path(self, path)
|
||||||
}
|
}
|
||||||
|
@ -602,7 +602,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||||||
String::from_utf8(wr).unwrap()
|
String::from_utf8(wr).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log_liveness(&self, entry_ln: LiveNode, hir_id: hir::HirId) {
|
fn log_liveness(&self, entry_ln: LiveNode, hir_id: HirId) {
|
||||||
// hack to skip the loop unless debug! is enabled:
|
// hack to skip the loop unless debug! is enabled:
|
||||||
debug!(
|
debug!(
|
||||||
"^^ liveness computation results for body {} (entry={:?})",
|
"^^ liveness computation results for body {} (entry={:?})",
|
||||||
|
@ -5,7 +5,7 @@ use rustc_hir as hir;
|
|||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
|
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_hir::{ExprKind, InlineAsmOperand, StmtKind};
|
use rustc_hir::{ExprKind, HirIdSet, InlineAsmOperand, StmtKind};
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::lint::builtin::UNDEFINED_NAKED_FUNCTION_ABI;
|
use rustc_session::lint::builtin::UNDEFINED_NAKED_FUNCTION_ABI;
|
||||||
@ -94,7 +94,7 @@ fn check_no_patterns(tcx: TyCtxt<'_>, params: &[hir::Param<'_>]) {
|
|||||||
|
|
||||||
/// Checks that function parameters aren't used in the function body.
|
/// Checks that function parameters aren't used in the function body.
|
||||||
fn check_no_parameters_use<'tcx>(tcx: TyCtxt<'tcx>, body: &'tcx hir::Body<'tcx>) {
|
fn check_no_parameters_use<'tcx>(tcx: TyCtxt<'tcx>, body: &'tcx hir::Body<'tcx>) {
|
||||||
let mut params = hir::HirIdSet::default();
|
let mut params = HirIdSet::default();
|
||||||
for param in body.params {
|
for param in body.params {
|
||||||
param.pat.each_binding(|_binding_mode, hir_id, _span, _ident| {
|
param.pat.each_binding(|_binding_mode, hir_id, _span, _ident| {
|
||||||
params.insert(hir_id);
|
params.insert(hir_id);
|
||||||
@ -105,7 +105,7 @@ fn check_no_parameters_use<'tcx>(tcx: TyCtxt<'tcx>, body: &'tcx hir::Body<'tcx>)
|
|||||||
|
|
||||||
struct CheckParameters<'tcx> {
|
struct CheckParameters<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
params: hir::HirIdSet,
|
params: HirIdSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Visitor<'tcx> for CheckParameters<'tcx> {
|
impl<'tcx> Visitor<'tcx> for CheckParameters<'tcx> {
|
||||||
|
@ -66,7 +66,7 @@ impl CaptureCollector<'_, '_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Visitor<'tcx> for CaptureCollector<'_, 'tcx> {
|
impl<'tcx> Visitor<'tcx> for CaptureCollector<'_, 'tcx> {
|
||||||
fn visit_path(&mut self, path: &hir::Path<'tcx>, _: hir::HirId) {
|
fn visit_path(&mut self, path: &hir::Path<'tcx>, _: HirId) {
|
||||||
if let Res::Local(var_id) = path.res {
|
if let Res::Local(var_id) = path.res {
|
||||||
self.visit_local_use(var_id, path.span);
|
self.visit_local_use(var_id, path.span);
|
||||||
}
|
}
|
||||||
|
@ -8,15 +8,14 @@
|
|||||||
//! In this case we try to build an abstract representation of this constant using
|
//! In this case we try to build an abstract representation of this constant using
|
||||||
//! `thir_abstract_const` which can then be checked for structural equality with other
|
//! `thir_abstract_const` which can then be checked for structural equality with other
|
||||||
//! generic constants mentioned in the `caller_bounds` of the current environment.
|
//! generic constants mentioned in the `caller_bounds` of the current environment.
|
||||||
|
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
use rustc_infer::infer::InferCtxt;
|
use rustc_infer::infer::InferCtxt;
|
||||||
use rustc_middle::mir::interpret::ErrorHandled;
|
use rustc_middle::mir::interpret::ErrorHandled;
|
||||||
|
|
||||||
use rustc_middle::traits::ObligationCause;
|
use rustc_middle::traits::ObligationCause;
|
||||||
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
|
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
|
||||||
use rustc_middle::ty::{self, TyCtxt, TypeVisitable, TypeVisitableExt, TypeVisitor};
|
use rustc_middle::ty::{self, TyCtxt, TypeVisitable, TypeVisitableExt, TypeVisitor};
|
||||||
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
use rustc_span::Span;
|
|
||||||
|
|
||||||
use crate::traits::ObligationCtxt;
|
use crate::traits::ObligationCtxt;
|
||||||
|
|
||||||
@ -116,12 +115,12 @@ pub fn is_const_evaluatable<'tcx>(
|
|||||||
tcx.dcx()
|
tcx.dcx()
|
||||||
.struct_span_fatal(
|
.struct_span_fatal(
|
||||||
// Slightly better span than just using `span` alone
|
// Slightly better span than just using `span` alone
|
||||||
if span == rustc_span::DUMMY_SP { tcx.def_span(uv.def) } else { span },
|
if span == DUMMY_SP { tcx.def_span(uv.def) } else { span },
|
||||||
"failed to evaluate generic const expression",
|
"failed to evaluate generic const expression",
|
||||||
)
|
)
|
||||||
.with_note("the crate this constant originates from uses `#![feature(generic_const_exprs)]`")
|
.with_note("the crate this constant originates from uses `#![feature(generic_const_exprs)]`")
|
||||||
.with_span_suggestion_verbose(
|
.with_span_suggestion_verbose(
|
||||||
rustc_span::DUMMY_SP,
|
DUMMY_SP,
|
||||||
"consider enabling this feature",
|
"consider enabling this feature",
|
||||||
"#![feature(generic_const_exprs)]\n",
|
"#![feature(generic_const_exprs)]\n",
|
||||||
rustc_errors::Applicability::MaybeIncorrect,
|
rustc_errors::Applicability::MaybeIncorrect,
|
||||||
|
@ -4251,7 +4251,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
type_diffs: &[TypeError<'tcx>],
|
type_diffs: &[TypeError<'tcx>],
|
||||||
span: Span,
|
span: Span,
|
||||||
prev_ty: Ty<'tcx>,
|
prev_ty: Ty<'tcx>,
|
||||||
body_id: hir::HirId,
|
body_id: HirId,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
) -> Vec<Option<(Span, (DefId, Ty<'tcx>))>> {
|
) -> Vec<Option<(Span, (DefId, Ty<'tcx>))>> {
|
||||||
let ocx = ObligationCtxt::new(self.infcx);
|
let ocx = ObligationCtxt::new(self.infcx);
|
||||||
@ -4764,7 +4764,7 @@ impl<'v> Visitor<'v> for ReturnsVisitor<'v> {
|
|||||||
/// Collect all the awaited expressions within the input expression.
|
/// Collect all the awaited expressions within the input expression.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct AwaitsVisitor {
|
struct AwaitsVisitor {
|
||||||
awaits: Vec<hir::HirId>,
|
awaits: Vec<HirId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'v> Visitor<'v> for AwaitsVisitor {
|
impl<'v> Visitor<'v> for AwaitsVisitor {
|
||||||
|
@ -408,7 +408,7 @@ impl Item {
|
|||||||
|
|
||||||
pub(crate) fn attr_span(&self, tcx: TyCtxt<'_>) -> rustc_span::Span {
|
pub(crate) fn attr_span(&self, tcx: TyCtxt<'_>) -> rustc_span::Span {
|
||||||
span_of_fragments(&self.attrs.doc_strings)
|
span_of_fragments(&self.attrs.doc_strings)
|
||||||
.unwrap_or_else(|| self.span(tcx).map_or(rustc_span::DUMMY_SP, |span| span.inner()))
|
.unwrap_or_else(|| self.span(tcx).map_or(DUMMY_SP, |span| span.inner()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Combine all doc strings into a single value handling indentation and newlines as needed.
|
/// Combine all doc strings into a single value handling indentation and newlines as needed.
|
||||||
|
@ -56,7 +56,7 @@ use rustc_middle::ty::{self, TyCtxt};
|
|||||||
use rustc_session::RustcVersion;
|
use rustc_session::RustcVersion;
|
||||||
use rustc_span::{
|
use rustc_span::{
|
||||||
symbol::{sym, Symbol},
|
symbol::{sym, Symbol},
|
||||||
BytePos, FileName, RealFileName,
|
BytePos, FileName, RealFileName, DUMMY_SP,
|
||||||
};
|
};
|
||||||
use serde::ser::SerializeMap;
|
use serde::ser::SerializeMap;
|
||||||
use serde::{Serialize, Serializer};
|
use serde::{Serialize, Serializer};
|
||||||
@ -2414,7 +2414,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
|
|||||||
let contents = match fs::read_to_string(&path) {
|
let contents = match fs::read_to_string(&path) {
|
||||||
Ok(contents) => contents,
|
Ok(contents) => contents,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
let span = item.span(tcx).map_or(rustc_span::DUMMY_SP, |span| span.inner());
|
let span = item.span(tcx).map_or(DUMMY_SP, |span| span.inner());
|
||||||
tcx.dcx().span_err(span, format!("failed to read file {}: {err}", path.display()));
|
tcx.dcx().span_err(span, format!("failed to read file {}: {err}", path.display()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2495,7 +2495,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
|
|||||||
file.start_pos + BytePos(byte_max),
|
file.start_pos + BytePos(byte_max),
|
||||||
))
|
))
|
||||||
})()
|
})()
|
||||||
.unwrap_or(rustc_span::DUMMY_SP);
|
.unwrap_or(DUMMY_SP);
|
||||||
|
|
||||||
let mut decoration_info = FxHashMap::default();
|
let mut decoration_info = FxHashMap::default();
|
||||||
decoration_info.insert("highlight focus", vec![byte_ranges.remove(0)]);
|
decoration_info.insert("highlight focus", vec![byte_ranges.remove(0)]);
|
||||||
|
@ -3,8 +3,7 @@ use askama::Template;
|
|||||||
use rustc_data_structures::captures::Captures;
|
use rustc_data_structures::captures::Captures;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_middle::span_bug;
|
use rustc_middle::span_bug;
|
||||||
use rustc_middle::ty::layout::LayoutError;
|
use rustc_middle::ty::{self, layout::LayoutError};
|
||||||
use rustc_middle::ty::Adt;
|
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
use rustc_target::abi::{Primitive, TagEncoding, Variants};
|
use rustc_target::abi::{Primitive, TagEncoding, Variants};
|
||||||
|
|
||||||
@ -57,7 +56,7 @@ pub(crate) fn document_type_layout<'a, 'cx: 'a>(
|
|||||||
variants
|
variants
|
||||||
.iter_enumerated()
|
.iter_enumerated()
|
||||||
.map(|(variant_idx, variant_layout)| {
|
.map(|(variant_idx, variant_layout)| {
|
||||||
let Adt(adt, _) = type_layout.ty.kind() else {
|
let ty::Adt(adt, _) = type_layout.ty.kind() else {
|
||||||
span_bug!(tcx.def_span(ty_def_id), "not an adt")
|
span_bug!(tcx.def_span(ty_def_id), "not an adt")
|
||||||
};
|
};
|
||||||
let name = adt.variant(variant_idx).name;
|
let name = adt.variant(variant_idx).name;
|
||||||
|
@ -9,7 +9,7 @@ use rustc_hir::{
|
|||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
|
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
|
||||||
use rustc_middle::ty::{self, Adt, AdtDef, GenericArgsRef, Ty, TypeckResults};
|
use rustc_middle::ty::{self, AdtDef, GenericArgsRef, Ty, TypeckResults};
|
||||||
use rustc_session::impl_lint_pass;
|
use rustc_session::impl_lint_pass;
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ fn is_path_self(e: &Expr<'_>) -> bool {
|
|||||||
fn contains_trait_object(ty: Ty<'_>) -> bool {
|
fn contains_trait_object(ty: Ty<'_>) -> bool {
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Ref(_, ty, _) => contains_trait_object(*ty),
|
ty::Ref(_, ty, _) => contains_trait_object(*ty),
|
||||||
Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object),
|
ty::Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object),
|
||||||
ty::Dynamic(..) => true,
|
ty::Dynamic(..) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
|
|||||||
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
|
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
|
||||||
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
|
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
|
||||||
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
|
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
|
||||||
&& let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
|
&& let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
|
||||||
&& let attrs = cx.tcx.hir().attrs(item.hir_id())
|
&& let attrs = cx.tcx.hir().attrs(item.hir_id())
|
||||||
&& !attrs.iter().any(|attr| attr.doc_str().is_some())
|
&& !attrs.iter().any(|attr| attr.doc_str().is_some())
|
||||||
&& cx.tcx.hir().attrs(impl_item_hir).is_empty()
|
&& cx.tcx.hir().attrs(impl_item_hir).is_empty()
|
||||||
|
@ -4,7 +4,7 @@ use clippy_utils::ty::is_c_void;
|
|||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::{Expr, ExprKind, QPath};
|
use rustc_hir::{Expr, ExprKind, QPath};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::RawPtr;
|
use rustc_middle::ty;
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ impl LateLintPass<'_> for FromRawWithVoidPtr {
|
|||||||
&& seg.ident.name == sym!(from_raw)
|
&& seg.ident.name == sym!(from_raw)
|
||||||
&& let Some(type_str) = path_def_id(cx, ty).and_then(|id| def_id_matches_type(cx, id))
|
&& let Some(type_str) = path_def_id(cx, ty).and_then(|id| def_id_matches_type(cx, id))
|
||||||
&& let arg_kind = cx.typeck_results().expr_ty(arg).kind()
|
&& let arg_kind = cx.typeck_results().expr_ty(arg).kind()
|
||||||
&& let RawPtr(ty, _) = arg_kind
|
&& let ty::RawPtr(ty, _) = arg_kind
|
||||||
&& is_c_void(cx, *ty)
|
&& is_c_void(cx, *ty)
|
||||||
{
|
{
|
||||||
let msg = format!("creating a `{type_str}` from a void raw pointer");
|
let msg = format!("creating a `{type_str}` from a void raw pointer");
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use rustc_hir::{self as hir, intravisit, HirIdSet};
|
use rustc_hir::{self as hir, intravisit, HirId, HirIdSet};
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::LocalDefId;
|
||||||
@ -74,7 +74,7 @@ fn check_raw_ptr<'tcx>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<hir::HirId> {
|
fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<HirId> {
|
||||||
if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = (
|
if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = (
|
||||||
&arg.pat.kind,
|
&arg.pat.kind,
|
||||||
cx.maybe_typeck_results()
|
cx.maybe_typeck_results()
|
||||||
|
@ -2,7 +2,7 @@ use rustc_errors::Diag;
|
|||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_lint::{LateContext, LintContext};
|
use rustc_lint::{LateContext, LintContext};
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_middle::ty::{Adt, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_span::{sym, Span};
|
use rustc_span::{sym, Span};
|
||||||
|
|
||||||
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
|
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
|
||||||
@ -25,7 +25,7 @@ fn result_err_ty<'tcx>(
|
|||||||
.tcx
|
.tcx
|
||||||
.instantiate_bound_regions_with_erased(cx.tcx.fn_sig(id).instantiate_identity().output())
|
.instantiate_bound_regions_with_erased(cx.tcx.fn_sig(id).instantiate_identity().output())
|
||||||
&& is_type_diagnostic_item(cx, ty, sym::Result)
|
&& is_type_diagnostic_item(cx, ty, sym::Result)
|
||||||
&& let Adt(_, args) = ty.kind()
|
&& let ty::Adt(_, args) = ty.kind()
|
||||||
{
|
{
|
||||||
let err_ty = args.type_at(1);
|
let err_ty = args.type_at(1);
|
||||||
Some((hir_ty, err_ty))
|
Some((hir_ty, err_ty))
|
||||||
@ -86,7 +86,7 @@ fn check_result_unit_err(cx: &LateContext<'_>, err_ty: Ty<'_>, fn_header_span: S
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty_span: Span, large_err_threshold: u64) {
|
fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty_span: Span, large_err_threshold: u64) {
|
||||||
if let Adt(adt, subst) = err_ty.kind()
|
if let ty::Adt(adt, subst) = err_ty.kind()
|
||||||
&& let Some(local_def_id) = err_ty
|
&& let Some(local_def_id) = err_ty
|
||||||
.ty_adt_def()
|
.ty_adt_def()
|
||||||
.expect("already checked this is adt")
|
.expect("already checked this is adt")
|
||||||
|
@ -7,7 +7,7 @@ use rustc_data_structures::packed::Pu128;
|
|||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
|
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::{Int, IntTy, Ty, Uint, UintTy};
|
use rustc_middle::ty::{IntTy, Ty, UintTy};
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
@ -97,6 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_int_max(ty: Ty<'_>) -> Option<u128> {
|
fn get_int_max(ty: Ty<'_>) -> Option<u128> {
|
||||||
|
use rustc_middle::ty::{Int, Uint};
|
||||||
match ty.peel_refs().kind() {
|
match ty.peel_refs().kind() {
|
||||||
Int(IntTy::I8) => i8::MAX.try_into().ok(),
|
Int(IntTy::I8) => i8::MAX.try_into().ok(),
|
||||||
Int(IntTy::I16) => i16::MAX.try_into().ok(),
|
Int(IntTy::I16) => i16::MAX.try_into().ok(),
|
||||||
|
@ -7,6 +7,7 @@ use clippy_utils::{is_expn_of, is_lint_allowed, path_to_local};
|
|||||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
use rustc_hir::HirId;
|
||||||
use rustc_hir::intravisit::{self, Visitor};
|
use rustc_hir::intravisit::{self, Visitor};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::nested_filter;
|
use rustc_middle::hir::nested_filter;
|
||||||
@ -87,9 +88,9 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice {
|
|||||||
extract_msrv_attr!(LateContext);
|
extract_msrv_attr!(LateContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<hir::HirId, SliceLintInformation> {
|
fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<HirId, SliceLintInformation> {
|
||||||
let mut removed_pat: FxHashSet<hir::HirId> = FxHashSet::default();
|
let mut removed_pat: FxHashSet<HirId> = FxHashSet::default();
|
||||||
let mut slices: FxIndexMap<hir::HirId, SliceLintInformation> = FxIndexMap::default();
|
let mut slices: FxIndexMap<HirId, SliceLintInformation> = FxIndexMap::default();
|
||||||
pat.walk_always(|pat| {
|
pat.walk_always(|pat| {
|
||||||
// We'll just ignore mut and ref mut for simplicity sake right now
|
// We'll just ignore mut and ref mut for simplicity sake right now
|
||||||
if let hir::PatKind::Binding(
|
if let hir::PatKind::Binding(
|
||||||
@ -206,10 +207,10 @@ impl SliceLintInformation {
|
|||||||
|
|
||||||
fn filter_lintable_slices<'tcx>(
|
fn filter_lintable_slices<'tcx>(
|
||||||
cx: &LateContext<'tcx>,
|
cx: &LateContext<'tcx>,
|
||||||
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>,
|
slice_lint_info: FxIndexMap<HirId, SliceLintInformation>,
|
||||||
max_suggested_slice: u64,
|
max_suggested_slice: u64,
|
||||||
scope: &'tcx hir::Expr<'tcx>,
|
scope: &'tcx hir::Expr<'tcx>,
|
||||||
) -> FxIndexMap<hir::HirId, SliceLintInformation> {
|
) -> FxIndexMap<HirId, SliceLintInformation> {
|
||||||
let mut visitor = SliceIndexLintingVisitor {
|
let mut visitor = SliceIndexLintingVisitor {
|
||||||
cx,
|
cx,
|
||||||
slice_lint_info,
|
slice_lint_info,
|
||||||
@ -223,7 +224,7 @@ fn filter_lintable_slices<'tcx>(
|
|||||||
|
|
||||||
struct SliceIndexLintingVisitor<'a, 'tcx> {
|
struct SliceIndexLintingVisitor<'a, 'tcx> {
|
||||||
cx: &'a LateContext<'tcx>,
|
cx: &'a LateContext<'tcx>,
|
||||||
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>,
|
slice_lint_info: FxIndexMap<HirId, SliceLintInformation>,
|
||||||
max_suggested_slice: u64,
|
max_suggested_slice: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ use rustc_errors::Applicability;
|
|||||||
use rustc_hir::{Item, ItemKind};
|
use rustc_hir::{Item, ItemKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::lint::in_external_macro;
|
use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_middle::ty::{Adt, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_session::impl_lint_pass;
|
use rustc_session::impl_lint_pass;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
|
|||||||
}
|
}
|
||||||
if let ItemKind::Enum(ref def, _) = item.kind {
|
if let ItemKind::Enum(ref def, _) = item.kind {
|
||||||
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||||
let Adt(adt, subst) = ty.kind() else {
|
let ty::Adt(adt, subst) = ty.kind() else {
|
||||||
panic!("already checked whether this is an enum")
|
panic!("already checked whether this is an enum")
|
||||||
};
|
};
|
||||||
if adt.variants().len() <= 1 {
|
if adt.variants().len() <= 1 {
|
||||||
@ -167,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
fn maybe_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
|
||||||
if let Adt(_def, args) = ty.kind()
|
if let ty::Adt(_def, args) = ty.kind()
|
||||||
&& args.types().next().is_some()
|
&& args.types().next().is_some()
|
||||||
&& let Some(copy_trait) = cx.tcx.lang_items().copy_trait()
|
&& let Some(copy_trait) = cx.tcx.lang_items().copy_trait()
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ use rustc_ast::ast::LitKind;
|
|||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{Expr, ExprKind, LangItem};
|
use rustc_hir::{Expr, ExprKind, LangItem};
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::ty::{Ref, Slice};
|
use rustc_middle::ty;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
use super::UNNECESSARY_JOIN;
|
use super::UNNECESSARY_JOIN;
|
||||||
@ -18,9 +18,9 @@ pub(super) fn check<'tcx>(
|
|||||||
) {
|
) {
|
||||||
let applicability = Applicability::MachineApplicable;
|
let applicability = Applicability::MachineApplicable;
|
||||||
let collect_output_adjusted_type = cx.typeck_results().expr_ty_adjusted(join_self_arg);
|
let collect_output_adjusted_type = cx.typeck_results().expr_ty_adjusted(join_self_arg);
|
||||||
if let Ref(_, ref_type, _) = collect_output_adjusted_type.kind()
|
if let ty::Ref(_, ref_type, _) = collect_output_adjusted_type.kind()
|
||||||
// the turbofish for collect is ::<Vec<String>>
|
// the turbofish for collect is ::<Vec<String>>
|
||||||
&& let Slice(slice) = ref_type.kind()
|
&& let ty::Slice(slice) = ref_type.kind()
|
||||||
&& is_type_lang_item(cx, *slice, LangItem::String)
|
&& is_type_lang_item(cx, *slice, LangItem::String)
|
||||||
// the argument for join is ""
|
// the argument for join is ""
|
||||||
&& let ExprKind::Lit(spanned) = &join_arg.kind
|
&& let ExprKind::Lit(spanned) = &join_arg.kind
|
||||||
|
@ -4,7 +4,7 @@ use clippy_utils::{def_path_def_ids, trait_ref_of_method};
|
|||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::{Adt, Ty};
|
use rustc_middle::ty::{self, Ty};
|
||||||
use rustc_session::impl_lint_pass;
|
use rustc_session::impl_lint_pass;
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::LocalDefId;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
@ -153,7 +153,7 @@ impl MutableKeyType {
|
|||||||
// generics (because the compiler cannot ensure immutability for unknown types).
|
// generics (because the compiler cannot ensure immutability for unknown types).
|
||||||
fn check_ty_<'tcx>(&self, cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) {
|
fn check_ty_<'tcx>(&self, cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) {
|
||||||
let ty = ty.peel_refs();
|
let ty = ty.peel_refs();
|
||||||
if let Adt(def, args) = ty.kind() {
|
if let ty::Adt(def, args) = ty.kind() {
|
||||||
let is_keyed_type = [sym::HashMap, sym::BTreeMap, sym::HashSet, sym::BTreeSet]
|
let is_keyed_type = [sym::HashMap, sym::BTreeMap, sym::HashSet, sym::BTreeSet]
|
||||||
.iter()
|
.iter()
|
||||||
.any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did()));
|
.any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did()));
|
||||||
|
@ -18,7 +18,7 @@ use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult, GlobalId};
|
|||||||
use rustc_middle::ty::adjustment::Adjust;
|
use rustc_middle::ty::adjustment::Adjust;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_session::impl_lint_pass;
|
use rustc_session::impl_lint_pass;
|
||||||
use rustc_span::{sym, InnerSpan, Span};
|
use rustc_span::{sym, DUMMY_SP, InnerSpan, Span};
|
||||||
use rustc_target::abi::VariantIdx;
|
use rustc_target::abi::VariantIdx;
|
||||||
|
|
||||||
// FIXME: this is a correctness problem but there's no suitable
|
// FIXME: this is a correctness problem but there's no suitable
|
||||||
@ -290,9 +290,7 @@ impl NonCopyConst {
|
|||||||
promoted: None,
|
promoted: None,
|
||||||
};
|
};
|
||||||
let param_env = cx.tcx.param_env(def_id).with_reveal_all_normalized(cx.tcx);
|
let param_env = cx.tcx.param_env(def_id).with_reveal_all_normalized(cx.tcx);
|
||||||
let result = cx
|
let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, DUMMY_SP);
|
||||||
.tcx
|
|
||||||
.const_eval_global_id_for_typeck(param_env, cid, rustc_span::DUMMY_SP);
|
|
||||||
self.is_value_unfrozen_raw(cx, result, ty)
|
self.is_value_unfrozen_raw(cx, result, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +301,7 @@ impl NonCopyConst {
|
|||||||
cx.tcx,
|
cx.tcx,
|
||||||
cx.param_env,
|
cx.param_env,
|
||||||
ty::UnevaluatedConst::new(def_id, args),
|
ty::UnevaluatedConst::new(def_id, args),
|
||||||
rustc_span::DUMMY_SP,
|
DUMMY_SP,
|
||||||
);
|
);
|
||||||
self.is_value_unfrozen_raw(cx, result, ty)
|
self.is_value_unfrozen_raw(cx, result, ty)
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ use clippy_utils::{binop_traits, eq_expr_value, trait_ref_of_method};
|
|||||||
use core::ops::ControlFlow;
|
use core::ops::ControlFlow;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
use rustc_hir::{HirId, HirIdSet};
|
||||||
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
|
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
|
||||||
use rustc_lint::LateContext;
|
use rustc_lint::LateContext;
|
||||||
use rustc_middle::mir::FakeReadCause;
|
use rustc_middle::mir::FakeReadCause;
|
||||||
@ -98,10 +99,10 @@ pub(super) fn check<'tcx>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet {
|
fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
|
||||||
struct S(hir::HirIdSet);
|
struct S(HirIdSet);
|
||||||
impl Delegate<'_> for S {
|
impl Delegate<'_> for S {
|
||||||
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind) {
|
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) {
|
||||||
if matches!(kind, BorrowKind::ImmBorrow | BorrowKind::UniqueImmBorrow) {
|
if matches!(kind, BorrowKind::ImmBorrow | BorrowKind::UniqueImmBorrow) {
|
||||||
self.0.insert(match place.place.base {
|
self.0.insert(match place.place.base {
|
||||||
PlaceBase::Local(id) => id,
|
PlaceBase::Local(id) => id,
|
||||||
@ -111,13 +112,13 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
|
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||||
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
|
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||||
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: hir::HirId) {}
|
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {}
|
||||||
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
|
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut s = S(hir::HirIdSet::default());
|
let mut s = S(HirIdSet::default());
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
let infcx = cx.tcx.infer_ctxt().build();
|
||||||
let mut v = ExprUseVisitor::new(
|
let mut v = ExprUseVisitor::new(
|
||||||
&mut s,
|
&mut s,
|
||||||
@ -130,10 +131,10 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
|
|||||||
s.0
|
s.0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet {
|
fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
|
||||||
struct S(hir::HirIdSet);
|
struct S(HirIdSet);
|
||||||
impl Delegate<'_> for S {
|
impl Delegate<'_> for S {
|
||||||
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind) {
|
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) {
|
||||||
if matches!(kind, BorrowKind::MutBorrow) {
|
if matches!(kind, BorrowKind::MutBorrow) {
|
||||||
self.0.insert(match place.place.base {
|
self.0.insert(match place.place.base {
|
||||||
PlaceBase::Local(id) => id,
|
PlaceBase::Local(id) => id,
|
||||||
@ -143,13 +144,13 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
|
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||||
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
|
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||||
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: hir::HirId) {}
|
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {}
|
||||||
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
|
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut s = S(hir::HirIdSet::default());
|
let mut s = S(HirIdSet::default());
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
let infcx = cx.tcx.infer_ctxt().build();
|
||||||
let mut v = ExprUseVisitor::new(
|
let mut v = ExprUseVisitor::new(
|
||||||
&mut s,
|
&mut s,
|
||||||
|
@ -8,7 +8,7 @@ use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_i
|
|||||||
use hir::LifetimeName;
|
use hir::LifetimeName;
|
||||||
use rustc_errors::{Applicability, MultiSpan};
|
use rustc_errors::{Applicability, MultiSpan};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::hir_id::HirIdMap;
|
use rustc_hir::hir_id::{HirId, HirIdMap};
|
||||||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg,
|
self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg,
|
||||||
@ -324,7 +324,7 @@ struct PtrArgReplacement {
|
|||||||
|
|
||||||
struct PtrArg<'tcx> {
|
struct PtrArg<'tcx> {
|
||||||
idx: usize,
|
idx: usize,
|
||||||
emission_id: hir::HirId,
|
emission_id: HirId,
|
||||||
span: Span,
|
span: Span,
|
||||||
ty_did: DefId,
|
ty_did: DefId,
|
||||||
ty_name: Symbol,
|
ty_name: Symbol,
|
||||||
|
@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
|||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::intravisit::{walk_expr, Visitor};
|
use rustc_hir::intravisit::{walk_expr, Visitor};
|
||||||
use rustc_hir::{self as hir};
|
use rustc_hir::{self as hir, HirId};
|
||||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
use rustc_middle::ty::{GenericArgKind, Ty};
|
use rustc_middle::ty::{GenericArgKind, Ty};
|
||||||
use rustc_session::impl_lint_pass;
|
use rustc_session::impl_lint_pass;
|
||||||
@ -55,7 +55,7 @@ impl_lint_pass!(SignificantDropTightening<'_> => [SIGNIFICANT_DROP_TIGHTENING]);
|
|||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct SignificantDropTightening<'tcx> {
|
pub struct SignificantDropTightening<'tcx> {
|
||||||
apas: FxIndexMap<hir::HirId, AuxParamsAttr>,
|
apas: FxIndexMap<HirId, AuxParamsAttr>,
|
||||||
/// Auxiliary structure used to avoid having to verify the same type multiple times.
|
/// Auxiliary structure used to avoid having to verify the same type multiple times.
|
||||||
seen_types: FxHashSet<Ty<'tcx>>,
|
seen_types: FxHashSet<Ty<'tcx>>,
|
||||||
type_cache: FxHashMap<Ty<'tcx>, bool>,
|
type_cache: FxHashMap<Ty<'tcx>, bool>,
|
||||||
@ -359,9 +359,9 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o
|
|||||||
/// Auxiliary parameters used on each block check of an item
|
/// Auxiliary parameters used on each block check of an item
|
||||||
struct AuxParams<'others, 'stmt, 'tcx> {
|
struct AuxParams<'others, 'stmt, 'tcx> {
|
||||||
//// See [AuxParamsAttr].
|
//// See [AuxParamsAttr].
|
||||||
apas: &'others mut FxIndexMap<hir::HirId, AuxParamsAttr>,
|
apas: &'others mut FxIndexMap<HirId, AuxParamsAttr>,
|
||||||
/// The current block identifier that is being visited.
|
/// The current block identifier that is being visited.
|
||||||
curr_block_hir_id: hir::HirId,
|
curr_block_hir_id: HirId,
|
||||||
/// The current block span that is being visited.
|
/// The current block span that is being visited.
|
||||||
curr_block_span: Span,
|
curr_block_span: Span,
|
||||||
/// The current statement that is being visited.
|
/// The current statement that is being visited.
|
||||||
@ -369,10 +369,10 @@ struct AuxParams<'others, 'stmt, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'others, 'stmt, 'tcx> AuxParams<'others, 'stmt, 'tcx> {
|
impl<'others, 'stmt, 'tcx> AuxParams<'others, 'stmt, 'tcx> {
|
||||||
fn new(apas: &'others mut FxIndexMap<hir::HirId, AuxParamsAttr>, curr_stmt: &'stmt hir::Stmt<'tcx>) -> Self {
|
fn new(apas: &'others mut FxIndexMap<HirId, AuxParamsAttr>, curr_stmt: &'stmt hir::Stmt<'tcx>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
apas,
|
apas,
|
||||||
curr_block_hir_id: hir::HirId::INVALID,
|
curr_block_hir_id: HirId::INVALID,
|
||||||
curr_block_span: DUMMY_SP,
|
curr_block_span: DUMMY_SP,
|
||||||
curr_stmt: Cow::Borrowed(curr_stmt),
|
curr_stmt: Cow::Borrowed(curr_stmt),
|
||||||
}
|
}
|
||||||
@ -389,7 +389,7 @@ struct AuxParamsAttr {
|
|||||||
has_expensive_expr_after_last_attr: bool,
|
has_expensive_expr_after_last_attr: bool,
|
||||||
|
|
||||||
/// The identifier of the block that involves the first `#[has_significant_drop]`.
|
/// The identifier of the block that involves the first `#[has_significant_drop]`.
|
||||||
first_block_hir_id: hir::HirId,
|
first_block_hir_id: HirId,
|
||||||
/// The span of the block that involves the first `#[has_significant_drop]`.
|
/// The span of the block that involves the first `#[has_significant_drop]`.
|
||||||
first_block_span: Span,
|
first_block_span: Span,
|
||||||
/// The binding or variable that references the initial construction of the type marked with
|
/// The binding or variable that references the initial construction of the type marked with
|
||||||
@ -414,7 +414,7 @@ impl Default for AuxParamsAttr {
|
|||||||
Self {
|
Self {
|
||||||
counter: 0,
|
counter: 0,
|
||||||
has_expensive_expr_after_last_attr: false,
|
has_expensive_expr_after_last_attr: false,
|
||||||
first_block_hir_id: hir::HirId::INVALID,
|
first_block_hir_id: HirId::INVALID,
|
||||||
first_bind_ident: Ident::empty(),
|
first_bind_ident: Ident::empty(),
|
||||||
first_block_span: DUMMY_SP,
|
first_block_span: DUMMY_SP,
|
||||||
first_method_span: DUMMY_SP,
|
first_method_span: DUMMY_SP,
|
||||||
@ -428,7 +428,7 @@ impl Default for AuxParamsAttr {
|
|||||||
|
|
||||||
fn dummy_stmt_expr<'any>(expr: &'any hir::Expr<'any>) -> hir::Stmt<'any> {
|
fn dummy_stmt_expr<'any>(expr: &'any hir::Expr<'any>) -> hir::Stmt<'any> {
|
||||||
hir::Stmt {
|
hir::Stmt {
|
||||||
hir_id: hir::HirId::INVALID,
|
hir_id: HirId::INVALID,
|
||||||
kind: hir::StmtKind::Expr(expr),
|
kind: hir::StmtKind::Expr(expr),
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use rustc_hir::{self as hir, HirId, ItemKind, Node};
|
|||||||
use rustc_hir_analysis::lower_ty;
|
use rustc_hir_analysis::lower_ty;
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::ty::layout::LayoutOf as _;
|
use rustc_middle::ty::layout::LayoutOf as _;
|
||||||
use rustc_middle::ty::{Adt, Ty, TypeVisitableExt};
|
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
||||||
use rustc_session::declare_lint_pass;
|
use rustc_session::declare_lint_pass;
|
||||||
use rustc_span::sym;
|
use rustc_span::sym;
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
|
|||||||
&& !in_trait_impl(cx, hir_ty.hir_id)
|
&& !in_trait_impl(cx, hir_ty.hir_id)
|
||||||
&& let ty = ty_from_hir_ty(cx, hir_ty)
|
&& let ty = ty_from_hir_ty(cx, hir_ty)
|
||||||
&& (is_type_diagnostic_item(cx, ty, sym::HashMap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap))
|
&& (is_type_diagnostic_item(cx, ty, sym::HashMap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap))
|
||||||
&& let Adt(_, args) = ty.kind()
|
&& let ty::Adt(_, args) = ty.kind()
|
||||||
&& let ty = args.type_at(1)
|
&& let ty = args.type_at(1)
|
||||||
// Fixes https://github.com/rust-lang/rust-clippy/issues/7447 because of
|
// Fixes https://github.com/rust-lang/rust-clippy/issues/7447 because of
|
||||||
// https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/sty.rs#L968
|
// https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/sty.rs#L968
|
||||||
|
Loading…
x
Reference in New Issue
Block a user