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 11 pull requests #103502

Merged
merged 23 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2414357
fix assertion failed for break_last_token and trailing token
chenyukang Oct 20, 2022
717bf35
Different suggestions for when associated functions are referred to
clubby789 Oct 21, 2022
3f1e999
Update UI tests
clubby789 Oct 21, 2022
e025306
Don't ICE on regions from anonymous_lifetime_in_impl_trait
compiler-errors Oct 22, 2022
45a9d18
rustdoc: remove no-op CSS `.source pre.rust { white-space: pre }`
notriddle Oct 24, 2022
e3a091a
Remove redundant sentence
jruderman Oct 24, 2022
c2bc3bc
Document link to unstable book
camsteffen Oct 22, 2022
1dff99f
Use functions in highlight-colors rustdoc GUI test
GuillaumeGomez Oct 24, 2022
4e1abcd
rustdoc: remove unused `.sidebar-logo` DOM on source pages
notriddle Oct 24, 2022
f0f0a7d
rustdoc: remove redundant CSS `a.test-arrow:hover`
notriddle Oct 24, 2022
5e624bf
rustdoc: Use `unix_sigpipe` instead of `rustc_driver::set_sigpipe_han…
Enselic Oct 24, 2022
fa5cf90
Delay span bug when we can't map lifetimes back in collect_trait_impl…
compiler-errors Oct 24, 2022
11d11e3
Rollup merge of #103333 - chenyukang:yukang/fix-103143, r=wesleywiser
Oct 24, 2022
e47d222
Rollup merge of #103350 - clubby789:refer-to-assoc-method, r=wesleywiser
Oct 24, 2022
6383540
Rollup merge of #103382 - compiler-errors:anon-apit-lt-region-ice, r=…
Oct 24, 2022
12babb6
Rollup merge of #103409 - compiler-errors:rpitit-signature-mismatch, …
Oct 24, 2022
3a325b1
Rollup merge of #103410 - camsteffen:link-unstable-book, r=JohnTitor
Oct 24, 2022
db0e438
Rollup merge of #103462 - notriddle:notriddle/source-pre-rust-white-s…
Oct 24, 2022
d1b00c6
Rollup merge of #103465 - jruderman:patch-1, r=compiler-errors
Oct 24, 2022
d77e239
Rollup merge of #103486 - GuillaumeGomez:cleanup-rustdoc-gui-highligh…
Oct 24, 2022
9ecba38
Rollup merge of #103493 - notriddle:notriddle/source-sidebar-logo, r=…
Oct 24, 2022
b09ce60
Rollup merge of #103494 - notriddle:notriddle/test-arrow-hover, r=Gui…
Oct 24, 2022
d0ffd20
Rollup merge of #103495 - Enselic:rustdoc-unix_sigpipe, r=notriddle
Oct 24, 2022
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
100 changes: 92 additions & 8 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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(),
Expand All @@ -888,4 +884,92 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
),
})
}

fn give_name_if_anonymous_region_appears_in_arg_position_impl_trait(
&self,
fr: RegionVid,
) -> Option<RegionName> {
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
}
})
}
}
2 changes: 0 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0210.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 10 additions & 2 deletions compiler/rustc_hir_analysis/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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[&region.into()].expect_region().kind()
else { bug!("expected ReFree to map to ReEarlyBound"); };
let Some(ty::ReEarlyBound(e)) = map.get(&region.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,
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_parse/src/parser/attr_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand All @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3142,6 +3142,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,`
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
42 changes: 29 additions & 13 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type Res = def::Res<ast::NodeId>;
/// 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,
}
Expand All @@ -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",
}
Expand Down Expand Up @@ -516,7 +522,9 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
let typo_sugg =
self.lookup_typo_candidate(path, source.namespace(), is_expected).to_opt_suggestion();
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 => {
Expand All @@ -531,16 +539,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(
Expand Down Expand Up @@ -1498,6 +1511,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
ident: Ident,
ns: Namespace,
filter_fn: FilterFn,
called: bool,
) -> Option<AssocSuggestion>
where
FilterFn: Fn(Res) -> bool,
Expand Down Expand Up @@ -1539,9 +1553,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,
});
Expand All @@ -1560,10 +1574,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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/command-line-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

<a id="option-cap-lints"></a>
## `--cap-lints`: set the most restrictive lint level
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/html/static/css/noscript.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ nav.sub {
/* The search bar and related controls don't work without JS */
display: none;
}

.source .sidebar {
display: none;
}
8 changes: 0 additions & 8 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -538,7 +534,6 @@ ul.block, .block li {
}

.source .content pre.rust {
white-space: pre;
overflow: auto;
padding-left: 0;
}
Expand Down Expand Up @@ -1233,9 +1228,6 @@ a.test-arrow {
.example-wrap:hover .test-arrow {
visibility: visible;
}
a.test-arrow:hover {
text-decoration: none;
}

.code-attribute {
font-weight: 300;
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/html/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ <h2></h2> {#- -#}
</nav> {#- -#}
{%- endif -%}
<nav class="sidebar"> {#- -#}
{%- if page.css_class != "source" -%}
<a class="sidebar-logo" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
<div class="logo-container"> {#- -#}
{%- if !layout.logo.is_empty() %}
Expand All @@ -98,6 +99,7 @@ <h2></h2> {#- -#}
{%- endif -%}
</div> {#- -#}
</a> {#- -#}
{%- endif -%}
{{- sidebar|safe -}}
</nav> {#- -#}
<main> {#- -#}
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading