Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 2 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e101e38
std_detect: Tidying of slice length
a4lg Jun 29, 2025
bb2d169
use `is_multiple_of` to check if an addr is aligned
folkertdev Jul 5, 2025
e8d9e80
Add empty rust-version file
Kobzol Jun 26, 2025
f697f81
Add josh synchronization scripts
Kobzol Jun 26, 2025
8ae4e6a
Update stabilization version of certain x86 intrinsics to 1.89
Amanieu Jun 30, 2025
e46d220
Use simd_extract! macro instead of calling simd_extract directly
clarfonthey Jun 30, 2025
600497f
Mark `avx` broadcast intrinsics as safe
okaneco Jun 23, 2025
b535003
Remove std-detect dev dependency in core_arch
Kobzol Jul 4, 2025
816f029
Update README.md
kilavvy Jun 29, 2025
8600192
Add config files for `rustc-josh-sync`
Kobzol Jul 4, 2025
ce73251
Prepare for merging from rust-lang/rust
Kobzol Jul 4, 2025
1bc289d
std_detect: RISC-V Linux: Ergonomic querying with `riscv_hwprobe`
a4lg Jun 29, 2025
fddd05b
some clippy fixes
hkBst Jul 6, 2025
658b5c8
Use `simd_funnel_sh{l,r}` and `simd_round_ties_even` to remove uses o…
sayantn Jul 7, 2025
a95bd00
Remove custom josh-sync scripts
Kobzol Jul 8, 2025
07d5fbb
Update README with link to `josh-sync`
Kobzol Jul 8, 2025
82126a6
fix whitespace in `aarch64.spec.yml`
folkertdev Jul 8, 2025
323c646
remote intermediate assignment
folkertdev Jul 8, 2025
92701fe
shorten array literals
folkertdev Jul 8, 2025
061a941
remove unneeded cast
folkertdev Jul 8, 2025
701d222
Reset rust-version
Kobzol Jul 8, 2025
3c9297c
Prepare for merging from rust-lang/rust
Kobzol Jul 8, 2025
bdead41
Merge ref '040e2f8b9ff2' from rust-lang/rust
Kobzol Jul 8, 2025
a310bdd
Merge pull request #1853 from Kobzol/pull-fixed
Amanieu Jul 8, 2025
d54c3ea
Preserve the .debug_gdb_scripts section
sebastianpoeplau Jul 3, 2025
e47eb32
Rename `*AsmOperandRef::Const` to `Interpolate`
nbdd0121 Oct 17, 2024
2028157
Add `InlineAsmOperandRef::Const`
nbdd0121 Oct 17, 2024
b38ec0d
Implement asm_const_ptr for inline asm
nbdd0121 Oct 24, 2024
60179d3
Give global_asm mangled names
nbdd0121 Mar 12, 2025
363fd49
Collect constants within `global_asm!` in collector
nbdd0121 Mar 12, 2025
81a4b3e
Implement asm_const_ptr for global_asm and naked_asm
nbdd0121 Mar 14, 2025
3e675f4
Fix `--skip-std-check-if-no-download-rustc`
Kobzol Jul 9, 2025
84eeca2
Make some "safe" llvm ops actually sound
oli-obk Jul 10, 2025
7632c55
extract single_import_can_define_name and finalize_glob_module_binding
b-naber Jul 10, 2025
7dfc3e9
Rework borrowing suggestions to use `Expr` instead of just `Span`
estebank Jul 10, 2025
0674eca
Make `Diag::multipart_suggestions` always verbose
estebank Jul 10, 2025
d692444
Update test
estebank Jul 10, 2025
341f12d
Properly track the depth when expanding free alias types
fmease Jul 10, 2025
0fa707b
Rollup merge of #138618 - nbdd0121:asm_const_ptr, r=compiler-errors
tgross35 Jul 10, 2025
00f2a41
Rollup merge of #143642 - Kobzol:stdarch-push, r=Amanieu
tgross35 Jul 10, 2025
5a09646
Rollup merge of #143679 - sebastianpoeplau:preserve-debug-gdb-scripts…
tgross35 Jul 10, 2025
e0eab83
Rollup merge of #143707 - Kobzol:bootstrap-std-check, r=jieyouxu
tgross35 Jul 10, 2025
4476dbe
Rollup merge of #143722 - oli-obk:sound-llvm, r=dianqk
tgross35 Jul 10, 2025
3ebdb8b
Rollup merge of #143728 - LorrensP-2158466:refactor-resolve-extractio…
tgross35 Jul 10, 2025
a85c1bb
Rollup merge of #143742 - estebank:borrow-suggestion, r=compiler-errors
tgross35 Jul 10, 2025
6cd0b1c
Rollup merge of #143744 - fmease:lta-expand-proper-depth, r=compiler-…
tgross35 Jul 10, 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
261 changes: 143 additions & 118 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_span::{Ident, Span, kw, sym};
use tracing::{debug, instrument};

use crate::errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
use crate::imports::Import;
use crate::imports::{Import, NameResolution};
use crate::late::{ConstantHasGenerics, NoConstantGenericsReason, PathSource, Rib, RibKind};
use crate::macros::{MacroRulesScope, sub_namespace_match};
use crate::{
Expand All @@ -37,7 +37,7 @@ impl From<UsePrelude> for bool {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone, Copy)]
enum Shadowing {
Restricted,
Unrestricted,
Expand Down Expand Up @@ -879,53 +879,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
.into_iter()
.find_map(|binding| if binding == ignore_binding { None } else { binding });

if let Some(Finalize { path_span, report_private, used, root_span, .. }) = finalize {
let Some(binding) = binding else {
return Err((Determined, Weak::No));
};

if !self.is_accessible_from(binding.vis, parent_scope.module) {
if report_private {
self.privacy_errors.push(PrivacyError {
ident,
binding,
dedup_span: path_span,
outermost_res: None,
parent_scope: *parent_scope,
single_nested: path_span != root_span,
});
} else {
return Err((Determined, Weak::No));
}
}

// Forbid expanded shadowing to avoid time travel.
if let Some(shadowed_glob) = resolution.shadowed_glob
&& shadowing == Shadowing::Restricted
&& binding.expansion != LocalExpnId::ROOT
&& binding.res() != shadowed_glob.res()
{
self.ambiguity_errors.push(AmbiguityError {
kind: AmbiguityKind::GlobVsExpanded,
ident,
b1: binding,
b2: shadowed_glob,
warning: false,
misc1: AmbiguityErrorMisc::None,
misc2: AmbiguityErrorMisc::None,
});
}

if shadowing == Shadowing::Unrestricted
&& binding.expansion != LocalExpnId::ROOT
&& let NameBindingKind::Import { import, .. } = binding.kind
&& matches!(import.kind, ImportKind::MacroExport)
{
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
}

self.record_use(ident, binding, used);
return Ok(binding);
if let Some(finalize) = finalize {
return self.finalize_module_binding(
ident,
binding,
resolution.shadowed_glob,
parent_scope,
finalize,
shadowing,
);
}

let check_usable = |this: &mut Self, binding: NameBinding<'ra>| {
Expand All @@ -944,75 +906,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

// Check if one of single imports can still define the name,
// if it can then our result is not determined and can be invalidated.
for single_import in &resolution.single_imports {
if ignore_import == Some(*single_import) {
// This branch handles a cycle in single imports.
//
// For example:
// ```
// use a::b;
// use b as a;
// ```
// 1. Record `use a::b` as the `ignore_import` and attempt to locate `a` in the
// current module.
// 2. Encounter the import `use b as a`, which is a `single_import` for `a`,
// and try to find `b` in the current module.
// 3. Re-encounter the `use a::b` import since it's a `single_import` of `b`.
// This leads to entering this branch.
continue;
}
if !self.is_accessible_from(single_import.vis, parent_scope.module) {
continue;
}
if let Some(ignored) = ignore_binding
&& let NameBindingKind::Import { import, .. } = ignored.kind
&& import == *single_import
{
// Ignore not just the binding itself, but if it has a shadowed_glob,
// ignore that, too, because this loop is supposed to only process
// named imports.
continue;
}

let Some(module) = single_import.imported_module.get() else {
return Err((Undetermined, Weak::No));
};
let ImportKind::Single { source, target, target_bindings, .. } = &single_import.kind
else {
unreachable!();
};
if source != target {
// This branch allows the binding to be defined or updated later if the target name
// can hide the source.
if target_bindings.iter().all(|binding| binding.get().is_none()) {
// None of the target bindings are available, so we can't determine
// if this binding is correct or not.
// See more details in #124840
return Err((Undetermined, Weak::No));
} else if target_bindings[ns].get().is_none() && binding.is_some() {
// `binding.is_some()` avoids the condition where the binding
// truly doesn't exist in this namespace and should return `Err(Determined)`.
return Err((Undetermined, Weak::No));
}
}

match self.resolve_ident_in_module(
module,
*source,
ns,
&single_import.parent_scope,
None,
ignore_binding,
ignore_import,
) {
Err((Determined, _)) => continue,
Ok(binding)
if !self.is_accessible_from(binding.vis, single_import.parent_scope.module) =>
{
continue;
}
Ok(_) | Err((Undetermined, _)) => return Err((Undetermined, Weak::No)),
}
if self.single_import_can_define_name(
&resolution,
binding,
ns,
ignore_import,
ignore_binding,
parent_scope,
) {
return Err((Undetermined, Weak::No));
}

// So we have a resolution that's from a glob import. This resolution is determined
Expand Down Expand Up @@ -1101,6 +1003,129 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
Err((Determined, Weak::No))
}

fn finalize_module_binding(
&mut self,
ident: Ident,
binding: Option<NameBinding<'ra>>,
shadowed_glob: Option<NameBinding<'ra>>,
parent_scope: &ParentScope<'ra>,
finalize: Finalize,
shadowing: Shadowing,
) -> Result<NameBinding<'ra>, (Determinacy, Weak)> {
let Finalize { path_span, report_private, used, root_span, .. } = finalize;

let Some(binding) = binding else {
return Err((Determined, Weak::No));
};

if !self.is_accessible_from(binding.vis, parent_scope.module) {
if report_private {
self.privacy_errors.push(PrivacyError {
ident,
binding,
dedup_span: path_span,
outermost_res: None,
parent_scope: *parent_scope,
single_nested: path_span != root_span,
});
} else {
return Err((Determined, Weak::No));
}
}

// Forbid expanded shadowing to avoid time travel.
if let Some(shadowed_glob) = shadowed_glob
&& shadowing == Shadowing::Restricted
&& binding.expansion != LocalExpnId::ROOT
&& binding.res() != shadowed_glob.res()
{
self.ambiguity_errors.push(AmbiguityError {
kind: AmbiguityKind::GlobVsExpanded,
ident,
b1: binding,
b2: shadowed_glob,
warning: false,
misc1: AmbiguityErrorMisc::None,
misc2: AmbiguityErrorMisc::None,
});
}

if shadowing == Shadowing::Unrestricted
&& binding.expansion != LocalExpnId::ROOT
&& let NameBindingKind::Import { import, .. } = binding.kind
&& matches!(import.kind, ImportKind::MacroExport)
{
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
}

self.record_use(ident, binding, used);
return Ok(binding);
}

// Checks if a single import can define the `Ident` corresponding to `binding`.
// This is used to check whether we can definitively accept a glob as a resolution.
fn single_import_can_define_name(
&mut self,
resolution: &NameResolution<'ra>,
binding: Option<NameBinding<'ra>>,
ns: Namespace,
ignore_import: Option<Import<'ra>>,
ignore_binding: Option<NameBinding<'ra>>,
parent_scope: &ParentScope<'ra>,
) -> bool {
for single_import in &resolution.single_imports {
if ignore_import == Some(*single_import) {
continue;
}
if !self.is_accessible_from(single_import.vis, parent_scope.module) {
continue;
}
if let Some(ignored) = ignore_binding
&& let NameBindingKind::Import { import, .. } = ignored.kind
&& import == *single_import
{
continue;
}

let Some(module) = single_import.imported_module.get() else {
return true;
};
let ImportKind::Single { source, target, target_bindings, .. } = &single_import.kind
else {
unreachable!();
};
if source != target {
if target_bindings.iter().all(|binding| binding.get().is_none()) {
return true;
} else if target_bindings[ns].get().is_none() && binding.is_some() {
return true;
}
}

match self.resolve_ident_in_module(
module,
*source,
ns,
&single_import.parent_scope,
None,
ignore_binding,
ignore_import,
) {
Err((Determined, _)) => continue,
Ok(binding)
if !self.is_accessible_from(binding.vis, single_import.parent_scope.module) =>
{
continue;
}
Ok(_) | Err((Undetermined, _)) => {
return true;
}
}
}

false
}

/// Validate a local resolution (from ribs).
#[instrument(level = "debug", skip(self, all_ribs))]
fn validate_res_from_ribs(
Expand Down