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 15 pull requests #64159

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
820aa5b
Stabilize pin_into_inner in 1.39.0
ghedo Aug 28, 2019
8648732
Add `Place::is_indirect`
ecstatic-morse Aug 29, 2019
0e597d4
Rev::rposition counts from the wrong end
sfanxiang Aug 30, 2019
96ac02b
Use new `Place::is_indirect` API where possible
ecstatic-morse Aug 29, 2019
5187a3e
Harden param_attrs test wrt. usage of proc macro attrs.
Centril Aug 31, 2019
7bb2d8b
Slightly clean up the error for recursive `async fn`
matthewjasper Aug 31, 2019
877faf3
Check impl trait substs when checking for recursive types
matthewjasper Aug 31, 2019
754a875
Add some more tests for underscore imports
matthewjasper Aug 31, 2019
b0bb301
Update xLTO compatibility table in rustc book.
michaelwoerister Sep 2, 2019
3ea932a
Refer to "`self` type" instead of "receiver type"
estebank Sep 3, 2019
c1e5e5c
On object safety violation, point at source when possible
estebank Sep 3, 2019
bb99fc3
review comment: update error code descr
estebank Sep 3, 2019
efe8594
account for DUMMY_SP and correct wording
estebank Sep 3, 2019
8c74eb7
Move path parsing earlier.
nnethercote Sep 3, 2019
23c76ff
Added warning around code with reference to uninit bytes
Sep 3, 2019
e85b181
unused_parens: fix for or-patterns + &(mut x)
Centril Sep 3, 2019
b03d3dc
Changed comment to better reflect std's exceptional situation
Sep 3, 2019
28b5184
review comments: error code text
estebank Sep 3, 2019
4a79633
review comments
estebank Sep 3, 2019
e16ce80
fix error code test
estebank Sep 3, 2019
b6f9523
Fix doc links in `std::cmp` module
tesuji Sep 4, 2019
8e06724
fix a few typos in comments
Sep 4, 2019
843fba3
Stabilize checked_duration_since for 1.39.0
vi Jul 21, 2019
5545582
Avoid feature name 'checked_duration_since' in a Tidy test
vi Sep 4, 2019
fe2c6b1
Opaque type locations in error message for clarity.
gilescope Sep 4, 2019
f062076
Rollup merge of #62860 - vi:stabilize_checked_duration_since, r=Mark-…
Centril Sep 5, 2019
9ac90fa
Rollup merge of #63549 - sfanxiang:rev-rposition, r=scottmcm
Centril Sep 5, 2019
a721221
Rollup merge of #63985 - ghedo:stabilize_pin_into_inner, r=alexcrichton
Centril Sep 5, 2019
77a033a
Rollup merge of #64005 - ecstatic-morse:is-indirect, r=oli-obk
Centril Sep 5, 2019
5a94d57
Rollup merge of #64031 - Centril:param-attrs-no-macros-test, r=nikoma…
Centril Sep 5, 2019
737efa6
Rollup merge of #64038 - matthewjasper:deny-mutual-impl-trait-recursi…
Centril Sep 5, 2019
f5af471
Rollup merge of #64043 - matthewjasper:underscore-import-tests, r=ale…
Centril Sep 5, 2019
a537aa1
Rollup merge of #64092 - michaelwoerister:update-xlto-table-rustc-boo…
Centril Sep 5, 2019
f8cdf38
Rollup merge of #64110 - estebank:receiver-type, r=Centril
Centril Sep 5, 2019
39d91e5
Rollup merge of #64120 - nnethercote:move-path-parsing-earlier, r=pet…
Centril Sep 5, 2019
b0f1a78
Rollup merge of #64123 - danielhenrymantilla:add_comment_about_uninit…
Centril Sep 5, 2019
74ffc43
Rollup merge of #64128 - Centril:unused-parens-pat, r=davidtwco
Centril Sep 5, 2019
ee90e61
Rollup merge of #64142 - lzutao:fix-doc-cmp, r=jonas-schievink
Centril Sep 5, 2019
cecca35
Rollup merge of #64148 - guanqun:typo-fix, r=zackmdavis
Centril Sep 5, 2019
00c3f67
Rollup merge of #64157 - gilescope:opaque-type-location, r=cramertj
Centril Sep 5, 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
1 change: 1 addition & 0 deletions src/doc/rustc/src/linker-plugin-lto.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ The following table shows known good combinations of toolchain versions.
| Rust 1.34 | ✗ | ✓ |
| Rust 1.35 | ✗ | ✓ |
| Rust 1.36 | ✗ | ✓ |
| Rust 1.37 | ✗ | ✓ |

Note that the compatibility policy for this feature might change in the future.
20 changes: 14 additions & 6 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@
//! * [`Ord`] and [`PartialOrd`] are traits that allow you to define total and
//! partial orderings between values, respectively. Implementing them overloads
//! the `<`, `<=`, `>`, and `>=` operators.
//! * [`Ordering`][cmp::Ordering] is an enum returned by the
//! main functions of [`Ord`] and [`PartialOrd`], and describes an ordering.
//! * [`Reverse`][cmp::Reverse] is a struct that allows you to easily reverse
//! an ordering.
//! * [`max`][cmp::max] and [`min`][cmp::min] are functions that build off of
//! [`Ord`] and allow you to find the maximum or minimum of two values.
//! * [`Ordering`] is an enum returned by the main functions of [`Ord`] and
//! [`PartialOrd`], and describes an ordering.
//! * [`Reverse`] is a struct that allows you to easily reverse an ordering.
//! * [`max`] and [`min`] are functions that build off of [`Ord`] and allow you
//! to find the maximum or minimum of two values.
//!
//! For more details, see the respective documentation of each item in the list.
//!
//! [`Eq`]: trait.Eq.html
//! [`PartialEq`]: trait.PartialEq.html
//! [`Ord`]: trait.Ord.html
//! [`PartialOrd`]: trait.PartialOrd.html
//! [`Ordering`]: enum.Ordering.html
//! [`Reverse`]: struct.Reverse.html
//! [`max`]: fn.max.html
//! [`min`]: fn.min.html

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
7 changes: 0 additions & 7 deletions src/libcore/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ impl<I> Iterator for Rev<I> where I: DoubleEndedIterator {
{
self.iter.rfind(predicate)
}

#[inline]
fn rposition<P>(&mut self, predicate: P) -> Option<usize> where
P: FnMut(Self::Item) -> bool
{
self.iter.position(predicate)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
/// can ignore the pinning invariants when unwrapping it.
///
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
#[unstable(feature = "pin_into_inner", issue = "60245")]
#[stable(feature = "pin_into_inner", since = "1.39.0")]
#[inline(always)]
pub fn into_inner(pin: Pin<P>) -> P {
pin.pointer
Expand Down Expand Up @@ -569,7 +569,7 @@ impl<P: Deref> Pin<P> {
///
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
/// [`Pin::into_inner`]: #method.into_inner
#[unstable(feature = "pin_into_inner", issue = "60245")]
#[stable(feature = "pin_into_inner", since = "1.39.0")]
#[inline(always)]
pub unsafe fn into_inner_unchecked(pin: Pin<P>) -> P {
pin.pointer
Expand Down
6 changes: 6 additions & 0 deletions src/libcore/tests/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,12 @@ fn test_rposition() {
assert!(v.iter().rposition(g).is_none());
}

#[test]
fn test_rev_rposition() {
let v = [0, 0, 1, 1];
assert_eq!(v.iter().rev().rposition(|&x| x == 1), Some(1));
}

#[test]
#[should_panic]
fn test_rposition_panic() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Generally, `Self: Sized` is used to indicate that the trait should not be used
as a trait object. If the trait comes from your own crate, consider removing
this restriction.

### Method references the `Self` type in its arguments or return type
### Method references the `Self` type in its parameters or return type

This happens when a trait has a method like the following:

Expand Down
19 changes: 16 additions & 3 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ use crate::ty::error::TypeError;
use crate::ty::{self, subst::{Subst, SubstsRef}, Region, Ty, TyCtxt, TypeFoldable};
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
use std::{cmp, fmt};
use std::borrow::Cow;
use syntax_pos::{Pos, Span};

mod note;
Expand Down Expand Up @@ -1140,8 +1141,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
&"type",
expected,
found,
&format!(" ({})", values.expected.sort_string(self.tcx)),
&format!(" ({})", values.found.sort_string(self.tcx)),
&format!(" ({})",
if let ty::Opaque(def_id, _) = values.expected.sty {
Cow::from(format!("opaque type at {}", self.tcx.sess
.source_map().mk_substr_filename(self.tcx.def_span(def_id))))
} else {
values.expected.sort_string(self.tcx)
}),
&format!(" ({})",
if let ty::Opaque(def_id, _) = values.found.sty {
Cow::from(format!("opaque type at {}", self.tcx.sess
.source_map().mk_substr_filename(self.tcx.def_span(def_id))))
} else {
values.found.sort_string(self.tcx)
}),
);
}
(_, false, _) => {
Expand Down Expand Up @@ -1627,7 +1640,7 @@ impl<'tcx> ObligationCause<'tcx> {
MainFunctionType => Error0580("main function has wrong type"),
StartFunctionType => Error0308("start function has wrong type"),
IntrinsicType => Error0308("intrinsic has wrong type"),
MethodReceiver => Error0308("mismatched method receiver"),
MethodReceiver => Error0308("mismatched `self` parameter type"),

// In the case where we have no more specific thing to
// say, also take a look at the error code, maybe we can
Expand Down
25 changes: 25 additions & 0 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,23 @@ pub enum ProjectionElem<V, T> {
Downcast(Option<Symbol>, VariantIdx),
}

impl<V, T> ProjectionElem<V, T> {
/// Returns `true` if the target of this projection may refer to a different region of memory
/// than the base.
fn is_indirect(&self) -> bool {
match self {
Self::Deref => true,

| Self::Field(_, _)
| Self::Index(_)
| Self::ConstantIndex { .. }
| Self::Subslice { .. }
| Self::Downcast(_, _)
=> false
}
}
}

/// Alias for projections as they appear in places, where the base is a place
/// and the index is a local.
pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>>;
Expand Down Expand Up @@ -1869,6 +1886,14 @@ impl<'tcx> Place<'tcx> {
}
}

/// Returns `true` if this `Place` contains a `Deref` projection.
///
/// If `Place::is_indirect` returns false, the caller knows that the `Place` refers to the
/// same region of memory as its base.
pub fn is_indirect(&self) -> bool {
self.iterate(|_, mut projections| projections.any(|proj| proj.elem.is_indirect()))
}

/// Finds the innermost `Local` from this `Place`, *if* it is either a local itself or
/// a single deref of a local.
//
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,10 @@ impl<'tcx> TyCtxt<'tcx> {
let mut reported_violations = FxHashSet::default();
for violation in violations {
if reported_violations.insert(violation.clone()) {
err.note(&violation.error_msg());
match violation.span() {
Some(span) => err.span_label(span, violation.error_msg()),
None => err.note(&violation.error_msg()),
};
}
}
Some(err)
Expand Down
72 changes: 44 additions & 28 deletions src/librustc/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::borrow::Cow;
use std::iter::{self};
use syntax::ast::{self};
use syntax::symbol::InternedString;
use syntax_pos::Span;
use syntax_pos::{Span, DUMMY_SP};

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum ObjectSafetyViolation {
Expand All @@ -32,10 +32,10 @@ pub enum ObjectSafetyViolation {
SupertraitSelf,

/// Method has something illegal.
Method(ast::Name, MethodViolationCode),
Method(ast::Name, MethodViolationCode, Span),

/// Associated const.
AssocConst(ast::Name),
AssocConst(ast::Name, Span),
}

impl ObjectSafetyViolation {
Expand All @@ -46,22 +46,35 @@ impl ObjectSafetyViolation {
ObjectSafetyViolation::SupertraitSelf =>
"the trait cannot use `Self` as a type parameter \
in the supertraits or where-clauses".into(),
ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod) =>
format!("method `{}` has no receiver", name).into(),
ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelf) =>
format!("method `{}` references the `Self` type \
in its arguments or return type", name).into(),
ObjectSafetyViolation::Method(name,
MethodViolationCode::WhereClauseReferencesSelf(_)) =>
format!("method `{}` references the `Self` type in where clauses", name).into(),
ObjectSafetyViolation::Method(name, MethodViolationCode::Generic) =>
ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod, _) =>
format!("associated function `{}` has no `self` parameter", name).into(),
ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelf, _) => format!(
"method `{}` references the `Self` type in its parameters or return type",
name,
).into(),
ObjectSafetyViolation::Method(
name,
MethodViolationCode::WhereClauseReferencesSelf,
_,
) => format!("method `{}` references the `Self` type in where clauses", name).into(),
ObjectSafetyViolation::Method(name, MethodViolationCode::Generic, _) =>
format!("method `{}` has generic type parameters", name).into(),
ObjectSafetyViolation::Method(name, MethodViolationCode::UndispatchableReceiver) =>
format!("method `{}`'s receiver cannot be dispatched on", name).into(),
ObjectSafetyViolation::AssocConst(name) =>
ObjectSafetyViolation::Method(name, MethodViolationCode::UndispatchableReceiver, _) =>
format!("method `{}`'s `self` parameter cannot be dispatched on", name).into(),
ObjectSafetyViolation::AssocConst(name, _) =>
format!("the trait cannot contain associated consts like `{}`", name).into(),
}
}

pub fn span(&self) -> Option<Span> {
// When `span` comes from a separate crate, it'll be `DUMMY_SP`. Treat it as `None` so
// diagnostics use a `note` instead of a `span_label`.
match *self {
ObjectSafetyViolation::AssocConst(_, span) |
ObjectSafetyViolation::Method(_, _, span) if span != DUMMY_SP => Some(span),
_ => None,
}
}
}

/// Reasons a method might not be object-safe.
Expand All @@ -74,7 +87,7 @@ pub enum MethodViolationCode {
ReferencesSelf,

/// e.g., `fn foo(&self) where Self: Clone`
WhereClauseReferencesSelf(Span),
WhereClauseReferencesSelf,

/// e.g., `fn foo<A>()`
Generic,
Expand All @@ -88,9 +101,10 @@ impl<'tcx> TyCtxt<'tcx> {
/// astconv -- currently, `Self` in supertraits. This is needed
/// because `object_safety_violations` can't be used during
/// type collection.
pub fn astconv_object_safety_violations(self, trait_def_id: DefId)
-> Vec<ObjectSafetyViolation>
{
pub fn astconv_object_safety_violations(
self,
trait_def_id: DefId,
) -> Vec<ObjectSafetyViolation> {
debug_assert!(self.generics_of(trait_def_id).has_self);
let violations = traits::supertrait_def_ids(self, trait_def_id)
.filter(|&def_id| self.predicates_reference_self(def_id, true))
Expand Down Expand Up @@ -128,7 +142,7 @@ impl<'tcx> TyCtxt<'tcx> {
}

match self.virtual_call_violation_for_method(trait_def_id, method) {
None | Some(MethodViolationCode::WhereClauseReferencesSelf(_)) => true,
None | Some(MethodViolationCode::WhereClauseReferencesSelf) => true,
Some(_) => false,
}
}
Expand All @@ -138,12 +152,15 @@ impl<'tcx> TyCtxt<'tcx> {
let mut violations: Vec<_> = self.associated_items(trait_def_id)
.filter(|item| item.kind == ty::AssocKind::Method)
.filter_map(|item|
self.object_safety_violation_for_method(trait_def_id, &item)
.map(|code| ObjectSafetyViolation::Method(item.ident.name, code))
self.object_safety_violation_for_method(trait_def_id, &item).map(|code| {
ObjectSafetyViolation::Method(item.ident.name, code, item.ident.span)
})
).filter(|violation| {
if let ObjectSafetyViolation::Method(_,
MethodViolationCode::WhereClauseReferencesSelf(span)) = violation
{
if let ObjectSafetyViolation::Method(
_,
MethodViolationCode::WhereClauseReferencesSelf,
span,
) = violation {
// Using `CRATE_NODE_ID` is wrong, but it's hard to get a more precise id.
// It's also hard to get a use site span, so we use the method definition span.
self.lint_node_note(
Expand All @@ -169,7 +186,7 @@ impl<'tcx> TyCtxt<'tcx> {

violations.extend(self.associated_items(trait_def_id)
.filter(|item| item.kind == ty::AssocKind::Const)
.map(|item| ObjectSafetyViolation::AssocConst(item.ident.name)));
.map(|item| ObjectSafetyViolation::AssocConst(item.ident.name, item.ident.span)));

debug!("object_safety_violations_for_trait(trait_def_id={:?}) = {:?}",
trait_def_id,
Expand Down Expand Up @@ -325,8 +342,7 @@ impl<'tcx> TyCtxt<'tcx> {
.visit_tys_shallow(|t| {
self.contains_illegal_self_type_reference(trait_def_id, t)
}) {
let span = self.def_span(method.def_id);
return Some(MethodViolationCode::WhereClauseReferencesSelf(span));
return Some(MethodViolationCode::WhereClauseReferencesSelf);
}

let receiver_ty = self.liberate_late_bound_regions(
Expand Down
6 changes: 4 additions & 2 deletions src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,10 @@ impl<'tcx> TyCtxt<'tcx> {
substs: SubstsRef<'tcx>,
) -> Option<Ty<'tcx>> {
if self.found_recursion {
None
} else if self.seen_opaque_tys.insert(def_id) {
return None;
}
let substs = substs.fold_with(self);
if self.seen_opaque_tys.insert(def_id) {
let generic_ty = self.tcx.type_of(def_id);
let concrete_ty = generic_ty.subst(self.tcx, substs);
let expanded_ty = self.fold_ty(concrete_ty);
Expand Down
Loading