Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #85125

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,9 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
if !cx.codegen_unit().contains_item(&MonoItem::Fn(instance)) {
return None;
}
} else {
// FIXME: Add support for non-local main fn codegen
let span = cx.tcx().main_def.unwrap().span;
let n = 28937;
cx.sess()
.struct_span_err(span, "entry symbol `main` from foreign crate is not yet supported.")
.note(&format!(
"see issue #{} <https://github.com/rust-lang/rust/issues/{}> \
for more information",
n, n,
))
.emit();
cx.sess().abort_if_errors();
bug!();
} else if !cx.codegen_unit().is_primary() {
// We want to create the wrapper only when the codegen unit is the primary one
return None;
}

let main_llfn = cx.get_fn_addr(instance);
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,6 @@ declare_features! (
/// Allows using non lexical lifetimes (RFC 2094).
(active, nll, "1.0.0", Some(43234), None),

/// Allows the definition of `const` functions with some advanced features.
(active, const_fn, "1.2.0", Some(57563), None),

/// Allows associated type defaults.
(active, associated_type_defaults, "1.2.0", Some(29661), None),

Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ declare_features! (
(removed, main, "1.53.0", Some(29634), None, None),
(removed, pub_macro_rules, "1.53.0", Some(78855), None,
Some("removed due to being incomplete, in particular it does not work across crates")),
/// Allows the definition of `const` functions with some advanced features.
(removed, const_fn, "1.54.0", Some(57563), None,
Some("split into finer-grained feature gates")),

// -------------------------------------------------------------------------
// feature-group-end: removed features
Expand Down
17 changes: 11 additions & 6 deletions compiler/rustc_lint/src/non_fmt_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_errors::{pluralize, Applicability};
use rustc_hir as hir;
use rustc_middle::ty;
use rustc_parse_format::{ParseMode, Parser, Piece};
use rustc_span::{sym, symbol::kw, InnerSpan, Span, Symbol};
use rustc_span::{hygiene, sym, symbol::kw, symbol::SymbolStr, InnerSpan, Span, Symbol};

declare_lint! {
/// The `non_fmt_panic` lint detects `panic!(..)` invocations where the first
Expand Down Expand Up @@ -67,7 +67,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc

// The argument is *not* a string literal.

let (span, panic) = panic_call(cx, f);
let (span, panic, symbol_str) = panic_call(cx, f);

// Find the span of the argument to `panic!()`, before expansion in the
// case of `panic!(some_macro!())`.
Expand Down Expand Up @@ -95,7 +95,7 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
}
if arg_macro.map_or(false, |id| cx.tcx.is_diagnostic_item(sym::format_macro, id)) {
// A case of `panic!(format!(..))`.
l.note("the panic!() macro supports formatting, so there's no need for the format!() macro here");
l.note(format!("the {}!() macro supports formatting, so there's no need for the format!() macro here", symbol_str).as_str());
if let Some((open, close, _)) = find_delimiters(cx, arg_span) {
l.multipart_suggestion(
"remove the `format!(..)` macro call",
Expand Down Expand Up @@ -160,7 +160,7 @@ fn check_panic_str<'tcx>(
Parser::new(fmt.as_ref(), style, snippet.clone(), false, ParseMode::Format);
let n_arguments = (&mut fmt_parser).filter(|a| matches!(a, Piece::NextArgument(_))).count();

let (span, _) = panic_call(cx, f);
let (span, _, _) = panic_call(cx, f);

if n_arguments > 0 && fmt_parser.errors.is_empty() {
let arg_spans: Vec<_> = match &fmt_parser.arg_places[..] {
Expand Down Expand Up @@ -230,7 +230,7 @@ fn find_delimiters<'tcx>(cx: &LateContext<'tcx>, span: Span) -> Option<(Span, Sp
))
}

fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span, Symbol) {
fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span, Symbol, SymbolStr) {
let mut expn = f.span.ctxt().outer_expn_data();

let mut panic_macro = kw::Empty;
Expand All @@ -248,5 +248,10 @@ fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span,
}
}

(expn.call_site, panic_macro)
let macro_symbol = if let hygiene::ExpnKind::Macro(_, symbol) = expn.kind {
symbol
} else {
Symbol::intern("panic")
};
(expn.call_site, panic_macro, macro_symbol.as_str())
}
12 changes: 11 additions & 1 deletion compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ pub struct CodegenUnit<'tcx> {
name: Symbol,
items: FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)>,
size_estimate: Option<usize>,
primary: bool,
}

/// Specifies the linkage type for a `MonoItem`.
Expand Down Expand Up @@ -258,7 +259,7 @@ pub enum Visibility {

impl<'tcx> CodegenUnit<'tcx> {
pub fn new(name: Symbol) -> CodegenUnit<'tcx> {
CodegenUnit { name, items: Default::default(), size_estimate: None }
CodegenUnit { name, items: Default::default(), size_estimate: None, primary: false }
}

pub fn name(&self) -> Symbol {
Expand All @@ -269,6 +270,14 @@ impl<'tcx> CodegenUnit<'tcx> {
self.name = name;
}

pub fn is_primary(&self) -> bool {
self.primary
}

pub fn make_primary(&mut self) {
self.primary = true;
}

pub fn items(&self) -> &FxHashMap<MonoItem<'tcx>, (Linkage, Visibility)> {
&self.items
}
Expand Down Expand Up @@ -378,6 +387,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for CodegenUnit<'tcx> {
name,
// The size estimate is not relevant to the hash
size_estimate: _,
primary: _,
} = *self;

name.hash_stable(hcx, hasher);
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_mir/src/monomorphize/partitioning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,14 @@ fn collect_and_partition_mono_items<'tcx>(
let (codegen_units, _) = tcx.sess.time("partition_and_assert_distinct_symbols", || {
sync::join(
|| {
&*tcx.arena.alloc_from_iter(partition(
let mut codegen_units = partition(
tcx,
&mut items.iter().cloned(),
tcx.sess.codegen_units(),
&inlining_map,
))
);
codegen_units[0].make_primary();
&*tcx.arena.alloc_from_iter(codegen_units)
},
|| assert_symbols_are_distinct(tcx, items.iter()),
)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ impl<'a> Parser<'a> {
let span = expr.span;

match &expr.kind {
// Not gated to supporte things like `doc = $expr` that work on stable.
// Not gated to support things like `doc = $expr` that work on stable.
_ if is_interpolated_expr => {}
ExprKind::Lit(lit) if lit.kind.is_unsuffixed() => {}
_ => self.sess.gated_spans.gate(sym::extended_key_value_attributes, span),
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,13 @@ pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateCo
user_cfg
}

pub(super) fn build_target_config(opts: &Options, target_override: Option<Target>) -> Target {
let target_result = target_override.map_or_else(|| Target::search(&opts.target_triple), Ok);
pub(super) fn build_target_config(
opts: &Options,
target_override: Option<Target>,
sysroot: &PathBuf,
) -> Target {
let target_result =
target_override.map_or_else(|| Target::search(&opts.target_triple, sysroot), Ok);
let target = target_result.unwrap_or_else(|e| {
early_error(
opts.error_format,
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,9 +1276,14 @@ pub fn build_session(
DiagnosticOutput::Raw(write) => Some(write),
};

let target_cfg = config::build_target_config(&sopts, target_override);
let sysroot = match &sopts.maybe_sysroot {
Some(sysroot) => sysroot.clone(),
None => filesearch::get_or_default_sysroot(),
};

let target_cfg = config::build_target_config(&sopts, target_override, &sysroot);
let host_triple = TargetTriple::from_triple(config::host_triple());
let host = Target::search(&host_triple).unwrap_or_else(|e| {
let host = Target::search(&host_triple, &sysroot).unwrap_or_else(|e| {
early_error(sopts.error_format, &format!("Error loading host specification: {}", e))
});

Expand Down Expand Up @@ -1325,10 +1330,6 @@ pub fn build_session(

let mut parse_sess = ParseSess::with_span_handler(span_diagnostic, source_map);
parse_sess.assume_incomplete_release = sopts.debugging_opts.assume_incomplete_release;
let sysroot = match &sopts.maybe_sysroot {
Some(sysroot) => sysroot.clone(),
None => filesearch::get_or_default_sysroot(),
};

let host_triple = config::host_triple();
let target_triple = sopts.target_triple.triple();
Expand Down
17 changes: 13 additions & 4 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1898,13 +1898,15 @@ impl Target {
}

/// Search RUST_TARGET_PATH for a JSON file specifying the given target
/// triple. Note that it could also just be a bare filename already, so also
/// triple. If none is found, look for a file called `target.json` inside
/// the sysroot under the target-triple's `rustlib` directory.
/// Note that it could also just be a bare filename already, so also
/// check for that. If one of the hardcoded targets we know about, just
/// return it directly.
///
/// The error string could come from any of the APIs called, including
/// filesystem access and JSON decoding.
pub fn search(target_triple: &TargetTriple) -> Result<Target, String> {
pub fn search(target_triple: &TargetTriple, sysroot: &PathBuf) -> Result<Target, String> {
use rustc_serialize::json;
use std::env;
use std::fs;
Expand All @@ -1931,14 +1933,21 @@ impl Target {

let target_path = env::var_os("RUST_TARGET_PATH").unwrap_or_default();

// FIXME 16351: add a sane default search path?

for dir in env::split_paths(&target_path) {
let p = dir.join(&path);
if p.is_file() {
return load_file(&p);
}
}

// Additionally look in the sysroot under `lib/rustlib/<triple>/target.json`
// as a fallback.
let p =
sysroot.join("lib").join("rustlib").join(&target_triple).join("target.json");
if p.is_file() {
return load_file(&p);
}

Err(format!("Could not find specification for target {:?}", target_triple))
}
TargetTriple::TargetPath(ref target_path) => {
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@
#![feature(const_cstr_unchecked)]
#![feature(const_fn_floating_point_arithmetic)]
#![feature(const_fn_transmute)]
#![feature(const_fn)]
#![feature(const_fn_fn_ptr_basics)]
#![feature(const_io_structs)]
#![feature(const_ip)]
Expand Down
10 changes: 0 additions & 10 deletions src/doc/unstable-book/src/language-features/const-fn.md

This file was deleted.

16 changes: 4 additions & 12 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,7 @@ impl Clean<Generics> for hir::Generics<'_> {
match param.kind {
GenericParamDefKind::Lifetime => unreachable!(),
GenericParamDefKind::Type { did, ref bounds, .. } => {
cx.impl_trait_bounds
.insert(FakeDefId::new_real(did).into(), bounds.clone());
cx.impl_trait_bounds.insert(did.into(), bounds.clone());
}
GenericParamDefKind::Const { .. } => unreachable!(),
}
Expand Down Expand Up @@ -615,7 +614,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
.collect::<Vec<GenericParamDef>>();

// param index -> [(DefId of trait, associated type name, type)]
let mut impl_trait_proj = FxHashMap::<u32, Vec<(FakeDefId, Symbol, Ty<'tcx>)>>::default();
let mut impl_trait_proj = FxHashMap::<u32, Vec<(DefId, Symbol, Ty<'tcx>)>>::default();

let where_predicates = preds
.predicates
Expand Down Expand Up @@ -687,13 +686,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
if let Some(proj) = impl_trait_proj.remove(&idx) {
for (trait_did, name, rhs) in proj {
let rhs = rhs.clean(cx);
simplify::merge_bounds(
cx,
&mut bounds,
trait_did.expect_real(),
name,
&rhs,
);
simplify::merge_bounds(cx, &mut bounds, trait_did, name, &rhs);
}
}
} else {
Expand Down Expand Up @@ -1183,8 +1176,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
if let Some(new_ty) = cx.ty_substs.get(&did).cloned() {
return new_ty;
}
if let Some(bounds) = cx.impl_trait_bounds.remove(&FakeDefId::new_real(did).into())
{
if let Some(bounds) = cx.impl_trait_bounds.remove(&did.into()) {
return ImplTrait(bounds);
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ impl FakeDefId {
Self::Fake(DefIndex::from(id), krate)
}

crate fn new_real(id: DefId) -> Self {
Self::Real(id)
}

#[inline]
crate fn is_local(self) -> bool {
match self {
Expand Down Expand Up @@ -470,7 +466,7 @@ impl Item {
.filter_map(|ItemLink { link: s, link_text, did, ref fragment }| {
match did {
Some(did) => {
if let Some((mut href, ..)) = href(did.expect_real(), cx) {
if let Some((mut href, ..)) = href(did.clone(), cx) {
if let Some(ref fragment) = *fragment {
href.push('#');
href.push_str(fragment);
Expand Down Expand Up @@ -972,7 +968,7 @@ crate struct ItemLink {
/// This may not be the same as `link` if there was a disambiguator
/// in an intra-doc link (e.g. \[`fn@f`\])
pub(crate) link_text: String,
pub(crate) did: Option<FakeDefId>,
pub(crate) did: Option<DefId>,
/// The url fragment to append to the link
pub(crate) fragment: Option<String>,
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,12 @@ impl<'tcx> Visitor<'tcx> for EmitIgnoredResolutionErrors<'tcx> {
/// for `impl Trait` in argument position.
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
crate enum ImplTraitParam {
DefId(FakeDefId),
DefId(DefId),
ParamIndex(u32),
}

impl From<FakeDefId> for ImplTraitParam {
fn from(did: FakeDefId) -> Self {
impl From<DefId> for ImplTraitParam {
fn from(did: DefId) -> Self {
ImplTraitParam::DefId(did)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ crate struct Cache {
/// When rendering traits, it's often useful to be able to list all
/// implementors of the trait, and this mapping is exactly, that: a mapping
/// of trait ids to the list of known implementors of the trait
crate implementors: FxHashMap<FakeDefId, Vec<Impl>>,
crate implementors: FxHashMap<DefId, Vec<Impl>>,

/// Cache of where external crate documentation can be found.
crate extern_locations: FxHashMap<CrateNum, ExternalLocation>,
Expand Down Expand Up @@ -299,7 +299,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
desc: item
.doc_value()
.map_or_else(String::new, |x| short_markdown_summary(&x.as_str())),
parent: parent.map(FakeDefId::new_real),
parent,
parent_idx: None,
search_type: get_index_search_type(&item, &self.empty_cache, self.tcx),
aliases: item.attrs.get_doc_aliases(),
Expand Down
Loading