Skip to content

Commit df52416

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 da19b9d commit df52416

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
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: 8 additions & 8 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!(); // because `path_generic_args` ignores the `GenericArgs`
760760
}
761761

762762
fn print_type(&mut self, _ty: Ty<'tcx>) -> Result<(), PrintError> {
763-
Ok(())
763+
unreachable!(); // because `path_generic_args` ignores the `GenericArgs`
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!(); // because `path_generic_args` ignores the `GenericArgs`
771771
}
772772

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

777777
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
@@ -784,10 +784,10 @@ 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

793793
// This shouldn't ever be needed, but just in case:

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: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,28 +235,29 @@ 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!(); // because `path_generic_args` ignores the `GenericArgs`
239239
}
240240

241241
fn print_type(&mut self, _ty: Ty<'tcx>) -> Result<(), PrintError> {
242-
Err(fmt::Error)
242+
unreachable!(); // because `path_generic_args` ignores the `GenericArgs`
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!(); // because `path_generic_args` ignores the `GenericArgs`
250250
}
251251

252252
fn print_const(&mut self, _ct: ty::Const<'tcx>) -> Result<(), PrintError> {
253-
Err(fmt::Error)
253+
unreachable!(); // because `path_generic_args` ignores the `GenericArgs`
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>,
@@ -274,6 +275,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
274275
) -> Result<(), PrintError> {
275276
Err(fmt::Error)
276277
}
278+
277279
fn path_append(
278280
&mut self,
279281
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
@@ -283,6 +285,7 @@ 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,
288291
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,

0 commit comments

Comments
 (0)