Auto merge of #85941 - cjgillot:qresolve, r=Aaron1011
Reduce the amount of untracked state in TyCtxt -- Take 2 Main part of #85153 The offending line (https://github.com/rust-lang/rust/pull/85153#discussion_r642866298) is replaced by a FIXME until the possible bug and the perf concern are both resolved. r? `@Aaron1011`
This commit is contained in:
commit
72568552fd
15 changed files with 139 additions and 122 deletions
|
@ -147,33 +147,36 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(De
|
|||
Some((tcx.hir().local_def_id(hir_id).to_def_id(), EntryFnType::Start))
|
||||
} else if let Some((hir_id, _)) = visitor.attr_main_fn {
|
||||
Some((tcx.hir().local_def_id(hir_id).to_def_id(), EntryFnType::Main))
|
||||
} else if let Some(def_id) = tcx.main_def.and_then(|main_def| main_def.opt_fn_def_id()) {
|
||||
// non-local main imports are handled below
|
||||
if def_id.is_local() {
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
if matches!(tcx.hir().find(hir_id), Some(Node::ForeignItem(_))) {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
tcx.hir().span(hir_id),
|
||||
"the `main` function cannot be declared in an `extern` block",
|
||||
} else {
|
||||
if let Some(main_def) = tcx.resolutions(()).main_def {
|
||||
if let Some(def_id) = main_def.opt_fn_def_id() {
|
||||
// non-local main imports are handled below
|
||||
if def_id.is_local() {
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
if matches!(tcx.hir().find(hir_id), Some(Node::ForeignItem(_))) {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
tcx.hir().span(hir_id),
|
||||
"the `main` function cannot be declared in an `extern` block",
|
||||
)
|
||||
.emit();
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
if main_def.is_import && !tcx.features().imported_main {
|
||||
let span = main_def.span;
|
||||
feature_err(
|
||||
&tcx.sess.parse_sess,
|
||||
sym::imported_main,
|
||||
span,
|
||||
"using an imported function as entry point `main` is experimental",
|
||||
)
|
||||
.emit();
|
||||
return None;
|
||||
}
|
||||
return Some((def_id, EntryFnType::Main));
|
||||
}
|
||||
}
|
||||
|
||||
if tcx.main_def.unwrap().is_import && !tcx.features().imported_main {
|
||||
let span = tcx.main_def.unwrap().span;
|
||||
feature_err(
|
||||
&tcx.sess.parse_sess,
|
||||
sym::imported_main,
|
||||
span,
|
||||
"using an imported function as entry point `main` is experimental",
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
Some((def_id, EntryFnType::Main))
|
||||
} else {
|
||||
no_main_err(tcx, visitor);
|
||||
None
|
||||
}
|
||||
|
@ -223,7 +226,7 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
|
|||
err.note(¬e);
|
||||
}
|
||||
|
||||
if let Some(main_def) = tcx.main_def {
|
||||
if let Some(main_def) = tcx.resolutions(()).main_def {
|
||||
if main_def.opt_fn_def_id().is_none() {
|
||||
// There is something at `crate::main`, but it is not a function definition.
|
||||
err.span_label(main_def.span, &format!("non-function item at `crate::main` is found"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue