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 7 pull requests #113865

Merged
merged 20 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift click to select a range
662e9d0
add test for incomplete alias bound preference
lcnr Jul 13, 2023
51e1f7a
Simplify foreign_modules.
cjgillot Jul 15, 2023
fdc93f3
Do not fetch HIR in native_libs.
cjgillot Jul 15, 2023
6fb4ce9
Fix invalid display of inlined re-export
GuillaumeGomez Jul 16, 2023
c845a53
Add regression test for #105735
GuillaumeGomez Jul 16, 2023
afec6d2
Remove unneeded `Option<Symbol>` in `foreign_items`
GuillaumeGomez Jul 17, 2023
cc08749
Add the `no-builtins` attribute to functions when `no_builtins` is ap…
DianQK Jul 18, 2023
09743b9
Bless ui tests.
cjgillot Jul 17, 2023
7197979
Fix inline_const with interpolated block
compiler-errors Jul 17, 2023
fe4d1f9
Fix quotes in output
compiler-errors Jul 17, 2023
a872762
Improve error message when closing bracket interpreted as formatting …
compiler-errors Jul 17, 2023
e021191
Fix unit tests
compiler-errors Jul 17, 2023
846cc63
Make it clearer that edition functions are >=, not ==
compiler-errors Jul 16, 2023
c2257b9
Rollup merge of #113444 - lcnr:alias-bound-test, r=compiler-errors
Dylan-DPC Jul 19, 2023
c1d6d32
Rollup merge of #113716 - DianQK:add-no_builtins-to-function, r=pnkfelix
Dylan-DPC Jul 19, 2023
dbb6b1a
Rollup merge of #113754 - cjgillot:simplify-foreign, r=petrochenkov
Dylan-DPC Jul 19, 2023
a47b7b0
Rollup merge of #113765 - compiler-errors:at-least, r=oli-obk
Dylan-DPC Jul 19, 2023
444ac1a
Rollup merge of #113774 - compiler-errors:fill-expr-bracket, r=eholk
Dylan-DPC Jul 19, 2023
c7c8914
Rollup merge of #113785 - GuillaumeGomez:tests/rustdoc/issue-105735-f…
Dylan-DPC Jul 19, 2023
6c3cbcd
Rollup merge of #113803 - compiler-errors:const-interp-block, r=fee1-…
Dylan-DPC Jul 19, 2023
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
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 335,10 @@ pub fn from_fn_attrs<'ll, 'tcx>(
to_add.extend(probestack_attr(cx));
to_add.extend(stackprotector_attr(cx));

if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_BUILTINS) {
to_add.push(llvm::CreateAttrString(cx.llcx, "no-builtins"));
}

if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::COLD) {
to_add.push(AttributeKind::Cold.create_attr(cx.llcx));
}
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
use rustc_ast::{ast, MetaItemKind, NestedMetaItem};
use rustc_ast::{ast, attr, MetaItemKind, NestedMetaItem};
use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr};
use rustc_errors::struct_span_err;
use rustc_hir as hir;
Expand Down Expand Up @@ -60,6 60,14 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER;
}

// When `no_builtins` is applied at the crate level, we should add the
// `no-builtins` attribute to each function to ensure it takes effect in LTO.
let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
let no_builtins = attr::contains_name(crate_attrs, sym::no_builtins);
if no_builtins {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_BUILTINS;
}

let supported_target_features = tcx.supported_target_features(LOCAL_CRATE);

let mut inline_span = None;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 1200,7 @@ fn check_matcher_core<'tt>(
err.span_label(sp, format!("not allowed after `{}` fragments", kind));

if kind == NonterminalKind::PatWithOr
&& sess.edition.rust_2021()
&& sess.edition.at_least_rust_2021()
&& next_token.is_token(&BinOp(token::BinOpToken::Or))
{
let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/astconv/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 86,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> 'o {
));
}

if self_ty.span.edition().rust_2021() {
if self_ty.span.edition().at_least_rust_2021() {
let msg = "trait objects must include the `dyn` keyword";
let label = "add `dyn` keyword before this trait";
let mut diag =
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id)
.and_then(|r| {
// lint bare trait if the method is found in the trait
if span.edition().rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
if span.edition().at_least_rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
diag.emit();
}
Ok(r)
Expand Down Expand Up @@ -890,7 890,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

// emit or cancel the diagnostic for bare traits
if span.edition().rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
if span.edition().at_least_rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
if trait_missing_method {
// cancel the diag for bare traits when meeting `MyTrait::missing_method`
diag.cancel();
Expand All @@ -908,7 908,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
error,
None,
Expectation::NoExpectation,
trait_missing_method && span.edition().rust_2021(), // emits missing method for trait only after edition 2021
trait_missing_method && span.edition().at_least_rust_2021(), // emits missing method for trait only after edition 2021
) {
e.emit();
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/prelude2021.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 32,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);

// Rust 2021 and later is already using the new prelude
if span.rust_2021() {
if span.at_least_rust_2021() {
return;
}

Expand Down Expand Up @@ -203,7 203,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pick: &Pick<'tcx>,
) {
// Rust 2021 and later is already using the new prelude
if span.rust_2021() {
if span.at_least_rust_2021() {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 437,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// this case used to be allowed by the compiler,
// so we do a future-compat lint here for the 2015 edition
// (see https://github.com/rust-lang/rust/issues/46906)
if self.tcx.sess.rust_2018() {
if self.tcx.sess.at_least_rust_2018() {
self.tcx.sess.emit_err(MethodCallOnUnknownRawPointee { span });
} else {
self.tcx.struct_span_lint_hir(
Expand Down Expand Up @@ -1592,7 1592,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
if let Some(method_name) = self.method_name {
// Some trait methods are excluded for arrays before 2021.
// (`array.into_iter()` wants a slice iterator for compatibility.)
if self_ty.is_array() && !method_name.span.rust_2021() {
if self_ty.is_array() && !method_name.span.at_least_rust_2021() {
let trait_def = self.tcx.trait_def(trait_ref.def_id);
if trait_def.skip_array_during_method_dispatch {
return ProbeResult::NoMatch;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 2001,7 @@ fn should_do_rust_2021_incompatible_closure_captures_analysis(
tcx: TyCtxt<'_>,
closure_id: hir::HirId,
) -> bool {
if tcx.sess.rust_2021() {
if tcx.sess.at_least_rust_2021() {
return false;
}

Expand Down Expand Up @@ -2247,5 2247,5 @@ fn truncate_capture_for_optimization(
fn enable_precise_capture(span: Span) -> bool {
// We use span here to ensure that if the closure was generated by a macro with a different
// edition.
span.rust_2021()
span.at_least_rust_2021()
}
17 changes: 13 additions & 4 deletions compiler/rustc_metadata/src/foreign_modules.rs
Original file line number Diff line number Diff line change
@@ -1,19 1,28 @@
use rustc_data_structures::fx::FxIndexMap;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_middle::query::LocalCrate;
use rustc_middle::ty::TyCtxt;
use rustc_session::cstore::ForeignModule;

pub(crate) fn collect(tcx: TyCtxt<'_>) -> Vec<ForeignModule> {
let mut modules = Vec::new();
pub(crate) fn collect(tcx: TyCtxt<'_>, LocalCrate: LocalCrate) -> FxIndexMap<DefId, ForeignModule> {
let mut modules = FxIndexMap::default();

// We need to collect all the `ForeignMod`, even if they are empty.
for id in tcx.hir().items() {
if !matches!(tcx.def_kind(id.owner_id), DefKind::ForeignMod) {
continue;
}

let def_id = id.owner_id.to_def_id();
let item = tcx.hir().item(id);
if let hir::ItemKind::ForeignMod { items, .. } = item.kind {

if let hir::ItemKind::ForeignMod { abi, items } = item.kind {
let foreign_items = items.iter().map(|it| it.id.owner_id.to_def_id()).collect();
modules.push(ForeignModule { foreign_items, def_id: id.owner_id.to_def_id() });
modules.insert(def_id, ForeignModule { def_id, abi, foreign_items });
}
}

modules
}
80 changes: 34 additions & 46 deletions compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
@@ -1,15 1,17 @@
use rustc_ast::{NestedMetaItem, CRATE_NODE_ID};
use rustc_attr as attr;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_middle::query::LocalCrate;
use rustc_middle::ty::{List, ParamEnv, ParamEnvAnd, Ty, TyCtxt};
use rustc_session::config::CrateType;
use rustc_session::cstore::{DllCallingConvention, DllImport, NativeLib, PeImportNameType};
use rustc_session::cstore::{
DllCallingConvention, DllImport, ForeignModule, NativeLib, PeImportNameType,
};
use rustc_session::parse::feature_err;
use rustc_session::search_paths::PathKind;
use rustc_session::utils::NativeLibKind;
use rustc_session::Session;
use rustc_span::def_id::{DefId, LOCAL_CRATE};
use rustc_span::symbol::{sym, Symbol};
use rustc_target::spec::abi::Abi;

Expand Down Expand Up @@ -66,10 68,12 @@ fn find_bundled_library(
None
}

pub(crate) fn collect(tcx: TyCtxt<'_>) -> Vec<NativeLib> {
pub(crate) fn collect(tcx: TyCtxt<'_>, LocalCrate: LocalCrate) -> Vec<NativeLib> {
let mut collector = Collector { tcx, libs: Vec::new() };
for id in tcx.hir().items() {
collector.process_item(id);
if tcx.sess.opts.unstable_opts.link_directives {
for module in tcx.foreign_modules(LOCAL_CRATE).values() {
collector.process_module(module);
}
}
collector.process_command_line();
collector.libs
Expand All @@ -88,29 92,20 @@ struct Collector<'tcx> {
}

impl<'tcx> Collector<'tcx> {
fn process_item(&mut self, id: rustc_hir::ItemId) {
if !matches!(self.tcx.def_kind(id.owner_id), DefKind::ForeignMod) {
return;
}
fn process_module(&mut self, module: &ForeignModule) {
let ForeignModule { def_id, abi, ref foreign_items } = *module;
let def_id = def_id.expect_local();

let it = self.tcx.hir().item(id);
let hir::ItemKind::ForeignMod { abi, items: foreign_mod_items } = it.kind else {
return;
};
let sess = self.tcx.sess;

if matches!(abi, Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic) {
return;
}

// Process all of the #[link(..)]-style arguments
let sess = self.tcx.sess;
let features = self.tcx.features();

if !sess.opts.unstable_opts.link_directives {
return;
}

for m in self.tcx.hir().attrs(it.hir_id()).iter().filter(|a| a.has_name(sym::link)) {
for m in self.tcx.get_attrs(def_id, sym::link) {
let Some(items) = m.meta_item_list() else {
continue;
};
Expand Down Expand Up @@ -340,9 335,9 @@ impl<'tcx> Collector<'tcx> {
if name.as_str().contains('\0') {
sess.emit_err(errors::RawDylibNoNul { span: name_span });
}
foreign_mod_items
foreign_items
.iter()
.map(|child_item| {
.map(|&child_item| {
self.build_dll_import(
abi,
import_name_type.map(|(import_name_type, _)| import_name_type),
Expand All @@ -352,21 347,12 @@ impl<'tcx> Collector<'tcx> {
.collect()
}
_ => {
for child_item in foreign_mod_items {
if self.tcx.def_kind(child_item.id.owner_id).has_codegen_attrs()
&& self
.tcx
.codegen_fn_attrs(child_item.id.owner_id)
.link_ordinal
.is_some()
for &child_item in foreign_items {
if self.tcx.def_kind(child_item).has_codegen_attrs()
&& self.tcx.codegen_fn_attrs(child_item).link_ordinal.is_some()
{
let link_ordinal_attr = self
.tcx
.hir()
.attrs(child_item.id.owner_id.into())
.iter()
.find(|a| a.has_name(sym::link_ordinal))
.unwrap();
let link_ordinal_attr =
self.tcx.get_attr(child_item, sym::link_ordinal).unwrap();
sess.emit_err(errors::LinkOrdinalRawDylib {
span: link_ordinal_attr.span,
});
Expand All @@ -384,7 370,7 @@ impl<'tcx> Collector<'tcx> {
filename,
kind,
cfg,
foreign_module: Some(it.owner_id.to_def_id()),
foreign_module: Some(def_id.to_def_id()),
verbatim,
dll_imports,
});
Expand Down Expand Up @@ -476,10 462,10 @@ impl<'tcx> Collector<'tcx> {
}
}

fn i686_arg_list_size(&self, item: &hir::ForeignItemRef) -> usize {
fn i686_arg_list_size(&self, item: DefId) -> usize {
let argument_types: &List<Ty<'_>> = self.tcx.erase_late_bound_regions(
self.tcx
.type_of(item.id.owner_id)
.type_of(item)
.instantiate_identity()
.fn_sig(self.tcx)
.inputs()
Expand All @@ -505,8 491,10 @@ impl<'tcx> Collector<'tcx> {
&self,
abi: Abi,
import_name_type: Option<PeImportNameType>,
item: &hir::ForeignItemRef,
item: DefId,
) -> DllImport {
let span = self.tcx.def_span(item);

let calling_convention = if self.tcx.sess.target.arch == "x86" {
match abi {
Abi::C { .. } | Abi::Cdecl { .. } => DllCallingConvention::C,
Expand All @@ -520,29 508,29 @@ impl<'tcx> Collector<'tcx> {
DllCallingConvention::Vectorcall(self.i686_arg_list_size(item))
}
_ => {
self.tcx.sess.emit_fatal(errors::UnsupportedAbiI686 { span: item.span });
self.tcx.sess.emit_fatal(errors::UnsupportedAbiI686 { span });
}
}
} else {
match abi {
Abi::C { .. } | Abi::Win64 { .. } | Abi::System { .. } => DllCallingConvention::C,
_ => {
self.tcx.sess.emit_fatal(errors::UnsupportedAbi { span: item.span });
self.tcx.sess.emit_fatal(errors::UnsupportedAbi { span });
}
}
};

let codegen_fn_attrs = self.tcx.codegen_fn_attrs(item.id.owner_id);
let codegen_fn_attrs = self.tcx.codegen_fn_attrs(item);
let import_name_type = codegen_fn_attrs
.link_ordinal
.map_or(import_name_type, |ord| Some(PeImportNameType::Ordinal(ord)));

DllImport {
name: codegen_fn_attrs.link_name.unwrap_or(item.ident.name),
name: codegen_fn_attrs.link_name.unwrap_or(self.tcx.item_name(item)),
import_name_type,
calling_convention,
span: item.span,
is_fn: self.tcx.def_kind(item.id.owner_id).is_fn_like(),
span,
is_fn: self.tcx.def_kind(item).is_fn_like(),
}
}
}
6 changes: 2 additions & 4 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 403,8 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) {
.contains(&id)
})
},
native_libraries: |tcx, LocalCrate| native_libs::collect(tcx),
foreign_modules: |tcx, LocalCrate| {
foreign_modules::collect(tcx).into_iter().map(|m| (m.def_id, m)).collect()
},
native_libraries: native_libs::collect,
foreign_modules: foreign_modules::collect,

// Returns a map from a sufficiently visible external item (i.e., an
// external item that is visible from at least one local module) to a
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/middle/codegen_fn_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 100,8 @@ bitflags! {
const REALLOCATOR = 1 << 18;
/// `#[rustc_allocator_zeroed]`: a hint to LLVM that the function only allocates zeroed memory.
const ALLOCATOR_ZEROED = 1 << 19;
/// `#[no_builtins]`: indicates that disable implicit builtin knowledge of functions for the function.
const NO_BUILTINS = 1 << 20;
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 1579,7 @@ rustc_queries! {
}

/// Returns a list of all `extern` blocks of a crate.
query foreign_modules(_: CrateNum) -> &'tcx FxHashMap<DefId, ForeignModule> {
query foreign_modules(_: CrateNum) -> &'tcx FxIndexMap<DefId, ForeignModule> {
arena_cache
desc { "looking up the foreign modules of a linked crate" }
separate_provide_extern
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 1932,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
self.empty_path = true;
if cnum == LOCAL_CRATE {
if self.tcx.sess.rust_2018() {
if self.tcx.sess.at_least_rust_2018() {
// We add the `crate::` keyword on Rust 2018, only when desired.
if SHOULD_PREFIX_WITH_CRATE.with(|flag| flag.get()) {
write!(self, "{}", kw::Crate)?;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/as_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,5 730,5 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

/// Precise capture is enabled if user is using Rust Edition 2021 or higher.
fn enable_precise_capture(closure_span: Span) -> bool {
closure_span.rust_2021()
closure_span.at_least_rust_2021()
}
Loading
Loading