Skip to content

Commit 15c4cce

Browse files
committed
Auto merge of rust-lang#139940 - matthiaskrgr:rollup-rd4d3fn, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#135340 (Add `explicit_extern_abis` Feature and Enforce Explicit ABIs) - rust-lang#139440 (rustc_target: RISC-V: feature addition batch 2) - rust-lang#139667 (cfi: Remove #[no_sanitize(cfi)] for extern weak functions) - rust-lang#139828 (Don't require rigid alias's trait to hold) - rust-lang#139854 (Improve parse errors for stray lifetimes in type position) - rust-lang#139889 (Clean UI tests 3 of n) - rust-lang#139894 (Fix `opt-dist` CLI flag and make it work without LLD) - rust-lang#139900 (stepping into impls for normalization is unproductive) - rust-lang#139915 (replace some #[rustc_intrinsic] usage with use of the libcore declarations) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 79a272c + f8f22ad commit 15c4cce

File tree

79 files changed

+939
-231
lines changed

Some content is hidden

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

79 files changed

+939
-231
lines changed

compiler/rustc_ast_passes/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ ast_passes_extern_types_cannot = `type`s inside `extern` blocks cannot have {$de
7979
.suggestion = remove the {$remove_descr}
8080
.label = `extern` block begins here
8181
82+
ast_passes_extern_without_abi = `extern` declarations without an explicit ABI are disallowed
83+
.suggestion = specify an ABI
84+
.help = prior to Rust 2024, a default ABI was inferred
85+
8286
ast_passes_feature_on_non_nightly = `#![feature]` may not be used on the {$channel} release channel
8387
.suggestion = remove the attribute
8488
.stable_since = the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable

compiler/rustc_ast_passes/src/ast_validation.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ impl<'a> AstValidator<'a> {
684684
self.dcx().emit_err(errors::PatternFnPointer { span });
685685
});
686686
if let Extern::Implicit(extern_span) = bfty.ext {
687-
self.maybe_lint_missing_abi(extern_span, ty.id);
687+
self.handle_missing_abi(extern_span, ty.id);
688688
}
689689
}
690690
TyKind::TraitObject(bounds, ..) => {
@@ -717,10 +717,12 @@ impl<'a> AstValidator<'a> {
717717
}
718718
}
719719

720-
fn maybe_lint_missing_abi(&mut self, span: Span, id: NodeId) {
720+
fn handle_missing_abi(&mut self, span: Span, id: NodeId) {
721721
// FIXME(davidtwco): This is a hack to detect macros which produce spans of the
722722
// call site which do not have a macro backtrace. See #61963.
723-
if self
723+
if span.edition().at_least_edition_future() && self.features.explicit_extern_abis() {
724+
self.dcx().emit_err(errors::MissingAbi { span });
725+
} else if self
724726
.sess
725727
.source_map()
726728
.span_to_snippet(span)
@@ -996,7 +998,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
996998
}
997999

9981000
if abi.is_none() {
999-
self.maybe_lint_missing_abi(*extern_span, item.id);
1001+
self.handle_missing_abi(*extern_span, item.id);
10001002
}
10011003
self.with_in_extern_mod(*safety, |this| {
10021004
visit::walk_item(this, item);
@@ -1370,7 +1372,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13701372
},
13711373
) = fk
13721374
{
1373-
self.maybe_lint_missing_abi(*extern_span, id);
1375+
self.handle_missing_abi(*extern_span, id);
13741376
}
13751377

13761378
// Functions without bodies cannot have patterns.

compiler/rustc_ast_passes/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,12 @@ pub(crate) struct DuplicatePreciseCapturing {
823823
#[label]
824824
pub bound2: Span,
825825
}
826+
827+
#[derive(Diagnostic)]
828+
#[diag(ast_passes_extern_without_abi)]
829+
#[help]
830+
pub(crate) struct MissingAbi {
831+
#[primary_span]
832+
#[suggestion(code = "extern \"<abi>\"", applicability = "has-placeholders")]
833+
pub span: Span,
834+
}

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ declare_features! (
477477
(incomplete, ergonomic_clones, "1.87.0", Some(132290)),
478478
/// Allows exhaustive pattern matching on types that contain uninhabited types.
479479
(unstable, exhaustive_patterns, "1.13.0", Some(51085)),
480+
/// Disallows `extern` without an explicit ABI.
481+
(unstable, explicit_extern_abis, "CURRENT_RUSTC_VERSION", Some(134986)),
480482
/// Allows explicit tail calls via `become` expression.
481483
(incomplete, explicit_tail_calls, "1.72.0", Some(112788)),
482484
/// Allows using `aapcs`, `efiapi`, `sysv64` and `win64` as calling conventions

compiler/rustc_lint/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ lint_expectation = this lint expectation is unfulfilled
271271
lint_extern_crate_not_idiomatic = `extern crate` is not idiomatic in the new edition
272272
.suggestion = convert it to a `use`
273273
274-
lint_extern_without_abi = extern declarations without an explicit ABI are deprecated
274+
lint_extern_without_abi = `extern` declarations without an explicit ABI are deprecated
275275
.label = ABI should be specified here
276276
.suggestion = explicitly specify the {$default_abi} ABI
277277

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -286,18 +286,23 @@ where
286286
// fixing it may cause inference breakage or introduce ambiguity.
287287
GoalSource::Misc => PathKind::Unknown,
288288
GoalSource::NormalizeGoal(path_kind) => path_kind,
289-
GoalSource::ImplWhereBound => {
289+
GoalSource::ImplWhereBound => match self.current_goal_kind {
290290
// We currently only consider a cycle coinductive if it steps
291291
// into a where-clause of a coinductive trait.
292+
CurrentGoalKind::CoinductiveTrait => PathKind::Coinductive,
293+
// While normalizing via an impl does step into a where-clause of
294+
// an impl, accessing the associated item immediately steps out of
295+
// it again. This means cycles/recursive calls are not guarded
296+
// by impls used for normalization.
292297
//
298+
// See tests/ui/traits/next-solver/cycles/normalizes-to-is-not-productive.rs
299+
// for how this can go wrong.
300+
CurrentGoalKind::NormalizesTo => PathKind::Inductive,
293301
// We probably want to make all traits coinductive in the future,
294-
// so we treat cycles involving their where-clauses as ambiguous.
295-
if let CurrentGoalKind::CoinductiveTrait = self.current_goal_kind {
296-
PathKind::Coinductive
297-
} else {
298-
PathKind::Unknown
299-
}
300-
}
302+
// so we treat cycles involving where-clauses of not-yet coinductive
303+
// traits as ambiguous for now.
304+
CurrentGoalKind::Misc => PathKind::Unknown,
305+
},
301306
// Relating types is always unproductive. If we were to map proof trees to
302307
// corecursive functions as explained in #136824, relating types never
303308
// introduces a constructor which could cause the recursion to be guarded.

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ where
4545
goal,
4646
goal.predicate.alias,
4747
);
48-
this.add_goal(GoalSource::AliasWellFormed, goal.with(cx, trait_ref));
4948
this.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
5049
})
5150
})

compiler/rustc_parse/messages.ftl

+4-2
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ parse_maybe_recover_from_bad_qpath_stage_2 =
543543
.suggestion = types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
544544
545545
parse_maybe_recover_from_bad_type_plus =
546-
expected a path on the left-hand side of `+`, not `{$ty}`
546+
expected a path on the left-hand side of `+`
547547
548548
parse_maybe_report_ambiguous_plus =
549549
ambiguous `+` in a type
@@ -642,7 +642,9 @@ parse_mut_on_nested_ident_pattern = `mut` must be attached to each individual bi
642642
.suggestion = add `mut` to each binding
643643
parse_mut_on_non_ident_pattern = `mut` must be followed by a named binding
644644
.suggestion = remove the `mut` prefix
645-
parse_need_plus_after_trait_object_lifetime = lifetime in trait object type must be followed by `+`
645+
646+
parse_need_plus_after_trait_object_lifetime = lifetimes must be followed by `+` to form a trait object type
647+
.suggestion = consider adding a trait bound after the potential lifetime bound
646648
647649
parse_nested_adt = `{$kw_str}` definition cannot be nested inside `{$keyword}`
648650
.suggestion = consider creating a new `{$kw_str}` definition instead of nesting

compiler/rustc_parse/src/errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ pub(crate) struct AmbiguousPlus {
3030
#[derive(Diagnostic)]
3131
#[diag(parse_maybe_recover_from_bad_type_plus, code = E0178)]
3232
pub(crate) struct BadTypePlus {
33-
pub ty: String,
3433
#[primary_span]
3534
pub span: Span,
3635
#[subdiagnostic]
@@ -2800,6 +2799,8 @@ pub(crate) struct ReturnTypesUseThinArrow {
28002799
pub(crate) struct NeedPlusAfterTraitObjectLifetime {
28012800
#[primary_span]
28022801
pub span: Span,
2802+
#[suggestion(code = " + /* Trait */", applicability = "has-placeholders")]
2803+
pub suggestion: Span,
28032804
}
28042805

28052806
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/diagnostics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1657,19 +1657,19 @@ impl<'a> Parser<'a> {
16571657

16581658
self.bump(); // `+`
16591659
let _bounds = self.parse_generic_bounds()?;
1660-
let sum_span = ty.span.to(self.prev_token.span);
1661-
16621660
let sub = match &ty.kind {
16631661
TyKind::Ref(_lifetime, mut_ty) => {
16641662
let lo = mut_ty.ty.span.shrink_to_lo();
16651663
let hi = self.prev_token.span.shrink_to_hi();
16661664
BadTypePlusSub::AddParen { suggestion: AddParen { lo, hi } }
16671665
}
1668-
TyKind::Ptr(..) | TyKind::BareFn(..) => BadTypePlusSub::ForgotParen { span: sum_span },
1669-
_ => BadTypePlusSub::ExpectPath { span: sum_span },
1666+
TyKind::Ptr(..) | TyKind::BareFn(..) => {
1667+
BadTypePlusSub::ForgotParen { span: ty.span.to(self.prev_token.span) }
1668+
}
1669+
_ => BadTypePlusSub::ExpectPath { span: ty.span },
16701670
};
16711671

1672-
self.dcx().emit_err(BadTypePlus { ty: pprust::ty_to_string(ty), span: sum_span, sub });
1672+
self.dcx().emit_err(BadTypePlus { span: ty.span, sub });
16731673

16741674
Ok(())
16751675
}

compiler/rustc_parse/src/parser/ty.rs

+57-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_ast::{
77
Pinnedness, PolyTraitRef, PreciseCapturingArg, TraitBoundModifiers, TraitObjectSyntax, Ty,
88
TyKind, UnsafeBinderTy,
99
};
10-
use rustc_errors::{Applicability, PResult};
10+
use rustc_errors::{Applicability, Diag, PResult};
1111
use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym};
1212
use thin_vec::{ThinVec, thin_vec};
1313

@@ -411,6 +411,9 @@ impl<'a> Parser<'a> {
411411
TyKind::Path(None, path) if maybe_bounds => {
412412
self.parse_remaining_bounds_path(ThinVec::new(), path, lo, true)
413413
}
414+
// For `('a) + …`, we know that `'a` in type position already lead to an error being
415+
// emitted. To reduce output, let's indirectly suppress E0178 (bad `+` in type) and
416+
// other irrelevant consequential errors.
414417
TyKind::TraitObject(bounds, TraitObjectSyntax::None)
415418
if maybe_bounds && bounds.len() == 1 && !trailing_plus =>
416419
{
@@ -425,12 +428,60 @@ impl<'a> Parser<'a> {
425428
}
426429

427430
fn parse_bare_trait_object(&mut self, lo: Span, allow_plus: AllowPlus) -> PResult<'a, TyKind> {
428-
let lt_no_plus = self.check_lifetime() && !self.look_ahead(1, |t| t.is_like_plus());
429-
let bounds = self.parse_generic_bounds_common(allow_plus)?;
430-
if lt_no_plus {
431-
self.dcx().emit_err(NeedPlusAfterTraitObjectLifetime { span: lo });
431+
// A lifetime only begins a bare trait object type if it is followed by `+`!
432+
if self.token.is_lifetime() && !self.look_ahead(1, |t| t.is_like_plus()) {
433+
// In Rust 2021 and beyond, we assume that the user didn't intend to write a bare trait
434+
// object type with a leading lifetime bound since that seems very unlikely given the
435+
// fact that `dyn`-less trait objects are *semantically* invalid.
436+
if self.psess.edition.at_least_rust_2021() {
437+
let lt = self.expect_lifetime();
438+
let mut err = self.dcx().struct_span_err(lo, "expected type, found lifetime");
439+
err.span_label(lo, "expected type");
440+
return Ok(match self.maybe_recover_ref_ty_no_leading_ampersand(lt, lo, err) {
441+
Ok(ref_ty) => ref_ty,
442+
Err(err) => TyKind::Err(err.emit()),
443+
});
444+
}
445+
446+
self.dcx().emit_err(NeedPlusAfterTraitObjectLifetime {
447+
span: lo,
448+
suggestion: lo.shrink_to_hi(),
449+
});
450+
}
451+
Ok(TyKind::TraitObject(
452+
self.parse_generic_bounds_common(allow_plus)?,
453+
TraitObjectSyntax::None,
454+
))
455+
}
456+
457+
fn maybe_recover_ref_ty_no_leading_ampersand<'cx>(
458+
&mut self,
459+
lt: Lifetime,
460+
lo: Span,
461+
mut err: Diag<'cx>,
462+
) -> Result<TyKind, Diag<'cx>> {
463+
if !self.may_recover() {
464+
return Err(err);
465+
}
466+
let snapshot = self.create_snapshot_for_diagnostic();
467+
let mutbl = self.parse_mutability();
468+
match self.parse_ty_no_plus() {
469+
Ok(ty) => {
470+
err.span_suggestion_verbose(
471+
lo.shrink_to_lo(),
472+
"you might have meant to write a reference type here",
473+
"&",
474+
Applicability::MaybeIncorrect,
475+
);
476+
err.emit();
477+
Ok(TyKind::Ref(Some(lt), MutTy { ty, mutbl }))
478+
}
479+
Err(diag) => {
480+
diag.cancel();
481+
self.restore_snapshot(snapshot);
482+
Err(err)
483+
}
432484
}
433-
Ok(TyKind::TraitObject(bounds, TraitObjectSyntax::None))
434485
}
435486

436487
fn parse_remaining_bounds_path(

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,7 @@ symbols! {
916916
expf16,
917917
expf32,
918918
expf64,
919+
explicit_extern_abis,
919920
explicit_generic_args_with_impl_trait,
920921
explicit_tail_calls,
921922
export_name,

compiler/rustc_target/src/spec/targets/riscv64_linux_android.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) fn target() -> Target {
1919
options: TargetOptions {
2020
code_model: Some(CodeModel::Medium),
2121
cpu: "generic-rv64".into(),
22-
features: "+m,+a,+f,+d,+c,+zicsr,+zifencei,+zba,+zbb,+zbs,+v".into(),
22+
features: "+m,+a,+f,+d,+c,+b,+v,+zicsr,+zifencei".into(),
2323
llvm_abiname: "lp64d".into(),
2424
supported_sanitizers: SanitizerSet::ADDRESS,
2525
max_atomic_width: Some(64),

compiler/rustc_target/src/target_features.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ const MIPS_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
491491
static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
492492
// tidy-alphabetical-start
493493
("a", Stable, &["zaamo", "zalrsc"]),
494-
("c", Stable, &[]),
494+
("b", Unstable(sym::riscv_target_feature), &["zba", "zbb", "zbs"]),
495+
("c", Stable, &["zca"]),
495496
("d", Unstable(sym::riscv_target_feature), &["f"]),
496497
("e", Unstable(sym::riscv_target_feature), &[]),
497498
("f", Unstable(sym::riscv_target_feature), &["zicsr"]),
@@ -520,17 +521,25 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
520521
("zbkc", Stable, &[]),
521522
("zbkx", Stable, &[]),
522523
("zbs", Stable, &[]),
524+
("zca", Unstable(sym::riscv_target_feature), &[]),
525+
("zcb", Unstable(sym::riscv_target_feature), &["zca"]),
526+
("zcmop", Unstable(sym::riscv_target_feature), &["zca"]),
523527
("zdinx", Unstable(sym::riscv_target_feature), &["zfinx"]),
528+
("zfa", Unstable(sym::riscv_target_feature), &["f"]),
524529
("zfh", Unstable(sym::riscv_target_feature), &["zfhmin"]),
525530
("zfhmin", Unstable(sym::riscv_target_feature), &["f"]),
526531
("zfinx", Unstable(sym::riscv_target_feature), &["zicsr"]),
527532
("zhinx", Unstable(sym::riscv_target_feature), &["zhinxmin"]),
528533
("zhinxmin", Unstable(sym::riscv_target_feature), &["zfinx"]),
534+
("zicboz", Unstable(sym::riscv_target_feature), &[]),
529535
("zicntr", Unstable(sym::riscv_target_feature), &["zicsr"]),
536+
("zicond", Unstable(sym::riscv_target_feature), &[]),
530537
("zicsr", Unstable(sym::riscv_target_feature), &[]),
531538
("zifencei", Unstable(sym::riscv_target_feature), &[]),
539+
("zihintntl", Unstable(sym::riscv_target_feature), &[]),
532540
("zihintpause", Unstable(sym::riscv_target_feature), &[]),
533541
("zihpm", Unstable(sym::riscv_target_feature), &["zicsr"]),
542+
("zimop", Unstable(sym::riscv_target_feature), &[]),
534543
("zk", Stable, &["zkn", "zkr", "zkt"]),
535544
("zkn", Stable, &["zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"]),
536545
("zknd", Stable, &[]),
@@ -541,6 +550,7 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
541550
("zksed", Stable, &[]),
542551
("zksh", Stable, &[]),
543552
("zkt", Stable, &[]),
553+
("ztso", Unstable(sym::riscv_target_feature), &[]),
544554
("zvbb", Unstable(sym::riscv_target_feature), &["zvkb"]),
545555
("zvbc", Unstable(sym::riscv_target_feature), &["zve64x"]),
546556
("zve32f", Unstable(sym::riscv_target_feature), &["zve32x", "f"]),

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@
312312
#![feature(needs_panic_runtime)]
313313
#![feature(negative_impls)]
314314
#![feature(never_type)]
315-
#![feature(no_sanitize)]
316315
#![feature(optimize_attribute)]
317316
#![feature(prelude_import)]
318317
#![feature(rustc_attrs)]

library/std/src/sys/fd/unix.rs

-3
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,6 @@ impl FileDesc {
259259
}
260260

261261
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
262-
// FIXME(#115199): Rust currently omits weak function definitions
263-
// and its metadata from LLVM IR.
264-
#[no_sanitize(cfi)]
265262
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
266263
weak!(
267264
fn preadv64(

library/std/src/sys/fs/unix.rs

-14
Original file line numberDiff line numberDiff line change
@@ -1463,20 +1463,6 @@ impl File {
14631463
Ok(())
14641464
}
14651465

1466-
// FIXME(#115199): Rust currently omits weak function definitions
1467-
// and its metadata from LLVM IR.
1468-
#[cfg_attr(
1469-
any(
1470-
target_os = "android",
1471-
all(
1472-
target_os = "linux",
1473-
target_env = "gnu",
1474-
target_pointer_width = "32",
1475-
not(target_arch = "riscv32")
1476-
)
1477-
),
1478-
no_sanitize(cfi)
1479-
)]
14801466
pub fn set_times(&self, times: FileTimes) -> io::Result<()> {
14811467
#[cfg(not(any(
14821468
target_os = "redox",

library/std/src/sys/pal/unix/thread.rs

-3
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,6 @@ impl Thread {
194194
}
195195

196196
#[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "nto"))]
197-
// FIXME(#115199): Rust currently omits weak function definitions
198-
// and its metadata from LLVM IR.
199-
#[no_sanitize(cfi)]
200197
pub fn set_name(name: &CStr) {
201198
weak!(
202199
fn pthread_setname_np(

library/std/src/sys/pal/unix/time.rs

-11
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,6 @@ impl Timespec {
9696
}
9797
}
9898

99-
// FIXME(#115199): Rust currently omits weak function definitions
100-
// and its metadata from LLVM IR.
101-
#[cfg_attr(
102-
all(
103-
target_os = "linux",
104-
target_env = "gnu",
105-
target_pointer_width = "32",
106-
not(target_arch = "riscv32")
107-
),
108-
no_sanitize(cfi)
109-
)]
11099
pub fn now(clock: libc::clockid_t) -> Timespec {
111100
use crate::mem::MaybeUninit;
112101
use crate::sys::cvt;

0 commit comments

Comments
 (0)