Skip to content

Commit 4a9ab0f

Browse files
committed
Auto merge of #65115 - Centril:rollup-gezozgl, r=Centril
Rollup of 8 pull requests Successful merges: - #64708 (Stabilize `Option::as_deref` and `Option::as_deref_mut`) - #64909 (When encountering chained operators use heuristics to recover from bad turbofish) - #65011 (Do not ICE when dereferencing non-Copy raw pointer) - #65064 (permit asyncawait-ondeck to be added by anyone) - #65066 ([const-prop] Fix ICE when trying to eval polymorphic promoted MIR) - #65100 (Replace GeneratorSubsts with SubstsRef) - #65105 (Split out some passes from librustc) - #65106 (Allow unused attributes to avoid incremental bug) Failed merges: r? @ghost
2 parents 7870050 + f320add commit 4a9ab0f

Some content is hidden

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

74 files changed

+713
-475
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,8 @@ dependencies = [
36133613
"rustc",
36143614
"rustc_data_structures",
36153615
"rustc_errors",
3616+
"rustc_index",
3617+
"rustc_target",
36163618
"syntax",
36173619
"syntax_pos",
36183620
]

src/libcore/option.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,6 @@ impl<T: Default> Option<T> {
11021102
}
11031103
}
11041104

1105-
#[unstable(feature = "inner_deref", reason = "newly added", issue = "50264")]
11061105
impl<T: Deref> Option<T> {
11071106
/// Converts from `Option<T>` (or `&Option<T>`) to `Option<&T::Target>`.
11081107
///
@@ -1114,20 +1113,18 @@ impl<T: Deref> Option<T> {
11141113
/// # Examples
11151114
///
11161115
/// ```
1117-
/// #![feature(inner_deref)]
1118-
///
11191116
/// let x: Option<String> = Some("hey".to_owned());
11201117
/// assert_eq!(x.as_deref(), Some("hey"));
11211118
///
11221119
/// let x: Option<String> = None;
11231120
/// assert_eq!(x.as_deref(), None);
11241121
/// ```
1122+
#[stable(feature = "option_deref", since = "1.40.0")]
11251123
pub fn as_deref(&self) -> Option<&T::Target> {
11261124
self.as_ref().map(|t| t.deref())
11271125
}
11281126
}
11291127

1130-
#[unstable(feature = "inner_deref", reason = "newly added", issue = "50264")]
11311128
impl<T: DerefMut> Option<T> {
11321129
/// Converts from `Option<T>` (or `&mut Option<T>`) to `Option<&mut T::Target>`.
11331130
///
@@ -1137,14 +1134,13 @@ impl<T: DerefMut> Option<T> {
11371134
/// # Examples
11381135
///
11391136
/// ```
1140-
/// #![feature(inner_deref)]
1141-
///
11421137
/// let mut x: Option<String> = Some("hey".to_owned());
11431138
/// assert_eq!(x.as_deref_mut().map(|x| {
11441139
/// x.make_ascii_uppercase();
11451140
/// x
11461141
/// }), Some("HEY".to_owned().as_mut_str()));
11471142
/// ```
1143+
#[stable(feature = "option_deref", since = "1.40.0")]
11481144
pub fn as_deref_mut(&mut self) -> Option<&mut T::Target> {
11491145
self.as_mut().map(|t| t.deref_mut())
11501146
}

src/libcore/slice/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl<T> [T] {
6363
#[stable(feature = "rust1", since = "1.0.0")]
6464
#[inline]
6565
// SAFETY: const sound because we transmute out the length field as a usize (which it must be)
66+
#[allow(unused_attributes)]
6667
#[allow_internal_unstable(const_fn_union)]
6768
pub const fn len(&self) -> usize {
6869
unsafe {

src/libcore/str/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,7 @@ impl str {
21672167
#[stable(feature = "rust1", since = "1.0.0")]
21682168
#[inline(always)]
21692169
// SAFETY: const sound because we transmute two types with the same layout
2170+
#[allow(unused_attributes)]
21702171
#[allow_internal_unstable(const_fn_union)]
21712172
pub const fn as_bytes(&self) -> &[u8] {
21722173
#[repr(C)]

src/librustc/error_codes.rs

-180
Original file line numberDiff line numberDiff line change
@@ -466,66 +466,6 @@ fn main() {
466466
```
467467
"##,
468468

469-
// This shouldn't really ever trigger since the repeated value error comes first
470-
E0136: r##"
471-
A binary can only have one entry point, and by default that entry point is the
472-
function `main()`. If there are multiple such functions, please rename one.
473-
"##,
474-
475-
E0137: r##"
476-
More than one function was declared with the `#[main]` attribute.
477-
478-
Erroneous code example:
479-
480-
```compile_fail,E0137
481-
#![feature(main)]
482-
483-
#[main]
484-
fn foo() {}
485-
486-
#[main]
487-
fn f() {} // error: multiple functions with a `#[main]` attribute
488-
```
489-
490-
This error indicates that the compiler found multiple functions with the
491-
`#[main]` attribute. This is an error because there must be a unique entry
492-
point into a Rust program. Example:
493-
494-
```
495-
#![feature(main)]
496-
497-
#[main]
498-
fn f() {} // ok!
499-
```
500-
"##,
501-
502-
E0138: r##"
503-
More than one function was declared with the `#[start]` attribute.
504-
505-
Erroneous code example:
506-
507-
```compile_fail,E0138
508-
#![feature(start)]
509-
510-
#[start]
511-
fn foo(argc: isize, argv: *const *const u8) -> isize {}
512-
513-
#[start]
514-
fn f(argc: isize, argv: *const *const u8) -> isize {}
515-
// error: multiple 'start' functions
516-
```
517-
518-
This error indicates that the compiler found multiple functions with the
519-
`#[start]` attribute. This is an error because there must be a unique entry
520-
point into a Rust program. Example:
521-
522-
```
523-
#![feature(start)]
524-
525-
#[start]
526-
fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!
527-
```
528-
"##,
529469

530470
E0139: r##"
531471
#### Note: this error code is no longer emitted by the compiler.
@@ -1626,33 +1566,6 @@ It is not possible to use stability attributes outside of the standard library.
16261566
Also, for now, it is not possible to write deprecation messages either.
16271567
"##,
16281568

1629-
E0512: r##"
1630-
Transmute with two differently sized types was attempted. Erroneous code
1631-
example:
1632-
1633-
```compile_fail,E0512
1634-
fn takes_u8(_: u8) {}
1635-
1636-
fn main() {
1637-
unsafe { takes_u8(::std::mem::transmute(0u16)); }
1638-
// error: cannot transmute between types of different sizes,
1639-
// or dependently-sized types
1640-
}
1641-
```
1642-
1643-
Please use types with same size or use the expected type directly. Example:
1644-
1645-
```
1646-
fn takes_u8(_: u8) {}
1647-
1648-
fn main() {
1649-
unsafe { takes_u8(::std::mem::transmute(0i8)); } // ok!
1650-
// or:
1651-
unsafe { takes_u8(0u8); } // ok!
1652-
}
1653-
```
1654-
"##,
1655-
16561569
E0517: r##"
16571570
This error indicates that a `#[repr(..)]` attribute was placed on an
16581571
unsupported item.
@@ -1847,84 +1760,6 @@ See [RFC 1522] for more details.
18471760
[RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
18481761
"##,
18491762

1850-
E0591: r##"
1851-
Per [RFC 401][rfc401], if you have a function declaration `foo`:
1852-
1853-
```
1854-
// For the purposes of this explanation, all of these
1855-
// different kinds of `fn` declarations are equivalent:
1856-
struct S;
1857-
fn foo(x: S) { /* ... */ }
1858-
# #[cfg(for_demonstration_only)]
1859-
extern "C" { fn foo(x: S); }
1860-
# #[cfg(for_demonstration_only)]
1861-
impl S { fn foo(self) { /* ... */ } }
1862-
```
1863-
1864-
the type of `foo` is **not** `fn(S)`, as one might expect.
1865-
Rather, it is a unique, zero-sized marker type written here as `typeof(foo)`.
1866-
However, `typeof(foo)` can be _coerced_ to a function pointer `fn(S)`,
1867-
so you rarely notice this:
1868-
1869-
```
1870-
# struct S;
1871-
# fn foo(_: S) {}
1872-
let x: fn(S) = foo; // OK, coerces
1873-
```
1874-
1875-
The reason that this matter is that the type `fn(S)` is not specific to
1876-
any particular function: it's a function _pointer_. So calling `x()` results
1877-
in a virtual call, whereas `foo()` is statically dispatched, because the type
1878-
of `foo` tells us precisely what function is being called.
1879-
1880-
As noted above, coercions mean that most code doesn't have to be
1881-
concerned with this distinction. However, you can tell the difference
1882-
when using **transmute** to convert a fn item into a fn pointer.
1883-
1884-
This is sometimes done as part of an FFI:
1885-
1886-
```compile_fail,E0591
1887-
extern "C" fn foo(userdata: Box<i32>) {
1888-
/* ... */
1889-
}
1890-
1891-
# fn callback(_: extern "C" fn(*mut i32)) {}
1892-
# use std::mem::transmute;
1893-
# unsafe {
1894-
let f: extern "C" fn(*mut i32) = transmute(foo);
1895-
callback(f);
1896-
# }
1897-
```
1898-
1899-
Here, transmute is being used to convert the types of the fn arguments.
1900-
This pattern is incorrect because, because the type of `foo` is a function
1901-
**item** (`typeof(foo)`), which is zero-sized, and the target type (`fn()`)
1902-
is a function pointer, which is not zero-sized.
1903-
This pattern should be rewritten. There are a few possible ways to do this:
1904-
1905-
- change the original fn declaration to match the expected signature,
1906-
and do the cast in the fn body (the preferred option)
1907-
- cast the fn item fo a fn pointer before calling transmute, as shown here:
1908-
1909-
```
1910-
# extern "C" fn foo(_: Box<i32>) {}
1911-
# use std::mem::transmute;
1912-
# unsafe {
1913-
let f: extern "C" fn(*mut i32) = transmute(foo as extern "C" fn(_));
1914-
let f: extern "C" fn(*mut i32) = transmute(foo as usize); // works too
1915-
# }
1916-
```
1917-
1918-
The same applies to transmutes to `*mut fn()`, which were observed in practice.
1919-
Note though that use of this type is generally incorrect.
1920-
The intention is typically to describe a function pointer, but just `fn()`
1921-
alone suffices for that. `*mut fn()` is a pointer to a fn pointer.
1922-
(Since these values are typically just passed to C code, however, this rarely
1923-
makes a difference in practice.)
1924-
1925-
[rfc401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
1926-
"##,
1927-
19281763
E0593: r##"
19291764
You tried to supply an `Fn`-based type with an incorrect number of arguments
19301765
than what was expected.
@@ -1941,21 +1776,6 @@ fn main() {
19411776
```
19421777
"##,
19431778

1944-
E0601: r##"
1945-
No `main` function was found in a binary crate. To fix this error, add a
1946-
`main` function. For example:
1947-
1948-
```
1949-
fn main() {
1950-
// Your program will start here.
1951-
println!("Hello world!");
1952-
}
1953-
```
1954-
1955-
If you don't know the basics of Rust, you can go look to the Rust Book to get
1956-
started: https://doc.rust-lang.org/book/
1957-
"##,
1958-
19591779
E0602: r##"
19601780
An unknown lint was used on the command line.
19611781

src/librustc/infer/opaque_types/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -733,12 +733,12 @@ where
733733
// Skip lifetime parameters of the enclosing item(s)
734734
// Also skip the witness type, because that has no free regions.
735735

736-
for upvar_ty in substs.upvar_tys(def_id, self.tcx) {
736+
for upvar_ty in substs.as_generator().upvar_tys(def_id, self.tcx) {
737737
upvar_ty.visit_with(self);
738738
}
739739

740-
substs.return_ty(def_id, self.tcx).visit_with(self);
741-
substs.yield_ty(def_id, self.tcx).visit_with(self);
740+
substs.as_generator().return_ty(def_id, self.tcx).visit_with(self);
741+
substs.as_generator().yield_ty(def_id, self.tcx).visit_with(self);
742742
}
743743
_ => {
744744
ty.super_visit_with(self);
@@ -902,7 +902,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
902902
ty::Generator(def_id, substs, movability) => {
903903
let generics = self.tcx.generics_of(def_id);
904904
let substs =
905-
self.tcx.mk_substs(substs.substs.iter().enumerate().map(|(index, &kind)| {
905+
self.tcx.mk_substs(substs.iter().enumerate().map(|(index, &kind)| {
906906
if index < generics.parent_count {
907907
// Accommodate missing regions in the parent kinds...
908908
self.fold_kind_mapping_missing_regions_to_empty(kind)
@@ -912,7 +912,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
912912
}
913913
}));
914914

915-
self.tcx.mk_generator(def_id, ty::GeneratorSubsts { substs }, movability)
915+
self.tcx.mk_generator(def_id, substs, movability)
916916
}
917917

918918
ty::Param(..) => {

src/librustc/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#![feature(const_transmute)]
3636
#![feature(core_intrinsics)]
3737
#![feature(drain_filter)]
38-
#![feature(inner_deref)]
3938
#![cfg_attr(windows, feature(libc))]
4039
#![feature(never_type)]
4140
#![feature(exhaustive_patterns)]
@@ -102,16 +101,12 @@ pub mod lint;
102101
pub mod middle {
103102
pub mod expr_use_visitor;
104103
pub mod cstore;
105-
pub mod dead;
106104
pub mod dependency_format;
107105
pub mod diagnostic_items;
108-
pub mod entry;
109106
pub mod exported_symbols;
110107
pub mod free_region;
111-
pub mod intrinsicck;
112108
pub mod lib_features;
113109
pub mod lang_items;
114-
pub mod liveness;
115110
pub mod mem_categorization;
116111
pub mod privacy;
117112
pub mod reachable;

src/librustc/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::ty::layout::VariantIdx;
1515
use crate::ty::print::{FmtPrinter, Printer};
1616
use crate::ty::subst::{Subst, SubstsRef};
1717
use crate::ty::{
18-
self, AdtDef, CanonicalUserTypeAnnotations, GeneratorSubsts, Region, Ty, TyCtxt,
18+
self, AdtDef, CanonicalUserTypeAnnotations, Region, Ty, TyCtxt,
1919
UserTypeAnnotationIndex,
2020
};
2121

@@ -2189,7 +2189,7 @@ pub enum AggregateKind<'tcx> {
21892189
Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
21902190

21912191
Closure(DefId, SubstsRef<'tcx>),
2192-
Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
2192+
Generator(DefId, SubstsRef<'tcx>, hir::GeneratorMovability),
21932193
}
21942194

21952195
#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]

src/librustc/mir/tcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<'tcx> Rvalue<'tcx> {
197197
let ty = place.ty(local_decls, tcx).ty;
198198
match ty.kind {
199199
ty::Adt(adt_def, _) => adt_def.repr.discr_type().to_ty(tcx),
200-
ty::Generator(_, substs, _) => substs.discr_ty(tcx),
200+
ty::Generator(_, substs, _) => substs.as_generator().discr_ty(tcx),
201201
_ => {
202202
// This can only be `0`, for now, so `u8` will suffice.
203203
tcx.types.u8

0 commit comments

Comments
 (0)