Skip to content

Commit c0a54cc

Browse files
committed
Auto merge of rust-lang#82530 - Aaron1011:rollup-aalwq15, r=Aaron1011
Rollup of 11 pull requests Successful merges: - rust-lang#82269 (Cleanup `PpMode` and friends) - rust-lang#82431 (Set RUST_BACKTRACE=0 when running `treat-err-as-bug` tests) - rust-lang#82441 (Fix typo in sanitizer flag in unstable book.) - rust-lang#82463 (panic_bounds_checks should be panic_bounds_check) - rust-lang#82464 (Update outdated comment in unix Command.) - rust-lang#82467 (library: Normalize safety-for-unsafe-block comments) - rust-lang#82468 (Move pick_by_value_method docs above function header) - rust-lang#82484 (rustdoc: Remove duplicate "List of all items") - rust-lang#82502 (Only look for HTML `tidy` when running rustdoc tests) - rust-lang#82503 (fix typo in `pre-commit.sh`) - rust-lang#82510 (Fix typo in `param_env_reveal_all_normalized`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 98f8cce + 42e53ff commit c0a54cc

File tree

24 files changed

+174
-168
lines changed

24 files changed

+174
-168
lines changed

compiler/rustc_driver/src/pretty.rs

+27-45
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir_pretty as pprust_hir;
99
use rustc_middle::hir::map as hir_map;
1010
use rustc_middle::ty::{self, TyCtxt};
1111
use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
12-
use rustc_session::config::{Input, PpMode, PpSourceMode};
12+
use rustc_session::config::{Input, PpHirMode, PpMode, PpSourceMode};
1313
use rustc_session::Session;
1414
use rustc_span::symbol::Ident;
1515
use rustc_span::FileName;
@@ -42,43 +42,41 @@ where
4242
F: FnOnce(&dyn PrinterSupport) -> A,
4343
{
4444
match *ppmode {
45-
PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
45+
Normal | EveryBodyLoops | Expanded => {
4646
let annotation = NoAnn { sess, tcx };
4747
f(&annotation)
4848
}
4949

50-
PpmIdentified | PpmExpandedIdentified => {
50+
Identified | ExpandedIdentified => {
5151
let annotation = IdentifiedAnnotation { sess, tcx };
5252
f(&annotation)
5353
}
54-
PpmExpandedHygiene => {
54+
ExpandedHygiene => {
5555
let annotation = HygieneAnnotation { sess };
5656
f(&annotation)
5757
}
58-
_ => panic!("Should use call_with_pp_support_hir"),
5958
}
6059
}
61-
fn call_with_pp_support_hir<A, F>(ppmode: &PpSourceMode, tcx: TyCtxt<'_>, f: F) -> A
60+
fn call_with_pp_support_hir<A, F>(ppmode: &PpHirMode, tcx: TyCtxt<'_>, f: F) -> A
6261
where
6362
F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate<'_>) -> A,
6463
{
6564
match *ppmode {
66-
PpmNormal => {
65+
PpHirMode::Normal => {
6766
let annotation = NoAnn { sess: tcx.sess, tcx: Some(tcx) };
6867
f(&annotation, tcx.hir().krate())
6968
}
7069

71-
PpmIdentified => {
70+
PpHirMode::Identified => {
7271
let annotation = IdentifiedAnnotation { sess: tcx.sess, tcx: Some(tcx) };
7372
f(&annotation, tcx.hir().krate())
7473
}
75-
PpmTyped => {
74+
PpHirMode::Typed => {
7675
abort_on_err(tcx.analysis(LOCAL_CRATE), tcx.sess);
7776

7877
let annotation = TypedAnnotation { tcx, maybe_typeck_results: Cell::new(None) };
7978
tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate()))
8079
}
81-
_ => panic!("Should use call_with_pp_support"),
8280
}
8381
}
8482

@@ -393,16 +391,13 @@ pub fn print_after_parsing(
393391
) {
394392
let (src, src_name) = get_source(input, sess);
395393

396-
let mut out = String::new();
397-
398-
if let PpmSource(s) = ppm {
394+
let out = if let Source(s) = ppm {
399395
// Silently ignores an identified node.
400-
let out = &mut out;
401396
call_with_pp_support(&s, sess, None, move |annotation| {
402397
debug!("pretty printing source code {:?}", s);
403398
let sess = annotation.sess();
404399
let parse = &sess.parse_sess;
405-
*out = pprust::print_crate(
400+
pprust::print_crate(
406401
sess.source_map(),
407402
krate,
408403
src_name,
@@ -413,7 +408,7 @@ pub fn print_after_parsing(
413408
)
414409
})
415410
} else {
416-
unreachable!();
411+
unreachable!()
417412
};
418413

419414
write_or_print(&out, ofile);
@@ -433,17 +428,14 @@ pub fn print_after_hir_lowering<'tcx>(
433428

434429
let (src, src_name) = get_source(input, tcx.sess);
435430

436-
let mut out = String::new();
437-
438-
match ppm {
439-
PpmSource(s) => {
431+
let out = match ppm {
432+
Source(s) => {
440433
// Silently ignores an identified node.
441-
let out = &mut out;
442434
call_with_pp_support(&s, tcx.sess, Some(tcx), move |annotation| {
443435
debug!("pretty printing source code {:?}", s);
444436
let sess = annotation.sess();
445437
let parse = &sess.parse_sess;
446-
*out = pprust::print_crate(
438+
pprust::print_crate(
447439
sess.source_map(),
448440
krate,
449441
src_name,
@@ -455,26 +447,20 @@ pub fn print_after_hir_lowering<'tcx>(
455447
})
456448
}
457449

458-
PpmHir(s) => {
459-
let out = &mut out;
460-
call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
461-
debug!("pretty printing source code {:?}", s);
462-
let sess = annotation.sess();
463-
let sm = sess.source_map();
464-
*out = pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann())
465-
})
466-
}
450+
Hir(s) => call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
451+
debug!("pretty printing HIR {:?}", s);
452+
let sess = annotation.sess();
453+
let sm = sess.source_map();
454+
pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann())
455+
}),
467456

468-
PpmHirTree(s) => {
469-
let out = &mut out;
470-
call_with_pp_support_hir(&s, tcx, move |_annotation, krate| {
471-
debug!("pretty printing source code {:?}", s);
472-
*out = format!("{:#?}", krate);
473-
});
474-
}
457+
HirTree => call_with_pp_support_hir(&PpHirMode::Normal, tcx, move |_annotation, krate| {
458+
debug!("pretty printing HIR tree");
459+
format!("{:#?}", krate)
460+
}),
475461

476462
_ => unreachable!(),
477-
}
463+
};
478464

479465
write_or_print(&out, ofile);
480466
}
@@ -493,14 +479,10 @@ fn print_with_analysis(
493479
tcx.analysis(LOCAL_CRATE)?;
494480

495481
match ppm {
496-
PpmMir | PpmMirCFG => match ppm {
497-
PpmMir => write_mir_pretty(tcx, None, &mut out),
498-
PpmMirCFG => write_mir_graphviz(tcx, None, &mut out),
499-
_ => unreachable!(),
500-
},
482+
Mir => write_mir_pretty(tcx, None, &mut out).unwrap(),
483+
MirCFG => write_mir_graphviz(tcx, None, &mut out).unwrap(),
501484
_ => unreachable!(),
502485
}
503-
.unwrap();
504486

505487
let out = std::str::from_utf8(&out).unwrap();
506488
write_or_print(out, ofile);

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ fn configure_and_expand_inner<'a>(
350350
rustc_builtin_macros::test_harness::inject(&sess, &mut resolver, &mut krate)
351351
});
352352

353-
if let Some(PpMode::PpmSource(PpSourceMode::PpmEveryBodyLoops)) = sess.opts.pretty {
353+
if let Some(PpMode::Source(PpSourceMode::EveryBodyLoops)) = sess.opts.pretty {
354354
tracing::debug!("replacing bodies with loop {{}}");
355355
util::ReplaceBodyWithLoop::new(&mut resolver).visit_crate(&mut krate);
356356
}

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ rustc_queries! {
956956
desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
957957
}
958958

959-
/// Like `param_env`, but returns the `ParamEnv in `Reveal::All` mode.
959+
/// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
960960
/// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
961961
/// as this method is more efficient.
962962
query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {

compiler/rustc_session/src/config.rs

+64-53
Original file line numberDiff line numberDiff line change
@@ -2057,40 +2057,21 @@ fn parse_pretty(
20572057
debugging_opts: &DebuggingOptions,
20582058
efmt: ErrorOutputType,
20592059
) -> Option<PpMode> {
2060-
let pretty = if debugging_opts.unstable_options {
2061-
matches.opt_default("pretty", "normal").map(|a| {
2062-
// stable pretty-print variants only
2063-
parse_pretty_inner(efmt, &a, false)
2064-
})
2065-
} else {
2066-
None
2067-
};
2068-
2069-
return if pretty.is_none() {
2070-
debugging_opts.unpretty.as_ref().map(|a| {
2071-
// extended with unstable pretty-print variants
2072-
parse_pretty_inner(efmt, &a, true)
2073-
})
2074-
} else {
2075-
pretty
2076-
};
2077-
20782060
fn parse_pretty_inner(efmt: ErrorOutputType, name: &str, extended: bool) -> PpMode {
20792061
use PpMode::*;
2080-
use PpSourceMode::*;
20812062
let first = match (name, extended) {
2082-
("normal", _) => PpmSource(PpmNormal),
2083-
("identified", _) => PpmSource(PpmIdentified),
2084-
("everybody_loops", true) => PpmSource(PpmEveryBodyLoops),
2085-
("expanded", _) => PpmSource(PpmExpanded),
2086-
("expanded,identified", _) => PpmSource(PpmExpandedIdentified),
2087-
("expanded,hygiene", _) => PpmSource(PpmExpandedHygiene),
2088-
("hir", true) => PpmHir(PpmNormal),
2089-
("hir,identified", true) => PpmHir(PpmIdentified),
2090-
("hir,typed", true) => PpmHir(PpmTyped),
2091-
("hir-tree", true) => PpmHirTree(PpmNormal),
2092-
("mir", true) => PpmMir,
2093-
("mir-cfg", true) => PpmMirCFG,
2063+
("normal", _) => Source(PpSourceMode::Normal),
2064+
("identified", _) => Source(PpSourceMode::Identified),
2065+
("everybody_loops", true) => Source(PpSourceMode::EveryBodyLoops),
2066+
("expanded", _) => Source(PpSourceMode::Expanded),
2067+
("expanded,identified", _) => Source(PpSourceMode::ExpandedIdentified),
2068+
("expanded,hygiene", _) => Source(PpSourceMode::ExpandedHygiene),
2069+
("hir", true) => Hir(PpHirMode::Normal),
2070+
("hir,identified", true) => Hir(PpHirMode::Identified),
2071+
("hir,typed", true) => Hir(PpHirMode::Typed),
2072+
("hir-tree", true) => HirTree,
2073+
("mir", true) => Mir,
2074+
("mir-cfg", true) => MirCFG,
20942075
_ => {
20952076
if extended {
20962077
early_error(
@@ -2119,6 +2100,18 @@ fn parse_pretty(
21192100
tracing::debug!("got unpretty option: {:?}", first);
21202101
first
21212102
}
2103+
2104+
if debugging_opts.unstable_options {
2105+
if let Some(a) = matches.opt_default("pretty", "normal") {
2106+
// stable pretty-print variants only
2107+
return Some(parse_pretty_inner(efmt, &a, false));
2108+
}
2109+
}
2110+
2111+
debugging_opts.unpretty.as_ref().map(|a| {
2112+
// extended with unstable pretty-print variants
2113+
parse_pretty_inner(efmt, &a, true)
2114+
})
21222115
}
21232116

21242117
pub fn make_crate_type_option() -> RustcOptGroup {
@@ -2226,45 +2219,63 @@ impl fmt::Display for CrateType {
22262219

22272220
#[derive(Copy, Clone, PartialEq, Debug)]
22282221
pub enum PpSourceMode {
2229-
PpmNormal,
2230-
PpmEveryBodyLoops,
2231-
PpmExpanded,
2232-
PpmIdentified,
2233-
PpmExpandedIdentified,
2234-
PpmExpandedHygiene,
2235-
PpmTyped,
2222+
/// `--pretty=normal`
2223+
Normal,
2224+
/// `-Zunpretty=everybody_loops`
2225+
EveryBodyLoops,
2226+
/// `--pretty=expanded`
2227+
Expanded,
2228+
/// `--pretty=identified`
2229+
Identified,
2230+
/// `--pretty=expanded,identified`
2231+
ExpandedIdentified,
2232+
/// `--pretty=expanded,hygiene`
2233+
ExpandedHygiene,
2234+
}
2235+
2236+
#[derive(Copy, Clone, PartialEq, Debug)]
2237+
pub enum PpHirMode {
2238+
/// `-Zunpretty=hir`
2239+
Normal,
2240+
/// `-Zunpretty=hir,identified`
2241+
Identified,
2242+
/// `-Zunpretty=hir,typed`
2243+
Typed,
22362244
}
22372245

22382246
#[derive(Copy, Clone, PartialEq, Debug)]
22392247
pub enum PpMode {
2240-
PpmSource(PpSourceMode),
2241-
PpmHir(PpSourceMode),
2242-
PpmHirTree(PpSourceMode),
2243-
PpmMir,
2244-
PpmMirCFG,
2248+
/// Options that print the source code, i.e.
2249+
/// `--pretty` and `-Zunpretty=everybody_loops`
2250+
Source(PpSourceMode),
2251+
/// Options that print the HIR, i.e. `-Zunpretty=hir`
2252+
Hir(PpHirMode),
2253+
/// `-Zunpretty=hir-tree`
2254+
HirTree,
2255+
/// `-Zunpretty=mir`
2256+
Mir,
2257+
/// `-Zunpretty=mir-cfg`
2258+
MirCFG,
22452259
}
22462260

22472261
impl PpMode {
22482262
pub fn needs_ast_map(&self) -> bool {
22492263
use PpMode::*;
22502264
use PpSourceMode::*;
22512265
match *self {
2252-
PpmSource(PpmNormal | PpmIdentified) => false,
2266+
Source(Normal | Identified) => false,
22532267

2254-
PpmSource(
2255-
PpmExpanded | PpmEveryBodyLoops | PpmExpandedIdentified | PpmExpandedHygiene,
2256-
)
2257-
| PpmHir(_)
2258-
| PpmHirTree(_)
2259-
| PpmMir
2260-
| PpmMirCFG => true,
2261-
PpmSource(PpmTyped) => panic!("invalid state"),
2268+
Source(Expanded | EveryBodyLoops | ExpandedIdentified | ExpandedHygiene)
2269+
| Hir(_)
2270+
| HirTree
2271+
| Mir
2272+
| MirCFG => true,
22622273
}
22632274
}
22642275

22652276
pub fn needs_analysis(&self) -> bool {
22662277
use PpMode::*;
2267-
matches!(*self, PpmMir | PpmMirCFG)
2278+
matches!(*self, Mir | MirCFG)
22682279
}
22692280
}
22702281

compiler/rustc_typeck/src/check/method/probe.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,21 @@ pub struct Pick<'tcx> {
160160
pub kind: PickKind<'tcx>,
161161
pub import_ids: SmallVec<[LocalDefId; 1]>,
162162

163-
// Indicates that the source expression should be autoderef'd N times
164-
//
165-
// A = expr | *expr | **expr | ...
163+
/// Indicates that the source expression should be autoderef'd N times
164+
///
165+
/// A = expr | *expr | **expr | ...
166166
pub autoderefs: usize,
167167

168-
// Indicates that an autoref is applied after the optional autoderefs
169-
//
170-
// B = A | &A | &mut A
168+
/// Indicates that an autoref is applied after the optional autoderefs
169+
///
170+
/// B = A | &A | &mut A
171171
pub autoref: Option<hir::Mutability>,
172172

173-
// Indicates that the source expression should be "unsized" to a
174-
// target type. This should probably eventually go away in favor
175-
// of just coercing method receivers.
176-
//
177-
// C = B | unsize(B)
173+
/// Indicates that the source expression should be "unsized" to a
174+
/// target type. This should probably eventually go away in favor
175+
/// of just coercing method receivers.
176+
///
177+
/// C = B | unsize(B)
178178
pub unsize: Option<Ty<'tcx>>,
179179
}
180180

@@ -1091,19 +1091,17 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10911091
.next()
10921092
}
10931093

1094+
/// For each type `T` in the step list, this attempts to find a method where
1095+
/// the (transformed) self type is exactly `T`. We do however do one
1096+
/// transformation on the adjustment: if we are passing a region pointer in,
1097+
/// we will potentially *reborrow* it to a shorter lifetime. This allows us
1098+
/// to transparently pass `&mut` pointers, in particular, without consuming
1099+
/// them for their entire lifetime.
10941100
fn pick_by_value_method(
10951101
&mut self,
10961102
step: &CandidateStep<'tcx>,
10971103
self_ty: Ty<'tcx>,
10981104
) -> Option<PickResult<'tcx>> {
1099-
//! For each type `T` in the step list, this attempts to find a
1100-
//! method where the (transformed) self type is exactly `T`. We
1101-
//! do however do one transformation on the adjustment: if we
1102-
//! are passing a region pointer in, we will potentially
1103-
//! *reborrow* it to a shorter lifetime. This allows us to
1104-
//! transparently pass `&mut` pointers, in particular, without
1105-
//! consuming them for their entire lifetime.
1106-
11071105
if step.unsize {
11081106
return None;
11091107
}

0 commit comments

Comments
 (0)