Skip to content

Commit 7c96085

Browse files
committed
Auto merge of #140581 - Zalathar:rollup-ig2jb9v, r=Zalathar
Rollup of 12 pull requests Successful merges: - #134034 (handle paren in macro expand for let-init-else expr) - #137474 (pretty-print: Print shebang at the top of the output) - #138872 (rustc_target: RISC-V `Zfinx` is incompatible with `{ILP32,LP64}[FD]` ABIs) - #139046 (Improve `Lifetime::suggestion`) - #139206 (std: use the address of `errno` to identify threads in `unique_thread_exit`) - #139608 (Clarify `async` block behaviour) - #139847 (Delegate to inner `vec::IntoIter` from `env::ArgsOs`) - #140159 (Avoid redundant WTF-8 checks in `PathBuf`) - #140197 (Document breaking out of a named code block) - #140389 (Remove `avx512dq` and `avx512vl` implication for `avx512fp16`) - #140430 (Improve test coverage of HIR pretty printing.) - #140507 (rustc_target: RISC-V: feature addition batch 3) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f97b3c6 + 19c9b76 commit 7c96085

Some content is hidden

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

44 files changed

+1724
-224
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, StashKey};
5555
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5656
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId};
5757
use rustc_hir::{
58-
self as hir, ConstArg, GenericArg, HirId, ItemLocalMap, LangItem, LifetimeSource,
59-
LifetimeSyntax, ParamName, TraitCandidate,
58+
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LangItem,
59+
LifetimeSource, LifetimeSyntax, ParamName, TraitCandidate,
6060
};
6161
use rustc_index::{Idx, IndexSlice, IndexVec};
6262
use rustc_macros::extension;
@@ -1087,7 +1087,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10871087
match arg {
10881088
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(
10891089
lt,
1090-
LifetimeSource::Path { with_angle_brackets: true },
1090+
LifetimeSource::Path { angle_brackets: hir::AngleBrackets::Full },
10911091
lt.ident.into(),
10921092
)),
10931093
ast::GenericArg::Type(ty) => {
@@ -1779,13 +1779,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17791779
&mut self,
17801780
id: NodeId,
17811781
span: Span,
1782-
with_angle_brackets: bool,
1782+
angle_brackets: AngleBrackets,
17831783
) -> &'hir hir::Lifetime {
17841784
self.new_named_lifetime(
17851785
id,
17861786
id,
17871787
Ident::new(kw::UnderscoreLifetime, span),
1788-
LifetimeSource::Path { with_angle_brackets },
1788+
LifetimeSource::Path { angle_brackets },
17891789
LifetimeSyntax::Hidden,
17901790
)
17911791
}

compiler/rustc_ast_lowering/src/path.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -432,27 +432,31 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
432432

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

448455
generic_args.args.insert_many(
449456
0,
450457
(start..end).map(|id| {
451-
let l = self.lower_lifetime_hidden_in_path(
452-
id,
453-
elided_lifetime_span,
454-
with_angle_brackets,
455-
);
458+
let l =
459+
self.lower_lifetime_hidden_in_path(id, elided_lifetime_span, angle_brackets);
456460
GenericArg::Lifetime(l)
457461
}),
458462
);

compiler/rustc_ast_pretty/src/pprust/state.rs

+19
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ pub fn print_crate<'a>(
240240
let mut s =
241241
State { s: pp::Printer::new(), comments: Some(Comments::new(sm, filename, input)), ann };
242242

243+
// We need to print shebang before anything else
244+
// otherwise the resulting code will not compile
245+
// and shebang will be useless.
246+
s.maybe_print_shebang();
247+
243248
if is_expanded && !krate.attrs.iter().any(|attr| attr.has_name(sym::no_core)) {
244249
// We need to print `#![no_std]` (and its feature gate) so that
245250
// compiling pretty-printed source won't inject libstd again.
@@ -560,6 +565,20 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
560565
self.word(st)
561566
}
562567

568+
fn maybe_print_shebang(&mut self) {
569+
if let Some(cmnt) = self.peek_comment() {
570+
// Comment is a shebang if it's:
571+
// Isolated, starts with #! and doesn't continue with `[`
572+
// See [rustc_lexer::strip_shebang] and [gather_comments] from pprust/state.rs for details
573+
if cmnt.style == CommentStyle::Isolated
574+
&& cmnt.lines.first().map_or(false, |l| l.starts_with("#!"))
575+
{
576+
let cmnt = self.next_comment().unwrap();
577+
self.print_comment(cmnt);
578+
}
579+
}
580+
}
581+
563582
fn print_inner_attributes(&mut self, attrs: &[ast::Attribute]) -> bool {
564583
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, true)
565584
}

compiler/rustc_hir/src/hir.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,24 @@ use crate::def_id::{DefId, LocalDefIdMap};
3535
pub(crate) use crate::hir_id::{HirId, ItemLocalId, ItemLocalMap, OwnerId};
3636
use crate::intravisit::{FnKind, VisitorExt};
3737

38+
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)]
39+
pub enum AngleBrackets {
40+
/// E.g. `Path`.
41+
Missing,
42+
/// E.g. `Path<>`.
43+
Empty,
44+
/// E.g. `Path<T>`.
45+
Full,
46+
}
47+
3848
#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable_Generic)]
3949
pub enum LifetimeSource {
4050
/// E.g. `&Type`, `&'_ Type`, `&'a Type`, `&mut Type`, `&'_ mut Type`, `&'a mut Type`
4151
Reference,
4252

43-
/// E.g. `ContainsLifetime`, `ContainsLifetime<'_>`, `ContainsLifetime<'a>`
44-
Path {
45-
/// - true for `ContainsLifetime<'_>`, `ContainsLifetime<'a>`,
46-
/// `ContainsLifetime<'_, T>`, `ContainsLifetime<'a, T>`
47-
/// - false for `ContainsLifetime`
48-
with_angle_brackets: bool,
49-
},
53+
/// E.g. `ContainsLifetime`, `ContainsLifetime<>`, `ContainsLifetime<'_>`,
54+
/// `ContainsLifetime<'a>`
55+
Path { angle_brackets: AngleBrackets },
5056

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

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

317+
// The user wrote `Path<>`, and omitted the `'_`..
318+
(Hidden, Path { angle_brackets: AngleBrackets::Empty }) => {
319+
(self.ident.span, format!("{new_lifetime}"))
320+
}
321+
311322
// The user wrote `Path` and omitted the `<'_>`.
312-
(Hidden, Path { with_angle_brackets: false }) => {
323+
(Hidden, Path { angle_brackets: AngleBrackets::Missing }) => {
313324
(self.ident.span.shrink_to_hi(), format!("<{new_lifetime}>"))
314325
}
315326

compiler/rustc_lint/src/unused.rs

+16
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,22 @@ trait UnusedDelimLint {
942942
match s.kind {
943943
StmtKind::Let(ref local) if Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX => {
944944
if let Some((init, els)) = local.kind.init_else_opt() {
945+
if els.is_some()
946+
&& let ExprKind::Paren(paren) = &init.kind
947+
&& !init.span.eq_ctxt(paren.span)
948+
{
949+
// This branch prevents cases where parentheses wrap an expression
950+
// resulting from macro expansion, such as:
951+
// ```
952+
// macro_rules! x {
953+
// () => { None::<i32> };
954+
// }
955+
// let Some(_) = (x!{}) else { return };
956+
// // -> let Some(_) = (None::<i32>) else { return };
957+
// // ~ ~ No Lint
958+
// ```
959+
return;
960+
}
945961
let ctx = match els {
946962
None => UnusedDelimsCtx::AssignedValue,
947963
Some(_) => UnusedDelimsCtx::AssignedValueLetElse,

compiler/rustc_target/src/target_features.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
401401
("avx512cd", Unstable(sym::avx512_target_feature), &["avx512f"]),
402402
("avx512dq", Unstable(sym::avx512_target_feature), &["avx512f"]),
403403
("avx512f", Unstable(sym::avx512_target_feature), &["avx2", "fma", "f16c"]),
404-
("avx512fp16", Unstable(sym::avx512_target_feature), &["avx512bw", "avx512vl", "avx512dq"]),
404+
("avx512fp16", Unstable(sym::avx512_target_feature), &["avx512bw"]),
405405
("avx512ifma", Unstable(sym::avx512_target_feature), &["avx512f"]),
406406
("avx512vbmi", Unstable(sym::avx512_target_feature), &["avx512bw"]),
407407
("avx512vbmi2", Unstable(sym::avx512_target_feature), &["avx512bw"]),
@@ -510,7 +510,7 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
510510
("unaligned-vector-mem", Unstable(sym::riscv_target_feature), &[]),
511511
("v", Unstable(sym::riscv_target_feature), &["zvl128b", "zve64d"]),
512512
("za128rs", Unstable(sym::riscv_target_feature), &[]),
513-
("za64rs", Unstable(sym::riscv_target_feature), &[]),
513+
("za64rs", Unstable(sym::riscv_target_feature), &["za128rs"]), // Za64rs ⊃ Za128rs
514514
("zaamo", Unstable(sym::riscv_target_feature), &[]),
515515
("zabha", Unstable(sym::riscv_target_feature), &["zaamo"]),
516516
("zacas", Unstable(sym::riscv_target_feature), &["zaamo"]),
@@ -529,12 +529,20 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
529529
("zcmop", Unstable(sym::riscv_target_feature), &["zca"]),
530530
("zdinx", Unstable(sym::riscv_target_feature), &["zfinx"]),
531531
("zfa", Unstable(sym::riscv_target_feature), &["f"]),
532+
("zfbfmin", Unstable(sym::riscv_target_feature), &["f"]), // and a subset of Zfhmin
532533
("zfh", Unstable(sym::riscv_target_feature), &["zfhmin"]),
533534
("zfhmin", Unstable(sym::riscv_target_feature), &["f"]),
534535
("zfinx", Unstable(sym::riscv_target_feature), &["zicsr"]),
535536
("zhinx", Unstable(sym::riscv_target_feature), &["zhinxmin"]),
536537
("zhinxmin", Unstable(sym::riscv_target_feature), &["zfinx"]),
538+
("zic64b", Unstable(sym::riscv_target_feature), &[]),
539+
("zicbom", Unstable(sym::riscv_target_feature), &[]),
540+
("zicbop", Unstable(sym::riscv_target_feature), &[]),
537541
("zicboz", Unstable(sym::riscv_target_feature), &[]),
542+
("ziccamoa", Unstable(sym::riscv_target_feature), &[]),
543+
("ziccif", Unstable(sym::riscv_target_feature), &[]),
544+
("zicclsm", Unstable(sym::riscv_target_feature), &[]),
545+
("ziccrse", Unstable(sym::riscv_target_feature), &[]),
538546
("zicntr", Unstable(sym::riscv_target_feature), &["zicsr"]),
539547
("zicond", Unstable(sym::riscv_target_feature), &[]),
540548
("zicsr", Unstable(sym::riscv_target_feature), &[]),
@@ -561,6 +569,8 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
561569
("zve64d", Unstable(sym::riscv_target_feature), &["zve64f", "d"]),
562570
("zve64f", Unstable(sym::riscv_target_feature), &["zve32f", "zve64x"]),
563571
("zve64x", Unstable(sym::riscv_target_feature), &["zve32x", "zvl64b"]),
572+
("zvfbfmin", Unstable(sym::riscv_target_feature), &["zve32f"]),
573+
("zvfbfwma", Unstable(sym::riscv_target_feature), &["zfbfmin", "zvfbfmin"]),
564574
("zvfh", Unstable(sym::riscv_target_feature), &["zvfhmin", "zve32f", "zfhmin"]), // Zvfh ⊃ Zvfhmin
565575
("zvfhmin", Unstable(sym::riscv_target_feature), &["zve32f"]),
566576
("zvkb", Unstable(sym::riscv_target_feature), &["zve32x"]),
@@ -966,12 +976,12 @@ impl Target {
966976
// about what the intended ABI is.
967977
match &*self.llvm_abiname {
968978
"ilp32d" | "lp64d" => {
969-
// Requires d (which implies f), incompatible with e.
970-
FeatureConstraints { required: &["d"], incompatible: &["e"] }
979+
// Requires d (which implies f), incompatible with e and zfinx.
980+
FeatureConstraints { required: &["d"], incompatible: &["e", "zfinx"] }
971981
}
972982
"ilp32f" | "lp64f" => {
973-
// Requires f, incompatible with e.
974-
FeatureConstraints { required: &["f"], incompatible: &["e"] }
983+
// Requires f, incompatible with e and zfinx.
984+
FeatureConstraints { required: &["f"], incompatible: &["e", "zfinx"] }
975985
}
976986
"ilp32" | "lp64" => {
977987
// Requires nothing, incompatible with e.

library/core/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ level = "warn"
3131
check-cfg = [
3232
'cfg(bootstrap)',
3333
'cfg(no_fp_fmt_parse)',
34-
'cfg(stdarch_intel_sde)',
3534
# core use #[path] imports to portable-simd `core_simd` crate
3635
# and to stdarch `core_arch` crate which messes-up with Cargo list
3736
# of declared features, we therefor expect any feature cfg

0 commit comments

Comments
 (0)