Skip to content
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

Rollup of 16 pull requests #88329

Merged
merged 39 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4130a32
bootstrap.py: recognize riscv64 when auto-detect
Icenowy Aug 19, 2021
51d598e
Adjust documentation of `Arc::make_mut`
steffahn Aug 19, 2021
65bfc31
Remove the `TryV2` alias
scottmcm Aug 21, 2021
41f9f38
Remove `Session.trait_methods_not_found`
Aaron1011 Aug 21, 2021
9c44d80
add Cell::as_array_of_cells, similar to Cell::as_slice_of_cells
oconnor663 Aug 11, 2021
ed43e02
2229: Update signature for truncate function
arora-aman Aug 23, 2021
bc33861
Fix references to `ControlFlow` in docs
jhpratt Aug 24, 2021
04fa1d8
Fix typo “a Rc” → “an Rc”
steffahn Aug 22, 2021
b823dc1
Also fix “a RwLock*”
steffahn Aug 22, 2021
6248dbc
Also fix “a `OwningRef`”
steffahn Aug 22, 2021
2af3b20
Update books
ehuss Aug 24, 2021
0b81c2e
Move `named_asm_labels` to a HIR lint
asquared31415 Aug 19, 2021
54df693
io::Error: alphabeticise the match in as_str()
ijackson Aug 24, 2021
4c0203e
io::ErrorKind: rationalise ordering in main enum
ijackson Aug 24, 2021
8f70079
Fix grammar
est31 Aug 24, 2021
7b5c0ec
Fix tidy
ijackson Aug 24, 2021
db13636
Stabilise BufWriter::into_parts
ijackson Apr 30, 2021
335bf7c
Clarifiy weak pointers being diassociated…
steffahn Aug 24, 2021
90354c7
Make explanations of cross-references between `make_mut` and `get_mut…
steffahn Aug 24, 2021
09e02a8
Add SAFETY comments to core::slice::sort::partition_in_blocks
mdsn Aug 24, 2021
08e20d9
Add type of a let tait test
spastorino Aug 25, 2021
dbadab5
Add type of a let tait test impl trait straight in let
spastorino Aug 25, 2021
f858c7c
Add mutable-noalias to the release notes for 1.54
jyn514 Aug 25, 2021
ccefe27
Rollup merge of #87944 - oconnor663:as_array_of_cells, r=scottmcm
LeSeulArtichaut Aug 25, 2021
214d8e3
Rollup merge of #88156 - steffahn:arc_make_mut_and_weak, r=Mark-Simul…
LeSeulArtichaut Aug 25, 2021
2512fb0
Rollup merge of #88157 - Icenowy:bootstrap-riscv64, r=Mark-Simulacrum
LeSeulArtichaut Aug 25, 2021
891fa3c
Rollup merge of #88196 - asquared31415:named-asm-labels-refactor, r=A…
LeSeulArtichaut Aug 25, 2021
f2cbbb9
Rollup merge of #88218 - Aaron1011:missing-method-dyn, r=nagisa
LeSeulArtichaut Aug 25, 2021
b09c254
Rollup merge of #88223 - scottmcm:fix-alias, r=yaahc
LeSeulArtichaut Aug 25, 2021
cc2a127
Rollup merge of #88226 - steffahn:an_rc, r=michaelwoerister
LeSeulArtichaut Aug 25, 2021
0693306
Rollup merge of #88267 - sexxi-goose:truncate_unique, r=nikomatsakis
LeSeulArtichaut Aug 25, 2021
3375283
Rollup merge of #88273 - jhpratt:update-iterator-docs, r=jyn514
LeSeulArtichaut Aug 25, 2021
e6d922b
Rollup merge of #88277 - ehuss:update-books, r=ehuss
LeSeulArtichaut Aug 25, 2021
dc2c974
Rollup merge of #88291 - mdsn:partition-in-blocks-safety, r=Mark-Simu…
LeSeulArtichaut Aug 25, 2021
0aabf4b
Rollup merge of #88293 - est31:fix_grammar, r=Mark-Simulacrum
LeSeulArtichaut Aug 25, 2021
82ecb0f
Rollup merge of #88298 - ijackson:errorkind-reorder, r=dtolnay
LeSeulArtichaut Aug 25, 2021
3eee91b
Rollup merge of #88299 - ijackson:bufwriter, r=Mark-Simulacrum
LeSeulArtichaut Aug 25, 2021
16fd95c
Rollup merge of #88314 - spastorino:type-of-a-let-tait-test, r=oli-obk
LeSeulArtichaut Aug 25, 2021
d9ed23a
Rollup merge of #88325 - jyn514:noalias, r=XAMPPRocky
LeSeulArtichaut Aug 25, 2021
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
2 changes: 2 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Compiler
- [Improved debugger output for enums on Windows MSVC platforms.][85292]
- [Added tier 3\* support for `bpfel-unknown-none`
and `bpfeb-unknown-none`.][79608]
- [`-Zmutable-noalias=yes`][82834] is enabled by default when using LLVM 12 or above.

\* Refer to Rust's [platform support page][platform-support-doc] for more
information on Rust's tiered platform support.
Expand Down Expand Up @@ -244,6 +245,7 @@ Compatibility Notes
[83366]: https://github.com/rust-lang/rust/pull/83366
[83278]: https://github.com/rust-lang/rust/pull/83278
[85292]: https://github.com/rust-lang/rust/pull/85292
[82834]: https://github.com/rust-lang/rust/pull/82834
[cargo/9520]: https://github.com/rust-lang/cargo/pull/9520
[cargo/9499]: https://github.com/rust-lang/cargo/pull/9499
[cargo/9488]: https://github.com/rust-lang/cargo/pull/9488
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,7 @@ pub enum InlineAsmOperand {
#[derive(Clone, Encodable, Decodable, Debug)]
pub struct InlineAsm {
pub template: Vec<InlineAsmTemplatePiece>,
pub template_strs: Box<[(Symbol, Option<Symbol>, Span)]>,
pub operands: Vec<(InlineAsmOperand, Span)>,
pub clobber_abi: Option<(Symbol, Span)>,
pub options: InlineAsmOptions,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ use crate::token;
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::Span;

#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum AssocCtxt {
Trait,
Impl,
}

#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum FnCtxt {
Free,
Foreign,
Assoc(AssocCtxt),
}

#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub enum FnKind<'a> {
/// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
Fn(FnCtxt, Ident, &'a FnSig, &'a Visibility, Option<&'a Block>),
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

let operands = self.arena.alloc_from_iter(operands);
let template = self.arena.alloc_from_iter(asm.template.iter().cloned());
let template_strs = self.arena.alloc_from_iter(asm.template_strs.iter().cloned());
let line_spans = self.arena.alloc_slice(&asm.line_spans[..]);
let hir_asm = hir::InlineAsm { template, operands, options: asm.options, line_spans };
let hir_asm =
hir::InlineAsm { template, template_strs, operands, options: asm.options, line_spans };
self.arena.alloc(hir_asm)
}
}
90 changes: 14 additions & 76 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_expand::base::{self, *};
use rustc_parse::parser::Parser;
use rustc_parse_format as parse;
use rustc_session::lint::{self, BuiltinLintDiagnostics};
use rustc_session::lint;
use rustc_span::symbol::Ident;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::{InnerSpan, MultiSpan, Span};
use rustc_span::{InnerSpan, Span};
use rustc_target::asm::InlineAsmArch;
use smallvec::smallvec;

Expand Down Expand Up @@ -484,11 +484,7 @@ fn parse_reg<'a>(
Ok(result)
}

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

let mut template_strs = Vec::with_capacity(args.templates.len());

for template_expr in args.templates.into_iter() {
if !template.is_empty() {
template.push(ast::InlineAsmTemplatePiece::String("\n".to_string()));
Expand All @@ -524,8 +522,13 @@ fn expand_preparsed_asm(
ast::StrStyle::Raw(raw) => Some(raw as usize),
};

let template_str = &template_str.as_str();
let template_snippet = ecx.source_map().span_to_snippet(template_sp).ok();
template_strs.push((
template_str,
template_snippet.as_ref().map(|s| Symbol::intern(s)),
template_sp,
));
let template_str = &template_str.as_str();

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

// Lint against the use of named labels in inline `asm!` but not `global_asm!`
if is_local_asm {
let find_label_span = |needle: &str| -> Option<Span> {
if let Some(snippet) = &template_snippet {
if let Some(pos) = snippet.find(needle) {
let end = pos
+ &snippet[pos..]
.find(|c| c == ':')
.unwrap_or(snippet[pos..].len() - 1);
let inner = InnerSpan::new(pos, end);
return Some(template_sp.from_inner(inner));
}
}

None
};

let mut found_labels = Vec::new();

// A semicolon might not actually be specified as a separator for all targets, but it seems like LLVM accepts it always
let statements = template_str.split(|c| matches!(c, '\n' | ';'));
for statement in statements {
// If there's a comment, trim it from the statement
let statement = statement.find("//").map_or(statement, |idx| &statement[..idx]);
let mut start_idx = 0;
for (idx, _) in statement.match_indices(':') {
let possible_label = statement[start_idx..idx].trim();
let mut chars = possible_label.chars();
if let Some(c) = chars.next() {
// A label starts with an alphabetic character or . or _ and continues with alphanumeric characters, _, or $
if (c.is_alphabetic() || matches!(c, '.' | '_'))
&& chars.all(|c| c.is_alphanumeric() || matches!(c, '_' | '$'))
{
found_labels.push(possible_label);
} else {
// If we encounter a non-label, there cannot be any further labels, so stop checking
break;
}
} else {
// Empty string means a leading ':' in this section, which is not a label
break;
}

start_idx = idx + 1;
}
}

if found_labels.len() > 0 {
let spans =
found_labels.into_iter().filter_map(find_label_span).collect::<Vec<Span>>();
// If there were labels but we couldn't find a span, combine the warnings and use the template span
let target_spans: MultiSpan =
if spans.len() > 0 { spans.into() } else { template_sp.into() };
ecx.parse_sess().buffer_lint_with_diagnostic(
lint::builtin::NAMED_ASM_LABELS,
target_spans,
ecx.current_expansion.lint_node_id,
"avoid using named labels in inline assembly",
BuiltinLintDiagnostics::NamedAsmLabel(
"only local labels of the form `<number>:` should be used in inline asm"
.to_string(),
),
);
}
}

// Don't treat raw asm as a format string.
if args.options.contains(ast::InlineAsmOptions::RAW) {
template.push(ast::InlineAsmTemplatePiece::String(template_str.to_string()));
Expand Down Expand Up @@ -819,6 +756,7 @@ fn expand_preparsed_asm(

Some(ast::InlineAsm {
template,
template_strs: template_strs.into_boxed_slice(),
operands: args.operands,
clobber_abi: args.clobber_abi,
options: args.options,
Expand All @@ -833,7 +771,7 @@ pub fn expand_asm<'cx>(
) -> Box<dyn base::MacResult + 'cx> {
match parse_args(ecx, sp, tts, false) {
Ok(args) => {
let expr = if let Some(inline_asm) = expand_preparsed_asm(ecx, args, true) {
let expr = if let Some(inline_asm) = expand_preparsed_asm(ecx, args) {
P(ast::Expr {
id: ast::DUMMY_NODE_ID,
kind: ast::ExprKind::InlineAsm(P(inline_asm)),
Expand All @@ -860,7 +798,7 @@ pub fn expand_global_asm<'cx>(
) -> Box<dyn base::MacResult + 'cx> {
match parse_args(ecx, sp, tts, true) {
Ok(args) => {
if let Some(inline_asm) = expand_preparsed_asm(ecx, args, false) {
if let Some(inline_asm) = expand_preparsed_asm(ecx, args) {
MacEager::items(smallvec![P(ast::Item {
ident: Ident::invalid(),
attrs: Vec::new(),
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_data_structures/src/owning_ref/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

This crate provides the _owning reference_ types `OwningRef` and `OwningRefMut`
that enables it to bundle a reference together with the owner of the data it points to.
This allows moving and dropping of a `OwningRef` without needing to recreate the reference.
This allows moving and dropping of an `OwningRef` without needing to recreate the reference.

This can sometimes be useful because Rust borrowing rules normally prevent
moving a type that has been moved from. For example, this kind of code gets rejected:
Expand Down Expand Up @@ -1146,7 +1146,7 @@ pub type VecRef<T, U = T> = OwningRef<Vec<T>, U>;
/// Typedef of an owning reference that uses a `String` as the owner.
pub type StringRef = OwningRef<String, str>;

/// Typedef of an owning reference that uses a `Rc` as the owner.
/// Typedef of an owning reference that uses an `Rc` as the owner.
pub type RcRef<T, U = T> = OwningRef<Rc<T>, U>;
/// Typedef of an owning reference that uses an `Arc` as the owner.
pub type ArcRef<T, U = T> = OwningRef<Arc<T>, U>;
Expand All @@ -1157,9 +1157,9 @@ pub type RefRef<'a, T, U = T> = OwningRef<Ref<'a, T>, U>;
pub type RefMutRef<'a, T, U = T> = OwningRef<RefMut<'a, T>, U>;
/// Typedef of an owning reference that uses a `MutexGuard` as the owner.
pub type MutexGuardRef<'a, T, U = T> = OwningRef<MutexGuard<'a, T>, U>;
/// Typedef of an owning reference that uses a `RwLockReadGuard` as the owner.
/// Typedef of an owning reference that uses an `RwLockReadGuard` as the owner.
pub type RwLockReadGuardRef<'a, T, U = T> = OwningRef<RwLockReadGuard<'a, T>, U>;
/// Typedef of an owning reference that uses a `RwLockWriteGuard` as the owner.
/// Typedef of an owning reference that uses an `RwLockWriteGuard` as the owner.
pub type RwLockWriteGuardRef<'a, T, U = T> = OwningRef<RwLockWriteGuard<'a, T>, U>;

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

unsafe impl<'a, T: 'a> IntoErased<'a> for Box<T> {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,7 @@ impl<'hir> InlineAsmOperand<'hir> {
#[derive(Debug, HashStable_Generic)]
pub struct InlineAsm<'hir> {
pub template: &'hir [InlineAsmTemplatePiece],
pub template_strs: &'hir [(Symbol, Option<Symbol>, Span)],
pub operands: &'hir [(InlineAsmOperand<'hir>, Span)],
pub options: InlineAsmOptions,
pub line_spans: &'hir [Span],
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_infer/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,5 @@ pub fn report_object_safety_error(
to be resolvable dynamically; for more information visit \
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
);

if tcx.sess.trait_methods_not_found.borrow().iter().any(|full_span| full_span.contains(span)) {
// Avoid emitting error caused by non-existing method (#58734)
err.cancel();
}

err
}
Loading