Skip to content

Commit 2cec7a8

Browse files
committed
Auto merge of rust-lang#128529 - matthiaskrgr:rollup-gzq2slo, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#126818 (Better handle suggestions for the already present code and fix some suggestions) - rust-lang#128436 (Update sysinfo version to 0.31.2) - rust-lang#128453 (raw_eq: using it on bytes with provenance is not UB (outside const-eval)) - rust-lang#128491 ([`macro_metavar_expr_concat`] Dogfooding) - rust-lang#128494 (MIR required_consts, mentioned_items: ensure we do not forget to fill these lists) - rust-lang#128521 (rustdoc: Remove dead opaque_tys rendering logic) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 05e692a + 1140fd1 commit 2cec7a8

File tree

39 files changed

+358
-225
lines changed

39 files changed

+358
-225
lines changed

Cargo.lock

+64-23
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ dependencies = [
771771
"tracing-subscriber",
772772
"unified-diff",
773773
"walkdir",
774-
"windows",
774+
"windows 0.52.0",
775775
]
776776

777777
[[package]]
@@ -1713,7 +1713,7 @@ dependencies = [
17131713
"iana-time-zone-haiku",
17141714
"js-sys",
17151715
"wasm-bindgen",
1716-
"windows-core",
1716+
"windows-core 0.52.0",
17171717
]
17181718

17191719
[[package]]
@@ -2436,15 +2436,6 @@ dependencies = [
24362436
"windows-sys 0.52.0",
24372437
]
24382438

2439-
[[package]]
2440-
name = "ntapi"
2441-
version = "0.4.1"
2442-
source = "registry+https://github.com/rust-lang/crates.io-index"
2443-
checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4"
2444-
dependencies = [
2445-
"winapi",
2446-
]
2447-
24482439
[[package]]
24492440
name = "nu-ansi-term"
24502441
version = "0.46.0"
@@ -3717,7 +3708,7 @@ dependencies = [
37173708
"thorin-dwp",
37183709
"tracing",
37193710
"wasm-encoder 0.210.0",
3720-
"windows",
3711+
"windows 0.52.0",
37213712
]
37223713

37233714
[[package]]
@@ -3774,7 +3765,7 @@ dependencies = [
37743765
"tempfile",
37753766
"thin-vec",
37763767
"tracing",
3777-
"windows",
3768+
"windows 0.52.0",
37783769
]
37793770

37803771
[[package]]
@@ -3835,7 +3826,7 @@ dependencies = [
38353826
"shlex",
38363827
"time",
38373828
"tracing",
3838-
"windows",
3829+
"windows 0.52.0",
38393830
]
38403831

38413832
[[package]]
@@ -3886,7 +3877,7 @@ dependencies = [
38863877
"termcolor",
38873878
"termize",
38883879
"tracing",
3889-
"windows",
3880+
"windows 0.52.0",
38903881
]
38913882

38923883
[[package]]
@@ -4607,7 +4598,7 @@ dependencies = [
46074598
"smallvec",
46084599
"termize",
46094600
"tracing",
4610-
"windows",
4601+
"windows 0.52.0",
46114602
]
46124603

46134604
[[package]]
@@ -5365,16 +5356,13 @@ dependencies = [
53655356

53665357
[[package]]
53675358
name = "sysinfo"
5368-
version = "0.30.12"
5359+
version = "0.31.2"
53695360
source = "registry+https://github.com/rust-lang/crates.io-index"
5370-
checksum = "732ffa00f53e6b2af46208fba5718d9662a421049204e156328b66791ffa15ae"
5361+
checksum = "d4115055da5f572fff541dd0c4e61b0262977f453cc9fe04be83aba25a89bdab"
53715362
dependencies = [
5372-
"cfg-if",
53735363
"core-foundation-sys",
53745364
"libc",
5375-
"ntapi",
5376-
"once_cell",
5377-
"windows",
5365+
"windows 0.57.0",
53785366
]
53795367

53805368
[[package]]
@@ -6299,7 +6287,17 @@ version = "0.52.0"
62996287
source = "registry+https://github.com/rust-lang/crates.io-index"
63006288
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
63016289
dependencies = [
6302-
"windows-core",
6290+
"windows-core 0.52.0",
6291+
"windows-targets 0.52.5",
6292+
]
6293+
6294+
[[package]]
6295+
name = "windows"
6296+
version = "0.57.0"
6297+
source = "registry+https://github.com/rust-lang/crates.io-index"
6298+
checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143"
6299+
dependencies = [
6300+
"windows-core 0.57.0",
63036301
"windows-targets 0.52.5",
63046302
]
63056303

@@ -6326,12 +6324,55 @@ dependencies = [
63266324
"windows-targets 0.52.5",
63276325
]
63286326

6327+
[[package]]
6328+
name = "windows-core"
6329+
version = "0.57.0"
6330+
source = "registry+https://github.com/rust-lang/crates.io-index"
6331+
checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d"
6332+
dependencies = [
6333+
"windows-implement",
6334+
"windows-interface",
6335+
"windows-result",
6336+
"windows-targets 0.52.5",
6337+
]
6338+
6339+
[[package]]
6340+
name = "windows-implement"
6341+
version = "0.57.0"
6342+
source = "registry+https://github.com/rust-lang/crates.io-index"
6343+
checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7"
6344+
dependencies = [
6345+
"proc-macro2",
6346+
"quote",
6347+
"syn 2.0.67",
6348+
]
6349+
6350+
[[package]]
6351+
name = "windows-interface"
6352+
version = "0.57.0"
6353+
source = "registry+https://github.com/rust-lang/crates.io-index"
6354+
checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7"
6355+
dependencies = [
6356+
"proc-macro2",
6357+
"quote",
6358+
"syn 2.0.67",
6359+
]
6360+
63296361
[[package]]
63306362
name = "windows-metadata"
63316363
version = "0.58.0"
63326364
source = "registry+https://github.com/rust-lang/crates.io-index"
63336365
checksum = "2e837f3c3012cfe9e7086302a93f441a7999439be1ad4c530d55d2f6d2921809"
63346366

6367+
[[package]]
6368+
name = "windows-result"
6369+
version = "0.1.2"
6370+
source = "registry+https://github.com/rust-lang/crates.io-index"
6371+
checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8"
6372+
dependencies = [
6373+
"windows-targets 0.52.5",
6374+
]
6375+
63356376
[[package]]
63366377
name = "windows-sys"
63376378
version = "0.48.0"

compiler/rustc_const_eval/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,6 @@ const_eval_range_upper = less or equal to {$hi}
316316
const_eval_range_wrapping = less or equal to {$hi}, or greater or equal to {$lo}
317317
const_eval_raw_bytes = the raw bytes of the constant (size: {$size}, align: {$align}) {"{"}{$bytes}{"}"}
318318
319-
const_eval_raw_eq_with_provenance =
320-
`raw_eq` on bytes with provenance
321-
322319
const_eval_raw_ptr_comparison =
323320
pointers cannot be reliably compared during const eval
324321
.note = see issue #53020 <https://github.com/rust-lang/rust/issues/53020> for more information

compiler/rustc_const_eval/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
877877
body: &'tcx mir::Body<'tcx>,
878878
) -> InterpResult<'tcx> {
879879
// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
880-
for &const_ in &body.required_consts {
880+
for &const_ in body.required_consts() {
881881
let c =
882882
self.instantiate_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
883883
c.eval(*self.tcx, self.param_env, const_.span).map_err(|err| {

compiler/rustc_const_eval/src/interpret/intrinsics.rs

-3
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
690690
// zero-sized access
691691
return Ok(&[]);
692692
};
693-
if alloc_ref.has_provenance() {
694-
throw_ub_custom!(fluent::const_eval_raw_eq_with_provenance);
695-
}
696693
alloc_ref.get_bytes_strip_provenance()
697694
};
698695

compiler/rustc_errors/src/emitter.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,10 @@ impl HumanEmitter {
17671767
debug!(?suggestions);
17681768

17691769
if suggestions.is_empty() {
1770-
// Suggestions coming from macros can have malformed spans. This is a heavy handed
1770+
// Here we check if there are suggestions that have actual code changes. We sometimes
1771+
// suggest the same code that is already there, instead of changing how we produce the
1772+
// suggestions and filtering there, we just don't emit the suggestion.
1773+
// Suggestions coming from macros can also have malformed spans. This is a heavy handed
17711774
// approach to avoid ICEs by ignoring the suggestion outright.
17721775
return Ok(());
17731776
}
@@ -2046,7 +2049,9 @@ impl HumanEmitter {
20462049
assert!(underline_start >= 0 && underline_end >= 0);
20472050
let padding: usize = max_line_num_len + 3;
20482051
for p in underline_start..underline_end {
2049-
if let DisplaySuggestion::Underline = show_code_change {
2052+
if let DisplaySuggestion::Underline = show_code_change
2053+
&& is_different(sm, &part.snippet, part.span)
2054+
{
20502055
// If this is a replacement, underline with `~`, if this is an addition
20512056
// underline with `+`.
20522057
buffer.putc(
@@ -2824,6 +2829,18 @@ impl Style {
28242829
}
28252830
}
28262831

2832+
/// Whether the original and suggested code are the same.
2833+
pub fn is_different(sm: &SourceMap, suggested: &str, sp: Span) -> bool {
2834+
let found = match sm.span_to_snippet(sp) {
2835+
Ok(snippet) => snippet,
2836+
Err(e) => {
2837+
warn!(error = ?e, "Invalid span {:?}", sp);
2838+
return true;
2839+
}
2840+
};
2841+
found != suggested
2842+
}
2843+
28272844
/// Whether the original and suggested code are visually similar enough to warrant extra wording.
28282845
pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool {
28292846
// FIXME: this should probably be extended to also account for `FO0` → `FOO` and unicode.

compiler/rustc_errors/src/lib.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub use diagnostic_impls::{
5050
IndicateAnonymousLifetime, SingleLabelManySpans,
5151
};
5252
pub use emitter::ColorConfig;
53-
use emitter::{is_case_difference, DynEmitter, Emitter};
53+
use emitter::{is_case_difference, is_different, DynEmitter, Emitter};
5454
use registry::Registry;
5555
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
5656
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
@@ -357,10 +357,16 @@ impl CodeSuggestion {
357357
_ => 1,
358358
})
359359
.sum();
360-
line_highlight.push(SubstitutionHighlight {
361-
start: (cur_lo.col.0 as isize + acc) as usize,
362-
end: (cur_lo.col.0 as isize + acc + len) as usize,
363-
});
360+
if !is_different(sm, &part.snippet, part.span) {
361+
// Account for cases where we are suggesting the same code that's already
362+
// there. This shouldn't happen often, but in some cases for multipart
363+
// suggestions it's much easier to handle it here than in the origin.
364+
} else {
365+
line_highlight.push(SubstitutionHighlight {
366+
start: (cur_lo.col.0 as isize + acc) as usize,
367+
end: (cur_lo.col.0 as isize + acc + len) as usize,
368+
});
369+
}
364370
buf.push_str(&part.snippet);
365371
let cur_hi = sm.lookup_char_pos(part.span.hi());
366372
// Account for the difference between the width of the current code and the
@@ -392,7 +398,11 @@ impl CodeSuggestion {
392398
while buf.ends_with('\n') {
393399
buf.pop();
394400
}
395-
Some((buf, substitution.parts, highlights, only_capitalization))
401+
if highlights.iter().all(|parts| parts.is_empty()) {
402+
None
403+
} else {
404+
Some((buf, substitution.parts, highlights, only_capitalization))
405+
}
396406
})
397407
.collect()
398408
}

compiler/rustc_middle/src/mir/mod.rs

+42-6
Original file line numberDiff line numberDiff line change
@@ -383,23 +383,25 @@ pub struct Body<'tcx> {
383383

384384
/// Constants that are required to evaluate successfully for this MIR to be well-formed.
385385
/// We hold in this field all the constants we are not able to evaluate yet.
386+
/// `None` indicates that the list has not been computed yet.
386387
///
387388
/// This is soundness-critical, we make a guarantee that all consts syntactically mentioned in a
388389
/// function have successfully evaluated if the function ever gets executed at runtime.
389-
pub required_consts: Vec<ConstOperand<'tcx>>,
390+
pub required_consts: Option<Vec<ConstOperand<'tcx>>>,
390391

391392
/// Further items that were mentioned in this function and hence *may* become monomorphized,
392393
/// depending on optimizations. We use this to avoid optimization-dependent compile errors: the
393394
/// collector recursively traverses all "mentioned" items and evaluates all their
394395
/// `required_consts`.
396+
/// `None` indicates that the list has not been computed yet.
395397
///
396398
/// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee.
397399
/// All that's relevant is that this set is optimization-level-independent, and that it includes
398400
/// everything that the collector would consider "used". (For example, we currently compute this
399401
/// set after drop elaboration, so some drop calls that can never be reached are not considered
400402
/// "mentioned".) See the documentation of `CollectionMode` in
401403
/// `compiler/rustc_monomorphize/src/collector.rs` for more context.
402-
pub mentioned_items: Vec<Spanned<MentionedItem<'tcx>>>,
404+
pub mentioned_items: Option<Vec<Spanned<MentionedItem<'tcx>>>>,
403405

404406
/// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
405407
///
@@ -477,8 +479,8 @@ impl<'tcx> Body<'tcx> {
477479
spread_arg: None,
478480
var_debug_info,
479481
span,
480-
required_consts: Vec::new(),
481-
mentioned_items: Vec::new(),
482+
required_consts: None,
483+
mentioned_items: None,
482484
is_polymorphic: false,
483485
injection_phase: None,
484486
tainted_by_errors,
@@ -507,8 +509,8 @@ impl<'tcx> Body<'tcx> {
507509
arg_count: 0,
508510
spread_arg: None,
509511
span: DUMMY_SP,
510-
required_consts: Vec::new(),
511-
mentioned_items: Vec::new(),
512+
required_consts: None,
513+
mentioned_items: None,
512514
var_debug_info: Vec::new(),
513515
is_polymorphic: false,
514516
injection_phase: None,
@@ -785,6 +787,40 @@ impl<'tcx> Body<'tcx> {
785787
// No inlined `SourceScope`s, or all of them were `#[track_caller]`.
786788
caller_location.unwrap_or_else(|| from_span(source_info.span))
787789
}
790+
791+
#[track_caller]
792+
pub fn set_required_consts(&mut self, required_consts: Vec<ConstOperand<'tcx>>) {
793+
assert!(
794+
self.required_consts.is_none(),
795+
"required_consts for {:?} have already been set",
796+
self.source.def_id()
797+
);
798+
self.required_consts = Some(required_consts);
799+
}
800+
#[track_caller]
801+
pub fn required_consts(&self) -> &[ConstOperand<'tcx>] {
802+
match &self.required_consts {
803+
Some(l) => l,
804+
None => panic!("required_consts for {:?} have not yet been set", self.source.def_id()),
805+
}
806+
}
807+
808+
#[track_caller]
809+
pub fn set_mentioned_items(&mut self, mentioned_items: Vec<Spanned<MentionedItem<'tcx>>>) {
810+
assert!(
811+
self.mentioned_items.is_none(),
812+
"mentioned_items for {:?} have already been set",
813+
self.source.def_id()
814+
);
815+
self.mentioned_items = Some(mentioned_items);
816+
}
817+
#[track_caller]
818+
pub fn mentioned_items(&self) -> &[Spanned<MentionedItem<'tcx>>] {
819+
match &self.mentioned_items {
820+
Some(l) => l,
821+
None => panic!("mentioned_items for {:?} have not yet been set", self.source.def_id()),
822+
}
823+
}
788824
}
789825

790826
impl<'tcx> Index<BasicBlock> for Body<'tcx> {

compiler/rustc_middle/src/mir/visit.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1066,9 +1066,11 @@ macro_rules! super_body {
10661066

10671067
$self.visit_span($(& $mutability)? $body.span);
10681068

1069-
for const_ in &$($mutability)? $body.required_consts {
1070-
let location = Location::START;
1071-
$self.visit_const_operand(const_, location);
1069+
if let Some(required_consts) = &$($mutability)? $body.required_consts {
1070+
for const_ in required_consts {
1071+
let location = Location::START;
1072+
$self.visit_const_operand(const_, location);
1073+
}
10721074
}
10731075
}
10741076
}

0 commit comments

Comments
 (0)