Skip to content

Commit 7b0e554

Browse files
committed
Auto merge of #88329 - LeSeulArtichaut:rollup-blg8hc0, r=LeSeulArtichaut
Rollup of 16 pull requests Successful merges: - #87944 (add Cell::as_array_of_cells, similar to Cell::as_slice_of_cells) - #88156 (Adjust / fix documentation of `Arc::make_mut`) - #88157 (bootstrap.py: recognize riscv64 when auto-detect) - #88196 (Refactor `named_asm_labels` to a HIR lint) - #88218 (Remove `Session.trait_methods_not_found`) - #88223 (Remove the `TryV2` alias) - #88226 (Fix typo “a Rc” → “an Rc” (and a few more)) - #88267 (2229: Update signature for truncate function) - #88273 (Fix references to `ControlFlow` in docs) - #88277 (Update books) - #88291 (Add SAFETY comments to core::slice::sort::partition_in_blocks) - #88293 (Fix grammar in alloc test) - #88298 (Errorkind reorder) - #88299 (Stabilise BufWriter::into_parts) - #88314 (Add type of a let tait test) - #88325 (Add mutable-noalias to the release notes for 1.54) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents a992a11 + d9ed23a commit 7b0e554

File tree

45 files changed

+682
-319
lines changed

Some content is hidden

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

45 files changed

+682
-319
lines changed

RELEASES.md

+2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ Compiler
175175
- [Improved debugger output for enums on Windows MSVC platforms.][85292]
176176
- [Added tier 3\* support for `bpfel-unknown-none`
177177
and `bpfeb-unknown-none`.][79608]
178+
- [`-Zmutable-noalias=yes`][82834] is enabled by default when using LLVM 12 or above.
178179

179180
\* Refer to Rust's [platform support page][platform-support-doc] for more
180181
information on Rust's tiered platform support.
@@ -244,6 +245,7 @@ Compatibility Notes
244245
[83366]: https://github.com/rust-lang/rust/pull/83366
245246
[83278]: https://github.com/rust-lang/rust/pull/83278
246247
[85292]: https://github.com/rust-lang/rust/pull/85292
248+
[82834]: https://github.com/rust-lang/rust/pull/82834
247249
[cargo/9520]: https://github.com/rust-lang/cargo/pull/9520
248250
[cargo/9499]: https://github.com/rust-lang/cargo/pull/9499
249251
[cargo/9488]: https://github.com/rust-lang/cargo/pull/9488

compiler/rustc_ast/src/ast.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,7 @@ pub enum InlineAsmOperand {
20282028
#[derive(Clone, Encodable, Decodable, Debug)]
20292029
pub struct InlineAsm {
20302030
pub template: Vec<InlineAsmTemplatePiece>,
2031+
pub template_strs: Box<[(Symbol, Option<Symbol>, Span)]>,
20312032
pub operands: Vec<(InlineAsmOperand, Span)>,
20322033
pub clobber_abi: Option<(Symbol, Span)>,
20332034
pub options: InlineAsmOptions,

compiler/rustc_ast/src/visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ use crate::token;
1919
use rustc_span::symbol::{Ident, Symbol};
2020
use rustc_span::Span;
2121

22-
#[derive(Copy, Clone, PartialEq)]
22+
#[derive(Copy, Clone, Debug, PartialEq)]
2323
pub enum AssocCtxt {
2424
Trait,
2525
Impl,
2626
}
2727

28-
#[derive(Copy, Clone, PartialEq)]
28+
#[derive(Copy, Clone, Debug, PartialEq)]
2929
pub enum FnCtxt {
3030
Free,
3131
Foreign,
3232
Assoc(AssocCtxt),
3333
}
3434

35-
#[derive(Copy, Clone)]
35+
#[derive(Copy, Clone, Debug)]
3636
pub enum FnKind<'a> {
3737
/// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
3838
Fn(FnCtxt, Ident, &'a FnSig, &'a Visibility, Option<&'a Block>),

compiler/rustc_ast_lowering/src/asm.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
392392

393393
let operands = self.arena.alloc_from_iter(operands);
394394
let template = self.arena.alloc_from_iter(asm.template.iter().cloned());
395+
let template_strs = self.arena.alloc_from_iter(asm.template_strs.iter().cloned());
395396
let line_spans = self.arena.alloc_slice(&asm.line_spans[..]);
396-
let hir_asm = hir::InlineAsm { template, operands, options: asm.options, line_spans };
397+
let hir_asm =
398+
hir::InlineAsm { template, template_strs, operands, options: asm.options, line_spans };
397399
self.arena.alloc(hir_asm)
398400
}
399401
}

compiler/rustc_builtin_macros/src/asm.rs

+14-76
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
77
use rustc_expand::base::{self, *};
88
use rustc_parse::parser::Parser;
99
use rustc_parse_format as parse;
10-
use rustc_session::lint::{self, BuiltinLintDiagnostics};
10+
use rustc_session::lint;
1111
use rustc_span::symbol::Ident;
1212
use rustc_span::symbol::{kw, sym, Symbol};
13-
use rustc_span::{InnerSpan, MultiSpan, Span};
13+
use rustc_span::{InnerSpan, Span};
1414
use rustc_target::asm::InlineAsmArch;
1515
use smallvec::smallvec;
1616

@@ -484,11 +484,7 @@ fn parse_reg<'a>(
484484
Ok(result)
485485
}
486486

487-
fn expand_preparsed_asm(
488-
ecx: &mut ExtCtxt<'_>,
489-
args: AsmArgs,
490-
is_local_asm: bool,
491-
) -> Option<ast::InlineAsm> {
487+
fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::InlineAsm> {
492488
let mut template = vec![];
493489
// Register operands are implicitly used since they are not allowed to be
494490
// referenced in the template string.
@@ -501,6 +497,8 @@ fn expand_preparsed_asm(
501497
let mut line_spans = Vec::with_capacity(args.templates.len());
502498
let mut curarg = 0;
503499

500+
let mut template_strs = Vec::with_capacity(args.templates.len());
501+
504502
for template_expr in args.templates.into_iter() {
505503
if !template.is_empty() {
506504
template.push(ast::InlineAsmTemplatePiece::String("\n".to_string()));
@@ -524,8 +522,13 @@ fn expand_preparsed_asm(
524522
ast::StrStyle::Raw(raw) => Some(raw as usize),
525523
};
526524

527-
let template_str = &template_str.as_str();
528525
let template_snippet = ecx.source_map().span_to_snippet(template_sp).ok();
526+
template_strs.push((
527+
template_str,
528+
template_snippet.as_ref().map(|s| Symbol::intern(s)),
529+
template_sp,
530+
));
531+
let template_str = &template_str.as_str();
529532

530533
if let Some(InlineAsmArch::X86 | InlineAsmArch::X86_64) = ecx.sess.asm_arch {
531534
let find_span = |needle: &str| -> Span {
@@ -560,72 +563,6 @@ fn expand_preparsed_asm(
560563
}
561564
}
562565

563-
// Lint against the use of named labels in inline `asm!` but not `global_asm!`
564-
if is_local_asm {
565-
let find_label_span = |needle: &str| -> Option<Span> {
566-
if let Some(snippet) = &template_snippet {
567-
if let Some(pos) = snippet.find(needle) {
568-
let end = pos
569-
+ &snippet[pos..]
570-
.find(|c| c == ':')
571-
.unwrap_or(snippet[pos..].len() - 1);
572-
let inner = InnerSpan::new(pos, end);
573-
return Some(template_sp.from_inner(inner));
574-
}
575-
}
576-
577-
None
578-
};
579-
580-
let mut found_labels = Vec::new();
581-
582-
// A semicolon might not actually be specified as a separator for all targets, but it seems like LLVM accepts it always
583-
let statements = template_str.split(|c| matches!(c, '\n' | ';'));
584-
for statement in statements {
585-
// If there's a comment, trim it from the statement
586-
let statement = statement.find("//").map_or(statement, |idx| &statement[..idx]);
587-
let mut start_idx = 0;
588-
for (idx, _) in statement.match_indices(':') {
589-
let possible_label = statement[start_idx..idx].trim();
590-
let mut chars = possible_label.chars();
591-
if let Some(c) = chars.next() {
592-
// A label starts with an alphabetic character or . or _ and continues with alphanumeric characters, _, or $
593-
if (c.is_alphabetic() || matches!(c, '.' | '_'))
594-
&& chars.all(|c| c.is_alphanumeric() || matches!(c, '_' | '$'))
595-
{
596-
found_labels.push(possible_label);
597-
} else {
598-
// If we encounter a non-label, there cannot be any further labels, so stop checking
599-
break;
600-
}
601-
} else {
602-
// Empty string means a leading ':' in this section, which is not a label
603-
break;
604-
}
605-
606-
start_idx = idx + 1;
607-
}
608-
}
609-
610-
if found_labels.len() > 0 {
611-
let spans =
612-
found_labels.into_iter().filter_map(find_label_span).collect::<Vec<Span>>();
613-
// If there were labels but we couldn't find a span, combine the warnings and use the template span
614-
let target_spans: MultiSpan =
615-
if spans.len() > 0 { spans.into() } else { template_sp.into() };
616-
ecx.parse_sess().buffer_lint_with_diagnostic(
617-
lint::builtin::NAMED_ASM_LABELS,
618-
target_spans,
619-
ecx.current_expansion.lint_node_id,
620-
"avoid using named labels in inline assembly",
621-
BuiltinLintDiagnostics::NamedAsmLabel(
622-
"only local labels of the form `<number>:` should be used in inline asm"
623-
.to_string(),
624-
),
625-
);
626-
}
627-
}
628-
629566
// Don't treat raw asm as a format string.
630567
if args.options.contains(ast::InlineAsmOptions::RAW) {
631568
template.push(ast::InlineAsmTemplatePiece::String(template_str.to_string()));
@@ -819,6 +756,7 @@ fn expand_preparsed_asm(
819756

820757
Some(ast::InlineAsm {
821758
template,
759+
template_strs: template_strs.into_boxed_slice(),
822760
operands: args.operands,
823761
clobber_abi: args.clobber_abi,
824762
options: args.options,
@@ -833,7 +771,7 @@ pub fn expand_asm<'cx>(
833771
) -> Box<dyn base::MacResult + 'cx> {
834772
match parse_args(ecx, sp, tts, false) {
835773
Ok(args) => {
836-
let expr = if let Some(inline_asm) = expand_preparsed_asm(ecx, args, true) {
774+
let expr = if let Some(inline_asm) = expand_preparsed_asm(ecx, args) {
837775
P(ast::Expr {
838776
id: ast::DUMMY_NODE_ID,
839777
kind: ast::ExprKind::InlineAsm(P(inline_asm)),
@@ -860,7 +798,7 @@ pub fn expand_global_asm<'cx>(
860798
) -> Box<dyn base::MacResult + 'cx> {
861799
match parse_args(ecx, sp, tts, true) {
862800
Ok(args) => {
863-
if let Some(inline_asm) = expand_preparsed_asm(ecx, args, false) {
801+
if let Some(inline_asm) = expand_preparsed_asm(ecx, args) {
864802
MacEager::items(smallvec![P(ast::Item {
865803
ident: Ident::invalid(),
866804
attrs: Vec::new(),

compiler/rustc_data_structures/src/owning_ref/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
This crate provides the _owning reference_ types `OwningRef` and `OwningRefMut`
77
that enables it to bundle a reference together with the owner of the data it points to.
8-
This allows moving and dropping of a `OwningRef` without needing to recreate the reference.
8+
This allows moving and dropping of an `OwningRef` without needing to recreate the reference.
99
1010
This can sometimes be useful because Rust borrowing rules normally prevent
1111
moving a type that has been moved from. For example, this kind of code gets rejected:
@@ -1146,7 +1146,7 @@ pub type VecRef<T, U = T> = OwningRef<Vec<T>, U>;
11461146
/// Typedef of an owning reference that uses a `String` as the owner.
11471147
pub type StringRef = OwningRef<String, str>;
11481148

1149-
/// Typedef of an owning reference that uses a `Rc` as the owner.
1149+
/// Typedef of an owning reference that uses an `Rc` as the owner.
11501150
pub type RcRef<T, U = T> = OwningRef<Rc<T>, U>;
11511151
/// Typedef of an owning reference that uses an `Arc` as the owner.
11521152
pub type ArcRef<T, U = T> = OwningRef<Arc<T>, U>;
@@ -1157,9 +1157,9 @@ pub type RefRef<'a, T, U = T> = OwningRef<Ref<'a, T>, U>;
11571157
pub type RefMutRef<'a, T, U = T> = OwningRef<RefMut<'a, T>, U>;
11581158
/// Typedef of an owning reference that uses a `MutexGuard` as the owner.
11591159
pub type MutexGuardRef<'a, T, U = T> = OwningRef<MutexGuard<'a, T>, U>;
1160-
/// Typedef of an owning reference that uses a `RwLockReadGuard` as the owner.
1160+
/// Typedef of an owning reference that uses an `RwLockReadGuard` as the owner.
11611161
pub type RwLockReadGuardRef<'a, T, U = T> = OwningRef<RwLockReadGuard<'a, T>, U>;
1162-
/// Typedef of an owning reference that uses a `RwLockWriteGuard` as the owner.
1162+
/// Typedef of an owning reference that uses an `RwLockWriteGuard` as the owner.
11631163
pub type RwLockWriteGuardRef<'a, T, U = T> = OwningRef<RwLockWriteGuard<'a, T>, U>;
11641164

11651165
/// Typedef of a mutable owning reference that uses a `Box` as the owner.
@@ -1173,7 +1173,7 @@ pub type StringRefMut = OwningRefMut<String, str>;
11731173
pub type RefMutRefMut<'a, T, U = T> = OwningRefMut<RefMut<'a, T>, U>;
11741174
/// Typedef of a mutable owning reference that uses a `MutexGuard` as the owner.
11751175
pub type MutexGuardRefMut<'a, T, U = T> = OwningRefMut<MutexGuard<'a, T>, U>;
1176-
/// Typedef of a mutable owning reference that uses a `RwLockWriteGuard` as the owner.
1176+
/// Typedef of a mutable owning reference that uses an `RwLockWriteGuard` as the owner.
11771177
pub type RwLockWriteGuardRefMut<'a, T, U = T> = OwningRef<RwLockWriteGuard<'a, T>, U>;
11781178

11791179
unsafe impl<'a, T: 'a> IntoErased<'a> for Box<T> {

compiler/rustc_hir/src/hir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2386,6 +2386,7 @@ impl<'hir> InlineAsmOperand<'hir> {
23862386
#[derive(Debug, HashStable_Generic)]
23872387
pub struct InlineAsm<'hir> {
23882388
pub template: &'hir [InlineAsmTemplatePiece],
2389+
pub template_strs: &'hir [(Symbol, Option<Symbol>, Span)],
23892390
pub operands: &'hir [(InlineAsmOperand<'hir>, Span)],
23902391
pub options: InlineAsmOptions,
23912392
pub line_spans: &'hir [Span],

compiler/rustc_infer/src/traits/error_reporting/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,5 @@ pub fn report_object_safety_error(
104104
to be resolvable dynamically; for more information visit \
105105
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
106106
);
107-
108-
if tcx.sess.trait_methods_not_found.borrow().iter().any(|full_span| full_span.contains(span)) {
109-
// Avoid emitting error caused by non-existing method (#58734)
110-
err.cancel();
111-
}
112-
113107
err
114108
}

0 commit comments

Comments
 (0)