Skip to content

Commit 94b49fd

Browse files
committed
Auto merge of #149222 - matthiaskrgr:rollup-cl428i7, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #148407 (Warn against calls which mutate an interior mutable `const`-item) - #149065 (Address annotate-snippets test differences) - #149072 (Fix the issue of unused assignment from MIR liveness checking) - #149077 (feat: Enable annotate-snippets' simd feature) - #149168 (Fix ICE when collecting opaques from trait method declarations) - #149180 (Couple of refactors to SharedEmitter) - #149185 (Handle cycles when checking impl candidates for `doc(hidden)`) - #149194 (Move safe computation out of unsafe block) - #149204 (Fix typo in HashMap performance comment) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4b1b6dd + be4c672 commit 94b49fd

File tree

58 files changed

+3034
-101
lines changed

Some content is hidden

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

58 files changed

+3034
-101
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
7979
checksum = "a44baf24dd94e781f74dfe67ffee75a09a57971ddf0f615a178b4f6d404b48ff"
8080
dependencies = [
8181
"anstyle",
82+
"memchr",
8283
"unicode-width 0.2.2",
8384
]
8485

compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ impl<S: Stage> NoArgsAttributeParser<S> for PassByValueParser {
3838
const CREATE: fn(Span) -> AttributeKind = AttributeKind::PassByValue;
3939
}
4040

41+
pub(crate) struct RustcShouldNotBeCalledOnConstItems;
42+
impl<S: Stage> NoArgsAttributeParser<S> for RustcShouldNotBeCalledOnConstItems {
43+
const PATH: &[Symbol] = &[sym::rustc_should_not_be_called_on_const_items];
44+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
45+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
46+
Allow(Target::Method(MethodKind::Inherent)),
47+
Allow(Target::Method(MethodKind::TraitImpl)),
48+
]);
49+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcShouldNotBeCalledOnConstItems;
50+
}
51+
4152
pub(crate) struct AutomaticallyDerivedParser;
4253
impl<S: Stage> NoArgsAttributeParser<S> for AutomaticallyDerivedParser {
4354
const PATH: &[Symbol] = &[sym::automatically_derived];

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use crate::attributes::link_attrs::{
3939
};
4040
use crate::attributes::lint_helpers::{
4141
AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser,
42+
RustcShouldNotBeCalledOnConstItems,
4243
};
4344
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
4445
use crate::attributes::macro_attrs::{
@@ -244,6 +245,7 @@ attribute_parsers!(
244245
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
245246
Single<WithoutArgs<RustcMainParser>>,
246247
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
248+
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
247249
Single<WithoutArgs<SpecializationTraitParser>>,
248250
Single<WithoutArgs<StdInternalSymbolParser>>,
249251
Single<WithoutArgs<TrackCallerParser>>,

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use libc::{c_char, c_int, c_void, size_t};
99
use rustc_codegen_ssa::back::link::ensure_removed;
1010
use rustc_codegen_ssa::back::versioned_llvm_target;
1111
use rustc_codegen_ssa::back::write::{
12-
BitcodeSection, CodegenContext, EmitObj, ModuleConfig, TargetMachineFactoryConfig,
13-
TargetMachineFactoryFn,
12+
BitcodeSection, CodegenContext, EmitObj, InlineAsmError, ModuleConfig,
13+
TargetMachineFactoryConfig, TargetMachineFactoryFn,
1414
};
1515
use rustc_codegen_ssa::base::wants_wasm_eh;
1616
use rustc_codegen_ssa::traits::*;
@@ -434,7 +434,7 @@ fn report_inline_asm(
434434
level: llvm::DiagnosticLevel,
435435
cookie: u64,
436436
source: Option<(String, Vec<InnerSpan>)>,
437-
) {
437+
) -> InlineAsmError {
438438
// In LTO build we may get srcloc values from other crates which are invalid
439439
// since they use a different source map. To be safe we just suppress these
440440
// in LTO builds.
@@ -454,7 +454,7 @@ fn report_inline_asm(
454454
llvm::DiagnosticLevel::Note | llvm::DiagnosticLevel::Remark => Level::Note,
455455
};
456456
let msg = msg.trim_prefix("error: ").to_string();
457-
cgcx.diag_emitter.inline_asm_error(span, msg, level, source);
457+
InlineAsmError { span, msg, level, source }
458458
}
459459

460460
unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void) {
@@ -466,7 +466,13 @@ unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void
466466

467467
match unsafe { llvm::diagnostic::Diagnostic::unpack(info) } {
468468
llvm::diagnostic::InlineAsm(inline) => {
469-
report_inline_asm(cgcx, inline.message, inline.level, inline.cookie, inline.source);
469+
cgcx.diag_emitter.inline_asm_error(report_inline_asm(
470+
cgcx,
471+
inline.message,
472+
inline.level,
473+
inline.cookie,
474+
inline.source,
475+
));
470476
}
471477

472478
llvm::diagnostic::Optimization(opt) => {

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,7 @@ pub struct CguMessage;
12081208
// - `is_lint`: lints aren't relevant during codegen.
12091209
// - `emitted_at`: not used for codegen diagnostics.
12101210
struct Diagnostic {
1211+
span: Vec<SpanData>,
12111212
level: Level,
12121213
messages: Vec<(DiagMessage, Style)>,
12131214
code: Option<ErrCode>,
@@ -1218,7 +1219,7 @@ struct Diagnostic {
12181219
// A cut-down version of `rustc_errors::Subdiag` that impls `Send`. It's
12191220
// missing the following fields from `rustc_errors::Subdiag`.
12201221
// - `span`: it doesn't impl `Send`.
1221-
pub(crate) struct Subdiagnostic {
1222+
struct Subdiagnostic {
12221223
level: Level,
12231224
messages: Vec<(DiagMessage, Style)>,
12241225
}
@@ -1897,10 +1898,17 @@ fn spawn_thin_lto_work<'a, B: ExtraBackendMethods>(
18971898

18981899
enum SharedEmitterMessage {
18991900
Diagnostic(Diagnostic),
1900-
InlineAsmError(SpanData, String, Level, Option<(String, Vec<InnerSpan>)>),
1901+
InlineAsmError(InlineAsmError),
19011902
Fatal(String),
19021903
}
19031904

1905+
pub struct InlineAsmError {
1906+
pub span: SpanData,
1907+
pub msg: String,
1908+
pub level: Level,
1909+
pub source: Option<(String, Vec<InnerSpan>)>,
1910+
}
1911+
19041912
#[derive(Clone)]
19051913
pub struct SharedEmitter {
19061914
sender: Sender<SharedEmitterMessage>,
@@ -1917,14 +1925,8 @@ impl SharedEmitter {
19171925
(SharedEmitter { sender }, SharedEmitterMain { receiver })
19181926
}
19191927

1920-
pub fn inline_asm_error(
1921-
&self,
1922-
span: SpanData,
1923-
msg: String,
1924-
level: Level,
1925-
source: Option<(String, Vec<InnerSpan>)>,
1926-
) {
1927-
drop(self.sender.send(SharedEmitterMessage::InlineAsmError(span, msg, level, source)));
1928+
pub fn inline_asm_error(&self, err: InlineAsmError) {
1929+
drop(self.sender.send(SharedEmitterMessage::InlineAsmError(err)));
19281930
}
19291931

19301932
fn fatal(&self, msg: &str) {
@@ -1940,7 +1942,7 @@ impl Emitter for SharedEmitter {
19401942
) {
19411943
// Check that we aren't missing anything interesting when converting to
19421944
// the cut-down local `DiagInner`.
1943-
assert_eq!(diag.span, MultiSpan::new());
1945+
assert!(!diag.span.has_span_labels());
19441946
assert_eq!(diag.suggestions, Suggestions::Enabled(vec![]));
19451947
assert_eq!(diag.sort_span, rustc_span::DUMMY_SP);
19461948
assert_eq!(diag.is_lint, None);
@@ -1949,6 +1951,7 @@ impl Emitter for SharedEmitter {
19491951
let args = mem::replace(&mut diag.args, DiagArgMap::default());
19501952
drop(
19511953
self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
1954+
span: diag.span.primary_spans().iter().map(|span| span.data()).collect::<Vec<_>>(),
19521955
level: diag.level(),
19531956
messages: diag.messages,
19541957
code: diag.code,
@@ -1993,6 +1996,9 @@ impl SharedEmitterMain {
19931996
let dcx = sess.dcx();
19941997
let mut d =
19951998
rustc_errors::DiagInner::new_with_messages(diag.level, diag.messages);
1999+
d.span = MultiSpan::from_spans(
2000+
diag.span.into_iter().map(|span| span.span()).collect(),
2001+
);
19962002
d.code = diag.code; // may be `None`, that's ok
19972003
d.children = diag
19982004
.children
@@ -2007,15 +2013,15 @@ impl SharedEmitterMain {
20072013
dcx.emit_diagnostic(d);
20082014
sess.dcx().abort_if_errors();
20092015
}
2010-
Ok(SharedEmitterMessage::InlineAsmError(span, msg, level, source)) => {
2011-
assert_matches!(level, Level::Error | Level::Warning | Level::Note);
2012-
let mut err = Diag::<()>::new(sess.dcx(), level, msg);
2013-
if !span.is_dummy() {
2014-
err.span(span.span());
2016+
Ok(SharedEmitterMessage::InlineAsmError(inner)) => {
2017+
assert_matches!(inner.level, Level::Error | Level::Warning | Level::Note);
2018+
let mut err = Diag::<()>::new(sess.dcx(), inner.level, inner.msg);
2019+
if !inner.span.is_dummy() {
2020+
err.span(inner.span.span());
20152021
}
20162022

20172023
// Point to the generated assembly if it is available.
2018-
if let Some((buffer, spans)) = source {
2024+
if let Some((buffer, spans)) = inner.source {
20192025
let source = sess
20202026
.source_map()
20212027
.new_source_file(FileName::inline_asm_source_code(&buffer), buffer);

compiler/rustc_error_messages/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,6 @@ impl MultiSpan {
455455
replacements_occurred
456456
}
457457

458-
pub fn pop_span_label(&mut self) -> Option<(Span, DiagMessage)> {
459-
self.span_labels.pop()
460-
}
461-
462458
/// Returns the strings to highlight. We always ensure that there
463459
/// is an entry for each of the primary spans -- for each primary
464460
/// span `P`, if there is at least one label with span `P`, we return

compiler/rustc_errors/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2024"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
annotate-snippets = "0.12.9"
8+
annotate-snippets = { version = "0.12.9", features = ["simd"] }
99
anstream = "0.6.20"
1010
anstyle = "1.0.13"
1111
derive_setters = "0.1.6"

compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ impl AnnotateSnippetEmitter {
213213
file_ann.swap(0, pos);
214214
}
215215

216+
let file_ann_len = file_ann.len();
216217
for (file_idx, (file, annotations)) in file_ann.into_iter().enumerate() {
217218
if should_show_source_code(&self.ignored_directories_in_source_blocks, sm, &file) {
218219
if let Some(snippet) = self.annotated_snippet(annotations, &file.name, sm) {
@@ -240,6 +241,7 @@ impl AnnotateSnippetEmitter {
240241
// ╰ warning: this was previously accepted
241242
if let Some(c) = children.first()
242243
&& (!c.span.has_primary_spans() && !c.span.has_span_labels())
244+
&& file_idx == file_ann_len - 1
243245
{
244246
group = group.element(Padding);
245247
}
@@ -631,7 +633,7 @@ impl AnnotateSnippetEmitter {
631633
report.push(std::mem::replace(&mut group, Group::with_level(level.clone())));
632634
}
633635

634-
if !line_tracker.contains(&lo.line) {
636+
if !line_tracker.contains(&lo.line) && (i == 0 || hi.line <= lo.line) {
635637
line_tracker.push(lo.line);
636638
// ╭▸ $SRC_DIR/core/src/option.rs:594:0 (<- It adds *this*)
637639
// ⸬ $SRC_DIR/core/src/option.rs:602:4
@@ -740,6 +742,14 @@ fn collect_annotations(
740742
}
741743
}
742744
}
745+
746+
// Sort annotations within each file by line number
747+
for (_, ann) in output.iter_mut() {
748+
ann.sort_by_key(|a| {
749+
let lo = sm.lookup_char_pos(a.span.lo());
750+
lo.line
751+
});
752+
}
743753
output
744754
}
745755

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,11 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
12671267
EncodeCrossCrate::Yes,
12681268
"`#[rustc_as_ptr]` is used to mark functions returning pointers to their inner allocations."
12691269
),
1270+
rustc_attr!(
1271+
rustc_should_not_be_called_on_const_items, Normal, template!(Word), ErrorFollowing,
1272+
EncodeCrossCrate::Yes,
1273+
"`#[rustc_should_not_be_called_on_const_items]` is used to mark methods that don't make sense to be called on interior mutable consts."
1274+
),
12701275
rustc_attr!(
12711276
rustc_pass_by_value, Normal, template!(Word), ErrorFollowing,
12721277
EncodeCrossCrate::Yes,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,9 @@ pub enum AttributeKind {
701701
/// Represents `#[rustc_pass_indirectly_in_non_rustic_abis]`
702702
RustcPassIndirectlyInNonRusticAbis(Span),
703703

704+
/// Represents `#[rustc_should_not_be_called_on_const_items]`
705+
RustcShouldNotBeCalledOnConstItems(Span),
706+
704707
/// Represents `#[rustc_simd_monomorphize_lane_limit = "N"]`.
705708
RustcSimdMonomorphizeLaneLimit(Limit),
706709

0 commit comments

Comments
 (0)