Skip to content

Commit a24f636

Browse files
committed
Auto merge of #64160 - Centril:rollup-vrfj1pt, r=Centril
Rollup of 15 pull requests Successful merges: - #62860 (Stabilize checked_duration_since for 1.38.0) - #63549 (Rev::rposition counts from the wrong end) - #63985 (Stabilize pin_into_inner in 1.39.0) - #64005 (Add a `Place::is_indirect` method to determine whether a `Place` contains a `Deref` projection) - #64031 (Harden `param_attrs` test wrt. usage of a proc macro `#[attr]`) - #64038 (Check impl trait substs when checking for recursive types) - #64043 (Add some more tests for underscore imports) - #64092 (Update xLTO compatibility table in rustc book.) - #64110 (Refer to "`self` type" instead of "receiver type") - #64120 (Move path parsing earlier) - #64123 (Added warning around code with reference to uninit bytes) - #64128 (unused_parens: account for or-patterns and `&(mut x)`) - #64141 (Minimize uses of `LocalInternedString`) - #64142 (Fix doc links in `std::cmp` module) - #64148 (fix a few typos in comments) Failed merges: r? @ghost
2 parents f257c40 + 51ae5d0 commit a24f636

File tree

102 files changed

+1182
-433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1182
-433
lines changed

src/doc/rustc/src/linker-plugin-lto.md

+1
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,6 @@ The following table shows known good combinations of toolchain versions.
105105
| Rust 1.34 |||
106106
| Rust 1.35 |||
107107
| Rust 1.36 |||
108+
| Rust 1.37 |||
108109

109110
Note that the compatibility policy for this feature might change in the future.

src/libcore/cmp.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@
99
//! * [`Ord`] and [`PartialOrd`] are traits that allow you to define total and
1010
//! partial orderings between values, respectively. Implementing them overloads
1111
//! the `<`, `<=`, `>`, and `>=` operators.
12-
//! * [`Ordering`][cmp::Ordering] is an enum returned by the
13-
//! main functions of [`Ord`] and [`PartialOrd`], and describes an ordering.
14-
//! * [`Reverse`][cmp::Reverse] is a struct that allows you to easily reverse
15-
//! an ordering.
16-
//! * [`max`][cmp::max] and [`min`][cmp::min] are functions that build off of
17-
//! [`Ord`] and allow you to find the maximum or minimum of two values.
12+
//! * [`Ordering`] is an enum returned by the main functions of [`Ord`] and
13+
//! [`PartialOrd`], and describes an ordering.
14+
//! * [`Reverse`] is a struct that allows you to easily reverse an ordering.
15+
//! * [`max`] and [`min`] are functions that build off of [`Ord`] and allow you
16+
//! to find the maximum or minimum of two values.
1817
//!
1918
//! For more details, see the respective documentation of each item in the list.
19+
//!
20+
//! [`Eq`]: trait.Eq.html
21+
//! [`PartialEq`]: trait.PartialEq.html
22+
//! [`Ord`]: trait.Ord.html
23+
//! [`PartialOrd`]: trait.PartialOrd.html
24+
//! [`Ordering`]: enum.Ordering.html
25+
//! [`Reverse`]: struct.Reverse.html
26+
//! [`max`]: fn.max.html
27+
//! [`min`]: fn.min.html
2028
2129
#![stable(feature = "rust1", since = "1.0.0")]
2230

src/libcore/iter/adapters/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,6 @@ impl<I> Iterator for Rev<I> where I: DoubleEndedIterator {
6666
{
6767
self.iter.rfind(predicate)
6868
}
69-
70-
#[inline]
71-
fn rposition<P>(&mut self, predicate: P) -> Option<usize> where
72-
P: FnMut(Self::Item) -> bool
73-
{
74-
self.iter.position(predicate)
75-
}
7669
}
7770

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

src/libcore/pin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
462462
/// can ignore the pinning invariants when unwrapping it.
463463
///
464464
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
465-
#[unstable(feature = "pin_into_inner", issue = "60245")]
465+
#[stable(feature = "pin_into_inner", since = "1.39.0")]
466466
#[inline(always)]
467467
pub fn into_inner(pin: Pin<P>) -> P {
468468
pin.pointer
@@ -569,7 +569,7 @@ impl<P: Deref> Pin<P> {
569569
///
570570
/// [`Unpin`]: ../../std/marker/trait.Unpin.html
571571
/// [`Pin::into_inner`]: #method.into_inner
572-
#[unstable(feature = "pin_into_inner", issue = "60245")]
572+
#[stable(feature = "pin_into_inner", since = "1.39.0")]
573573
#[inline(always)]
574574
pub unsafe fn into_inner_unchecked(pin: Pin<P>) -> P {
575575
pin.pointer

src/libcore/tests/iter.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,12 @@ fn test_rposition() {
16881688
assert!(v.iter().rposition(g).is_none());
16891689
}
16901690

1691+
#[test]
1692+
fn test_rev_rposition() {
1693+
let v = [0, 0, 1, 1];
1694+
assert_eq!(v.iter().rev().rposition(|&x| x == 1), Some(1));
1695+
}
1696+
16911697
#[test]
16921698
#[should_panic]
16931699
fn test_rposition_panic() {

src/librustc/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Generally, `Self: Sized` is used to indicate that the trait should not be used
3939
as a trait object. If the trait comes from your own crate, consider removing
4040
this restriction.
4141
42-
### Method references the `Self` type in its arguments or return type
42+
### Method references the `Self` type in its parameters or return type
4343
4444
This happens when a trait has a method like the following:
4545

src/librustc/hir/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
186186
});
187187

188188
let mut upstream_crates: Vec<_> = cstore.crates_untracked().iter().map(|&cnum| {
189-
let name = cstore.crate_name_untracked(cnum).as_str();
189+
let name = cstore.crate_name_untracked(cnum).as_interned_str();
190190
let disambiguator = cstore.crate_disambiguator_untracked(cnum).to_fingerprint();
191191
let hash = cstore.crate_hash_untracked(cnum);
192192
(name, disambiguator, hash)

src/librustc/ich/impls_syntax.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::mem;
99
use syntax::ast;
1010
use syntax::feature_gate;
1111
use syntax::parse::token;
12-
use syntax::symbol::{InternedString, LocalInternedString};
12+
use syntax::symbol::InternedString;
1313
use syntax::tokenstream;
1414
use syntax_pos::SourceFile;
1515

@@ -39,27 +39,6 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for InternedString {
3939
}
4040
}
4141

42-
impl<'a> HashStable<StableHashingContext<'a>> for LocalInternedString {
43-
#[inline]
44-
fn hash_stable<W: StableHasherResult>(&self,
45-
hcx: &mut StableHashingContext<'a>,
46-
hasher: &mut StableHasher<W>) {
47-
let s: &str = &**self;
48-
s.hash_stable(hcx, hasher);
49-
}
50-
}
51-
52-
impl<'a> ToStableHashKey<StableHashingContext<'a>> for LocalInternedString {
53-
type KeyType = LocalInternedString;
54-
55-
#[inline]
56-
fn to_stable_hash_key(&self,
57-
_: &StableHashingContext<'a>)
58-
-> LocalInternedString {
59-
self.clone()
60-
}
61-
}
62-
6342
impl<'a> HashStable<StableHashingContext<'a>> for ast::Name {
6443
#[inline]
6544
fn hash_stable<W: StableHasherResult>(&self,

src/librustc/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,7 @@ impl<'tcx> ObligationCause<'tcx> {
16271627
MainFunctionType => Error0580("main function has wrong type"),
16281628
StartFunctionType => Error0308("start function has wrong type"),
16291629
IntrinsicType => Error0308("intrinsic has wrong type"),
1630-
MethodReceiver => Error0308("mismatched method receiver"),
1630+
MethodReceiver => Error0308("mismatched `self` parameter type"),
16311631

16321632
// In the case where we have no more specific thing to
16331633
// say, also take a look at the error code, maybe we can

src/librustc/lint/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::util::common::time;
3333
use std::default::Default as StdDefault;
3434
use syntax::ast;
3535
use syntax::edition;
36-
use syntax_pos::{MultiSpan, Span, symbol::{LocalInternedString, Symbol}};
36+
use syntax_pos::{MultiSpan, Span, symbol::Symbol};
3737
use errors::DiagnosticBuilder;
3838
use crate::hir;
3939
use crate::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
@@ -405,7 +405,7 @@ impl LintStore {
405405
pub fn check_lint_name(
406406
&self,
407407
lint_name: &str,
408-
tool_name: Option<LocalInternedString>,
408+
tool_name: Option<Symbol>,
409409
) -> CheckLintNameResult<'_> {
410410
let complete_name = if let Some(tool_name) = tool_name {
411411
format!("{}::{}", tool_name, lint_name)

src/librustc/lint/levels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl<'a> LintLevelsBuilder<'a> {
291291
continue;
292292
}
293293

294-
Some(tool_ident.as_str())
294+
Some(tool_ident.name)
295295
} else {
296296
None
297297
};

src/librustc/mir/mod.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,23 @@ pub enum ProjectionElem<V, T> {
18081808
Downcast(Option<Symbol>, VariantIdx),
18091809
}
18101810

1811+
impl<V, T> ProjectionElem<V, T> {
1812+
/// Returns `true` if the target of this projection may refer to a different region of memory
1813+
/// than the base.
1814+
fn is_indirect(&self) -> bool {
1815+
match self {
1816+
Self::Deref => true,
1817+
1818+
| Self::Field(_, _)
1819+
| Self::Index(_)
1820+
| Self::ConstantIndex { .. }
1821+
| Self::Subslice { .. }
1822+
| Self::Downcast(_, _)
1823+
=> false
1824+
}
1825+
}
1826+
}
1827+
18111828
/// Alias for projections as they appear in places, where the base is a place
18121829
/// and the index is a local.
18131830
pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>>;
@@ -1869,6 +1886,14 @@ impl<'tcx> Place<'tcx> {
18691886
}
18701887
}
18711888

1889+
/// Returns `true` if this `Place` contains a `Deref` projection.
1890+
///
1891+
/// If `Place::is_indirect` returns false, the caller knows that the `Place` refers to the
1892+
/// same region of memory as its base.
1893+
pub fn is_indirect(&self) -> bool {
1894+
self.iterate(|_, mut projections| projections.any(|proj| proj.elem.is_indirect()))
1895+
}
1896+
18721897
/// Finds the innermost `Local` from this `Place`, *if* it is either a local itself or
18731898
/// a single deref of a local.
18741899
//

src/librustc/traits/error_reporting.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,10 @@ impl<'tcx> TyCtxt<'tcx> {
13841384
let mut reported_violations = FxHashSet::default();
13851385
for violation in violations {
13861386
if reported_violations.insert(violation.clone()) {
1387-
err.note(&violation.error_msg());
1387+
match violation.span() {
1388+
Some(span) => err.span_label(span, violation.error_msg()),
1389+
None => err.note(&violation.error_msg()),
1390+
};
13881391
}
13891392
}
13901393
Some(err)

src/librustc/traits/object_safety.rs

+44-28
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::borrow::Cow;
2020
use std::iter::{self};
2121
use syntax::ast::{self};
2222
use syntax::symbol::InternedString;
23-
use syntax_pos::Span;
23+
use syntax_pos::{Span, DUMMY_SP};
2424

2525
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
2626
pub enum ObjectSafetyViolation {
@@ -32,10 +32,10 @@ pub enum ObjectSafetyViolation {
3232
SupertraitSelf,
3333

3434
/// Method has something illegal.
35-
Method(ast::Name, MethodViolationCode),
35+
Method(ast::Name, MethodViolationCode, Span),
3636

3737
/// Associated const.
38-
AssocConst(ast::Name),
38+
AssocConst(ast::Name, Span),
3939
}
4040

4141
impl ObjectSafetyViolation {
@@ -46,22 +46,35 @@ impl ObjectSafetyViolation {
4646
ObjectSafetyViolation::SupertraitSelf =>
4747
"the trait cannot use `Self` as a type parameter \
4848
in the supertraits or where-clauses".into(),
49-
ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod) =>
50-
format!("method `{}` has no receiver", name).into(),
51-
ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelf) =>
52-
format!("method `{}` references the `Self` type \
53-
in its arguments or return type", name).into(),
54-
ObjectSafetyViolation::Method(name,
55-
MethodViolationCode::WhereClauseReferencesSelf(_)) =>
56-
format!("method `{}` references the `Self` type in where clauses", name).into(),
57-
ObjectSafetyViolation::Method(name, MethodViolationCode::Generic) =>
49+
ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod, _) =>
50+
format!("associated function `{}` has no `self` parameter", name).into(),
51+
ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelf, _) => format!(
52+
"method `{}` references the `Self` type in its parameters or return type",
53+
name,
54+
).into(),
55+
ObjectSafetyViolation::Method(
56+
name,
57+
MethodViolationCode::WhereClauseReferencesSelf,
58+
_,
59+
) => format!("method `{}` references the `Self` type in where clauses", name).into(),
60+
ObjectSafetyViolation::Method(name, MethodViolationCode::Generic, _) =>
5861
format!("method `{}` has generic type parameters", name).into(),
59-
ObjectSafetyViolation::Method(name, MethodViolationCode::UndispatchableReceiver) =>
60-
format!("method `{}`'s receiver cannot be dispatched on", name).into(),
61-
ObjectSafetyViolation::AssocConst(name) =>
62+
ObjectSafetyViolation::Method(name, MethodViolationCode::UndispatchableReceiver, _) =>
63+
format!("method `{}`'s `self` parameter cannot be dispatched on", name).into(),
64+
ObjectSafetyViolation::AssocConst(name, _) =>
6265
format!("the trait cannot contain associated consts like `{}`", name).into(),
6366
}
6467
}
68+
69+
pub fn span(&self) -> Option<Span> {
70+
// When `span` comes from a separate crate, it'll be `DUMMY_SP`. Treat it as `None` so
71+
// diagnostics use a `note` instead of a `span_label`.
72+
match *self {
73+
ObjectSafetyViolation::AssocConst(_, span) |
74+
ObjectSafetyViolation::Method(_, _, span) if span != DUMMY_SP => Some(span),
75+
_ => None,
76+
}
77+
}
6578
}
6679

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

7689
/// e.g., `fn foo(&self) where Self: Clone`
77-
WhereClauseReferencesSelf(Span),
90+
WhereClauseReferencesSelf,
7891

7992
/// e.g., `fn foo<A>()`
8093
Generic,
@@ -88,9 +101,10 @@ impl<'tcx> TyCtxt<'tcx> {
88101
/// astconv -- currently, `Self` in supertraits. This is needed
89102
/// because `object_safety_violations` can't be used during
90103
/// type collection.
91-
pub fn astconv_object_safety_violations(self, trait_def_id: DefId)
92-
-> Vec<ObjectSafetyViolation>
93-
{
104+
pub fn astconv_object_safety_violations(
105+
self,
106+
trait_def_id: DefId,
107+
) -> Vec<ObjectSafetyViolation> {
94108
debug_assert!(self.generics_of(trait_def_id).has_self);
95109
let violations = traits::supertrait_def_ids(self, trait_def_id)
96110
.filter(|&def_id| self.predicates_reference_self(def_id, true))
@@ -128,7 +142,7 @@ impl<'tcx> TyCtxt<'tcx> {
128142
}
129143

130144
match self.virtual_call_violation_for_method(trait_def_id, method) {
131-
None | Some(MethodViolationCode::WhereClauseReferencesSelf(_)) => true,
145+
None | Some(MethodViolationCode::WhereClauseReferencesSelf) => true,
132146
Some(_) => false,
133147
}
134148
}
@@ -138,12 +152,15 @@ impl<'tcx> TyCtxt<'tcx> {
138152
let mut violations: Vec<_> = self.associated_items(trait_def_id)
139153
.filter(|item| item.kind == ty::AssocKind::Method)
140154
.filter_map(|item|
141-
self.object_safety_violation_for_method(trait_def_id, &item)
142-
.map(|code| ObjectSafetyViolation::Method(item.ident.name, code))
155+
self.object_safety_violation_for_method(trait_def_id, &item).map(|code| {
156+
ObjectSafetyViolation::Method(item.ident.name, code, item.ident.span)
157+
})
143158
).filter(|violation| {
144-
if let ObjectSafetyViolation::Method(_,
145-
MethodViolationCode::WhereClauseReferencesSelf(span)) = violation
146-
{
159+
if let ObjectSafetyViolation::Method(
160+
_,
161+
MethodViolationCode::WhereClauseReferencesSelf,
162+
span,
163+
) = violation {
147164
// Using `CRATE_NODE_ID` is wrong, but it's hard to get a more precise id.
148165
// It's also hard to get a use site span, so we use the method definition span.
149166
self.lint_node_note(
@@ -169,7 +186,7 @@ impl<'tcx> TyCtxt<'tcx> {
169186

170187
violations.extend(self.associated_items(trait_def_id)
171188
.filter(|item| item.kind == ty::AssocKind::Const)
172-
.map(|item| ObjectSafetyViolation::AssocConst(item.ident.name)));
189+
.map(|item| ObjectSafetyViolation::AssocConst(item.ident.name, item.ident.span)));
173190

174191
debug!("object_safety_violations_for_trait(trait_def_id={:?}) = {:?}",
175192
trait_def_id,
@@ -325,8 +342,7 @@ impl<'tcx> TyCtxt<'tcx> {
325342
.visit_tys_shallow(|t| {
326343
self.contains_illegal_self_type_reference(trait_def_id, t)
327344
}) {
328-
let span = self.def_span(method.def_id);
329-
return Some(MethodViolationCode::WhereClauseReferencesSelf(span));
345+
return Some(MethodViolationCode::WhereClauseReferencesSelf);
330346
}
331347

332348
let receiver_ty = self.liberate_late_bound_regions(

0 commit comments

Comments
 (0)