Skip to content

Commit d216b73

Browse files
committed
Remove duplicated code
1 parent cb6dfea commit d216b73

File tree

2 files changed

+1
-73
lines changed

2 files changed

+1
-73
lines changed

src/librustc/traits/error_reporting/mod.rs

-72
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2727
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
2828
use rustc_hir as hir;
2929
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
30-
use rustc_span::source_map::SourceMap;
3130
use rustc_span::{ExpnKind, Span, DUMMY_SP};
3231
use std::fmt;
3332
use syntax::ast;
@@ -1427,74 +1426,3 @@ impl ArgKind {
14271426
}
14281427
}
14291428
}
1430-
1431-
/// Suggest restricting a type param with a new bound.
1432-
pub fn suggest_constraining_type_param(
1433-
generics: &hir::Generics<'_>,
1434-
err: &mut DiagnosticBuilder<'_>,
1435-
param_name: &str,
1436-
constraint: &str,
1437-
source_map: &SourceMap,
1438-
span: Span,
1439-
) -> bool {
1440-
let restrict_msg = "consider further restricting this bound";
1441-
if let Some(param) =
1442-
generics.params.iter().filter(|p| p.name.ident().as_str() == param_name).next()
1443-
{
1444-
if param_name.starts_with("impl ") {
1445-
// `impl Trait` in argument:
1446-
// `fn foo(x: impl Trait) {}` → `fn foo(t: impl Trait + Trait2) {}`
1447-
err.span_suggestion(
1448-
param.span,
1449-
restrict_msg,
1450-
// `impl CurrentTrait + MissingTrait`
1451-
format!("{} + {}", param_name, constraint),
1452-
Applicability::MachineApplicable,
1453-
);
1454-
} else if generics.where_clause.predicates.is_empty() && param.bounds.is_empty() {
1455-
// If there are no bounds whatsoever, suggest adding a constraint
1456-
// to the type parameter:
1457-
// `fn foo<T>(t: T) {}` → `fn foo<T: Trait>(t: T) {}`
1458-
err.span_suggestion(
1459-
param.span,
1460-
"consider restricting this bound",
1461-
format!("{}: {}", param_name, constraint),
1462-
Applicability::MachineApplicable,
1463-
);
1464-
} else if !generics.where_clause.predicates.is_empty() {
1465-
// There is a `where` clause, so suggest expanding it:
1466-
// `fn foo<T>(t: T) where T: Debug {}` →
1467-
// `fn foo<T>(t: T) where T: Debug, T: Trait {}`
1468-
err.span_suggestion(
1469-
generics.where_clause.span().unwrap().shrink_to_hi(),
1470-
&format!("consider further restricting type parameter `{}`", param_name),
1471-
format!(", {}: {}", param_name, constraint),
1472-
Applicability::MachineApplicable,
1473-
);
1474-
} else {
1475-
// If there is no `where` clause lean towards constraining to the
1476-
// type parameter:
1477-
// `fn foo<X: Bar, T>(t: T, x: X) {}` → `fn foo<T: Trait>(t: T) {}`
1478-
// `fn foo<T: Bar>(t: T) {}` → `fn foo<T: Bar + Trait>(t: T) {}`
1479-
let sp = param.span.with_hi(span.hi());
1480-
let span = source_map.span_through_char(sp, ':');
1481-
if sp != param.span && sp != span {
1482-
// Only suggest if we have high certainty that the span
1483-
// covers the colon in `foo<T: Trait>`.
1484-
err.span_suggestion(
1485-
span,
1486-
restrict_msg,
1487-
format!("{}: {} + ", param_name, constraint),
1488-
Applicability::MachineApplicable,
1489-
);
1490-
} else {
1491-
err.span_label(
1492-
param.span,
1493-
&format!("consider adding a `where {}: {}` bound", param_name, constraint),
1494-
);
1495-
}
1496-
}
1497-
return true;
1498-
}
1499-
false
1500-
}

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc::mir::{
33
FakeReadCause, Local, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
44
ProjectionElem, Rvalue, Statement, StatementKind, TerminatorKind, VarBindingForm,
55
};
6-
use rustc::traits::error_reporting::suggest_constraining_type_param;
6+
use rustc::traits::error_reporting::suggestions::suggest_constraining_type_param;
77
use rustc::ty::{self, Ty};
88
use rustc_data_structures::fx::FxHashSet;
99
use rustc_errors::{Applicability, DiagnosticBuilder};

0 commit comments

Comments
 (0)