Skip to content

Commit 507bff9

Browse files
committed
Auto merge of #80510 - JohnTitor:rollup-gow7y0l, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #80185 (Fix ICE when pointing at multi bytes character) - #80260 (slightly more typed interface to panic implementation) - #80311 (Improvements to NatVis support) - #80337 (Use `desc` as a doc-comment for queries if there are no doc comments) - #80381 (Revert "Cleanup markdown span handling") - #80492 (remove empty wraps, don't return Results from from infallible functions) - #80509 (where possible, pass slices instead of &Vec or &String (clippy::ptr_arg)) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents bbcaed0 + 41fa0db commit 507bff9

File tree

45 files changed

+387
-279
lines changed

Some content is hidden

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

45 files changed

+387
-279
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ pub(crate) unsafe fn optimize(
485485
diag_handler: &Handler,
486486
module: &ModuleCodegen<ModuleLlvm>,
487487
config: &ModuleConfig,
488-
) -> Result<(), FatalError> {
488+
) {
489489
let _timer = cgcx.prof.generic_activity_with_arg("LLVM_module_optimize", &module.name[..]);
490490

491491
let llmod = module.module_llvm.llmod();
@@ -511,7 +511,7 @@ pub(crate) unsafe fn optimize(
511511
_ => llvm::OptStage::PreLinkNoLTO,
512512
};
513513
optimize_with_new_llvm_pass_manager(cgcx, module, config, opt_level, opt_stage);
514-
return Ok(());
514+
return;
515515
}
516516

517517
if cgcx.prof.llvm_recording_enabled() {
@@ -634,7 +634,6 @@ pub(crate) unsafe fn optimize(
634634
llvm::LLVMDisposePassManager(fpm);
635635
llvm::LLVMDisposePassManager(mpm);
636636
}
637-
Ok(())
638637
}
639638

640639
unsafe fn add_sanitizer_passes(config: &ModuleConfig, passes: &mut Vec<&'static mut llvm::Pass>) {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2322,13 +2322,13 @@ fn set_members_of_composite_type(
23222322
DIB(cx),
23232323
composite_type_metadata,
23242324
Some(type_array),
2325-
type_params,
2325+
Some(type_params),
23262326
);
23272327
}
23282328
}
23292329

23302330
/// Computes the type parameters for a type, if any, for the given metadata.
2331-
fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> Option<&'ll DIArray> {
2331+
fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> &'ll DIArray {
23322332
if let ty::Adt(def, substs) = *ty.kind() {
23332333
if substs.types().next().is_some() {
23342334
let generics = cx.tcx.generics_of(def.did);
@@ -2358,10 +2358,10 @@ fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> Option<&'
23582358
})
23592359
.collect();
23602360

2361-
return Some(create_DIArray(DIB(cx), &template_params[..]));
2361+
return create_DIArray(DIB(cx), &template_params[..]);
23622362
}
23632363
}
2364-
return Some(create_DIArray(DIB(cx), &[]));
2364+
return create_DIArray(DIB(cx), &[]);
23652365

23662366
fn get_parameter_names(cx: &CodegenCx<'_, '_>, generics: &ty::Generics) -> Vec<Symbol> {
23672367
let mut names = generics

compiler/rustc_codegen_llvm/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
160160
module: &ModuleCodegen<Self::Module>,
161161
config: &ModuleConfig,
162162
) -> Result<(), FatalError> {
163-
back::write::optimize(cgcx, diag_handler, module, config)
163+
Ok(back::write::optimize(cgcx, diag_handler, module, config))
164164
}
165165
unsafe fn optimize_thin(
166166
cgcx: &CodegenContext<Self>,

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
522522
mut bx: Bx,
523523
terminator: &mir::Terminator<'tcx>,
524524
func: &mir::Operand<'tcx>,
525-
args: &Vec<mir::Operand<'tcx>>,
525+
args: &[mir::Operand<'tcx>],
526526
destination: &Option<(mir::Place<'tcx>, mir::BasicBlock)>,
527527
cleanup: Option<mir::BasicBlock>,
528528
fn_span: Span,

compiler/rustc_driver/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
603603
}
604604
}
605605

606-
fn show_content_with_pager(content: &String) {
606+
fn show_content_with_pager(content: &str) {
607607
let pager_name = env::var_os("PAGER").unwrap_or_else(|| {
608608
if cfg!(windows) { OsString::from("more.com") } else { OsString::from("less") }
609609
});

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
417417
// obviously it never weeds out ALL errors.
418418
fn process_errors(
419419
&self,
420-
errors: &Vec<RegionResolutionError<'tcx>>,
420+
errors: &[RegionResolutionError<'tcx>],
421421
) -> Vec<RegionResolutionError<'tcx>> {
422422
debug!("process_errors()");
423423

@@ -442,7 +442,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
442442
};
443443

444444
let mut errors = if errors.iter().all(|e| is_bound_failure(e)) {
445-
errors.clone()
445+
errors.to_owned()
446446
} else {
447447
errors.iter().filter(|&e| !is_bound_failure(e)).cloned().collect()
448448
};

compiler/rustc_macros/src/query.rs

+36-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use syn::parse::{Parse, ParseStream, Result};
55
use syn::punctuated::Punctuated;
66
use syn::spanned::Spanned;
77
use syn::{
8-
braced, parenthesized, parse_macro_input, AttrStyle, Attribute, Block, Error, Expr, Ident,
9-
ReturnType, Token, Type,
8+
braced, parenthesized, parse_macro_input, parse_quote, AttrStyle, Attribute, Block, Error,
9+
Expr, Ident, ReturnType, Token, Type,
1010
};
1111

1212
mod kw {
@@ -272,6 +272,40 @@ fn process_modifiers(query: &mut Query) -> QueryModifiers {
272272
if desc.is_some() {
273273
panic!("duplicate modifier `desc` for query `{}`", query.name);
274274
}
275+
// If there are no doc-comments, give at least some idea of what
276+
// it does by showing the query description.
277+
if query.doc_comments.is_empty() {
278+
use ::syn::*;
279+
let mut list = list.iter();
280+
let format_str: String = match list.next() {
281+
Some(&Expr::Lit(ExprLit { lit: Lit::Str(ref lit_str), .. })) => {
282+
lit_str.value().replace("`{}`", "{}") // We add them later anyways for consistency
283+
}
284+
_ => panic!("Expected a string literal"),
285+
};
286+
let mut fmt_fragments = format_str.split("{}");
287+
let mut doc_string = fmt_fragments.next().unwrap().to_string();
288+
list.map(::quote::ToTokens::to_token_stream).zip(fmt_fragments).for_each(
289+
|(tts, next_fmt_fragment)| {
290+
use ::core::fmt::Write;
291+
write!(
292+
&mut doc_string,
293+
" `{}` {}",
294+
tts.to_string().replace(" . ", "."),
295+
next_fmt_fragment,
296+
)
297+
.unwrap();
298+
},
299+
);
300+
let doc_string = format!(
301+
"[query description - consider adding a doc-comment!] {}",
302+
doc_string
303+
);
304+
let comment = parse_quote! {
305+
#[doc = #doc_string]
306+
};
307+
query.doc_comments.push(comment);
308+
}
275309
desc = Some((tcx, list));
276310
}
277311
QueryModifier::FatalCycle => {

compiler/rustc_macros/src/session_diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl<'a> SessionDiagnosticDeriveBuilder<'a> {
574574
/// format!("Expected a point greater than ({x}, {y})", x = self.x, y = self.y)
575575
/// ```
576576
/// This function builds the entire call to format!.
577-
fn build_format(&self, input: &String, span: proc_macro2::Span) -> proc_macro2::TokenStream {
577+
fn build_format(&self, input: &str, span: proc_macro2::Span) -> proc_macro2::TokenStream {
578578
// This set is used later to generate the final format string. To keep builds reproducible,
579579
// the iteration order needs to be deterministic, hence why we use a BTreeSet here instead
580580
// of a HashSet.

compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
954954
&self,
955955
def_id: DefId,
956956
target_place: PlaceRef<'tcx>,
957-
places: &Vec<Operand<'tcx>>,
957+
places: &[Operand<'tcx>],
958958
) -> Option<(Span, Option<GeneratorKind>, Span)> {
959959
debug!(
960960
"closure_span: def_id={:?} target_place={:?} places={:?}",

compiler/rustc_mir/src/borrow_check/type_check/liveness/local_use_map.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ impl vll::LinkElem for Appearance {
5858
}
5959

6060
impl LocalUseMap {
61-
crate fn build(
62-
live_locals: &Vec<Local>,
63-
elements: &RegionValueElements,
64-
body: &Body<'_>,
65-
) -> Self {
61+
crate fn build(live_locals: &[Local], elements: &RegionValueElements, body: &Body<'_>) -> Self {
6662
let nones = IndexVec::from_elem_n(None, body.local_decls.len());
6763
let mut local_use_map = LocalUseMap {
6864
first_def_at: nones.clone(),

compiler/rustc_mir/src/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<T: Copy + Eq + Hash + std::fmt::Debug, PATH: Default> RefTracking<T, PATH>
153153
}
154154

155155
/// Format a path
156-
fn write_path(out: &mut String, path: &Vec<PathElem>) {
156+
fn write_path(out: &mut String, path: &[PathElem]) {
157157
use self::PathElem::*;
158158

159159
for elem in path.iter() {

compiler/rustc_mir/src/transform/coverage/counters.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'a> BcbCounters<'a> {
140140
/// message for subsequent debugging.
141141
fn make_bcb_counters(
142142
&mut self,
143-
coverage_spans: &Vec<CoverageSpan>,
143+
coverage_spans: &[CoverageSpan],
144144
) -> Result<Vec<CoverageKind>, Error> {
145145
debug!("make_bcb_counters(): adding a counter or expression to each BasicCoverageBlock");
146146
let num_bcbs = self.basic_coverage_blocks.num_nodes();
@@ -465,7 +465,7 @@ impl<'a> BcbCounters<'a> {
465465
fn choose_preferred_expression_branch(
466466
&self,
467467
traversal: &TraverseCoverageGraphWithLoops,
468-
branches: &Vec<BcbBranch>,
468+
branches: &[BcbBranch],
469469
) -> BcbBranch {
470470
let branch_needs_a_counter =
471471
|branch: &BcbBranch| branch.counter(&self.basic_coverage_blocks).is_none();
@@ -509,7 +509,7 @@ impl<'a> BcbCounters<'a> {
509509
fn find_some_reloop_branch(
510510
&self,
511511
traversal: &TraverseCoverageGraphWithLoops,
512-
branches: &Vec<BcbBranch>,
512+
branches: &[BcbBranch],
513513
) -> Option<BcbBranch> {
514514
let branch_needs_a_counter =
515515
|branch: &BcbBranch| branch.counter(&self.basic_coverage_blocks).is_none();

compiler/rustc_mir/src/transform/function_item_references.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a, 'tcx> FunctionItemRefChecker<'a, 'tcx> {
9999
&self,
100100
def_id: DefId,
101101
substs_ref: SubstsRef<'tcx>,
102-
args: &Vec<Operand<'tcx>>,
102+
args: &[Operand<'tcx>],
103103
source_info: SourceInfo,
104104
) {
105105
let param_env = self.tcx.param_env(def_id);
@@ -162,7 +162,7 @@ impl<'a, 'tcx> FunctionItemRefChecker<'a, 'tcx> {
162162
.unwrap_or(None)
163163
}
164164

165-
fn nth_arg_span(&self, args: &Vec<Operand<'tcx>>, n: usize) -> Span {
165+
fn nth_arg_span(&self, args: &[Operand<'tcx>], n: usize) -> Span {
166166
match &args[n] {
167167
Operand::Copy(place) | Operand::Move(place) => {
168168
self.body.local_decls[place.local].source_info.span

compiler/rustc_mir_build/src/build/expr/as_place.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ crate struct PlaceBuilder<'tcx> {
7979
/// part of a path that is captued by a closure. We stop applying projections once we see the first
8080
/// projection that isn't captured by a closure.
8181
fn convert_to_hir_projections_and_truncate_for_capture<'tcx>(
82-
mir_projections: &Vec<PlaceElem<'tcx>>,
82+
mir_projections: &[PlaceElem<'tcx>],
8383
) -> Vec<HirProjectionKind> {
8484

8585
let mut hir_projections = Vec::new();
@@ -128,7 +128,7 @@ fn convert_to_hir_projections_and_truncate_for_capture<'tcx>(
128128
/// list are being applied to the same root variable.
129129
fn is_ancestor_or_same_capture(
130130
proj_possible_ancestor: &Vec<HirProjectionKind>,
131-
proj_capture: &Vec<HirProjectionKind>,
131+
proj_capture: &[HirProjectionKind],
132132
) -> bool {
133133
// We want to make sure `is_ancestor_or_same_capture("x.0.0", "x.0")` to return false.
134134
// Therefore we can't just check if all projections are same in the zipped iterator below.
@@ -171,7 +171,7 @@ fn find_capture_matching_projections<'a, 'tcx>(
171171
typeck_results: &'a ty::TypeckResults<'tcx>,
172172
var_hir_id: HirId,
173173
closure_def_id: DefId,
174-
projections: &Vec<PlaceElem<'tcx>>,
174+
projections: &[PlaceElem<'tcx>],
175175
) -> Option<(usize, &'a ty::CapturedPlace<'tcx>)> {
176176
let closure_min_captures = typeck_results.closure_min_captures.get(&closure_def_id)?;
177177
let root_variable_min_captures = closure_min_captures.get(&var_hir_id)?;

compiler/rustc_parse/src/parser/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -721,13 +721,9 @@ impl<'a> Parser<'a> {
721721
Ok(t) => {
722722
// Parsed successfully, therefore most probably the code only
723723
// misses a separator.
724-
let mut exp_span = self.sess.source_map().next_point(sp);
725-
if self.sess.source_map().is_multiline(exp_span) {
726-
exp_span = sp;
727-
}
728724
expect_err
729725
.span_suggestion_short(
730-
exp_span,
726+
sp,
731727
&format!("missing `{}`", token_str),
732728
token_str,
733729
Applicability::MaybeIncorrect,

compiler/rustc_resolve/src/build_reduced_graph.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ impl<'a> Resolver<'a> {
185185

186186
crate fn get_macro(&mut self, res: Res) -> Option<Lrc<SyntaxExtension>> {
187187
match res {
188-
Res::Def(DefKind::Macro(..), def_id) => self.get_macro_by_def_id(def_id),
188+
Res::Def(DefKind::Macro(..), def_id) => Some(self.get_macro_by_def_id(def_id)),
189189
Res::NonMacroAttr(attr_kind) => Some(self.non_macro_attr(attr_kind.is_used())),
190190
_ => None,
191191
}
192192
}
193193

194-
crate fn get_macro_by_def_id(&mut self, def_id: DefId) -> Option<Lrc<SyntaxExtension>> {
194+
crate fn get_macro_by_def_id(&mut self, def_id: DefId) -> Lrc<SyntaxExtension> {
195195
if let Some(ext) = self.macro_map.get(&def_id) {
196-
return Some(ext.clone());
196+
return ext.clone();
197197
}
198198

199199
let ext = Lrc::new(match self.cstore().load_macro_untracked(def_id, &self.session) {
@@ -202,7 +202,7 @@ impl<'a> Resolver<'a> {
202202
});
203203

204204
self.macro_map.insert(def_id, ext.clone());
205-
Some(ext)
205+
ext
206206
}
207207

208208
crate fn build_reduced_graph(

compiler/rustc_resolve/src/late.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1151,13 +1151,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
11511151
/// When evaluating a `trait` use its associated types' idents for suggestions in E0412.
11521152
fn with_trait_items<T>(
11531153
&mut self,
1154-
trait_items: &'ast Vec<P<AssocItem>>,
1154+
trait_items: &'ast [P<AssocItem>],
11551155
f: impl FnOnce(&mut Self) -> T,
11561156
) -> T {
1157-
let trait_assoc_items = replace(
1158-
&mut self.diagnostic_metadata.current_trait_assoc_items,
1159-
Some(&trait_items[..]),
1160-
);
1157+
let trait_assoc_items =
1158+
replace(&mut self.diagnostic_metadata.current_trait_assoc_items, Some(&trait_items));
11611159
let result = f(self);
11621160
self.diagnostic_metadata.current_trait_assoc_items = trait_assoc_items;
11631161
result

compiler/rustc_resolve/src/lib.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1991,14 +1991,13 @@ impl<'a> Resolver<'a> {
19911991
{
19921992
// The macro is a proc macro derive
19931993
if let Some(def_id) = module.expansion.expn_data().macro_def_id {
1994-
if let Some(ext) = self.get_macro_by_def_id(def_id) {
1995-
if !ext.is_builtin
1996-
&& ext.macro_kind() == MacroKind::Derive
1997-
&& parent.expansion.outer_expn_is_descendant_of(span.ctxt())
1998-
{
1999-
*poisoned = Some(node_id);
2000-
return module.parent;
2001-
}
1994+
let ext = self.get_macro_by_def_id(def_id);
1995+
if !ext.is_builtin
1996+
&& ext.macro_kind() == MacroKind::Derive
1997+
&& parent.expansion.outer_expn_is_descendant_of(span.ctxt())
1998+
{
1999+
*poisoned = Some(node_id);
2000+
return module.parent;
20022001
}
20032002
}
20042003
}

compiler/rustc_session/src/filesearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'a> FileSearch<'a> {
7676
pub fn new(
7777
sysroot: &'a Path,
7878
triple: &'a str,
79-
search_paths: &'a Vec<SearchPath>,
79+
search_paths: &'a [SearchPath],
8080
tlib_path: &'a SearchPath,
8181
kind: PathKind,
8282
) -> FileSearch<'a> {

0 commit comments

Comments
 (0)