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 6 pull requests #59801

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e721f5e
don't process `external_traits` when collecting intra-doc links
QuietMisdreavus Mar 6, 2019
49cde40
add test for spurious intra-doc link warning
QuietMisdreavus Mar 6, 2019
968ea1c
Mark variables captured by reference as mutable correctly
matthewjasper Apr 4, 2019
63080b3
remove lookup_char_pos_adj
matklad Apr 5, 2019
2f948ea
Limit dylib symbols
Zoxc Apr 6, 2019
cb51f87
miri engine: lazily allocate memory for locals on first write
RalfJung Apr 6, 2019
525c68c
make StorageLive lazy as well
RalfJung Apr 7, 2019
ae1f8ab
fix miri engine debug output for uninitialized locals
RalfJung Apr 7, 2019
a2d4e85
Uplift `get_def_path` from Clippy
flip1995 Apr 7, 2019
944ffbf
initialize unsized locals when copying to the for the first time
RalfJung Apr 7, 2019
b00fd57
implement by-value object safety
RalfJung Apr 7, 2019
5731945
Apply suggestions from code review
RalfJung Apr 8, 2019
4d79d39
avoid reading from ZST locals
RalfJung Apr 8, 2019
e0e0a90
Rollup merge of #58972 - QuietMisdreavus:intra-doc-link-imports, r=Gu…
Centril Apr 8, 2019
868aa7c
Rollup merge of #59708 - matthewjasper:double-closure-unused-mut, r=p…
Centril Apr 8, 2019
fec3c44
Rollup merge of #59735 - matklad:deadcode, r=sanxiyn
Centril Apr 8, 2019
81927ca
Rollup merge of #59752 - Zoxc:dylib-fix, r=michaelwoerister
Centril Apr 8, 2019
1f97d88
Rollup merge of #59779 - flip1995:uplift_get_def_path, r=Manishearth
Centril Apr 8, 2019
4564c89
Rollup merge of #59780 - RalfJung:miri-unsized, r=oli-obk
Centril Apr 8, 2019
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: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}

fn explain_span(self, heading: &str, span: Span) -> (String, Option<Span>) {
let lo = self.sess.source_map().lookup_char_pos_adj(span.lo());
let lo = self.sess.source_map().lookup_char_pos(span.lo());
(
format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize() + 1),
Some(span),
Expand Down
35 changes: 30 additions & 5 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,31 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
}

/// Check if a `DefId`'s path matches the given absolute type path usage.
///
/// # Examples
/// ```rust,ignore (no cx or def_id available)
/// if cx.match_def_path(def_id, &["core", "option", "Option"]) {
/// // The given `def_id` is that of an `Option` type
/// }
/// ```
// Uplifted from rust-lang/rust-clippy
pub fn match_path(&self, def_id: DefId, path: &[&str]) -> bool {
pub fn match_def_path(&self, def_id: DefId, path: &[&str]) -> bool {
let names = self.get_def_path(def_id);

names.len() == path.len() && names.into_iter().zip(path.iter()).all(|(a, &b)| *a == *b)
}

/// Gets the absolute path of `def_id` as a vector of `&str`.
///
/// # Examples
/// ```rust,ignore (no cx or def_id available)
/// let def_path = cx.get_def_path(def_id);
/// if let &["core", "option", "Option"] = &def_path[..] {
/// // The given `def_id` is that of an `Option` type
/// }
/// ```
// Uplifted from rust-lang/rust-clippy
pub fn get_def_path(&self, def_id: DefId) -> Vec<&'static str> {
pub struct AbsolutePathPrinter<'a, 'tcx> {
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
Expand Down Expand Up @@ -856,10 +879,12 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
}
}

let names = AbsolutePathPrinter { tcx: self.tcx }.print_def_path(def_id, &[]).unwrap();

names.len() == path.len()
&& names.into_iter().zip(path.iter()).all(|(a, &b)| *a == *b)
AbsolutePathPrinter { tcx: self.tcx }
.print_def_path(def_id, &[])
.unwrap()
.iter()
.map(LocalInternedString::get)
.collect()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn lint_ty_kind_usage(cx: &LateContext<'_, '_>, segment: &PathSegment) -> bool {
if segment.ident.as_str() == "TyKind" {
if let Some(def) = segment.def {
if let Some(did) = def.opt_def_id() {
return cx.match_path(did, &["rustc", "ty", "sty", "TyKind"]);
return cx.match_def_path(did, &["rustc", "ty", "sty", "TyKind"]);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
write!(f, "inside call to `{}`", self.instance)?;
}
if !self.call_site.is_dummy() {
let lo = tcx.sess.source_map().lookup_char_pos_adj(self.call_site.lo());
write!(f, " at {}:{}:{}", lo.filename, lo.line, lo.col.to_usize() + 1)?;
let lo = tcx.sess.source_map().lookup_char_pos(self.call_site.lo());
write!(f, " at {}:{}:{}", lo.file.name, lo.line, lo.col.to_usize() + 1)?;
}
Ok(())
})
Expand Down
14 changes: 5 additions & 9 deletions src/librustc_codegen_ssa/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,11 @@ impl<'a> Linker for GccLinker<'a> {
}

fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType) {
// If we're compiling a dylib, then we let symbol visibility in object
// files to take care of whether they're exported or not.
//
// If we're compiling a cdylib, however, we manually create a list of
// exported symbols to ensure we don't expose any more. The object files
// have far more public symbols than we actually want to export, so we
// hide them all here.
if crate_type == CrateType::Dylib ||
crate_type == CrateType::ProcMacro {
// We manually create a list of exported symbols to ensure we don't expose any more.
// The object files have far more public symbols than we actually want to export,
// so we hide them all here.

if crate_type == CrateType::ProcMacro {
return
}

Expand Down
96 changes: 76 additions & 20 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::rc::Rc;
use syntax_pos::{Span, DUMMY_SP};

use crate::dataflow::indexes::{BorrowIndex, InitIndex, MoveOutIndex, MovePathIndex};
use crate::dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MoveError};
use crate::dataflow::move_paths::{HasMoveData, InitLocation, LookupResult, MoveData, MoveError};
use crate::dataflow::Borrows;
use crate::dataflow::DataflowResultsConsumer;
use crate::dataflow::FlowAtLocation;
Expand Down Expand Up @@ -1277,25 +1277,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
} = self.infcx.tcx.mir_borrowck(def_id);
debug!("{:?} used_mut_upvars={:?}", def_id, used_mut_upvars);
for field in used_mut_upvars {
// This relies on the current way that by-value
// captures of a closure are copied/moved directly
// when generating MIR.
match operands[field.index()] {
Operand::Move(Place::Base(PlaceBase::Local(local)))
| Operand::Copy(Place::Base(PlaceBase::Local(local))) => {
self.used_mut.insert(local);
}
Operand::Move(ref place @ Place::Projection(_))
| Operand::Copy(ref place @ Place::Projection(_)) => {
if let Some(field) = place.is_upvar_field_projection(
self.mir, &self.infcx.tcx) {
self.used_mut_upvars.push(field);
}
}
Operand::Move(Place::Base(PlaceBase::Static(..)))
| Operand::Copy(Place::Base(PlaceBase::Static(..)))
| Operand::Constant(..) => {}
}
self.propagate_closure_used_mut_upvar(&operands[field.index()]);
}
}
AggregateKind::Adt(..)
Expand All @@ -1310,6 +1292,80 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
}
}

fn propagate_closure_used_mut_upvar(&mut self, operand: &Operand<'tcx>) {
let propagate_closure_used_mut_place = |this: &mut Self, place: &Place<'tcx>| {
match *place {
Place::Projection { .. } => {
if let Some(field) = place.is_upvar_field_projection(
this.mir, &this.infcx.tcx) {
this.used_mut_upvars.push(field);
}
}
Place::Base(PlaceBase::Local(local)) => {
this.used_mut.insert(local);
}
Place::Base(PlaceBase::Static(_)) => {}
}
};

// This relies on the current way that by-value
// captures of a closure are copied/moved directly
// when generating MIR.
match *operand {
Operand::Move(Place::Base(PlaceBase::Local(local)))
| Operand::Copy(Place::Base(PlaceBase::Local(local)))
if self.mir.local_decls[local].is_user_variable.is_none() =>
{
if self.mir.local_decls[local].ty.is_mutable_pointer() {
// The variable will be marked as mutable by the borrow.
return;
}
// This is an edge case where we have a `move` closure
// inside a non-move closure, and the inner closure
// contains a mutation:
//
// let mut i = 0;
// || { move || { i += 1; }; };
//
// In this case our usual strategy of assuming that the
// variable will be captured by mutable reference is
// wrong, since `i` can be copied into the inner
// closure from a shared reference.
//
// As such we have to search for the local that this
// capture comes from and mark it as being used as mut.

let temp_mpi = self.move_data.rev_lookup.find_local(local);
let init = if let [init_index] = *self.move_data.init_path_map[temp_mpi] {
&self.move_data.inits[init_index]
} else {
bug!("temporary should be initialized exactly once")
};

let loc = match init.location {
InitLocation::Statement(stmt) => stmt,
_ => bug!("temporary initialized in arguments"),
};

let bbd = &self.mir[loc.block];
let stmt = &bbd.statements[loc.statement_index];
debug!("temporary assigned in: stmt={:?}", stmt);

if let StatementKind::Assign(_, box Rvalue::Ref(_, _, ref source)) = stmt.kind {
propagate_closure_used_mut_place(self, source);
} else {
bug!("closures should only capture user variables \
or references to user variables");
}
}
Operand::Move(ref place)
| Operand::Copy(ref place) => {
propagate_closure_used_mut_place(self, place);
}
Operand::Constant(..) => {}
}
}

fn consume_operand(
&mut self,
context: Context,
Expand Down
Loading