Skip to content
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b86c0d8
(std::net::parser): Fix capitalization of IP versions
pierwill Mar 6, 2021
3612953
Do not insert impl_trait_in_bindings opaque definitions twice.
cjgillot Mar 14, 2021
17d3308
Remove dead code.
cjgillot Mar 14, 2021
e8b2e7b
Assert there is no duplicate node.
cjgillot Mar 14, 2021
7e66e9d
More precise spans for HIR paths
petrochenkov Mar 13, 2021
e98b7d1
Update clippy tests
petrochenkov Mar 15, 2021
b5ca329
Show details in cfg version unstable book
pickfire Mar 16, 2021
0701b5e
Update books
ehuss Mar 16, 2021
c1b99f0
Don't warn about old rustdoc lint names (temporarily)
jyn514 Mar 16, 2021
65c0110
Update cargo
ehuss Mar 16, 2021
ea355bc
Fix bad diagnostics for anon params with ref
JohnTitor Mar 4, 2021
8240f1a
Fix bad diagnostics for anon params with qualified paths
JohnTitor Mar 5, 2021
2d99e68
Emit more pretty diagnostics for qualified paths
JohnTitor Mar 17, 2021
55bdf7f
Add more test case
JohnTitor Mar 17, 2021
a16db3d
Rollup merge of #82774 - JohnTitor:bad-diag-for-anon-params-with-ref,…
JohnTitor Mar 17, 2021
3122510
Rollup merge of #82826 - pierwill:fix-IPv, r=JohnTitor
JohnTitor Mar 17, 2021
70edab8
Rollup merge of #83092 - petrochenkov:qspan, r=estebank
JohnTitor Mar 17, 2021
9c7aca5
Rollup merge of #83124 - cjgillot:iiib, r=petrochenkov
JohnTitor Mar 17, 2021
b7863f9
Rollup merge of #83202 - pickfire:patch-6, r=JohnTitor
JohnTitor Mar 17, 2021
42e6d42
Rollup merge of #83203 - jyn514:rustdoc-warnings, r=Manishearth
JohnTitor Mar 17, 2021
ab83b4f
Rollup merge of #83206 - ehuss:update-books, r=ehuss
JohnTitor Mar 17, 2021
95bbcdb
Rollup merge of #83219 - ehuss:update-cargo, r=ehuss
JohnTitor Mar 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
@@ -149,9 +149,17 @@ impl PathSegment {
pub fn from_ident(ident: Ident) -> Self {
PathSegment { ident, id: DUMMY_NODE_ID, args: None }
}

pub fn path_root(span: Span) -> Self {
PathSegment::from_ident(Ident::new(kw::PathRoot, span))
}

pub fn span(&self) -> Span {
match &self.args {
Some(args) => self.ident.span.to(args.span()),
None => self.ident.span,
}
}
}

/// The arguments of a path segment.
78 changes: 15 additions & 63 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
@@ -438,31 +438,6 @@ impl<'a> TokenStreamLowering<'a> {
}
}

struct ImplTraitTypeIdVisitor<'a> {
ids: &'a mut SmallVec<[NodeId; 1]>,
}

impl Visitor<'_> for ImplTraitTypeIdVisitor<'_> {
fn visit_ty(&mut self, ty: &Ty) {
match ty.kind {
TyKind::Typeof(_) | TyKind::BareFn(_) => return,

TyKind::ImplTrait(id, _) => self.ids.push(id),
_ => {}
}
visit::walk_ty(self, ty);
}

fn visit_path_segment(&mut self, path_span: Span, path_segment: &PathSegment) {
if let Some(ref p) = path_segment.args {
if let GenericArgs::Parenthesized(_) = **p {
return;
}
}
visit::walk_path_segment(self, path_span, path_segment)
}
}

impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_crate(mut self, c: &Crate) -> hir::Crate<'hir> {
/// Full-crate AST visitor that inserts into a fresh
@@ -1789,14 +1764,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
)
}

fn lower_local(&mut self, l: &Local) -> (hir::Local<'hir>, SmallVec<[NodeId; 1]>) {
let mut ids = SmallVec::<[NodeId; 1]>::new();
if self.sess.features_untracked().impl_trait_in_bindings {
if let Some(ref ty) = l.ty {
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids };
visitor.visit_ty(ty);
}
}
fn lower_local(&mut self, l: &Local) -> hir::Local<'hir> {
let ty = l.ty.as_ref().map(|t| {
let mut capturable_lifetimes;
self.lower_ty(
@@ -1815,17 +1783,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let init = l.init.as_ref().map(|e| self.lower_expr(e));
let hir_id = self.lower_node_id(l.id);
self.lower_attrs(hir_id, &l.attrs);
(
hir::Local {
hir_id,
ty,
pat: self.lower_pat(&l.pat),
init,
span: l.span,
source: hir::LocalSource::Normal,
},
ids,
)
hir::Local {
hir_id,
ty,
pat: self.lower_pat(&l.pat),
init,
span: l.span,
source: hir::LocalSource::Normal,
}
}

fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
@@ -2445,27 +2410,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt<'hir>; 1]> {
let (hir_id, kind) = match s.kind {
StmtKind::Local(ref l) => {
let (l, item_ids) = self.lower_local(l);
let mut ids: SmallVec<[hir::Stmt<'hir>; 1]> = item_ids
.into_iter()
.map(|item_id| {
let item_id = hir::ItemId {
// All the items that `lower_local` finds are `impl Trait` types.
def_id: self.lower_node_id(item_id).expect_owner(),
};
self.stmt(s.span, hir::StmtKind::Item(item_id))
})
.collect();
let l = self.lower_local(l);
let hir_id = self.lower_node_id(s.id);
self.alias_attrs(hir_id, l.hir_id);
ids.push({
hir::Stmt {
hir_id,
kind: hir::StmtKind::Local(self.arena.alloc(l)),
span: s.span,
}
});
return ids;
return smallvec![hir::Stmt {
hir_id,
kind: hir::StmtKind::Local(self.arena.alloc(l)),
span: s.span,
}];
}
StmtKind::Item(ref it) => {
// Can only use the ID once.
13 changes: 8 additions & 5 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let partial_res =
self.resolver.get_partial_res(id).unwrap_or_else(|| PartialRes::new(Res::Err));

let path_span_lo = p.span.shrink_to_lo();
let proj_start = p.segments.len() - partial_res.unresolved_segments();
let path = self.arena.alloc(hir::Path {
res: self.lower_res(partial_res.base_res()),
@@ -108,7 +109,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
)
},
)),
span: p.span,
span: p.segments[..proj_start]
.last()
.map_or(path_span_lo, |segment| path_span_lo.to(segment.span())),
});

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

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

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

// Wrap the associated extension in another type node.
let new_id = self.next_id();
ty = self.arena.alloc(self.ty_path(new_id, p.span, qpath));
ty = self.arena.alloc(self.ty_path(new_id, path_span_lo.to(segment.span()), qpath));
}

// We should've returned in the for loop above.
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
@@ -1809,7 +1809,7 @@ impl<'hir> QPath<'hir> {
pub fn span(&self) -> Span {
match *self {
QPath::Resolved(_, path) => path.span,
QPath::TypeRelative(_, ps) => ps.ident.span,
QPath::TypeRelative(qself, ps) => qself.span.to(ps.ident.span),
QPath::LangItem(_, span) => span,
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ pub fn report_object_safety_error(
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
);

if tcx.sess.trait_methods_not_found.borrow().contains(&span) {
if tcx.sess.trait_methods_not_found.borrow().iter().any(|full_span| full_span.contains(span)) {
// Avoid emitting error caused by non-existing method (#58734)
err.cancel();
}
34 changes: 34 additions & 0 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
@@ -100,6 +100,11 @@ enum TargetLint {
/// Lint with this name existed previously, but has been removed/deprecated.
/// The string argument is the reason for removal.
Removed(String),

/// A lint name that should give no warnings and have no effect.
///
/// This is used by rustc to avoid warning about old rustdoc lints before rustdoc registers them as tool lints.
Ignored,
}

pub enum FindLintError {
@@ -266,6 +271,33 @@ impl LintStore {
}
}

/// This lint should be available with either the old or the new name.
///
/// Using the old name will not give a warning.
/// You must register a lint with the new name before calling this function.
#[track_caller]
pub fn register_alias(&mut self, old_name: &str, new_name: &str) {
let target = match self.by_name.get(new_name) {
Some(&Id(lint_id)) => lint_id,
_ => bug!("cannot add alias {} for lint {} that does not exist", old_name, new_name),
};
match self.by_name.insert(old_name.to_string(), Id(target)) {
None | Some(Ignored) => {}
Some(x) => bug!("duplicate specification of lint {} (was {:?})", old_name, x),
}
}

/// This lint should give no warning and have no effect.
///
/// This is used by rustc to avoid warning about old rustdoc lints before rustdoc registers them as tool lints.
#[track_caller]
pub fn register_ignored(&mut self, name: &str) {
if self.by_name.insert(name.to_string(), Ignored).is_some() {
bug!("duplicate specification of lint {}", name);
}
}

/// This lint has been renamed; warn about using the new name and apply the lint.
#[track_caller]
pub fn register_renamed(&mut self, old_name: &str, new_name: &str) {
let target = match self.by_name.get(new_name) {
@@ -284,6 +316,7 @@ impl LintStore {
Some(&Id(lint_id)) => Ok(vec![lint_id]),
Some(&Renamed(_, lint_id)) => Ok(vec![lint_id]),
Some(&Removed(_)) => Err(FindLintError::Removed),
Some(&Ignored) => Ok(vec![]),
None => loop {
return match self.lint_groups.get(lint_name) {
Some(LintGroup { lint_ids, depr, .. }) => {
@@ -427,6 +460,7 @@ impl LintStore {
}
},
Some(&Id(ref id)) => CheckLintNameResult::Ok(slice::from_ref(id)),
Some(&Ignored) => CheckLintNameResult::Ok(&[]),
}
}

2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
@@ -340,7 +340,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
"non_autolinks",
];
for rustdoc_lint in RUSTDOC_LINTS {
store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint));
store.register_ignored(rustdoc_lint);
}
store.register_removed(
"intra_doc_link_resolution_failure",
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/hir/map/collector.rs
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ fn insert_vec_map<K: Idx, V: Clone>(map: &mut IndexVec<K, Option<V>>, k: K, v: V
if i >= len {
map.extend(repeat(None).take(i - len + 1));
}
debug_assert!(map[k].is_none());
map[k] = Some(v);
}

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

// FIXME: feature(impl_trait_in_bindings) broken and trigger this assert
//assert!(data.signature.is_none());

debug_assert!(data.signature.is_none());
data.signature =
Some(self.arena.alloc(Owner { parent: entry.parent, node: entry.node }));

Loading