Skip to content

Commit 5460c2c

Browse files
committed
Mark Printer methods as unreachable where appropriate.
This helps me understand the structure of the code a lot. If any of these are actually reachable, we can put the old code back, add a new test case, and we will have improved our test coverage.
1 parent adcb3d3 commit 5460c2c

File tree

4 files changed

+22
-26
lines changed

4 files changed

+22
-26
lines changed

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
1818
}
1919

2020
fn print_region(&mut self, _region: ty::Region<'_>) -> Result<(), PrintError> {
21-
Ok(())
21+
unreachable!(); // because `<Self As PrettyPrinter>::should_print_region` returns false
2222
}
2323

2424
fn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError> {

compiler/rustc_lint/src/context.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -756,22 +756,22 @@ impl<'tcx> LateContext<'tcx> {
756756
}
757757

758758
fn print_region(&mut self, _region: ty::Region<'_>) -> Result<(), PrintError> {
759-
Ok(())
759+
unreachable!();
760760
}
761761

762762
fn print_type(&mut self, _ty: Ty<'tcx>) -> Result<(), PrintError> {
763-
Ok(())
763+
unreachable!();
764764
}
765765

766766
fn print_dyn_existential(
767767
&mut self,
768768
_predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
769769
) -> Result<(), PrintError> {
770-
Ok(())
770+
unreachable!();
771771
}
772772

773773
fn print_const(&mut self, _ct: ty::Const<'tcx>) -> Result<(), PrintError> {
774-
Ok(())
774+
unreachable!();
775775
}
776776

777777
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
@@ -784,20 +784,13 @@ impl<'tcx> LateContext<'tcx> {
784784
self_ty: Ty<'tcx>,
785785
trait_ref: Option<ty::TraitRef<'tcx>>,
786786
) -> Result<(), PrintError> {
787-
if trait_ref.is_none() {
788-
if let ty::Adt(def, args) = self_ty.kind() {
789-
return self.print_def_path(def.did(), args);
790-
}
787+
if trait_ref.is_none()
788+
&& let ty::Adt(def, args) = self_ty.kind()
789+
{
790+
return self.print_def_path(def.did(), args);
791791
}
792792

793-
// This shouldn't ever be needed, but just in case:
794-
with_no_trimmed_paths!({
795-
self.path = vec![match trait_ref {
796-
Some(trait_ref) => Symbol::intern(&format!("{trait_ref:?}")),
797-
None => Symbol::intern(&format!("<{self_ty}>")),
798-
}];
799-
Ok(())
800-
})
793+
unreachable!();
801794
}
802795

803796
fn path_append_impl(

compiler/rustc_symbol_mangling/src/legacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
236236
}
237237

238238
fn print_region(&mut self, _region: ty::Region<'_>) -> Result<(), PrintError> {
239-
Ok(())
239+
unreachable!(); // because `<Self As PrettyPrinter>::should_print_region` returns false
240240
}
241241

242242
fn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError> {

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,34 +235,35 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
235235
}
236236

237237
fn print_region(&mut self, _region: ty::Region<'_>) -> Result<(), PrintError> {
238-
Err(fmt::Error)
238+
unreachable!();
239239
}
240240

241241
fn print_type(&mut self, _ty: Ty<'tcx>) -> Result<(), PrintError> {
242-
Err(fmt::Error)
242+
unreachable!();
243243
}
244244

245245
fn print_dyn_existential(
246246
&mut self,
247247
_predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
248248
) -> Result<(), PrintError> {
249-
Err(fmt::Error)
249+
unreachable!();
250250
}
251251

252252
fn print_const(&mut self, _ct: ty::Const<'tcx>) -> Result<(), PrintError> {
253-
Err(fmt::Error)
253+
unreachable!();
254254
}
255255

256256
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
257257
self.segments = vec![self.tcx.crate_name(cnum)];
258258
Ok(())
259259
}
260+
260261
fn path_qualified(
261262
&mut self,
262263
_self_ty: Ty<'tcx>,
263264
_trait_ref: Option<ty::TraitRef<'tcx>>,
264265
) -> Result<(), PrintError> {
265-
Err(fmt::Error)
266+
unreachable!();
266267
}
267268

268269
fn path_append_impl(
@@ -272,8 +273,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
272273
_self_ty: Ty<'tcx>,
273274
_trait_ref: Option<ty::TraitRef<'tcx>>,
274275
) -> Result<(), PrintError> {
275-
Err(fmt::Error)
276+
unreachable!();
276277
}
278+
277279
fn path_append(
278280
&mut self,
279281
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
@@ -283,12 +285,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
283285
self.segments.push(disambiguated_data.as_sym(true));
284286
Ok(())
285287
}
288+
286289
fn path_generic_args(
287290
&mut self,
288-
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
291+
_print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
289292
_args: &[GenericArg<'tcx>],
290293
) -> Result<(), PrintError> {
291-
print_prefix(self)
294+
unreachable!();
292295
}
293296
}
294297

0 commit comments

Comments
 (0)