Skip to content

Rollup of 10 pull requests #135891

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 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
de0cb6c
Start work on dangling pointers lint
Anthony-Eid Nov 13, 2024
6d95b5b
Update compiler/rustc_lint/src/lints.rs
Anthony-Eid Dec 5, 2024
bab8a41
Update compiler/rustc_lint/messages.ftl
Anthony-Eid Dec 5, 2024
3a83422
Fix ICE-133063
Shunpoco Jan 12, 2025
8a57fa6
Fix ICE-133117
Shunpoco Jan 12, 2025
8c0c149
Remove solved crashes
Shunpoco Jan 12, 2025
0385dd4
Fix ICE-130779
Shunpoco Jan 12, 2025
be56f10
Properly note when query stack is being cut off
compiler-errors Jan 16, 2025
cd9dcfc
ci: use ghcr buildkit image
marcoieni Jan 21, 2025
a93616a
rustc_resolve: remove unneeded `return`s
yotamofek Jan 18, 2025
cf91a93
rustc_resolve: flatten nested `if`s
yotamofek Jan 20, 2025
ae87d00
rustc_resolve: reduce rightwards drift with `let..else` 👉💨
yotamofek Jan 20, 2025
6f22dfe
rustc_resolve: use `Iterator` combinators instead of `for` loops wher…
yotamofek Jan 20, 2025
efabee2
rustc_resolve: don't open-code `Option::filter`
yotamofek Jan 21, 2025
fed5f98
Remove test panic from File::open
ChrisDenton Jan 21, 2025
922e6bb
Detect missing fields with default values and suggest `..`
estebank Jan 20, 2025
e727641
Reword "crate not found" resolve message
estebank Nov 18, 2024
57dd42d
Point at invalid utf-8 span on user's source code
estebank Jan 15, 2025
e7db092
address review: modify ICE-133117-duplicated-never-arm.rs
Shunpoco Jan 22, 2025
d8a216b
address review: modify ICE-133063-never-arm-no-otherwise-block.rs
Shunpoco Jan 22, 2025
481ed2d
address review: modify matches/mod.rs
Shunpoco Jan 22, 2025
7275bdf
modify comment
Shunpoco Jan 22, 2025
9e98d25
Library: Finalize dyn compatibility renaming
fmease Jan 22, 2025
12214db
Update lint tests with new dangling pointers message
Anthony-Eid Jan 22, 2025
5a36359
Rollup merge of #132983 - Anthony-Eid:dangling-pointers-lint, r=Urgau
matthiaskrgr Jan 22, 2025
f699947
Rollup merge of #133154 - estebank:issue-133137, r=wesleywiser
matthiaskrgr Jan 22, 2025
c2ea5ba
Rollup merge of #135409 - Shunpoco:issue-133117-ICE-never-false-edge-…
matthiaskrgr Jan 22, 2025
3cf5a81
Rollup merge of #135557 - estebank:wtf8, r=fee1-dead
matthiaskrgr Jan 22, 2025
b1285e1
Rollup merge of #135596 - compiler-errors:stack, r=oli-obk
matthiaskrgr Jan 22, 2025
8723964
Rollup merge of #135794 - estebank:non-exhaustive-dfv-ctor, r=jieyouxu
matthiaskrgr Jan 22, 2025
a634c4c
Rollup merge of #135814 - marcoieni:use-buildkit-ghcr, r=Kobzol
matthiaskrgr Jan 22, 2025
e98d9f5
Rollup merge of #135826 - yotamofek:resolve-cleanups4, r=petrochenkov
matthiaskrgr Jan 22, 2025
caf38c7
Rollup merge of #135837 - ChrisDenton:trunc, r=Noratrieb
matthiaskrgr Jan 22, 2025
578f0d7
Rollup merge of #135856 - fmease:library-mv-obj-save-dyn-compat-ii, r…
matthiaskrgr Jan 22, 2025
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
rustc_resolve: flatten nested ifs
  • Loading branch information
yotamofek committed Jan 21, 2025
commit cf91a93d09db875ba28cd395f9339331324a14c7
54 changes: 26 additions & 28 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,10 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
let self_spans = items
.iter()
.filter_map(|(use_tree, _)| {
if let ast::UseTreeKind::Simple(..) = use_tree.kind {
if use_tree.ident().name == kw::SelfLower {
return Some(use_tree.span);
}
if let ast::UseTreeKind::Simple(..) = use_tree.kind
&& use_tree.ident().name == kw::SelfLower
{
return Some(use_tree.span);
}

None
Expand Down Expand Up @@ -947,19 +947,19 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
let imported_binding = self.r.import(binding, import);
if parent == self.r.graph_root {
let ident = ident.normalize_to_macros_2_0();
if let Some(entry) = self.r.extern_prelude.get(&ident) {
if expansion != LocalExpnId::ROOT && orig_name.is_some() && !entry.is_import() {
self.r.dcx().emit_err(
errors::MacroExpandedExternCrateCannotShadowExternArguments {
span: item.span,
},
);
// `return` is intended to discard this binding because it's an
// unregistered ambiguity error which would result in a panic
// caused by inconsistency `path_res`
// more details: https://github.com/rust-lang/rust/pull/111761
return;
}
if let Some(entry) = self.r.extern_prelude.get(&ident)
&& expansion != LocalExpnId::ROOT
&& orig_name.is_some()
&& !entry.is_import()
{
self.r.dcx().emit_err(
errors::MacroExpandedExternCrateCannotShadowExternArguments { span: item.span },
);
// `return` is intended to discard this binding because it's an
// unregistered ambiguity error which would result in a panic
// caused by inconsistency `path_res`
// more details: https://github.com/rust-lang/rust/pull/111761
return;
}
let entry = self
.r
Expand Down Expand Up @@ -1040,10 +1040,10 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
span: item.span,
});
}
if let ItemKind::ExternCrate(Some(orig_name)) = item.kind {
if orig_name == kw::SelfLower {
self.r.dcx().emit_err(errors::MacroUseExternCrateSelf { span: attr.span });
}
if let ItemKind::ExternCrate(Some(orig_name)) = item.kind
&& orig_name == kw::SelfLower
{
self.r.dcx().emit_err(errors::MacroUseExternCrateSelf { span: attr.span });
}
let ill_formed = |span| {
self.r.dcx().emit_err(errors::BadMacroImport { span });
Expand Down Expand Up @@ -1179,14 +1179,12 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
return Some((MacroKind::Bang, item.ident, item.span));
} else if ast::attr::contains_name(&item.attrs, sym::proc_macro_attribute) {
return Some((MacroKind::Attr, item.ident, item.span));
} else if let Some(attr) = ast::attr::find_by_name(&item.attrs, sym::proc_macro_derive) {
if let Some(meta_item_inner) =
} else if let Some(attr) = ast::attr::find_by_name(&item.attrs, sym::proc_macro_derive)
&& let Some(meta_item_inner) =
attr.meta_item_list().and_then(|list| list.get(0).cloned())
{
if let Some(ident) = meta_item_inner.ident() {
return Some((MacroKind::Derive, ident, ident.span));
}
}
&& let Some(ident) = meta_item_inner.ident()
{
return Some((MacroKind::Derive, ident, ident.span));
}
None
}
Expand Down
127 changes: 58 additions & 69 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let (name, span) =
(ident.name, self.tcx.sess.source_map().guess_head_span(new_binding.span));

if let Some(s) = self.name_already_seen.get(&name) {
if s == &span {
return;
}
if self.name_already_seen.get(&name) == Some(&span) {
return;
}

let old_kind = match (ns, old_binding.module()) {
Expand Down Expand Up @@ -380,20 +378,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
suggestion = Some(format!("self as {suggested_name}"))
}
ImportKind::Single { source, .. } => {
if let Some(pos) =
source.span.hi().0.checked_sub(binding_span.lo().0).map(|pos| pos as usize)
if let Some(pos) = source.span.hi().0.checked_sub(binding_span.lo().0)
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(binding_span)
&& pos as usize <= snippet.len()
{
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(binding_span) {
if pos <= snippet.len() {
span = binding_span
.with_lo(binding_span.lo() + BytePos(pos as u32))
.with_hi(
binding_span.hi()
- BytePos(if snippet.ends_with(';') { 1 } else { 0 }),
);
suggestion = Some(format!(" as {suggested_name}"));
}
}
span = binding_span.with_lo(binding_span.lo() + BytePos(pos)).with_hi(
binding_span.hi() - BytePos(if snippet.ends_with(';') { 1 } else { 0 }),
);
suggestion = Some(format!(" as {suggested_name}"));
}
}
ImportKind::ExternCrate { source, target, .. } => {
Expand Down Expand Up @@ -510,13 +502,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// If the first element of our path was actually resolved to an
// `ExternCrate` (also used for `crate::...`) then no need to issue a
// warning, this looks all good!
if let Some(binding) = second_binding {
if let NameBindingKind::Import { import, .. } = binding.kind {
// Careful: we still want to rewrite paths from renamed extern crates.
if let ImportKind::ExternCrate { source: None, .. } = import.kind {
return;
}
}
if let Some(binding) = second_binding
&& let NameBindingKind::Import { import, .. } = binding.kind
// Careful: we still want to rewrite paths from renamed extern crates.
&& let ImportKind::ExternCrate { source: None, .. } = import.kind
{
return;
}

let diag = BuiltinLintDiag::AbsPathWithModule(root_span);
Expand Down Expand Up @@ -1215,12 +1206,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}

// #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;
}
if let NameBindingKind::Import { binding, .. } = name_binding.kind
&& this.is_accessible_from(binding.vis, parent_scope.module)
&& !this.is_accessible_from(name_binding.vis, parent_scope.module)
{
return;
}

let res = name_binding.res();
Expand Down Expand Up @@ -1253,14 +1243,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
segms.push(ast::PathSegment::from_ident(ident));
let path = Path { span: name_binding.span, segments: segms, tokens: None };

if child_accessible {
if child_accessible
// Remove invisible match if exists
if let Some(idx) = candidates
&& let Some(idx) = candidates
.iter()
.position(|v: &ImportSuggestion| v.did == did && !v.accessible)
{
candidates.remove(idx);
}
{
candidates.remove(idx);
}

if candidates.iter().all(|v: &ImportSuggestion| v.did != did) {
Expand Down Expand Up @@ -1545,19 +1534,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
macro_kind.descr_expected(),
),
};
if let crate::NameBindingKind::Import { import, .. } = binding.kind {
if !import.span.is_dummy() {
let note = errors::IdentImporterHereButItIsDesc {
span: import.span,
imported_ident: ident,
imported_ident_desc: &desc,
};
err.subdiagnostic(note);
// Silence the 'unused import' warning we might get,
// since this diagnostic already covers that import.
self.record_use(ident, binding, Used::Other);
return;
}
if let crate::NameBindingKind::Import { import, .. } = binding.kind
&& !import.span.is_dummy()
{
let note = errors::IdentImporterHereButItIsDesc {
span: import.span,
imported_ident: ident,
imported_ident_desc: &desc,
};
err.subdiagnostic(note);
// Silence the 'unused import' warning we might get,
// since this diagnostic already covers that import.
self.record_use(ident, binding, Used::Other);
return;
}
let note = errors::IdentInScopeButItIsDesc {
imported_ident: ident,
Expand Down Expand Up @@ -2436,20 +2425,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
debug!(found_closing_brace, ?binding_span);

let mut removal_span = binding_span;
if found_closing_brace {
// If the binding span ended with a closing brace, as in the below example:
// ie. `use a::b::{c, d};`
// ^
// Then expand the span of characters to remove to include the previous
// binding's trailing comma.
// ie. `use a::b::{c, d};`
// ^^^
if let Some(previous_span) =

// If the binding span ended with a closing brace, as in the below example:
// ie. `use a::b::{c, d};`
// ^
// Then expand the span of characters to remove to include the previous
// binding's trailing comma.
// ie. `use a::b::{c, d};`
// ^^^
if found_closing_brace
&& let Some(previous_span) =
extend_span_to_previous_binding(self.tcx.sess, binding_span)
{
debug!(?previous_span);
removal_span = removal_span.with_lo(previous_span.lo());
}
{
debug!(?previous_span);
removal_span = removal_span.with_lo(previous_span.lo());
}
debug!(?removal_span);

Expand Down Expand Up @@ -3064,16 +3053,16 @@ impl<'tcx> visit::Visitor<'tcx> for UsePlacementFinder {

fn search_for_any_use_in_items(items: &[P<ast::Item>]) -> Option<Span> {
for item in items {
if let ItemKind::Use(..) = item.kind {
if is_span_suitable_for_use_injection(item.span) {
let mut lo = item.span.lo();
for attr in &item.attrs {
if attr.span.eq_ctxt(item.span) {
lo = std::cmp::min(lo, attr.span.lo());
}
if let ItemKind::Use(..) = item.kind
&& is_span_suitable_for_use_injection(item.span)
{
let mut lo = item.span.lo();
for attr in &item.attrs {
if attr.span.eq_ctxt(item.span) {
lo = std::cmp::min(lo, attr.span.lo());
}
return Some(Span::new(lo, lo, item.span.ctxt(), item.span.parent()));
}
return Some(Span::new(lo, lo, item.span.ctxt(), item.span.parent()));
}
}
None
Expand Down
Loading