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 11 pull requests #74110

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7d7221c
typeck: adding type information to projection
Azhng Jun 24, 2020
8dc1e42
libstd/net/tcp.rs: #![deny(unsafe_op_in_unsafe_fn)]
ryr3 Jul 2, 2020
ec31b4e
Audit uses of `span_suggestion_short`
JohnTitor Jul 2, 2020
84282fd
Audit uses of `tool_only_span_suggestion`
JohnTitor Jul 2, 2020
1b747a0
mir: mark mir construction temporaries as internal
davidtwco Jul 2, 2020
7391bf8
Move A|Rc::as_ptr from feature(weak_into_raw)
CAD97 Jul 2, 2020
2f31426
rustdoc: Restore underline text decoration on hover for FQN in header
rye Jul 5, 2020
5fa19ad
Remove unused RUSTC_DEBUG_ASSERTIONS
tmiasko Jul 6, 2020
f226e6b
Add `read_exact_at` and `write_all_at` to WASI's `FileExt`
sunfishcode Jul 3, 2020
6196eaa
Fix the return type of Windows' `OpenOptionsExt::security_qos_flags`.
sunfishcode Jul 3, 2020
e46c187
Always resolve type@primitive as a primitive, not a module
jyn514 Jul 6, 2020
fdd39a3
Add rust-analyzer to the build manifest
matklad Jul 6, 2020
96a8f37
Rollup merge of #73870 - sexxi-goose:projection-ty, r=nikomatsakis
Manishearth Jul 6, 2020
a394dee
Rollup merge of #73953 - JohnTitor:audit-hidden-sugg, r=estebank
Manishearth Jul 6, 2020
ac069b2
Rollup merge of #73962 - ryr3:unsafe_tcp, r=LukasKalbertodt
Manishearth Jul 6, 2020
31690ac
Rollup merge of #73969 - davidtwco:issue-73914-checkedadd-temp-genera…
Manishearth Jul 6, 2020
bbf3efa
Rollup merge of #73974 - CAD97:rc-no-weak, r=dtolnay
Manishearth Jul 6, 2020
26935a4
Rollup merge of #74067 - rye:rustdoc-fqn-hover-underline, r=Guillaume…
Manishearth Jul 6, 2020
a16490e
Rollup merge of #74074 - sunfishcode:windows-openoptionsext-return-ty…
Manishearth Jul 6, 2020
53dee43
Rollup merge of #74076 - sunfishcode:wasi-fileext-newmethods, r=alexc…
Manishearth Jul 6, 2020
6819d56
Rollup merge of #74078 - jyn514:lut, r=Manishearth
Manishearth Jul 6, 2020
95f3c5d
Rollup merge of #74089 - matklad:ship-rust-analyzer-some-more, r=piet…
Manishearth Jul 6, 2020
0eba54f
Rollup merge of #74090 - tmiasko:rustc-debug-assertions, r=RalfJung
Manishearth Jul 6, 2020
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
2 changes: 0 additions & 2 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,6 @@ impl Step for Miri {
cargo.env("MIRI", &miri);
// Debug things.
cargo.env("RUST_BACKTRACE", "1");
// Overwrite bootstrap's `rustc` wrapper overwriting our flags.
cargo.env("RUSTC_DEBUG_ASSERTIONS", "true");
// Let cargo-miri know where xargo ended up.
cargo.env("XARGO_CHECK", builder.out.join("bin").join("xargo-check"));

Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ impl<T> Weak<T> {
/// ```
///
/// [`null`]: ../../std/ptr/fn.null.html
#[stable(feature = "weak_into_raw", since = "1.45.0")]
#[stable(feature = "rc_as_ptr", since = "1.45.0")]
pub fn as_ptr(&self) -> *const T {
let ptr: *mut RcBox<T> = NonNull::as_ptr(self.ptr);

Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ impl<T: ?Sized> Arc<T> {
/// assert_eq!(x_ptr, Arc::as_ptr(&y));
/// assert_eq!(unsafe { &*x_ptr }, "hello");
/// ```
#[stable(feature = "weak_into_raw", since = "1.45.0")]
#[stable(feature = "rc_as_ptr", since = "1.45.0")]
pub fn as_ptr(this: &Self) -> *const T {
let ptr: *mut ArcInner<T> = NonNull::as_ptr(this.ptr);

Expand Down
2 changes: 2 additions & 0 deletions src/librustc_builtin_macros/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ impl<'a, 'b> Context<'a, 'b> {
("x", "LowerHex"),
("X", "UpperHex"),
] {
// FIXME: rustfix (`run-rustfix`) fails to apply suggestions.
// > "Cannot replace slice of data that was already replaced"
err.tool_only_span_suggestion(
sp,
&format!("use the `{}` trait", name),
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_mir_build/build/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// N.B., **No cleanup is scheduled for this temporary.** You should
/// call `schedule_drop` once the temporary is initialized.
crate fn temp(&mut self, ty: Ty<'tcx>, span: Span) -> Place<'tcx> {
let temp = self.local_decls.push(LocalDecl::new(ty, span));
// Mark this local as internal to avoid temporaries with types not present in the
// user's code resulting in ICEs from the generator transform.
let temp = self.local_decls.push(LocalDecl::new(ty, span).internal());
let place = Place::from(temp);
debug!("temp: created temp {:?} with type {:?}", place, self.local_decls[temp].ty);
place
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_parse/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,10 +1228,13 @@ impl<'a> Parser<'a> {
if let Some(sp) = unmatched.unclosed_span {
err.span_label(sp, "unclosed delimiter");
}
// Backticks should be removed to apply suggestions.
let mut delim = delim.to_string();
delim.retain(|c| c != '`');
err.span_suggestion_short(
self.prev_token.span.shrink_to_hi(),
&format!("{} may belong here", delim.to_string()),
delim.to_string(),
&format!("`{}` may belong here", delim),
delim,
Applicability::MaybeIncorrect,
);
if unmatched.found_delim.is_none() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ impl<'a> Parser<'a> {
// misses a separator.
expect_err
.span_suggestion_short(
sp,
self.sess.source_map().next_point(sp),
&format!("missing `{}`", token_str),
token_str,
Applicability::MaybeIncorrect,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/regionck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
) {
if let mc::PlaceBase::Rvalue = place_with_id.place.base {
if place_with_id.place.projections.is_empty() {
let typ = self.resolve_type(place_with_id.place.ty);
let typ = self.resolve_type(place_with_id.place.ty());
let body_id = self.body_id;
let _ = dropck::check_drop_obligations(self, typ, span, body_id);
}
Expand Down Expand Up @@ -640,8 +640,8 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
borrow_kind: ty::BorrowKind,
borrow_place: &mc::PlaceWithHirId<'tcx>,
) {
let origin = infer::DataBorrowed(borrow_place.place.ty, span);
self.type_must_outlive(origin, borrow_place.place.ty, borrow_region);
let origin = infer::DataBorrowed(borrow_place.place.ty(), span);
self.type_must_outlive(origin, borrow_place.place.ty(), borrow_region);

for pointer_ty in borrow_place.place.deref_tys() {
debug!(
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {

// Select just those fields of the `with`
// expression that will actually be used
match with_place.place.ty.kind {
match with_place.place.ty().kind {
ty::Adt(adt, substs) if adt.is_struct() => {
// Consume those fields of the with expression that are needed.
for (f_index, with_field) in adt.non_enum_variant().fields.iter().enumerate() {
Expand Down Expand Up @@ -583,7 +583,7 @@ fn copy_or_move<'a, 'tcx>(
place_with_id: &PlaceWithHirId<'tcx>,
) -> ConsumeMode {
if !mc.type_is_copy_modulo_regions(
place_with_id.place.ty,
place_with_id.place.ty(),
mc.tcx().hir().span(place_with_id.hir_id),
) {
Move
Expand Down
67 changes: 48 additions & 19 deletions src/librustc_typeck/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,30 @@ pub enum PlaceBase {
Upvar(ty::UpvarId),
}

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

#[derive(Clone, Debug)]
pub struct Projection<'tcx> {
// Type after the projection is being applied.
ty: Ty<'tcx>,

/// Defines the type of access
kind: ProjectionKind<'tcx>,
kind: ProjectionKind,
}

/// A `Place` represents how a value is located in memory.
///
/// This is an HIR version of `mir::Place`
#[derive(Clone, Debug)]
pub struct Place<'tcx> {
/// The type of the `Place`
pub ty: Ty<'tcx>,
/// The type of the `PlaceBase`
pub base_ty: Ty<'tcx>,
/// The "outermost" place that holds this value.
pub base: PlaceBase,
/// How this place is derived from the base place.
Expand All @@ -115,13 +118,13 @@ pub struct PlaceWithHirId<'tcx> {
impl<'tcx> PlaceWithHirId<'tcx> {
crate fn new(
hir_id: hir::HirId,
ty: Ty<'tcx>,
base_ty: Ty<'tcx>,
base: PlaceBase,
projections: Vec<Projection<'tcx>>,
) -> PlaceWithHirId<'tcx> {
PlaceWithHirId {
hir_id: hir_id,
place: Place { ty: ty, base: base, projections: projections },
place: Place { base_ty: base_ty, base: base, projections: projections },
}
}
}
Expand All @@ -134,10 +137,26 @@ impl<'tcx> Place<'tcx> {
/// `x: &*const u32` and the `Place` is `**x`, then the types returned are
///`*const u32` then `&*const u32`.
crate fn deref_tys(&self) -> impl Iterator<Item = Ty<'tcx>> + '_ {
self.projections.iter().rev().filter_map(|proj| {
if let ProjectionKind::Deref(deref_ty) = proj.kind { Some(deref_ty) } else { None }
self.projections.iter().enumerate().rev().filter_map(move |(index, proj)| {
if ProjectionKind::Deref == proj.kind {
Some(self.ty_before_projection(index))
} else {
None
}
})
}

// Returns the type of this `Place` after all projections have been applied.
pub fn ty(&self) -> Ty<'tcx> {
self.projections.last().map_or_else(|| self.base_ty, |proj| proj.ty)
}

// Returns the type of this `Place` immediately before `projection_index`th projection
// is applied.
crate fn ty_before_projection(&self, projection_index: usize) -> Ty<'tcx> {
assert!(projection_index < self.projections.len());
if projection_index == 0 { self.base_ty } else { self.projections[projection_index - 1].ty }
}
}

crate trait HirNode {
Expand Down Expand Up @@ -516,8 +535,13 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
ty: Ty<'tcx>,
) -> PlaceWithHirId<'tcx> {
let mut projections = base_place.place.projections;
projections.push(Projection { kind: ProjectionKind::Other });
let ret = PlaceWithHirId::new(node.hir_id(), ty, base_place.place.base, projections);
projections.push(Projection { kind: ProjectionKind::Other, ty: ty });
let ret = PlaceWithHirId::new(
node.hir_id(),
base_place.place.base_ty,
base_place.place.base,
projections,
);
debug!("cat_field ret {:?}", ret);
ret
}
Expand Down Expand Up @@ -552,18 +576,23 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
) -> McResult<PlaceWithHirId<'tcx>> {
debug!("cat_deref: base_place={:?}", base_place);

let base_ty = base_place.place.ty;
let deref_ty = match base_ty.builtin_deref(true) {
let base_curr_ty = base_place.place.ty();
let deref_ty = match base_curr_ty.builtin_deref(true) {
Some(mt) => mt.ty,
None => {
debug!("explicit deref of non-derefable type: {:?}", base_ty);
debug!("explicit deref of non-derefable type: {:?}", base_curr_ty);
return Err(());
}
};
let mut projections = base_place.place.projections;
projections.push(Projection { kind: ProjectionKind::Deref(base_ty) });

let ret = PlaceWithHirId::new(node.hir_id(), deref_ty, base_place.place.base, projections);
projections.push(Projection { kind: ProjectionKind::Deref, ty: deref_ty });

let ret = PlaceWithHirId::new(
node.hir_id(),
base_place.place.base_ty,
base_place.place.base,
projections,
);
debug!("cat_deref ret {:?}", ret);
Ok(ret)
}
Expand Down Expand Up @@ -687,7 +716,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
}

PatKind::Slice(before, ref slice, after) => {
let element_ty = match place_with_id.place.ty.builtin_index() {
let element_ty = match place_with_id.place.ty().builtin_index() {
Some(ty) => ty,
None => {
debug!("explicit index of non-indexable type {:?}", place_with_id);
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ h1.fqn {
border-bottom: 1px dashed;
margin-top: 0;
}
h1.fqn > .in-band > a:hover {
text-decoration: underline;
}
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant) {
border-bottom: 1px solid;
}
Expand Down
33 changes: 28 additions & 5 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
fn resolve(
&self,
path_str: &str,
disambiguator: Option<&str>,
ns: Namespace,
current_item: &Option<String>,
parent_id: Option<hir::HirId>,
Expand Down Expand Up @@ -203,11 +204,22 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
}
return Ok((res, Some(path_str.to_owned())));
}
other => {
debug!(
"failed to resolve {} in namespace {:?} (got {:?})",
path_str, ns, other
);
Res::Def(DefKind::Mod, _) => {
// This resolved to a module, but if we were passed `type@`,
// we want primitive types to take precedence instead.
if disambiguator == Some("type") {
if let Some(prim) = is_primitive(path_str, ns) {
if extra_fragment.is_some() {
return Err(ErrorKind::AnchorFailure(
"primitive types cannot be followed by anchors",
));
}
return Ok((prim, Some(path_str.to_owned())));
}
}
return Ok((res, extra_fragment.clone()));
}
_ => {
return Ok((res, extra_fragment.clone()));
}
};
Expand Down Expand Up @@ -566,11 +578,13 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
let mut path_str;
let (res, fragment) = {
let mut kind = None;
let mut disambiguator = None;
path_str = if let Some(prefix) = ["struct@", "enum@", "type@", "trait@", "union@"]
.iter()
.find(|p| link.starts_with(**p))
{
kind = Some(TypeNS);
disambiguator = Some(&prefix[..prefix.len() - 1]);
link.trim_start_matches(prefix)
} else if let Some(prefix) = [
"const@",
Expand All @@ -586,18 +600,23 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
.find(|p| link.starts_with(**p))
{
kind = Some(ValueNS);
disambiguator = Some(&prefix[..prefix.len() - 1]);
link.trim_start_matches(prefix)
} else if link.ends_with("()") {
kind = Some(ValueNS);
disambiguator = Some("fn");
link.trim_end_matches("()")
} else if link.starts_with("macro@") {
kind = Some(MacroNS);
disambiguator = Some("macro");
link.trim_start_matches("macro@")
} else if link.starts_with("derive@") {
kind = Some(MacroNS);
disambiguator = Some("derive");
link.trim_start_matches("derive@")
} else if link.ends_with('!') {
kind = Some(MacroNS);
disambiguator = Some("macro");
link.trim_end_matches('!')
} else {
&link[..]
Expand Down Expand Up @@ -634,6 +653,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
Some(ns @ ValueNS) => {
match self.resolve(
path_str,
disambiguator,
ns,
&current_item,
base_node,
Expand All @@ -657,6 +677,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
Some(ns @ TypeNS) => {
match self.resolve(
path_str,
disambiguator,
ns,
&current_item,
base_node,
Expand All @@ -683,6 +704,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
.map(|res| (res, extra_fragment.clone())),
type_ns: match self.resolve(
path_str,
disambiguator,
TypeNS,
&current_item,
base_node,
Expand All @@ -697,6 +719,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
},
value_ns: match self.resolve(
path_str,
disambiguator,
ValueNS,
&current_item,
base_node,
Expand Down
7 changes: 5 additions & 2 deletions src/libstd/net/tcp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(unsafe_op_in_unsafe_fn)]
use crate::io::prelude::*;

use crate::fmt;
Expand Down Expand Up @@ -583,7 +584,8 @@ impl Read for TcpStream {

#[inline]
unsafe fn initializer(&self) -> Initializer {
Initializer::nop()
// SAFETY: Read is guaranteed to work on uninitialized memory
unsafe { Initializer::nop() }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -622,7 +624,8 @@ impl Read for &TcpStream {

#[inline]
unsafe fn initializer(&self) -> Initializer {
Initializer::nop()
// SAFETY: Read is guaranteed to work on uninitialized memory
unsafe { Initializer::nop() }
}
}
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
Loading