Skip to content

Commit

Permalink
Auto merge of rust-lang#137040 - jhpratt:rollup-lr17zya, r=jhpratt
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Feb 14, 2025
2 parents d8810e3 + 8491b54 commit a931943
Show file tree
Hide file tree
Showing 64 changed files with 457 additions and 281 deletions.
40 changes: 11 additions & 29 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ pub(crate) enum RegionErrorKind<'tcx> {
pub(crate) struct ErrorConstraintInfo<'tcx> {
// fr: outlived_fr
pub(super) fr: RegionVid,
pub(super) fr_is_local: bool,
pub(super) outlived_fr: RegionVid,
pub(super) outlived_fr_is_local: bool,

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

let errci = ErrorConstraintInfo {
fr,
outlived_fr,
fr_is_local,
outlived_fr_is_local,
category,
span: cause.span,
};
let errci = ErrorConstraintInfo { fr, outlived_fr, category, span: cause.span };

let mut diag = match (category, fr_is_local, outlived_fr_is_local) {
(ConstraintCategory::Return(kind), true, false) if self.is_closure_fn_mut(fr) => {
Expand Down Expand Up @@ -680,11 +671,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
&& self.regioncx.universal_regions().defining_ty.is_fn_def())
|| self.regioncx.universal_regions().defining_ty.is_const()
{
return self.report_general_error(&ErrorConstraintInfo {
fr_is_local: true,
outlived_fr_is_local: false,
..*errci
});
return self.report_general_error(errci);
}

let mut diag =
Expand Down Expand Up @@ -762,15 +749,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
/// ```
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
fn report_general_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> Diag<'infcx> {
let ErrorConstraintInfo {
fr,
fr_is_local,
outlived_fr,
outlived_fr_is_local,
span,
category,
..
} = errci;
let ErrorConstraintInfo { fr, outlived_fr, span, category, .. } = errci;

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

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

let err_category = match (category, outlived_fr_is_local, fr_is_local) {
(ConstraintCategory::Return(_), true, _) => LifetimeReturnCategoryErr::WrongReturn {
let err_category = if matches!(category, ConstraintCategory::Return(_))
&& self.regioncx.universal_regions().is_local_free_region(*outlived_fr)
{
LifetimeReturnCategoryErr::WrongReturn {
span: *span,
mir_def_name,
outlived_fr_name,
fr_name: &fr_name,
},
_ => LifetimeReturnCategoryErr::ShortReturn {
}
} else {
LifetimeReturnCategoryErr::ShortReturn {
span: *span,
category_desc: category.description(),
free_region_name: &fr_name,
outlived_fr_name,
},
}
};

diag.subdiagnostic(err_category);
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2272,10 +2272,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
let len = d.read_usize();
let mmap = if len > 0 {
let mut mmap = MmapMut::map_anon(len).unwrap();
for _ in 0..len {
(&mut mmap[..]).write_all(&[d.read_u8()]).unwrap();
}
mmap.flush().unwrap();
mmap.copy_from_slice(d.read_raw_bytes(len));
Some(mmap.make_read_only().unwrap())
} else {
None
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 @@ -116,7 +116,7 @@ rustc_queries! {
}

query early_lint_checks(_: ()) {
desc { "perform lints prior to macro expansion" }
desc { "perform lints prior to AST lowering" }
}

query resolutions(_: ()) -> &'tcx ty::ResolverGlobalCtxt {
Expand Down
82 changes: 44 additions & 38 deletions compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {

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

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

hir::PatKind::Never => PatKind::Never,

hir::PatKind::Expr(value) => self.lower_lit(value),
hir::PatKind::Expr(value) => self.lower_pat_expr(value),

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

let pat_from_kind = |kind| Box::new(Pat { span, ty, kind });

let (def_id, is_associated_const) = match res {
Res::Def(DefKind::Const, def_id) => (def_id, false),
Res::Def(DefKind::AssocConst, def_id) => (def_id, true),
let (def_id, user_ty) = match res {
Res::Def(DefKind::Const, def_id) => (def_id, None),
Res::Def(DefKind::AssocConst, def_id) => {
(def_id, self.typeck_results.user_provided_types().get(id))
}

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

// Lower the named constant to a THIR pattern.
let args = self.typeck_results.node_args(id);
let c = ty::Const::new_unevaluated(self.tcx, ty::UnevaluatedConst { def: def_id, args });
let subpattern = self.const_to_pat(c, ty, id, span);
let pattern = Box::new(Pat {
span,
ty,
kind: PatKind::ExpandedConstant { subpattern, def_id, is_inline: false },
});

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

let user_provided_types = self.typeck_results.user_provided_types();
if let Some(&user_ty) = user_provided_types.get(id) {
// If this is an associated constant with an explicit user-written
// type, add an ascription node (e.g. `<Foo<'a> as MyTrait>::CONST`).
if let Some(&user_ty) = user_ty {
let annotation = CanonicalUserTypeAnnotation {
user_ty: Box::new(user_ty),
span,
inferred_ty: self.typeck_results.node_type(id),
};
Box::new(Pat {
span,
kind: PatKind::AscribeUserType {
subpattern: pattern,
ascription: Ascription {
annotation,
// Note that use `Contravariant` here. See the
// `variance` field documentation for details.
variance: ty::Contravariant,
},
let kind = PatKind::AscribeUserType {
subpattern: pattern,
ascription: Ascription {
annotation,
// Note that we use `Contravariant` here. See the
// `variance` field documentation for details.
variance: ty::Contravariant,
},
ty,
})
} else {
pattern
};
pattern = Box::new(Pat { span, kind, ty });
}

pattern
}

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

let ct = ty::UnevaluatedConst { def: def_id.to_def_id(), args };
let subpattern = self.const_to_pat(ty::Const::new_unevaluated(self.tcx, ct), ty, id, span);

// Wrap the pattern in a marker node to indicate that it is the result
// of lowering an inline const block.
PatKind::ExpandedConstant { subpattern, def_id: def_id.to_def_id(), is_inline: true }
}

/// Converts literals, paths and negation of literals to patterns.
/// The special case for negation exists to allow things like `-128_i8`
/// which would overflow if we tried to evaluate `128_i8` and then negate
/// afterwards.
fn lower_lit(&mut self, expr: &'tcx hir::PatExpr<'tcx>) -> PatKind<'tcx> {
/// Lowers the kinds of "expression" that can appear in a HIR pattern:
/// - Paths (e.g. `FOO`, `foo::BAR`, `Option::None`)
/// - Inline const blocks (e.g. `const { 1 + 1 }`)
/// - Literals, possibly negated (e.g. `-128u8`, `"hello"`)
fn lower_pat_expr(&mut self, expr: &'tcx hir::PatExpr<'tcx>) -> PatKind<'tcx> {
let (lit, neg) = match &expr.kind {
hir::PatExprKind::Path(qpath) => {
return self.lower_path(qpath, expr.hir_id, expr.span).kind;
Expand Down
71 changes: 65 additions & 6 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,15 @@ dependencies = [
"unwind",
]

[[package]]
name = "proc-macro2"
version = "1.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
dependencies = [
"unicode-ident",
]

[[package]]
name = "proc_macro"
version = "0.0.0"
Expand All @@ -230,6 +239,15 @@ dependencies = [
"cc",
]

[[package]]
name = "quote"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
dependencies = [
"proc-macro2",
]

[[package]]
name = "r-efi"
version = "4.5.0"
Expand All @@ -253,24 +271,28 @@ dependencies = [

[[package]]
name = "rand"
version = "0.8.5"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94"
dependencies = [
"rand_core",
"zerocopy",
]

[[package]]
name = "rand_core"
version = "0.6.4"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
checksum = "b08f3c9802962f7e1b25113931d94f43ed9725bebc59db9d0c3e9a23b67e15ff"
dependencies = [
"zerocopy",
]

[[package]]
name = "rand_xorshift"
version = "0.3.0"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f"
checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a"
dependencies = [
"rand_core",
]
Expand Down Expand Up @@ -352,6 +374,17 @@ dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "syn"
version = "2.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]

[[package]]
name = "sysroot"
version = "0.0.0"
Expand All @@ -372,6 +405,12 @@ dependencies = [
"std",
]

[[package]]
name = "unicode-ident"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"

[[package]]
name = "unicode-width"
version = "0.1.14"
Expand Down Expand Up @@ -492,3 +531,23 @@ name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

[[package]]
name = "zerocopy"
version = "0.8.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa91407dacce3a68c56de03abe2760159582b846c6a4acd2f456618087f12713"
dependencies = [
"zerocopy-derive",
]

[[package]]
name = "zerocopy-derive"
version = "0.8.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06718a168365cad3d5ff0bb133aad346959a2074bd4a85c121255a11304a8626"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
4 changes: 2 additions & 2 deletions library/alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ core = { path = "../core" }
compiler_builtins = { version = "=0.1.146", features = ['rustc-dep-of-std'] }

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

[[test]]
name = "alloctests"
Expand Down
Loading

0 comments on commit a931943

Please sign in to comment.