Skip to content

Commit 8235469

Browse files
committed
Auto merge of #118687 - matthiaskrgr:rollup-317ztgu, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #117981 (Remove deprecated `--check-cfg` syntax) - #118177 (Suppress warnings in LLVM wrapper when targeting MSVC) - #118317 (tip for define macro name after `macro_rules!`) - #118504 (Enforce `must_use` on associated types and RPITITs that have a must-use trait in bounds) - #118660 (rustc_arena: add `alloc_str`) - #118681 (Fix is_foreign_item for StableMIR instance ) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1fdfe12 + 3c1357c commit 8235469

File tree

60 files changed

+334
-427
lines changed

Some content is hidden

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

60 files changed

+334
-427
lines changed

compiler/rustc_arena/src/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,20 @@ impl DroplessArena {
484484
}
485485
}
486486

487+
/// Allocates a string slice that is copied into the `DroplessArena`, returning a
488+
/// reference to it. Will panic if passed an empty string.
489+
///
490+
/// Panics:
491+
///
492+
/// - Zero-length string
493+
#[inline]
494+
pub fn alloc_str(&self, string: &str) -> &str {
495+
let slice = self.alloc_slice(string.as_bytes());
496+
497+
// SAFETY: the result has a copy of the same valid UTF-8 bytes.
498+
unsafe { std::str::from_utf8_unchecked(slice) }
499+
}
500+
487501
/// # Safety
488502
///
489503
/// The caller must ensure that `mem` is valid for writes up to `size_of::<T>() * len`, and that
@@ -655,6 +669,14 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
655669
self.dropless.alloc_slice(value)
656670
}
657671

672+
#[inline]
673+
pub fn alloc_str(&self, string: &str) -> &str {
674+
if string.is_empty() {
675+
return "";
676+
}
677+
self.dropless.alloc_str(string)
678+
}
679+
658680
#[allow(clippy::mut_from_ref)]
659681
pub fn alloc_from_iter<T: ArenaAllocatable<'tcx, C>, C>(
660682
&self,

compiler/rustc_interface/src/interface.rs

+83-157
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_data_structures::sync::Lrc;
1010
use rustc_errors::registry::Registry;
1111
use rustc_errors::{ErrorGuaranteed, Handler};
1212
use rustc_lint::LintStore;
13+
use rustc_middle::ty;
1314
use rustc_middle::util::Providers;
14-
use rustc_middle::{bug, ty};
1515
use rustc_parse::maybe_new_parser_from_source_str;
1616
use rustc_query_impl::QueryCtxt;
1717
use rustc_query_system::query::print_query_stack;
@@ -104,7 +104,6 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
104104
let exhaustive_values = !specs.is_empty();
105105
let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg::default() };
106106

107-
let mut old_syntax = None;
108107
for s in specs {
109108
let sess = ParseSess::with_silent_emitter(Some(format!(
110109
"this error occurred on the command line: `--check-cfg={s}`"
@@ -142,174 +141,101 @@ pub(crate) fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -
142141
expected_error();
143142
};
144143

145-
let mut set_old_syntax = || {
146-
// defaults are flipped for the old syntax
147-
if old_syntax == None {
148-
check_cfg.exhaustive_names = false;
149-
check_cfg.exhaustive_values = false;
150-
}
151-
old_syntax = Some(true);
152-
};
153-
154-
if meta_item.has_name(sym::names) {
155-
set_old_syntax();
156-
157-
check_cfg.exhaustive_names = true;
158-
for arg in args {
159-
if arg.is_word()
160-
&& let Some(ident) = arg.ident()
161-
{
162-
check_cfg.expecteds.entry(ident.name).or_insert(ExpectedValues::Any);
163-
} else {
164-
error!("`names()` arguments must be simple identifiers");
165-
}
166-
}
167-
} else if meta_item.has_name(sym::values) {
168-
set_old_syntax();
169-
170-
if let Some((name, values)) = args.split_first() {
171-
if name.is_word()
172-
&& let Some(ident) = name.ident()
173-
{
174-
let expected_values = check_cfg
175-
.expecteds
176-
.entry(ident.name)
177-
.and_modify(|expected_values| match expected_values {
178-
ExpectedValues::Some(_) => {}
179-
ExpectedValues::Any => {
180-
// handle the case where names(...) was done
181-
// before values by changing to a list
182-
*expected_values = ExpectedValues::Some(FxHashSet::default());
183-
}
184-
})
185-
.or_insert_with(|| ExpectedValues::Some(FxHashSet::default()));
144+
if !meta_item.has_name(sym::cfg) {
145+
expected_error();
146+
}
186147

187-
let ExpectedValues::Some(expected_values) = expected_values else {
188-
bug!("`expected_values` should be a list a values")
189-
};
148+
let mut names = Vec::new();
149+
let mut values: FxHashSet<_> = Default::default();
190150

191-
for val in values {
192-
if let Some(LitKind::Str(s, _)) = val.lit().map(|lit| &lit.kind) {
193-
expected_values.insert(Some(*s));
194-
} else {
195-
error!("`values()` arguments must be string literals");
196-
}
197-
}
151+
let mut any_specified = false;
152+
let mut values_specified = false;
153+
let mut values_any_specified = false;
198154

199-
if values.is_empty() {
200-
expected_values.insert(None);
201-
}
202-
} else {
203-
error!("`values()` first argument must be a simple identifier");
155+
for arg in args {
156+
if arg.is_word()
157+
&& let Some(ident) = arg.ident()
158+
{
159+
if values_specified {
160+
error!("`cfg()` names cannot be after values");
204161
}
205-
} else if args.is_empty() {
206-
check_cfg.exhaustive_values = true;
207-
} else {
208-
expected_error();
209-
}
210-
} else if meta_item.has_name(sym::cfg) {
211-
old_syntax = Some(false);
212-
213-
let mut names = Vec::new();
214-
let mut values: FxHashSet<_> = Default::default();
215-
216-
let mut any_specified = false;
217-
let mut values_specified = false;
218-
let mut values_any_specified = false;
219-
220-
for arg in args {
221-
if arg.is_word()
222-
&& let Some(ident) = arg.ident()
223-
{
224-
if values_specified {
225-
error!("`cfg()` names cannot be after values");
226-
}
227-
names.push(ident);
228-
} else if arg.has_name(sym::any)
229-
&& let Some(args) = arg.meta_item_list()
230-
{
231-
if any_specified {
232-
error!("`any()` cannot be specified multiple times");
233-
}
234-
any_specified = true;
235-
if !args.is_empty() {
236-
error!("`any()` must be empty");
237-
}
238-
} else if arg.has_name(sym::values)
239-
&& let Some(args) = arg.meta_item_list()
240-
{
241-
if names.is_empty() {
242-
error!("`values()` cannot be specified before the names");
243-
} else if values_specified {
244-
error!("`values()` cannot be specified multiple times");
245-
}
246-
values_specified = true;
247-
248-
for arg in args {
249-
if let Some(LitKind::Str(s, _)) = arg.lit().map(|lit| &lit.kind) {
250-
values.insert(Some(*s));
251-
} else if arg.has_name(sym::any)
252-
&& let Some(args) = arg.meta_item_list()
253-
{
254-
if values_any_specified {
255-
error!("`any()` in `values()` cannot be specified multiple times");
256-
}
257-
values_any_specified = true;
258-
if !args.is_empty() {
259-
error!("`any()` must be empty");
260-
}
261-
} else {
262-
error!("`values()` arguments must be string literals or `any()`");
162+
names.push(ident);
163+
} else if arg.has_name(sym::any)
164+
&& let Some(args) = arg.meta_item_list()
165+
{
166+
if any_specified {
167+
error!("`any()` cannot be specified multiple times");
168+
}
169+
any_specified = true;
170+
if !args.is_empty() {
171+
error!("`any()` must be empty");
172+
}
173+
} else if arg.has_name(sym::values)
174+
&& let Some(args) = arg.meta_item_list()
175+
{
176+
if names.is_empty() {
177+
error!("`values()` cannot be specified before the names");
178+
} else if values_specified {
179+
error!("`values()` cannot be specified multiple times");
180+
}
181+
values_specified = true;
182+
183+
for arg in args {
184+
if let Some(LitKind::Str(s, _)) = arg.lit().map(|lit| &lit.kind) {
185+
values.insert(Some(*s));
186+
} else if arg.has_name(sym::any)
187+
&& let Some(args) = arg.meta_item_list()
188+
{
189+
if values_any_specified {
190+
error!("`any()` in `values()` cannot be specified multiple times");
191+
}
192+
values_any_specified = true;
193+
if !args.is_empty() {
194+
error!("`any()` must be empty");
263195
}
196+
} else {
197+
error!("`values()` arguments must be string literals or `any()`");
264198
}
265-
} else {
266-
error!(
267-
"`cfg()` arguments must be simple identifiers, `any()` or `values(...)`"
268-
);
269199
}
200+
} else {
201+
error!("`cfg()` arguments must be simple identifiers, `any()` or `values(...)`");
270202
}
203+
}
271204

272-
if values.is_empty() && !values_any_specified && !any_specified {
273-
values.insert(None);
274-
} else if !values.is_empty() && values_any_specified {
275-
error!(
276-
"`values()` arguments cannot specify string literals and `any()` at the same time"
277-
);
278-
}
205+
if values.is_empty() && !values_any_specified && !any_specified {
206+
values.insert(None);
207+
} else if !values.is_empty() && values_any_specified {
208+
error!(
209+
"`values()` arguments cannot specify string literals and `any()` at the same time"
210+
);
211+
}
279212

280-
if any_specified {
281-
if names.is_empty()
282-
&& values.is_empty()
283-
&& !values_specified
284-
&& !values_any_specified
285-
{
286-
check_cfg.exhaustive_names = false;
287-
} else {
288-
error!("`cfg(any())` can only be provided in isolation");
289-
}
213+
if any_specified {
214+
if names.is_empty() && values.is_empty() && !values_specified && !values_any_specified {
215+
check_cfg.exhaustive_names = false;
290216
} else {
291-
for name in names {
292-
check_cfg
293-
.expecteds
294-
.entry(name.name)
295-
.and_modify(|v| match v {
296-
ExpectedValues::Some(v) if !values_any_specified => {
297-
v.extend(values.clone())
298-
}
299-
ExpectedValues::Some(_) => *v = ExpectedValues::Any,
300-
ExpectedValues::Any => {}
301-
})
302-
.or_insert_with(|| {
303-
if values_any_specified {
304-
ExpectedValues::Any
305-
} else {
306-
ExpectedValues::Some(values.clone())
307-
}
308-
});
309-
}
217+
error!("`cfg(any())` can only be provided in isolation");
310218
}
311219
} else {
312-
expected_error();
220+
for name in names {
221+
check_cfg
222+
.expecteds
223+
.entry(name.name)
224+
.and_modify(|v| match v {
225+
ExpectedValues::Some(v) if !values_any_specified => {
226+
v.extend(values.clone())
227+
}
228+
ExpectedValues::Some(_) => *v = ExpectedValues::Any,
229+
ExpectedValues::Any => {}
230+
})
231+
.or_insert_with(|| {
232+
if values_any_specified {
233+
ExpectedValues::Any
234+
} else {
235+
ExpectedValues::Some(values.clone())
236+
}
237+
});
238+
}
313239
}
314240
}
315241

compiler/rustc_lint/src/unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
291291
.map(|inner| MustUsePath::Pinned(Box::new(inner)))
292292
}
293293
ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
294-
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
294+
ty::Alias(ty::Opaque | ty::Projection, ty::AliasTy { def_id: def, .. }) => {
295295
elaborate(
296296
cx.tcx,
297297
cx.tcx.explicit_item_bounds(def).instantiate_identity_iter_copied(),

compiler/rustc_lint_defs/src/builtin.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -3135,7 +3135,7 @@ declare_lint! {
31353135
/// ### Example
31363136
///
31373137
/// ```text
3138-
/// rustc --check-cfg 'names()'
3138+
/// rustc --check-cfg 'cfg()'
31393139
/// ```
31403140
///
31413141
/// ```rust,ignore (needs command line option)
@@ -3146,7 +3146,7 @@ declare_lint! {
31463146
/// This will produce:
31473147
///
31483148
/// ```text
3149-
/// warning: unknown condition name used
3149+
/// warning: unexpected `cfg` condition name: `widnows`
31503150
/// --> lint_example.rs:1:7
31513151
/// |
31523152
/// 1 | #[cfg(widnows)]
@@ -3157,9 +3157,10 @@ declare_lint! {
31573157
///
31583158
/// ### Explanation
31593159
///
3160-
/// This lint is only active when a `--check-cfg='names(...)'` option has been passed
3161-
/// to the compiler and triggers whenever an unknown condition name or value is used.
3162-
/// The known condition include names or values passed in `--check-cfg`, `--cfg`, and some
3160+
/// This lint is only active when `--check-cfg` arguments are being passed
3161+
/// to the compiler and triggers whenever an unexpected condition name or value is used.
3162+
///
3163+
/// The known condition include names or values passed in `--check-cfg`, and some
31633164
/// well-knows names and values built into the compiler.
31643165
pub UNEXPECTED_CFGS,
31653166
Warn,

compiler/rustc_llvm/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn output(cmd: &mut Command) -> String {
102102

103103
fn main() {
104104
for component in REQUIRED_COMPONENTS.iter().chain(OPTIONAL_COMPONENTS.iter()) {
105-
println!("cargo:rustc-check-cfg=values(llvm_component,\"{component}\")");
105+
println!("cargo:rustc-check-cfg=cfg(llvm_component,values(\"{component}\"))");
106106
}
107107

108108
if tracked_env_var_os("RUST_CHECK").is_some() {

compiler/rustc_llvm/llvm-wrapper/LLVMWrapper.h

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "SuppressLLVMWarnings.h"
2+
13
#include "llvm-c/BitReader.h"
24
#include "llvm-c/Core.h"
35
#include "llvm-c/Object.h"

compiler/rustc_llvm/llvm-wrapper/Linker.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "SuppressLLVMWarnings.h"
12
#include "llvm/Linker/Linker.h"
23

34
#include "LLVMWrapper.h"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef _rustc_llvm_SuppressLLVMWarnings_h
2+
#define _rustc_llvm_SuppressLLVMWarnings_h
3+
4+
// LLVM currently generates many warnings when compiled using MSVC. These warnings make it difficult
5+
// to diagnose real problems when working on C++ code, so we suppress them.
6+
7+
#ifdef _MSC_VER
8+
#pragma warning(disable:4530) // C++ exception handler used, but unwind semantics are not enabled.
9+
#pragma warning(disable:4624) // 'xxx': destructor was implicitly defined as deleted
10+
#pragma warning(disable:4244) // conversion from 'xxx' to 'yyy', possible loss of data
11+
#endif
12+
13+
#endif // _rustc_llvm_SuppressLLVMWarnings_h

compiler/rustc_llvm/llvm-wrapper/SymbolWrapper.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// * https://github.com/llvm/llvm-project/blob/8ef3e895ad8ab1724e2b87cabad1dacdc7a397a3/llvm/include/llvm/Object/ArchiveWriter.h
88
// * https://github.com/llvm/llvm-project/blob/8ef3e895ad8ab1724e2b87cabad1dacdc7a397a3/llvm/lib/Object/ArchiveWriter.cpp
99

10+
#include "SuppressLLVMWarnings.h"
1011
#include "llvm/ADT/SmallString.h"
1112
#include "llvm/IR/LLVMContext.h"
1213
#include "llvm/Object/ObjectFile.h"

0 commit comments

Comments
 (0)