Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0cc4f4f

Browse files
committedJan 29, 2025
Auto merge of #136248 - matthiaskrgr:rollup-leaxgfd, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #133382 (Suggest considering casting fn item as fn pointer in more cases) - #136092 (Test pipes also when not running on Windows and Linux simultaneously) - #136190 (Remove duplicated code in RISC-V asm bad-reg test) - #136192 (ci: remove unused windows runner) - #136205 (Properly check that array length is valid type during built-in unsizing in index) - #136211 (Update mdbook to 0.4.44) - #136212 (Tweak `&mut self` suggestion span) - #136214 (Make crate AST mutation accessible for driver callback) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a1d7676 + c941b1c commit 0cc4f4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+321
-206
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,10 +1140,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11401140

11411141
let amp_mut_sugg = match *local_decl.local_info() {
11421142
LocalInfo::User(mir::BindingForm::ImplicitSelf(_)) => {
1143-
let suggestion = suggest_ampmut_self(self.infcx.tcx, decl_span);
1144-
let additional =
1145-
local_trait.map(|span| (span, suggest_ampmut_self(self.infcx.tcx, span)));
1146-
Some(AmpMutSugg { has_sugg: true, span: decl_span, suggestion, additional })
1143+
let (span, suggestion) = suggest_ampmut_self(self.infcx.tcx, decl_span);
1144+
let additional = local_trait.map(|span| suggest_ampmut_self(self.infcx.tcx, span));
1145+
Some(AmpMutSugg { has_sugg: true, span, suggestion, additional })
11471146
}
11481147

11491148
LocalInfo::User(mir::BindingForm::Var(mir::VarBindingForm {
@@ -1202,10 +1201,11 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12021201
opt_ty_info: None,
12031202
..
12041203
})) => {
1205-
let sugg = suggest_ampmut_self(self.infcx.tcx, decl_span);
1204+
let (span, sugg) =
1205+
suggest_ampmut_self(self.infcx.tcx, decl_span);
12061206
Some(AmpMutSugg {
12071207
has_sugg: true,
1208-
span: decl_span,
1208+
span,
12091209
suggestion: sugg,
12101210
additional: None,
12111211
})
@@ -1461,17 +1461,12 @@ fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<Symb
14611461
}
14621462
}
14631463

1464-
fn suggest_ampmut_self<'tcx>(tcx: TyCtxt<'tcx>, span: Span) -> String {
1464+
fn suggest_ampmut_self(tcx: TyCtxt<'_>, span: Span) -> (Span, String) {
14651465
match tcx.sess.source_map().span_to_snippet(span) {
1466-
Ok(snippet) => {
1467-
let lt_pos = snippet.find('\'');
1468-
if let Some(lt_pos) = lt_pos {
1469-
format!("&{}mut self", &snippet[lt_pos..snippet.len() - 4])
1470-
} else {
1471-
"&mut self".to_string()
1472-
}
1466+
Ok(snippet) if snippet.ends_with("self") => {
1467+
(span.with_hi(span.hi() - BytePos(4)).shrink_to_hi(), "mut ".to_string())
14731468
}
1474-
_ => "&mut self".to_string(),
1469+
_ => (span, "&mut self".to_string()),
14751470
}
14761471
}
14771472

‎compiler/rustc_driver_impl/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub trait Callbacks {
160160
fn after_crate_root_parsing(
161161
&mut self,
162162
_compiler: &interface::Compiler,
163-
_queries: &ast::Crate,
163+
_krate: &mut ast::Crate,
164164
) -> Compilation {
165165
Compilation::Continue
166166
}
@@ -311,7 +311,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
311311

312312
// Parse the crate root source code (doesn't parse submodules yet)
313313
// Everything else is parsed during macro expansion.
314-
let krate = passes::parse(sess);
314+
let mut krate = passes::parse(sess);
315315

316316
// If pretty printing is requested: Figure out the representation, print it and exit
317317
if let Some(pp_mode) = sess.opts.pretty {
@@ -328,7 +328,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
328328
return early_exit();
329329
}
330330

331-
if callbacks.after_crate_root_parsing(compiler, &krate) == Compilation::Stop {
331+
if callbacks.after_crate_root_parsing(compiler, &mut krate) == Compilation::Stop {
332332
return early_exit();
333333
}
334334

0 commit comments

Comments
 (0)
Please sign in to comment.