From 241435737451c521a78faab31c54457b1cb97413 Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 20 Oct 2022 19:40:21 +0800 Subject: [PATCH 01/12] fix assertion failed for break_last_token and trailing token --- .../rustc_parse/src/parser/attr_wrapper.rs | 13 +++++++----- compiler/rustc_parse/src/parser/expr.rs | 2 ++ compiler/rustc_parse/src/parser/mod.rs | 1 + src/test/ui/parser/issue-103143.rs | 5 +++++ src/test/ui/parser/issue-103143.stderr | 20 +++++++++++++++++++ 5 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/parser/issue-103143.rs create mode 100644 src/test/ui/parser/issue-103143.stderr diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index 81c051b8f35e4..1b16ecb5ec2d6 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -273,16 +273,23 @@ impl<'a> Parser<'a> { let cursor_snapshot_next_calls = cursor_snapshot.num_next_calls; let mut end_pos = self.token_cursor.num_next_calls; + let mut captured_trailing = false; + // Capture a trailing token if requested by the callback 'f' match trailing { TrailingToken::None => {} + TrailingToken::Gt => { + assert_eq!(self.token.kind, token::Gt); + } TrailingToken::Semi => { assert_eq!(self.token.kind, token::Semi); end_pos += 1; + captured_trailing = true; } TrailingToken::MaybeComma => { if self.token.kind == token::Comma { end_pos += 1; + captured_trailing = true; } } } @@ -292,11 +299,7 @@ impl<'a> Parser<'a> { // was not actually bumped past it. When the `LazyAttrTokenStream` gets converted // into an `AttrTokenStream`, we will create the proper token. if self.token_cursor.break_last_token { - assert_eq!( - trailing, - TrailingToken::None, - "Cannot set `break_last_token` and have trailing token" - ); + assert!(!captured_trailing, "Cannot set break_last_token and have trailing token"); end_pos += 1; } diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index afa116ce1bccd..d9d20195c5f81 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -3080,6 +3080,8 @@ impl<'a> Parser<'a> { && this.token.kind == token::Semi { TrailingToken::Semi + } else if this.token.kind == token::Gt { + TrailingToken::Gt } else { // FIXME - pass this through from the place where we know // we need a comma, rather than assuming that `#[attr] expr,` diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index b934e087608a5..89c24920f857d 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -79,6 +79,7 @@ pub enum ForceCollect { pub enum TrailingToken { None, Semi, + Gt, /// If the trailing token is a comma, then capture it /// Otherwise, ignore the trailing token MaybeComma, diff --git a/src/test/ui/parser/issue-103143.rs b/src/test/ui/parser/issue-103143.rs new file mode 100644 index 0000000000000..a584274c40514 --- /dev/null +++ b/src/test/ui/parser/issue-103143.rs @@ -0,0 +1,5 @@ +fn main() { + x::<#[a]y::> + //~^ ERROR invalid const generic expression + //~| ERROR cannot find value `x` in this scope +} diff --git a/src/test/ui/parser/issue-103143.stderr b/src/test/ui/parser/issue-103143.stderr new file mode 100644 index 0000000000000..4035c69afa712 --- /dev/null +++ b/src/test/ui/parser/issue-103143.stderr @@ -0,0 +1,20 @@ +error: invalid const generic expression + --> $DIR/issue-103143.rs:2:13 + | +LL | x::<#[a]y::> + | ^^^^^^ + | +help: expressions must be enclosed in braces to be used as const generic arguments + | +LL | x::<#[a]{ y:: }> + | + + + +error[E0425]: cannot find value `x` in this scope + --> $DIR/issue-103143.rs:2:5 + | +LL | x::<#[a]y::> + | ^ not found in this scope + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0425`. From 717bf35366e2baf44e0c9a6594041d58d35a0f13 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Fri, 21 Oct 2022 14:38:44 +0100 Subject: [PATCH 02/12] Different suggestions for when associated functions are referred to --- .../rustc_resolve/src/late/diagnostics.rs | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 4fd5bc1d60a47..6de63282df4e2 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -38,8 +38,8 @@ type Res = def::Res; /// A field or associated item from self type suggested in case of resolution failure. enum AssocSuggestion { Field, - MethodWithSelf, - AssocFn, + MethodWithSelf { called: bool }, + AssocFn { called: bool }, AssocType, AssocConst, } @@ -48,8 +48,14 @@ impl AssocSuggestion { fn action(&self) -> &'static str { match self { AssocSuggestion::Field => "use the available field", - AssocSuggestion::MethodWithSelf => "call the method with the fully-qualified path", - AssocSuggestion::AssocFn => "call the associated function", + AssocSuggestion::MethodWithSelf { called: true } => { + "call the method with the fully-qualified path" + } + AssocSuggestion::MethodWithSelf { called: false } => { + "refer to the method with the fully-qualified path" + } + AssocSuggestion::AssocFn { called: true } => "call the associated function", + AssocSuggestion::AssocFn { called: false } => "refer to the associated function", AssocSuggestion::AssocConst => "use the associated `const`", AssocSuggestion::AssocType => "use the associated type", } @@ -498,7 +504,9 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { // Try Levenshtein algorithm. let typo_sugg = self.lookup_typo_candidate(path, source.namespace(), is_expected); if path.len() == 1 && self.self_type_is_available() { - if let Some(candidate) = self.lookup_assoc_candidate(ident, ns, is_expected) { + if let Some(candidate) = + self.lookup_assoc_candidate(ident, ns, is_expected, source.is_call()) + { let self_is_available = self.self_value_is_available(path[0].ident.span); match candidate { AssocSuggestion::Field => { @@ -513,16 +521,21 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { err.span_label(span, "a field by this name exists in `Self`"); } } - AssocSuggestion::MethodWithSelf if self_is_available => { + AssocSuggestion::MethodWithSelf { called } if self_is_available => { + let msg = if called { + "you might have meant to call the method" + } else { + "you might have meant to refer to the method" + }; err.span_suggestion( span, - "you might have meant to call the method", + msg, format!("self.{path_str}"), Applicability::MachineApplicable, ); } - AssocSuggestion::MethodWithSelf - | AssocSuggestion::AssocFn + AssocSuggestion::MethodWithSelf { .. } + | AssocSuggestion::AssocFn { .. } | AssocSuggestion::AssocConst | AssocSuggestion::AssocType => { err.span_suggestion( @@ -1494,6 +1507,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { ident: Ident, ns: Namespace, filter_fn: FilterFn, + called: bool, ) -> Option where FilterFn: Fn(Res) -> bool, @@ -1535,9 +1549,9 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { return Some(match &assoc_item.kind { ast::AssocItemKind::Const(..) => AssocSuggestion::AssocConst, ast::AssocItemKind::Fn(box ast::Fn { sig, .. }) if sig.decl.has_self() => { - AssocSuggestion::MethodWithSelf + AssocSuggestion::MethodWithSelf { called } } - ast::AssocItemKind::Fn(..) => AssocSuggestion::AssocFn, + ast::AssocItemKind::Fn(..) => AssocSuggestion::AssocFn { called }, ast::AssocItemKind::Type(..) => AssocSuggestion::AssocType, ast::AssocItemKind::MacCall(_) => continue, }); @@ -1556,10 +1570,12 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { let res = binding.res(); if filter_fn(res) { if self.r.has_self.contains(&res.def_id()) { - return Some(AssocSuggestion::MethodWithSelf); + return Some(AssocSuggestion::MethodWithSelf { called }); } else { match res { - Res::Def(DefKind::AssocFn, _) => return Some(AssocSuggestion::AssocFn), + Res::Def(DefKind::AssocFn, _) => { + return Some(AssocSuggestion::AssocFn { called }); + } Res::Def(DefKind::AssocConst, _) => { return Some(AssocSuggestion::AssocConst); } From 3f1e99936a821976fec469dd503ad1bdcad423e7 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Fri, 21 Oct 2022 14:43:58 +0100 Subject: [PATCH 03/12] Update UI tests --- src/test/ui/resolve/issue-14254.stderr | 49 ++++++++++++++++--- .../resolve/resolve-assoc-suggestions.stderr | 2 +- ...e-with-name-similar-to-struct-field.stderr | 2 +- 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/test/ui/resolve/issue-14254.stderr b/src/test/ui/resolve/issue-14254.stderr index c848014ad8f0f..690a40f7edd77 100644 --- a/src/test/ui/resolve/issue-14254.stderr +++ b/src/test/ui/resolve/issue-14254.stderr @@ -26,7 +26,12 @@ error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:36:9 | LL | bah; - | ^^^ help: you might have meant to call the associated function: `Self::bah` + | ^^^ + | +help: you might have meant to refer to the associated function + | +LL | Self::bah; + | ~~~~~~~~~ error[E0425]: cannot find value `b` in this scope --> $DIR/issue-14254.rs:38:9 @@ -56,7 +61,12 @@ error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:53:9 | LL | bah; - | ^^^ help: you might have meant to call the associated function: `Self::bah` + | ^^^ + | +help: you might have meant to refer to the associated function + | +LL | Self::bah; + | ~~~~~~~~~ error[E0425]: cannot find value `b` in this scope --> $DIR/issue-14254.rs:55:9 @@ -68,31 +78,56 @@ error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:64:9 | LL | bah; - | ^^^ help: you might have meant to call the associated function: `Self::bah` + | ^^^ + | +help: you might have meant to refer to the associated function + | +LL | Self::bah; + | ~~~~~~~~~ error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:73:9 | LL | bah; - | ^^^ help: you might have meant to call the associated function: `Self::bah` + | ^^^ + | +help: you might have meant to refer to the associated function + | +LL | Self::bah; + | ~~~~~~~~~ error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:82:9 | LL | bah; - | ^^^ help: you might have meant to call the associated function: `Self::bah` + | ^^^ + | +help: you might have meant to refer to the associated function + | +LL | Self::bah; + | ~~~~~~~~~ error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:91:9 | LL | bah; - | ^^^ help: you might have meant to call the associated function: `Self::bah` + | ^^^ + | +help: you might have meant to refer to the associated function + | +LL | Self::bah; + | ~~~~~~~~~ error[E0425]: cannot find value `bah` in this scope --> $DIR/issue-14254.rs:100:9 | LL | bah; - | ^^^ help: you might have meant to call the associated function: `Self::bah` + | ^^^ + | +help: you might have meant to refer to the associated function + | +LL | Self::bah; + | ~~~~~~~~~ error[E0425]: cannot find function `baz` in this scope --> $DIR/issue-14254.rs:19:9 diff --git a/src/test/ui/resolve/resolve-assoc-suggestions.stderr b/src/test/ui/resolve/resolve-assoc-suggestions.stderr index b6acaeb8cc232..8def9aa20253b 100644 --- a/src/test/ui/resolve/resolve-assoc-suggestions.stderr +++ b/src/test/ui/resolve/resolve-assoc-suggestions.stderr @@ -50,7 +50,7 @@ error[E0425]: cannot find value `method` in this scope --> $DIR/resolve-assoc-suggestions.rs:34:9 | LL | method; - | ^^^^^^ help: you might have meant to call the method: `self.method` + | ^^^^^^ help: you might have meant to refer to the method: `self.method` error: aborting due to 9 previous errors diff --git a/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr b/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr index 2764e1f813287..f32e0404e46cb 100644 --- a/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr +++ b/src/test/ui/resolve/typo-suggestion-for-variable-with-name-similar-to-struct-field.stderr @@ -40,7 +40,7 @@ LL | bah; LL | fn ba() {} | ------- similarly named function `ba` defined here | -help: you might have meant to call the associated function +help: you might have meant to refer to the associated function | LL | Self::bah; | ~~~~~~~~~ From e025306fa050ac593bff366eb1c9bff7bfd00b1d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 22 Oct 2022 02:48:36 +0000 Subject: [PATCH 04/12] Don't ICE on regions from anonymous_lifetime_in_impl_trait --- .../src/diagnostics/region_name.rs | 100 ++++++++++++++++-- .../ui/borrowck/anonymous-region-in-apit.rs | 12 +++ .../borrowck/anonymous-region-in-apit.stderr | 16 +++ 3 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 src/test/ui/borrowck/anonymous-region-in-apit.rs create mode 100644 src/test/ui/borrowck/anonymous-region-in-apit.stderr diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 4d251cf7ac752..c044dbaba47e2 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -251,7 +251,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { .or_else(|| self.give_name_if_anonymous_region_appears_in_upvars(fr)) .or_else(|| self.give_name_if_anonymous_region_appears_in_output(fr)) .or_else(|| self.give_name_if_anonymous_region_appears_in_yield_ty(fr)) - .or_else(|| self.give_name_if_anonymous_region_appears_in_impl_signature(fr)); + .or_else(|| self.give_name_if_anonymous_region_appears_in_impl_signature(fr)) + .or_else(|| self.give_name_if_anonymous_region_appears_in_arg_position_impl_trait(fr)); if let Some(ref value) = value { self.region_names.try_borrow_mut().unwrap().insert(fr, value.clone()); @@ -869,13 +870,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { return None; } - let mut found = false; - tcx.fold_regions(tcx.type_of(region_parent), |r: ty::Region<'tcx>, _| { - if *r == ty::ReEarlyBound(region) { - found = true; - } - r - }); + let found = tcx + .any_free_region_meets(&tcx.type_of(region_parent), |r| *r == ty::ReEarlyBound(region)); Some(RegionName { name: self.synthesize_region_name(), @@ -888,4 +884,92 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> { ), }) } + + fn give_name_if_anonymous_region_appears_in_arg_position_impl_trait( + &self, + fr: RegionVid, + ) -> Option { + let ty::ReEarlyBound(region) = *self.to_error_region(fr)? else { + return None; + }; + if region.has_name() { + return None; + }; + + let predicates = self + .infcx + .tcx + .predicates_of(self.body.source.def_id()) + .instantiate_identity(self.infcx.tcx) + .predicates; + + if let Some(upvar_index) = self + .regioncx + .universal_regions() + .defining_ty + .upvar_tys() + .position(|ty| self.any_param_predicate_mentions(&predicates, ty, region)) + { + let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region( + self.infcx.tcx, + &self.upvars, + upvar_index, + ); + let region_name = self.synthesize_region_name(); + + Some(RegionName { + name: region_name, + source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name), + }) + } else if let Some(arg_index) = self + .regioncx + .universal_regions() + .unnormalized_input_tys + .iter() + .position(|ty| self.any_param_predicate_mentions(&predicates, *ty, region)) + { + let (arg_name, arg_span) = self.regioncx.get_argument_name_and_span_for_region( + self.body, + &self.local_names, + arg_index, + ); + let region_name = self.synthesize_region_name(); + + Some(RegionName { + name: region_name, + source: RegionNameSource::AnonRegionFromArgument( + RegionNameHighlight::CannotMatchHirTy(arg_span, arg_name?.to_string()), + ), + }) + } else { + None + } + } + + fn any_param_predicate_mentions( + &self, + predicates: &[ty::Predicate<'tcx>], + ty: Ty<'tcx>, + region: ty::EarlyBoundRegion, + ) -> bool { + let tcx = self.infcx.tcx; + ty.walk().any(|arg| { + if let ty::GenericArgKind::Type(ty) = arg.unpack() + && let ty::Param(_) = ty.kind() + { + predicates.iter().any(|pred| { + match pred.kind().skip_binder() { + ty::PredicateKind::Trait(data) if data.self_ty() == ty => {} + ty::PredicateKind::Projection(data) if data.projection_ty.self_ty() == ty => {} + _ => return false, + } + tcx.any_free_region_meets(pred, |r| { + *r == ty::ReEarlyBound(region) + }) + }) + } else { + false + } + }) + } } diff --git a/src/test/ui/borrowck/anonymous-region-in-apit.rs b/src/test/ui/borrowck/anonymous-region-in-apit.rs new file mode 100644 index 0000000000000..7799a7cb151de --- /dev/null +++ b/src/test/ui/borrowck/anonymous-region-in-apit.rs @@ -0,0 +1,12 @@ +#![feature(anonymous_lifetime_in_impl_trait)] + +trait Foo { + fn bar(self, baz: T); +} + +fn qux(foo: impl Foo<&str>) { + |baz: &str| foo.bar(baz); + //~^ ERROR borrowed data escapes outside of closure +} + +fn main() {} diff --git a/src/test/ui/borrowck/anonymous-region-in-apit.stderr b/src/test/ui/borrowck/anonymous-region-in-apit.stderr new file mode 100644 index 0000000000000..9e100f8ac3c50 --- /dev/null +++ b/src/test/ui/borrowck/anonymous-region-in-apit.stderr @@ -0,0 +1,16 @@ +error[E0521]: borrowed data escapes outside of closure + --> $DIR/anonymous-region-in-apit.rs:8:17 + | +LL | fn qux(foo: impl Foo<&str>) { + | --- lifetime `'2` appears in the type of `foo` +LL | |baz: &str| foo.bar(baz); + | --- - ^^^^^^^^^^^^ + | | | | + | | | `baz` escapes the closure body here + | | | argument requires that `'1` must outlive `'2` + | | let's call the lifetime of this reference `'1` + | `baz` is a reference that is only valid in the closure body + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0521`. From 45a9d18969894757ab3294fd95242cc9bde4be6c Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 23 Oct 2022 22:16:13 -0700 Subject: [PATCH 05/12] rustdoc: remove no-op CSS `.source pre.rust { white-space: pre }` This rule, added in 49e6db7f3510a99ab3d3723b2430add985629c39, overrode a rule in normalize.css. https://github.com/rust-lang/rust/blob/49e6db7f3510a99ab3d3723b2430add985629c39/src/librustdoc/html/static/normalize.css#L169-L175 When normalize.css was updated, this rule went away. https://github.com/necolas/normalize.css/commit/a8edd0c5aa06b905e8e1550fd6a5c01e46375194 --- src/librustdoc/html/static/css/rustdoc.css | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 293c9787609b0..8a9a74a0ce399 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -538,7 +538,6 @@ ul.block, .block li { } .source .content pre.rust { - white-space: pre; overflow: auto; padding-left: 0; } From e3a091ad6ab9cdc8b25da1bc52093023bc90e232 Mon Sep 17 00:00:00 2001 From: Jesse Ruderman Date: Mon, 24 Oct 2022 00:52:26 -0700 Subject: [PATCH 06/12] Remove redundant sentence --- compiler/rustc_error_codes/src/error_codes/E0210.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0210.md b/compiler/rustc_error_codes/src/error_codes/E0210.md index dc2fd9b0ca049..41263e5e3f5ac 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0210.md +++ b/compiler/rustc_error_codes/src/error_codes/E0210.md @@ -76,7 +76,5 @@ Let `Ti` be the first such type. For information on the design of the orphan rules, see [RFC 2451] and [RFC 1023]. -For information on the design of the orphan rules, see [RFC 1023]. - [RFC 2451]: https://rust-lang.github.io/rfcs/2451-re-rebalancing-coherence.html [RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md From c2bc3bcfb04707dedfc24881746054086198b6e5 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sat, 22 Oct 2022 13:29:10 -0500 Subject: [PATCH 07/12] Document link to unstable book --- src/doc/rustc/src/command-line-arguments.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/rustc/src/command-line-arguments.md b/src/doc/rustc/src/command-line-arguments.md index 2d12cf382b160..2dc182b3d83ed 100644 --- a/src/doc/rustc/src/command-line-arguments.md +++ b/src/doc/rustc/src/command-line-arguments.md @@ -302,7 +302,7 @@ _Note:_ The order of these lint level arguments is taken into account, see [lint This flag will allow you to set unstable options of rustc. In order to set multiple options, the -Z flag can be used multiple times. For example: `rustc -Z verbose -Z time-passes`. Specifying options with -Z is only available on nightly. To view all available options -run: `rustc -Z help`. +run: `rustc -Z help`, or see [The Unstable Book](../unstable-book/index.html). ## `--cap-lints`: set the most restrictive lint level From 1dff99f46c7698c4e7ca231572e4c3794b6b52b5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 24 Oct 2022 17:44:17 +0200 Subject: [PATCH 08/12] Use functions in highlight-colors rustdoc GUI test --- src/test/rustdoc-gui/highlight-colors.goml | 141 +++++++++++++-------- 1 file changed, 89 insertions(+), 52 deletions(-) diff --git a/src/test/rustdoc-gui/highlight-colors.goml b/src/test/rustdoc-gui/highlight-colors.goml index dd01dbf6148d2..51693314e85ef 100644 --- a/src/test/rustdoc-gui/highlight-colors.goml +++ b/src/test/rustdoc-gui/highlight-colors.goml @@ -2,56 +2,93 @@ goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" show-text: true -local-storage: {"rustdoc-theme": "ayu", "rustdoc-use-system-theme": "false"} -reload: +define-function: ( + "check-colors", + ( + theme, + kw, + kw2, + prelude_ty, + prelude_val, + lifetime, + number, + string, + bool_val, + self, + attribute, + macro, + question_mark, + comment, + doc_comment, + ), + [ + ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}), + ("reload"), + ("assert-css", ("pre.rust .kw", {"color": |kw|}, ALL)), + ("assert-css", ("pre.rust .kw-2", {"color": |kw2|}, ALL)), + ("assert-css", ("pre.rust .prelude-ty", {"color": |prelude_ty|}, ALL)), + ("assert-css", ("pre.rust .prelude-val", {"color": |prelude_val|}, ALL)), + ("assert-css", ("pre.rust .lifetime", {"color": |lifetime|}, ALL)), + ("assert-css", ("pre.rust .number", {"color": |number|}, ALL)), + ("assert-css", ("pre.rust .string", {"color": |string|}, ALL)), + ("assert-css", ("pre.rust .bool-val", {"color": |bool_val|}, ALL)), + ("assert-css", ("pre.rust .self", {"color": |self|}, ALL)), + ("assert-css", ("pre.rust .attribute", {"color": |attribute|}, ALL)), + ("assert-css", ("pre.rust .macro", {"color": |macro|}, ALL)), + ("assert-css", ("pre.rust .question-mark", {"color": |question_mark|}, ALL)), + ("assert-css", ("pre.rust .comment", {"color": |comment|}, ALL)), + ("assert-css", ("pre.rust .doccomment", {"color": |doc_comment|}, ALL)), + ], +) -assert-css: ("pre.rust .kw", {"color": "rgb(255, 119, 51)"}, ALL) -assert-css: ("pre.rust .kw-2", {"color": "rgb(255, 119, 51)"}, ALL) -assert-css: ("pre.rust .prelude-ty", {"color": "rgb(105, 242, 223)"}, ALL) -assert-css: ("pre.rust .prelude-val", {"color": "rgb(255, 119, 51)"}, ALL) -assert-css: ("pre.rust .lifetime", {"color": "rgb(255, 119, 51)"}, ALL) -assert-css: ("pre.rust .number", {"color": "rgb(184, 204, 82)"}, ALL) -assert-css: ("pre.rust .string", {"color": "rgb(184, 204, 82)"}, ALL) -assert-css: ("pre.rust .bool-val", {"color": "rgb(255, 119, 51)"}, ALL) -assert-css: ("pre.rust .self", {"color": "rgb(54, 163, 217)"}, ALL) -assert-css: ("pre.rust .attribute", {"color": "rgb(230, 225, 207)"}, ALL) -assert-css: ("pre.rust .macro", {"color": "rgb(163, 122, 204)"}, ALL) -assert-css: ("pre.rust .question-mark", {"color": "rgb(255, 144, 17)"}, ALL) -assert-css: ("pre.rust .comment", {"color": "rgb(120, 135, 151)"}, ALL) -assert-css: ("pre.rust .doccomment", {"color": "rgb(161, 172, 136)"}, ALL) - -local-storage: {"rustdoc-theme": "dark"} -reload: - -assert-css: ("pre.rust .kw", {"color": "rgb(171, 138, 193)"}, ALL) -assert-css: ("pre.rust .kw-2", {"color": "rgb(118, 154, 203)"}, ALL) -assert-css: ("pre.rust .prelude-ty", {"color": "rgb(118, 154, 203)"}, ALL) -assert-css: ("pre.rust .prelude-val", {"color": "rgb(238, 104, 104)"}, ALL) -assert-css: ("pre.rust .lifetime", {"color": "rgb(217, 127, 38)"}, ALL) -assert-css: ("pre.rust .number", {"color": "rgb(131, 163, 0)"}, ALL) -assert-css: ("pre.rust .string", {"color": "rgb(131, 163, 0)"}, ALL) -assert-css: ("pre.rust .bool-val", {"color": "rgb(238, 104, 104)"}, ALL) -assert-css: ("pre.rust .self", {"color": "rgb(238, 104, 104)"}, ALL) -assert-css: ("pre.rust .attribute", {"color": "rgb(238, 104, 104)"}, ALL) -assert-css: ("pre.rust .macro", {"color": "rgb(62, 153, 159)"}, ALL) -assert-css: ("pre.rust .question-mark", {"color": "rgb(255, 144, 17)"}, ALL) -assert-css: ("pre.rust .comment", {"color": "rgb(141, 141, 139)"}, ALL) -assert-css: ("pre.rust .doccomment", {"color": "rgb(140, 163, 117)"}, ALL) - -local-storage: {"rustdoc-theme": "light"} -reload: - -assert-css: ("pre.rust .kw", {"color": "rgb(137, 89, 168)"}, ALL) -assert-css: ("pre.rust .kw-2", {"color": "rgb(66, 113, 174)"}, ALL) -assert-css: ("pre.rust .prelude-ty", {"color": "rgb(66, 113, 174)"}, ALL) -assert-css: ("pre.rust .prelude-val", {"color": "rgb(200, 40, 41)"}, ALL) -assert-css: ("pre.rust .lifetime", {"color": "rgb(183, 101, 20)"}, ALL) -assert-css: ("pre.rust .number", {"color": "rgb(113, 140, 0)"}, ALL) -assert-css: ("pre.rust .string", {"color": "rgb(113, 140, 0)"}, ALL) -assert-css: ("pre.rust .bool-val", {"color": "rgb(200, 40, 41)"}, ALL) -assert-css: ("pre.rust .self", {"color": "rgb(200, 40, 41)"}, ALL) -assert-css: ("pre.rust .attribute", {"color": "rgb(200, 40, 41)"}, ALL) -assert-css: ("pre.rust .macro", {"color": "rgb(62, 153, 159)"}, ALL) -assert-css: ("pre.rust .question-mark", {"color": "rgb(255, 144, 17)"}, ALL) -assert-css: ("pre.rust .comment", {"color": "rgb(142, 144, 140)"}, ALL) -assert-css: ("pre.rust .doccomment", {"color": "rgb(77, 77, 76)"}, ALL) +call-function: ("check-colors", { + "theme": "ayu", + "kw": "rgb(255, 119, 51)", + "kw2": "rgb(255, 119, 51)", + "prelude_ty": "rgb(105, 242, 223)", + "prelude_val": "rgb(255, 119, 51)", + "lifetime": "rgb(255, 119, 51)", + "number": "rgb(184, 204, 82)", + "string": "rgb(184, 204, 82)", + "bool_val": "rgb(255, 119, 51)", + "self": "rgb(54, 163, 217)", + "attribute": "rgb(230, 225, 207)", + "macro": "rgb(163, 122, 204)", + "question_mark": "rgb(255, 144, 17)", + "comment": "rgb(120, 135, 151)", + "doc_comment": "rgb(161, 172, 136)", +}) +call-function: ("check-colors", { + "theme": "dark", + "kw": "rgb(171, 138, 193)", + "kw2": "rgb(118, 154, 203)", + "prelude_ty": "rgb(118, 154, 203)", + "prelude_val": "rgb(238, 104, 104)", + "lifetime": "rgb(217, 127, 38)", + "number": "rgb(131, 163, 0)", + "string": "rgb(131, 163, 0)", + "bool_val": "rgb(238, 104, 104)", + "self": "rgb(238, 104, 104)", + "attribute": "rgb(238, 104, 104)", + "macro": "rgb(62, 153, 159)", + "question_mark": "rgb(255, 144, 17)", + "comment": "rgb(141, 141, 139)", + "doc_comment": "rgb(140, 163, 117)", +}) +call-function: ("check-colors", { + "theme": "light", + "kw": "rgb(137, 89, 168)", + "kw2": "rgb(66, 113, 174)", + "prelude_ty": "rgb(66, 113, 174)", + "prelude_val": "rgb(200, 40, 41)", + "lifetime": "rgb(183, 101, 20)", + "number": "rgb(113, 140, 0)", + "string": "rgb(113, 140, 0)", + "bool_val": "rgb(200, 40, 41)", + "self": "rgb(200, 40, 41)", + "attribute": "rgb(200, 40, 41)", + "macro": "rgb(62, 153, 159)", + "question_mark": "rgb(255, 144, 17)", + "comment": "rgb(142, 144, 140)", + "doc_comment": "rgb(77, 77, 76)", +}) From 4e1abcda1b195e7636e1e289c8a60e870eeba37a Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 24 Oct 2022 10:47:24 -0700 Subject: [PATCH 09/12] rustdoc: remove unused `.sidebar-logo` DOM on source pages --- src/librustdoc/html/static/css/noscript.css | 4 ++++ src/librustdoc/html/static/css/rustdoc.css | 4 ---- src/librustdoc/html/templates/page.html | 2 ++ src/test/rustdoc-gui/sidebar-source-code-display.goml | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/static/css/noscript.css b/src/librustdoc/html/static/css/noscript.css index 63b35f5d0df0d..301f03a16427a 100644 --- a/src/librustdoc/html/static/css/noscript.css +++ b/src/librustdoc/html/static/css/noscript.css @@ -18,3 +18,7 @@ nav.sub { /* The search bar and related controls don't work without JS */ display: none; } + +.source .sidebar { + display: none; +} diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 293c9787609b0..8dea0547ee8d3 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -402,10 +402,6 @@ img { overflow-y: hidden; } -.rustdoc.source .sidebar .sidebar-logo { - display: none; -} - .source .sidebar, #sidebar-toggle, #source-sidebar { background-color: var(--sidebar-background-color); } diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index 2a111f94e5078..ee8938ea6030c 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -89,6 +89,7 @@

{#- -#} {#- -#} {%- endif -%} {#- -#}
{#- -#} diff --git a/src/test/rustdoc-gui/sidebar-source-code-display.goml b/src/test/rustdoc-gui/sidebar-source-code-display.goml index 548fd22dcea90..4155dab64eb98 100644 --- a/src/test/rustdoc-gui/sidebar-source-code-display.goml +++ b/src/test/rustdoc-gui/sidebar-source-code-display.goml @@ -3,7 +3,7 @@ javascript: false goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" // Since the javascript is disabled, there shouldn't be a toggle. assert-false: "#sidebar-toggle" -wait-for-css: (".sidebar > *", {"visibility": "hidden"}) +wait-for-css: (".sidebar", {"display": "none"}) // Let's retry with javascript enabled. javascript: true From f0f0a7dbc29c589a4bddf0aa1e208b550e1b2fad Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 24 Oct 2022 11:39:19 -0700 Subject: [PATCH 10/12] rustdoc: remove redundant CSS `a.test-arrow:hover` In 4b402dbe690dd00f567542ca9e41042826a168b5, when this rule was added, it was overriding a rule that made all links in docblock get an underline when hovered. This became redundant when, after reordering the rules, 7585632052298f9c84cc12ac5afcb23786ae1d3d changed the pro-underline rule to exclude the test-arrow link anyway. --- src/librustdoc/html/static/css/rustdoc.css | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 293c9787609b0..91a4e9ca2d9cc 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1233,9 +1233,6 @@ a.test-arrow { .example-wrap:hover .test-arrow { visibility: visible; } -a.test-arrow:hover { - text-decoration: none; -} .code-attribute { font-weight: 300; From 5e624bf4bad3156f63ca95702b7bd6246751ded5 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Mon, 24 Oct 2022 20:14:28 +0200 Subject: [PATCH 11/12] rustdoc: Use `unix_sigpipe` instead of `rustc_driver::set_sigpipe_handler` Start using `unix_sigpipe` instead of `rustc_driver::set_sigpipe_handler`. After this has been merged, we can completely remove `rustc_driver::set_sigpipe_handler`. Verification of this change --------------------------- 1. Remove `#[unix_sigpipe = "sig_dfl"]` 1. Run `./x.py build` 1. Run `./build/aarch64-apple-darwin/stage1/bin/rustdoc --help | false` 1. Observe ICE 1. Add back `#[unix_sigpipe = "sig_dfl"]` 1. Run `./x.py build` 1. Run `./build/aarch64-apple-darwin/stage1/bin/rustdoc --help | false` 1. Observe ICE fixed --- src/librustdoc/lib.rs | 1 - src/tools/rustdoc/main.rs | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 793061a9f7a06..4cf9435d9c8ee 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -154,7 +154,6 @@ pub fn main() { } } - rustc_driver::set_sigpipe_handler(); rustc_driver::install_ice_hook(); // When using CI artifacts (with `download_stage1 = true`), tracing is unconditionally built diff --git a/src/tools/rustdoc/main.rs b/src/tools/rustdoc/main.rs index 5b499a1fa1fa8..b81f46d1211ce 100644 --- a/src/tools/rustdoc/main.rs +++ b/src/tools/rustdoc/main.rs @@ -1,3 +1,6 @@ +#![feature(unix_sigpipe)] + +#[unix_sigpipe = "sig_dfl"] fn main() { rustdoc::main() } From fa5cf90b8dd335b53056e3af96a468905b482226 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 24 Oct 2022 18:45:50 +0000 Subject: [PATCH 12/12] Delay span bug when we can't map lifetimes back in collect_trait_impl_trait_tys --- .../src/check/compare_method.rs | 12 +++++++++-- .../impl-trait/in-trait/signature-mismatch.rs | 21 +++++++++++++++++++ .../in-trait/signature-mismatch.stderr | 16 ++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/impl-trait/in-trait/signature-mismatch.rs create mode 100644 src/test/ui/impl-trait/in-trait/signature-mismatch.stderr diff --git a/compiler/rustc_hir_analysis/src/check/compare_method.rs b/compiler/rustc_hir_analysis/src/check/compare_method.rs index 3469ec4767b7c..e72f18012ab33 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_method.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_method.rs @@ -598,8 +598,16 @@ pub fn collect_trait_impl_trait_tys<'tcx>( let num_impl_substs = tcx.generics_of(impl_m.container_id(tcx)).params.len(); let ty = tcx.fold_regions(ty, |region, _| { let ty::ReFree(_) = region.kind() else { return region; }; - let ty::ReEarlyBound(e) = map[®ion.into()].expect_region().kind() - else { bug!("expected ReFree to map to ReEarlyBound"); }; + let Some(ty::ReEarlyBound(e)) = map.get(®ion.into()).map(|r| r.expect_region().kind()) + else { + tcx + .sess + .delay_span_bug( + return_span, + "expected ReFree to map to ReEarlyBound" + ); + return tcx.lifetimes.re_static; + }; tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { def_id: e.def_id, name: e.name, diff --git a/src/test/ui/impl-trait/in-trait/signature-mismatch.rs b/src/test/ui/impl-trait/in-trait/signature-mismatch.rs new file mode 100644 index 0000000000000..90682631aa032 --- /dev/null +++ b/src/test/ui/impl-trait/in-trait/signature-mismatch.rs @@ -0,0 +1,21 @@ +// edition:2021 + +#![feature(return_position_impl_trait_in_trait)] +#![allow(incomplete_features)] + +use std::future::Future; + +pub trait AsyncTrait { + fn async_fn(&self, buff: &[u8]) -> impl Future>; +} + +pub struct Struct; + +impl AsyncTrait for Struct { + fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future> + 'a { + //~^ ERROR `impl` item signature doesn't match `trait` item signature + async move { buff.to_vec() } + } +} + +fn main() {} diff --git a/src/test/ui/impl-trait/in-trait/signature-mismatch.stderr b/src/test/ui/impl-trait/in-trait/signature-mismatch.stderr new file mode 100644 index 0000000000000..6663d7faa1e57 --- /dev/null +++ b/src/test/ui/impl-trait/in-trait/signature-mismatch.stderr @@ -0,0 +1,16 @@ +error: `impl` item signature doesn't match `trait` item signature + --> $DIR/signature-mismatch.rs:15:5 + | +LL | fn async_fn(&self, buff: &[u8]) -> impl Future>; + | ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future> + 'static` +... +LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future> + 'a { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future> + '2` + | + = note: expected `fn(&'1 Struct, &'2 [u8]) -> impl Future> + 'static` + found `fn(&'1 Struct, &'2 [u8]) -> impl Future> + '2` + = help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait` + = help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output + +error: aborting due to previous error +