Skip to content

Commit 6423ab3

Browse files
committed
Auto merge of rust-lang#99998 - matthiaskrgr:rollup-igafy0r, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#99519 (Remove implicit names and values from `--cfg` in `--check-cfg`) - rust-lang#99620 (`-Z location-detail`: provide option to disable all location details) - rust-lang#99932 (Fix unwinding on certain platforms when debug assertions are enabled) - rust-lang#99973 (Layout things) - rust-lang#99980 (Remove more Clean trait implementations) - rust-lang#99984 (Fix compat.rs for `cfg(miri)`) - rust-lang#99986 (Add wrap suggestions for record variants) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 34805f3 + 20a5e9f commit 6423ab3

28 files changed

+1096
-1064
lines changed

compiler/rustc_interface/src/util.rs

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ pub fn create_session(
117117

118118
let mut check_cfg = config::to_crate_check_config(check_cfg);
119119
check_cfg.fill_well_known();
120-
check_cfg.fill_actual(&cfg);
121120

122121
sess.parse_sess.config = cfg;
123122
sess.parse_sess.check_config = check_cfg;

compiler/rustc_middle/src/ty/layout.rs

+4
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ fn sanity_check_layout<'tcx>(
232232
assert!(layout.abi.is_uninhabited());
233233
}
234234

235+
if layout.size.bytes() % layout.align.abi.bytes() != 0 {
236+
bug!("size is not a multiple of align, in the following layout:\n{layout:#?}");
237+
}
238+
235239
if cfg!(debug_assertions) {
236240
fn check_layout_abi<'tcx>(tcx: TyCtxt<'tcx>, layout: Layout<'tcx>) {
237241
match layout.abi() {

compiler/rustc_session/src/config.rs

-14
Original file line numberDiff line numberDiff line change
@@ -1159,20 +1159,6 @@ impl CrateCheckConfig {
11591159
self.fill_well_known_names();
11601160
self.fill_well_known_values();
11611161
}
1162-
1163-
/// Fills a `CrateCheckConfig` with configuration names and values that are actually active.
1164-
pub fn fill_actual(&mut self, cfg: &CrateConfig) {
1165-
for &(k, v) in cfg {
1166-
if let Some(names_valid) = &mut self.names_valid {
1167-
names_valid.insert(k);
1168-
}
1169-
if let Some(v) = v {
1170-
self.values_valid.entry(k).and_modify(|values| {
1171-
values.insert(v);
1172-
});
1173-
}
1174-
}
1175-
}
11761162
}
11771163

11781164
pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateConfig {

compiler/rustc_session/src/options.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,7 @@ mod desc {
393393
"either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
394394
pub const parse_linker_plugin_lto: &str =
395395
"either a boolean (`yes`, `no`, `on`, `off`, etc), or the path to the linker plugin";
396-
pub const parse_location_detail: &str =
397-
"comma separated list of location details to track: `file`, `line`, or `column`";
396+
pub const parse_location_detail: &str = "either `none`, or a comma separated list of location details to track: `file`, `line`, or `column`";
398397
pub const parse_switch_with_opt_path: &str =
399398
"an optional path to the profiling data output directory";
400399
pub const parse_merge_functions: &str = "one of: `disabled`, `trampolines`, or `aliases`";
@@ -551,6 +550,9 @@ mod parse {
551550
ld.line = false;
552551
ld.file = false;
553552
ld.column = false;
553+
if v == "none" {
554+
return true;
555+
}
554556
for s in v.split(',') {
555557
match s {
556558
"file" => ld.file = true,
@@ -1374,8 +1376,9 @@ options! {
13741376
llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
13751377
"generate JSON tracing data file from LLVM data (default: no)"),
13761378
location_detail: LocationDetail = (LocationDetail::all(), parse_location_detail, [TRACKED],
1377-
"comma separated list of location details to be tracked when using caller_location \
1378-
valid options are `file`, `line`, and `column` (default: all)"),
1379+
"what location details should be tracked when using caller_location, either \
1380+
`none`, or a comma separated list of location details, for which \
1381+
valid options are `file`, `line`, and `column` (default: `file,line,column`)"),
13791382
ls: bool = (false, parse_bool, [UNTRACKED],
13801383
"list the symbols defined by a library crate (default: no)"),
13811384
macro_backtrace: bool = (false, parse_bool, [UNTRACKED],

compiler/rustc_target/src/abi/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1279,13 +1279,14 @@ impl<'a> fmt::Debug for LayoutS<'a> {
12791279
// This is how `Layout` used to print before it become
12801280
// `Interned<LayoutS>`. We print it like this to avoid having to update
12811281
// expected output in a lot of tests.
1282+
let LayoutS { size, align, abi, fields, largest_niche, variants } = self;
12821283
f.debug_struct("Layout")
1283-
.field("fields", &self.fields)
1284-
.field("variants", &self.variants)
1285-
.field("abi", &self.abi)
1286-
.field("largest_niche", &self.largest_niche)
1287-
.field("align", &self.align)
1288-
.field("size", &self.size)
1284+
.field("size", size)
1285+
.field("align", align)
1286+
.field("abi", abi)
1287+
.field("fields", fields)
1288+
.field("largest_niche", largest_niche)
1289+
.field("variants", variants)
12891290
.finish()
12901291
}
12911292
}

compiler/rustc_typeck/src/check/demand.rs

+33-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::check::FnCtxt;
22
use rustc_infer::infer::InferOk;
3+
use rustc_middle::middle::stability::EvalResult;
34
use rustc_trait_selection::infer::InferCtxtExt as _;
45
use rustc_trait_selection::traits::ObligationCause;
56

@@ -363,18 +364,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
363364
}
364365
}
365366

366-
let compatible_variants: Vec<(String, Option<String>)> = expected_adt
367+
let compatible_variants: Vec<(String, _, _, Option<String>)> = expected_adt
367368
.variants()
368369
.iter()
369370
.filter(|variant| {
370-
variant.fields.len() == 1 && variant.ctor_kind == hir::def::CtorKind::Fn
371+
variant.fields.len() == 1
371372
})
372373
.filter_map(|variant| {
373374
let sole_field = &variant.fields[0];
374375

375376
let field_is_local = sole_field.did.is_local();
376377
let field_is_accessible =
377-
sole_field.vis.is_accessible_from(expr.hir_id.owner.to_def_id(), self.tcx);
378+
sole_field.vis.is_accessible_from(expr.hir_id.owner.to_def_id(), self.tcx)
379+
// Skip suggestions for unstable public fields (for example `Pin::pointer`)
380+
&& matches!(self.tcx.eval_stability(sole_field.did, None, expr.span, None), EvalResult::Allow | EvalResult::Unmarked);
378381

379382
if !field_is_local && !field_is_accessible {
380383
return None;
@@ -391,33 +394,45 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
391394
if let Some(path) = variant_path.strip_prefix("std::prelude::")
392395
&& let Some((_, path)) = path.split_once("::")
393396
{
394-
return Some((path.to_string(), note_about_variant_field_privacy));
397+
return Some((path.to_string(), variant.ctor_kind, sole_field.name, note_about_variant_field_privacy));
395398
}
396-
Some((variant_path, note_about_variant_field_privacy))
399+
Some((variant_path, variant.ctor_kind, sole_field.name, note_about_variant_field_privacy))
397400
} else {
398401
None
399402
}
400403
})
401404
.collect();
402405

403-
let prefix = match self.maybe_get_struct_pattern_shorthand_field(expr) {
404-
Some(ident) => format!("{ident}: "),
405-
None => String::new(),
406+
let suggestions_for = |variant: &_, ctor, field_name| {
407+
let prefix = match self.maybe_get_struct_pattern_shorthand_field(expr) {
408+
Some(ident) => format!("{ident}: "),
409+
None => String::new(),
410+
};
411+
412+
let (open, close) = match ctor {
413+
hir::def::CtorKind::Fn => ("(".to_owned(), ")"),
414+
hir::def::CtorKind::Fictive => (format!(" {{ {field_name}: "), " }"),
415+
416+
// unit variants don't have fields
417+
hir::def::CtorKind::Const => unreachable!(),
418+
};
419+
420+
vec![
421+
(expr.span.shrink_to_lo(), format!("{prefix}{variant}{open}")),
422+
(expr.span.shrink_to_hi(), close.to_owned()),
423+
]
406424
};
407425

408426
match &compatible_variants[..] {
409427
[] => { /* No variants to format */ }
410-
[(variant, note)] => {
428+
[(variant, ctor_kind, field_name, note)] => {
411429
// Just a single matching variant.
412430
err.multipart_suggestion_verbose(
413431
&format!(
414432
"try wrapping the expression in `{variant}`{note}",
415433
note = note.as_deref().unwrap_or("")
416434
),
417-
vec![
418-
(expr.span.shrink_to_lo(), format!("{prefix}{variant}(")),
419-
(expr.span.shrink_to_hi(), ")".to_string()),
420-
],
435+
suggestions_for(&**variant, *ctor_kind, *field_name),
421436
Applicability::MaybeIncorrect,
422437
);
423438
}
@@ -428,12 +443,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
428443
"try wrapping the expression in a variant of `{}`",
429444
self.tcx.def_path_str(expected_adt.did())
430445
),
431-
compatible_variants.into_iter().map(|(variant, _)| {
432-
vec![
433-
(expr.span.shrink_to_lo(), format!("{prefix}{variant}(")),
434-
(expr.span.shrink_to_hi(), ")".to_string()),
435-
]
436-
}),
446+
compatible_variants.into_iter().map(
447+
|(variant, ctor_kind, field_name, _)| {
448+
suggestions_for(&variant, ctor_kind, field_name)
449+
},
450+
),
437451
Applicability::MaybeIncorrect,
438452
);
439453
}

library/panic_unwind/src/gcc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ unsafe fn find_eh_action(context: *mut uw::_Unwind_Context) -> Result<EHAction,
306306
let eh_context = EHContext {
307307
// The return address points 1 byte past the call instruction,
308308
// which could be in the next IP range in LSDA range table.
309-
ip: if ip_before_instr != 0 { ip } else { ip - 1 },
309+
//
310+
// `ip = -1` has special meaning, so use wrapping sub to allow for that
311+
ip: if ip_before_instr != 0 { ip } else { ip.wrapping_sub(1) },
310312
func_start: uw::_Unwind_GetRegionStart(context),
311313
get_text_start: &|| uw::_Unwind_GetTextRelBase(context),
312314
get_data_start: &|| uw::_Unwind_GetDataRelBase(context),

library/std/src/sys/windows/compat.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ macro_rules! compat_fn_with_fallback {
180180

181181
fn load_from_module(module: Option<Module>) -> F {
182182
unsafe {
183-
static symbol_name: &CStr = ansi_str!(sym $symbol);
184-
if let Some(f) = module.and_then(|m| m.proc_address(symbol_name)) {
183+
static SYMBOL_NAME: &CStr = ansi_str!(sym $symbol);
184+
if let Some(f) = module.and_then(|m| m.proc_address(SYMBOL_NAME)) {
185185
PTR.store(f.as_ptr(), Ordering::Relaxed);
186186
mem::transmute(f)
187187
} else {
@@ -251,7 +251,7 @@ macro_rules! compat_fn_optional {
251251
pub fn option() -> Option<F> {
252252
let mut func = NonNull::new(PTR.load(Ordering::Relaxed));
253253
if func.is_none() {
254-
Module::new($module).map(preload);
254+
unsafe { Module::new($module).map(preload) };
255255
func = NonNull::new(PTR.load(Ordering::Relaxed));
256256
}
257257
unsafe {
@@ -262,8 +262,8 @@ macro_rules! compat_fn_optional {
262262
#[allow(unused)]
263263
pub(in crate::sys) fn preload(module: Module) {
264264
unsafe {
265-
let symbol_name = ansi_str!(sym $symbol);
266-
if let Some(f) = module.proc_address(symbol_name) {
265+
static SYMBOL_NAME: &CStr = ansi_str!(sym $symbol);
266+
if let Some(f) = module.proc_address(SYMBOL_NAME) {
267267
PTR.store(f.as_ptr(), Ordering::Relaxed);
268268
}
269269
}

src/doc/unstable-book/src/compiler-flags/check-cfg.md

+9-26
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ check cfg specification is parsed using the Rust metadata syntax, just as the `-
1818
These two options are independent. `names` checks only the namespace of condition names
1919
while `values` checks only the namespace of the values of list-valued conditions.
2020

21+
NOTE: No implicit expectation is added when using `--cfg` for both forms. Users are expected to
22+
pass all expected names and values using `names(...)` and `values(...)`.
23+
2124
## The `names(...)` form
2225

2326
The `names(...)` form enables checking the names. This form uses a named list:
@@ -53,27 +56,6 @@ The first form enables checking condition names, while specifying that there are
5356
condition names (outside of the set of well-known names defined by `rustc`). Omitting the
5457
`--check-cfg 'names(...)'` option does not enable checking condition names.
5558

56-
Conditions that are enabled are implicitly valid; it is unnecessary (but legal) to specify a
57-
condition name as both enabled and valid. For example, the following invocations are equivalent:
58-
59-
```bash
60-
# condition names will be checked, and 'has_time_travel' is valid
61-
rustc --cfg 'has_time_travel' --check-cfg 'names()'
62-
63-
# condition names will be checked, and 'has_time_travel' is valid
64-
rustc --cfg 'has_time_travel' --check-cfg 'names(has_time_travel)'
65-
```
66-
67-
In contrast, the following two invocations are _not_ equivalent:
68-
69-
```bash
70-
# condition names will not be checked (because there is no --check-cfg names(...))
71-
rustc --cfg 'has_time_travel'
72-
73-
# condition names will be checked, and 'has_time_travel' is both valid and enabled.
74-
rustc --cfg 'has_time_travel' --check-cfg 'names(has_time_travel)'
75-
```
76-
7759
## The `values(...)` form
7860

7961
The `values(...)` form enables checking the values within list-valued conditions. It has this
@@ -149,7 +131,7 @@ fn tame_lion() {}
149131
```bash
150132
# This turns on checking for condition names, but not values, such as 'feature' values.
151133
rustc --check-cfg 'names(is_embedded, has_feathers)' \
152-
--cfg has_feathers --cfg 'feature = "zapping"' -Z unstable-options
134+
--cfg has_feathers -Z unstable-options
153135
```
154136
155137
```rust
@@ -159,13 +141,14 @@ fn do_embedded() {}
159141
#[cfg(has_feathers)] // This is expected as "has_feathers" was provided in names()
160142
fn do_features() {}
161143
144+
#[cfg(has_feathers = "zapping")] // This is expected as "has_feathers" was provided in names()
145+
// and because no value checking was enable for "has_feathers"
146+
// no warning is emited for the value "zapping"
147+
fn do_zapping() {}
148+
162149
#[cfg(has_mumble_frotz)] // This is UNEXPECTED because names checking is enable and
163150
// "has_mumble_frotz" was not provided in names()
164151
fn do_mumble_frotz() {}
165-
166-
#[cfg(feature = "lasers")] // This doesn't raise a warning, because values checking for "feature"
167-
// was never used
168-
fn shoot_lasers() {}
169152
```
170153
171154
### Example: Checking feature values, but not condition names

src/doc/unstable-book/src/compiler-flags/location-detail.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ within this list are:
1717
- `line` - the source line of the panic will be included in the panic output
1818
- `column` - the source column of the panic will be included in the panic output
1919

20-
Any combination of these three options are supported. If this option is not specified,
21-
all three are included by default.
20+
Any combination of these three options are supported. Alternatively, you can pass
21+
`none` to this option, which results in no location details being tracked.
22+
If this option is not specified, all three are included by default.
2223

2324
An example of a panic output when using `-Z location-detail=line`:
2425
```text

0 commit comments

Comments
 (0)