Skip to content

Commit efbaa41

Browse files
committed
Auto merge of rust-lang#77557 - Dylan-DPC:rollup-aib9ptp, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - rust-lang#75853 (Use more intra-doc-links in `core::fmt`) - rust-lang#75928 (Remove trait_selection error message in specific case) - rust-lang#76329 (Add check for doc alias attribute at crate level) - rust-lang#77219 (core::global_allocator docs link to std::alloc::GlobalAlloc) - rust-lang#77395 (BTreeMap: admit the existence of leaf edges in comments) - rust-lang#77407 (Improve build-manifest to work with the improved promote-release) - rust-lang#77426 (Include scope id in SocketAddrV6::Display) - rust-lang#77439 (Fix missing diagnostic span for `impl Trait` with const generics, and add various tests for `min_const_generics` and `const_generics`) - rust-lang#77471 (BTreeMap: refactoring around edges, missed spots) - rust-lang#77512 (Allow `Abort` terminators in all const-contexts) - rust-lang#77514 (Replace some once(x).chain(once(y)) with [x, y] IntoIter) Failed merges: r? `@ghost`
2 parents ced813f + 9dbc9ed commit efbaa41

File tree

116 files changed

+1645
-661
lines changed

Some content is hidden

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

116 files changed

+1645
-661
lines changed

Cargo.lock

+64-8
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,16 @@ dependencies = [
183183
"block-padding",
184184
"byte-tools",
185185
"byteorder",
186-
"generic-array",
186+
"generic-array 0.12.3",
187+
]
188+
189+
[[package]]
190+
name = "block-buffer"
191+
version = "0.9.0"
192+
source = "registry+https://github.com/rust-lang/crates.io-index"
193+
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
194+
dependencies = [
195+
"generic-array 0.14.4",
187196
]
188197

189198
[[package]]
@@ -233,8 +242,11 @@ version = "0.1.0"
233242
dependencies = [
234243
"anyhow",
235244
"flate2",
245+
"hex 0.4.2",
246+
"rayon",
236247
"serde",
237248
"serde_json",
249+
"sha2",
238250
"tar",
239251
"toml",
240252
]
@@ -687,6 +699,12 @@ version = "0.8.0"
687699
source = "registry+https://github.com/rust-lang/crates.io-index"
688700
checksum = "9a21fa21941700a3cd8fcb4091f361a6a712fac632f85d9f487cc892045d55c6"
689701

702+
[[package]]
703+
name = "cpuid-bool"
704+
version = "0.1.2"
705+
source = "registry+https://github.com/rust-lang/crates.io-index"
706+
checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634"
707+
690708
[[package]]
691709
name = "crates-io"
692710
version = "0.31.1"
@@ -884,7 +902,16 @@ version = "0.8.1"
884902
source = "registry+https://github.com/rust-lang/crates.io-index"
885903
checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
886904
dependencies = [
887-
"generic-array",
905+
"generic-array 0.12.3",
906+
]
907+
908+
[[package]]
909+
name = "digest"
910+
version = "0.9.0"
911+
source = "registry+https://github.com/rust-lang/crates.io-index"
912+
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
913+
dependencies = [
914+
"generic-array 0.14.4",
888915
]
889916

890917
[[package]]
@@ -1166,6 +1193,16 @@ dependencies = [
11661193
"typenum",
11671194
]
11681195

1196+
[[package]]
1197+
name = "generic-array"
1198+
version = "0.14.4"
1199+
source = "registry+https://github.com/rust-lang/crates.io-index"
1200+
checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
1201+
dependencies = [
1202+
"typenum",
1203+
"version_check",
1204+
]
1205+
11691206
[[package]]
11701207
name = "getopts"
11711208
version = "0.2.21"
@@ -1835,9 +1872,9 @@ version = "0.8.0"
18351872
source = "registry+https://github.com/rust-lang/crates.io-index"
18361873
checksum = "a18af3dcaf2b0219366cdb4e2af65a6101457b415c3d1a5c71dd9c2b7c77b9c8"
18371874
dependencies = [
1838-
"block-buffer",
1839-
"digest",
1840-
"opaque-debug",
1875+
"block-buffer 0.7.3",
1876+
"digest 0.8.1",
1877+
"opaque-debug 0.2.3",
18411878
]
18421879

18431880
[[package]]
@@ -2097,6 +2134,12 @@ version = "0.2.3"
20972134
source = "registry+https://github.com/rust-lang/crates.io-index"
20982135
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
20992136

2137+
[[package]]
2138+
name = "opaque-debug"
2139+
version = "0.3.0"
2140+
source = "registry+https://github.com/rust-lang/crates.io-index"
2141+
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
2142+
21002143
[[package]]
21012144
name = "open"
21022145
version = "1.4.0"
@@ -4362,10 +4405,23 @@ version = "0.8.2"
43624405
source = "registry+https://github.com/rust-lang/crates.io-index"
43634406
checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df"
43644407
dependencies = [
4365-
"block-buffer",
4366-
"digest",
4408+
"block-buffer 0.7.3",
4409+
"digest 0.8.1",
43674410
"fake-simd",
4368-
"opaque-debug",
4411+
"opaque-debug 0.2.3",
4412+
]
4413+
4414+
[[package]]
4415+
name = "sha2"
4416+
version = "0.9.1"
4417+
source = "registry+https://github.com/rust-lang/crates.io-index"
4418+
checksum = "2933378ddfeda7ea26f48c555bdad8bb446bf8a3d17832dc83e380d444cfb8c1"
4419+
dependencies = [
4420+
"block-buffer 0.9.0",
4421+
"cfg-if",
4422+
"cpuid-bool",
4423+
"digest 0.9.0",
4424+
"opaque-debug 0.3.0",
43694425
]
43704426

43714427
[[package]]

compiler/rustc_feature/src/active.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ declare_features! (
581581
/// Allows `if let` guard in match arms.
582582
(active, if_let_guard, "1.47.0", Some(51114), None),
583583

584-
/// Allows non trivial generic constants which have to be manually propageted upwards.
584+
/// Allows non-trivial generic constants which have to be manually propageted upwards.
585585
(active, const_evaluatable_checked, "1.48.0", Some(76560), None),
586586

587587
/// Allows basic arithmetic on floating point types in a `const fn`.

compiler/rustc_hir/src/def.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ impl<T> PerNS<Option<T>> {
341341

342342
/// Returns an iterator over the items which are `Some`.
343343
pub fn present_items(self) -> impl Iterator<Item = T> {
344-
use std::iter::once;
345-
346-
once(self.type_ns).chain(once(self.value_ns)).chain(once(self.macro_ns)).filter_map(|it| it)
344+
IntoIter::new([self.type_ns, self.value_ns, self.macro_ns]).filter_map(|it| it)
347345
}
348346
}
349347

compiler/rustc_hir/src/target.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ use crate::{Item, ItemKind, TraitItem, TraitItemKind};
99

1010
use std::fmt::{self, Display};
1111

12-
#[derive(Copy, Clone, PartialEq)]
12+
#[derive(Copy, Clone, PartialEq, Debug)]
1313
pub enum MethodKind {
1414
Trait { body: bool },
1515
Inherent,
1616
}
1717

18-
#[derive(Copy, Clone, PartialEq)]
18+
#[derive(Copy, Clone, PartialEq, Debug)]
1919
pub enum Target {
2020
ExternCrate,
2121
Use,

compiler/rustc_mir/src/transform/check_consts/ops.rs

-12
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,6 @@ pub trait NonConstOp: std::fmt::Debug {
4141
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx>;
4242
}
4343

44-
#[derive(Debug)]
45-
pub struct Abort;
46-
impl NonConstOp for Abort {
47-
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
48-
mcf_status_in_item(ccx)
49-
}
50-
51-
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
52-
mcf_build_error(ccx, span, "abort is not stable in const fn")
53-
}
54-
}
55-
5644
#[derive(Debug)]
5745
pub struct FloatingPointOp;
5846
impl NonConstOp for FloatingPointOp {

compiler/rustc_mir/src/transform/check_consts/validation.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,13 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
434434
fn visit_basic_block_data(&mut self, bb: BasicBlock, block: &BasicBlockData<'tcx>) {
435435
trace!("visit_basic_block_data: bb={:?} is_cleanup={:?}", bb, block.is_cleanup);
436436

437-
// Just as the old checker did, we skip const-checking basic blocks on the unwind path.
438-
// These blocks often drop locals that would otherwise be returned from the function.
437+
// We don't const-check basic blocks on the cleanup path since we never unwind during
438+
// const-eval: a panic causes an immediate compile error. In other words, cleanup blocks
439+
// are unreachable during const-eval.
439440
//
440-
// FIXME: This shouldn't be unsound since a panic at compile time will cause a compiler
441-
// error anyway, but maybe we should do more here?
441+
// We can't be more conservative (e.g., by const-checking cleanup blocks anyways) because
442+
// locals that would never be dropped during normal execution are sometimes dropped during
443+
// unwinding, which means backwards-incompatible live-drop errors.
442444
if block.is_cleanup {
443445
return;
444446
}
@@ -874,12 +876,16 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
874876
}
875877

876878
TerminatorKind::InlineAsm { .. } => self.check_op(ops::InlineAsm),
877-
TerminatorKind::Abort => self.check_op(ops::Abort),
878879

879880
TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } => {
880881
self.check_op(ops::Generator(hir::GeneratorKind::Gen))
881882
}
882883

884+
TerminatorKind::Abort => {
885+
// Cleanup blocks are skipped for const checking (see `visit_basic_block_data`).
886+
span_bug!(self.span, "`Abort` terminator outside of cleanup block")
887+
}
888+
883889
TerminatorKind::Assert { .. }
884890
| TerminatorKind::FalseEdge { .. }
885891
| TerminatorKind::FalseUnwind { .. }

compiler/rustc_passes/src/check_attr.rs

+53-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ use rustc_errors::{pluralize, struct_span_err};
1313
use rustc_hir as hir;
1414
use rustc_hir::def_id::LocalDefId;
1515
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
16-
use rustc_hir::{self, FnSig, ForeignItem, ForeignItemKind, HirId, Item, ItemKind, TraitItem};
16+
use rustc_hir::{
17+
self, FnSig, ForeignItem, ForeignItemKind, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID,
18+
};
1719
use rustc_hir::{MethodKind, Target};
1820
use rustc_session::lint::builtin::{CONFLICTING_REPR_HINTS, UNUSED_ATTRIBUTES};
1921
use rustc_session::parse::feature_err;
20-
use rustc_span::symbol::sym;
21-
use rustc_span::Span;
22+
use rustc_span::symbol::{sym, Symbol};
23+
use rustc_span::{Span, DUMMY_SP};
2224

2325
pub(crate) fn target_from_impl_item<'tcx>(
2426
tcx: TyCtxt<'tcx>,
@@ -333,6 +335,17 @@ impl CheckAttrVisitor<'tcx> {
333335
.emit();
334336
return false;
335337
}
338+
if CRATE_HIR_ID == hir_id {
339+
self.tcx
340+
.sess
341+
.struct_span_err(
342+
meta.span(),
343+
"`#![doc(alias = \"...\")]` isn't allowed as a crate \
344+
level attribute",
345+
)
346+
.emit();
347+
return false;
348+
}
336349
}
337350
}
338351
}
@@ -808,9 +821,46 @@ fn is_c_like_enum(item: &Item<'_>) -> bool {
808821
}
809822
}
810823

824+
fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
825+
const ATTRS_TO_CHECK: &[Symbol] = &[
826+
sym::macro_export,
827+
sym::repr,
828+
sym::path,
829+
sym::automatically_derived,
830+
sym::start,
831+
sym::main,
832+
];
833+
834+
for attr in attrs {
835+
for attr_to_check in ATTRS_TO_CHECK {
836+
if tcx.sess.check_name(attr, *attr_to_check) {
837+
tcx.sess
838+
.struct_span_err(
839+
attr.span,
840+
&format!(
841+
"`{}` attribute cannot be used at crate level",
842+
attr_to_check.to_ident_string()
843+
),
844+
)
845+
.emit();
846+
}
847+
}
848+
}
849+
}
850+
811851
fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
812852
tcx.hir()
813853
.visit_item_likes_in_module(module_def_id, &mut CheckAttrVisitor { tcx }.as_deep_visitor());
854+
if module_def_id.is_top_level_module() {
855+
CheckAttrVisitor { tcx }.check_attributes(
856+
CRATE_HIR_ID,
857+
tcx.hir().krate_attrs(),
858+
&DUMMY_SP,
859+
Target::Mod,
860+
None,
861+
);
862+
check_invalid_crate_level_attr(tcx, tcx.hir().krate_attrs());
863+
}
814864
}
815865

816866
pub(crate) fn provide(providers: &mut Providers) {

compiler/rustc_passes/src/entry.rs

+26-18
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,38 @@ fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(LocalDefId, EntryFnType)
7878
// Beware, this is duplicated in `librustc_builtin_macros/test_harness.rs`
7979
// (with `ast::Item`), so make sure to keep them in sync.
8080
fn entry_point_type(sess: &Session, item: &Item<'_>, at_root: bool) -> EntryPointType {
81-
match item.kind {
82-
ItemKind::Fn(..) => {
83-
if sess.contains_name(&item.attrs, sym::start) {
84-
EntryPointType::Start
85-
} else if sess.contains_name(&item.attrs, sym::main) {
86-
EntryPointType::MainAttr
87-
} else if item.ident.name == sym::main {
88-
if at_root {
89-
// This is a top-level function so can be `main`.
90-
EntryPointType::MainNamed
91-
} else {
92-
EntryPointType::OtherMain
93-
}
94-
} else {
95-
EntryPointType::None
96-
}
81+
if sess.contains_name(&item.attrs, sym::start) {
82+
EntryPointType::Start
83+
} else if sess.contains_name(&item.attrs, sym::main) {
84+
EntryPointType::MainAttr
85+
} else if item.ident.name == sym::main {
86+
if at_root {
87+
// This is a top-level function so can be `main`.
88+
EntryPointType::MainNamed
89+
} else {
90+
EntryPointType::OtherMain
9791
}
98-
_ => EntryPointType::None,
92+
} else {
93+
EntryPointType::None
9994
}
10095
}
10196

97+
fn throw_attr_err(sess: &Session, span: Span, attr: &str) {
98+
sess.struct_span_err(span, &format!("`{}` attribute can only be used on functions", attr))
99+
.emit();
100+
}
101+
102102
fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
103103
match entry_point_type(&ctxt.session, item, at_root) {
104+
EntryPointType::None => (),
105+
_ if !matches!(item.kind, ItemKind::Fn(..)) => {
106+
if let Some(attr) = ctxt.session.find_by_name(item.attrs, sym::start) {
107+
throw_attr_err(&ctxt.session, attr.span, "start");
108+
}
109+
if let Some(attr) = ctxt.session.find_by_name(item.attrs, sym::main) {
110+
throw_attr_err(&ctxt.session, attr.span, "main");
111+
}
112+
}
104113
EntryPointType::MainNamed => {
105114
if ctxt.main_fn.is_none() {
106115
ctxt.main_fn = Some((item.hir_id, item.span));
@@ -137,7 +146,6 @@ fn find_item(item: &Item<'_>, ctxt: &mut EntryContext<'_, '_>, at_root: bool) {
137146
.emit();
138147
}
139148
}
140-
EntryPointType::None => (),
141149
}
142150
}
143151

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ impl<'a> Resolver<'a> {
469469
ResolutionError::ParamInNonTrivialAnonConst { name, is_type } => {
470470
let mut err = self.session.struct_span_err(
471471
span,
472-
"generic parameters must not be used inside of non trivial constant values",
472+
"generic parameters must not be used inside of non-trivial constant values",
473473
);
474474
err.span_label(
475475
span,

compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ enum ResolutionError<'a> {
218218
ParamInTyOfConstParam(Symbol),
219219
/// constant values inside of type parameter defaults must not depend on generic parameters.
220220
ParamInAnonConstInTyDefault(Symbol),
221-
/// generic parameters must not be used inside of non trivial constant values.
221+
/// generic parameters must not be used inside of non-trivial constant values.
222222
///
223223
/// This error is only emitted when using `min_const_generics`.
224224
ParamInNonTrivialAnonConst { name: Symbol, is_type: bool },

compiler/rustc_session/src/lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ declare_lint! {
518518
/// ### Example
519519
///
520520
/// ```rust
521-
/// #![macro_export]
521+
/// #![ignore]
522522
/// ```
523523
///
524524
/// {{produces}}

0 commit comments

Comments
 (0)