Skip to content

Commit acb5c16

Browse files
committed
Auto merge of #97342 - JohnTitor:rollup-zqxctaw, r=JohnTitor
Rollup of 5 pull requests Successful merges: - #97240 (Typo suggestion for a variable with a name similar to struct fields) - #97289 (Lifetime variance fixes for clippy) - #97290 (Turn on `fast_submodules` unconditionally) - #97336 (typo) - #97337 (Fix stabilization version of `Ipv6Addr::to_ipv4_mapped`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b8d0cd8 + a1cbf66 commit acb5c16

File tree

17 files changed

+219
-81
lines changed

17 files changed

+219
-81
lines changed

compiler/rustc_interface/src/callbacks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) {
2424
}
2525

2626
/// This is a callback from `rustc_ast` as it cannot access the implicit state
27-
/// in `rustc_middle` otherwise. It is used to when diagnostic messages are
27+
/// in `rustc_middle` otherwise. It is used when diagnostic messages are
2828
/// emitted and stores them in the current query, if there is one.
2929
fn track_diagnostic(diagnostic: &Diagnostic) {
3030
tls::with_context_opt(|icx| {

compiler/rustc_resolve/src/late/diagnostics.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
445445
);
446446
}
447447
}
448+
// Try Levenshtein algorithm.
449+
let typo_sugg = self.lookup_typo_candidate(path, ns, is_expected);
448450
if path.len() == 1 && self.self_type_is_available() {
449451
if let Some(candidate) = self.lookup_assoc_candidate(ident, ns, is_expected) {
450452
let self_is_available = self.self_value_is_available(path[0].ident.span);
@@ -454,7 +456,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
454456
err.span_suggestion(
455457
span,
456458
"you might have meant to use the available field",
457-
format!("self.{}", path_str),
459+
format!("self.{path_str}"),
458460
Applicability::MachineApplicable,
459461
);
460462
} else {
@@ -465,7 +467,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
465467
err.span_suggestion(
466468
span,
467469
"you might have meant to call the method",
468-
format!("self.{}", path_str),
470+
format!("self.{path_str}"),
469471
Applicability::MachineApplicable,
470472
);
471473
}
@@ -476,11 +478,12 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
476478
err.span_suggestion(
477479
span,
478480
&format!("you might have meant to {}", candidate.action()),
479-
format!("Self::{}", path_str),
481+
format!("Self::{path_str}"),
480482
Applicability::MachineApplicable,
481483
);
482484
}
483485
}
486+
self.r.add_typo_suggestion(&mut err, typo_sugg, ident_span);
484487
return (err, candidates);
485488
}
486489

@@ -495,16 +498,14 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
495498

496499
err.span_suggestion(
497500
call_span,
498-
&format!("try calling `{}` as a method", ident),
499-
format!("self.{}({})", path_str, args_snippet),
501+
&format!("try calling `{ident}` as a method"),
502+
format!("self.{path_str}({args_snippet})"),
500503
Applicability::MachineApplicable,
501504
);
502505
return (err, candidates);
503506
}
504507
}
505508

506-
// Try Levenshtein algorithm.
507-
let typo_sugg = self.lookup_typo_candidate(path, ns, is_expected);
508509
// Try context-dependent help if relaxed lookup didn't work.
509510
if let Some(res) = res {
510511
if self.smart_resolve_context_dependent_help(

config.toml.example

-4
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,6 @@ changelog-seen = 2
240240
# Indicate whether git submodules are managed and updated automatically.
241241
#submodules = true
242242

243-
# Update git submodules only when the checked out commit in the submodules differs
244-
# from what is committed in the main rustc repo.
245-
#fast-submodules = true
246-
247243
# The path to (or name of) the GDB executable to use. This is only used for
248244
# executing the debuginfo test suite.
249245
#gdb = "gdb"

library/std/src/net/ip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ impl Ipv6Addr {
16551655
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1).to_ipv4_mapped(), None);
16561656
/// ```
16571657
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
1658-
#[stable(feature = "ipv6_to_ipv4_mapped", since = "1.62.0")]
1658+
#[stable(feature = "ipv6_to_ipv4_mapped", since = "1.63.0")]
16591659
#[must_use = "this returns the result of the operation, \
16601660
without modifying the original"]
16611661
#[inline]

src/bootstrap/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1111
- The options `infodir`, `localstatedir`, and `gpg-password-file` are no longer allowed in config.toml. Previously, they were ignored without warning. Note that `infodir` and `localstatedir` are still accepted by `./configure`, with a warning. [#82451](https://github.com/rust-lang/rust/pull/82451)
1212
- Add options for enabling overflow checks, one for std (`overflow-checks-std`) and one for everything else (`overflow-checks`). Both default to false.
1313
- Change the names for `dist` commands to match the component they generate. [#90684](https://github.com/rust-lang/rust/pull/90684)
14+
- The `build.fast-submodules` option has been removed. Fast submodule checkouts are enabled unconditionally. Automatic submodule handling can still be disabled with `build.submodules = false`.
1415

1516
### Non-breaking changes
1617

src/bootstrap/bootstrap.py

+11-19
Original file line numberDiff line numberDiff line change
@@ -926,23 +926,19 @@ def build_triple(self):
926926
return config
927927
return default_build_triple(self.verbose)
928928

929-
def check_submodule(self, module, slow_submodules):
930-
if not slow_submodules:
931-
checked_out = subprocess.Popen(["git", "rev-parse", "HEAD"],
932-
cwd=os.path.join(self.rust_root, module),
933-
stdout=subprocess.PIPE)
934-
return checked_out
935-
else:
936-
return None
929+
def check_submodule(self, module):
930+
checked_out = subprocess.Popen(["git", "rev-parse", "HEAD"],
931+
cwd=os.path.join(self.rust_root, module),
932+
stdout=subprocess.PIPE)
933+
return checked_out
937934

938935
def update_submodule(self, module, checked_out, recorded_submodules):
939936
module_path = os.path.join(self.rust_root, module)
940937

941-
if checked_out is not None:
942-
default_encoding = sys.getdefaultencoding()
943-
checked_out = checked_out.communicate()[0].decode(default_encoding).strip()
944-
if recorded_submodules[module] == checked_out:
945-
return
938+
default_encoding = sys.getdefaultencoding()
939+
checked_out = checked_out.communicate()[0].decode(default_encoding).strip()
940+
if recorded_submodules[module] == checked_out:
941+
return
946942

947943
print("Updating submodule", module)
948944

@@ -991,12 +987,8 @@ def update_submodules(self):
991987
git_version_str = require(['git', '--version']).split()[2].decode(default_encoding)
992988
self.git_version = distutils.version.LooseVersion(git_version_str)
993989

994-
slow_submodules = self.get_toml('fast-submodules') == "false"
995990
start_time = time()
996-
if slow_submodules:
997-
print('Unconditionally updating submodules')
998-
else:
999-
print('Updating only changed submodules')
991+
print('Updating only changed submodules')
1000992
default_encoding = sys.getdefaultencoding()
1001993
# Only update submodules that are needed to build bootstrap. These are needed because Cargo
1002994
# currently requires everything in a workspace to be "locally present" when starting a
@@ -1022,7 +1014,7 @@ def update_submodules(self):
10221014
filtered_submodules = []
10231015
submodules_names = []
10241016
for module in submodules:
1025-
check = self.check_submodule(module, slow_submodules)
1017+
check = self.check_submodule(module)
10261018
filtered_submodules.append((module, check))
10271019
submodules_names.append(module)
10281020
recorded = subprocess.Popen(["git", "ls-tree", "HEAD"] + submodules_names,

src/bootstrap/config.rs

-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ pub struct Config {
5050
pub ninja_in_file: bool,
5151
pub verbose: usize,
5252
pub submodules: Option<bool>,
53-
pub fast_submodules: bool,
5453
pub compiler_docs: bool,
5554
pub docs_minification: bool,
5655
pub docs: bool,
@@ -517,7 +516,6 @@ define_config! {
517516
compiler_docs: Option<bool> = "compiler-docs",
518517
docs_minification: Option<bool> = "docs-minification",
519518
submodules: Option<bool> = "submodules",
520-
fast_submodules: Option<bool> = "fast-submodules",
521519
gdb: Option<String> = "gdb",
522520
nodejs: Option<String> = "nodejs",
523521
npm: Option<String> = "npm",
@@ -705,7 +703,6 @@ impl Config {
705703
config.rust_optimize = true;
706704
config.rust_optimize_tests = true;
707705
config.submodules = None;
708-
config.fast_submodules = true;
709706
config.docs = true;
710707
config.docs_minification = true;
711708
config.rust_rpath = true;
@@ -847,7 +844,6 @@ impl Config {
847844
set(&mut config.compiler_docs, build.compiler_docs);
848845
set(&mut config.docs_minification, build.docs_minification);
849846
set(&mut config.docs, build.docs);
850-
set(&mut config.fast_submodules, build.fast_submodules);
851847
set(&mut config.locked_deps, build.locked_deps);
852848
set(&mut config.vendor, build.vendor);
853849
set(&mut config.full_bootstrap, build.full_bootstrap);

src/bootstrap/lib.rs

+18-21
Original file line numberDiff line numberDiff line change
@@ -556,27 +556,24 @@ impl Build {
556556
}
557557

558558
// check_submodule
559-
if self.config.fast_submodules {
560-
let checked_out_hash = output(
561-
Command::new("git").args(&["rev-parse", "HEAD"]).current_dir(&absolute_path),
562-
);
563-
// update_submodules
564-
let recorded = output(
565-
Command::new("git")
566-
.args(&["ls-tree", "HEAD"])
567-
.arg(relative_path)
568-
.current_dir(&self.config.src),
569-
);
570-
let actual_hash = recorded
571-
.split_whitespace()
572-
.nth(2)
573-
.unwrap_or_else(|| panic!("unexpected output `{}`", recorded));
574-
575-
// update_submodule
576-
if actual_hash == checked_out_hash.trim_end() {
577-
// already checked out
578-
return;
579-
}
559+
let checked_out_hash =
560+
output(Command::new("git").args(&["rev-parse", "HEAD"]).current_dir(&absolute_path));
561+
// update_submodules
562+
let recorded = output(
563+
Command::new("git")
564+
.args(&["ls-tree", "HEAD"])
565+
.arg(relative_path)
566+
.current_dir(&self.config.src),
567+
);
568+
let actual_hash = recorded
569+
.split_whitespace()
570+
.nth(2)
571+
.unwrap_or_else(|| panic!("unexpected output `{}`", recorded));
572+
573+
// update_submodule
574+
if actual_hash == checked_out_hash.trim_end() {
575+
// already checked out
576+
return;
580577
}
581578

582579
println!("Updating submodule {}", relative_path.display());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
struct A {
2+
config: String,
3+
}
4+
5+
impl A {
6+
fn new(cofig: String) -> Self {
7+
Self { config } //~ Error cannot find value `config` in this scope
8+
}
9+
10+
fn do_something(cofig: String) {
11+
println!("{config}"); //~ Error cannot find value `config` in this scope
12+
}
13+
14+
fn self_is_available(self, cofig: String) {
15+
println!("{config}"); //~ Error cannot find value `config` in this scope
16+
}
17+
}
18+
19+
trait B {
20+
const BAR: u32 = 3;
21+
type Baz;
22+
fn bar(&self);
23+
fn baz(&self) {}
24+
fn bah() {}
25+
}
26+
27+
impl B for Box<isize> {
28+
type Baz = String;
29+
fn bar(&self) {
30+
// let baz = 3;
31+
baz();
32+
//~^ ERROR cannot find function `baz`
33+
bah;
34+
//~^ ERROR cannot find value `bah`
35+
BAR;
36+
//~^ ERROR cannot find value `BAR` in this scope
37+
let foo: Baz = "".to_string();
38+
//~^ ERROR cannot find type `Baz` in this scope
39+
}
40+
}
41+
42+
fn ba() {}
43+
const BARR: u32 = 3;
44+
type Bar = String;
45+
46+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
error[E0425]: cannot find value `config` in this scope
2+
--> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:7:16
3+
|
4+
LL | Self { config }
5+
| ^^^^^^
6+
| |
7+
| a field by this name exists in `Self`
8+
| help: a local variable with a similar name exists: `cofig`
9+
10+
error[E0425]: cannot find value `config` in this scope
11+
--> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:11:20
12+
|
13+
LL | println!("{config}");
14+
| ^^^^^^
15+
| |
16+
| a field by this name exists in `Self`
17+
| help: a local variable with a similar name exists: `cofig`
18+
19+
error[E0425]: cannot find value `config` in this scope
20+
--> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:15:20
21+
|
22+
LL | println!("{config}");
23+
| ^^^^^^
24+
|
25+
help: you might have meant to use the available field
26+
|
27+
LL | println!("{self.config}");
28+
| ~~~~~~~~~~~
29+
help: a local variable with a similar name exists
30+
|
31+
LL | println!("{cofig}");
32+
| ~~~~~
33+
34+
error[E0425]: cannot find function `baz` in this scope
35+
--> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:31:9
36+
|
37+
LL | baz();
38+
| ^^^
39+
...
40+
LL | fn ba() {}
41+
| ------- similarly named function `ba` defined here
42+
|
43+
help: you might have meant to call the method
44+
|
45+
LL | self.baz();
46+
| ~~~~~~~~
47+
help: a function with a similar name exists
48+
|
49+
LL | ba();
50+
| ~~
51+
52+
error[E0425]: cannot find value `bah` in this scope
53+
--> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:33:9
54+
|
55+
LL | bah;
56+
| ^^^
57+
...
58+
LL | fn ba() {}
59+
| ------- similarly named function `ba` defined here
60+
|
61+
help: you might have meant to call the associated function
62+
|
63+
LL | Self::bah;
64+
| ~~~~~~~~~
65+
help: a function with a similar name exists
66+
|
67+
LL | ba;
68+
| ~~
69+
70+
error[E0425]: cannot find value `BAR` in this scope
71+
--> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:35:9
72+
|
73+
LL | BAR;
74+
| ^^^
75+
...
76+
LL | const BARR: u32 = 3;
77+
| -------------------- similarly named constant `BARR` defined here
78+
|
79+
help: you might have meant to use the associated `const`
80+
|
81+
LL | Self::BAR;
82+
| ~~~~~~~~~
83+
help: a constant with a similar name exists
84+
|
85+
LL | BARR;
86+
| ~~~~
87+
88+
error[E0412]: cannot find type `Baz` in this scope
89+
--> $DIR/typo-suggestion-for-variable-with-name-similar-to-struct-field.rs:37:18
90+
|
91+
LL | let foo: Baz = "".to_string();
92+
| ^^^
93+
...
94+
LL | type Bar = String;
95+
| ------------------ similarly named type alias `Bar` defined here
96+
|
97+
help: you might have meant to use the associated type
98+
|
99+
LL | let foo: Self::Baz = "".to_string();
100+
| ~~~~~~~~~
101+
help: a type alias with a similar name exists
102+
|
103+
LL | let foo: Bar = "".to_string();
104+
| ~~~
105+
106+
error: aborting due to 7 previous errors
107+
108+
Some errors have detailed explanations: E0412, E0425.
109+
For more information about an error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)