Skip to content

Commit

Permalink
Auto merge of #90249 - matthiaskrgr:rollup-xwtfhq3, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - #89889 (Use the "nice E0277 errors"[1] for `!Send` `impl Future` from foreign crate)
 - #90127 (Do not mention a reexported item if it's private)
 - #90143 (tidy: Remove submodules from edition exception list)
 - #90238 (Add alias for guillaume.gomez@huawei.com)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 25, 2021
2 parents 56694b0 + 34dcfd3 commit 32f3887
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 102 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Graydon Hoare <graydon@pobox.com> Graydon Hoare <graydon@mozilla.com>
Guillaume Gomez <guillaume1.gomez@gmail.com>
Guillaume Gomez <guillaume1.gomez@gmail.com> ggomez <ggomez@ggo.ifr.lan>
Guillaume Gomez <guillaume1.gomez@gmail.com> Guillaume Gomez <ggomez@ggo.ifr.lan>
Guillaume Gomez <guillaume1.gomez@gmail.com> Guillaume Gomez <guillaume.gomez@huawei.com>
Hanna Kruppe <hanna.kruppe@gmail.com> <robin.kruppe@gmail.com>
Heather <heather@cynede.net> <Cynede@Gentoo.org>
Heather <heather@cynede.net> <Heather@cynede.net>
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,15 @@ impl<'a> Resolver<'a> {
return;
}

// #90113: Do not count an inaccessible reexported item as a candidate.
if let NameBindingKind::Import { binding, .. } = name_binding.kind {
if this.is_accessible_from(binding.vis, parent_scope.module)
&& !this.is_accessible_from(name_binding.vis, parent_scope.module)
{
return;
}
}

// collect results based on the filter function
// avoid suggesting anything from the same module in which we are resolving
if ident.name == lookup_ident.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub trait InferCtxtExt<'tcx> {
outer_generator: Option<DefId>,
trait_ref: ty::TraitRef<'tcx>,
target_ty: Ty<'tcx>,
typeck_results: &ty::TypeckResults<'tcx>,
typeck_results: Option<&ty::TypeckResults<'tcx>>,
obligation: &PredicateObligation<'tcx>,
next_code: Option<&ObligationCauseCode<'tcx>>,
);
Expand Down Expand Up @@ -1460,11 +1460,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}

// Only continue if a generator was found.
debug!(
"maybe_note_obligation_cause_for_async_await: generator={:?} trait_ref={:?} \
target_ty={:?}",
generator, trait_ref, target_ty
);
debug!(?generator, ?trait_ref, ?target_ty, "maybe_note_obligation_cause_for_async_await");
let (generator_did, trait_ref, target_ty) = match (generator, trait_ref, target_ty) {
(Some(generator_did), Some(trait_ref), Some(target_ty)) => {
(generator_did, trait_ref, target_ty)
Expand All @@ -1474,14 +1470,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {

let span = self.tcx.def_span(generator_did);

// Do not ICE on closure typeck (#66868).
if !generator_did.is_local() {
return false;
}

// Get the typeck results from the infcx if the generator is the function we are
// currently type-checking; otherwise, get them by performing a query.
// This is needed to avoid cycles.
let in_progress_typeck_results = self.in_progress_typeck_results.map(|t| t.borrow());
let generator_did_root = self.tcx.closure_base_def_id(generator_did);
debug!(
Expand All @@ -1492,14 +1480,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
in_progress_typeck_results.as_ref().map(|t| t.hir_owner),
span
);
let query_typeck_results;
let typeck_results: &TypeckResults<'tcx> = match &in_progress_typeck_results {
Some(t) if t.hir_owner.to_def_id() == generator_did_root => t,
_ => {
query_typeck_results = self.tcx.typeck(generator_did.expect_local());
&query_typeck_results
}
};

let generator_body = generator_did
.as_local()
Expand Down Expand Up @@ -1542,51 +1522,59 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let mut interior_or_upvar_span = None;
let mut interior_extra_info = None;

if let Some(upvars) = self.tcx.upvars_mentioned(generator_did) {
interior_or_upvar_span = upvars.iter().find_map(|(upvar_id, upvar)| {
let upvar_ty = typeck_results.node_type(*upvar_id);
let upvar_ty = self.resolve_vars_if_possible(upvar_ty);
if ty_matches(ty::Binder::dummy(upvar_ty)) {
Some(GeneratorInteriorOrUpvar::Upvar(upvar.span))
} else {
None
}
});
// Get the typeck results from the infcx if the generator is the function we are currently
// type-checking; otherwise, get them by performing a query. This is needed to avoid
// cycles. If we can't use resolved types because the generator comes from another crate,
// we still provide a targeted error but without all the relevant spans.
let query_typeck_results;
let typeck_results: Option<&TypeckResults<'tcx>> = match &in_progress_typeck_results {
Some(t) if t.hir_owner.to_def_id() == generator_did_root => Some(&t),
_ if generator_did.is_local() => {
query_typeck_results = self.tcx.typeck(generator_did.expect_local());
Some(&query_typeck_results)
}
_ => None, // Do not ICE on closure typeck (#66868).
};
if let Some(typeck_results) = typeck_results {
if let Some(upvars) = self.tcx.upvars_mentioned(generator_did) {
interior_or_upvar_span = upvars.iter().find_map(|(upvar_id, upvar)| {
let upvar_ty = typeck_results.node_type(*upvar_id);
let upvar_ty = self.resolve_vars_if_possible(upvar_ty);
if ty_matches(ty::Binder::dummy(upvar_ty)) {
Some(GeneratorInteriorOrUpvar::Upvar(upvar.span))
} else {
None
}
});
};

// The generator interior types share the same binders
if let Some(cause) =
typeck_results.generator_interior_types.as_ref().skip_binder().iter().find(
|ty::GeneratorInteriorTypeCause { ty, .. }| {
ty_matches(typeck_results.generator_interior_types.rebind(ty))
},
)
{
// Check to see if any awaited expressions have the target type.
let from_awaited_ty = visitor
.awaits
.into_iter()
.map(|id| hir.expect_expr(id))
.find(|await_expr| {
let ty = typeck_results.expr_ty_adjusted(&await_expr);
debug!(
"maybe_note_obligation_cause_for_async_await: await_expr={:?}",
await_expr
);
ty_matches(ty::Binder::dummy(ty))
})
.map(|expr| expr.span);
let ty::GeneratorInteriorTypeCause { span, scope_span, yield_span, expr, .. } = cause;
// The generator interior types share the same binders
if let Some(cause) =
typeck_results.generator_interior_types.as_ref().skip_binder().iter().find(
|ty::GeneratorInteriorTypeCause { ty, .. }| {
ty_matches(typeck_results.generator_interior_types.rebind(ty))
},
)
{
// Check to see if any awaited expressions have the target type.
let from_awaited_ty = visitor
.awaits
.into_iter()
.map(|id| hir.expect_expr(id))
.find(|await_expr| {
ty_matches(ty::Binder::dummy(typeck_results.expr_ty_adjusted(&await_expr)))
})
.map(|expr| expr.span);
let ty::GeneratorInteriorTypeCause { span, scope_span, yield_span, expr, .. } =
cause;

interior_or_upvar_span = Some(GeneratorInteriorOrUpvar::Interior(*span));
interior_extra_info = Some((*scope_span, *yield_span, *expr, from_awaited_ty));
};
interior_or_upvar_span = Some(GeneratorInteriorOrUpvar::Interior(*span));
interior_extra_info = Some((*scope_span, *yield_span, *expr, from_awaited_ty));
};
} else {
interior_or_upvar_span = Some(GeneratorInteriorOrUpvar::Interior(span));
}

debug!(
"maybe_note_obligation_cause_for_async_await: interior_or_upvar={:?} \
generator_interior_types={:?}",
interior_or_upvar_span, typeck_results.generator_interior_types
);
if let Some(interior_or_upvar_span) = interior_or_upvar_span {
self.note_obligation_cause_for_async_await(
err,
Expand Down Expand Up @@ -1617,7 +1605,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
outer_generator: Option<DefId>,
trait_ref: ty::TraitRef<'tcx>,
target_ty: Ty<'tcx>,
typeck_results: &ty::TypeckResults<'tcx>,
typeck_results: Option<&ty::TypeckResults<'tcx>>,
obligation: &PredicateObligation<'tcx>,
next_code: Option<&ObligationCauseCode<'tcx>>,
) {
Expand Down Expand Up @@ -1828,7 +1816,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// Look at the last interior type to get a span for the `.await`.
debug!(
"note_obligation_cause_for_async_await generator_interior_types: {:#?}",
typeck_results.generator_interior_types
typeck_results.as_ref().map(|t| &t.generator_interior_types)
);
explain_yield(interior_span, yield_span, scope_span);
}
Expand All @@ -1849,10 +1837,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// ^^^^^^^ a temporary `&T` created inside this method call due to `&self`
// ```
//
let is_region_borrow = typeck_results
.expr_adjustments(expr)
.iter()
.any(|adj| adj.is_region_borrow());
let is_region_borrow = if let Some(typeck_results) = typeck_results {
typeck_results
.expr_adjustments(expr)
.iter()
.any(|adj| adj.is_region_borrow())
} else {
false
};

// ```rust
// struct Foo(*const u8);
Expand All @@ -1865,15 +1857,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
DefKind::Fn | DefKind::Ctor(..) => target_ty.is_unsafe_ptr(),
_ => false,
};

if (typeck_results.is_method_call(e) && is_region_borrow)
|| is_raw_borrow_inside_fn_like_call
{
err.span_help(
parent_span,
"consider moving this into a `let` \
if let Some(typeck_results) = typeck_results {
if (typeck_results.is_method_call(e) && is_region_borrow)
|| is_raw_borrow_inside_fn_like_call
{
err.span_help(
parent_span,
"consider moving this into a `let` \
binding to create a shorter lived borrow",
);
);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/doc/reference
2 changes: 1 addition & 1 deletion src/doc/rustc-dev-guide
2 changes: 1 addition & 1 deletion src/test/ui/async-await/issues/issue-67893.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ fn g(_: impl Send) {}

fn main() {
g(issue_67893::run())
//~^ ERROR: `MutexGuard<'_, ()>` cannot be sent between threads safely
//~^ ERROR generator cannot be sent between threads safely
}
15 changes: 2 additions & 13 deletions src/test/ui/async-await/issues/issue-67893.stderr
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
error[E0277]: `MutexGuard<'_, ()>` cannot be sent between threads safely
error: generator cannot be sent between threads safely
--> $DIR/issue-67893.rs:9:5
|
LL | g(issue_67893::run())
| ^ `MutexGuard<'_, ()>` cannot be sent between threads safely
|
::: $DIR/auxiliary/issue_67893.rs:7:20
|
LL | pub async fn run() {
| - within this `impl Future`
| ^ generator is not `Send`
|
= help: within `impl Future`, the trait `Send` is not implemented for `MutexGuard<'_, ()>`
= note: required because it appears within the type `for<'r, 's, 't0, 't1, 't2, 't3> {ResumeTy, Arc<Mutex<()>>, &'r Mutex<()>, Result<MutexGuard<'s, ()>, PoisonError<MutexGuard<'t0, ()>>>, &'t1 MutexGuard<'t2, ()>, MutexGuard<'t3, ()>, (), impl Future}`
= note: required because it appears within the type `[static generator@run::{closure#0}]`
= note: required because it appears within the type `from_generator::GenFuture<[static generator@run::{closure#0}]>`
= note: required because it appears within the type `impl Future`
= note: required because it appears within the type `impl Future`
note: required by a bound in `g`
--> $DIR/issue-67893.rs:6:14
|
Expand All @@ -23,4 +13,3 @@ LL | fn g(_: impl Send) {}

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
21 changes: 21 additions & 0 deletions src/test/ui/resolve/issue-90113.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
mod list {
pub use self::List::Cons;

pub enum List<T> {
Cons(T, Box<List<T>>),
}
}

mod alias {
use crate::list::List;

pub type Foo = List<String>;
}

fn foo(l: crate::alias::Foo) {
match l {
Cons(..) => {} //~ ERROR: cannot find tuple struct or tuple variant `Cons` in this scope
}
}

fn main() {}
14 changes: 14 additions & 0 deletions src/test/ui/resolve/issue-90113.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0531]: cannot find tuple struct or tuple variant `Cons` in this scope
--> $DIR/issue-90113.rs:17:9
|
LL | Cons(..) => {}
| ^^^^ not found in this scope
|
help: consider importing this tuple variant
|
LL | use list::List::Cons;
|

error: aborting due to previous error

For more information about this error, try `rustc --explain E0531`.
10 changes: 1 addition & 9 deletions src/tools/tidy/src/edition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,13 @@ pub fn check(path: &Path, bad: &mut bool) {
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
&mut |entry, contents| {
let file = entry.path();
let filestr = file.to_string_lossy().replace("\\", "/");
let filename = file.file_name().unwrap();
if filename != "Cargo.toml" {
return;
}

// Library crates are not yet ready to migrate to 2021.
//
// The reference and rustc-dev-guide are submodules, so are left at
// 2018 for now. They should be removed from this exception list
// when bumped.
if path.components().any(|c| c.as_os_str() == "library")
|| filestr.contains("src/doc/reference/style-check/Cargo.toml")
|| filestr.contains("src/doc/rustc-dev-guide/ci/date-check/Cargo.toml")
{
if path.components().any(|c| c.as_os_str() == "library") {
let has = contents.lines().any(is_edition_2018);
if !has {
tidy_error!(
Expand Down

0 comments on commit 32f3887

Please sign in to comment.