Skip to content

Commit c8a0819

Browse files
Auto merge of #150923 - matthiaskrgr:rollup-6NslXw7, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - #148196 (Implement create_dir_all() to operate iteratively instead of recursively) - #150494 ( Fix dso_local for external statics with linkage) - #150788 (THIR patterns: Replace `AscribeUserType` and `ExpandedConstant` wrappers with per-node data) - #150799 (Fix ICE: can't type-check body of DefId for issue #148729) - #150804 (Remove std_detect_file_io and std_detect_dlsym_getauxval features) - #150852 (std: sys: fs: uefi: Implement File::write) - #150871 (Use f64 NaN in documentation instead of sqrt(-1.0)) - #150878 (Emit an error for linking staticlibs on BPF) - #150911 (Add missing documentation for globs feature) - #150913 (compiler: Forward attributes to eii-expanded macros) - #150916 (Once again, reorganize the EII tests a bit) r? @ghost
2 parents ad04f76 + f094066 commit c8a0819

66 files changed

Lines changed: 598 additions & 480 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_builtin_macros/src/eii.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ fn eii_(
133133
macro_name,
134134
foreign_item_name,
135135
impl_unsafe,
136+
&attrs_from_decl,
136137
)));
137138

138139
return_items.into_iter().map(wrap_item).collect()
@@ -416,9 +417,14 @@ fn generate_attribute_macro_to_implement(
416417
macro_name: Ident,
417418
foreign_item_name: Ident,
418419
impl_unsafe: bool,
420+
attrs_from_decl: &[Attribute],
419421
) -> ast::Item {
420422
let mut macro_attrs = ThinVec::new();
421423

424+
// To avoid e.g. `error: attribute macro has missing stability attribute`
425+
// errors for eii's in std.
426+
macro_attrs.extend_from_slice(attrs_from_decl);
427+
422428
// #[builtin_macro(eii_shared_macro)]
423429
macro_attrs.push(ecx.attr_nested_word(sym::rustc_builtin_macro, sym::eii_shared_macro, span));
424430

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ fn check_and_apply_linkage<'ll, 'tcx>(
187187
};
188188
llvm::set_linkage(g1, base::linkage_to_llvm(linkage));
189189

190+
// Normally this is done in `get_static_inner`, but when as we generate an internal global,
191+
// it will apply the dso_local to the internal global instead, so do it here, too.
192+
cx.assume_dso_local(g1, true);
193+
190194
// Declare an internal global `extern_with_linkage_foo` which
191195
// is initialized with the address of `foo`. If `foo` is
192196
// discarded during linking (for example, if `foo` has weak

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ codegen_ssa_archive_build_failure = failed to build archive at `{$path}`: {$erro
1010
1111
codegen_ssa_binary_output_to_tty = option `-o` or `--emit` is used to write binary output type `{$shorthand}` to stdout, but stdout is a tty
1212
13+
codegen_ssa_bpf_staticlib_not_supported = linking static libraries is not supported for BPF
14+
1315
codegen_ssa_cgu_not_recorded =
1416
CGU-reuse for `{$cgu_user_name}` is (mangled: `{$cgu_name}`) was not recorded
1517

compiler/rustc_codegen_ssa/src/back/archive.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ use tracing::trace;
2222

2323
use super::metadata::{create_compressed_metadata_file, search_for_section};
2424
use crate::common;
25-
// Re-exporting for rustc_codegen_llvm::back::archive
26-
pub use crate::errors::{ArchiveBuildFailure, ExtractBundledLibsError, UnknownArchiveKind};
25+
// Public for ArchiveBuilderBuilder::extract_bundled_libs
26+
pub use crate::errors::ExtractBundledLibsError;
2727
use crate::errors::{
28-
DlltoolFailImportLibrary, ErrorCallingDllTool, ErrorCreatingImportLibrary, ErrorWritingDEFFile,
28+
ArchiveBuildFailure, DlltoolFailImportLibrary, ErrorCallingDllTool, ErrorCreatingImportLibrary,
29+
ErrorWritingDEFFile, UnknownArchiveKind,
2930
};
3031

3132
/// An item to be included in an import library.

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,7 @@ impl<'a> Linker for BpfLinker<'a> {
20752075
}
20762076

20772077
fn link_staticlib_by_name(&mut self, _name: &str, _verbatim: bool, _whole_archive: bool) {
2078-
panic!("staticlibs not supported")
2078+
self.sess.dcx().emit_fatal(errors::BpfStaticlibNotSupported)
20792079
}
20802080

20812081
fn link_staticlib_by_path(&mut self, path: &Path, _whole_archive: bool) {

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ pub(crate) struct RlibArchiveBuildFailure {
661661
}
662662

663663
#[derive(Diagnostic)]
664-
// Public for rustc_codegen_llvm::back::archive
664+
// Public for ArchiveBuilderBuilder::extract_bundled_libs
665665
pub enum ExtractBundledLibsError<'a> {
666666
#[diag(codegen_ssa_extract_bundled_libs_open_file)]
667667
OpenFile { rlib: &'a Path, error: Box<dyn std::error::Error> },
@@ -700,19 +700,21 @@ pub(crate) struct UnsupportedLinkSelfContained;
700700

701701
#[derive(Diagnostic)]
702702
#[diag(codegen_ssa_archive_build_failure)]
703-
// Public for rustc_codegen_llvm::back::archive
704-
pub struct ArchiveBuildFailure {
703+
pub(crate) struct ArchiveBuildFailure {
705704
pub path: PathBuf,
706705
pub error: std::io::Error,
707706
}
708707

709708
#[derive(Diagnostic)]
710709
#[diag(codegen_ssa_unknown_archive_kind)]
711-
// Public for rustc_codegen_llvm::back::archive
712-
pub struct UnknownArchiveKind<'a> {
710+
pub(crate) struct UnknownArchiveKind<'a> {
713711
pub kind: &'a str,
714712
}
715713

714+
#[derive(Diagnostic)]
715+
#[diag(codegen_ssa_bpf_staticlib_not_supported)]
716+
pub(crate) struct BpfStaticlibNotSupported;
717+
716718
#[derive(Diagnostic)]
717719
#[diag(codegen_ssa_multiple_main_functions)]
718720
#[help]

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
// having basically only two use-cases that act in different ways.
77

88
use rustc_errors::ErrorGuaranteed;
9-
use rustc_hir::attrs::AttributeKind;
10-
use rustc_hir::def::DefKind;
11-
use rustc_hir::{LangItem, find_attr};
9+
use rustc_hir::LangItem;
1210
use rustc_infer::infer::TyCtxtInferExt;
1311
use rustc_middle::mir::*;
1412
use rustc_middle::ty::{self, AdtDef, Ty};
@@ -366,14 +364,10 @@ where
366364
// check performed after the promotion. Verify that with an assertion.
367365
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
368366

369-
// Avoid looking at attrs of anon consts as that will ICE
370-
let is_type_const_item =
371-
matches!(cx.tcx.def_kind(def), DefKind::Const | DefKind::AssocConst)
372-
&& find_attr!(cx.tcx.get_all_attrs(def), AttributeKind::TypeConst(_));
373-
374367
// Don't peak inside trait associated constants, also `#[type_const] const` items
375368
// don't have bodies so there's nothing to look at
376-
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() && !is_type_const_item {
369+
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() && !cx.tcx.is_type_const(def)
370+
{
377371
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def);
378372

379373
if !Q::in_qualifs(&qualifs) {

compiler/rustc_feature/src/accepted.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ declare_features! (
235235
(accepted, generic_param_attrs, "1.27.0", Some(48848)),
236236
/// Allows the `#[global_allocator]` attribute.
237237
(accepted, global_allocator, "1.28.0", Some(27389)),
238-
// FIXME: explain `globs`.
238+
/// Allows globs imports (`use module::*;`) to import all public items from a module.
239239
(accepted, globs, "1.0.0", None),
240240
/// Allows using `..=X` as a pattern.
241241
(accepted, half_open_range_patterns, "1.66.0", Some(67264)),

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,22 @@ fn infer_placeholder_type<'tcx>(
420420
kind: &'static str,
421421
) -> Ty<'tcx> {
422422
let tcx = cx.tcx();
423-
let ty = tcx.typeck(def_id).node_type(hir_id);
423+
// If the type is omitted on a #[type_const] we can't run
424+
// type check on since that requires the const have a body
425+
// which type_consts don't.
426+
let ty = if tcx.is_type_const(def_id.to_def_id()) {
427+
if let Some(trait_item_def_id) = tcx.trait_item_of(def_id.to_def_id()) {
428+
tcx.type_of(trait_item_def_id).instantiate_identity()
429+
} else {
430+
Ty::new_error_with_message(
431+
tcx,
432+
ty_span,
433+
"constant with #[type_const] requires an explicit type",
434+
)
435+
}
436+
} else {
437+
tcx.typeck(def_id).node_type(hir_id)
438+
};
424439

425440
// If this came from a free `const` or `static mut?` item,
426441
// then the user may have written e.g. `const A = 42;`.

compiler/rustc_middle/src/thir.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,26 @@ pub struct FieldPat<'tcx> {
643643
pub pattern: Pat<'tcx>,
644644
}
645645

646+
/// Additional per-node data that is not present on most THIR pattern nodes.
647+
#[derive(Clone, Debug, Default, HashStable, TypeVisitable)]
648+
pub struct PatExtra<'tcx> {
649+
/// If present, this node represents a named constant that was lowered to
650+
/// a pattern using `const_to_pat`.
651+
///
652+
/// This is used by some diagnostics for non-exhaustive matches, to map
653+
/// the pattern node back to the `DefId` of its original constant.
654+
pub expanded_const: Option<DefId>,
655+
656+
/// User-written types that must be preserved into MIR so that they can be
657+
/// checked.
658+
pub ascriptions: Vec<Ascription<'tcx>>,
659+
}
660+
646661
#[derive(Clone, Debug, HashStable, TypeVisitable)]
647662
pub struct Pat<'tcx> {
648663
pub ty: Ty<'tcx>,
649664
pub span: Span,
665+
pub extra: Option<Box<PatExtra<'tcx>>>,
650666
pub kind: PatKind<'tcx>,
651667
}
652668

@@ -762,11 +778,6 @@ pub enum PatKind<'tcx> {
762778
/// A wildcard pattern: `_`.
763779
Wild,
764780

765-
AscribeUserType {
766-
ascription: Ascription<'tcx>,
767-
subpattern: Box<Pat<'tcx>>,
768-
},
769-
770781
/// `x`, `ref x`, `x @ P`, etc.
771782
Binding {
772783
name: Symbol,
@@ -831,21 +842,6 @@ pub enum PatKind<'tcx> {
831842
value: ty::Value<'tcx>,
832843
},
833844

834-
/// Wrapper node representing a named constant that was lowered to a pattern
835-
/// using `const_to_pat`.
836-
///
837-
/// This is used by some diagnostics for non-exhaustive matches, to map
838-
/// the pattern node back to the `DefId` of its original constant.
839-
///
840-
/// FIXME(#150498): Can we make this an `Option<DefId>` field on `Pat`
841-
/// instead, so that non-diagnostic code can ignore it more easily?
842-
ExpandedConstant {
843-
/// [DefId] of the constant item.
844-
def_id: DefId,
845-
/// The pattern that the constant lowered to.
846-
subpattern: Box<Pat<'tcx>>,
847-
},
848-
849845
Range(Arc<PatRange<'tcx>>),
850846

851847
/// Matches against a slice, checking the length and extracting elements.
@@ -1119,7 +1115,7 @@ mod size_asserts {
11191115
static_assert_size!(Block, 48);
11201116
static_assert_size!(Expr<'_>, 64);
11211117
static_assert_size!(ExprKind<'_>, 40);
1122-
static_assert_size!(Pat<'_>, 64);
1118+
static_assert_size!(Pat<'_>, 72);
11231119
static_assert_size!(PatKind<'_>, 48);
11241120
static_assert_size!(Stmt<'_>, 48);
11251121
static_assert_size!(StmtKind<'_>, 48);

0 commit comments

Comments
 (0)