Skip to content

Rollup of 12 pull requests #140581

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

Merged
merged 32 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3d41095
Put shebang at the top of pretty-print
VlaDexa Feb 23, 2025
ff37c7d
std: use the address of `errno` to identify threads in `unique_thread…
joboet Apr 1, 2025
a576362
Document async block control flow in async keyword
Lynnesbian Apr 10, 2025
e2caab1
Doc more control flow behaviour for return keyword
Lynnesbian Apr 10, 2025
36ae657
Document breaking out of a named code block
ktnlvr Apr 23, 2025
e9d2fef
stop check paren if has different ctx
bvanjoi Apr 29, 2025
1157b78
Remove `avx512dq` and `avx512vl` implication for `avx512fp16`
sayantn Apr 18, 2025
adb92ae
rustc_target: Adjust RISC-V feature implication (Za64rs and Za128rs)
a4lg Apr 30, 2025
c6ed786
rustc_target: RISC-V: Add atomics/memory-related extensions
a4lg Apr 30, 2025
501a539
rustc_target: RISC-V: Add BF16 extensions
a4lg Apr 30, 2025
eec6cfb
rustc_target: RISC-V "Zfinx" is incompatible with {ILP32,LP64}[FD] ABIs
a4lg Mar 24, 2025
7cb357a
Make internal `OsString::truncate` and `extend_from_slice` unsafe
thaliaarchi Apr 11, 2025
0f0c0d8
Avoid redundant WTF-8 checks in `PathBuf`
thaliaarchi Apr 22, 2025
7443d03
Update stdarch
sayantn Apr 29, 2025
175f717
Simplify docs for breaking out of a named code block
ktnlvr May 1, 2025
b2bf951
Augment `impl-trait-missing-lifetime-gated.rs`.
nnethercote Mar 28, 2025
28deaa6
Delegate to inner `vec::IntoIter` from `env::ArgsOs`
thaliaarchi Apr 12, 2025
d42edee
Handle `Path<>` better in error messages.
nnethercote Apr 28, 2025
3f842e5
Improve coverage of HIR pretty printing.
nnethercote Apr 29, 2025
360012f
Amend language regarding the never type
Lynnesbian May 2, 2025
96852e2
Rollup merge of #134034 - bvanjoi:issue-131655, r=petrochenkov
Zalathar May 2, 2025
8619438
Rollup merge of #137474 - VlaDexa:shebang-placement, r=wesleywiser
Zalathar May 2, 2025
b24288b
Rollup merge of #138872 - a4lg:riscv-fix-incompatible-abi-zfinx, r=wo…
Zalathar May 2, 2025
c3f500e
Rollup merge of #139046 - nnethercote:hir-Lifetime-better, r=lcnr
Zalathar May 2, 2025
8ffdb00
Rollup merge of #139206 - joboet:unique_thread_errno, r=ibraheemdev
Zalathar May 2, 2025
192fbcc
Rollup merge of #139608 - Lynnesbian:improve-async-block-docs, r=ibra…
Zalathar May 2, 2025
6fc78d4
Rollup merge of #139847 - thaliaarchi:args/delegate-iter, r=workingju…
Zalathar May 2, 2025
5a58c7a
Rollup merge of #140159 - thaliaarchi:pathbuf-extension, r=workingjub…
Zalathar May 2, 2025
30e556e
Rollup merge of #140197 - ktnlvr:master, r=workingjubilee
Zalathar May 2, 2025
27d419a
Rollup merge of #140389 - sayantn:avx512fp16, r=Amanieu
Zalathar May 2, 2025
01adc82
Rollup merge of #140430 - nnethercote:hir-exhaustive, r=dtolnay
Zalathar May 2, 2025
19c9b76
Rollup merge of #140507 - a4lg:riscv-feature-addition-batch-3, r=Amanieu
Zalathar May 2, 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
10 changes: 5 additions & 5 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, StashKey};
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId};
use rustc_hir::{
self as hir, ConstArg, GenericArg, HirId, ItemLocalMap, LangItem, LifetimeSource,
LifetimeSyntax, ParamName, TraitCandidate,
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LangItem,
LifetimeSource, LifetimeSyntax, ParamName, TraitCandidate,
};
use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_macros::extension;
Expand Down Expand Up @@ -1087,7 +1087,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
match arg {
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(
lt,
LifetimeSource::Path { with_angle_brackets: true },
LifetimeSource::Path { angle_brackets: hir::AngleBrackets::Full },
lt.ident.into(),
)),
ast::GenericArg::Type(ty) => {
Expand Down Expand Up @@ -1779,13 +1779,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self,
id: NodeId,
span: Span,
with_angle_brackets: bool,
angle_brackets: AngleBrackets,
) -> &'hir hir::Lifetime {
self.new_named_lifetime(
id,
id,
Ident::new(kw::UnderscoreLifetime, span),
LifetimeSource::Path { with_angle_brackets },
LifetimeSource::Path { angle_brackets },
LifetimeSyntax::Hidden,
)
}
Expand Down
30 changes: 17 additions & 13 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,27 +432,31 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

// Note: these spans are used for diagnostics when they can't be inferred.
// See rustc_resolve::late::lifetimes::LifetimeContext::add_missing_lifetime_specifiers_label
let (elided_lifetime_span, with_angle_brackets) = if generic_args.span.is_empty() {
// If there are no brackets, use the identifier span.
let (elided_lifetime_span, angle_brackets) = if generic_args.span.is_empty() {
// No brackets, e.g. `Path`: use an empty span just past the end of the identifier.
// HACK: we use find_ancestor_inside to properly suggest elided spans in paths
// originating from macros, since the segment's span might be from a macro arg.
(segment_ident_span.find_ancestor_inside(path_span).unwrap_or(path_span), false)
} else if generic_args.is_empty() {
// If there are brackets, but not generic arguments, then use the opening bracket
(generic_args.span.with_hi(generic_args.span.lo() + BytePos(1)), true)
(
segment_ident_span.find_ancestor_inside(path_span).unwrap_or(path_span),
hir::AngleBrackets::Missing,
)
} else {
// Else use an empty span right after the opening bracket.
(generic_args.span.with_lo(generic_args.span.lo() + BytePos(1)).shrink_to_lo(), true)
// Brackets, e.g. `Path<>` or `Path<T>`: use an empty span just after the `<`.
(
generic_args.span.with_lo(generic_args.span.lo() + BytePos(1)).shrink_to_lo(),
if generic_args.is_empty() {
hir::AngleBrackets::Empty
} else {
hir::AngleBrackets::Full
},
)
};

generic_args.args.insert_many(
0,
(start..end).map(|id| {
let l = self.lower_lifetime_hidden_in_path(
id,
elided_lifetime_span,
with_angle_brackets,
);
let l =
self.lower_lifetime_hidden_in_path(id, elided_lifetime_span, angle_brackets);
GenericArg::Lifetime(l)
}),
);
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ pub fn print_crate<'a>(
let mut s =
State { s: pp::Printer::new(), comments: Some(Comments::new(sm, filename, input)), ann };

// We need to print shebang before anything else
// otherwise the resulting code will not compile
// and shebang will be useless.
s.maybe_print_shebang();

if is_expanded && !krate.attrs.iter().any(|attr| attr.has_name(sym::no_core)) {
// We need to print `#![no_std]` (and its feature gate) so that
// compiling pretty-printed source won't inject libstd again.
Expand Down Expand Up @@ -560,6 +565,20 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.word(st)
}

fn maybe_print_shebang(&mut self) {
if let Some(cmnt) = self.peek_comment() {
// Comment is a shebang if it's:
// Isolated, starts with #! and doesn't continue with `[`
// See [rustc_lexer::strip_shebang] and [gather_comments] from pprust/state.rs for details
if cmnt.style == CommentStyle::Isolated
&& cmnt.lines.first().map_or(false, |l| l.starts_with("#!"))
{
let cmnt = self.next_comment().unwrap();
self.print_comment(cmnt);
}
}
}

fn print_inner_attributes(&mut self, attrs: &[ast::Attribute]) -> bool {
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, true)
}
Expand Down
29 changes: 20 additions & 9 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,24 @@ use crate::def_id::{DefId, LocalDefIdMap};
pub(crate) use crate::hir_id::{HirId, ItemLocalId, ItemLocalMap, OwnerId};
use crate::intravisit::{FnKind, VisitorExt};

#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)]
pub enum AngleBrackets {
/// E.g. `Path`.
Missing,
/// E.g. `Path<>`.
Empty,
/// E.g. `Path<T>`.
Full,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)]
pub enum LifetimeSource {
/// E.g. `&Type`, `&'_ Type`, `&'a Type`, `&mut Type`, `&'_ mut Type`, `&'a mut Type`
Reference,

/// E.g. `ContainsLifetime`, `ContainsLifetime<'_>`, `ContainsLifetime<'a>`
Path {
/// - true for `ContainsLifetime<'_>`, `ContainsLifetime<'a>`,
/// `ContainsLifetime<'_, T>`, `ContainsLifetime<'a, T>`
/// - false for `ContainsLifetime`
with_angle_brackets: bool,
},
/// E.g. `ContainsLifetime`, `ContainsLifetime<>`, `ContainsLifetime<'_>`,
/// `ContainsLifetime<'a>`
Path { angle_brackets: AngleBrackets },

/// E.g. `impl Trait + '_`, `impl Trait + 'a`
OutlivesBound,
Expand Down Expand Up @@ -304,12 +310,17 @@ impl Lifetime {
(Named | Anonymous, _) => (self.ident.span, format!("{new_lifetime}")),

// The user wrote `Path<T>`, and omitted the `'_,`.
(Hidden, Path { with_angle_brackets: true }) => {
(Hidden, Path { angle_brackets: AngleBrackets::Full }) => {
(self.ident.span, format!("{new_lifetime}, "))
}

// The user wrote `Path<>`, and omitted the `'_`..
(Hidden, Path { angle_brackets: AngleBrackets::Empty }) => {
(self.ident.span, format!("{new_lifetime}"))
}

// The user wrote `Path` and omitted the `<'_>`.
(Hidden, Path { with_angle_brackets: false }) => {
(Hidden, Path { angle_brackets: AngleBrackets::Missing }) => {
(self.ident.span.shrink_to_hi(), format!("<{new_lifetime}>"))
}

Expand Down
16 changes: 16 additions & 0 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,22 @@ trait UnusedDelimLint {
match s.kind {
StmtKind::Let(ref local) if Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX => {
if let Some((init, els)) = local.kind.init_else_opt() {
if els.is_some()
&& let ExprKind::Paren(paren) = &init.kind
&& !init.span.eq_ctxt(paren.span)
{
// This branch prevents cases where parentheses wrap an expression
// resulting from macro expansion, such as:
// ```
// macro_rules! x {
// () => { None::<i32> };
// }
// let Some(_) = (x!{}) else { return };
// // -> let Some(_) = (None::<i32>) else { return };
// // ~ ~ No Lint
// ```
return;
}
let ctx = match els {
None => UnusedDelimsCtx::AssignedValue,
Some(_) => UnusedDelimsCtx::AssignedValueLetElse,
Expand Down
22 changes: 16 additions & 6 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("avx512cd", Unstable(sym::avx512_target_feature), &["avx512f"]),
("avx512dq", Unstable(sym::avx512_target_feature), &["avx512f"]),
("avx512f", Unstable(sym::avx512_target_feature), &["avx2", "fma", "f16c"]),
("avx512fp16", Unstable(sym::avx512_target_feature), &["avx512bw", "avx512vl", "avx512dq"]),
("avx512fp16", Unstable(sym::avx512_target_feature), &["avx512bw"]),
("avx512ifma", Unstable(sym::avx512_target_feature), &["avx512f"]),
("avx512vbmi", Unstable(sym::avx512_target_feature), &["avx512bw"]),
("avx512vbmi2", Unstable(sym::avx512_target_feature), &["avx512bw"]),
Expand Down Expand Up @@ -510,7 +510,7 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("unaligned-vector-mem", Unstable(sym::riscv_target_feature), &[]),
("v", Unstable(sym::riscv_target_feature), &["zvl128b", "zve64d"]),
("za128rs", Unstable(sym::riscv_target_feature), &[]),
("za64rs", Unstable(sym::riscv_target_feature), &[]),
("za64rs", Unstable(sym::riscv_target_feature), &["za128rs"]), // Za64rs ⊃ Za128rs
("zaamo", Unstable(sym::riscv_target_feature), &[]),
("zabha", Unstable(sym::riscv_target_feature), &["zaamo"]),
("zacas", Unstable(sym::riscv_target_feature), &["zaamo"]),
Expand All @@ -529,12 +529,20 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("zcmop", Unstable(sym::riscv_target_feature), &["zca"]),
("zdinx", Unstable(sym::riscv_target_feature), &["zfinx"]),
("zfa", Unstable(sym::riscv_target_feature), &["f"]),
("zfbfmin", Unstable(sym::riscv_target_feature), &["f"]), // and a subset of Zfhmin
("zfh", Unstable(sym::riscv_target_feature), &["zfhmin"]),
("zfhmin", Unstable(sym::riscv_target_feature), &["f"]),
("zfinx", Unstable(sym::riscv_target_feature), &["zicsr"]),
("zhinx", Unstable(sym::riscv_target_feature), &["zhinxmin"]),
("zhinxmin", Unstable(sym::riscv_target_feature), &["zfinx"]),
("zic64b", Unstable(sym::riscv_target_feature), &[]),
("zicbom", Unstable(sym::riscv_target_feature), &[]),
("zicbop", Unstable(sym::riscv_target_feature), &[]),
("zicboz", Unstable(sym::riscv_target_feature), &[]),
("ziccamoa", Unstable(sym::riscv_target_feature), &[]),
("ziccif", Unstable(sym::riscv_target_feature), &[]),
("zicclsm", Unstable(sym::riscv_target_feature), &[]),
("ziccrse", Unstable(sym::riscv_target_feature), &[]),
("zicntr", Unstable(sym::riscv_target_feature), &["zicsr"]),
("zicond", Unstable(sym::riscv_target_feature), &[]),
("zicsr", Unstable(sym::riscv_target_feature), &[]),
Expand All @@ -561,6 +569,8 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("zve64d", Unstable(sym::riscv_target_feature), &["zve64f", "d"]),
("zve64f", Unstable(sym::riscv_target_feature), &["zve32f", "zve64x"]),
("zve64x", Unstable(sym::riscv_target_feature), &["zve32x", "zvl64b"]),
("zvfbfmin", Unstable(sym::riscv_target_feature), &["zve32f"]),
("zvfbfwma", Unstable(sym::riscv_target_feature), &["zfbfmin", "zvfbfmin"]),
("zvfh", Unstable(sym::riscv_target_feature), &["zvfhmin", "zve32f", "zfhmin"]), // Zvfh ⊃ Zvfhmin
("zvfhmin", Unstable(sym::riscv_target_feature), &["zve32f"]),
("zvkb", Unstable(sym::riscv_target_feature), &["zve32x"]),
Expand Down Expand Up @@ -966,12 +976,12 @@ impl Target {
// about what the intended ABI is.
match &*self.llvm_abiname {
"ilp32d" | "lp64d" => {
// Requires d (which implies f), incompatible with e.
FeatureConstraints { required: &["d"], incompatible: &["e"] }
// Requires d (which implies f), incompatible with e and zfinx.
FeatureConstraints { required: &["d"], incompatible: &["e", "zfinx"] }
}
"ilp32f" | "lp64f" => {
// Requires f, incompatible with e.
FeatureConstraints { required: &["f"], incompatible: &["e"] }
// Requires f, incompatible with e and zfinx.
FeatureConstraints { required: &["f"], incompatible: &["e", "zfinx"] }
}
"ilp32" | "lp64" => {
// Requires nothing, incompatible with e.
Expand Down
1 change: 0 additions & 1 deletion library/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ level = "warn"
check-cfg = [
'cfg(bootstrap)',
'cfg(no_fp_fmt_parse)',
'cfg(stdarch_intel_sde)',
# core use #[path] imports to portable-simd `core_simd` crate
# and to stdarch `core_arch` crate which messes-up with Cargo list
# of declared features, we therefor expect any feature cfg
Expand Down
Loading
Loading