Skip to content

Commit 2c74903

Browse files
committed
Auto merge of rust-lang#83225 - JohnTitor:rollup-4hnuhb8, r=JohnTitor
Rollup of 8 pull requests Successful merges: - rust-lang#82774 (Fix bad diagnostics for anon params with ref and/or qualified paths) - rust-lang#82826 ((std::net::parser): Fix capitalization of IP version names) - rust-lang#83092 (More precise spans for HIR paths) - rust-lang#83124 (Do not insert impl_trait_in_bindings opaque definitions twice.) - rust-lang#83202 (Show details in cfg version unstable book) - rust-lang#83203 (Don't warn about old rustdoc lint names (temporarily)) - rust-lang#83206 (Update books) - rust-lang#83219 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0c34122 + 95bbcdb commit 2c74903

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+353
-227
lines changed

compiler/rustc_ast/src/ast.rs

+8
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,17 @@ impl PathSegment {
149149
pub fn from_ident(ident: Ident) -> Self {
150150
PathSegment { ident, id: DUMMY_NODE_ID, args: None }
151151
}
152+
152153
pub fn path_root(span: Span) -> Self {
153154
PathSegment::from_ident(Ident::new(kw::PathRoot, span))
154155
}
156+
157+
pub fn span(&self) -> Span {
158+
match &self.args {
159+
Some(args) => self.ident.span.to(args.span()),
160+
None => self.ident.span,
161+
}
162+
}
155163
}
156164

157165
/// The arguments of a path segment.

compiler/rustc_ast_lowering/src/lib.rs

+15-63
Original file line numberDiff line numberDiff line change
@@ -438,31 +438,6 @@ impl<'a> TokenStreamLowering<'a> {
438438
}
439439
}
440440

441-
struct ImplTraitTypeIdVisitor<'a> {
442-
ids: &'a mut SmallVec<[NodeId; 1]>,
443-
}
444-
445-
impl Visitor<'_> for ImplTraitTypeIdVisitor<'_> {
446-
fn visit_ty(&mut self, ty: &Ty) {
447-
match ty.kind {
448-
TyKind::Typeof(_) | TyKind::BareFn(_) => return,
449-
450-
TyKind::ImplTrait(id, _) => self.ids.push(id),
451-
_ => {}
452-
}
453-
visit::walk_ty(self, ty);
454-
}
455-
456-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &PathSegment) {
457-
if let Some(ref p) = path_segment.args {
458-
if let GenericArgs::Parenthesized(_) = **p {
459-
return;
460-
}
461-
}
462-
visit::walk_path_segment(self, path_span, path_segment)
463-
}
464-
}
465-
466441
impl<'a, 'hir> LoweringContext<'a, 'hir> {
467442
fn lower_crate(mut self, c: &Crate) -> hir::Crate<'hir> {
468443
/// Full-crate AST visitor that inserts into a fresh
@@ -1789,14 +1764,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17891764
)
17901765
}
17911766

1792-
fn lower_local(&mut self, l: &Local) -> (hir::Local<'hir>, SmallVec<[NodeId; 1]>) {
1793-
let mut ids = SmallVec::<[NodeId; 1]>::new();
1794-
if self.sess.features_untracked().impl_trait_in_bindings {
1795-
if let Some(ref ty) = l.ty {
1796-
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids };
1797-
visitor.visit_ty(ty);
1798-
}
1799-
}
1767+
fn lower_local(&mut self, l: &Local) -> hir::Local<'hir> {
18001768
let ty = l.ty.as_ref().map(|t| {
18011769
let mut capturable_lifetimes;
18021770
self.lower_ty(
@@ -1815,17 +1783,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18151783
let init = l.init.as_ref().map(|e| self.lower_expr(e));
18161784
let hir_id = self.lower_node_id(l.id);
18171785
self.lower_attrs(hir_id, &l.attrs);
1818-
(
1819-
hir::Local {
1820-
hir_id,
1821-
ty,
1822-
pat: self.lower_pat(&l.pat),
1823-
init,
1824-
span: l.span,
1825-
source: hir::LocalSource::Normal,
1826-
},
1827-
ids,
1828-
)
1786+
hir::Local {
1787+
hir_id,
1788+
ty,
1789+
pat: self.lower_pat(&l.pat),
1790+
init,
1791+
span: l.span,
1792+
source: hir::LocalSource::Normal,
1793+
}
18291794
}
18301795

18311796
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
@@ -2445,27 +2410,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24452410
fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt<'hir>; 1]> {
24462411
let (hir_id, kind) = match s.kind {
24472412
StmtKind::Local(ref l) => {
2448-
let (l, item_ids) = self.lower_local(l);
2449-
let mut ids: SmallVec<[hir::Stmt<'hir>; 1]> = item_ids
2450-
.into_iter()
2451-
.map(|item_id| {
2452-
let item_id = hir::ItemId {
2453-
// All the items that `lower_local` finds are `impl Trait` types.
2454-
def_id: self.lower_node_id(item_id).expect_owner(),
2455-
};
2456-
self.stmt(s.span, hir::StmtKind::Item(item_id))
2457-
})
2458-
.collect();
2413+
let l = self.lower_local(l);
24592414
let hir_id = self.lower_node_id(s.id);
24602415
self.alias_attrs(hir_id, l.hir_id);
2461-
ids.push({
2462-
hir::Stmt {
2463-
hir_id,
2464-
kind: hir::StmtKind::Local(self.arena.alloc(l)),
2465-
span: s.span,
2466-
}
2467-
});
2468-
return ids;
2416+
return smallvec![hir::Stmt {
2417+
hir_id,
2418+
kind: hir::StmtKind::Local(self.arena.alloc(l)),
2419+
span: s.span,
2420+
}];
24692421
}
24702422
StmtKind::Item(ref it) => {
24712423
// Can only use the ID once.

compiler/rustc_ast_lowering/src/path.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3030
let partial_res =
3131
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));
3232

33+
let path_span_lo = p.span.shrink_to_lo();
3334
let proj_start = p.segments.len() - partial_res.unresolved_segments();
3435
let path = self.arena.alloc(hir::Path {
3536
res: self.lower_res(partial_res.base_res()),
@@ -108,7 +109,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
108109
)
109110
},
110111
)),
111-
span: p.span,
112+
span: p.segments[..proj_start]
113+
.last()
114+
.map_or(path_span_lo, |segment| path_span_lo.to(segment.span())),
112115
});
113116

114117
// Simple case, either no projections, or only fully-qualified.
@@ -127,7 +130,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
127130
// e.g., `Vec` in `Vec::new` or `<I as Iterator>::Item` in
128131
// `<I as Iterator>::Item::default`.
129132
let new_id = self.next_id();
130-
self.arena.alloc(self.ty_path(new_id, p.span, hir::QPath::Resolved(qself, path)))
133+
self.arena.alloc(self.ty_path(new_id, path.span, hir::QPath::Resolved(qself, path)))
131134
};
132135

133136
// Anything after the base path are associated "extensions",
@@ -141,7 +144,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
141144
// 3. `<<std::vec::Vec<T>>::IntoIter>::Item`
142145
// * final path is `<<<std::vec::Vec<T>>::IntoIter>::Item>::clone`
143146
for (i, segment) in p.segments.iter().enumerate().skip(proj_start) {
144-
let segment = self.arena.alloc(self.lower_path_segment(
147+
let hir_segment = self.arena.alloc(self.lower_path_segment(
145148
p.span,
146149
segment,
147150
param_mode,
@@ -150,7 +153,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
150153
itctx.reborrow(),
151154
None,
152155
));
153-
let qpath = hir::QPath::TypeRelative(ty, segment);
156+
let qpath = hir::QPath::TypeRelative(ty, hir_segment);
154157

155158
// It's finished, return the extension of the right node type.
156159
if i == p.segments.len() - 1 {
@@ -159,7 +162,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
159162

160163
// Wrap the associated extension in another type node.
161164
let new_id = self.next_id();
162-
ty = self.arena.alloc(self.ty_path(new_id, p.span, qpath));
165+
ty = self.arena.alloc(self.ty_path(new_id, path_span_lo.to(segment.span()), qpath));
163166
}
164167

165168
// We should've returned in the for loop above.

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ impl<'hir> QPath<'hir> {
18091809
pub fn span(&self) -> Span {
18101810
match *self {
18111811
QPath::Resolved(_, path) => path.span,
1812-
QPath::TypeRelative(_, ps) => ps.ident.span,
1812+
QPath::TypeRelative(qself, ps) => qself.span.to(ps.ident.span),
18131813
QPath::LangItem(_, span) => span,
18141814
}
18151815
}

compiler/rustc_infer/src/traits/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn report_object_safety_error(
104104
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
105105
);
106106

107-
if tcx.sess.trait_methods_not_found.borrow().contains(&span) {
107+
if tcx.sess.trait_methods_not_found.borrow().iter().any(|full_span| full_span.contains(span)) {
108108
// Avoid emitting error caused by non-existing method (#58734)
109109
err.cancel();
110110
}

compiler/rustc_lint/src/context.rs

+34
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ enum TargetLint {
100100
/// Lint with this name existed previously, but has been removed/deprecated.
101101
/// The string argument is the reason for removal.
102102
Removed(String),
103+
104+
/// A lint name that should give no warnings and have no effect.
105+
///
106+
/// This is used by rustc to avoid warning about old rustdoc lints before rustdoc registers them as tool lints.
107+
Ignored,
103108
}
104109

105110
pub enum FindLintError {
@@ -266,6 +271,33 @@ impl LintStore {
266271
}
267272
}
268273

274+
/// This lint should be available with either the old or the new name.
275+
///
276+
/// Using the old name will not give a warning.
277+
/// You must register a lint with the new name before calling this function.
278+
#[track_caller]
279+
pub fn register_alias(&mut self, old_name: &str, new_name: &str) {
280+
let target = match self.by_name.get(new_name) {
281+
Some(&Id(lint_id)) => lint_id,
282+
_ => bug!("cannot add alias {} for lint {} that does not exist", old_name, new_name),
283+
};
284+
match self.by_name.insert(old_name.to_string(), Id(target)) {
285+
None | Some(Ignored) => {}
286+
Some(x) => bug!("duplicate specification of lint {} (was {:?})", old_name, x),
287+
}
288+
}
289+
290+
/// This lint should give no warning and have no effect.
291+
///
292+
/// This is used by rustc to avoid warning about old rustdoc lints before rustdoc registers them as tool lints.
293+
#[track_caller]
294+
pub fn register_ignored(&mut self, name: &str) {
295+
if self.by_name.insert(name.to_string(), Ignored).is_some() {
296+
bug!("duplicate specification of lint {}", name);
297+
}
298+
}
299+
300+
/// This lint has been renamed; warn about using the new name and apply the lint.
269301
#[track_caller]
270302
pub fn register_renamed(&mut self, old_name: &str, new_name: &str) {
271303
let target = match self.by_name.get(new_name) {
@@ -284,6 +316,7 @@ impl LintStore {
284316
Some(&Id(lint_id)) => Ok(vec![lint_id]),
285317
Some(&Renamed(_, lint_id)) => Ok(vec![lint_id]),
286318
Some(&Removed(_)) => Err(FindLintError::Removed),
319+
Some(&Ignored) => Ok(vec![]),
287320
None => loop {
288321
return match self.lint_groups.get(lint_name) {
289322
Some(LintGroup { lint_ids, depr, .. }) => {
@@ -427,6 +460,7 @@ impl LintStore {
427460
}
428461
},
429462
Some(&Id(ref id)) => CheckLintNameResult::Ok(slice::from_ref(id)),
463+
Some(&Ignored) => CheckLintNameResult::Ok(&[]),
430464
}
431465
}
432466

compiler/rustc_lint/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
340340
"non_autolinks",
341341
];
342342
for rustdoc_lint in RUSTDOC_LINTS {
343-
store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint));
343+
store.register_ignored(rustdoc_lint);
344344
}
345345
store.register_removed(
346346
"intra_doc_link_resolution_failure",

compiler/rustc_middle/src/hir/map/collector.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fn insert_vec_map<K: Idx, V: Clone>(map: &mut IndexVec<K, Option<V>>, k: K, v: V
5252
if i >= len {
5353
map.extend(repeat(None).take(i - len + 1));
5454
}
55+
debug_assert!(map[k].is_none());
5556
map[k] = Some(v);
5657
}
5758

@@ -216,9 +217,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
216217
// Overwrite the dummy hash with the real HIR owner hash.
217218
nodes.hash = hash;
218219

219-
// FIXME: feature(impl_trait_in_bindings) broken and trigger this assert
220-
//assert!(data.signature.is_none());
221-
220+
debug_assert!(data.signature.is_none());
222221
data.signature =
223222
Some(self.arena.alloc(Owner { parent: entry.parent, node: entry.node }));
224223

0 commit comments

Comments
 (0)