Skip to content

Commit a931943

Browse files
committed
Auto merge of rust-lang#137040 - jhpratt:rollup-lr17zya, r=jhpratt
Rollup of 11 pull requests Successful merges: - rust-lang#133312 (triagebot: automatically add more rustdoc related labels) - rust-lang#134016 (Stabilize `const_is_char_boundary` and `const_str_split_at`.) - rust-lang#135813 (CI: split i686-mingw job to three free runners) - rust-lang#136879 (Add safe new() to NotAllOnes) - rust-lang#136971 (Add a new check-pass UI test for returning `impl Fn(T) -> impl Trait`) - rust-lang#136983 (Prepare standard library for Rust 2024 migration) - rust-lang#137002 (Fix early lint check desc in query) - rust-lang#137006 (borrowck diagnostics cleanup: remove an unused and a barely-used field) - rust-lang#137026 (Stabilize (and const-stabilize) `integer_sign_cast`) - rust-lang#137028 (mir_build: Clarify some code for lowering `hir::PatExpr` to THIR) - rust-lang#137032 (Decode metadata buffer in one go) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d8810e3 + 8491b54 commit a931943

File tree

64 files changed

+457
-281
lines changed

Some content is hidden

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

64 files changed

+457
-281
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+11-29
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ pub(crate) enum RegionErrorKind<'tcx> {
147147
pub(crate) struct ErrorConstraintInfo<'tcx> {
148148
// fr: outlived_fr
149149
pub(super) fr: RegionVid,
150-
pub(super) fr_is_local: bool,
151150
pub(super) outlived_fr: RegionVid,
152-
pub(super) outlived_fr_is_local: bool,
153151

154152
// Category and span for best blame constraint
155153
pub(super) category: ConstraintCategory<'tcx>,
@@ -471,14 +469,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
471469
fr_is_local, outlived_fr_is_local, category
472470
);
473471

474-
let errci = ErrorConstraintInfo {
475-
fr,
476-
outlived_fr,
477-
fr_is_local,
478-
outlived_fr_is_local,
479-
category,
480-
span: cause.span,
481-
};
472+
let errci = ErrorConstraintInfo { fr, outlived_fr, category, span: cause.span };
482473

483474
let mut diag = match (category, fr_is_local, outlived_fr_is_local) {
484475
(ConstraintCategory::Return(kind), true, false) if self.is_closure_fn_mut(fr) => {
@@ -680,11 +671,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
680671
&& self.regioncx.universal_regions().defining_ty.is_fn_def())
681672
|| self.regioncx.universal_regions().defining_ty.is_const()
682673
{
683-
return self.report_general_error(&ErrorConstraintInfo {
684-
fr_is_local: true,
685-
outlived_fr_is_local: false,
686-
..*errci
687-
});
674+
return self.report_general_error(errci);
688675
}
689676

690677
let mut diag =
@@ -762,15 +749,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
762749
/// ```
763750
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
764751
fn report_general_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> Diag<'infcx> {
765-
let ErrorConstraintInfo {
766-
fr,
767-
fr_is_local,
768-
outlived_fr,
769-
outlived_fr_is_local,
770-
span,
771-
category,
772-
..
773-
} = errci;
752+
let ErrorConstraintInfo { fr, outlived_fr, span, category, .. } = errci;
774753

775754
let mir_def_name = self.infcx.tcx.def_descr(self.mir_def_id().to_def_id());
776755

@@ -789,19 +768,22 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
789768
let outlived_fr_name = self.give_region_a_name(*outlived_fr).unwrap();
790769
outlived_fr_name.highlight_region_name(&mut diag);
791770

792-
let err_category = match (category, outlived_fr_is_local, fr_is_local) {
793-
(ConstraintCategory::Return(_), true, _) => LifetimeReturnCategoryErr::WrongReturn {
771+
let err_category = if matches!(category, ConstraintCategory::Return(_))
772+
&& self.regioncx.universal_regions().is_local_free_region(*outlived_fr)
773+
{
774+
LifetimeReturnCategoryErr::WrongReturn {
794775
span: *span,
795776
mir_def_name,
796777
outlived_fr_name,
797778
fr_name: &fr_name,
798-
},
799-
_ => LifetimeReturnCategoryErr::ShortReturn {
779+
}
780+
} else {
781+
LifetimeReturnCategoryErr::ShortReturn {
800782
span: *span,
801783
category_desc: category.description(),
802784
free_region_name: &fr_name,
803785
outlived_fr_name,
804-
},
786+
}
805787
};
806788

807789
diag.subdiagnostic(err_category);

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2272,10 +2272,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
22722272
let len = d.read_usize();
22732273
let mmap = if len > 0 {
22742274
let mut mmap = MmapMut::map_anon(len).unwrap();
2275-
for _ in 0..len {
2276-
(&mut mmap[..]).write_all(&[d.read_u8()]).unwrap();
2277-
}
2278-
mmap.flush().unwrap();
2275+
mmap.copy_from_slice(d.read_raw_bytes(len));
22792276
Some(mmap.make_read_only().unwrap())
22802277
} else {
22812278
None

Diff for: compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ rustc_queries! {
116116
}
117117

118118
query early_lint_checks(_: ()) {
119-
desc { "perform lints prior to macro expansion" }
119+
desc { "perform lints prior to AST lowering" }
120120
}
121121

122122
query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {

Diff for: compiler/rustc_mir_build/src/thir/pattern/mod.rs

+44-38
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
189189

190190
// Lower the endpoint into a temporary `PatKind` that will then be
191191
// deconstructed to obtain the constant value and other data.
192-
let mut kind: PatKind<'tcx> = self.lower_lit(expr);
192+
let mut kind: PatKind<'tcx> = self.lower_pat_expr(expr);
193193

194194
// Unpeel any ascription or inline-const wrapper nodes.
195195
loop {
@@ -353,7 +353,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
353353

354354
hir::PatKind::Never => PatKind::Never,
355355

356-
hir::PatKind::Expr(value) => self.lower_lit(value),
356+
hir::PatKind::Expr(value) => self.lower_pat_expr(value),
357357

358358
hir::PatKind::Range(ref lo_expr, ref hi_expr, end) => {
359359
let (lo_expr, hi_expr) = (lo_expr.as_deref(), hi_expr.as_deref());
@@ -638,54 +638,57 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
638638
let ty = self.typeck_results.node_type(id);
639639
let res = self.typeck_results.qpath_res(qpath, id);
640640

641-
let pat_from_kind = |kind| Box::new(Pat { span, ty, kind });
642-
643-
let (def_id, is_associated_const) = match res {
644-
Res::Def(DefKind::Const, def_id) => (def_id, false),
645-
Res::Def(DefKind::AssocConst, def_id) => (def_id, true),
641+
let (def_id, user_ty) = match res {
642+
Res::Def(DefKind::Const, def_id) => (def_id, None),
643+
Res::Def(DefKind::AssocConst, def_id) => {
644+
(def_id, self.typeck_results.user_provided_types().get(id))
645+
}
646646

647-
_ => return pat_from_kind(self.lower_variant_or_leaf(res, id, span, ty, vec![])),
647+
_ => {
648+
// The path isn't the name of a constant, so it must actually
649+
// be a unit struct or unit variant (e.g. `Option::None`).
650+
let kind = self.lower_variant_or_leaf(res, id, span, ty, vec![]);
651+
return Box::new(Pat { span, ty, kind });
652+
}
648653
};
649654

655+
// Lower the named constant to a THIR pattern.
650656
let args = self.typeck_results.node_args(id);
651657
let c = ty::Const::new_unevaluated(self.tcx, ty::UnevaluatedConst { def: def_id, args });
652658
let subpattern = self.const_to_pat(c, ty, id, span);
653-
let pattern = Box::new(Pat {
654-
span,
655-
ty,
656-
kind: PatKind::ExpandedConstant { subpattern, def_id, is_inline: false },
657-
});
658659

659-
if !is_associated_const {
660-
return pattern;
661-
}
660+
// Wrap the pattern in a marker node to indicate that it is the result
661+
// of lowering a named constant. This marker is used for improved
662+
// diagnostics in some situations, but has no effect at runtime.
663+
let mut pattern = {
664+
let kind = PatKind::ExpandedConstant { subpattern, def_id, is_inline: false };
665+
Box::new(Pat { span, ty, kind })
666+
};
662667

663-
let user_provided_types = self.typeck_results.user_provided_types();
664-
if let Some(&user_ty) = user_provided_types.get(id) {
668+
// If this is an associated constant with an explicit user-written
669+
// type, add an ascription node (e.g. `<Foo<'a> as MyTrait>::CONST`).
670+
if let Some(&user_ty) = user_ty {
665671
let annotation = CanonicalUserTypeAnnotation {
666672
user_ty: Box::new(user_ty),
667673
span,
668674
inferred_ty: self.typeck_results.node_type(id),
669675
};
670-
Box::new(Pat {
671-
span,
672-
kind: PatKind::AscribeUserType {
673-
subpattern: pattern,
674-
ascription: Ascription {
675-
annotation,
676-
// Note that use `Contravariant` here. See the
677-
// `variance` field documentation for details.
678-
variance: ty::Contravariant,
679-
},
676+
let kind = PatKind::AscribeUserType {
677+
subpattern: pattern,
678+
ascription: Ascription {
679+
annotation,
680+
// Note that we use `Contravariant` here. See the
681+
// `variance` field documentation for details.
682+
variance: ty::Contravariant,
680683
},
681-
ty,
682-
})
683-
} else {
684-
pattern
684+
};
685+
pattern = Box::new(Pat { span, kind, ty });
685686
}
687+
688+
pattern
686689
}
687690

688-
/// Converts inline const patterns.
691+
/// Lowers an inline const block (e.g. `const { 1 + 1 }`) to a pattern.
689692
fn lower_inline_const(
690693
&mut self,
691694
block: &'tcx hir::ConstBlock,
@@ -705,14 +708,17 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
705708

706709
let ct = ty::UnevaluatedConst { def: def_id.to_def_id(), args };
707710
let subpattern = self.const_to_pat(ty::Const::new_unevaluated(self.tcx, ct), ty, id, span);
711+
712+
// Wrap the pattern in a marker node to indicate that it is the result
713+
// of lowering an inline const block.
708714
PatKind::ExpandedConstant { subpattern, def_id: def_id.to_def_id(), is_inline: true }
709715
}
710716

711-
/// Converts literals, paths and negation of literals to patterns.
712-
/// The special case for negation exists to allow things like `-128_i8`
713-
/// which would overflow if we tried to evaluate `128_i8` and then negate
714-
/// afterwards.
715-
fn lower_lit(&mut self, expr: &'tcx hir::PatExpr<'tcx>) -> PatKind<'tcx> {
717+
/// Lowers the kinds of "expression" that can appear in a HIR pattern:
718+
/// - Paths (e.g. `FOO`, `foo::BAR`, `Option::None`)
719+
/// - Inline const blocks (e.g. `const { 1 + 1 }`)
720+
/// - Literals, possibly negated (e.g. `-128u8`, `"hello"`)
721+
fn lower_pat_expr(&mut self, expr: &'tcx hir::PatExpr<'tcx>) -> PatKind<'tcx> {
716722
let (lit, neg) = match &expr.kind {
717723
hir::PatExprKind::Path(qpath) => {
718724
return self.lower_path(qpath, expr.hir_id, expr.span).kind;

Diff for: library/Cargo.lock

+65-6
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,15 @@ dependencies = [
215215
"unwind",
216216
]
217217

218+
[[package]]
219+
name = "proc-macro2"
220+
version = "1.0.93"
221+
source = "registry+https://github.com/rust-lang/crates.io-index"
222+
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
223+
dependencies = [
224+
"unicode-ident",
225+
]
226+
218227
[[package]]
219228
name = "proc_macro"
220229
version = "0.0.0"
@@ -230,6 +239,15 @@ dependencies = [
230239
"cc",
231240
]
232241

242+
[[package]]
243+
name = "quote"
244+
version = "1.0.38"
245+
source = "registry+https://github.com/rust-lang/crates.io-index"
246+
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
247+
dependencies = [
248+
"proc-macro2",
249+
]
250+
233251
[[package]]
234252
name = "r-efi"
235253
version = "4.5.0"
@@ -253,24 +271,28 @@ dependencies = [
253271

254272
[[package]]
255273
name = "rand"
256-
version = "0.8.5"
274+
version = "0.9.0"
257275
source = "registry+https://github.com/rust-lang/crates.io-index"
258-
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
276+
checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94"
259277
dependencies = [
260278
"rand_core",
279+
"zerocopy",
261280
]
262281

263282
[[package]]
264283
name = "rand_core"
265-
version = "0.6.4"
284+
version = "0.9.0"
266285
source = "registry+https://github.com/rust-lang/crates.io-index"
267-
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
286+
checksum = "b08f3c9802962f7e1b25113931d94f43ed9725bebc59db9d0c3e9a23b67e15ff"
287+
dependencies = [
288+
"zerocopy",
289+
]
268290

269291
[[package]]
270292
name = "rand_xorshift"
271-
version = "0.3.0"
293+
version = "0.4.0"
272294
source = "registry+https://github.com/rust-lang/crates.io-index"
273-
checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
295+
checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
274296
dependencies = [
275297
"rand_core",
276298
]
@@ -352,6 +374,17 @@ dependencies = [
352374
"rustc-std-workspace-core",
353375
]
354376

377+
[[package]]
378+
name = "syn"
379+
version = "2.0.98"
380+
source = "registry+https://github.com/rust-lang/crates.io-index"
381+
checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1"
382+
dependencies = [
383+
"proc-macro2",
384+
"quote",
385+
"unicode-ident",
386+
]
387+
355388
[[package]]
356389
name = "sysroot"
357390
version = "0.0.0"
@@ -372,6 +405,12 @@ dependencies = [
372405
"std",
373406
]
374407

408+
[[package]]
409+
name = "unicode-ident"
410+
version = "1.0.16"
411+
source = "registry+https://github.com/rust-lang/crates.io-index"
412+
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
413+
375414
[[package]]
376415
name = "unicode-width"
377416
version = "0.1.14"
@@ -492,3 +531,23 @@ name = "windows_x86_64_msvc"
492531
version = "0.52.6"
493532
source = "registry+https://github.com/rust-lang/crates.io-index"
494533
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
534+
535+
[[package]]
536+
name = "zerocopy"
537+
version = "0.8.17"
538+
source = "registry+https://github.com/rust-lang/crates.io-index"
539+
checksum = "aa91407dacce3a68c56de03abe2760159582b846c6a4acd2f456618087f12713"
540+
dependencies = [
541+
"zerocopy-derive",
542+
]
543+
544+
[[package]]
545+
name = "zerocopy-derive"
546+
version = "0.8.17"
547+
source = "registry+https://github.com/rust-lang/crates.io-index"
548+
checksum = "06718a168365cad3d5ff0bb133aad346959a2074bd4a85c121255a11304a8626"
549+
dependencies = [
550+
"proc-macro2",
551+
"quote",
552+
"syn",
553+
]

Diff for: library/alloc/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ core = { path = "../core" }
1313
compiler_builtins = { version = "=0.1.146", features = ['rustc-dep-of-std'] }
1414

1515
[dev-dependencies]
16-
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
17-
rand_xorshift = "0.3.0"
16+
rand = { version = "0.9.0", default-features = false, features = ["alloc"] }
17+
rand_xorshift = "0.4.0"
1818

1919
[[test]]
2020
name = "alloctests"

0 commit comments

Comments
 (0)