Auto merge of #134414 - jhpratt:rollup-4gtfd1h, r=jhpratt
Rollup of 10 pull requests Successful merges: - #134202 (Remove `rustc::existing_doc_keyword` lint) - #134354 (Handle fndef rendering together with signature rendering) - #134365 (Rename `rustc_mir_build::build` to `builder`) - #134368 (Use links to edition guide for edition migrations) - #134397 (rustc_borrowck: Suggest changing `&raw const` to `&raw mut` if applicable) - #134398 (AIX: add alignment info for test) - #134400 (Fix some comments related to upvars handling) - #134406 (Fix `-Z input-stats` ordering) - #134409 (bootstrap: fix a comment) - #134412 (small borrowck cleanup) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
f23a80a4c2
121 changed files with 577 additions and 627 deletions
|
@ -1474,16 +1474,27 @@ fn suggest_ampmut<'tcx>(
|
|||
// let x: &i32 = &'a 5;
|
||||
// ^^ lifetime annotation not allowed
|
||||
//
|
||||
if let Some(assignment_rhs_span) = opt_assignment_rhs_span
|
||||
&& let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span)
|
||||
&& let Some(stripped) = src.strip_prefix('&')
|
||||
if let Some(rhs_span) = opt_assignment_rhs_span
|
||||
&& let Ok(rhs_str) = tcx.sess.source_map().span_to_snippet(rhs_span)
|
||||
&& let Some(rhs_str_no_amp) = rhs_str.strip_prefix('&')
|
||||
{
|
||||
let is_raw_ref = stripped.trim_start().starts_with("raw ");
|
||||
// We don't support raw refs yet
|
||||
if is_raw_ref {
|
||||
return None;
|
||||
// Suggest changing `&raw const` to `&raw mut` if applicable.
|
||||
if rhs_str_no_amp.trim_start().strip_prefix("raw const").is_some() {
|
||||
let const_idx = rhs_str.find("const").unwrap() as u32;
|
||||
let const_span = rhs_span
|
||||
.with_lo(rhs_span.lo() + BytePos(const_idx))
|
||||
.with_hi(rhs_span.lo() + BytePos(const_idx + "const".len() as u32));
|
||||
|
||||
return Some(AmpMutSugg {
|
||||
has_sugg: true,
|
||||
span: const_span,
|
||||
suggestion: "mut".to_owned(),
|
||||
additional: None,
|
||||
});
|
||||
}
|
||||
let is_mut = if let Some(rest) = stripped.trim_start().strip_prefix("mut") {
|
||||
|
||||
// Figure out if rhs already is `&mut`.
|
||||
let is_mut = if let Some(rest) = rhs_str_no_amp.trim_start().strip_prefix("mut") {
|
||||
match rest.chars().next() {
|
||||
// e.g. `&mut x`
|
||||
Some(c) if c.is_whitespace() => true,
|
||||
|
@ -1500,9 +1511,8 @@ fn suggest_ampmut<'tcx>(
|
|||
// if the reference is already mutable then there is nothing we can do
|
||||
// here.
|
||||
if !is_mut {
|
||||
let span = assignment_rhs_span;
|
||||
// shrink the span to just after the `&` in `&variable`
|
||||
let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();
|
||||
let span = rhs_span.with_lo(rhs_span.lo() + BytePos(1)).shrink_to_lo();
|
||||
|
||||
// FIXME(Ezrashaw): returning is bad because we still might want to
|
||||
// update the annotated type, see #106857.
|
||||
|
|
|
@ -848,7 +848,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
return;
|
||||
};
|
||||
|
||||
let fn_returns = self.infcx.tcx.return_type_impl_or_dyn_traits(suitable_region.def_id);
|
||||
let fn_returns = self.infcx.tcx.return_type_impl_or_dyn_traits(suitable_region.scope);
|
||||
|
||||
let param = if let Some(param) =
|
||||
find_param_with_region(self.infcx.tcx, self.mir_def_id(), f, outlived_f)
|
||||
|
@ -875,7 +875,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
Some(arg),
|
||||
captures,
|
||||
Some((param.param_ty_span, param.param_ty.to_string())),
|
||||
Some(suitable_region.def_id),
|
||||
Some(suitable_region.scope),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -883,7 +883,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
let Some((alias_tys, alias_span, lt_addition_span)) = self
|
||||
.infcx
|
||||
.tcx
|
||||
.return_type_impl_or_dyn_traits_with_type_alias(suitable_region.def_id)
|
||||
.return_type_impl_or_dyn_traits_with_type_alias(suitable_region.scope)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
@ -1018,18 +1018,20 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
return;
|
||||
};
|
||||
|
||||
let Some((ty_sub, _)) =
|
||||
self.infcx.tcx.is_suitable_region(self.mir_def_id(), sub).and_then(|anon_reg| {
|
||||
find_anon_type(self.infcx.tcx, self.mir_def_id(), sub, &anon_reg.bound_region)
|
||||
})
|
||||
let Some((ty_sub, _)) = self
|
||||
.infcx
|
||||
.tcx
|
||||
.is_suitable_region(self.mir_def_id(), sub)
|
||||
.and_then(|_| find_anon_type(self.infcx.tcx, self.mir_def_id(), sub))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some((ty_sup, _)) =
|
||||
self.infcx.tcx.is_suitable_region(self.mir_def_id(), sup).and_then(|anon_reg| {
|
||||
find_anon_type(self.infcx.tcx, self.mir_def_id(), sup, &anon_reg.bound_region)
|
||||
})
|
||||
let Some((ty_sup, _)) = self
|
||||
.infcx
|
||||
.tcx
|
||||
.is_suitable_region(self.mir_def_id(), sup)
|
||||
.and_then(|_| find_anon_type(self.infcx.tcx, self.mir_def_id(), sup))
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
|
|
@ -141,6 +141,9 @@ fn do_mir_borrowck<'tcx>(
|
|||
) -> (BorrowCheckResult<'tcx>, Option<Box<BodyWithBorrowckFacts<'tcx>>>) {
|
||||
let def = input_body.source.def_id().expect_local();
|
||||
let infcx = BorrowckInferCtxt::new(tcx, def);
|
||||
if let Some(e) = input_body.tainted_by_errors {
|
||||
infcx.set_tainted_by_errors(e);
|
||||
}
|
||||
|
||||
let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
|
||||
for var_debug_info in &input_body.var_debug_info {
|
||||
|
@ -162,13 +165,6 @@ fn do_mir_borrowck<'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
let diags = &mut diags::BorrowckDiags::new();
|
||||
|
||||
// Gather the upvars of a closure, if any.
|
||||
if let Some(e) = input_body.tainted_by_errors {
|
||||
infcx.set_tainted_by_errors(e);
|
||||
}
|
||||
|
||||
// Replace all regions with fresh inference variables. This
|
||||
// requires first making our own copy of the MIR. This copy will
|
||||
// be modified (in place) to contain non-lexical lifetimes. It
|
||||
|
@ -224,6 +220,7 @@ fn do_mir_borrowck<'tcx>(
|
|||
|
||||
// We also have a `#[rustc_regions]` annotation that causes us to dump
|
||||
// information.
|
||||
let diags = &mut diags::BorrowckDiags::new();
|
||||
nll::dump_annotation(&infcx, body, ®ioncx, &opt_closure_req, &opaque_type_values, diags);
|
||||
|
||||
let movable_coroutine =
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
//! to everything owned by `x`, so the result is the same for something
|
||||
//! like `x.f = 5` and so on (presuming `x` is not a borrowed pointer to a
|
||||
//! struct). These adjustments are performed in
|
||||
//! `adjust_upvar_borrow_kind()` (you can trace backwards through the code
|
||||
//! `adjust_for_non_move_closure` (you can trace backwards through the code
|
||||
//! from there).
|
||||
//!
|
||||
//! The fact that we are inferring borrow kinds as we go results in a
|
||||
|
@ -1684,8 +1684,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// want to capture by ref to allow precise capture using reborrows.
|
||||
//
|
||||
// If the data will be moved out of this place, then the place will be truncated
|
||||
// at the first Deref in `adjust_upvar_borrow_kind_for_consume` and then moved into
|
||||
// the closure.
|
||||
// at the first Deref in `adjust_for_move_closure` and then moved into the closure.
|
||||
hir::CaptureBy::Value { .. } if !place.deref_tys().any(Ty::is_ref) => {
|
||||
ty::UpvarCapture::ByValue
|
||||
}
|
||||
|
|
|
@ -689,7 +689,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
/// Require that the region `r` be equal to one of the regions in
|
||||
/// the set `regions`.
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn member_constraint(
|
||||
pub fn add_member_constraint(
|
||||
&self,
|
||||
key: ty::OpaqueTypeKey<'tcx>,
|
||||
definition_span: Span,
|
||||
|
@ -697,7 +697,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
region: ty::Region<'tcx>,
|
||||
in_regions: Lrc<Vec<ty::Region<'tcx>>>,
|
||||
) {
|
||||
self.inner.borrow_mut().unwrap_region_constraints().member_constraint(
|
||||
self.inner.borrow_mut().unwrap_region_constraints().add_member_constraint(
|
||||
key,
|
||||
definition_span,
|
||||
hidden_ty,
|
||||
|
|
|
@ -364,7 +364,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
concrete_ty.visit_with(&mut ConstrainOpaqueTypeRegionVisitor {
|
||||
tcx: self.tcx,
|
||||
op: |r| {
|
||||
self.member_constraint(
|
||||
self.add_member_constraint(
|
||||
opaque_type_key,
|
||||
span,
|
||||
concrete_ty,
|
||||
|
|
|
@ -466,7 +466,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn member_constraint(
|
||||
pub(super) fn add_member_constraint(
|
||||
&mut self,
|
||||
key: ty::OpaqueTypeKey<'tcx>,
|
||||
definition_span: Span,
|
||||
|
|
|
@ -536,9 +536,6 @@ lint_non_camel_case_type = {$sort} `{$name}` should have an upper camel case nam
|
|||
.suggestion = convert the identifier to upper camel case
|
||||
.label = should have an UpperCamelCase name
|
||||
|
||||
lint_non_existent_doc_keyword = found non-existing keyword `{$keyword}` used in `#[doc(keyword = "...")]`
|
||||
.help = only existing keywords are allowed in core/std
|
||||
|
||||
lint_non_fmt_panic = panic message is not a string literal
|
||||
.note = this usage of `{$name}!()` is deprecated; it will be a hard error in Rust 2021
|
||||
.more_info_note = for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
|
||||
|
|
|
@ -1814,7 +1814,7 @@ declare_lint! {
|
|||
"detects edition keywords being used as an identifier",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
|
||||
reference: "issue #49716 <https://github.com/rust-lang/rust/issues/49716>",
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/gen-keyword.html>",
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ declare_lint! {
|
|||
rewriting in `match` is an option to preserve the semantics up to Edition 2021",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
|
||||
reference: "issue #124085 <https://github.com/rust-lang/rust/issues/124085>",
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html>",
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,11 @@ use rustc_middle::ty::{self, GenericArgsRef, Ty as MiddleTy};
|
|||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::hygiene::{ExpnKind, MacroKind};
|
||||
use rustc_span::symbol::{Symbol, kw, sym};
|
||||
use rustc_span::symbol::sym;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::lints::{
|
||||
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand, NonExistentDocKeyword,
|
||||
BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand,
|
||||
NonGlobImportTypeIrInherent, QueryInstability, QueryUntracked, SpanUseEqCtxtDiag,
|
||||
SymbolInternStringLiteralDiag, TyQualified, TykindDiag, TykindKind, TypeIrInherentUsage,
|
||||
UntranslatableDiag,
|
||||
|
@ -375,46 +375,6 @@ impl EarlyLintPass for LintPassImpl {
|
|||
}
|
||||
}
|
||||
|
||||
declare_tool_lint! {
|
||||
/// The `existing_doc_keyword` lint detects use `#[doc()]` keywords
|
||||
/// that don't exist, e.g. `#[doc(keyword = "..")]`.
|
||||
pub rustc::EXISTING_DOC_KEYWORD,
|
||||
Allow,
|
||||
"Check that documented keywords in std and core actually exist",
|
||||
report_in_external_macro: true
|
||||
}
|
||||
|
||||
declare_lint_pass!(ExistingDocKeyword => [EXISTING_DOC_KEYWORD]);
|
||||
|
||||
fn is_doc_keyword(s: Symbol) -> bool {
|
||||
s <= kw::Union
|
||||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
|
||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::Item<'_>) {
|
||||
for attr in cx.tcx.hir().attrs(item.hir_id()) {
|
||||
if !attr.has_name(sym::doc) {
|
||||
continue;
|
||||
}
|
||||
if let Some(list) = attr.meta_item_list() {
|
||||
for nested in list {
|
||||
if nested.has_name(sym::keyword) {
|
||||
let keyword = nested
|
||||
.value_str()
|
||||
.expect("#[doc(keyword = \"...\")] expected a value!");
|
||||
if is_doc_keyword(keyword) {
|
||||
return;
|
||||
}
|
||||
cx.emit_span_lint(EXISTING_DOC_KEYWORD, attr.span, NonExistentDocKeyword {
|
||||
keyword,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare_tool_lint! {
|
||||
/// The `untranslatable_diagnostic` lint detects messages passed to functions with `impl
|
||||
/// Into<{D,Subd}iagMessage` parameters without using translatable Fluent strings.
|
||||
|
|
|
@ -600,8 +600,6 @@ fn register_internals(store: &mut LintStore) {
|
|||
store.register_late_mod_pass(|_| Box::new(DefaultHashTypes));
|
||||
store.register_lints(&QueryStability::lint_vec());
|
||||
store.register_late_mod_pass(|_| Box::new(QueryStability));
|
||||
store.register_lints(&ExistingDocKeyword::lint_vec());
|
||||
store.register_late_mod_pass(|_| Box::new(ExistingDocKeyword));
|
||||
store.register_lints(&TyTyKind::lint_vec());
|
||||
store.register_late_mod_pass(|_| Box::new(TyTyKind));
|
||||
store.register_lints(&TypeIr::lint_vec());
|
||||
|
@ -629,7 +627,6 @@ fn register_internals(store: &mut LintStore) {
|
|||
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
|
||||
LintId::of(USAGE_OF_QUALIFIED_TY),
|
||||
LintId::of(NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT),
|
||||
LintId::of(EXISTING_DOC_KEYWORD),
|
||||
LintId::of(BAD_OPT_ACCESS),
|
||||
LintId::of(SPAN_USE_EQ_CTXT),
|
||||
]);
|
||||
|
|
|
@ -950,13 +950,6 @@ pub(crate) struct NonGlobImportTypeIrInherent {
|
|||
#[help]
|
||||
pub(crate) struct LintPassByHand;
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_non_existent_doc_keyword)]
|
||||
#[help]
|
||||
pub(crate) struct NonExistentDocKeyword {
|
||||
pub keyword: Symbol,
|
||||
}
|
||||
|
||||
#[derive(LintDiagnostic)]
|
||||
#[diag(lint_diag_out_of_impl)]
|
||||
pub(crate) struct DiagOutOfImpl;
|
||||
|
|
|
@ -61,6 +61,7 @@ declare_lint! {
|
|||
"detects calling `into_iter` on boxed slices in Rust 2015, 2018, and 2021",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/intoiterator-box-slice.html>"
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1677,7 +1677,7 @@ declare_lint! {
|
|||
"detects patterns whose meaning will change in Rust 2024",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
|
||||
reference: "123076",
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2606,7 +2606,7 @@ declare_lint! {
|
|||
"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
|
||||
reference: "issue #71668 <https://github.com/rust-lang/rust/issues/71668>",
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html>",
|
||||
explain_reason: false
|
||||
};
|
||||
@edition Edition2024 => Warn;
|
||||
|
@ -4189,7 +4189,7 @@ declare_lint! {
|
|||
"never type fallback affecting unsafe function calls",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(Edition::Edition2024),
|
||||
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/never-type-fallback.html>",
|
||||
};
|
||||
@edition Edition2024 => Deny;
|
||||
report_in_external_macro
|
||||
|
@ -4243,7 +4243,7 @@ declare_lint! {
|
|||
"never type fallback affecting unsafe function calls",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionAndFutureReleaseError(Edition::Edition2024),
|
||||
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/never-type-fallback.html>",
|
||||
};
|
||||
report_in_external_macro
|
||||
}
|
||||
|
@ -4790,7 +4790,7 @@ declare_lint! {
|
|||
"detects unsafe functions being used as safe functions",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
|
||||
reference: "issue #27970 <https://github.com/rust-lang/rust/issues/27970>",
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/newly-unsafe-functions.html>",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -4826,7 +4826,7 @@ declare_lint! {
|
|||
"detects missing unsafe keyword on extern declarations",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
|
||||
reference: "issue #123743 <https://github.com/rust-lang/rust/issues/123743>",
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-extern.html>",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -4867,7 +4867,7 @@ declare_lint! {
|
|||
"detects unsafe attributes outside of unsafe",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
|
||||
reference: "issue #123757 <https://github.com/rust-lang/rust/issues/123757>",
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-attributes.html>",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -5069,7 +5069,7 @@ declare_lint! {
|
|||
"Detect and warn on significant change in drop order in tail expression location",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
|
||||
reference: "issue #123739 <https://github.com/rust-lang/rust/issues/123739>",
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -5108,7 +5108,7 @@ declare_lint! {
|
|||
"will be parsed as a guarded string in Rust 2024",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
|
||||
reference: "issue #123735 <https://github.com/rust-lang/rust/issues/123735>",
|
||||
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/reserved-syntax.html>",
|
||||
};
|
||||
crate_level_only
|
||||
}
|
||||
|
|
|
@ -1119,10 +1119,10 @@ impl<'tcx> CommonConsts<'tcx> {
|
|||
/// either a `ReEarlyParam` or `ReLateParam`.
|
||||
#[derive(Debug)]
|
||||
pub struct FreeRegionInfo {
|
||||
/// `LocalDefId` of the free region.
|
||||
pub def_id: LocalDefId,
|
||||
/// the bound region corresponding to free region.
|
||||
pub bound_region: ty::BoundRegionKind,
|
||||
/// `LocalDefId` of the scope.
|
||||
pub scope: LocalDefId,
|
||||
/// the `DefId` of the free region.
|
||||
pub region_def_id: DefId,
|
||||
/// checks if bound region is in Impl Item
|
||||
pub is_impl_item: bool,
|
||||
}
|
||||
|
@ -1960,7 +1960,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
generic_param_scope: LocalDefId,
|
||||
mut region: Region<'tcx>,
|
||||
) -> Option<FreeRegionInfo> {
|
||||
let (suitable_region_binding_scope, bound_region) = loop {
|
||||
let (suitable_region_binding_scope, region_def_id) = loop {
|
||||
let def_id =
|
||||
region.opt_param_def_id(self, generic_param_scope.to_def_id())?.as_local()?;
|
||||
let scope = self.local_parent(def_id);
|
||||
|
@ -1970,10 +1970,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
region = self.map_opaque_lifetime_to_parent_lifetime(def_id);
|
||||
continue;
|
||||
}
|
||||
break (
|
||||
scope,
|
||||
ty::BoundRegionKind::Named(def_id.into(), self.item_name(def_id.into())),
|
||||
);
|
||||
break (scope, def_id.into());
|
||||
};
|
||||
|
||||
let is_impl_item = match self.hir_node_by_def_id(suitable_region_binding_scope) {
|
||||
|
@ -1982,7 +1979,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
_ => false,
|
||||
};
|
||||
|
||||
Some(FreeRegionInfo { def_id: suitable_region_binding_scope, bound_region, is_impl_item })
|
||||
Some(FreeRegionInfo { scope: suitable_region_binding_scope, region_def_id, is_impl_item })
|
||||
}
|
||||
|
||||
/// Given a `DefId` for an `fn`, return all the `dyn` and `impl` traits in its return type.
|
||||
|
|
|
@ -5,9 +5,9 @@ use rustc_middle::{span_bug, ty};
|
|||
use rustc_span::Span;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::build::ForGuard::OutsideGuard;
|
||||
use crate::build::matches::{DeclareLetBindings, EmitStorageLive, ScheduleDrops};
|
||||
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
|
||||
use crate::builder::ForGuard::OutsideGuard;
|
||||
use crate::builder::matches::{DeclareLetBindings, EmitStorageLive, ScheduleDrops};
|
||||
use crate::builder::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
pub(crate) fn ast_block(
|
|
@ -4,7 +4,7 @@ use rustc_middle::mir::*;
|
|||
use rustc_middle::ty::TyCtxt;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::build::CFG;
|
||||
use crate::builder::CFG;
|
||||
|
||||
impl<'tcx> CFG<'tcx> {
|
||||
pub(crate) fn block_data(&self, blk: BasicBlock) -> &BasicBlockData<'tcx> {
|
|
@ -8,8 +8,8 @@ use rustc_middle::thir::{ExprId, ExprKind, Pat, Thir};
|
|||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
|
||||
use crate::build::coverageinfo::mcdc::MCDCInfoBuilder;
|
||||
use crate::build::{Builder, CFG};
|
||||
use crate::builder::coverageinfo::mcdc::MCDCInfoBuilder;
|
||||
use crate::builder::{Builder, CFG};
|
||||
|
||||
mod mcdc;
|
||||
|
|
@ -9,7 +9,7 @@ use rustc_middle::thir::LogicalOp;
|
|||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::Span;
|
||||
|
||||
use crate::build::Builder;
|
||||
use crate::builder::Builder;
|
||||
use crate::errors::MCDCExceedsConditionLimit;
|
||||
|
||||
/// LLVM uses `i16` to represent condition id. Hence `i16::MAX` is the hard limit for number of
|
|
@ -9,8 +9,8 @@ use rustc_span::Span;
|
|||
use rustc_span::source_map::Spanned;
|
||||
|
||||
use super::{PResult, ParseCtxt, parse_by_kind};
|
||||
use crate::build::custom::ParseError;
|
||||
use crate::build::expr::as_constant::as_constant_inner;
|
||||
use crate::builder::custom::ParseError;
|
||||
use crate::builder::expr::as_constant::as_constant_inner;
|
||||
|
||||
impl<'a, 'tcx> ParseCtxt<'a, 'tcx> {
|
||||
pub(crate) fn parse_statement(&self, expr_id: ExprId) -> PResult<StatementKind<'tcx>> {
|
|
@ -14,7 +14,7 @@ use rustc_middle::ty::{
|
|||
use rustc_middle::{bug, mir, span_bug};
|
||||
use tracing::{instrument, trace};
|
||||
|
||||
use crate::build::{Builder, parse_float_into_constval};
|
||||
use crate::builder::{Builder, parse_float_into_constval};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Compile `expr`, yielding a compile-time constant. Assumes that
|
|
@ -4,8 +4,8 @@ use rustc_middle::mir::*;
|
|||
use rustc_middle::thir::*;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::build::expr::category::Category;
|
||||
use crate::build::{BlockAnd, BlockAndExtension, Builder, NeedsTemporary};
|
||||
use crate::builder::expr::category::Category;
|
||||
use crate::builder::{BlockAnd, BlockAndExtension, Builder, NeedsTemporary};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Construct a temporary lifetime restricted to just the local scope
|
|
@ -14,9 +14,9 @@ use rustc_middle::{bug, span_bug};
|
|||
use rustc_span::{DesugaringKind, Span};
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};
|
||||
use crate::build::expr::category::Category;
|
||||
use crate::build::{BlockAnd, BlockAndExtension, Builder, Capture, CaptureMap};
|
||||
use crate::builder::ForGuard::{OutsideGuard, RefWithinGuard};
|
||||
use crate::builder::expr::category::Category;
|
||||
use crate::builder::{BlockAnd, BlockAndExtension, Builder, Capture, CaptureMap};
|
||||
|
||||
/// The "outermost" place that holds this value.
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
|
@ -68,7 +68,7 @@ pub(crate) enum PlaceBase {
|
|||
/// This is used internally when building a place for an expression like `a.b.c`. The fields `b`
|
||||
/// and `c` can be progressively pushed onto the place builder that is created when converting `a`.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(in crate::build) struct PlaceBuilder<'tcx> {
|
||||
pub(in crate::builder) struct PlaceBuilder<'tcx> {
|
||||
base: PlaceBase,
|
||||
projection: Vec<PlaceElem<'tcx>>,
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ fn strip_prefix<'a, 'tcx>(
|
|||
}
|
||||
|
||||
impl<'tcx> PlaceBuilder<'tcx> {
|
||||
pub(in crate::build) fn to_place(&self, cx: &Builder<'_, 'tcx>) -> Place<'tcx> {
|
||||
pub(in crate::builder) fn to_place(&self, cx: &Builder<'_, 'tcx>) -> Place<'tcx> {
|
||||
self.try_to_place(cx).unwrap_or_else(|| match self.base {
|
||||
PlaceBase::Local(local) => span_bug!(
|
||||
cx.local_decls[local].source_info.span,
|
||||
|
@ -265,7 +265,7 @@ impl<'tcx> PlaceBuilder<'tcx> {
|
|||
}
|
||||
|
||||
/// Creates a `Place` or returns `None` if an upvar cannot be resolved
|
||||
pub(in crate::build) fn try_to_place(&self, cx: &Builder<'_, 'tcx>) -> Option<Place<'tcx>> {
|
||||
pub(in crate::builder) fn try_to_place(&self, cx: &Builder<'_, 'tcx>) -> Option<Place<'tcx>> {
|
||||
let resolved = self.resolve_upvar(cx);
|
||||
let builder = resolved.as_ref().unwrap_or(self);
|
||||
let PlaceBase::Local(local) = builder.base else { return None };
|
||||
|
@ -283,7 +283,7 @@ impl<'tcx> PlaceBuilder<'tcx> {
|
|||
/// not captured. This can happen because the final mir that will be
|
||||
/// generated doesn't require a read for this place. Failures will only
|
||||
/// happen inside closures.
|
||||
pub(in crate::build) fn resolve_upvar(
|
||||
pub(in crate::builder) fn resolve_upvar(
|
||||
&self,
|
||||
cx: &Builder<'_, 'tcx>,
|
||||
) -> Option<PlaceBuilder<'tcx>> {
|
|
@ -16,9 +16,9 @@ use rustc_span::source_map::Spanned;
|
|||
use rustc_span::{DUMMY_SP, Span};
|
||||
use tracing::debug;
|
||||
|
||||
use crate::build::expr::as_place::PlaceBase;
|
||||
use crate::build::expr::category::{Category, RvalueFunc};
|
||||
use crate::build::{BlockAnd, BlockAndExtension, Builder, NeedsTemporary};
|
||||
use crate::builder::expr::as_place::PlaceBase;
|
||||
use crate::builder::expr::category::{Category, RvalueFunc};
|
||||
use crate::builder::{BlockAnd, BlockAndExtension, Builder, NeedsTemporary};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Returns an rvalue suitable for use until the end of the current
|
|
@ -7,8 +7,8 @@ use rustc_middle::mir::*;
|
|||
use rustc_middle::thir::*;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::build::scope::DropKind;
|
||||
use crate::build::{BlockAnd, BlockAndExtension, Builder};
|
||||
use crate::builder::scope::DropKind;
|
||||
use crate::builder::{BlockAnd, BlockAndExtension, Builder};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Compile `expr` into a fresh temporary. This is used when building
|
|
@ -11,9 +11,9 @@ use rustc_middle::ty::CanonicalUserTypeAnnotation;
|
|||
use rustc_span::source_map::Spanned;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::build::expr::category::{Category, RvalueFunc};
|
||||
use crate::build::matches::DeclareLetBindings;
|
||||
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder, NeedsTemporary};
|
||||
use crate::builder::expr::category::{Category, RvalueFunc};
|
||||
use crate::builder::matches::DeclareLetBindings;
|
||||
use crate::builder::{BlockAnd, BlockAndExtension, BlockFrame, Builder, NeedsTemporary};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Compile `expr`, storing the result into `destination`, which
|
|
@ -5,8 +5,8 @@ use rustc_middle::thir::*;
|
|||
use rustc_span::source_map::Spanned;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::build::scope::BreakableTarget;
|
||||
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
|
||||
use crate::builder::scope::BreakableTarget;
|
||||
use crate::builder::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Builds a block of MIR statements to evaluate the THIR `expr`.
|
|
@ -2,9 +2,9 @@ use rustc_middle::mir::*;
|
|||
use rustc_middle::thir::{self, *};
|
||||
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
||||
|
||||
use crate::build::Builder;
|
||||
use crate::build::expr::as_place::{PlaceBase, PlaceBuilder};
|
||||
use crate::build::matches::{FlatPat, MatchPairTree, TestCase};
|
||||
use crate::builder::Builder;
|
||||
use crate::builder::expr::as_place::{PlaceBase, PlaceBuilder};
|
||||
use crate::builder::matches::{FlatPat, MatchPairTree, TestCase};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Builds and returns [`MatchPairTree`] subtrees, one for each pattern in
|
||||
|
@ -86,7 +86,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
impl<'pat, 'tcx> MatchPairTree<'pat, 'tcx> {
|
||||
/// Recursively builds a match pair tree for the given pattern and its
|
||||
/// subpatterns.
|
||||
pub(in crate::build) fn for_pattern(
|
||||
pub(in crate::builder) fn for_pattern(
|
||||
mut place_builder: PlaceBuilder<'tcx>,
|
||||
pattern: &'pat Pat<'tcx>,
|
||||
cx: &mut Builder<'_, 'tcx>,
|
|
@ -18,10 +18,10 @@ use rustc_span::symbol::Symbol;
|
|||
use rustc_span::{BytePos, Pos, Span};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
|
||||
use crate::build::expr::as_place::PlaceBuilder;
|
||||
use crate::build::scope::DropKind;
|
||||
use crate::build::{
|
||||
use crate::builder::ForGuard::{self, OutsideGuard, RefWithinGuard};
|
||||
use crate::builder::expr::as_place::PlaceBuilder;
|
||||
use crate::builder::scope::DropKind;
|
||||
use crate::builder::{
|
||||
BlockAnd, BlockAndExtension, Builder, GuardFrame, GuardFrameLocal, LocalsForNode,
|
||||
};
|
||||
|
|
@ -16,8 +16,8 @@ use std::mem;
|
|||
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::build::Builder;
|
||||
use crate::build::matches::{MatchPairTree, PatternExtraData, TestCase};
|
||||
use crate::builder::Builder;
|
||||
use crate::builder::matches::{MatchPairTree, PatternExtraData, TestCase};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Simplify a list of match pairs so they all require a test. Stores relevant bindings and
|
|
@ -20,8 +20,8 @@ use rustc_span::symbol::{Symbol, sym};
|
|||
use rustc_span::{DUMMY_SP, Span};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::build::Builder;
|
||||
use crate::build::matches::{Candidate, MatchPairTree, Test, TestBranch, TestCase, TestKind};
|
||||
use crate::builder::Builder;
|
||||
use crate::builder::matches::{Candidate, MatchPairTree, Test, TestBranch, TestCase, TestKind};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Identifies what test is needed to decide if `match_pair` is applicable.
|
|
@ -4,9 +4,9 @@ use rustc_middle::ty::Ty;
|
|||
use rustc_span::Span;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::build::Builder;
|
||||
use crate::build::expr::as_place::PlaceBase;
|
||||
use crate::build::matches::{Binding, Candidate, FlatPat, MatchPairTree, TestCase};
|
||||
use crate::builder::Builder;
|
||||
use crate::builder::expr::as_place::PlaceBase;
|
||||
use crate::builder::matches::{Binding, Candidate, FlatPat, MatchPairTree, TestCase};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Creates a false edge to `imaginary_target` and a real edge to
|
|
@ -7,7 +7,7 @@ use rustc_span::Span;
|
|||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::build::Builder;
|
||||
use crate::builder::Builder;
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Adds a new temporary value of type `ty` storing the result of
|
|
@ -1,3 +1,8 @@
|
|||
//! This module used to be named `build`, but that was causing GitHub's
|
||||
//! "Go to file" feature to silently ignore all files in the module, probably
|
||||
//! because it assumes that "build" is a build-output directory.
|
||||
//! See <https://github.com/rust-lang/rust/pull/134365>.
|
||||
|
||||
use itertools::Itertools;
|
||||
use rustc_abi::{ExternAbi, FieldIdx};
|
||||
use rustc_apfloat::Float;
|
||||
|
@ -23,8 +28,8 @@ use rustc_span::symbol::sym;
|
|||
use rustc_span::{Span, Symbol};
|
||||
|
||||
use super::lints;
|
||||
use crate::build::expr::as_place::PlaceBuilder;
|
||||
use crate::build::scope::DropKind;
|
||||
use crate::builder::expr::as_place::PlaceBuilder;
|
||||
use crate::builder::scope::DropKind;
|
||||
|
||||
pub(crate) fn closure_saved_names_of_captured_variables<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
|
@ -95,7 +95,7 @@ use rustc_span::source_map::Spanned;
|
|||
use rustc_span::{DUMMY_SP, Span};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG};
|
||||
use crate::builder::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Scopes<'tcx> {
|
|
@ -18,7 +18,7 @@ use rustc_span::def_id::{DefId, LocalDefId};
|
|||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::{Span, sym};
|
||||
|
||||
use crate::build::ExprCategory;
|
||||
use crate::builder::ExprCategory;
|
||||
use crate::errors::*;
|
||||
|
||||
struct UnsafetyVisitor<'a, 'tcx> {
|
||||
|
|
|
@ -11,7 +11,10 @@
|
|||
#![warn(unreachable_pub)]
|
||||
// tidy-alphabetical-end
|
||||
|
||||
mod build;
|
||||
// The `builder` module used to be named `build`, but that was causing GitHub's
|
||||
// "Go to file" feature to silently ignore all files in the module, probably
|
||||
// because it assumes that "build" is a build-output directory. See #134365.
|
||||
mod builder;
|
||||
mod check_tail_calls;
|
||||
mod check_unsafety;
|
||||
mod errors;
|
||||
|
@ -25,9 +28,9 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
|||
pub fn provide(providers: &mut Providers) {
|
||||
providers.check_match = thir::pattern::check_match;
|
||||
providers.lit_to_const = thir::constant::lit_to_const;
|
||||
providers.hooks.build_mir = build::mir_build;
|
||||
providers.hooks.build_mir = builder::mir_build;
|
||||
providers.closure_saved_names_of_captured_variables =
|
||||
build::closure_saved_names_of_captured_variables;
|
||||
builder::closure_saved_names_of_captured_variables;
|
||||
providers.check_unsafety = check_unsafety::check_unsafety;
|
||||
providers.check_tail_calls = check_tail_calls::check_tail_calls;
|
||||
providers.thir_body = thir::cx::thir_body;
|
||||
|
|
|
@ -5,7 +5,7 @@ use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput};
|
|||
use rustc_middle::ty::{self, ScalarInt, TyCtxt, TypeVisitableExt as _};
|
||||
use tracing::trace;
|
||||
|
||||
use crate::build::parse_float_into_scalar;
|
||||
use crate::builder::parse_float_into_scalar;
|
||||
|
||||
pub(crate) fn lit_to_const<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
|
|
|
@ -1197,7 +1197,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
.temporary_scope(self.region_scope_tree, closure_expr.hir_id.local_id);
|
||||
let var_ty = place.base_ty;
|
||||
|
||||
// The result of capture analysis in `rustc_hir_analysis/check/upvar.rs`represents a captured path
|
||||
// The result of capture analysis in `rustc_hir_typeck/src/upvar.rs` represents a captured path
|
||||
// as it's seen for use within the closure and not at the time of closure creation.
|
||||
//
|
||||
// That is we see expect to see it start from a captured upvar and not something that is local
|
||||
|
|
|
@ -16,7 +16,6 @@ rustc_feature = { path = "../rustc_feature" }
|
|||
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
|
||||
rustc_hir = { path = "../rustc_hir" }
|
||||
rustc_index = { path = "../rustc_index" }
|
||||
rustc_lexer = { path = "../rustc_lexer" }
|
||||
rustc_macros = { path = "../rustc_macros" }
|
||||
rustc_middle = { path = "../rustc_middle" }
|
||||
rustc_privacy = { path = "../rustc_privacy" }
|
||||
|
|
|
@ -211,8 +211,9 @@ passes_doc_invalid =
|
|||
passes_doc_keyword_empty_mod =
|
||||
`#[doc(keyword = "...")]` should be used on empty modules
|
||||
|
||||
passes_doc_keyword_invalid_ident =
|
||||
`{$doc_keyword}` is not a valid identifier
|
||||
passes_doc_keyword_not_keyword =
|
||||
nonexistent keyword `{$keyword}` used in `#[doc(keyword = "...")]`
|
||||
.help = only existing keywords are allowed in core/std
|
||||
|
||||
passes_doc_keyword_not_mod =
|
||||
`#[doc(keyword = "...")]` should be used on modules
|
||||
|
|
|
@ -912,6 +912,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
}
|
||||
|
||||
fn check_doc_keyword(&self, meta: &MetaItemInner, hir_id: HirId) {
|
||||
fn is_doc_keyword(s: Symbol) -> bool {
|
||||
// FIXME: Once rustdoc can handle URL conflicts on case insensitive file systems, we
|
||||
// can remove the `SelfTy` case here, remove `sym::SelfTy`, and update the
|
||||
// `#[doc(keyword = "SelfTy")` attribute in `library/std/src/keyword_docs.rs`.
|
||||
s <= kw::Union || s == sym::SelfTy
|
||||
}
|
||||
|
||||
let doc_keyword = meta.value_str().unwrap_or(kw::Empty);
|
||||
if doc_keyword == kw::Empty {
|
||||
self.doc_attr_str_error(meta, "keyword");
|
||||
|
@ -933,10 +940,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
return;
|
||||
}
|
||||
}
|
||||
if !rustc_lexer::is_ident(doc_keyword.as_str()) {
|
||||
self.dcx().emit_err(errors::DocKeywordInvalidIdent {
|
||||
if !is_doc_keyword(doc_keyword) {
|
||||
self.dcx().emit_err(errors::DocKeywordNotKeyword {
|
||||
span: meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
|
||||
doc_keyword,
|
||||
keyword: doc_keyword,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,6 +215,15 @@ pub(crate) struct DocKeywordEmptyMod {
|
|||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_doc_keyword_not_keyword)]
|
||||
#[help]
|
||||
pub(crate) struct DocKeywordNotKeyword {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub keyword: Symbol,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_doc_keyword_not_mod)]
|
||||
pub(crate) struct DocKeywordNotMod {
|
||||
|
@ -222,14 +231,6 @@ pub(crate) struct DocKeywordNotMod {
|
|||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_doc_keyword_invalid_ident)]
|
||||
pub(crate) struct DocKeywordInvalidIdent {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub doc_keyword: Symbol,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_doc_fake_variadic_not_valid)]
|
||||
pub(crate) struct DocFakeVariadicNotValid {
|
||||
|
|
|
@ -22,6 +22,10 @@ impl NodeStats {
|
|||
fn new() -> NodeStats {
|
||||
NodeStats { count: 0, size: 0 }
|
||||
}
|
||||
|
||||
fn accum_size(&self) -> usize {
|
||||
self.count * self.size
|
||||
}
|
||||
}
|
||||
|
||||
struct Node {
|
||||
|
@ -121,11 +125,9 @@ impl<'k> StatCollector<'k> {
|
|||
// We will soon sort, so the initial order does not matter.
|
||||
#[allow(rustc::potential_query_instability)]
|
||||
let mut nodes: Vec<_> = self.nodes.iter().collect();
|
||||
nodes.sort_by_cached_key(|(label, node)| {
|
||||
(node.stats.count * node.stats.size, label.to_owned())
|
||||
});
|
||||
nodes.sort_by_cached_key(|(label, node)| (node.stats.accum_size(), label.to_owned()));
|
||||
|
||||
let total_size = nodes.iter().map(|(_, node)| node.stats.count * node.stats.size).sum();
|
||||
let total_size = nodes.iter().map(|(_, node)| node.stats.accum_size()).sum();
|
||||
let total_count = nodes.iter().map(|(_, node)| node.stats.count).sum();
|
||||
|
||||
eprintln!("{prefix} {title}");
|
||||
|
@ -138,7 +140,7 @@ impl<'k> StatCollector<'k> {
|
|||
let percent = |m, n| (m * 100) as f64 / n as f64;
|
||||
|
||||
for (label, node) in nodes {
|
||||
let size = node.stats.count * node.stats.size;
|
||||
let size = node.stats.accum_size();
|
||||
eprintln!(
|
||||
"{} {:<18}{:>10} ({:4.1}%){:>14}{:>14}",
|
||||
prefix,
|
||||
|
@ -152,10 +154,12 @@ impl<'k> StatCollector<'k> {
|
|||
// We will soon sort, so the initial order does not matter.
|
||||
#[allow(rustc::potential_query_instability)]
|
||||
let mut subnodes: Vec<_> = node.subnodes.iter().collect();
|
||||
subnodes.sort_by_key(|(_, subnode)| subnode.count * subnode.size);
|
||||
subnodes.sort_by_cached_key(|(label, subnode)| {
|
||||
(subnode.accum_size(), label.to_owned())
|
||||
});
|
||||
|
||||
for (label, subnode) in subnodes {
|
||||
let size = subnode.count * subnode.size;
|
||||
let size = subnode.accum_size();
|
||||
eprintln!(
|
||||
"{} - {:<18}{:>10} ({:4.1}%){:>14}",
|
||||
prefix,
|
||||
|
|
|
@ -306,6 +306,7 @@ symbols! {
|
|||
RwLockWriteGuard,
|
||||
Saturating,
|
||||
SeekFrom,
|
||||
SelfTy,
|
||||
Send,
|
||||
SeqCst,
|
||||
Sized,
|
||||
|
|
|
@ -824,7 +824,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
fn cmp_fn_sig(
|
||||
&self,
|
||||
sig1: &ty::PolyFnSig<'tcx>,
|
||||
fn_def1: Option<(DefId, &'tcx [ty::GenericArg<'tcx>])>,
|
||||
sig2: &ty::PolyFnSig<'tcx>,
|
||||
fn_def2: Option<(DefId, &'tcx [ty::GenericArg<'tcx>])>,
|
||||
) -> (DiagStyledString, DiagStyledString) {
|
||||
let sig1 = &(self.normalize_fn_sig)(*sig1);
|
||||
let sig2 = &(self.normalize_fn_sig)(*sig2);
|
||||
|
@ -930,6 +932,25 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
(values.1).0.extend(x2.0);
|
||||
}
|
||||
|
||||
let fmt = |(did, args)| format!(" {{{}}}", self.tcx.def_path_str_with_args(did, args));
|
||||
|
||||
match (fn_def1, fn_def2) {
|
||||
(None, None) => {}
|
||||
(Some(fn_def1), Some(fn_def2)) => {
|
||||
let path1 = fmt(fn_def1);
|
||||
let path2 = fmt(fn_def2);
|
||||
let same_path = path1 == path2;
|
||||
values.0.push(path1, !same_path);
|
||||
values.1.push(path2, !same_path);
|
||||
}
|
||||
(Some(fn_def1), None) => {
|
||||
values.0.push_highlighted(fmt(fn_def1));
|
||||
}
|
||||
(None, Some(fn_def2)) => {
|
||||
values.1.push_highlighted(fmt(fn_def2));
|
||||
}
|
||||
}
|
||||
|
||||
values
|
||||
}
|
||||
|
||||
|
@ -1318,36 +1339,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
(ty::FnDef(did1, args1), ty::FnDef(did2, args2)) => {
|
||||
let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1);
|
||||
let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2);
|
||||
let mut values = self.cmp_fn_sig(&sig1, &sig2);
|
||||
let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did1, args1));
|
||||
let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2));
|
||||
let same_path = path1 == path2;
|
||||
values.0.push(path1, !same_path);
|
||||
values.1.push(path2, !same_path);
|
||||
values
|
||||
self.cmp_fn_sig(&sig1, Some((*did1, args1)), &sig2, Some((*did2, args2)))
|
||||
}
|
||||
|
||||
(ty::FnDef(did1, args1), ty::FnPtr(sig_tys2, hdr2)) => {
|
||||
let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1);
|
||||
let mut values = self.cmp_fn_sig(&sig1, &sig_tys2.with(*hdr2));
|
||||
values.0.push_highlighted(format!(
|
||||
" {{{}}}",
|
||||
self.tcx.def_path_str_with_args(*did1, args1)
|
||||
));
|
||||
values
|
||||
self.cmp_fn_sig(&sig1, Some((*did1, args1)), &sig_tys2.with(*hdr2), None)
|
||||
}
|
||||
|
||||
(ty::FnPtr(sig_tys1, hdr1), ty::FnDef(did2, args2)) => {
|
||||
let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2);
|
||||
let mut values = self.cmp_fn_sig(&sig_tys1.with(*hdr1), &sig2);
|
||||
values
|
||||
.1
|
||||
.push_normal(format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2)));
|
||||
values
|
||||
self.cmp_fn_sig(&sig_tys1.with(*hdr1), None, &sig2, Some((*did2, args2)))
|
||||
}
|
||||
|
||||
(ty::FnPtr(sig_tys1, hdr1), ty::FnPtr(sig_tys2, hdr2)) => {
|
||||
self.cmp_fn_sig(&sig_tys1.with(*hdr1), &sig_tys2.with(*hdr2))
|
||||
self.cmp_fn_sig(&sig_tys1.with(*hdr1), None, &sig_tys2.with(*hdr2), None)
|
||||
}
|
||||
|
||||
_ => {
|
||||
|
@ -2102,7 +2108,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
if exp_found.references_error() {
|
||||
return None;
|
||||
}
|
||||
let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, &exp_found.found);
|
||||
let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, None, &exp_found.found, None);
|
||||
Some((exp, fnd, None))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,26 +63,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
}
|
||||
|
||||
// Determine whether the sub and sup consist of both anonymous (elided) regions.
|
||||
let anon_reg_sup = self.tcx().is_suitable_region(self.generic_param_scope, sup)?;
|
||||
let sup_info = self.tcx().is_suitable_region(self.generic_param_scope, sup)?;
|
||||
|
||||
let anon_reg_sub = self.tcx().is_suitable_region(self.generic_param_scope, sub)?;
|
||||
let scope_def_id_sup = anon_reg_sup.def_id;
|
||||
let bregion_sup = anon_reg_sup.bound_region;
|
||||
let scope_def_id_sub = anon_reg_sub.def_id;
|
||||
let bregion_sub = anon_reg_sub.bound_region;
|
||||
let sub_info = self.tcx().is_suitable_region(self.generic_param_scope, sub)?;
|
||||
|
||||
let ty_sup = find_anon_type(self.tcx(), self.generic_param_scope, sup, &bregion_sup)?;
|
||||
let ty_sup = find_anon_type(self.tcx(), self.generic_param_scope, sup)?;
|
||||
|
||||
let ty_sub = find_anon_type(self.tcx(), self.generic_param_scope, sub, &bregion_sub)?;
|
||||
let ty_sub = find_anon_type(self.tcx(), self.generic_param_scope, sub)?;
|
||||
|
||||
debug!(
|
||||
"try_report_anon_anon_conflict: found_param1={:?} sup={:?} br1={:?}",
|
||||
ty_sub, sup, bregion_sup
|
||||
);
|
||||
debug!(
|
||||
"try_report_anon_anon_conflict: found_param2={:?} sub={:?} br2={:?}",
|
||||
ty_sup, sub, bregion_sub
|
||||
);
|
||||
debug!("try_report_anon_anon_conflict: found_param1={:?} sup={:?}", ty_sub, sup);
|
||||
debug!("try_report_anon_anon_conflict: found_param2={:?} sub={:?}", ty_sup, sub);
|
||||
|
||||
let (ty_sup, ty_fndecl_sup) = ty_sup;
|
||||
let (ty_sub, ty_fndecl_sub) = ty_sub;
|
||||
|
@ -93,9 +83,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
self.find_param_with_region(sub, sub)?;
|
||||
|
||||
let sup_is_ret_type =
|
||||
self.is_return_type_anon(scope_def_id_sup, bregion_sup, ty_fndecl_sup);
|
||||
self.is_return_type_anon(sup_info.scope, sup_info.region_def_id, ty_fndecl_sup);
|
||||
let sub_is_ret_type =
|
||||
self.is_return_type_anon(scope_def_id_sub, bregion_sub, ty_fndecl_sub);
|
||||
self.is_return_type_anon(sub_info.scope, sub_info.region_def_id, ty_fndecl_sub);
|
||||
|
||||
debug!(
|
||||
"try_report_anon_anon_conflict: sub_is_ret_type={:?} sup_is_ret_type={:?}",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use core::ops::ControlFlow;
|
||||
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
|
@ -28,16 +28,15 @@ pub fn find_anon_type<'tcx>(
|
|||
tcx: TyCtxt<'tcx>,
|
||||
generic_param_scope: LocalDefId,
|
||||
region: Region<'tcx>,
|
||||
br: &ty::BoundRegionKind,
|
||||
) -> Option<(&'tcx hir::Ty<'tcx>, &'tcx hir::FnSig<'tcx>)> {
|
||||
let anon_reg = tcx.is_suitable_region(generic_param_scope, region)?;
|
||||
let fn_sig = tcx.hir_node_by_def_id(anon_reg.def_id).fn_sig()?;
|
||||
let fn_sig = tcx.hir_node_by_def_id(anon_reg.scope).fn_sig()?;
|
||||
|
||||
fn_sig
|
||||
.decl
|
||||
.inputs
|
||||
.iter()
|
||||
.find_map(|arg| find_component_for_bound_region(tcx, arg, br))
|
||||
.find_map(|arg| find_component_for_bound_region(tcx, arg, anon_reg.region_def_id))
|
||||
.map(|ty| (ty, fn_sig))
|
||||
}
|
||||
|
||||
|
@ -46,9 +45,9 @@ pub fn find_anon_type<'tcx>(
|
|||
fn find_component_for_bound_region<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
arg: &'tcx hir::Ty<'tcx>,
|
||||
br: &ty::BoundRegionKind,
|
||||
region_def_id: DefId,
|
||||
) -> Option<&'tcx hir::Ty<'tcx>> {
|
||||
FindNestedTypeVisitor { tcx, bound_region: *br, current_index: ty::INNERMOST }
|
||||
FindNestedTypeVisitor { tcx, region_def_id, current_index: ty::INNERMOST }
|
||||
.visit_ty(arg)
|
||||
.break_value()
|
||||
}
|
||||
|
@ -62,9 +61,8 @@ fn find_component_for_bound_region<'tcx>(
|
|||
// specific part of the type in the error message.
|
||||
struct FindNestedTypeVisitor<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
// The bound_region corresponding to the Refree(freeregion)
|
||||
// associated with the anonymous region we are looking for.
|
||||
bound_region: ty::BoundRegionKind,
|
||||
// The `DefId` of the region we're looking for.
|
||||
region_def_id: DefId,
|
||||
current_index: ty::DebruijnIndex,
|
||||
}
|
||||
|
||||
|
@ -96,16 +94,13 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
|
|||
hir::TyKind::Ref(lifetime, _) => {
|
||||
// the lifetime of the Ref
|
||||
let hir_id = lifetime.hir_id;
|
||||
match (self.tcx.named_bound_var(hir_id), self.bound_region) {
|
||||
match self.tcx.named_bound_var(hir_id) {
|
||||
// Find the index of the named region that was part of the
|
||||
// error. We will then search the function parameters for a bound
|
||||
// region at the right depth with the same index
|
||||
(
|
||||
Some(rbv::ResolvedArg::EarlyBound(id)),
|
||||
ty::BoundRegionKind::Named(def_id, _),
|
||||
) => {
|
||||
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
|
||||
if id.to_def_id() == def_id {
|
||||
Some(rbv::ResolvedArg::EarlyBound(id)) => {
|
||||
debug!("EarlyBound id={:?}", id);
|
||||
if id.to_def_id() == self.region_def_id {
|
||||
return ControlFlow::Break(arg);
|
||||
}
|
||||
}
|
||||
|
@ -113,31 +108,25 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
|
|||
// Find the index of the named region that was part of the
|
||||
// error. We will then search the function parameters for a bound
|
||||
// region at the right depth with the same index
|
||||
(
|
||||
Some(rbv::ResolvedArg::LateBound(debruijn_index, _, id)),
|
||||
ty::BoundRegionKind::Named(def_id, _),
|
||||
) => {
|
||||
Some(rbv::ResolvedArg::LateBound(debruijn_index, _, id)) => {
|
||||
debug!(
|
||||
"FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
|
||||
debruijn_index
|
||||
);
|
||||
debug!("LateBound id={:?} def_id={:?}", id, def_id);
|
||||
if debruijn_index == self.current_index && id.to_def_id() == def_id {
|
||||
debug!("LateBound id={:?}", id);
|
||||
if debruijn_index == self.current_index
|
||||
&& id.to_def_id() == self.region_def_id
|
||||
{
|
||||
return ControlFlow::Break(arg);
|
||||
}
|
||||
}
|
||||
|
||||
(
|
||||
Some(
|
||||
rbv::ResolvedArg::StaticLifetime
|
||||
| rbv::ResolvedArg::Free(_, _)
|
||||
| rbv::ResolvedArg::EarlyBound(_)
|
||||
| rbv::ResolvedArg::LateBound(_, _, _)
|
||||
| rbv::ResolvedArg::Error(_),
|
||||
)
|
||||
| None,
|
||||
_,
|
||||
) => {
|
||||
Some(
|
||||
rbv::ResolvedArg::StaticLifetime
|
||||
| rbv::ResolvedArg::Free(_, _)
|
||||
| rbv::ResolvedArg::Error(_),
|
||||
)
|
||||
| None => {
|
||||
debug!("no arg found");
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +140,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
|
|||
return if intravisit::walk_ty(
|
||||
&mut TyPathVisitor {
|
||||
tcx: self.tcx,
|
||||
bound_region: self.bound_region,
|
||||
region_def_id: self.region_def_id,
|
||||
current_index: self.current_index,
|
||||
},
|
||||
arg,
|
||||
|
@ -179,7 +168,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
|
|||
// specific part of the type in the error message.
|
||||
struct TyPathVisitor<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
bound_region: ty::BoundRegionKind,
|
||||
region_def_id: DefId,
|
||||
current_index: ty::DebruijnIndex,
|
||||
}
|
||||
|
||||
|
@ -192,38 +181,29 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_lifetime(&mut self, lifetime: &hir::Lifetime) -> Self::Result {
|
||||
match (self.tcx.named_bound_var(lifetime.hir_id), self.bound_region) {
|
||||
match self.tcx.named_bound_var(lifetime.hir_id) {
|
||||
// the lifetime of the TyPath!
|
||||
(Some(rbv::ResolvedArg::EarlyBound(id)), ty::BoundRegionKind::Named(def_id, _)) => {
|
||||
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
|
||||
if id.to_def_id() == def_id {
|
||||
Some(rbv::ResolvedArg::EarlyBound(id)) => {
|
||||
debug!("EarlyBound id={:?}", id);
|
||||
if id.to_def_id() == self.region_def_id {
|
||||
return ControlFlow::Break(());
|
||||
}
|
||||
}
|
||||
|
||||
(
|
||||
Some(rbv::ResolvedArg::LateBound(debruijn_index, _, id)),
|
||||
ty::BoundRegionKind::Named(def_id, _),
|
||||
) => {
|
||||
Some(rbv::ResolvedArg::LateBound(debruijn_index, _, id)) => {
|
||||
debug!("FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}", debruijn_index,);
|
||||
debug!("id={:?}", id);
|
||||
debug!("def_id={:?}", def_id);
|
||||
if debruijn_index == self.current_index && id.to_def_id() == def_id {
|
||||
if debruijn_index == self.current_index && id.to_def_id() == self.region_def_id {
|
||||
return ControlFlow::Break(());
|
||||
}
|
||||
}
|
||||
|
||||
(
|
||||
Some(
|
||||
rbv::ResolvedArg::StaticLifetime
|
||||
| rbv::ResolvedArg::EarlyBound(_)
|
||||
| rbv::ResolvedArg::LateBound(_, _, _)
|
||||
| rbv::ResolvedArg::Free(_, _)
|
||||
| rbv::ResolvedArg::Error(_),
|
||||
)
|
||||
| None,
|
||||
_,
|
||||
) => {
|
||||
Some(
|
||||
rbv::ResolvedArg::StaticLifetime
|
||||
| rbv::ResolvedArg::Free(_, _)
|
||||
| rbv::ResolvedArg::Error(_),
|
||||
)
|
||||
| None => {
|
||||
debug!("no arg found");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,9 +54,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
let param = anon_param_info.param;
|
||||
let new_ty = anon_param_info.param_ty;
|
||||
let new_ty_span = anon_param_info.param_ty_span;
|
||||
let br = anon_param_info.bound_region;
|
||||
let br = anon_param_info.br;
|
||||
let is_first = anon_param_info.is_first;
|
||||
let scope_def_id = region_info.def_id;
|
||||
let scope_def_id = region_info.scope;
|
||||
let is_impl_item = region_info.is_impl_item;
|
||||
|
||||
match br {
|
||||
|
@ -73,7 +73,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
return None;
|
||||
}
|
||||
|
||||
if find_anon_type(self.tcx(), self.generic_param_scope, anon, &br).is_some()
|
||||
if find_anon_type(self.tcx(), self.generic_param_scope, anon).is_some()
|
||||
&& self.is_self_anon(is_first, scope_def_id)
|
||||
{
|
||||
return None;
|
||||
|
|
|
@ -50,7 +50,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
// This may have a closure and it would cause ICE
|
||||
// through `find_param_with_region` (#78262).
|
||||
let anon_reg_sup = tcx.is_suitable_region(self.generic_param_scope, *sup_r)?;
|
||||
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.def_id);
|
||||
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.scope);
|
||||
if fn_returns.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
|
||||
let mut err = self.tcx().dcx().create_err(diag);
|
||||
|
||||
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.def_id);
|
||||
let fn_returns = tcx.return_type_impl_or_dyn_traits(anon_reg_sup.scope);
|
||||
|
||||
let mut override_error_code = None;
|
||||
if let SubregionOrigin::Subtype(box TypeTrace { cause, .. }) = &sup_origin
|
||||
|
@ -250,7 +250,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
Some(arg),
|
||||
captures,
|
||||
Some((param.param_ty_span, param.param_ty.to_string())),
|
||||
Some(anon_reg_sup.def_id),
|
||||
Some(anon_reg_sup.scope),
|
||||
);
|
||||
|
||||
let reported = err.emit();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//! anonymous regions.
|
||||
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_middle::ty::fold::fold_regions;
|
||||
use rustc_middle::ty::{self, Binder, Region, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_span::Span;
|
||||
|
@ -17,8 +17,8 @@ pub struct AnonymousParamInfo<'tcx> {
|
|||
pub param: &'tcx hir::Param<'tcx>,
|
||||
/// The type corresponding to the anonymous region parameter.
|
||||
pub param_ty: Ty<'tcx>,
|
||||
/// The ty::BoundRegionKind corresponding to the anonymous region.
|
||||
pub bound_region: ty::BoundRegionKind,
|
||||
/// The `ty::BoundRegionKind` corresponding to the anonymous region.
|
||||
pub br: ty::BoundRegionKind,
|
||||
/// The `Span` of the parameter type.
|
||||
pub param_ty_span: Span,
|
||||
/// Signals that the argument is the first parameter in the declaration.
|
||||
|
@ -43,7 +43,7 @@ pub fn find_param_with_region<'tcx>(
|
|||
anon_region: Region<'tcx>,
|
||||
replace_region: Region<'tcx>,
|
||||
) -> Option<AnonymousParamInfo<'tcx>> {
|
||||
let (id, bound_region) = match *anon_region {
|
||||
let (id, br) = match *anon_region {
|
||||
ty::ReLateParam(late_param) => (late_param.scope, late_param.bound_region),
|
||||
ty::ReEarlyParam(ebr) => {
|
||||
let region_def = tcx.generics_of(generic_param_scope).region_param(ebr, tcx).def_id;
|
||||
|
@ -96,13 +96,7 @@ pub fn find_param_with_region<'tcx>(
|
|||
let ty_hir_id = fn_decl.inputs[index].hir_id;
|
||||
let param_ty_span = hir.span(ty_hir_id);
|
||||
let is_first = index == 0;
|
||||
AnonymousParamInfo {
|
||||
param,
|
||||
param_ty: new_param_ty,
|
||||
param_ty_span,
|
||||
bound_region,
|
||||
is_first,
|
||||
}
|
||||
AnonymousParamInfo { param, param_ty: new_param_ty, param_ty_span, br, is_first }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -122,7 +116,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
pub(super) fn is_return_type_anon(
|
||||
&self,
|
||||
scope_def_id: LocalDefId,
|
||||
br: ty::BoundRegionKind,
|
||||
region_def_id: DefId,
|
||||
hir_sig: &hir::FnSig<'_>,
|
||||
) -> Option<Span> {
|
||||
let fn_ty = self.tcx().type_of(scope_def_id).instantiate_identity();
|
||||
|
@ -135,8 +129,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
None
|
||||
};
|
||||
return match future_output {
|
||||
Some(output) if self.includes_region(output, br) => Some(span),
|
||||
None if self.includes_region(ret_ty, br) => Some(span),
|
||||
Some(output) if self.includes_region(output, region_def_id) => Some(span),
|
||||
None if self.includes_region(ret_ty, region_def_id) => Some(span),
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
|
@ -146,12 +140,15 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
fn includes_region(
|
||||
&self,
|
||||
ty: Binder<'tcx, impl TypeFoldable<TyCtxt<'tcx>>>,
|
||||
region: ty::BoundRegionKind,
|
||||
region_def_id: DefId,
|
||||
) -> bool {
|
||||
let late_bound_regions = self.tcx().collect_referenced_late_bound_regions(ty);
|
||||
// We are only checking is any region meets the condition so order doesn't matter
|
||||
#[allow(rustc::potential_query_instability)]
|
||||
late_bound_regions.iter().any(|r| *r == region)
|
||||
late_bound_regions.iter().any(|r| match *r {
|
||||
ty::BoundRegionKind::Named(def_id, _) => def_id == region_def_id,
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
|
||||
// Here we check for the case where anonymous region
|
||||
|
|
|
@ -790,7 +790,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
let lifetime_scope = match sub.kind() {
|
||||
ty::ReStatic => hir::def_id::CRATE_DEF_ID,
|
||||
_ => match self.tcx.is_suitable_region(generic_param_scope, sub) {
|
||||
Some(info) => info.def_id,
|
||||
Some(info) => info.scope,
|
||||
None => generic_param_scope,
|
||||
},
|
||||
};
|
||||
|
@ -864,13 +864,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
let (lifetime_def_id, lifetime_scope) =
|
||||
match self.tcx.is_suitable_region(generic_param_scope, lifetime) {
|
||||
Some(info) if !lifetime.has_name() => {
|
||||
(info.bound_region.get_id().unwrap().expect_local(), info.def_id)
|
||||
}
|
||||
_ => return lifetime.get_name_or_anon().to_string(),
|
||||
};
|
||||
let (lifetime_def_id, lifetime_scope) = match self
|
||||
.tcx
|
||||
.is_suitable_region(generic_param_scope, lifetime)
|
||||
{
|
||||
Some(info) if !lifetime.has_name() => (info.region_def_id.expect_local(), info.scope),
|
||||
_ => return lifetime.get_name_or_anon().to_string(),
|
||||
};
|
||||
|
||||
let new_lt = {
|
||||
let generics = self.tcx.generics_of(lifetime_scope);
|
||||
|
@ -1097,8 +1097,7 @@ fn msg_span_from_named_region<'tcx>(
|
|||
}
|
||||
ty::ReLateParam(ref fr) => {
|
||||
if !fr.bound_region.is_named()
|
||||
&& let Some((ty, _)) =
|
||||
find_anon_type(tcx, generic_param_scope, region, &fr.bound_region)
|
||||
&& let Some((ty, _)) = find_anon_type(tcx, generic_param_scope, region)
|
||||
{
|
||||
("the anonymous lifetime defined here".to_string(), Some(ty.span))
|
||||
} else {
|
||||
|
|
|
@ -517,7 +517,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
|
|||
return false;
|
||||
};
|
||||
|
||||
let node = self.tcx.hir_node_by_def_id(anon_reg.def_id);
|
||||
let node = self.tcx.hir_node_by_def_id(anon_reg.scope);
|
||||
let is_impl = matches!(&node, hir::Node::ImplItem(_));
|
||||
let (generics, parent_generics) = match node {
|
||||
hir::Node::Item(&hir::Item {
|
||||
|
@ -527,7 +527,7 @@ impl Subdiagnostic for AddLifetimeParamsSuggestion<'_> {
|
|||
| hir::Node::TraitItem(&hir::TraitItem { ref generics, .. })
|
||||
| hir::Node::ImplItem(&hir::ImplItem { ref generics, .. }) => (
|
||||
generics,
|
||||
match self.tcx.parent_hir_node(self.tcx.local_def_id_to_hir_id(anon_reg.def_id))
|
||||
match self.tcx.parent_hir_node(self.tcx.local_def_id_to_hir_id(anon_reg.scope))
|
||||
{
|
||||
hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Trait(_, _, ref generics, ..),
|
||||
|
|
|
@ -41,8 +41,7 @@ impl<'a> DescriptionCtx<'a> {
|
|||
}
|
||||
ty::ReLateParam(ref fr) => {
|
||||
if !fr.bound_region.is_named()
|
||||
&& let Some((ty, _)) =
|
||||
find_anon_type(tcx, generic_param_scope, region, &fr.bound_region)
|
||||
&& let Some((ty, _)) = find_anon_type(tcx, generic_param_scope, region)
|
||||
{
|
||||
(Some(ty.span), "defined_here", String::new())
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue