Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #99998

Merged
merged 21 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ebf4cc3
Remove implicit names and values from --cfg in --check-cfg
Urgau Jul 20, 2022
6dea21a
location-detail: disable all location details when passed `none`
hudson-ayers Jul 22, 2022
15b7a08
Fix unwinding when debug assertions are enabled
madsmtm Jul 30, 2022
98e52c2
check 'size multiple of align' for all layouts
RalfJung Jul 28, 2022
279af1d
Remove Clean trait implementation for hir::Path
GuillaumeGomez Jul 31, 2022
9dd59dd
Remove Clean trait implementation for hir::TypeBinding
GuillaumeGomez Jul 31, 2022
abd80d9
reorder fields in Laout debug output
RalfJung Jul 31, 2022
fc1c858
Remove Clean trait implementation for hir::TypeBindingKind
GuillaumeGomez Jul 31, 2022
506c98f
Suggest wrapping expressions in single-field record variants
WaffleLapkin Jul 31, 2022
7f3d11e
Fix compat.rs for `cfg(miri)`
ChrisDenton Jul 31, 2022
260a840
Refactor wrap suggestion code (just a bit)
WaffleLapkin Jul 31, 2022
5e39b35
--bless tests
WaffleLapkin Jul 31, 2022
1c2ea78
Skip unstable fields when suggesting wrapping expression in structs
WaffleLapkin Jul 31, 2022
bf0b18e
Make sure `symbol_name` is const evaluated
ChrisDenton Jul 31, 2022
e820ecd
Rollup merge of #99519 - Urgau:check-cfg-implicit, r=petrochenkov
matthiaskrgr Jul 31, 2022
9cc06eb
Rollup merge of #99620 - hudson-ayers:fix-location-detail, r=davidtwco
matthiaskrgr Jul 31, 2022
c98e893
Rollup merge of #99932 - madsmtm:fix-unwinding-debug-assertions, r=Am…
matthiaskrgr Jul 31, 2022
549463f
Rollup merge of #99973 - RalfJung:layout-things, r=eddyb
matthiaskrgr Jul 31, 2022
0c3989e
Rollup merge of #99980 - GuillaumeGomez:rm-clean-impls, r=Dylan-DPC
matthiaskrgr Jul 31, 2022
e4fcee5
Rollup merge of #99984 - ChrisDenton:fix-miri, r=Mark-Simulacrum
matthiaskrgr Jul 31, 2022
20a5e9f
Rollup merge of #99986 - WaffleLapkin:record_struct_wrap_suggestion, …
matthiaskrgr Jul 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ pub fn create_session(

let mut check_cfg = config::to_crate_check_config(check_cfg);
check_cfg.fill_well_known();
check_cfg.fill_actual(&cfg);

sess.parse_sess.config = cfg;
sess.parse_sess.check_config = check_cfg;
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ fn sanity_check_layout<'tcx>(
assert!(layout.abi.is_uninhabited());
}

if layout.size.bytes() % layout.align.abi.bytes() != 0 {
bug!("size is not a multiple of align, in the following layout:\n{layout:#?}");
}

if cfg!(debug_assertions) {
fn check_layout_abi<'tcx>(tcx: TyCtxt<'tcx>, layout: Layout<'tcx>) {
match layout.abi() {
Expand Down
14 changes: 0 additions & 14 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,20 +1159,6 @@ impl CrateCheckConfig {
self.fill_well_known_names();
self.fill_well_known_values();
}

/// Fills a `CrateCheckConfig` with configuration names and values that are actually active.
pub fn fill_actual(&mut self, cfg: &CrateConfig) {
for &(k, v) in cfg {
if let Some(names_valid) = &mut self.names_valid {
names_valid.insert(k);
}
if let Some(v) = v {
self.values_valid.entry(k).and_modify(|values| {
values.insert(v);
});
}
}
}
}

pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateConfig {
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,7 @@ mod desc {
"either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
pub const parse_linker_plugin_lto: &str =
"either a boolean (`yes`, `no`, `on`, `off`, etc), or the path to the linker plugin";
pub const parse_location_detail: &str =
"comma separated list of location details to track: `file`, `line`, or `column`";
pub const parse_location_detail: &str = "either `none`, or a comma separated list of location details to track: `file`, `line`, or `column`";
pub const parse_switch_with_opt_path: &str =
"an optional path to the profiling data output directory";
pub const parse_merge_functions: &str = "one of: `disabled`, `trampolines`, or `aliases`";
Expand Down Expand Up @@ -551,6 +550,9 @@ mod parse {
ld.line = false;
ld.file = false;
ld.column = false;
if v == "none" {
return true;
}
for s in v.split(',') {
match s {
"file" => ld.file = true,
Expand Down Expand Up @@ -1374,8 +1376,9 @@ options! {
llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
"generate JSON tracing data file from LLVM data (default: no)"),
location_detail: LocationDetail = (LocationDetail::all(), parse_location_detail, [TRACKED],
"comma separated list of location details to be tracked when using caller_location \
valid options are `file`, `line`, and `column` (default: all)"),
"what location details should be tracked when using caller_location, either \
`none`, or a comma separated list of location details, for which \
valid options are `file`, `line`, and `column` (default: `file,line,column`)"),
ls: bool = (false, parse_bool, [UNTRACKED],
"list the symbols defined by a library crate (default: no)"),
macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_target/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1279,13 +1279,14 @@ impl<'a> fmt::Debug for LayoutS<'a> {
// This is how `Layout` used to print before it become
// `Interned<LayoutS>`. We print it like this to avoid having to update
// expected output in a lot of tests.
let LayoutS { size, align, abi, fields, largest_niche, variants } = self;
f.debug_struct("Layout")
.field("fields", &self.fields)
.field("variants", &self.variants)
.field("abi", &self.abi)
.field("largest_niche", &self.largest_niche)
.field("align", &self.align)
.field("size", &self.size)
.field("size", size)
.field("align", align)
.field("abi", abi)
.field("fields", fields)
.field("largest_niche", largest_niche)
.field("variants", variants)
.finish()
}
}
Expand Down
52 changes: 33 additions & 19 deletions compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::check::FnCtxt;
use rustc_infer::infer::InferOk;
use rustc_middle::middle::stability::EvalResult;
use rustc_trait_selection::infer::InferCtxtExt as _;
use rustc_trait_selection::traits::ObligationCause;

Expand Down Expand Up @@ -363,18 +364,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

let compatible_variants: Vec<(String, Option<String>)> = expected_adt
let compatible_variants: Vec<(String, _, _, Option<String>)> = expected_adt
.variants()
.iter()
.filter(|variant| {
variant.fields.len() == 1 && variant.ctor_kind == hir::def::CtorKind::Fn
variant.fields.len() == 1
})
.filter_map(|variant| {
let sole_field = &variant.fields[0];

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

if !field_is_local && !field_is_accessible {
return None;
Expand All @@ -391,33 +394,45 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(path) = variant_path.strip_prefix("std::prelude::")
&& let Some((_, path)) = path.split_once("::")
{
return Some((path.to_string(), note_about_variant_field_privacy));
return Some((path.to_string(), variant.ctor_kind, sole_field.name, note_about_variant_field_privacy));
}
Some((variant_path, note_about_variant_field_privacy))
Some((variant_path, variant.ctor_kind, sole_field.name, note_about_variant_field_privacy))
} else {
None
}
})
.collect();

let prefix = match self.maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!("{ident}: "),
None => String::new(),
let suggestions_for = |variant: &_, ctor, field_name| {
let prefix = match self.maybe_get_struct_pattern_shorthand_field(expr) {
Some(ident) => format!("{ident}: "),
None => String::new(),
};

let (open, close) = match ctor {
hir::def::CtorKind::Fn => ("(".to_owned(), ")"),
hir::def::CtorKind::Fictive => (format!(" {{ {field_name}: "), " }"),

// unit variants don't have fields
hir::def::CtorKind::Const => unreachable!(),
};

vec![
(expr.span.shrink_to_lo(), format!("{prefix}{variant}{open}")),
(expr.span.shrink_to_hi(), close.to_owned()),
]
};

match &compatible_variants[..] {
[] => { /* No variants to format */ }
[(variant, note)] => {
[(variant, ctor_kind, field_name, note)] => {
// Just a single matching variant.
err.multipart_suggestion_verbose(
&format!(
"try wrapping the expression in `{variant}`{note}",
note = note.as_deref().unwrap_or("")
),
vec![
(expr.span.shrink_to_lo(), format!("{prefix}{variant}(")),
(expr.span.shrink_to_hi(), ")".to_string()),
],
suggestions_for(&**variant, *ctor_kind, *field_name),
Applicability::MaybeIncorrect,
);
}
Expand All @@ -428,12 +443,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
"try wrapping the expression in a variant of `{}`",
self.tcx.def_path_str(expected_adt.did())
),
compatible_variants.into_iter().map(|(variant, _)| {
vec![
(expr.span.shrink_to_lo(), format!("{prefix}{variant}(")),
(expr.span.shrink_to_hi(), ")".to_string()),
]
}),
compatible_variants.into_iter().map(
|(variant, ctor_kind, field_name, _)| {
suggestions_for(&variant, ctor_kind, field_name)
},
),
Applicability::MaybeIncorrect,
);
}
Expand Down
4 changes: 3 additions & 1 deletion library/panic_unwind/src/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ unsafe fn find_eh_action(context: *mut uw::_Unwind_Context) -> Result<EHAction,
let eh_context = EHContext {
// The return address points 1 byte past the call instruction,
// which could be in the next IP range in LSDA range table.
ip: if ip_before_instr != 0 { ip } else { ip - 1 },
//
// `ip = -1` has special meaning, so use wrapping sub to allow for that
ip: if ip_before_instr != 0 { ip } else { ip.wrapping_sub(1) },
func_start: uw::_Unwind_GetRegionStart(context),
get_text_start: &|| uw::_Unwind_GetTextRelBase(context),
get_data_start: &|| uw::_Unwind_GetDataRelBase(context),
Expand Down
10 changes: 5 additions & 5 deletions library/std/src/sys/windows/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ macro_rules! compat_fn_with_fallback {

fn load_from_module(module: Option<Module>) -> F {
unsafe {
static symbol_name: &CStr = ansi_str!(sym $symbol);
if let Some(f) = module.and_then(|m| m.proc_address(symbol_name)) {
static SYMBOL_NAME: &CStr = ansi_str!(sym $symbol);
if let Some(f) = module.and_then(|m| m.proc_address(SYMBOL_NAME)) {
PTR.store(f.as_ptr(), Ordering::Relaxed);
mem::transmute(f)
} else {
Expand Down Expand Up @@ -251,7 +251,7 @@ macro_rules! compat_fn_optional {
pub fn option() -> Option<F> {
let mut func = NonNull::new(PTR.load(Ordering::Relaxed));
if func.is_none() {
Module::new($module).map(preload);
unsafe { Module::new($module).map(preload) };
func = NonNull::new(PTR.load(Ordering::Relaxed));
}
unsafe {
Expand All @@ -262,8 +262,8 @@ macro_rules! compat_fn_optional {
#[allow(unused)]
pub(in crate::sys) fn preload(module: Module) {
unsafe {
let symbol_name = ansi_str!(sym $symbol);
if let Some(f) = module.proc_address(symbol_name) {
static SYMBOL_NAME: &CStr = ansi_str!(sym $symbol);
if let Some(f) = module.proc_address(SYMBOL_NAME) {
PTR.store(f.as_ptr(), Ordering::Relaxed);
}
}
Expand Down
35 changes: 9 additions & 26 deletions src/doc/unstable-book/src/compiler-flags/check-cfg.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ check cfg specification is parsed using the Rust metadata syntax, just as the `-
These two options are independent. `names` checks only the namespace of condition names
while `values` checks only the namespace of the values of list-valued conditions.

NOTE: No implicit expectation is added when using `--cfg` for both forms. Users are expected to
pass all expected names and values using `names(...)` and `values(...)`.

## The `names(...)` form

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

Conditions that are enabled are implicitly valid; it is unnecessary (but legal) to specify a
condition name as both enabled and valid. For example, the following invocations are equivalent:

```bash
# condition names will be checked, and 'has_time_travel' is valid
rustc --cfg 'has_time_travel' --check-cfg 'names()'

# condition names will be checked, and 'has_time_travel' is valid
rustc --cfg 'has_time_travel' --check-cfg 'names(has_time_travel)'
```

In contrast, the following two invocations are _not_ equivalent:

```bash
# condition names will not be checked (because there is no --check-cfg names(...))
rustc --cfg 'has_time_travel'

# condition names will be checked, and 'has_time_travel' is both valid and enabled.
rustc --cfg 'has_time_travel' --check-cfg 'names(has_time_travel)'
```

## The `values(...)` form

The `values(...)` form enables checking the values within list-valued conditions. It has this
Expand Down Expand Up @@ -149,7 +131,7 @@ fn tame_lion() {}
```bash
# This turns on checking for condition names, but not values, such as 'feature' values.
rustc --check-cfg 'names(is_embedded, has_feathers)' \
--cfg has_feathers --cfg 'feature = "zapping"' -Z unstable-options
--cfg has_feathers -Z unstable-options
```

```rust
Expand All @@ -159,13 +141,14 @@ fn do_embedded() {}
#[cfg(has_feathers)] // This is expected as "has_feathers" was provided in names()
fn do_features() {}

#[cfg(has_feathers = "zapping")] // This is expected as "has_feathers" was provided in names()
// and because no value checking was enable for "has_feathers"
// no warning is emited for the value "zapping"
fn do_zapping() {}

#[cfg(has_mumble_frotz)] // This is UNEXPECTED because names checking is enable and
// "has_mumble_frotz" was not provided in names()
fn do_mumble_frotz() {}

#[cfg(feature = "lasers")] // This doesn't raise a warning, because values checking for "feature"
// was never used
fn shoot_lasers() {}
```

### Example: Checking feature values, but not condition names
Expand Down
5 changes: 3 additions & 2 deletions src/doc/unstable-book/src/compiler-flags/location-detail.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ within this list are:
- `line` - the source line of the panic will be included in the panic output
- `column` - the source column of the panic will be included in the panic output

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

An example of a panic output when using `-Z location-detail=line`:
```text
Expand Down
Loading