Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7aec84d
resolve: Merge `ExternPreludeEntry::introduced_by_item` into `item_bi…
petrochenkov Aug 29, 2025
f0dbfad
resolve: Merge `ExternPreludeEntry::only_item` into `flag_binding`
petrochenkov Aug 29, 2025
1112274
add `Bound::copied`
connortsui20 Aug 28, 2025
9c1255f
add feature gate in doc test
connortsui20 Aug 28, 2025
114c0c2
Add `#[must_use] and update `cloned` documentation
connortsui20 Aug 30, 2025
18a36bc
Detect negative literal inferred to unsigned integer
estebank Aug 30, 2025
263766b
suggest method name with maybe ty mismatch
chenyukang Aug 31, 2025
cfba491
fix
LorrensP-2158466 Aug 31, 2025
ea2daa3
Split `ObligationCauseCode::BinOp` for unops to `UnOp`
estebank Aug 31, 2025
7ea882d
Inline and remove `dump_matched_mir_node`.
nnethercote Aug 14, 2025
3a0d0be
Inline and remove `dump_mir_for_pass`.
nnethercote Aug 14, 2025
d7faa56
Avoid unnecessary `mut`-ness for various closures.
nnethercote Aug 14, 2025
d3e2c93
Use trait object references for closures.
nnethercote Aug 15, 2025
2d21c13
Indent some functions.
nnethercote Aug 15, 2025
5ce3797
Introduce `MirDumper` and `MirWriter`.
nnethercote Aug 15, 2025
d17b3fb
Rollup merge of #145421 - nnethercote:dump_mir-cleanups, r=davidtwco
Zalathar Sep 1, 2025
0fa8265
Rollup merge of #145968 - connortsui20:bound-copied, r=joboet
Zalathar Sep 1, 2025
5adc0fe
Rollup merge of #146004 - petrochenkov:epentry, r=nnethercote
Zalathar Sep 1, 2025
142ad69
Rollup merge of #146042 - estebank:issue-83413, r=lcnr
Zalathar Sep 1, 2025
eed5259
Rollup merge of #146046 - chenyukang:yukang-fix-method-exists-for-ret…
Zalathar Sep 1, 2025
0dbd8e6
Rollup merge of #146051 - LorrensP-2158466:miri-libstd-fix, r=RalfJung
Zalathar Sep 1, 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
Next Next commit
resolve: Merge ExternPreludeEntry::introduced_by_item into `item_bi…
…nding`
  • Loading branch information
petrochenkov committed Aug 29, 2025
commit 7aec84d485ec1159c3ead3800ba601fd6d1d7869
6 changes: 2 additions & 4 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,16 +1008,14 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
let msg = format!("extern crate `{ident}` already in extern prelude");
self.r.tcx.dcx().span_delayed_bug(item.span, msg);
} else {
entry.item_binding = Some(imported_binding);
entry.introduced_by_item = orig_name.is_some();
entry.item_binding = Some((imported_binding, orig_name.is_some()));
}
entry
}
Entry::Vacant(vacant) => vacant.insert(ExternPreludeEntry {
item_binding: Some(imported_binding),
item_binding: Some((imported_binding, true)),
flag_binding: Cell::new(None),
only_item: true,
introduced_by_item: true,
}),
};
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<'a, 'ra, 'tcx> UnusedImportCheckVisitor<'a, 'ra, 'tcx> {
.r
.extern_prelude
.get(&Macros20NormalizedIdent::new(extern_crate.ident))
.is_none_or(|entry| entry.introduced_by_item)
.is_none_or(|entry| entry.introduced_by_item())
{
continue;
}
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let from_item = self
.extern_prelude
.get(&Macros20NormalizedIdent::new(ident))
.is_none_or(|entry| entry.introduced_by_item);
.is_none_or(|entry| entry.introduced_by_item());
// Only suggest removing an import if both bindings are to the same def, if both spans
// aren't dummy spans. Further, if both bindings are imports, then the ident must have
// been introduced by an item.
Expand Down Expand Up @@ -1845,7 +1845,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let AmbiguityError { kind, ident, b1, b2, misc1, misc2, .. } = *ambiguity_error;
let extern_prelude_ambiguity = || {
self.extern_prelude.get(&Macros20NormalizedIdent::new(ident)).is_some_and(|entry| {
entry.item_binding == Some(b1) && entry.flag_binding.get() == Some(b2)
entry.item_binding.map(|(b, _)| b) == Some(b1)
&& entry.flag_binding.get() == Some(b2)
})
};
let (b1, b2, misc1, misc2, swapped) = if b2.span.is_dummy() && !b1.span.is_dummy() {
Expand Down
26 changes: 15 additions & 11 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,15 +1028,20 @@ impl<'ra> NameBindingData<'ra> {
#[derive(Default, Clone)]
struct ExternPreludeEntry<'ra> {
/// Binding from an `extern crate` item.
item_binding: Option<NameBinding<'ra>>,
/// The boolean flag is true is `item_binding` is non-redundant, happens either when
/// `only_item` is true, or when `extern crate` introducing `item_binding` used renaming.
item_binding: Option<(NameBinding<'ra>, /* introduced by item */ bool)>,
/// Binding from an `--extern` flag, lazily populated on first use.
flag_binding: Cell<Option<NameBinding<'ra>>>,
/// There was no `--extern` flag introducing this name,
/// `flag_binding` doesn't need to be populated.
only_item: bool,
/// `item_binding` is non-redundant, happens either when `only_item` is true,
/// or when `extern crate` introducing `item_binding` used renaming.
introduced_by_item: bool,
}

impl ExternPreludeEntry<'_> {
fn introduced_by_item(&self) -> bool {
matches!(self.item_binding, Some((_, true)))
}
}

struct DeriveData {
Expand Down Expand Up @@ -2062,12 +2067,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
// Avoid marking `extern crate` items that refer to a name from extern prelude,
// but not introduce it, as used if they are accessed from lexical scope.
if used == Used::Scope {
if let Some(entry) = self.extern_prelude.get(&Macros20NormalizedIdent::new(ident)) {
if !entry.introduced_by_item && entry.item_binding == Some(used_binding) {
return;
}
}
if used == Used::Scope
&& let Some(entry) = self.extern_prelude.get(&Macros20NormalizedIdent::new(ident))
&& entry.item_binding == Some((used_binding, false))
{
return;
}
let old_used = self.import_use_map.entry(import).or_insert(used);
if *old_used < used {
Expand Down Expand Up @@ -2226,7 +2230,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
finalize: bool,
) -> Option<NameBinding<'ra>> {
let entry = self.extern_prelude.get(&Macros20NormalizedIdent::new(ident));
entry.and_then(|entry| entry.item_binding).map(|binding| {
entry.and_then(|entry| entry.item_binding).map(|(binding, _)| {
if finalize {
self.get_mut().record_use(ident, binding, Used::Scope);
}
Expand Down