Skip to content

Rollup of 11 pull requests #137040

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

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1383272
Const-stabilize `str::is_char_boundary` and `str::split_at(_mut)(_che…
zachs18 Nov 13, 2024
ef34064
core: Apply unsafe_attr_outside_unsafe
ehuss Feb 13, 2025
cc74ed0
triagebot: automatically add more rustdoc related labels
lolbinarycat Feb 13, 2025
b7c975b
library: Update rand to 0.9.0
ehuss Feb 13, 2025
0aa634e
Migrate coretests to Rust 2024
ehuss Feb 11, 2025
890530e
alloc: Workaround hidden doctest line
ehuss Feb 13, 2025
55ef73c
alloc: Apply unsafe_attr_outside_unsafe
ehuss Feb 13, 2025
07ebbdd
alloc: Apply missing_unsafe_on_extern
ehuss Feb 13, 2025
9e60b0e
std: Apply unsafe_attr_outside_unsafe
ehuss Feb 12, 2025
c1791a1
std: Apply missing_unsafe_on_extern
ehuss Feb 12, 2025
7dc9e05
std: Apply dependency_on_unit_never_type_fallback
ehuss Feb 12, 2025
1ba59f8
std: Apply rust_2024_incompatible_pat
ehuss Feb 12, 2025
1b3940f
std: Apply fixes for tail drop expressions
ehuss Feb 12, 2025
36733f3
test: Apply deprecated_safe_2024
ehuss Feb 13, 2025
ef20a1b
std: Apply deprecated_safe_2024
ehuss Feb 13, 2025
37520e6
Fix early lint check desc in query
chenyukang Feb 14, 2025
3f9cca3
remove `fr_is_local` and `outlived_fr_is_local` fields from `ErrorCon…
dianne Feb 14, 2025
00683a0
CI: split i686-mingw job to three free runners
marcoieni Feb 14, 2025
2ea9e1d
further simplify a match
dianne Feb 14, 2025
00964aa
Add safe new to NotAllOnes
kornelski Feb 11, 2025
1284765
Rename `PatCtxt::lower_lit` to `lower_pat_expr`
Zalathar Feb 5, 2025
c3eea53
Clarify control-flow in `lower_path`
Zalathar Feb 4, 2025
92fc085
More comments for `lower_inline_const`
Zalathar Feb 5, 2025
e8a4f9d
Stabilize (and const-stabilize) `integer_sign_cast`
GrigorenkoPV Feb 14, 2025
7d1262a
Add new ui test for returning an Fn trait that returns impl Trait
LFS6502 Feb 13, 2025
be2cd95
Decode metadata buffer in one go
oli-obk Feb 14, 2025
4fa3318
Rollup merge of #133312 - lolbinarycat:triagebot-rustdoc-labels, r=Gu…
jhpratt Feb 14, 2025
8b88b2e
Rollup merge of #134016 - zachs18:stable-const-str-split_at, r=Amanieu
jhpratt Feb 14, 2025
af82b11
Rollup merge of #135813 - marcoieni:free-runner-i686-mingw, r=jdno
jhpratt Feb 14, 2025
562e1ed
Rollup merge of #136879 - kornelski:non1, r=Noratrieb
jhpratt Feb 14, 2025
8356c09
Rollup merge of #136971 - HypheX:patch1, r=WaffleLapkin
jhpratt Feb 14, 2025
b963ba2
Rollup merge of #136983 - ehuss:misc-2024-prep, r=tgross35
jhpratt Feb 14, 2025
aed26c9
Rollup merge of #137002 - chenyukang:fix-early-lint-check-desc, r=com…
jhpratt Feb 14, 2025
ecca7da
Rollup merge of #137006 - dianne:remove-errci-fields, r=compiler-errors
jhpratt Feb 14, 2025
3cbe03f
Rollup merge of #137026 - GrigorenkoPV:integer_sign_cast, r=Noratrieb
jhpratt Feb 14, 2025
3235a0b
Rollup merge of #137028 - Zalathar:thir-pat-expr, r=compiler-errors
jhpratt Feb 14, 2025
8491b54
Rollup merge of #137032 - oli-obk:push-ptvssqnomkpo, r=the8472
jhpratt Feb 14, 2025
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
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
Loading