Auto merge of #84401 - crlf0710:impl_main_by_path, r=petrochenkov
Implement RFC 1260 with feature_name `imported_main`. This is the second extraction part of #84062 plus additional adjustments. This (mostly) implements RFC 1260. However there's still one test case failure in the extern crate case. Maybe `LocalDefId` doesn't work here? I'm not sure. cc https://github.com/rust-lang/rust/issues/28937 r? `@petrochenkov`
This commit is contained in:
commit
bcd696d722
38 changed files with 463 additions and 193 deletions
|
@ -6,7 +6,7 @@ use rustc_data_structures::base_n;
|
|||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||
use rustc_hir::{HirId, ItemId};
|
||||
use rustc_session::config::OptLevel;
|
||||
use rustc_span::source_map::Span;
|
||||
|
@ -93,7 +93,7 @@ impl<'tcx> MonoItem<'tcx> {
|
|||
// indicator, then we'll be creating a globally shared version.
|
||||
if tcx.codegen_fn_attrs(instance.def_id()).contains_extern_indicator()
|
||||
|| !instance.def.generates_cgu_internal_copy(tcx)
|
||||
|| Some(instance.def_id()) == entry_def_id.map(LocalDefId::to_def_id)
|
||||
|| Some(instance.def_id()) == entry_def_id
|
||||
{
|
||||
return InstantiationMode::GloballyShared { may_conflict: false };
|
||||
}
|
||||
|
|
|
@ -1194,7 +1194,7 @@ rustc_queries! {
|
|||
|
||||
/// Identifies the entry-point (e.g., the `main` function) for a given
|
||||
/// crate, returning `None` if there is no entry point (such as for library crates).
|
||||
query entry_fn(_: CrateNum) -> Option<(LocalDefId, EntryFnType)> {
|
||||
query entry_fn(_: CrateNum) -> Option<(DefId, EntryFnType)> {
|
||||
desc { "looking up the entry function of a crate" }
|
||||
}
|
||||
query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {
|
||||
|
|
|
@ -20,8 +20,8 @@ use crate::ty::TyKind::*;
|
|||
use crate::ty::{
|
||||
self, AdtDef, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid,
|
||||
DefIdTree, ExistentialPredicate, FloatTy, FloatVar, FloatVid, GenericParamDefKind, InferConst,
|
||||
InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate,
|
||||
PredicateInner, PredicateKind, ProjectionTy, Region, RegionKind, ReprOptions,
|
||||
InferTy, IntTy, IntVar, IntVid, List, MainDefinition, ParamConst, ParamTy, PolyFnSig,
|
||||
Predicate, PredicateInner, PredicateKind, ProjectionTy, Region, RegionKind, ReprOptions,
|
||||
TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy, Visibility,
|
||||
};
|
||||
use rustc_ast as ast;
|
||||
|
@ -1025,6 +1025,8 @@ pub struct GlobalCtxt<'tcx> {
|
|||
layout_interner: ShardedHashMap<&'tcx Layout, ()>,
|
||||
|
||||
output_filenames: Arc<OutputFilenames>,
|
||||
|
||||
pub main_def: Option<MainDefinition>,
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
|
@ -1185,6 +1187,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
const_stability_interner: Default::default(),
|
||||
alloc_map: Lock::new(interpret::AllocMap::new()),
|
||||
output_filenames: Arc::new(output_filenames.clone()),
|
||||
main_def: resolutions.main_def,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -124,6 +124,20 @@ pub struct ResolverOutputs {
|
|||
/// Extern prelude entries. The value is `true` if the entry was introduced
|
||||
/// via `extern crate` item and not `--extern` option or compiler built-in.
|
||||
pub extern_prelude: FxHashMap<Symbol, bool>,
|
||||
pub main_def: Option<MainDefinition>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct MainDefinition {
|
||||
pub res: Res<ast::NodeId>,
|
||||
pub is_import: bool,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
impl MainDefinition {
|
||||
pub fn opt_fn_def_id(self) -> Option<DefId> {
|
||||
if let Res::Def(DefKind::Fn, def_id) = self.res { Some(def_id) } else { None }
|
||||
}
|
||||
}
|
||||
|
||||
/// The "header" of an impl is everything outside the body: a Self type, a trait
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue