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 5 pull requests #73018

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ Compatibility Notes
previously a warning.
- [In 1.45.0 (the next release) converting a `f64` to `u32` using the `as`
operator has been defined as a saturating operation.][71269] This was previously
undefined behaviour, you can use the `{f64, f32}::to_int_unchecked` methods to
continue using the current behaviour which may desirable in rare performance
undefined behaviour, but you can use the `{f64, f32}::to_int_unchecked` methods to
continue using the current behaviour, which may be desirable in rare performance
sensitive situations.

Internal Only
Expand Down
22 changes: 4 additions & 18 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,29 +963,15 @@ impl Build {
return s;
}

let beta = output(
Command::new("git").arg("ls-remote").arg("origin").arg("beta").current_dir(&self.src),
);
let beta = beta.trim().split_whitespace().next().unwrap();
let master = output(
Command::new("git").arg("ls-remote").arg("origin").arg("master").current_dir(&self.src),
);
let master = master.trim().split_whitespace().next().unwrap();

// Figure out where the current beta branch started.
let base = output(
Command::new("git").arg("merge-base").arg(beta).arg(master).current_dir(&self.src),
);
let base = base.trim();

// Next figure out how many merge commits happened since we branched off
// beta. That's our beta number!
// Figure out how many merge commits happened since we branched off master.
// That's our beta number!
// (Note that we use a `..` range, not the `...` symmetric difference.)
let count = output(
Command::new("git")
.arg("rev-list")
.arg("--count")
.arg("--merges")
.arg(format!("{}...HEAD", base))
.arg("refs/remotes/origin/master..HEAD")
.current_dir(&self.src),
);
let n = count.trim().parse().unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ E0751: include_str!("./error_codes/E0751.md"),
E0752: include_str!("./error_codes/E0752.md"),
E0753: include_str!("./error_codes/E0753.md"),
E0754: include_str!("./error_codes/E0754.md"),
E0760: include_str!("./error_codes/E0760.md"),
;
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard
Expand Down
32 changes: 32 additions & 0 deletions src/librustc_error_codes/error_codes/E0760.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
`async fn`/`impl trait` return type cannot contain a projection
or `Self` that references lifetimes from a parent scope.

Erroneous code example:

```compile_fail,E0760,edition2018
struct S<'a>(&'a i32);

impl<'a> S<'a> {
async fn new(i: &'a i32) -> Self {
S(&22)
}
}
```

To fix this error we need to spell out `Self` to `S<'a>`:

```edition2018
struct S<'a>(&'a i32);

impl<'a> S<'a> {
async fn new(i: &'a i32) -> S<'a> {
S(&22)
}
}
```

This will be allowed at some point in the future,
but the implementation is not yet complete.
See the [issue-61949] for this limitation.

[issue-61949]: https://github.com/rust-lang/rust/issues/61949
6 changes: 6 additions & 0 deletions src/librustc_hir/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ impl Definitions {
self.node_id_to_hir_id[node_id]
}

#[inline]
pub fn opt_hir_id_to_local_def_id(&self, hir_id: hir::HirId) -> Option<LocalDefId> {
let node_id = self.hir_id_to_node_id(hir_id);
self.opt_local_def_id(node_id)
}

/// Retrieves the span of the given `DefId` if `DefId` is in the local crate.
#[inline]
pub fn opt_span(&self, def_id: DefId) -> Option<Span> {
Expand Down
37 changes: 2 additions & 35 deletions src/librustc_middle/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use self::collector::NodeCollector;
use crate::hir::{Owner, OwnerNodes};
use crate::ty::query::Providers;
use crate::ty::TyCtxt;
use rustc_ast::ast::{self, NodeId};
use rustc_ast::ast::{self};
use rustc_data_structures::svh::Svh;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
Expand Down Expand Up @@ -157,18 +157,6 @@ impl<'hir> Map<'hir> {
self.tcx.definitions.def_path(def_id)
}

#[inline]
pub fn local_def_id_from_node_id(&self, node: NodeId) -> LocalDefId {
self.opt_local_def_id_from_node_id(node).unwrap_or_else(|| {
let hir_id = self.node_id_to_hir_id(node);
bug!(
"local_def_id_from_node_id: no entry for `{}`, which has a map of `{:?}`",
node,
self.find_entry(hir_id)
)
})
}

#[inline]
pub fn local_def_id(&self, hir_id: HirId) -> LocalDefId {
self.opt_local_def_id(hir_id).unwrap_or_else(|| {
Expand All @@ -182,35 +170,14 @@ impl<'hir> Map<'hir> {

#[inline]
pub fn opt_local_def_id(&self, hir_id: HirId) -> Option<LocalDefId> {
let node_id = self.hir_id_to_node_id(hir_id);
self.opt_local_def_id_from_node_id(node_id)
}

#[inline]
pub fn opt_local_def_id_from_node_id(&self, node: NodeId) -> Option<LocalDefId> {
self.tcx.definitions.opt_local_def_id(node)
self.tcx.definitions.opt_hir_id_to_local_def_id(hir_id)
}

#[inline]
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> HirId {
self.tcx.definitions.as_local_hir_id(def_id)
}

#[inline]
pub fn hir_id_to_node_id(&self, hir_id: HirId) -> NodeId {
self.tcx.definitions.hir_id_to_node_id(hir_id)
}

#[inline]
pub fn node_id_to_hir_id(&self, node_id: NodeId) -> HirId {
self.tcx.definitions.node_id_to_hir_id(node_id)
}

#[inline]
pub fn opt_node_id_to_hir_id(&self, node_id: NodeId) -> Option<HirId> {
self.tcx.definitions.opt_node_id_to_hir_id(node_id)
}

#[inline]
pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId {
self.tcx.definitions.local_def_id_to_hir_id(def_id)
Expand Down
96 changes: 58 additions & 38 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1623,12 +1623,17 @@ fn check_opaque_for_inheriting_lifetimes(tcx: TyCtxt<'tcx>, def_id: LocalDefId,
struct ProhibitOpaqueVisitor<'tcx> {
opaque_identity_ty: Ty<'tcx>,
generics: &'tcx ty::Generics,
ty: Option<Ty<'tcx>>,
};

impl<'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueVisitor<'tcx> {
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
debug!("check_opaque_for_inheriting_lifetimes: (visit_ty) t={:?}", t);
if t == self.opaque_identity_ty { false } else { t.super_visit_with(self) }
if t != self.opaque_identity_ty && t.super_visit_with(self) {
self.ty = Some(t);
return true;
}
false
}

fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
Expand All @@ -1651,46 +1656,61 @@ fn check_opaque_for_inheriting_lifetimes(tcx: TyCtxt<'tcx>, def_id: LocalDefId,
}
}

let prohibit_opaque = match item.kind {
ItemKind::OpaqueTy(hir::OpaqueTy {
origin: hir::OpaqueTyOrigin::AsyncFn | hir::OpaqueTyOrigin::FnReturn,
..
}) => {
let mut visitor = ProhibitOpaqueVisitor {
opaque_identity_ty: tcx.mk_opaque(
def_id.to_def_id(),
InternalSubsts::identity_for_item(tcx, def_id.to_def_id()),
),
generics: tcx.generics_of(def_id),
};
debug!("check_opaque_for_inheriting_lifetimes: visitor={:?}", visitor);

tcx.predicates_of(def_id)
.predicates
.iter()
.any(|(predicate, _)| predicate.visit_with(&mut visitor))
}
_ => false,
};

debug!("check_opaque_for_inheriting_lifetimes: prohibit_opaque={:?}", prohibit_opaque);
if prohibit_opaque {
let is_async = match item.kind {
ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => match origin {
hir::OpaqueTyOrigin::AsyncFn => true,
_ => false,
},
_ => unreachable!(),
if let ItemKind::OpaqueTy(hir::OpaqueTy {
origin: hir::OpaqueTyOrigin::AsyncFn | hir::OpaqueTyOrigin::FnReturn,
..
}) = item.kind
{
let mut visitor = ProhibitOpaqueVisitor {
opaque_identity_ty: tcx.mk_opaque(
def_id.to_def_id(),
InternalSubsts::identity_for_item(tcx, def_id.to_def_id()),
),
generics: tcx.generics_of(def_id),
ty: None,
};
let prohibit_opaque = tcx
.predicates_of(def_id)
.predicates
.iter()
.any(|(predicate, _)| predicate.visit_with(&mut visitor));
debug!(
"check_opaque_for_inheriting_lifetimes: prohibit_opaque={:?}, visitor={:?}",
prohibit_opaque, visitor
);

tcx.sess.span_err(
span,
&format!(
"`{}` return type cannot contain a projection or `Self` that references lifetimes from \
if prohibit_opaque {
let is_async = match item.kind {
ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => match origin {
hir::OpaqueTyOrigin::AsyncFn => true,
_ => false,
},
_ => unreachable!(),
};

let mut err = struct_span_err!(
tcx.sess,
span,
E0760,
"`{}` return type cannot contain a projection or `Self` that references lifetimes from \
a parent scope",
if is_async { "async fn" } else { "impl Trait" },
),
);
if is_async { "async fn" } else { "impl Trait" },
);

if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(span) {
if snippet == "Self" {
if let Some(ty) = visitor.ty {
err.span_suggestion(
span,
"consider spelling out the type instead",
format!("{:?}", ty),
Applicability::MaybeIncorrect,
);
}
}
}
err.emit();
}
}
}

Expand Down
39 changes: 39 additions & 0 deletions src/test/run-make-fulldeps/incr-add-rust-src-component/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-include ../tools.mk

# rust-lang/rust#70924: Test that if we add rust-src component in between two
# incremetnal compiles, the compiler does not ICE on the second.

SYSROOT:=$(shell $(RUSTC) --print sysroot)
FAKEROOT=$(TMPDIR)/fakeroot
INCR=$(TMPDIR)/incr

# Make a local copy of the sysroot; then remove the rust-src part of it, if
# present, for the *first* build. Then put in a facsimile of the rust-src
# component for the second build, in order to expose the ICE from issue #70924.
#
# Note that it is much easier to just do `cp -a $(SYSROOT)/* $(FAKEROOT)` as a
# first step, but I am concerned that would be too expensive in a unit test
# compared to making symbolic links.
#
# Anyway, the pattern you'll see here is: For every prefix in
# root/lib/rustlib/src, link all of prefix parent content, then remove the
# prefix, then loop on the next prefix. This way, we basically create a copy of
# the context around root/lib/rustlib/src, and can freely add/remove the src
# component itself.
all:
mkdir $(FAKEROOT)
ln -s $(SYSROOT)/* $(FAKEROOT)
rm -f $(FAKEROOT)/lib
mkdir $(FAKEROOT)/lib
ln -s $(SYSROOT)/lib/* $(FAKEROOT)/lib
rm -f $(FAKEROOT)/lib/rustlib
mkdir $(FAKEROOT)/lib/rustlib
ln -s $(SYSROOT)/lib/rustlib/* $(FAKEROOT)/lib/rustlib
rm -f $(FAKEROOT)/lib/rustlib/src
mkdir $(FAKEROOT)/lib/rustlib/src
ln -s $(SYSROOT)/lib/rustlib/src/* $(FAKEROOT)/lib/rustlib/src
rm -f $(FAKEROOT)/lib/rustlib/src/rust
$(RUSTC) --sysroot $(FAKEROOT) -C incremental=$(INCR) main.rs
mkdir -p $(FAKEROOT)/lib/rustlib/src/rust/src/libstd
touch $(FAKEROOT)/lib/rustlib/src/rust/src/libstd/lib.rs
$(RUSTC) --sysroot $(FAKEROOT) -C incremental=$(INCR) main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello World");
}
5 changes: 3 additions & 2 deletions src/test/ui/async-await/issue-61949-self-return-type.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
error: `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
error[E0760]: `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
--> $DIR/issue-61949-self-return-type.rs:11:40
|
LL | pub async fn new(_bar: &'a i32) -> Self {
| ^^^^
| ^^^^ help: consider spelling out the type instead: `Foo<'a>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0760`.
5 changes: 3 additions & 2 deletions src/test/ui/impl-trait/bound-normalization-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ help: consider constraining the associated type `<T as impl_trait::Trait>::Assoc
LL | fn foo_fail<T: Trait<Assoc = ()>>() -> impl FooLike<Output=T::Assoc> {
| ^^^^^^^^^^^^

error: `impl Trait` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
error[E0760]: `impl Trait` return type cannot contain a projection or `Self` that references lifetimes from a parent scope
--> $DIR/bound-normalization-fail.rs:43:41
|
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output=T::Assoc> {
Expand All @@ -43,4 +43,5 @@ LL | fn foo2_fail<'a, T: Trait<'a, Assoc = ()>>() -> impl FooLike<Output=T::

error: aborting due to 3 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0271`.
Some errors have detailed explanations: E0271, E0760.
For more information about an error, try `rustc --explain E0271`.