Skip to content

Commit f0e0434

Browse files
committed
resolve: Merge last_import_segment into Finalize
1 parent ffedcec commit f0e0434

File tree

5 files changed

+16
-44
lines changed

5 files changed

+16
-44
lines changed

compiler/rustc_resolve/src/diagnostics.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,6 @@ impl<'a> Resolver<'a> {
15001500
&parent_scope,
15011501
None,
15021502
false,
1503-
false,
15041503
None,
15051504
) {
15061505
let desc = match binding.res() {
@@ -1860,7 +1859,6 @@ impl<'a> Resolver<'a> {
18601859
ns_to_try,
18611860
parent_scope,
18621861
None,
1863-
false,
18641862
unusable_binding,
18651863
).ok()
18661864
} else if let Some(ribs) = ribs
@@ -1886,7 +1884,6 @@ impl<'a> Resolver<'a> {
18861884
parent_scope,
18871885
None,
18881886
false,
1889-
false,
18901887
unusable_binding,
18911888
).ok()
18921889
};

compiler/rustc_resolve/src/ident.rs

+5-25
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ impl<'a> Resolver<'a> {
343343
ns,
344344
parent_scope,
345345
finalize,
346-
false,
347346
unusable_binding,
348347
);
349348
if let Ok(binding) = item {
@@ -357,7 +356,6 @@ impl<'a> Resolver<'a> {
357356
parent_scope,
358357
finalize,
359358
finalize.is_some(),
360-
false,
361359
unusable_binding,
362360
)
363361
.ok()
@@ -377,7 +375,6 @@ impl<'a> Resolver<'a> {
377375
parent_scope: &ParentScope<'a>,
378376
finalize: Option<Finalize>,
379377
force: bool,
380-
last_import_segment: bool,
381378
unusable_binding: Option<&'a NameBinding<'a>>,
382379
) -> Result<&'a NameBinding<'a>, Determinacy> {
383380
bitflags::bitflags! {
@@ -498,7 +495,6 @@ impl<'a> Resolver<'a> {
498495
ns,
499496
parent_scope,
500497
finalize,
501-
last_import_segment,
502498
unusable_binding,
503499
);
504500
match binding {
@@ -521,7 +517,6 @@ impl<'a> Resolver<'a> {
521517
adjusted_parent_scope,
522518
!matches!(scope_set, ScopeSet::Late(..)),
523519
finalize,
524-
last_import_segment,
525520
unusable_binding,
526521
);
527522
match binding {
@@ -607,7 +602,6 @@ impl<'a> Resolver<'a> {
607602
ns,
608603
parent_scope,
609604
None,
610-
last_import_segment,
611605
unusable_binding,
612606
) {
613607
if use_prelude || this.is_builtin_macro(binding.res()) {
@@ -730,7 +724,7 @@ impl<'a> Resolver<'a> {
730724
ns: Namespace,
731725
parent_scope: &ParentScope<'a>,
732726
) -> Result<&'a NameBinding<'a>, Determinacy> {
733-
self.resolve_ident_in_module_ext(module, ident, ns, parent_scope, None, false, None)
727+
self.resolve_ident_in_module_ext(module, ident, ns, parent_scope, None, None)
734728
.map_err(|(determinacy, _)| determinacy)
735729
}
736730

@@ -742,8 +736,6 @@ impl<'a> Resolver<'a> {
742736
ns: Namespace,
743737
parent_scope: &ParentScope<'a>,
744738
finalize: Option<Finalize>,
745-
// We are resolving a last import segment during import validation.
746-
last_import_segment: bool,
747739
// This binding should be ignored during in-module resolution, so that we don't get
748740
// "self-confirming" import resolutions during import validation.
749741
unusable_binding: Option<&'a NameBinding<'a>>,
@@ -754,7 +746,6 @@ impl<'a> Resolver<'a> {
754746
ns,
755747
parent_scope,
756748
finalize,
757-
last_import_segment,
758749
unusable_binding,
759750
)
760751
.map_err(|(determinacy, _)| determinacy)
@@ -768,7 +759,6 @@ impl<'a> Resolver<'a> {
768759
ns: Namespace,
769760
parent_scope: &ParentScope<'a>,
770761
finalize: Option<Finalize>,
771-
last_import_segment: bool,
772762
unusable_binding: Option<&'a NameBinding<'a>>,
773763
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
774764
let tmp_parent_scope;
@@ -795,7 +785,6 @@ impl<'a> Resolver<'a> {
795785
adjusted_parent_scope,
796786
false,
797787
finalize,
798-
last_import_segment,
799788
unusable_binding,
800789
)
801790
}
@@ -808,7 +797,6 @@ impl<'a> Resolver<'a> {
808797
ns: Namespace,
809798
parent_scope: &ParentScope<'a>,
810799
finalize: Option<Finalize>,
811-
last_import_segment: bool,
812800
unusable_binding: Option<&'a NameBinding<'a>>,
813801
) -> Result<&'a NameBinding<'a>, Determinacy> {
814802
self.resolve_ident_in_module_unadjusted_ext(
@@ -818,7 +806,6 @@ impl<'a> Resolver<'a> {
818806
parent_scope,
819807
false,
820808
finalize,
821-
last_import_segment,
822809
unusable_binding,
823810
)
824811
.map_err(|(determinacy, _)| determinacy)
@@ -835,7 +822,6 @@ impl<'a> Resolver<'a> {
835822
parent_scope: &ParentScope<'a>,
836823
restricted_shadowing: bool,
837824
finalize: Option<Finalize>,
838-
last_import_segment: bool,
839825
unusable_binding: Option<&'a NameBinding<'a>>,
840826
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
841827
let module = match module {
@@ -848,7 +834,6 @@ impl<'a> Resolver<'a> {
848834
parent_scope,
849835
finalize,
850836
finalize.is_some(),
851-
last_import_segment,
852837
unusable_binding,
853838
);
854839
return binding.map_err(|determinacy| (determinacy, Weak::No));
@@ -889,7 +874,6 @@ impl<'a> Resolver<'a> {
889874
parent_scope,
890875
finalize,
891876
finalize.is_some(),
892-
last_import_segment,
893877
unusable_binding,
894878
);
895879
return binding.map_err(|determinacy| (determinacy, Weak::No));
@@ -900,7 +884,7 @@ impl<'a> Resolver<'a> {
900884
let resolution =
901885
self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports.
902886

903-
if let Some(Finalize { path_span, .. }) = finalize {
887+
if let Some(Finalize { path_span, report_private, .. }) = finalize {
904888
// If the primary binding is unusable, search further and return the shadowed glob
905889
// binding if it exists. What we really want here is having two separate scopes in
906890
// a module - one for non-globs and one for globs, but until that's done use this
@@ -921,14 +905,14 @@ impl<'a> Resolver<'a> {
921905
};
922906

923907
if !self.is_accessible_from(binding.vis, parent_scope.module) {
924-
if last_import_segment {
925-
return Err((Determined, Weak::No));
926-
} else {
908+
if report_private {
927909
self.privacy_errors.push(PrivacyError {
928910
ident,
929911
binding,
930912
dedup_span: path_span,
931913
});
914+
} else {
915+
return Err((Determined, Weak::No));
932916
}
933917
}
934918

@@ -995,7 +979,6 @@ impl<'a> Resolver<'a> {
995979
ns,
996980
&single_import.parent_scope,
997981
None,
998-
last_import_segment,
999982
unusable_binding,
1000983
) {
1001984
Err(Determined) => continue,
@@ -1072,7 +1055,6 @@ impl<'a> Resolver<'a> {
10721055
ns,
10731056
adjusted_parent_scope,
10741057
None,
1075-
last_import_segment,
10761058
unusable_binding,
10771059
);
10781060

@@ -1495,7 +1477,6 @@ impl<'a> Resolver<'a> {
14951477
ns,
14961478
parent_scope,
14971479
finalize,
1498-
false,
14991480
unusable_binding,
15001481
)
15011482
} else if let Some(ribs) = ribs
@@ -1523,7 +1504,6 @@ impl<'a> Resolver<'a> {
15231504
parent_scope,
15241505
finalize,
15251506
finalize.is_some(),
1526-
false,
15271507
unusable_binding,
15281508
)
15291509
};

compiler/rustc_resolve/src/imports.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
545545
ns,
546546
&import.parent_scope,
547547
None,
548-
false,
549548
None,
550549
);
551550
import.vis.set(orig_vis);
@@ -594,13 +593,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
594593
_ => None,
595594
};
596595
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
597-
let finalize =
598-
Some(Finalize::with_root_span(import.root_id, import.span, import.root_span));
596+
let finalize = Finalize::with_root_span(import.root_id, import.span, import.root_span);
599597
let path_res = self.r.resolve_path(
600598
&import.module_path,
601599
None,
602600
&import.parent_scope,
603-
finalize,
601+
Some(finalize),
604602
unusable_binding,
605603
);
606604
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
@@ -682,7 +680,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
682680
// 2 segments, so the `resolve_path` above won't trigger it.
683681
let mut full_path = import.module_path.clone();
684682
full_path.push(Segment::from_ident(Ident::empty()));
685-
self.r.lint_if_path_starts_with_module(finalize, &full_path, None);
683+
self.r.lint_if_path_starts_with_module(Some(finalize), &full_path, None);
686684
}
687685

688686
if let ModuleOrUniformRoot::Module(module) = module {
@@ -717,8 +715,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
717715
ident,
718716
ns,
719717
&import.parent_scope,
720-
finalize,
721-
true,
718+
Some(Finalize { report_private: false, ..finalize }),
722719
target_bindings[ns].get(),
723720
);
724721
import.vis.set(orig_vis);
@@ -778,8 +775,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
778775
ident,
779776
ns,
780777
&import.parent_scope,
781-
finalize,
782-
false,
778+
Some(finalize),
783779
None,
784780
);
785781
if binding.is_ok() {
@@ -945,7 +941,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
945941
full_path.push(Segment::from_ident(ident));
946942
self.r.per_ns(|this, ns| {
947943
if let Ok(binding) = source_bindings[ns].get() {
948-
this.lint_if_path_starts_with_module(finalize, &full_path, Some(binding));
944+
this.lint_if_path_starts_with_module(Some(finalize), &full_path, Some(binding));
949945
}
950946
});
951947
}
@@ -1000,7 +996,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
1000996
&import.parent_scope,
1001997
None,
1002998
false,
1003-
false,
1004999
target_bindings[ns].get(),
10051000
) {
10061001
Ok(other_binding) => {

compiler/rustc_resolve/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2053,15 +2053,18 @@ struct Finalize {
20532053
/// Span of the path start, suitable for prepending something to to it.
20542054
/// E.g. span of `foo` in `foo::{a, b, c}`, or full span for regular paths.
20552055
root_span: Span,
2056+
/// Whether to report privacy errors or silently return "no resolution" for them,
2057+
/// similarly to speculative resolution.
2058+
report_private: bool,
20562059
}
20572060

20582061
impl Finalize {
20592062
fn new(node_id: NodeId, path_span: Span) -> Finalize {
2060-
Finalize { node_id, path_span, root_span: path_span }
2063+
Finalize::with_root_span(node_id, path_span, path_span)
20612064
}
20622065

20632066
fn with_root_span(node_id: NodeId, path_span: Span, root_span: Span) -> Finalize {
2064-
Finalize { node_id, path_span, root_span }
2067+
Finalize { node_id, path_span, root_span, report_private: true }
20652068
}
20662069
}
20672070

compiler/rustc_resolve/src/macros.rs

-3
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,6 @@ impl<'a> Resolver<'a> {
604604
parent_scope,
605605
None,
606606
force,
607-
false,
608607
None,
609608
);
610609
if let Err(Determinacy::Undetermined) = binding {
@@ -710,7 +709,6 @@ impl<'a> Resolver<'a> {
710709
&parent_scope,
711710
Some(Finalize::new(ast::CRATE_NODE_ID, ident.span)),
712711
true,
713-
false,
714712
None,
715713
) {
716714
Ok(binding) => {
@@ -753,7 +751,6 @@ impl<'a> Resolver<'a> {
753751
&parent_scope,
754752
Some(Finalize::new(ast::CRATE_NODE_ID, ident.span)),
755753
true,
756-
false,
757754
None,
758755
);
759756
}

0 commit comments

Comments
 (0)