Skip to content

Rollup of 10 pull requests #76771

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

Merged
merged 30 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
73e27b3
deny(unsafe_op_in_unsafe_fn) in libstd/process.rs
hellow554 Jul 2, 2020
a746870
Use translated variable for test string
pickfire Aug 24, 2020
ea5dc09
Make some Ordering methods const
Sep 1, 2020
79d563c
Move const tests for `Ordering` to `library\core`
CDirkx Sep 3, 2020
b54386a
Detect overflow in proc_macro_server subspan
tmiasko Aug 4, 2020
d98bac4
Add tests for overflow in Vec::drain
tmiasko Aug 4, 2020
f8cfb2f
Add tests for overflow in String / VecDeque operations using ranges
tmiasko Sep 4, 2020
d18b4bb
Note when a a move/borrow error is caused by a deref coercion
Aaron1011 Jul 25, 2020
e4c28bf
Upgrade to pulldown-cmark 0.8.0
jyn514 Sep 14, 2020
f7983ca
Don't use `link.span` yet
jyn514 Sep 14, 2020
6f2e1c6
Use `.as_str()` instead of `CowStr::Borrowed`
jyn514 Sep 14, 2020
a4183f0
librustc_target: Initial support for riscv32gc_unknown_linux_gnu
alistair23 Jul 7, 2020
82bd5a3
librustc_target: Address comments
alistair23 Sep 15, 2020
0f1d25e
Test that bounds checks are elided for indexing after .[r]position()
erikdesjardins Aug 24, 2020
5a4098e
Consolidate byte-identical modules.
ehuss Aug 20, 2020
cfb955d
Consolidate wasi alloc with unix alloc.
ehuss Aug 20, 2020
25cca07
Consolidate wasi::process and unsupported::process
ehuss Aug 20, 2020
cbda154
doc: platform-support.md: Document port
alistair23 Sep 15, 2020
e968f86
doc: platform-support.md: Move to tier 3
alistair23 Sep 15, 2020
f95d7ba
Update cargo
ehuss Sep 15, 2020
4f0c245
Rollup merge of #73955 - hellow554:unsafe_process, r=Mark-Simulacrum
Dylan-DPC Sep 15, 2020
fb9bb2b
Rollup merge of #75146 - tmiasko:range-overflow, r=Mark-Simulacrum
Dylan-DPC Sep 15, 2020
fa4cfeb
Rollup merge of #75304 - Aaron1011:feature/diag-deref-move-out, r=est…
Dylan-DPC Sep 15, 2020
034af08
Rollup merge of #75749 - ehuss:consolidate-sys, r=alexcrichton
Dylan-DPC Sep 15, 2020
c910518
Rollup merge of #75882 - pickfire:patch-6, r=jyn514
Dylan-DPC Sep 15, 2020
056c7b0
Rollup merge of #75886 - erikdesjardins:index, r=nikic
Dylan-DPC Sep 15, 2020
db22898
Rollup merge of #76048 - alistair23:alistair/rv32-linux, r=Amanieu
Dylan-DPC Sep 15, 2020
69ac076
Rollup merge of #76198 - CDirkx:const-ordering, r=dtolnay
Dylan-DPC Sep 15, 2020
1fd22fc
Rollup merge of #76689 - jyn514:update-pulldown, r=GuillaumeGomez
Dylan-DPC Sep 15, 2020
2e1f012
Rollup merge of #76763 - ehuss:update-cargo, r=ehuss
Dylan-DPC Sep 15, 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
17 changes: 14 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ dependencies = [
"if_chain",
"itertools 0.9.0",
"lazy_static",
"pulldown-cmark",
"pulldown-cmark 0.7.2",
"quine-mc_cluskey",
"quote",
"regex-syntax",
Expand Down Expand Up @@ -1853,7 +1853,7 @@ dependencies = [
"log",
"memchr",
"open",
"pulldown-cmark",
"pulldown-cmark 0.7.2",
"regex",
"serde",
"serde_derive",
Expand Down Expand Up @@ -2511,6 +2511,17 @@ dependencies = [
"unicase",
]

[[package]]
name = "pulldown-cmark"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8"
dependencies = [
"bitflags",
"memchr",
"unicase",
]

[[package]]
name = "punycode"
version = "0.4.1"
Expand Down Expand Up @@ -4122,7 +4133,7 @@ dependencies = [
"expect-test",
"itertools 0.9.0",
"minifier",
"pulldown-cmark",
"pulldown-cmark 0.8.0",
"rustc-rayon",
"serde",
"serde_json",
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,12 @@ impl server::Literal for Rustc<'_> {

let start = match start {
Bound::Included(lo) => lo,
Bound::Excluded(lo) => lo + 1,
Bound::Excluded(lo) => lo.checked_add(1)?,
Bound::Unbounded => 0,
};

let end = match end {
Bound::Included(hi) => hi + 1,
Bound::Included(hi) => hi.checked_add(1)?,
Bound::Excluded(hi) => hi,
Bound::Unbounded => length,
};
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::lang_items::LangItem;
use rustc_macros::HashStable;
use rustc_span::Span;

#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, HashStable)]
pub enum PointerCast {
Expand Down Expand Up @@ -113,6 +114,9 @@ pub enum Adjust<'tcx> {
pub struct OverloadedDeref<'tcx> {
pub region: ty::Region<'tcx>,
pub mutbl: hir::Mutability,
/// The `Span` associated with the field access or method call
/// that triggered this overloaded deref.
pub span: Span,
}

impl<'tcx> OverloadedDeref<'tcx> {
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_middle/src/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,11 @@ impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::Adjust<'a> {
impl<'a, 'tcx> Lift<'tcx> for ty::adjustment::OverloadedDeref<'a> {
type Lifted = ty::adjustment::OverloadedDeref<'tcx>;
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
tcx.lift(&self.region)
.map(|region| ty::adjustment::OverloadedDeref { region, mutbl: self.mutbl })
tcx.lift(&self.region).map(|region| ty::adjustment::OverloadedDeref {
region,
mutbl: self.mutbl,
span: self.span,
})
}
}

Expand Down
27 changes: 23 additions & 4 deletions compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let span = use_spans.args_or_use();

let move_site_vec = self.get_moved_indexes(location, mpi);
debug!("report_use_of_moved_or_uninitialized: move_site_vec={:?}", move_site_vec);
debug!(
"report_use_of_moved_or_uninitialized: move_site_vec={:?} use_spans={:?}",
move_site_vec, use_spans
);
let move_out_indices: Vec<_> =
move_site_vec.iter().map(|move_site| move_site.moi).collect();

Expand Down Expand Up @@ -229,6 +232,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);
}
}
// Deref::deref takes &self, which cannot cause a move
FnSelfUseKind::DerefCoercion { .. } => unreachable!(),
}
} else {
err.span_label(
Expand Down Expand Up @@ -355,6 +360,20 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
self.note_type_does_not_implement_copy(&mut err, &note_msg, ty, span, partial_str);
}

if let UseSpans::FnSelfUse {
kind: FnSelfUseKind::DerefCoercion { deref_target, deref_target_ty },
..
} = use_spans
{
err.note(&format!(
"{} occurs due to deref coercion to `{}`",
desired_action.as_noun(),
deref_target_ty
));

err.span_note(deref_target, "deref defined here");
}

if let Some((_, mut old_err)) =
self.move_error_reported.insert(move_out_indices, (used_place, err))
{
Expand Down Expand Up @@ -945,7 +964,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
name: &str,
borrow: &BorrowData<'tcx>,
drop_span: Span,
borrow_spans: UseSpans,
borrow_spans: UseSpans<'tcx>,
explanation: BorrowExplanation,
) -> DiagnosticBuilder<'cx> {
debug!(
Expand Down Expand Up @@ -1146,7 +1165,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
location: Location,
borrow: &BorrowData<'tcx>,
drop_span: Span,
borrow_spans: UseSpans,
borrow_spans: UseSpans<'tcx>,
proper_span: Span,
explanation: BorrowExplanation,
) -> DiagnosticBuilder<'cx> {
Expand Down Expand Up @@ -1274,7 +1293,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

fn report_escaping_closure_capture(
&mut self,
use_span: UseSpans,
use_span: UseSpans<'tcx>,
var_span: Span,
fr_name: &RegionName,
category: ConstraintCategory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
fn later_use_kind(
&self,
borrow: &BorrowData<'tcx>,
use_spans: UseSpans,
use_spans: UseSpans<'tcx>,
location: Location,
) -> (LaterUseKind, Span) {
match use_spans {
Expand Down
73 changes: 57 additions & 16 deletions compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_middle::mir::{
PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
};
use rustc_middle::ty::print::Print;
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt};
use rustc_middle::ty::{self, DefIdTree, Instance, Ty, TyCtxt};
use rustc_span::{
hygiene::{DesugaringKind, ForLoopLoc},
symbol::sym,
Expand Down Expand Up @@ -538,7 +538,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

/// The span(s) associated to a use of a place.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub(super) enum UseSpans {
pub(super) enum UseSpans<'tcx> {
/// The access is caused by capturing a variable for a closure.
ClosureUse {
/// This is true if the captured variable was from a generator.
Expand All @@ -558,7 +558,7 @@ pub(super) enum UseSpans {
fn_call_span: Span,
/// The definition span of the method being called
fn_span: Span,
kind: FnSelfUseKind,
kind: FnSelfUseKind<'tcx>,
},
/// This access is caused by a `match` or `if let` pattern.
PatUse(Span),
Expand All @@ -567,31 +567,44 @@ pub(super) enum UseSpans {
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub(super) enum FnSelfUseKind {
pub(super) enum FnSelfUseKind<'tcx> {
/// A normal method call of the form `receiver.foo(a, b, c)`
Normal { self_arg: Ident, implicit_into_iter: bool },
/// A call to `FnOnce::call_once`, desugared from `my_closure(a, b, c)`
FnOnceCall,
/// A call to an operator trait, desuraged from operator syntax (e.g. `a << b`)
Operator { self_arg: Ident },
DerefCoercion {
/// The `Span` of the `Target` associated type
/// in the `Deref` impl we are using.
deref_target: Span,
/// The type `T::Deref` we are dereferencing to
deref_target_ty: Ty<'tcx>,
},
}

impl UseSpans {
impl UseSpans<'_> {
pub(super) fn args_or_use(self) -> Span {
match self {
UseSpans::ClosureUse { args_span: span, .. }
| UseSpans::PatUse(span)
| UseSpans::FnSelfUse { var_span: span, .. }
| UseSpans::OtherUse(span) => span,
UseSpans::FnSelfUse {
fn_call_span, kind: FnSelfUseKind::DerefCoercion { .. }, ..
} => fn_call_span,
UseSpans::FnSelfUse { var_span, .. } => var_span,
}
}

pub(super) fn var_or_use(self) -> Span {
match self {
UseSpans::ClosureUse { var_span: span, .. }
| UseSpans::PatUse(span)
| UseSpans::FnSelfUse { var_span: span, .. }
| UseSpans::OtherUse(span) => span,
UseSpans::FnSelfUse {
fn_call_span, kind: FnSelfUseKind::DerefCoercion { .. }, ..
} => fn_call_span,
UseSpans::FnSelfUse { var_span, .. } => var_span,
}
}

Expand Down Expand Up @@ -754,7 +767,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&self,
moved_place: PlaceRef<'tcx>, // Could also be an upvar.
location: Location,
) -> UseSpans {
) -> UseSpans<'tcx> {
use self::UseSpans::*;

let stmt = match self.body[location.block].statements.get(location.statement_index) {
Expand Down Expand Up @@ -809,36 +822,64 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
kind: TerminatorKind::Call { fn_span, from_hir_call, .. }, ..
}) = &self.body[location.block].terminator
{
let method_did = if let Some(method_did) =
let (method_did, method_substs) = if let Some(info) =
crate::util::find_self_call(self.infcx.tcx, &self.body, target_temp, location.block)
{
method_did
info
} else {
return normal_ret;
};

let tcx = self.infcx.tcx;

let parent = tcx.parent(method_did);
let is_fn_once = parent == tcx.lang_items().fn_once_trait();
let is_operator = !from_hir_call
&& parent.map_or(false, |p| tcx.lang_items().group(LangItemGroup::Op).contains(&p));
let is_deref = !from_hir_call && tcx.is_diagnostic_item(sym::deref_method, method_did);
let fn_call_span = *fn_span;

let self_arg = tcx.fn_arg_names(method_did)[0];

debug!(
"terminator = {:?} from_hir_call={:?}",
self.body[location.block].terminator, from_hir_call
);

// Check for a 'special' use of 'self' -
// an FnOnce call, an operator (e.g. `<<`), or a
// deref coercion.
let kind = if is_fn_once {
FnSelfUseKind::FnOnceCall
Some(FnSelfUseKind::FnOnceCall)
} else if is_operator {
FnSelfUseKind::Operator { self_arg }
Some(FnSelfUseKind::Operator { self_arg })
} else if is_deref {
let deref_target =
tcx.get_diagnostic_item(sym::deref_target).and_then(|deref_target| {
Instance::resolve(tcx, self.param_env, deref_target, method_substs)
.transpose()
});
if let Some(Ok(instance)) = deref_target {
let deref_target_ty = instance.ty(tcx, self.param_env);
Some(FnSelfUseKind::DerefCoercion {
deref_target: tcx.def_span(instance.def_id()),
deref_target_ty,
})
} else {
None
}
} else {
None
};

let kind = kind.unwrap_or_else(|| {
// This isn't a 'special' use of `self`
debug!("move_spans: method_did={:?}, fn_call_span={:?}", method_did, fn_call_span);
let implicit_into_iter = matches!(
fn_call_span.desugaring_kind(),
Some(DesugaringKind::ForLoop(ForLoopLoc::IntoIter))
);
FnSelfUseKind::Normal { self_arg, implicit_into_iter }
};
});

return FnSelfUse {
var_span: stmt.source_info.span,
Expand All @@ -859,7 +900,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// and its usage of the local assigned at `location`.
/// This is done by searching in statements succeeding `location`
/// and originating from `maybe_closure_span`.
pub(super) fn borrow_spans(&self, use_span: Span, location: Location) -> UseSpans {
pub(super) fn borrow_spans(&self, use_span: Span, location: Location) -> UseSpans<'tcx> {
use self::UseSpans::*;
debug!("borrow_spans: use_span={:?} location={:?}", use_span, location);

Expand Down Expand Up @@ -963,7 +1004,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

/// Helper to retrieve span(s) of given borrow from the current MIR
/// representation
pub(super) fn retrieve_borrow_spans(&self, borrow: &BorrowData<'_>) -> UseSpans {
pub(super) fn retrieve_borrow_spans(&self, borrow: &BorrowData<'_>) -> UseSpans<'tcx> {
let span = self.body.source_info(borrow.reserve_location).span;
self.borrow_spans(span, borrow.reserve_location)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum GroupedMoveError<'tcx> {
// Everything that isn't from pattern matching.
OtherIllegalMove {
original_path: Place<'tcx>,
use_spans: UseSpans,
use_spans: UseSpans<'tcx>,
kind: IllegalMoveOriginKind<'tcx>,
},
}
Expand Down Expand Up @@ -222,7 +222,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let (mut err, err_span) = {
let (span, use_spans, original_path, kind): (
Span,
Option<UseSpans>,
Option<UseSpans<'tcx>>,
Place<'tcx>,
&IllegalMoveOriginKind<'_>,
) = match error {
Expand Down Expand Up @@ -291,7 +291,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
move_place: Place<'tcx>,
deref_target_place: Place<'tcx>,
span: Span,
use_spans: Option<UseSpans>,
use_spans: Option<UseSpans<'tcx>>,
) -> DiagnosticBuilder<'a> {
// Inspect the type of the content behind the
// borrow to provide feedback about why this
Expand Down
Loading