8000 Rollup of 7 pull requests by Dylan-DPC-zz · Pull Request #70063 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Rollup of 7 pull requests #70063

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

Closed
wants to merge 19 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
cdc7304
Compute the correct layout for variants of uninhabited enums and read…
oli-obk Mar 6, 2020
ec88ffa
Comment nits
oli-obk Mar 11, 2020
74608c7
Rustfmt and adjust capitalization
oli-obk Mar 11, 2020
71ebc61
resolve: Simplify `fn report_privacy_error`
petrochenkov Mar 7, 2020
580c6a2
resolve: Print import chains on privacy errors
petrochenkov Mar 7, 2020
afa940b
Update the mir inline costs
andjo403 Mar 11, 2020
f4083c6
Add the "consider importing it directly" label to public imports as well
petrochenkov Mar 11, 2020
f4eb6ed
Ensure HAS_FREE_LOCAL_NAMES is set for ReFree
matthewjasper Mar 11, 2020
e80cb20
resolve: Fix regression in resolution of raw keywords in paths
petrochenkov Mar 14, 2020
81099c2
VariantSizeDifferences: bail on SizeOverflow
Centril Mar 10, 2020
ce5e49f
Use sublice patterns to avoid computing the len
tesuji Mar 16, 2020
e1bc9af
Fix wrong deref
tesuji Mar 16, 2020
dd0d904
Rollup merge of #69768 - oli-obk:union_field_ice, r=eddyb,RalfJung
Dylan-DPC Mar 17, 2020
f6703ef
Rollup merge of #69811 - petrochenkov:privdiag2, r=estebank
Dylan-DPC Mar 17, 2020
2dab4f4
Rollup merge of #69881 - Centril:fix-69485, r=oli-obk
Dylan-DPC Mar 17, 2020
7e8c3b2
Rollup merge of #69934 - andjo403:inlinecost, r=wesleywiser
Dylan-DPC Mar 17, 2020
875392d
Rollup merge of #69956 - matthewjasper:fix-region-flags, r=nikomatsakis
Dylan-DPC Mar 17, 2020
ca2e83d
Rollup merge of #70000 - petrochenkov:rawkeypars, r=davidtwco
Dylan-DPC Mar 17, 2020
d7eabe5
Rollup merge of #70046 - lzutao:patch-1, r=Centril
Dylan-DPC Mar 17, 2020 8000
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
Prev Previous commit
Next Next commit
resolve: Simplify fn report_privacy_error
by factoring out `fn ctor_fields_span` into a separate function
  • Loading branch information
petrochenkov committed Mar 11, 2020
commit 71ebc6182012d80e076e4aaa03e0dbe44132fcbf
67 changes: 31 additions & 36 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,51 +916,46 @@ impl<'a> Resolver<'a> {
err.emit();
}

crate fn report_privacy_error(&self, privacy_error: &PrivacyError<'_>) {
let PrivacyError { ident, binding, .. } = *privacy_error;
let session = &self.session;
let mk_struct_span_error = |is_constructor| {
let mut descr = binding.res().descr().to_string();
if is_constructor {
descr += " constructor";
}
if binding.is_import() {
descr += " import";
}

let mut err =
struct_span_err!(session, ident.span, E0603, "{} `{}` is private", descr, ident);

err.span_label(ident.span, &format!("this {} is private", descr));
err.span_note(
session.source_map().def_span(binding.span),
&format!("the {} `{}` is defined here", descr, ident),
);

err
};

let mut err = if let NameBindingKind::Res(
/// If the binding refers to a tuple struct constructor with fields,
/// returns the span of its fields.
fn ctor_fields_span(&self, binding: &NameBinding<'_>) -> Option<Span> {
if let NameBindingKind::Res(
Res::Def(DefKind::Ctor(CtorOf::Struct, CtorKind::Fn), ctor_def_id),
_,
) = binding.kind
{
let def_id = (&*self).parent(ctor_def_id).expect("no parent for a constructor");
if let Some(fields) = self.field_names.get(&def_id) {
let mut err = mk_struct_span_error(true);
let first_field = fields.first().expect("empty field list in the map");
err.span_label(
fields.iter().fold(first_field.span, |acc, field| acc.to(field.span)),
"a constructor is private if any of the fields is private",
);
err
} else {
mk_struct_span_error(false)
return Some(fields.iter().fold(first_field.span, |acc, field| acc.to(field.span)));
}
} else {
mk_struct_span_error(false)
};
}
None
}

crate fn report_privacy_error(&self, privacy_error: &PrivacyError<'_>) {
let PrivacyError { ident, binding, .. } = *privacy_error;

let ctor_fields_span = self.ctor_fields_span(binding);
let mut descr = binding.res().descr().to_string();
if ctor_fields_span.is_some() {
descr += " constructor";
}
if binding.is_import() {
descr += " import";
}

let mut err =
struct_span_err!(self.session, ident.span, E0603, "{} `{}` is private", descr, ident);
err.span_label(ident.span, &format!("this {} is private", descr));
if let Some(span) = ctor_fields_span {
err.span_label(span, "a constructor is private if any of the fields is private");
}

err.span_note(
self.session.source_map().def_span(binding.span),
&format!("the {} `{}` is defined here", descr, ident),
);
err.emit();
}
}
Expand Down
0