Skip to content

Commit c3c8d5c

Browse files
committed
Auto merge of #149216 - matthiaskrgr:rollup-xtf90h6, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #147536 (Add `rust-mingw` component for `*-windows-gnullvm` hosts) - #148407 (Warn against calls which mutate an interior mutable `const`-item) - #149168 (Fix ICE when collecting opaques from trait method declarations) - #149170 (automate gpu offloading - part 1) - #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 1dd43f2 + 1717388 commit c3c8d5c

File tree

55 files changed

+2939
-90
lines changed

Some content is hidden

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

55 files changed

+2939
-90
lines changed

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: 18 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) => {
@@ -765,6 +771,13 @@ pub(crate) unsafe fn llvm_optimize(
765771
llvm_plugins.len(),
766772
)
767773
};
774+
775+
if cgcx.target_is_like_gpu && config.offload.contains(&config::Offload::Enable) {
776+
unsafe {
777+
llvm::LLVMRustBundleImages(module.module_llvm.llmod(), module.module_llvm.tm.raw());
778+
}
779+
}
780+
768781
result.into_result().unwrap_or_else(|()| llvm_err(dcx, LlvmError::RunLlvmPasses))
769782
}
770783

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,9 @@ unsafe extern "C" {
16411641
Name: *const c_char,
16421642
) -> &'a Value;
16431643

1644+
/// Processes the module and writes it in an offload compatible way into a "host.out" file.
1645+
pub(crate) fn LLVMRustBundleImages<'a>(M: &'a Module, TM: &'a TargetMachine) -> bool;
1646+
16441647
/// Writes a module to the specified path. Returns 0 on success.
16451648
pub(crate) fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
16461649

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_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

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ impl AttributeKind {
9191
RustcMain => No,
9292
RustcObjectLifetimeDefault => No,
9393
RustcPassIndirectlyInNonRusticAbis(..) => No,
94+
RustcShouldNotBeCalledOnConstItems(..) => Yes,
9495
RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate
9596
Sanitize { .. } => No,
9697
ShouldPanic { .. } => No,

compiler/rustc_lint/messages.ftl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ lint_confusable_identifier_pair = found both `{$existing_sym}` and `{$sym}` as i
193193
.current_use = this identifier can be confused with `{$existing_sym}`
194194
.other_use = other identifier used here
195195
196+
lint_const_item_interior_mutations =
197+
mutation of an interior mutable `const` item with call to `{$method_name}`
198+
.label = `{$const_name}` is a interior mutable `const` item of type `{$const_ty}`
199+
.temporary = each usage of a `const` item creates a new temporary
200+
.never_original = only the temporaries and never the original `const {$const_name}` will be modified
201+
.suggestion_static = for a shared instance of `{$const_name}`, consider making it a `static` item instead
202+
.help = for more details on interior mutability see <https://doc.rust-lang.org/reference/interior-mutability.html>
203+
196204
lint_dangling_pointers_from_locals = {$fn_kind} returns a dangling pointer to dropped local variable `{$local_var_name}`
197205
.ret_ty = return type is `{$ret_ty}`
198206
.local_var = local variable `{$local_var_name}` is dropped at the end of the {$fn_kind}

0 commit comments

Comments
 (0)