Skip to content

Commit 70f9d23

Browse files
committed
Auto merge of #74117 - Manishearth:rollup-ds7z0kx, r=Manishearth
Rollup of 14 pull requests Successful merges: - #70563 ([rustdoc] Page hash handling) - #73856 (Edit librustc_lexer top-level docs) - #73870 (typeck: adding type information to projection) - #73953 (Audit hidden/short code suggestions) - #73962 (libstd/net/tcp.rs: #![deny(unsafe_op_in_unsafe_fn)]) - #73969 (mir: mark mir construction temporaries as internal) - #73974 (Move A|Rc::as_ptr from feature(weak_into_raw) to feature(rc_as_ptr)) - #74067 (rustdoc: Restore underline text decoration on hover for FQN in header) - #74074 (Fix the return type of Windows' `OpenOptionsExt::security_qos_flags`.) - #74078 (Always resolve type@primitive as a primitive, not a module) - #74089 (Add rust-analyzer to the build manifest) - #74090 (Remove unused RUSTC_DEBUG_ASSERTIONS) - #74102 (Fix const prop ICE) - #74112 (Expand abbreviation in core::ffi description) Failed merges: r? @ghost
2 parents 8981dbb + 73f2069 commit 70f9d23

File tree

193 files changed

+2048
-542
lines changed

Some content is hidden

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

193 files changed

+2048
-542
lines changed

src/bootstrap/bin/rustdoc.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ fn main() {
1313
let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");
1414
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
1515
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
16-
let mut has_unstable = false;
1716

1817
use std::str::FromStr;
1918

@@ -55,22 +54,10 @@ fn main() {
5554
cmd.arg("--crate-version").arg(version);
5655
}
5756

58-
// Needed to be able to run all rustdoc tests.
59-
if env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES").is_some() {
60-
// This "unstable-options" can be removed when `--generate-redirect-pages` is stabilized
61-
if !has_unstable {
62-
cmd.arg("-Z").arg("unstable-options");
63-
}
64-
cmd.arg("--generate-redirect-pages");
65-
has_unstable = true;
66-
}
67-
6857
// Needed to be able to run all rustdoc tests.
6958
if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") {
7059
// This "unstable-options" can be removed when `--resource-suffix` is stabilized
71-
if !has_unstable {
72-
cmd.arg("-Z").arg("unstable-options");
73-
}
60+
cmd.arg("-Z").arg("unstable-options");
7461
cmd.arg("--resource-suffix").arg(x);
7562
}
7663

src/bootstrap/doc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ impl Step for Std {
451451
.arg("--markdown-css")
452452
.arg("rust.css")
453453
.arg("--markdown-no-toc")
454-
.arg("--generate-redirect-pages")
455454
.arg("-Z")
456455
.arg("unstable-options")
457456
.arg("--resource-suffix")

src/bootstrap/test.rs

-2
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,6 @@ impl Step for Miri {
397397
cargo.env("MIRI", &miri);
398398
// Debug things.
399399
cargo.env("RUST_BACKTRACE", "1");
400-
// Overwrite bootstrap's `rustc` wrapper overwriting our flags.
401-
cargo.env("RUSTC_DEBUG_ASSERTIONS", "true");
402400
// Let cargo-miri know where xargo ended up.
403401
cargo.env("XARGO_CHECK", builder.out.join("bin").join("xargo-check"));
404402

src/liballoc/rc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,7 @@ impl<T> Weak<T> {
17011701
/// ```
17021702
///
17031703
/// [`null`]: ../../std/ptr/fn.null.html
1704-
#[stable(feature = "weak_into_raw", since = "1.45.0")]
1704+
#[stable(feature = "rc_as_ptr", since = "1.45.0")]
17051705
pub fn as_ptr(&self) -> *const T {
17061706
let ptr: *mut RcBox<T> = NonNull::as_ptr(self.ptr);
17071707

src/liballoc/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ impl<T: ?Sized> Arc<T> {
587587
/// assert_eq!(x_ptr, Arc::as_ptr(&y));
588588
/// assert_eq!(unsafe { &*x_ptr }, "hello");
589589
/// ```
590-
#[stable(feature = "weak_into_raw", since = "1.45.0")]
590+
#[stable(feature = "rc_as_ptr", since = "1.45.0")]
591591
pub fn as_ptr(this: &Self) -> *const T {
592592
let ptr: *mut ArcInner<T> = NonNull::as_ptr(this.ptr);
593593

src/libcore/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![stable(feature = "", since = "1.30.0")]
22
#![allow(non_camel_case_types)]
33

4-
//! Utilities related to FFI bindings.
4+
//! Utilities related to foreign function interface (FFI) bindings.
55
66
use crate::fmt;
77
use crate::marker::PhantomData;

src/librustc_builtin_macros/format.rs

+2
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ impl<'a, 'b> Context<'a, 'b> {
280280
("x", "LowerHex"),
281281
("X", "UpperHex"),
282282
] {
283+
// FIXME: rustfix (`run-rustfix`) fails to apply suggestions.
284+
// > "Cannot replace slice of data that was already replaced"
283285
err.tool_only_span_suggestion(
284286
sp,
285287
&format!("use the `{}` trait", name),

src/librustc_lexer/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
//! produces simple tokens which are a pair of type-tag and a bit of original text,
77
//! and does not report errors, instead storing them as flags on the token.
88
//!
9-
//! Tokens produced by this lexer are not yet ready for parsing the Rust syntax,
10-
//! for that see `librustc_parse::lexer`, which converts this basic token stream
9+
//! Tokens produced by this lexer are not yet ready for parsing the Rust syntax.
10+
//! For that see [`librustc_parse::lexer`], which converts this basic token stream
1111
//! into wide tokens used by actual parser.
1212
//!
1313
//! The purpose of this crate is to convert raw sources into a labeled sequence
1414
//! of well-known token types, so building an actual Rust token stream will
1515
//! be easier.
1616
//!
17-
//! Main entity of this crate is [`TokenKind`] enum which represents common
17+
//! The main entity of this crate is the [`TokenKind`] enum which represents common
1818
//! lexeme types.
19-
19+
//!
20+
//! [`librustc_parse::lexer`]: ../rustc_parse/lexer/index.html
2021
// We want to be able to build this crate with a stable compiler, so no
2122
// `#![feature]` attributes should be added.
2223

src/librustc_mir/transform/const_prop.rs

+21-19
Original file line numberDiff line numberDiff line change
@@ -1004,14 +1004,6 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
10041004
let expected = ScalarMaybeUninit::from(Scalar::from_bool(*expected));
10051005
let value_const = self.ecx.read_scalar(value).unwrap();
10061006
if expected != value_const {
1007-
// Poison all places this operand references so that further code
1008-
// doesn't use the invalid value
1009-
match cond {
1010-
Operand::Move(ref place) | Operand::Copy(ref place) => {
1011-
Self::remove_const(&mut self.ecx, place.local);
1012-
}
1013-
Operand::Constant(_) => {}
1014-
}
10151007
let mut eval_to_int = |op| {
10161008
let op = self
10171009
.eval_operand(op, source_info)
@@ -1020,27 +1012,37 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
10201012
};
10211013
let msg = match msg {
10221014
AssertKind::DivisionByZero(op) => {
1023-
AssertKind::DivisionByZero(eval_to_int(op))
1015+
Some(AssertKind::DivisionByZero(eval_to_int(op)))
10241016
}
10251017
AssertKind::RemainderByZero(op) => {
1026-
AssertKind::RemainderByZero(eval_to_int(op))
1018+
Some(AssertKind::RemainderByZero(eval_to_int(op)))
10271019
}
10281020
AssertKind::BoundsCheck { ref len, ref index } => {
10291021
let len = eval_to_int(len);
10301022
let index = eval_to_int(index);
1031-
AssertKind::BoundsCheck { len, index }
1023+
Some(AssertKind::BoundsCheck { len, index })
10321024
}
10331025
// Overflow is are already covered by checks on the binary operators.
1034-
AssertKind::Overflow(..) | AssertKind::OverflowNeg(_) => return,
1026+
AssertKind::Overflow(..) | AssertKind::OverflowNeg(_) => None,
10351027
// Need proper const propagator for these.
1036-
_ => return,
1028+
_ => None,
10371029
};
1038-
self.report_assert_as_lint(
1039-
lint::builtin::UNCONDITIONAL_PANIC,
1040-
source_info,
1041-
"this operation will panic at runtime",
1042-
msg,
1043-
);
1030+
// Poison all places this operand references so that further code
1031+
// doesn't use the invalid value
1032+
match cond {
1033+
Operand::Move(ref place) | Operand::Copy(ref place) => {
1034+
Self::remove_const(&mut self.ecx, place.local);
1035+
}
1036+
Operand::Constant(_) => {}
1037+
}
1038+
if let Some(msg) = msg {
1039+
self.report_assert_as_lint(
1040+
lint::builtin::UNCONDITIONAL_PANIC,
1041+
source_info,
1042+
"this operation will panic at runtime",
1043+
msg,
1044+
);
1045+
}
10441046
} else {
10451047
if self.should_const_prop(value) {
10461048
if let ScalarMaybeUninit::Scalar(scalar) = value_const {

src/librustc_mir_build/build/misc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1515
/// N.B., **No cleanup is scheduled for this temporary.** You should
1616
/// call `schedule_drop` once the temporary is initialized.
1717
crate fn temp(&mut self, ty: Ty<'tcx>, span: Span) -> Place<'tcx> {
18-
let temp = self.local_decls.push(LocalDecl::new(ty, span));
18+
// Mark this local as internal to avoid temporaries with types not present in the
19+
// user's code resulting in ICEs from the generator transform.
20+
let temp = self.local_decls.push(LocalDecl::new(ty, span).internal());
1921
let place = Place::from(temp);
2022
debug!("temp: created temp {:?} with type {:?}", place, self.local_decls[temp].ty);
2123
place

src/librustc_parse/parser/diagnostics.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1228,10 +1228,13 @@ impl<'a> Parser<'a> {
12281228
if let Some(sp) = unmatched.unclosed_span {
12291229
err.span_label(sp, "unclosed delimiter");
12301230
}
1231+
// Backticks should be removed to apply suggestions.
1232+
let mut delim = delim.to_string();
1233+
delim.retain(|c| c != '`');
12311234
err.span_suggestion_short(
12321235
self.prev_token.span.shrink_to_hi(),
1233-
&format!("{} may belong here", delim.to_string()),
1234-
delim.to_string(),
1236+
&format!("`{}` may belong here", delim),
1237+
delim,
12351238
Applicability::MaybeIncorrect,
12361239
);
12371240
if unmatched.found_delim.is_none() {

src/librustc_parse/parser/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ impl<'a> Parser<'a> {
699699
// misses a separator.
700700
expect_err
701701
.span_suggestion_short(
702-
sp,
702+
self.sess.source_map().next_point(sp),
703703
&format!("missing `{}`", token_str),
704704
token_str,
705705
Applicability::MaybeIncorrect,

src/librustc_typeck/check/regionck.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
488488
) {
489489
if let mc::PlaceBase::Rvalue = place_with_id.place.base {
490490
if place_with_id.place.projections.is_empty() {
491-
let typ = self.resolve_type(place_with_id.place.ty);
491+
let typ = self.resolve_type(place_with_id.place.ty());
492492
let body_id = self.body_id;
493493
let _ = dropck::check_drop_obligations(self, typ, span, body_id);
494494
}
@@ -640,8 +640,8 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
640640
borrow_kind: ty::BorrowKind,
641641
borrow_place: &mc::PlaceWithHirId<'tcx>,
642642
) {
643-
let origin = infer::DataBorrowed(borrow_place.place.ty, span);
644-
self.type_must_outlive(origin, borrow_place.place.ty, borrow_region);
643+
let origin = infer::DataBorrowed(borrow_place.place.ty(), span);
644+
self.type_must_outlive(origin, borrow_place.place.ty(), borrow_region);
645645

646646
for pointer_ty in borrow_place.place.deref_tys() {
647647
debug!(

src/librustc_typeck/expr_use_visitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
384384

385385
// Select just those fields of the `with`
386386
// expression that will actually be used
387-
match with_place.place.ty.kind {
387+
match with_place.place.ty().kind {
388388
ty::Adt(adt, substs) if adt.is_struct() => {
389389
// Consume those fields of the with expression that are needed.
390390
for (f_index, with_field) in adt.non_enum_variant().fields.iter().enumerate() {
@@ -583,7 +583,7 @@ fn copy_or_move<'a, 'tcx>(
583583
place_with_id: &PlaceWithHirId<'tcx>,
584584
) -> ConsumeMode {
585585
if !mc.type_is_copy_modulo_regions(
586-
place_with_id.place.ty,
586+
place_with_id.place.ty(),
587587
mc.tcx().hir().span(place_with_id.hir_id),
588588
) {
589589
Move

src/librustc_typeck/mem_categorization.rs

+48-19
Original file line numberDiff line numberDiff line change
@@ -73,27 +73,30 @@ pub enum PlaceBase {
7373
Upvar(ty::UpvarId),
7474
}
7575

76-
#[derive(Clone, Debug)]
77-
pub enum ProjectionKind<'tcx> {
76+
#[derive(Clone, Debug, Eq, PartialEq)]
77+
pub enum ProjectionKind {
7878
/// A dereference of a pointer, reference or `Box<T>` of the given type
79-
Deref(Ty<'tcx>),
79+
Deref,
8080
/// An index or a field
8181
Other,
8282
}
8383

8484
#[derive(Clone, Debug)]
8585
pub struct Projection<'tcx> {
86+
// Type after the projection is being applied.
87+
ty: Ty<'tcx>,
88+
8689
/// Defines the type of access
87-
kind: ProjectionKind<'tcx>,
90+
kind: ProjectionKind,
8891
}
8992

9093
/// A `Place` represents how a value is located in memory.
9194
///
9295
/// This is an HIR version of `mir::Place`
9396
#[derive(Clone, Debug)]
9497
pub struct Place<'tcx> {
95-
/// The type of the `Place`
96-
pub ty: Ty<'tcx>,
98+
/// The type of the `PlaceBase`
99+
pub base_ty: Ty<'tcx>,
97100
/// The "outermost" place that holds this value.
98101
pub base: PlaceBase,
99102
/// How this place is derived from the base place.
@@ -115,13 +118,13 @@ pub struct PlaceWithHirId<'tcx> {
115118
impl<'tcx> PlaceWithHirId<'tcx> {
116119
crate fn new(
117120
hir_id: hir::HirId,
118-
ty: Ty<'tcx>,
121+
base_ty: Ty<'tcx>,
119122
base: PlaceBase,
120123
projections: Vec<Projection<'tcx>>,
121124
) -> PlaceWithHirId<'tcx> {
122125
PlaceWithHirId {
123126
hir_id: hir_id,
124-
place: Place { ty: ty, base: base, projections: projections },
127+
place: Place { base_ty: base_ty, base: base, projections: projections },
125128
}
126129
}
127130
}
@@ -134,10 +137,26 @@ impl<'tcx> Place<'tcx> {
134137
/// `x: &*const u32` and the `Place` is `**x`, then the types returned are
135138
///`*const u32` then `&*const u32`.
136139
crate fn deref_tys(&self) -> impl Iterator<Item = Ty<'tcx>> + '_ {
137-
self.projections.iter().rev().filter_map(|proj| {
138-
if let ProjectionKind::Deref(deref_ty) = proj.kind { Some(deref_ty) } else { None }
140+
self.projections.iter().enumerate().rev().filter_map(move |(index, proj)| {
141+
if ProjectionKind::Deref == proj.kind {
142+
Some(self.ty_before_projection(index))
143+
} else {
144+
None
145+
}
139146
})
140147
}
148+
149+
// Returns the type of this `Place` after all projections have been applied.
150+
pub fn ty(&self) -> Ty<'tcx> {
151+
self.projections.last().map_or_else(|| self.base_ty, |proj| proj.ty)
152+
}
153+
154+
// Returns the type of this `Place` immediately before `projection_index`th projection
155+
// is applied.
156+
crate fn ty_before_projection(&self, projection_index: usize) -> Ty<'tcx> {
157+
assert!(projection_index < self.projections.len());
158+
if projection_index == 0 { self.base_ty } else { self.projections[projection_index - 1].ty }
159+
}
141160
}
142161

143162
crate trait HirNode {
@@ -516,8 +535,13 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
516535
ty: Ty<'tcx>,
517536
) -> PlaceWithHirId<'tcx> {
518537
let mut projections = base_place.place.projections;
519-
projections.push(Projection { kind: ProjectionKind::Other });
520-
let ret = PlaceWithHirId::new(node.hir_id(), ty, base_place.place.base, projections);
538+
projections.push(Projection { kind: ProjectionKind::Other, ty: ty });
539+
let ret = PlaceWithHirId::new(
540+
node.hir_id(),
541+
base_place.place.base_ty,
542+
base_place.place.base,
543+
projections,
544+
);
521545
debug!("cat_field ret {:?}", ret);
522546
ret
523547
}
@@ -552,18 +576,23 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
552576
) -> McResult<PlaceWithHirId<'tcx>> {
553577
debug!("cat_deref: base_place={:?}", base_place);
554578

555-
let base_ty = base_place.place.ty;
556-
let deref_ty = match base_ty.builtin_deref(true) {
579+
let base_curr_ty = base_place.place.ty();
580+
let deref_ty = match base_curr_ty.builtin_deref(true) {
557581
Some(mt) => mt.ty,
558582
None => {
559-
debug!("explicit deref of non-derefable type: {:?}", base_ty);
583+
debug!("explicit deref of non-derefable type: {:?}", base_curr_ty);
560584
return Err(());
561585
}
562586
};
563587
let mut projections = base_place.place.projections;
564-
projections.push(Projection { kind: ProjectionKind::Deref(base_ty) });
565-
566-
let ret = PlaceWithHirId::new(node.hir_id(), deref_ty, base_place.place.base, projections);
588+
projections.push(Projection { kind: ProjectionKind::Deref, ty: deref_ty });
589+
590+
let ret = PlaceWithHirId::new(
591+
node.hir_id(),
592+
base_place.place.base_ty,
593+
base_place.place.base,
594+
projections,
595+
);
567596
debug!("cat_deref ret {:?}", ret);
568597
Ok(ret)
569598
}
@@ -687,7 +716,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
687716
}
688717

689718
PatKind::Slice(before, ref slice, after) => {
690-
let element_ty = match place_with_id.place.ty.builtin_index() {
719+
let element_ty = match place_with_id.place.ty().builtin_index() {
691720
Some(ty) => ty,
692721
None => {
693722
debug!("explicit index of non-indexable type {:?}", place_with_id);

0 commit comments

Comments
 (0)