Skip to content

Commit f0f8565

Browse files
committed
remove the resolver warnings
1 parent 96e9496 commit f0f8565

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

src/cargo/core/resolver/context.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ pub struct Context {
4848
// at the very end and actually construct the map that we're making.
4949
pub resolve_graph: RcList<GraphNode>,
5050
pub resolve_replacements: RcList<(PackageId, PackageId)>,
51-
52-
// These warnings are printed after resolution.
53-
pub warnings: RcList<String>,
5451
}
5552

5653
/// When backtracking it can be useful to know how far back to go.
@@ -109,7 +106,6 @@ impl Context {
109106
parents: Graph::new(),
110107
resolve_replacements: RcList::new(),
111108
activations: im_rc::HashMap::new(),
112-
warnings: RcList::new(),
113109
}
114110
}
115111

@@ -174,7 +170,7 @@ impl Context {
174170
// First, figure out our set of dependencies based on the requested set
175171
// of features. This also calculates what features we're going to enable
176172
// for our own dependencies.
177-
let deps = self.resolve_features(parent, candidate, method)?;
173+
let deps = self.resolve_features(parent, candidate, method, None)?;
178174

179175
// Next, transform all dependencies into a list of possible candidates
180176
// which can satisfy that dependency.
@@ -229,11 +225,12 @@ impl Context {
229225
}
230226

231227
/// Returns all dependencies and the features we want from them.
232-
fn resolve_features<'b>(
228+
pub fn resolve_features<'b>(
233229
&mut self,
234230
parent: Option<&Summary>,
235231
s: &'b Summary,
236232
method: &'b Method<'_>,
233+
config: Option<&crate::util::config::Config>,
237234
) -> ActivateResult<Vec<(Dependency, Vec<InternedString>)>> {
238235
let dev_deps = match *method {
239236
Method::Everything => true,
@@ -261,20 +258,23 @@ impl Context {
261258
// name.
262259
let base = reqs.deps.get(&dep.name_in_toml()).unwrap_or(&default_dep);
263260
used_features.insert(dep.name_in_toml());
264-
let always_required = !dep.is_optional()
265-
&& !s
266-
.dependencies()
267-
.iter()
268-
.any(|d| d.is_optional() && d.name_in_toml() == dep.name_in_toml());
269-
if always_required && base.0 {
270-
self.warnings.push(format!(
271-
"Package `{}` does not have feature `{}`. It has a required dependency \
272-
with that name, but only optional dependencies can be used as features. \
273-
This is currently a warning to ease the transition, but it will become an \
274-
error in the future.",
275-
s.package_id(),
276-
dep.name_in_toml()
277-
));
261+
if let Some(config) = config {
262+
let mut shell = config.shell();
263+
let always_required = !dep.is_optional()
264+
&& !s
265+
.dependencies()
266+
.iter()
267+
.any(|d| d.is_optional() && d.name_in_toml() == dep.name_in_toml());
268+
if always_required && base.0 {
269+
shell.warn(&format!(
270+
"Package `{}` does not have feature `{}`. It has a required dependency \
271+
with that name, but only optional dependencies can be used as features. \
272+
This is currently a warning to ease the transition, but it will become an \
273+
error in the future.",
274+
s.package_id(),
275+
dep.name_in_toml()
276+
))?
277+
}
278278
}
279279
let mut base = base.1.clone();
280280
base.extend(dep.features().iter());

src/cargo/core/resolver/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,18 @@ pub fn resolve(
158158
trace!("resolved: {:?}", resolve);
159159

160160
// If we have a shell, emit warnings about required deps used as feature.
161-
if let Some(config) = config {
162-
if print_warnings {
163-
let mut shell = config.shell();
164-
let mut warnings = &cx.warnings;
165-
while let Some(ref head) = warnings.head {
166-
shell.warn(&head.0)?;
167-
warnings = &head.1;
161+
if print_warnings && config.is_some() {
162+
let mut new_cx = cx.clone();
163+
for (j, _) in cx.activations.values() {
164+
if let Some(features) = cx.resolve_features.get(&j.package_id()) {
165+
let features: Vec<_> = features.iter().cloned().collect();
166+
let method = Method::Required {
167+
dev_deps: false,
168+
features: &features,
169+
all_features: false,
170+
uses_default_features: false,
171+
};
172+
let _ = new_cx.resolve_features(None, j, &method, config);
168173
}
169174
}
170175
}

0 commit comments

Comments
 (0)