Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
02dac5c
add test suggest-clone-in-macro-issue-139253.rs
xizheyin Jun 17, 2025
fd9c1b9
Find correct span when suggesting using clone
xizheyin Jun 17, 2025
b315e9a
clippy fix: rely on autoderef
hkBst Jul 4, 2025
54cc45d
tests: Don't check for self-printed output in std-backtrace.rs test
Enselic Jul 3, 2025
d77c387
Fixes for Arm64EC
dpaoliello Jul 13, 2025
05154af
docs: update documentation of core::mem::copy to include const on the…
SunkenPotato Jul 15, 2025
690ae52
Tweak borrowck label pointing at `!Copy` value moved into closure
estebank Jul 20, 2025
5082e6a
Generalize logic pointing at binding moved into closure
estebank Jul 20, 2025
8df93e6
Tweak spans when encountering multiline initializer in move error
estebank Jul 20, 2025
dafc9f9
Reduce comment verbosity
estebank Jul 21, 2025
01fdafc
Hint that choose_pivot returns index in bounds
kornelski Jul 22, 2025
6237e73
Point at the type that doesn't impl `Clone` in more cases beyond clos…
estebank Jul 21, 2025
a93a9aa
Don't emit two `assume`s in transmutes when one is a subset of the other
scottmcm Jul 20, 2025
e44a738
Remove dead code and extend test coverage and diagnostics around it
oli-obk Jul 24, 2025
642deb3
remove movability from `RigidTy::Coroutine` and `AggregateKind::Corou…
makai410 Jul 24, 2025
9ffa775
resolve: Remove `Scope::CrateRoot`
petrochenkov Jul 22, 2025
94c0cf8
Rename tests/ui/SUMMARY.md and update rustc dev guide on error-pattern
Oneirical Jul 23, 2025
2e54f7f
Rollup merge of #142569 - xizheyin:139253, r=davidtwco
matthiaskrgr Jul 25, 2025
e9744c9
Rollup merge of #143401 - Enselic:no-stack-backtrace-print-in-display…
matthiaskrgr Jul 25, 2025
dd159ee
Rollup merge of #143424 - hkBst:auto-deref, r=jhpratt
matthiaskrgr Jul 25, 2025
e3b0735
Rollup merge of #143970 - SunkenPotato:update_mem_copy_docs, r=scottmcm
matthiaskrgr Jul 25, 2025
dfbd0c4
Rollup merge of #143979 - dpaoliello:arm64ectest, r=petrochenkov
matthiaskrgr Jul 25, 2025
33a9e4f
Rollup merge of #144200 - estebank:dont-point-at-closure, r=lcnr
matthiaskrgr Jul 25, 2025
f414e7a
Rollup merge of #144209 - scottmcm:assume_less, r=lcnr,dianqk
matthiaskrgr Jul 25, 2025
a2681f9
Rollup merge of #144314 - kornelski:pivot-safely, r=jhpratt
matthiaskrgr Jul 25, 2025
405b2e6
Rollup merge of #144340 - Oneirical:uncertain-illusion, r=jieyouxu
matthiaskrgr Jul 25, 2025
9c257e5
Rollup merge of #144368 - petrochenkov:rmrootscope, r=b-naber
matthiaskrgr Jul 25, 2025
acd4a1c
Rollup merge of #144390 - oli-obk:arbitrary-enum-discrs, r=SparrowLii
matthiaskrgr Jul 25, 2025
1caf701
Rollup merge of #144392 - makai410:rm-mov, r=scottmcm
matthiaskrgr Jul 25, 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
5 changes: 0 additions & 5 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,11 +1076,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
}
}
Scope::CrateRoot => {
let root_ident = Ident::new(kw::PathRoot, ident.span);
let root_module = this.resolve_crate_root(root_ident);
this.add_module_candidates(root_module, &mut suggestions, filter_fn, None);
}
Scope::Module(module, _) => {
this.add_module_candidates(module, &mut suggestions, filter_fn, None);
}
Expand Down
72 changes: 29 additions & 43 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// 6. Language prelude: builtin attributes (closed, controlled).

let rust_2015 = ctxt.edition().is_rust_2015();
let (ns, macro_kind, is_absolute_path) = match scope_set {
ScopeSet::All(ns) => (ns, None, false),
ScopeSet::AbsolutePath(ns) => (ns, None, true),
ScopeSet::Macro(macro_kind) => (MacroNS, Some(macro_kind), false),
ScopeSet::Late(ns, ..) => (ns, None, false),
let (ns, macro_kind) = match scope_set {
ScopeSet::All(ns)
| ScopeSet::ModuleAndExternPrelude(ns, _)
| ScopeSet::Late(ns, ..) => (ns, None),
ScopeSet::Macro(macro_kind) => (MacroNS, Some(macro_kind)),
};
let module = match scope_set {
// Start with the specified module.
ScopeSet::Late(_, module, _) => module,
ScopeSet::Late(_, module, _) | ScopeSet::ModuleAndExternPrelude(_, module) => module,
// Jump out of trait or enum modules, they do not act as scopes.
_ => parent_scope.module.nearest_item_scope(),
};
let module_and_extern_prelude = matches!(scope_set, ScopeSet::ModuleAndExternPrelude(..));
let mut scope = match ns {
_ if is_absolute_path => Scope::CrateRoot,
_ if module_and_extern_prelude => Scope::Module(module, None),
TypeNS | ValueNS => Scope::Module(module, None),
MacroNS => Scope::DeriveHelpers(parent_scope.expansion),
};
Expand Down Expand Up @@ -134,11 +135,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
true
}
Scope::CrateRoot => true,
Scope::Module(..) => true,
Scope::MacroUsePrelude => use_prelude || rust_2015,
Scope::BuiltinAttrs => true,
Scope::ExternPrelude => use_prelude || is_absolute_path,
Scope::ExternPrelude => use_prelude || module_and_extern_prelude,
Scope::ToolPrelude => use_prelude,
Scope::StdLibPrelude => use_prelude || ns == MacroNS,
Scope::BuiltinTypes => true,
Expand Down Expand Up @@ -174,7 +174,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
MacroRulesScope::Empty => Scope::Module(module, None),
},
Scope::CrateRoot => match ns {
Scope::Module(..) if module_and_extern_prelude => match ns {
TypeNS => {
ctxt.adjust(ExpnId::root());
Scope::ExternPrelude
Expand Down Expand Up @@ -203,7 +203,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}
Scope::MacroUsePrelude => Scope::StdLibPrelude,
Scope::BuiltinAttrs => break, // nowhere else to search
Scope::ExternPrelude if is_absolute_path => break,
Scope::ExternPrelude if module_and_extern_prelude => break,
Scope::ExternPrelude => Scope::ToolPrelude,
Scope::ToolPrelude => Scope::StdLibPrelude,
Scope::StdLibPrelude => match ns {
Expand Down Expand Up @@ -404,10 +404,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}

let (ns, macro_kind) = match scope_set {
ScopeSet::All(ns) => (ns, None),
ScopeSet::AbsolutePath(ns) => (ns, None),
ScopeSet::All(ns)
| ScopeSet::ModuleAndExternPrelude(ns, _)
| ScopeSet::Late(ns, ..) => (ns, None),
ScopeSet::Macro(macro_kind) => (MacroNS, Some(macro_kind)),
ScopeSet::Late(ns, ..) => (ns, None),
};

// This is *the* result, resolution from the scope closest to the resolved identifier.
Expand Down Expand Up @@ -487,31 +487,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
MacroRulesScope::Invocation(_) => Err(Determinacy::Undetermined),
_ => Err(Determinacy::Determined),
},
Scope::CrateRoot => {
let root_ident = Ident::new(kw::PathRoot, ident.span);
let root_module = this.resolve_crate_root(root_ident);
let binding = this.resolve_ident_in_module(
ModuleOrUniformRoot::Module(root_module),
ident,
ns,
parent_scope,
finalize,
ignore_binding,
ignore_import,
);
match binding {
Ok(binding) => Ok((binding, Flags::MODULE | Flags::MISC_SUGGEST_CRATE)),
Err((Determinacy::Undetermined, Weak::No)) => {
return Some(Err(Determinacy::determined(force)));
}
Err((Determinacy::Undetermined, Weak::Yes)) => {
Err(Determinacy::Undetermined)
}
Err((Determinacy::Determined, _)) => Err(Determinacy::Determined),
}
}
Scope::Module(module, derive_fallback_lint_id) => {
let adjusted_parent_scope = &ParentScope { module, ..*parent_scope };
let (adjusted_parent_scope, finalize) =
if matches!(scope_set, ScopeSet::ModuleAndExternPrelude(..)) {
(parent_scope, finalize)
} else {
(
&ParentScope { module, ..*parent_scope },
finalize.map(|f| Finalize { used: Used::Scope, ..f }),
)
};
let binding = this.resolve_ident_in_module_unadjusted(
ModuleOrUniformRoot::Module(module),
ident,
Expand All @@ -522,7 +507,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
} else {
Shadowing::Restricted
},
finalize.map(|finalize| Finalize { used: Used::Scope, ..finalize }),
finalize,
ignore_binding,
ignore_import,
);
Expand Down Expand Up @@ -776,7 +761,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
ModuleOrUniformRoot::ExternPrelude => {
ident.span.normalize_to_macros_2_0_and_adjust(ExpnId::root());
}
ModuleOrUniformRoot::CrateRootAndExternPrelude | ModuleOrUniformRoot::CurrentScope => {
ModuleOrUniformRoot::ModuleAndExternPrelude(..) | ModuleOrUniformRoot::CurrentScope => {
// No adjustments
}
}
Expand Down Expand Up @@ -810,11 +795,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
) -> Result<NameBinding<'ra>, (Determinacy, Weak)> {
let module = match module {
ModuleOrUniformRoot::Module(module) => module,
ModuleOrUniformRoot::CrateRootAndExternPrelude => {
ModuleOrUniformRoot::ModuleAndExternPrelude(module) => {
assert_eq!(shadowing, Shadowing::Unrestricted);
let binding = self.early_resolve_ident_in_lexical_scope(
ident,
ScopeSet::AbsolutePath(ns),
ScopeSet::ModuleAndExternPrelude(ns, module),
parent_scope,
finalize,
finalize.is_some(),
Expand Down Expand Up @@ -1531,7 +1516,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
&& self.tcx.sess.at_least_rust_2018()
{
// `::a::b` from 2015 macro on 2018 global edition
module = Some(ModuleOrUniformRoot::CrateRootAndExternPrelude);
let crate_root = self.resolve_crate_root(ident);
module = Some(ModuleOrUniformRoot::ModuleAndExternPrelude(crate_root));
continue;
}
if name == kw::PathRoot || name == kw::Crate || name == kw::DollarCrate {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ pub(crate) struct ImportData<'ra> {
///
/// | `module_path` | `imported_module` | remark |
/// |-|-|-|
/// |`use prefix::foo`| `ModuleOrUniformRoot::Module(prefix)` | - |
/// |`use ::foo` | `ModuleOrUniformRoot::ExternPrelude` | 2018+ editions |
/// |`use ::foo` | `ModuleOrUniformRoot::CrateRootAndExternPrelude` | a special case in 2015 edition |
/// |`use foo` | `ModuleOrUniformRoot::CurrentScope` | - |
/// |`use prefix::foo`| `ModuleOrUniformRoot::Module(prefix)` | - |
/// |`use ::foo` | `ModuleOrUniformRoot::ExternPrelude` | 2018+ editions |
/// |`use ::foo` | `ModuleOrUniformRoot::ModuleAndExternPrelude` | a special case in 2015 edition |
/// |`use foo` | `ModuleOrUniformRoot::CurrentScope` | - |
pub imported_module: Cell<Option<ModuleOrUniformRoot<'ra>>>,
pub vis: Visibility,
}
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ enum Scope<'ra> {
DeriveHelpers(LocalExpnId),
DeriveHelpersCompat,
MacroRules(MacroRulesScopeRef<'ra>),
CrateRoot,
// The node ID is for reporting the `PROC_MACRO_DERIVE_RESOLUTION_FALLBACK`
// lint if it should be reported.
Module(Module<'ra>, Option<NodeId>),
Expand All @@ -139,8 +138,8 @@ enum Scope<'ra> {
enum ScopeSet<'ra> {
/// All scopes with the given namespace.
All(Namespace),
/// Crate root, then extern prelude (used for mixed 2015-2018 mode in macros).
AbsolutePath(Namespace),
/// A module, then extern prelude (used for mixed 2015-2018 mode in macros).
ModuleAndExternPrelude(Namespace, Module<'ra>),
/// All scopes with macro namespace and the given macro kind restriction.
Macro(MacroKind),
/// All scopes with the given namespace, used for partially performing late resolution.
Expand Down Expand Up @@ -419,8 +418,10 @@ enum ModuleOrUniformRoot<'ra> {
/// Regular module.
Module(Module<'ra>),

/// Virtual module that denotes resolution in crate root with fallback to extern prelude.
CrateRootAndExternPrelude,
/// Virtual module that denotes resolution in a module with fallback to extern prelude.
/// Used for paths starting with `::` coming from 2015 edition macros
/// used in 2018+ edition crates.
ModuleAndExternPrelude(Module<'ra>),

/// Virtual module that denotes resolution in extern prelude.
/// Used for paths starting with `::` on 2018 edition.
Expand Down