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

[beta] Process backports #51037

Merged
merged 11 commits into from
Jun 3, 2018
2 changes: 1 addition & 1 deletion src/doc/rustc/src/lints/listing/allowed-by-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ To fix it, do as the help message suggests:

```rust
#![feature(dyn_trait)]
#![deny(bare_trait_object)]
#![deny(bare_trait_objects)]

trait Trait { }

Expand Down
7 changes: 5 additions & 2 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2932,7 +2932,10 @@ impl<'a> LoweringContext<'a> {
fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
let kind = match e.node {
ExprKind::Box(ref inner) => hir::ExprBox(P(self.lower_expr(inner))),

ExprKind::ObsoleteInPlace(..) => {
self.sess.abort_if_errors();
span_bug!(e.span, "encountered ObsoleteInPlace expr during lowering");
}
ExprKind::Array(ref exprs) => {
hir::ExprArray(exprs.iter().map(|x| self.lower_expr(x)).collect())
}
Expand Down Expand Up @@ -4122,7 +4125,7 @@ impl<'a> LoweringContext<'a> {

fn maybe_lint_bare_trait(&self, span: Span, id: NodeId, is_global: bool) {
self.sess.buffer_lint_with_diagnostic(
builtin::BARE_TRAIT_OBJECT,
builtin::BARE_TRAIT_OBJECTS,
id,
span,
"trait objects without an explicit `dyn` are deprecated",
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ declare_lint! {
}

declare_lint! {
pub SINGLE_USE_LIFETIME,
pub SINGLE_USE_LIFETIMES,
Allow,
"detects single use lifetimes"
}
Expand All @@ -243,19 +243,19 @@ declare_lint! {
}

declare_lint! {
pub ELIDED_LIFETIME_IN_PATH,
pub ELIDED_LIFETIMES_IN_PATHS,
Allow,
"hidden lifetime parameters are deprecated, try `Foo<'_>`"
}

declare_lint! {
pub BARE_TRAIT_OBJECT,
pub BARE_TRAIT_OBJECTS,
Allow,
"suggest using `dyn Trait` for trait objects"
}

declare_lint! {
pub ABSOLUTE_PATH_STARTING_WITH_MODULE,
pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
Allow,
"fully qualified paths that start with a module name \
instead of `crate`, `self`, or an extern crate name"
Expand All @@ -268,7 +268,7 @@ declare_lint! {
}

declare_lint! {
pub UNSTABLE_NAME_COLLISION,
pub UNSTABLE_NAME_COLLISIONS,
Warn,
"detects name collision with an existing but unstable method"
}
Expand Down Expand Up @@ -317,12 +317,12 @@ impl LintPass for HardwiredLints {
DEPRECATED,
UNUSED_UNSAFE,
UNUSED_MUT,
SINGLE_USE_LIFETIME,
SINGLE_USE_LIFETIMES,
TYVAR_BEHIND_RAW_POINTER,
ELIDED_LIFETIME_IN_PATH,
BARE_TRAIT_OBJECT,
ABSOLUTE_PATH_STARTING_WITH_MODULE,
UNSTABLE_NAME_COLLISION,
ELIDED_LIFETIMES_IN_PATHS,
BARE_TRAIT_OBJECTS,
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
UNSTABLE_NAME_COLLISIONS,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
"this was previously accepted by the compiler but is being phased out; \
it will become a hard error";

let explanation = if lint_id == LintId::of(::lint::builtin::UNSTABLE_NAME_COLLISION) {
let explanation = if lint_id == LintId::of(::lint::builtin::UNSTABLE_NAME_COLLISIONS) {
"once this method is added to the standard library, \
the ambiguity may cause an error or change in behavior!"
.to_owned()
Expand Down
11 changes: 9 additions & 2 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,17 +837,24 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
/// established up front, e.g. via `determine_pat_move_mode` (see
/// also `walk_irrefutable_pat` for patterns that stand alone).
fn walk_pat(&mut self, cmt_discr: mc::cmt<'tcx>, pat: &hir::Pat, match_mode: MatchMode) {
debug!("walk_pat cmt_discr={:?} pat={:?}", cmt_discr, pat);
debug!("walk_pat(cmt_discr={:?}, pat={:?})", cmt_discr, pat);

let ExprUseVisitor { ref mc, ref mut delegate, param_env } = *self;
return_if_err!(mc.cat_pattern(cmt_discr.clone(), pat, |cmt_pat, pat| {
if let PatKind::Binding(_, canonical_id, ..) = pat.node {
debug!("binding cmt_pat={:?} pat={:?} match_mode={:?}", cmt_pat, pat, match_mode);
debug!(
"walk_pat: binding cmt_pat={:?} pat={:?} match_mode={:?}",
cmt_pat,
pat,
match_mode,
);
let bm = *mc.tables.pat_binding_modes().get(pat.hir_id)
.expect("missing binding mode");
debug!("walk_pat: pat.hir_id={:?} bm={:?}", pat.hir_id, bm);

// pat_ty: the type of the binding being produced.
let pat_ty = return_if_err!(mc.node_ty(pat.hir_id));
debug!("walk_pat: pat_ty={:?}", pat_ty);

// Each match binding is effectively an assignment to the
// binding being produced.
Expand Down
90 changes: 45 additions & 45 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub enum Categorization<'tcx> {
StaticItem,
Upvar(Upvar), // upvar referenced by closure env
Local(ast::NodeId), // local variable
Deref(cmt<'tcx>, PointerKind<'tcx>), // deref of a ptr
Deref(cmt<'tcx>, PointerKind<'tcx>), // deref of a ptr
Interior(cmt<'tcx>, InteriorKind), // something interior: field, tuple, etc
Downcast(cmt<'tcx>, DefId), // selects a particular enum variant (*1)

Expand All @@ -120,9 +120,6 @@ pub enum PointerKind<'tcx> {

/// `*T`
UnsafePtr(hir::Mutability),

/// Implicit deref of the `&T` that results from an overloaded index `[]`.
Implicit(ty::BorrowKind, ty::Region<'tcx>),
}

// We use the term "interior" to mean "something reachable from the
Expand Down Expand Up @@ -172,6 +169,7 @@ pub enum MutabilityCategory {
pub enum Note {
NoteClosureEnv(ty::UpvarId), // Deref through closure env
NoteUpvarRef(ty::UpvarId), // Deref through by-ref upvar
NoteIndex, // Deref as part of desugaring `x[]` into its two components
NoteNone // Nothing special
}

Expand Down Expand Up @@ -231,8 +229,7 @@ impl<'tcx> cmt_<'tcx> {

pub fn immutability_blame(&self) -> Option<ImmutabilityBlame<'tcx>> {
match self.cat {
Categorization::Deref(ref base_cmt, BorrowedPtr(ty::ImmBorrow, _)) |
Categorization::Deref(ref base_cmt, Implicit(ty::ImmBorrow, _)) => {
Categorization::Deref(ref base_cmt, BorrowedPtr(ty::ImmBorrow, _)) => {
// try to figure out where the immutable reference came from
match base_cmt.cat {
Categorization::Local(node_id) =>
Expand Down Expand Up @@ -328,7 +325,7 @@ impl MutabilityCategory {
Unique => {
base_mutbl.inherit()
}
BorrowedPtr(borrow_kind, _) | Implicit(borrow_kind, _) => {
BorrowedPtr(borrow_kind, _) => {
MutabilityCategory::from_borrow_kind(borrow_kind)
}
UnsafePtr(m) => {
Expand Down Expand Up @@ -617,7 +614,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
} else {
previous()?
});
self.cat_deref(expr, base, false)
self.cat_deref(expr, base, NoteNone)
}

adjustment::Adjust::NeverToAny |
Expand All @@ -640,10 +637,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
match expr.node {
hir::ExprUnary(hir::UnDeref, ref e_base) => {
if self.tables.is_method_call(expr) {
self.cat_overloaded_place(expr, e_base, false)
self.cat_overloaded_place(expr, e_base, NoteNone)
} else {
let base_cmt = Rc::new(self.cat_expr(&e_base)?);
self.cat_deref(expr, base_cmt, false)
self.cat_deref(expr, base_cmt, NoteNone)
}
}

Expand All @@ -664,7 +661,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
// The call to index() returns a `&T` value, which
// is an rvalue. That is what we will be
// dereferencing.
self.cat_overloaded_place(expr, base, true)
self.cat_overloaded_place(expr, base, NoteIndex)
} else {
let base_cmt = Rc::new(self.cat_expr(&base)?);
self.cat_index(expr, base_cmt, expr_ty, InteriorOffsetKind::Index)
Expand Down Expand Up @@ -998,12 +995,18 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
ret
}

fn cat_overloaded_place(&self,
expr: &hir::Expr,
base: &hir::Expr,
implicit: bool)
-> McResult<cmt_<'tcx>> {
debug!("cat_overloaded_place: implicit={}", implicit);
fn cat_overloaded_place(
&self,
expr: &hir::Expr,
base: &hir::Expr,
note: Note,
) -> McResult<cmt_<'tcx>> {
debug!(
"cat_overloaded_place(expr={:?}, base={:?}, note={:?})",
expr,
base,
note,
);

// Reconstruct the output assuming it's a reference with the
// same region and mutability as the receiver. This holds for
Expand All @@ -1023,14 +1026,15 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
});

let base_cmt = Rc::new(self.cat_rvalue_node(expr.id, expr.span, ref_ty));
self.cat_deref(expr, base_cmt, implicit)
self.cat_deref(expr, base_cmt, note)
}

pub fn cat_deref<N:ast_node>(&self,
node: &N,
base_cmt: cmt<'tcx>,
implicit: bool)
-> McResult<cmt_<'tcx>> {
pub fn cat_deref(
&self,
node: &impl ast_node,
base_cmt: cmt<'tcx>,
note: Note,
) -> McResult<cmt_<'tcx>> {
debug!("cat_deref: base_cmt={:?}", base_cmt);

let base_cmt_ty = base_cmt.ty;
Expand All @@ -1048,7 +1052,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
ty::TyRawPtr(ref mt) => UnsafePtr(mt.mutbl),
ty::TyRef(r, mt) => {
let bk = ty::BorrowKind::from_mutbl(mt.mutbl);
if implicit { Implicit(bk, r) } else { BorrowedPtr(bk, r) }
BorrowedPtr(bk, r)
}
ref ty => bug!("unexpected type in cat_deref: {:?}", ty)
};
Expand All @@ -1059,7 +1063,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
mutbl: MutabilityCategory::from_pointer_kind(base_cmt.mutbl, ptr),
cat: Categorization::Deref(base_cmt, ptr),
ty: deref_ty,
note: NoteNone
note: note,
};
debug!("cat_deref ret {:?}", ret);
Ok(ret)
Expand Down Expand Up @@ -1192,7 +1196,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
// step out of sync again. So you'll see below that we always
// get the type of the *subpattern* and use that.

debug!("cat_pattern: {:?} cmt={:?}", pat, cmt);
debug!("cat_pattern(pat={:?}, cmt={:?})", pat, cmt);

// If (pattern) adjustments are active for this pattern, adjust the `cmt` correspondingly.
// `cmt`s are constructed differently from patterns. For example, in
Expand Down Expand Up @@ -1230,10 +1234,13 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
.pat_adjustments()
.get(pat.hir_id)
.map(|v| v.len())
.unwrap_or(0) {
cmt = Rc::new(self.cat_deref(pat, cmt, true /* implicit */)?);
.unwrap_or(0)
{
debug!("cat_pattern: applying adjustment to cmt={:?}", cmt);
cmt = Rc::new(self.cat_deref(pat, cmt, NoteNone)?);
}
let cmt = cmt; // lose mutability
debug!("cat_pattern: applied adjustment derefs to get cmt={:?}", cmt);

// Invoke the callback, but only now, after the `cmt` has adjusted.
//
Expand Down Expand Up @@ -1329,7 +1336,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
// box p1, &p1, &mut p1. we can ignore the mutability of
// PatKind::Ref since that information is already contained
// in the type.
let subcmt = Rc::new(self.cat_deref(pat, cmt, false)?);
let subcmt = Rc::new(self.cat_deref(pat, cmt, NoteNone)?);
self.cat_pattern_(subcmt, &subpat, op)?;
}

Expand Down Expand Up @@ -1390,7 +1397,6 @@ impl<'tcx> cmt_<'tcx> {
Categorization::Local(..) |
Categorization::Deref(_, UnsafePtr(..)) |
Categorization::Deref(_, BorrowedPtr(..)) |
Categorization::Deref(_, Implicit(..)) |
Categorization::Upvar(..) => {
(*self).clone()
}
Expand All @@ -1410,9 +1416,7 @@ impl<'tcx> cmt_<'tcx> {

match self.cat {
Categorization::Deref(ref b, BorrowedPtr(ty::MutBorrow, _)) |
Categorization::Deref(ref b, Implicit(ty::MutBorrow, _)) |
Categorization::Deref(ref b, BorrowedPtr(ty::UniqueImmBorrow, _)) |
Categorization::Deref(ref b, Implicit(ty::UniqueImmBorrow, _)) |
Categorization::Deref(ref b, Unique) |
Categorization::Downcast(ref b, _) |
Categorization::Interior(ref b, _) => {
Expand All @@ -1435,8 +1439,7 @@ impl<'tcx> cmt_<'tcx> {
}
}

Categorization::Deref(_, BorrowedPtr(ty::ImmBorrow, _)) |
Categorization::Deref(_, Implicit(ty::ImmBorrow, _)) => {
Categorization::Deref(_, BorrowedPtr(ty::ImmBorrow, _)) => {
FreelyAliasable(AliasableBorrowed)
}
}
Expand All @@ -1459,7 +1462,7 @@ impl<'tcx> cmt_<'tcx> {
_ => bug!()
})
}
NoteNone => None
NoteIndex | NoteNone => None
}
}

Expand All @@ -1486,17 +1489,17 @@ impl<'tcx> cmt_<'tcx> {
Some(_) => bug!(),
None => {
match pk {
Implicit(..) => {
format!("indexed content")
}
Unique => {
format!("`Box` content")
}
UnsafePtr(..) => {
format!("dereference of raw pointer")
}
BorrowedPtr(..) => {
format!("borrowed content")
match self.note {
NoteIndex => format!("indexed content"),
_ => format!("borrowed content"),
}
}
}
}
Expand Down Expand Up @@ -1524,12 +1527,9 @@ impl<'tcx> cmt_<'tcx> {
pub fn ptr_sigil(ptr: PointerKind) -> &'static str {
match ptr {
Unique => "Box",
BorrowedPtr(ty::ImmBorrow, _) |
Implicit(ty::ImmBorrow, _) => "&",
BorrowedPtr(ty::MutBorrow, _) |
Implicit(ty::MutBorrow, _) => "&mut",
BorrowedPtr(ty::UniqueImmBorrow, _) |
Implicit(ty::UniqueImmBorrow, _) => "&unique",
BorrowedPtr(ty::ImmBorrow, _) => "&",
BorrowedPtr(ty::MutBorrow, _) => "&mut",
BorrowedPtr(ty::UniqueImmBorrow, _) => "&unique",
UnsafePtr(_) => "*",
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {

this.tcx
.struct_span_lint_node(
lint::builtin::SINGLE_USE_LIFETIME,
lint::builtin::SINGLE_USE_LIFETIMES,
id,
span,
&format!(
Expand Down Expand Up @@ -1901,7 +1901,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
if deprecated {
self.tcx
.struct_span_lint_node(
lint::builtin::ELIDED_LIFETIME_IN_PATH,
lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
id,
span,
&format!("hidden lifetime parameters are deprecated, try `Foo<'_>`"),
Expand Down
Loading