Skip to content

Commit 146f574

Browse files
committed
Auto merge of rust-lang#83247 - Dylan-DPC:rollup-bdwmvjg, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - rust-lang#82191 (Vec::dedup_by optimization) - rust-lang#82270 (Emit error when trying to use assembler syntax directives in `asm!`) - rust-lang#82434 (Add more links between hash and btree collections) - rust-lang#83080 (Make source-based code coverage compatible with MIR inlining) - rust-lang#83168 (Extend `proc_macro_back_compat` lint to `procedural-masquerade`) - rust-lang#83192 (ci/docker: Add SDK/NDK level 21 to android docker for 32bit platforms) - rust-lang#83204 (Simplify C compilation for Fortanix-SGX target) - rust-lang#83216 (Allow registering tool lints with `register_tool`) - rust-lang#83223 (Display error details when a `mmap` call fails) - rust-lang#83228 (Don't show HTML diff if tidy isn't installed for rustdoc tests) - rust-lang#83231 (Switch riscvgc-unknown-none-elf use lp64d ABI) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 36f1f04 + 1839d1d commit 146f574

File tree

63 files changed

+1837
-192
lines changed

Some content is hidden

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

63 files changed

+1837
-192
lines changed

Diff for: compiler/rustc_ast/src/attr/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ impl MarkedAttrs {
3333
}
3434
}
3535

36-
pub fn is_known_lint_tool(m_item: Ident) -> bool {
37-
[sym::clippy, sym::rustc, sym::rustdoc].contains(&m_item.name)
38-
}
39-
4036
impl NestedMetaItem {
4137
/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem`.
4238
pub fn meta_item(&self) -> Option<&MetaItem> {

Diff for: compiler/rustc_ast/src/token.rs

-27
Original file line numberDiff line numberDiff line change
@@ -784,33 +784,6 @@ impl Nonterminal {
784784
NtTT(tt) => tt.span(),
785785
}
786786
}
787-
788-
/// This nonterminal looks like some specific enums from
789-
/// `proc-macro-hack` and `procedural-masquerade` crates.
790-
/// We need to maintain some special pretty-printing behavior for them due to incorrect
791-
/// asserts in old versions of those crates and their wide use in the ecosystem.
792-
/// See issue #73345 for more details.
793-
/// FIXME(#73933): Remove this eventually.
794-
pub fn pretty_printing_compatibility_hack(&self) -> bool {
795-
let item = match self {
796-
NtItem(item) => item,
797-
NtStmt(stmt) => match &stmt.kind {
798-
ast::StmtKind::Item(item) => item,
799-
_ => return false,
800-
},
801-
_ => return false,
802-
};
803-
804-
let name = item.ident.name;
805-
if name == sym::ProceduralMasqueradeDummyType || name == sym::ProcMacroHack {
806-
if let ast::ItemKind::Enum(enum_def, _) = &item.kind {
807-
if let [variant] = &*enum_def.variants {
808-
return variant.ident.name == sym::Input;
809-
}
810-
}
811-
}
812-
false
813-
}
814787
}
815788

816789
impl PartialEq for Nonterminal {

Diff for: compiler/rustc_builtin_macros/src/asm.rs

+72-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +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_span::symbol::{kw, sym, Symbol};
10+
use rustc_span::{
11+
symbol::{kw, sym, Symbol},
12+
BytePos,
13+
};
1114
use rustc_span::{InnerSpan, Span};
1215

1316
struct AsmArgs {
@@ -399,6 +402,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
399402
let mut line_spans = Vec::with_capacity(args.templates.len());
400403
let mut curarg = 0;
401404

405+
let default_dialect = ecx.sess.inline_asm_dialect();
406+
402407
for template_expr in args.templates.into_iter() {
403408
if !template.is_empty() {
404409
template.push(ast::InlineAsmTemplatePiece::String("\n".to_string()));
@@ -424,6 +429,60 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, sp: Span, args: AsmArgs) -> P<ast
424429

425430
let template_str = &template_str.as_str();
426431
let template_snippet = ecx.source_map().span_to_snippet(template_sp).ok();
432+
433+
if let Some(snippet) = &template_snippet {
434+
let snippet = snippet.trim_matches('"');
435+
match default_dialect {
436+
ast::LlvmAsmDialect::Intel => {
437+
if let Some(span) = check_syntax_directive(snippet, ".intel_syntax") {
438+
let span = template_span.from_inner(span);
439+
let mut err = ecx.struct_span_err(span, "intel syntax is the default syntax on this target, and trying to use this directive may cause issues");
440+
err.span_suggestion(
441+
span,
442+
"remove this assembler directive",
443+
"".to_string(),
444+
Applicability::MachineApplicable,
445+
);
446+
err.emit();
447+
}
448+
449+
if let Some(span) = check_syntax_directive(snippet, ".att_syntax") {
450+
let span = template_span.from_inner(span);
451+
let mut err = ecx.struct_span_err(span, "using the .att_syntax directive may cause issues, use the att_syntax option instead");
452+
let asm_end = sp.hi() - BytePos(2);
453+
let suggestions = vec![
454+
(span, "".to_string()),
455+
(
456+
Span::new(asm_end, asm_end, sp.ctxt()),
457+
", options(att_syntax)".to_string(),
458+
),
459+
];
460+
err.multipart_suggestion(
461+
"remove the assembler directive and replace it with options(att_syntax)",
462+
suggestions,
463+
Applicability::MachineApplicable,
464+
);
465+
err.emit();
466+
}
467+
}
468+
ast::LlvmAsmDialect::Att => {
469+
if let Some(span) = check_syntax_directive(snippet, ".att_syntax") {
470+
let span = template_span.from_inner(span);
471+
let mut err = ecx.struct_span_err(span, "att syntax is the default syntax on this target, and trying to use this directive may cause issues");
472+
err.span_suggestion(
473+
span,
474+
"remove this assembler directive",
475+
"".to_string(),
476+
Applicability::MachineApplicable,
477+
);
478+
err.emit();
479+
}
480+
481+
// Use of .intel_syntax is ignored
482+
}
483+
}
484+
}
485+
427486
let mut parser = parse::Parser::new(
428487
template_str,
429488
str_style,
@@ -631,3 +690,15 @@ pub fn expand_asm<'cx>(
631690
}
632691
}
633692
}
693+
694+
fn check_syntax_directive<S: AsRef<str>>(piece: S, syntax: &str) -> Option<InnerSpan> {
695+
let piece = piece.as_ref();
696+
if let Some(idx) = piece.find(syntax) {
697+
let end =
698+
idx + &piece[idx..].find(|c| matches!(c, '\n' | ';')).unwrap_or(piece[idx..].len());
699+
// Offset by one because these represent the span with the " removed
700+
Some(InnerSpan::new(idx + 1, end + 1))
701+
} else {
702+
None
703+
}
704+
}

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ fn save_function_record(
254254
///
255255
/// 1. The file name of an "Unreachable" function must match the file name of the existing
256256
/// codegenned (covered) function to which the unreachable code regions will be added.
257-
/// 2. The function to which the unreachable code regions will be added must not be a genaric
257+
/// 2. The function to which the unreachable code regions will be added must not be a generic
258258
/// function (must not have type parameters) because the coverage tools will get confused
259259
/// if the codegenned function has more than one instantiation and additional `CodeRegion`s
260260
/// attached to only one of those instantiations.
@@ -284,7 +284,7 @@ fn add_unreachable_coverage<'tcx>(
284284
let all_def_ids: DefIdSet =
285285
tcx.mir_keys(LOCAL_CRATE).iter().map(|local_def_id| local_def_id.to_def_id()).collect();
286286

287-
let (codegenned_def_ids, _) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
287+
let codegenned_def_ids = tcx.codegened_and_inlined_items(LOCAL_CRATE);
288288

289289
let mut unreachable_def_ids_by_file: FxHashMap<Symbol, Vec<DefId>> = FxHashMap::default();
290290
for &non_codegenned_def_id in all_def_ids.difference(codegenned_def_ids) {

Diff for: compiler/rustc_codegen_ssa/src/coverageinfo/map.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::mir::coverage::{
88
use rustc_middle::ty::Instance;
99
use rustc_middle::ty::TyCtxt;
1010

11-
#[derive(Clone, Debug)]
11+
#[derive(Clone, Debug, PartialEq)]
1212
pub struct Expression {
1313
lhs: ExpressionOperandId,
1414
op: Op,
@@ -64,7 +64,9 @@ impl<'tcx> FunctionCoverage<'tcx> {
6464

6565
/// Adds a code region to be counted by an injected counter intrinsic.
6666
pub fn add_counter(&mut self, id: CounterValueReference, region: CodeRegion) {
67-
self.counters[id].replace(region).expect_none("add_counter called with duplicate `id`");
67+
if let Some(previous_region) = self.counters[id].replace(region.clone()) {
68+
assert_eq!(previous_region, region, "add_counter: code region for id changed");
69+
}
6870
}
6971

7072
/// Both counters and "counter expressions" (or simply, "expressions") can be operands in other
@@ -94,9 +96,18 @@ impl<'tcx> FunctionCoverage<'tcx> {
9496
expression_id, lhs, op, rhs, region
9597
);
9698
let expression_index = self.expression_index(u32::from(expression_id));
97-
self.expressions[expression_index]
98-
.replace(Expression { lhs, op, rhs, region })
99-
.expect_none("add_counter_expression called with duplicate `id_descending_from_max`");
99+
if let Some(previous_expression) = self.expressions[expression_index].replace(Expression {
100+
lhs,
101+
op,
102+
rhs,
103+
region: region.clone(),
104+
}) {
105+
assert_eq!(
106+
previous_expression,
107+
Expression { lhs, op, rhs, region },
108+
"add_counter_expression: expression for id changed"
109+
);
110+
}
100111
}
101112

102113
/// Add a region that will be marked as "unreachable", with a constant "zero counter".

Diff for: compiler/rustc_codegen_ssa/src/mir/coverageinfo.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,38 @@ use crate::traits::*;
22

33
use rustc_middle::mir::coverage::*;
44
use rustc_middle::mir::Coverage;
5+
use rustc_middle::mir::SourceScope;
56

67
use super::FunctionCx;
78

89
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
9-
pub fn codegen_coverage(&self, bx: &mut Bx, coverage: Coverage) {
10+
pub fn codegen_coverage(&self, bx: &mut Bx, coverage: Coverage, scope: SourceScope) {
11+
// Determine the instance that coverage data was originally generated for.
12+
let scope_data = &self.mir.source_scopes[scope];
13+
let instance = if let Some((inlined_instance, _)) = scope_data.inlined {
14+
self.monomorphize(inlined_instance)
15+
} else if let Some(inlined_scope) = scope_data.inlined_parent_scope {
16+
self.monomorphize(self.mir.source_scopes[inlined_scope].inlined.unwrap().0)
17+
} else {
18+
self.instance
19+
};
20+
1021
let Coverage { kind, code_region } = coverage;
1122
match kind {
1223
CoverageKind::Counter { function_source_hash, id } => {
13-
if bx.set_function_source_hash(self.instance, function_source_hash) {
24+
if bx.set_function_source_hash(instance, function_source_hash) {
1425
// If `set_function_source_hash()` returned true, the coverage map is enabled,
1526
// so continue adding the counter.
1627
if let Some(code_region) = code_region {
1728
// Note: Some counters do not have code regions, but may still be referenced
1829
// from expressions. In that case, don't add the counter to the coverage map,
1930
// but do inject the counter intrinsic.
20-
bx.add_coverage_counter(self.instance, id, code_region);
31+
bx.add_coverage_counter(instance, id, code_region);
2132
}
2233

23-
let coverageinfo = bx.tcx().coverageinfo(self.instance.def_id());
34+
let coverageinfo = bx.tcx().coverageinfo(instance.def_id());
2435

25-
let fn_name = bx.create_pgo_func_name_var(self.instance);
36+
let fn_name = bx.create_pgo_func_name_var(instance);
2637
let hash = bx.const_u64(function_source_hash);
2738
let num_counters = bx.const_u32(coverageinfo.num_counters);
2839
let index = bx.const_u32(u32::from(id));
@@ -34,11 +45,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3445
}
3546
}
3647
CoverageKind::Expression { id, lhs, op, rhs } => {
37-
bx.add_coverage_counter_expression(self.instance, id, lhs, op, rhs, code_region);
48+
bx.add_coverage_counter_expression(instance, id, lhs, op, rhs, code_region);
3849
}
3950
CoverageKind::Unreachable => {
4051
bx.add_coverage_unreachable(
41-
self.instance,
52+
instance,
4253
code_region.expect("unreachable regions always have code regions"),
4354
);
4455
}

Diff for: compiler/rustc_codegen_ssa/src/mir/statement.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
112112
bx
113113
}
114114
mir::StatementKind::Coverage(box ref coverage) => {
115-
self.codegen_coverage(&mut bx, coverage.clone());
115+
self.codegen_coverage(&mut bx, coverage.clone(), statement.source_info.scope);
116116
bx
117117
}
118118
mir::StatementKind::CopyNonOverlapping(box mir::CopyNonOverlapping {

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

+40
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use rustc_attr::{self as attr, Deprecation, Stability};
1010
use rustc_data_structures::fx::FxHashMap;
1111
use rustc_data_structures::sync::{self, Lrc};
1212
use rustc_errors::{DiagnosticBuilder, ErrorReported};
13+
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
14+
use rustc_lint_defs::BuiltinLintDiagnostics;
1315
use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
1416
use rustc_session::{parse::ParseSess, Limit, Session};
1517
use rustc_span::def_id::DefId;
@@ -1241,3 +1243,41 @@ pub fn get_exprs_from_tts(
12411243
}
12421244
Some(es)
12431245
}
1246+
1247+
/// This nonterminal looks like some specific enums from
1248+
/// `proc-macro-hack` and `procedural-masquerade` crates.
1249+
/// We need to maintain some special pretty-printing behavior for them due to incorrect
1250+
/// asserts in old versions of those crates and their wide use in the ecosystem.
1251+
/// See issue #73345 for more details.
1252+
/// FIXME(#73933): Remove this eventually.
1253+
pub(crate) fn pretty_printing_compatibility_hack(nt: &Nonterminal, sess: &ParseSess) -> bool {
1254+
let item = match nt {
1255+
Nonterminal::NtItem(item) => item,
1256+
Nonterminal::NtStmt(stmt) => match &stmt.kind {
1257+
ast::StmtKind::Item(item) => item,
1258+
_ => return false,
1259+
},
1260+
_ => return false,
1261+
};
1262+
1263+
let name = item.ident.name;
1264+
if name == sym::ProceduralMasqueradeDummyType {
1265+
if let ast::ItemKind::Enum(enum_def, _) = &item.kind {
1266+
if let [variant] = &*enum_def.variants {
1267+
if variant.ident.name == sym::Input {
1268+
sess.buffer_lint_with_diagnostic(
1269+
&PROC_MACRO_BACK_COMPAT,
1270+
item.ident.span,
1271+
ast::CRATE_NODE_ID,
1272+
"using `procedural-masquerade` crate",
1273+
BuiltinLintDiagnostics::ProcMacroBackCompat(
1274+
"The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. \
1275+
Versions of this crate below 0.1.7 will eventually stop compiling.".to_string())
1276+
);
1277+
return true;
1278+
}
1279+
}
1280+
}
1281+
}
1282+
false
1283+
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ impl MultiItemModifier for ProcMacroDerive {
9090
}
9191
_ => unreachable!(),
9292
};
93-
let input = if item.pretty_printing_compatibility_hack() {
93+
let input = if crate::base::pretty_printing_compatibility_hack(&item, &ecx.sess.parse_sess)
94+
{
9495
TokenTree::token(token::Interpolated(Lrc::new(item)), DUMMY_SP).into()
9596
} else {
9697
nt_to_tokenstream(&item, &ecx.sess.parse_sess, CanSynthesizeMissingTokens::Yes)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl FromInternal<(TreeAndSpacing, &'_ ParseSess, &'_ mut Vec<Self>)>
187187
delimiter: Delimiter::None,
188188
stream,
189189
span: DelimSpan::from_single(span),
190-
flatten: nt.pretty_printing_compatibility_hack(),
190+
flatten: crate::base::pretty_printing_compatibility_hack(&nt, sess),
191191
})
192192
}
193193
}

Diff for: compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ impl<'a> EarlyContext<'a> {
748748
sess,
749749
krate,
750750
lint_store,
751-
builder: LintLevelsBuilder::new(sess, warn_about_weird_lints, lint_store),
751+
builder: LintLevelsBuilder::new(sess, warn_about_weird_lints, lint_store, &krate.attrs),
752752
buffered,
753753
}
754754
}

0 commit comments

Comments
 (0)