diff --git a/.mailmap b/.mailmap index 3b3e7334b75..a160f2f4fbf 100644 --- a/.mailmap +++ b/.mailmap @@ -111,6 +111,7 @@ Graydon Hoare Graydon Hoare Guillaume Gomez Guillaume Gomez ggomez Guillaume Gomez Guillaume Gomez +Guillaume Gomez Guillaume Gomez Hanna Kruppe Heather Heather diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 63000a9d13d..e599bf4cab0 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -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 diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index b4fd851f456..d602662ba6b 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -151,7 +151,7 @@ pub trait InferCtxtExt<'tcx> { outer_generator: Option, 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>>, ); @@ -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) @@ -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!( @@ -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() @@ -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, @@ -1617,7 +1605,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { outer_generator: Option, 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>>, ) { @@ -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); } @@ -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); @@ -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", - ); + ); + } } } } diff --git a/src/doc/reference b/src/doc/reference index b5c68b02984..a01d151a725 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit b5c68b02984f74e99d1f1b332029e05f607e2660 +Subproject commit a01d151a7250a540a9cb7ccce5956f020c677c21 diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide index fba15a46ca8..b06008731af 160000 --- a/src/doc/rustc-dev-guide +++ b/src/doc/rustc-dev-guide @@ -1 +1 @@ -Subproject commit fba15a46ca8efa97e8a955794724ac7ce27805b8 +Subproject commit b06008731af0f7d07cd0614e820c8276dfed1c18 diff --git a/src/test/ui/async-await/issues/issue-67893.rs b/src/test/ui/async-await/issues/issue-67893.rs index f34ce8081ca..8b53408d758 100644 --- a/src/test/ui/async-await/issues/issue-67893.rs +++ b/src/test/ui/async-await/issues/issue-67893.rs @@ -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 } diff --git a/src/test/ui/async-await/issues/issue-67893.stderr b/src/test/ui/async-await/issues/issue-67893.stderr index c4b55e6ec20..7321a38c021 100644 --- a/src/test/ui/async-await/issues/issue-67893.stderr +++ b/src/test/ui/async-await/issues/issue-67893.stderr @@ -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>, &'r Mutex<()>, Result, PoisonError>>, &'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 | @@ -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`. diff --git a/src/test/ui/resolve/issue-90113.rs b/src/test/ui/resolve/issue-90113.rs new file mode 100644 index 00000000000..f6658b45ed1 --- /dev/null +++ b/src/test/ui/resolve/issue-90113.rs @@ -0,0 +1,21 @@ +mod list { + pub use self::List::Cons; + + pub enum List { + Cons(T, Box>), + } +} + +mod alias { + use crate::list::List; + + pub type Foo = List; +} + +fn foo(l: crate::alias::Foo) { + match l { + Cons(..) => {} //~ ERROR: cannot find tuple struct or tuple variant `Cons` in this scope + } +} + +fn main() {} diff --git a/src/test/ui/resolve/issue-90113.stderr b/src/test/ui/resolve/issue-90113.stderr new file mode 100644 index 00000000000..1b78720571c --- /dev/null +++ b/src/test/ui/resolve/issue-90113.stderr @@ -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`. diff --git a/src/tools/tidy/src/edition.rs b/src/tools/tidy/src/edition.rs index b5e9ceddbaf..3f59fefd041 100644 --- a/src/tools/tidy/src/edition.rs +++ b/src/tools/tidy/src/edition.rs @@ -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!(