From 4a0473c0f5d6fa05d7c42df6ab1fa7f3729e0970 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Mon, 25 Jul 2022 15:45:36 +0300 Subject: [PATCH 1/8] Bubble up obligations --- compiler/rustc_traits/src/evaluate_obligation.rs | 4 ++-- compiler/rustc_traits/src/type_op.rs | 13 ++++++++----- .../issue-53398-cyclic-types.stderr | 4 +++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_traits/src/evaluate_obligation.rs b/compiler/rustc_traits/src/evaluate_obligation.rs index 3fc141471b92a..c8f12c876c020 100644 --- a/compiler/rustc_traits/src/evaluate_obligation.rs +++ b/compiler/rustc_traits/src/evaluate_obligation.rs @@ -1,4 +1,4 @@ -use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{ParamEnvAnd, TyCtxt}; use rustc_span::source_map::DUMMY_SP; @@ -16,7 +16,7 @@ fn evaluate_obligation<'tcx>( canonical_goal: CanonicalPredicateGoal<'tcx>, ) -> Result { debug!("evaluate_obligation(canonical_goal={:#?})", canonical_goal); - tcx.infer_ctxt().enter_with_canonical( + tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_with_canonical( DUMMY_SP, &canonical_goal, |ref infcx, goal, _canonical_inference_vars| { diff --git a/compiler/rustc_traits/src/type_op.rs b/compiler/rustc_traits/src/type_op.rs index f8bac1d7b263f..108a4c2e02d6b 100644 --- a/compiler/rustc_traits/src/type_op.rs +++ b/compiler/rustc_traits/src/type_op.rs @@ -2,7 +2,7 @@ use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_infer::infer::at::ToTrace; use rustc_infer::infer::canonical::{Canonical, QueryResponse}; -use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; +use rustc_infer::infer::{DefiningAnchor, InferCtxt, TyCtxtInferExt}; use rustc_infer::traits::TraitEngineExt as _; use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::{GenericArg, Subst, UserSelfTy, UserSubsts}; @@ -258,10 +258,13 @@ fn type_op_prove_predicate<'tcx>( tcx: TyCtxt<'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, ProvePredicate<'tcx>>>, ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> { - tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| { - type_op_prove_predicate_with_cause(infcx, fulfill_cx, key, ObligationCause::dummy()); - Ok(()) - }) + tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_canonical_trait_query( + &canonicalized, + |infcx, fulfill_cx, key| { + type_op_prove_predicate_with_cause(infcx, fulfill_cx, key, ObligationCause::dummy()); + Ok(()) + }, + ) } /// The core of the `type_op_prove_predicate` query: for diagnostics purposes in NLL HRTB errors, diff --git a/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr b/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr index 00c682b21939c..d20b1cc6d851b 100644 --- a/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr @@ -1,8 +1,10 @@ -error[E0275]: overflow evaluating the requirement ` Foo {foo} as FnOnce<()>>::Output == fn() -> Foo {foo}` +error[E0275]: overflow evaluating the requirement `fn() -> Foo {foo}: Sized` --> $DIR/issue-53398-cyclic-types.rs:5:13 | LL | fn foo() -> Foo { | ^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_53398_cyclic_types`) error: aborting due to previous error From 8716eae3b16cda362186765ad739ca56331728cf Mon Sep 17 00:00:00 2001 From: ouz-a Date: Wed, 27 Jul 2022 14:43:46 +0300 Subject: [PATCH 2/8] add tests and comment --- compiler/rustc_traits/src/evaluate_obligation.rs | 2 ++ compiler/rustc_traits/src/type_op.rs | 2 ++ src/test/ui/impl-trait/issue-99642-2.rs | 8 ++++++++ src/test/ui/impl-trait/issue-99642.rs | 7 +++++++ 4 files changed, 19 insertions(+) create mode 100644 src/test/ui/impl-trait/issue-99642-2.rs create mode 100644 src/test/ui/impl-trait/issue-99642.rs diff --git a/compiler/rustc_traits/src/evaluate_obligation.rs b/compiler/rustc_traits/src/evaluate_obligation.rs index c8f12c876c020..49c9ba459632d 100644 --- a/compiler/rustc_traits/src/evaluate_obligation.rs +++ b/compiler/rustc_traits/src/evaluate_obligation.rs @@ -16,6 +16,8 @@ fn evaluate_obligation<'tcx>( canonical_goal: CanonicalPredicateGoal<'tcx>, ) -> Result { debug!("evaluate_obligation(canonical_goal={:#?})", canonical_goal); + // HACK This bubble is required for this tests to pass: + // impl-trait/issue99642.rs tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_with_canonical( DUMMY_SP, &canonical_goal, diff --git a/compiler/rustc_traits/src/type_op.rs b/compiler/rustc_traits/src/type_op.rs index 108a4c2e02d6b..d895b647db0b1 100644 --- a/compiler/rustc_traits/src/type_op.rs +++ b/compiler/rustc_traits/src/type_op.rs @@ -258,6 +258,8 @@ fn type_op_prove_predicate<'tcx>( tcx: TyCtxt<'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, ProvePredicate<'tcx>>>, ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> { + // HACK This bubble is required for this test to pass: + // impl-trait/issue-99642.rs tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).enter_canonical_trait_query( &canonicalized, |infcx, fulfill_cx, key| { diff --git a/src/test/ui/impl-trait/issue-99642-2.rs b/src/test/ui/impl-trait/issue-99642-2.rs new file mode 100644 index 0000000000000..0e88b363338a9 --- /dev/null +++ b/src/test/ui/impl-trait/issue-99642-2.rs @@ -0,0 +1,8 @@ +// check-pass + +#![feature(type_alias_impl_trait)] +type Opq = impl Sized; +fn test() -> impl Iterator { + Box::new(0..) as Box> +} +fn main(){} diff --git a/src/test/ui/impl-trait/issue-99642.rs b/src/test/ui/impl-trait/issue-99642.rs new file mode 100644 index 0000000000000..75af60491e438 --- /dev/null +++ b/src/test/ui/impl-trait/issue-99642.rs @@ -0,0 +1,7 @@ +// check-pass + +fn test() -> impl Iterator { + Box::new(0..) as Box> +} + +fn main() {} From 9d118c5dcae473dab98fc150f581fa8d31e06811 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 27 Jul 2022 14:24:47 +0200 Subject: [PATCH 3/8] Fix settings display on small screen size --- src/librustdoc/html/static/css/settings.css | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/css/settings.css b/src/librustdoc/html/static/css/settings.css index e531e6ce6bbde..e82ec04263718 100644 --- a/src/librustdoc/html/static/css/settings.css +++ b/src/librustdoc/html/static/css/settings.css @@ -41,9 +41,7 @@ .toggle { position: relative; - display: inline-block; width: 100%; - height: 27px; margin-right: 20px; display: flex; align-items: center; @@ -58,6 +56,7 @@ .slider { position: relative; width: 45px; + min-width: 45px; display: block; height: 28px; margin-right: 20px; From 1564305a9f5448750fe3998f9c5272d0e36092e9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 27 Jul 2022 14:45:07 +0200 Subject: [PATCH 4/8] Add GUI test for settings in small device --- src/test/rustdoc-gui/settings.goml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/rustdoc-gui/settings.goml b/src/test/rustdoc-gui/settings.goml index 8a3365d3cc25e..d9cf5ee66140f 100644 --- a/src/test/rustdoc-gui/settings.goml +++ b/src/test/rustdoc-gui/settings.goml @@ -147,3 +147,12 @@ assert-false: "noscript section" javascript: false reload: assert-css: ("noscript section", {"display": "block"}) +javascript: true + +// Check for the display on small screen +show-text: true +reload: +size: (300, 1000) +click: "#settings-menu" +wait-for: "#settings" +assert-css: ("#settings .slider", {"width": "45px"}, ALL) From 0eb28abcc99476e1456874872545bf51bb2ff7a0 Mon Sep 17 00:00:00 2001 From: bstrie <865233+bstrie@users.noreply.github.com> Date: Wed, 27 Jul 2022 10:20:21 -0400 Subject: [PATCH 5/8] Allow using stable os::fd::raw items through unstable os::wasi module This fixes a regression from stable to nightly. Closes #99502. --- library/std/src/os/fd/raw.rs | 4 ++++ library/std/src/os/wasi/io/raw.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/library/std/src/os/fd/raw.rs b/library/std/src/os/fd/raw.rs index ff4e25b792ad0..081915ed148b3 100644 --- a/library/std/src/os/fd/raw.rs +++ b/library/std/src/os/fd/raw.rs @@ -14,6 +14,7 @@ use crate::os::wasi::io::OwnedFd; use crate::sys_common::{AsInner, IntoInner}; /// Raw file descriptors. +#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)] #[stable(feature = "rust1", since = "1.0.0")] pub type RawFd = raw::c_int; @@ -22,6 +23,7 @@ pub type RawFd = raw::c_int; /// This is only available on unix and WASI platforms and must be imported in /// order to call the method. Windows platforms have a corresponding /// `AsRawHandle` and `AsRawSocket` set of traits. +#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)] #[stable(feature = "rust1", since = "1.0.0")] pub trait AsRawFd { /// Extracts the raw file descriptor. @@ -57,6 +59,7 @@ pub trait AsRawFd { /// A trait to express the ability to construct an object from a raw file /// descriptor. +#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)] #[stable(feature = "from_raw_os", since = "1.1.0")] pub trait FromRawFd { /// Constructs a new instance of `Self` from the given raw file @@ -100,6 +103,7 @@ pub trait FromRawFd { /// A trait to express the ability to consume an object and acquire ownership of /// its raw file descriptor. +#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)] #[stable(feature = "into_raw_os", since = "1.4.0")] pub trait IntoRawFd { /// Consumes this object, returning the raw underlying file descriptor. diff --git a/library/std/src/os/wasi/io/raw.rs b/library/std/src/os/wasi/io/raw.rs index 0e0c5824e3404..da3b36adad409 100644 --- a/library/std/src/os/wasi/io/raw.rs +++ b/library/std/src/os/wasi/io/raw.rs @@ -2,4 +2,19 @@ #![unstable(feature = "wasi_ext", issue = "71213")] +// NOTE: despite the fact that this module is unstable, +// stable Rust had the capability to access the stable +// re-exported items from os::fd::raw through this +// unstable module. +// In PR #95956 the stability checker was changed to check +// all path segments of an item rather than just the last, +// which caused the aforementioned stable usage to regress +// (see issue #99502). +// As a result, the items in os::fd::raw were given the +// rustc_allowed_through_unstable_modules attribute. +// No regression tests were added to ensure this property, +// as CI is not configured to test wasm32-wasi. +// If this module is stabilized, +// you may want to remove those attributes +// (assuming no other unstable modules need them). pub use crate::os::fd::raw::*; From 3cbc94427cb00ff53b0b085acacc7219a32a444f Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Thu, 28 Jul 2022 10:20:55 +0900 Subject: [PATCH 6/8] avoid `Symbol` to `String` conversions --- compiler/rustc_expand/src/config.rs | 2 +- .../src/traits/error_reporting/suggestions.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs index 2b941ec68098a..ccc29adc0153e 100644 --- a/compiler/rustc_expand/src/config.rs +++ b/compiler/rustc_expand/src/config.rs @@ -129,7 +129,7 @@ fn get_features( .span_suggestion( mi.span(), "expected just one word", - format!("{}", ident.name), + ident.name, Applicability::MaybeIncorrect, ) .emit(); 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 7ab85e7fa663e..ecb9d473c0053 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -184,7 +184,7 @@ pub trait InferCtxtExt<'tcx> { trait_pred: ty::PolyTraitPredicate<'tcx>, ) -> bool; - fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option; + fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option; fn suggest_fn_call( &self, @@ -737,13 +737,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { /// Given a closure's `DefId`, return the given name of the closure. /// /// This doesn't account for reassignments, but it's only used for suggestions. - fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option { - let get_name = |err: &mut Diagnostic, kind: &hir::PatKind<'_>| -> Option { + fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option { + let get_name = |err: &mut Diagnostic, kind: &hir::PatKind<'_>| -> Option { // Get the local name of this closure. This can be inaccurate because // of the possibility of reassignment, but this should be good enough. match &kind { - hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => { - Some(format!("{}", name)) + hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, None) => { + Some(ident.name) } _ => { err.note(msg); From 089471b129896fbaedaf99b8d60df109b4a2fb0e Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Thu, 28 Jul 2022 18:17:55 +0900 Subject: [PATCH 7/8] change the type of `note` field to `Option` --- compiler/rustc_resolve/src/diagnostics.rs | 31 ++++++++++------------- compiler/rustc_resolve/src/imports.rs | 16 +++++------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 0343e8d9b8ec3..22a307a15edc0 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -2023,7 +2023,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { span: Span, mut path: Vec, parent_scope: &ParentScope<'b>, - ) -> Option<(Vec, Vec)> { + ) -> Option<(Vec, Option)> { debug!("make_path_suggestion: span={:?} path={:?}", span, path); match (path.get(0), path.get(1)) { @@ -2058,12 +2058,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> { &mut self, mut path: Vec, parent_scope: &ParentScope<'b>, - ) -> Option<(Vec, Vec)> { + ) -> Option<(Vec, Option)> { // Replace first ident with `self` and check if that is valid. path[0].ident.name = kw::SelfLower; let result = self.r.maybe_resolve_path(&path, None, parent_scope); debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result); - if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None } + if let PathResult::Module(..) = result { Some((path, None)) } else { None } } /// Suggests a missing `crate::` if that resolves to an correct module. @@ -2077,7 +2077,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { &mut self, mut path: Vec, parent_scope: &ParentScope<'b>, - ) -> Option<(Vec, Vec)> { + ) -> Option<(Vec, Option)> { // Replace first ident with `crate` and check if that is valid. path[0].ident.name = kw::Crate; let result = self.r.maybe_resolve_path(&path, None, parent_scope); @@ -2085,12 +2085,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> { if let PathResult::Module(..) = result { Some(( path, - vec![ + Some( "`use` statements changed in Rust 2018; read more at \ " .to_string(), - ], + ), )) } else { None @@ -2108,12 +2108,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> { &mut self, mut path: Vec, parent_scope: &ParentScope<'b>, - ) -> Option<(Vec, Vec)> { + ) -> Option<(Vec, Option)> { // Replace first ident with `crate` and check if that is valid. path[0].ident.name = kw::Super; let result = self.r.maybe_resolve_path(&path, None, parent_scope); debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result); - if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None } + if let PathResult::Module(..) = result { Some((path, None)) } else { None } } /// Suggests a missing external crate name if that resolves to an correct module. @@ -2130,7 +2130,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { &mut self, mut path: Vec, parent_scope: &ParentScope<'b>, - ) -> Option<(Vec, Vec)> { + ) -> Option<(Vec, Option)> { if path[1].ident.span.rust_2015() { return None; } @@ -2151,7 +2151,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { name, path, result ); if let PathResult::Module(..) = result { - return Some((path, Vec::new())); + return Some((path, None)); } } @@ -2175,7 +2175,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { import: &'b Import<'b>, module: ModuleOrUniformRoot<'b>, ident: Ident, - ) -> Option<(Option, Vec)> { + ) -> Option<(Option, Option)> { let ModuleOrUniformRoot::Module(mut crate_module) = module else { return None; }; @@ -2287,12 +2287,9 @@ impl<'a, 'b> ImportResolver<'a, 'b> { String::from("a macro with this name exists at the root of the crate"), Applicability::MaybeIncorrect, )); - let note = vec![ - "this could be because a macro annotated with `#[macro_export]` will be exported \ - at the root of the crate instead of the module where it is defined" - .to_string(), - ]; - Some((suggestion, note)) + Some((suggestion, Some("this could be because a macro annotated with `#[macro_export]` will be exported \ + at the root of the crate instead of the module where it is defined" + .to_string()))) } else { None } diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index e6060ad46650e..b89273990d8e5 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -336,7 +336,7 @@ impl<'a> Resolver<'a> { struct UnresolvedImportError { span: Span, label: Option, - note: Vec, + note: Option, suggestion: Option, } @@ -427,7 +427,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { let err = UnresolvedImportError { span: import.span, label: None, - note: Vec::new(), + note: None, suggestion: None, }; if path.contains("::") { @@ -463,10 +463,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> { let mut diag = struct_span_err!(self.r.session, span, E0432, "{}", &msg); - if let Some((_, UnresolvedImportError { note, .. })) = errors.iter().last() { - for message in note { - diag.note(message); - } + if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.iter().last() { + diag.note(note); } for (_, err) in errors.into_iter().take(MAX_LABEL_COUNT) { @@ -644,7 +642,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { None => UnresolvedImportError { span, label: Some(label), - note: Vec::new(), + note: None, suggestion, }, }; @@ -686,7 +684,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { return Some(UnresolvedImportError { span: import.span, label: Some(String::from("cannot glob-import a module into itself")), - note: Vec::new(), + note: None, suggestion: None, }); } @@ -830,7 +828,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { let (suggestion, note) = match self.check_for_module_export_macro(import, module, ident) { Some((suggestion, note)) => (suggestion.or(lev_suggestion), note), - _ => (lev_suggestion, Vec::new()), + _ => (lev_suggestion, None), }; let label = match module { From 2ce42eb79cb66d4e1fc80cdba9547b2603824537 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Thu, 28 Jul 2022 18:28:29 +0900 Subject: [PATCH 8/8] remove an unnecessary line break --- compiler/rustc_parse/src/parser/item.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 87bc0d9762ea5..a14a7fc0610cb 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1677,7 +1677,6 @@ impl<'a> Parser<'a> { } /// Is this a possibly malformed start of a `macro_rules! foo` item definition? - fn is_macro_rules_item(&mut self) -> IsMacroRulesItem { if self.check_keyword(kw::MacroRules) { let macro_rules_span = self.token.span;