Skip to content

Commit 1c02878

Browse files
committed
Auto merge of #91388 - JohnTitor:rollup-640o1e5, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #91243 (Don't treat unnormalized function arguments as well-formed) - #91250 (Refactor EmitterWriter::emit_suggestion_default ) - #91317 (tests: Ignore `test/debuginfo/rc_arc.rs` on windows-gnu) - #91323 (CTFE: support assert_zero_valid and assert_uninit_valid) - #91358 (Fix small typo) - #91360 (:arrow_up: rust-analyzer) - #91368 (Don't re-export `MirPass`) - #91383 (Add `drop_while` as doc alias to `Iterator::skip_while`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 90912e6 + 28176a4 commit 1c02878

22 files changed

+172
-100
lines changed

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
256256
debug!("build: input_or_output={:?}", ty);
257257
// We add implied bounds from both the unnormalized and normalized ty
258258
// See issue #87748
259-
let constraints_implied_1 = self.add_implied_bounds(ty);
260259
let TypeOpOutput { output: norm_ty, constraints: constraints1, .. } = self
261260
.param_env
262261
.and(type_op::normalize::Normalize::new(ty))
@@ -284,10 +283,9 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
284283
// }
285284
// ```
286285
// Both &Self::Bar and &() are WF
287-
let constraints_implied_2 =
288-
if ty != norm_ty { self.add_implied_bounds(norm_ty) } else { None };
286+
let constraints_implied = self.add_implied_bounds(norm_ty);
289287
normalized_inputs_and_output.push(norm_ty);
290-
constraints1.into_iter().chain(constraints_implied_1).chain(constraints_implied_2)
288+
constraints1.into_iter().chain(constraints_implied)
291289
})
292290
.collect();
293291

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
394394
sym::transmute => {
395395
self.copy_op_transmute(&args[0], dest)?;
396396
}
397-
sym::assert_inhabited => {
397+
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => {
398398
let ty = instance.substs.type_at(0);
399399
let layout = self.layout_of(ty)?;
400400

401+
// For *all* intrinsics we first check `is_uninhabited` to give a more specific
402+
// error message.
401403
if layout.abi.is_uninhabited() {
402404
// The run-time intrinsic panics just to get a good backtrace; here we abort
403405
// since there is no problem showing a backtrace even for aborts.
@@ -409,6 +411,28 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
409411
),
410412
)?;
411413
}
414+
if intrinsic_name == sym::assert_zero_valid
415+
&& !layout.might_permit_raw_init(self, /*zero:*/ true)
416+
{
417+
M::abort(
418+
self,
419+
format!(
420+
"aborted execution: attempted to zero-initialize type `{}`, which is invalid",
421+
ty
422+
),
423+
)?;
424+
}
425+
if intrinsic_name == sym::assert_uninit_valid
426+
&& !layout.might_permit_raw_init(self, /*zero:*/ false)
427+
{
428+
M::abort(
429+
self,
430+
format!(
431+
"aborted execution: attempted to leave type `{}` uninitialized, which is invalid",
432+
ty
433+
),
434+
)?;
435+
}
412436
}
413437
sym::simd_insert => {
414438
let index = u64::from(self.read_scalar(&args[1])?.to_u32()?);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
pub mod check_consts;
22
pub mod promote_consts;
33
pub mod validate;
4-
5-
pub use rustc_middle::mir::MirPass;

compiler/rustc_const_eval/src/transform/promote_consts.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use std::cell::Cell;
2727
use std::{cmp, iter, mem};
2828

2929
use crate::transform::check_consts::{qualifs, ConstCx};
30-
use crate::transform::MirPass;
3130

3231
/// A `MirPass` for promotion.
3332
///

compiler/rustc_const_eval/src/transform/validate.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
//! Validates the MIR to ensure that invariants are upheld.
22
3-
use super::MirPass;
43
use rustc_index::bit_set::BitSet;
54
use rustc_infer::infer::TyCtxtInferExt;
65
use rustc_middle::mir::interpret::Scalar;
76
use rustc_middle::mir::traversal;
87
use rustc_middle::mir::visit::{PlaceContext, Visitor};
98
use rustc_middle::mir::{
10-
AggregateKind, BasicBlock, Body, BorrowKind, Local, Location, MirPhase, Operand, PlaceElem,
11-
PlaceRef, ProjectionElem, Rvalue, SourceScope, Statement, StatementKind, Terminator,
9+
AggregateKind, BasicBlock, Body, BorrowKind, Local, Location, MirPass, MirPhase, Operand,
10+
PlaceElem, PlaceRef, ProjectionElem, Rvalue, SourceScope, Statement, StatementKind, Terminator,
1211
TerminatorKind, START_BLOCK,
1312
};
1413
use rustc_middle::ty::fold::BottomUpFolder;

compiler/rustc_errors/src/emitter.rs

+26-15
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub trait Emitter {
214214

215215
/// Formats the substitutions of the primary_span
216216
///
217-
/// The are a lot of conditions to this method, but in short:
217+
/// There are a lot of conditions to this method, but in short:
218218
///
219219
/// * If the current `Diagnostic` has only one visible `CodeSuggestion`,
220220
/// we format the `help` suggestion depending on the content of the
@@ -736,7 +736,9 @@ impl EmitterWriter {
736736

737737
let line_offset = buffer.num_lines();
738738

739-
let left = margin.left(source_string.len()); // Left trim
739+
// Left trim
740+
let left = margin.left(source_string.len());
741+
740742
// Account for unicode characters of width !=0 that were removed.
741743
let left = source_string
742744
.chars()
@@ -1623,18 +1625,27 @@ impl EmitterWriter {
16231625
suggestions.iter().take(MAX_SUGGESTIONS)
16241626
{
16251627
notice_capitalization |= only_capitalization;
1626-
// Only show underline if the suggestion spans a single line and doesn't cover the
1627-
// entirety of the code output. If you have multiple replacements in the same line
1628-
// of code, show the underline.
1629-
let show_underline = !(parts.len() == 1 && parts[0].snippet.trim() == complete.trim())
1630-
&& complete.lines().count() == 1;
16311628

16321629
let has_deletion = parts.iter().any(|p| p.is_deletion());
16331630
let is_multiline = complete.lines().count() > 1;
16341631

1635-
let show_diff = has_deletion && !is_multiline;
1632+
enum DisplaySuggestion {
1633+
Underline,
1634+
Diff,
1635+
None,
1636+
}
1637+
1638+
let show_code_change = if has_deletion && !is_multiline {
1639+
DisplaySuggestion::Diff
1640+
} else if (parts.len() != 1 || parts[0].snippet.trim() != complete.trim())
1641+
&& !is_multiline
1642+
{
1643+
DisplaySuggestion::Underline
1644+
} else {
1645+
DisplaySuggestion::None
1646+
};
16361647

1637-
if show_diff {
1648+
if let DisplaySuggestion::Diff = show_code_change {
16381649
row_num += 1;
16391650
}
16401651

@@ -1657,7 +1668,7 @@ impl EmitterWriter {
16571668
&self.maybe_anonymized(line_start + line_pos),
16581669
Style::LineNumber,
16591670
);
1660-
if show_diff {
1671+
if let DisplaySuggestion::Diff = show_code_change {
16611672
// Add the line number for both addition and removal to drive the point home.
16621673
//
16631674
// N - fn foo<A: T>(bar: A) {
@@ -1727,7 +1738,7 @@ impl EmitterWriter {
17271738
let mut offsets: Vec<(usize, isize)> = Vec::new();
17281739
// Only show an underline in the suggestions if the suggestion is not the
17291740
// entirety of the code being shown and the displayed code is not multiline.
1730-
if show_underline {
1741+
if let DisplaySuggestion::Diff | DisplaySuggestion::Underline = show_code_change {
17311742
draw_col_separator(&mut buffer, row_num, max_line_num_len + 1);
17321743
for part in parts {
17331744
let span_start_pos = sm.lookup_char_pos(part.span.lo()).col_display;
@@ -1755,7 +1766,7 @@ impl EmitterWriter {
17551766
assert!(underline_start >= 0 && underline_end >= 0);
17561767
let padding: usize = max_line_num_len + 3;
17571768
for p in underline_start..underline_end {
1758-
if !show_diff {
1769+
if let DisplaySuggestion::Underline = show_code_change {
17591770
// If this is a replacement, underline with `^`, if this is an addition
17601771
// underline with `+`.
17611772
buffer.putc(
@@ -1766,7 +1777,7 @@ impl EmitterWriter {
17661777
);
17671778
}
17681779
}
1769-
if show_diff {
1780+
if let DisplaySuggestion::Diff = show_code_change {
17701781
// Colorize removal with red in diff format.
17711782
buffer.set_style_range(
17721783
row_num - 2,
@@ -1797,7 +1808,7 @@ impl EmitterWriter {
17971808
// if we elided some lines, add an ellipsis
17981809
if lines.next().is_some() {
17991810
buffer.puts(row_num, max_line_num_len - 1, "...", Style::LineNumber);
1800-
} else if !show_underline {
1811+
} else if let DisplaySuggestion::None = show_code_change {
18011812
draw_col_separator_no_space(&mut buffer, row_num, max_line_num_len + 1);
18021813
row_num += 1;
18031814
}
@@ -2083,7 +2094,7 @@ const OUTPUT_REPLACEMENTS: &[(char, &str)] = &[
20832094
('\t', " "), // We do our own tab replacement
20842095
('\u{200D}', ""), // Replace ZWJ with nothing for consistent terminal output of grapheme clusters.
20852096
('\u{202A}', ""), // The following unicode text flow control characters are inconsistently
2086-
('\u{202B}', ""), // supported accross CLIs and can cause confusion due to the bytes on disk
2097+
('\u{202B}', ""), // supported across CLIs and can cause confusion due to the bytes on disk
20872098
('\u{202D}', ""), // not corresponding to the visible source code, so we replace them always.
20882099
('\u{202E}', ""),
20892100
('\u{2066}', ""),

compiler/rustc_mir_transform/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
2727
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
2828
use rustc_index::vec::IndexVec;
2929
use rustc_middle::mir::visit::Visitor as _;
30-
use rustc_middle::mir::{dump_mir, traversal, Body, ConstQualifs, MirPhase, Promoted};
30+
use rustc_middle::mir::{dump_mir, traversal, Body, ConstQualifs, MirPass, MirPhase, Promoted};
3131
use rustc_middle::ty::query::Providers;
3232
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
3333
use rustc_span::{Span, Symbol};
@@ -78,7 +78,6 @@ mod unreachable_prop;
7878
use rustc_const_eval::transform::check_consts;
7979
use rustc_const_eval::transform::promote_consts;
8080
use rustc_const_eval::transform::validate;
81-
pub use rustc_const_eval::transform::MirPass;
8281
use rustc_mir_dataflow::rustc_peek;
8382

8483
pub fn provide(providers: &mut Providers) {

compiler/rustc_typeck/src/check/compare_method.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,9 @@ fn compare_predicate_entailment<'tcx>(
264264
// First liberate late bound regions and subst placeholders
265265
let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, tcx.fn_sig(trait_m.def_id));
266266
let trait_sig = trait_sig.subst(tcx, trait_to_placeholder_substs);
267-
// Next, add all inputs and output as well-formed tys. Importantly,
268-
// we have to do this before normalization, since the normalized ty may
269-
// not contain the input parameters. See issue #87748.
270-
wf_tys.extend(trait_sig.inputs_and_output.iter());
271267
let trait_sig =
272268
inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, trait_sig);
273-
// Also add the resulting inputs and output as well-formed.
274-
// This probably isn't strictly necessary.
269+
// Add the resulting inputs and output as well-formed.
275270
wf_tys.extend(trait_sig.inputs_and_output.iter());
276271
let trait_fty = tcx.mk_fn_ptr(ty::Binder::dummy(trait_sig));
277272

compiler/rustc_typeck/src/check/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ fn typeck_with_fallback<'tcx>(
391391
let mut wf_tys = FxHashSet::default();
392392
// Compute the fty from point of view of inside the fn.
393393
let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);
394-
wf_tys.extend(fn_sig.inputs_and_output.iter());
395394
let fn_sig = inh.normalize_associated_types_in(
396395
body.value.span,
397396
body_id.hir_id,

compiler/rustc_typeck/src/check/wfcheck.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1334,11 +1334,6 @@ fn check_fn_or_method<'fcx, 'tcx>(
13341334
) {
13351335
let sig = fcx.tcx.liberate_late_bound_regions(def_id, sig);
13361336

1337-
// Unnormalized types in signature are WF too
1338-
implied_bounds.extend(sig.inputs());
1339-
// FIXME(#27579) return types should not be implied bounds
1340-
implied_bounds.insert(sig.output());
1341-
13421337
// Normalize the input and output types one at a time, using a different
13431338
// `WellFormedLoc` for each. We cannot call `normalize_associated_types`
13441339
// on the entire `FnSig`, since this would use the same `WellFormedLoc`

library/core/src/intrinsics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -860,12 +860,14 @@ extern "rust-intrinsic" {
860860
/// zero-initialization: This will statically either panic, or do nothing.
861861
///
862862
/// This intrinsic does not have a stable counterpart.
863+
#[rustc_const_unstable(feature = "const_assert_type2", issue = "none")]
863864
pub fn assert_zero_valid<T>();
864865

865866
/// A guard for unsafe functions that cannot ever be executed if `T` has invalid
866867
/// bit patterns: This will statically either panic, or do nothing.
867868
///
868869
/// This intrinsic does not have a stable counterpart.
870+
#[rustc_const_unstable(feature = "const_assert_type2", issue = "none")]
869871
pub fn assert_uninit_valid<T>();
870872

871873
/// Gets a reference to a static `Location` indicating where it was called.

library/core/src/iter/traits/iterator.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ pub trait Iterator {
10231023
/// assert_eq!(iter.next(), None);
10241024
/// ```
10251025
#[inline]
1026+
#[doc(alias = "drop_while")]
10261027
#[stable(feature = "rust1", since = "1.0.0")]
10271028
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
10281029
where

src/test/debuginfo/rc_arc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// pretty-printers are not loaded
1+
// ignore-windows-gnu: pretty-printers are not loaded
22
// compile-flags:-g
33

44
// min-gdb-version: 8.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// error-pattern: any use of this value will cause an error
2+
3+
#![feature(never_type)]
4+
#![feature(const_maybe_uninit_assume_init, const_assert_type2)]
5+
#![feature(core_intrinsics)]
6+
7+
use std::intrinsics;
8+
9+
#[allow(invalid_value)]
10+
fn main() {
11+
use std::mem::MaybeUninit;
12+
13+
const _BAD1: () = unsafe {
14+
MaybeUninit::<!>::uninit().assume_init();
15+
};
16+
const _BAD2: () = unsafe {
17+
intrinsics::assert_uninit_valid::<bool>();
18+
};
19+
const _BAD3: () = unsafe {
20+
intrinsics::assert_zero_valid::<&'static i32>();
21+
};
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error: any use of this value will cause an error
2+
--> $DIR/assert-type-intrinsics.rs:14:9
3+
|
4+
LL | / const _BAD1: () = unsafe {
5+
LL | | MaybeUninit::<!>::uninit().assume_init();
6+
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to instantiate uninhabited type `!`
7+
LL | | };
8+
| |______-
9+
|
10+
= note: `#[deny(const_err)]` on by default
11+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
12+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
13+
14+
error: any use of this value will cause an error
15+
--> $DIR/assert-type-intrinsics.rs:17:9
16+
|
17+
LL | / const _BAD2: () = unsafe {
18+
LL | | intrinsics::assert_uninit_valid::<bool>();
19+
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `bool` uninitialized, which is invalid
20+
LL | | };
21+
| |______-
22+
|
23+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
24+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
25+
26+
error: any use of this value will cause an error
27+
--> $DIR/assert-type-intrinsics.rs:20:9
28+
|
29+
LL | / const _BAD3: () = unsafe {
30+
LL | | intrinsics::assert_zero_valid::<&'static i32>();
31+
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to zero-initialize type `&i32`, which is invalid
32+
LL | | };
33+
| |______-
34+
|
35+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
36+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
37+
38+
error: aborting due to 3 previous errors
39+

src/test/ui/consts/assume-type-intrinsics.rs

-13
This file was deleted.

src/test/ui/consts/assume-type-intrinsics.stderr

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/implied-bounds-unnorm-associated-type.rs:14:5
3+
|
4+
LL | fn f<'a, 'b>(s: &'b str, _: <&'a &'b () as Trait>::Type) -> &'a str {
5+
| -- -- lifetime `'b` defined here
6+
| |
7+
| lifetime `'a` defined here
8+
LL | s
9+
| ^ returning this value requires that `'b` must outlive `'a`
10+
|
11+
= help: consider adding the following bound: `'b: 'a`
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)