Skip to content

Commit 4a9013e

Browse files
committed
Auto merge of rust-lang#139761 - jhpratt:rollup-tki77or, r=jhpratt
Rollup of 11 pull requests Successful merges: - rust-lang#137043 (Initial `UnsafePinned` implementation [Part 1: Libs]) - rust-lang#138962 (Expect an array when expected and acutal types are both arrays during cast) - rust-lang#139001 (add `naked_functions_rustic_abi` feature gate) - rust-lang#139379 (Use delayed bug for normalization errors in drop elaboration) - rust-lang#139582 (Various coercion cleanups) - rust-lang#139628 (Suggest remove redundant `$()?` around `vis`) - rust-lang#139644 (Micro-optimize `InstSimplify`'s `simplify_primitive_clone`) - rust-lang#139671 (Proc macro span API redesign: Replace proc_macro::SourceFile by Span::{file, local_file}) - rust-lang#139674 (In `rustc_mir_transform`, iterate over index newtypes instead of ints) - rust-lang#139740 (Convert `tests/ui/lint/dead-code/self-assign.rs` to a known-bug test) - rust-lang#139741 (fix smir's run! doc and import) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 092a284 + d454788 commit 4a9013e

File tree

85 files changed

+901
-558
lines changed

Some content is hidden

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

85 files changed

+901
-558
lines changed

Diff for: compiler/rustc_abi/src/layout.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
315315
repr: &ReprOptions,
316316
variants: &IndexSlice<VariantIdx, IndexVec<FieldIdx, F>>,
317317
is_enum: bool,
318-
is_unsafe_cell: bool,
318+
is_special_no_niche: bool,
319319
scalar_valid_range: (Bound<u128>, Bound<u128>),
320320
discr_range_of_repr: impl Fn(i128, i128) -> (Integer, bool),
321321
discriminants: impl Iterator<Item = (VariantIdx, i128)>,
@@ -348,7 +348,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
348348
repr,
349349
variants,
350350
is_enum,
351-
is_unsafe_cell,
351+
is_special_no_niche,
352352
scalar_valid_range,
353353
always_sized,
354354
present_first,
@@ -505,7 +505,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
505505
repr: &ReprOptions,
506506
variants: &IndexSlice<VariantIdx, IndexVec<FieldIdx, F>>,
507507
is_enum: bool,
508-
is_unsafe_cell: bool,
508+
is_special_no_niche: bool,
509509
scalar_valid_range: (Bound<u128>, Bound<u128>),
510510
always_sized: bool,
511511
present_first: VariantIdx,
@@ -524,7 +524,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
524524
let mut st = self.univariant(&variants[v], repr, kind)?;
525525
st.variants = Variants::Single { index: v };
526526

527-
if is_unsafe_cell {
527+
if is_special_no_niche {
528528
let hide_niches = |scalar: &mut _| match scalar {
529529
Scalar::Initialized { value, valid_range } => {
530530
*valid_range = WrappingRange::full(value.size(dl))

Diff for: compiler/rustc_expand/src/mbe/macro_rules.rs

+38-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_ast::{self as ast, DUMMY_NODE_ID, NodeId};
1212
use rustc_ast_pretty::pprust;
1313
use rustc_attr_parsing::{AttributeKind, find_attr};
1414
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
15-
use rustc_errors::{Applicability, ErrorGuaranteed};
15+
use rustc_errors::{Applicability, Diag, ErrorGuaranteed};
1616
use rustc_feature::Features;
1717
use rustc_hir as hir;
1818
use rustc_lint_defs::BuiltinLintDiag;
@@ -27,19 +27,18 @@ use rustc_span::hygiene::Transparency;
2727
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, kw, sym};
2828
use tracing::{debug, instrument, trace, trace_span};
2929

30-
use super::diagnostics;
3130
use super::macro_parser::{NamedMatches, NamedParseResult};
31+
use super::{SequenceRepetition, diagnostics};
3232
use crate::base::{
3333
DummyResult, ExpandResult, ExtCtxt, MacResult, MacroExpanderResult, SyntaxExtension,
3434
SyntaxExtensionKind, TTMacroExpander,
3535
};
3636
use crate::expand::{AstFragment, AstFragmentKind, ensure_complete_parse, parse_ast_fragment};
37-
use crate::mbe;
3837
use crate::mbe::diagnostics::{annotate_doc_comment, parse_failure_msg};
39-
use crate::mbe::macro_check;
4038
use crate::mbe::macro_parser::NamedMatch::*;
4139
use crate::mbe::macro_parser::{Error, ErrorReported, Failure, MatcherLoc, Success, TtParser};
4240
use crate::mbe::transcribe::transcribe;
41+
use crate::mbe::{self, KleeneOp, macro_check};
4342

4443
pub(crate) struct ParserAnyMacro<'a> {
4544
parser: Parser<'a>,
@@ -640,6 +639,37 @@ fn is_empty_token_tree(sess: &Session, seq: &mbe::SequenceRepetition) -> bool {
640639
}
641640
}
642641

642+
/// Checks if a `vis` nonterminal fragment is unnecessarily wrapped in an optional repetition.
643+
///
644+
/// When a `vis` fragment (which can already be empty) is wrapped in `$(...)?`,
645+
/// this suggests removing the redundant repetition syntax since it provides no additional benefit.
646+
fn check_redundant_vis_repetition(
647+
err: &mut Diag<'_>,
648+
sess: &Session,
649+
seq: &SequenceRepetition,
650+
span: &DelimSpan,
651+
) {
652+
let is_zero_or_one: bool = seq.kleene.op == KleeneOp::ZeroOrOne;
653+
let is_vis = seq.tts.first().map_or(false, |tt| {
654+
matches!(tt, mbe::TokenTree::MetaVarDecl(_, _, Some(NonterminalKind::Vis)))
655+
});
656+
657+
if is_vis && is_zero_or_one {
658+
err.note("a `vis` fragment can already be empty");
659+
err.multipart_suggestion(
660+
"remove the `$(` and `)?`",
661+
vec![
662+
(
663+
sess.source_map().span_extend_to_prev_char_before(span.open, '$', true),
664+
"".to_string(),
665+
),
666+
(span.close.with_hi(seq.kleene.span.hi()), "".to_string()),
667+
],
668+
Applicability::MaybeIncorrect,
669+
);
670+
}
671+
}
672+
643673
/// Checks that the lhs contains no repetition which could match an empty token
644674
/// tree, because then the matcher would hang indefinitely.
645675
fn check_lhs_no_empty_seq(sess: &Session, tts: &[mbe::TokenTree]) -> Result<(), ErrorGuaranteed> {
@@ -654,8 +684,10 @@ fn check_lhs_no_empty_seq(sess: &Session, tts: &[mbe::TokenTree]) -> Result<(),
654684
TokenTree::Sequence(span, seq) => {
655685
if is_empty_token_tree(sess, seq) {
656686
let sp = span.entire();
657-
let guar = sess.dcx().span_err(sp, "repetition matches empty token tree");
658-
return Err(guar);
687+
let mut err =
688+
sess.dcx().struct_span_err(sp, "repetition matches empty token tree");
689+
check_redundant_vis_repetition(&mut err, sess, seq, span);
690+
return Err(err.emit());
659691
}
660692
check_lhs_no_empty_seq(sess, &seq.tts)?
661693
}

Diff for: compiler/rustc_expand/src/proc_macro_server.rs

+24-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::ops::{Bound, Range};
2-
use std::sync::Arc;
32

43
use ast::token::IdentIsRaw;
54
use pm::bridge::{
@@ -18,7 +17,7 @@ use rustc_parse::parser::Parser;
1817
use rustc_parse::{exp, new_parser_from_source_str, source_str_to_stream, unwrap_or_emit_fatal};
1918
use rustc_session::parse::ParseSess;
2019
use rustc_span::def_id::CrateNum;
21-
use rustc_span::{BytePos, FileName, Pos, SourceFile, Span, Symbol, sym};
20+
use rustc_span::{BytePos, FileName, Pos, Span, Symbol, sym};
2221
use smallvec::{SmallVec, smallvec};
2322

2423
use crate::base::ExtCtxt;
@@ -467,7 +466,6 @@ impl<'a, 'b> Rustc<'a, 'b> {
467466
impl server::Types for Rustc<'_, '_> {
468467
type FreeFunctions = FreeFunctions;
469468
type TokenStream = TokenStream;
470-
type SourceFile = Arc<SourceFile>;
471469
type Span = Span;
472470
type Symbol = Symbol;
473471
}
@@ -673,28 +671,6 @@ impl server::TokenStream for Rustc<'_, '_> {
673671
}
674672
}
675673

676-
impl server::SourceFile for Rustc<'_, '_> {
677-
fn eq(&mut self, file1: &Self::SourceFile, file2: &Self::SourceFile) -> bool {
678-
Arc::ptr_eq(file1, file2)
679-
}
680-
681-
fn path(&mut self, file: &Self::SourceFile) -> String {
682-
match &file.name {
683-
FileName::Real(name) => name
684-
.local_path()
685-
.expect("attempting to get a file path in an imported file in `proc_macro::SourceFile::path`")
686-
.to_str()
687-
.expect("non-UTF8 file path in `proc_macro::SourceFile::path`")
688-
.to_string(),
689-
_ => file.name.prefer_local().to_string(),
690-
}
691-
}
692-
693-
fn is_real(&mut self, file: &Self::SourceFile) -> bool {
694-
file.is_real_file()
695-
}
696-
}
697-
698674
impl server::Span for Rustc<'_, '_> {
699675
fn debug(&mut self, span: Self::Span) -> String {
700676
if self.ecx.ecfg.span_debug {
@@ -704,8 +680,29 @@ impl server::Span for Rustc<'_, '_> {
704680
}
705681
}
706682

707-
fn source_file(&mut self, span: Self::Span) -> Self::SourceFile {
708-
self.psess().source_map().lookup_char_pos(span.lo()).file
683+
fn file(&mut self, span: Self::Span) -> String {
684+
self.psess()
685+
.source_map()
686+
.lookup_char_pos(span.lo())
687+
.file
688+
.name
689+
.prefer_remapped_unconditionaly()
690+
.to_string()
691+
}
692+
693+
fn local_file(&mut self, span: Self::Span) -> Option<String> {
694+
self.psess()
695+
.source_map()
696+
.lookup_char_pos(span.lo())
697+
.file
698+
.name
699+
.clone()
700+
.into_local_path()
701+
.map(|p| {
702+
p.to_str()
703+
.expect("non-UTF8 file path in `proc_macro::SourceFile::path`")
704+
.to_string()
705+
})
709706
}
710707

711708
fn parent(&mut self, span: Self::Span) -> Option<Self::Span> {

Diff for: compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ declare_features! (
565565
(incomplete, mut_ref, "1.79.0", Some(123076)),
566566
/// Allows using `#[naked]` on functions.
567567
(unstable, naked_functions, "1.9.0", Some(90957)),
568+
/// Allows using `#[naked]` on `extern "Rust"` functions.
569+
(unstable, naked_functions_rustic_abi, "CURRENT_RUSTC_VERSION", Some(138997)),
568570
/// Allows using `#[target_feature(enable = "...")]` on `#[naked]` on functions.
569571
(unstable, naked_functions_target_feature, "1.86.0", Some(138568)),
570572
/// Allows specifying the as-needed link modifier

Diff for: compiler/rustc_fluent_macro/src/fluent.rs

+3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ fn invocation_relative_path_to_absolute(span: Span, path: &str) -> PathBuf {
2525
path.to_path_buf()
2626
} else {
2727
// `/a/b/c/foo/bar.rs` contains the current macro invocation
28+
#[cfg(bootstrap)]
2829
let mut source_file_path = span.source_file().path();
30+
#[cfg(not(bootstrap))]
31+
let mut source_file_path = span.local_file().unwrap();
2932
// `/a/b/c/foo/`
3033
source_file_path.pop();
3134
// `/a/b/c/foo/../locales/en-US/example.ftl`

Diff for: compiler/rustc_hir/src/lang_items.rs

+3
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ language_item_table! {
182182
DynMetadata, sym::dyn_metadata, dyn_metadata, Target::Struct, GenericRequirement::None;
183183

184184
Freeze, sym::freeze, freeze_trait, Target::Trait, GenericRequirement::Exact(0);
185+
UnsafeUnpin, sym::unsafe_unpin, unsafe_unpin_trait, Target::Trait, GenericRequirement::Exact(0);
185186

186187
FnPtrTrait, sym::fn_ptr_trait, fn_ptr_trait, Target::Trait, GenericRequirement::Exact(0);
187188
FnPtrAddr, sym::fn_ptr_addr, fn_ptr_addr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
@@ -235,6 +236,8 @@ language_item_table! {
235236
IndexMut, sym::index_mut, index_mut_trait, Target::Trait, GenericRequirement::Exact(1);
236237

237238
UnsafeCell, sym::unsafe_cell, unsafe_cell_type, Target::Struct, GenericRequirement::None;
239+
UnsafePinned, sym::unsafe_pinned, unsafe_pinned_type, Target::Struct, GenericRequirement::None;
240+
238241
VaList, sym::va_list, va_list, Target::Struct, GenericRequirement::None;
239242

240243
Deref, sym::deref, deref_trait, Target::Trait, GenericRequirement::Exact(0);

Diff for: compiler/rustc_hir_typeck/src/cast.rs

+20-19
Original file line numberDiff line numberDiff line change
@@ -1042,30 +1042,31 @@ impl<'a, 'tcx> CastCheck<'tcx> {
10421042
m_cast: ty::TypeAndMut<'tcx>,
10431043
) -> Result<CastKind, CastError<'tcx>> {
10441044
// array-ptr-cast: allow mut-to-mut, mut-to-const, const-to-const
1045-
if m_expr.mutbl >= m_cast.mutbl {
1046-
if let ty::Array(ety, _) = m_expr.ty.kind() {
1047-
// Due to the limitations of LLVM global constants,
1048-
// region pointers end up pointing at copies of
1049-
// vector elements instead of the original values.
1050-
// To allow raw pointers to work correctly, we
1051-
// need to special-case obtaining a raw pointer
1052-
// from a region pointer to a vector.
1053-
1054-
// Coerce to a raw pointer so that we generate RawPtr in MIR.
1055-
let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr.ty, m_expr.mutbl);
1056-
fcx.coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None)
1057-
.unwrap_or_else(|_| {
1058-
bug!(
1045+
if m_expr.mutbl >= m_cast.mutbl
1046+
&& let ty::Array(ety, _) = m_expr.ty.kind()
1047+
&& fcx.can_eq(fcx.param_env, *ety, m_cast.ty)
1048+
{
1049+
// Due to the limitations of LLVM global constants,
1050+
// region pointers end up pointing at copies of
1051+
// vector elements instead of the original values.
1052+
// To allow raw pointers to work correctly, we
1053+
// need to special-case obtaining a raw pointer
1054+
// from a region pointer to a vector.
1055+
1056+
// Coerce to a raw pointer so that we generate RawPtr in MIR.
1057+
let array_ptr_type = Ty::new_ptr(fcx.tcx, m_expr.ty, m_expr.mutbl);
1058+
fcx.coerce(self.expr, self.expr_ty, array_ptr_type, AllowTwoPhase::No, None)
1059+
.unwrap_or_else(|_| {
1060+
bug!(
10591061
"could not cast from reference to array to pointer to array ({:?} to {:?})",
10601062
self.expr_ty,
10611063
array_ptr_type,
10621064
)
1063-
});
1065+
});
10641066

1065-
// this will report a type mismatch if needed
1066-
fcx.demand_eqtype(self.span, *ety, m_cast.ty);
1067-
return Ok(CastKind::ArrayPtrCast);
1068-
}
1067+
// this will report a type mismatch if needed
1068+
fcx.demand_eqtype(self.span, *ety, m_cast.ty);
1069+
return Ok(CastKind::ArrayPtrCast);
10691070
}
10701071

10711072
Err(CastError::IllegalCast)

0 commit comments

Comments
 (0)